summaryrefslogtreecommitdiff
path: root/src/base
diff options
context:
space:
mode:
Diffstat (limited to 'src/base')
-rwxr-xr-xsrc/base/director.c8
-rwxr-xr-xsrc/base/modules.c31
-rw-r--r--src/base/modules.h13
-rw-r--r--src/base/net_multiplayer.c49
-rw-r--r--src/base/proto.c42
-rw-r--r--src/base/proto.h22
-rw-r--r--src/base/server.c186
-rw-r--r--src/base/server.h50
8 files changed, 172 insertions, 229 deletions
diff --git a/src/base/director.c b/src/base/director.c
index 0cece6b..1877a8b 100755
--- a/src/base/director.c
+++ b/src/base/director.c
@@ -44,6 +44,14 @@ director_t* loadDirector(char *s)
dir = opendir(new->path);
+ if( dir == NULL )
+ {
+ free(new->path);
+ free(new);
+
+ return NULL;
+ }
+
while( ( item = readdir(dir) ) != NULL )
addList(new->list, strdup(item->d_name) );
diff --git a/src/base/modules.c b/src/base/modules.c
index 8b84987..afe192c 100755
--- a/src/base/modules.c
+++ b/src/base/modules.c
@@ -21,12 +21,6 @@
#include "configFile.h"
#endif
-int pokus(char *s)
-{
- printf("s = %s\n", s);
- return 0;
-}
-
static export_fce_t export_fce =
{
#ifndef PUBLIC_SERVER
@@ -37,7 +31,6 @@ static export_fce_t export_fce =
.fce_getNetTypeGame = getNetTypeGame,
.fce_getTuxProportion = getTuxProportion,
.fce_setTuxProportion = setTuxProportion,
- //.fce_getTuxID = getTuxID,
.fce_actionTux = actionTux,
.fce_getMyTime = getMyTime,
@@ -46,8 +39,12 @@ static export_fce_t export_fce =
.fce_conflictSpace = conflictSpace,
.fce_isFreeSpace = isFreeSpace,
.fce_findFreeSpace = findFreeSpace,
- .fce_proto_send_newtux_server = proto_send_newtux_server,
- .fce_proto_send_shot_server = proto_send_shot_server,
+
+ .fce_proto_send_module_server = proto_send_module_server,
+#ifndef PUBLIC_SERVER
+ .fce_proto_send_module_client = proto_send_module_client,
+#endif
+
.fce_destroyShot = destroyShot,
.fce_boundBombBall = boundBombBall,
.fce_transformOnlyLasser = transformOnlyLasser
@@ -101,6 +98,7 @@ static module_t* newModule(char *name)
ret->fce_destroy = getFce(ret, "destroy");
ret->fce_isConflict = getFce(ret, "isConflict");
ret->fce_cmd = getFce(ret, "cmdArena");
+ ret->fce_recvMsg = getFce(ret, "recvMsg");
printf("load module.. (%s)\n", name);
@@ -216,6 +214,21 @@ int isConflictModule(int x, int y, int w, int h)
return 0;
}
+int recvMsgModule(char *msg)
+{
+ int i;
+
+ for( i = 0 ; i < listModule->count ; i++ )
+ {
+ module_t *this;
+
+ this = (module_t *)listModule->list[i];
+ this->fce_recvMsg(msg);
+ }
+
+ return 0;
+}
+
void quitModule()
{
destroyListItem(listModule, destroyModule);
diff --git a/src/base/modules.h b/src/base/modules.h
index 0b31292..5456ffb 100644
--- a/src/base/modules.h
+++ b/src/base/modules.h
@@ -21,8 +21,8 @@ typedef struct export_fce_s
SDL_Surface* (*fce_getImage)(char *group, char *name);
void (*fce_addLayer)(SDL_Surface *img,
- int x,int y, int px,int py,
- int w,int h, int player);
+ int x,int y, int px,int py,
+ int w,int h, int player);
#endif
int (*fce_getNetTypeGame)();
@@ -36,17 +36,14 @@ typedef struct export_fce_s
int (*fce_conflictSpace)(int x1,int y1,int w1,int h1,int x2,int y2,int w2,int h2);
int (*fce_isFreeSpace)(arena_t *arena, int x, int y, int w, int h);
void (*fce_findFreeSpace)(arena_t *arena, int *x, int *y, int w, int h);
- void (*fce_proto_send_newtux_server)(int type, client_t *client, tux_t *tux);
- void (*fce_proto_send_shot_server)(int type, client_t *client, shot_t *p);
+ void (*fce_proto_send_module_server)(int type, client_t *client, char *msg);
+ void (*fce_proto_send_module_client)(char *msg);
my_time_t (*fce_getMyTime)();
void (*fce_destroyShot)(shot_t *p);
void (*fce_boundBombBall)(shot_t *shot);
void (*fce_transformOnlyLasser)(shot_t *shot);
-
- int (*fce_pokus)(char *s);
-
} export_fce_t;
typedef struct module_s
@@ -61,6 +58,7 @@ typedef struct module_s
int (*fce_event)();
int (*fce_isConflict)(int x, int y, int w, int h);
void (*fce_cmd)(char *line);
+ void (*fce_recvMsg)(char *msg);
int (*fce_destroy)();
} module_t;
@@ -73,6 +71,7 @@ extern void drawModule(int x, int y, int w, int h);
extern void eventModule();
extern void cmdModule(char *s);
extern int isConflictModule(int x, int y, int w, int h);
+extern int recvMsgModule(char *msg);
extern void quitModule();
#endif
diff --git a/src/base/net_multiplayer.c b/src/base/net_multiplayer.c
index b028e0f..43a9508 100644
--- a/src/base/net_multiplayer.c
+++ b/src/base/net_multiplayer.c
@@ -54,42 +54,22 @@ int initNetMuliplayer(int type, char *ip, int port, int proto)
break;
case NET_GAME_TYPE_SERVER :
-#ifdef SUPPORT_NET_UNIX_UDP
if( initUdpServer(ip, port, proto) != 0 )
{
fprintf(stderr, "Neomzem inicalizovat sietovu hru pre server !\n");
netGameType = NET_GAME_TYPE_NONE;
return -1;
}
-#endif
-#ifdef SUPPORT_NET_SDL_UDP
- if( initSdlUdpServer(port) != 0 )
- {
- fprintf(stderr, "Neomzem inicalizovat sietovu hru pre server !\n");
- netGameType = NET_GAME_TYPE_NONE;
- return -1;
- }
-#endif
break;
#ifndef PUBLIC_SERVER
case NET_GAME_TYPE_CLIENT :
-#ifdef SUPPORT_NET_UNIX_UDP
if( initUdpClient(ip, port, proto) != 0 )
{
fprintf(stderr, "Neomzem inicalizovat sietovu hru pre clienta !\n");
netGameType = NET_GAME_TYPE_NONE;
return -1;
}
-#endif
-#ifdef SUPPORT_NET_SDL_UDP
- if( initSdlUdpClient(ip, port) != 0 )
- {
- fprintf(stderr, "Neomzem inicalizovat sietovu hru pre clienta !\n");
- netGameType = NET_GAME_TYPE_NONE;
- return -1;
- }
-#endif
break;
#endif
default :
@@ -108,28 +88,14 @@ void eventNetMultiplayer()
break;
case NET_GAME_TYPE_SERVER :
-#ifdef SUPPORT_NET_UNIX_UDP
- eventServer();
-#endif
-#ifdef SUPPORT_NET_SDL_UDP
eventServer();
-#endif
break;
#ifndef PUBLIC_SERVER
case NET_GAME_TYPE_CLIENT :
-#ifdef SUPPORT_NET_UNIX_UDP
- eventPingServer();
- selectClientUdpSocket();
- eventServerBuffer();
-#endif
-#ifdef SUPPORT_NET_SDL_UDP
- eventPingServer();
- selectClientSdlUdpSocket();
- eventServerBuffer();
-#endif
-#endif
+ eventClient();
break;
+#endif
default :
assert( ! "Premenna netGameType ma zlu hodnotu !" );
break;
@@ -144,25 +110,14 @@ void quitNetMultiplayer()
break;
case NET_GAME_TYPE_SERVER :
-#ifdef SUPPORT_NET_UNIX_UDP
quitUdpServer();
-#endif
-#ifdef SUPPORT_NET_SDL_UDP
- quitSdlUdpServer();
-#endif
break;
#ifndef PUBLIC_SERVER
case NET_GAME_TYPE_CLIENT :
-#ifdef SUPPORT_NET_UNIX_UDP
quitUdpClient();
-#endif
-#ifdef SUPPORT_NET_SDL_UDP
- quitSdlUdpClient();
-#endif
break;
#endif
-
default :
assert( ! "Premenna netGameType ma zlu hodnotu !" );
break;
diff --git a/src/base/proto.c b/src/base/proto.c
index 052a0c4..5d1debd 100644
--- a/src/base/proto.c
+++ b/src/base/proto.c
@@ -16,6 +16,7 @@
#include "net_multiplayer.h"
#include "checkFront.h"
#include "idManager.h"
+#include "modules.h"
#include "protect.h"
#ifndef PUBLIC_SERVER
@@ -747,6 +748,47 @@ void proto_recv_chat_client(char *msg)
#ifndef PUBLIC_SERVER
+void proto_send_module_client(char *msg)
+{
+ char out[STR_PROTO_SIZE];
+
+ strcpy(out, "modules ");
+ strcat(out, msg);
+ strcat(out, "\n");
+
+ sendServer(out);
+}
+
+#endif
+
+void proto_recv_module_server(client_t *client, char *msg)
+{
+ recvMsgModule(msg+7);
+}
+
+void proto_send_module_server(int type, client_t *client, char *msg)
+{
+ char out[STR_PROTO_SIZE];
+
+ strcpy(out, "module ");
+ strcat(out, msg);
+ strcat(out, "\n");
+
+ protoSendClient(type, client, out, CHECK_FORNT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE);
+}
+
+#ifndef PUBLIC_SERVER
+
+void proto_recv_module_client(char *msg)
+{
+ recvMsgModule(msg+7);
+}
+
+#endif
+
+
+#ifndef PUBLIC_SERVER
+
void proto_send_ping_client()
{
char msg[STR_PROTO_SIZE];
diff --git a/src/base/proto.h b/src/base/proto.h
index bcc8f42..b7f198b 100644
--- a/src/base/proto.h
+++ b/src/base/proto.h
@@ -42,40 +42,60 @@
extern void proto_send_error_server(int type, client_t *client, int errorcode);
extern void proto_recv_error_client(char *msg);
+
extern void proto_send_hello_client(char *name);
extern void proto_recv_hello_server(client_t *client, char *msg);
+
extern void proto_send_status_server(int type, client_t *client);
extern void proto_recv_status_server(client_t *client, char *msg);
+
extern void proto_send_listscore_server(int type, client_t *client, int max);
extern void proto_recv_listscore_server(client_t *client, char *msg);
+
extern void proto_send_check_client(int id);
extern void proto_recv_check_server(client_t *client, char *msg);
+
extern void proto_send_init_server(int type, client_t *client, client_t *client2);
extern void proto_recv_init_client(char *msg);
+
extern void proto_send_event_server(int type, client_t *client, tux_t *tux, int action);
extern void proto_recv_event_client(char *msg);
extern void proto_send_event_client(int action);
extern void proto_recv_event_server(client_t *client, char *msg);
+
extern void proto_send_newtux_server(int type, client_t *client, tux_t *tux);
extern void proto_recv_newtux_client(char *msg);
+
extern void proto_send_kill_server(int type, client_t *client, tux_t *tux);
extern void proto_recv_kill_client(char *msg);
+
extern void proto_send_score_server(int type, client_t *client, tux_t *tux);
extern void proto_recv_score_client(char *msg);
+
extern void proto_send_del_server(int type, client_t *client, int id);
extern void proto_recv_del_client(char *msg);
+
extern void proto_send_additem_server(int type, client_t *client, item_t *p);
extern void proto_recv_additem_client(char *msg);
+
extern void proto_send_shot_server(int type, client_t *client, shot_t *p);
extern void proto_recv_shot_client(char *msg);
-extern void proto_send_ping_client();
+
extern void proto_send_chat_client(char *s);
extern void proto_recv_chat_server(client_t *client, char *msg);
extern void proto_send_chat_server(int type, client_t *client, char *msg);
extern void proto_recv_chat_client(char *msg);
+
+extern void proto_send_module_client(char *s);
+extern void proto_recv_module_server(client_t *client, char *msg);
+extern void proto_send_module_server(int type, client_t *client, char *msg);
+extern void proto_recv_module_client(char *msg);
+
+extern void proto_send_ping_client();
extern void proto_recv_ping_server(client_t *client, char *msg);
extern void proto_send_ping_server(int type, client_t *client);
extern void proto_recv_ping_client(char *msg);
+
extern void proto_send_end_server(int type, client_t *client);
extern void proto_recv_end_client(char *msg);
extern void proto_send_end_client();
diff --git a/src/base/server.c b/src/base/server.c
index 3c1148a..25079c8 100644
--- a/src/base/server.c
+++ b/src/base/server.c
@@ -55,6 +55,59 @@ time_t getUpdateServer()
return time(NULL) - timeUpdate;
}
+static 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 = malloc( sizeof(client_t) );
+ memset(new, 0, sizeof(client_t));
+
+ new->status = NET_STATUS_OK;
+ new->listRecvMsg = newList();
+ new->listSendMsg = newCheckFront();
+ new->listSeesShot = newList();
+ new->protect = newProtect();
+ new->socket_udp = sock_udp;
+
+ return new;
+}
+
+static void destroyClient(client_t *p)
+{
+ char str_ip[STR_IP_SIZE];
+
+ assert( p != NULL );
+
+ eventMsgInCheckFront(p);
+
+ getSockUdpIp(p->socket_udp, str_ip, STR_IP_SIZE);
+ printf("close connect %s %d\n", str_ip, getSockUdpPort(p->socket_udp) );
+
+ closeUdpSocket(p->socket_udp);
+
+ destroyListItem(p->listRecvMsg, free);
+ destroyListItem(p->listSeesShot, free);
+ destroyCheckFront(p->listSendMsg);
+
+ destroyProtect(p->protect);
+
+ if( p->tux != NULL )
+ {
+#ifdef PUBLIC_SERVER
+ addPlayerInHighScore(p->tux->name, p->tux->score);
+#endif
+ delObjectFromSpaceWithObject(getCurrentArena()->spaceTux, p->tux, destroyTux);
+ }
+
+ free(p);
+}
+
static void eventDelClient(client_t *client)
{
int offset;
@@ -213,59 +266,6 @@ int initUdpPublicServer(char *ip4, int port4, char *ip6, int port6)
#endif
-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 = malloc( sizeof(client_t) );
- memset(new, 0, sizeof(client_t));
-
- new->status = NET_STATUS_OK;
- new->listRecvMsg = newList();
- new->listSendMsg = newCheckFront();
- new->listSeesShot = newList();
- new->protect = newProtect();
- new->socket_udp = sock_udp;
-
- return new;
-}
-
-void destroyClient(client_t *p)
-{
- char str_ip[STR_IP_SIZE];
-
- assert( p != NULL );
-
- eventMsgInCheckFront(p);
-
- getSockUdpIp(p->socket_udp, str_ip, STR_IP_SIZE);
- printf("close connect %s %d\n", str_ip, getSockUdpPort(p->socket_udp) );
-
- closeUdpSocket(p->socket_udp);
-
- destroyListItem(p->listRecvMsg, free);
- destroyListItem(p->listSeesShot, free);
- destroyCheckFront(p->listSendMsg);
-
- destroyProtect(p->protect);
-
- if( p->tux != NULL )
- {
-#ifdef PUBLIC_SERVER
- addPlayerInHighScore(p->tux->name, p->tux->score);
-#endif
- delObjectFromSpaceWithObject(getCurrentArena()->spaceTux, p->tux, destroyTux);
- }
-
- free(p);
-}
-
list_t* getListServerClient()
{
return listClient;
@@ -376,26 +376,11 @@ static void addMsgAllClientSeesTux(char *msg, tux_t *tux, int type, int id)
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);
- }
-
+ 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);
+
getObjectFromSpace(space, x, y, w, h, listHelp);
//printf("%d %d %d %d %d\n", x, y, w, h, listHelp->count);
@@ -418,28 +403,6 @@ static void addMsgAllClientSeesTux(char *msg, tux_t *tux, int type, int id)
addMsgClient(thisClient, msg, type, id);
}
}
-
-#if 0
- 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( thisTux == NULL )
- {
- continue;
- }
-
- if( tux != thisTux &&
- isTuxSeesTux(thisTux, tux) )
- {
- addMsgClient(thisClient, msg, type, id);
- }
- }
-#endif
}
void protoSendClient(int type, client_t *client, char *msg, int type2, int id)
@@ -481,29 +444,6 @@ void protoSendClient(int type, client_t *client, char *msg, int type2, int id)
}
}
-tux_t *getServerTux()
-{
- return NULL;
-}
-
-client_t *getClientFromTux(tux_t *tux)
-{
- client_t *thisClient;
- int i;
-
- for( i = 0 ; i < listClient->count; i++)
- {
- thisClient = (client_t *) listClient->list[i];
-
- if( thisClient->tux == tux )
- {
- return thisClient;
- }
- }
-
- return NULL;
-}
-
void sendInfoCreateClient(client_t *client)
{
client_t *thisClient;
@@ -613,6 +553,12 @@ static void eventClientBuffer(client_t *client)
continue;
}
+ if( strncmp(line, "module", 7) == 0 )
+ {
+ proto_recv_module_server(client, line);
+ continue;
+ }
+
if( strncmp(line, "chat", 4) == 0 )
{
proto_recv_chat_server(client, line);
@@ -642,7 +588,7 @@ static void eventClientBuffer(client_t *client)
client->listRecvMsg = newList();
}
-void eventClientListBuffer()
+static void eventClientListBuffer()
{
int i;
client_t *thisClient;
@@ -723,7 +669,7 @@ static void eventClientUdpSelect(sock_udp_t *sock_server)
addList(client->listRecvMsg, strdup(listRecvMsg) );
}
-int selectServerUdpSocket()
+static int selectServerUdpSocket()
{
struct timeval tv;
fd_set readfds;
diff --git a/src/base/server.h b/src/base/server.h
index e6f0b93..0da4969 100644
--- a/src/base/server.h
+++ b/src/base/server.h
@@ -9,24 +9,12 @@
#include "tux.h"
#include "myTimer.h"
#include "protect.h"
+#include "udp.h"
#ifndef PUBLIC_SERVER
#include "interface.h"
#endif
-
-#ifdef SUPPORT_NET_SDL_UDP
-
-#include "sdl_udp.h"
-
-#endif
-
-#ifdef SUPPORT_NET_UNIX_UDP
-
-#include "udp.h"
-
-#endif
-
#define SERVER_TIMEOUT 1000
#define SERVER_TIME_SYNC 1000
#define SERVER_TIME_PING 1000
@@ -37,13 +25,8 @@
typedef struct client_struct
{
-#ifdef SUPPORT_NET_UNIX_UDP
sock_udp_t *socket_udp;
-#endif
-#ifdef SUPPORT_NET_SDL_UDP
- sock_sdl_udp_t *socket_sdl_udp;
-#endif
int status;
tux_t *tux;
@@ -56,40 +39,17 @@ typedef struct client_struct
list_t *listSeesShot;
} client_t;
-#ifdef PUBLIC_SERVER
-extern int initUdpPublicServer(char *ip4, int port4, char *ip6, int port6);
-#endif
-
-#ifdef SUPPORT_NET_UNIX_UDP
-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 int selectServerUdpSocket();
-extern void quitUdpServer();
-#endif
-
-#ifdef SUPPORT_NET_SDL_UDP
-extern int initSdlUdpServer(int port);
-extern client_t* newSdlUdpClient(sock_sdl_udp_t *sock_udp);
-extern void selectServerSdlUdpSocket();
-extern void quitSdlUdpServer();
-#endif
-
-extern void destroyClient(client_t *p);
extern time_t getUpdateServer();
+extern int initUdpServer(char *ip, int port, int proto);
+extern int initUdpPublicServer(char *ip4, int port4, char *ip6, int port6);
extern list_t* getListServerClient();
extern int getServerMaxClients();
extern void setServerMaxClients(int n);
-
extern void sendClient(client_t *p, char *msg);
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);
-extern void eventClientListBuffer();
extern void sendInfoCreateClient(client_t *client);
extern void eventServer();
+extern void quitUdpServer();
-#endif
-
+#endif