Exemple #1
0
void CTable::updateFlopPercentage()
{
    int all = countPlayers(PLAYER_STATE_ACTIVE|PLAYER_STATE_SITOUT);
    if (all != 0)
    {
        flopprcnt_ = (100 * countPlayers(PLAYER_STATE_PLAYING)) / all;
    }
}
Exemple #2
0
void CMapInfo::mapInit(const std::string & fname)
{
	fileURI = fname;
	CMapService mapService;
	mapHeader = mapService.loadMapHeader(ResourceID(fname, EResType::MAP));
	countPlayers();
}
Exemple #3
0
void CMapInfo::saveInit(ResourceID file)
{
	CLoadFile lf(*CResourceHandler::get()->getResourceName(file), MINIMAL_SERIALIZATION_VERSION);
	lf.checkMagicBytes(SAVEGAME_MAGIC);

	mapHeader = make_unique<CMapHeader>();
	lf >> *(mapHeader.get()) >> scenarioOptionsOfSave;
	fileURI = file.getName();
	countPlayers();
	std::time_t time = boost::filesystem::last_write_time(*CResourceHandler::get()->getResourceName(file));
	date = std::asctime(std::localtime(&time));
	// We absolutely not need this data for lobby and server will read it from save
	// FIXME: actually we don't want them in CMapHeader!
	mapHeader->triggeredEvents.clear();
}
PlayerID Team::getrandomplayer() const
{
    PlayerID count = 0;
    PlayerID player_id, result =0;
    Uint8 player = rand()%countPlayers();
 
    for ( player_id = 0; player_id < PlayerInterface::getMaxPlayers(); ++player_id )
    {
        if (PlayerInterface::getPlayer(player_id)->isActive())
        {
            if (PlayerInterface::getPlayer(player_id)->getTeamID() == teamID)
            {
                if (count == player) return player_id;
                count++;
                result = player_id;
            }
        }
    }
    return result; // default return the last
}
void PlayerInterface::reset()
{
    resetPlayerStats(countPlayers() > 0);
    resetAllianceMatrix(); // XXX ALLY
}
Exemple #6
0
void CMapInfo::mapInit(const std::string & fname)
{
	fileURI = fname;
	mapHeader = CMapService::loadMapHeader(fname);
	countPlayers();
}
Exemple #7
0
void CTable::tableLogin(SOCKET sd, CpduLogin* loginPdu)
{
  bool loginOk = true;
  u_int32_t ipaddr = 0;

  // Is there a valid login entry for the player? If not,
  // he could be trying to log in directly and not via lounge
  LoginEntries::iterator pos = loginEntries_.find(loginPdu->getUsername());
  if (pos == loginEntries_.end())
  {
#ifdef ALLOW_DIRECT_LOGINS_
#pragma message("Allowing direct logins!!!")

    // WILL ALLOW DIRECT LOGINS

#else
    char s[200];
    sprintf(s, "Login rejected: no login entry for user %s", loginPdu->getUsername());
    Sys_LogError(s);
    loginOk = false;
#endif
  }
  else
  {
    ipaddr = (*pos).second.ipaddr_;
    // player is logging in, remove his entry
    loginEntries_.erase(pos);
  }

  // In theory we didn't need to do these checks here
  // because they're done when the lounge server asks
  // whether the login is ok. Do the check just in case
  // someone finds a way to log in to table without
  // the lounge server.
  if (loginOk)
    loginOk = checkLogin(ipaddr, loginPdu->getUsername());

  if (!loginOk || !dbase_->authenticate(loginPdu->getUsername(), loginPdu->getPassword()))
  {
    // Send Table Reject PDU
    CpduLoginReject pdu;
    pdu.sendReject(sd);
    // Terminate the connection
    CPoller::Instance()->removeClient(sd);
  }
  else
  {
    CPlayer* newPlayer = NULL;

    // Add player to table
    SingleLock l(&tableMutex_);
    if (l.lock())
    {
      newPlayer = getUnusedPlayer(loginPdu->getUsername());
      if (newPlayer)
      {
				// In tournaments there is a small window during which a
        // player may succeed logging in twice because the first
        // login does not "reanimate the zombie" immediately.
        // This check prevents it from happening.
				if (CTournament::Inst()->isTournament() &&
				    checkDoubleLogin(loginPdu->getUsername(), newPlayer))
				{
					// Send Table Reject PDU
					CpduLoginReject pdu;
					pdu.sendReject(sd);
					// Terminate the connection
					CPoller::Instance()->removeClient(sd);
					return;
				}

        newPlayer->setPlayer(sd, 
                             loginPdu->getUsername(),
                             loginPdu->getPassword(),
                             CChips(), // 0 chips until he buys in
                             ipaddr);

        newPlayer->setIsFreeSeat(false);
        newPlayer->setReanimate(true);

        string city;
        if (dbase_->getCity(loginPdu->getUsername(), city))
        {
          newPlayer->setCity(city.c_str());
        }

        if (countPlayers(PLAYER_STATE_PLAYING|PLAYER_STATE_WAITING) >= 1 &&
            countPlayersRaw(false) > 2 &&
            !CTournament::Inst()->isTournament()) // XXX Fix tournament double big blind bug
        {
          // a game is in progress - must charge 'new player's blind'
          newPlayer->setMissedBlind(getLo());
        }

        CpduPlayerInfo myPlayerInfoPdu(this);
        CpduBuyinQuery myBuyinQueryPdu(this);

        // Send Player Info PDU
        myPlayerInfoPdu.sendPlayerInfo(newPlayer); 

        if (CTournament::Inst()->isTournament())
        {
          char buf[100];
          sprintf(buf, "Player %s logged in",
                  newPlayer->getUsername());
          Sys_LogTournament(buf);

          CTournament* t = CTournament::Inst();
          CChips lo(DEFAULT_LOW), hi(DEFAULT_HI);
          t->getLimits(lo, hi);

          // Send current game type & limits
          CpduTournamentParams params;
          params.sendParams(newPlayer, TF_GameType,
                            t->getGameType(),
                            t->isHiLo() ? 1 : 0);
          params.sendParams(newPlayer, TF_Limit,
                            lo.getRep(),
                            hi.getRep());

          // In tournament there is automatic buy-in when
          // players are seated
          if (newPlayer->matchState(PLAYER_STATE_UNUSED|PLAYER_STATE_LOGGEDIN))
              newPlayer->stateChange(PLAYER_STATE_BOUGHTIN); 
        }
        else
        {
          // Send buy in query
          myBuyinQueryPdu.sendBuyinQuery(newPlayer);
        }

        // Send table update to lounge server
        if (CLoungeServer* ls = CLoungeServer::Inst())
        {
          ls->sendPlayerSeated(newPlayer->getUsername());
          ls->sendTableUpdate(countPlayersRaw());
        }
      }
    }

    if (!newPlayer)
    {   // no room for player!
      CPoller::Instance()->removeClient(sd);
    }
  }
}