summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config.h4
-rw-r--r--include/heightScore.h13
-rw-r--r--include/proto.h2
-rw-r--r--include/screen_analyze.h1
-rw-r--r--lang/cs.lang4
-rw-r--r--lang/en.lang4
-rw-r--r--lang/fr.lang35
-rw-r--r--lang/sk.lang4
-rwxr-xr-xsrc/Makefile-publicServer5
-rw-r--r--src/client.c4
-rw-r--r--src/heightScore.c98
-rw-r--r--src/proto.c60
-rw-r--r--src/publicServer.c3
-rw-r--r--src/screen_analyze.c13
-rw-r--r--src/screen_world.c3
-rw-r--r--src/server.c13
-rw-r--r--src/storage.c2
17 files changed, 261 insertions, 7 deletions
diff --git a/config.h b/config.h
index 4b3ab74..2147311 100644
--- a/config.h
+++ b/config.h
@@ -6,8 +6,8 @@
#define DEBUG_CLIENT_RECV
*/
-#define TUXANCI_NG_VERSION "svn57"
+#define TUXANCI_NG_VERSION "svn58"
#define DESTDIR "/usr/local/"
#define SUPPORT_NET_SDL_UDP
-//#define PUBLIC_SERVER
+#define PUBLIC_SERVER
diff --git a/include/heightScore.h b/include/heightScore.h
new file mode 100644
index 0000000..b1bf7e2
--- /dev/null
+++ b/include/heightScore.h
@@ -0,0 +1,13 @@
+
+#ifndef HEIGHT_SCORE_H
+
+#define HEIGHT_SCORE_H
+
+#define HEIGHTSCORE_MAX_PLAYERS 100
+
+extern void initHeightScore(char *file);
+extern int addPlayerInHighScore(char *name, int score);
+extern char* getTableItem(int index);
+extern void quitHeightScore();
+
+#endif
diff --git a/include/proto.h b/include/proto.h
index 5a097a6..f392aaa 100644
--- a/include/proto.h
+++ b/include/proto.h
@@ -53,6 +53,8 @@ extern void proto_send_hello_client(char *name);
extern void proto_recv_hello_server(client_t *client, char *msg);
extern void proto_send_status_server(int type, client_t *client);
extern void proto_recv_status_server(client_t *client, char *msg);
+extern void proto_send_listscore_server(int type, client_t *client, int max);
+extern void proto_recv_listscore_server(client_t *client, char *msg);
extern void proto_send_check_client(int id);
extern void proto_recv_check_server(client_t *client, char *msg);
extern void proto_send_init_server(int type, client_t *client, client_t *client2);
diff --git a/include/screen_analyze.h b/include/screen_analyze.h
index 515c6ef..7404da6 100644
--- a/include/screen_analyze.h
+++ b/include/screen_analyze.h
@@ -17,6 +17,7 @@ extern void eventScreenAnalyze();
extern void stopScreenAnalyze();
extern void restartAnalyze();
extern void addAnalyze(char *name, int score);
+extern void setMsgToAnalyze(char *msg);
extern void endAnalyze();
extern void initScreenAnalyze();
extern void quitScreenAnalyze();
diff --git a/lang/cs.lang b/lang/cs.lang
index ccd3f7d..fa40672 100644
--- a/lang/cs.lang
+++ b/lang/cs.lang
@@ -16,6 +16,10 @@ OK Ok
BACK Zpět
NEXT Další
+# error message
+ERROR_BAD_VERSION Máte verzi klienta, kterou server nepodporuje.
+ERROR_SERVER_DONT_ALIVE Server neodpovida.
+
# main menu
PLAY Hraj
SETTING Nastavení
diff --git a/lang/en.lang b/lang/en.lang
index 64b1393..351eb9d 100644
--- a/lang/en.lang
+++ b/lang/en.lang
@@ -16,6 +16,10 @@ OK Ok
BACK Back
NEXT Next
+# error message
+ERROR_BAD_VERSION Version of your client isn't supported by the server.
+ERROR_SERVER_DONT_ALIVE Server's not responding, connection was closed.
+
# main menu
PLAY Play
SETTING Settings
diff --git a/lang/fr.lang b/lang/fr.lang
new file mode 100644
index 0000000..8123af6
--- /dev/null
+++ b/lang/fr.lang
@@ -0,0 +1,35 @@
+###
+# Englis translation file
+# Author: Oroborus <dusan.d@centrum.sk>
+###
+
+# about the author of this translation
+AUTHOR MeV
+AUTHOR_EMAIL chrystalyst@free.fr
+AUTHOR_JABBER unknown
+
+
+# specify font for this language
+HEAD fontfile="DejaVuSans.ttf" fontsize="16"
+
+# general
+OK Ok
+BACK Précédent
+NEXT Suivant
+
+# error message
+ERROR_BAD_VERSION Version of your client isn't supported by the server.
+
+# main menu
+PLAY Jouer
+SETTING Paramètres
+TABLE Meilleur Score
+CREDITS Auteurs
+END Quitter
+
+# settings - menu
+COUNT_ROUND Count Round:
+NAME_PLAYER1 Joueur de droite :
+NAME_PLAYER2 Joueur de gauche :
+MUSIC Musique :
+SOUND Son :
diff --git a/lang/sk.lang b/lang/sk.lang
index 9f01a26..7b1df7c 100644
--- a/lang/sk.lang
+++ b/lang/sk.lang
@@ -16,6 +16,10 @@ OK Ok
BACK Späť
NEXT Ďalej
+# error message
+ERROR_BAD_VERSION Mate verziu clienta, ktoru server nepodporuje.
+ERROR_SERVER_DONT_ALIVE Server neodpoveda.
+
# main menu
PLAY Hrať
SETTING Nastavenia
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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+
+#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 <stdio.h>
#include <assert.h>
@@ -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 );