diff options
Diffstat (limited to 'src/base/proto.c')
| -rw-r--r-- | src/base/proto.c | 1240 |
1 files changed, 605 insertions, 635 deletions
diff --git a/src/base/proto.c b/src/base/proto.c index 7fedb24..304eff8 100644 --- a/src/base/proto.c +++ b/src/base/proto.c @@ -38,106 +38,101 @@ #include "serverConfigFile.h" #endif -void -proto_send_error_server(int type, client_t * client, int errorcode) +void proto_send_error_server(int type, client_t *client, int errorcode) { - char msg[STR_PROTO_SIZE]; + char msg[STR_PROTO_SIZE]; + + snprintf(msg, STR_PROTO_SIZE, "error %d\n", errorcode); - snprintf(msg, STR_PROTO_SIZE, "error %d\n", errorcode); - - protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, - CHECK_FRONT_ID_NONE); + protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE); } #ifndef PUBLIC_SERVER -void -proto_recv_error_client(char *msg) +void proto_recv_error_client(char *msg) { - char cmd[STR_PROTO_SIZE]; - int errorcode; - int recv_count; + char cmd[STR_PROTO_SIZE]; + int errorcode; + int recv_count; - assert(msg != NULL); + assert( msg != NULL ); - recv_count = sscanf(msg, "%s %d", cmd, &errorcode); + recv_count = sscanf(msg, "%s %d", + cmd, &errorcode); - if (recv_count != 2) { - return; - } + if( recv_count != 2 ) + { + return; + } #ifdef DEBUG - printf(_("Proto error code: \"%d\"\n"), errorcode); + printf(_("Proto error code: \"%d\"\n"), errorcode); #endif - switch (errorcode) { - case PROTO_ERROR_CODE_BAD_VERSION: - setMsgToAnalyze(_ - ("Version of your client isn't supported by the server.")); - setWorldEnd(); - break; - case PROTO_ERROR_CODE_TIMEOUT: - setMsgToAnalyze(_("The timeout of ping from server is out")); - setWorldEnd(); - break; - case PROTO_ERROR_LIMIT_MAX_CLIENT: - setMsgToAnalyze(_ - ("The maximum amount of connected players has been exceeded!")); - setWorldEnd(); - break; - } + switch(errorcode) + { + case PROTO_ERROR_CODE_BAD_VERSION : + setMsgToAnalyze(_("Version of your client isn't supported by the server.")); + setWorldEnd(); + break; + case PROTO_ERROR_CODE_TIMEOUT : + setMsgToAnalyze(_("The timeout of ping from server is out")); + setWorldEnd(); + break; + case PROTO_ERROR_LIMIT_MAX_CLIENT : + setMsgToAnalyze(_("The maximum amount of connected players has been exceeded!")); + setWorldEnd(); + break; + } } #endif #ifndef PUBLIC_SERVER -void -proto_send_hello_client(char *name) +void proto_send_hello_client(char *name) { - char msg[STR_PROTO_SIZE]; - - snprintf(msg, STR_PROTO_SIZE, "hello %s %s\n", - getParamElse("--version", TUXANCI_VERSION), name); - sendServer(msg); + char msg[STR_PROTO_SIZE]; + + snprintf(msg, STR_PROTO_SIZE, "hello %s %s\n", getParamElse("--version", TUXANCI_VERSION), name); + sendServer(msg); } #endif -static void -action_sendItem(space_t * space, item_t * item, client_t * client) +static void action_sendItem(space_t *space, item_t *item, client_t *client) { - proto_send_additem_server(PROTO_SEND_ONE, client, item); + proto_send_additem_server(PROTO_SEND_ONE, client, item); } -static void -sendInfoCreateClient(client_t * client) +static void sendInfoCreateClient(client_t *client) { - list_t *listClient; - client_t *thisClient; - tux_t *thisTux; - int i; + list_t *listClient; + client_t *thisClient; + tux_t *thisTux; + int i; - assert(client != NULL); + assert( client != NULL ); - listClient = getListServerClient(); + listClient = getListServerClient(); - proto_send_init_server(PROTO_SEND_ONE, client, client); + proto_send_init_server(PROTO_SEND_ONE, client, client); #ifndef PUBLIC_SERVER - proto_send_newtux_server(PROTO_SEND_ONE, client, - getControlTux(TUX_CONTROL_KEYBOARD_RIGHT)); + proto_send_newtux_server(PROTO_SEND_ONE, client, getControlTux(TUX_CONTROL_KEYBOARD_RIGHT) ); #endif - for (i = 0; i < listClient->count; i++) { - thisClient = (client_t *) listClient->list[i]; - thisTux = thisClient->tux; - - if (thisTux != NULL && thisTux != client->tux) { - proto_send_newtux_server(PROTO_SEND_ONE, thisClient, client->tux); - proto_send_newtux_server(PROTO_SEND_ONE, client, thisTux); - } - } + for( i = 0 ; i < listClient->count; i++) + { + thisClient = (client_t *) listClient->list[i]; + thisTux = thisClient->tux; + + if( thisTux != NULL && thisTux != client->tux ) + { + proto_send_newtux_server(PROTO_SEND_ONE, thisClient, client->tux); + proto_send_newtux_server(PROTO_SEND_ONE, client, thisTux); + } + } - actionSpace(getCurrentArena()->spaceItem, action_sendItem, client); + actionSpace(getCurrentArena()->spaceItem, action_sendItem, client); /* for( i = 0 ; i < getCurrentArena()->spaceItem->listIndex->count; i++) { @@ -147,891 +142,866 @@ sendInfoCreateClient(client_t * client) */ } -void -proto_recv_hello_server(client_t * client, char *msg) +void proto_recv_hello_server(client_t *client, char *msg) { - static char *supportVersion = NULL; - char cmd[STR_PROTO_SIZE]; - char version[STR_NAME_SIZE]; - char name[STR_NAME_SIZE]; - int recv_count; - - assert(client != NULL); + static char *supportVersion = NULL; + char cmd[STR_PROTO_SIZE]; + char version[STR_NAME_SIZE]; + char name[STR_NAME_SIZE]; + int recv_count; - if (getSpaceCount(getCurrentArena()->spaceTux) + 1 > getServerMaxClients()) { - proto_send_error_server(PROTO_SEND_ONE, client, - PROTO_ERROR_LIMIT_MAX_CLIENT); - eventMsgInCheckFront(client); - client->status = NET_STATUS_ZOMBIE; - return; - } - - strcpy(version, ""); - strcpy(name, ""); + assert( client != NULL ); + + if( getSpaceCount(getCurrentArena()->spaceTux)+1 > getServerMaxClients() ) + { + proto_send_error_server(PROTO_SEND_ONE, client, PROTO_ERROR_LIMIT_MAX_CLIENT); + eventMsgInCheckFront(client); + client->status = NET_STATUS_ZOMBIE; + return; + } + strcpy(version, ""); + strcpy(name, ""); + #ifdef PUBLIC_SERVER - if (supportVersion == NULL) { - supportVersion = - getSetting("SUPPORT_CLIENTS", "--support-clients", TUXANCI_VERSION); - } + if( supportVersion == NULL ) + { + supportVersion = getSetting("SUPPORT_CLIENTS", "--support-clients", TUXANCI_VERSION); + } #endif #ifndef PUBLIC_SERVER - if (supportVersion == NULL) { - supportVersion = TUXANCI_VERSION; - } + if( supportVersion == NULL ) + { + supportVersion = TUXANCI_VERSION; + } #endif - recv_count = sscanf(msg, "%s %s %s", cmd, version, name); + recv_count = sscanf(msg, "%s %s %s", cmd, version, name); - if (recv_count != 3) { - return; - } + if( recv_count != 3 ) + { + return; + } - if (strstr(supportVersion, version) == NULL) { - proto_send_error_server(PROTO_SEND_ONE, client, - PROTO_ERROR_CODE_BAD_VERSION); - eventMsgInCheckFront(client); - client->status = NET_STATUS_ZOMBIE; - return; - } + if( strstr(supportVersion, version ) == NULL ) + { + proto_send_error_server(PROTO_SEND_ONE, client, PROTO_ERROR_CODE_BAD_VERSION); + eventMsgInCheckFront(client); + client->status = NET_STATUS_ZOMBIE; + return; + } - client->tux = newTux(); - client->tux->control = TUX_CONTROL_NET; - client->tux->client = client; + client->tux = newTux(); + client->tux->control = TUX_CONTROL_NET; + client->tux->client = client; - addObjectToSpace(getCurrentArena()->spaceTux, client->tux); + addObjectToSpace(getCurrentArena()->spaceTux, client->tux); - if (strlen(name) > STR_NAME_SIZE - 1) { - name[STR_NAME_SIZE - 1] = '\0'; - } + if( strlen(name) > STR_NAME_SIZE-1 ) + { + name[STR_NAME_SIZE-1] = '\0'; + } - tuxSetName(client->tux, name); - sendInfoCreateClient(client); + tuxSetName(client->tux, name); + sendInfoCreateClient(client); } -void -proto_send_status_server(int type, client_t * client) +void proto_send_status_server(int type, client_t *client) { - char msg[STR_PROTO_SIZE]; - char *name; - char *version; - int clients; - int maxclients; - unsigned int uptime; - char *arena; + char msg[STR_PROTO_SIZE]; + char *name; + char *version; + int clients; + int maxclients; + unsigned int uptime; + char *arena; #ifndef PUBLIC_SERVER - name = "noname"; + name = "noname"; #endif #ifdef PUBLIC_SERVER - name = getSetting("NAME", "--name", "noname"); + name = getSetting("NAME", "--name", "noname"); #endif - version = TUXANCI_VERSION; - clients = getCurrentArena()->spaceTux->listIndex->count; - maxclients = getServerMaxClients(); - uptime = (unsigned int) getUpdateServer(); - arena = getArenaNetName(getChoiceArena()); - - snprintf(msg, STR_PROTO_SIZE, - "name: %s\n" - "version: %s\n" - "clients: %d\n" - "maxclients: %d\n" - "uptime: %d\n" - "arena: %s\n", name, version, clients, maxclients, uptime, arena); - - protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, - CHECK_FRONT_ID_NONE); - //proto_send(type, client, msg); + version = TUXANCI_VERSION; + clients = getCurrentArena()->spaceTux->listIndex->count; + maxclients = getServerMaxClients(); + uptime = (unsigned int)getUpdateServer(); + arena = getArenaNetName( getChoiceArena() ); + + snprintf(msg, STR_PROTO_SIZE, + "name: %s\n" + "version: %s\n" + "clients: %d\n" + "maxclients: %d\n" + "uptime: %d\n" + "arena: %s\n", + + name, version, clients, + maxclients, uptime, arena); + + protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE); + //proto_send(type, client, msg); } -void -proto_recv_status_server(client_t * client, char *msg) +void proto_recv_status_server(client_t *client, char *msg) { - proto_send_status_server(PROTO_SEND_ONE, client); + proto_send_status_server(PROTO_SEND_ONE, client); } #ifdef PUBLIC_SERVER -void -proto_send_listscore_server(int type, client_t * client, int max) +void proto_send_listscore_server(int type, client_t *client, int max) { - char *str; - char *msg; - int i; + char *str; + char *msg; + int i; - msg = malloc((max * 48) * sizeof(char)); - strcpy(msg, ""); + msg = malloc( (max * 48) * sizeof(char) ); + strcpy(msg, ""); - for (i = 0; i < max; i++) { - str = getTableItem(i); + for( i = 0 ; i < max ; i++ ) + { + str = getTableItem(i); - if (str == NULL) { - break; - } + if( str == NULL ) + { + break; + } - strcat(msg, str); - strcat(msg, "\n"); - } + strcat(msg, str); + strcat(msg, "\n"); + } - //proto_send(type, client, msg); - protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, - CHECK_FRONT_ID_NONE); - free(msg); + //proto_send(type, client, msg); + protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE); + free(msg); } -void -proto_recv_listscore_server(client_t * client, char *msg) +void proto_recv_listscore_server(client_t *client, char *msg) { - char cmd[STR_PROTO_SIZE]; - int recv_count; - int max; + char cmd[STR_PROTO_SIZE]; + int recv_count; + int max; - assert(msg != NULL); + assert( msg != NULL ); - recv_count = sscanf(msg, "%s %d", cmd, &max); + recv_count = sscanf(msg, "%s %d", + cmd, &max); - if (recv_count != 2) { - max = HEIGHTSCORE_MAX_PLAYERS; - } + if( recv_count != 2 ) + { + max = HEIGHTSCORE_MAX_PLAYERS; + } - proto_send_listscore_server(PROTO_SEND_ONE, client, max); + proto_send_listscore_server(PROTO_SEND_ONE, client, max); } #endif #ifndef PUBLIC_SERVER -void -proto_send_check_client(int id) +void proto_send_check_client(int id) { - char msg[STR_PROTO_SIZE]; - - snprintf(msg, STR_PROTO_SIZE, "check %d\n", id); - sendServer(msg); + char msg[STR_PROTO_SIZE]; + + snprintf(msg, STR_PROTO_SIZE, "check %d\n", id); + sendServer(msg); } #endif -void -proto_recv_check_server(client_t * client, char *msg) +void proto_recv_check_server(client_t *client, char *msg) { - char cmd[STR_PROTO_SIZE]; - int recv_count; - int id; + char cmd[STR_PROTO_SIZE]; + int recv_count; + int id; - assert(msg != NULL); + assert( msg != NULL ); - recv_count = sscanf(msg, "%s %d", cmd, &id); + recv_count = sscanf(msg, "%s %d", + cmd, &id); - if (recv_count != 2) { - return; - } + if( recv_count != 2 ) + { + return; + } - delMsgInCheckFront(client->listSendMsg, id); + delMsgInCheckFront(client->listSendMsg, id); } -void -proto_send_init_server(int type, client_t * client, client_t * client2) +void proto_send_init_server(int type, client_t *client, client_t *client2) { - char msg[STR_PROTO_SIZE]; - int count; - int check_id; + char msg[STR_PROTO_SIZE]; + int count; + int check_id; - assert(client2 != NULL); + assert( client2 != NULL ); - count = WORLD_COUNT_ROUND_UNLIMITED; + count = WORLD_COUNT_ROUND_UNLIMITED; #ifndef PUBLIC_SERVER - getSettingCountRound(&count); + getSettingCountRound(&count); #endif - check_id = getNewIDcount(0); - - snprintf(msg, STR_PROTO_SIZE, "init %d %d %d %d %s %d\n", - client2->tux->id, client2->tux->x, client2->tux->y, - count, getArenaNetName(getChoiceArena()), check_id); - - //proto_send(type, client, msg); - protoSendClient(type, client, msg, CHECK_FRONT_TYPE_CHECK, check_id); + check_id = getNewIDcount(0); + + snprintf(msg, STR_PROTO_SIZE, "init %d %d %d %d %s %d\n", + client2->tux->id, client2->tux->x, client2->tux->y, + count, getArenaNetName( getChoiceArena() ), check_id); + + //proto_send(type, client, msg); + protoSendClient(type, client, msg, CHECK_FRONT_TYPE_CHECK, check_id); } #ifndef PUBLIC_SERVER -void -proto_recv_init_client(char *msg) +void proto_recv_init_client(char *msg) { - char cmd[STR_PROTO_SIZE]; - char arena_name[STR_PROTO_SIZE]; - tux_t *tux; - int id; - int x, y, n; - int check_id; - int recv_count; - arena_t *arena; + char cmd[STR_PROTO_SIZE]; + char arena_name[STR_PROTO_SIZE]; + tux_t *tux; + int id; + int x, y, n; + int check_id; + int recv_count; + arena_t *arena; - assert(msg != NULL); + assert( msg != NULL ); - recv_count = sscanf(msg, "%s %d %d %d %d %s %d", - cmd, &id, &x, &y, &n, arena_name, &check_id); + recv_count = sscanf(msg, "%s %d %d %d %d %s %d", + cmd, &id, &x, &y, &n, arena_name, &check_id); - if (recv_count != 7) { - return; - } + if( recv_count != 7 ) + { + return; + } - proto_send_check_client(check_id); + proto_send_check_client(check_id); - if (getCurrentArena() != NULL) { - return; - } + if( getCurrentArena() != NULL ) + { + return; + } - setWorldArena(getArenaFileFormNetName(arena_name)); + setWorldArena( getArenaFileFormNetName(arena_name) ); - arena = getCurrentArena(); - arena->max_countRound = n; + arena = getCurrentArena(); + arena->max_countRound = n; - tux = newTux(); - replaceTuxID(tux, id); - tux->x = x; - tux->y = y; - tux->control = TUX_CONTROL_KEYBOARD_RIGHT; - setControlTux(tux, TUX_CONTROL_KEYBOARD_RIGHT); + tux = newTux(); + replaceTuxID(tux, id); + tux->x = x; + tux->y = y; + tux->control = TUX_CONTROL_KEYBOARD_RIGHT; + setControlTux(tux, TUX_CONTROL_KEYBOARD_RIGHT); - getSettingNameRight(tux->name); + getSettingNameRight(tux->name); - addObjectToSpace(arena->spaceTux, tux); + addObjectToSpace(arena->spaceTux, tux); } #endif -void -proto_send_event_server(int type, client_t * client, tux_t * tux, int action) +void proto_send_event_server(int type, client_t *client, tux_t *tux, int action) { - char msg[STR_PROTO_SIZE]; - - snprintf(msg, STR_PROTO_SIZE, "event %d %d\n", tux->id, action); - - //proto_send(type, client, msg); - protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, - CHECK_FRONT_ID_NONE); + char msg[STR_PROTO_SIZE]; + + snprintf(msg, STR_PROTO_SIZE, "event %d %d\n", tux->id, action); + + //proto_send(type, client, msg); + protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE); } #ifndef PUBLIC_SERVER -void -proto_recv_event_client(char *msg) +void proto_recv_event_client(char *msg) { - char cmd[STR_PROTO_SIZE]; - int id, action; - tux_t *tux; - int recv_count; + char cmd[STR_PROTO_SIZE]; + int id, action; + tux_t *tux; + int recv_count; - assert(msg != NULL); + assert( msg != NULL ); - recv_count = sscanf(msg, "%s %d %d", cmd, &id, &action); + recv_count = sscanf(msg, "%s %d %d", cmd, &id, &action); - if (recv_count != 3) { - return; - } + if( recv_count != 3 ) + { + return; + } - tux = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, id); + tux = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, id); - if (tux != NULL) { - actionTux(tux, action); - addToRadar(tux->id, tux->x, tux->y, RADAR_TYPE_TUX); - } + if( tux != NULL ) + { + actionTux(tux, action); + addToRadar(tux->id, tux->x, tux->y, RADAR_TYPE_TUX); + } } #endif #ifndef PUBLIC_SERVER -void -proto_send_event_client(int action) +void proto_send_event_client(int action) { - char msg[STR_PROTO_SIZE]; - - snprintf(msg, STR_PROTO_SIZE, "event %d\n", action); - - sendServer(msg); + char msg[STR_PROTO_SIZE]; + + snprintf(msg, STR_PROTO_SIZE, "event %d\n", action); + + sendServer(msg); } #endif -void -proto_recv_event_server(client_t * client, char *msg) +void proto_recv_event_server(client_t *client, char *msg) { - char cmd[STR_PROTO_SIZE]; - int action; - int recv_count; + char cmd[STR_PROTO_SIZE]; + int action; + int recv_count; - assert(client != NULL); - assert(msg != NULL); + assert( client != NULL ); + assert( msg != NULL ); - //debug_interval(); + //debug_interval(); - recv_count = sscanf(msg, "%s %d", cmd, &action); + recv_count = sscanf(msg, "%s %d", cmd, &action); - if (recv_count != 2) { - return; - } + if( recv_count != 2 ) + { + return; + } - if (client->tux->bonus != BONUS_HIDDEN) { - proto_send_event_server(PROTO_SEND_ALL_SEES_TUX, client, client->tux, - action); - } + if( client->tux->bonus != BONUS_HIDDEN ) + { + proto_send_event_server(PROTO_SEND_ALL_SEES_TUX, client, client->tux, action); + } - refreshLastMove(client->protect); + refreshLastMove(client->protect); - actionTux(client->tux, action); + actionTux(client->tux, action); } -void -proto_send_newtux_server(int type, client_t * client, tux_t * tux) +void proto_send_newtux_server(int type, client_t *client, tux_t *tux) { - char msg[STR_PROTO_SIZE]; - int x, y; - - assert(tux != NULL); - - if (tux->bonus == BONUS_HIDDEN) { - x = TUX_LOCATE_UNKNOWN; - y = TUX_LOCATE_UNKNOWN; - } - else { - getTuxProportion(tux, &x, &y, NULL, NULL); - } - - snprintf(msg, STR_PROTO_SIZE, - "newtux %d %d %d %d %d %d %d %s %d %d %d %d %d %d %d %d %d %d %d\n", - tux->id, x, y, tux->status, tux->position, tux->frame, tux->score, - tux->name, tux->gun, tux->bonus, tux->shot[GUN_SIMPLE], - tux->shot[GUN_DUAL_SIMPLE], tux->shot[GUN_SCATTER], - tux->shot[GUN_TOMMY], tux->shot[GUN_LASSER], tux->shot[GUN_MINE], - tux->shot[GUN_BOMBBALL], tux->bonus_time, tux->pickup_time); - - //proto_send(type, client, msg); - protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, - CHECK_FRONT_ID_NONE); + char msg[STR_PROTO_SIZE]; + int x, y; + + assert( tux != NULL ); + + if( tux->bonus == BONUS_HIDDEN ) + { + x = TUX_LOCATE_UNKNOWN; + y = TUX_LOCATE_UNKNOWN; + } + else + { + getTuxProportion(tux, &x, &y, NULL, NULL); + } + + snprintf(msg, STR_PROTO_SIZE, + "newtux %d %d %d %d %d %d %d %s %d %d %d %d %d %d %d %d %d %d %d\n", + tux->id ,x, y, tux->status, tux->position ,tux->frame, tux->score, tux->name, + tux->gun, tux->bonus, tux->shot[GUN_SIMPLE], tux->shot[GUN_DUAL_SIMPLE], + tux->shot[GUN_SCATTER], tux->shot[GUN_TOMMY], tux->shot[GUN_LASSER], + tux->shot[GUN_MINE], tux->shot[GUN_BOMBBALL], + tux->bonus_time, tux->pickup_time); + + //proto_send(type, client, msg); + protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE); } #ifndef PUBLIC_SERVER -void -proto_recv_newtux_client(char *msg) +void proto_recv_newtux_client(char *msg) { - char cmd[STR_PROTO_SIZE]; - char name[STR_NAME_SIZE]; - int id, x, y, status, position, frame, score; - int myGun, myBonus; - int gun1, gun2, gun3, gun4, gun5, gun6, gun7; - int time1, time2; - tux_t *tux; - int recv_count; - - assert(msg != NULL); - - if (getCurrentArena() == NULL) { - return; - } - - recv_count = - sscanf(msg, - "%s %d %d %d %d %d %d %d %s %d %d %d %d %d %d %d %d %d %d %d", - cmd, &id, &x, &y, &status, &position, &frame, &score, name, - &myGun, &myBonus, &gun1, &gun2, &gun3, &gun4, &gun5, &gun6, - &gun7, &time1, &time2); - - if (recv_count != 20) { - return; - } - - tux = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, id); - - if (tux != NULL) { - assert(tux->id == id); - } - - if (tux == NULL) { - tux = newTux(); - replaceTuxID(tux, id); - tux->control = TUX_CONTROL_NET; - addObjectToSpace(getCurrentArena()->spaceTux, tux); - } - - if (tux->control == TUX_CONTROL_KEYBOARD_RIGHT && - x == TUX_LOCATE_UNKNOWN && y == TUX_LOCATE_UNKNOWN) { - getTuxProportion(tux, &x, &y, NULL, NULL); - } - - addToRadar(id, x, y, RADAR_TYPE_TUX); - - if (tux->bonus == BONUS_HIDDEN) { - delFromRadar(id); - } - - moveObjectInSpace(getCurrentArena()->spaceTux, tux, x, y); - tux->status = status; - tux->position = position; - tux->frame = frame; - tux->score = score; - strcpy(tux->name, name); - tux->gun = myGun; - tux->bonus = myBonus; - tux->shot[GUN_SIMPLE] = gun1; - tux->shot[GUN_DUAL_SIMPLE] = gun2; - tux->shot[GUN_SCATTER] = gun3; - tux->shot[GUN_TOMMY] = gun4; - tux->shot[GUN_LASSER] = gun5; - tux->shot[GUN_MINE] = gun6; - tux->shot[GUN_BOMBBALL] = gun7; - tux->bonus_time = time1; - tux->pickup_time = time2; + char cmd[STR_PROTO_SIZE]; + char name[STR_NAME_SIZE]; + int id, x, y, status, position, frame, score; + int myGun, myBonus; + int gun1, gun2, gun3, gun4, gun5, gun6, gun7; + int time1, time2; + tux_t *tux; + int recv_count; + + assert( msg != NULL ); + + if( getCurrentArena() == NULL ) + { + return; + } + + recv_count = sscanf(msg, "%s %d %d %d %d %d %d %d %s %d %d %d %d %d %d %d %d %d %d %d", + cmd, &id, &x, &y, &status, &position, &frame, &score, name, + &myGun, &myBonus, &gun1, &gun2, &gun3, &gun4, &gun5, &gun6, &gun7, &time1, &time2); + + if( recv_count != 20 ) + { + return; + } + + tux = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, id); + + if( tux != NULL ) + { + assert( tux->id == id ); + } + + if( tux == NULL ) + { + tux = newTux(); + replaceTuxID(tux, id); + tux->control = TUX_CONTROL_NET; + addObjectToSpace(getCurrentArena()->spaceTux, tux); + } + + if( tux->control == TUX_CONTROL_KEYBOARD_RIGHT && + x == TUX_LOCATE_UNKNOWN && y == TUX_LOCATE_UNKNOWN ) + { + getTuxProportion(tux, &x, &y, NULL, NULL); + } + + addToRadar(id, x, y, RADAR_TYPE_TUX); + + if( tux->bonus == BONUS_HIDDEN ) + { + delFromRadar(id); + } + + moveObjectInSpace(getCurrentArena()->spaceTux, tux, x, y); + tux->status = status; + tux->position = position; + tux->frame = frame; + tux->score = score; + strcpy(tux->name, name); + tux->gun = myGun; + tux->bonus = myBonus; + tux->shot[GUN_SIMPLE] = gun1; + tux->shot[GUN_DUAL_SIMPLE] = gun2; + tux->shot[GUN_SCATTER] = gun3; + tux->shot[GUN_TOMMY] = gun4; + tux->shot[GUN_LASSER] = gun5; + tux->shot[GUN_MINE] = gun6; + tux->shot[GUN_BOMBBALL] = gun7; + tux->bonus_time = time1; + tux->pickup_time = time2; } #endif -void -proto_send_kill_server(int type, client_t * client, tux_t * tux) +void proto_send_kill_server(int type, client_t *client, tux_t *tux) { - char msg[STR_PROTO_SIZE]; - - assert(tux != NULL); + char msg[STR_PROTO_SIZE]; + + assert( tux != NULL ); - snprintf(msg, STR_PROTO_SIZE, "kill %d\n", tux->id); - - //proto_send(type, client, msg); - protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, - CHECK_FRONT_ID_NONE); + snprintf(msg, STR_PROTO_SIZE, "kill %d\n", tux->id); + + //proto_send(type, client, msg); + protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE); } #ifndef PUBLIC_SERVER -void -proto_recv_kill_client(char *msg) +void proto_recv_kill_client(char *msg) { - char cmd[STR_PROTO_SIZE]; - int id; - tux_t *tux; - int recv_count; + char cmd[STR_PROTO_SIZE]; + int id; + tux_t *tux; + int recv_count; - assert(msg != NULL); + assert( msg != NULL ); - recv_count = sscanf(msg, "%s %d", cmd, &id); + recv_count = sscanf(msg, "%s %d", cmd, &id); - if (recv_count != 2) { - return; - } + if( recv_count != 2 ) + { + return; + } - tux = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, id); + tux = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, id); - if (tux != NULL) { - eventTuxIsDead(tux); - } + if( tux != NULL ) + { + eventTuxIsDead(tux); + } } #endif -void -proto_send_del_server(int type, client_t * client, int id) +void proto_send_del_server(int type, client_t *client, int id) { - char msg[STR_PROTO_SIZE]; - int check_id; + char msg[STR_PROTO_SIZE]; + int check_id; - check_id = getNewIDcount(0); + check_id = getNewIDcount(0); - snprintf(msg, STR_PROTO_SIZE, "del %d %d\n", id, check_id); + snprintf(msg, STR_PROTO_SIZE, "del %d %d\n", + id, check_id); - protoSendClient(type, client, msg, CHECK_FRONT_TYPE_CHECK, check_id); - //proto_check(type, client, msg, check_id); + protoSendClient(type, client, msg, CHECK_FRONT_TYPE_CHECK, check_id); + //proto_check(type, client, msg, check_id); } #ifndef PUBLIC_SERVER -void -proto_recv_del_client(char *msg) +void proto_recv_del_client(char *msg) { - char cmd[STR_PROTO_SIZE]; - int id, check_id; - tux_t *tux; - shot_t *shot; - item_t *item; - int recv_count; - - assert(msg != NULL); - - recv_count = sscanf(msg, "%s %d %d", cmd, &id, &check_id); - - if (recv_count != 3) { - return; - } - - proto_send_check_client(check_id); - - tux = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, id); - - if (tux != NULL) { - delFromRadar(id); - delObjectFromSpaceWithObject(getCurrentArena()->spaceTux, tux, - destroyTux); - return; - } - - shot = getObjectFromSpaceWithID(getCurrentArena()->spaceShot, id); - - if (shot != NULL) { - //printf("delete shot..\n"); - delFromRadar(id); - delObjectFromSpaceWithObject(getCurrentArena()->spaceShot, shot, - destroyShot); - return; - } - - item = getObjectFromSpaceWithID(getCurrentArena()->spaceItem, id); - - if (item != NULL) { - //printf("delete item..\n"); - delFromRadar(id); - delObjectFromSpaceWithObject(getCurrentArena()->spaceItem, item, - destroyItem); - return; - } + char cmd[STR_PROTO_SIZE]; + int id, check_id; + tux_t *tux; + shot_t *shot; + item_t *item; + int recv_count; + + assert( msg != NULL ); + + recv_count = sscanf(msg, "%s %d %d", + cmd, &id, &check_id); + + if( recv_count != 3 ) + { + return; + } + + proto_send_check_client(check_id); + + tux = getObjectFromSpaceWithID(getCurrentArena()->spaceTux, id); + + if( tux != NULL ) + { + delFromRadar(id); + delObjectFromSpaceWithObject(getCurrentArena()->spaceTux, tux, destroyTux); + return; + } + + shot = getObjectFromSpaceWithID(getCurrentArena()->spaceShot, id); + + if( shot != NULL ) + { + //printf("delete shot..\n"); + delFromRadar(id); + delObjectFromSpaceWithObject(getCurrentArena()->spaceShot, shot, destroyShot); + return; + } + + item = getObjectFromSpaceWithID(getCurrentArena()->spaceItem, id); + + if( item != NULL ) + { + //printf("delete item..\n"); + delFromRadar(id); + delObjectFromSpaceWithObject(getCurrentArena()->spaceItem, item, destroyItem); + return; + } } #endif -void -proto_send_additem_server(int type, client_t * client, item_t * p) +void proto_send_additem_server(int type, client_t *client, item_t *p) { - char msg[STR_PROTO_SIZE]; - int check_id; + char msg[STR_PROTO_SIZE]; + int check_id; - assert(p != NULL); + assert( p != NULL ); - check_id = getNewIDcount(0); + check_id = getNewIDcount(0); - snprintf(msg, STR_PROTO_SIZE, "additem %d %d %d %d %d %d %d %d\n", - p->id, p->type, p->x, p->y, p->count, p->frame, p->author_id, - check_id); + snprintf(msg, STR_PROTO_SIZE, "additem %d %d %d %d %d %d %d %d\n", + p->id, p->type, p->x, p->y, p->count, p->frame, p->author_id, check_id); - //proto_send(type, client, msg); - //proto_check(type, client, msg, check_id); - protoSendClient(type, client, msg, CHECK_FRONT_TYPE_CHECK, check_id); + //proto_send(type, client, msg); + //proto_check(type, client, msg, check_id); + protoSendClient(type, client, msg, CHECK_FRONT_TYPE_CHECK, check_id); } #ifndef PUBLIC_SERVER -void -proto_recv_additem_client(char *msg) +void proto_recv_additem_client(char *msg) { - char cmd[STR_PROTO_SIZE]; - int id, type, x, y, count, frame, author_id, check_id; - item_t *item; - int recv_count; + char cmd[STR_PROTO_SIZE]; + int id, type, x, y, count, frame, author_id, check_id; + item_t *item; + int recv_count; - assert(msg != NULL); + assert( msg != NULL ); - if (getCurrentArena() == NULL) { - return; - } + if( getCurrentArena() == NULL ) + { + return; + } - recv_count = sscanf(msg, "%s %d %d %d %d %d %d %d %d", - cmd, &id, &type, &x, &y, &count, &frame, &author_id, - &check_id); + recv_count = sscanf(msg, "%s %d %d %d %d %d %d %d %d", + cmd, &id, &type, &x, &y, &count, &frame, &author_id, &check_id); - if (recv_count != 9) { - return; - } + if( recv_count != 9 ) + { + return; + } - proto_send_check_client(check_id); + proto_send_check_client(check_id); - if ((item = - getObjectFromSpaceWithID(getCurrentArena()->spaceItem, id)) != NULL) { - return; - } + if( ( item = getObjectFromSpaceWithID(getCurrentArena()->spaceItem, id) ) != NULL ) + { + return; + } - if (type != ITEM_MINE && type != ITEM_EXPLOSION - && type != ITEM_BIG_EXPLOSION) { - addToRadar(id, x, y, RADAR_TYPE_ITEM); - } + if( type != ITEM_MINE && type != ITEM_EXPLOSION && type != ITEM_BIG_EXPLOSION ) + { + addToRadar(id, x, y, RADAR_TYPE_ITEM); + } - item = newItem(x, y, type, author_id); + item = newItem(x, y, type, author_id); - replaceItemID(item, id); - item->count = count; - item->frame = frame; + replaceItemID(item, id); + item->count = count; + item->frame = frame; - addObjectToSpace(getCurrentArena()->spaceItem, item); + addObjectToSpace(getCurrentArena()->spaceItem, item); } #endif -void -proto_send_shot_server(int type, client_t * client, shot_t * p) +void proto_send_shot_server(int type, client_t *client, shot_t *p) { - char msg[STR_PROTO_SIZE]; + char msg[STR_PROTO_SIZE]; - assert(p != NULL); + assert( p != NULL ); - snprintf(msg, STR_PROTO_SIZE, "shot %d %d %d %d %d %d %d %d %d\n", - p->id, p->x, p->y, p->px, p->py, p->position, p->gun, - p->author_id, p->isCanKillAuthor); + snprintf(msg, STR_PROTO_SIZE, "shot %d %d %d %d %d %d %d %d %d\n", + p->id, p->x, p->y, p->px, p->py, p->position, p->gun, p->author_id, p->isCanKillAuthor); - //proto_send(type, client, msg); - //proto_check(type, client, msg, check_id); - protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, - CHECK_FRONT_ID_NONE); + //proto_send(type, client, msg); + //proto_check(type, client, msg, check_id); + protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE); } #ifndef PUBLIC_SERVER -void -proto_recv_shot_client(char *msg) +void proto_recv_shot_client(char *msg) { - char cmd[STR_PROTO_SIZE]; - int x, y, px, py, position, gun, shot_id, author_id, isCanKillAuthor; - shot_t *shot; - int recv_count; + char cmd[STR_PROTO_SIZE]; + int x, y, px, py, position, gun, shot_id, author_id, isCanKillAuthor; + shot_t *shot; + int recv_count; - assert(msg != NULL); + assert( msg != NULL ); - recv_count = sscanf(msg, "%s %d %d %d %d %d %d %d %d %d", - cmd, &shot_id, &x, &y, &px, &py, &position, &gun, - &author_id, &isCanKillAuthor); + recv_count = sscanf(msg, "%s %d %d %d %d %d %d %d %d %d", + cmd, &shot_id, &x, &y, &px, &py, &position, &gun, &author_id, &isCanKillAuthor); - if (recv_count != 10) { - return; - } + if( recv_count != 10 ) + { + return; + } - if ((shot = - getObjectFromSpaceWithID(getCurrentArena()->spaceShot, - shot_id)) != NULL) { - delObjectFromSpaceWithObject(getCurrentArena()->spaceShot, shot, - destroyShot); + if( ( shot = getObjectFromSpaceWithID(getCurrentArena()->spaceShot, shot_id) ) != NULL ) + { + delObjectFromSpaceWithObject(getCurrentArena()->spaceShot, shot, destroyShot); - //return; - } + //return; + } - shot = newShot(x, y, px, py, gun, author_id); + shot = newShot(x, y, px, py, gun, author_id); - replaceShotID(shot, shot_id); - shot->isCanKillAuthor = isCanKillAuthor; - shot->position = position; + replaceShotID(shot, shot_id); + shot->isCanKillAuthor = isCanKillAuthor; + shot->position = position; - if (shot->gun == GUN_LASSER) { - transformOnlyLasser(shot); - } + if( shot->gun == GUN_LASSER ) + { + transformOnlyLasser(shot); + } - addObjectToSpace(getCurrentArena()->spaceShot, shot); + addObjectToSpace(getCurrentArena()->spaceShot, shot); } #endif #ifndef PUBLIC_SERVER -void -proto_send_chat_client(char *s) +void proto_send_chat_client(char *s) { - char msg[STR_PROTO_SIZE]; - snprintf(msg, STR_PROTO_SIZE, "chat %s\n", s); - sendServer(msg); + char msg[STR_PROTO_SIZE]; + snprintf(msg, STR_PROTO_SIZE, "chat %s\n", s); + sendServer(msg); } #endif -void -proto_recv_chat_server(client_t * client, char *msg) +void proto_recv_chat_server(client_t *client, char *msg) { - char out[STR_PROTO_SIZE]; - int len; - - if (client->tux == NULL) { - return; - } + char out[STR_PROTO_SIZE]; + int len; + + if( client->tux == NULL ) + { + return; + } - len = strlen(msg); - msg[len - 1] = '\0'; + len = strlen(msg); + msg[len-1] = '\0'; - snprintf(out, STR_PROTO_SIZE, "chat %s:%s\n", client->tux->name, msg + 5); + snprintf(out, STR_PROTO_SIZE, "chat %s:%s\n", client->tux->name, msg+5); - proto_send_chat_server(PROTO_SEND_ALL, NULL, out); + proto_send_chat_server(PROTO_SEND_ALL, NULL, out); } -void -proto_send_chat_server(int type, client_t * client, char *msg) +void proto_send_chat_server(int type, client_t *client, char *msg) { - protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, - CHECK_FRONT_ID_NONE); + protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE); #ifndef PUBLIC_SERVER - proto_recv_chat_client(msg); + proto_recv_chat_client(msg); #endif } #ifndef PUBLIC_SERVER -void -proto_recv_chat_client(char *msg) +void proto_recv_chat_client(char *msg) { - int len; + int len; - assert(msg != NULL); + assert( msg != NULL ); - len = strlen(msg); - msg[len - 1] = '\0'; + len = strlen(msg); + msg[len-1] = '\0'; - addToChat(msg + 5); + addToChat(msg+5); } #endif #ifndef PUBLIC_SERVER -void -proto_send_module_client(char *msg) +void proto_send_module_client(char *msg) { - char out[STR_PROTO_SIZE]; + char out[STR_PROTO_SIZE]; - snprintf(out, STR_PROTO_SIZE, "module %s\n", msg); + snprintf(out, STR_PROTO_SIZE, "module %s\n", msg); /* strcpy(out, "modules "); strcat(out, msg); strcat(out, "\n"); */ - sendServer(out); + sendServer(out); } #endif -void -proto_recv_module_server(client_t * client, char *msg) +void proto_recv_module_server(client_t *client, char *msg) { - recvMsgModule(msg + 7); + recvMsgModule(msg+7); } -void -proto_send_module_server(int type, client_t * client, char *msg) +void proto_send_module_server(int type, client_t *client, char *msg) { - char out[STR_PROTO_SIZE]; + char out[STR_PROTO_SIZE]; - snprintf(out, STR_PROTO_SIZE, "module %s\n", msg); + snprintf(out, STR_PROTO_SIZE, "module %s\n", msg); /* strcpy(out, "modules "); strcat(out, msg); strcat(out, "\n"); */ - protoSendClient(type, client, out, CHECK_FRONT_TYPE_SIMPLE, - CHECK_FRONT_ID_NONE); + protoSendClient(type, client, out, CHECK_FRONT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE); } #ifndef PUBLIC_SERVER -void -proto_recv_module_client(char *msg) +void proto_recv_module_client(char *msg) { - recvMsgModule(msg + 7); + recvMsgModule(msg+7); } #endif #ifndef PUBLIC_SERVER -void -proto_send_ping_client() +void proto_send_ping_client() { - char msg[STR_PROTO_SIZE]; - snprintf(msg, STR_PROTO_SIZE, "ping\n"); - sendServer(msg); + char msg[STR_PROTO_SIZE]; + snprintf(msg, STR_PROTO_SIZE, "ping\n"); + sendServer(msg); } #endif -void -proto_recv_ping_server(client_t * client, char *msg) +void proto_recv_ping_server(client_t *client, char *msg) { } -void -proto_send_ping_server(int type, client_t * client) +void proto_send_ping_server(int type, client_t *client) { - char msg[STR_PROTO_SIZE]; - snprintf(msg, STR_PROTO_SIZE, "ping\n"); - //proto_send(type, client, msg); - protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, - CHECK_FRONT_ID_NONE); + char msg[STR_PROTO_SIZE]; + snprintf(msg, STR_PROTO_SIZE, "ping\n"); + //proto_send(type, client, msg); + protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE); } #ifndef PUBLIC_SERVER -void -proto_recv_ping_client(char *msg) +void proto_recv_ping_client(char *msg) { } #endif -void -proto_recv_echo_server(client_t * client, char *msg) +void proto_recv_echo_server(client_t *client, char *msg) { - proto_send_echo_server(PROTO_SEND_ONE, client, msg + 4); // msg + strlen("echo"); + proto_send_echo_server(PROTO_SEND_ONE, client, msg+4); // msg + strlen("echo"); } -void -proto_send_echo_server(int type, client_t * client, char *s) +void proto_send_echo_server(int type, client_t *client, char *s) { - char msg[STR_PROTO_SIZE]; + char msg[STR_PROTO_SIZE]; - snprintf(msg, STR_PROTO_SIZE, "echo%s", s); - //proto_send(type, client, msg); - protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, - CHECK_FRONT_ID_NONE); + snprintf(msg, STR_PROTO_SIZE, "echo%s", s); + //proto_send(type, client, msg); + protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE); } -void -proto_send_end_server(int type, client_t * client) +void proto_send_end_server(int type, client_t *client) { - char msg[STR_PROTO_SIZE]; + char msg[STR_PROTO_SIZE]; - snprintf(msg, STR_PROTO_SIZE, "end\n"); - //proto_send(type, client, msg); - protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, - CHECK_FRONT_ID_NONE); + snprintf(msg, STR_PROTO_SIZE, "end\n"); + //proto_send(type, client, msg); + protoSendClient(type, client, msg, CHECK_FRONT_TYPE_SIMPLE, CHECK_FRONT_ID_NONE); } #ifndef PUBLIC_SERVER -void -proto_recv_end_client(char *msg) +void proto_recv_end_client(char *msg) { - assert(msg != NULL); + assert( msg != NULL ); - setWorldEnd(); + setWorldEnd(); } #endif #ifndef PUBLIC_SERVER -void -proto_send_end_client() +void proto_send_end_client() { - char msg[STR_PROTO_SIZE]; + char msg[STR_PROTO_SIZE]; - snprintf(msg, STR_PROTO_SIZE, "end\n"); - sendServer(msg); + snprintf(msg, STR_PROTO_SIZE, "end\n"); + sendServer(msg); } #endif -void -proto_recv_end_server(client_t * client, char *msg) +void proto_recv_end_server(client_t *client, char *msg) { - assert(msg != NULL); - assert(client != NULL); + assert( msg != NULL ); + assert( client != NULL ); - client->status = NET_STATUS_ZOMBIE; + client->status = NET_STATUS_ZOMBIE; } + |