diff options
| author | oroborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e> | 2008-07-10 11:28:59 +0000 |
|---|---|---|
| committer | oroborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e> | 2008-07-10 11:28:59 +0000 |
| commit | bb15df3f3428df7cd2a4482adebcdaa6fc2f516e (patch) | |
| tree | 61993b5576bebeff7cf9dbcecc5fabdf592abfcc /src/client | |
| parent | 0eda3185ba30d433029c9a7e725529a801c93d80 (diff) | |
- precisteny kod sietoveho multiplayera
- moduly si mozu mosielat spravy cez sietovy protokol
- opravy chyb v moduloch
- oprava chyby, v textovych poliach sa zobrazuju znaky, ktore ste nestalcili
- director_t* loadDirector(char *s) vracia NULL ak adresar neexistuje ( predtym sa proces zrutil )
git-svn-id: http://opensvn.csie.org/tuxanci_ng@126 0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e
Diffstat (limited to 'src/client')
| -rw-r--r-- | src/client/client.c | 117 | ||||
| -rw-r--r-- | src/client/client.h | 21 |
2 files changed, 18 insertions, 120 deletions
diff --git a/src/client/client.c b/src/client/client.c index 1ac74dd..8d7b613 100644 --- a/src/client/client.c +++ b/src/client/client.c @@ -21,17 +21,11 @@ #include "screen_analyze.h" #include "screen_world.h" +#include "udp.h" + static int protocolType; -#ifdef SUPPORT_NET_UNIX_UDP -#include "udp.h" static sock_udp_t *sock_server_udp; -#endif - -#ifdef SUPPORT_NET_SDL_UDP -#include "sdl_udp.h" -static sock_sdl_udp_t *sock_server_sdl_udp; -#endif static list_t *clientBuffer; static my_time_t lastPing; @@ -49,8 +43,6 @@ static void initClient() proto_send_hello_client(name); } -#ifdef SUPPORT_NET_UNIX_UDP - int initUdpClient(char *ip, int port, int proto) { sock_server_udp = connectUdpSocket(ip, port, proto); @@ -68,29 +60,6 @@ int initUdpClient(char *ip, int port, int proto) return 0; } -#endif - -#ifdef SUPPORT_NET_SDL_UDP - -int initSdlUdpClient(char *ip, int port) -{ - sock_server_sdl_udp = connectSdlUdpSocket(ip, port); - - if( sock_server_sdl_udp == NULL ) - { - return -1; - } - - printf("connect UDP %s %d\n", ip, port); - - protocolType = NET_PROTOCOL_TYPE_UDP; - initClient(); - - return 0; -} - -#endif - void sendServer(char *msg) { int ret; @@ -98,19 +67,13 @@ void sendServer(char *msg) assert( msg != NULL ); #ifndef PUBLIC_SERVER - if( isParamFlag("--send") ) - { - printf("send -> %s", msg); - } + if( isParamFlag("--send") ) + { + printf("send -> %s", msg); + } #endif -#ifdef SUPPORT_NET_UNIX_UDP ret = writeUdpSocket(sock_server_udp, sock_server_udp, msg, strlen(msg)); -#endif - -#ifdef SUPPORT_NET_SDL_UDP - ret = writeSdlUdpSocket(sock_server_sdl_udp, sock_server_sdl_udp, msg, strlen(msg)); -#endif } static int eventServerSelect() @@ -120,32 +83,19 @@ static int eventServerSelect() memset(buffer,0 ,STR_PROTO_SIZE); -#ifdef SUPPORT_NET_UNIX_UDP ret = readUdpSocket(sock_server_udp, sock_server_udp, buffer, STR_PROTO_SIZE-1); -#endif - -#ifdef SUPPORT_NET_SDL_UDP - ret = readSdlUdpSocket(sock_server_sdl_udp, sock_server_sdl_udp, buffer, STR_PROTO_SIZE-1); if( ret < 0 ) { return ret; } -#endif addList(clientBuffer, strdup(buffer) ); -/* - if( addBuffer(clientBuffer, buffer, ret) != 0 ) - { - fprintf(stderr, "chyba, nemozem zapisovat do mojho buffera !\n"); - setWorldEnd(); - return ret; - } -*/ + return ret; } -void eventServerBuffer() +static void eventServerBuffer() { char *line; int i; @@ -172,6 +122,7 @@ void eventServerBuffer() if( strncmp(line, "additem", 7) == 0 )proto_recv_additem_client(line); if( strncmp(line, "shot", 4) == 0 )proto_recv_shot_client(line); if( strncmp(line, "kill", 4) == 0 )proto_recv_kill_client(line); + if( strncmp(line, "module", 6) == 0 )proto_recv_module_client(line); if( strncmp(line, "chat", 4) == 0 )proto_recv_chat_client(line); if( strncmp(line, "ping", 4) == 0 )proto_recv_ping_client(line); if( strncmp(line, "end", 3) == 0 )proto_recv_end_client(line); @@ -183,7 +134,7 @@ void eventServerBuffer() clientBuffer = newList(); } -void eventPingServer() +static void eventPingServer() { my_time_t currentTime; @@ -196,7 +147,7 @@ void eventPingServer() } } -bool_t isServerAlive() +static bool_t isServerAlive() { my_time_t currentTime; @@ -210,9 +161,7 @@ bool_t isServerAlive() return TRUE; } -#ifdef SUPPORT_NET_UNIX_UDP - -void selectClientUdpSocket() +static void selectClientUdpSocket() { fd_set readfds; struct timeval tv; @@ -246,31 +195,15 @@ void selectClientUdpSocket() } }while( isNext == TRUE ); - } -#endif - -#ifdef SUPPORT_NET_SDL_UDP - -void selectClientSdlUdpSocket() +void eventClient() { - int ret; - - if( isServerAlive() == FALSE ) - { - setMsgToAnalyze(getMyText("ERROR_SERVER_DONT_ALIVE")); - setWorldEnd(); - return; - } - - do{ - ret = eventServerSelect(); - }while( ret > 0); + eventPingServer(); + selectClientUdpSocket(); + eventServerBuffer(); } -#endif - static void quitClient() { proto_send_end_client(); @@ -278,8 +211,6 @@ static void quitClient() destroyListItem(clientBuffer, free); } -#ifdef SUPPORT_NET_UNIX_UDP - void quitUdpClient() { quitClient(); @@ -289,19 +220,3 @@ void quitUdpClient() printf("quit UDP conenct\n"); } - -#endif - -#ifdef SUPPORT_NET_SDL_UDP - -void quitSdlUdpClient() -{ - quitClient(); - - assert( sock_server_sdl_udp != NULL ); - closeSdlUdpSocket(sock_server_sdl_udp); - - printf("quit UDP conenct\n"); -} - -#endif diff --git a/src/client/client.h b/src/client/client.h index cd8c4c4..e301c4b 100644 --- a/src/client/client.h +++ b/src/client/client.h @@ -5,31 +5,14 @@ #include "main.h" -#if defined SUPPORT_NET_UNIX_UDP || defined SUPPORT_NET_SDL_UDP #define CLIENT_TIMEOUT 1000 #define SERVER_TIMEOUT_ALIVE 5000 -#endif - -#ifdef SUPPORT_NET_UNIX_UDP extern int initUdpClient(char *ip, int port, int proto); -extern void eventPingServer(); -extern void selectClientUdpSocket(); -extern void refreshPingServerAlive(); +extern void sendServer(char *msg); +extern void eventClient(); extern void quitUdpClient(); -#endif -#ifdef SUPPORT_NET_SDL_UDP -extern int initSdlUdpClient(char *ip, int port); -extern void eventPingServer(); -extern void selectClientSdlUdpSocket(); -extern void refreshPingServerAlive(); -extern bool_t isServerAlive(); -extern void quitSdlUdpClient(); #endif -extern void sendServer(char *msg); -extern void eventServerBuffer(); - -#endif |