From aec5ba5ca31f3d7c895beb658a93c353b2b8d5c1 Mon Sep 17 00:00:00 2001 From: oroborus Date: Sun, 23 Mar 2008 21:38:56 +0000 Subject: - zobratie zbrani/bonusov prebieha na server, a server tuto informaciu posiela clientom - server checkuje, ci ma client spravnu verziu - clientovy, ktory sa neprihlasil do hry prikazom hello, neposiela stavy aku su end, alebo deltux - oprava malej chyby v textfiled - posladna aktivita serveru/clienta zistuje druha strana na zaklade kazdeho prijateho packetu, nie iba podla packetu ping - server posile clientovy pakcety "error " ) nespravny pikaz, veriza, timeout git-svn-id: http://opensvn.csie.org/tuxanci_ng@33 0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e --- src/proto.c | 126 +++++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 107 insertions(+), 19 deletions(-) (limited to 'src/proto.c') diff --git a/src/proto.c b/src/proto.c index 974f84c..0707c72 100644 --- a/src/proto.c +++ b/src/proto.c @@ -38,21 +38,21 @@ static void proto_send(int type, client_t *client, char *msg) assert( client != NULL ); sendClient(client, msg); #ifdef DEBUG_SERVER_SEND - printf("send one client msg->%s", msg); + printf("send one client msg->%s\n", msg); #endif break; case PROTO_SEND_ALL : assert( client == NULL ); sendAllClient(msg); #ifdef DEBUG_SERVER_SEND - printf("send all clients msg->%s", msg); + printf("send all clients msg->%s\n", msg); #endif break; case PROTO_SEND_BUT : assert( client != NULL ); sendAllClientBut(msg, client); #ifdef DEBUG_SERVER_SEND - printf("send but client msg->%s", msg); + printf("send but client msg->%s\n", msg); #endif break; default : @@ -61,13 +61,39 @@ static void proto_send(int type, client_t *client, char *msg) } } +void proto_send_error_server(int type, client_t *client, int errorcode) +{ + char msg[STR_PROTO_SIZE]; + + sprintf(msg, "error %d\n", errorcode); + + proto_send(type, client, msg); +} + +#ifndef BUBLIC_SERVER + +void proto_recv_error_client(char *msg) +{ + char cmd[STR_PROTO_SIZE]; + int errorcode; + + assert( msg != NULL ); + + sscanf(msg, "%s %d", + cmd, &errorcode); + + printf("proto error code %d\n", errorcode); +} + +#endif + #ifndef BUBLIC_SERVER void proto_send_hello_client(char *name) { char msg[STR_PROTO_SIZE]; - sprintf(msg, "hello %s\n", name); + sprintf(msg, "hello %s %s\n", TUXANCI_NG_VERSION, name); sendServer(msg); } @@ -76,12 +102,23 @@ void proto_send_hello_client(char *name) void proto_recv_hello_server(client_t *client, char *msg) { char cmd[STR_PROTO_SIZE]; + char version[STR_NAME_SIZE]; char name[STR_NAME_SIZE]; assert( client != NULL ); - - sscanf(msg, "%s %s\n", cmd, name); + strcpy(version, ""); + strcpy(name, ""); + + sscanf(msg, "%s %s %s", cmd, version, name); + + if( strncmp(version, TUXANCI_NG_VERSION, strlen(TUXANCI_NG_VERSION)) != 0 ) + { + proto_send_error_server(PROTO_SEND_ONE, client, PROTO_ERROR_CODE_BAD_VERSION); + client->status = NET_STATUS_ZOMBIE; + return; + } + client->tux = newTux(); client->tux->control = TUX_CONTROL_NET; addList(getWorldArena()->listTux, client->tux); @@ -144,7 +181,7 @@ void proto_recv_init_client(char *msg) assert( msg != NULL ); - sscanf(msg, "%s %d %d %d %d %s\n", + sscanf(msg, "%s %d %d %d %d %s", cmd, &id, &x, &y, &n, arena_name); setWorldArena( getArenaIdFormNetName(arena_name) ); @@ -388,7 +425,7 @@ void proto_recv_deltux_client(char *msg) assert( msg != NULL ); - sscanf(msg, "%s %d\n", cmd, &id); + sscanf(msg, "%s %d", cmd, &id); tux = getTuxID(getWorldArena()->listTux, id); @@ -419,8 +456,8 @@ void proto_send_additem_server(int type, client_t *client, item_t *p) id = p->author->id; } - sprintf(msg, "additem %d %d %d %d %d %d\n", - p->type, p->x, p->y, p->count, p->frame, id); + sprintf(msg, "additem %d %d %d %d %d %d %d\n", + p->id, p->type, p->x, p->y, p->count, p->frame, id); proto_send(type, client, msg); } @@ -431,14 +468,14 @@ void proto_recv_additem_client(char *msg) { char term_msg[STR_SIZE]; char cmd[STR_PROTO_SIZE]; - int type, x, y, count, frame, id; + int id, type, x, y, count, frame, author_id; item_t *item; assert( msg != NULL ); - sscanf(msg, "%s %d %d %d %d %d %d\n", cmd, &type, &x, &y, &count, &frame, &id); + sscanf(msg, "%s %d %d %d %d %d %d %d", cmd, &id, &type, &x, &y, &count, &frame, &author_id); - item = newItem(x, y, type, getTuxID(getWorldArena()->listTux, id)); + item = newItem(x, y, type, getTuxID(getWorldArena()->listTux, author_id)); if( isConflictWithListItem(getWorldArena()->listItem, item->x, item->y, item->w, item->h) ) { @@ -446,6 +483,7 @@ void proto_recv_additem_client(char *msg) return; } + item->id = id; item->count = count; item->frame = frame; @@ -458,6 +496,61 @@ void proto_recv_additem_client(char *msg) #endif +void proto_send_item_server(int type, client_t *client, tux_t *tux, item_t *item) +{ + char msg[STR_PROTO_SIZE]; + int tux_id = -1; + + assert( item != NULL ); + + if( tux != NULL ) + { + tux_id = tux->id; + } + + sprintf(msg, "item %d %d\n", + tux_id, item->id); + + proto_send(type, client, msg); +} + +#ifndef BUBLIC_SERVER + +void proto_recv_item_client(char *msg) +{ + char cmd[STR_PROTO_SIZE]; + int tux_id, item_id; + arena_t *arena; + + item_t *item; + tux_t *tux; + + assert( msg != NULL ); + + sscanf(msg, "%s %d %d", cmd, &tux_id, &item_id); + + arena = getWorldArena(); + + item = getItemID(arena->listItem, item_id); + tux = getTuxID(arena->listTux, tux_id); + + if( item == NULL) + { + return; + } + + if( tux != NULL ) + { + eventGiveTuxItem(tux, arena->listItem, item); + } + else + { + mineExplosion(arena->listItem, item); + } +} + +#endif + void proto_send_shot_server(int type, client_t *client, shot_t *p) { char msg[STR_PROTO_SIZE]; @@ -486,7 +579,7 @@ void proto_recv_shot_client(char *msg) assert( msg != NULL ); - sscanf(msg, "%s %d %d %d %d %d %d %d %d\n", + sscanf(msg, "%s %d %d %d %d %d %d %d %d", cmd, &x, &y, &px, &py, &position, &gun, &id, &isCanKillAuthor); shot = newShot(x, y, px, py, gun, getTuxID(getWorldArena()->listTux, id)); @@ -550,11 +643,6 @@ void proto_send_ping_server(int type, client_t *client) void proto_recv_ping_client(char *msg) { - assert( msg != NULL ); - -#if defined SUPPORT_NET_UNIX_UDP || defined SUPPORT_NET_SDL_UDP - refreshPingServerAlive(); -#endif } #endif -- cgit v1.2.3