summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authororoborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e>2008-06-26 19:57:20 +0000
committeroroborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e>2008-06-26 19:57:20 +0000
commite528950ac7a2d23512be2a06378525b00be74185 (patch)
tree27fc486408154bcf540cdc63a293bfaf51355169
parent3501cd8b1173f6c6d8c84f631734344252ebd31d (diff)
- oprava chyby, server s GUI bol niekedy pozadu, lebo spracoval iba jeden packet aj ked ich bolo viac
- jednodny subsystem na odosielanie packetov zo servera clientom ( checkFront.c sa pouziva aj na odosielaie sprav, ktorych prichod sa nemusi kontrolovat ) git-svn-id: http://opensvn.csie.org/tuxanci_ng@74 0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e
-rw-r--r--config.h4
-rw-r--r--include/checkFront.h6
-rw-r--r--include/server.h11
-rw-r--r--src/checkFront.c55
-rw-r--r--src/proto.c113
-rw-r--r--src/server.c139
6 files changed, 127 insertions, 201 deletions
diff --git a/config.h b/config.h
index 0e4edf8..ebf5323 100644
--- a/config.h
+++ b/config.h
@@ -6,9 +6,9 @@
#define DEBUG_CLIENT_RECV
*/
-#define TUXANCI_NG_VERSION "svn73"
+#define TUXANCI_NG_VERSION "svn74"
#define DESTDIR "/usr/local/"
#define SUPPORT_NET_UNIX_UDP
//#define SUPPORT_NET_SDL_UDP
-//#define PUBLIC_SERVER
+#define PUBLIC_SERVER
diff --git a/include/checkFront.h b/include/checkFront.h
index 84f6906..dde30f0 100644
--- a/include/checkFront.h
+++ b/include/checkFront.h
@@ -9,8 +9,12 @@
#define CHECK_FRONT_SEND_TIME_INTERVAL 100
#define CHECK_FRONT_MAX_COUNT_SEND 30
+#define CHECK_FRONT_ID_NONE -1
+#define CHECK_FORNT_TYPE_SIMPLE 1
+#define CHECK_FORNT_TYPE_CHECK 2
+
extern list_t* newCheckFront();
-extern void addMsgInCheckFront(list_t *list, char *msg, int id);
+extern void addMsgInCheckFront(list_t *list, char *msg, int type, int id);
extern void eventMsgInCheckFront(client_t *client);
extern void delMsgInCheckFront(list_t *listCheckFront, int id);
extern void destroyCheckFront(list_t *p);
diff --git a/include/server.h b/include/server.h
index 5942a78..f1abc8f 100644
--- a/include/server.h
+++ b/include/server.h
@@ -59,7 +59,7 @@ extern int initUdpPublicServer(char *ip4, int port4, char *ip6, int port6);
extern int initUdpServer(char *ip, int port, int proto);
extern int initUdpServerMultiProto(char *ip4, char *ip6, int port4, int port6);
extern client_t* newUdpClient(sock_udp_t *sock_udp);
-extern void selectServerUdpSocket();
+extern int selectServerUdpSocket();
extern void quitUdpServer();
#endif
@@ -78,14 +78,7 @@ extern int getServerMaxClients();
extern void setServerMaxClients(int n);
extern void sendClient(client_t *p, char *msg);
-extern void sendAllClientBut(char *msg, client_t *p);
-extern void sendAllClient(char *msg);
-extern void sendAllClientSeesTux(char *msg, tux_t *tux);
-
-extern void addMsgClient(client_t *p, char *msg, int id);
-extern void addMsgAllClientBut(char *msg, client_t *p, int id);
-extern void addMsgAllClient(char *msg, int id);
-extern void addMsgAllClientSeesTux(char *msg, tux_t *tux, int id);
+extern void protoSendClient(int type, client_t *client, char *msg, int type2, int id);
extern tux_t *getServerTux();
extern client_t *getClientFromTux(tux_t *tux);
diff --git a/src/checkFront.c b/src/checkFront.c
index 340a8d8..7baa4f2 100644
--- a/src/checkFront.c
+++ b/src/checkFront.c
@@ -17,9 +17,10 @@ typedef struct struct_checkfront_t
my_time_t time;
int id;
int count;
+ int type;
} checkfront_t;
-static checkfront_t* newCheck(char *s, int id)
+static checkfront_t* newCheck(char *s, int type, int id)
{
checkfront_t *new;
@@ -31,6 +32,7 @@ static checkfront_t* newCheck(char *s, int id)
new->msg = strdup(s);
new->time = getMyTime();
new->id = id;
+ new->type = type;
new->count = 0;
return new;
@@ -44,18 +46,16 @@ static void destroyCheck(checkfront_t *p)
free(p);
}
-
list_t* newCheckFront()
{
return newList();
}
-void addMsgInCheckFront(list_t *list, char *msg, int id)
+void addMsgInCheckFront(list_t *list, char *msg, int type, int id)
{
- addList(list, newCheck(msg, id) );
+ addList(list, newCheck(msg, type, id) );
}
-
void eventMsgInCheckFront(client_t *client)
{
my_time_t currentTime;
@@ -69,22 +69,37 @@ void eventMsgInCheckFront(client_t *client)
this = (checkfront_t *)client->listCheck->list[i];
- if( this->count == 0 || currentTime - this->time > CHECK_FRONT_SEND_TIME_INTERVAL )
- {
- sendClient(client, this->msg);
- this->time = currentTime;
- this->count++;
- }
-
- if( this->count > CHECK_FRONT_MAX_COUNT_SEND )
+ switch( this->type )
{
- if( isRegisterID(this->id) != -1 )
- {
- delID(this->id);
- }
-
- delListItem(client->listCheck, i, destroyCheck);
- i--;
+ case CHECK_FORNT_TYPE_SIMPLE :
+ sendClient(client, this->msg);
+ delListItem(client->listCheck, i, destroyCheck);
+ i--;
+ break;
+
+ case CHECK_FORNT_TYPE_CHECK :
+ if( this->count == 0 || currentTime - this->time > CHECK_FRONT_SEND_TIME_INTERVAL )
+ {
+ sendClient(client, this->msg);
+ this->time = currentTime;
+ this->count++;
+ }
+
+ if( this->count > CHECK_FRONT_MAX_COUNT_SEND )
+ {
+ if( isRegisterID(this->id) != -1 )
+ {
+ delID(this->id);
+ }
+
+ delListItem(client->listCheck, i, destroyCheck);
+ i--;
+ }
+ break;
+
+ default :
+ assert( ! "Zly typ !" );
+ break;
}
}
}
diff --git a/src/proto.c b/src/proto.c
index f33f74f..dd6aeeb 100644
--- a/src/proto.c
+++ b/src/proto.c
@@ -33,91 +33,13 @@
#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);
- break;
- case PROTO_SEND_ALL :
- assert( client == NULL );
- sendAllClient(msg);
- break;
- case PROTO_SEND_BUT :
- assert( client != NULL );
- sendAllClientBut(msg, client);
- break;
- case PROTO_SEND_ALL_SEES_TUX :
-#ifndef PUBLIC_SERVER
- if( client != NULL )
- {
- sendAllClientSeesTux(msg, client->tux);
- }
- else
- {
- sendAllClientSeesTux(msg, getControlTux(TUX_CONTROL_KEYBOARD_RIGHT));
- }
-#endif
-#ifdef PUBLIC_SERVER
- sendAllClientSeesTux(msg, client->tux);
-#endif
- break;
- default :
- assert( ! "Premenna type ma zlu hodnotu !" );
- break;
- }
-}
-
-static void proto_check(int type, client_t *client, char *msg, int id)
-{
- assert( msg != NULL );
-
- switch( type )
- {
- case PROTO_SEND_ONE :
- assert( client != NULL );
- addMsgClient(client, msg, id);
- break;
- case PROTO_SEND_ALL :
- assert( client == NULL );
- addMsgAllClient(msg, id);
- break;
- case PROTO_SEND_BUT :
- assert( client != NULL );
- addMsgAllClientBut(msg, client, id);
- break;
- case PROTO_SEND_ALL_SEES_TUX :
-#ifndef PUBLIC_SERVER
- if( client != NULL )
- {
- addMsgAllClientSeesTux(msg, client->tux, id);
- }
- else
- {
- addMsgAllClientSeesTux(msg, getControlTux(TUX_CONTROL_KEYBOARD_RIGHT), id);
- }
-#endif
-#ifdef PUBLIC_SERVER
- addMsgAllClientSeesTux(msg, client->tux, id);
-#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);
+ protoSendClient(type, client, msg, CHECK_FORNT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE);
}
#ifndef PUBLIC_SERVER
@@ -205,7 +127,8 @@ void proto_send_status_server(int type, client_t *client)
getServerMaxClients(), (unsigned int)getUpdateServer(),
getArenaNetName( getChoiceArenaId() ) );
- proto_send(type, client, msg);
+ protoSendClient(type, client, msg, CHECK_FORNT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE);
+ //proto_send(type, client, msg);
}
void proto_recv_status_server(client_t *client, char *msg)
@@ -237,7 +160,8 @@ void proto_send_listscore_server(int type, client_t *client, int max)
strcat(msg, "\n");
}
- proto_send(type, client, msg);
+ //proto_send(type, client, msg);
+ protoSendClient(type, client, msg, CHECK_FORNT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE);
free(msg);
}
@@ -302,7 +226,8 @@ void proto_send_init_server(int type, client_t *client, client_t *client2)
client2->tux->id, client2->tux->x, client2->tux->y,
n, getArenaNetName( getChoiceArenaId() ));
- proto_send(type, client, msg);
+ //proto_send(type, client, msg);
+ protoSendClient(type, client, msg, CHECK_FORNT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE);
}
#ifndef PUBLIC_SERVER
@@ -343,7 +268,8 @@ void proto_send_event_server(int type, client_t *client, tux_t *tux, int action)
sprintf(msg, "event %d %d\n", tux->id, action);
- proto_send(type, client, msg);
+ //proto_send(type, client, msg);
+ protoSendClient(type, client, msg, CHECK_FORNT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE);
}
#ifndef PUBLIC_SERVER
@@ -423,7 +349,8 @@ void proto_send_newtux_server(int type, client_t *client, tux_t *tux)
tux->shot[GUN_MINE], tux->shot[GUN_BOMBBALL],
tux->bonus_time, tux->pickup_time);
- proto_send(type, client, msg);
+ //proto_send(type, client, msg);
+ protoSendClient(type, client, msg, CHECK_FORNT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE);
}
#ifndef PUBLIC_SERVER
@@ -497,7 +424,8 @@ void proto_send_kill_server(int type, client_t *client, tux_t *tux)
sprintf(msg, "kill %d\n", tux->id);
- proto_send(type, client, msg);
+ //proto_send(type, client, msg);
+ protoSendClient(type, client, msg, CHECK_FORNT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE);
}
#ifndef PUBLIC_SERVER
@@ -532,7 +460,8 @@ void proto_send_del_server(int type, client_t *client, int id)
sprintf(msg, "del %d %d\n",
id, check_id);
- proto_check(type, client, msg, check_id);
+ protoSendClient(type, client, msg, CHECK_FORNT_TYPE_CHECK, check_id);
+ //proto_check(type, client, msg, check_id);
}
#ifndef PUBLIC_SERVER
@@ -600,7 +529,8 @@ void proto_send_additem_server(int type, client_t *client, item_t *p)
p->id, p->type, p->x, p->y, p->count, p->frame, p->author_id, check_id);
//proto_send(type, client, msg);
- proto_check(type, client, msg, check_id);
+ //proto_check(type, client, msg, check_id);
+ protoSendClient(type, client, msg, CHECK_FORNT_TYPE_CHECK, check_id);
}
#ifndef PUBLIC_SERVER
@@ -651,7 +581,8 @@ void proto_send_shot_server(int type, client_t *client, shot_t *p)
p->id, p->x, p->y, p->px, p->py, p->position, p->gun, p->author_id, p->isCanKillAuthor, check_id);
//proto_send(type, client, msg);
- proto_check(type, client, msg, check_id);
+ //proto_check(type, client, msg, check_id);
+ protoSendClient(type, client, msg, CHECK_FORNT_TYPE_CHECK, check_id);
}
#ifndef PUBLIC_SERVER
@@ -711,7 +642,8 @@ void proto_send_ping_server(int type, client_t *client)
{
char msg[STR_PROTO_SIZE];
sprintf(msg, "ping\n");
- proto_send(type, client, msg);
+ //proto_send(type, client, msg);
+ protoSendClient(type, client, msg, CHECK_FORNT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE);
}
#ifndef PUBLIC_SERVER
@@ -726,7 +658,8 @@ void proto_send_end_server(int type, client_t *client)
{
char msg[STR_PROTO_SIZE];
strcpy(msg, "end\n");
- proto_send(type, client, msg);
+ //proto_send(type, client, msg);
+ protoSendClient(type, client, msg, CHECK_FORNT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE);
}
#ifndef PUBLIC_SERVER
diff --git a/src/server.c b/src/server.c
index a85e9c3..d328d73 100644
--- a/src/server.c
+++ b/src/server.c
@@ -129,30 +129,11 @@ static void eventPeriodicSyncClient(void *p_nothink)
}
}
-/*
-static void eventPeriodicSyncSelfClient(void *p_nothink)
-{
- client_t *thisClient;
- int i;
-
- for( i = 0 ; i < listClient->count; i++)
- {
- thisClient = (client_t *) listClient->list[i];
-
- if( thisClient->tux != NULL )
- {
- proto_send_newtux_server(PROTO_SEND_ONE, thisClient, thisClient->tux);
- }
- }
-}
-*/
-
static void eventSendPingClients(void *p_nothink)
{
proto_send_ping_server(PROTO_SEND_ALL, NULL);
}
-
static void setServerTimer()
{
if( listServerTimer != NULL )
@@ -165,9 +146,7 @@ static void setServerTimer()
addTaskToTimer(listServerTimer, TIMER_PERIODIC, delZombieCLient, NULL, SERVER_TIMEOUT);
addTaskToTimer(listServerTimer, TIMER_PERIODIC, eventPeriodicSyncClient, NULL, SERVER_TIME_SYNC);
- //addTaskToTimer(listServerTimer, TIMER_PERIODIC, eventPeriodicSyncSelfClient, NULL, 5000);
addTaskToTimer(listServerTimer, TIMER_PERIODIC, eventSendPingClients, NULL, SERVER_TIME_PING);
-
}
void static initServer()
@@ -395,65 +374,18 @@ void sendClient(client_t *p, char *msg)
}
}
-void sendAllClientBut(char *msg, client_t *p)
-{
- 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 )
- {
- sendClient(thisClient, msg);
- }
- }
-}
-
-void sendAllClient(char *msg)
-{
- assert( msg != NULL );
-
- sendAllClientBut(msg, NULL);
-}
-
-void sendAllClientSeesTux(char *msg, tux_t *tux)
-{
- int i;
-
- assert( msg != NULL );
-
- for( i = 0 ; i < listClient->count ; i++ )
- {
- client_t *thisClient;
- tux_t *thisTux;
-
- thisClient = (client_t *)listClient->list[i];
- thisTux = (tux_t *)thisClient->tux;
-
- if( tux != thisTux &&
- isTuxSeesTux(thisTux, tux) )
- {
- sendClient(thisClient, msg);
- }
- }
-}
-
-void addMsgClient(client_t *p, char *msg, int id)
+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->listCheck, msg, id);
+ addMsgInCheckFront(p->listCheck, msg, type, id);
}
}
-void addMsgAllClientBut(char *msg, client_t *p, int id)
+static void addMsgAllClientBut(char *msg, client_t *p, int type, int id)
{
client_t *thisClient;
int i;
@@ -466,19 +398,19 @@ void addMsgAllClientBut(char *msg, client_t *p, int id)
if( thisClient->tux != NULL && thisClient != p )
{
- addMsgClient(thisClient, msg, id);
+ addMsgClient(thisClient, msg, type, id);
}
}
}
-void addMsgAllClient(char *msg, int id)
+static void addMsgAllClient(char *msg, int type, int id)
{
assert( msg != NULL );
- addMsgAllClientBut(msg, NULL, id);
+ addMsgAllClientBut(msg, NULL, type, id);
}
-void addMsgAllClientSeesTux(char *msg, tux_t *tux, int id)
+static void addMsgAllClientSeesTux(char *msg, tux_t *tux, int type, int id)
{
int i;
@@ -495,11 +427,50 @@ void addMsgAllClientSeesTux(char *msg, tux_t *tux, int id)
if( tux != thisTux &&
isTuxSeesTux(thisTux, tux) )
{
- addMsgClient(thisClient, msg, id);
+ addMsgClient(thisClient, msg, type, id);
}
}
}
+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;
+ }
+}
+
tux_t *getServerTux()
{
return NULL;
@@ -750,13 +721,14 @@ static void eventClientUdpSelect(sock_udp_t *sock_server)
addList(client->buffer, strdup(buffer) );
}
-void selectServerUdpSocket()
+int selectServerUdpSocket()
{
struct timeval tv;
fd_set readfds;
fd_set errorfds;
int max_fd;
int ret;
+ int count;
#ifndef PUBLIC_SERVER
tv.tv_sec = 0;
@@ -772,6 +744,7 @@ void selectServerUdpSocket()
FD_ZERO(&errorfds);
max_fd = 0;
+ count = 0;
if( sock_server_udp != NULL )
{
@@ -810,7 +783,7 @@ void selectServerUdpSocket()
if( ret < 0 )
{
//printf("select ret = %d\n", ret);
- return;
+ return 0;
}
if( sock_server_udp != NULL )
@@ -818,6 +791,7 @@ void selectServerUdpSocket()
if( FD_ISSET(sock_server_udp->sock, &readfds) )
{
eventClientUdpSelect(sock_server_udp);
+ count = 1;
}
if( FD_ISSET(sock_server_udp->sock, &errorfds) )
@@ -831,6 +805,7 @@ void selectServerUdpSocket()
if( FD_ISSET(sock_server_udp_second->sock, &readfds) )
{
eventClientUdpSelect(sock_server_udp_second);
+ count = 1;
}
if( FD_ISSET(sock_server_udp_second->sock, &errorfds) )
@@ -838,6 +813,8 @@ void selectServerUdpSocket()
printf("error\n");
}
}
+
+ return count;
}
#endif
@@ -920,12 +897,16 @@ void selectServerSdlUdpSocket()
void eventServer()
{
+ int count;
+
#ifdef SUPPORT_NET_SDL_UDP
selectServerSdlUdpSocket();
#endif
#ifdef SUPPORT_NET_UNIX_UDP
- selectServerUdpSocket();
+ do{
+ count = selectServerUdpSocket();
+ }while( count > 0 );
#endif
eventClientListBuffer();