summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/base/server.c47
-rw-r--r--src/client/client.c93
2 files changed, 113 insertions, 27 deletions
diff --git a/src/base/server.c b/src/base/server.c
index 818999c..1acdbac 100644
--- a/src/base/server.c
+++ b/src/base/server.c
@@ -22,8 +22,6 @@
#include "tux.h"
#include "proto.h"
#include "server.h"
-#include "udp_server.h"
-#include "tcp_server.h"
#include "myTimer.h"
#include "arena.h"
#include "net_multiplayer.h"
@@ -42,6 +40,14 @@
#include "heightScore.h"
#endif
+#ifdef SUPPORT_UDP
+#include "udp_server.h"
+#endif
+
+#ifdef SUPPORT_TCP
+#include "tcp_server.h"
+#endif
+
static list_t *listClient;
static list_t *listServerTimer;
@@ -152,12 +158,17 @@ static void destroyUdpOrTcpClient(client_t *client)
{
switch( client->type )
{
+#ifdef SUPPORT_UDP
case CLIENT_TYPE_UDP :
destroyUdpClient(client);
break;
+#endif
+
+#ifdef SUPPORT_TCP
case CLIENT_TYPE_TCP :
destroyTcpClient(client);
break;
+#endif
default :
assert( ! _("Bad client type (TCP/UDP)!"));
break;
@@ -264,19 +275,23 @@ int initServer(char *ip4, int port4, char *ip6, int port6)
setServerMaxClients(SERVER_MAX_CLIENTS);
setServerTimer();
+#ifdef SUPPORT_UDP
ret = initUdpServer(ip4, port4, ip6, port6);
if( ret == 0 )
{
return -1;
}
+#endif
+#ifdef SUPPORT_TCP
ret = initTcpServer(ip4, port4, ip6, port6);
if( ret == 0 )
{
return -1;
}
+#endif
return ret;
}
@@ -314,12 +329,18 @@ void sendClient(client_t *p, char *msg)
switch( p->type )
{
+#ifdef SUPPORT_UDP
case CLIENT_TYPE_UDP :
ret = writeUdpSocket(p->socket_udp, p->socket_udp, msg, strlen(msg));
break;
+#endif
+
+#ifdef SUPPORT_TCP
case CLIENT_TYPE_TCP :
ret = addBuffer(p->sendBuffer, msg, strlen(msg));
break;
+#endif
+
default :
assert( ! _("Bad client type (TCP/UDP)!"));
break;
@@ -381,10 +402,12 @@ static void porcesListClients()
eventClientWorkRecvList(thisClient);
eventMsgInCheckFront(thisClient);
+#ifdef SUPPORT_TCP
if( thisClient->type == CLIENT_TYPE_TCP )
{
sendTcpClientBuffer(thisClient);
}
+#endif
}
}
@@ -393,13 +416,16 @@ void eventServer()
#ifndef PUBLIC_SERVER
int count;
+#ifdef SUPPORT_TCP
do{
restartSelect();
setServerTcpSelect();
actionSelect();
count = selectServerTcpSocket();
}while( count > 0 );
+#endif
+#ifdef SUPPORT_UDP
do{
restartSelect();
setServerUdpSelect();
@@ -408,20 +434,32 @@ void eventServer()
}while( count > 0 );
#endif
+#endif
+
#ifdef PUBLIC_SERVER
int ret;
restartSelect();
+#ifdef SUPPORT_TCP
setServerTcpSelect();
+#endif
+
+#ifdef SUPPORT_UDP
setServerUdpSelect();
+#endif
ret = actionSelect();
if( ret > 0 )
{
+#ifdef SUPPORT_TCP
selectServerTcpSocket();
+#endif
+
+#ifdef SUPPORT_UDP
selectServerUdpSocket();
+#endif
}
#endif
@@ -439,6 +477,11 @@ void quitServer()
destroyTimer(listServerTimer);
+#ifdef SUPPORT_UDP
quitUdpServer();
+#endif
+
+#ifdef SUPPORT_TCP
quitTcpServer();
+#endif
}
diff --git a/src/client/client.c b/src/client/client.c
index 4637d01..66c5700 100644
--- a/src/client/client.c
+++ b/src/client/client.c
@@ -25,13 +25,23 @@
#include "screen_analyze.h"
#include "screen_world.h"
+#include "buffer.h"
+#ifdef SUPPORT_UDP
#include "udp.h"
+#endif
+
+#ifdef SUPPORT_TCP
#include "tcp.h"
-#include "buffer.h"
+#endif
+#ifdef SUPPORT_UDP
static sock_udp_t *sock_server_udp;
+#endif
+
+#ifdef SUPPORT_TCP
static sock_tcp_t *sock_server_tcp;
+#endif
static list_t *listRecvMsg;
@@ -47,6 +57,7 @@ static int traffic_down;
static int traffic_up;
#endif
+
typedef struct proto_cmd_client_struct
{
char *name;
@@ -93,6 +104,8 @@ static proto_cmd_client_t* findCmdProto(char *msg)
return NULL;
}
+#ifdef SUPPORT_UDP
+
static int initUdpClient(char *ip, int port, int proto)
{
sock_server_udp = connectUdpSocket(ip, port, proto);
@@ -107,6 +120,10 @@ static int initUdpClient(char *ip, int port, int proto)
return 0;
}
+#endif
+
+#ifdef SUPPORT_TCP
+
static int initTcpClient(char *ip, int port, int proto)
{
sock_server_tcp = connectTcpSocket(ip, port, proto);
@@ -125,6 +142,8 @@ static int initTcpClient(char *ip, int port, int proto)
return 0;
}
+#endif
+
int initClient(char *ip, int port, int proto)
{
char name[STR_NAME_SIZE];
@@ -143,35 +162,23 @@ int initClient(char *ip, int port, int proto)
clientRecvBuffer = newBuffer(CLIENT_BUFFER_LIMIT);
clientSendBuffer = newBuffer(CLIENT_BUFFER_LIMIT);
- if( ! isParamFlag("--udp") && ! isParamFlag("--tcp") )
- {
- ret = initUdpClient(ip, port, proto);
+#ifdef SUPPORT_UDP
+ ret = initUdpClient(ip, port, proto);
- if( ret < 0 )
- {
- return -1;
- }
- }
-
- if( isParamFlag("--udp") && ! isParamFlag("--tcp") )
+ if( ret < 0 )
{
- ret = initUdpClient(ip, port, proto);
-
- if( ret < 0 )
- {
- return -1;
- }
+ return -1;
}
+#endif
- if( isParamFlag("--tcp") && ! isParamFlag("--udp") )
- {
- ret = initTcpClient(ip, port, proto);
+#ifdef SUPPORT_TCP
+ ret = initTcpClient(ip, port, proto);
- if( ret < 0 )
- {
- return -1;
- }
+ if( ret < 0 )
+ {
+ return -1;
}
+#endif
getSettingNameRight(name);
proto_send_hello_client(name);
@@ -186,6 +193,8 @@ static void errorWithServer()
setWorldEnd();
}
+#ifdef SUPPORT_TCP
+
static void sendBuffer()
{
void *data;
@@ -212,6 +221,8 @@ static void sendBuffer()
cutBuffer(clientSendBuffer, res);
}
+#endif
+
void sendServer(char *msg)
{
int ret;
@@ -230,16 +241,20 @@ void sendServer(char *msg)
traffic_up += strlen(msg);
#endif
+#ifdef SUPPORT_UDP
if( sock_server_udp != NULL )
{
ret = writeUdpSocket(sock_server_udp, sock_server_udp, msg, strlen(msg));
}
+#endif
+#ifdef SUPPORT_TCP
if( sock_server_tcp != NULL )
{
//ret = writeTcpSocket(sock_server_tcp, msg, strlen(msg));
ret = addBuffer(clientSendBuffer, msg, strlen(msg));
}
+#endif
if( ret < 0 )
{
@@ -255,15 +270,19 @@ static int eventServerSelect()
memset(buffer, 0, STR_PROTO_SIZE);
+#ifdef SUPPORT_UDP
if( sock_server_udp != NULL )
{
ret = readUdpSocket(sock_server_udp, sock_server_udp, buffer, STR_PROTO_SIZE-1);
}
+#endif
+#ifdef SUPPORT_TCP
if( sock_server_tcp != NULL )
{
ret = readTcpSocket(sock_server_tcp, buffer, STR_PROTO_SIZE-1);
}
+#endif
if( ret < 0 )
{
@@ -337,6 +356,8 @@ static void eventPingServer()
}
}
+#ifdef SUPPORT_UDP
+
static bool_t isServerAlive()
{
my_time_t currentTime;
@@ -351,6 +372,8 @@ static bool_t isServerAlive()
return TRUE;
}
+#endif
+
static void selectClientSocket()
{
fd_set readfds;
@@ -359,6 +382,7 @@ static void selectClientSocket()
int sock;
bool_t isNext;
+#ifdef SUPPORT_UDP
if( sock_server_udp != NULL )
{
if( isServerAlive() == FALSE )
@@ -367,6 +391,7 @@ static void selectClientSocket()
return;
}
}
+#endif
do{
isNext = FALSE;
@@ -376,16 +401,19 @@ static void selectClientSocket()
FD_ZERO(&readfds);
+#ifdef SUPPORT_UDP
if( sock_server_udp != NULL )
{
sock = sock_server_udp->sock;
}
+#endif
+#ifdef SUPPORT_TCP
if( sock_server_tcp != NULL )
{
sock = sock_server_tcp->sock;
}
-
+#endif
FD_SET(sock, &readfds);
max_fd = sock;
select(max_fd+1, &readfds, (fd_set *)NULL, (fd_set *)NULL, &tv);
@@ -433,9 +461,14 @@ void eventClient()
eventPingServer();
selectClientSocket();
eventClientWorkRecvList();
+
+#ifdef SUPPORT_TCP
sendBuffer();
+#endif
}
+#ifdef SUPPORT_UDP
+
static void quitUdpClient()
{
assert( sock_server_udp != NULL );
@@ -445,6 +478,10 @@ static void quitUdpClient()
#endif
}
+#endif
+
+#ifdef SUPPORT_TCP
+
static void quitTcpClient()
{
assert( sock_server_tcp != NULL );
@@ -454,6 +491,8 @@ static void quitTcpClient()
#endif
}
+#endif
+
void quitClient()
{
proto_send_end_client();
@@ -464,14 +503,18 @@ void quitClient()
destroyBuffer(clientRecvBuffer);
destroyBuffer(clientSendBuffer);
+#ifdef SUPPORT_UDP
if( sock_server_udp != NULL )
{
quitUdpClient();
}
+#endif
+#ifdef SUPPORT_TCP
if( sock_server_tcp != NULL )
{
quitTcpClient();
}
+#endif
}