Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/lobby/scripting/JSInterface_Lobby.cpp
Show First 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | #if CONFIG2_LOBBY // Allow the lobby to be disabled | ||||
scriptInterface.RegisterFunction<JS::Value, &JSI_Lobby::LobbyGuiPollHistoricMessages>("LobbyGuiPollHistoricMessages"); | scriptInterface.RegisterFunction<JS::Value, &JSI_Lobby::LobbyGuiPollHistoricMessages>("LobbyGuiPollHistoricMessages"); | ||||
scriptInterface.RegisterFunction<bool, &JSI_Lobby::LobbyGuiPollHasPlayerListUpdate>("LobbyGuiPollHasPlayerListUpdate"); | scriptInterface.RegisterFunction<bool, &JSI_Lobby::LobbyGuiPollHasPlayerListUpdate>("LobbyGuiPollHasPlayerListUpdate"); | ||||
scriptInterface.RegisterFunction<void, std::wstring, &JSI_Lobby::LobbySendMessage>("LobbySendMessage"); | scriptInterface.RegisterFunction<void, std::wstring, &JSI_Lobby::LobbySendMessage>("LobbySendMessage"); | ||||
scriptInterface.RegisterFunction<void, std::wstring, &JSI_Lobby::LobbySetPlayerPresence>("LobbySetPlayerPresence"); | scriptInterface.RegisterFunction<void, std::wstring, &JSI_Lobby::LobbySetPlayerPresence>("LobbySetPlayerPresence"); | ||||
scriptInterface.RegisterFunction<void, std::wstring, &JSI_Lobby::LobbySetNick>("LobbySetNick"); | scriptInterface.RegisterFunction<void, std::wstring, &JSI_Lobby::LobbySetNick>("LobbySetNick"); | ||||
scriptInterface.RegisterFunction<std::wstring, &JSI_Lobby::LobbyGetNick>("LobbyGetNick"); | scriptInterface.RegisterFunction<std::wstring, &JSI_Lobby::LobbyGetNick>("LobbyGetNick"); | ||||
scriptInterface.RegisterFunction<void, std::wstring, std::wstring, &JSI_Lobby::LobbyKick>("LobbyKick"); | scriptInterface.RegisterFunction<void, std::wstring, std::wstring, &JSI_Lobby::LobbyKick>("LobbyKick"); | ||||
scriptInterface.RegisterFunction<void, std::wstring, std::wstring, &JSI_Lobby::LobbyBan>("LobbyBan"); | scriptInterface.RegisterFunction<void, std::wstring, std::wstring, &JSI_Lobby::LobbyBan>("LobbyBan"); | ||||
scriptInterface.RegisterFunction<std::wstring, std::wstring, &JSI_Lobby::LobbyGetPlayerPresence>("LobbyGetPlayerPresence"); | scriptInterface.RegisterFunction<const char*, std::wstring, &JSI_Lobby::LobbyGetPlayerPresence>("LobbyGetPlayerPresence"); | ||||
scriptInterface.RegisterFunction<std::wstring, std::wstring, &JSI_Lobby::LobbyGetPlayerRole>("LobbyGetPlayerRole"); | scriptInterface.RegisterFunction<const char*, std::wstring, &JSI_Lobby::LobbyGetPlayerRole>("LobbyGetPlayerRole"); | ||||
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::CxPrivate* UNUSED(pCxPrivate)) | ||||
{ | { | ||||
return g_XmppClient; | return g_XmppClient; | ||||
▲ Show 20 Lines • Show All 226 Lines • ▼ Show 20 Lines | |||||
void JSI_Lobby::LobbyBan(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::wstring& nick, const std::wstring& reason) | void JSI_Lobby::LobbyBan(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::wstring& nick, const std::wstring& reason) | ||||
{ | { | ||||
if (!g_XmppClient) | if (!g_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)); | ||||
} | } | ||||
std::wstring JSI_Lobby::LobbyGetPlayerPresence(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::wstring& nickname) | const char* JSI_Lobby::LobbyGetPlayerPresence(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::wstring& nickname) | ||||
{ | { | ||||
if (!g_XmppClient) | if (!g_XmppClient) | ||||
return L""; | return ""; | ||||
std::string presence; | return g_XmppClient->GetPresence(utf8_from_wstring(nickname)); | ||||
g_XmppClient->GetPresence(utf8_from_wstring(nickname), presence); | |||||
return wstring_from_utf8(presence); | |||||
} | } | ||||
std::wstring JSI_Lobby::LobbyGetPlayerRole(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::wstring& nickname) | const char* JSI_Lobby::LobbyGetPlayerRole(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::wstring& nickname) | ||||
{ | { | ||||
if (!g_XmppClient) | if (!g_XmppClient) | ||||
return L""; | return ""; | ||||
std::string role; | return g_XmppClient->GetRole(utf8_from_wstring(nickname)); | ||||
g_XmppClient->GetRole(utf8_from_wstring(nickname), role); | |||||
return wstring_from_utf8(role); | |||||
} | } | ||||
// Non-public secure PBKDF2 hash function with salting and 1,337 iterations | // Non-public secure PBKDF2 hash function with salting and 1,337 iterations | ||||
// | // | ||||
// TODO: We should use libsodium's crypto_pwhash instead of this. The first reason is that | // TODO: We should use libsodium's crypto_pwhash instead of this. The first reason is that | ||||
// libsodium doesn't propose a bare PBKDF2 hash in its API and it's too bad to rely on custom | // libsodium doesn't propose a bare PBKDF2 hash in its API and it's too bad to rely on custom | ||||
// code when we have a fully-fledged library available; the second reason is that Argon2 (the | // code when we have a fully-fledged library available; the second reason is that Argon2 (the | ||||
// default algorithm for crypto_pwhash) is better than what we use (and it's the default one | // default algorithm for crypto_pwhash) is better than what we use (and it's the default one | ||||
Show All 38 Lines | 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))); | return wstring_from_utf8(JSI_Lobby::EncryptPassword(utf8_from_wstring(pass), utf8_from_wstring(user))); | ||||
} | } | ||||
std::wstring JSI_Lobby::LobbyGetRoomSubject(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) | std::wstring JSI_Lobby::LobbyGetRoomSubject(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) | ||||
{ | { | ||||
if (!g_XmppClient) | if (!g_XmppClient) | ||||
return L""; | return L""; | ||||
std::string subject; | return g_XmppClient->GetSubject(); | ||||
g_XmppClient->GetSubject(subject); | |||||
return wstring_from_utf8(subject); | |||||
} | } | ||||
#endif | #endif |
Wildfire Games · Phabricator