Page 1 of 2
Help with UDP?

Posted:
Wed Nov 28, 2012 07:35
by OmniStudent
I'm trying to make a client "bot", for running NPCs with AIs that won't take up the servers processing capabilities.
However, I'm either doing something wrong, or Minetest refuses to listen to a second local player (one is started when I start the server in GUI mode).
Can anyone tell me how to get Minetest to write the information it received from a client to debug.txt?

Posted:
Wed Nov 28, 2012 08:47
by Calinou
Create a dedicated server, or a "listen" server from your client (by putting no address in the "Advanced" tab), then connect the second client with the address "localhost" (or 127.0.0.1), it should always work.

Posted:
Wed Nov 28, 2012 11:53
by OmniStudent
Calinou wrote:Create a dedicated server, or a "listen" server from your client (by putting no address in the "Advanced" tab), then connect the second client with the address "localhost" (or 127.0.0.1), it should always work.
Yes I have a dedicated server set up in the way you suggest.
The problem is that it doesn't respond to my home-made UDP "client", which so far only sends (I hope) an SERVER_INIT request to the server.
I don't understand the server code enough to see if it even receives ANY signal from my client program, much less if the signal I've put together (using what I assume is some binary stuff from the original client code) is understood by the server.
My primary concern right now is actually to get the server to print the TEXT or data messages it receives on port 30000 to debug.txt

Posted:
Wed Nov 28, 2012 21:19
by OmniStudent
I finally got the minetest server to respond!
I had missed that the message to the server is wrapped in some extra data by makePacket in connection.cpp.
Now I can send messages that the server thinks is from a new player!

After hours of hopeless courting, finally a response!

Posted:
Fri Nov 30, 2012 09:48
by aldobr
Mind sharing the packet formats with us ?

Posted:
Fri Nov 30, 2012 19:52
by OmniStudent
aldobr wrote:Mind sharing the packet formats with us ?
I didn't figure out the whole package format when I mangaged to do this, and now I'm stuck because I can't figure out the rest.
Here's what I got so far:
Most of the packet making and processing goes on in connection.cpp, socket.cpp, and some in server.cpp. The h files of these contains some info about the package format, and define constants that are used everywhere in the files.
The Receive and Send functions in socket.cpp can be set to printing the packages but setting DP to true.
Here's the line I send to Minetest to make it respond:
4F45 7403 0000 0001 0010 194D 6F6E 6973 7475 6465...
4F45 7403 -an "id" that must precede all messages
0000 probably peer id of server
00 probably channel
01 control type?
00 unknown
10 I think this is the SERVER_INIT1 code
19 possible SER_FMT_VER_HIGHEST
4D 6F6E 6973 7475 6465 - my username
I mostly used this part of client.cpp to figure out the first message to send to the server :
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
// Send TOSERVER_INIT
// [0] u16 TOSERVER_INIT
// [2] u8 SER_FMT_VER_HIGHEST
// [3] u8[20] player_name
// [23] u8[28] password (new in some version)
// [51] u16 minimum supported network protocol version (added sometime)
// [53] u16 maximum supported network protocol version (added later than the previous one)
SharedBuffer<u8> data(2+1+PLAYERNAME_SIZE+PASSWORD_SIZE+2+2);
writeU16(&data[0], TOSERVER_INIT);
writeU8(&data[2], SER_FMT_VER_HIGHEST);
memset((char*)&data[3], 0, PLAYERNAME_SIZE);
snprintf((char*)&data[3], PLAYERNAME_SIZE, "%s", myplayer->getName());
/*infostream<<"Client: sending initial password hash: ""<<m_password<<"""
<<std::endl;*/
memset((char*)&data[23], 0, PASSWORD_SIZE);
snprintf((char*)&data[23], PASSWORD_SIZE, "%s", m_password.c_str());
writeU16(&data[51], CLIENT_PROTOCOL_VERSION_MIN);
writeU16(&data[53], CLIENT_PROTOCOL_VERSION_MAX);
// Send as unreliable
Send(0, data, false);
The server then responds with a command I think means "set your client id to 2:
4F45 7403 0001 0003 FFDC 0001 0002
The high number FFDC in the middle corresponds to
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
in connection.h. I think this has something to do with "reliable" packets, whatever those are.
If you have any further questions, please let me now.

Posted:
Sat Dec 08, 2012 20:36
by rarkenin
Right now, I am also trying to make my own wrapper for something like this. Will someone working on development explain the network protocol? With that said, when you make such a "bot", can you release a copy of the source? With that said, what language is it written in?

