WSAG Multi Player Online Network Game

There are 2 standard ways to handle disconnects.

  1. The socket supports events / callback hooking:
    You can give a pointer to the code that handles the event and tell the socket to call that on any disconnect. Well, that won’t work on UDP and broadcast sockets because they are connection less. Note some routers cut TPC connections if there was no traffic for a specific interval , so the client might want to reconnect immediately. ( Very rare case for games i think )

  2. Keep alive / ping packets
    The client must send a small ’ i am still alive ’ packet every now and then or the server sends ‘are you still living’ packets. In any case you work down the list “last time client was seen alive” and if a client failed to answer/report N- times it is assumed to be gone.

In any case i don’t know how to do it in python but have done both several times in C.
The second way is a bit clumsy and creates additional network load, but i prefer it still because it is very tolerant.
And if you start every message with the client ID you can keep the “last time client was seen alive” list on the fly.
Things may get pretty nasty when you use separate threads for “regular” traffic and “administrative” on the other hand then you are absolutely free in tuning the timeouts.

BM

I was thinking of your Idea #2
I’M just not sure how to go about it.
I could have the Server open an extra port that doses nothing else then to ping the Clients… If client is not answering the Pin for lets say 10 times the Server will think its Disconnected. Now comes the hard part how do I set up the Server and the Clients to delete all the related things of the just disconnected Client.
See list above…
This would be easy If I had every Client defined but since my script is Dynamic and all things needed for a client is created in real-time and stands together in proportion of different lists and Dictionaries it gets hard to define what parts will have do get disconnected (deleted)… have you looked at my WSAGdev.blend and read the Tutorial that shows how everything is set up…
The second way I was thinking of is:
If I hat a counter in the receive script and it counts how many times it missed to receive Data from a client. There it would already have all the Data of that Client in the Right proportion and would be able to disconnect all of them together… At least for the Server side… the Client side has all dictionaries because it dose not know in what order it receives Data so it would be a little bit more complicated there.
But my main problem is that this solution would slow down the Sync time very much… so…
Thanks for your idea.
Hope to get more…

Have been browsing the word doc briefly.
I vaguely understood that everything is controlled by the game engine and script linking -->
There is no object called “Server” which holds a list of all open sockets, this Server would also know the method “Notify All Clients” …“Add Client” “Remove Client”
and it would be the only one allowed to accept a connection to a “Server socket”
One method of this object would use the list of open sockets to the clients to “ping” them.
The only thing in the scripts would be
TheServer.AddClient()

TheServer.RemoveClient()

TheServer.PingAll()

Hum, i think you should dig out the OOP side of Python
Well that would be the way i would try to go after 25 years of coding.
BM

No there is no object called server just different scripts that are all linked to the Main empty…
I do not totally understand how you would build this up. Do you have a .blend that would show…?
Or a small tutorial? This would not only help me but a lot of other people out there…

class Server:
     def init(self):
     nof_clients=0

      def AddClient(clientID,socket):
      #do something useful here
      # e.g. clientlist.append(clientID,socket)
      #....

      def RemoveClient(clientID):
       #do something useful here
       #....

#^^^^^^ this could be a external file e.g. myserver.py

# create one instance of the server
import myserver

... somewhere
TheServer = Server()

... somewhere
TheServer.AddClient(1234,sock)


this is about objects and classes

http://docs.python.org/tut/node11.html

found that so you could start a “background ping thread” without choking the GE process

http://docs.python.org/tut/node13.html#SECTION0013400000000000000000

Well i am a C , C++, Pascal, Delphi coder … so don’t ask me for python details but as far as i can see
that should work.

BM

How do I connect my bros comp to the server?

@Bjornmose
Thanx for the Code I will start working whit it and Post here when I have something that that works…
@alienKid
You get the WSAGdev.blend file on your and on your Bros Computer

On your Computer you start the WSAGdev.blend file and start a server (Space-Key, S-Key, R-Key (or B/G-Key))
Then you start a second WSAG.blend file there you Start a client (Space-Key, C-Key, R-Key (or B/G-Key), Enter your PlayerName and press the Enter-Key, Enter the Servers IP and press the Enter-Key) (the servers IP is displays in the Runtime Window of the server you started.) And Voila the first client is connected to the server
No in the Same way you start a Client on your Bros Computer.

Hope this helps…
OldJim

Thanks put you forgot to pack the textures in the dev file.

ups… sorry will update this mistake in the next 24h…

I just took a closer look at the WSAGdev.blend file the VErsion currently uplaodet is:
3.55WSAG.blend 30.3.08 15:27
And it has all textures Packed…
So I wonder what for a Problem you are having… Any body any Help
When you Open the File it schould look like the first picture I uploaded.
The I you change to “SR: My Setup 3D” Se first Picture. and then PRess the P-Key it should look like the second Picture. If you can see the Logo and the Text Intro… All textures are packet. If not… I hope someone can tell me what im doing wrong… everytime bevore I upload a File I go to File => Pack Date and then File=> Save As… give it the upload name and then I Zip it and upload it…

