Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/lobby/XmppClient.cpp
Show First 20 Lines • Show All 533 Lines • ▼ Show 20 Lines | |||||
* | * | ||||
* @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) | ||||
{ | { | ||||
JSContext* cx = scriptInterface.GetContext(); | JSContext* cx = scriptInterface.GetContext(); | ||||
JSAutoRequest rq(cx); | JSAutoRequest rq(cx); | ||||
scriptInterface.CreateArray(ret); | ScriptInterface::CreateArray(cx, 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(cx); | JS::RootedValue player(cx); | ||||
scriptInterface.CreateObject( | ScriptInterface::CreateObject( | ||||
cx, | |||||
&player, | &player, | ||||
"name", p.first, | "name", p.first, | ||||
"presence", p.second.m_Presence, | "presence", p.second.m_Presence, | ||||
"rating", p.second.m_Rating, | "rating", p.second.m_Rating, | ||||
"role", p.second.m_Role); | "role", p.second.m_Role); | ||||
scriptInterface.SetPropertyInt(ret, j++, player); | scriptInterface.SetPropertyInt(ret, j++, player); | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* 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) | ||||
{ | { | ||||
JSContext* cx = scriptInterface.GetContext(); | JSContext* cx = scriptInterface.GetContext(); | ||||
JSAutoRequest rq(cx); | JSAutoRequest rq(cx); | ||||
scriptInterface.CreateArray(ret); | ScriptInterface::CreateArray(cx, 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", | ||||
"victoryCondition", "startTime", "mods" }; | "victoryCondition", "startTime", "mods" }; | ||||
for(const glooxwrapper::Tag* const& t : m_GameList) | for(const glooxwrapper::Tag* const& t : m_GameList) | ||||
{ | { | ||||
JS::RootedValue game(cx); | JS::RootedValue game(cx); | ||||
scriptInterface.CreateObject(&game); | ScriptInterface::CreateObject(cx, &game); | ||||
for (size_t i = 0; i < ARRAY_SIZE(stats); ++i) | for (size_t i = 0; i < ARRAY_SIZE(stats); ++i) | ||||
scriptInterface.SetProperty(game, stats[i], t->findAttribute(stats[i])); | scriptInterface.SetProperty(game, stats[i], t->findAttribute(stats[i])); | ||||
scriptInterface.SetPropertyInt(ret, j++, game); | scriptInterface.SetPropertyInt(ret, j++, game); | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* 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) | ||||
{ | { | ||||
JSContext* cx = scriptInterface.GetContext(); | JSContext* cx = scriptInterface.GetContext(); | ||||
JSAutoRequest rq(cx); | JSAutoRequest rq(cx); | ||||
scriptInterface.CreateArray(ret); | ScriptInterface::CreateArray(cx, 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) | ||||
{ | { | ||||
JS::RootedValue board(cx); | JS::RootedValue board(cx); | ||||
scriptInterface.CreateObject(&board); | ScriptInterface::CreateObject(cx, &board); | ||||
for (size_t i = 0; i < ARRAY_SIZE(attributes); ++i) | for (size_t i = 0; i < ARRAY_SIZE(attributes); ++i) | ||||
scriptInterface.SetProperty(board, attributes[i], t->findAttribute(attributes[i])); | scriptInterface.SetProperty(board, attributes[i], t->findAttribute(attributes[i])); | ||||
scriptInterface.SetPropertyInt(ret, j++, board); | scriptInterface.SetPropertyInt(ret, j++, board); | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* 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) | ||||
{ | { | ||||
JSContext* cx = scriptInterface.GetContext(); | JSContext* cx = scriptInterface.GetContext(); | ||||
JSAutoRequest rq(cx); | JSAutoRequest rq(cx); | ||||
scriptInterface.CreateArray(ret); | ScriptInterface::CreateArray(cx, 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(cx); | JS::RootedValue profile(cx); | ||||
scriptInterface.CreateObject(&profile); | ScriptInterface::CreateObject(cx, &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); | ||||
} | } | ||||
} | } | ||||
Show All 22 Lines | void XmppClient::CreateGUIMessage( | ||||
const std::time_t time, | const std::time_t time, | ||||
Args const&... args) | Args const&... args) | ||||
{ | { | ||||
if (!m_ScriptInterface) | if (!m_ScriptInterface) | ||||
return; | return; | ||||
JSContext* cx = m_ScriptInterface->GetContext(); | JSContext* cx = m_ScriptInterface->GetContext(); | ||||
JSAutoRequest rq(cx); | JSAutoRequest rq(cx); | ||||
JS::RootedValue message(cx); | JS::RootedValue message(cx); | ||||
m_ScriptInterface->CreateObject( | ScriptInterface::CreateObject( | ||||
cx, | |||||
&message, | &message, | ||||
"type", type, | "type", type, | ||||
"level", level, | "level", level, | ||||
"historic", false, | "historic", false, | ||||
"time", static_cast<double>(time)); | "time", static_cast<double>(time)); | ||||
JS::RootedObject messageObj(cx, message.toObjectOrNull()); | JS::RootedObject messageObj(cx, message.toObjectOrNull()); | ||||
SetGUIMessageProperty(cx, messageObj, args...); | SetGUIMessageProperty(cx, messageObj, args...); | ||||
Show All 33 Lines | |||||
} | } | ||||
JS::Value XmppClient::GuiPollHistoricMessages(const ScriptInterface& scriptInterface) | JS::Value XmppClient::GuiPollHistoricMessages(const ScriptInterface& scriptInterface) | ||||
{ | { | ||||
JSContext* cx = scriptInterface.GetContext(); | JSContext* cx = scriptInterface.GetContext(); | ||||
JSAutoRequest rq(cx); | JSAutoRequest rq(cx); | ||||
JS::RootedValue ret(cx); | JS::RootedValue ret(cx); | ||||
scriptInterface.CreateArray(&ret); | ScriptInterface::CreateArray(cx, &ret); | ||||
int j = 0; | int j = 0; | ||||
for (const JS::Heap<JS::Value>& message : m_HistoricGuiMessages) | for (const JS::Heap<JS::Value>& message : m_HistoricGuiMessages) | ||||
scriptInterface.SetPropertyInt(ret, j++, message); | scriptInterface.SetPropertyInt(ret, j++, message); | ||||
return ret; | return ret; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 603 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator