From 35185452d7546ab56aa0040d7c2d68795c3f813f Mon Sep 17 00:00:00 2001 From: oroborus Date: Sun, 6 Apr 2008 17:25:52 +0000 Subject: - synchronizuju sa aj veci - preklady obsahuju aj font a velkost pismen - upravy aby to slo ( po stahnut tejto verzii sa hra musi odinstalovat a znova naonstalovat ) git-svn-id: http://opensvn.csie.org/tuxanci_ng@43 0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e --- src/client.c | 112 +---------------------------------------------------- src/gun.c | 11 +++--- src/item.c | 14 +++++++ src/keytable.c | 2 +- src/language.c | 76 ++++++++++++++++++++++++++++++++++-- src/main.c | 10 ++++- src/proto.c | 5 ++- src/screen_world.c | 18 +++++++++ src/server.c | 26 ++++++------- src/tux.c | 24 ++++++++++-- 10 files changed, 155 insertions(+), 143 deletions(-) (limited to 'src') diff --git a/src/client.c b/src/client.c index 8e5aae3..612a5b4 100644 --- a/src/client.c +++ b/src/client.c @@ -15,11 +15,6 @@ static int protocolType; -#ifdef SUPPORT_NET_UNIX_TCP -#include "tcp.h" -static sock_tcp_t *sock_server_tcp; -#endif - #ifdef SUPPORT_NET_UNIX_UDP #include "udp.h" static sock_udp_t *sock_server_udp; @@ -46,27 +41,6 @@ static void initClient() proto_send_hello_client(name); } -#ifdef SUPPORT_NET_UNIX_TCP - -int initTcpClient(char *ip, int port) -{ - sock_server_tcp = connectTcpSocket(ip, port); - - if( sock_server_tcp == NULL ) - { - return -1; - } - - printf("connect TCP %s %d\n", ip, port); - - protocolType = NET_PROTOCOL_TYPE_TCP; - initClient(); - - return 0; -} - -#endif - #ifdef SUPPORT_NET_UNIX_UDP int initUdpClient(char *ip, int port) @@ -115,22 +89,6 @@ void sendServer(char *msg) assert( msg != NULL ); -#ifdef SUPPORT_NET_UNIX_TCP - ret = writeTcpSocket(sock_server_tcp, msg, strlen(msg)); - - if ( ret == 0 ) - { - fprintf(stderr, "server uzatvoril sietovy socket\n"); - setWorldEnd(); - } - - if ( ret < 0 ) - { - fprintf(stderr, "nastala chyba pri poslani spravy serveru\n"); - setWorldEnd(); - } -#endif - #ifdef SUPPORT_NET_UNIX_UDP ret = writeUdpSocket(sock_server_udp, sock_server_udp, msg, strlen(msg)); #endif @@ -151,24 +109,6 @@ static int eventServerSelect() memset(buffer,0 ,STR_PROTO_SIZE); -#ifdef SUPPORT_NET_UNIX_TCP - ret = readTcpSocket(sock_server_tcp, buffer, STR_PROTO_SIZE-1); - - if( ret == 0 ) - { - fprintf(stderr, "server uzatovril sietovy socket\n"); - setWorldEnd(); - return ret; - } - - if( ret < 0 ) - { - fprintf(stderr, "chyba, spojenie prerusene \n"); - setWorldEnd(); - return ret; - } -#endif - #ifdef SUPPORT_NET_UNIX_UDP ret = readUdpSocket(sock_server_udp, sock_server_udp, buffer, STR_PROTO_SIZE-1); #endif @@ -205,6 +145,7 @@ void eventServerBuffer() #ifdef DEBUG_CLIENT_RECV printf("recv server msg->%s", line); #endif + if( strncmp(line, "error", 5) == 0 )proto_recv_error_client(line); if( strncmp(line, "init", 4) == 0 )proto_recv_init_client(line); if( strncmp(line, "event", 5) == 0 )proto_recv_event_client(line); @@ -218,45 +159,10 @@ void eventServerBuffer() if( strncmp(line, "ping", 4) == 0 )proto_recv_ping_client(line); if( strncmp(line, "end", 3) == 0 )proto_recv_end_client(line); -#if defined SUPPORT_NET_UNIX_UDP || defined SUPPORT_NET_SDL_UDP lastPingServerAlive = getMyTime(); -#endif } } -#ifdef SUPPORT_NET_UNIX_TCP - -void selectClientTcpSocket() -{ - fd_set readfds; - struct timeval tv; - int max_fd; - bool_t isNext; - - do{ - isNext = FALSE; - - tv.tv_sec = 0; - tv.tv_usec = 0; - - FD_ZERO(&readfds); - FD_SET(sock_server_tcp->sock, &readfds); - max_fd = sock_server_tcp->sock; - - select(max_fd+1, &readfds, (fd_set *)NULL, (fd_set *)NULL, &tv); - - if( FD_ISSET(sock_server_tcp->sock, &readfds) ) - { - eventServerSelect(); - isNext = TRUE; - } - - }while( isNext == TRUE ); -} - -#endif - -#if defined SUPPORT_NET_UNIX_UDP || defined SUPPORT_NET_SDL_UDP void eventPingServer() { @@ -285,8 +191,6 @@ bool_t isServerAlive() return TRUE; } -#endif - #ifdef SUPPORT_NET_UNIX_UDP void selectClientUdpSocket() @@ -354,20 +258,6 @@ static void quitClient() destroyBuffer(clientBuffer); } -#ifdef SUPPORT_NET_UNIX_TCP - -void quitTcpClient() -{ - quitClient(); - - assert( sock_server_tcp != NULL ); - closeTcpSocket(sock_server_tcp); - - printf("quit TCP conenct\n"); -} - -#endif - #ifdef SUPPORT_NET_UNIX_UDP void quitUdpClient() diff --git a/src/gun.c b/src/gun.c index fbbeeb3..b46b995 100644 --- a/src/gun.c +++ b/src/gun.c @@ -60,11 +60,6 @@ static void addShotTrivial(tux_t *tux, int x, int y, int px, int py, int gun) int dest_px = 0, dest_py = 0; shot_t *shot; - if( getNetTypeGame() == NET_GAME_TYPE_CLIENT ) - { - return; - } - modificiationCopuse(tux->position, px, py, &dest_px, &dest_py); modificiationCopuse(tux->position, x, y, &dest_x, &dest_y); @@ -96,6 +91,11 @@ static void addShot(tux_t *tux,int x, int y, int px, int py) { int gun; + if( getNetTypeGame() == NET_GAME_TYPE_CLIENT ) + { + return; + } + if( tux->gun == GUN_LASSER ) { gun = GUN_LASSER; @@ -253,7 +253,6 @@ static void putInGunMine(tux_t *tux) appendTextInTerm(msg); #endif - tux->shot[tux->gun]--; if( getNetTypeGame() != NET_GAME_TYPE_CLIENT ) diff --git a/src/item.c b/src/item.c index 22691e6..373189e 100644 --- a/src/item.c +++ b/src/item.c @@ -76,6 +76,7 @@ item_t* newItem(int x, int y, int type, tux_t *author) new->img = g_item[type]; #endif new->author = author; + new->lastSync = getMyTime(); switch( type ) { @@ -242,9 +243,12 @@ void drawListItem(list_t *listItem) void eventListItem(list_t *listItem) { + my_time_t currentTime; item_t *thisItem; int i; + currentTime = getMyTime(); + assert( listItem != NULL ); for( i = 0 ; i < listItem->count ; i++ ) @@ -252,6 +256,16 @@ void eventListItem(list_t *listItem) thisItem = (item_t *)listItem->list[i]; assert( thisItem != NULL ); + if( getNetTypeGame() == NET_GAME_TYPE_CLIENT ) + { + if( currentTime - thisItem->lastSync > ITEM_SYNC_TIMEOUT ) + { + delListItem(listItem, i, destroyItem); + i--; + continue; + } + } + thisItem->count++; if( thisItem->count == ITEM_MAX_COUNT ) diff --git a/src/keytable.c b/src/keytable.c index 7e2ed0e..db4aa02 100644 --- a/src/keytable.c +++ b/src/keytable.c @@ -46,7 +46,7 @@ void initKeyTable() /* int i; */ - sprintf(path, PATH_DATA "keytable.conf"); + sprintf(path, PATH_CONFIG "keytable.conf"); keytableFile = loadTextFile(path); if( keytableFile == NULL ) diff --git a/src/language.c b/src/language.c index 51a7d5b..5291f44 100644 --- a/src/language.c +++ b/src/language.c @@ -8,15 +8,38 @@ #include "list.h" #include "homeDirector.h" #include "textFile.h" +#include "configFile.h" #include "language.h" static textFile_t *languageFile; +static char fontFile[STR_FILE_NAME_SIZE]; +static int fontSize; -void initLanguage() +char* getHead(textFile_t *ts) +{ + int i; + + for( i = 0 ; i < ts->text->count ; i++ ) + { + char *line; + line = (char *) (ts->text->list[i]); + + if( strncmp(line, "HEAD", 4) == 0 ) + { + return line; + } + } + + return NULL; +} + + +int initLanguage() { textFile_t *languageTypeFile; char path[STR_PATH_SIZE]; char *lang; + char *head; sprintf(path, "%s/lang.conf", getHomeDirector()); languageTypeFile = loadTextFile(path); @@ -34,25 +57,60 @@ void initLanguage() if( languageTypeFile == NULL ) { fprintf(stderr, "Don't create %s\n", path); - return; + return -1; } if( languageTypeFile->text->count == 0 ) { fprintf(stderr, "File %s empty\n", path); - return; + return -1; } lang = ((char *)languageTypeFile->text->list[0]); printf("select lang %s\n", lang); - sprintf(path, PATH_DATA "lang.%s", lang); + sprintf(path, PATH_LANG "%s.lang", lang); languageFile = loadTextFile(path); if( languageFile == NULL ) { fprintf(stderr, "Don't load %s\n", path); + return -1; + } + + head = getHead(languageFile); + + if( head != NULL ) + { + char val[STR_SIZE]; + + if( getValue(head, "fontfile", val, STR_SIZE) == 0 ) + { + strcpy(fontFile, val); + } + else + { + fprintf(stderr, "fontfile in lang file %s not found\n", path); + return -1; + } + + if( getValue(head, "fontsize", val, STR_SIZE) == 0 ) + { + fontSize = atoi(val); + } + else + { + fprintf(stderr, "fontsize in lang file %s not found\n", path); + return -1; + } } + else + { + fprintf(stderr, "head in lang file %s not found\n", path); + return -1; + } + + return 0; } char* getMyText(char *key) @@ -76,6 +134,16 @@ char* getMyText(char *key) return NULL; } +char* getLanguageFont() +{ + return fontFile; +} + +int getLanguageSize() +{ + return fontSize; +} + void quitLanguage() { destroyTextFile(languageFile); diff --git a/src/main.c b/src/main.c index e77f044..0978f89 100644 --- a/src/main.c +++ b/src/main.c @@ -45,11 +45,17 @@ static void init() { createHomeDirector(); + if( initLanguage() == -1 ) + { + printf("fatal error !\n"); + exit(-1); + } + initSDL(); + initLayer(); - initFont("DejaVuSans.ttf", 16); + initFont(getLanguageFont(), getLanguageSize()); initKeyTable(); - initLanguage(); initImageData(); initAudio(); initSound(); diff --git a/src/proto.c b/src/proto.c index a646d9c..042ce7f 100644 --- a/src/proto.c +++ b/src/proto.c @@ -254,6 +254,7 @@ void proto_recv_event_server(client_t *client, char *msg) assert( client != NULL ); assert( msg != NULL ); + sscanf(msg, "%s %d", cmd, &action); proto_send_event_server(PROTO_SEND_BUT, client, client->tux, action); @@ -488,8 +489,9 @@ void proto_recv_additem_client(char *msg) sscanf(msg, "%s %d %d %d %d %d %d %d", cmd, &id, &type, &x, &y, &count, &frame, &author_id); - if( getItemID(getCurrentArena()->listItem, id) != NULL ) + if( ( item = getItemID(getCurrentArena()->listItem, id) ) != NULL ) { + item->lastSync = getMyTime(); return; } @@ -504,6 +506,7 @@ void proto_recv_additem_client(char *msg) item->id = id; item->count = count; item->frame = frame; + item->lastSync = getMyTime(); addList(getCurrentArena()->listItem, item); diff --git a/src/screen_world.c b/src/screen_world.c index 02536de..589161e 100644 --- a/src/screen_world.c +++ b/src/screen_world.c @@ -210,9 +210,27 @@ static void netAction(tux_t *tux, int action) static void control_keyboard_right(tux_t *tux) { +/* + static my_time_t lastTime = 0; + my_time_t currentTime; +*/ Uint8 *mapa; mapa = SDL_GetKeyState(NULL); +/* + if( lastTime == 0 ) + { + lastTime = getMyTime(); + } + + currentTime = getMyTime(); + if( currentTime - lastTime < 45 ) + { + return; + } + + lastTime = getMyTime(); +*/ assert( tux != NULL ); assert( mapa != NULL ); diff --git a/src/server.c b/src/server.c index 5c11781..f3972d3 100644 --- a/src/server.c +++ b/src/server.c @@ -29,11 +29,6 @@ #include "publicServer.h" #endif -#ifdef SUPPORT_NET_UNIX_TCP -#include "tcp.h" -static sock_tcp_t *sock_server_tcp; -#endif - #ifdef SUPPORT_NET_UNIX_UDP #include "udp.h" static sock_udp_t *sock_server_udp; @@ -49,8 +44,6 @@ static list_t *listServerTimer; static my_time_t lastSyncClient; static int maxClients; -#if defined SUPPORT_NET_UNIX_UDP || defined SUPPORT_NET_SDL_UDP - static void delZombieCLient(void *p_nothink) { client_t *thisClient; @@ -83,14 +76,21 @@ static void delZombieCLient(void *p_nothink) static void eventPeriodicSyncClient(void *p_nothink) { - my_time_t currentTime; client_t *thisClientInfo; client_t *thisClientSend; + item_t *thisItem; tux_t *thisTux; int i, j; - currentTime = getMyTime(); - + for( i = 0 ; i < getCurrentArena()->listItem->count; i++) + { + thisItem = (item_t *) getCurrentArena()->listItem->list[i]; + + if( thisItem->type != ITEM_EXPLOSION || thisItem->type != ITEM_BIG_EXPLOSION ) + { + proto_send_additem_server(PROTO_SEND_ALL, NULL, thisItem); + } + } for( i = 0 ; i < listClient->count; i++) { @@ -126,8 +126,6 @@ static void eventSendPingClients(void *p_nothink) proto_send_ping_server(PROTO_SEND_ALL, NULL); } -#endif - void static initServer() { listClient = newList(); @@ -186,6 +184,8 @@ static client_t* newAnyClient() new->status = NET_STATUS_OK; new->buffer = newBuffer(LIMIT_BUFFER); + new->lastPing = getMyTime(); + new->lastEvent = getMyTime(); return new; } @@ -202,7 +202,6 @@ client_t* newUdpClient(sock_udp_t *sock_udp) printf("new client from %s:%d\n", str_ip, getSockUdpPort(sock_udp)); new = newAnyClient(); - new->lastPing = getMyTime(); new->socket_udp = sock_udp; return new; @@ -218,7 +217,6 @@ client_t* newSdlUdpClient(sock_sdl_udp_t *sock_sdl_udp) printf("new client from %d\n", getSockSdlUdpPort(sock_sdl_udp)); new = newAnyClient(); - new->lastPing = getMyTime(); new->socket_sdl_udp = sock_sdl_udp; return new; diff --git a/src/tux.c b/src/tux.c index 2069978..3b14427 100644 --- a/src/tux.c +++ b/src/tux.c @@ -87,7 +87,7 @@ tux_t* newTux() new->gun = GUN_SIMPLE; new->shot[ new->gun ] = GUN_MAX_SHOT; - sprintf(new->name, "no_name_id_%dde", new->id); + sprintf(new->name, "no_name_id_%d", new->id); new->score = 0; new->frame = 0; @@ -155,14 +155,14 @@ void drawTux(tux_t *tux) SDL_Surface *g_image = NULL; assert( tux != NULL ); -/* + if( tux->bonus == BONUS_HIDDEN && getNetTypeGame() != NET_GAME_TYPE_NONE && tux->control == TUX_CONTROL_NET ) { return; } -*/ + switch( tux->position ) { case TUX_UP : @@ -528,6 +528,22 @@ void moveTux(tux_t *tux, int n) int x, y, w, h; arena_t *arena; +/* + static my_time_t lastTime = 0; + my_time_t currentTime; + + if( lastTime == 0 ) + { + lastTime = getMyTime(); + } + + currentTime = getMyTime(); + + printf("%d\n", currentTime - lastTime ); + + lastTime = getMyTime(); +*/ + assert( tux != NULL ); if( tux->position != n ) @@ -668,7 +684,7 @@ void shotTux(tux_t *tux) void actionTux(tux_t *tux, int action) { - if( tux->status != TUX_STATUS_ALIVE ) + if( tux->status == TUX_STATUS_DEAD ) { return; } -- cgit v1.2.3