diff options
| -rw-r--r-- | config.h | 2 | ||||
| -rw-r--r-- | data/conf/server.conf | 15 | ||||
| -rw-r--r-- | src/CMakeLists.txt | 4 | ||||
| -rw-r--r-- | src/base/gun.c | 1 | ||||
| -rw-r--r-- | src/base/item.c | 1 | ||||
| -rw-r--r-- | src/base/proto.c | 62 | ||||
| -rw-r--r-- | src/base/proto.h | 5 | ||||
| -rw-r--r-- | src/base/server.c | 176 | ||||
| -rw-r--r-- | src/base/server.h | 2 | ||||
| -rw-r--r-- | src/base/serverSendMsg.c | 146 | ||||
| -rw-r--r-- | src/base/serverSendMsg.h | 15 | ||||
| -rw-r--r-- | src/base/shot.c | 1 | ||||
| -rw-r--r-- | src/base/string_length.h | 1 | ||||
| -rw-r--r-- | src/base/tcp_server.c | 26 | ||||
| -rw-r--r-- | src/base/tux.c | 1 | ||||
| -rw-r--r-- | src/base/udp_server.c | 26 | ||||
| -rw-r--r-- | src/client/chat.c | 1 | ||||
| -rwxr-xr-x | src/modules/modMove.c | 1 | ||||
| -rw-r--r-- | src/screen/screen_world.c | 1 | ||||
| -rw-r--r-- | src/server/heightScore.c | 1 | ||||
| -rw-r--r-- | src/server/log.c | 67 | ||||
| -rw-r--r-- | src/server/log.h | 15 | ||||
| -rw-r--r-- | src/server/publicServer.c | 21 | ||||
| -rw-r--r-- | src/server/serverConfigFile.c | 9 |
24 files changed, 382 insertions, 218 deletions
@@ -1 +1 @@ -#define TUXANCI_VERSION "svn187" +#define TUXANCI_VERSION "svn188" diff --git a/data/conf/server.conf b/data/conf/server.conf index 45ac0f4..329188b 100644 --- a/data/conf/server.conf +++ b/data/conf/server.conf @@ -1,11 +1,18 @@ -NAME oroborus gameserver +NAME defalt gameserver + IP4 0.0.0.0 -#IP6 ::1 -PORTv4 2200 -#PORTv6 2206 +IP6 ::1 + +PORT4 2200 +PORT6 2206 + MAX_CLIENTS 32 ARENA BAIACO8B ITEM 10 MAX_ITEM 10 +LOG_FILE tuxanci-server.log +SCORE_FILE height-score.txt + +SUPPORT_CLIENTS 0.20.0 svn188 svn187 svn186 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5d353dc..e931dc2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -3,7 +3,7 @@ SET ( WORKDIR ${CMAKE_SOURCE_DIR}/src ) # find ./ -maxdepth 1 -type f -name \*.c |grep "$" |sed -e 's/^\.\//\$\{WORKDIR\}\/DIR\//' -e 's/\.c//' |tr '\n' ' ' > DIRfiles # nahradte DIR potrebnym adresarem a pak vemte vse co je v DIRfiles a vlozte to sem SET ( SRC_base -${WORKDIR}/base/main ${WORKDIR}/base/shot ${WORKDIR}/base/space ${WORKDIR}/base/checkFront ${WORKDIR}/base/storage ${WORKDIR}/base/myTimer ${WORKDIR}/base/protect ${WORKDIR}/base/list ${WORKDIR}/base/arena ${WORKDIR}/base/server ${WORKDIR}/base/udp_server ${WORKDIR}/base/tcp_server ${WORKDIR}/base/serverSelect ${WORKDIR}/base/textFile ${WORKDIR}/base/gun ${WORKDIR}/base/arenaFile ${WORKDIR}/base/modules ${WORKDIR}/base/net_multiplayer ${WORKDIR}/base/index ${WORKDIR}/base/item ${WORKDIR}/base/tux ${WORKDIR}/base/director ${WORKDIR}/base/idManager ${WORKDIR}/base/homeDirector ${WORKDIR}/base/proto ${WORKDIR}/base/exportFunction ${WORKDIR}/base/buffer +${WORKDIR}/base/main ${WORKDIR}/base/shot ${WORKDIR}/base/space ${WORKDIR}/base/checkFront ${WORKDIR}/base/storage ${WORKDIR}/base/myTimer ${WORKDIR}/base/protect ${WORKDIR}/base/list ${WORKDIR}/base/arena ${WORKDIR}/base/server ${WORKDIR}/base/udp_server ${WORKDIR}/base/tcp_server ${WORKDIR}/base/serverSelect ${WORKDIR}/base/serverSendMsg ${WORKDIR}/base/textFile ${WORKDIR}/base/gun ${WORKDIR}/base/arenaFile ${WORKDIR}/base/modules ${WORKDIR}/base/net_multiplayer ${WORKDIR}/base/index ${WORKDIR}/base/item ${WORKDIR}/base/tux ${WORKDIR}/base/director ${WORKDIR}/base/idManager ${WORKDIR}/base/homeDirector ${WORKDIR}/base/proto ${WORKDIR}/base/exportFunction ${WORKDIR}/base/buffer ${WORKDIR}/net/udp ${WORKDIR}/net/tcp ${WORKDIR}/net/dns ) @@ -19,7 +19,7 @@ ${WORKDIR}/widget/widget_check ${WORKDIR}/widget/widget_button ${WORKDIR}/widget SET ( SRC_audio ${WORKDIR}/audio/audio ${WORKDIR}/audio/music ${WORKDIR}/audio/sound) SET ( SRC_server -${WORKDIR}/server/logFile ${WORKDIR}/server/serverConfigFile ${WORKDIR}/server/heightScore ${WORKDIR}/server/publicServer +${WORKDIR}/server/log ${WORKDIR}/server/serverConfigFile ${WORKDIR}/server/heightScore ${WORKDIR}/server/publicServer ) ADD_DEFINITIONS ( -DSUPPORT_NET_UNIX_UDP ) #ADD_DEFINITIONS ( -DZZEEXX86_READKEY ) diff --git a/src/base/gun.c b/src/base/gun.c index 45234af..8befcbb 100644 --- a/src/base/gun.c +++ b/src/base/gun.c @@ -12,6 +12,7 @@ #include "gun.h" #include "proto.h" #include "net_multiplayer.h" +#include "serverSendMsg.h" #ifndef NO_SOUND #include "sound.h" diff --git a/src/base/item.c b/src/base/item.c index 141240b..0eb70c3 100644 --- a/src/base/item.c +++ b/src/base/item.c @@ -10,6 +10,7 @@ #include "proto.h" #include "idManager.h" #include "net_multiplayer.h" +#include "serverSendMsg.h" #ifndef PUBLIC_SERVER diff --git a/src/base/proto.c b/src/base/proto.c index e95ca4e..25bcb61 100644 --- a/src/base/proto.c +++ b/src/base/proto.c @@ -18,6 +18,7 @@ #include "idManager.h" #include "modules.h" #include "protect.h" +#include "serverSendMsg.h" #ifndef PUBLIC_SERVER #include "language.h" @@ -83,20 +84,73 @@ void proto_send_hello_client(char *name) #endif +static void sendInfoCreateClient(client_t *client) +{ + list_t *listClient; + client_t *thisClient; + tux_t *thisTux; + item_t *thisItem; + int i; + + assert( client != NULL ); + + listClient = getListServerClient(); + + proto_send_init_server(PROTO_SEND_ONE, client, client); + +#ifndef PUBLIC_SERVER + proto_send_newtux_server(PROTO_SEND_ONE, client, getControlTux(TUX_CONTROL_KEYBOARD_RIGHT) ); +#endif + + for( i = 0 ; i < listClient->count; i++) + { + thisClient = (client_t *) listClient->list[i]; + thisTux = thisClient->tux; + + if( thisTux != NULL && thisTux != client->tux ) + { + proto_send_newtux_server(PROTO_SEND_ONE, thisClient, client->tux); + proto_send_newtux_server(PROTO_SEND_ONE, client, thisTux); + } + } + + for( i = 0 ; i < getCurrentArena()->spaceItem->list->count; i++) + { + thisItem = (item_t *) getCurrentArena()->spaceItem->list->list[i]; + proto_send_additem_server(PROTO_SEND_ONE, client, thisItem); + } +} + void proto_recv_hello_server(client_t *client, char *msg) { + static char *supportVersion = NULL; char cmd[STR_PROTO_SIZE]; char version[STR_NAME_SIZE]; char name[STR_NAME_SIZE]; - + assert( client != NULL ); strcpy(version, ""); strcpy(name, ""); +#ifdef PUBLIC_SERVER + if( supportVersion == NULL ) + { + supportVersion = getSetting("SUPPORT_CLIENTS", "--support-clients", TUXANCI_VERSION); + } +#endif + +#ifndef PUBLIC_SERVER + if( supportVersion == NULL ) + { + supportVersion = TUXANCI_VERSION; + } +#endif + sscanf(msg, "%s %s %s", cmd, version, name); - - if( strncmp(version, TUXANCI_VERSION, strlen(TUXANCI_VERSION)) != 0 ) + + + if( strstr(supportVersion, version ) == NULL ) { proto_send_error_server(PROTO_SEND_ONE, client, PROTO_ERROR_CODE_BAD_VERSION); eventMsgInCheckFront(client); @@ -134,7 +188,7 @@ void proto_send_status_server(int type, client_t *client) #endif #ifdef PUBLIC_SERVER - name = getServerConfigFileValue("NAME", "noname"); + name = getSetting("NAME", "--name", "noname"); #endif version = TUXANCI_VERSION; diff --git a/src/base/proto.h b/src/base/proto.h index b7f198b..c746393 100644 --- a/src/base/proto.h +++ b/src/base/proto.h @@ -29,11 +29,6 @@ #include "publicServer.h" #endif -#define PROTO_SEND_ONE 0 -#define PROTO_SEND_ALL 1 -#define PROTO_SEND_BUT 3 -#define PROTO_SEND_ALL_SEES_TUX 4 - #define PROTO_ERROR_CODE_UNKNOWN 0 #define PROTO_ERROR_CODE_BAD_VERSION 1 #define PROTO_ERROR_CODE_BAD_NAME 2 diff --git a/src/base/server.c b/src/base/server.c index fe01b5f..ad057a2 100644 --- a/src/base/server.c +++ b/src/base/server.c @@ -31,6 +31,7 @@ #include "protect.h" #include "index.h" #include "serverSelect.h" +#include "serverSendMsg.h" #ifndef PUBLIC_SERVER #include "screen_world.h" @@ -47,20 +48,6 @@ static list_t *listServerTimer; static time_t timeUpdate; static int maxClients; -/* - TRAFFIC - - za 5 sekund : - - up : COUNT_PLAYERS * ( COUNT_PLAYERS - 1 ) * 1KB - down : COUNT_PLAYERS * 0.2KB - - za 1 sekund : - - up : COUNT_PLAYERS * ( COUNT_PLAYERS - 1 ) * 1/5 KB - down : COUNT_PLAYERS * 1/25 KB -*/ - typedef struct proto_cmd_server_struct { char *name; @@ -344,167 +331,6 @@ void sendClient(client_t *p, char *msg) } } -static void addMsgClient(client_t *p, char *msg, int type, int id) -{ - assert( p != NULL ); - assert( msg != NULL ); - - if( p->status != NET_STATUS_ZOMBIE ) - { - addMsgInCheckFront(p->listSendMsg, msg, type, id); - } -} - -static void addMsgAllClientBut(char *msg, client_t *p, int type, int id) -{ - client_t *thisClient; - int i; - - assert( msg != NULL ); - - for( i = 0 ; i < listClient->count; i++) - { - thisClient = (client_t *) listClient->list[i]; - - if( thisClient->tux != NULL && thisClient != p ) - { - addMsgClient(thisClient, msg, type, id); - } - } -} - -static void addMsgAllClient(char *msg, int type, int id) -{ - assert( msg != NULL ); - - addMsgAllClientBut(msg, NULL, type, id); -} - -static void addMsgAllClientSeesTux(char *msg, tux_t *tux, int type, int id) -{ - list_t *listHelp; - arena_t *arena; - space_t *space; - int x, y, w, h; - int i; - - assert( msg != NULL ); - - arena = getCurrentArena(); - space = arena->spaceTux; - - x = tux->x - WINDOW_SIZE_X; - y = tux->y - WINDOW_SIZE_Y; - - w = 2 * WINDOW_SIZE_X; - h = 2 * WINDOW_SIZE_Y; - - if( x < 0 )x = 0; - if( y < 0 )y = 0; - if( w+x >= arena->w )w = arena->w - (x+1); - if( h+y >= arena->h )h = arena->h - (y+1); - - listHelp = newList(); - - getObjectFromSpace(space, x, y, w, h, listHelp); - //printf("%d %d %d %d %d\n", x, y, w, h, listHelp->count); - - for( i = 0 ; i < listHelp->count ; i++ ) - { - tux_t *thisTux; - client_t *thisClient; - - thisTux = (tux_t *)listHelp->list[i]; - - if( thisTux == tux ) - { - continue; - } - - thisClient = thisTux->client; - - if( thisClient != NULL ) - { - addMsgClient(thisClient, msg, type, id); - } - } - - destroyList(listHelp); -} - -void protoSendClient(int type, client_t *client, char *msg, int type2, int id) -{ - assert( msg != NULL ); - - switch( type ) - { - case PROTO_SEND_ONE : - assert( client != NULL ); - addMsgClient(client, msg, type2, id); - break; - case PROTO_SEND_ALL : - assert( client == NULL ); - addMsgAllClient(msg, type2, id); - break; - case PROTO_SEND_BUT : - assert( client != NULL ); - addMsgAllClientBut(msg, client, type2, id); - break; - case PROTO_SEND_ALL_SEES_TUX : -#ifndef PUBLIC_SERVER - if( client != NULL ) - { - addMsgAllClientSeesTux(msg, client->tux, type2, id); - } - else - { - addMsgAllClientSeesTux(msg, getControlTux(TUX_CONTROL_KEYBOARD_RIGHT), type2, id); - } -#endif -#ifdef PUBLIC_SERVER - addMsgAllClientSeesTux(msg, client->tux, type2, id); -#endif - break; - default : - assert( ! "Premenna type ma zlu hodnotu !" ); - break; - } -} - -void sendInfoCreateClient(client_t *client) -{ - client_t *thisClient; - tux_t *thisTux; - item_t *thisItem; - int i; - - assert( client != NULL ); - - proto_send_init_server(PROTO_SEND_ONE, client, client); - -#ifndef PUBLIC_SERVER - proto_send_newtux_server(PROTO_SEND_ONE, client, getControlTux(TUX_CONTROL_KEYBOARD_RIGHT) ); -#endif - - for( i = 0 ; i < listClient->count; i++) - { - thisClient = (client_t *) listClient->list[i]; - thisTux = thisClient->tux; - - if( thisTux != NULL && thisTux != client->tux ) - { - proto_send_newtux_server(PROTO_SEND_ONE, thisClient, client->tux); - proto_send_newtux_server(PROTO_SEND_ONE, client, thisTux); - } - } - - for( i = 0 ; i < getCurrentArena()->spaceItem->list->count; i++) - { - thisItem = (item_t *) getCurrentArena()->spaceItem->list->list[i]; - proto_send_additem_server(PROTO_SEND_ONE, client, thisItem); - } -} - static void eventClientBuffer(client_t *client) { proto_cmd_server_t* protoCmd; diff --git a/src/base/server.h b/src/base/server.h index 0e5ed6b..2e731a7 100644 --- a/src/base/server.h +++ b/src/base/server.h @@ -55,9 +55,7 @@ extern list_t* getListServerClient(); extern int getServerMaxClients(); extern void setServerTimer(); extern void setServerMaxClients(int n); -extern void sendInfoCreateClient(client_t *client); extern void sendClient(client_t *p, char *msg); -extern void protoSendClient(int type, client_t *client, char *msg, int type2, int id); extern void eventServer(); extern void quitServer(); diff --git a/src/base/serverSendMsg.c b/src/base/serverSendMsg.c new file mode 100644 index 0000000..772469b --- /dev/null +++ b/src/base/serverSendMsg.c @@ -0,0 +1,146 @@ + +#include <unistd.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <assert.h> + +#include "server.h" +#include "net_multiplayer.h" +#include "checkFront.h" +#include "serverSendMsg.h" + +#ifndef PUBLIC_SERVER +#include "screen_world.h" +#endif + +static void addMsgClient(client_t *p, char *msg, int type, int id) +{ + assert( p != NULL ); + assert( msg != NULL ); + + if( p->status != NET_STATUS_ZOMBIE ) + { + addMsgInCheckFront(p->listSendMsg, msg, type, id); + } +} + +static void addMsgAllClientBut(char *msg, client_t *p, int type, int id) +{ + list_t *listClient; + client_t *thisClient; + int i; + + assert( msg != NULL ); + + listClient = getListServerClient(); + + for( i = 0 ; i < listClient->count; i++) + { + thisClient = (client_t *) listClient->list[i]; + + if( thisClient->tux != NULL && thisClient != p ) + { + addMsgClient(thisClient, msg, type, id); + } + } +} + +static void addMsgAllClient(char *msg, int type, int id) +{ + assert( msg != NULL ); + + addMsgAllClientBut(msg, NULL, type, id); +} + +static void addMsgAllClientSeesTux(char *msg, tux_t *tux, int type, int id) +{ + list_t *listHelp; + arena_t *arena; + space_t *space; + int x, y, w, h; + int i; + + assert( msg != NULL ); + + arena = getCurrentArena(); + space = arena->spaceTux; + + x = tux->x - WINDOW_SIZE_X; + y = tux->y - WINDOW_SIZE_Y; + + w = 2 * WINDOW_SIZE_X; + h = 2 * WINDOW_SIZE_Y; + + if( x < 0 )x = 0; + if( y < 0 )y = 0; + if( w+x >= arena->w )w = arena->w - (x+1); + if( h+y >= arena->h )h = arena->h - (y+1); + + listHelp = newList(); + + getObjectFromSpace(space, x, y, w, h, listHelp); + //printf("%d %d %d %d %d\n", x, y, w, h, listHelp->count); + + for( i = 0 ; i < listHelp->count ; i++ ) + { + tux_t *thisTux; + client_t *thisClient; + + thisTux = (tux_t *)listHelp->list[i]; + + if( thisTux == tux ) + { + continue; + } + + thisClient = thisTux->client; + + if( thisClient != NULL ) + { + addMsgClient(thisClient, msg, type, id); + } + } + + destroyList(listHelp); +} + +void protoSendClient(int type, client_t *client, char *msg, int type2, int id) +{ + assert( msg != NULL ); + + switch( type ) + { + case PROTO_SEND_ONE : + assert( client != NULL ); + addMsgClient(client, msg, type2, id); + break; + case PROTO_SEND_ALL : + assert( client == NULL ); + addMsgAllClient(msg, type2, id); + break; + case PROTO_SEND_BUT : + assert( client != NULL ); + addMsgAllClientBut(msg, client, type2, id); + break; + case PROTO_SEND_ALL_SEES_TUX : +#ifndef PUBLIC_SERVER + if( client != NULL ) + { + addMsgAllClientSeesTux(msg, client->tux, type2, id); + } + else + { + addMsgAllClientSeesTux(msg, getControlTux(TUX_CONTROL_KEYBOARD_RIGHT), type2, id); + } +#endif +#ifdef PUBLIC_SERVER + addMsgAllClientSeesTux(msg, client->tux, type2, id); +#endif + break; + default : + assert( ! "Premenna type ma zlu hodnotu !" ); + break; + } +} + diff --git a/src/base/serverSendMsg.h b/src/base/serverSendMsg.h new file mode 100644 index 0000000..49da067 --- /dev/null +++ b/src/base/serverSendMsg.h @@ -0,0 +1,15 @@ + +#ifndef SERVER_SEND_MSG_H + +#define SERVER_SEND_MSG_H + +#include "server.h" + +#define PROTO_SEND_ONE 0 +#define PROTO_SEND_ALL 1 +#define PROTO_SEND_BUT 3 +#define PROTO_SEND_ALL_SEES_TUX 4 + +extern void protoSendClient(int type, client_t *client, char *msg, int type2, int id); + +#endif diff --git a/src/base/shot.c b/src/base/shot.c index 463796a..c5cbc05 100644 --- a/src/base/shot.c +++ b/src/base/shot.c @@ -9,6 +9,7 @@ #include "net_multiplayer.h" #include "proto.h" #include "idManager.h" +#include "serverSendMsg.h" #ifndef PUBLIC_SERVER #include "image.h" diff --git a/src/base/string_length.h b/src/base/string_length.h index b1712ee..7a8ab04 100644 --- a/src/base/string_length.h +++ b/src/base/string_length.h @@ -7,6 +7,7 @@ #define STR_SIZE 128 #define STR_PROTO_SIZE 128 +#define STR_LOG_SIZE 256 #define STR_NUM_SIZE 8 #define STR_NAME_SIZE 32 #define STR_PATH_SIZE 4096 diff --git a/src/base/tcp_server.c b/src/base/tcp_server.c index b201235..01a7b17 100644 --- a/src/base/tcp_server.c +++ b/src/base/tcp_server.c @@ -36,6 +36,7 @@ #ifdef PUBLIC_SERVER #include "publicServer.h" #include "heightScore.h" +#include "log.h" #endif #include "tcp.h" @@ -48,29 +49,38 @@ static sock_tcp_t *sock_server_tcp_second; 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, STR_IP_SIZE); - printf("new client TCP from %s %d\n", str_ip, getSockTcpPort(sock_tcp)); - - new = newAnyClient(); + new = newAnyClient(); new->type = CLIENT_TYPE_TCP; new->socket_tcp = sock_tcp; new->buffer = newBuffer(4096); +#ifdef PUBLIC_SERVER + char str_log[STR_LOG_SIZE]; + char str_ip[STR_IP_SIZE]; + + getSockTcpIp(sock_tcp, str_ip, STR_IP_SIZE); + sprintf(str_log, "new client TCP from %s %d", str_ip, getSockTcpPort(sock_tcp)); + addToLog(LOG_INF, str_log); +#endif + return new; } void destroyTcpClient(client_t *p) { - char str_ip[STR_IP_SIZE]; - eventMsgInCheckFront(p); +#ifdef PUBLIC_SERVER + char str_log[STR_LOG_SIZE]; + char str_ip[STR_IP_SIZE]; + getSockTcpIp(p->socket_tcp, str_ip, STR_IP_SIZE); - printf("close TCP connect %s %d\n", str_ip, getSockTcpPort(p->socket_tcp) ); + sprintf(str_log, "close TCP connect %s %d", str_ip, getSockTcpPort(p->socket_tcp)); + addToLog(LOG_INF, str_log); +#endif closeTcpSocket(p->socket_tcp); destroyBuffer(p->buffer); diff --git a/src/base/tux.c b/src/base/tux.c index 6823452..75b6c03 100644 --- a/src/base/tux.c +++ b/src/base/tux.c @@ -16,6 +16,7 @@ #include "proto.h" #include "modules.h" #include "idManager.h" +#include "serverSendMsg.h" #ifndef PUBLIC_SERVER #include "font.h" diff --git a/src/base/udp_server.c b/src/base/udp_server.c index 63a24ea..e534975 100644 --- a/src/base/udp_server.c +++ b/src/base/udp_server.c @@ -36,6 +36,7 @@ #ifdef PUBLIC_SERVER #include "publicServer.h" #include "heightScore.h" +#include "log.h" #endif #include "udp.h" @@ -48,28 +49,37 @@ static sock_udp_t *sock_server_udp_second; client_t* newUdpClient(sock_udp_t *sock_udp) { client_t *new; - char str_ip[STR_IP_SIZE]; assert( sock_udp != NULL ); - getSockUdpIp(sock_udp, str_ip, STR_IP_SIZE); - printf("new client UDP from %s %d\n", str_ip, getSockUdpPort(sock_udp)); - - new = newAnyClient(); + new = newAnyClient(); new->type = CLIENT_TYPE_UDP; new->socket_udp = sock_udp; +#ifdef PUBLIC_SERVER + char str_log[STR_LOG_SIZE]; + char str_ip[STR_IP_SIZE]; + + getSockUdpIp(sock_udp, str_ip, STR_IP_SIZE); + sprintf(str_log, "new client UDP from %s %d", str_ip, getSockUdpPort(sock_udp)); + addToLog(LOG_INF, str_log); +#endif + return new; } void destroyUdpClient(client_t *p) { - char str_ip[STR_IP_SIZE]; - eventMsgInCheckFront(p); +#ifdef PUBLIC_SERVER + char str_log[STR_LOG_SIZE]; + char str_ip[STR_IP_SIZE]; + getSockUdpIp(p->socket_udp, str_ip, STR_IP_SIZE); - printf("close UDP connect %s %d\n", str_ip, getSockUdpPort(p->socket_udp) ); + sprintf(str_log, "close UDP connect %s %d", str_ip, getSockUdpPort(p->socket_udp)); + addToLog(LOG_INF, str_log); +#endif destroySockUdp(p->socket_udp); diff --git a/src/client/chat.c b/src/client/chat.c index a50af88..ade5452 100644 --- a/src/client/chat.c +++ b/src/client/chat.c @@ -13,6 +13,7 @@ #include "interface.h" #include "chat.h" #include "font.h" +#include "serverSendMsg.h" static image_t *g_chat; diff --git a/src/modules/modMove.c b/src/modules/modMove.c index dc51685..0f7c0d9 100755 --- a/src/modules/modMove.c +++ b/src/modules/modMove.c @@ -11,6 +11,7 @@ #include "list.h" #include "gun.h" #include "space.h" +#include "serverSendMsg.h" #ifndef PUBLIC_SERVER #include "interface.h" diff --git a/src/screen/screen_world.c b/src/screen/screen_world.c index 9e686b8..518128f 100644 --- a/src/screen/screen_world.c +++ b/src/screen/screen_world.c @@ -15,6 +15,7 @@ #include "proto.h" #include "modules.h" #include "idManager.h" +#include "serverSendMsg.h" #include "interface.h" #include "screen_settingKeys.h" diff --git a/src/server/heightScore.c b/src/server/heightScore.c index aebe4f2..e29fad7 100644 --- a/src/server/heightScore.c +++ b/src/server/heightScore.c @@ -25,6 +25,7 @@ void initHeightScore(char *file) } else { + printf("I use %s as scorefile\n", file); return; } diff --git a/src/server/log.c b/src/server/log.c new file mode 100644 index 0000000..cf58e0f --- /dev/null +++ b/src/server/log.c @@ -0,0 +1,67 @@ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/stat.h> +#include <time.h> +#include <assert.h> + +#include "log.h" +#include "main.h" + +static FILE *logFile; + +int initLog(char *name) +{ + logFile = fopen(name, "a"); + + if( logFile == NULL ) + { + printf("open file %s as log file failed !!!\n", name); + return -1; + } + + printf("I use %s as log file\n", name); + + addToLog(LOG_INF, "open log file"); + + return 0; +} + +void addToLog(int type, char *msg) +{ + char str[STR_LOG_SIZE]; + struct tm *tm_struct; + time_t currentTime; + char *str_type; + + currentTime = time(NULL); + tm_struct = localtime(¤tTime); + + switch( type ) + { + case LOG_INF : str_type = "INF"; break; + case LOG_DBG : str_type = "DBG"; break; + case LOG_WRN : str_type = "WRN"; break; + case LOG_ERR : str_type = "ERR"; break; + default : + assert( ! "Bad log type !" ); + break; + } + + sprintf(str, "(%02d-%02d-%02d %02d:%02d:%02d) %s %s\n", + 1900+tm_struct->tm_year, tm_struct->tm_mon, tm_struct->tm_mday, + tm_struct->tm_hour, tm_struct->tm_min, tm_struct->tm_sec, + str_type, msg); + + fprintf(logFile, str); + + fflush(logFile); +} + +void quitLog() +{ + addToLog(LOG_INF, "close log file"); + fclose(logFile); +} + diff --git a/src/server/log.h b/src/server/log.h new file mode 100644 index 0000000..af60911 --- /dev/null +++ b/src/server/log.h @@ -0,0 +1,15 @@ + +#ifndef LOG_H + +#define LOG_H + +#define LOG_INF 1 +#define LOG_DBG 2 +#define LOG_WRN 3 +#define LOG_ERR 4 + +extern int initLog(char *name); +extern void addToLog(int type, char *msg); +extern void quitLog(); + +#endif diff --git a/src/server/publicServer.c b/src/server/publicServer.c index 7d434d7..5b96dea 100644 --- a/src/server/publicServer.c +++ b/src/server/publicServer.c @@ -37,6 +37,7 @@ #include "publicServer.h" #include "serverConfigFile.h" #include "heightScore.h" +#include "log.h" #include "dns.h" @@ -167,7 +168,7 @@ static int registerPublicServer() register_head *head = (register_head *) str; head->cmd = 'p'; - head->port = atoi( getSetting("PORTv4", "--port", "2200") ); + head->port = atoi( getSetting("PORT4", "--port4", "2200") ); head->ip = 0; // TODO /* send request for server list */ @@ -225,8 +226,8 @@ static int initPublicServerNetwork() p_ip6 = NULL; } - port4 = atoi( getSetting("PORTv4", "--port", "2200") ); - port6 = atoi( getSetting("PORTv6", "--port", "2200") ); + port4 = atoi( getSetting("PORT4", "--port4", "2200") ); + port6 = atoi( getSetting("PORT6", "--port6", "2200") ); //ret = initNetMulitplayerPublicServer(p_ip4, port4, p_ip6, port6); @@ -247,7 +248,16 @@ int initPublicServer() initItem(); initShot(); initServerConfigFile(); - initHeightScore( getSetting("SCOREFILE", "--scorefile", "./heightscore") ); + + ret = initLog(getSetting("LOG_FILE", "--log-file", "/tmp/tuxanci-server.log") ); + + if( ret < 0 ) + { + fprintf(stderr, "I down open log file !\n"); + return -1; + } + + initHeightScore( getSetting("SCORE_FILE", "--score-file", "/tmp/heightscore") ); arenaId = getArenaIdFormNetName( getSetting("ARENA", "--arena", "FAGN") ); arena = getArena(arenaId); @@ -268,7 +278,7 @@ int initPublicServer() return -1; } - setServerMaxClients( atoi( getSetting("MAX_CLIENTS", "--maxclients", "32") )); + setServerMaxClients( atoi( getSetting("MAX_CLIENTS", "--max-clients", "32") )); if (registerPublicServer() < 0) { @@ -336,6 +346,7 @@ void quitPublicServer() quitModule(); quitListID(); quitHeightScore(); + quitLog(); exit(0); } diff --git a/src/server/serverConfigFile.c b/src/server/serverConfigFile.c index f50f2a9..31d3db3 100644 --- a/src/server/serverConfigFile.c +++ b/src/server/serverConfigFile.c @@ -32,14 +32,16 @@ static void prepareConfigFile(textFile_t *ts) } } } - } void initServerConfigFile() { - printf("load configuration form %s\n", SERVER_CONFIG); + char *configFile; + + configFile = getParamElse("--config-file", SERVER_CONFIG); + printf("load configuration from %s\n", getParamElse("--config-file", SERVER_CONFIG) ); - serverTextFile = loadTextFile(SERVER_CONFIG); + serverTextFile = loadTextFile(configFile); if( serverTextFile == NULL ) { @@ -48,7 +50,6 @@ void initServerConfigFile() } prepareConfigFile(serverTextFile); - } static char *findValue(char *s) |