/* To start the game */ TEG_STATUS token_start( int fd ) { char strout[PROT_MAX_LEN + PLAYERNAME_MAX_LEN * TEG_MAX_PLAYERS + 200]; PSPLAYER pJ; PLAY_DEBUG("token_start()\n"); if( JUEGO_EMPEZADO || g_game.players < 2 ) goto error; if( g_server.with_console && fd != CONSOLE_FD) { if( !SPLAYER_HABILITADO_P(fd,&pJ) || !pJ->is_player ) goto error; } JUEGO_EN_EMPEZAR; g_game.playing = g_game.players; con_text_out(M_INF,_("Starting game number: %d with seed: %u\n"),g_game.gamenumber,g_game.seed); player_all_set_status ( PLAYER_STATUS_START ); countries_repartir(); if(turno_init() != TEG_STATUS_SUCCESS ) { con_text_out(M_ERR,_("Error, can't initialize a new turn\n")); goto error; } JUEGO_EN_FICHAS; g_game.turno->estado = PLAYER_STATUS_FICHAS; aux_token_stasta(strout, sizeof(strout) -1 ); netall_printf( "%s=%s;%s=%d,%d;%s=%d,%d,%d,%d;%s=%d,%d\n" ,TOKEN_START ,strout /* available players */ ,TOKEN_NEW_ROUND ,g_game.turno->numjug /* who starts the new turn */ ,g_game.round_number /* the round number */ ,TOKEN_MODALIDAD ,g_game.mission /* play with missions ? */ ,g_game.cmission /* play with common mission */ ,g_game.fog_of_war /* play with fog of war */ ,g_game.reglas /* which rules ? */ ,TOKEN_FICHAS ,g_game.turno->numjug, /* who starts ? */ g_game.fichas ); /* how many armies to place */ return TEG_STATUS_SUCCESS; error: net_print(fd,TOKEN_ERROR"="TOKEN_START"\n"); return TEG_STATUS_PARSEERROR; }
/* Show the status of all the players */ STATIC TEG_STATUS token_status( int fd, char *unused ) { char strout[PROT_MAX_LEN + PLAYERNAME_MAX_LEN * TEG_MAX_PLAYERS + 200]; PLAY_DEBUG("token_status()\n"); if( !SPLAYER_CONNECTED( fd )) goto error; if( aux_token_stasta(strout, sizeof(strout) -1 ) != TEG_STATUS_SUCCESS ) goto error; net_printf(fd,"%s=%s\n", TOKEN_STATUS, strout); return TEG_STATUS_SUCCESS; error: net_print(fd,TOKEN_ERROR"="TOKEN_STATUS"\n"); return TEG_STATUS_PARSEERROR; }
/* ends the game */ void game_end( PSPLAYER winner ) { char strout[PROT_MAX_LEN + PLAYERNAME_MAX_LEN * TEG_MAX_PLAYERS + 200]; PLIST_ENTRY l = g_list_player.Flink; PSPLAYER pJ; /* add points to the winner */ if( winner && g_game.round_number > 0 ) { int points = 350 / g_game.round_number; winner->player_stats.score += points; } /* update scores */ player_map( player_insert_scores ); if( aux_token_stasta(strout, sizeof(strout) -1 ) == TEG_STATUS_SUCCESS ) { /* send the last status to all the players */ while( !IsListEmpty( &g_list_player ) && (l != &g_list_player) ) { pJ = (PSPLAYER) l; if( pJ->is_player && pJ->fd != 1) net_printf(pJ->fd,TOKEN_STATUS"=%s\n",strout); l = LIST_NEXT(l); } } /* delete disconn players */ player_map( player_delete_discon ); /* send who is the winner */ if( winner ) netall_printf( TOKEN_WINNER"=%d,%d\n",winner->numjug,winner->mission ); game_new(); }