summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authororoborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e>2008-03-19 19:32:50 +0000
committeroroborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e>2008-03-19 19:32:50 +0000
commit01d613a7ccf695090262c9e22c396251146f00bd (patch)
tree3f176dd05944d108259f02d968e5b221704fb274 /src
parent11239bc45b51f9cc9eaec8272e58a0dea0e10b93 (diff)
- upravy v kode
git-svn-id: http://opensvn.csie.org/tuxanci_ng@27 0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e
Diffstat (limited to 'src')
-rw-r--r--src/client.c8
-rw-r--r--src/item.c2
-rw-r--r--src/pipe.c11
-rw-r--r--src/proto.c92
-rw-r--r--src/screen_world.c19
-rw-r--r--src/server.c26
-rw-r--r--src/shot.c5
-rw-r--r--src/teleport.c2
-rw-r--r--src/tux.c19
9 files changed, 121 insertions, 63 deletions
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);
diff --git a/src/item.c b/src/item.c
index 187885c..bcde2b1 100644
--- a/src/item.c
+++ b/src/item.c
@@ -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);
}
}
diff --git a/src/pipe.c b/src/pipe.c
index 5a435e4..dde1a11 100644
--- a/src/pipe.c
+++ b/src/pipe.c
@@ -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);
}
diff --git a/src/shot.c b/src/shot.c
index d105a5c..f9cfdb1 100644
--- a/src/shot.c
+++ b/src/shot.c
@@ -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);
}
}
}
diff --git a/src/tux.c b/src/tux.c
index c8b80cc..2c9c6a0 100644
--- a/src/tux.c
+++ b/src/tux.c
@@ -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);
}
}
}