summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authororoborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e>2008-07-01 20:46:04 +0000
committeroroborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e>2008-07-01 20:46:04 +0000
commit7a41e2f1d440f521660a251125cd064490164f60 (patch)
treeef7820b6cb16c9fd93f81aedd49cb5bc1223fb24
parent38b98c9ecd0c300d40ae6db05ab9dc2b9189df8d (diff)
- oprava chyby, ked mal tux bonus neviditelnost server aj tak odosielal vsetkym clientom spravu o jeho pohybe (
upravou clienta by sa z toho dalo vycitat kde sa nachadza ) - oprava chyby, v sietovej hre sa client zrutil vzdy ked dostal spravu o stielani z lassera. - oprava chyby, pri vybuch bombballu, program pristupoval do uvolnenej pamate - v protokole musi client checknut aj prikaz "init" - do stataus ptibudla polozka "name: [name]" nastavuje sa v server.conf ako "NAME [name]" ak nie je tak sa pouzije "noname" - z server.c boli odstraneny kod #ifdef SUPPORT_NET_SDL_UDP ... #endif git-svn-id: http://opensvn.csie.org/tuxanci_ng@82 0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e
-rw-r--r--config.h2
-rw-r--r--server.conf3
-rw-r--r--src/base/proto.c86
-rw-r--r--src/base/server.c212
-rw-r--r--src/base/shot.c16
-rw-r--r--src/base/tux.c4
-rw-r--r--src/screen/screen_world.c1
-rw-r--r--src/server/serverConfigFile.c1
8 files changed, 84 insertions, 241 deletions
diff --git a/config.h b/config.h
index 9bffa67..503d702 100644
--- a/config.h
+++ b/config.h
@@ -6,6 +6,6 @@
#define DEBUG_CLIENT_RECV
*/
-#define TUXANCI_NG_VERSION "svn81"
+#define TUXANCI_NG_VERSION "svn82"
#define DESTDIR "/usr/local/"
diff --git a/server.conf b/server.conf
index dbbf6a8..25c26fa 100644
--- a/server.conf
+++ b/server.conf
@@ -1,6 +1,7 @@
+NAME oroborus-gameserver
IP4 0.0.0.0
IP6 ::1
PORTv4 2200
PORTv6 2206
MAX_CLIENTS 32
-ARENA FAGN
+ARENA IACO8B
diff --git a/src/base/proto.c b/src/base/proto.c
index 52c9dd6..3936917 100644
--- a/src/base/proto.c
+++ b/src/base/proto.c
@@ -31,6 +31,7 @@
#ifdef PUBLIC_SERVER
#include "server/heightScore.h"
#include "server/publicServer.h"
+#include "server/serverConfigFile.h"
#endif
void proto_send_error_server(int type, client_t *client, int errorcode)
@@ -117,15 +118,36 @@ void proto_recv_hello_server(client_t *client, char *msg)
void proto_send_status_server(int type, client_t *client)
{
char msg[STR_PROTO_SIZE];
-
- sprintf(msg, "version: %s\n"
+ char *name;
+ char *version;
+ int clients;
+ int maxclients;
+ unsigned int uptime;
+ char *arena;
+
+#ifndef PUBLIC_SERVER
+ name = "noname";
+#endif
+
+#ifdef PUBLIC_SERVER
+ name = getServerConfigFileValue("NAME", "noname");
+#endif
+
+ version = TUXANCI_NG_VERSION;
+ clients = getCurrentArena()->spaceTux->list->count;
+ maxclients = getServerMaxClients();
+ uptime = (unsigned int)getUpdateServer();
+ arena = getArenaNetName( getChoiceArenaId() );
+
+ sprintf(msg, "name: %s\n"
+ "version: %s\n"
"clients: %d\n"
"maxclients: %d\n"
"uptime: %d\n"
"arena: %s\n",
- TUXANCI_NG_VERSION, getCurrentArena()->spaceTux->list->count,
- getServerMaxClients(), (unsigned int)getUpdateServer(),
- getArenaNetName( getChoiceArenaId() ) );
+
+ name, version, clients,
+ maxclients, uptime, arena);
protoSendClient(type, client, msg, CHECK_FORNT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE);
//proto_send(type, client, msg);
@@ -144,7 +166,7 @@ void proto_send_listscore_server(int type, client_t *client, int max)
char *msg;
int i;
- msg = malloc( (max * 24) * sizeof(char) );
+ msg = malloc( (max * 48) * sizeof(char) );
strcpy(msg, "");
for( i = 0 ; i < max ; i++ )
@@ -214,20 +236,25 @@ void proto_recv_check_server(client_t *client, char *msg)
void proto_send_init_server(int type, client_t *client, client_t *client2)
{
char msg[STR_PROTO_SIZE];
- int n = WORLD_COUNT_ROUND_UNLIMITED;
+ int count;
+ int check_id;
assert( client2 != NULL );
+ count = WORLD_COUNT_ROUND_UNLIMITED;
+
#ifndef PUBLIC_SERVER
- getSettingCountRound(&n);
+ getSettingCountRound(&count);
#endif
- sprintf(msg, "init %d %d %d %d %s\n",
+ check_id = getNewID();
+
+ sprintf(msg, "init %d %d %d %d %s %d\n",
client2->tux->id, client2->tux->x, client2->tux->y,
- n, getArenaNetName( getChoiceArenaId() ));
+ count, getArenaNetName( getChoiceArenaId() ), check_id);
//proto_send(type, client, msg);
- protoSendClient(type, client, msg, CHECK_FORNT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE);
+ protoSendClient(type, client, msg, CHECK_FORNT_TYPE_CHECK, check_id);
}
#ifndef PUBLIC_SERVER
@@ -239,11 +266,19 @@ void proto_recv_init_client(char *msg)
tux_t *tux;
int id;
int x, y, n;
+ int check_id;
assert( msg != NULL );
- sscanf(msg, "%s %d %d %d %d %s",
- cmd, &id, &x, &y, &n, arena_name);
+ sscanf(msg, "%s %d %d %d %d %s %d",
+ cmd, &id, &x, &y, &n, arena_name, &check_id);
+
+ proto_send_check_client(check_id);
+
+ if( getCurrentArena() != NULL )
+ {
+ return;
+ }
setWorldArena( getArenaIdFormNetName(arena_name) );
setMaxCountRound(n);
@@ -307,25 +342,6 @@ void proto_send_event_client(int action)
#endif
-/*
-static void debug_interval()
-{
- static my_time_t lastEvent = 0;
- my_time_t curentTime;
-
- if( lastEvent == 0 )
- {
- lastEvent = getMyTime();
- }
-
- curentTime = getMyTime();
-
- printf("time = %d\n", curentTime - lastEvent);
-
- lastEvent = getMyTime();
-}
-*/
-
void proto_recv_event_server(client_t *client, char *msg)
{
char cmd[STR_PROTO_SIZE];
@@ -338,9 +354,13 @@ void proto_recv_event_server(client_t *client, char *msg)
sscanf(msg, "%s %d", cmd, &action);
- proto_send_event_server(PROTO_SEND_ALL_SEES_TUX, client, client->tux, action);
+ if( client->tux->bonus != BONUS_HIDDEN )
+ {
+ proto_send_event_server(PROTO_SEND_ALL_SEES_TUX, client, client->tux, action);
+ }
refreshLastMove(client->protect);
+
actionTux(client->tux, action);
}
diff --git a/src/base/server.c b/src/base/server.c
index ae9f170..e91e85c 100644
--- a/src/base/server.c
+++ b/src/base/server.c
@@ -32,16 +32,10 @@
#include "server/heightScore.h"
#endif
-#ifdef SUPPORT_NET_UNIX_UDP
#include "net_unix/udp.h"
+
static sock_udp_t *sock_server_udp;
static sock_udp_t *sock_server_udp_second;
-#endif
-
-#ifdef SUPPORT_NET_SDL_UDP
-#include "net_sdl/sdl_udp.h"
-static sock_sdl_udp_t *sock_server_sdl_udp;
-#endif
static list_t *listClient;
static list_t *listServerTimer;
@@ -72,7 +66,6 @@ static void delZombieCLient(void *p_nothink)
if( isDown(thisClient->protect) == TRUE )
{
- //proto_send_error_server(PROTO_SEND_ONE, thisClient, PROTO_ERROR_CODE_TIMEOUT);
proto_send_end_server(PROTO_SEND_ONE, thisClient);
eventMsgInCheckFront(thisClient);
thisClient->status = NET_STATUS_ZOMBIE;
@@ -149,7 +142,8 @@ static void setServerTimer()
addTaskToTimer(listServerTimer, TIMER_PERIODIC, eventSendPingClients, NULL, SERVER_TIME_PING);
}
-void static initServer()
+
+static void initServer()
{
startUpdateServer();
listServerTimer = NULL;
@@ -158,7 +152,6 @@ void static initServer()
setServerTimer();
}
-#ifdef SUPPORT_NET_UNIX_UDP
int initUdpServer(char *ip, int port, int proto)
{
sock_server_udp = bindUdpSocket(ip, port, proto);
@@ -175,7 +168,6 @@ int initUdpServer(char *ip, int port, int proto)
return 0;
}
-#endif
#ifdef PUBLIC_SERVER
@@ -215,27 +207,15 @@ int initUdpPublicServer(char *ip4, int port4, char *ip6, int port6)
#endif
-#ifdef SUPPORT_NET_SDL_UDP
-int initSdlUdpServer(int port)
+client_t* newUdpClient(sock_udp_t *sock_udp)
{
- sock_server_sdl_udp = bindSdlUdpSocket(port);
-
- if( sock_server_sdl_udp == NULL )
- {
- return -1;
- }
-
- initServer();
-
- printf("server listen UDP port %d\n", port);
+ client_t *new;
+ char str_ip[STR_IP_SIZE];
- return 0;
-}
-#endif
+ assert( sock_udp != NULL );
-static client_t* newAnyClient()
-{
- client_t *new;
+ getSockUdpIp(sock_udp, str_ip, STR_IP_SIZE);
+ printf("new client from %s %d\n", str_ip, getSockUdpPort(sock_udp));
new = malloc( sizeof(client_t) );
memset(new, 0, sizeof(client_t));
@@ -244,42 +224,10 @@ static client_t* newAnyClient()
new->listRecvMsg = newList();
new->listSendMsg = newCheckFront();
new->protect = newProtect();
-
- return new;
-}
-
-#ifdef SUPPORT_NET_UNIX_UDP
-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 from %s %d\n", str_ip, getSockUdpPort(sock_udp));
-
- new = newAnyClient();
new->socket_udp = sock_udp;
return new;
}
-#endif
-
-#ifdef SUPPORT_NET_SDL_UDP
-client_t* newSdlUdpClient(sock_sdl_udp_t *sock_sdl_udp)
-{
- client_t *new;
-
- assert( sock_sdl_udp != NULL );
-
- printf("new client from %d\n", getSockSdlUdpPort(sock_sdl_udp));
- new = newAnyClient();
- new->socket_sdl_udp = sock_sdl_udp;
-
- return new;
-}
-#endif
void destroyClient(client_t *p)
{
@@ -289,18 +237,10 @@ void destroyClient(client_t *p)
eventMsgInCheckFront(p);
-#ifdef SUPPORT_NET_UNIX_UDP
getSockUdpIp(p->socket_udp, str_ip, STR_IP_SIZE);
printf("close connect %s %d\n", str_ip, getSockUdpPort(p->socket_udp) );
-#endif
-#ifdef SUPPORT_NET_UNIX_UDP
closeUdpSocket(p->socket_udp);
-#endif
-
-#ifdef SUPPORT_NET_SDL_UDP
- closeSdlUdpSocket(p->socket_sdl_udp);
-#endif
destroyListItem(p->listRecvMsg, free);
destroyCheckFront(p->listSendMsg);
@@ -349,7 +289,6 @@ void sendClient(client_t *p, char *msg)
}
#endif
-#ifdef SUPPORT_NET_UNIX_UDP
if( p->socket_udp->proto == PROTO_UDPv4 &&
sock_server_udp != NULL &&
sock_server_udp->proto == PROTO_UDPv4 )
@@ -370,11 +309,6 @@ void sendClient(client_t *p, char *msg)
{
ret = writeUdpSocket(sock_server_udp_second, p->socket_udp, msg, strlen(msg));
}
-#endif
-
-#ifdef SUPPORT_NET_SDL_UDP
- ret = writeSdlUdpSocket(sock_server_sdl_udp, p->socket_sdl_udp, msg, strlen(msg));
-#endif
}
}
@@ -537,8 +471,6 @@ void sendInfoCreateClient(client_t *client)
}
}
-#ifdef SUPPORT_NET_UNIX_UDP
-
static void eventCreateNewUdpClient(sock_udp_t *socket_udp)
{
client_t *client;
@@ -549,22 +481,6 @@ static void eventCreateNewUdpClient(sock_udp_t *socket_udp)
addList(listClient, client);
}
-#endif
-
-#ifdef SUPPORT_NET_SDL_UDP
-
-static void eventCreateNewSdlUdpClient(sock_sdl_udp_t *socket_sdl_udp)
-{
- client_t *client;
-
- assert( socket_sdl_udp != NULL );
-
- client = newSdlUdpClient( socket_sdl_udp );
- addList(listClient, client);
-}
-
-#endif
-
static void eventClientBuffer(client_t *client)
{
char *line;
@@ -574,7 +490,6 @@ static void eventClientBuffer(client_t *client)
/* obsluha udalosti od clientov */
- //while( getBufferLine(client->listRecvMsg, line, STR_PROTO_SIZE) >= 0 )
for( i = 0 ; i < client->listRecvMsg->count ; i++ )
{
line = (char *)client->listRecvMsg->list[i];
@@ -658,8 +573,6 @@ void eventClientListBuffer()
}
}
-#ifdef SUPPORT_NET_UNIX_UDP
-
static client_t* findUdpClient(sock_udp_t *sock_udp)
{
int i;
@@ -833,94 +746,12 @@ int selectServerUdpSocket()
return count;
}
-#endif
-
-#ifdef SUPPORT_NET_SDL_UDP
-
-static client_t* findSdlUdpClient(sock_sdl_udp_t *sock_sdl_udp)
-{
- int i;
- client_t *thisClient;
-
- for( i = 0 ; i < listClient->count; i++)
- {
- thisClient = (client_t *) listClient->list[i];
-
- if( getSockSdlUdpPort(thisClient->socket_sdl_udp) == getSockSdlUdpPort(sock_sdl_udp) )
- {
- return thisClient;
- }
- }
-
- return NULL;
-}
-
-void selectServerSdlUdpSocket()
-{
- sock_sdl_udp_t *sock_client;
- client_t *client;
- char listRecvMsg[STR_PROTO_SIZE];
- bool_t isCreateNewClient;
- int ret;
-
- assert( sock_server_sdl_udp != NULL );
-
- do{
- sock_client = newSdlSockUdp();
- isCreateNewClient = FALSE;
-
- memset(listRecvMsg, 0, STR_PROTO_SIZE);
-
- ret = readSdlUdpSocket(sock_server_sdl_udp, sock_client, listRecvMsg, STR_PROTO_SIZE-1);
-
- if( ret < 0 )
- {
- destroySockSdlUdp(sock_client);
- break;
- }
-
- client = findSdlUdpClient(sock_client);
-
- if( client == NULL )
- {
- eventCreateNewSdlUdpClient(sock_client);
- client = findSdlUdpClient(sock_client);
- isCreateNewClient = TRUE;
- }
-
- if( client == NULL )
- {
- fprintf(stderr, "Client total not found !\n");
- return;
- }
-
- if( isCreateNewClient == FALSE )
- {
- destroySockSdlUdp(sock_client);
- }
-
- if( ret <= 0 )
- {
- client->status = NET_STATUS_ZOMBIE;
- return;
- }
-
- addList(client->listRecvMsg, strdup(listRecvMsg) );
- }while( ret > 0 );
-}
-
-#endif
-
void eventServer()
{
#ifndef PUBLIC_SERVER
int count;
-#ifdef SUPPORT_NET_SDL_UDP
- selectServerSdlUdpSocket();
-#endif
-
#ifdef SUPPORT_NET_UNIX_UDP
do{
count = selectServerUdpSocket();
@@ -937,20 +768,13 @@ void eventServer()
eventTimer(listServerTimer);
}
-static void quitServer()
+void quitUdpServer()
{
proto_send_end_server(PROTO_SEND_ALL, NULL);
assert( listClient != NULL );
destroyListItem(listClient, destroyClient);
destroyTimer(listServerTimer);
-}
-
-#ifdef SUPPORT_NET_UNIX_UDP
-
-void quitUdpServer()
-{
- quitServer();
if( sock_server_udp != NULL )
{
@@ -966,19 +790,3 @@ void quitUdpServer()
printf("quit UDP port\n");
}
-
-#endif
-
-#ifdef SUPPORT_NET_SDL_UDP
-
-void quitSdlUdpServer()
-{
- quitServer();
-
- assert( sock_server_sdl_udp != NULL );
- closeSdlUdpSocket(sock_server_sdl_udp);
-
- printf("quit UDP port\n");
-}
-
-#endif
diff --git a/src/base/shot.c b/src/base/shot.c
index 9c0e33c..1858bc0 100644
--- a/src/base/shot.c
+++ b/src/base/shot.c
@@ -227,10 +227,19 @@ void boundBombBall(shot_t *shot)
void transformOnlyLasser(shot_t *shot)
{
space_t *space;
+ int mustRefesh = 0;
space = getCurrentArena()->spaceShot;
- delObjectFromSpace(space, shot);
+ if( getObjectFromSpaceWithID(space, shot->id) != NULL )
+ {
+ mustRefesh = 1;
+ }
+
+ if( mustRefesh )
+ {
+ delObjectFromSpace(space, shot);
+ }
switch( shot->position )
{
@@ -252,7 +261,10 @@ void transformOnlyLasser(shot_t *shot)
break;
}
- addObjectToSpace(space, shot);
+ if( mustRefesh)
+ {
+ addObjectToSpace(space, shot);
+ }
}
void eventMoveListShot(arena_t *arena)
diff --git a/src/base/tux.c b/src/base/tux.c
index 0c0717c..cd7cd4a 100644
--- a/src/base/tux.c
+++ b/src/base/tux.c
@@ -409,13 +409,13 @@ static void bombBallExplosion(shot_t *shot)
addObjectToSpace(getCurrentArena()->spaceItem, item );
- delObjectFromSpaceWithObject(getCurrentArena()->spaceShot, shot, destroyShot);
-
if( getNetTypeGame() == NET_GAME_TYPE_SERVER )
{
proto_send_del_server(PROTO_SEND_ALL, NULL, shot->id);
proto_send_additem_server(PROTO_SEND_ALL, NULL, item);
}
+
+ delObjectFromSpaceWithObject(getCurrentArena()->spaceShot, shot, destroyShot);
}
void eventConflictTuxWithShot(arena_t *arena)
diff --git a/src/screen/screen_world.c b/src/screen/screen_world.c
index 3c656f5..c758e06 100644
--- a/src/screen/screen_world.c
+++ b/src/screen/screen_world.c
@@ -126,6 +126,7 @@ void prepareArena()
tux_t *tux;
//printf("getSettingAI = %s\n", getSettingAI());
+ arena = NULL;
switch( getNetTypeGame() )
{
diff --git a/src/server/serverConfigFile.c b/src/server/serverConfigFile.c
index 7f03019..c6456ee 100644
--- a/src/server/serverConfigFile.c
+++ b/src/server/serverConfigFile.c
@@ -48,6 +48,7 @@ void initServerConfigFile()
prepareConfigFile(serverTextFile);
}
+
char* getServerConfigFileValue(char *env, char *s)
{
int i;