Posted:
Mon Dec 10, 2012 07:26
by OmniStudent
I got lost and changed strategy:
Writing a program myself that used the minetest protocol got too complicated, especially for two reasons:
Minetest sometimes uses "split packages" that I haven't been able to decipher.
There is a system for acknowledning and re-sending "Reliable" packages that I don't understand.
But for people more fluent in C++, I think the protocol is quite clearly described in the source code comments.
My current strategy for the "bot" is basically just a commandline, headless client. This means that I have to remove all dependencies to Irrlicht for the client (something I think should be done anyway*).
So far I've got a commandline prog that puts a second player in the game, but I can't get it to move.
* Sorry, I really don't like phrases like "should be done", as it implies "should be done BY SOMEONE ELSE", but I don't have the programming skills to do this.

Posted:
Wed Dec 12, 2012 16:04
by aldobr
Omni, i have another idea:
Use lua as a bridge between a bot and another program.
We can make our own protocol. My bot is intended to run in the same machine as the minetest server, so we can use TCP without problems.
(TCP = no need to create special reliability packets etc, a lot of problems are solved, only problem is that it lags a lot on unreliable links)
In the lua side of things you will need lua:sockets. We can make the server load lua:sockets (i dont even know yet how to do this :P)
Lua can talk TCP and UDP.
So, concluding, take this as a starting point :
http://minetest.net/forum/viewtopic.php?id=4023this mod currently is "mindless" (the bot wanders around).
make a proxy between this npc and the external program using TCP.
I believe this will be a much easier road.

Posted:
Thu Dec 13, 2012 09:14
by OmniStudent
I dunno, I'm mainly doing this to get familiar with the minetest c++ code, so I don't want to mix in lua.
Seems like jordan4ibanez has come a lot further than I on NPCs, but using a separate computer for running them opens up opportunities for really smart NPCs.

Posted:
Thu Dec 13, 2012 11:58
by aldobr
well, take the npc, remove his brain, put a TCP lua wrapper and exchange info via tcp with a remote application !

Posted:
Thu Dec 13, 2012 13:01
by OmniStudent
But now that I use a mutilated version of the minetest game, UDP works for the communication. Everything is done just as with a human player.
I've already got most of this working, but from the position info I get from the bot player, he appears to be rapidly falling towards the center of the earth (freemove with no fly? Something I removed in the code marking the player as "on firm ground?).
He appears to be doing random movement as he is supposed to - all three coords are changing - but I haven't been able to observe it with another player in the game, because of the aforementioned falling problem.

Posted:
Thu Dec 13, 2012 15:17
by Ragnar
if i understand correctly (that the npcs will move, maybe follow a player, hit him/her if he gets hit, maybe even builds something) than i cant wait til this gets released

Posted:
Thu Dec 13, 2012 19:07
by OmniStudent
Ragnar wrote:if i understand correctly (that the npcs will move, maybe follow a player, hit him/her if he gets hit, maybe even builds something) than i cant wait til this gets released
That's the idea. There seem to be a lot of people interested in NPCs/AI, so I don't think you'll have to wait TOO long.
(Progress report: NPC still plumetting)

