00:00
00:00
jirachi99

Age 29, Male

Programmer

QLD, Australia

Joined on 11/13/07

Level:
6
Exp Points:
300 / 400
Exp Rank:
> 100,000
Vote Power:
4.58 votes
Rank:
Civilian
Global Rank:
> 100,000
Blams:
1
Saves:
5
B/P Bonus:
0%
Whistle:
Normal
Medals:
307

Making an online game P.2

Posted by jirachi99 - February 3rd, 2011


In addition to my previous post I will now explain HOW I will make the game actually run!

So as we have seen before, each players information will be stored on the save group here on Newgrounds, when you click 'Online Mulltiplayer' from the main menu and the game starts connecting here is what will be sent to the save groups.

\[USER].ipAddress
\[USER].port
\[USER].language

Just to begin with, then the person gets 2 options, Host game and Join Game, Since we have already covered hosting I will now show you Joining.

Once the user (Which from now on will be referred to as joinPlayer) finds a game and clicks join the first thing it does is downloads the IP from the server (Which is actually just another player hosting the game, and from now on will be referred to as serverPlayer), to get the IP and port from the server joinPlayer will want to check the save group for \serverPlayer.ipAddress and \serverPlayer.port for the IP and port numbers.

After getting the IP and PORT of serverPlayer, joinPlayer uses XMLSocket and send a piece of information saying 'joinPlayerWantsToJoin' and it is defined as true.

serverPlayer than recieves this information and checks the server for \joinPlayer.ipAddress and \joinPlayer.port.

After serverPlayer gets these it uses XMLSocket to connect to the player, now at this point the player has joined the game.

joinPlayer recieves info from serverPlayer saying that the request has been accepted or denied and if accepted the player starts to get info from serverPlayer

serverPlayer will now setup joinPlayer's data, this can include things like
MAP
GAMETYPE
CURRENTSCORETEAMA
CURRENTSCORETEAMB
SCORETOWIN
WEAPONS

And all that kind of data.

once serverPlayer has sent the initial data and joinPlayer has received and setup his game the actual game begins.

So, when joinPlayer spawns into the game the immediate thing to do is tell all other players in the lobby that joinPlayer is now playing!

To do this joinPlayer send data to serverPlayer simply saying 'joinPlayer.inGame' and serverPlayer will be waiting for this info!

After receiving the information the serverPlayer would tell all other players, now the serverPlayer has already downloaded the entire list of ip addresses and ports for everyone in the game so it knows where to send everything, now like before, all other players have already gone through what joinPlayer has gone through, so they will already be playing in the server

Ok so lets say there are 3 players OTHER THAN joinPlayer and serverPlayer, well call them alreadyPlayer1 2 and 3.

Now when serverPlayer recieves the info that joinPlayer is in the game it will XMLSocket the info to alreadyPlayer(i) (i being the number)

So joinPlayer joins, then he starts to walk forward...

joinPlayer is constantly sending various data about his player, things could include
PLAYERXPOSITION
PLAYERYPOSITION
PLAYERDIRECTION
PLAYERHEALTH

And so on

serverPlayer is constantly receiving all this data from joinPlayer and needs to do something with it...

to begin serverPlayer may need to slightly choke the info that he\she is getting to keep the game from disconnecting...

This is where 'LAG' takes place, have you ever been in a multiplayer game, than someone with really slow internet joins and then all of a sudden the game is either unplayable or you get disconnected?

Yep thats lag, but its hardly ever the servers fault, in most cases the server is actually trying to reach a certain player, but that player is unresponsive, but the server devotes too much power TRYING to find this person that LAG occurs because the server isn't worrying about everyone else...

when serverPlayer receives the data from joinPlayer it then stores the information as joinPlayer.data where data is the variable like playerXposition.

After it gets this data it gets the list of IP and PORTS for alreadyPlayer(i) and send the info to them with XMLSockets.

To put this last part simply, all other players are sending info to serverPlayer and it automatically sends it to everyone else.

======================================
======================================
=========
Extras

timeouts occur when the server cannot reach the player for a period of time, by default the XMLSocket has a timeout time of 2000 milliseconds, but I would probably make that a bit higher.

At all times there would be at least 1 server running (I hope) and that server would be madly checking all players and comparing it to any other servers, if ALL servers reported a player unreachable for a period of time then it would say that the player is disconnected (just incase you didn't use the 'Back to main menu' or 'Disconnect from multiplayer' button) and would treat the situation like you clicked Quit.

Now we don't want very private information stored very long now do we? So after you have quit/get disconnected you will have your IP address removed from the server AND your name will be removed from the 'Available users' list.
==================

Thank you, I am Jirachi99 signing off for a while since this took me like 25 minutes to type any my hand is hurting...


Comments

Comments ain't a thing here.