Display IP address of game host before connection is established and handles disconnection of peer.
This commit is contained in:
@@ -108,8 +108,8 @@ class GameObserver{
|
|||||||
#ifdef TESTSUITE
|
#ifdef TESTSUITE
|
||||||
void loadTestSuitePlayer(int playerId, TestSuiteGame* testSuite);
|
void loadTestSuitePlayer(int playerId, TestSuiteGame* testSuite);
|
||||||
#endif //TESTSUITE
|
#endif //TESTSUITE
|
||||||
virtual void loadPlayer(int playerId, PlayerType playerType = PLAYER_TYPE_HUMAN, int decknb=0, bool premadeDeck=false);
|
void loadPlayer(int playerId, PlayerType playerType = PLAYER_TYPE_HUMAN, int decknb=0, bool premadeDeck=false);
|
||||||
void loadPlayer(int playerId, Player* player);
|
virtual void loadPlayer(int playerId, Player* player);
|
||||||
|
|
||||||
Player * currentPlayer;
|
Player * currentPlayer;
|
||||||
Player * currentActionPlayer;
|
Player * currentActionPlayer;
|
||||||
@@ -198,7 +198,7 @@ public:
|
|||||||
// no serverIp means a server is being instantiated, otherwise a client
|
// no serverIp means a server is being instantiated, otherwise a client
|
||||||
NetworkGameObserver(JNetwork* pNetwork, WResourceManager* output = 0, JGE* input = 0);
|
NetworkGameObserver(JNetwork* pNetwork, WResourceManager* output = 0, JGE* input = 0);
|
||||||
virtual ~NetworkGameObserver();
|
virtual ~NetworkGameObserver();
|
||||||
virtual void loadPlayer(int playerId, PlayerType playerType = PLAYER_TYPE_HUMAN, int decknb=0, bool premadeDeck=false);
|
virtual void loadPlayer(int playerId, Player* player);
|
||||||
virtual void Update(float dt);
|
virtual void Update(float dt);
|
||||||
void synchronize();
|
void synchronize();
|
||||||
static void loadPlayer(void*pThis, stringstream& in, stringstream& out);
|
static void loadPlayer(void*pThis, stringstream& in, stringstream& out);
|
||||||
@@ -206,6 +206,7 @@ public:
|
|||||||
static void synchronize(void*pThis, stringstream& in, stringstream& out);
|
static void synchronize(void*pThis, stringstream& in, stringstream& out);
|
||||||
static void checkSynchro(void*pxThis, stringstream& in, stringstream& out);
|
static void checkSynchro(void*pxThis, stringstream& in, stringstream& out);
|
||||||
static void ignoreResponse(void*pThis, stringstream& in, stringstream& out){};
|
static void ignoreResponse(void*pThis, stringstream& in, stringstream& out){};
|
||||||
|
static void disconnect(void*pxThis, stringstream& in, stringstream& out);
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -1957,10 +1957,18 @@ NetworkGameObserver::NetworkGameObserver(JNetwork* pNetwork, WResourceManager* o
|
|||||||
mpNetworkSession->registerCommand("loadPlayer", this, loadPlayer, ignoreResponse);
|
mpNetworkSession->registerCommand("loadPlayer", this, loadPlayer, ignoreResponse);
|
||||||
mpNetworkSession->registerCommand("synchronize", this, synchronize, checkSynchro);
|
mpNetworkSession->registerCommand("synchronize", this, synchronize, checkSynchro);
|
||||||
mpNetworkSession->registerCommand("sendAction", this, sendAction, checkSynchro);
|
mpNetworkSession->registerCommand("sendAction", this, sendAction, checkSynchro);
|
||||||
|
mpNetworkSession->registerCommand("disconnect", this, disconnect, ignoreResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkGameObserver::~NetworkGameObserver()
|
NetworkGameObserver::~NetworkGameObserver()
|
||||||
{
|
{
|
||||||
|
mpNetworkSession->sendCommand("disconnect", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
void NetworkGameObserver::disconnect(void*pxThis, stringstream& in, stringstream& out)
|
||||||
|
{
|
||||||
|
NetworkGameObserver* pThis = (NetworkGameObserver*)pxThis;
|
||||||
|
pThis->setLoser(pThis->getView()->getRenderedPlayerOpponent());
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetworkGameObserver::Update(float dt)
|
void NetworkGameObserver::Update(float dt)
|
||||||
@@ -1969,10 +1977,9 @@ void NetworkGameObserver::Update(float dt)
|
|||||||
::GameObserver::Update(dt);
|
::GameObserver::Update(dt);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetworkGameObserver::loadPlayer(int playerId, PlayerType playerType, int decknb, bool premadeDeck)
|
void NetworkGameObserver::loadPlayer(int playerId, Player* player)
|
||||||
{
|
{
|
||||||
GameObserver::loadPlayer(playerId, playerType, decknb, premadeDeck);
|
GameObserver::loadPlayer(playerId, player);
|
||||||
Player* player = getPlayer(playerId);
|
|
||||||
stringstream out;
|
stringstream out;
|
||||||
out << *player;
|
out << *player;
|
||||||
mpNetworkSession->sendCommand("loadPlayer", out.str());
|
mpNetworkSession->sendCommand("loadPlayer", out.str());
|
||||||
|
|||||||
@@ -609,11 +609,14 @@ void GameStateMenu::Update(float dt)
|
|||||||
}
|
}
|
||||||
else if(!subMenuController)
|
else if(!subMenuController)
|
||||||
{
|
{
|
||||||
// currentState = MENU_STATE_MAJOR_SUBMENU;
|
string aString;
|
||||||
subMenuController = NEW SimpleMenu(JGE::GetInstance(), MENU_FIRST_DUEL_SUBMENU, this, Fonts::MENU_FONT, 150, 60);
|
mParent->mpNetwork->getServerIp(aString);
|
||||||
|
aString = "Waiting for connection to " + aString;
|
||||||
|
|
||||||
|
subMenuController = NEW SimpleMenu(JGE::GetInstance(), MENU_FIRST_DUEL_SUBMENU, this, Fonts::MENU_FONT, 150, 60, aString.c_str());
|
||||||
if (subMenuController)
|
if (subMenuController)
|
||||||
{
|
{
|
||||||
subMenuController->Add(SUBMENUITEM_CANCEL, "Cancel connection");
|
subMenuController->Add(SUBMENUITEM_CANCEL, "Cancel");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
@@ -920,7 +923,7 @@ void GameStateMenu::ButtonPressed(int controllerId, int controlId)
|
|||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#ifdef TESTSUITE
|
#ifdef TESTSUITE
|
||||||
case SUBMENUITEM_TESTSUITE:
|
case SUBMENUITEM_TESTSUITE:
|
||||||
mParent->rules = Rules::getRulesByFilename("testsuite.txt");
|
mParent->rules = Rules::getRulesByFilename("testsuite.txt");
|
||||||
this->hasChosenGameType = true;
|
this->hasChosenGameType = true;
|
||||||
mParent->gameType = GAME_TYPE_CLASSIC;
|
mParent->gameType = GAME_TYPE_CLASSIC;
|
||||||
|
|||||||
Reference in New Issue
Block a user