diff --git a/source/lobby/IXmppClient.h b/source/lobby/IXmppClient.h index 18c9d565ac..503c323aa4 100644 --- a/source/lobby/IXmppClient.h +++ b/source/lobby/IXmppClient.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 Wildfire Games. +/* Copyright (C) 2018 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -33,6 +33,7 @@ public: virtual void connect() = 0; virtual void disconnect() = 0; + virtual bool isConnected() = 0; virtual void recv() = 0; virtual void SendIqGetBoardList() = 0; virtual void SendIqGetProfile(const std::string& player) = 0; diff --git a/source/lobby/XmppClient.cpp b/source/lobby/XmppClient.cpp index 9bbc91dbd7..0f0ccbf704 100644 --- a/source/lobby/XmppClient.cpp +++ b/source/lobby/XmppClient.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 Wildfire Games. +/* Copyright (C) 2018 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -75,7 +75,7 @@ IXmppClient* IXmppClient::create(const std::string& sUsername, const std::string * @param regOpt If we are just registering or not. */ XmppClient::XmppClient(const std::string& sUsername, const std::string& sPassword, const std::string& sRoom, const std::string& sNick, const int historyRequestSize, bool regOpt) - : m_client(NULL), m_mucRoom(NULL), m_registration(NULL), m_username(sUsername), m_password(sPassword), m_nick(sNick), m_initialLoadComplete(false), m_sessionManager() + : m_client(NULL), m_mucRoom(NULL), m_registration(NULL), m_username(sUsername), m_password(sPassword), m_nick(sNick), m_initialLoadComplete(false), m_isConnected(false), m_sessionManager() { // Read lobby configuration from default.cfg std::string sServer; @@ -176,6 +176,11 @@ void XmppClient::disconnect() m_client->disconnect(); } +bool XmppClient::isConnected() +{ + return m_isConnected; +} + void XmppClient::recv() { m_client->recv(1); @@ -200,6 +205,7 @@ void XmppClient::onConnect() { if (m_mucRoom) { + m_isConnected = true; CreateGUIMessage("system", "connected"); m_mucRoom->join(); } @@ -225,12 +231,14 @@ void XmppClient::onDisconnect(gloox::ConnectionError error) glooxwrapper::Tag::free(t); for (const glooxwrapper::Tag* const& t : m_Profile) glooxwrapper::Tag::free(t); + m_BoardList.clear(); m_GameList.clear(); m_PlayerMap.clear(); m_Profile.clear(); m_HistoricGuiMessages.clear(); + m_isConnected = false; CreateGUIMessage("system", "disconnected", "reason", ConnectionErrorToString(error)); } diff --git a/source/lobby/XmppClient.h b/source/lobby/XmppClient.h index fbe5f6e5ac..942543b582 100644 --- a/source/lobby/XmppClient.h +++ b/source/lobby/XmppClient.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 Wildfire Games. +/* Copyright (C) 2018 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -52,6 +52,7 @@ private: // State bool m_initialLoadComplete; + bool m_isConnected; public: // Basic @@ -61,6 +62,7 @@ public: // Network void connect(); void disconnect(); + bool isConnected(); void recv(); void SendIqGetBoardList(); void SendIqGetProfile(const std::string& player); diff --git a/source/lobby/scripting/JSInterface_Lobby.cpp b/source/lobby/scripting/JSInterface_Lobby.cpp index 99707dcbcf..df9c6d2c9c 100644 --- a/source/lobby/scripting/JSInterface_Lobby.cpp +++ b/source/lobby/scripting/JSInterface_Lobby.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 Wildfire Games. +/* Copyright (C) 2018 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -39,6 +39,7 @@ void JSI_Lobby::RegisterScriptFunctions(const ScriptInterface& scriptInterface) scriptInterface.RegisterFunction("StopXmppClient"); scriptInterface.RegisterFunction("ConnectXmppClient"); scriptInterface.RegisterFunction("DisconnectXmppClient"); + scriptInterface.RegisterFunction("IsXmppClientConnected"); scriptInterface.RegisterFunction("SendGetBoardList"); scriptInterface.RegisterFunction("SendGetProfile"); scriptInterface.RegisterFunction("SendRegisterGame"); @@ -118,6 +119,12 @@ void JSI_Lobby::DisconnectXmppClient(ScriptInterface::CxPrivate* UNUSED(pCxPriva g_XmppClient->disconnect(); } +bool JSI_Lobby::IsXmppClientConnected(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) +{ + ENSURE(g_XmppClient); + return g_XmppClient->isConnected(); +} + void JSI_Lobby::SendGetBoardList(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) { if (!g_XmppClient) diff --git a/source/lobby/scripting/JSInterface_Lobby.h b/source/lobby/scripting/JSInterface_Lobby.h index ae8710362b..60c381a277 100644 --- a/source/lobby/scripting/JSInterface_Lobby.h +++ b/source/lobby/scripting/JSInterface_Lobby.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 Wildfire Games. +/* Copyright (C) 2018 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -36,6 +36,7 @@ namespace JSI_Lobby void StopXmppClient(ScriptInterface::CxPrivate* pCxPrivate); void ConnectXmppClient(ScriptInterface::CxPrivate* pCxPrivate); void DisconnectXmppClient(ScriptInterface::CxPrivate* pCxPrivate); + bool IsXmppClientConnected(ScriptInterface::CxPrivate* pCxPrivate); void SendGetBoardList(ScriptInterface::CxPrivate* pCxPrivate); void SendGetProfile(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& player); void SendGameReport(ScriptInterface::CxPrivate* pCxPrivate, JS::HandleValue data);