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