Attachments



OK thanks. was going through your tut and got explore mode done but I get stuck at player selection I checked the names heres my code for the playerselection menu

 import*
Cont = getCurrentController()
KeySens = Cont.getSensor("sKeyInput")
Keyinput = KeySens.getPressedKeys()
SetSceneAct = Cont.getActuator("aSetScene")


if GameLogic.PlayerMod == "Explorer":
	if Keyinput == [[98, 1]]:
		print "Player = Blue"
		GameLogic.PlayerTyp = "ContBlue"
		SetSceneAct.setScene("4eLocationSelection")
	
	if Keyinput == [[114, 1]]:
		print "Player = Red"
		GameLogic.PlayerTyp = "ContRed"
		SetSceneAct.setScene("4eLocationSelection")

	if Keyinput == [[103, 1]]:
		print "Player = Green"
		GameLogic.PlayerTyp = "ContGreen"
		SetSceneAct.setScene("4eLocationSelection")
addActiveActuator(SetSceneAct,1)

Code seams to be ok… Please send me your blend and I will take a look at it… its either a other part of code that is not wokring or a Logic Brick setup…

how do I send you my .blend?

the best way would be to eiter upload it somewehre and post the link here… or send me a Email… oldjim at bluewin dot ch

OK I am e-mailing it to you.

Howdy you are moving along very good don’t let yourself get discouraged by the Mistake list below:

Your mistakes are mostly typing mistakes… You really have to watch out that you Type everything the same way every Time. “test” is not the same as “Test” or “teest” or “tes” or “TTest”…

First mistake:
You Named the Scene where you select the Players “3ePlayerSection” and not “3ePlayerSelection” (you forgot the “l”)
If you do this then in the mainmenu.py in Line10

SetSceneAct.setScene(“3ePlayerSelection”)

it Will try to open a Scene that dose not exist whit this name…

Second Mistake:
In mainmenu.py
in Line 9 you have this code…

 GameLogic.PlayerMod = "Explore"

Then in ePlayerMenu.py
in Line 8 you have this code…

if GameLogic.PlayerMod == “Explorer”:

So the first time you write Explore the second time Explorer… This way the ePlayerMenu.py will never start because GameLogic.PlayerMod is not == Explorer…

Then in AddYourPlayer.py in Line 3:

if GameLogic.PlayerMod = = “Explore” or GameLogic.PlayerMod = = “Client”:

no spaces between the “=”
The code should look like this…

if GameLogic.PlayerMod == “Explore” or GameLogic.PlayerMod == “Client”:

Then in the LogicBricks of the Scene” 5BasicGamePlay”
you named the Actuator that will create your Player “AAddPlayer” and in the Script “AddYourPlayer.py” in Line 5 y

AddPlayerAct = cont.getActuator(“aAddPlayer”)

So the one Time you write “AAddPlayer” the second time “aAddPlayer” this will of course not work …

In The Script move.py in Line 15,17,19,21,23,26,31,33,35,37.39 and 43 you again have spaces between the “=”
these Lines should look like this for example:
Line 15

if Keyimput == [[146, 1]]:

Line 31

if Keyimput == [[146, 3]]:

This error whit the spaces between the “=” probably happened if you just Copied the Script from My Tutorial… In the Word File of My Tutorial I have spaces between the “=” because if you don’t you cant see that there are 2 “=” and not only One…

The in the LogicBricks of ContBlue you name the Actuator “AMove” and in the Script Move.py in Line 6:

MoveAct = Cont.getActuator(“aMove”)

once again “aMove” is not the Same as “AMove”

The you forgot the Logic Brick setup for ContRed and ContGreen
Just do the the same way as you did it for ContBlue… But write aMove and not AMove as name for the Actuator…

Okay and one last thing if you send or Post a File always go to File => Pack Data before you save the File and post it otherwise the other Person will have no Textures and that makes it hard to use the File or to find the Error…

Stay at it Start to work more precise and you will become a very god Blender Programmer and maybe will one day soon to come be able to help me Improve the WSAG setup…
Keep it up
OldJim

Thanks and I didn’t forget then for red and green there just hidden. Fixed sry about not packing. EDIT: it adds the player but I can’t move.

Okay Pack the Data and repost it to me and I will take a second look at it…
And here comes the first thing that you can learn me…

I didn’t forget then for red and green there just hidden.

How can you hide logick bricks?

Keep the good work up (im not sure that I will have time to look at your .blend befor Monday Morning but send it anyway as soon as posible. Maybe I will finde some time bevor…

yes click the name next to add.

Ok I got your secon .blend this time its just a small little thin in(22)WSAG – Gameplay – Setting up the Players – Moving (BV 2.44 PV 2.5.1) (LU 5.4.08) you can see in the screenshoot that you wil have to:
In the Logic Bricks of ContRed (ContGreen and ContBlue) click on the “Bounds” Button and then on the new appeared button called Compound. Make sure the dropdown menu is set to Box.

I will write this step more precise in the next update of the Tutorial
Thats it… See Screenshoot:

Attachments