Changeset View
Changeset View
Standalone View
Standalone View
source/lobby/scripting/JSInterface_Lobby.cpp
Show All 20 Lines | |||||
#include "gui/GUIManager.h" | #include "gui/GUIManager.h" | ||||
#include "lib/utf8.h" | #include "lib/utf8.h" | ||||
#include "lobby/IXmppClient.h" | #include "lobby/IXmppClient.h" | ||||
#include "network/NetServer.h" | #include "network/NetServer.h" | ||||
#include "ps/CLogger.h" | #include "ps/CLogger.h" | ||||
#include "ps/CStr.h" | #include "ps/CStr.h" | ||||
#include "ps/Util.h" | #include "ps/Util.h" | ||||
#include "scriptinterface/FunctionWrapper.h" | |||||
#include "scriptinterface/ScriptInterface.h" | #include "scriptinterface/ScriptInterface.h" | ||||
#include "scriptinterface/ScriptVal.h" | #include "scriptinterface/ScriptVal.h" | ||||
#include "third_party/encryption/pkcs5_pbkdf2.h" | #include "third_party/encryption/pkcs5_pbkdf2.h" | ||||
#include <string> | #include <string> | ||||
void JSI_Lobby::RegisterScriptFunctions(const ScriptInterface& scriptInterface) | void JSI_Lobby::RegisterScriptFunctions(const ScriptInterface& scriptInterface) | ||||
{ | { | ||||
#define Register(name) ScriptWrapper::WrapAndRegister<decltype(&JSI_Lobby::name), &JSI_Lobby::name>(scriptInterface, #name) | |||||
// Lobby functions | // Lobby functions | ||||
scriptInterface.RegisterFunction<bool, &JSI_Lobby::HasXmppClient>("HasXmppClient"); | Register(HasXmppClient); | ||||
scriptInterface.RegisterFunction<void, bool, &JSI_Lobby::SetRankedGame>("SetRankedGame"); | Register(SetRankedGame); | ||||
#if CONFIG2_LOBBY // Allow the lobby to be disabled | #if CONFIG2_LOBBY // Allow the lobby to be disabled | ||||
scriptInterface.RegisterFunction<void, std::wstring, std::wstring, std::wstring, std::wstring, int, &JSI_Lobby::StartXmppClient>("StartXmppClient"); | Register(StartXmppClient); | ||||
scriptInterface.RegisterFunction<void, std::wstring, std::wstring, &JSI_Lobby::StartRegisterXmppClient>("StartRegisterXmppClient"); | Register(StartRegisterXmppClient); | ||||
scriptInterface.RegisterFunction<void, &JSI_Lobby::StopXmppClient>("StopXmppClient"); | Register(StopXmppClient); | ||||
scriptInterface.RegisterFunction<void, &JSI_Lobby::ConnectXmppClient>("ConnectXmppClient"); | Register(ConnectXmppClient); | ||||
scriptInterface.RegisterFunction<void, &JSI_Lobby::DisconnectXmppClient>("DisconnectXmppClient"); | Register(DisconnectXmppClient); | ||||
scriptInterface.RegisterFunction<bool, &JSI_Lobby::IsXmppClientConnected>("IsXmppClientConnected"); | Register(IsXmppClientConnected); | ||||
scriptInterface.RegisterFunction<void, &JSI_Lobby::SendGetBoardList>("SendGetBoardList"); | Register(SendGetBoardList); | ||||
scriptInterface.RegisterFunction<void, std::wstring, &JSI_Lobby::SendGetProfile>("SendGetProfile"); | Register(SendGetProfile); | ||||
scriptInterface.RegisterFunction<void, JS::HandleValue, &JSI_Lobby::SendRegisterGame>("SendRegisterGame"); | Register(SendRegisterGame); | ||||
scriptInterface.RegisterFunction<void, JS::HandleValue, &JSI_Lobby::SendGameReport>("SendGameReport"); | Register(SendGameReport); | ||||
scriptInterface.RegisterFunction<void, &JSI_Lobby::SendUnregisterGame>("SendUnregisterGame"); | Register(SendUnregisterGame); | ||||
scriptInterface.RegisterFunction<void, std::wstring, std::wstring, &JSI_Lobby::SendChangeStateGame>("SendChangeStateGame"); | Register(SendChangeStateGame); | ||||
scriptInterface.RegisterFunction<JS::Value, &JSI_Lobby::GetPlayerList>("GetPlayerList"); | Register(GetPlayerList); | ||||
scriptInterface.RegisterFunction<JS::Value, &JSI_Lobby::GetGameList>("GetGameList"); | Register(GetGameList); | ||||
scriptInterface.RegisterFunction<JS::Value, &JSI_Lobby::GetBoardList>("GetBoardList"); | Register(GetBoardList); | ||||
scriptInterface.RegisterFunction<JS::Value, &JSI_Lobby::GetProfile>("GetProfile"); | Register(GetProfile); | ||||
scriptInterface.RegisterFunction<JS::Value, &JSI_Lobby::LobbyGuiPollNewMessages>("LobbyGuiPollNewMessages"); | Register(LobbyGuiPollNewMessages); | ||||
scriptInterface.RegisterFunction<JS::Value, &JSI_Lobby::LobbyGuiPollHistoricMessages>("LobbyGuiPollHistoricMessages"); | Register(LobbyGuiPollHistoricMessages); | ||||
scriptInterface.RegisterFunction<bool, &JSI_Lobby::LobbyGuiPollHasPlayerListUpdate>("LobbyGuiPollHasPlayerListUpdate"); | Register(LobbyGuiPollHasPlayerListUpdate); | ||||
scriptInterface.RegisterFunction<void, std::wstring, &JSI_Lobby::LobbySendMessage>("LobbySendMessage"); | Register(LobbySendMessage); | ||||
scriptInterface.RegisterFunction<void, std::wstring, &JSI_Lobby::LobbySetPlayerPresence>("LobbySetPlayerPresence"); | Register(LobbySetPlayerPresence); | ||||
scriptInterface.RegisterFunction<void, std::wstring, &JSI_Lobby::LobbySetNick>("LobbySetNick"); | Register(LobbySetNick); | ||||
scriptInterface.RegisterFunction<std::wstring, &JSI_Lobby::LobbyGetNick>("LobbyGetNick"); | Register(LobbyGetNick); | ||||
scriptInterface.RegisterFunction<void, std::wstring, std::wstring, &JSI_Lobby::LobbyKick>("LobbyKick"); | Register(LobbyKick); | ||||
scriptInterface.RegisterFunction<void, std::wstring, std::wstring, &JSI_Lobby::LobbyBan>("LobbyBan"); | Register(LobbyBan); | ||||
scriptInterface.RegisterFunction<const char*, std::wstring, &JSI_Lobby::LobbyGetPlayerPresence>("LobbyGetPlayerPresence"); | Register(LobbyGetPlayerPresence); | ||||
scriptInterface.RegisterFunction<const char*, std::wstring, &JSI_Lobby::LobbyGetPlayerRole>("LobbyGetPlayerRole"); | Register(LobbyGetPlayerRole); | ||||
scriptInterface.RegisterFunction<std::wstring, std::wstring, &JSI_Lobby::LobbyGetPlayerRating>("LobbyGetPlayerRating"); | Register(LobbyGetPlayerRating); | ||||
scriptInterface.RegisterFunction<std::wstring, std::wstring, std::wstring, &JSI_Lobby::EncryptPassword>("EncryptPassword"); | Register(EncryptPassword); | ||||
scriptInterface.RegisterFunction<std::wstring, &JSI_Lobby::LobbyGetRoomSubject>("LobbyGetRoomSubject"); | Register(LobbyGetRoomSubject); | ||||
#endif // CONFIG2_LOBBY | #endif // CONFIG2_LOBBY | ||||
#undef Register | |||||
} | } | ||||
bool JSI_Lobby::HasXmppClient(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) | bool JSI_Lobby::HasXmppClient() | ||||
{ | { | ||||
return g_XmppClient; | return g_XmppClient; | ||||
} | } | ||||
void JSI_Lobby::SetRankedGame(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), bool isRanked) | void JSI_Lobby::SetRankedGame(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::CxPrivate* pCxPrivate, const std::wstring& username, const std::wstring& password, const std::wstring& room, const std::wstring& nick, int historyRequestSize) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 434 Lines • ▼ Show 20 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) | |||||
{ | |||||
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::CxPrivate* pCxPrivate) | ||||
{ | { | ||||
if (!g_XmppClient) | if (!g_XmppClient) | ||||
{ | { | ||||
JSContext* cx = pCxPrivate->pScriptInterface->GetContext(); | JSContext* cx = pCxPrivate->pScriptInterface->GetContext(); | ||||
JSAutoRequest rq(cx); | JSAutoRequest rq(cx); | ||||
JS_ReportError(cx, "Cannot call LobbyGetRoomSubject without an initialized XmppClient!"); | JS_ReportError(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