Exemple #1
0
//-------------------------------------------------------------------------
bool DcMidiData::set14bit(int offset, int val)
{
    bool rtval = false;

    if( (offset+1) <= _data.length())
    {
        _data[offset] = getHi(val);
        _data[offset+1] = getLo(val);
        rtval = true;
    }

    return rtval;
}
Exemple #2
0
// The player can be added to queue if he has
// 10 * lolimit chips.
bool CWaitingList::canAddPlayer(CPlayer& player)
{
  CChips chips;
  CdbInterface::Inst()->getChips(&player, chips);

  if ((10 * getLo()) > chips)
  {
    CpduQueueFull pdu;
    pdu.sendQueueFull(getQueueNumber(),
                      &player,
                      QF_NotEnoughChips);
    return false;
  }

  return true;
}
Exemple #3
0
//
// If players are to be serviced, then
// - if there is room in tables, send player there
// - if no room, decide if we should spawn table
//
int CWaitingList::tick(long now)
{
  if (!isOwner())
  {
    // This waiting list is owned by another Lounge
    // Server instance
    return 0;
  }

  if (CLounge::Inst()->getShutdown())
  {
    printf("Server is shutting down, waiting list not serviced.\n");
    return 0;
  }
  
  printf("   Waiting list %d has %d players waiting.\n",
         queueNumber_, players_.size());
  
  const int TimeBetweenSpawns = 60;
  
  if (state_ == WS_Spawning &&
      (now - spawnTime_ > TimeBetweenSpawns))
  { // more than N seconds has passed since
    // last spawn
    state_ = WS_Servicing;
  }
  
  if (state_ == WS_Servicing)
  {
    // If we have more players in queue than the
    // spawn threshold, spawn new table
    if (players_.size() >= GetTableSpawnThreshold(tables_.size()) )
    {
      state_ = WS_Spawning;
      CLounge::Inst()->spawnTable(pGame_->getGameType(),
                                  getGameType(), // queueIndex!
                                  getTableMax(),
                                  getLo(),
                                  getHi(),
                                  pGame_->isHiLoSplit());
      spawnTime_ = now;
    } 
  }
  
  return 0;
}
Exemple #4
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);
    }
  }
}