Changeset View
Changeset View
Standalone View
Standalone View
source/lobby/XmppClient.cpp
Show First 20 Lines • Show All 531 Lines • ▼ Show 20 Lines | |||||
/** | /** | ||||
* Handle requests from the GUI for the list of players. | * Handle requests from the GUI for the list of players. | ||||
* | * | ||||
* @return A JS array containing all known players and their presences | * @return A JS array containing all known players and their presences | ||||
*/ | */ | ||||
void XmppClient::GUIGetPlayerList(const ScriptInterface& scriptInterface, JS::MutableHandleValue ret) | void XmppClient::GUIGetPlayerList(const ScriptInterface& scriptInterface, JS::MutableHandleValue ret) | ||||
{ | { | ||||
ScriptInterface::Request rq(scriptInterface); | ScriptRequest rq(scriptInterface); | ||||
ScriptInterface::CreateArray(rq, ret); | ScriptInterface::CreateArray(rq, ret); | ||||
int j = 0; | int j = 0; | ||||
for (const std::pair<glooxwrapper::string, SPlayer>& p : m_PlayerMap) | for (const std::pair<glooxwrapper::string, SPlayer>& p : m_PlayerMap) | ||||
{ | { | ||||
JS::RootedValue player(rq.cx); | JS::RootedValue player(rq.cx); | ||||
Show All 11 Lines | |||||
/** | /** | ||||
* Handle requests from the GUI for the list of all active games. | * Handle requests from the GUI for the list of all active games. | ||||
* | * | ||||
* @return A JS array containing all known games | * @return A JS array containing all known games | ||||
*/ | */ | ||||
void XmppClient::GUIGetGameList(const ScriptInterface& scriptInterface, JS::MutableHandleValue ret) | void XmppClient::GUIGetGameList(const ScriptInterface& scriptInterface, JS::MutableHandleValue ret) | ||||
{ | { | ||||
ScriptInterface::Request rq(scriptInterface); | ScriptRequest rq(scriptInterface); | ||||
ScriptInterface::CreateArray(rq, ret); | ScriptInterface::CreateArray(rq, ret); | ||||
int j = 0; | int j = 0; | ||||
const char* stats[] = { "name", "ip", "port", "stunIP", "stunPort", "hostUsername", "state", | const char* stats[] = { "name", "ip", "port", "stunIP", "stunPort", "hostUsername", "state", | ||||
"nbp", "maxnbp", "players", "mapName", "niceMapName", "mapSize", "mapType", | "nbp", "maxnbp", "players", "mapName", "niceMapName", "mapSize", "mapType", | ||||
"victoryConditions", "startTime", "mods" }; | "victoryConditions", "startTime", "mods" }; | ||||
Show All 11 Lines | |||||
/** | /** | ||||
* Handle requests from the GUI for leaderboard data. | * Handle requests from the GUI for leaderboard data. | ||||
* | * | ||||
* @return A JS array containing all known leaderboard data | * @return A JS array containing all known leaderboard data | ||||
*/ | */ | ||||
void XmppClient::GUIGetBoardList(const ScriptInterface& scriptInterface, JS::MutableHandleValue ret) | void XmppClient::GUIGetBoardList(const ScriptInterface& scriptInterface, JS::MutableHandleValue ret) | ||||
{ | { | ||||
ScriptInterface::Request rq(scriptInterface); | ScriptRequest rq(scriptInterface); | ||||
ScriptInterface::CreateArray(rq, ret); | ScriptInterface::CreateArray(rq, ret); | ||||
int j = 0; | int j = 0; | ||||
const char* attributes[] = { "name", "rank", "rating" }; | const char* attributes[] = { "name", "rank", "rating" }; | ||||
for(const glooxwrapper::Tag* const& t : m_BoardList) | for(const glooxwrapper::Tag* const& t : m_BoardList) | ||||
{ | { | ||||
Show All 9 Lines | |||||
/** | /** | ||||
* Handle requests from the GUI for profile data. | * Handle requests from the GUI for profile data. | ||||
* | * | ||||
* @return A JS array containing the specific user's profile data | * @return A JS array containing the specific user's profile data | ||||
*/ | */ | ||||
void XmppClient::GUIGetProfile(const ScriptInterface& scriptInterface, JS::MutableHandleValue ret) | void XmppClient::GUIGetProfile(const ScriptInterface& scriptInterface, JS::MutableHandleValue ret) | ||||
{ | { | ||||
ScriptInterface::Request rq(scriptInterface); | ScriptRequest rq(scriptInterface); | ||||
ScriptInterface::CreateArray(rq, ret); | ScriptInterface::CreateArray(rq, ret); | ||||
int j = 0; | int j = 0; | ||||
const char* stats[] = { "player", "rating", "totalGamesPlayed", "highestRating", "wins", "losses", "rank" }; | const char* stats[] = { "player", "rating", "totalGamesPlayed", "highestRating", "wins", "losses", "rank" }; | ||||
for (const glooxwrapper::Tag* const& t : m_Profile) | for (const glooxwrapper::Tag* const& t : m_Profile) | ||||
{ | { | ||||
JS::RootedValue profile(rq.cx); | JS::RootedValue profile(rq.cx); | ||||
ScriptInterface::CreateObject(rq, &profile); | ScriptInterface::CreateObject(rq, &profile); | ||||
for (size_t i = 0; i < ARRAY_SIZE(stats); ++i) | for (size_t i = 0; i < ARRAY_SIZE(stats); ++i) | ||||
scriptInterface.SetProperty(profile, stats[i], t->findAttribute(stats[i])); | scriptInterface.SetProperty(profile, stats[i], t->findAttribute(stats[i])); | ||||
scriptInterface.SetPropertyInt(ret, j++, profile); | scriptInterface.SetPropertyInt(ret, j++, profile); | ||||
} | } | ||||
} | } | ||||
/***************************************************** | /***************************************************** | ||||
* Message interfaces * | * Message interfaces * | ||||
*****************************************************/ | *****************************************************/ | ||||
void SetGUIMessageProperty(const ScriptInterface::Request& UNUSED(rq), JS::HandleObject UNUSED(messageObj)) | void SetGUIMessageProperty(const ScriptRequest& UNUSED(rq), JS::HandleObject UNUSED(messageObj)) | ||||
{ | { | ||||
} | } | ||||
template<typename T, typename... Args> | template<typename T, typename... Args> | ||||
void SetGUIMessageProperty(const ScriptInterface::Request& rq, JS::HandleObject messageObj, const std::string& propertyName, const T& propertyValue, Args const&... args) | void SetGUIMessageProperty(const ScriptRequest& rq, JS::HandleObject messageObj, const std::string& propertyName, const T& propertyValue, Args const&... args) | ||||
{ | { | ||||
JS::RootedValue scriptPropertyValue(rq.cx); | JS::RootedValue scriptPropertyValue(rq.cx); | ||||
ScriptInterface::AssignOrToJSVal(rq, &scriptPropertyValue, propertyValue); | ScriptInterface::AssignOrToJSVal(rq, &scriptPropertyValue, propertyValue); | ||||
JS_DefineProperty(rq.cx, messageObj, propertyName.c_str(), scriptPropertyValue, JSPROP_ENUMERATE); | JS_DefineProperty(rq.cx, messageObj, propertyName.c_str(), scriptPropertyValue, JSPROP_ENUMERATE); | ||||
SetGUIMessageProperty(rq, messageObj, args...); | SetGUIMessageProperty(rq, messageObj, args...); | ||||
} | } | ||||
template<typename... Args> | template<typename... Args> | ||||
void XmppClient::CreateGUIMessage( | void XmppClient::CreateGUIMessage( | ||||
const std::string& type, | const std::string& type, | ||||
const std::string& level, | const std::string& level, | ||||
const std::time_t time, | const std::time_t time, | ||||
Args const&... args) | Args const&... args) | ||||
{ | { | ||||
if (!m_ScriptInterface) | if (!m_ScriptInterface) | ||||
return; | return; | ||||
ScriptInterface::Request rq(m_ScriptInterface); | ScriptRequest rq(m_ScriptInterface); | ||||
JS::RootedValue message(rq.cx); | JS::RootedValue message(rq.cx); | ||||
ScriptInterface::CreateObject( | ScriptInterface::CreateObject( | ||||
rq, | rq, | ||||
&message, | &message, | ||||
"type", type, | "type", type, | ||||
"level", level, | "level", level, | ||||
"historic", false, | "historic", false, | ||||
"time", static_cast<double>(time)); | "time", static_cast<double>(time)); | ||||
Show All 16 Lines | bool XmppClient::GuiPollHasPlayerListUpdate() | ||||
return hasUpdate; | return hasUpdate; | ||||
} | } | ||||
JS::Value XmppClient::GuiPollNewMessages(const ScriptInterface& scriptInterface) | JS::Value XmppClient::GuiPollNewMessages(const ScriptInterface& scriptInterface) | ||||
{ | { | ||||
if ((m_isConnected && !m_initialLoadComplete) || m_GuiMessageQueue.empty()) | if ((m_isConnected && !m_initialLoadComplete) || m_GuiMessageQueue.empty()) | ||||
return JS::UndefinedValue(); | return JS::UndefinedValue(); | ||||
ScriptInterface::Request rq(m_ScriptInterface); | ScriptRequest rq(m_ScriptInterface); | ||||
// Optimize for batch message processing that is more | // Optimize for batch message processing that is more | ||||
// performance demanding than processing a lone message. | // performance demanding than processing a lone message. | ||||
JS::RootedValue messages(rq.cx); | JS::RootedValue messages(rq.cx); | ||||
ScriptInterface::CreateArray(rq, &messages); | ScriptInterface::CreateArray(rq, &messages); | ||||
int j = 0; | int j = 0; | ||||
Show All 30 Lines | JS::Value XmppClient::GuiPollNewMessages(const ScriptInterface& scriptInterface) | ||||
return scriptInterface.CloneValueFromOtherCompartment(*m_ScriptInterface, messages); | return scriptInterface.CloneValueFromOtherCompartment(*m_ScriptInterface, messages); | ||||
} | } | ||||
JS::Value XmppClient::GuiPollHistoricMessages(const ScriptInterface& scriptInterface) | JS::Value XmppClient::GuiPollHistoricMessages(const ScriptInterface& scriptInterface) | ||||
{ | { | ||||
if (m_HistoricGuiMessages.empty()) | if (m_HistoricGuiMessages.empty()) | ||||
return JS::UndefinedValue(); | return JS::UndefinedValue(); | ||||
ScriptInterface::Request rq(m_ScriptInterface); | ScriptRequest rq(m_ScriptInterface); | ||||
JS::RootedValue messages(rq.cx); | JS::RootedValue messages(rq.cx); | ||||
ScriptInterface::CreateArray(rq, &messages); | ScriptInterface::CreateArray(rq, &messages); | ||||
int j = 0; | int j = 0; | ||||
for (const JS::Heap<JS::Value>& message : m_HistoricGuiMessages) | for (const JS::Heap<JS::Value>& message : m_HistoricGuiMessages) | ||||
m_ScriptInterface->SetPropertyInt(messages, j++, message); | m_ScriptInterface->SetPropertyInt(messages, j++, message); | ||||
▲ Show 20 Lines • Show All 621 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator