Ok, i have my UDP procedures ready,
the client connects by sending "AUTHORIZE" packet
struct PACKET_authentication{_u16 code;_u16 login;_u16 password;_u16 version;};
Server bound to the port listens for all incoming packets,
when he receives any packet it checks if a client is already authenticated
(flag client[x].status==CLIENT_AUTHENTICATED), if this is true,
packets are processed.
If client is not authorized but sending some data, connection is ignored
If client is not authorized but sending PACKET_authorization, we go through
a function checking MySQL for proper _u16 login and _u16 password and if
ok, client[x].status=CLIENT_AUTHENTICATED
From now on, server applies a flag called :
client[id].lastpacket_received=time(NULL)
and checks in a timer (running every second):
;#define MAX_PING 5 //seconds...for(int a=0;a<MAX_CLIENTS;a++){ if(time(NULL)-client[a].lastpacket_received > MAX_PING){ client[a].status=CLIENT_DISCONNECTED; }}
So we can ensure that client stay's online 5seconds without interruption.
This might be too small for final release, but it is okay for testing.
Hope this is okay for now, or am i missing anything in the beginning?
Next phase is to have the correct data sent/broadcasted.
What do you think guys, how should that work exactly when it comes to something like a fast topdown shooter?
[1] Scenario vulnerable for cheating
Players are sending their positions to server every Xms
Server broadcasts that to others
[2] Scenario most adequate?
Server runs his own calculations of players positions - the algorithm used is exactly the same on client's machines and server.
Lets say, a timer running with 10ms algorithm:
int a; for(a=0;a<MAX_CLIENTS;a++){ if(client[a].W==1){ client[a].position[0]+= ((float)sin(client[a].rotation*piover180))*PLAYER_SPEED; // Move On The X-Plane Based On Player Direction client[a].position[1]+= ((float)cos(client[a].rotation*piover180))*PLAYER_SPEED; } if(client[a].S==1){ client[a].position[0]-= ((float)sin(client[a].rotation*piover180))*PLAYER_SPEED; // Move On The X-Plane Based On Player Direction client[a].position[1]-= ((float)cos(client[a].rotation*piover180))*PLAYER_SPEED; } if(client[a].A==1){ client[a].position[0]-=PLAYER_SPEED; } if(client[a].D==1){ client[a].position[0]+=PLAYER_SPEED; } }
Clients are sending their key inputs to server every Xms,
they locally move their characters without waiting for anything.
Server is receiving those packets and broadcasts actual server positions to the players
Clients are running a network procedure where both:
local positions
server received positions
are compared.
If distance between those two is > MAX ( lets say 2.0f )
client whose distance is > MAX is being snapped to the server received pos.
That is all i came up to right now,
how do you think, is there anything else that can be done in order to have it working smoothly for 5 players ?
Many thanks for all suggestions :)