Help with UDP?

OmniStudent
Member
 
Posts: 261
Joined: Sat Nov 03, 2012 06:40

Help with UDP?

by OmniStudent » Wed Nov 28, 2012 07:35

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?
 

User avatar
Calinou
Member
 
Posts: 3124
Joined: Mon Aug 01, 2011 14:26
GitHub: Calinou
IRC: Calinou
In-game: Calinou

by Calinou » Wed Nov 28, 2012 08:47

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.
 

OmniStudent
Member
 
Posts: 261
Joined: Sat Nov 03, 2012 06:40

by OmniStudent » Wed Nov 28, 2012 11:53

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
 

OmniStudent
Member
 
Posts: 261
Joined: Sat Nov 03, 2012 06:40

by OmniStudent » Wed Nov 28, 2012 21:19

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!

Image

After hours of hopeless courting, finally a response!
Last edited by OmniStudent on Wed Nov 28, 2012 21:20, edited 1 time in total.
 

User avatar
aldobr
Member
 
Posts: 316
Joined: Sun Nov 25, 2012 05:46

by aldobr » Fri Nov 30, 2012 09:48

Mind sharing the packet formats with us ?
 

OmniStudent
Member
 
Posts: 261
Joined: Sat Nov 03, 2012 06:40

by OmniStudent » Fri Nov 30, 2012 19:52

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.
Code: Select all
#define SEQNUM_INITIAL 65500

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.
 

rarkenin
Member
 
Posts: 668
Joined: Tue Nov 20, 2012 20:48

by rarkenin » Sat Dec 08, 2012 20:36

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?
Admin pro tempore on 0gb.us:30000. Ask me if you have a problem, or just want help.
This is a signature virus. Add me to your signature so that I can multiply.
Now working on my own clone, Mosstest.
I guess I'm back for some time.
 

OmniStudent
Member
 
Posts: 261
Joined: Sat Nov 03, 2012 06:40

by OmniStudent » Mon Dec 10, 2012 07:26

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.
Last edited by OmniStudent on Mon Dec 10, 2012 08:40, edited 1 time in total.
 

User avatar
aldobr
Member
 
Posts: 316
Joined: Sun Nov 25, 2012 05:46

by aldobr » Wed Dec 12, 2012 16:04

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=4023

this 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.
 

OmniStudent
Member
 
Posts: 261
Joined: Sat Nov 03, 2012 06:40

by OmniStudent » Thu Dec 13, 2012 09:14

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.
 

User avatar
aldobr
Member
 
Posts: 316
Joined: Sun Nov 25, 2012 05:46

by aldobr » Thu Dec 13, 2012 11:58

well, take the npc, remove his brain, put a TCP lua wrapper and exchange info via tcp with a remote application !
 

OmniStudent
Member
 
Posts: 261
Joined: Sat Nov 03, 2012 06:40

by OmniStudent » Thu Dec 13, 2012 13:01

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.
Last edited by OmniStudent on Thu Dec 13, 2012 20:11, edited 1 time in total.
 

Ragnar
Member
 
Posts: 850
Joined: Thu Oct 25, 2012 15:19

by Ragnar » Thu Dec 13, 2012 15:17

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
Are you saying that I put an abnormal brain into a seven and a half foot long, fifty-four inch wide GORILLA?
 

OmniStudent
Member
 
Posts: 261
Joined: Sat Nov 03, 2012 06:40

by OmniStudent » Thu Dec 13, 2012 19:07

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)
 

OmniStudent
Member
 
Posts: 261
Joined: Sat Nov 03, 2012 06:40

by OmniStudent » Mon Dec 17, 2012 06:33

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!)
 

User avatar
kaeza
Member
 
Posts: 2141
Joined: Thu Oct 18, 2012 05:00
GitHub: kaeza
IRC: kaeza diemartin blaaaaargh
In-game: kaeza

by kaeza » Mon Dec 17, 2012 16:05

+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.
Your signature is not the place for a blog post. Please keep it as concise as possible. Thank you!

Check out my stuff! | Donations greatly appreciated! PayPal | BTC: 1DFZAa5VtNG7Levux4oP6BuUzr1e83pJK2
 

