summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config.h2
-rwxr-xr-xdata/keytable.conf289
-rw-r--r--data/lang.en30
-rw-r--r--data/lang.sk30
-rw-r--r--include/keytable.h27
-rw-r--r--include/language.h10
-rw-r--r--include/myTimer.h9
-rw-r--r--include/proto.h4
-rw-r--r--include/screen_world.h3
-rw-r--r--include/server.h30
-rw-r--r--include/serverConfigFile.h11
-rw-r--r--include/tux.h2
-rw-r--r--server.conf4
-rwxr-xr-xsrc/Makefile7
-rwxr-xr-xsrc/Makefile-publicServer57
-rw-r--r--src/gun.c6
-rwxr-xr-xsrc/interface.c2
-rw-r--r--src/item.c7
-rw-r--r--src/keytable.c121
-rw-r--r--src/language.c83
-rw-r--r--src/main.c30
-rw-r--r--src/myTimer.c68
-rw-r--r--src/net_multiplayer.c39
-rw-r--r--src/proto.c49
-rw-r--r--src/publicServer.c24
-rw-r--r--src/screen_choiceArena.c5
-rw-r--r--src/screen_credits.c3
-rw-r--r--src/screen_gameType.c15
-rw-r--r--src/screen_mainMenu.c11
-rw-r--r--src/screen_setting.c13
-rw-r--r--src/screen_table.c3
-rw-r--r--src/screen_world.c56
-rw-r--r--src/server.c364
-rw-r--r--src/serverConfigFile.c86
-rw-r--r--src/tux.c8
-rw-r--r--src/udp.c3
-rw-r--r--src/zal_proto.c692
37 files changed, 1736 insertions, 467 deletions
diff --git a/config.h b/config.h
index 5f78ee3..6dbad55 100644
--- a/config.h
+++ b/config.h
@@ -6,7 +6,7 @@
#define DEBUG_CLIENT_RECV
*/
-#define TUXANCI_NG_VERSION "svn38"
+#define TUXANCI_NG_VERSION "svn39"
#define DESTDIR "/usr/local/"
#define SUPPORT_NET_SDL_UDP
diff --git a/data/keytable.conf b/data/keytable.conf
new file mode 100755
index 0000000..1e349f4
--- /dev/null
+++ b/data/keytable.conf
@@ -0,0 +1,289 @@
+
+#********************************************
+
+#
+# Key table :
+#
+
+#********************************************
+
+keycode SDLK_FIRST = 0
+keycode SDLK_BACKSPACE = 8
+keycode SDLK_TAB = 9
+keycode SDLK_CLEAR = 12
+keycode SDLK_RETURN = 13
+keycode SDLK_PAUSE = 19
+keycode SDLK_ESCAPE = 27
+keycode SDLK_SPACE = 32
+keycode SDLK_EXCLAIM = 33
+keycode SDLK_QUOTEDBL = 34
+keycode SDLK_HASH = 35
+keycode SDLK_DOLLAR = 36
+keycode SDLK_AMPERSAND = 38
+keycode SDLK_QUOTE = 39
+keycode SDLK_LEFTPAREN = 40
+keycode SDLK_RIGHTPAREN = 41
+keycode SDLK_ASTERISK = 42
+keycode SDLK_PLUS = 43
+keycode SDLK_COMMA = 44
+keycode SDLK_MINUS = 45
+keycode SDLK_PERIOD = 46
+keycode SDLK_SLASH = 47
+
+#********************************************
+
+keycode SDLK_0 = 48
+keycode SDLK_1 = 49
+keycode SDLK_2 = 50
+keycode SDLK_3 = 51
+keycode SDLK_4 = 52
+keycode SDLK_5 = 53
+keycode SDLK_6 = 54
+keycode SDLK_7 = 55
+keycode SDLK_8 = 56
+keycode SDLK_9 = 57
+
+#********************************************
+
+keycode SDLK_COLON = 58
+keycode SDLK_SEMICOLON = 59
+keycode SDLK_LESS = 60
+keycode SDLK_EQUALS = 61
+keycode SDLK_GREATER = 62
+keycode SDLK_QUESTION = 63
+keycode SDLK_AT = 64
+
+#********************************************
+
+keycode SDLK_LEFTBRACKET = 91
+keycode SDLK_BACKSLASH = 92
+keycode SDLK_RIGHTBRACKET = 93
+keycode SDLK_CARET = 94
+keycode SDLK_UNDERSCORE = 95
+keycode SDLK_BACKQUOTE = 96
+
+#********************************************
+
+keycode SDLK_a = 97
+keycode SDLK_b = 98
+keycode SDLK_c = 99
+keycode SDLK_d = 100
+keycode SDLK_e = 101
+keycode SDLK_f = 102
+keycode SDLK_g = 103
+keycode SDLK_h = 104
+keycode SDLK_i = 105
+keycode SDLK_j = 106
+keycode SDLK_k = 107
+keycode SDLK_l = 108
+keycode SDLK_m = 1
+keycode SDLK_n = 110
+keycode SDLK_o = 111
+keycode SDLK_p = 112
+keycode SDLK_q = 113
+keycode SDLK_r = 114
+keycode SDLK_s = 115
+keycode SDLK_t = 116
+keycode SDLK_u = 117
+keycode SDLK_v = 118
+keycode SDLK_w = 119
+keycode SDLK_x = 120
+keycode SDLK_y = 121
+keycode SDLK_z = 122
+keycode SDLK_DELETE = 127
+
+#********************************************
+
+keycode SDLK_WORLD_0 = 160
+keycode SDLK_WORLD_1 = 161
+keycode SDLK_WORLD_2 = 162
+keycode SDLK_WORLD_3 = 163
+keycode SDLK_WORLD_4 = 164
+keycode SDLK_WORLD_5 = 165
+keycode SDLK_WORLD_6 = 166
+keycode SDLK_WORLD_7 = 167
+keycode SDLK_WORLD_8 = 168
+keycode SDLK_WORLD_9 = 169
+keycode SDLK_WORLD_10 = 170
+keycode SDLK_WORLD_11 = 171
+keycode SDLK_WORLD_12 = 172
+keycode SDLK_WORLD_13 = 173
+keycode SDLK_WORLD_14 = 174
+keycode SDLK_WORLD_15 = 175
+keycode SDLK_WORLD_16 = 176
+keycode SDLK_WORLD_17 = 177
+keycode SDLK_WORLD_18 = 178
+keycode SDLK_WORLD_19 = 179
+keycode SDLK_WORLD_20 = 180
+keycode SDLK_WORLD_21 = 181
+keycode SDLK_WORLD_22 = 182
+keycode SDLK_WORLD_23 = 183
+keycode SDLK_WORLD_24 = 184
+keycode SDLK_WORLD_25 = 185
+keycode SDLK_WORLD_26 = 186
+keycode SDLK_WORLD_27 = 187
+keycode SDLK_WORLD_28 = 188
+keycode SDLK_WORLD_29 = 189
+keycode SDLK_WORLD_30 = 190
+keycode SDLK_WORLD_31 = 191
+keycode SDLK_WORLD_32 = 192
+keycode SDLK_WORLD_33 = 193
+keycode SDLK_WORLD_34 = 194
+keycode SDLK_WORLD_35 = 195
+keycode SDLK_WORLD_36 = 196
+keycode SDLK_WORLD_37 = 197
+keycode SDLK_WORLD_38 = 198
+keycode SDLK_WORLD_39 = 199
+keycode SDLK_WORLD_40 = 200
+keycode SDLK_WORLD_41 = 201
+keycode SDLK_WORLD_42 = 202
+keycode SDLK_WORLD_43 = 203
+keycode SDLK_WORLD_44 = 204
+keycode SDLK_WORLD_45 = 205
+keycode SDLK_WORLD_46 = 206
+keycode SDLK_WORLD_47 = 207
+keycode SDLK_WORLD_48 = 208
+keycode SDLK_WORLD_49 = 2
+keycode SDLK_WORLD_50 = 210
+keycode SDLK_WORLD_51 = 211
+keycode SDLK_WORLD_52 = 212
+keycode SDLK_WORLD_53 = 213
+keycode SDLK_WORLD_54 = 214
+keycode SDLK_WORLD_55 = 215
+keycode SDLK_WORLD_56 = 216
+keycode SDLK_WORLD_57 = 217
+keycode SDLK_WORLD_58 = 218
+keycode SDLK_WORLD_59 = 219
+keycode SDLK_WORLD_60 = 220
+keycode SDLK_WORLD_61 = 221
+keycode SDLK_WORLD_62 = 222
+keycode SDLK_WORLD_63 = 223
+keycode SDLK_WORLD_64 = 224
+keycode SDLK_WORLD_65 = 225
+keycode SDLK_WORLD_66 = 226
+keycode SDLK_WORLD_67 = 227
+keycode SDLK_WORLD_68 = 228
+keycode SDLK_WORLD_69 = 229
+keycode SDLK_WORLD_70 = 230
+keycode SDLK_WORLD_71 = 231
+keycode SDLK_WORLD_72 = 232
+keycode SDLK_WORLD_73 = 233
+keycode SDLK_WORLD_74 = 234
+keycode SDLK_WORLD_75 = 235
+keycode SDLK_WORLD_76 = 236
+keycode SDLK_WORLD_77 = 237
+keycode SDLK_WORLD_78 = 238
+keycode SDLK_WORLD_79 = 239
+keycode SDLK_WORLD_80 = 240
+keycode SDLK_WORLD_81 = 241
+keycode SDLK_WORLD_82 = 242
+keycode SDLK_WORLD_83 = 243
+keycode SDLK_WORLD_84 = 244
+keycode SDLK_WORLD_85 = 245
+keycode SDLK_WORLD_86 = 246
+keycode SDLK_WORLD_87 = 247
+keycode SDLK_WORLD_88 = 248
+keycode SDLK_WORLD_89 = 249
+keycode SDLK_WORLD_90 = 250
+keycode SDLK_WORLD_91 = 251
+keycode SDLK_WORLD_92 = 252
+keycode SDLK_WORLD_93 = 253
+keycode SDLK_WORLD_94 = 254
+keycode SDLK_WORLD_95 = 255
+
+#********************************************
+
+keycode SDLK_KP0 = 256
+keycode SDLK_KP1 = 257
+keycode SDLK_KP2 = 258
+keycode SDLK_KP3 = 259
+keycode SDLK_KP4 = 260
+keycode SDLK_KP5 = 261
+keycode SDLK_KP6 = 262
+keycode SDLK_KP7 = 263
+keycode SDLK_KP8 = 264
+keycode SDLK_KP9 = 265
+keycode SDLK_KP_PERIOD = 266
+keycode SDLK_KP_DIVIDE = 267
+keycode SDLK_KP_MULTIPLY = 268
+keycode SDLK_KP_MINUS = 269
+keycode SDLK_KP_PLUS = 270
+keycode SDLK_KP_ENTER = 271
+keycode SDLK_KP_EQUALS = 272
+
+#********************************************
+
+keycode SDLK_UP = 273
+keycode SDLK_DOWN = 274
+keycode SDLK_RIGHT = 275
+keycode SDLK_LEFT = 276
+keycode SDLK_INSERT = 277
+keycode SDLK_HOME = 278
+keycode SDLK_END = 279
+keycode SDLK_PAGEUP = 280
+keycode SDLK_PAGEDOWN = 281
+
+#********************************************
+
+keycode SDLK_F1 = 282
+keycode SDLK_F2 = 283
+keycode SDLK_F3 = 284
+keycode SDLK_F4 = 285
+keycode SDLK_F5 = 286
+keycode SDLK_F6 = 287
+keycode SDLK_F7 = 288
+keycode SDLK_F8 = 289
+keycode SDLK_F9 = 290
+keycode SDLK_F10 = 291
+keycode SDLK_F11 = 292
+keycode SDLK_F12 = 293
+keycode SDLK_F13 = 294
+keycode SDLK_F14 = 295
+keycode SDLK_F15 = 296
+
+#********************************************
+
+keycode SDLK_NUMLOCK = 300
+keycode SDLK_CAPSLOCK = 301
+keycode SDLK_SCROLLOCK = 302
+keycode SDLK_RSHIFT = 303
+keycode SDLK_LSHIFT = 304
+keycode SDLK_RCTRL = 305
+keycode SDLK_LCTRL = 306
+keycode SDLK_RALT = 307
+keycode SDLK_LALT = 308
+keycode SDLK_RMETA = 3
+keycode SDLK_LMETA = 310
+keycode SDLK_LSUPER = 311
+keycode SDLK_RSUPER = 312
+keycode SDLK_MODE = 313
+keycode SDLK_COMPOSE = 314
+
+#********************************************
+
+keycode SDLK_HELP = 315
+keycode SDLK_PRINT = 316
+keycode SDLK_SYSREQ = 317
+keycode SDLK_BREAK = 318
+keycode SDLK_MENU = 319
+keycode SDLK_POWER = 320
+keycode SDLK_EURO = 321
+keycode SDLK_UNDO = 322
+
+#********************************************
+
+TUX_RIGHT_MOVE_UP = SDLK_KP8 SDLK_UP
+TUX_RIGHT_MOVE_RIGHT = SDLK_KP6 SDLK_RIGHT
+TUX_RIGHT_MOVE_LEFT = SDLK_KP4 SDLK_LEFT
+TUX_RIGHT_MOVE_DOWN = SDLK_KP5 SDLK_DOWN
+TUX_RIGHT_SHOOT = SDLK_KP0
+TUX_RIGHT_SWITCH_WEAPON = SDLK_KP1
+
+TUX_LEFT_MOVE_UP = SDLK_w
+TUX_LEFT_MOVE_RIGHT = SDLK_d
+TUX_LEFT_MOVE_LEFT = SDLK_a
+TUX_LEFT_MOVE_DOWN = SDLK_s
+TUX_LEFT_SHOOT = SDLK_q
+TUX_LEFT_SWITCH_WEAPON = SDLK_TAB
+
+#********************************************
diff --git a/data/lang.en b/data/lang.en
new file mode 100644
index 0000000..abb4c8d
--- /dev/null
+++ b/data/lang.en
@@ -0,0 +1,30 @@
+
+# generally strings
+
+OK Ok
+BACK Back
+NEXT Next
+
+#main menu
+
+PLAY Play
+SETTING Setting
+TABLE Table
+CREDITS Credits
+END End
+
+# setting menu
+
+COUNT_ROUND Count Round
+NAME_PLAYER1 Name Player1 :
+NAME_PLAYER2 Name Player2 :
+MUSIC Music :
+SOUND Sound :
+
+# setting game type
+
+NONE none
+SERVER server
+CLIENT client
+IP_ADDR IP address :
+NET_PORT network port :
diff --git a/data/lang.sk b/data/lang.sk
new file mode 100644
index 0000000..f3bdd84
--- /dev/null
+++ b/data/lang.sk
@@ -0,0 +1,30 @@
+
+# generally strings
+
+OK Ok
+BACK Späť
+NEXT Ďalej
+
+#main menu
+
+PLAY Hrať
+SETTING Nastavenia
+TABLE Tabuľka
+CREDITS Autori
+END Koniec
+
+# setting menu
+
+COUNT_ROUND Počet kôl
+NAME_PLAYER1 Meno Hraca1 :
+NAME_PLAYER2 Meno Hraca2 :
+MUSIC Hudba :
+SOUND Zvuk :
+
+# setting game type
+
+NONE žiadne
+SERVER server
+CLIENT client
+IP_ADDR IP adresa :
+NET_PORT sieotvy port :
diff --git a/include/keytable.h b/include/keytable.h
new file mode 100644
index 0000000..80ca258
--- /dev/null
+++ b/include/keytable.h
@@ -0,0 +1,27 @@
+
+#ifndef KEYTABLE_H
+
+#define KEYTABLE_H
+
+#define KEY_LENGTH 12
+
+#define KEY_TUX_RIGHT_MOVE_UP 0
+#define KEY_TUX_RIGHT_MOVE_RIGHT 1
+#define KEY_TUX_RIGHT_MOVE_LEFT 2
+#define KEY_TUX_RIGHT_MOVE_DOWN 3
+#define KEY_TUX_RIGHT_SHOOT 4
+#define KEY_TUX_RIGHT_SWITCH_WEAPON 5
+#define KEY_TUX_LEFT_MOVE_UP 6
+#define KEY_TUX_LEFT_MOVE_RIGHT 7
+#define KEY_TUX_LEFT_MOVE_LEFT 8
+#define KEY_TUX_LEFT_MOVE_DOWN 9
+#define KEY_TUX_LEFT_SHOOT 10
+#define KEY_TUX_LEFT_SWITCH_WEAPON 11
+
+extern void initKeyTable();
+extern int getKey(int n);
+extern void quitKeyTable();
+
+#endif
+
+
diff --git a/include/language.h b/include/language.h
new file mode 100644
index 0000000..03f13e7
--- /dev/null
+++ b/include/language.h
@@ -0,0 +1,10 @@
+
+#ifndef LANGUAGE_H
+
+#define LANGUAGE_H
+
+extern void initLanguage();
+extern char* getMyText(char *key);
+extern void quitLanguage();
+
+#endif
diff --git a/include/myTimer.h b/include/myTimer.h
index 21738bb..97c2f65 100644
--- a/include/myTimer.h
+++ b/include/myTimer.h
@@ -4,20 +4,27 @@
#define MY_TIME_H
#include "main.h"
+#include "list.h"
#define my_time_t unsigned int
+#define TIMER_ONE 0
+#define TIMER_PERIODIC 1
+
typedef struct my_timer_struct
{
unsigned int id;
void (*fce)(void *p);
void *arg;
+ int type;
+ my_time_t createTime;
my_time_t time;
} my_timer_t;
extern list_t* newTimer();
+extern void restartTimer();
extern my_time_t getMyTime();
-extern int addTimer(list_t *listTimer, void (*fce)(void *p), void *arg, my_time_t my_time);
+extern int addTaskToTimer(list_t *listTimer, int type, void (*fce)(void *p), void *arg, my_time_t my_time);
extern void eventTimer(list_t *listTimer);
extern void delTimer(list_t *listTimer, int id);
extern void destroyTimer(list_t *listTimer);
diff --git a/include/proto.h b/include/proto.h
index e083c6c..bd5b2c0 100644
--- a/include/proto.h
+++ b/include/proto.h
@@ -75,12 +75,12 @@ extern void proto_send_shot_server(int type, client_t *client, shot_t *p);
extern void proto_recv_shot_client(char *msg);
extern void proto_send_ping_client();
extern void proto_recv_ping_server(client_t *client, char *msg);
-extern void proto_send_end_client();
-extern void proto_recv_end_server(client_t *client, char *msg);
extern void proto_send_ping_server(int type, client_t *client);
extern void proto_recv_ping_client(char *msg);
extern void proto_send_end_server(int type, client_t *client);
extern void proto_recv_end_client(char *msg);
+extern void proto_send_end_client();
+extern void proto_recv_end_server(client_t *client, char *msg);
#endif
diff --git a/include/screen_world.h b/include/screen_world.h
index c9a46e6..955e0fc 100644
--- a/include/screen_world.h
+++ b/include/screen_world.h
@@ -4,15 +4,18 @@
#define SCREEN_WORLD_H
#include "main.h"
+#include "myTimer.h"
#include "tux.h"
#include "arena.h"
#define TIMER_END_ARENA 5000
#define WORLD_COUNT_ROUND_UNLIMITED -1
+#define LAG_SERVER_UNKNOWN -1
extern bool_t isScreenWorldInicialized();
extern void initWorld();
extern void setWorldArena(int id);
+extern void setLagServer(my_time_t lag);
extern void countRoundInc();
extern void setWorldEnd();
extern void setMaxCountRound(int n);
diff --git a/include/server.h b/include/server.h
index 066c170..bf7a1e9 100644
--- a/include/server.h
+++ b/include/server.h
@@ -12,39 +12,29 @@
#include "interface.h"
#endif
-#ifdef SUPPORT_NET_UNIX_TCP
-#include "tcp.h"
+
+#ifdef SUPPORT_NET_SDL_UDP
+
+#include "sdl_udp.h"
+
#endif
#ifdef SUPPORT_NET_UNIX_UDP
#include "udp.h"
-#define SERVER_TIMEOUT 5000
-#define SERVER_TIME_SYNC 1000
-#define SERVER_MAX_CLIENTS 100
-
#endif
-#ifdef SUPPORT_NET_SDL_UDP
-
-#include "sdl_udp.h"
-
#define SERVER_TIMEOUT 5000
#define SERVER_TIME_SYNC 1000
+#define SERVER_TIME_PING 1000
#define SERVER_MAX_CLIENTS 100
-#endif
-
#define SERVER_INDEX_ROOT_TUX 0
typedef struct client_struct
{
-#ifdef SUPPORT_NET_UNIX_TCP
- sock_tcp_t *socket_tcp;
-#endif
-
#ifdef SUPPORT_NET_UNIX_UDP
sock_udp_t *socket_udp;
my_time_t lastPing;
@@ -59,12 +49,6 @@ typedef struct client_struct
buffer_t *buffer;
} client_t;
-#ifdef SUPPORT_NET_UNIX_TCP
-extern int initTcpServer(int port);
-extern client_t* newTcpClient(sock_tcp_t *sock_tcp);
-extern void selectServerTcpSocket();
-extern void quitTcpServer();
-#endif
#ifdef SUPPORT_NET_UNIX_UDP
extern int initUdpServer(char *ip, int port);
@@ -91,7 +75,7 @@ extern void sendAllClientBut(char *msg, client_t *p);
extern void sendAllClient(char *msg);
extern void eventClientListBuffer();
extern void sendInfoCreateClient(client_t *client);
-extern void eventPeriodicSyncClient();
+extern void eventServer();
#endif
diff --git a/include/serverConfigFile.h b/include/serverConfigFile.h
new file mode 100644
index 0000000..d016807
--- /dev/null
+++ b/include/serverConfigFile.h
@@ -0,0 +1,11 @@
+
+
+#ifndef SERVER_CONFIG_FILE_H
+
+#define SERVER_CONFIG_FILE_H
+
+extern void initServerConfigFile();
+extern char* getServerConfigFileValue(char *env, char *s);
+extern void quitServerConfigFile();
+
+#endif
diff --git a/include/tux.h b/include/tux.h
index 3cb6699..8767afa 100644
--- a/include/tux.h
+++ b/include/tux.h
@@ -12,6 +12,8 @@
#define TUX_MAX_ANIMATION_FRAME 10
#define TUX_KEY 1
+#define TUX_LOCATE_UNKNOWN -1
+
#define TUX_MAX_PICKUP 50
#define TUX_MAX_BONUS 500
diff --git a/server.conf b/server.conf
new file mode 100644
index 0000000..0d65729
--- /dev/null
+++ b/server.conf
@@ -0,0 +1,4 @@
+IP 0.0.0.0
+PORT 2200
+MAX_CLIENTS 32
+ARENA FAGN
diff --git a/src/Makefile b/src/Makefile
index 4c2e4ef..990b752 100755
--- a/src/Makefile
+++ b/src/Makefile
@@ -14,7 +14,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
+ sdl_udp.o proto.o server.o client.o term.o keytable.o language.o
tuxanci-ng: $(FILES)
$(CC) $(CFLAGS) $(LIBS) -o tuxanci-ng $(FILES)
@@ -169,5 +169,10 @@ screen_table.o: screen_table.c ../include/screen_table.h
term.o: term.c ../include/term.h
$(CC) $(CFLAGS) -o term.o -c term.c
+keytable.o: keytable.c ../include/keytable.h
+ $(CC) $(CFLAGS) -o keytable.o -c keytable.c
+
+language.o: language.c ../include/language.h
+ $(CC) $(CFLAGS) -o language.o -c language.c
clean:
rm -rf *.o *.c~ ../include/*.h~ Makefile~ tuxanci-ng
diff --git a/src/Makefile-publicServer b/src/Makefile-publicServer
index a9fc788..0d589e4 100755
--- a/src/Makefile-publicServer
+++ b/src/Makefile-publicServer
@@ -7,80 +7,85 @@ DESTDIR:=/usr/local
CFLAGS = -g -O0 -DPUBLIC_SERVER -DSUPPORT_NET_UNIX_UDP -I../include -Wall
#CFLAGS = -O2 -DDESTDIR=\"$(DESTDIR)\" `sdl-config --cflags` -I../include -Wall
+BUILD_DIR = ../build-server/
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
+ udp.o proto.o server.o publicServer.o net_multiplayer.o serverConfigFile.o
-publicserver: $(FILES)
- $(CC) $(CFLAGS) $(LIBS) -o publicserver $(FILES)
+$(BUILD_DIR)publicserver: $(FILES)
+ $(CC) $(CFLAGS) $(LIBS) -o $(BUILD_DIR)publicserver $(BUILD_DIR)*.o
publicServer.o: publicServer.c
- $(CC) $(CFLAGS) -o publicServer.o -c publicServer.c
+ $(CC) $(CFLAGS) -o $(BUILD_DIR)publicServer.o -c publicServer.c
list.o: list.c ../include/list.h
- $(CC) $(CFLAGS) -o list.o -c list.c
+ $(CC) $(CFLAGS) -o $(BUILD_DIR)list.o -c list.c
director.o: director.c ../include/director.h
- $(CC) $(CFLAGS) -o director.o -c director.c
+ $(CC) $(CFLAGS) -o $(BUILD_DIR)director.o -c director.c
configFile.o: configFile.c ../include/configFile.h
- $(CC) $(CFLAGS) -o configFile.o -c configFile.c
+ $(CC) $(CFLAGS) -o $(BUILD_DIR)configFile.o -c configFile.c
tux.o: tux.c ../include/tux.h
- $(CC) $(CFLAGS) -o tux.o -c tux.c
+ $(CC) $(CFLAGS) -o $(BUILD_DIR)tux.o -c tux.c
wall.o: wall.c ../include/wall.h
- $(CC) $(CFLAGS) -o wall.o -c wall.c
+ $(CC) $(CFLAGS) -o $(BUILD_DIR)wall.o -c wall.c
shot.o: shot.c ../include/shot.h
- $(CC) $(CFLAGS) -o shot.o -c shot.c
+ $(CC) $(CFLAGS) -o $(BUILD_DIR)shot.o -c shot.c
myTimer.o: myTimer.c ../include/myTimer.h
- $(CC) $(CFLAGS) -o myTimer.o -c myTimer.c
+ $(CC) $(CFLAGS) -o $(BUILD_DIR)myTimer.o -c myTimer.c
buffer.o: buffer.c ../include/buffer.h
- $(CC) $(CFLAGS) -o buffer.o -c buffer.c
+ $(CC) $(CFLAGS) -o $(BUILD_DIR)buffer.o -c buffer.c
tcp.o: tcp.c ../include/tcp.h
- $(CC) $(CFLAGS) -o tcp.o -c tcp.c
+ $(CC) $(CFLAGS) -o $(BUILD_DIR)tcp.o -c tcp.c
udp.o: udp.c ../include/udp.h
- $(CC) $(CFLAGS) -o udp.o -c udp.c
+ $(CC) $(CFLAGS) -o $(BUILD_DIR)udp.o -c udp.c
proto.o: proto.c ../include/proto.h
- $(CC) $(CFLAGS) -o proto.o -c proto.c
+ $(CC) $(CFLAGS) -o $(BUILD_DIR)proto.o -c proto.c
server.o: server.c ../include/server.h
- $(CC) $(CFLAGS) -o server.o -c server.c
+ $(CC) $(CFLAGS) -o $(BUILD_DIR)server.o -c server.c
net_multiplayer.o: net_multiplayer.c ../include/net_multiplayer.h
- $(CC) $(CFLAGS) -o net_multiplayer.o -c net_multiplayer.c
+ $(CC) $(CFLAGS) -o $(BUILD_DIR)net_multiplayer.o -c net_multiplayer.c
dynamicInt.o: dynamicInt.c ../include/dynamicInt.h
- $(CC) $(CFLAGS) -o dynamicInt.o -c dynamicInt.c
+ $(CC) $(CFLAGS) -o $(BUILD_DIR)dynamicInt.o -c dynamicInt.c
arena.o: arena.c ../include/arena.h
- $(CC) $(CFLAGS) -o arena.o -c arena.c
+ $(CC) $(CFLAGS) -o $(BUILD_DIR)arena.o -c arena.c
textFile.o: textFile.c ../include/textFile.h
- $(CC) $(CFLAGS) -o textFile.o -c textFile.c
+ $(CC) $(CFLAGS) -o $(BUILD_DIR)textFile.o -c textFile.c
arenaFile.o: arenaFile.c ../include/arenaFile.h
- $(CC) $(CFLAGS) -o arenaFile.o -c arenaFile.c
+ $(CC) $(CFLAGS) -o $(BUILD_DIR)arenaFile.o -c arenaFile.c
gun.o: gun.c ../include/gun.h
- $(CC) $(CFLAGS) -o gun.o -c gun.c
+ $(CC) $(CFLAGS) -o $(BUILD_DIR)gun.o -c gun.c
item.o: item.c ../include/item.h
- $(CC) $(CFLAGS) -o item.o -c item.c
+ $(CC) $(CFLAGS) -o $(BUILD_DIR)item.o -c item.c
teleport.o: teleport.c ../include/teleport.h
- $(CC) $(CFLAGS) -o teleport.o -c teleport.c
+ $(CC) $(CFLAGS) -o $(BUILD_DIR)teleport.o -c teleport.c
pipe.o: pipe.c ../include/pipe.h
- $(CC) $(CFLAGS) -o pipe.o -c pipe.c
+ $(CC) $(CFLAGS) -o $(BUILD_DIR)pipe.o -c pipe.c
+
+serverConfigFile.o: serverConfigFile.c ../include/serverConfigFile.h
+ $(CC) $(CFLAGS) -o $(BUILD_DIR)serverConfigFile.o -c serverConfigFile.c
+
clean:
- rm -rf *.o *.c~ ../include*.h~ Makefile-publicServer~ publicserver
+ rm -rf $(BUILD_DIR)*.o *.c~ ../include*.h~ Makefile-publicServer~ $(BUILD_DIR)publicserver
diff --git a/src/gun.c b/src/gun.c
index 9433b4c..fbbeeb3 100644
--- a/src/gun.c
+++ b/src/gun.c
@@ -1,4 +1,4 @@
-
+//
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
@@ -181,7 +181,7 @@ static void shotInGunTommy(tux_t *tux)
for( i = 0 ; i < 10 ; i++ )
{
- addTimer(getCurrentArena()->listTimer, timer_addShotTimer, newInt(tux->id), i * 100 );
+ addTaskToTimer(getCurrentArena()->listTimer, TIMER_ONE, timer_addShotTimer, newInt(tux->id), i * 100 );
}
}
@@ -212,7 +212,7 @@ static void shotInGunLasser(tux_t *tux)
for( i = 0 ; i < 50 ; i++ )
{
- addTimer(getCurrentArena()->listTimer, timer_addLaserTimer, newInt(tux->id), i * 10 );
+ addTaskToTimer(getCurrentArena()->listTimer, TIMER_ONE, timer_addLaserTimer, newInt(tux->id), i * 10 );
}
}
diff --git a/src/interface.c b/src/interface.c
index 2353bed..d629c5b 100755
--- a/src/interface.c
+++ b/src/interface.c
@@ -4,6 +4,7 @@
#include "main.h"
#include "interface.h"
#include "screen.h"
+#include "myTimer.h"
//povrch okna
static SDL_Surface *screen;
@@ -141,6 +142,7 @@ int eventAction()
{
SDL_Event event;
+
while(SDL_WaitEvent(&event))
{
switch(event.type)
diff --git a/src/item.c b/src/item.c
index a84b97b..22691e6 100644
--- a/src/item.c
+++ b/src/item.c
@@ -372,7 +372,11 @@ void eventConflictShotWithItem(list_t *listItem, list_t *listShot)
conflictSpace(thisShot->x, thisShot->y, thisShot->w, thisShot->h,
thisItem->x, thisItem->y, thisItem->w, thisItem->h) )
{
- proto_send_item_server(PROTO_SEND_ALL, NULL, NULL, thisItem);
+ if( getNetTypeGame() == NET_GAME_TYPE_SERVER )
+ {
+ proto_send_item_server(PROTO_SEND_ALL, NULL, NULL, thisItem);
+ }
+
mineExplosion(listItem, thisItem);
j--;
}
@@ -403,6 +407,7 @@ static void eventTuxIsDeadWithItem(tux_t *tux, item_t *item)
if( tux->bonus == BONUS_TELEPORT )
{
tuxTeleport(tux);
+ return;
}
if( item->author != NULL && item->author != tux )
diff --git a/src/keytable.c b/src/keytable.c
new file mode 100644
index 0000000..d0b76f2
--- /dev/null
+++ b/src/keytable.c
@@ -0,0 +1,121 @@
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+
+#include "main.h"
+#include "list.h"
+#include "homeDirector.h"
+#include "textFile.h"
+#include "configFile.h"
+#include "keytable.h"
+
+static textFile_t *keytableFile;
+static textFile_t *keycontrolFile;
+static int keytable[KEY_LENGTH];
+
+static int getKeyCode(char *s)
+{
+ char str[STR_SIZE];
+ char *find;
+ int i;
+
+ for( i = 0 ; i < keytableFile->text->count ; i++ )
+ {
+ char *line;
+ line = (char *) (keytableFile->text->list[i]);
+
+ if( ( find = strstr(line, str) ) != NULL )
+ {
+ int ret;
+ ret = atoi( strchr(line, '=')+1 );
+ return ret;
+ }
+ }
+
+ return -1;
+}
+
+void initKeyTable()
+{
+ char path[STR_PATH_SIZE];
+ char val[STR_SIZE];
+
+ sprintf(path, PATH_DATA "keytable.conf");
+ keytableFile = loadTextFile(path);
+
+ if( keytableFile == NULL )
+ {
+ fprintf(stderr, "Don't load %s\n", path);
+ return;
+ }
+
+ sprintf(path, "%s/keycontrol.conf", getHomeDirector());
+ keycontrolFile = loadTextFile(path);
+
+ if( keycontrolFile == NULL )
+ {
+ fprintf(stderr, "Don't load %s\n", path);
+ fprintf(stderr, "I create %s\n", path);
+
+ keycontrolFile = newTextFile(path);
+ }
+
+ if( keycontrolFile == NULL )
+ {
+ fprintf(stderr, "Don't create %s\n", path);
+ return;
+ }
+
+ loadValueFromConfigFile(keycontrolFile, "TUX_RIGHT_MOVE_UP", val, STR_SIZE, "SDLK_UP");
+ keytable[ KEY_TUX_RIGHT_MOVE_UP ] = getKeyCode(val);
+
+ loadValueFromConfigFile(keycontrolFile, "TUX_RIGHT_MOVE_RIGHT", val, STR_SIZE, "SDLK_RIGHT");
+ keytable[ KEY_TUX_RIGHT_MOVE_RIGHT ] = getKeyCode(val);
+
+ loadValueFromConfigFile(keycontrolFile, "TUX_RIGHT_MOVE_LEFT", val, STR_SIZE, "SDLK_LEFT");
+ keytable[ KEY_TUX_RIGHT_MOVE_LEFT ] = getKeyCode(val);
+
+ loadValueFromConfigFile(keycontrolFile, "TUX_RIGHT_MOVE_DOWN", val, STR_SIZE, "SDLK_DOWN");
+ keytable[ KEY_TUX_RIGHT_MOVE_DOWN ] = getKeyCode(val);
+
+ loadValueFromConfigFile(keycontrolFile, "TUX_RIGHT_SHOOT", val, STR_SIZE, "SDLK_KP0");
+ keytable[ KEY_TUX_RIGHT_SHOOT ] = getKeyCode(val);
+
+ loadValueFromConfigFile(keycontrolFile, "TUX_RIGHT_SWITCH_WEAPON", val, STR_SIZE, "SDLK_KP1");
+ keytable[ KEY_TUX_RIGHT_SWITCH_WEAPON] = getKeyCode(val);
+
+ loadValueFromConfigFile(keycontrolFile, "TUX_LEFT_MOVE_UP", val, STR_SIZE, "SDLK_w");
+ keytable[ KEY_TUX_LEFT_MOVE_UP ] = getKeyCode(val);
+
+ loadValueFromConfigFile(keycontrolFile, "TUX_LEFT_MOVE_RIGHT", val, STR_SIZE, "SDLK_d");
+ keytable[ KEY_TUX_LEFT_MOVE_RIGHT ] = getKeyCode(val);
+
+ loadValueFromConfigFile(keycontrolFile, "TUX_LEFT_MOVE_LEFT", val, STR_SIZE, "SDLK_a");
+ keytable[ KEY_TUX_LEFT_MOVE_LEFT ] = getKeyCode(val);
+
+ loadValueFromConfigFile(keycontrolFile, "TUX_LEFT_MOVE_DOWN", val, STR_SIZE, "SDLK_s");
+ keytable[ KEY_TUX_LEFT_MOVE_DOWN ] = getKeyCode(val);
+
+ loadValueFromConfigFile(keycontrolFile, "TUX_LEFT_SHOOT", val, STR_SIZE, "SDLK_q");
+ keytable[ KEY_TUX_LEFT_SHOOT ] = getKeyCode(val);
+
+ loadValueFromConfigFile(keycontrolFile, "TUX_LEFT_SWITCH_WEAPON", val, STR_SIZE, "SDLK_TAB");
+ keytable[ KEY_TUX_LEFT_SWITCH_WEAPON ] = getKeyCode(val);
+
+ saveTextFile(keycontrolFile);
+}
+
+int getKey(int n)
+{
+ assert( n >= 0 && n < KEY_LENGTH );
+ return keytable[n];
+}
+
+void quitKeyTable()
+{
+ destroyTextFile(keycontrolFile);
+ destroyTextFile(keytableFile);
+}
+
diff --git a/src/language.c b/src/language.c
new file mode 100644
index 0000000..51a7d5b
--- /dev/null
+++ b/src/language.c
@@ -0,0 +1,83 @@
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+
+#include "main.h"
+#include "list.h"
+#include "homeDirector.h"
+#include "textFile.h"
+#include "language.h"
+
+static textFile_t *languageFile;
+
+void initLanguage()
+{
+ textFile_t *languageTypeFile;
+ char path[STR_PATH_SIZE];
+ char *lang;
+
+ sprintf(path, "%s/lang.conf", getHomeDirector());
+ languageTypeFile = loadTextFile(path);
+
+ if( languageTypeFile == NULL )
+ {
+ fprintf(stderr, "Don't load %s\n", path);
+ fprintf(stderr, "I create %s\n", path);
+
+ languageTypeFile = newTextFile(path);
+ addList(languageTypeFile->text, strdup("en") );
+ saveTextFile(languageTypeFile);
+ }
+
+ if( languageTypeFile == NULL )
+ {
+ fprintf(stderr, "Don't create %s\n", path);
+ return;
+ }
+
+ if( languageTypeFile->text->count == 0 )
+ {
+ fprintf(stderr, "File %s empty\n", path);
+ return;
+ }
+
+ lang = ((char *)languageTypeFile->text->list[0]);
+ printf("select lang %s\n", lang);
+
+ sprintf(path, PATH_DATA "lang.%s", lang);
+ languageFile = loadTextFile(path);
+
+ if( languageFile == NULL )
+ {
+ fprintf(stderr, "Don't load %s\n", path);
+ }
+}
+
+char* getMyText(char *key)
+{
+ int i;
+ int len;
+
+ len = strlen(key);
+
+ for( i = 0 ; i < languageFile->text->count ; i++ )
+ {
+ char *line;
+ line = (char *) (languageFile->text->list[i]);
+
+ if( strncmp(key, line, len) == 0 )
+ {
+ return line+strlen(key)+1;
+ }
+ }
+
+ return NULL;
+}
+
+void quitLanguage()
+{
+ destroyTextFile(languageFile);
+}
+
diff --git a/src/main.c b/src/main.c
index 27d89aa..e77f044 100644
--- a/src/main.c
+++ b/src/main.c
@@ -11,6 +11,8 @@
#ifndef PUBLIC_SERVER
#include "font.h"
+#include "keytable.h"
+#include "language.h"
#include "image.h"
#include "layer.h"
#include "interface.h"
@@ -46,6 +48,8 @@ static void init()
initSDL();
initLayer();
initFont("DejaVuSans.ttf", 16);
+ initKeyTable();
+ initLanguage();
initImageData();
initAudio();
initSound();
@@ -71,6 +75,8 @@ void quit()
quitSDL();
quitLayer();
quitFont();
+ quitKeyTable();
+ quitLanguage();
quitScreen();
quitArenaFile();
quitItem();
@@ -165,36 +171,12 @@ int main(int argc, char *argv[])
my_argc = argc;
my_argv = argv;
-#ifndef PUBLIC_SERVER
-
init();
setScreen("mainMenu");
eventSDL();
quit();
-#endif
-
-#ifdef PUBLIC_SERVER
-
- signal(SIGPIPE, SIG_IGN);
- signal(SIGINT, my_handler_quit);
- signal(SIGTERM, my_handler_quit);
- signal(SIGQUIT, my_handler_quit);
-
- if( initPublicServer() < 0 )
- {
- quitPublicServer();
- return -1;
- }
-
- while(1)
- {
- eventPublicServer();
- }
-
-#endif
return 0;
}
-
diff --git a/src/myTimer.c b/src/myTimer.c
index a9393dd..f9e46da 100644
--- a/src/myTimer.c
+++ b/src/myTimer.c
@@ -2,6 +2,7 @@
#include <time.h>
#include <assert.h>
#include <stdlib.h>
+#include <string.h>
#include <sys/time.h>
#include <signal.h>
@@ -14,20 +15,27 @@
#endif
+static struct timeval start = { .tv_sec = 0, .tv_usec = 0 };
+
list_t* newTimer()
{
return newList();
}
+void restartTimer()
+{
+ gettimeofday(&start, NULL);
+}
+
+
my_time_t getMyTime()
{
- static struct timeval start = { .tv_sec = 0, .tv_usec = 0 };
struct timeval now;
my_time_t ticks;
if( start.tv_sec == 0 && start.tv_usec == 0 )
{
- gettimeofday(&start, NULL);
+ restartTimer();
}
gettimeofday(&now, NULL);
@@ -37,22 +45,38 @@ my_time_t getMyTime()
return ticks;
}
-int addTimer(list_t *listTimer, void (*fce)(void *p), void *arg, my_time_t my_time)
+my_timer_t* newTimerItem(int type, void (*fce)(void *p), void *arg, my_time_t my_time)
{
static int new_id = 0;
my_timer_t *new;
- my_time_t currentTime;
-
- currentTime = getMyTime();
+
+ assert( fce != NULL );
new = malloc( sizeof(my_timer_t) );
- assert( new != NULL );
+ memset(new, 0, sizeof(my_timer_t));
new->id = new_id++;
+ new->type = type;
new->fce = fce;
new->arg = arg;
- new->time = currentTime + my_time;
+ new->createTime = getMyTime();
+ new->time = my_time;
+
+ return new;
+}
+
+static void destroyTimerItem(my_timer_t *p)
+{
+ assert( p != NULL );
+ free(p);
+}
+
+int addTaskToTimer(list_t *listTimer, int type, void (*fce)(void *p), void *arg, my_time_t my_time)
+{
+ my_timer_t *new;
+
+ new = newTimerItem(type, fce, arg, my_time);
addList(listTimer, new);
return new->id;
@@ -71,13 +95,29 @@ void eventTimer(list_t *listTimer)
thisTimer = (my_timer_t *)listTimer->list[i];
assert( thisTimer != NULL );
- if( currentTime >= thisTimer->time )
+ switch( thisTimer->type )
{
- thisTimer->fce(thisTimer->arg);
-
- delListItem(listTimer, i, free);
- i--;
+ case TIMER_ONE:
+ if( currentTime >= thisTimer->createTime + thisTimer->time )
+ {
+ thisTimer->fce(thisTimer->arg);
+
+ delListItem(listTimer, i, free);
+ i--;
+ }
+ break;
+ case TIMER_PERIODIC:
+ if( currentTime >= thisTimer->createTime + thisTimer->time )
+ {
+ thisTimer->fce(thisTimer->arg);
+ thisTimer->createTime = getMyTime();
+ }
+ break;
+ default :
+ assert( ! "bad timer type !" );
+ break;
}
+
}
}
@@ -104,5 +144,5 @@ void delTimer(list_t *listTimer, int id)
void destroyTimer(list_t *listTimer)
{
- destroyListItem(listTimer, free);
+ destroyListItem(listTimer, destroyTimerItem);
}
diff --git a/src/net_multiplayer.c b/src/net_multiplayer.c
index 87538c1..92e9504 100644
--- a/src/net_multiplayer.c
+++ b/src/net_multiplayer.c
@@ -1,4 +1,3 @@
-
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -42,14 +41,6 @@ int initNetMuliplayer(int type, char *ip, int port)
break;
case NET_GAME_TYPE_SERVER :
-#ifdef SUPPORT_NET_UNIX_TCP
- if( initTcpServer(port) != 0 )
- {
- fprintf(stderr, "Neomzem inicalizovat sietovu hru pre server !\n");
- netGameType = NET_GAME_TYPE_NONE;
- return -1;
- }
-#endif
#ifdef SUPPORT_NET_UNIX_UDP
if( initUdpServer(ip, port) != 0 )
{
@@ -70,14 +61,6 @@ int initNetMuliplayer(int type, char *ip, int port)
#ifndef PUBLIC_SERVER
case NET_GAME_TYPE_CLIENT :
-#ifdef SUPPORT_NET_UNIX_TCP
- if( initTcpClient(ip, port) != 0 )
- {
- fprintf(stderr, "Neomzem inicalizovat sietovu hru pre clienta !\n");
- netGameType = NET_GAME_TYPE_NONE;
- return -1;
- }
-#endif
#ifdef SUPPORT_NET_UNIX_UDP
if( initUdpClient(ip, port) != 0 )
{
@@ -112,28 +95,16 @@ void eventNetMultiplayer()
break;
case NET_GAME_TYPE_SERVER :
-#ifdef SUPPORT_NET_UNIX_TCP
- selectServerTcpSocket();
- eventClientListBuffer();
-#endif
#ifdef SUPPORT_NET_UNIX_UDP
- selectServerUdpSocket();
- eventClientListBuffer();
- eventPeriodicSyncClient();
+ eventServer();
#endif
#ifdef SUPPORT_NET_SDL_UDP
- selectServerSdlUdpSocket();
- eventClientListBuffer();
- eventPeriodicSyncClient();
+ eventServer();
#endif
break;
#ifndef PUBLIC_SERVER
case NET_GAME_TYPE_CLIENT :
-#ifdef SUPPORT_NET_UNIX_TCP
- selectClientTcpSocket();
- eventServerBuffer();
-#endif
#ifdef SUPPORT_NET_UNIX_UDP
eventPingServer();
selectClientUdpSocket();
@@ -160,9 +131,6 @@ void quitNetMultiplayer()
break;
case NET_GAME_TYPE_SERVER :
-#ifdef SUPPORT_NET_UNIX_TCP
- quitTcpServer();
-#endif
#ifdef SUPPORT_NET_UNIX_UDP
quitUdpServer();
#endif
@@ -173,9 +141,6 @@ void quitNetMultiplayer()
#ifndef PUBLIC_SERVER
case NET_GAME_TYPE_CLIENT :
-#ifdef SUPPORT_NET_UNIX_TCP
- quitTcpClient();
-#endif
#ifdef SUPPORT_NET_UNIX_UDP
quitUdpClient();
#endif
diff --git a/src/proto.c b/src/proto.c
index bb1a14c..a646d9c 100644
--- a/src/proto.c
+++ b/src/proto.c
@@ -271,8 +271,8 @@ void proto_send_newtux_server(int type, client_t *client, tux_t *tux)
if( tux->bonus == BONUS_HIDDEN )
{
- x = -100;
- y = -100;
+ x = TUX_LOCATE_UNKNOWN;
+ y = TUX_LOCATE_UNKNOWN;
}
else
{
@@ -607,7 +607,6 @@ void proto_recv_shot_client(char *msg)
if( shot->gun == GUN_LASSER )
{
- printf("transform\n");
transformOnlyLasser(shot);
}
@@ -621,7 +620,7 @@ void proto_recv_shot_client(char *msg)
void proto_send_ping_client()
{
char msg[STR_PROTO_SIZE];
- strcpy(msg, "ping\n");
+ sprintf(msg, "ping\n");
sendServer(msg);
}
@@ -631,29 +630,10 @@ void proto_recv_ping_server(client_t *client, char *msg)
{
}
-#ifndef PUBLIC_SERVER
-
-void proto_send_end_client()
-{
- char msg[STR_PROTO_SIZE];
- strcpy(msg, "end\n");
- sendServer(msg);
-}
-
-#endif
-
-void proto_recv_end_server(client_t *client, char *msg)
-{
- assert( msg != NULL );
- assert( client != NULL );
-
- client->status = NET_STATUS_ZOMBIE;
-}
-
void proto_send_ping_server(int type, client_t *client)
{
char msg[STR_PROTO_SIZE];
- strcpy(msg, "ping\n");
+ sprintf(msg, "ping\n");
proto_send(type, client, msg);
}
@@ -672,7 +652,6 @@ void proto_send_end_server(int type, client_t *client)
proto_send(type, client, msg);
}
-
#ifndef PUBLIC_SERVER
void proto_recv_end_client(char *msg)
@@ -683,3 +662,23 @@ void proto_recv_end_client(char *msg)
}
#endif
+
+#ifndef PUBLIC_SERVER
+
+void proto_send_end_client()
+{
+ char msg[STR_PROTO_SIZE];
+ strcpy(msg, "end\n");
+ sendServer(msg);
+}
+
+#endif
+
+void proto_recv_end_server(client_t *client, char *msg)
+{
+ assert( msg != NULL );
+ assert( client != NULL );
+
+ client->status = NET_STATUS_ZOMBIE;
+}
+
diff --git a/src/publicServer.c b/src/publicServer.c
index 1f74ce1..f1907e9 100644
--- a/src/publicServer.c
+++ b/src/publicServer.c
@@ -20,6 +20,7 @@
#include "proto.h"
#include "publicServer.h"
#include "net_multiplayer.h"
+#include "serverConfigFile.h"
static int arenaId;
static arena_t *arena;
@@ -32,14 +33,20 @@ void countRoundInc()
{
}
+static char *getSetting(char *env, char *param, char *default_val)
+{
+ return getParamElse(param, getServerConfigFileValue(env, default_val) );
+}
+
int initPublicServer()
{
initArenaFile();
initTux();
initItem();
initShot();
+ initServerConfigFile();
- arenaId = getArenaIdFormNetName( getParamElse("--arena", "FAGN") );
+ arenaId = getArenaIdFormNetName( getSetting("ARENA", "--arena", "FAGN") );
arena = getArena(arenaId);
setCurrentArena(arena);
@@ -47,13 +54,13 @@ int initPublicServer()
isSignalEnd = FALSE;
if( initNetMuliplayer(NET_GAME_TYPE_SERVER,
- getParamElse("--ip", "127.0.0.1") , atoi( getParamElse("--port", "2200") ) ) < 0 )
+ getSetting("IP", "--ip", "0.0.0.0") , atoi( getSetting("PORT", "--port", "2200") ) ) < 0 )
{
printf("Nemozem inicalizovat sietovy socket !\n");
return -1;
}
- setServerMaxClients( atoi( getParamElse("--maxclients", "100") ));
+ setServerMaxClients( atoi( getSetting("MAX_CLIENTS", "--maxclients", "100") ));
return 0;
}
@@ -107,6 +114,8 @@ void quitPublicServer()
quitNetMultiplayer();
destroyArena(arena);
quitArenaFile();
+ quitServerConfigFile();
+
exit(0);
}
@@ -119,14 +128,7 @@ char* getParam(char *s)
for( i = 1 ; i < my_argc ; i++ )
{
- //printf("%s %s\n", s, my_argv[i]);
-
- if( strlen(my_argv[i]) < len )
- {
- continue;
- }
-
- if( strncmp(s, my_argv[i], len) == 0 )
+ if( strstr(my_argv[i], s) == my_argv[i] )
{
return strchr(my_argv[i], '=')+1;
}
diff --git a/src/screen_choiceArena.c b/src/screen_choiceArena.c
index 50cd9c2..5bfaefd 100644
--- a/src/screen_choiceArena.c
+++ b/src/screen_choiceArena.c
@@ -3,6 +3,7 @@
#include <assert.h>
#include "main.h"
+#include "language.h"
#include "interface.h"
#include "list.h"
#include "screen.h"
@@ -121,8 +122,8 @@ void initScreenChoiceArena()
image = getImage(IMAGE_GROUP_BASE, "screen_main");
image_backgorund = newWidgetImage(0, 0, image);
- button_back = newWidgetButton("Back", 100, WINDOW_SIZE_Y-100, eventWidget);
- button_play = newWidgetButton("Play", WINDOW_SIZE_X-200, WINDOW_SIZE_Y-100, eventWidget);
+ button_back = newWidgetButton(getMyText("BACK"), 100, WINDOW_SIZE_Y-100, eventWidget);
+ button_play = newWidgetButton(getMyText("PLAY"), WINDOW_SIZE_X-200, WINDOW_SIZE_Y-100, eventWidget);
listWidgetButtonimage = newList();
choiceArenaId = 0;
diff --git a/src/screen_credits.c b/src/screen_credits.c
index 7cd44ea..b42cfe1 100644
--- a/src/screen_credits.c
+++ b/src/screen_credits.c
@@ -3,6 +3,7 @@
#include <assert.h>
#include "main.h"
+#include "language.h"
#include "interface.h"
#include "list.h"
#include "textFile.h"
@@ -93,7 +94,7 @@ void initScreenCredits()
image = getImage(IMAGE_GROUP_BASE, "screen_main");
image_backgorund = newWidgetImage(0, 0, image);
- button_back = newWidgetButton("Back", WINDOW_SIZE_X/2 -WIDGET_BUTTON_WIDTH/2, WINDOW_SIZE_Y-80, eventWidget);
+ button_back = newWidgetButton(getMyText("BACK"), WINDOW_SIZE_X/2 -WIDGET_BUTTON_WIDTH/2, WINDOW_SIZE_Y-80, eventWidget);
listWidgetLabel = newList();
textFile = loadTextFile(PATH_DATA SCREEN_CREDITS_FILE);
diff --git a/src/screen_gameType.c b/src/screen_gameType.c
index 126d7a6..d46924a 100644
--- a/src/screen_gameType.c
+++ b/src/screen_gameType.c
@@ -4,6 +4,7 @@
#include <assert.h>
#include "main.h"
+#include "language.h"
#include "interface.h"
#include "screen.h"
#include "image.h"
@@ -148,8 +149,8 @@ void initScreenGameType()
image = getImage(IMAGE_GROUP_BASE, "screen_main");
image_backgorund = newWidgetImage(0, 0, image);
- button_back = newWidgetButton("Back", 100, WINDOW_SIZE_Y-100, eventWidget);
- button_play = newWidgetButton("Play", WINDOW_SIZE_X-200, WINDOW_SIZE_Y-100, eventWidget);
+ button_back = newWidgetButton(getMyText("BACK"), 100, WINDOW_SIZE_Y-100, eventWidget);
+ button_play = newWidgetButton(getMyText("PLAY"), WINDOW_SIZE_X-200, WINDOW_SIZE_Y-100, eventWidget);
check_none = newWidgetCheck(100, 150, FALSE, eventWidget);
check_server = newWidgetCheck(100, 200, FALSE, eventWidget);
@@ -168,12 +169,12 @@ void initScreenGameType()
check_none->status = TRUE;
}
- label_none = newWidgetLabel("none", 130, 145, WIDGET_LABEL_LEFT);
- label_server = newWidgetLabel("server", 130, 195, WIDGET_LABEL_LEFT);
- label_client = newWidgetLabel("client", 130, 245, WIDGET_LABEL_LEFT);
+ label_none = newWidgetLabel(getMyText("NONE"), 130, 145, WIDGET_LABEL_LEFT);
+ label_server = newWidgetLabel(getMyText("SERVER"), 130, 195, WIDGET_LABEL_LEFT);
+ label_client = newWidgetLabel(getMyText("CLIENT"), 130, 245, WIDGET_LABEL_LEFT);
- label_ip = newWidgetLabel("IP address :", 300, 145, WIDGET_LABEL_LEFT);
- label_port = newWidgetLabel("net port :", 300, 245, WIDGET_LABEL_LEFT);
+ label_ip = newWidgetLabel(getMyText("IP_ADDR"), 300, 145, WIDGET_LABEL_LEFT);
+ label_port = newWidgetLabel(getMyText("NET_PORT"), 300, 245, WIDGET_LABEL_LEFT);
textfield_ip = newWidgetTextfield(getParamElse("--ip", "127.0.0.1"), 300, 180);
textfield_port = newWidgetTextfield(getParamElse("--port", "2200"), 300, 280);
diff --git a/src/screen_mainMenu.c b/src/screen_mainMenu.c
index f36a21d..171b1a7 100644
--- a/src/screen_mainMenu.c
+++ b/src/screen_mainMenu.c
@@ -4,6 +4,7 @@
#include "main.h"
#include "interface.h"
+#include "language.h"
#include "screen.h"
#include "image.h"
#include "music.h"
@@ -92,11 +93,11 @@ void initScreenMainMenu()
image = addImageData("screen_main.png", IMAGE_NO_ALPHA, "screen_main", IMAGE_GROUP_BASE);
image_backgorund = newWidgetImage(0, 0, image);
- button_play = newWidgetButton("Play", WINDOW_SIZE_X/2 -WIDGET_BUTTON_WIDTH/2, 200, eventWidget);
- button_setting = newWidgetButton("Setting", WINDOW_SIZE_X/2 -WIDGET_BUTTON_WIDTH/2, 250, eventWidget);
- button_table = newWidgetButton("Table", WINDOW_SIZE_X/2 -WIDGET_BUTTON_WIDTH/2, 300, eventWidget);
- button_credits = newWidgetButton("Credits", WINDOW_SIZE_X/2 -WIDGET_BUTTON_WIDTH/2, 350, eventWidget);
- button_end = newWidgetButton("End", WINDOW_SIZE_X/2 -WIDGET_BUTTON_WIDTH/2, 400, eventWidget);
+ button_play = newWidgetButton(getMyText("PLAY"), WINDOW_SIZE_X/2 -WIDGET_BUTTON_WIDTH/2, 200, eventWidget);
+ button_setting = newWidgetButton(getMyText("SETTING"), WINDOW_SIZE_X/2 -WIDGET_BUTTON_WIDTH/2, 250, eventWidget);
+ button_table = newWidgetButton(getMyText("TABLE"), WINDOW_SIZE_X/2 -WIDGET_BUTTON_WIDTH/2, 300, eventWidget);
+ button_credits = newWidgetButton(getMyText("CREDITS"), WINDOW_SIZE_X/2 -WIDGET_BUTTON_WIDTH/2, 350, eventWidget);
+ button_end = newWidgetButton(getMyText("END"), WINDOW_SIZE_X/2 -WIDGET_BUTTON_WIDTH/2, 400, eventWidget);
addMusic("menu.ogg", "menu", MUSIC_GROUP_BASE);
diff --git a/src/screen_setting.c b/src/screen_setting.c
index 344d8ff..72368c1 100644
--- a/src/screen_setting.c
+++ b/src/screen_setting.c
@@ -4,6 +4,7 @@
#include <assert.h>
#include "main.h"
+#include "language.h"
#include "interface.h"
#include "screen.h"
#include "image.h"
@@ -267,21 +268,21 @@ void initScreenSetting()
image = getImage(IMAGE_GROUP_BASE, "screen_main");
image_backgorund = newWidgetImage(0, 0, image);
- button_back = newWidgetButton("Back", WINDOW_SIZE_X-200, WINDOW_SIZE_Y-100, eventWidget);
+ button_back = newWidgetButton(getMyText("BACK"), WINDOW_SIZE_X-200, WINDOW_SIZE_Y-100, eventWidget);
- label_count_round = newWidgetLabel("Count Round :", 100, WINDOW_SIZE_Y-200, WIDGET_LABEL_LEFT);
- label_name_player1 = newWidgetLabel("Name player1 :", 100, WINDOW_SIZE_Y-160, WIDGET_LABEL_LEFT);
- label_name_player2 = newWidgetLabel("Name player2 :", 100, WINDOW_SIZE_Y-120, WIDGET_LABEL_LEFT);
+ label_count_round = newWidgetLabel(getMyText("COUNT_ROUND"), 100, WINDOW_SIZE_Y-200, WIDGET_LABEL_LEFT);
+ label_name_player1 = newWidgetLabel(getMyText("NAME_PLAYER1"), 100, WINDOW_SIZE_Y-160, WIDGET_LABEL_LEFT);
+ label_name_player2 = newWidgetLabel(getMyText("NAME_PLAYER2"), 100, WINDOW_SIZE_Y-120, WIDGET_LABEL_LEFT);
textfield_count_cound = newWidgetTextfield(getParamElse("--count", "15"), 110+label_count_round->w, WINDOW_SIZE_Y-200);
textfield_name_player1 = newWidgetTextfield(getParamElse("--name1", "name1"), 110+label_name_player1->w, WINDOW_SIZE_Y-160);
textfield_name_player2 = newWidgetTextfield(getParamElse("--name2", "name2"), 110+label_name_player2->w, WINDOW_SIZE_Y-120);
- label_music = newWidgetLabel("Music :", 100, WINDOW_SIZE_Y-85, WIDGET_LABEL_LEFT);
+ label_music = newWidgetLabel(getMyText("MUSIC"), 100, WINDOW_SIZE_Y-85, WIDGET_LABEL_LEFT);
check_music = newWidgetCheck(label_music->x + label_music->w + 10,
WINDOW_SIZE_Y-80, isMusicActive() , eventWidget);
- label_sound = newWidgetLabel("Sound :", check_music->x + WIDGET_CHECK_WIDTH + 10,
+ label_sound = newWidgetLabel(getMyText("SOUND"), check_music->x + WIDGET_CHECK_WIDTH + 10,
WINDOW_SIZE_Y-85, WIDGET_LABEL_LEFT);
check_sound = newWidgetCheck(label_sound->x + label_sound->w + 10,
WINDOW_SIZE_Y-80, isSoundActive() , eventWidget);
diff --git a/src/screen_table.c b/src/screen_table.c
index 2733859..5a02e33 100644
--- a/src/screen_table.c
+++ b/src/screen_table.c
@@ -4,6 +4,7 @@
#include <assert.h>
#include "main.h"
+#include "language.h"
#include "interface.h"
#include "list.h"
#include "textFile.h"
@@ -201,7 +202,7 @@ void initScreenTable()
image = addImageData("screen_table.png", IMAGE_NO_ALPHA, "screen_table", IMAGE_GROUP_BASE);
image_backgorund = newWidgetImage(0, 0, image);
- button_back = newWidgetButton("Back", WINDOW_SIZE_X/2 -WIDGET_BUTTON_WIDTH/2,
+ button_back = newWidgetButton(getMyText("BACK"), WINDOW_SIZE_X/2 -WIDGET_BUTTON_WIDTH/2,
WINDOW_SIZE_Y-100, eventWidget);
loadHighscoreFile();
diff --git a/src/screen_world.c b/src/screen_world.c
index 571b10e..02536de 100644
--- a/src/screen_world.c
+++ b/src/screen_world.c
@@ -13,6 +13,7 @@
#include "screen_choiceArena.h"
#include "screen_table.h"
+#include "keytable.h"
#include "list.h"
#include "layer.h"
#include "image.h"
@@ -32,11 +33,12 @@
#include "arenaFile.h"
#include "proto.h"
#include "term.h"
+#include "font.h"
static arena_t *arena;
static int count;
static int max_count;
-
+static my_time_t lastServerLag;
static bool_t isScreenWorldInit = FALSE;
static bool_t isEndWorld;
@@ -70,6 +72,11 @@ void setMaxCountRound(int n)
max_count = n;
}
+void setLagServer(my_time_t lag)
+{
+ lastServerLag = lag;
+}
+
void setWorldEnd()
{
isEndWorld = TRUE;
@@ -98,7 +105,7 @@ void countRoundInc()
{
printf("count %d ending\n", count);
playSound("end", SOUND_GROUP_BASE);
- addTimer(getCurrentArena()->listTimer, timer_endArena, NULL, TIMER_END_ARENA);
+ addTaskToTimer(getCurrentArena()->listTimer, TIMER_ONE, timer_endArena, NULL, TIMER_END_ARENA);
}
}
@@ -158,6 +165,25 @@ void prepareArena()
}
}
+/*
+static void drawServerLag()
+{
+ char msg[STR_SIZE];
+
+ if( lastServerLag == LAG_SERVER_UNKNOWN )
+ {
+ sprintf(msg, "lag server: unknown");
+ }
+ else
+ {
+ sprintf(msg, "lag server: %d", lastServerLag);
+ }
+
+ drawFont(msg, WINDOW_SIZE_X-150, 20, COLOR_WHITE);
+
+}
+*/
+
void drawWorld()
{
if( arena != NULL )
@@ -190,37 +216,37 @@ static void control_keyboard_right(tux_t *tux)
assert( tux != NULL );
assert( mapa != NULL );
- if( mapa[(SDLKey)SDLK_UP] == SDL_PRESSED )
+ if( mapa[(SDLKey)getKey(KEY_TUX_RIGHT_MOVE_UP)] == SDL_PRESSED )
{
netAction(tux, TUX_UP);
actionTux(tux, TUX_UP);
}
- if( mapa[(SDLKey)SDLK_RIGHT] == SDL_PRESSED )
+ if( mapa[(SDLKey)getKey(KEY_TUX_RIGHT_MOVE_RIGHT)] == SDL_PRESSED )
{
netAction(tux, TUX_RIGHT);
actionTux(tux, TUX_RIGHT);
}
- if( mapa[(SDLKey)SDLK_LEFT] == SDL_PRESSED )
+ if( mapa[(SDLKey)getKey(KEY_TUX_RIGHT_MOVE_LEFT)] == SDL_PRESSED )
{
netAction(tux, TUX_LEFT);
actionTux(tux, TUX_LEFT);
}
- if( mapa[(SDLKey)SDLK_DOWN] == SDL_PRESSED )
+ if( mapa[(SDLKey)getKey(KEY_TUX_RIGHT_MOVE_DOWN)] == SDL_PRESSED )
{
netAction(tux, TUX_DOWN);
actionTux(tux, TUX_DOWN);
}
- if( mapa[(SDLKey)SDLK_KP0] == SDL_PRESSED && tux->isCanShot == TRUE )
+ if( mapa[(SDLKey)getKey(KEY_TUX_RIGHT_SHOOT)] == SDL_PRESSED && tux->isCanShot == TRUE )
{
netAction(tux, TUX_SHOT);
actionTux(tux, TUX_SHOT);
}
- if( mapa[(SDLKey)SDLK_KP1] == SDL_PRESSED )
+ if( mapa[(SDLKey)getKey(KEY_TUX_RIGHT_SWITCH_WEAPON)] == SDL_PRESSED )
{
if( tux->isCanSwitchGun == TRUE )
{
@@ -238,17 +264,16 @@ static void control_keyboard_left(tux_t *tux)
assert( tux != NULL );
assert( mapa != NULL );
- if( mapa[(SDLKey)SDLK_w] == SDL_PRESSED )actionTux(tux, TUX_UP);
- if( mapa[(SDLKey)SDLK_d] == SDL_PRESSED )actionTux(tux, TUX_RIGHT);
- if( mapa[(SDLKey)SDLK_a] == SDL_PRESSED )actionTux(tux, TUX_LEFT);
- if( mapa[(SDLKey)SDLK_s] == SDL_PRESSED )actionTux(tux, TUX_DOWN);
- if( mapa[(SDLKey)SDLK_q] == SDL_PRESSED )actionTux(tux, TUX_SHOT);
+ if( mapa[(SDLKey)getKey(KEY_TUX_LEFT_MOVE_UP)] == SDL_PRESSED )actionTux(tux, TUX_UP);
+ if( mapa[(SDLKey)getKey(KEY_TUX_LEFT_MOVE_RIGHT)] == SDL_PRESSED )actionTux(tux, TUX_RIGHT);
+ if( mapa[(SDLKey)getKey(KEY_TUX_LEFT_MOVE_LEFT)] == SDL_PRESSED )actionTux(tux, TUX_LEFT);
+ if( mapa[(SDLKey)getKey(KEY_TUX_LEFT_MOVE_DOWN)] == SDL_PRESSED )actionTux(tux, TUX_DOWN);
+ if( mapa[(SDLKey)getKey(KEY_TUX_LEFT_SHOOT)] == SDL_PRESSED )actionTux(tux, TUX_SHOT);
- if( mapa[(SDLKey)SDLK_TAB] == SDL_PRESSED )
+ if( mapa[(SDLKey)getKey(KEY_TUX_LEFT_SWITCH_WEAPON)] == SDL_PRESSED )
{
if( tux->isCanSwitchGun == TRUE )
{
- netAction(tux, TUX_SWITCH_GUN);
actionTux(tux, TUX_SWITCH_GUN);
}
}
@@ -326,6 +351,7 @@ void startWorld()
isEndWorld = FALSE;
count = 0;
+ lastServerLag = LAG_SERVER_UNKNOWN;
setGameType();
initTerm();
diff --git a/src/server.c b/src/server.c
index 92c60cf..5c11781 100644
--- a/src/server.c
+++ b/src/server.c
@@ -45,34 +45,102 @@ static sock_sdl_udp_t *sock_server_sdl_udp;
#endif
static list_t *listClient;
+static list_t *listServerTimer;
static my_time_t lastSyncClient;
static int maxClients;
-void static initServer()
+#if defined SUPPORT_NET_UNIX_UDP || defined SUPPORT_NET_SDL_UDP
+
+static void delZombieCLient(void *p_nothink)
{
- listClient = newList();
- lastSyncClient = getMyTime();
- setServerMaxClients(SERVER_MAX_CLIENTS);
+ client_t *thisClient;
+ my_time_t currentTime;
+ int i;
+
+ currentTime = getMyTime();
+
+ for( i = 0 ; i < listClient->count; i++)
+ {
+ thisClient = (client_t *) listClient->list[i];
+
+ if( currentTime - thisClient->lastPing > SERVER_TIMEOUT )
+ {
+ proto_send_error_server(PROTO_SEND_ONE, thisClient, PROTO_ERROR_CODE_TIMEOUT);
+ thisClient->status = NET_STATUS_ZOMBIE;
+ }
+
+ if( thisClient->status == NET_STATUS_ZOMBIE )
+ {
+ if( thisClient->tux != NULL )
+ {
+ proto_send_deltux_server(PROTO_SEND_ALL, NULL, thisClient);
+ }
+
+ delListItem(listClient, i, destroyClient);
+ }
+ }
}
-#ifdef SUPPORT_NET_UNIX_TCP
-int initTcpServer(int port)
+static void eventPeriodicSyncClient(void *p_nothink)
{
- sock_server_tcp = bindTcpSocket(port);
+ my_time_t currentTime;
+ client_t *thisClientInfo;
+ client_t *thisClientSend;
+ tux_t *thisTux;
+ int i, j;
+
+ currentTime = getMyTime();
- if( sock_server_tcp == NULL )
+
+ for( i = 0 ; i < listClient->count; i++)
{
- return -1;
- }
+ thisClientSend = (client_t *) listClient->list[i];
- initServer();
+ if( thisClientSend->tux != NULL )
+ {
+#ifndef PUBLIC_SERVER
+ proto_send_newtux_server(PROTO_SEND_ONE, thisClientSend,
+ (tux_t *)(getCurrentArena()->listTux->list[SERVER_INDEX_ROOT_TUX]));
+#endif
+ }
- printf("server listen TCP port %d\n", port);
+ for( j = 0 ; j < listClient->count; j++)
+ {
+ thisClientInfo = (client_t *) listClient->list[j];
+ thisTux = thisClientInfo->tux;
- return 0;
+ if( thisTux != NULL &&
+ thisClientSend->tux != NULL &&
+ thisClientSend != thisClientInfo /*&&
+ thisTux->status == TUX_STATUS_ALIVE*/ )
+ {
+ proto_send_newtux_server(PROTO_SEND_ONE,
+ thisClientSend, thisTux);
+ }
+ }
+ }
+}
+
+static void eventSendPingClients(void *p_nothink)
+{
+ proto_send_ping_server(PROTO_SEND_ALL, NULL);
}
+
#endif
+void static initServer()
+{
+ listClient = newList();
+ lastSyncClient = getMyTime();
+ setServerMaxClients(SERVER_MAX_CLIENTS);
+
+ listServerTimer = newTimer();
+
+ addTaskToTimer(listServerTimer, TIMER_PERIODIC, delZombieCLient, NULL, SERVER_TIMEOUT);
+ addTaskToTimer(listServerTimer, TIMER_PERIODIC, eventPeriodicSyncClient, NULL, SERVER_TIME_SYNC);
+ addTaskToTimer(listServerTimer, TIMER_PERIODIC, eventSendPingClients, NULL, SERVER_TIME_PING);
+}
+
#ifdef SUPPORT_NET_UNIX_UDP
int initUdpServer(char *ip, int port)
{
@@ -122,24 +190,6 @@ static client_t* newAnyClient()
return new;
}
-#ifdef SUPPORT_NET_UNIX_TCP
-client_t* newTcpClient(sock_tcp_t *sock_tcp)
-{
- client_t *new;
- char str_ip[STR_IP_SIZE];
-
- assert( sock_tcp != NULL );
-
- getSockTcpIp(sock_tcp, str_ip);
- printf("new client from %s:%d\n", str_ip, getSockTcpPort(sock_tcp));
-
- new = newAnyClient();
- new->socket_tcp = sock_tcp;
-
- return new;
-}
-#endif
-
#ifdef SUPPORT_NET_UNIX_UDP
client_t* newUdpClient(sock_udp_t *sock_udp)
{
@@ -181,10 +231,6 @@ void destroyClient(client_t *p)
assert( p != NULL );
-#ifdef SUPPORT_NET_UNIX_TCP
- closeTcpSocket(p->socket_tcp);
-#endif
-
#ifdef SUPPORT_NET_UNIX_UDP
closeUdpSocket(p->socket_udp);
#endif
@@ -228,22 +274,6 @@ void sendClient(client_t *p, char *msg)
{
int ret;
-#ifdef SUPPORT_NET_UNIX_TCP
- ret = writeTcpSocket(p->socket_tcp, msg, strlen(msg));
-
- if( ret == 0 )
- {
- fprintf(stderr, "client sa odpojil\n");
- p->status = NET_STATUS_ZOMBIE;
- }
-
- if( ret < 0 )
- {
- fprintf(stderr, "nastala chyba pri posielanie spravy clientovy\n");
- p->status = NET_STATUS_ZOMBIE;
- }
-#endif
-
#ifdef SUPPORT_NET_UNIX_UDP
ret = writeUdpSocket(sock_server_udp, p->socket_udp, msg, strlen(msg));
#endif
@@ -314,20 +344,6 @@ void sendInfoCreateClient(client_t *client)
}
}
-#ifdef SUPPORT_NET_UNIX_TCP
-
-static void eventCreateNewTcpClient(sock_tcp_t *socket_tcp)
-{
- client_t *client;
-
- assert( socket_tcp != NULL );
-
- client = newTcpClient( getTcpNewClient(socket_tcp) );
- addList(listClient, client);
-}
-
-#endif
-
#ifdef SUPPORT_NET_UNIX_UDP
static void eventCreateNewUdpClient(sock_udp_t *socket_udp)
@@ -356,33 +372,6 @@ static void eventCreateNewSdlUdpClient(sock_sdl_udp_t *socket_sdl_udp)
#endif
-#ifdef SUPPORT_NET_UNIX_TCP
-
-static void eventClientTcpSelect(client_t *client)
-{
- char buffer[STR_PROTO_SIZE];
- int ret;
-
- assert( client != NULL );
-
- memset(buffer, 0, STR_SIZE);
- ret = readTcpSocket(client->socket_tcp, buffer, STR_PROTO_SIZE-1);
-
- if( ret <= 0 )
- {
- client->status = NET_STATUS_ZOMBIE;
- return;
- }
-
- if( addBuffer(client->buffer, buffer, ret) != 0 )
- {
- client->status = NET_STATUS_ZOMBIE;
- return;
- }
-}
-
-#endif
-
static void eventClientBuffer(client_t *client)
{
char line[STR_PROTO_SIZE];
@@ -396,10 +385,8 @@ static void eventClientBuffer(client_t *client)
#ifdef DEBUG_SERVER_RECV
printf("recv client msg->%s", line);
#endif
-
-#if defined SUPPORT_NET_UNIX_UDP || defined SUPPORT_NET_SDL_UDP
client->lastPing = getMyTime();
-#endif
+
if( strncmp(line, "hello", 5) == 0 )
{
proto_recv_hello_server(client, line);
@@ -452,146 +439,6 @@ void eventClientListBuffer()
}
}
-#ifdef SUPPORT_NET_UNIX_TCP
-
-void selectServerTcpSocket()
-{
- fd_set readfds;
- struct timeval tv;
- client_t *thisClient;
- int max_fd;
- int i;
-
- tv.tv_sec = 0;
- tv.tv_usec = 0;
-
- FD_ZERO(&readfds);
- FD_SET(sock_server_tcp->sock, &readfds);
- max_fd = sock_server_tcp->sock;
-
- for( i = 0 ; i < listClient->count; i++)
- {
- thisClient = (client_t *) listClient->list[i];
-
- FD_SET(thisClient->socket_tcp->sock, &readfds);
-
- if( thisClient->socket_tcp->sock > max_fd )
- {
- max_fd = thisClient->socket_tcp->sock;
- }
- }
-
- select(max_fd+1, &readfds, (fd_set *)NULL, (fd_set *)NULL, &tv);
-
- if( FD_ISSET(sock_server_tcp->sock, &readfds) )
- {
- eventCreateNewTcpClient(sock_server_tcp);
- }
-
- for( i = 0 ; i < listClient->count; i++)
- {
- thisClient = (client_t *) listClient->list[i];
-
- if( FD_ISSET(thisClient->socket_tcp->sock, &readfds) )
- {
- eventClientTcpSelect(thisClient);
- }
-
- if( thisClient->status == NET_STATUS_ZOMBIE )
- {
- if( thisClient->tux != NULL )
- {
- proto_send_deltux_server(PROTO_SEND_ALL, NULL, thisClient);
- }
-
- delListItem(listClient, i, destroyClient);
- }
- }
-}
-
-#endif
-
-#if defined SUPPORT_NET_UNIX_UDP || defined SUPPORT_NET_SDL_UDP
-
-static void delZombieCLient()
-{
- client_t *thisClient;
- my_time_t currentTime;
- int i;
-
- currentTime = getMyTime();
-
- for( i = 0 ; i < listClient->count; i++)
- {
- thisClient = (client_t *) listClient->list[i];
-
- if( currentTime - thisClient->lastPing > SERVER_TIMEOUT )
- {
- proto_send_error_server(PROTO_SEND_ONE, thisClient, PROTO_ERROR_CODE_TIMEOUT);
- thisClient->status = NET_STATUS_ZOMBIE;
- }
-
- if( thisClient->status == NET_STATUS_ZOMBIE )
- {
- if( thisClient->tux != NULL )
- {
- proto_send_deltux_server(PROTO_SEND_ALL, NULL, thisClient);
- }
-
- delListItem(listClient, i, destroyClient);
- }
- }
-}
-
-void eventPeriodicSyncClient()
-{
- my_time_t currentTime;
-
- currentTime = getMyTime();
-
- if( currentTime - lastSyncClient > SERVER_TIME_SYNC )
- {
- client_t *thisClientInfo;
- client_t *thisClientSend;
- tux_t *thisTux;
- int i, j;
-
- for( i = 0 ; i < listClient->count; i++)
- {
- thisClientSend = (client_t *) listClient->list[i];
-
- if( thisClientSend->tux != NULL )
- {
- proto_send_ping_server(PROTO_SEND_ONE, thisClientSend);
-
-#ifndef PUBLIC_SERVER
- proto_send_newtux_server(PROTO_SEND_ONE, thisClientSend,
- (tux_t *)(getCurrentArena()->listTux->list[SERVER_INDEX_ROOT_TUX]));
-#endif
- }
-
- for( j = 0 ; j < listClient->count; j++)
- {
- thisClientInfo = (client_t *) listClient->list[j];
- thisTux = thisClientInfo->tux;
-
- if( thisTux != NULL &&
- thisClientSend->tux != NULL &&
- thisClientSend != thisClientInfo &&
- thisTux->status == TUX_STATUS_ALIVE )
- {
- proto_send_newtux_server(PROTO_SEND_ONE,
- thisClientSend, thisTux);
- }
- }
- }
-
- lastSyncClient = getMyTime();
- }
-}
-
-#endif
-
#ifdef SUPPORT_NET_UNIX_UDP
static client_t* findUdpClient(sock_udp_t *sock_udp)
@@ -688,11 +535,17 @@ void selectServerUdpSocket()
FD_ZERO(&readfds);
FD_SET(sock_server_udp->sock, &readfds);
max_fd = sock_server_udp->sock;
-
- delZombieCLient();
-
- ret = select(max_fd+1, &readfds, (fd_set *)NULL, (fd_set *)NULL, &tv);
-
+
+ if( listClient->count == 0 )
+ {
+ ret = select(max_fd+1, &readfds, (fd_set *)NULL, (fd_set *)NULL, NULL);
+ //restartTimer();
+ }
+ else
+ {
+ ret = select(max_fd+1, &readfds, (fd_set *)NULL, (fd_set *)NULL, &tv);
+ }
+
if( ret < 0 )
{
return;
@@ -736,8 +589,6 @@ void selectServerSdlUdpSocket()
assert( sock_server_sdl_udp != NULL );
- delZombieCLient();
-
do{
sock_client = newSdlSockUdp();
isCreateNewClient = FALSE;
@@ -789,27 +640,28 @@ void selectServerSdlUdpSocket()
#endif
+void eventServer()
+{
+#ifdef SUPPORT_NET_SDL_UDP
+ selectServerSdlUdpSocket();
+#endif
+
+#ifdef SUPPORT_NET_UNIX_UDP
+ selectServerUdpSocket();
+#endif
+
+ eventClientListBuffer();
+ eventTimer(listServerTimer);
+}
+
static void quitServer()
{
proto_send_end_server(PROTO_SEND_ALL, NULL);
assert( listClient != NULL );
destroyListItem(listClient, destroyClient);
+ destroyTimer(listServerTimer);
}
-#ifdef SUPPORT_NET_UNIX_TCP
-
-void quitTcpServer()
-{
- quitServer();
-
- assert( sock_server_tcp != NULL );
- closeTcpSocket(sock_server_tcp);
-
- printf("quit TCP port\n");
-}
-
-#endif
-
#ifdef SUPPORT_NET_UNIX_UDP
void quitUdpServer()
diff --git a/src/serverConfigFile.c b/src/serverConfigFile.c
new file mode 100644
index 0000000..8640333
--- /dev/null
+++ b/src/serverConfigFile.c
@@ -0,0 +1,86 @@
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+
+#include "main.h"
+#include "list.h"
+#include "textFile.h"
+#include "serverConfigFile.h"
+
+static textFile_t *serverTextFile;
+
+static void prepareConfigFile(textFile_t *ts)
+{
+ int i;
+ int j;
+
+ for( i = 0 ; i < serverTextFile->text->count ; i++ )
+ {
+ char *line;
+ int len;
+
+ line = (char *)(serverTextFile->text->list[i]);
+ len = strlen(line);
+
+ for( j = 0 ; j < len ; j++ )
+ {
+ if( line[j] == ' ' ) // [TAB]
+ {
+ line[j] = ' ';
+ }
+ }
+ }
+
+}
+
+void initServerConfigFile()
+{
+ serverTextFile = loadTextFile("./server.conf");
+
+ if( serverTextFile == NULL )
+ {
+ fprintf(stderr, "I dont load config file, I used default values\n");
+ return;
+ }
+
+ prepareConfigFile(serverTextFile);
+
+}
+char* getServerConfigFileValue(char *env, char *s)
+{
+ int i;
+ int len;
+
+ if( serverTextFile == NULL )
+ {
+ return s;
+ }
+
+ len = strlen(env);
+
+ for( i = 0 ; i < serverTextFile->text->count ; i++ )
+ {
+ char *line;
+
+ line = (char *)(serverTextFile->text->list[i]);
+
+ if( strncmp(line, env, len) == 0 )
+ {
+ return strrchr(line,' ')+1;
+ }
+ }
+
+ return s;
+}
+
+void quitServerConfigFile()
+{
+ if( serverTextFile != NULL )
+ {
+ destroyTextFile(serverTextFile);
+ }
+}
+
+
diff --git a/src/tux.c b/src/tux.c
index 07691a4..2069978 100644
--- a/src/tux.c
+++ b/src/tux.c
@@ -391,7 +391,7 @@ void eventTuxIsDead(tux_t *tux)
if( getNetTypeGame() != NET_GAME_TYPE_CLIENT )
{
- addTimer(getCurrentArena()->listTimer, timer_spawnTux, newInt(tux->id), TUX_TIME_SPAWN );
+ addTaskToTimer(getCurrentArena()->listTimer, TIMER_ONE, timer_spawnTux, newInt(tux->id), TUX_TIME_SPAWN );
}
if( getNetTypeGame() == NET_GAME_TYPE_SERVER )
@@ -609,7 +609,7 @@ void switchTuxGun(tux_t *tux)
{
tux->gun = i;
tux->isCanSwitchGun = FALSE;
- addTimer(getCurrentArena()->listTimer, timer_tuxCanSwitchGun,
+ addTaskToTimer(getCurrentArena()->listTimer, TIMER_ONE, timer_tuxCanSwitchGun,
newInt(tux->id), TUX_TIME_CAN_SWITCH_GUN );
#ifndef PUBLIC_SERVER
playSound("switch_gun", SOUND_GROUP_BASE);
@@ -626,7 +626,7 @@ void switchTuxGun(tux_t *tux)
{
tux->gun = i;
tux->isCanSwitchGun = FALSE;
- addTimer(getCurrentArena()->listTimer, timer_tuxCanSwitchGun,
+ addTaskToTimer(getCurrentArena()->listTimer, TIMER_ONE, timer_tuxCanSwitchGun,
newInt(tux->id), TUX_TIME_CAN_SWITCH_GUN );
#ifndef PUBLIC_SERVER
@@ -657,7 +657,7 @@ void shotTux(tux_t *tux)
shotInGun(tux);
tux->isCanShot = FALSE;
- addTimer(getCurrentArena()->listTimer, timer_tuxCanShot,
+ addTaskToTimer(getCurrentArena()->listTimer, TIMER_ONE, timer_tuxCanShot,
newInt(tux->id), TUX_TIME_CAN_SHOT );
if( tux->shot[tux->gun] == 0 )
diff --git a/src/udp.c b/src/udp.c
index af254de..d59902a 100644
--- a/src/udp.c
+++ b/src/udp.c
@@ -173,6 +173,8 @@ void closeUdpSocket(sock_udp_t *p)
destroySockUdp(p);
}
+#if 0
+
static int myWait(sock_udp_t *p)
{
fd_set readfds;
@@ -201,7 +203,6 @@ static int myWait(sock_udp_t *p)
return 0;
}
-#if 0
int test_udp_main(int argc, char *argv[])
{
sock_udp_t *sock;
diff --git a/src/zal_proto.c b/src/zal_proto.c
new file mode 100644
index 0000000..a091e19
--- /dev/null
+++ b/src/zal_proto.c
@@ -0,0 +1,692 @@
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+
+#include "main.h"
+#include "list.h"
+#include "tux.h"
+#include "item.h"
+#include "shot.h"
+#include "arenaFile.h"
+#include "myTimer.h"
+#include "server.h"
+#include "proto.h"
+#include "net_multiplayer.h"
+
+#ifndef PUBLIC_SERVER
+#include "network.h"
+#include "screen_world.h"
+#include "screen_setting.h"
+#include "screen_choiceArena.h"
+#include "client.h"
+#include "term.h"
+#endif
+
+#ifdef PUBLIC_SERVER
+#include "publicServer.h"
+#endif
+
+static void proto_send(int type, client_t *client, char *msg)
+{
+ assert( msg != NULL );
+
+ switch( type )
+ {
+ case PROTO_SEND_ONE :
+ assert( client != NULL );
+ sendClient(client, msg);
+#ifdef DEBUG_SERVER_SEND
+ printf("send one client msg->%s\n", msg);
+#endif
+ break;
+ case PROTO_SEND_ALL :
+ assert( client == NULL );
+ sendAllClient(msg);
+#ifdef DEBUG_SERVER_SEND
+ printf("send all clients msg->%s\n", msg);
+#endif
+ break;
+ case PROTO_SEND_BUT :
+ assert( client != NULL );
+ sendAllClientBut(msg, client);
+#ifdef DEBUG_SERVER_SEND
+ printf("send but client msg->%s\n", msg);
+#endif
+ break;
+ default :
+ assert( ! "Premenna type ma zlu hodnotu !" );
+ break;
+ }
+}
+
+void proto_send_error_server(int type, client_t *client, int errorcode)
+{
+ char msg[STR_PROTO_SIZE];
+
+ sprintf(msg, "error %d\n", errorcode);
+
+ proto_send(type, client, msg);
+}
+
+#ifndef PUBLIC_SERVER
+
+void proto_recv_error_client(char *msg)
+{
+ char cmd[STR_PROTO_SIZE];
+ int errorcode;
+
+ assert( msg != NULL );
+
+ sscanf(msg, "%s %d",
+ cmd, &errorcode);
+
+ printf("proto error code %d\n", errorcode);
+}
+
+#endif
+
+#ifndef PUBLIC_SERVER
+
+void proto_send_hello_client(char *name)
+{
+ char msg[STR_PROTO_SIZE];
+
+ sprintf(msg, "hello %s %s\n", TUXANCI_NG_VERSION, name);
+ sendServer(msg);
+}
+
+#endif
+
+void proto_recv_hello_server(client_t *client, char *msg)
+{
+ char cmd[STR_PROTO_SIZE];
+ char version[STR_NAME_SIZE];
+ char name[STR_NAME_SIZE];
+
+ assert( client != NULL );
+
+ strcpy(version, "");
+ strcpy(name, "");
+
+ sscanf(msg, "%s %s %s", cmd, version, name);
+
+ if( strncmp(version, TUXANCI_NG_VERSION, strlen(TUXANCI_NG_VERSION)) != 0 )
+ {
+ proto_send_error_server(PROTO_SEND_ONE, client, PROTO_ERROR_CODE_BAD_VERSION);
+ client->status = NET_STATUS_ZOMBIE;
+ return;
+ }
+
+ client->tux = newTux();
+ client->tux->control = TUX_CONTROL_NET;
+ addList(getCurrentArena()->listTux, client->tux);
+
+ if( strlen(name) > STR_NAME_SIZE-1 )
+ {
+ name[STR_NAME_SIZE-1] = '\0';
+ }
+
+ strcpy(client->tux->name, name);
+ sendInfoCreateClient(client);
+}
+
+void proto_send_status_server(int type, client_t *client)
+{
+ char msg[STR_PROTO_SIZE];
+
+ sprintf(msg, "version: %s\n"
+ "clients: %d\n"
+ "maxclients: %d\n"
+ "uptime: %d\n",
+ TUXANCI_NG_VERSION, getCurrentArena()->listTux->count,
+ getServerMaxClients(), getMyTime() );
+
+ proto_send(type, client, msg);
+}
+
+void proto_recv_status_server(client_t *client, char *msg)
+{
+ proto_send_status_server(PROTO_SEND_ONE, client);
+}
+
+void proto_send_init_server(int type, client_t *client, client_t *client2)
+{
+ char msg[STR_PROTO_SIZE];
+ int n = WORLD_COUNT_ROUND_UNLIMITED;
+
+ assert( client2 != NULL );
+
+#ifndef PUBLIC_SERVER
+ getSettingCountRound(&n);
+#endif
+
+ sprintf(msg, "init %d %d %d %d %s\n",
+ client2->tux->id, client2->tux->x, client2->tux->y,
+ n, getArenaNetName( getChoiceArenaId() ));
+
+ proto_send(type, client, msg);
+}
+
+#ifndef PUBLIC_SERVER
+
+void proto_recv_init_client(char *msg)
+{
+ char cmd[STR_PROTO_SIZE];
+ char arena_name[STR_PROTO_SIZE];
+ tux_t *tux;
+ int id;
+ int x, y, n;
+
+ assert( msg != NULL );
+
+ sscanf(msg, "%s %d %d %d %d %s",
+ cmd, &id, &x, &y, &n, arena_name);
+
+ setWorldArena( getArenaIdFormNetName(arena_name) );
+ setMaxCountRound(n);
+
+ tux = newTux();
+ tux->id = id;
+ tux->x = x;
+ tux->y = y;
+ tux->control = TUX_CONTROL_KEYBOARD_RIGHT;
+
+ getSettingNameRight(tux->name);
+
+ addList(getCurrentArena()->listTux, tux);
+}
+
+#endif
+
+void proto_send_event_server(int type, client_t *client, tux_t *tux, int action)
+{
+ char msg[STR_PROTO_SIZE];
+
+ assert( tux != NULL );
+
+ sprintf(msg, "event %d %d\n", tux->id, action);
+
+ proto_send(type, client, msg);
+}
+
+#ifndef PUBLIC_SERVER
+
+void proto_recv_event_client(char *msg)
+{
+ char cmd[STR_PROTO_SIZE];
+ int id, action;
+ tux_t *tux;
+
+ assert( msg != NULL );
+
+ sscanf(msg, "%s %d %d", cmd, &id, &action);
+
+ tux = getTuxID(getCurrentArena()->listTux, id);
+
+ if( tux != NULL )
+ {
+ actionTux(tux, action);
+ }
+}
+
+#endif
+
+#ifndef PUBLIC_SERVER
+
+void proto_send_event_client(int action)
+{
+ char msg[STR_PROTO_SIZE];
+
+ sprintf(msg, "event %d\n", action);
+
+ sendServer(msg);
+}
+
+#endif
+
+void proto_recv_event_server(client_t *client, char *msg)
+{
+ char cmd[STR_PROTO_SIZE];
+ int action;
+
+ assert( client != NULL );
+ assert( msg != NULL );
+
+ sscanf(msg, "%s %d", cmd, &action);
+
+ proto_send_event_server(PROTO_SEND_BUT, client, client->tux, action);
+
+ actionTux(client->tux, action);
+
+}
+
+void proto_send_newtux_server(int type, client_t *client, tux_t *tux)
+{
+ char msg[STR_PROTO_SIZE];
+ int x, y;
+
+ assert( tux != NULL );
+
+ if( tux->bonus == BONUS_HIDDEN )
+ {
+ x = TUX_LOCATE_UNKNOWN;
+ y = TUX_LOCATE_UNKNOWN;
+ }
+ else
+ {
+ x = tux->x;
+ y = tux->y;
+ }
+
+ sprintf(msg, "newtux %d %d %d %d %d %d %d %s %d %d %d %d %d %d %d %d %d %d %d\n",
+ tux->id ,x, y, tux->status, tux->position ,tux->frame, tux->score, tux->name,
+ tux->gun, tux->bonus, tux->shot[GUN_SIMPLE], tux->shot[GUN_DUAL_SIMPLE],
+ tux->shot[GUN_SCATTER], tux->shot[GUN_TOMMY], tux->shot[GUN_LASSER],
+ tux->shot[GUN_MINE], tux->shot[GUN_BOMBBALL],
+ tux->bonus_time, tux->pickup_time);
+
+ proto_send(type, client, msg);
+}
+
+#ifndef PUBLIC_SERVER
+
+void proto_recv_newtux_client(char *msg)
+{
+ char cmd[STR_PROTO_SIZE];
+ char name[STR_NAME_SIZE];
+ int id, x, y, status, position, frame, score;
+ int myGun, myBonus;
+ int gun1, gun2, gun3, gun4, gun5, gun6, gun7;
+ int time1, time2;
+ tux_t *tux;
+
+ assert( msg != NULL );
+
+ sscanf(msg, "%s %d %d %d %d %d %d %d %s %d %d %d %d %d %d %d %d %d %d %d",
+ cmd, &id, &x, &y, &status, &position, &frame, &score, name,
+ &myGun, &myBonus, &gun1, &gun2, &gun3, &gun4, &gun5, &gun6, &gun7, &time1, &time2);
+
+ tux = getTuxID(getCurrentArena()->listTux, id);
+
+ if( tux == NULL )
+ {
+ char term_msg[STR_SIZE];
+ sprintf(term_msg, "connect new client( id = %d)\n", id);
+ appendTextInTerm(term_msg);
+
+ tux = newTux();
+ tux->control = TUX_CONTROL_NET;
+ addList(getCurrentArena()->listTux, tux);
+ }
+
+ tux->id = id;
+
+ tux->x = x;
+ tux->y = y;
+ tux->status = status;
+ tux->position = position;
+ tux->frame = frame;
+ tux->score = score;
+ strcpy(tux->name, name);
+ tux->gun = myGun;
+ tux->bonus = myBonus;
+ tux->shot[GUN_SIMPLE] = gun1;
+ tux->shot[GUN_DUAL_SIMPLE] = gun2;
+ tux->shot[GUN_SCATTER] = gun3;
+ tux->shot[GUN_TOMMY] = gun4;
+ tux->shot[GUN_LASSER] = gun5;
+ tux->shot[GUN_MINE] = gun6;
+ tux->shot[GUN_BOMBBALL] = gun7;
+ tux->bonus_time = time1;
+ tux->pickup_time = time2;
+}
+
+#endif
+
+void proto_send_kill_server(int type, client_t *client, tux_t *tux)
+{
+ char msg[STR_PROTO_SIZE];
+
+ assert( tux != NULL );
+
+ sprintf(msg, "kill %d\n", tux->id);
+
+ proto_send(type, client, msg);
+}
+
+#ifndef PUBLIC_SERVER
+
+void proto_recv_kill_client(char *msg)
+{
+ char cmd[STR_PROTO_SIZE];
+ int id;
+ tux_t *tux;
+
+ assert( msg != NULL );
+
+ sscanf(msg, "%s %d", cmd, &id);
+
+ tux = getTuxID(getCurrentArena()->listTux, id);
+
+ if( tux != NULL )
+ {
+ eventTuxIsDead(tux);
+ }
+}
+
+#endif
+
+void proto_send_score_server(int type, client_t *client, tux_t *tux)
+{
+ char msg[STR_PROTO_SIZE];
+
+ assert( tux != NULL );
+
+ sprintf(msg, "score %d %d\n", tux->id, tux->score);
+
+ proto_send(type, client, msg);
+}
+
+#ifndef PUBLIC_SERVER
+
+void proto_recv_score_client(char *msg)
+{
+ char cmd[STR_PROTO_SIZE];
+ int id, score;
+ tux_t *tux;
+
+ assert( msg != NULL );
+
+ sscanf(msg, "%s %d %d", cmd, &id, &score);
+
+ tux = getTuxID(getCurrentArena()->listTux, id);
+
+ if( tux != NULL )
+ {
+ char term_msg[STR_SIZE];
+ sprintf(term_msg, "tux with id %d set score to %d\n", tux->id, score);
+ appendTextInTerm(term_msg);
+
+ tux->score = score;
+ }
+
+ countRoundInc();
+}
+
+#endif
+
+void proto_send_deltux_server(int type, client_t *client, client_t *client2)
+{
+ char msg[STR_PROTO_SIZE];
+
+ assert( client2 != NULL );
+
+ sprintf(msg, "deltux %d\n", client2->tux->id);
+
+ proto_send(type, client, msg);
+}
+
+#ifndef PUBLIC_SERVER
+
+void proto_recv_deltux_client(char *msg)
+{
+ char cmd[STR_PROTO_SIZE];
+ int id;
+ tux_t *tux;
+
+ assert( msg != NULL );
+
+ sscanf(msg, "%s %d", cmd, &id);
+
+ tux = getTuxID(getCurrentArena()->listTux, id);
+
+ if( tux != NULL )
+ {
+ char term_msg[STR_SIZE];
+ int index;
+
+ sprintf(term_msg, "tux with id %d is disconnect\n", tux->id);
+ appendTextInTerm(term_msg);
+
+ index = searchListItem(getCurrentArena()->listTux, tux);
+ delListItem(getCurrentArena()->listTux, index, destroyTux);
+ }
+}
+
+#endif
+
+void proto_send_additem_server(int type, client_t *client, item_t *p)
+{
+ char msg[STR_PROTO_SIZE];
+ int id = -1;
+
+ assert( p != NULL );
+
+ if( p->author != NULL )
+ {
+ id = p->author->id;
+ }
+
+ sprintf(msg, "additem %d %d %d %d %d %d %d\n",
+ p->id, p->type, p->x, p->y, p->count, p->frame, id);
+
+ proto_send(type, client, msg);
+}
+
+#ifndef PUBLIC_SERVER
+
+void proto_recv_additem_client(char *msg)
+{
+ char term_msg[STR_SIZE];
+ char cmd[STR_PROTO_SIZE];
+ int id, type, x, y, count, frame, author_id;
+ item_t *item;
+
+ assert( msg != NULL );
+
+ 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 )
+ {
+ return;
+ }
+
+ item = newItem(x, y, type, getTuxID(getCurrentArena()->listTux, author_id));
+/*
+ if( isConflictWithListItem(getCurrentArena()->listItem, item->x, item->y, item->w, item->h) )
+ {
+ destroyItem(item);
+ return;
+ }
+*/
+ item->id = id;
+ item->count = count;
+ item->frame = frame;
+
+ addList(getCurrentArena()->listItem, item);
+
+ sprintf(term_msg, "in arena is new item\n");
+ appendTextInTerm(term_msg);
+
+}
+
+#endif
+
+void proto_send_item_server(int type, client_t *client, tux_t *tux, item_t *item)
+{
+ char msg[STR_PROTO_SIZE];
+ int tux_id = -1;
+
+ assert( item != NULL );
+
+ if( tux != NULL )
+ {
+ tux_id = tux->id;
+ }
+
+ sprintf(msg, "item %d %d\n",
+ tux_id, item->id);
+
+ proto_send(type, client, msg);
+}
+
+#ifndef PUBLIC_SERVER
+
+void proto_recv_item_client(char *msg)
+{
+ char cmd[STR_PROTO_SIZE];
+ int tux_id, item_id;
+ arena_t *arena;
+
+ item_t *item;
+ tux_t *tux;
+
+ assert( msg != NULL );
+
+ sscanf(msg, "%s %d %d", cmd, &tux_id, &item_id);
+
+ arena = getCurrentArena();
+
+ item = getItemID(arena->listItem, item_id);
+ tux = getTuxID(arena->listTux, tux_id);
+
+ if( item == NULL)
+ {
+ return;
+ }
+
+ if( tux != NULL )
+ {
+ eventGiveTuxItem(tux, arena->listItem, item);
+ }
+ else
+ {
+ mineExplosion(arena->listItem, item);
+ }
+}
+
+#endif
+
+void proto_send_shot_server(int type, client_t *client, shot_t *p)
+{
+ char msg[STR_PROTO_SIZE];
+ int id = -1;
+
+ assert( p != NULL );
+
+ if( p->author != NULL )
+ {
+ id = p->author->id;
+ }
+
+ sprintf(msg, "shot %d %d %d %d %d %d %d %d\n",
+ p->x, p->y, p->px, p->py, p->position, p->gun, id, p->isCanKillAuthor);
+
+ proto_send(type, client, msg);
+}
+
+#ifndef PUBLIC_SERVER
+
+void proto_recv_shot_client(char *msg)
+{
+ char cmd[STR_PROTO_SIZE];
+ int x, y, px, py, position, gun, id, isCanKillAuthor;
+ shot_t *shot;
+
+ assert( msg != NULL );
+
+ sscanf(msg, "%s %d %d %d %d %d %d %d %d",
+ cmd, &x, &y, &px, &py, &position, &gun, &id, &isCanKillAuthor);
+
+ shot = newShot(x, y, px, py, gun, getTuxID(getCurrentArena()->listTux, id));
+
+ shot->isCanKillAuthor = isCanKillAuthor;
+ shot->position = position;
+
+ if( shot->gun == GUN_LASSER )
+ {
+ transformOnlyLasser(shot);
+ }
+
+ addList(getCurrentArena()->listShot, shot);
+}
+
+#endif
+
+#ifndef PUBLIC_SERVER
+
+void proto_send_ping_client()
+{
+ char msg[STR_PROTO_SIZE];
+ sprintf(msg, "ping %d\n", getMyTime());
+ sendServer(msg);
+}
+
+#endif
+
+void proto_recv_ping_server(client_t *client, char *msg)
+{
+ proto_send_ping_server(PROTO_SEND_ONE, client, msg);
+}
+
+void proto_send_ping_server(int type, client_t *client, char *msg)
+{
+ proto_send(type, client, msg);
+}
+
+#ifndef PUBLIC_SERVER
+
+void proto_recv_ping_client(char *msg)
+{
+ char cmd[STR_PROTO_SIZE];
+ my_time_t currentTime;
+ my_time_t time;
+
+ sscanf(msg, "%s %d", cmd, &time);
+
+ currentTime = getMyTime();
+ printf("lag = %d\n", (currentTime-time));
+ setLagServer((currentTime-time));
+}
+
+#endif
+
+void proto_send_end_server(int type, client_t *client)
+{
+ char msg[STR_PROTO_SIZE];
+ strcpy(msg, "end\n");
+ proto_send(type, client, msg);
+}
+
+#ifndef PUBLIC_SERVER
+
+void proto_recv_end_client(char *msg)
+{
+ assert( msg != NULL );
+
+ setWorldEnd();
+}
+
+#endif
+
+#ifndef PUBLIC_SERVER
+
+void proto_send_end_client()
+{
+ char msg[STR_PROTO_SIZE];
+ strcpy(msg, "end\n");
+ sendServer(msg);
+}
+
+#endif
+
+void proto_recv_end_server(client_t *client, char *msg)
+{
+ assert( msg != NULL );
+ assert( client != NULL );
+
+ client->status = NET_STATUS_ZOMBIE;
+}
+