示例#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);
}
示例#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;
}
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
NetworkServer::onClientDisconected(ClientSocket *s, const char * msg)
{
    LOGGER.debug("NetworkServer::onClientDisconected( %d, '%s')", s->getId(), msg ? msg : "nice");
    
    bool cleandisconnect = false;
    bool sendalert = true;
    
    if ( ServerConnectDaemon::inConnectQueue(s) )
    {
        // player was connecting and dropped.
        ServerConnectDaemon::removeClientFromQueue(s);
        sendalert = false;
        LOGGER.debug("NetworkServer::onClientDisconected player was connecting");
    }
    
    if ( NetworkInterface::receive_queue.isReady() )
    {
        unsigned long frontsave = NetworkInterface::receive_queue.front;
        while ( NetworkInterface::receive_queue.isReady() )
        {
            LOGGER.debug("NetworkServer::onClientDisconected there was a packet");
            NetPacket packet;

            NetworkInterface::receive_queue.dequeue(&packet);

            if ( packet.fromClient == s )
            {
                LOGGER.debug("NetworkServer::onClientDisconected the packet was from our friend");
                const NetMessage * netmessage = packet.getNetMessage();
                if (   netmessage->message_class == _net_message_class_connect 
                    && netmessage->message_id == _net_message_id_connect_netPanzer_client_disconnect )
                {
                    LOGGER.debug("NetworkServer::onClientDisconected so is a clean disconnect");
                    cleandisconnect = true;
                }
            }
        }
        NetworkInterface::receive_queue.front = frontsave;
    }
    
    PlayerID player_index = s->getPlayerIndex();
    
    if ( player_index != INVALID_PLAYER_ID )
    {
        PlayerState * player = PlayerInterface::getPlayer(player_index);
        bool kicked = player ? player->isKicked() : false;

        if ( player && sendalert && ! kicked)
        {
            if (GameConfig::game_teammode == true)
            ConsoleInterface::postMessage(Color::cyan, true, player->getFlag(),
                                      _("'%s' has left."),
                                      player->getName().c_str());
        }

        ObjectiveInterface::disownPlayerObjectives( player_index );
        UnitInterface::destroyPlayerUnits( player_index );
        PlayerInterface::disconnectPlayerCleanup( player_index );    

        if ( sendalert )
        {
            SystemConnectAlert scmsg;
            if ( cleandisconnect || ! msg )
            {
                scmsg.set( player_index, _connect_alert_mesg_disconnect);
            }
            else if ( kicked )
            {
                scmsg.set( player_index, _connect_alert_mesg_client_kicked);
            }
            else
            {
                scmsg.set( player_index, _connect_alert_mesg_client_drop );
            }
            SERVER->broadcastMessage(&scmsg, sizeof(scmsg));
        }
        if (GameConfig::game_teammode == true)
        {
            TeamManager::removePlayer(player->getID(), player->getTeamID());
            TeamManager::BalancedTeam();
        }
    }
}