diff options
Diffstat (limited to 'src/base')
| -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 |
13 files changed, 261 insertions, 202 deletions
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); |