Esempio n. 1
0
void Team::addPlayer(PlayerID new_player)
{
    for ( PlayerID player_id = 0; player_id < PlayerInterface::getMaxPlayers(); ++player_id )
    {
        PlayerState* state = PlayerInterface::getPlayer(player_id);
        if (state->isActive())
        {
            if (state->getTeamID() == teamID
                    && (player_id != new_player))
            {
                PlayerInterface::allyplayers( player_id, new_player);
            }
        }
    }
    PlayerInterface::getPlayer(new_player)->setTeamID(teamID);
}
Esempio n. 2
0
short Team::getTeamObjective() const
{
    short TeamObjective = 0;
    PlayerID player_id;
 
    for ( player_id = 0; player_id < PlayerInterface::getMaxPlayers(); ++player_id )
    {
        PlayerState* state = PlayerInterface::getPlayer(player_id);
        if (state->isActive())
        {
            if (state->getTeamID() == teamID)
            {
                TeamObjective += state->getObjectivesHeld();
            }
        }
    }
    return TeamObjective;
}
bool
DedicatedGameManager::mainLoop()
{
    if ( heartbeat )
        heartbeat->checkHeartbeat();

    static NTimer aktimer(10000); //all 10 sec only
    if (aktimer.isTimeOut())
    {
        aktimer.reset();
        PlayerState * player = 0;
        unsigned long max_players;
        max_players = PlayerInterface::getMaxPlayers();
        for (unsigned long i = 0; i < max_players; i++)
        {
            player = PlayerInterface::getPlayer((unsigned short) i);
            if ( player->isActive() )
            {
                if ( player->checkAutokick() )
                {
                    char chat_string[256];
                    sprintf(chat_string, "Server kicked '%s' due to inactivity",player->getName().c_str());
                    LOGGER.info("DED: %s", chat_string);
                    ChatInterface::serversay(chat_string);
                    SERVER->kickClient((PlayerID)i);

                }
            }

        }
        if (VoteManager::checkVoteTimer())
        {
            VoteManager::checkPlayersVote();
        }
    }
    return BaseGameManager::mainLoop();
}
Esempio n. 4
0
void tPlayerStateBox::UpdateState(bool ForceUpdate)
{
    int nbPlayer = PlayerInterface::getActivePlayerCount();
    if (GameConfig::game_teammode && ShowTeam)
        nbPlayer = TeamManager::CountPlayerinTeam(TeamNumber);

    if ((nbPlayer != Count()) || ForceUpdate) 
    {
        Clear();
        for ( int i = 0; i < PlayerInterface::getMaxPlayers(); ++i)
        {
            PlayerState* state = PlayerInterface::getPlayer(i);
            if( state->isActive() )
            {
                if (ShowTeam)
                {
                    if (state->getTeamID() == TeamNumber)
                        AddData(state->getName(), state);
                } 
                else AddData(state->getName(), state);
            }
        }
    }
}
void
ObjectiveInterface::clientHandleNetMessage(const NetMessage* message)
{
    switch(message->message_id)
    {
        case _net_message_id_occupation_status_update:
        {
            const ObjectiveOccupationUpdate* msg =
                (const ObjectiveOccupationUpdate*) message;

            ObjectiveID obj_id = msg->getObjectiveId();
            if ( obj_id >= num_objectives )
            {
                LOGGER.warning("OICH_OOU CHEAT SERVER sent invalid objective_id %u, max is %u",
                               obj_id, num_objectives);
                break;
            }

            PlayerID player_id = msg->getPlayerId();
            if ( player_id >= PlayerInterface::getMaxPlayers() && player_id != INVALID_PLAYER_ID )
            {
                LOGGER.warning("OICH_OOU CHEAT SERVER sent invalid player_id %u, max is %u",
                               player_id, PlayerInterface::getMaxPlayers());
                break;
            }
            
            PlayerState* player = 0;

            if ( player_id != INVALID_PLAYER_ID )
            {
                player = PlayerInterface::getPlayer(player_id);
                if ( player && ! player->isActive() )
                {
                    LOGGER.warning("OICH_OOU CHEAT SERVER sent inactive player_id %u",
                                   player_id);
                    break;
                }
            }

            objective_list[obj_id]->changeOwner(player);

            break;
        }

        case _net_message_id_objective_sync:
        {
            const ObjectiveSyncMesg* msg =
                (const ObjectiveSyncMesg*) message;

            ObjectiveID obj_id = msg->getObjectiveId();
            if ( obj_id >= num_objectives )
            {
                LOGGER.warning("OICH_OSM CHEAT SERVER sent invalid objective_id %u, max is %u",
                               obj_id, num_objectives);
                break;
            }

            objective_list[obj_id]->syncFromData(msg->sync_data);

            break;
        }

        case _net_message_id_change_generating_unit:
        {
            const ObjectiveChangeGeneratingUnit* msg =
                (const ObjectiveChangeGeneratingUnit*) message;

            ObjectiveID obj_id = msg->getObjectiveId();
            if ( obj_id >= num_objectives )
            {
                LOGGER.warning("OICH_CGU CHEAT SERVER sent invalid objective_id %u, max is %u",
                               obj_id, num_objectives-1);
                break;
            }

            if ( msg->unit_type >= UnitProfileInterface::getNumUnitTypes() )
            {
                LOGGER.warning("OICH_CGU CHEAT SERVER sent invalid unit type %u, max is %u",
                               msg->unit_type,
                               UnitProfileInterface::getNumUnitTypes());
                break;
            }

            objective_list[obj_id]->changeUnitGeneration(msg->unit_gen_on, msg->unit_type);

            break;
        }

        case _net_message_id_change_output_location:
        {
            const ObjectiveChangeOutputLocation* msg =
                (const ObjectiveChangeOutputLocation*) message;

            ObjectiveID obj_id = msg->getObjectiveId();
            if ( obj_id >= num_objectives )
            {
                LOGGER.warning("OICH_COL CHEAT SERVER sent invalid objective_id %u, max is %u",
                               obj_id, num_objectives-1);
                break;
            }

            Uint32 map_x = msg->getMapX();
            Uint32 map_y = msg->getMapY();

            if ( map_x >= MapInterface::getWidth()
                 || map_y >= MapInterface::getHeight() )
            {
                LOGGER.warning("OICH_COL CHEAT SERVER sent invalid map location %u,%u; max is %u,%u",
                               map_x, map_y,
                               (unsigned int)MapInterface::getWidth(),
                               (unsigned int)MapInterface::getHeight());
                break;
            }

            objective_list[obj_id]->unit_collection_loc.x = msg->getMapX();
            objective_list[obj_id]->unit_collection_loc.y = msg->getMapY();

            break;
        }
        
        default:
            LOGGER.warning("OICH CHEAT SERVER sent unknown message type %u",
                           message->message_id);
    }
}
Esempio n. 6
0
// drawPlayerStats
//---------------------------------------------------------------------------
// Purpose:
//---------------------------------------------------------------------------
void RankView::drawPlayerStats(Surface &dest, unsigned int flagHeight)
{
    char statBuf[256];

    states.clear();
    PlayerID i;
    for( i = 0; i < PlayerInterface::getMaxPlayers(); ++i)
    {
        PlayerState* state = PlayerInterface::getPlayer(i);
        if ( state->isActive() )
        {
            states.push_back(state);
        }
    }

    switch(GameConfig::game_gametype)
    {
        case _gametype_objective:
            std::sort(states.begin(), states.end(), StatesSortByObjectives());
            break;
        case _gametype_timelimit:
        case _gametype_fraglimit:
            std::sort(states.begin(), states.end(), StatesSortByPoints());
            break;
    }

    int cur_line_pos = TABLE_START + ((ENTRY_HEIGHT - Surface::getFontHeight())/2);
    int flag_pos = TABLE_START + (int(ENTRY_HEIGHT - flagHeight))/2;
    Surface * flag = 0;
    int cur_state = 0;
    for(std::vector<const PlayerState*>::iterator i = states.begin();
            i != states.end(); ++i) {
        const PlayerState* state = *i;

        snprintf(statBuf, sizeof(statBuf),
                stats_format, state->getName().substr(0,20).c_str(),
                state->getKills(), state->getLosses(), state->getTotal(),
                state->getObjectivesHeld());
        dest.bltStringShadowed(NAME_START, cur_line_pos, statBuf,
                               (cur_state == selected_line)?Color::yellow:Color::gray224,
                               Color::gray64);
        
        flag = ResourceManager::getFlag(state->getFlag());
        flag->blt( dest, FLAG_START, flag_pos );
        if ( state->getID() != PlayerInterface::getLocalPlayerIndex() )
        {
            // XXX ALLY
            bool meWithHim = PlayerInterface::isSingleAllied(PlayerInterface::getLocalPlayerIndex(), state->getID());
            bool himWithMe = PlayerInterface::isSingleAllied(state->getID(), PlayerInterface::getLocalPlayerIndex());            
            if ( meWithHim && himWithMe )
            {
                allyImage.bltTrans(dest, ALLY_START, flag_pos );
            }
            else if ( meWithHim )
            {
                allyRequestImage.bltTrans(dest, ALLY_START, flag_pos );
            }
            else if ( himWithMe )
            {
                allyOtherImage.bltTrans(dest, ALLY_START, flag_pos );
            }
            else
            {
                noAllyImage.bltTrans(dest, ALLY_START, flag_pos );
            }
        }

        colorImage.bltTransColor(dest, TABLE_HEADER_PIX_LEN+2, flag_pos, state->getColor());

        cur_line_pos += ENTRY_HEIGHT;
        flag_pos += ENTRY_HEIGHT;
        ++cur_state;
    }

} // end RankView::drawPlayerStats
//-----------------------------------------------------------------
void DedicatedGameManager::inputLoop()
{
    // handle server commands
    SDL_mutexP(commandqueue_mutex);
    while(!commandqueue.empty()) {
        const ServerCommand& command = commandqueue.front();

        switch(command.type) {
            case ServerCommand::QUIT:
            {
                ActionManager::runAction("quit");
                break;
            }
            case ServerCommand::CHAT:
            {
                ChatInterface::serversay(command.argument.c_str());
                break;
            }
            case ServerCommand::STATUS:
            {
                //*Console::server
                std::cout
                    << "Server " << *GameConfig::server_name
                    << " version " << PACKAGE_VERSION << " port "
                    << GameConfig::server_port << "\n"
                    << "Map: " << *GameConfig::game_map << "\n"
                    << std::setw(3) << "ID" << " "
                    << std::setw(30) << "Name" << " "
                    << std::setw(4) << "Kill" << " "
                    << std::setw(4) << "Lost" << " "
                    << std::setw(5) << "Score" << " "
                    << std::setw(21) << "IP\n";
                PlayerID i;
                for ( i = 0; i<PlayerInterface::getMaxPlayers(); ++i)
                {
                    PlayerState* playerstate = PlayerInterface::getPlayer(i);
                    if ( playerstate->isActive() )
                    {
                        //*Console::server
                        std::cout
                            << std::setw(3) << static_cast<int>(i) << " "
                            << std::setw(30) << playerstate->getName() << " "
                            << std::setw(4) << playerstate->getKills() << " "
                            << std::setw(4) << playerstate->getLosses() << " "
                            << std::setw(5) << playerstate->getTotal() << " "
                            << std::setw(21)
                            << SERVER->getIP(playerstate->getID())
                            << "\n";
                    }
                }
                //*Console::server << std::flush;
                std::cout << std::flush;
                break;
            }
            case ServerCommand::MAPCHANGE:
                if(!MapsManager::existsMap(command.argument)) {
                    std::cout << "map '" << command.argument
                        << "' doesn't exist." << std::endl;
                    break;
                }
            
                GameControlRulesDaemon::forceMapChange(command.argument);
                std::cout << "Preparing mapchange..." << std::endl;
                break;
            case ServerCommand::KICK:
                std::stringstream idstream(command.argument);
                PlayerID id = INVALID_PLAYER_ID;
                idstream >> (int&)id; // XXX KREMOVE
                if(id >= PlayerInterface::getMaxPlayers()) {
                    std::cout << "Unknown player." << std::endl;
                    break;
                }
                SERVER->kickClient(id);
                break;
        }
        commandqueue.pop();
    }
    SDL_mutexV(commandqueue_mutex);
    BaseGameManager::inputLoop();
}