// By rebuilding everything every tick, menus can be dynamically updated
void PlayerMenuUserInterface::idle(U32 timeDelta)
{
   clearMenuItems();

   GameConnection *conn = getGame()->getConnectionToServer();
   if(!conn)
      return;

   char c[] = "A";      // Dummy shortcut key
   for(S32 i = 0; i < getGame()->getClientCount(); i++)
   {
      ClientInfo *clientInfo = ((Game *)getGame())->getClientInfo(i);      // Lame!

      strncpy(c, clientInfo->getName().getString(), 1);        // Grab first char of name for a shortcut key

      // Will be used to show admin/player/robot prefix on menu
      PlayerType pt = clientInfo->isRobot() ? PlayerTypeRobot : (clientInfo->isAdmin() ? PlayerTypeAdmin : PlayerTypePlayer);    

      PlayerMenuItem *newItem = new PlayerMenuItem(i, clientInfo->getName().getString(), playerSelectedCallback, 
                                                   InputCodeManager::stringToInputCode(c), pt);
      newItem->setUnselectedColor(getGame()->getTeamColor(clientInfo->getTeamIndex()));

      addMenuItem(newItem);
   }

   sortMenuItems();

   if(action == PlayerActionKick)
      mMenuTitle = "CHOOSE PLAYER TO KICK";
   else if(action == PlayerActionChangeTeam)
      mMenuTitle = "CHOOSE WHOSE TEAM TO CHANGE";
   else
      TNLAssert(false, "Unknown action!");
}
Пример #2
0
// The nexus is open.  A ship has entered it.  Now what?
// Runs on server only
void NexusGameType::shipTouchNexus(Ship *ship, NexusZone *nexus)
{
    FlagItem *flag = findFirstFlag(ship);

    if(!flag)      // findFirstFlag can return NULL
        return;

    S32 flagsReturned = flag->getFlagCount();

    if(flagsReturned == 0)
        return;

    updateScore(ship, ReturnFlagsToNexus, flagsReturned);
    nexus->s2cFlagsReturned();       // Alert the Nexus that someone has returned flags to it

    ClientInfo *clientInfo = ship->getClientInfo();

    if(clientInfo)          // Should always be true!!
    {
        if(!isGameOver())    // Avoid flooding messages at end of game
        {
            S32 score = getEventScore(TeamScore, ReturnFlagsToNexus, flag->getFlagCount());
            s2cNexusMessage(NexusMsgScore, clientInfo->getName().getString(), flag->getFlagCount(), score);
        }

        // See if this event qualifies for an achievement
        if(flagsReturned >= 25 &&                                   // Return 25+ flags
                clientInfo && clientInfo->isAuthenticated() &&           // Player must be authenticated
                getGame()->getPlayerCount() >= 4 &&                      // Game must have 4+ human players
                getGame()->getAuthenticatedPlayerCount() >= 2 &&         // Two of whom must be authenticated
                !hasFlagSpawns() && !hasPredeployedFlags() &&            // Level can have no flag spawns, nor any predeployed flags
                !clientInfo->hasBadge(BADGE_TWENTY_FIVE_FLAGS))          // Player doesn't already have the badge
        {
            achievementAchieved(BADGE_TWENTY_FIVE_FLAGS, clientInfo->getName());
        }
    }

    flag->changeFlagCount(0);
}
Пример #3
0
void ServerImpl::onClientInfo(
		CL_NetGameConnection *p_conn,
		const CL_NetGameEvent &p_event
)
{
	ClientInfo clientInfo;
	clientInfo.parseEvent(p_event);

	// check the version
	if (clientInfo.getProtocolVersion().getMajor() != PROTOCOL_VERSION_MAJOR) {
		cl_log_event(
				LOG_EVENT,
				"unsupported protocol version for player '%2'",
				reinterpret_cast<unsigned>(p_conn)
		);

		// send goodbye
		Net::Goodbye goodbye;
		goodbye.setGoodbyeReason(GR_UNSUPPORTED_PROTOCOL_VERSION);

		send(p_conn, goodbye.buildEvent());
		return;
	}

	// check name availability
	// check name availability
	bool nameAvailable = true;
	TConnectionPlayerPair pair;
	foreach (pair, m_connections) {
		if (pair.second.m_name == clientInfo.getName()) {
			nameAvailable = false;
		}
	}

	if (!nameAvailable) {
		cl_log_event(
				LOG_EVENT,
				"name '%1' already in use for player '%2'",
				clientInfo.getName(),
				reinterpret_cast<unsigned>(p_conn)
		);

		// send goodbye
		Goodbye goodbye;
		goodbye.setGoodbyeReason(GR_NAME_ALREADY_IN_USE);

		send(p_conn, goodbye.buildEvent());
		return;
	}

	// set the name and inform all
	m_connections[p_conn].m_name = clientInfo.getName();

	cl_log_event(
			LOG_EVENT,
			"'%1' is now known as '%2', sending gamestate...",
			reinterpret_cast<unsigned>(p_conn),
			clientInfo.getName()
	);

	PlayerJoined playerJoined;
	playerJoined.setName(clientInfo.getName());

	sendToAll(playerJoined.buildEvent(), p_conn);

	// send the gamestate
	const GameState gamestate = prepareGameState();
	send(p_conn, gamestate.buildEvent());

	m_connections[p_conn].m_gameStateSent = true;
}