diff options
| -rw-r--r-- | Makefile | 40 | ||||
| -rwxr-xr-x | build.sh | 2 | ||||
| -rw-r--r-- | config.h | 8 | ||||
| -rwxr-xr-x | include/interface.h | 2 | ||||
| -rw-r--r-- | include/proto.h | 54 | ||||
| -rw-r--r-- | r | 2 | ||||
| -rw-r--r-- | src/client.c | 8 | ||||
| -rw-r--r-- | src/item.c | 2 | ||||
| -rw-r--r-- | src/pipe.c | 11 | ||||
| -rw-r--r-- | src/proto.c | 92 | ||||
| -rw-r--r-- | src/screen_world.c | 19 | ||||
| -rw-r--r-- | src/server.c | 26 | ||||
| -rw-r--r-- | src/shot.c | 5 | ||||
| -rw-r--r-- | src/teleport.c | 2 | ||||
| -rw-r--r-- | src/tux.c | 19 |
15 files changed, 194 insertions, 98 deletions
@@ -1,5 +1,5 @@ -#DISTDIR=/usr/local +DESTDIR:=/usr/local/ all: make -C ./src @@ -48,24 +48,24 @@ server: make -C ./src -f Makefile-publicServer install: - cp ./src/tuxanci-ng $(DISTDIR)bin/ - mkdir $(DISTDIR)share/tuxanci-ng - mkdir $(DISTDIR)share/tuxanci-ng/arena - mkdir $(DISTDIR)share/tuxanci-ng/font - mkdir $(DISTDIR)share/tuxanci-ng/image - mkdir $(DISTDIR)share/tuxanci-ng/lang - mkdir $(DISTDIR)share/tuxanci-ng/music - mkdir $(DISTDIR)share/tuxanci-ng/sound - mkdir $(DISTDIR)share/tuxanci-ng/data - - cp -rf ./arena/* $(DISTDIR)share/tuxanci-ng/arena - cp -rf ./font/* $(DISTDIR)share/tuxanci-ng/font - cp -rf ./image/* $(DISTDIR)share/tuxanci-ng/image - cp -rf ./lang/* $(DISTDIR)share/tuxanci-ng/lang - cp -rf ./music/* $(DISTDIR)share/tuxanci-ng/music - cp -rf ./sound/* $(DISTDIR)share/tuxanci-ng/sound - cp -rf ./data/* $(DISTDIR)share/tuxanci-ng/data + cp ./src/tuxanci-ng $(DESTDIR)bin/ + mkdir $(DESTDIR)share/tuxanci-ng + mkdir $(DESTDIR)share/tuxanci-ng/arena + mkdir $(DESTDIR)share/tuxanci-ng/font + mkdir $(DESTDIR)share/tuxanci-ng/image + mkdir $(DESTDIR)share/tuxanci-ng/lang + mkdir $(DESTDIR)share/tuxanci-ng/music + mkdir $(DESTDIR)share/tuxanci-ng/sound + mkdir $(DESTDIR)share/tuxanci-ng/data + + cp -rf ./arena/* $(DESTDIR)share/tuxanci-ng/arena + cp -rf ./font/* $(DESTDIR)share/tuxanci-ng/font + cp -rf ./image/* $(DESTDIR)share/tuxanci-ng/image + cp -rf ./lang/* $(DESTDIR)share/tuxanci-ng/lang + cp -rf ./music/* $(DESTDIR)share/tuxanci-ng/music + cp -rf ./sound/* $(DESTDIR)share/tuxanci-ng/sound + cp -rf ./data/* $(DESTDIR)share/tuxanci-ng/data uninstall: - rm -rf $(DISTDIR)bin/tuxanci-ng - rm -rf $(DISTDIR)share/tuxanci-ng + rm -rf $(DESTDIR)bin/tuxanci-ng + rm -rf $(DESTDIR)share/tuxanci-ng @@ -24,7 +24,7 @@ mkdir myusr mkdir myusr/bin mkdir myusr/share -make install DISTDIR=./myusr/ +make install DESTDIR=./myusr/ mv config.h path_config.h ./deb-build.sh @@ -1,2 +1,8 @@ -#define DISTDIR "/usr/" +/* +#define DEBUG_SERVER_SEND +#define DEBUG_SERVER_RECV +#define DEBUG_CLIENT_SEND +#define DEBUG_CLIENT_RECV +*/ +#define DISTDIR "/usr/local/" #define SUPPORT_NET_SDL_UDP diff --git a/include/interface.h b/include/interface.h index 77f515b..bcb2a17 100755 --- a/include/interface.h +++ b/include/interface.h @@ -19,7 +19,7 @@ #define SDL_SUBSYSTEMS SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_DOUBLEBUF //napis na okne -#define WINDOW_TITLE "Tuxanci next generation SVN revision 24" +#define WINDOW_TITLE "Tuxanci next generation SVN revision 27" #define WIN_BPP 0 #define USR_EVT_TIMER 0 diff --git a/include/proto.h b/include/proto.h index e94c086..37595fe 100644 --- a/include/proto.h +++ b/include/proto.h @@ -9,35 +9,67 @@ #include "item.h" #include "shot.h" +#define PROTO_SEND_ONE 0 +#define PROTO_SEND_ALL 1 +#define PROTO_SEND_BUT 2 + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <assert.h> + +#include "main.h" +#include "list.h" +#include "tux.h" +#include "item.h" +#include "shot.h" +#include "arenaFile.h" +#include "myTimer.h" +#include "server.h" +#include "proto.h" +#include "net_multiplayer.h" + +#ifndef BUBLIC_SERVER +#include "network.h" +#include "screen_world.h" +#include "screen_setting.h" +#include "screen_choiceArena.h" +#include "client.h" +#endif + +#ifdef BUBLIC_SERVER +#include "publicServer.h" +#endif + extern void proto_send_hello_client(); extern void proto_recv_hello_server(client_t *client, char *msg); -extern void proto_send_init_server(client_t *client); +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(tux_t *tux, int action, client_t *client); +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(client_t *client, tux_t *tux); +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(tux_t *tux); +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(tux_t *tux); +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_deltux_server(client_t *client); +extern void proto_send_deltux_server(int type, client_t *client, client_t *client2); extern void proto_recv_deltux_client(char *msg); -extern void proto_send_additem_server(item_t *p); +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(shot_t *p); +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_context_client(tux_t *tux); extern void proto_recv_context_server(client_t *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(); -extern void proto_recv_ping_client(char *msg); extern void proto_send_end_client(); extern void proto_recv_end_server(client_t *client, char *msg); -extern void proto_send_end_server(); +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); #endif @@ -1 +1 @@ -26 +27 diff --git a/src/client.c b/src/client.c index 12c9c0f..8ca55e1 100644 --- a/src/client.c +++ b/src/client.c @@ -134,6 +134,10 @@ void sendServer(char *msg) #ifdef SUPPORT_NET_SDL_UDP ret = writeSdlUdpSocket(sock_server_sdl_udp, sock_server_sdl_udp, msg, strlen(msg)); #endif + +#ifdef DEBUG_CLIENT_SEND + printf("send server msg->%s", msg); +#endif } static int eventServerSelect() @@ -194,7 +198,9 @@ void eventServerBuffer() while ( getBufferLine(clientBuffer, line, STR_SIZE) >= 0 ) { - //printf("spracuvavam %s", line); +#ifdef DEBUG_CLIENT_RECV + printf("recv server msg->%s", line); +#endif if( strncmp(line, "init", 4) == 0 )proto_recv_init_client(line); if( strncmp(line, "event", 5) == 0 )proto_recv_event_client(line); @@ -176,7 +176,7 @@ void addNewItem(list_t *listItem, tux_t *author) if( getNetTypeGame() == NET_GAME_TYPE_SERVER ) { - proto_send_additem_server(item); + proto_send_additem_server(PROTO_SEND_ALL, NULL, item); } } @@ -6,6 +6,7 @@ #include "main.h" #include "pipe.h" #include "shot.h" +#include "net_multiplayer.h" #ifndef BUBLIC_SERVER #include "screen_world.h" @@ -178,7 +179,15 @@ void eventConflictShotWithPipe(list_t *listPipe, list_t *listShot) if( negPosition( thisShot->position ) == thisPipe->position ) { - moveShotFromPipe(thisShot, thisPipe, listPipe); + if( getNetTypeGame() == NET_GAME_TYPE_CLIENT ) + { + delListItem(listShot, i, destroyShot); + i--; + } + else + { + moveShotFromPipe(thisShot, thisPipe, listPipe); + } } else { diff --git a/src/proto.c b/src/proto.c index 0cda257..77ce16f 100644 --- a/src/proto.c +++ b/src/proto.c @@ -27,6 +27,39 @@ #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); +#ifdef DEBUG_SERVER_SEND + printf("send one client msg->%s", msg); +#endif + break; + case PROTO_SEND_ALL : + assert( client == NULL ); + sendAllClient(msg); +#ifdef DEBUG_SERVER_SEND + printf("send all clients msg->%s", msg); +#endif + break; + case PROTO_SEND_BUT : + assert( client != NULL ); + sendAllClientBut(msg, client); +#ifdef DEBUG_SERVER_SEND + printf("send but client msg->%s", msg); +#endif + break; + default : + assert( ! "Premenna type ma zlu hodnotu !" ); + break; + } +} + #ifndef BUBLIC_SERVER void proto_send_hello_client() @@ -43,22 +76,22 @@ void proto_recv_hello_server(client_t *client, char *msg) { } -void proto_send_init_server(client_t *client) +void proto_send_init_server(int type, client_t *client, client_t *client2) { char msg[STR_SIZE]; int n = 9999; - assert( client != NULL ); + assert( client2 != NULL ); #ifndef BUBLIC_SERVER getSettingCountRound(&n); #endif sprintf(msg, "init %d %d %d %d %s\n", - client->tux->id, client->tux->x, client->tux->y, + client2->tux->id, client2->tux->x, client2->tux->y, n, getArenaNetName( getChoiceArenaId() )); - sendClient(client, msg); + proto_send(type, client, msg); } #ifndef BUBLIC_SERVER @@ -92,7 +125,7 @@ void proto_recv_init_client(char *msg) #endif -void proto_send_event_server(tux_t *tux, int action, client_t *client) +void proto_send_event_server(int type, client_t *client, tux_t *tux, int action) { char msg[STR_SIZE]; @@ -100,7 +133,7 @@ void proto_send_event_server(tux_t *tux, int action, client_t *client) sprintf(msg, "event %d %d\n", tux->id, action); - sendAllClientBut(msg, client); + proto_send(type, client, msg); } #ifndef BUBLIC_SERVER @@ -150,10 +183,10 @@ void proto_recv_event_server(client_t *client, char *msg) actionTux(client->tux, action); - proto_send_event_server(client->tux, action, client); + proto_send_event_server(PROTO_SEND_BUT, client, client->tux, action); } -void proto_send_newtux_server(client_t *client, tux_t *tux) +void proto_send_newtux_server(int type, client_t *client, tux_t *tux) { char msg[STR_SIZE]; @@ -166,14 +199,7 @@ void proto_send_newtux_server(client_t *client, tux_t *tux) tux->shot[GUN_MINE], tux->shot[GUN_BOMBBALL], tux->bonus_time, tux->pickup_time); - if( client == NULL ) - { - sendAllClient(msg); - } - else - { - sendClient(client, msg); - } + proto_send(type, client, msg); } #ifndef BUBLIC_SERVER @@ -226,7 +252,7 @@ void proto_recv_newtux_client(char *msg) #endif -void proto_send_kill_server(tux_t *tux) +void proto_send_kill_server(int type, client_t *client, tux_t *tux) { char msg[STR_SIZE]; @@ -234,7 +260,7 @@ void proto_send_kill_server(tux_t *tux) sprintf(msg, "kill %d\n", tux->id); - sendAllClient(msg); + proto_send(type, client, msg); } #ifndef BUBLIC_SERVER @@ -259,7 +285,7 @@ void proto_recv_kill_client(char *msg) #endif -void proto_send_score_server(tux_t *tux) +void proto_send_score_server(int type, client_t *client, tux_t *tux) { char msg[STR_SIZE]; @@ -267,7 +293,7 @@ void proto_send_score_server(tux_t *tux) sprintf(msg, "score %d %d\n", tux->id, tux->score); - sendAllClient(msg); + proto_send(type, client, msg); } #ifndef BUBLIC_SERVER @@ -294,15 +320,15 @@ void proto_recv_score_client(char *msg) #endif -void proto_send_deltux_server(client_t *client) +void proto_send_deltux_server(int type, client_t *client, client_t *client2) { char msg[STR_SIZE]; - assert( client != NULL ); + assert( client2 != NULL ); - sprintf(msg, "deltux %d\n", client->tux->id); + sprintf(msg, "deltux %d\n", client2->tux->id); - sendAllClientBut(msg, client); + proto_send(type, client, msg); } #ifndef BUBLIC_SERVER @@ -330,7 +356,7 @@ void proto_recv_deltux_client(char *msg) #endif -void proto_send_additem_server(item_t *p) +void proto_send_additem_server(int type, client_t *client, item_t *p) { char msg[STR_SIZE]; int id = -1; @@ -345,7 +371,7 @@ void proto_send_additem_server(item_t *p) sprintf(msg, "additem %d %d %d %d %d %d\n", p->type, p->x, p->y, p->count, p->frame, id); - sendAllClient(msg); + proto_send(type, client, msg); } #ifndef BUBLIC_SERVER @@ -376,7 +402,7 @@ void proto_recv_additem_client(char *msg) #endif -void proto_send_shot_server(shot_t *p) +void proto_send_shot_server(int type, client_t *client, shot_t *p) { char msg[STR_SIZE]; int id = -1; @@ -391,7 +417,7 @@ void proto_send_shot_server(shot_t *p) sprintf(msg, "shot %d %d %d %d %d %d %d %d\n", p->x, p->y, p->px, p->py, p->position, p->gun, id, p->isCanKillAuthor); - sendAllClient(msg); + proto_send(type, client, msg); } #ifndef BUBLIC_SERVER @@ -450,7 +476,7 @@ void proto_recv_context_server(client_t *client, char *msg) strcpy(client->tux->name, name); - proto_send_newtux_server(NULL, client->tux); +// proto_send_newtux_server(NULL, client->tux); } #ifndef BUBLIC_SERVER @@ -493,11 +519,11 @@ void proto_recv_end_server(client_t *client, char *msg) client->status = NET_STATUS_ZOMBIE; } -void proto_send_ping_server() +void proto_send_ping_server(int type, client_t *client) { char msg[STR_SIZE]; strcpy(msg, "ping\n"); - sendAllClient(msg); + proto_send(type, client, msg); } #ifndef BUBLIC_SERVER @@ -513,11 +539,11 @@ void proto_recv_ping_client(char *msg) #endif -void proto_send_end_server() +void proto_send_end_server(int type, client_t *client) { char msg[STR_SIZE]; strcpy(msg, "end\n"); - sendAllClient(msg); + proto_send(type, client, msg); } diff --git a/src/screen_world.c b/src/screen_world.c index 45daee5..60260b9 100644 --- a/src/screen_world.c +++ b/src/screen_world.c @@ -241,7 +241,7 @@ static void netAction(tux_t *tux, int action) { if( getSettingGameType() == NET_GAME_TYPE_SERVER ) { - proto_send_event_server(tux , action, NULL); + proto_send_event_server(PROTO_SEND_ALL, NULL, tux , action); } if( getSettingGameType() == NET_GAME_TYPE_CLIENT ) @@ -290,8 +290,11 @@ static void control_keyboard_right(tux_t *tux) if( mapa[(SDLKey)SDLK_KP1] == SDL_PRESSED ) { - netAction(tux, TUX_SWITCH_GUN); - actionTux(tux, TUX_SWITCH_GUN); + if( tux->isCanSwitchGun == TRUE ) + { + netAction(tux, TUX_SWITCH_GUN); + actionTux(tux, TUX_SWITCH_GUN); + } } } @@ -308,7 +311,15 @@ static void control_keyboard_left(tux_t *tux) if( mapa[(SDLKey)SDLK_a] == SDL_PRESSED )actionTux(tux, TUX_LEFT); if( mapa[(SDLKey)SDLK_s] == SDL_PRESSED )actionTux(tux, TUX_DOWN); if( mapa[(SDLKey)SDLK_q] == SDL_PRESSED )actionTux(tux, TUX_SHOT); - if( mapa[(SDLKey)SDLK_TAB] == SDL_PRESSED )actionTux(tux, TUX_SWITCH_GUN); + + if( mapa[(SDLKey)SDLK_TAB] == SDL_PRESSED ) + { + if( tux->isCanSwitchGun == TRUE ) + { + netAction(tux, TUX_SWITCH_GUN); + actionTux(tux, TUX_SWITCH_GUN); + } + } } static void eventEsc() diff --git a/src/server.c b/src/server.c index f824c33..b66d97e 100644 --- a/src/server.c +++ b/src/server.c @@ -274,10 +274,10 @@ static void eventCreateClient(client_t *client) assert( client != NULL ); - proto_send_init_server(client); + proto_send_init_server(PROTO_SEND_ONE, client, client); #ifndef BUBLIC_SERVER - proto_send_newtux_server(client, + proto_send_newtux_server(PROTO_SEND_ONE, client, (tux_t *)(getWorldArena()->listTux->list[SERVER_INDEX_ROOT_TUX]) ); #endif @@ -288,15 +288,15 @@ static void eventCreateClient(client_t *client) if( thisTux != client->tux ) { - proto_send_newtux_server(thisClient, client->tux); - proto_send_newtux_server(client, thisTux); + proto_send_newtux_server(PROTO_SEND_ONE, thisClient, client->tux); + proto_send_newtux_server(PROTO_SEND_ONE, client, thisTux); } } for( i = 0 ; i < getWorldArena()->listItem->count; i++) { thisItem = (item_t *) getWorldArena()->listItem->list[i]; - proto_send_additem_server(thisItem); + proto_send_additem_server(PROTO_SEND_ONE, client, thisItem); } } @@ -385,7 +385,9 @@ static void eventClientBuffer(client_t *client) while( getBufferLine(client->buffer, line, STR_SIZE) >= 0 ) { - //printf("spracuvavam %s", line); +#ifdef DEBUG_SERVER_RECV + printf("recv client msg->%s", line); +#endif if( strncmp(line, "hello", 5) == 0 )proto_recv_hello_server(client, line); if( strncmp(line, "event", 5) == 0 )proto_recv_event_server(client, line); @@ -454,7 +456,7 @@ void selectServerTcpSocket() if( thisClient->status == NET_STATUS_ZOMBIE ) { - proto_send_deltux_server(thisClient); + proto_send_deltux_server(PROTO_SEND_ALL, NULL, thisClient); delListItem(listClient, i, destroyClient); } } @@ -484,7 +486,7 @@ static void delZombieCLient() if( thisClient->status == NET_STATUS_ZOMBIE ) { - proto_send_deltux_server(thisClient); + proto_send_deltux_server(PROTO_SEND_ALL, NULL, thisClient); delListItem(listClient, i, destroyClient); } } @@ -503,10 +505,10 @@ void eventPeriodicSyncClient() tux_t *thisTux; int i, j; - proto_send_ping_server(); + proto_send_ping_server(PROTO_SEND_ALL, NULL); #ifndef BUBLIC_SERVER - proto_send_newtux_server(NULL, + proto_send_newtux_server(PROTO_SEND_ALL, NULL, (tux_t *)(getWorldArena()->listTux->list[SERVER_INDEX_ROOT_TUX])); #endif for( i = 0 ; i < listClient->count; i++) @@ -521,7 +523,7 @@ void eventPeriodicSyncClient() if( thisClientSend != thisClientInfo && thisTux->status == TUX_STATUS_ALIVE ) { - proto_send_newtux_server(thisClientSend, thisTux); + proto_send_newtux_server(PROTO_SEND_ONE, thisClientSend, thisTux); } } } @@ -725,7 +727,7 @@ void selectServerSdlUdpSocket() static void quitServer() { - proto_send_end_server(); + proto_send_end_server(PROTO_SEND_ALL, NULL); assert( listClient != NULL ); destroyListItem(listClient, destroyClient); } @@ -297,9 +297,12 @@ void moveShot(shot_t *shot, int position, int src_x, int src_y, break; } + shot->x += shot->px; + shot->y += shot->py; + if( getNetTypeGame() == NET_GAME_TYPE_SERVER ) { - proto_send_shot_server(shot); + proto_send_shot_server(PROTO_SEND_ALL, NULL, shot); } } diff --git a/src/teleport.c b/src/teleport.c index b004589..397acb7 100644 --- a/src/teleport.c +++ b/src/teleport.c @@ -222,7 +222,7 @@ void eventTeleportTux(list_t *listTeleport, teleport_t *teleport, tux_t *tux) #endif if( getNetTypeGame() == NET_GAME_TYPE_SERVER ) { - proto_send_newtux_server(NULL, tux); + proto_send_newtux_server(PROTO_SEND_ALL, NULL, tux); } } } @@ -324,7 +324,7 @@ static void timer_spawnTux(void *p) if( getNetTypeGame() == NET_GAME_TYPE_SERVER ) { - proto_send_newtux_server(NULL, tux); + proto_send_newtux_server(PROTO_SEND_ALL, NULL, tux); } } @@ -389,7 +389,7 @@ void eventTuxIsDead(tux_t *tux) if( getNetTypeGame() == NET_GAME_TYPE_SERVER ) { - proto_send_kill_server(tux); + proto_send_kill_server(PROTO_SEND_ALL, NULL, tux); } } @@ -398,11 +398,11 @@ static void eventTuxIsDeadWIthShot(tux_t *tux, shot_t *shot) if( shot->author != NULL && shot->author != tux ) { shot->author->score++; - } - if( getNetTypeGame() == NET_GAME_TYPE_SERVER ) - { - proto_send_score_server(shot->author); + if( getNetTypeGame() == NET_GAME_TYPE_SERVER ) + { + proto_send_score_server(PROTO_SEND_ALL, NULL, shot->author); + } } countRoundInc(); @@ -426,7 +426,7 @@ void tuxTeleport(tux_t *tux) if( getNetTypeGame() == NET_GAME_TYPE_SERVER ) { - proto_send_newtux_server(NULL, tux); + proto_send_newtux_server(PROTO_SEND_ALL, NULL, tux); } } @@ -575,7 +575,8 @@ void switchTuxGun(tux_t *tux) { int i; - if( tux->isCanSwitchGun == FALSE ) + if( tux->control != TUX_CONTROL_NET && + tux->isCanSwitchGun == FALSE ) { return; } @@ -695,7 +696,7 @@ static void eventBonus(tux_t *tux) if( getNetTypeGame() == NET_GAME_TYPE_SERVER ) { - proto_send_newtux_server(NULL, tux); + proto_send_newtux_server(PROTO_SEND_ALL, NULL, tux); } } } |