Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/lobby/XmppClient.cpp
/* Copyright (C) 2017 Wildfire Games. | /* Copyright (C) 2018 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | |||||
* @param sUsername Username to login with of register. | * @param sUsername Username to login with of register. | ||||
* @param sPassword Password to login with or register. | * @param sPassword Password to login with or register. | ||||
* @param sRoom MUC room to join. | * @param sRoom MUC room to join. | ||||
* @param sNick Nick to join with. | * @param sNick Nick to join with. | ||||
* @param historyRequestSize Number of stanzas of room history to request. | * @param historyRequestSize Number of stanzas of room history to request. | ||||
* @param regOpt If we are just registering or not. | * @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) | 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 | // Read lobby configuration from default.cfg | ||||
std::string sServer; | std::string sServer; | ||||
std::string sXpartamupp; | std::string sXpartamupp; | ||||
CFG_GET_VAL("lobby.server", sServer); | CFG_GET_VAL("lobby.server", sServer); | ||||
CFG_GET_VAL("lobby.xpartamupp", sXpartamupp); | CFG_GET_VAL("lobby.xpartamupp", sXpartamupp); | ||||
m_xpartamuppId = sXpartamupp + "@" + sServer + "/CC"; | m_xpartamuppId = sXpartamupp + "@" + sServer + "/CC"; | ||||
▲ Show 20 Lines • Show All 84 Lines • ▼ Show 20 Lines | void XmppClient::connect() | ||||
m_client->connect(false); | m_client->connect(false); | ||||
} | } | ||||
void XmppClient::disconnect() | void XmppClient::disconnect() | ||||
{ | { | ||||
m_client->disconnect(); | m_client->disconnect(); | ||||
} | } | ||||
bool XmppClient::isConnected() | |||||
{ | |||||
return m_isConnected; | |||||
} | |||||
void XmppClient::recv() | void XmppClient::recv() | ||||
{ | { | ||||
m_client->recv(1); | m_client->recv(1); | ||||
} | } | ||||
/** | /** | ||||
* Log (debug) Handler | * Log (debug) Handler | ||||
*/ | */ | ||||
void XmppClient::handleLog(gloox::LogLevel level, gloox::LogArea area, const std::string& message) | void XmppClient::handleLog(gloox::LogLevel level, gloox::LogArea area, const std::string& message) | ||||
{ | { | ||||
std::cout << "log: level: " << level << ", area: " << area << ", message: " << message << std::endl; | std::cout << "log: level: " << level << ", area: " << area << ", message: " << message << std::endl; | ||||
} | } | ||||
/***************************************************** | /***************************************************** | ||||
* Connection handlers * | * Connection handlers * | ||||
*****************************************************/ | *****************************************************/ | ||||
/** | /** | ||||
* Handle connection | * Handle connection | ||||
*/ | */ | ||||
void XmppClient::onConnect() | void XmppClient::onConnect() | ||||
{ | { | ||||
if (m_mucRoom) | if (m_mucRoom) | ||||
{ | { | ||||
m_isConnected = true; | |||||
CreateGUIMessage("system", "connected"); | CreateGUIMessage("system", "connected"); | ||||
m_mucRoom->join(); | m_mucRoom->join(); | ||||
} | } | ||||
if (m_registration) | if (m_registration) | ||||
m_registration->fetchRegistrationFields(); | m_registration->fetchRegistrationFields(); | ||||
} | } | ||||
Show All 9 Lines | void XmppClient::onDisconnect(gloox::ConnectionError error) | ||||
// Clear game, board and player lists. | // Clear game, board and player lists. | ||||
for (const glooxwrapper::Tag* const& t : m_GameList) | for (const glooxwrapper::Tag* const& t : m_GameList) | ||||
glooxwrapper::Tag::free(t); | glooxwrapper::Tag::free(t); | ||||
for (const glooxwrapper::Tag* const& t : m_BoardList) | for (const glooxwrapper::Tag* const& t : m_BoardList) | ||||
glooxwrapper::Tag::free(t); | glooxwrapper::Tag::free(t); | ||||
for (const glooxwrapper::Tag* const& t : m_Profile) | for (const glooxwrapper::Tag* const& t : m_Profile) | ||||
glooxwrapper::Tag::free(t); | glooxwrapper::Tag::free(t); | ||||
m_BoardList.clear(); | m_BoardList.clear(); | ||||
m_GameList.clear(); | m_GameList.clear(); | ||||
m_PlayerMap.clear(); | m_PlayerMap.clear(); | ||||
m_Profile.clear(); | m_Profile.clear(); | ||||
m_HistoricGuiMessages.clear(); | m_HistoricGuiMessages.clear(); | ||||
m_isConnected = false; | |||||
CreateGUIMessage("system", "disconnected", "reason", ConnectionErrorToString(error)); | CreateGUIMessage("system", "disconnected", "reason", ConnectionErrorToString(error)); | ||||
} | } | ||||
/** | /** | ||||
* Handle TLS connection | * Handle TLS connection | ||||
*/ | */ | ||||
bool XmppClient::onTLSConnect(const glooxwrapper::CertInfo& info) | bool XmppClient::onTLSConnect(const glooxwrapper::CertInfo& info) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 902 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator