MP server IRC-like bot

Discussion of all aspects of multiplayer development: unit balancing, map development, server development, and so forth.

Moderator: Forum Moderators

Post Reply
User avatar
norbert
Posts: 368
Joined: June 14th, 2009, 6:57 pm
Location: The Netherlands

MP server IRC-like bot

Post by norbert »

[Edit: Newer versions of wesirc are available; see further down this thread!]

As some of you already know, I'm currently working on a bot (coded in C) that will connect to the MP server to interact with users. My goal is to allow users to vote on maps and get map information via my bot. I have some code ready and it's attached to this post. Note that this is just version 0.1, so don't expect too much.

Two main problems with this code: 1. most of it works with a wesnothd on localhost, but not with server.wesnoth.org, and 2. for some reason, the hash created with the salt and password is incorrect. I'd appreciate help with both things.

I will update this wiki page and add a section before "The login procedure" about the handshake. Basically, the client sends 4 bytes (0x00 0x00 0x00 0x00) to get a new connection number. The server sends the number back and then the communication back and forth is <package size (4 bytes)><gzipped package>.
Attachments
wesirc-0.1.tar.gz
wesirc 0.1
(22.93 KiB) Downloaded 382 times
Last edited by norbert on June 4th, 2010, 6:39 pm, edited 2 times in total.
joshudson
Posts: 501
Joined: January 17th, 2006, 8:04 pm
Contact:

Re: MP server IRC-like bot

Post by joshudson »

Great! I've been after that info to make a command line lobby program.
CHKDSK has repaired bad sectors in CHKDSK.EXE
User avatar
norbert
Posts: 368
Joined: June 14th, 2009, 6:57 pm
Location: The Netherlands

Re: MP server IRC-like bot

Post by norbert »

Hi Sirp, I have a question about the unsigned char* md5 function in hash.cpp. Normally, md5 returns only readable characters, but the md5_worker.raw_digest() that this function returns contains non-readable characters. When I add two printf-lines to show the in- and output...

Code: Select all

unsigned char* md5(const std::string& input) {
  printf ("INPUT: >%s<\n", input.c_str());
  MD5 md5_worker;
  md5_worker.update((unsigned char*) input.c_str(), input.size());
  md5_worker.finalize();
  printf ("OUTPUT: >%s<\n", md5_worker.raw_digest());
  return md5_worker.raw_digest();
}
...and add a user/pass combination "testuser"/"testpass" to phpBB, with for example the salt "$H$9eCZoV4ty74753177", the first couple of printf outputs are:
Spoiler:
The first output should be: b3159a773652b766989242b00bc698cb
Why is it different, what's going on?
Dave
Founding Developer
Posts: 7071
Joined: August 17th, 2003, 5:07 am
Location: Seattle
Contact:

Re: MP server IRC-like bot

Post by Dave »

norbert wrote:Hi Sirp, I have a question about the unsigned char* md5 function in hash.cpp. Normally, md5 returns only readable characters, but the md5_worker.raw_digest() that this function returns contains non-readable characters.
MD5 produces a 16 byte digest. It is customary for human readability to display these 16 bytes in hex, meaning you will see 32 hexadecimal characters. However, raw_digest() returns just the 16 bytes. Of course, printing out a raw digest in hex is pretty easy:

Code: Select all

for(int n = 0; n != 16; ++n) {
  printf("%02x", digest[n]);
}
“At Gambling, the deadly sin is to mistake bad play for bad luck.” -- Ian Fleming
User avatar
norbert
Posts: 368
Joined: June 14th, 2009, 6:57 pm
Location: The Netherlands

Re: MP server IRC-like bot

Post by norbert »

Dave wrote:MD5 produces a 16 byte digest.
Right; I should have seen that.
Anyways, thanks for the feedback.

[Edit: I attached a file to this post that shows (exactly) how hashed passwords are being generated in Wesnoth.]
Attachments
HashedPasswords.pdf
Hashed Password Generation in Wesnoth
(884.54 KiB) Downloaded 1752 times
User avatar
norbert
Posts: 368
Joined: June 14th, 2009, 6:57 pm
Location: The Netherlands

Re: MP server IRC-like bot

Post by norbert »

norbert wrote:As some of you already know, I'm currently working on a bot (coded in C) that will connect to the MP server to interact with users.
Okay, it was a lot of work, but I finally managed to fix the two bugs in version 0.1. Version 0.2 of wesirc is attached to this post. It now: connects to the server, sends its version number, redirects if instructed, if required generates a correct hashed password, sends ping replies, and replies to messages it receives. :D I'm now going to work on getting the bot to act as a bridge between wsrsw.org and the users in the lobby!
Attachments
wesirc-0.2.tar.gz
wesirc 0.2
(23.18 KiB) Downloaded 368 times
User avatar
norbert
Posts: 368
Joined: June 14th, 2009, 6:57 pm
Location: The Netherlands

Re: MP server IRC-like bot

Post by norbert »

Attached is wesirc version 0.3. I've added the first two WSRSW features to the bot, and it's now also communicating with the MySQL database. The added features are:

/whisper <NICK> mapp <scenario>
Returns the map pack that contains the <scenario> - if any.

/whisper <NICK> comment <scenario>|<comment>
Adds the <comment> to the add-on page of the <scenario>.
Attachments
wesirc-0.3.tar.gz
wesirc 0.3
(27.28 KiB) Downloaded 358 times
User avatar
norbert
Posts: 368
Joined: June 14th, 2009, 6:57 pm
Location: The Netherlands

Re: MP server IRC-like bot

Post by norbert »

Attached is wesirc version 0.4. Two more WSRSW features were added:

/whisper <NICK> get_votes <scenario>|<whose>
Provides information about how the <scenario> is rated.
<whose> should be 'my' or 'all'
Example: /whisper <NICK> get_votes 4p - Isar's Cross|all

/whisper <NICK> vote <scenario>|derf<difficulty><enjoyment><replayability><favorite>
Adds your votes to the <scenario>.
votes should be '1' (low), '2' (normal) or '3' (high)
<favorite> should be '0' (no) or '1' (yes)
Example: /whisper <NICK> vote 4p - Isar's Cross|derf2130

This is the penultimate version to be added on the forum.
Attachments
wesirc-0.4.tar.gz
wesirc 0.4
(30.54 KiB) Downloaded 357 times
Post Reply