OmniStudent
Member
 
Posts: 261
Joined: Sat Nov 03, 2012 06:40

by OmniStudent » Mon Dec 17, 2012 19:34

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.
 

OmniStudent
Member
 
Posts: 261
Joined: Sat Nov 03, 2012 06:40

by OmniStudent » Wed Jan 02, 2013 22:18

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.
 

tinoesroho
Member
 
Posts: 570
Joined: Fri Feb 17, 2012 21:55

by tinoesroho » Fri Jan 04, 2013 02:18

Next up: add in random taunts and "griefing simulation" - an excellent approximation of a Minecraft player!
We are what we create.

I tinker and occasionally make (lousy) mods. Currently building an MMO subgame and updating mods. Pirate Party of Canada member. Sporadic author. 21 years old.

My github:
https://github.com/tinoesroho/
 

OmniStudent
Member
 
Posts: 261
Joined: Sat Nov 03, 2012 06:40

by OmniStudent » Fri Jan 04, 2013 08:35

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
 

OmniStudent
Member
 
Posts: 261
Joined: Sat Nov 03, 2012 06:40

by OmniStudent » Sat Jan 05, 2013 18:43

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.
 

OmniStudent
Member
 
Posts: 261
Joined: Sat Nov 03, 2012 06:40

by OmniStudent » Sat Jan 05, 2013 20:15

double LOL!

Second attempt :
http://youtu.be/NAlHvsIKeis
 

rarkenin
Member
 
Posts: 668
Joined: Tue Nov 20, 2012 20:48

by rarkenin » Wed Jan 09, 2013 13:25

If you're interested, I've started a different attempt, using image recognition.
Admin pro tempore on 0gb.us:30000. Ask me if you have a problem, or just want help.
This is a signature virus. Add me to your signature so that I can multiply.
Now working on my own clone, Mosstest.
I guess I'm back for some time.
 

OmniStudent
Member
 
Posts: 261
Joined: Sat Nov 03, 2012 06:40

by OmniStudent » Wed Jan 09, 2013 18:41

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!
 

User avatar
kaeza
Member
 
Posts: 2141
Joined: Thu Oct 18, 2012 05:00
GitHub: kaeza
IRC: kaeza diemartin blaaaaargh
In-game: kaeza

by kaeza » Wed Jan 09, 2013 20:23

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.
Last edited by kaeza on Wed Jan 09, 2013 20:24, edited 1 time in total.
Your signature is not the place for a blog post. Please keep it as concise as possible. Thank you!

Check out my stuff! | Donations greatly appreciated! PayPal | BTC: 1DFZAa5VtNG7Levux4oP6BuUzr1e83pJK2
 

rarkenin
Member
 
Posts: 668
Joined: Tue Nov 20, 2012 20:48

by rarkenin » Wed Jan 09, 2013 20:31

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.
Admin pro tempore on 0gb.us:30000. Ask me if you have a problem, or just want help.
This is a signature virus. Add me to your signature so that I can multiply.
Now working on my own clone, Mosstest.
I guess I'm back for some time.
 

OmniStudent
Member
 
Posts: 261
Joined: Sat Nov 03, 2012 06:40

by OmniStudent » Thu Jan 10, 2013 06:33

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.
 

OmniStudent
Member
 
Posts: 261
Joined: Sat Nov 03, 2012 06:40

by OmniStudent » Fri Jan 11, 2013 10:14

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!
 

rarkenin
Member
 
Posts: 668
Joined: Tue Nov 20, 2012 20:48

by rarkenin » Fri Jan 11, 2013 11:22

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.
Last edited by rarkenin on Fri Jan 11, 2013 11:26, edited 1 time in total.
Admin pro tempore on 0gb.us:30000. Ask me if you have a problem, or just want help.
This is a signature virus. Add me to your signature so that I can multiply.
Now working on my own clone, Mosstest.
I guess I'm back for some time.
 

OmniStudent
Member
 
Posts: 261
Joined: Sat Nov 03, 2012 06:40

by OmniStudent » Sat Jan 12, 2013 06:49

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 :)
 

Next

Return to Minetest Engine

Who is online

Users browsing this forum: No registered users and 2 guests

cron