From bb15df3f3428df7cd2a4482adebcdaa6fc2f516e Mon Sep 17 00:00:00 2001 From: oroborus Date: Thu, 10 Jul 2008 11:28:59 +0000 Subject: - precisteny kod sietoveho multiplayera - moduly si mozu mosielat spravy cez sietovy protokol - opravy chyb v moduloch - oprava chyby, v textovych poliach sa zobrazuju znaky, ktore ste nestalcili - director_t* loadDirector(char *s) vracia NULL ak adresar neexistuje ( predtym sa proces zrutil ) git-svn-id: http://opensvn.csie.org/tuxanci_ng@126 0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e --- config.h | 2 +- src/base/director.c | 8 ++ src/base/modules.c | 31 +++++-- src/base/modules.h | 13 ++- src/base/net_multiplayer.c | 49 +---------- src/base/proto.c | 42 ++++++++++ src/base/proto.h | 22 ++++- src/base/server.c | 186 +++++++++++++++--------------------------- src/base/server.h | 50 ++---------- src/client/client.c | 117 ++++---------------------- src/client/client.h | 21 +---- src/modules/modAI.c | 4 + src/modules/modPipe.c | 64 +++++++++++++-- src/modules/modTeleport.c | 94 ++++++++++++++++++--- src/modules/modWall.c | 4 + src/widget/widget_textfield.c | 3 + 16 files changed, 341 insertions(+), 369 deletions(-) diff --git a/config.h b/config.h index 9a8394e..d9663d2 100644 --- a/config.h +++ b/config.h @@ -1 +1 @@ -#define TUXANCI_NG_VERSION "svn125" +#define TUXANCI_NG_VERSION "svn126" 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 @@ -745,6 +746,47 @@ void proto_recv_chat_client(char *msg) #endif +#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() 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 diff --git a/src/client/client.c b/src/client/client.c index 1ac74dd..8d7b613 100644 --- a/src/client/client.c +++ b/src/client/client.c @@ -21,17 +21,11 @@ #include "screen_analyze.h" #include "screen_world.h" +#include "udp.h" + static int protocolType; -#ifdef SUPPORT_NET_UNIX_UDP -#include "udp.h" static sock_udp_t *sock_server_udp; -#endif - -#ifdef SUPPORT_NET_SDL_UDP -#include "sdl_udp.h" -static sock_sdl_udp_t *sock_server_sdl_udp; -#endif static list_t *clientBuffer; static my_time_t lastPing; @@ -49,8 +43,6 @@ static void initClient() proto_send_hello_client(name); } -#ifdef SUPPORT_NET_UNIX_UDP - int initUdpClient(char *ip, int port, int proto) { sock_server_udp = connectUdpSocket(ip, port, proto); @@ -68,29 +60,6 @@ int initUdpClient(char *ip, int port, int proto) return 0; } -#endif - -#ifdef SUPPORT_NET_SDL_UDP - -int initSdlUdpClient(char *ip, int port) -{ - sock_server_sdl_udp = connectSdlUdpSocket(ip, port); - - if( sock_server_sdl_udp == NULL ) - { - return -1; - } - - printf("connect UDP %s %d\n", ip, port); - - protocolType = NET_PROTOCOL_TYPE_UDP; - initClient(); - - return 0; -} - -#endif - void sendServer(char *msg) { int ret; @@ -98,19 +67,13 @@ void sendServer(char *msg) assert( msg != NULL ); #ifndef PUBLIC_SERVER - if( isParamFlag("--send") ) - { - printf("send -> %s", msg); - } + if( isParamFlag("--send") ) + { + printf("send -> %s", msg); + } #endif -#ifdef SUPPORT_NET_UNIX_UDP ret = writeUdpSocket(sock_server_udp, sock_server_udp, msg, strlen(msg)); -#endif - -#ifdef SUPPORT_NET_SDL_UDP - ret = writeSdlUdpSocket(sock_server_sdl_udp, sock_server_sdl_udp, msg, strlen(msg)); -#endif } static int eventServerSelect() @@ -120,32 +83,19 @@ static int eventServerSelect() memset(buffer,0 ,STR_PROTO_SIZE); -#ifdef SUPPORT_NET_UNIX_UDP ret = readUdpSocket(sock_server_udp, sock_server_udp, buffer, STR_PROTO_SIZE-1); -#endif - -#ifdef SUPPORT_NET_SDL_UDP - ret = readSdlUdpSocket(sock_server_sdl_udp, sock_server_sdl_udp, buffer, STR_PROTO_SIZE-1); if( ret < 0 ) { return ret; } -#endif addList(clientBuffer, strdup(buffer) ); -/* - if( addBuffer(clientBuffer, buffer, ret) != 0 ) - { - fprintf(stderr, "chyba, nemozem zapisovat do mojho buffera !\n"); - setWorldEnd(); - return ret; - } -*/ + return ret; } -void eventServerBuffer() +static void eventServerBuffer() { char *line; int i; @@ -172,6 +122,7 @@ void eventServerBuffer() if( strncmp(line, "additem", 7) == 0 )proto_recv_additem_client(line); if( strncmp(line, "shot", 4) == 0 )proto_recv_shot_client(line); if( strncmp(line, "kill", 4) == 0 )proto_recv_kill_client(line); + if( strncmp(line, "module", 6) == 0 )proto_recv_module_client(line); if( strncmp(line, "chat", 4) == 0 )proto_recv_chat_client(line); if( strncmp(line, "ping", 4) == 0 )proto_recv_ping_client(line); if( strncmp(line, "end", 3) == 0 )proto_recv_end_client(line); @@ -183,7 +134,7 @@ void eventServerBuffer() clientBuffer = newList(); } -void eventPingServer() +static void eventPingServer() { my_time_t currentTime; @@ -196,7 +147,7 @@ void eventPingServer() } } -bool_t isServerAlive() +static bool_t isServerAlive() { my_time_t currentTime; @@ -210,9 +161,7 @@ bool_t isServerAlive() return TRUE; } -#ifdef SUPPORT_NET_UNIX_UDP - -void selectClientUdpSocket() +static void selectClientUdpSocket() { fd_set readfds; struct timeval tv; @@ -246,31 +195,15 @@ void selectClientUdpSocket() } }while( isNext == TRUE ); - } -#endif - -#ifdef SUPPORT_NET_SDL_UDP - -void selectClientSdlUdpSocket() +void eventClient() { - int ret; - - if( isServerAlive() == FALSE ) - { - setMsgToAnalyze(getMyText("ERROR_SERVER_DONT_ALIVE")); - setWorldEnd(); - return; - } - - do{ - ret = eventServerSelect(); - }while( ret > 0); + eventPingServer(); + selectClientUdpSocket(); + eventServerBuffer(); } -#endif - static void quitClient() { proto_send_end_client(); @@ -278,8 +211,6 @@ static void quitClient() destroyListItem(clientBuffer, free); } -#ifdef SUPPORT_NET_UNIX_UDP - void quitUdpClient() { quitClient(); @@ -289,19 +220,3 @@ void quitUdpClient() printf("quit UDP conenct\n"); } - -#endif - -#ifdef SUPPORT_NET_SDL_UDP - -void quitSdlUdpClient() -{ - quitClient(); - - assert( sock_server_sdl_udp != NULL ); - closeSdlUdpSocket(sock_server_sdl_udp); - - printf("quit UDP conenct\n"); -} - -#endif diff --git a/src/client/client.h b/src/client/client.h index cd8c4c4..e301c4b 100644 --- a/src/client/client.h +++ b/src/client/client.h @@ -5,31 +5,14 @@ #include "main.h" -#if defined SUPPORT_NET_UNIX_UDP || defined SUPPORT_NET_SDL_UDP #define CLIENT_TIMEOUT 1000 #define SERVER_TIMEOUT_ALIVE 5000 -#endif - -#ifdef SUPPORT_NET_UNIX_UDP extern int initUdpClient(char *ip, int port, int proto); -extern void eventPingServer(); -extern void selectClientUdpSocket(); -extern void refreshPingServerAlive(); +extern void sendServer(char *msg); +extern void eventClient(); extern void quitUdpClient(); -#endif -#ifdef SUPPORT_NET_SDL_UDP -extern int initSdlUdpClient(char *ip, int port); -extern void eventPingServer(); -extern void selectClientSdlUdpSocket(); -extern void refreshPingServerAlive(); -extern bool_t isServerAlive(); -extern void quitSdlUdpClient(); #endif -extern void sendServer(char *msg); -extern void eventServerBuffer(); - -#endif diff --git a/src/modules/modAI.c b/src/modules/modAI.c index 61cb23f..b137ad3 100755 --- a/src/modules/modAI.c +++ b/src/modules/modAI.c @@ -247,6 +247,10 @@ void cmdArena(char *line) if( strncmp(line, "ai", 2) == 0 )cmd_ai(line); } +void recvMsg(char *msg) +{ +} + int destroy() { return 0; diff --git a/src/modules/modPipe.c b/src/modules/modPipe.c index efe4230..4a65756 100755 --- a/src/modules/modPipe.c +++ b/src/modules/modPipe.c @@ -170,7 +170,6 @@ static int myAbs(int n) return ( n > 0 ? n : -n ); } - static int getSppedShot(shot_t *shot) { return ( myAbs(shot->px) > myAbs(shot->py) ? myAbs(shot->px) : myAbs(shot->py) ); @@ -239,33 +238,38 @@ static void moveShot(shot_t *shot, int position, int src_x, int src_y, { case TUX_UP : new_x = dist_x + offset; - new_y = dist_y; + new_y = dist_y - ( shot->h + 5 ); break; case TUX_LEFT : - new_x = dist_x; + new_x = dist_x - ( shot->w + 5 ); new_y = dist_y + offset; break; case TUX_RIGHT : - new_x = dist_x + dist_w; + new_x = dist_x + dist_w + 5; new_y = dist_y + offset; break; case TUX_DOWN : new_x = dist_x + offset; - new_y = dist_y + dist_h; + new_y = dist_y + dist_h + 5; break; } - new_x += myAbs(shot->px) * shot->px; - new_y += myAbs(shot->py) * shot->py; + //new_x += myValueOperator(shot->px) * shot->w; + //new_y += myValueOperator(shot->py) * shot->h; moveObjectInSpace(export_fce->fce_getCurrentArena()->spaceShot, shot, new_x, new_y); if( export_fce->fce_getNetTypeGame() == NET_GAME_TYPE_SERVER ) { - export_fce->fce_proto_send_shot_server(PROTO_SEND_ALL, NULL, shot); + char msg[STR_PROTO_SIZE]; + + sprintf(msg, "pipe %d %d %d %d %d %d", + shot->id, shot->x, shot->y, shot->px, shot->py, shot->position); + + export_fce->fce_proto_send_module_server(PROTO_SEND_ALL, NULL, msg); } } @@ -424,6 +428,50 @@ void cmdArena(char *line) if( strncmp(line, "pipe", 4) == 0 )cmd_teleport(line); } +static void proto_pipe(char *msg) +{ + char cmd[STR_PROTO_SIZE]; + int shot_id, x, y, px, py, position; + space_t *space; + shot_t *shot; + + assert( msg != NULL ); + + sscanf(msg, "%s %d %d %d %d %d %d", + cmd, &shot_id, &x, &y, &px, &py, &position); + + + space = export_fce->fce_getCurrentArena()->spaceShot; + + if( ( shot = getObjectFromSpaceWithID(space, shot_id) ) == NULL ) + { + //delObjectFromSpaceWithObject(getCurrentArena()->spaceShot, shot, destroyShot); + + return; + } + + moveObjectInSpace(space, shot, x, y); + shot->isCanKillAuthor = 1; + shot->position = position; + shot->px = px; + shot->py = py; + + if( shot->gun == GUN_LASSER ) + { + transformOnlyLasser(shot); + } +} + +void recvMsg(char *msg) +{ + if( export_fce->fce_getNetTypeGame() == NET_GAME_TYPE_SERVER ) + { + return; + } + + if( strncmp(msg, "pipe", 4) == 0 )proto_pipe(msg); +} + int destroy() { destroySpaceWithObject(spacePipe, destroyPipe); diff --git a/src/modules/modTeleport.c b/src/modules/modTeleport.c index d54bb4c..9d8eb70 100755 --- a/src/modules/modTeleport.c +++ b/src/modules/modTeleport.c @@ -236,13 +236,19 @@ static void teleportTux(tux_t *tux, teleport_t *teleport) #endif if( export_fce->fce_getNetTypeGame() == NET_GAME_TYPE_SERVER ) { + char msg[STR_PROTO_SIZE]; + + sprintf(msg, "teleporttux %d %d %d", tux->id, dist_x, dist_y); + if( tux->bonus == BONUS_HIDDEN ) { - export_fce->fce_proto_send_newtux_server(PROTO_SEND_ONE, (client_t *)tux->client, tux); + export_fce->fce_proto_send_module_server(PROTO_SEND_ONE, (client_t *)tux->client, msg); + //export_fce->fce_proto_send_newtux_server(PROTO_SEND_ONE, (client_t *)tux->client, tux); } else { - export_fce->fce_proto_send_newtux_server(PROTO_SEND_ALL, NULL, tux); + export_fce->fce_proto_send_module_server(PROTO_SEND_ALL, NULL, msg); + //export_fce->fce_proto_send_newtux_server(PROTO_SEND_ALL, NULL, msg); } } } @@ -301,7 +307,7 @@ static void moveShot(shot_t *shot, int position, int src_x, int src_y, int dist_x, int dist_y, int dist_w, int dist_h) { int offset = 0; - int new_x = 0, new_y = 0; // no warnning + int new_x = 0, new_y = 0; // no warninng switch( shot->position ) { @@ -322,33 +328,35 @@ static void moveShot(shot_t *shot, int position, int src_x, int src_y, { case TUX_UP : new_x = dist_x + offset; - new_y = dist_y; + new_y = dist_y - ( shot->h + 5 ); break; case TUX_LEFT : - new_x = dist_x; + new_x = dist_x - ( shot->w + 5 ); new_y = dist_y + offset; break; case TUX_RIGHT : - new_x = dist_x + dist_w; + new_x = dist_x + dist_w + 5; new_y = dist_y + offset; break; case TUX_DOWN : new_x = dist_x + offset; - new_y = dist_y + dist_h; + new_y = dist_y + dist_h + 5; break; } - new_y += shot->px; - new_y += shot->py; - moveObjectInSpace(export_fce->fce_getCurrentArena()->spaceShot, shot, new_x, new_y); if( export_fce->fce_getNetTypeGame() == NET_GAME_TYPE_SERVER ) { - export_fce->fce_proto_send_shot_server(PROTO_SEND_ALL, NULL, shot); + char msg[STR_PROTO_SIZE]; + + sprintf(msg, "teleportshot %d %d %d %d %d %d", + shot->id, shot->x, shot->y, shot->px, shot->py, shot->position); + + export_fce->fce_proto_send_module_server(PROTO_SEND_ALL, NULL, msg); } } @@ -480,6 +488,70 @@ void cmdArena(char *line) if( strncmp(line, "teleport", 8) == 0 )cmd_teleport(line); } +static void proto_teleporttux(char *msg) +{ + char cmd[STR_PROTO_SIZE]; + int id, x, y; + space_t *space; + tux_t *tux; + + assert( msg != NULL ); + + sscanf(msg, "%s %d %d %d", + cmd, &id, &x, &y); + + space = export_fce->fce_getCurrentArena()->spaceTux; + tux = getObjectFromSpaceWithID(space, id); + + if( tux != NULL ) + { + moveObjectInSpace(space, tux, x, y); + } +} + +static void proto_teleportshot(char *msg) +{ + char cmd[STR_PROTO_SIZE]; + int shot_id, x, y, px, py, position; + space_t *space; + shot_t *shot; + + assert( msg != NULL ); + + sscanf(msg, "%s %d %d %d %d %d %d", + cmd, &shot_id, &x, &y, &px, &py, &position); + + + space = export_fce->fce_getCurrentArena()->spaceShot; + + if( ( shot = getObjectFromSpaceWithID(space, shot_id) ) == NULL ) + { + return; + } + + moveObjectInSpace(space, shot, x, y); + shot->isCanKillAuthor = 1; + shot->position = position; + shot->px = px; + shot->py = py; + + if( shot->gun == GUN_LASSER ) + { + transformOnlyLasser(shot); + } +} + +void recvMsg(char *msg) +{ + if( export_fce->fce_getNetTypeGame() == NET_GAME_TYPE_SERVER ) + { + return; + } + + if( strncmp(msg, "teleporttux", 11) == 0 )proto_teleporttux(msg); + if( strncmp(msg, "teleportshot", 12) == 0 )proto_teleportshot(msg); +} + int destroy() { destroySpaceWithObject(spaceTeleport, destroyTeleport); diff --git a/src/modules/modWall.c b/src/modules/modWall.c index 4030795..c2cf69e 100755 --- a/src/modules/modWall.c +++ b/src/modules/modWall.c @@ -338,6 +338,10 @@ void cmdArena(char *line) if( strncmp(line, "wall", 4) == 0 )cmd_wall(line); } +void recvMsg(char *msg) +{ +} + int destroy() { destroySpaceWithObject(spaceWall, destroyWall); diff --git a/src/widget/widget_textfield.c b/src/widget/widget_textfield.c index ff6e64a..a1e78f6 100644 --- a/src/widget/widget_textfield.c +++ b/src/widget/widget_textfield.c @@ -11,6 +11,8 @@ widget_textfield_t* newWidgetTextfield(char *text, int filter, int x, int y) widget_textfield_t *new; new = malloc( sizeof(widget_textfield_t) ); + memset(new, 0, sizeof(widget_textfield_t)); + strcpy(new->text, text); new->x = x; new->y = y; @@ -85,6 +87,7 @@ void drawWidgetTextfield(widget_textfield_t *p) void setWidgetTextFiledText(widget_textfield_t *p, char *text) { + memset(p->text, 0, STR_SIZE); strcpy(p->text, text); getTextSize(text, &p->w, &p->h); } -- cgit v1.2.3