From 9058b5c0bfc9a05c9004cfbbcdd3bb85d80ed6fc Mon Sep 17 00:00:00 2001 From: oroborus Date: Fri, 2 May 2008 16:57:36 +0000 Subject: - o obsluhu odstaneni streli pri vybuchu sa stara server - server sa _nemusi_ restartovat kazdych 49 dni - uptime sa rata v sekundach, v statuse je aj nazov areny - drobne upravy v kode ( vymazanie mensej duplicity kodu ) git-svn-id: http://opensvn.csie.org/tuxanci_ng@49 0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e --- src/Makefile | 5 ++- src/Makefile-publicServer | 5 ++- src/game.c | 112 ++++++++++++++++++++++++++++++++++++++++++++++ src/item.c | 11 ++++- src/main.c | 109 ++++---------------------------------------- src/myTimer.c | 1 + src/proto.c | 6 ++- src/publicServer.c | 65 +-------------------------- src/screen_mainMenu.c | 3 +- src/server.c | 37 ++++++++++++--- 10 files changed, 178 insertions(+), 176 deletions(-) create mode 100644 src/game.c (limited to 'src') diff --git a/src/Makefile b/src/Makefile index 2ce95be..df5b2d2 100755 --- a/src/Makefile +++ b/src/Makefile @@ -15,7 +15,7 @@ FILES = interface.o font.o list.o image.o layer.o director.o configFile.o tux.o item.o widget_label.o screen_mainMenu.o widget_button.o screen_analyze.o widget_textfield.o \ widget_check.o widget_image.o screen_setting.o screen_gameType.o screen_choiceArena.o \ widget_buttonimage.o screen_credits.o teleport.o pipe.o homeDirector.o screen_table.o \ - sdl_udp.o proto.o server.o client.o term.o keytable.o language.o + sdl_udp.o proto.o server.o client.o term.o keytable.o language.o game.o tuxanci-ng: $(FILES) $(CC) $(CFLAGS) $(LIBS) -o $(BUILD_DIR)/tuxanci-ng $(BUILD_DIR)/*.o @@ -176,5 +176,8 @@ keytable.o: keytable.c ../include/keytable.h language.o: language.c ../include/language.h $(CC) $(CFLAGS) -o $(BUILD_DIR)/language.o -c language.c +game.o: game.c ../include/game.h + $(CC) $(CFLAGS) -o $(BUILD_DIR)/game.o -c game.c + clean: rm -rf *.o *.c~ ../include/*.h~ Makefile~ diff --git a/src/Makefile-publicServer b/src/Makefile-publicServer index 37e5c42..39537ee 100755 --- a/src/Makefile-publicServer +++ b/src/Makefile-publicServer @@ -12,7 +12,7 @@ LIBS = FILES = list.o director.o configFile.o tux.o wall.o shot.o myTimer.o \ buffer.o dynamicInt.o arena.o arenaFile.o textFile.o gun.o item.o teleport.o pipe.o \ - udp.o proto.o server.o publicServer.o net_multiplayer.o serverConfigFile.o + udp.o proto.o server.o publicServer.o net_multiplayer.o serverConfigFile.o main.o $(BUILD_DIR)/publicserver: mkdir_build $(FILES) $(CC) $(CFLAGS) $(LIBS) -o $(BUILD_DIR)/publicserver $(BUILD_DIR)/*.o @@ -20,6 +20,9 @@ $(BUILD_DIR)/publicserver: mkdir_build $(FILES) mkdir_build: mkdir -p $(BUILD_DIR) +main.o: main.c + $(CC) $(CFLAGS) -o $(BUILD_DIR)/main.o -c main.c + publicServer.o: publicServer.c $(CC) $(CFLAGS) -o $(BUILD_DIR)/publicServer.o -c publicServer.c diff --git a/src/game.c b/src/game.c new file mode 100644 index 0000000..34334c1 --- /dev/null +++ b/src/game.c @@ -0,0 +1,112 @@ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "main.h" +#include "tux.h" + +#include "font.h" +#include "keytable.h" +#include "language.h" +#include "image.h" +#include "layer.h" +#include "interface.h" +#include "screen.h" +#include "screen_world.h" +#include "screen_mainMenu.h" +#include "screen_analyze.h" +#include "screen_setting.h" +#include "screen_gameType.h" +#include "screen_choiceArena.h" +#include "screen_table.h" +#include "screen_credits.h" +#include "homeDirector.h" +#include "item.h" +#include "shot.h" +#include "arenaFile.h" +#include "panel.h" +#include "audio.h" +#include "sound.h" +#include "music.h" + +static void initGame() +{ + createHomeDirector(); + + if( initLanguage() == -1 ) + { + printf("fatal error !\n"); + exit(-1); + } + + initSDL(); + + initLayer(); + initFont(getLanguageFont(), getLanguageSize()); + initKeyTable(); + initImageData(); + initAudio(); + initSound(); + initMusic(); + initScreen(); + initArenaFile(); + initTux(); + initItem(); + initShot(); + initPanel(); + initWorld(); + initScreenMainMenu(); + initScreenAnalyze(); + initScreenSetting(); + initScreenGameType(); + initScreenChoiceArena(); + initScreenCredits(); + initScreenTable(); +} + +void quitGame() +{ + quitSDL(); + quitLayer(); + quitFont(); + quitKeyTable(); + quitLanguage(); + quitScreen(); + quitArenaFile(); + quitItem(); + quitTux(); + quitShot(); + quitPanel(); + quitWorld(); + quitImageData(); + quitSound(); + quitMusic(); + quitAudio(); + quitScreenMainMenu(); + quitScreenAnalyze(); + quitScreenSetting(); + quitScreenGameType(); + quitScreenChoiceArena(); + quitScreenCredits(); + quitScreenTable(); + + printf("quit..\n"); + + exit(0); +} + +void startGame() +{ + initGame(); + + setScreen("mainMenu"); + + eventSDL(); + quitGame(); +} diff --git a/src/item.c b/src/item.c index 70b43fb..3e4e6e5 100644 --- a/src/item.c +++ b/src/item.c @@ -370,6 +370,11 @@ void eventConflictShotWithItem(list_t *listItem, list_t *listShot) item_t *thisItem; int i, j; + if( getNetTypeGame() == NET_GAME_TYPE_CLIENT ) + { + return; + } + assert( listItem != NULL ); assert( listShot != NULL ); @@ -416,7 +421,11 @@ void eventConflictShotWithItem(list_t *listItem, list_t *listShot) if( isDelShot ) { - //printf("del shot\n"); + if( getNetTypeGame() == NET_GAME_TYPE_SERVER ) + { + proto_send_delshot_server(PROTO_SEND_ALL, NULL, thisShot); + } + delListItem(listShot, i, destroyShot); i--; } diff --git a/src/main.c b/src/main.c index c1c3371..4b14c63 100644 --- a/src/main.c +++ b/src/main.c @@ -10,108 +10,17 @@ #include "main.h" #include "tux.h" +#include "game.h" -#ifndef PUBLIC_SERVER +#ifdef PUBLIC_SERVER -#include "font.h" -#include "keytable.h" -#include "language.h" -#include "image.h" -#include "layer.h" -#include "interface.h" -#include "screen.h" -#include "screen_world.h" -#include "screen_mainMenu.h" -#include "screen_analyze.h" -#include "screen_setting.h" -#include "screen_gameType.h" -#include "screen_choiceArena.h" -#include "screen_table.h" -#include "screen_credits.h" -#include "homeDirector.h" -#include "item.h" -#include "shot.h" -#include "arenaFile.h" -#include "panel.h" -#include "audio.h" -#include "sound.h" -#include "music.h" +#include "publicServer.h" #endif static int my_argc; static char **my_argv; -#ifndef PUBLIC_SERVER - -static void init() -{ - createHomeDirector(); - - if( initLanguage() == -1 ) - { - printf("fatal error !\n"); - exit(-1); - } - - initSDL(); - - initLayer(); - initFont(getLanguageFont(), getLanguageSize()); - initKeyTable(); - initImageData(); - initAudio(); - initSound(); - initMusic(); - initScreen(); - initArenaFile(); - initTux(); - initItem(); - initShot(); - initPanel(); - initWorld(); - initScreenMainMenu(); - initScreenAnalyze(); - initScreenSetting(); - initScreenGameType(); - initScreenChoiceArena(); - initScreenCredits(); - initScreenTable(); -} - -void quit() -{ - quitSDL(); - quitLayer(); - quitFont(); - quitKeyTable(); - quitLanguage(); - quitScreen(); - quitArenaFile(); - quitItem(); - quitTux(); - quitShot(); - quitPanel(); - quitWorld(); - quitImageData(); - quitSound(); - quitMusic(); - quitAudio(); - quitScreenMainMenu(); - quitScreenAnalyze(); - quitScreenSetting(); - quitScreenGameType(); - quitScreenChoiceArena(); - quitScreenCredits(); - quitScreenTable(); - - printf("quit..\n"); - - exit(0); -} - -#endif - char* getParam(char *s) { int i; @@ -137,7 +46,6 @@ char* getParam(char *s) return NULL; } - char* getParamElse(char *s1, char *s2) { char *ret; @@ -189,12 +97,13 @@ int main(int argc, char *argv[]) my_argc = argc; my_argv = argv; - init(); - - setScreen("mainMenu"); +#ifndef PUBLIC_SERVER + startGame(); +#endif - eventSDL(); - quit(); +#ifdef PUBLIC_SERVER + startPublicServer(); +#endif return 0; } diff --git a/src/myTimer.c b/src/myTimer.c index f9e46da..89696e6 100644 --- a/src/myTimer.c +++ b/src/myTimer.c @@ -42,6 +42,7 @@ my_time_t getMyTime() ticks = (now.tv_sec-start.tv_sec)*1000+(now.tv_usec-start.tv_usec)/1000; + //printf("-> %d\n", ticks); return ticks; } diff --git a/src/proto.c b/src/proto.c index 60bcf20..6cb042e 100644 --- a/src/proto.c +++ b/src/proto.c @@ -139,9 +139,11 @@ void proto_send_status_server(int type, client_t *client) sprintf(msg, "version: %s\n" "clients: %d\n" "maxclients: %d\n" - "uptime: %d\n", + "uptime: %d\n" + "arena: %s\n", TUXANCI_NG_VERSION, getCurrentArena()->listTux->count, - getServerMaxClients(), getMyTime() ); + getServerMaxClients(), (unsigned int)getUpdateServer(), + getArenaNetName( getChoiceArenaId() ) ); proto_send(type, client, msg); } diff --git a/src/publicServer.c b/src/publicServer.c index d6910f7..c539b3b 100644 --- a/src/publicServer.c +++ b/src/publicServer.c @@ -26,9 +26,6 @@ static int arenaId; static arena_t *arena; static bool_t isSignalEnd; -static int my_argc; -static char **my_argv; - void countRoundInc() { } @@ -119,66 +116,8 @@ void quitPublicServer() exit(0); } -char* getParam(char *s) -{ - int i; - int len; - - len = strlen(s); - - for( i = 1 ; i < my_argc ; i++ ) - { - if( strstr(my_argv[i], s) == my_argv[i] ) - { - return strchr(my_argv[i], '=')+1; - } - } - - return NULL; -} - -char* getParamElse(char *s1, char *s2) -{ - char *ret; - ret = getParam(s1); - - if( ret == NULL) - { - return s2; - } - - return ret; -} - -bool_t isParamFlag(char *s) -{ - int i; - - for( i = 0 ; i < my_argc ; i++ ) - { - if( strcmp(s, my_argv[i]) == 0 ) - { - return TRUE; - } - } - - return FALSE; -} - -char *getString(int n) +int startPublicServer() { - char str[STR_NUM_SIZE]; - sprintf(str, "%d", n); - return strdup(str); -} - -int main(int argc, char *argv[]) -{ - srand( (unsigned) time(NULL) ); - - my_argc = argc; - my_argv = argv; - signal(SIGPIPE, SIG_IGN); signal(SIGINT, my_handler_quit); signal(SIGTERM, my_handler_quit); @@ -197,5 +136,3 @@ int main(int argc, char *argv[]) return 0; } - - diff --git a/src/screen_mainMenu.c b/src/screen_mainMenu.c index 171b1a7..7627dc0 100644 --- a/src/screen_mainMenu.c +++ b/src/screen_mainMenu.c @@ -3,6 +3,7 @@ #include #include "main.h" +#include "game.h" #include "interface.h" #include "language.h" #include "screen.h" @@ -82,7 +83,7 @@ static void eventWidget(void *p) if( button == button_end ) { - quit(); + quitGame(); } } diff --git a/src/server.c b/src/server.c index 37f38eb..26867a8 100644 --- a/src/server.c +++ b/src/server.c @@ -41,9 +41,19 @@ static sock_sdl_udp_t *sock_server_sdl_udp; static list_t *listClient; static list_t *listServerTimer; -static my_time_t lastSyncClient; +static time_t timeUpdate; static int maxClients; +static void startUpdateServer() +{ + timeUpdate = time(NULL); +} + +time_t getUpdateServer() +{ + return time(NULL) - timeUpdate; +} + static void delZombieCLient(void *p_nothink) { client_t *thisClient; @@ -121,6 +131,7 @@ static void eventPeriodicSyncClient(void *p_nothink) } } +/* static void eventPeriodicSyncSelfClient(void *p_nothink) { client_t *thisClient; @@ -136,24 +147,38 @@ static void eventPeriodicSyncSelfClient(void *p_nothink) } } } +*/ static void eventSendPingClients(void *p_nothink) { proto_send_ping_server(PROTO_SEND_ALL, NULL); } -void static initServer() + +static void setServerTimer() { - listClient = newList(); - lastSyncClient = getMyTime(); - setServerMaxClients(SERVER_MAX_CLIENTS); + if( listServerTimer != NULL ) + { + destroyTimer(listServerTimer); + } + restartTimer(); listServerTimer = newTimer(); addTaskToTimer(listServerTimer, TIMER_PERIODIC, delZombieCLient, NULL, SERVER_TIMEOUT); addTaskToTimer(listServerTimer, TIMER_PERIODIC, eventPeriodicSyncClient, NULL, SERVER_TIME_SYNC); //addTaskToTimer(listServerTimer, TIMER_PERIODIC, eventPeriodicSyncSelfClient, NULL, 5000); addTaskToTimer(listServerTimer, TIMER_PERIODIC, eventSendPingClients, NULL, SERVER_TIME_PING); + +} + +void static initServer() +{ + startUpdateServer(); + listServerTimer = NULL; + listClient = newList(); + setServerMaxClients(SERVER_MAX_CLIENTS); + setServerTimer(); } #ifdef SUPPORT_NET_UNIX_UDP @@ -554,7 +579,7 @@ void selectServerUdpSocket() if( listClient->count == 0 ) { ret = select(max_fd+1, &readfds, (fd_set *)NULL, (fd_set *)NULL, NULL); - //restartTimer(); + setServerTimer(); } else { -- cgit v1.2.3