diff options
| -rw-r--r-- | Makefile | 3 | ||||
| -rwxr-xr-x | conf/keytable.conf (renamed from data/keytable.conf) | 0 | ||||
| -rw-r--r-- | config.h | 2 | ||||
| -rw-r--r-- | include/item.h | 6 | ||||
| -rw-r--r-- | include/language.h | 4 | ||||
| -rw-r--r-- | include/server.h | 5 | ||||
| -rw-r--r-- | include/tux.h | 3 | ||||
| -rw-r--r-- | lang/cs.lang | 2 | ||||
| -rw-r--r-- | lang/en.lang | 2 | ||||
| -rw-r--r-- | lang/sk.lang | 2 | ||||
| -rw-r--r-- | src/client.c | 112 | ||||
| -rw-r--r-- | src/gun.c | 11 | ||||
| -rw-r--r-- | src/item.c | 14 | ||||
| -rw-r--r-- | src/keytable.c | 2 | ||||
| -rw-r--r-- | src/language.c | 76 | ||||
| -rw-r--r-- | src/main.c | 10 | ||||
| -rw-r--r-- | src/proto.c | 5 | ||||
| -rw-r--r-- | src/screen_world.c | 18 | ||||
| -rw-r--r-- | src/server.c | 26 | ||||
| -rw-r--r-- | src/tux.c | 24 |
20 files changed, 178 insertions, 149 deletions
@@ -49,7 +49,7 @@ server: install: mkdir -p $(DESTDIR)/bin - mkdir -p $(DESTDIR)/share/tuxanci-ng/{arena,data,font,image,lang,music,sound} + mkdir -p $(DESTDIR)/share/tuxanci-ng/{arena,data,font,image,lang,music,sound,conf} cp ./src/tuxanci-ng $(DESTDIR)/bin/ cp -rf ./arena/* $(DESTDIR)/share/tuxanci-ng/arena/ @@ -59,6 +59,7 @@ install: cp -rf ./music/* $(DESTDIR)/share/tuxanci-ng/music/ cp -rf ./sound/* $(DESTDIR)/share/tuxanci-ng/sound/ cp -rf ./data/* $(DESTDIR)/share/tuxanci-ng/data/ + cp -rf ./conf/* $(DESTDIR)/share/tuxanci-ng/conf/ uninstall: rm -rf $(DESTDIR)/{bin,share}/tuxanci-ng diff --git a/data/keytable.conf b/conf/keytable.conf index 1e349f4..1e349f4 100755 --- a/data/keytable.conf +++ b/conf/keytable.conf @@ -6,7 +6,7 @@ #define DEBUG_CLIENT_RECV */ -#define TUXANCI_NG_VERSION "svn42" +#define TUXANCI_NG_VERSION "svn43" #define DESTDIR "/usr/local/" #define SUPPORT_NET_SDL_UDP diff --git a/include/item.h b/include/item.h index b2c8098..ad390a1 100644 --- a/include/item.h +++ b/include/item.h @@ -4,11 +4,16 @@ #define ITEM_H #include "main.h" + +#define ITEM_SYNC_TIMEOUT 5000 + #ifndef PUBLIC_SERVER #include "interface.h" #endif + #include "list.h" #include "tux.h" +#include "myTimer.h" typedef struct item_struct { @@ -23,6 +28,7 @@ typedef struct item_struct int frame; //poradove cislo animacie int count; + my_time_t lastSync; tux_t *author; #ifndef PUBLIC_SERVER diff --git a/include/language.h b/include/language.h index 03f13e7..23fc1a4 100644 --- a/include/language.h +++ b/include/language.h @@ -3,8 +3,10 @@ #define LANGUAGE_H -extern void initLanguage(); +extern int initLanguage(); extern char* getMyText(char *key); +extern char* getLanguageFont(); +extern int getLanguageSize(); extern void quitLanguage(); #endif diff --git a/include/server.h b/include/server.h index bf7a1e9..f865282 100644 --- a/include/server.h +++ b/include/server.h @@ -37,15 +37,16 @@ typedef struct client_struct { #ifdef SUPPORT_NET_UNIX_UDP sock_udp_t *socket_udp; - my_time_t lastPing; #endif #ifdef SUPPORT_NET_SDL_UDP sock_sdl_udp_t *socket_sdl_udp; - my_time_t lastPing; #endif int status; tux_t *tux; + my_time_t lastPing; + my_time_t lastEvent; + buffer_t *buffer; } client_t; diff --git a/include/tux.h b/include/tux.h index 8767afa..fbe4ecc 100644 --- a/include/tux.h +++ b/include/tux.h @@ -12,7 +12,7 @@ #define TUX_MAX_ANIMATION_FRAME 10 #define TUX_KEY 1 -#define TUX_LOCATE_UNKNOWN -1 +#define TUX_LOCATE_UNKNOWN -100 #define TUX_MAX_PICKUP 50 #define TUX_MAX_BONUS 500 @@ -23,6 +23,7 @@ #define TUX_STATUS_ALIVE 0 #define TUX_STATUS_DEAD 1 +#define TUX_STATUS_PAUZED 2 #define TUX_CONTROL_NONE 0 #define TUX_CONTROL_KEYBOARD_LEFT 1 diff --git a/lang/cs.lang b/lang/cs.lang index b364e6f..f283411 100644 --- a/lang/cs.lang +++ b/lang/cs.lang @@ -8,6 +8,8 @@ AUTHOR xHire AUTHOR_EMAIL xhire@tuxportal.cz AUTHOR_JABBER Miczek@gmail.com +HEAD fontfile="DejaVuSans.ttf" fontsize="16" + # general OK Ok BACK Zpět diff --git a/lang/en.lang b/lang/en.lang index 8d567a3..6cb6dd8 100644 --- a/lang/en.lang +++ b/lang/en.lang @@ -8,6 +8,8 @@ AUTHOR Oroborus AUTHOR_EMAIL dusan.d@centrum.sk AUTHOR_JABBER oroborus@jabbim.sk +HEAD fontfile="DejaVuSans.ttf" fontsize="16" + # general OK Ok BACK Back diff --git a/lang/sk.lang b/lang/sk.lang index 4255be2..3ae922d 100644 --- a/lang/sk.lang +++ b/lang/sk.lang @@ -8,6 +8,8 @@ AUTHOR Oroborus AUTHOR_EMAIL dusan.d@centrum.sk AUTHOR_JABBER oroborus@jabbim.sk +HEAD fontfile="DejaVuSans.ttf" fontsize="16" + # general OK Ok BACK Späť 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() @@ -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 ) @@ -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); @@ -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; @@ -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; } |