/** * 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) { std::string presence; CScriptValRooted playerList; scriptInterface.Eval("({})", playerList); for(std::map<std::string, gloox::Presence::PresenceType>::const_iterator it = m_PlayerMap.begin(); it != m_PlayerMap.end(); ++it) { CScriptValRooted player; GetPresenceString(it->second, presence); scriptInterface.Eval("({})", player); scriptInterface.SetProperty(player.get(), "name", wstring_from_utf8(it->first)); scriptInterface.SetProperty(player.get(), "presence", wstring_from_utf8(presence)); scriptInterface.SetProperty(playerList.get(), wstring_from_utf8(it->first).c_str(), player); } return playerList; }
/** * 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 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 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; }
CScriptVal CProfileViewer::SaveToJS(ScriptInterface& scriptInterface) { CScriptVal root; scriptInterface.Eval("({})", root); std::vector<AbstractProfileTable*> tables = m->rootTables; sort(tables.begin(), tables.end(), SortByName); for_each(tables.begin(), tables.end(), DumpTable(scriptInterface, root)); return root; }
CScriptVal ConvertTLBs(ScriptInterface& scriptInterface) { CScriptVal ret; scriptInterface.Eval("[]", ret); for(size_t i = 0; ; i++) { const x86_x64::Cache* ptlb = x86_x64::Caches(x86_x64::TLB+i); if (!ptlb) break; CScriptVal tlb; scriptInterface.Eval("({})", tlb); scriptInterface.SetProperty(tlb.get(), "type", (u32)ptlb->type); scriptInterface.SetProperty(tlb.get(), "level", (u32)ptlb->level); scriptInterface.SetProperty(tlb.get(), "associativity", (u32)ptlb->associativity); scriptInterface.SetProperty(tlb.get(), "pagesize", (u32)ptlb->entrySize); scriptInterface.SetProperty(tlb.get(), "entries", (u32)ptlb->numEntries); scriptInterface.SetPropertyInt(ret.get(), i, tlb); } return ret; }
CScriptVal ConvertCaches(ScriptInterface& scriptInterface, x86_x64::IdxCache idxCache) { CScriptVal ret; scriptInterface.Eval("[]", ret); for (size_t idxLevel = 0; idxLevel < x86_x64::Cache::maxLevels; ++idxLevel) { const x86_x64::Cache* pcache = x86_x64::Caches(idxCache+idxLevel); if (pcache->type == x86_x64::Cache::kNull || pcache->numEntries == 0) continue; CScriptVal cache; scriptInterface.Eval("({})", cache); scriptInterface.SetProperty(cache.get(), "type", (u32)pcache->type); scriptInterface.SetProperty(cache.get(), "level", (u32)pcache->level); scriptInterface.SetProperty(cache.get(), "associativity", (u32)pcache->associativity); scriptInterface.SetProperty(cache.get(), "linesize", (u32)pcache->entrySize); scriptInterface.SetProperty(cache.get(), "sharedby", (u32)pcache->sharedBy); scriptInterface.SetProperty(cache.get(), "totalsize", (u32)pcache->TotalSize()); scriptInterface.SetPropertyInt(ret.get(), idxLevel, cache); } return ret; }
void ConvertTLBs(ScriptInterface& scriptInterface, JS::MutableHandleValue ret) { JSContext* cx = scriptInterface.GetContext(); JSAutoRequest rq(cx); scriptInterface.Eval("[]", ret); for(size_t i = 0; ; i++) { const x86_x64::Cache* ptlb = x86_x64::Caches(x86_x64::TLB+i); if (!ptlb) break; JS::RootedValue tlb(cx); scriptInterface.Eval("({})", &tlb); scriptInterface.SetProperty(tlb, "type", (u32)ptlb->type); scriptInterface.SetProperty(tlb, "level", (u32)ptlb->level); scriptInterface.SetProperty(tlb, "associativity", (u32)ptlb->associativity); scriptInterface.SetProperty(tlb, "pagesize", (u32)ptlb->entrySize); scriptInterface.SetProperty(tlb, "entries", (u32)ptlb->numEntries); scriptInterface.SetPropertyInt(ret, i, tlb); } }
void ConvertCaches(ScriptInterface& scriptInterface, x86_x64::IdxCache idxCache, JS::MutableHandleValue ret) { JSContext* cx = scriptInterface.GetContext(); JSAutoRequest rq(cx); scriptInterface.Eval("[]", ret); for (size_t idxLevel = 0; idxLevel < x86_x64::Cache::maxLevels; ++idxLevel) { const x86_x64::Cache* pcache = x86_x64::Caches(idxCache+idxLevel); if (pcache->type == x86_x64::Cache::kNull || pcache->numEntries == 0) continue; JS::RootedValue cache(cx); scriptInterface.Eval("({})", &cache); scriptInterface.SetProperty(cache, "type", (u32)pcache->type); scriptInterface.SetProperty(cache, "level", (u32)pcache->level); scriptInterface.SetProperty(cache, "associativity", (u32)pcache->associativity); scriptInterface.SetProperty(cache, "linesize", (u32)pcache->entrySize); scriptInterface.SetProperty(cache, "sharedby", (u32)pcache->sharedBy); scriptInterface.SetProperty(cache, "totalsize", (u32)pcache->TotalSize()); scriptInterface.SetPropertyInt(ret, idxLevel, cache); } }
JS::Value CProfileViewer::SaveToJS(ScriptInterface& scriptInterface) { JSContext* cx = scriptInterface.GetContext(); JSAutoRequest rq(cx); JS::RootedValue root(cx); scriptInterface.Eval("({})", &root); std::vector<AbstractProfileTable*> tables = m->rootTables; sort(tables.begin(), tables.end(), SortByName); for_each(tables.begin(), tables.end(), DumpTable(scriptInterface, root)); return root; }
std::vector<CScriptValRooted> SavedGames::GetSavedGames(ScriptInterface& scriptInterface) { TIMER(L"GetSavedGames"); std::vector<CScriptValRooted> games; Status err; VfsPaths pathnames; err = vfs::GetPathnames(g_VFS, "saves/", L"*.0adsave", pathnames); WARN_IF_ERR(err); for (size_t i = 0; i < pathnames.size(); ++i) { OsPath realPath; err = g_VFS->GetRealPath(pathnames[i], realPath); if (err < 0) { DEBUG_WARN_ERR(err); continue; // skip this file } PIArchiveReader archiveReader = CreateArchiveReader_Zip(realPath); if (!archiveReader) { // Triggered by e.g. the file being open in another program LOGWARNING(L"Failed to read saved game '%ls'", realPath.string().c_str()); continue; // skip this file } CScriptValRooted metadata; CGameLoader loader(scriptInterface, &metadata, NULL); err = archiveReader->ReadEntries(CGameLoader::ReadEntryCallback, (uintptr_t)&loader); if (err < 0) { DEBUG_WARN_ERR(err); continue; // skip this file } CScriptValRooted game; scriptInterface.Eval("({})", game); scriptInterface.SetProperty(game.get(), "id", pathnames[i].Basename()); scriptInterface.SetProperty(game.get(), "metadata", metadata); games.push_back(game); } return games; }
/** * Send GUI message queue when queried. */ CScriptValRooted XmppClient::GuiPollMessage(ScriptInterface& scriptInterface) { if (m_GuiMessageQueue.empty()) return CScriptValRooted(); GUIMessage message = m_GuiMessageQueue.front(); CScriptValRooted messageVal; scriptInterface.Eval("({})", messageVal); scriptInterface.SetProperty(messageVal.get(), "type", message.type); if (!message.from.empty()) scriptInterface.SetProperty(messageVal.get(), "from", message.from); if (!message.text.empty()) scriptInterface.SetProperty(messageVal.get(), "text", message.text); if (!message.level.empty()) scriptInterface.SetProperty(messageVal.get(), "level", message.level); if (!message.message.empty()) scriptInterface.SetProperty(messageVal.get(), "message", message.message); if (!message.data.empty()) scriptInterface.SetProperty(messageVal.get(), "data", message.data); m_GuiMessageQueue.pop_front(); return messageVal; }