void PDUNetworkError::execute(Base::GameState*)
{
#ifdef PSPOT_TABLE_MODULE_

  Base::GameLogic::Instance().setNextState(0);
  Global::Instance().closeConnections();

  CTableView* pView = CTableView::Instance();
  if (pView)
  {
    pView->setCaption();
    pView->resetCards();
    pView->announce("");

    for (int i = 0; i < 10; i++)
      pView->removePlayer(i);
    pView->Invalidate();
  }

  // CONNRESET means server closed connection - it's ok
  if (!Global::CloseConnection())//errorCode_ != WSAECONNRESET)
  {
    CString msg;
    msg.Format(g_szErrFmt, errorCode_);
    if (AfxGetMainWnd())
      AfxGetMainWnd()->MessageBox(msg, NULL, MB_OK|MB_ICONEXCLAMATION);
  }

#else

  Global::Instance().closeConnections();

  CFloorMap* pFM = CFloorMap::Instance();
  if (pFM)
    pFM->disconnect();

  if (!Global::CloseConnection())
  {
    CString msg;
    msg.Format(g_szErrFmt, errorCode_);
    if (AfxGetMainWnd())
      AfxGetMainWnd()->MessageBox(msg, NULL, MB_OK|MB_ICONEXCLAMATION);
  }


#endif

}
Exemple #2
0
//
// This PDU is always sent at the start of hand.
//
// The dealer is set twice to make sure the old
// blind positions are erased and new positions
// painted correctly.
//
// The player states are reset to sit-in.
//
void PDUButton::execute(Base::GameState* pState)
{
  CTableView* pView = CTableView::Instance();
  if (pView)
  { 
    pView->resetCards(true);
    pView->setDealer(dealerslot_, true);

    static bool is_first_button = true;
    if (!is_first_button)
    {
      for (int i = 0; i < 10; i++)
      {
        Player* pP = pView->getPlayer(i);
        if (pP)
        {
          if (pP->getChips() > 0 &&
              pP->getState() != Base::AllIn)
          {
            pP->setState(Base::SitIn);
            pP->setActionText("", true);
          }
          else
          {
            pP->setState(Base::SitOut);
          }
        }
      }
    }
    else
      is_first_button = true;

    pView->setDealer(dealerslot_, true);
    pView->Invalidate();
  }

  if (GameLogic::Instance().currentState() == NULL)
  { // Set the next state already!
    GameLogic::Instance().setNextState(new StatePromptPostBlind(10, 0, 0));
  }
}
void PDUPlayerInfo::execute(GameState*)
{
  CString msg;
  CTableView* pTable = CTableView::Instance();
  ASSERT(pTable);
  CChatView* pChat = CChatView::Instance();
  int num_players_b4_pdu = pTable->numPlayers();

  if (pTable)
  {
    int num_players = num_players_b4_pdu;

    PlayerInfo* pP = pPlayers_;
    if (pP != NULL)
    {
      for (int i = 0; i < num_players_; i++)
      {
        CString namesz = MakeString(pP->username_);
        Player* p = pTable->getPlayer(pP->slot_);
        bool wasThere = false;
        if (p && p->getName() == namesz)
          wasThere = true;

        pTable->addPlayer(namesz, CChips_n(pP->chips_).ntohl(), pP->slot_);

        // Set initial player state
        if (pP->state_ & PLAYER_STATE_ACTIVE)
          pTable->setState(pP->slot_, Base::SitIn);
        else
          pTable->setState(pP->slot_, Base::SitOut);

        Player* pPlayer = pTable->getPlayer(pP->slot_);

        ASSERT(pPlayer);
        if (pPlayer)
        {
          if (pP->state_ & PLAYER_STATE_ZOMBIE)
            pPlayer->setState(Base::Zombie);

          CString citysz = MakeString(pP->city_);
          pPlayer->setHomeCity(citysz);
          pTable->InvalidateRect(&pPlayer->getArea());  
        }

        if (pChat && !wasThere)
        {
          CString msg;
          msg.Format(g_szPlayerJoined, (LPCSTR)namesz, pP->slot_ + 1);
          pChat->addDealerMessage(msg, CChatView::CF_GameNormal);
        }
        
        pP++;
      }
    }

    // make a full redraw if original player
    // count was 0
    if (num_players == 0)
      pTable->Invalidate();
  }

  if (num_players_b4_pdu == 0)
  {
    // Send initial sit in status
    BOOL b = GameLogic::SitOut();
    if (Global::TableServer())
    {
      if (b)
        Global::TableServer()->sendPlaySitOutPDU();
      else
        Global::TableServer()->sendPlaySitInPDU();
    }

    // Send initial muck hand status
    b = GameLogic::HideHand();
    if (Global::TableServer())
    {
      if (b)
        Global::TableServer()->sendPlayHideCardsPDU();
      else
        Global::TableServer()->sendPlayShowCardsPDU();
    }

    // Done, start waiting for new hand to start
    GameLogic::Instance().setNextState(new StateWait());
  }
}