From d9e19a0d5ba8a797e12052e29f9c3a945d2331bc Mon Sep 17 00:00:00 2001 From: oroborus Date: Fri, 14 Mar 2008 22:11:31 +0000 Subject: - 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 --- src/client.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'src/client.c') diff --git a/src/client.c b/src/client.c index 530c0f3..dc9d324 100644 --- a/src/client.c +++ b/src/client.c @@ -18,6 +18,7 @@ static int protocolType; static sock_tcp_t *sock_server_tcp; static sock_udp_t *sock_server_udp; static buffer_t *clientBuffer; +static Uint32 lastPing; static void initClient() { @@ -34,7 +35,7 @@ int initTcpClient(char *ip, int port) return -1; } - printf("connect %s %d\n", ip, port); + printf("connect TCP %s %d\n", ip, port); protocolType = NET_PROTOCOL_TYPE_TCP; initClient(); @@ -50,8 +51,9 @@ int initUdpClient(char *ip, int port) return -1; } - printf("connect %s %d\n", ip, port); + printf("connect UDP %s %d\n", ip, port); protocolType = NET_PROTOCOL_TYPE_UDP; + lastPing = SDL_GetTicks(); initClient(); return 0; @@ -143,6 +145,8 @@ void eventServerBuffer() if( strncmp(line, "newtux", 6) == 0 )proto_recv_newtux_client(line); if( strncmp(line, "deltux", 6) == 0 )proto_recv_deltux_client(line); if( strncmp(line, "additem", 7) == 0 )proto_recv_additem_client(line); + if( strncmp(line, "kill", 4) == 0 )proto_recv_kill_client(line); + if( strncmp(line, "score", 5) == 0 )proto_recv_score_client(line); if( strncmp(line, "end", 3) == 0 )proto_recv_end_client(line); } } @@ -168,12 +172,27 @@ void selectClientTcpSocket() } } +void eventPingServer() +{ + Uint32 currentTime; + + currentTime = SDL_GetTicks(); + + if( currentTime - lastPing > CLIENT_TIMEOUT ) + { + proto_send_ping_client(); + lastPing = SDL_GetTicks(); + } +} + void selectClientUdpSocket() { fd_set readfds; struct timeval tv; int max_fd; + eventPingServer(); + tv.tv_sec = 0; tv.tv_usec = 0; -- cgit v1.2.3