From 38b98c9ecd0c300d40ae6db05ab9dc2b9189df8d Mon Sep 17 00:00:00 2001 From: oroborus Date: Tue, 1 Jul 2008 17:53:41 +0000 Subject: - oprava chyby pri teleportacii lasserov - skutocne opravena chybya s neinicializovany audiom, a strielanim pri chodeni - ZeXxove patche pre spojenie s master serverom - client zobrazuje hlasku ak sa nepodarilo spojit zo serverom alebo sppojenie nasilne ukoncilo git-svn-id: http://opensvn.csie.org/tuxanci_ng@81 0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e --- config.h | 4 +- src/audio/music.c | 5 ++ src/base/index.c | 54 +++------------ src/base/shot.c | 8 +++ src/base/storage.c | 8 ++- src/client/client.c | 1 + src/net_unix/udp.c | 15 +++++ src/net_unix/udp.h | 1 + src/screen/screen_browser.c | 156 ++++++++++++++++++++++++++++++++++---------- src/screen/screen_world.c | 26 ++++---- 10 files changed, 181 insertions(+), 97 deletions(-) diff --git a/config.h b/config.h index dbbfd9f..9bffa67 100644 --- a/config.h +++ b/config.h @@ -6,6 +6,6 @@ #define DEBUG_CLIENT_RECV */ -#define TUXANCI_NG_VERSION "svn80" +#define TUXANCI_NG_VERSION "svn81" -//#define DESTDIR "/usr/local/" +#define DESTDIR "/usr/local/" diff --git a/src/audio/music.c b/src/audio/music.c index 90bc5a0..b449950 100644 --- a/src/audio/music.c +++ b/src/audio/music.c @@ -192,6 +192,11 @@ char* getCurrentMusic() void delAllMusicInGroup(char *group) { + if( isMusicInit == FALSE ) + { + return; + } + delAllItemFromStorage(listStorage, group, destroyMusic); } diff --git a/src/base/index.c b/src/base/index.c index d3f75a5..caa8572 100644 --- a/src/base/index.c +++ b/src/base/index.c @@ -77,7 +77,6 @@ int addToIndex(list_t *list, int index) if( len == 0 ) { - //printf("OK first\n"); addList(list, index_newInt(index)); checkIndex(list); return 0; @@ -85,79 +84,53 @@ int addToIndex(list_t *list, int index) if( len == 1 ) { - //space->getStatus(space->list->list[0], &point_id, &x, &y, &w, &h); point_index = *(int *)list->list[0]; if( index > point_index ) { addList(list, index_newInt(index)); - //checkIndex(list); + checkIndex(list); return 1; } if( index < point_index ) { insList(list, 0, index_newInt(index)); - //checkIndex(list); + checkIndex(list); return 0; } - //printf("OK\n") return -1; } min = 0; max = len-1; -/* - if( max < 0 ) - { - max = 0; - } -*/ + for(;;) { point = min + ( max - min ) / 2; -/* - space->getStatus(space->list->list[min], &id_min, &x, &y, &w, &h); - space->getStatus(space->list->list[max], &id_max, &x, &y, &w, &h); -*/ - //printf("min = %d max = %d point = %d len = %d id = %d\n", min, max, point, len, id); if( max < 0 ) { - //printf("OK first\n"); insList(list, 0, index_newInt(index)); - //checkIndex(list); + checkIndex(list); return 0; } - if( point+1 >= len /*|| min >= len*/ ) + if( point+1 >= len ) { addList(list, index_newInt(index) ); - //printf("OK height\n"); - //checkIndex(list); + checkIndex(list); return len; } -// space->getStatus(space->list->list[point], &point_id, &x, &y, &w, &h); -// space->getStatus(space->list->list[point+1], &inc_point_id, &x, &y, &w, &h); - point_index = *(int *)list->list[point]; inc_point_index = *(int *)list->list[point+1]; -/* - if( min == max ) - { - //printf("OK\n"); - insList(space->list, min, p); - checkList(space); - return; - } -*/ + if( point_index < index && index < inc_point_index ) { - //printf("OK\n"); insList(list, point+1, index_newInt(index) ); - //checkIndex(list); + checkIndex(list); return point+1; } @@ -182,7 +155,6 @@ int getFormIndex(list_t *list, int index) int min, max; int point; - //printf("getFormIndex %d\n", index); //printIndex(list); @@ -195,23 +167,13 @@ int getFormIndex(list_t *list, int index) { point = min + ( max - min ) / 2; - //printf("min = %d max = %d point = %d len = %d id = %d\n", min, max, point, len, id); - if( max < 0 || point >= len || max < min ) { return -1; } - //space->getStatus(space->list->list[point], &point_id, &x, &y, &w, &h); - point_index = *(int *)list->list[point]; - if( min == max ) - { - //space->getStatus(space->list->list[min], &point_id, &x, &y, &w, &h); - point_index = *(int *)list->list[point]; - } - if( point_index == index ) { return point; diff --git a/src/base/shot.c b/src/base/shot.c index e8cdff9..9c0e33c 100644 --- a/src/base/shot.c +++ b/src/base/shot.c @@ -226,6 +226,12 @@ void boundBombBall(shot_t *shot) void transformOnlyLasser(shot_t *shot) { + space_t *space; + + space = getCurrentArena()->spaceShot; + + delObjectFromSpace(space, shot); + switch( shot->position ) { case TUX_RIGHT : @@ -245,6 +251,8 @@ void transformOnlyLasser(shot_t *shot) #endif break; } + + addObjectToSpace(space, shot); } void eventMoveListShot(arena_t *arena) diff --git a/src/base/storage.c b/src/base/storage.c index e7afa45..f3eb937 100644 --- a/src/base/storage.c +++ b/src/base/storage.c @@ -1,4 +1,3 @@ - #include #include #include @@ -52,6 +51,10 @@ static void destroyStorageItem(storage_item_t *p, void *f) void addItemToStorage(list_t *list, char *group, char *name, void *data) { + assert( list != NULL ); + assert( group != NULL ); + assert( name != NULL ); + addList(list, newStorageItem(group, name, data) ); } @@ -60,6 +63,7 @@ void* getItemFromStorage(list_t *list, char *group, char *name) storage_item_t *this; int i; + assert( list != NULL ); assert( group != NULL ); assert( name != NULL ); @@ -82,6 +86,7 @@ void delItemFromStorage(list_t *list, char *group, char *name, void *f) storage_item_t *this; int i; + assert( list != NULL ); assert( group != NULL ); assert( name != NULL ); @@ -105,6 +110,7 @@ void delAllItemFromStorage(list_t *list, char *group, void *f) storage_item_t *this; int i; + assert( list != NULL ); assert( group != NULL ); for(i = 0 ; i < list->count; i++) diff --git a/src/client/client.c b/src/client/client.c index 975c9da..2ed5e0a 100644 --- a/src/client/client.c +++ b/src/client/client.c @@ -221,6 +221,7 @@ void selectClientUdpSocket() if( isServerAlive() == FALSE ) { fprintf(stderr, "server neodpoveda !\n"); + setMsgToAnalyze(getMyText("ERROR_SERVER_DONT_ALIVE")); setWorldEnd(); return; } diff --git a/src/net_unix/udp.c b/src/net_unix/udp.c index a701d48..79df4b0 100644 --- a/src/net_unix/udp.c +++ b/src/net_unix/udp.c @@ -12,6 +12,7 @@ #include #include #include +#include #define BUFSIZE 1000 @@ -149,6 +150,20 @@ sock_udp_t* connectUdpSocket(char *address, int port, int proto) return new; } +int setUdpSockNonBlock(sock_udp_t *p) +{ + int oldFlag; + + oldFlag = fcntl (p->sock, F_GETFL, 0); + + if( fcntl(p->sock, F_SETFL, oldFlag|O_NONBLOCK ) == -1 ) + { + return -1; + } + + return 0; +} + int readUdpSocket(sock_udp_t *src, sock_udp_t *dst, void *address, int len) { int addrlen; diff --git a/src/net_unix/udp.h b/src/net_unix/udp.h index e5fd648..a8d935f 100644 --- a/src/net_unix/udp.h +++ b/src/net_unix/udp.h @@ -22,6 +22,7 @@ extern sock_udp_t* newSockUdp(int proto); extern void destroySockUdp(sock_udp_t *p); extern sock_udp_t* bindUdpSocket(char *address, int port, int proto); extern sock_udp_t* connectUdpSocket(char *address, int port, int proto); +extern int setUdpSockNonBlock(sock_udp_t *p); extern int readUdpSocket(sock_udp_t *src, sock_udp_t *dst, void *address, int len); extern int writeUdpSocket(sock_udp_t *src, sock_udp_t *dst, void *address, int len); extern void getSockUdpIp(sock_udp_t *p, char *str_ip, int len); diff --git a/src/screen/screen_browser.c b/src/screen/screen_browser.c index 602881f..3307423 100644 --- a/src/screen/screen_browser.c +++ b/src/screen/screen_browser.c @@ -22,8 +22,11 @@ #include #include #include +#include #include "net_unix/udp.h" + +extern int errno; #endif #ifndef NO_SOUND @@ -165,55 +168,94 @@ int server_getinfo (server_t *server) { #ifdef SUPPORT_NET_UNIX_UDP struct sockaddr_in srv; + int mySocket; + + if ((mySocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) { + return -1; + } + + // Lets make socket non-blocking + int oldFlag = fcntl (mySocket, F_GETFL, 0); + if (fcntl (mySocket, F_SETFL, oldFlag | O_NONBLOCK) == -1) { + return -1; + } + + struct timeval tv; + // Množina + fd_set myset; + // Množina obsahuje náhodná data. Odstraním je. + FD_ZERO(&myset); + // Zaplnění množiny sokety + FD_SET(mySocket, &myset); + // Vyplním časový údaj (například na 3 minuty) + tv.tv_sec = 2;// Počet sekund + tv.tv_usec = 0;// Počet mikrosekund + + srv.sin_family = AF_INET; + srv.sin_port = htons (server->port); srv.sin_addr.s_addr = server->ip; - sock_udp_t *sock = connectUdpSocket(inet_ntoa (srv.sin_addr), server->port, PROTO_UDPv4); + if (connect (mySocket, (struct sockaddr *) &srv, sizeof (srv)) == -1) { + if (errno != EINPROGRESS) + return -1; + } + + // Zavolám select (V Linuxu musím mít nastavenou proměnnou max.) + int ret = select (mySocket+1, NULL, &myset, NULL, &tv); + + if (ret == -1) + return 0; + + if (ret == 0) + return -2; char request[8]; memcpy (request, "status\n", 7); - writeUdpSocket(sock, sock, request, 7); + int r = send (mySocket, request, 7, 0); + + if (r == -1) + return -2; + + FD_ZERO(&myset); + FD_SET(mySocket, &myset); + tv.tv_sec = 1; + tv.tv_usec = 0; char *str = (char *) malloc (sizeof (char) * 257); - // Lets make socket non-blocking - int oldFlag = fcntl (sock->sock, F_GETFL, 0); - if (fcntl (sock->sock, F_SETFL, oldFlag | O_NONBLOCK) == -1) { + if (!str) return -1; - } -#else - return 0; -#endif - /* 500ms timeout */ - unsigned timeout = SERVER_TIMEOUT; - int ret = 0; - while (timeout) { - usleep (1); -#ifdef SUPPORT_NET_UNIX_UDP - ret = readUdpSocket(sock, sock, str, 256); -#endif + while (1) { + int sel = select (mySocket + 1, &myset, NULL, NULL, &tv); + + if (sel == 0) + return -2; + + if (sel == -1) + return -2; + + if ((ret = recv(mySocket, str, 256, 0)) == -1) + return -1; + if (ret > 0) break; - - timeout --; } - /* server not respond */ - if (timeout < 1) { - free (str); - server->state = 0; - return 0; - } + close (mySocket); - server->ping = SERVER_TIMEOUT - timeout; + server->ping = 1000 - (tv.tv_usec/1000); +#else + return 0; +#endif -/* - "version: svnX\n" - "clients: N\n" - "maxclients: M\n" - "uptime: D\n" -*/ + /* + "version: svnX\n" + "clients: N\n" + "maxclients: M\n" + "uptime: D\n" + */ typedef struct { char *version; @@ -298,14 +340,56 @@ static int LoadServers () return 0; } - if (connect (s, (struct sockaddr *) &server, sizeof (server)) == -1) + int oldFlag = fcntl (s, F_GETFL, 0); + if (fcntl (s, F_SETFL, oldFlag | O_NONBLOCK) == -1) { + return -1; + } + + if (connect (s, (struct sockaddr *) &server, sizeof (server)) == -1) { + if (errno != EINPROGRESS) + return -1; + } + + struct timeval tv; + // Množina + fd_set myset; + // Množina obsahuje náhodná data. Odstraním je. + FD_ZERO(&myset); + // Zaplnění množiny sokety + FD_SET(s, &myset); + // Vyplním časový údaj (například na 3 minuty) + tv.tv_sec = 3;// Počet sekund + tv.tv_usec = 0;// Počet mikrosekund + // Zavolám select (V Linuxu musím mít nastavenou proměnnou max.) + int ret = select (s+1, NULL, &myset, NULL, &tv); + + if (ret == -1) return 0; + if (ret == 0) + return -2; + /* send request for server list */ send (s, "l", 1, 0); + // Množina obsahuje náhodná data. Odstraním je. + FD_ZERO(&myset); + // Zaplnění množiny sokety + FD_SET(s, &myset); + + ret = select (s+1, &myset, NULL, NULL, &tv); + + if (ret == -1) + return 0; + + if (ret == 0) + return -2; + /* receive server list if exist */ + //int len; + //do { int len = recv (s, buf, 1024, 0); + //} while (len < 1); close (s); #else @@ -340,10 +424,12 @@ static int LoadServers () int ret = server_getinfo (ctx); - if (ret) { + if (ret == 1) { sprintf (list, "%s:%d (%s) - %s - %d/%d - %dms", inet_ntoa (srv.sin_addr), ctx->port, ctx->version, ctx->arena, ctx->clients, ctx->maxclients, ctx->ping); - } else + } else if (ret == -2) + sprintf (list, "%s:%d - Timeout", inet_ntoa (srv.sin_addr), ctx->port); + else sprintf (list, "%s:%d - Offline", inet_ntoa (srv.sin_addr), ctx->port); addToWidgetSelect(select_server, list); diff --git a/src/screen/screen_world.c b/src/screen/screen_world.c index 296c31f..3c656f5 100644 --- a/src/screen/screen_world.c +++ b/src/screen/screen_world.c @@ -230,6 +230,13 @@ static void control_keyboard_right(tux_t *tux) if( mapa[(SDLKey)getKey(KEY_TUX_RIGHT_MOVE_LEFT)] == SDL_PRESSED )countKey++; if( mapa[(SDLKey)getKey(KEY_TUX_RIGHT_MOVE_DOWN)] == SDL_PRESSED )countKey++; + if( mapa[(SDLKey)getKey(KEY_TUX_RIGHT_SHOOT)] == SDL_PRESSED && tux->isCanShot == TRUE ) + { + netAction(tux, TUX_SHOT); + actionTux(tux, TUX_SHOT); + return; + } + if( mapa[(SDLKey)getKey(KEY_TUX_RIGHT_MOVE_UP)] == SDL_PRESSED ) { if(countKey > 1 && lastKey == getKey(KEY_TUX_RIGHT_MOVE_UP) )goto tuUp; @@ -279,13 +286,6 @@ static void control_keyboard_right(tux_t *tux) tuDown:; } - if( mapa[(SDLKey)getKey(KEY_TUX_RIGHT_SHOOT)] == SDL_PRESSED && tux->isCanShot == TRUE ) - { - netAction(tux, TUX_SHOT); - actionTux(tux, TUX_SHOT); - return; - } - if( mapa[(SDLKey)getKey(KEY_TUX_RIGHT_SWITCH_WEAPON)] == SDL_PRESSED ) { if( tux->isCanSwitchGun == TRUE ) @@ -314,6 +314,12 @@ static void control_keyboard_left(tux_t *tux) if( mapa[(SDLKey)getKey(KEY_TUX_LEFT_MOVE_LEFT)] == SDL_PRESSED )countKey++; if( mapa[(SDLKey)getKey(KEY_TUX_LEFT_MOVE_DOWN)] == SDL_PRESSED )countKey++; + if( mapa[(SDLKey)getKey(KEY_TUX_LEFT_SHOOT)] == SDL_PRESSED && tux->isCanShot == TRUE ) + { + actionTux(tux, TUX_SHOT); + return; + } + if( mapa[(SDLKey)getKey(KEY_TUX_LEFT_MOVE_UP)] == SDL_PRESSED ) { if(countKey > 1 && lastKey == getKey(KEY_TUX_LEFT_MOVE_UP) )goto tuUp; @@ -359,12 +365,6 @@ static void control_keyboard_left(tux_t *tux) tuDown:; } - if( mapa[(SDLKey)getKey(KEY_TUX_LEFT_SHOOT)] == SDL_PRESSED && tux->isCanShot == TRUE ) - { - actionTux(tux, TUX_SHOT); - return; - } - if( mapa[(SDLKey)getKey(KEY_TUX_LEFT_SWITCH_WEAPON)] == SDL_PRESSED ) { if( tux->isCanSwitchGun == TRUE ) -- cgit v1.2.3