[Networking] Ralph Server + Client HELP


Ive managed to fully get a server and client running with ralph.
Users can login to the server which connects to MySQL and checks information.

How do i go about loading other users x,y,z and then adding their model into the game? Also how to send the coordinates to the server?

Ive heard about predicting their x,y,z so you dont need to send coordinates every 1 sec or so but im not sure how…

There isnt much on the forums to do with this, or not that i can find.


  • Chris

you “could” do the following.
when a player logs in on your server. give him a unique ID (for example an continous number starting from 0).
then start to send his data to the clients.
the server sends the positions+ID to the clients.
the clients receive the data, check if they already have a model loaded which matches the ID, update its position.
if the ID is still unknown to the client. the client loads a new model, tags it with the ID, and displays it.

its a very simple but robust way to add player. removing them is a bit more tricky (especially if they quit due to lost connection).

about prediction: you can use prediction, but you don’t always have to. this depends on your application. for example:
-a first-person-shooter: very timing-criticial, if people aim at something and shoot, they want to hit it, without prediction you can only play such games on LAN or with really good internet-conenctions.
-an (mmo)rpg: you usualy controll your player. movements are not really timing critical in most cases. lags up to a second have only little impact on the gameplay. prediction does help here a bit.lag-compensation is recommended.
-a strategy game: usualy you only give your commands, it rarely matters if your unit starts to move 1 second sooner or later as long as their movement itself is fluid.

so it really depends. if you dont need fast-paced timing-critical representation of your game world. you can just send data every 500ms or maybe only once per second. and lerp-interpolate your players to the new position. it sounds like a cheap&dirty trick. but it works quite well for 3rd-person stuff where you only walk around

if i find some free time i can untrash some old code of mine to show an example.


That actually makes alot of sense now that i read it…
How would i use lerp? Ive tried before, but it just seems to not work for me…

Im building an (mmo)rpg just for referance…

an example would help alot… Thanks again!

Also I want to add on that you may want to have a buffer for all the incomming messages so your computer can “pick” witch ones to deal with first over other things. This alows for any lag that may happen or to many messages comming in at any one time. For example a new player’s movement(s) comes in very fast so instead of waiting to get all the player(s) movements you may only want the newest of them.

panda3d.org/manual/index.php/U … _the_Panda

Sorta tells you how to use them, they are really easy to use. They take their current position then move to the positon you tell them to move to.

self.userlist[self.otherperson].posInterval(.4, Point3(theirx,theiry,theirz), fluid=1).start()

This calls for my user list (a list of ips that the computer knows that is connected to the server) and changes their position in a fluid like state. Meaning it “moves” instead of just jump to the position like Actor.setpos() would do. The “theirx-z” is the number they sent the server when they either moved their x-z movements. You could also add + 5 or how ever fast your players move so to take in for the lag that could happen.

My client now sends the x,y,z to the server and the server sends it to all clients.

I dont know how to make a actor for each client and then check if it exists etc etc.

how do i make a buffer like you suggested?
How do you add remove a users from self.user list and also how to view them?

you dont have to do the buffering, it was just a optimization thing you could do later on.

To store the ip, you can do this 2 ways, either by just the server (client server) or have all clients know about it and handle them for their own use (P2P)

Server to client is the safest but also a little slower.
P2P fastest but not really safe.

Heres a mixs of both, you can have the server store the ip in a stack or list then call a “if then” to see if that ip in your list. If it is, then send its data onto the other clients like for example

If in self.userlist:
  send.data = " X=-1,Y=10,Z=45"
elif not in self.userlist:
  'Tho if you want to make this safe you wouldnt send their ips to the other clients but just send their current postion in the list instead.
  SendAll self.userlist


if in self.userlist:
  'get its number in the userlist then make a array to go with it to make the actors.
  self.userlist[theirnumber] = loader.loadModel("cube")
  'so on what ever else they may need
elif not in self.userlist:
  'tell the server you need a new userlist
  send.data = "server need new a new userlist 

Hope this helps, sorry I didn’t go indeath in code, some of the stuff more python then panda 3d, so the net would help you on more of the code.

my advice… dont use P2P stuff unless you have experience with it and know what you’r doing. handling data in p2p networks is hard to keep consistent. manipulation is easy unless you make it very difficult and keeping track of disconnects sux.
i might find some time to untrash my code on sunday.

Below is my version

in my init i have

self.userlist = []

    def msgGetCoordinates(self, msgID, data):
        flag = data.getString()
        (clientID, data, dataA, dataB) = flag.split(', ')
        if clientID in self.userlist:
            self.userlist[clientID] = loader.loadModel("data/models/ralph")
            #clientStartPosX = float(data)
            #clientStartPosY = float(dataA)
            #clientStartPosZ = float(dataB)
            #self.userlist[clientID].setPos(clientStartPosX, clientStartPosY, clientStartPosZ)
        elif not clientID in self.userlist: 
            print clientID + 'APPENDED'

Thats what i have in my class.
However it doesnt work… any ideas?

The error is: List indecies must be integers
and the error happens at self.userlist[clientID] = loader.loadModel(“data/models/ralph”)

I dont do anything server side, except send the ClientID, x, y and z…

Here is my server, client and globals

its missing settings and language files but there not relevant.
Might help me with my problems if you can see my entire code.

2shared.com/file/5693681/b7f … obals.html
2shared.com/file/5693684/7b1 … erver.html


Please anyone?