summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config.h2
-rw-r--r--deb_config.h4
-rw-r--r--include/game.h9
-rw-r--r--include/main.h1
-rw-r--r--include/publicServer.h1
-rw-r--r--include/server.h3
-rw-r--r--packaging/deb/control8
-rw-r--r--packaging/deb/r2
-rwxr-xr-xsrc/Makefile5
-rwxr-xr-xsrc/Makefile-publicServer5
-rw-r--r--src/game.c112
-rw-r--r--src/item.c11
-rw-r--r--src/main.c109
-rw-r--r--src/myTimer.c1
-rw-r--r--src/proto.c6
-rw-r--r--src/publicServer.c65
-rw-r--r--src/screen_mainMenu.c3
-rw-r--r--src/server.c37
18 files changed, 201 insertions, 183 deletions
diff --git a/config.h b/config.h
index dba75f2..7a3a936 100644
--- a/config.h
+++ b/config.h
@@ -6,7 +6,7 @@
#define DEBUG_CLIENT_RECV
*/
-#define TUXANCI_NG_VERSION "svn47"
+#define TUXANCI_NG_VERSION "svn49"
#define DESTDIR "/usr/local/"
#define SUPPORT_NET_SDL_UDP
diff --git a/deb_config.h b/deb_config.h
new file mode 100644
index 0000000..9b69b81
--- /dev/null
+++ b/deb_config.h
@@ -0,0 +1,4 @@
+
+#define TUXANCI_NG_VERSION "svn49"
+#define DESTDIR "/usr/"
+#define SUPPORT_NET_SDL_UDP
diff --git a/include/game.h b/include/game.h
new file mode 100644
index 0000000..6ce694d
--- /dev/null
+++ b/include/game.h
@@ -0,0 +1,9 @@
+
+#ifndef GAME_H
+
+#define GAME_H
+
+extern void quitGame();
+extern void startGame();
+
+#endif
diff --git a/include/main.h b/include/main.h
index 7524cc6..3dd5fc1 100644
--- a/include/main.h
+++ b/include/main.h
@@ -26,6 +26,5 @@ extern char* getParamElse(char *s1, char *s2);
extern bool_t isParamFlag(char *s);
extern char *getString(int n);
extern void accessExistFile(const char *s);
-extern void quit();
#endif
diff --git a/include/publicServer.h b/include/publicServer.h
index 6d0c8b4..7fb22da 100644
--- a/include/publicServer.h
+++ b/include/publicServer.h
@@ -13,5 +13,6 @@ extern int getChoiceArenaId();
extern void eventPublicServer();
extern void my_handler_quit(int n);
extern void quitPublicServer();
+extern int startPublicServer();
#endif
diff --git a/include/server.h b/include/server.h
index f865282..3a07b43 100644
--- a/include/server.h
+++ b/include/server.h
@@ -3,6 +3,8 @@
#define MY_SERVER
+#include <time.h>
+
#include "list.h"
#include "tux.h"
#include "buffer.h"
@@ -67,6 +69,7 @@ extern void quitSdlUdpServer();
extern void destroyClient(client_t *p);
+extern time_t getUpdateServer();
extern list_t* getListServerClient();
extern int getServerMaxClients();
extern void setServerMaxClients(int n);
diff --git a/packaging/deb/control b/packaging/deb/control
index 9779ea8..407074c 100644
--- a/packaging/deb/control
+++ b/packaging/deb/control
@@ -1,12 +1,12 @@
Package: tuxanci-ng
-Version: svn48
+Version: svn49
Section: Game
Priority: optional
Depends: libc6 (>= 2.2.4-4), libsdl1.2debian (>= 1.2), libsdl-image1.2 (>= 1.2), libsdl-mixer1.2 (>= 1.2), libsdl-net1.2 (>= 1.2), libsdl-ttf2.0-0 (>= 2.0)
Architecture: i386
-Installed-Size: 4510
+Installed-Size: 4630
Maintainer: Dušan Ďurech <dusan.d@centrum.sk>
-Description: Game tuxanci next generation SVN revision 27
- Game tuxanci next generation SVN revision 27
+Description: Game tuxanci next generation SVN revision 49
+ Game tuxanci next generation SVN revision 49
.
http://www.tuxanci.org
diff --git a/packaging/deb/r b/packaging/deb/r
index 21e72e8..2e66562 100644
--- a/packaging/deb/r
+++ b/packaging/deb/r
@@ -1 +1 @@
-48
+49 \ No newline at end of file
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 <time.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <signal.h>
+#include <unistd.h>
+#include <assert.h>
+#include <sys/stat.h>
+
+#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 <assert.h>
#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
{