Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/lobby/scripting/JSInterface_Lobby.cpp
Show First 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | #if CONFIG2_LOBBY // Allow the lobby to be disabled | ||||
scriptInterface.RegisterFunction<const char*, std::wstring, &JSI_Lobby::LobbyGetPlayerPresence>("LobbyGetPlayerPresence"); | scriptInterface.RegisterFunction<const char*, std::wstring, &JSI_Lobby::LobbyGetPlayerPresence>("LobbyGetPlayerPresence"); | ||||
scriptInterface.RegisterFunction<const char*, std::wstring, &JSI_Lobby::LobbyGetPlayerRole>("LobbyGetPlayerRole"); | scriptInterface.RegisterFunction<const char*, std::wstring, &JSI_Lobby::LobbyGetPlayerRole>("LobbyGetPlayerRole"); | ||||
scriptInterface.RegisterFunction<std::wstring, std::wstring, &JSI_Lobby::LobbyGetPlayerRating>("LobbyGetPlayerRating"); | scriptInterface.RegisterFunction<std::wstring, std::wstring, &JSI_Lobby::LobbyGetPlayerRating>("LobbyGetPlayerRating"); | ||||
scriptInterface.RegisterFunction<std::wstring, std::wstring, std::wstring, &JSI_Lobby::EncryptPassword>("EncryptPassword"); | scriptInterface.RegisterFunction<std::wstring, std::wstring, std::wstring, &JSI_Lobby::EncryptPassword>("EncryptPassword"); | ||||
scriptInterface.RegisterFunction<std::wstring, &JSI_Lobby::LobbyGetRoomSubject>("LobbyGetRoomSubject"); | scriptInterface.RegisterFunction<std::wstring, &JSI_Lobby::LobbyGetRoomSubject>("LobbyGetRoomSubject"); | ||||
#endif // CONFIG2_LOBBY | #endif // CONFIG2_LOBBY | ||||
} | } | ||||
bool JSI_Lobby::HasXmppClient(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) | bool JSI_Lobby::HasXmppClient(ScriptInterface::CmptPrivate* UNUSED(pCmptPrivate)) | ||||
{ | { | ||||
return g_XmppClient; | return g_XmppClient; | ||||
} | } | ||||
void JSI_Lobby::SetRankedGame(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), bool isRanked) | void JSI_Lobby::SetRankedGame(ScriptInterface::CmptPrivate* UNUSED(pCmptPrivate), bool isRanked) | ||||
{ | { | ||||
g_rankedGame = isRanked; | g_rankedGame = isRanked; | ||||
} | } | ||||
#if CONFIG2_LOBBY | #if CONFIG2_LOBBY | ||||
void JSI_Lobby::StartXmppClient(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& username, const std::wstring& password, const std::wstring& room, const std::wstring& nick, int historyRequestSize) | void JSI_Lobby::StartXmppClient(ScriptInterface::CmptPrivate* pCmptPrivate, const std::wstring& username, const std::wstring& password, const std::wstring& room, const std::wstring& nick, int historyRequestSize) | ||||
{ | { | ||||
if (g_XmppClient) | if (g_XmppClient) | ||||
{ | { | ||||
ScriptInterface::Request rq(pCxPrivate); | ScriptInterface::Request rq(pCmptPrivate); | ||||
JS_ReportError(rq.cx, "Cannot call StartXmppClient with an already initialized XmppClient!"); | JS_ReportError(rq.cx, "Cannot call StartXmppClient with an already initialized XmppClient!"); | ||||
return; | return; | ||||
} | } | ||||
g_XmppClient = | g_XmppClient = | ||||
IXmppClient::create( | IXmppClient::create( | ||||
g_GUI->GetScriptInterface().get(), | g_GUI->GetScriptInterface().get(), | ||||
utf8_from_wstring(username), | utf8_from_wstring(username), | ||||
utf8_from_wstring(password), | utf8_from_wstring(password), | ||||
utf8_from_wstring(room), | utf8_from_wstring(room), | ||||
utf8_from_wstring(nick), | utf8_from_wstring(nick), | ||||
historyRequestSize); | historyRequestSize); | ||||
g_rankedGame = true; | g_rankedGame = true; | ||||
} | } | ||||
void JSI_Lobby::StartRegisterXmppClient(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& username, const std::wstring& password) | void JSI_Lobby::StartRegisterXmppClient(ScriptInterface::CmptPrivate* pCmptPrivate, const std::wstring& username, const std::wstring& password) | ||||
{ | { | ||||
if (g_XmppClient) | if (g_XmppClient) | ||||
{ | { | ||||
ScriptInterface::Request rq(pCxPrivate); | ScriptInterface::Request rq(pCmptPrivate); | ||||
JS_ReportError(rq.cx, "Cannot call StartRegisterXmppClient with an already initialized XmppClient!"); | JS_ReportError(rq.cx, "Cannot call StartRegisterXmppClient with an already initialized XmppClient!"); | ||||
return; | return; | ||||
} | } | ||||
g_XmppClient = | g_XmppClient = | ||||
IXmppClient::create( | IXmppClient::create( | ||||
g_GUI->GetScriptInterface().get(), | g_GUI->GetScriptInterface().get(), | ||||
utf8_from_wstring(username), | utf8_from_wstring(username), | ||||
utf8_from_wstring(password), | utf8_from_wstring(password), | ||||
std::string(), | std::string(), | ||||
std::string(), | std::string(), | ||||
0, | 0, | ||||
true); | true); | ||||
} | } | ||||
void JSI_Lobby::StopXmppClient(ScriptInterface::CxPrivate* pCxPrivate) | void JSI_Lobby::StopXmppClient(ScriptInterface::CmptPrivate* pCmptPrivate) | ||||
{ | { | ||||
if (!g_XmppClient) | if (!g_XmppClient) | ||||
{ | { | ||||
ScriptInterface::Request rq(pCxPrivate); | ScriptInterface::Request rq(pCmptPrivate); | ||||
JS_ReportError(rq.cx, "Cannot call StopXmppClient without an initialized XmppClient!"); | JS_ReportError(rq.cx, "Cannot call StopXmppClient without an initialized XmppClient!"); | ||||
return; | return; | ||||
} | } | ||||
SAFE_DELETE(g_XmppClient); | SAFE_DELETE(g_XmppClient); | ||||
g_rankedGame = false; | g_rankedGame = false; | ||||
} | } | ||||
void JSI_Lobby::ConnectXmppClient(ScriptInterface::CxPrivate* pCxPrivate) | void JSI_Lobby::ConnectXmppClient(ScriptInterface::CmptPrivate* pCmptPrivate) | ||||
{ | { | ||||
if (!g_XmppClient) | if (!g_XmppClient) | ||||
{ | { | ||||
ScriptInterface::Request rq(pCxPrivate); | ScriptInterface::Request rq(pCmptPrivate); | ||||
JS_ReportError(rq.cx, "Cannot call ConnectXmppClient without an initialized XmppClient!"); | JS_ReportError(rq.cx, "Cannot call ConnectXmppClient without an initialized XmppClient!"); | ||||
return; | return; | ||||
} | } | ||||
g_XmppClient->connect(); | g_XmppClient->connect(); | ||||
} | } | ||||
void JSI_Lobby::DisconnectXmppClient(ScriptInterface::CxPrivate* pCxPrivate) | void JSI_Lobby::DisconnectXmppClient(ScriptInterface::CmptPrivate* pCmptPrivate) | ||||
{ | { | ||||
if (!g_XmppClient) | if (!g_XmppClient) | ||||
{ | { | ||||
ScriptInterface::Request rq(pCxPrivate); | ScriptInterface::Request rq(pCmptPrivate); | ||||
JS_ReportError(rq.cx, "Cannot call DisconnectXmppClient without an initialized XmppClient!"); | JS_ReportError(rq.cx, "Cannot call DisconnectXmppClient without an initialized XmppClient!"); | ||||
return; | return; | ||||
} | } | ||||
g_XmppClient->disconnect(); | g_XmppClient->disconnect(); | ||||
} | } | ||||
bool JSI_Lobby::IsXmppClientConnected(ScriptInterface::CxPrivate* pCxPrivate) | bool JSI_Lobby::IsXmppClientConnected(ScriptInterface::CmptPrivate* pCmptPrivate) | ||||
{ | { | ||||
if (!g_XmppClient) | if (!g_XmppClient) | ||||
{ | { | ||||
ScriptInterface::Request rq(pCxPrivate); | ScriptInterface::Request rq(pCmptPrivate); | ||||
JS_ReportError(rq.cx, "Cannot call IsXmppClientConnected without an initialized XmppClient!"); | JS_ReportError(rq.cx, "Cannot call IsXmppClientConnected without an initialized XmppClient!"); | ||||
return false; | return false; | ||||
} | } | ||||
return g_XmppClient->isConnected(); | return g_XmppClient->isConnected(); | ||||
} | } | ||||
void JSI_Lobby::SendGetBoardList(ScriptInterface::CxPrivate* pCxPrivate) | void JSI_Lobby::SendGetBoardList(ScriptInterface::CmptPrivate* pCmptPrivate) | ||||
{ | { | ||||
if (!g_XmppClient) | if (!g_XmppClient) | ||||
{ | { | ||||
ScriptInterface::Request rq(pCxPrivate); | ScriptInterface::Request rq(pCmptPrivate); | ||||
JS_ReportError(rq.cx, "Cannot call SendGetBoardList without an initialized XmppClient!"); | JS_ReportError(rq.cx, "Cannot call SendGetBoardList without an initialized XmppClient!"); | ||||
return; | return; | ||||
} | } | ||||
g_XmppClient->SendIqGetBoardList(); | g_XmppClient->SendIqGetBoardList(); | ||||
} | } | ||||
void JSI_Lobby::SendGetProfile(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& player) | void JSI_Lobby::SendGetProfile(ScriptInterface::CmptPrivate* pCmptPrivate, const std::wstring& player) | ||||
{ | { | ||||
if (!g_XmppClient) | if (!g_XmppClient) | ||||
{ | { | ||||
ScriptInterface::Request rq(pCxPrivate); | ScriptInterface::Request rq(pCmptPrivate); | ||||
JS_ReportError(rq.cx, "Cannot call SendGetProfile without an initialized XmppClient!"); | JS_ReportError(rq.cx, "Cannot call SendGetProfile without an initialized XmppClient!"); | ||||
return; | return; | ||||
} | } | ||||
g_XmppClient->SendIqGetProfile(utf8_from_wstring(player)); | g_XmppClient->SendIqGetProfile(utf8_from_wstring(player)); | ||||
} | } | ||||
void JSI_Lobby::SendGameReport(ScriptInterface::CxPrivate* pCxPrivate, JS::HandleValue data) | void JSI_Lobby::SendGameReport(ScriptInterface::CmptPrivate* pCmptPrivate, JS::HandleValue data) | ||||
{ | { | ||||
if (!g_XmppClient) | if (!g_XmppClient) | ||||
{ | { | ||||
ScriptInterface::Request rq(pCxPrivate); | ScriptInterface::Request rq(pCmptPrivate); | ||||
JS_ReportError(rq.cx, "Cannot call SendGameReport without an initialized XmppClient!"); | JS_ReportError(rq.cx, "Cannot call SendGameReport without an initialized XmppClient!"); | ||||
return; | return; | ||||
} | } | ||||
g_XmppClient->SendIqGameReport(*(pCxPrivate->pScriptInterface), data); | g_XmppClient->SendIqGameReport(*(pCmptPrivate->pScriptInterface), data); | ||||
} | } | ||||
void JSI_Lobby::SendRegisterGame(ScriptInterface::CxPrivate* pCxPrivate, JS::HandleValue data) | void JSI_Lobby::SendRegisterGame(ScriptInterface::CmptPrivate* pCmptPrivate, JS::HandleValue data) | ||||
{ | { | ||||
if (!g_XmppClient) | if (!g_XmppClient) | ||||
{ | { | ||||
ScriptInterface::Request rq(pCxPrivate); | ScriptInterface::Request rq(pCmptPrivate); | ||||
JS_ReportError(rq.cx, "Cannot call SendRegisterGame without an initialized XmppClient!"); | JS_ReportError(rq.cx, "Cannot call SendRegisterGame without an initialized XmppClient!"); | ||||
return; | return; | ||||
} | } | ||||
// Prevent JS mods to register matches in the lobby that were started with lobby authentication disabled | // Prevent JS mods to register matches in the lobby that were started with lobby authentication disabled | ||||
if (!g_NetServer || !g_NetServer->UseLobbyAuth()) | if (!g_NetServer || !g_NetServer->UseLobbyAuth()) | ||||
{ | { | ||||
LOGERROR("Registering games in the lobby requires lobby authentication to be enabled!"); | LOGERROR("Registering games in the lobby requires lobby authentication to be enabled!"); | ||||
return; | return; | ||||
} | } | ||||
g_XmppClient->SendIqRegisterGame(*(pCxPrivate->pScriptInterface), data); | g_XmppClient->SendIqRegisterGame(*(pCmptPrivate->pScriptInterface), data); | ||||
} | } | ||||
void JSI_Lobby::SendUnregisterGame(ScriptInterface::CxPrivate* pCxPrivate) | void JSI_Lobby::SendUnregisterGame(ScriptInterface::CmptPrivate* pCmptPrivate) | ||||
{ | { | ||||
if (!g_XmppClient) | if (!g_XmppClient) | ||||
{ | { | ||||
ScriptInterface::Request rq(pCxPrivate); | ScriptInterface::Request rq(pCmptPrivate); | ||||
JS_ReportError(rq.cx, "Cannot call SendUnregisterGame without an initialized XmppClient!"); | JS_ReportError(rq.cx, "Cannot call SendUnregisterGame without an initialized XmppClient!"); | ||||
return; | return; | ||||
} | } | ||||
g_XmppClient->SendIqUnregisterGame(); | g_XmppClient->SendIqUnregisterGame(); | ||||
} | } | ||||
void JSI_Lobby::SendChangeStateGame(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& nbp, const std::wstring& players) | void JSI_Lobby::SendChangeStateGame(ScriptInterface::CmptPrivate* pCmptPrivate, const std::wstring& nbp, const std::wstring& players) | ||||
{ | { | ||||
if (!g_XmppClient) | if (!g_XmppClient) | ||||
{ | { | ||||
ScriptInterface::Request rq(pCxPrivate); | ScriptInterface::Request rq(pCmptPrivate); | ||||
JS_ReportError(rq.cx, "Cannot call SendChangeStateGame without an initialized XmppClient!"); | JS_ReportError(rq.cx, "Cannot call SendChangeStateGame without an initialized XmppClient!"); | ||||
return; | return; | ||||
} | } | ||||
g_XmppClient->SendIqChangeStateGame(utf8_from_wstring(nbp), utf8_from_wstring(players)); | g_XmppClient->SendIqChangeStateGame(utf8_from_wstring(nbp), utf8_from_wstring(players)); | ||||
} | } | ||||
JS::Value JSI_Lobby::GetPlayerList(ScriptInterface::CxPrivate* pCxPrivate) | JS::Value JSI_Lobby::GetPlayerList(ScriptInterface::CmptPrivate* pCmptPrivate) | ||||
{ | { | ||||
ScriptInterface::Request rq(pCxPrivate); | ScriptInterface::Request rq(pCmptPrivate); | ||||
if (!g_XmppClient) | if (!g_XmppClient) | ||||
{ | { | ||||
JS_ReportError(rq.cx, "Cannot call GetPlayerList without an initialized XmppClient!"); | JS_ReportError(rq.cx, "Cannot call GetPlayerList without an initialized XmppClient!"); | ||||
return JS::UndefinedValue(); | return JS::UndefinedValue(); | ||||
} | } | ||||
JS::RootedValue playerList(rq.cx); | JS::RootedValue playerList(rq.cx); | ||||
g_XmppClient->GUIGetPlayerList(*(pCxPrivate->pScriptInterface), &playerList); | g_XmppClient->GUIGetPlayerList(*(pCmptPrivate->pScriptInterface), &playerList); | ||||
return playerList; | return playerList; | ||||
} | } | ||||
JS::Value JSI_Lobby::GetGameList(ScriptInterface::CxPrivate* pCxPrivate) | JS::Value JSI_Lobby::GetGameList(ScriptInterface::CmptPrivate* pCmptPrivate) | ||||
{ | { | ||||
ScriptInterface::Request rq(pCxPrivate); | ScriptInterface::Request rq(pCmptPrivate); | ||||
if (!g_XmppClient) | if (!g_XmppClient) | ||||
{ | { | ||||
JS_ReportError(rq.cx, "Cannot call GetGameList without an initialized XmppClient!"); | JS_ReportError(rq.cx, "Cannot call GetGameList without an initialized XmppClient!"); | ||||
return JS::UndefinedValue(); | return JS::UndefinedValue(); | ||||
} | } | ||||
JS::RootedValue gameList(rq.cx); | JS::RootedValue gameList(rq.cx); | ||||
g_XmppClient->GUIGetGameList(*(pCxPrivate->pScriptInterface), &gameList); | g_XmppClient->GUIGetGameList(*(pCmptPrivate->pScriptInterface), &gameList); | ||||
return gameList; | return gameList; | ||||
} | } | ||||
JS::Value JSI_Lobby::GetBoardList(ScriptInterface::CxPrivate* pCxPrivate) | JS::Value JSI_Lobby::GetBoardList(ScriptInterface::CmptPrivate* pCmptPrivate) | ||||
{ | { | ||||
ScriptInterface::Request rq(pCxPrivate); | ScriptInterface::Request rq(pCmptPrivate); | ||||
if (!g_XmppClient) | if (!g_XmppClient) | ||||
{ | { | ||||
JS_ReportError(rq.cx, "Cannot call GetBoardList without an initialized XmppClient!"); | JS_ReportError(rq.cx, "Cannot call GetBoardList without an initialized XmppClient!"); | ||||
return JS::UndefinedValue(); | return JS::UndefinedValue(); | ||||
} | } | ||||
JS::RootedValue boardList(rq.cx); | JS::RootedValue boardList(rq.cx); | ||||
g_XmppClient->GUIGetBoardList(*(pCxPrivate->pScriptInterface), &boardList); | g_XmppClient->GUIGetBoardList(*(pCmptPrivate->pScriptInterface), &boardList); | ||||
return boardList; | return boardList; | ||||
} | } | ||||
JS::Value JSI_Lobby::GetProfile(ScriptInterface::CxPrivate* pCxPrivate) | JS::Value JSI_Lobby::GetProfile(ScriptInterface::CmptPrivate* pCmptPrivate) | ||||
{ | { | ||||
ScriptInterface::Request rq(pCxPrivate); | ScriptInterface::Request rq(pCmptPrivate); | ||||
if (!g_XmppClient) | if (!g_XmppClient) | ||||
{ | { | ||||
JS_ReportError(rq.cx, "Cannot call GetProfile without an initialized XmppClient!"); | JS_ReportError(rq.cx, "Cannot call GetProfile without an initialized XmppClient!"); | ||||
return JS::UndefinedValue(); | return JS::UndefinedValue(); | ||||
} | } | ||||
JS::RootedValue profileFetch(rq.cx); | JS::RootedValue profileFetch(rq.cx); | ||||
g_XmppClient->GUIGetProfile(*(pCxPrivate->pScriptInterface), &profileFetch); | g_XmppClient->GUIGetProfile(*(pCmptPrivate->pScriptInterface), &profileFetch); | ||||
return profileFetch; | return profileFetch; | ||||
} | } | ||||
bool JSI_Lobby::LobbyGuiPollHasPlayerListUpdate(ScriptInterface::CxPrivate* pCxPrivate) | bool JSI_Lobby::LobbyGuiPollHasPlayerListUpdate(ScriptInterface::CmptPrivate* pCmptPrivate) | ||||
{ | { | ||||
if (!g_XmppClient) | if (!g_XmppClient) | ||||
{ | { | ||||
ScriptInterface::Request rq(pCxPrivate); | ScriptInterface::Request rq(pCmptPrivate); | ||||
JS_ReportError(rq.cx, "Cannot call LobbyGuiPollHasPlayerListUpdate without an initialized XmppClient!"); | JS_ReportError(rq.cx, "Cannot call LobbyGuiPollHasPlayerListUpdate without an initialized XmppClient!"); | ||||
return false; | return false; | ||||
} | } | ||||
return g_XmppClient->GuiPollHasPlayerListUpdate(); | return g_XmppClient->GuiPollHasPlayerListUpdate(); | ||||
} | } | ||||
JS::Value JSI_Lobby::LobbyGuiPollNewMessages(ScriptInterface::CxPrivate* pCxPrivate) | JS::Value JSI_Lobby::LobbyGuiPollNewMessages(ScriptInterface::CmptPrivate* pCmptPrivate) | ||||
{ | { | ||||
if (!g_XmppClient) | if (!g_XmppClient) | ||||
return JS::UndefinedValue(); | return JS::UndefinedValue(); | ||||
return g_XmppClient->GuiPollNewMessages(*(pCxPrivate->pScriptInterface)); | return g_XmppClient->GuiPollNewMessages(*(pCmptPrivate->pScriptInterface)); | ||||
} | } | ||||
JS::Value JSI_Lobby::LobbyGuiPollHistoricMessages(ScriptInterface::CxPrivate* pCxPrivate) | JS::Value JSI_Lobby::LobbyGuiPollHistoricMessages(ScriptInterface::CmptPrivate* pCmptPrivate) | ||||
{ | { | ||||
if (!g_XmppClient) | if (!g_XmppClient) | ||||
{ | { | ||||
ScriptInterface::Request rq(pCxPrivate); | ScriptInterface::Request rq(pCmptPrivate); | ||||
JS_ReportError(rq.cx, "Cannot call LobbyGuiPollHistoricMessages without an initialized XmppClient!"); | JS_ReportError(rq.cx, "Cannot call LobbyGuiPollHistoricMessages without an initialized XmppClient!"); | ||||
return JS::UndefinedValue(); | return JS::UndefinedValue(); | ||||
} | } | ||||
return g_XmppClient->GuiPollHistoricMessages(*(pCxPrivate->pScriptInterface)); | return g_XmppClient->GuiPollHistoricMessages(*(pCmptPrivate->pScriptInterface)); | ||||
} | } | ||||
void JSI_Lobby::LobbySendMessage(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& message) | void JSI_Lobby::LobbySendMessage(ScriptInterface::CmptPrivate* pCmptPrivate, const std::wstring& message) | ||||
{ | { | ||||
if (!g_XmppClient) | if (!g_XmppClient) | ||||
{ | { | ||||
ScriptInterface::Request rq(pCxPrivate); | ScriptInterface::Request rq(pCmptPrivate); | ||||
JS_ReportError(rq.cx, "Cannot call LobbySendMessage without an initialized XmppClient!"); | JS_ReportError(rq.cx, "Cannot call LobbySendMessage without an initialized XmppClient!"); | ||||
return; | return; | ||||
} | } | ||||
g_XmppClient->SendMUCMessage(utf8_from_wstring(message)); | g_XmppClient->SendMUCMessage(utf8_from_wstring(message)); | ||||
} | } | ||||
void JSI_Lobby::LobbySetPlayerPresence(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& presence) | void JSI_Lobby::LobbySetPlayerPresence(ScriptInterface::CmptPrivate* pCmptPrivate, const std::wstring& presence) | ||||
{ | { | ||||
if (!g_XmppClient) | if (!g_XmppClient) | ||||
{ | { | ||||
ScriptInterface::Request rq(pCxPrivate); | ScriptInterface::Request rq(pCmptPrivate); | ||||
JS_ReportError(rq.cx, "Cannot call LobbySetPlayerPresence without an initialized XmppClient!"); | JS_ReportError(rq.cx, "Cannot call LobbySetPlayerPresence without an initialized XmppClient!"); | ||||
return; | return; | ||||
} | } | ||||
g_XmppClient->SetPresence(utf8_from_wstring(presence)); | g_XmppClient->SetPresence(utf8_from_wstring(presence)); | ||||
} | } | ||||
void JSI_Lobby::LobbySetNick(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& nick) | void JSI_Lobby::LobbySetNick(ScriptInterface::CmptPrivate* pCmptPrivate, const std::wstring& nick) | ||||
{ | { | ||||
if (!g_XmppClient) | if (!g_XmppClient) | ||||
{ | { | ||||
ScriptInterface::Request rq(pCxPrivate); | ScriptInterface::Request rq(pCmptPrivate); | ||||
JS_ReportError(rq.cx, "Cannot call LobbySetNick without an initialized XmppClient!"); | JS_ReportError(rq.cx, "Cannot call LobbySetNick without an initialized XmppClient!"); | ||||
return; | return; | ||||
} | } | ||||
g_XmppClient->SetNick(utf8_from_wstring(nick)); | g_XmppClient->SetNick(utf8_from_wstring(nick)); | ||||
} | } | ||||
std::wstring JSI_Lobby::LobbyGetNick(ScriptInterface::CxPrivate* pCxPrivate) | std::wstring JSI_Lobby::LobbyGetNick(ScriptInterface::CmptPrivate* pCmptPrivate) | ||||
{ | { | ||||
if (!g_XmppClient) | if (!g_XmppClient) | ||||
{ | { | ||||
ScriptInterface::Request rq(pCxPrivate); | ScriptInterface::Request rq(pCmptPrivate); | ||||
JS_ReportError(rq.cx, "Cannot call LobbyGetNick without an initialized XmppClient!"); | JS_ReportError(rq.cx, "Cannot call LobbyGetNick without an initialized XmppClient!"); | ||||
return std::wstring(); | return std::wstring(); | ||||
} | } | ||||
std::string nick; | std::string nick; | ||||
g_XmppClient->GetNick(nick); | g_XmppClient->GetNick(nick); | ||||
return wstring_from_utf8(nick); | return wstring_from_utf8(nick); | ||||
} | } | ||||
void JSI_Lobby::LobbyKick(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& nick, const std::wstring& reason) | void JSI_Lobby::LobbyKick(ScriptInterface::CmptPrivate* pCmptPrivate, const std::wstring& nick, const std::wstring& reason) | ||||
{ | { | ||||
if (!g_XmppClient) | if (!g_XmppClient) | ||||
{ | { | ||||
ScriptInterface::Request rq(pCxPrivate); | ScriptInterface::Request rq(pCmptPrivate); | ||||
JS_ReportError(rq.cx, "Cannot call LobbyKick without an initialized XmppClient!"); | JS_ReportError(rq.cx, "Cannot call LobbyKick without an initialized XmppClient!"); | ||||
return; | return; | ||||
} | } | ||||
g_XmppClient->kick(utf8_from_wstring(nick), utf8_from_wstring(reason)); | g_XmppClient->kick(utf8_from_wstring(nick), utf8_from_wstring(reason)); | ||||
} | } | ||||
void JSI_Lobby::LobbyBan(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& nick, const std::wstring& reason) | void JSI_Lobby::LobbyBan(ScriptInterface::CmptPrivate* pCmptPrivate, const std::wstring& nick, const std::wstring& reason) | ||||
{ | { | ||||
if (!g_XmppClient) | if (!g_XmppClient) | ||||
{ | { | ||||
ScriptInterface::Request rq(pCxPrivate); | ScriptInterface::Request rq(pCmptPrivate); | ||||
JS_ReportError(rq.cx, "Cannot call LobbyBan without an initialized XmppClient!"); | JS_ReportError(rq.cx, "Cannot call LobbyBan without an initialized XmppClient!"); | ||||
return; | return; | ||||
} | } | ||||
g_XmppClient->ban(utf8_from_wstring(nick), utf8_from_wstring(reason)); | g_XmppClient->ban(utf8_from_wstring(nick), utf8_from_wstring(reason)); | ||||
} | } | ||||
const char* JSI_Lobby::LobbyGetPlayerPresence(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& nickname) | const char* JSI_Lobby::LobbyGetPlayerPresence(ScriptInterface::CmptPrivate* pCmptPrivate, const std::wstring& nickname) | ||||
{ | { | ||||
if (!g_XmppClient) | if (!g_XmppClient) | ||||
{ | { | ||||
ScriptInterface::Request rq(pCxPrivate); | ScriptInterface::Request rq(pCmptPrivate); | ||||
JS_ReportError(rq.cx, "Cannot call LobbyGetPlayerPresence without an initialized XmppClient!"); | JS_ReportError(rq.cx, "Cannot call LobbyGetPlayerPresence without an initialized XmppClient!"); | ||||
return ""; | return ""; | ||||
} | } | ||||
return g_XmppClient->GetPresence(utf8_from_wstring(nickname)); | return g_XmppClient->GetPresence(utf8_from_wstring(nickname)); | ||||
} | } | ||||
const char* JSI_Lobby::LobbyGetPlayerRole(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& nickname) | const char* JSI_Lobby::LobbyGetPlayerRole(ScriptInterface::CmptPrivate* pCmptPrivate, const std::wstring& nickname) | ||||
{ | { | ||||
if (!g_XmppClient) | if (!g_XmppClient) | ||||
{ | { | ||||
ScriptInterface::Request rq(pCxPrivate); | ScriptInterface::Request rq(pCmptPrivate); | ||||
JS_ReportError(rq.cx, "Cannot call LobbyGetPlayerRole without an initialized XmppClient!"); | JS_ReportError(rq.cx, "Cannot call LobbyGetPlayerRole without an initialized XmppClient!"); | ||||
return ""; | return ""; | ||||
} | } | ||||
return g_XmppClient->GetRole(utf8_from_wstring(nickname)); | return g_XmppClient->GetRole(utf8_from_wstring(nickname)); | ||||
} | } | ||||
std::wstring JSI_Lobby::LobbyGetPlayerRating(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& nickname) | std::wstring JSI_Lobby::LobbyGetPlayerRating(ScriptInterface::CmptPrivate* pCmptPrivate, const std::wstring& nickname) | ||||
{ | { | ||||
if (!g_XmppClient) | if (!g_XmppClient) | ||||
{ | { | ||||
ScriptInterface::Request rq(pCxPrivate); | ScriptInterface::Request rq(pCmptPrivate); | ||||
JS_ReportError(rq.cx, "Cannot call LobbyGetPlayerRating without an initialized XmppClient!"); | JS_ReportError(rq.cx, "Cannot call LobbyGetPlayerRating without an initialized XmppClient!"); | ||||
return std::wstring(); | return std::wstring(); | ||||
} | } | ||||
return g_XmppClient->GetRating(utf8_from_wstring(nickname)); | return g_XmppClient->GetRating(utf8_from_wstring(nickname)); | ||||
} | } | ||||
// Non-public secure PBKDF2 hash function with salting and 1,337 iterations | // Non-public secure PBKDF2 hash function with salting and 1,337 iterations | ||||
Show All 33 Lines | std::string JSI_Lobby::EncryptPassword(const std::string& password, const std::string& username) | ||||
// PBKDF2 to create the buffer | // PBKDF2 to create the buffer | ||||
unsigned char encrypted[DIGESTSIZE]; | unsigned char encrypted[DIGESTSIZE]; | ||||
pbkdf2(encrypted, (unsigned char*)password.c_str(), password.length(), salt_buffer, DIGESTSIZE, ITERATIONS); | pbkdf2(encrypted, (unsigned char*)password.c_str(), password.length(), salt_buffer, DIGESTSIZE, ITERATIONS); | ||||
return CStr(Hexify(encrypted, DIGESTSIZE)).UpperCase(); | return CStr(Hexify(encrypted, DIGESTSIZE)).UpperCase(); | ||||
} | } | ||||
std::wstring JSI_Lobby::EncryptPassword(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::wstring& pass, const std::wstring& user) | std::wstring JSI_Lobby::EncryptPassword(ScriptInterface::CmptPrivate* UNUSED(pCmptPrivate), const std::wstring& pass, const std::wstring& user) | ||||
{ | { | ||||
return wstring_from_utf8(JSI_Lobby::EncryptPassword(utf8_from_wstring(pass), utf8_from_wstring(user))); | return wstring_from_utf8(JSI_Lobby::EncryptPassword(utf8_from_wstring(pass), utf8_from_wstring(user))); | ||||
} | } | ||||
std::wstring JSI_Lobby::LobbyGetRoomSubject(ScriptInterface::CxPrivate* pCxPrivate) | std::wstring JSI_Lobby::LobbyGetRoomSubject(ScriptInterface::CmptPrivate* pCmptPrivate) | ||||
{ | { | ||||
if (!g_XmppClient) | if (!g_XmppClient) | ||||
{ | { | ||||
ScriptInterface::Request rq(pCxPrivate); | ScriptInterface::Request rq(pCmptPrivate); | ||||
JS_ReportError(rq.cx, "Cannot call LobbyGetRoomSubject without an initialized XmppClient!"); | JS_ReportError(rq.cx, "Cannot call LobbyGetRoomSubject without an initialized XmppClient!"); | ||||
return std::wstring(); | return std::wstring(); | ||||
} | } | ||||
return g_XmppClient->GetSubject(); | return g_XmppClient->GetSubject(); | ||||
} | } | ||||
#endif | #endif |
Wildfire Games · Phabricator