Merge branch 'new_local_game' of github.com:/pokerth/pokerth into gocode

This commit is contained in:
lotodore
2014-07-13 13:38:07 +02:00
9 changed files with 233 additions and 12 deletions
+4 -1
View File
@@ -46,6 +46,8 @@
#define SQLITE_LOG_VERSION 1
//#define NEW_LOCAL_GAME
#define RANKING_GAME_START_CASH 10000
#define RANKING_GAME_NUMBER_OF_PLAYERS 10
#define RANKING_GAME_START_SBLIND 50
@@ -54,7 +56,8 @@
enum ServerMode {
SERVER_MODE_LAN,
SERVER_MODE_INTERNET_NOAUTH,
SERVER_MODE_INTERNET_AUTH
SERVER_MODE_INTERNET_AUTH,
SERVER_MODE_LAN_LOCAL
};
enum ServerTransportProtocol {
+137
View File
@@ -256,6 +256,12 @@ startWindowImpl::startWindowImpl(ConfigFile *c, Log *l)
connect(this, SIGNAL(signalPlayerGameInvitation(unsigned, unsigned, unsigned)), myGameLobbyDialog, SLOT(chatInfoPlayerInvitation(unsigned, unsigned, unsigned)));
connect(this, SIGNAL(signalRejectedGameInvitation(unsigned, unsigned, DenyGameInvitationReason)), myGameLobbyDialog, SLOT(chatInfoPlayerRejectedInvitation(unsigned, unsigned, DenyGameInvitationReason)));
#ifdef NEW_LOCAL_GAME
QAction *actionStart_Local_Game_new = new QAction("Start (new) local game ...",this);
menuPokerTH->addAction(actionStart_Local_Game_new);
connect( actionStart_Local_Game_new, SIGNAL( triggered() ), this, SLOT( callNewGameDialogNew() ) );
#endif
this->show();
//update HACKS
@@ -289,6 +295,26 @@ void startWindowImpl::callNewGameDialog()
}
}
void startWindowImpl::callNewGameDialogNew()
{
//wenn Dialogfenster gezeigt werden soll
if(myConfig->readConfigInt("ShowGameSettingsDialogOnNewGame")) {
#ifdef ANDROID
myGuiInterface->getMyW()->hide();
#endif
myNewGameDialog->exec();
if (myNewGameDialog->result() == QDialog::Accepted ) {
startNewLocalGameNew(myNewGameDialog);
}
}
// sonst mit gespeicherten Werten starten
else {
startNewLocalGameNew();
}
}
void startWindowImpl::startNewLocalGame(newGameDialogImpl *v)
{
@@ -392,6 +418,117 @@ void startWindowImpl::startNewLocalGame(newGameDialogImpl *v)
mySession->startLocalGame(gameData, startData);
}
void startWindowImpl::startNewLocalGameNew(newGameDialogImpl *v)
{
// Stop local game.
myGuiInterface->getMyW()->stopTimer();
if (!myServerGuiInterface) {
// Create pseudo Gui Wrapper for the server.
myServerGuiInterface.reset(new ServerGuiWrapper(myConfig, mySession->getGui(), mySession->getGui(), mySession->getGui()));
{
boost::shared_ptr<Session> session(new Session(myServerGuiInterface.get(), myConfig, 0));
session->init(mySession->getAvatarManager());
myServerGuiInterface->setSession(session);
}
}
// Terminate existing network games.
mySession->terminateNetworkClient();
myServerGuiInterface->getSession()->terminateNetworkServer();
GameData gameData;
if(v) {
gameData.maxNumberOfPlayers = v->spinBox_quantityPlayers->value();
gameData.startMoney = v->spinBox_startCash->value();
gameData.firstSmallBlind = v->getChangeCompleteBlindsDialog()->spinBox_firstSmallBlind->value();
if(v->getChangeCompleteBlindsDialog()->radioButton_raiseBlindsAtHands->isChecked()) {
gameData.raiseIntervalMode = RAISE_ON_HANDNUMBER;
gameData.raiseSmallBlindEveryHandsValue = v->getChangeCompleteBlindsDialog()->spinBox_raiseSmallBlindEveryHands->value();
} else {
gameData.raiseIntervalMode = RAISE_ON_MINUTES;
gameData.raiseSmallBlindEveryMinutesValue = v->getChangeCompleteBlindsDialog()->spinBox_raiseSmallBlindEveryMinutes->value();
}
if(v->getChangeCompleteBlindsDialog()->radioButton_alwaysDoubleBlinds->isChecked()) {
gameData.raiseMode = DOUBLE_BLINDS;
} else {
gameData.raiseMode = MANUAL_BLINDS_ORDER;
list<int> tempBlindList;
int i;
bool ok = true;
for(i=0; i<v->getChangeCompleteBlindsDialog()->listWidget_blinds->count(); i++) {
tempBlindList.push_back(v->getChangeCompleteBlindsDialog()->listWidget_blinds->item(i)->text().toInt(&ok,10));
}
gameData.manualBlindsList = tempBlindList;
if(v->getChangeCompleteBlindsDialog()->radioButton_afterThisAlwaysDoubleBlinds->isChecked()) {
gameData.afterManualBlindsMode = AFTERMB_DOUBLE_BLINDS;
} else {
if(v->getChangeCompleteBlindsDialog()->radioButton_afterThisAlwaysRaiseAbout->isChecked()) {
gameData.afterManualBlindsMode = AFTERMB_RAISE_ABOUT;
gameData.afterMBAlwaysRaiseValue = v->getChangeCompleteBlindsDialog()->spinBox_afterThisAlwaysRaiseValue->value();
} else {
gameData.afterManualBlindsMode = AFTERMB_STAY_AT_LAST_BLIND;
}
}
}
gameData.guiSpeed = v->spinBox_gameSpeed->value();
} else {
gameData.maxNumberOfPlayers = myConfig->readConfigInt("NumberOfPlayers");
gameData.startMoney = myConfig->readConfigInt("StartCash");
gameData.firstSmallBlind = myConfig->readConfigInt("FirstSmallBlind");
if(myConfig->readConfigInt("RaiseBlindsAtHands")) {
gameData.raiseIntervalMode = RAISE_ON_HANDNUMBER;
gameData.raiseSmallBlindEveryHandsValue = myConfig->readConfigInt("RaiseSmallBlindEveryHands");
} else {
gameData.raiseIntervalMode = RAISE_ON_MINUTES;
gameData.raiseSmallBlindEveryMinutesValue = myConfig->readConfigInt("RaiseSmallBlindEveryMinutes");
}
if(myConfig->readConfigInt("AlwaysDoubleBlinds")) {
gameData.raiseMode = DOUBLE_BLINDS;
} else {
gameData.raiseMode = MANUAL_BLINDS_ORDER;
gameData.manualBlindsList = myConfig->readConfigIntList("ManualBlindsList");
if(myConfig->readConfigInt("AfterMBAlwaysDoubleBlinds")) {
gameData.afterManualBlindsMode = AFTERMB_DOUBLE_BLINDS;
} else {
if(myConfig->readConfigInt("AfterMBAlwaysRaiseAbout")) {
gameData.afterManualBlindsMode = AFTERMB_RAISE_ABOUT;
gameData.afterMBAlwaysRaiseValue = myConfig->readConfigInt("AfterMBAlwaysRaiseValue");
} else {
gameData.afterManualBlindsMode = AFTERMB_STAY_AT_LAST_BLIND;
}
}
}
gameData.guiSpeed = myConfig->readConfigInt("GameSpeed");
}
gameData.delayBetweenHandsSec = 7;
gameData.playerActionTimeoutSec = 20;
myGameLobbyDialog->setSession(getSession());
myStartNetworkGameDialog->setSession(getSession());
myServerGuiInterface->getSession()->startNetworkServer(false,true);
mySession->startNetworkClientForLocalServer(gameData);
myGuiInterface->getMyW()->show();
myGuiInterface->getMyW()->networkGameModification();
assert(getSession());
getSession()->sendStartEvent(true);
}
void startWindowImpl::callGameLobbyDialog()
{
+2
View File
@@ -149,6 +149,7 @@ public slots:
void callSettingsDialog(bool);
void callSettingsDialogFromStartwindow();
void callNewGameDialog();
void callNewGameDialogNew();
void callGameLobbyDialog();
void callCreateNetworkGameDialog();
void callJoinNetworkGameDialog();
@@ -161,6 +162,7 @@ public slots:
void callLogFileDialog();
void startNewLocalGame(newGameDialogImpl* =0);
void startNewLocalGameNew(newGameDialogImpl* =0);
void showTimeoutDialog(int msgID, unsigned duration);
void hideTimeoutDialog();
+1 -1
View File
@@ -1138,7 +1138,7 @@ bool
ServerGame::CheckSettings(const GameData &data, const string &password, ServerMode mode)
{
bool retVal = true;
if (mode != SERVER_MODE_LAN) {
if (mode != SERVER_MODE_LAN && mode != SERVER_MODE_LAN_LOCAL) {
if (data.playerActionTimeoutSec < 5) {
retVal = false;
}
+67 -7
View File
@@ -70,7 +70,7 @@ using namespace boost::chrono;
#define SERVER_COMPUTER_ACTION_DELAY_SEC 0
#define SERVER_PLAYER_TIMEOUT_ADD_DELAY_SEC 1
#else
#define SERVER_DELAY_NEXT_GAME_SEC 10
#define SERVER_DELAY_NEXT_GAME_SEC 10
#define SERVER_DEAL_FLOP_CARDS_DELAY_SEC 5
#define SERVER_DEAL_TURN_CARD_DELAY_SEC 2
#define SERVER_DEAL_RIVER_CARD_DELAY_SEC 2
@@ -80,6 +80,17 @@ using namespace boost::chrono;
#define SERVER_PLAYER_TIMEOUT_ADD_DELAY_SEC 2
#endif
#ifdef NEW_LOCAL_GAME
#define LAN_LOCAL_SERVER_DELAY_NEXT_GAME_SEC 0
#define LAN_LOCAL_SERVER_DEAL_FLOP_CARDS_DELAY_SEC 0
#define LAN_LOCAL_SERVER_DEAL_TURN_CARD_DELAY_SEC 0
#define LAN_LOCAL_SERVER_DEAL_RIVER_CARD_DELAY_SEC 0
#define LAN_LOCAL_SERVER_DEAL_ADD_ALL_IN_DELAY_SEC 0
#define LAN_LOCAL_SERVER_SHOW_CARDS_DELAY_SEC 0
#define LAN_LOCAL_SERVER_COMPUTER_ACTION_DELAY_SEC 0
#define LAN_LOCAL_SERVER_PLAYER_TIMEOUT_ADD_DELAY_SEC 0
#endif
#define SERVER_START_GAME_TIMEOUT_SEC 10
#define SERVER_AUTOSTART_GAME_DELAY_SEC 6
#define SERVER_GAME_ADMIN_WARNING_REMAINING_SEC 60
@@ -574,7 +585,7 @@ void
ServerGameStateInit::RegisterAdminTimer(boost::shared_ptr<ServerGame> server)
{
// No admin timeout in LAN or ranking games.
if (server->GetLobbyThread().GetServerMode() != SERVER_MODE_LAN && server->GetGameData().gameType != GAME_TYPE_RANKING) {
if (server->GetLobbyThread().GetServerMode() != SERVER_MODE_LAN && server->GetLobbyThread().GetServerMode() != SERVER_MODE_LAN_LOCAL && server->GetGameData().gameType != GAME_TYPE_RANKING) {
server->GetStateTimer1().expires_from_now(
seconds(SERVER_GAME_ADMIN_TIMEOUT_SEC - SERVER_GAME_ADMIN_WARNING_REMAINING_SEC));
server->GetStateTimer1().async_wait(
@@ -593,7 +604,7 @@ void
ServerGameStateInit::RegisterAutoStartTimer(boost::shared_ptr<ServerGame> server)
{
// No autostart in LAN games.
if (server->GetLobbyThread().GetServerMode() != SERVER_MODE_LAN) {
if (server->GetLobbyThread().GetServerMode() != SERVER_MODE_LAN && server->GetLobbyThread().GetServerMode() != SERVER_MODE_LAN_LOCAL) {
server->GetStateTimer2().expires_from_now(
seconds(SERVER_AUTOSTART_GAME_DELAY_SEC));
server->GetStateTimer2().async_wait(
@@ -1007,8 +1018,12 @@ ServerGameStateHand::EngineLoop(boost::shared_ptr<ServerGame> server)
server->SendToAllPlayers(allIn, SessionData::Game | SessionData::Spectating);
curGame.getCurrentHand()->setCardsShown(true);
server->GetStateTimer1().expires_from_now(
seconds(SERVER_SHOW_CARDS_DELAY_SEC));
#ifdef NEW_LOCAL_GAME
if(server->getLanLocal()) server->GetStateTimer1().expires_from_now(seconds(LAN_LOCAL_SERVER_SHOW_CARDS_DELAY_SEC));
else server->GetStateTimer1().expires_from_now(seconds(SERVER_SHOW_CARDS_DELAY_SEC));
#else
server->GetStateTimer1().expires_from_now(seconds(SERVER_SHOW_CARDS_DELAY_SEC));
#endif
server->GetStateTimer1().async_wait(
boost::bind(
&ServerGameStateHand::TimerShowCards, this, boost::asio::placeholders::error, server));
@@ -1043,8 +1058,12 @@ ServerGameStateHand::EngineLoop(boost::shared_ptr<ServerGame> server)
// If the player is computer controlled, let the engine act.
if (curPlayer->getMyType() == PLAYER_TYPE_COMPUTER) {
server->GetStateTimer1().expires_from_now(
seconds(SERVER_COMPUTER_ACTION_DELAY_SEC));
#ifdef NEW_LOCAL_GAME
if(server->getLanLocal()) server->GetStateTimer1().expires_from_now(seconds(LAN_LOCAL_SERVER_COMPUTER_ACTION_DELAY_SEC));
else server->GetStateTimer1().expires_from_now(seconds(SERVER_COMPUTER_ACTION_DELAY_SEC));
#else
server->GetStateTimer1().expires_from_now(seconds(SERVER_COMPUTER_ACTION_DELAY_SEC));
#endif
server->GetStateTimer1().async_wait(
boost::bind(
&ServerGameStateHand::TimerComputerAction, this, boost::asio::placeholders::error, server));
@@ -1122,8 +1141,19 @@ ServerGameStateHand::EngineLoop(boost::shared_ptr<ServerGame> server)
server->InternalEndGame();
// View a dialog for a new game - delayed.
#ifdef NEW_LOCAL_GAME
if(server->getLanLocal()) {
server->GetStateTimer1().expires_from_now(
seconds(LAN_LOCAL_SERVER_DELAY_NEXT_GAME_SEC));
} else {
server->GetStateTimer1().expires_from_now(
seconds(SERVER_DELAY_NEXT_GAME_SEC));
}
#else
server->GetStateTimer1().expires_from_now(
seconds(SERVER_DELAY_NEXT_GAME_SEC));
#endif
server->GetStateTimer1().async_wait(
boost::bind(
&ServerGameStateHand::TimerNextGame, this, boost::asio::placeholders::error, server, winnerPlayer->getMyUniqueID()));
@@ -1200,18 +1230,42 @@ int
ServerGameStateHand::GetDealCardsDelaySec(ServerGame &server)
{
Game &curGame = server.GetGame();
#ifdef NEW_LOCAL_GAME
int allInDelay;
if(server.getLanLocal()) {
allInDelay = curGame.getCurrentHand()->getAllInCondition() ? LAN_LOCAL_SERVER_DEAL_ADD_ALL_IN_DELAY_SEC : 0;
} else {
allInDelay = curGame.getCurrentHand()->getAllInCondition() ? SERVER_DEAL_ADD_ALL_IN_DELAY_SEC : 0;
}
#else
int allInDelay = curGame.getCurrentHand()->getAllInCondition() ? SERVER_DEAL_ADD_ALL_IN_DELAY_SEC : 0;
#endif
int delay = 0;
switch(curGame.getCurrentHand()->getCurrentRound()) {
case GAME_STATE_FLOP:
#ifdef NEW_LOCAL_GAME
if(server.getLanLocal()) delay = LAN_LOCAL_SERVER_DEAL_FLOP_CARDS_DELAY_SEC;
else delay = SERVER_DEAL_FLOP_CARDS_DELAY_SEC;
#else
delay = SERVER_DEAL_FLOP_CARDS_DELAY_SEC;
#endif
break;
case GAME_STATE_TURN:
#ifdef NEW_LOCAL_GAME
if(server.getLanLocal()) delay = LAN_LOCAL_SERVER_DEAL_TURN_CARD_DELAY_SEC + allInDelay;
else delay = SERVER_DEAL_TURN_CARD_DELAY_SEC + allInDelay;
#else
delay = SERVER_DEAL_TURN_CARD_DELAY_SEC + allInDelay;
#endif
break;
case GAME_STATE_RIVER:
#ifdef NEW_LOCAL_GAME
if(server.getLanLocal()) delay = LAN_LOCAL_SERVER_DEAL_RIVER_CARD_DELAY_SEC;
else delay = SERVER_DEAL_RIVER_CARD_DELAY_SEC;
#else
delay = SERVER_DEAL_RIVER_CARD_DELAY_SEC;
#endif
break;
default:
break;
@@ -1509,8 +1563,14 @@ ServerGameStateWaitPlayerAction::Enter(boost::shared_ptr<ServerGame> server)
if (server->GetGameData().playerActionTimeoutSec > 0) { // zero means unlimited thinking time
#ifdef POKERTH_SERVER_TEST
int timeoutSec = SERVER_PLAYER_TIMEOUT_ADD_DELAY_SEC;
#else
#ifdef NEW_LOCAL_GAME
int timeoutSec;
if(server->getLanLocal()) timeoutSec = server->GetGameData().playerActionTimeoutSec + LAN_LOCAL_SERVER_PLAYER_TIMEOUT_ADD_DELAY_SEC;
else timeoutSec = server->GetGameData().playerActionTimeoutSec + SERVER_PLAYER_TIMEOUT_ADD_DELAY_SEC;
#else
int timeoutSec = server->GetGameData().playerActionTimeoutSec + SERVER_PLAYER_TIMEOUT_ADD_DELAY_SEC;
#endif
#endif
server->GetStateTimer1().expires_from_now(seconds(timeoutSec));
+4
View File
@@ -301,6 +301,7 @@ ServerLobbyThread::AddConnection(boost::shared_ptr<SessionData> sessionData)
netAnnounce->set_latestbetarevision(POKERTH_BETA_REVISION);
switch (GetServerMode()) {
case SERVER_MODE_LAN:
case SERVER_MODE_LAN_LOCAL:
netAnnounce->set_servertype(AnnounceMessage::serverTypeLAN);
break;
case SERVER_MODE_INTERNET_NOAUTH:
@@ -1353,6 +1354,9 @@ ServerLobbyThread::HandleNetPacketCreateGame(boost::shared_ptr<SessionData> sess
session->GetPlayerData()->GetDBId(),
GetGui(),
m_serverConfig));
#ifdef NEW_LOCAL_GAME
if(m_mode == SERVER_MODE_LAN_LOCAL) game->setLanLocal(true);
#endif
game->Init();
// Add game to list of games.
+14
View File
@@ -126,6 +126,15 @@ public:
void KickPlayer(unsigned playerId);
#ifdef NEW_LOCAL_GAME
bool getLanLocal() {
return lan_local;
}
void setLanLocal(bool theValue) {
lan_local = theValue;
}
#endif
protected:
struct RankingData {
@@ -252,6 +261,11 @@ private:
friend class ServerGameStateHand;
friend class ServerGameStateWaitPlayerAction;
friend class ServerGameStateWaitNextHand;
#ifdef NEW_LOCAL_GAME
bool lan_local;
#endif
};
#endif
+3 -2
View File
@@ -310,7 +310,7 @@ void Session::clientRejoinGame(unsigned gameId)
);
}
void Session::startNetworkServer(bool dedicated)
void Session::startNetworkServer(bool dedicated, bool lan_local)
{
if (myNetServer) {
assert(false);
@@ -325,7 +325,8 @@ void Session::startNetworkServer(bool dedicated)
mode = SERVER_MODE_INTERNET_NOAUTH;
#endif
} else {
mode = SERVER_MODE_LAN;
if(lan_local) mode = SERVER_MODE_LAN_LOCAL;
else mode = SERVER_MODE_LAN;
}
myNetServer = ServerManagerFactory::CreateServerManager(*myConfig, *myGui, mode, *myAvatarManager);
+1 -1
View File
@@ -88,7 +88,7 @@ public:
void clientJoinGame(unsigned gameId, const std::string &password);
void clientRejoinGame(unsigned gameId);
void startNetworkServer(bool dedicated);
void startNetworkServer(bool dedicated, bool lan_local = false);
void sendLeaveCurrentGame();
void sendStartEvent(bool fillUpWithCpuPlayers);
void terminateNetworkServer();