From 2fd0c9d50f1eb83d46080fb114cba5465e8c4506 Mon Sep 17 00:00:00 2001 From: oroborus Date: Tue, 3 Jun 2008 21:26:17 +0000 Subject: - zaciatok podpory FR jazyka - server podporuje socre ( treb este zdokumentovat protokol ) - prelozene dve chybove hlasky pre siete - odosielam to na rychlo git-svn-id: http://opensvn.csie.org/tuxanci_ng@59 0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e --- src/Makefile-publicServer | 5 ++- src/client.c | 4 +- src/heightScore.c | 98 +++++++++++++++++++++++++++++++++++++++++++++++ src/proto.c | 60 +++++++++++++++++++++++++++++ src/publicServer.c | 3 ++ src/screen_analyze.c | 13 +++++++ src/screen_world.c | 3 +- src/server.c | 13 +++++++ src/storage.c | 2 +- 9 files changed, 196 insertions(+), 5 deletions(-) create mode 100644 src/heightScore.c (limited to 'src') diff --git a/src/Makefile-publicServer b/src/Makefile-publicServer index f81d845..99f3eea 100755 --- a/src/Makefile-publicServer +++ b/src/Makefile-publicServer @@ -10,7 +10,7 @@ CFLAGS = -g -O0 -I../include -Wall BUILD_DIR = ../build-server LIBS = -ldl -FILES = list.o modules.o director.o configFile.o tux.o shot.o myTimer.o \ +FILES = list.o heightScore.o modules.o director.o configFile.o tux.o shot.o myTimer.o \ buffer.o arena.o arenaFile.o textFile.o gun.o item.o idManager.o checkFront.o\ udp.o proto.o server.o publicServer.o net_multiplayer.o serverConfigFile.o main.o @@ -20,6 +20,9 @@ $(BUILD_DIR)/publicserver: mkdir_build $(FILES) mkdir_build: mkdir -p $(BUILD_DIR) +heightScore.o: heightScore.c + $(CC) $(CFLAGS) -o $(BUILD_DIR)/heightScore.o -c heightScore.c + main.o: main.c $(CC) $(CFLAGS) -o $(BUILD_DIR)/main.o -c main.c diff --git a/src/client.c b/src/client.c index 2d98790..0009909 100644 --- a/src/client.c +++ b/src/client.c @@ -11,6 +11,8 @@ #include "screen_world.h" #include "proto.h" #include "client.h" +#include "language.h" +#include "screen_analyze.h" static int protocolType; @@ -243,7 +245,7 @@ void selectClientSdlUdpSocket() if( isServerAlive() == FALSE ) { - fprintf(stderr, "server neodpoveda !\n"); + setMsgToAnalyze(getMyText("ERROR_SERVER_DONT_ALIVE")); setWorldEnd(); return; } diff --git a/src/heightScore.c b/src/heightScore.c new file mode 100644 index 0000000..fa7402e --- /dev/null +++ b/src/heightScore.c @@ -0,0 +1,98 @@ + +#include +#include +#include +#include + +#include "main.h" +#include "list.h" +#include "textFile.h" +#include "heightScore.h" + +static textFile_t *textFile; + +void initHeightScore(char *file) +{ + int i; + + textFile = loadTextFile(file); + + if( textFile == NULL ) + { + fprintf(stderr, "I can't load %s !\n", file); + fprintf(stderr, "I create %s\n", file); + textFile = newTextFile(file); + } + else + { + return; + } + + if( textFile == NULL ) + { + fprintf(stderr, "I can't create %s!\n", file); + return; + } + + for( i = 0 ; i < HEIGHTSCORE_MAX_PLAYERS ; i++ ) + { + addList(textFile->text, strdup("no_name 0") ); + } + + saveTextFile(textFile); +} + +int addPlayerInHighScore(char *name, int score) +{ + int i; + + if( score <= 0 ) + { + return -1; // Ha ha ha + } + + for( i = 0 ; i < HEIGHTSCORE_MAX_PLAYERS ; i++ ) + { + char *line; + char thisName[STR_NAME_SIZE]; + int thisCore; + + line = (char *) textFile->text->list[i]; + sscanf(line, "%s %d", thisName, &thisCore); + + if( score >= thisCore ) + { + char new[STR_SIZE]; + + sprintf(new, "%s %d", name, score); + insList(textFile->text, i, strdup(new) ); + delListItem(textFile->text, HEIGHTSCORE_MAX_PLAYERS, free); + saveTextFile(textFile); + + return 0; + } + } + + return -1; +} + +char* getTableItem(int index) +{ + if( textFile != NULL && + index >= 0 && + index < textFile->text->count ) + { + return (char *)textFile->text->list[index]; + } + + return NULL; +} + +void quitHeightScore() +{ + if( textFile != NULL ) + { + saveTextFile(textFile); + destroyTextFile(textFile); + } +} diff --git a/src/proto.c b/src/proto.c index d925011..a31e640 100644 --- a/src/proto.c +++ b/src/proto.c @@ -18,15 +18,18 @@ #include "idManager.h" #ifndef PUBLIC_SERVER +#include "language.h" #include "network.h" #include "screen_world.h" #include "screen_setting.h" #include "screen_choiceArena.h" +#include "screen_analyze.h" #include "client.h" #include "term.h" #endif #ifdef PUBLIC_SERVER +#include "heightScore.h" #include "publicServer.h" #endif @@ -100,6 +103,14 @@ void proto_recv_error_client(char *msg) cmd, &errorcode); printf("proto error code %d\n", errorcode); + + switch(errorcode) + { + case PROTO_ERROR_CODE_BAD_VERSION : + setMsgToAnalyze(getMyText("ERROR_BAD_VERSION")); + setWorldEnd(); + break; + } } #endif @@ -170,6 +181,55 @@ void proto_recv_status_server(client_t *client, char *msg) proto_send_status_server(PROTO_SEND_ONE, client); } +#ifdef PUBLIC_SERVER + +void proto_send_listscore_server(int type, client_t *client, int max) +{ + char *str; + char *msg; + int i; + + msg = malloc( (max * 24) * sizeof(char) ); + strcpy(msg, ""); + + for( i = 0 ; i < max ; i++ ) + { + str = getTableItem(i); + + if( str == NULL ) + { + break; + } + + strcat(msg, str); + strcat(msg, "\n"); + } + + proto_send(type, client, msg); + free(msg); +} + +void proto_recv_listscore_server(client_t *client, char *msg) +{ + char cmd[STR_PROTO_SIZE]; + int max; + int ret; + + assert( msg != NULL ); + + ret = sscanf(msg, "%s %d", + cmd, &max); + + if( ret != 2 ) + { + max = HEIGHTSCORE_MAX_PLAYERS; + } + + proto_send_listscore_server(PROTO_SEND_ONE, client, max); +} + +#endif + #ifndef PUBLIC_SERVER void proto_send_check_client(int id) diff --git a/src/publicServer.c b/src/publicServer.c index 2b7d2cc..6d55dbb 100644 --- a/src/publicServer.c +++ b/src/publicServer.c @@ -19,6 +19,7 @@ #include "publicServer.h" #include "net_multiplayer.h" #include "serverConfigFile.h" +#include "heightScore.h" #include "modules.h" static int arenaId; @@ -43,6 +44,7 @@ int initPublicServer() initItem(); initShot(); initServerConfigFile(); + initHeightScore( getSetting("SCOREFILE", "--scorefile", "./heightscore") ); arenaId = getArenaIdFormNetName( getSetting("ARENA", "--arena", "FAGN") ); arena = getArena(arenaId); @@ -122,6 +124,7 @@ void quitPublicServer() quitServerConfigFile(); quitModule(); quitListID(); + quitHeightScore(); exit(0); } diff --git a/src/screen_analyze.c b/src/screen_analyze.c index c223677..de84679 100644 --- a/src/screen_analyze.c +++ b/src/screen_analyze.c @@ -22,6 +22,7 @@ static widget_image_t *image_backgorund; static list_t *listWidgetLabelName; static list_t *listWidgetLabelScore; static list_t *listAnalyze; +static widget_label_t *widgetLabelMsg; static widget_button_t *button_ok; @@ -66,6 +67,7 @@ void drawScreenAnalyze() drawWidgetLabel(this); } + drawWidgetLabel(widgetLabelMsg); drawWidgetButton(button_ok); } @@ -76,6 +78,8 @@ void eventScreenAnalyze() void stopScreenAnalyze() { + destroyWidgetLabel(widgetLabelMsg); + widgetLabelMsg = newWidgetLabel("", WINDOW_SIZE_X / 2 , 250, WIDGET_LABEL_CENTER); } static void eventWidget(void *p) @@ -106,6 +110,12 @@ void addAnalyze(char *name, int score) addList(listAnalyze, newAnalyze(name, score) ); } +void setMsgToAnalyze(char *msg) +{ + destroyWidgetLabel(widgetLabelMsg); + widgetLabelMsg = newWidgetLabel(msg, WINDOW_SIZE_X / 2 , 250, WIDGET_LABEL_CENTER); +} + void endAnalyze() { int i; @@ -145,6 +155,8 @@ void initScreenAnalyze() registerScreen( newScreen("analyze", startScreenAnalyze, eventScreenAnalyze, drawScreenAnalyze, stopScreenAnalyze) ); + + widgetLabelMsg = newWidgetLabel("", WINDOW_SIZE_X / 2 , 250, WIDGET_LABEL_CENTER); } void quitScreenAnalyze() @@ -156,5 +168,6 @@ void quitScreenAnalyze() destroyListItem(listAnalyze, destroyAnalyze); destroyWidgetButton(button_ok); + destroyWidgetLabel(widgetLabelMsg); } diff --git a/src/screen_world.c b/src/screen_world.c index 907f659..b158dee 100644 --- a/src/screen_world.c +++ b/src/screen_world.c @@ -1,4 +1,3 @@ - #include #include @@ -35,6 +34,7 @@ #include "music.h" #include "modules.h" #include "idManager.h" +#include "heightScore.h" static arena_t *arena; static int count; @@ -457,4 +457,3 @@ void quitWorld() printf("quit world\n"); isScreenWorldInit = FALSE; } - diff --git a/src/server.c b/src/server.c index ab45fef..8777e7a 100644 --- a/src/server.c +++ b/src/server.c @@ -27,6 +27,7 @@ #ifdef PUBLIC_SERVER #include "publicServer.h" +#include "heightScore.h" #endif #ifdef SUPPORT_NET_UNIX_UDP @@ -282,8 +283,12 @@ void destroyClient(client_t *p) destroyBuffer(p->buffer); destroyCheckFront(p->listCheck); + if( p->tux != NULL ) { +#ifdef PUBLIC_SERVER + addPlayerInHighScore(p->tux->name, p->tux->score); +#endif index = searchListItem(getCurrentArena()->listTux, p->tux); delListItem(getCurrentArena()->listTux, index, destroyTux); } @@ -486,6 +491,14 @@ static void eventClientBuffer(client_t *client) continue; } +#ifdef PUBLIC_SERVER + if( strncmp(line, "list", 4) == 0 ) + { + proto_recv_listscore_server(client, line); + continue; + } +#endif + if( client->tux != NULL ) { if( strncmp(line, "event", 5) == 0 ) diff --git a/src/storage.c b/src/storage.c index 0ae057c..b1c378c 100644 --- a/src/storage.c +++ b/src/storage.c @@ -35,7 +35,7 @@ static storage_item_t* newStorageItem(char *group, char *name, void *data) return new; } -static void destroyStorageItem(storage_item_t *p, void(*f)(void *)) +static void destroyStorageItem(storage_item_t *p, void(*f)(void *)) { assert( p != NULL ); assert( f != NULL ); -- cgit v1.2.3