/** * Handle requests from the GUI for the list of all active games. * * @return A JS array containing all known games */ CScriptValRooted XmppClient::GUIGetGameList(ScriptInterface& scriptInterface) { CScriptValRooted gameList; scriptInterface.Eval("([])", gameList); for(std::vector<const glooxwrapper::Tag*>::const_iterator it = m_GameList.begin(); it != m_GameList.end(); ++it) { CScriptValRooted game; scriptInterface.Eval("({})", game); const char* stats[] = { "name", "ip", "state", "nbp", "tnbp", "players", "mapName", "niceMapName", "mapSize", "mapType", "victoryCondition" }; short stats_length = 11; for (short i = 0; i < stats_length; i++) scriptInterface.SetProperty(game.get(), stats[i], wstring_from_utf8((*it)->findAttribute(stats[i]).to_string())); scriptInterface.CallFunctionVoid(gameList.get(), "push", game); } return gameList; }
/** * Handle requests from the GUI for leaderboard data. * * @return A JS array containing all known leaderboard data */ CScriptValRooted XmppClient::GUIGetBoardList(ScriptInterface& scriptInterface) { CScriptValRooted boardList; scriptInterface.Eval("([])", boardList); for(std::vector<const glooxwrapper::Tag*>::const_iterator it = m_BoardList.begin(); it != m_BoardList.end(); ++it) { CScriptValRooted board; scriptInterface.Eval("({})", board); const char* attributes[] = { "name", "rank", "rating" }; short attributes_length = 3; for (short i = 0; i < attributes_length; i++) scriptInterface.SetProperty(board.get(), attributes[i], wstring_from_utf8((*it)->findAttribute(attributes[i]).to_string())); scriptInterface.CallFunctionVoid(boardList.get(), "push", board); } return boardList; }
/** * Handle requests from the GUI for the list of players. * * @return A JS array containing all known players and their presences */ CScriptValRooted XmppClient::GUIGetPlayerList(ScriptInterface& scriptInterface) { CScriptValRooted playerList; scriptInterface.Eval("([])", playerList); // Convert the internal data structure to a Javascript object. for (std::map<std::string, std::vector<std::string> >::const_iterator it = m_PlayerMap.begin(); it != m_PlayerMap.end(); ++it) { CScriptValRooted player; scriptInterface.Eval("({})", player); scriptInterface.SetProperty(player.get(), "name", wstring_from_utf8(it->first)); scriptInterface.SetProperty(player.get(), "presence", wstring_from_utf8(it->second[0])); scriptInterface.SetProperty(player.get(), "rating", wstring_from_utf8(it->second[1])); scriptInterface.SetProperty(player.get(), "role", wstring_from_utf8(it->second[2])); scriptInterface.CallFunctionVoid(playerList.get(), "push", player); } return playerList; }