forked from 0ad/0ad
Allow the JS GUI to find out if the lobby client is currently disconnected.
Differential Revision: https://code.wildfiregames.com/D1224 Patch By: fpre / ffffffff Refs #4106, D817 This was SVN commit r20872.
This commit is contained in:
parent
e9e983c2d4
commit
5c605cf218
@ -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;
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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<void, &JSI_Lobby::StopXmppClient>("StopXmppClient");
|
||||
scriptInterface.RegisterFunction<void, &JSI_Lobby::ConnectXmppClient>("ConnectXmppClient");
|
||||
scriptInterface.RegisterFunction<void, &JSI_Lobby::DisconnectXmppClient>("DisconnectXmppClient");
|
||||
scriptInterface.RegisterFunction<bool, &JSI_Lobby::IsXmppClientConnected>("IsXmppClientConnected");
|
||||
scriptInterface.RegisterFunction<void, &JSI_Lobby::SendGetBoardList>("SendGetBoardList");
|
||||
scriptInterface.RegisterFunction<void, std::wstring, &JSI_Lobby::SendGetProfile>("SendGetProfile");
|
||||
scriptInterface.RegisterFunction<void, JS::HandleValue, &JSI_Lobby::SendRegisterGame>("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)
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user