summaryrefslogtreecommitdiff
path: root/src/client.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/client.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/client.c')
-rw-r--r--src/client.c23
1 files changed, 21 insertions, 2 deletions
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;