Posted:
Mon Dec 17, 2012 06:33
by OmniStudent
STILL no progress on the movement code! It seems to reside in localplayer.cpp, environment.cpp, client.cpp, player.cpp... I can't make heads or tails of it!
Help!
(But now I've changed the code so much, nothing less than a full description of the local player movement will help me, so ARRGGGH!)

Posted:
Mon Dec 17, 2012 16:05
by kaeza
+1 Cool!
I like the idea of a bot as NPC. Can you provide a link to the code? If pleople see your code, they may be better able to help you.

Posted:
Mon Dec 17, 2012 19:34
by OmniStudent
kaeza wrote:+1 Cool!
I like the idea of a bot as NPC. Can you provide a link to the code? If pleople see your code, they may be better able to help you.
Providing a link to the code is pointless: this is my first attempt at C++ in ten years and I never was any good with it to start with.
The code is a horribly mutilated and Frankensteined carcass of Minetest 0.4.3 with uncommented changes in like ten of the major classes. Anyone fluent in C++ could do it better in half a week. If I manage to get it working, I'll clean the code and publish it though.
UPDATE: I've made some progress since this morning, at least:
By setting gravity real low, I have now been able to observe the elusive, ground-through-falling tirre2222 (the bots name at the moment) in-game. He moves back and forth randomly as supposed to, obeying the random function for movement, while gently falling down to the ground and then through it.

Posted:
Wed Jan 02, 2013 22:18
by OmniStudent
UPDATE:
I finally solved a bloody "bus error" that almost made me give up. It was probably an audio function that got a NULL pointer, since sound is disabled/commented out.
I now have a program that logs into my server with a player that jumps around randomly (there is a ready-made function for random movement in the code). It obeys physics and doesn't fall through the ground anymore.
Problem is its FLAT, since the code I started on was pre-0.44. It will be an interesting adventure to go through the new code and see how they've changed it.

Posted:
Fri Jan 04, 2013 02:18
by tinoesroho
Next up: add in random taunts and "griefing simulation" - an excellent approximation of a Minecraft player!

Posted:
Fri Jan 04, 2013 08:35
by OmniStudent
No need to bash Minecraft. Not many games are so good I'm interested in their open-source alternatives.
Bad players happes when you get enough people together, regardless of what game it is.
"Hell is other people" - Sartre

Posted:
Sat Jan 05, 2013 18:43
by OmniStudent
LOL :D
During my attempts to make a "follow" function, the (now 3D) bot got scared of me and ran into the sea.
Progress report:
Adapting the 0.4.4 code to my changes was way easier than I thought it would be. I used the splitdiffwith function in macVim (editor of choice). Some chunks of new code pertaining to bones flashed by, but I never really looked at how the 3D player figures were done.
I now have a "bot" that can sense the type of blocks around it, and find the position of other players. I am now trying to get the bot to turn towards an "owner" player, with the abovementioned hilarious results.

Posted:
Sat Jan 05, 2013 20:15
by OmniStudent
double LOL!
Second attempt :
http://youtu.be/NAlHvsIKeis

Posted:
Wed Jan 09, 2013 13:25
by rarkenin
If you're interested, I've started a
different attempt, using image recognition.

Posted:
Wed Jan 09, 2013 18:41
by OmniStudent
Not sure I understand, but image recognition is cool in any case!
It would be very cool to have MOBs using image recognition to spot players!

Posted:
Wed Jan 09, 2013 20:23
by kaeza
OmniStudent wrote:Not sure I understand, but image recognition is cool in any case!
It would be very cool to have MOBs using image recognition to spot players!
That's overkill. Why scan an image to find a pattern when you have the player position/looking direction and surrounding nodes readily available from the communication with the server? It would require *way* less computation (processor time) to just check if the player is in the bot's field of vision.

Posted:
Wed Jan 09, 2013 20:31
by rarkenin
kaeza wrote:OmniStudent wrote:Not sure I understand, but image recognition is cool in any case!
It would be very cool to have MOBs using image recognition to spot players!
That's overkill. Why scan an image to find a pattern when you have the player position/looking direction and surrounding nodes readily available from the communication with the server? It would require *way* less computation (processor time) to just check if the player is in the bot's field of vision.
The thing is, I gave u[ on network communication before this progress occured.

Posted:
Thu Jan 10, 2013 06:33
by OmniStudent
kaeza wrote:OmniStudent wrote:Not sure I understand, but image recognition is cool in any case!
It would be very cool to have MOBs using image recognition to spot players!
That's overkill. Why scan an image to find a pattern when you have the player position/looking direction and surrounding nodes readily available from the communication with the server? It would require *way* less computation (processor time) to just check if the player is in the bot's field of vision.
I know its overkill, but it would allow for eg camouflage and non-omniscient mobs. Players will have to plan with the knowledge that the MOBs might SEE them, rather than planning according to whether they're IN RANGE of a MOB.

Posted:
Fri Jan 11, 2013 10:14
by OmniStudent
rarkenin wrote:The thing is, I gave u[ on network communication before this progress occured.
Would you like to have my files? They're basically the minetest source with some stuff added or commented out, but makes a bot that can tell the material on nodes around it, loop through active objects (like other players) and can respond to chat commands.
Right now I'm trying to move the decision making into a "brain" class, that sets the bot commands according to the sensory input it gets from chat, nodes and active objects.
But I don't want to discourage you from your image recognition project as I think that's way cooler!

Posted:
Fri Jan 11, 2013 11:22
by rarkenin
I can never seem to compile Minetest in the build environment of my choice. Sorry. Can I still take a look at the files?
Anyway, I hope we could possibly collaborate on one, or both, of our projects.
I'm good with algorithm design, but dealing with the intricacies of C++ is a bit too much for me, as I get mired in formalities of the code.

Posted:
Sat Jan 12, 2013 06:49
by OmniStudent
Uploading the files to a dropbox folder now - tried to upload it to github but don't have the brains for it.
It will probably take some time to make sense of the files but I'm here to answer questions. If you like it, we can build on it together on github. I think I've already done the hard work, which was building the client as command-line, so the program is ready for programming bot behaviour.
Unfortunately, my c++ skills are quite low as well. I get by with tutorials and cut-and-paste :)