summaryrefslogtreecommitdiff
path: root/src/server.c
diff options
context:
space:
mode:
authororoborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e>2008-03-14 22:11:31 +0000
committeroroborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e>2008-03-14 22:11:31 +0000
commitd9e19a0d5ba8a797e12052e29f9c3a945d2331bc (patch)
tree95e18dfbf1879b5edd973d81003a43955adb141b /src/server.c
parent593ac1e25c2053f06cb1b7e29785a695d3c57ad3 (diff)
- upravy v kode, lepsia synchronizacia
- clienty posielaju serveru "pingy", ak server isty cas ping od client anedostane tak ho dpoji ( nespojive UDP ) git-svn-id: http://opensvn.csie.org/tuxanci_ng@16 0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e
Diffstat (limited to 'src/server.c')
-rw-r--r--src/server.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/server.c b/src/server.c
index 419990d..6ff8491 100644
--- a/src/server.c
+++ b/src/server.c
@@ -34,7 +34,7 @@ int initTcpServer(int port)
initServer();
- printf("server listen port %d\n", port);
+ printf("server listen TCP port %d\n", port);
return 0;
}
@@ -52,7 +52,7 @@ int initUdpServer(int port)
initServer();
- printf("server listen port %d\n", port);
+ printf("server listen UDP port %d\n", port);
return 0;
}
@@ -68,6 +68,7 @@ static client_t* newAnyClient()
new->buffer = newBuffer(LIMIT_BUFFER);
new->tux = newTux();
new->tux->control = TUX_CONTROL_NET;
+ new->lastPing = SDL_GetTicks();
addList(getWorldArena()->listTux, new->tux);
return new;
@@ -269,6 +270,7 @@ static void eventClientBuffer(client_t *client)
if( strncmp(line, "hello", 5) == 0 )proto_recv_hello_server(client, line);
if( strncmp(line, "event", 5) == 0 )proto_recv_event_server(client, line);
if( strncmp(line, "context", 7) == 0 )proto_recv_context_server(client, line);
+ if( strncmp(line, "ping", 4) == 0 )proto_recv_ping_server(client, line);
if( strncmp(line, "end", 3) == 0 )proto_recv_end_server(client, line);
}
}
@@ -357,12 +359,21 @@ static client_t* findUdpClient(sock_udp_t *sock_udp)
static void delZombieCLient()
{
client_t *thisClient;
+ Uint32 currentTime;
int i;
+ currentTime = SDL_GetTicks();
+
for( i = 0 ; i < listClient->count; i++)
{
thisClient = (client_t *) listClient->list[i];
+ if( currentTime - thisClient->lastPing > SERVER_TIMEOUT )
+ {
+ printf("client ping timeout\n");
+ thisClient->status = NET_STATUS_ZOMBIE;
+ }
+
if( thisClient->status == NET_STATUS_ZOMBIE )
{
proto_send_deltux_server(thisClient);