Beispiel #1
0
void Mud::removeInactivePlayers()
{
    PlayerList toRemove = PlayerList();
    for (auto iterator : mudPlayers)
    {
        // Proceed only if the player is not connected and is closing.
        if (!iterator->checkConnection() || iterator->closing)
        {
            // Add the player to the list of players that have to be removed.
            toRemove.insert(iterator);
        }
    }
    for (auto iterator = toRemove.begin(); iterator != toRemove.end(); ++iterator)
    {
        // Get the player at the given position.
        Player * player = *iterator;
        // Log the action of removing.
        Logger::log(LogLevel::Global, "Removing inactive player : " + player->getName());
        // Only if the player has successfully logged in, save its state on DB.
        if (player->logged_in)
        {
            SQLiteDbms::instance().beginTransaction();
            player->updateOnDB();
            SQLiteDbms::instance().endTransaction();
        }
        // Remove the player from the list of players.
        remPlayer(player);
        // Delete the player.
        delete (player);
    }
}
Beispiel #2
0
void freePlayer(Player * p, Game * g)
{
	if (p == NULL)
		return;

	if (p->game == g)
	{
		if (p->game == NULL)
			delNilPlayer(p);
		else
			delPlayer(p);
	}
	remPlayer(p);
}