2014-11-16 03:10:24 +01:00
|
|
|
/* Copyright (C) 2014 Wildfire Games.
|
2013-11-16 19:38:40 +01:00
|
|
|
* This file is part of 0 A.D.
|
|
|
|
*
|
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "precompiled.h"
|
|
|
|
|
|
|
|
#include "JSInterface_Lobby.h"
|
|
|
|
|
|
|
|
#include "gui/GUIManager.h"
|
|
|
|
#include "lib/utf8.h"
|
|
|
|
#include "lobby/IXmppClient.h"
|
2014-11-16 03:10:24 +01:00
|
|
|
#include "scriptinterface/ScriptInterface.h"
|
2014-01-17 21:14:41 +01:00
|
|
|
#include "third_party/encryption/pkcs5_pbkdf2.h"
|
|
|
|
#include "third_party/encryption/sha.h"
|
2013-11-16 19:38:40 +01:00
|
|
|
|
2014-11-16 03:10:24 +01:00
|
|
|
void JSI_Lobby::RegisterScriptFunctions(ScriptInterface& scriptInterface)
|
|
|
|
{
|
|
|
|
// Lobby functions
|
|
|
|
scriptInterface.RegisterFunction<bool, &JSI_Lobby::HasXmppClient>("HasXmppClient");
|
|
|
|
scriptInterface.RegisterFunction<bool, &JSI_Lobby::IsRankedGame>("IsRankedGame");
|
|
|
|
scriptInterface.RegisterFunction<void, bool, &JSI_Lobby::SetRankedGame>("SetRankedGame");
|
|
|
|
#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");
|
|
|
|
scriptInterface.RegisterFunction<void, std::wstring, std::wstring, &JSI_Lobby::StartRegisterXmppClient>("StartRegisterXmppClient");
|
|
|
|
scriptInterface.RegisterFunction<void, &JSI_Lobby::StopXmppClient>("StopXmppClient");
|
|
|
|
scriptInterface.RegisterFunction<void, &JSI_Lobby::ConnectXmppClient>("ConnectXmppClient");
|
|
|
|
scriptInterface.RegisterFunction<void, &JSI_Lobby::DisconnectXmppClient>("DisconnectXmppClient");
|
|
|
|
scriptInterface.RegisterFunction<void, &JSI_Lobby::SendGetGameList>("SendGetGameList");
|
|
|
|
scriptInterface.RegisterFunction<void, &JSI_Lobby::SendGetBoardList>("SendGetBoardList");
|
|
|
|
scriptInterface.RegisterFunction<void, &JSI_Lobby::SendGetRatingList>("SendGetRatingList");
|
|
|
|
scriptInterface.RegisterFunction<void, std::wstring, &JSI_Lobby::SendGetProfile>("SendGetProfile");
|
2015-01-24 15:46:52 +01:00
|
|
|
scriptInterface.RegisterFunction<void, JS::HandleValue, &JSI_Lobby::SendRegisterGame>("SendRegisterGame");
|
|
|
|
scriptInterface.RegisterFunction<void, JS::HandleValue, &JSI_Lobby::SendGameReport>("SendGameReport");
|
2014-11-16 03:10:24 +01:00
|
|
|
scriptInterface.RegisterFunction<void, &JSI_Lobby::SendUnregisterGame>("SendUnregisterGame");
|
|
|
|
scriptInterface.RegisterFunction<void, std::wstring, std::wstring, &JSI_Lobby::SendChangeStateGame>("SendChangeStateGame");
|
2015-01-24 15:46:52 +01:00
|
|
|
scriptInterface.RegisterFunction<JS::Value, &JSI_Lobby::GetPlayerList>("GetPlayerList");
|
|
|
|
scriptInterface.RegisterFunction<JS::Value, &JSI_Lobby::GetGameList>("GetGameList");
|
|
|
|
scriptInterface.RegisterFunction<JS::Value, &JSI_Lobby::GetBoardList>("GetBoardList");
|
|
|
|
scriptInterface.RegisterFunction<JS::Value, &JSI_Lobby::GetProfile>("GetProfile");
|
|
|
|
scriptInterface.RegisterFunction<JS::Value, &JSI_Lobby::LobbyGuiPollMessage>("LobbyGuiPollMessage");
|
2014-11-16 03:10:24 +01:00
|
|
|
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::LobbySetNick>("LobbySetNick");
|
|
|
|
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::LobbyBan>("LobbyBan");
|
|
|
|
scriptInterface.RegisterFunction<std::wstring, std::wstring, &JSI_Lobby::LobbyGetPlayerPresence>("LobbyGetPlayerPresence");
|
|
|
|
scriptInterface.RegisterFunction<std::wstring, std::wstring, &JSI_Lobby::LobbyGetPlayerRole>("LobbyGetPlayerRole");
|
|
|
|
scriptInterface.RegisterFunction<std::wstring, std::wstring, std::wstring, &JSI_Lobby::EncryptPassword>("EncryptPassword");
|
|
|
|
scriptInterface.RegisterFunction<std::wstring, &JSI_Lobby::LobbyGetRoomSubject>("LobbyGetRoomSubject");
|
|
|
|
#endif // CONFIG2_LOBBY
|
|
|
|
}
|
2013-11-16 19:38:40 +01:00
|
|
|
|
2014-01-04 11:14:53 +01:00
|
|
|
bool JSI_Lobby::HasXmppClient(ScriptInterface::CxPrivate* UNUSED(pCxPrivate))
|
2013-11-16 19:38:40 +01:00
|
|
|
{
|
|
|
|
return (g_XmppClient ? true : false);
|
|
|
|
}
|
|
|
|
|
2014-04-16 08:03:49 +02:00
|
|
|
bool JSI_Lobby::IsRankedGame(ScriptInterface::CxPrivate* UNUSED(pCxPrivate))
|
|
|
|
{
|
|
|
|
return g_rankedGame;
|
|
|
|
}
|
|
|
|
|
|
|
|
void JSI_Lobby::SetRankedGame(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), bool isRanked)
|
|
|
|
{
|
|
|
|
g_rankedGame = isRanked;
|
|
|
|
}
|
|
|
|
|
2013-11-16 19:38:40 +01:00
|
|
|
#if CONFIG2_LOBBY
|
|
|
|
|
2014-01-26 06:39:55 +01:00
|
|
|
void JSI_Lobby::StartXmppClient(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), std::wstring username, std::wstring password, std::wstring room, std::wstring nick, int historyRequestSize)
|
2013-11-16 19:38:40 +01:00
|
|
|
{
|
|
|
|
ENSURE(!g_XmppClient);
|
|
|
|
|
|
|
|
g_XmppClient = IXmppClient::create(utf8_from_wstring(username), utf8_from_wstring(password),
|
2014-01-26 06:39:55 +01:00
|
|
|
utf8_from_wstring(room), utf8_from_wstring(nick), historyRequestSize);
|
2013-11-16 19:38:40 +01:00
|
|
|
g_rankedGame = true;
|
|
|
|
}
|
|
|
|
|
2014-01-04 11:14:53 +01:00
|
|
|
void JSI_Lobby::StartRegisterXmppClient(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), std::wstring username, std::wstring password)
|
2013-11-16 19:38:40 +01:00
|
|
|
{
|
|
|
|
ENSURE(!g_XmppClient);
|
|
|
|
|
|
|
|
g_XmppClient = IXmppClient::create(utf8_from_wstring(username), utf8_from_wstring(password),
|
2014-03-07 02:52:06 +01:00
|
|
|
"", "", 0, true);
|
2013-11-16 19:38:40 +01:00
|
|
|
}
|
|
|
|
|
2014-01-04 11:14:53 +01:00
|
|
|
void JSI_Lobby::StopXmppClient(ScriptInterface::CxPrivate* UNUSED(pCxPrivate))
|
2013-11-16 19:38:40 +01:00
|
|
|
{
|
|
|
|
ENSURE(g_XmppClient);
|
|
|
|
SAFE_DELETE(g_XmppClient);
|
|
|
|
g_rankedGame = false;
|
|
|
|
}
|
|
|
|
|
2014-01-04 11:14:53 +01:00
|
|
|
void JSI_Lobby::ConnectXmppClient(ScriptInterface::CxPrivate* UNUSED(pCxPrivate))
|
2013-11-16 19:38:40 +01:00
|
|
|
{
|
|
|
|
ENSURE(g_XmppClient);
|
|
|
|
g_XmppClient->connect();
|
|
|
|
}
|
|
|
|
|
2014-01-04 11:14:53 +01:00
|
|
|
void JSI_Lobby::DisconnectXmppClient(ScriptInterface::CxPrivate* UNUSED(pCxPrivate))
|
2013-11-16 19:38:40 +01:00
|
|
|
{
|
|
|
|
ENSURE(g_XmppClient);
|
|
|
|
g_XmppClient->disconnect();
|
|
|
|
}
|
|
|
|
|
2014-01-04 11:14:53 +01:00
|
|
|
void JSI_Lobby::SendGetGameList(ScriptInterface::CxPrivate* UNUSED(pCxPrivate))
|
2013-11-16 19:38:40 +01:00
|
|
|
{
|
|
|
|
if (!g_XmppClient)
|
|
|
|
return;
|
|
|
|
g_XmppClient->SendIqGetGameList();
|
|
|
|
}
|
|
|
|
|
2014-01-04 11:14:53 +01:00
|
|
|
void JSI_Lobby::SendGetBoardList(ScriptInterface::CxPrivate* UNUSED(pCxPrivate))
|
2013-11-16 19:38:40 +01:00
|
|
|
{
|
|
|
|
if (!g_XmppClient)
|
|
|
|
return;
|
|
|
|
g_XmppClient->SendIqGetBoardList();
|
|
|
|
}
|
|
|
|
|
2014-01-24 00:13:13 +01:00
|
|
|
void JSI_Lobby::SendGetRatingList(ScriptInterface::CxPrivate* UNUSED(pCxPrivate))
|
|
|
|
{
|
|
|
|
if (!g_XmppClient)
|
|
|
|
return;
|
|
|
|
g_XmppClient->SendIqGetRatingList();
|
|
|
|
}
|
|
|
|
|
2014-09-20 17:35:26 +02:00
|
|
|
void JSI_Lobby::SendGetProfile(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), std::wstring player)
|
|
|
|
{
|
|
|
|
if (!g_XmppClient)
|
|
|
|
return;
|
|
|
|
g_XmppClient->SendIqGetProfile(utf8_from_wstring(player));
|
|
|
|
}
|
|
|
|
|
2015-01-24 15:46:52 +01:00
|
|
|
void JSI_Lobby::SendGameReport(ScriptInterface::CxPrivate* pCxPrivate, JS::HandleValue data)
|
2013-11-16 19:38:40 +01:00
|
|
|
{
|
|
|
|
if (!g_XmppClient)
|
|
|
|
return;
|
|
|
|
|
2014-01-04 11:14:53 +01:00
|
|
|
g_XmppClient->SendIqGameReport(*(pCxPrivate->pScriptInterface), data);
|
2013-11-16 19:38:40 +01:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:46:52 +01:00
|
|
|
void JSI_Lobby::SendRegisterGame(ScriptInterface::CxPrivate* pCxPrivate, JS::HandleValue data)
|
2013-11-16 19:38:40 +01:00
|
|
|
{
|
|
|
|
if (!g_XmppClient)
|
|
|
|
return;
|
2014-01-04 11:14:53 +01:00
|
|
|
|
|
|
|
g_XmppClient->SendIqRegisterGame(*(pCxPrivate->pScriptInterface), data);
|
2013-11-16 19:38:40 +01:00
|
|
|
}
|
|
|
|
|
2014-01-04 11:14:53 +01:00
|
|
|
void JSI_Lobby::SendUnregisterGame(ScriptInterface::CxPrivate* UNUSED(pCxPrivate))
|
2013-11-16 19:38:40 +01:00
|
|
|
{
|
|
|
|
if (!g_XmppClient)
|
|
|
|
return;
|
|
|
|
g_XmppClient->SendIqUnregisterGame();
|
|
|
|
}
|
|
|
|
|
2014-01-04 11:14:53 +01:00
|
|
|
void JSI_Lobby::SendChangeStateGame(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), std::wstring nbp, std::wstring players)
|
2013-11-16 19:38:40 +01:00
|
|
|
{
|
|
|
|
if (!g_XmppClient)
|
|
|
|
return;
|
|
|
|
g_XmppClient->SendIqChangeStateGame(utf8_from_wstring(nbp), utf8_from_wstring(players));
|
|
|
|
}
|
|
|
|
|
2015-01-24 15:46:52 +01:00
|
|
|
JS::Value JSI_Lobby::GetPlayerList(ScriptInterface::CxPrivate* pCxPrivate)
|
2013-11-16 19:38:40 +01:00
|
|
|
{
|
|
|
|
if (!g_XmppClient)
|
2015-01-24 15:46:52 +01:00
|
|
|
return JS::UndefinedValue();
|
|
|
|
|
|
|
|
JSContext* cx = pCxPrivate->pScriptInterface->GetContext();
|
|
|
|
JSAutoRequest rq(cx);
|
2013-11-16 19:38:40 +01:00
|
|
|
|
2015-01-24 15:46:52 +01:00
|
|
|
JS::RootedValue playerList(cx);
|
|
|
|
g_XmppClient->GUIGetPlayerList(*(pCxPrivate->pScriptInterface), &playerList);
|
2013-11-16 19:38:40 +01:00
|
|
|
|
2015-01-24 15:46:52 +01:00
|
|
|
return playerList;
|
2013-11-16 19:38:40 +01:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:46:52 +01:00
|
|
|
JS::Value JSI_Lobby::GetGameList(ScriptInterface::CxPrivate* pCxPrivate)
|
2013-11-16 19:38:40 +01:00
|
|
|
{
|
|
|
|
if (!g_XmppClient)
|
2015-01-24 15:46:52 +01:00
|
|
|
return JS::UndefinedValue();
|
|
|
|
|
|
|
|
JSContext* cx = pCxPrivate->pScriptInterface->GetContext();
|
|
|
|
JSAutoRequest rq(cx);
|
2013-11-16 19:38:40 +01:00
|
|
|
|
2015-01-24 15:46:52 +01:00
|
|
|
JS::RootedValue gameList(cx);
|
|
|
|
g_XmppClient->GUIGetGameList(*(pCxPrivate->pScriptInterface), &gameList);
|
2013-11-16 19:38:40 +01:00
|
|
|
|
2015-01-24 15:46:52 +01:00
|
|
|
return gameList;
|
2013-11-16 19:38:40 +01:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:46:52 +01:00
|
|
|
JS::Value JSI_Lobby::GetBoardList(ScriptInterface::CxPrivate* pCxPrivate)
|
2013-11-16 19:38:40 +01:00
|
|
|
{
|
|
|
|
if (!g_XmppClient)
|
2015-01-24 15:46:52 +01:00
|
|
|
return JS::UndefinedValue();
|
|
|
|
|
|
|
|
JSContext* cx = pCxPrivate->pScriptInterface->GetContext();
|
|
|
|
JSAutoRequest rq(cx);
|
2013-11-16 19:38:40 +01:00
|
|
|
|
2015-01-24 15:46:52 +01:00
|
|
|
JS::RootedValue boardList(cx);
|
|
|
|
g_XmppClient->GUIGetBoardList(*(pCxPrivate->pScriptInterface), &boardList);
|
2013-11-16 19:38:40 +01:00
|
|
|
|
2015-01-24 15:46:52 +01:00
|
|
|
return boardList;
|
2013-11-16 19:38:40 +01:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:46:52 +01:00
|
|
|
JS::Value JSI_Lobby::GetProfile(ScriptInterface::CxPrivate* pCxPrivate)
|
2014-09-20 17:35:26 +02:00
|
|
|
{
|
|
|
|
if (!g_XmppClient)
|
2015-01-24 15:46:52 +01:00
|
|
|
return JS::UndefinedValue();
|
2014-09-20 17:35:26 +02:00
|
|
|
|
2015-01-24 15:46:52 +01:00
|
|
|
JSContext* cx = pCxPrivate->pScriptInterface->GetContext();
|
|
|
|
JSAutoRequest rq(cx);
|
2014-09-20 17:35:26 +02:00
|
|
|
|
2015-01-24 15:46:52 +01:00
|
|
|
JS::RootedValue profileFetch(cx);
|
|
|
|
g_XmppClient->GUIGetProfile(*(pCxPrivate->pScriptInterface), &profileFetch);
|
|
|
|
|
|
|
|
return profileFetch;
|
2014-09-20 17:35:26 +02:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:46:52 +01:00
|
|
|
JS::Value JSI_Lobby::LobbyGuiPollMessage(ScriptInterface::CxPrivate* pCxPrivate)
|
2013-11-16 19:38:40 +01:00
|
|
|
{
|
|
|
|
if (!g_XmppClient)
|
2015-01-24 15:46:52 +01:00
|
|
|
return JS::UndefinedValue();
|
|
|
|
|
|
|
|
JSContext* cx = pCxPrivate->pScriptInterface->GetContext();
|
|
|
|
JSAutoRequest rq(cx);
|
2014-01-04 11:14:53 +01:00
|
|
|
|
2015-01-24 15:46:52 +01:00
|
|
|
JS::RootedValue poll(cx);
|
|
|
|
g_XmppClient->GuiPollMessage(*(pCxPrivate->pScriptInterface), &poll);
|
2013-11-16 19:38:40 +01:00
|
|
|
|
2015-01-24 15:46:52 +01:00
|
|
|
return poll;
|
2013-11-16 19:38:40 +01:00
|
|
|
}
|
|
|
|
|
2014-01-04 11:14:53 +01:00
|
|
|
void JSI_Lobby::LobbySendMessage(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), std::wstring message)
|
2013-11-16 19:38:40 +01:00
|
|
|
{
|
|
|
|
if (!g_XmppClient)
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_XmppClient->SendMUCMessage(utf8_from_wstring(message));
|
|
|
|
}
|
|
|
|
|
2014-01-04 11:14:53 +01:00
|
|
|
void JSI_Lobby::LobbySetPlayerPresence(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), std::wstring presence)
|
2013-11-16 19:38:40 +01:00
|
|
|
{
|
|
|
|
if (!g_XmppClient)
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_XmppClient->SetPresence(utf8_from_wstring(presence));
|
|
|
|
}
|
|
|
|
|
2014-01-04 11:14:53 +01:00
|
|
|
void JSI_Lobby::LobbySetNick(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), std::wstring nick)
|
2013-11-16 19:38:40 +01:00
|
|
|
{
|
|
|
|
if (!g_XmppClient)
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_XmppClient->SetNick(utf8_from_wstring(nick));
|
|
|
|
}
|
|
|
|
|
2014-01-04 11:14:53 +01:00
|
|
|
std::wstring JSI_Lobby::LobbyGetNick(ScriptInterface::CxPrivate* UNUSED(pCxPrivate))
|
2013-11-16 19:38:40 +01:00
|
|
|
{
|
|
|
|
if (!g_XmppClient)
|
|
|
|
return L"";
|
|
|
|
|
|
|
|
std::string nick;
|
|
|
|
g_XmppClient->GetNick(nick);
|
|
|
|
return wstring_from_utf8(nick);
|
|
|
|
}
|
|
|
|
|
2014-01-04 11:14:53 +01:00
|
|
|
void JSI_Lobby::LobbyKick(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), std::wstring nick, std::wstring reason)
|
2013-11-16 19:38:40 +01:00
|
|
|
{
|
|
|
|
if (!g_XmppClient)
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_XmppClient->kick(utf8_from_wstring(nick), utf8_from_wstring(reason));
|
|
|
|
}
|
|
|
|
|
2014-01-04 11:14:53 +01:00
|
|
|
void JSI_Lobby::LobbyBan(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), std::wstring nick, std::wstring reason)
|
2013-11-16 19:38:40 +01:00
|
|
|
{
|
|
|
|
if (!g_XmppClient)
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_XmppClient->ban(utf8_from_wstring(nick), utf8_from_wstring(reason));
|
|
|
|
}
|
|
|
|
|
2014-01-04 11:14:53 +01:00
|
|
|
std::wstring JSI_Lobby::LobbyGetPlayerPresence(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), std::wstring nickname)
|
2013-11-16 19:38:40 +01:00
|
|
|
{
|
|
|
|
if (!g_XmppClient)
|
|
|
|
return L"";
|
|
|
|
|
|
|
|
std::string presence;
|
|
|
|
g_XmppClient->GetPresence(utf8_from_wstring(nickname), presence);
|
|
|
|
return wstring_from_utf8(presence);
|
|
|
|
}
|
|
|
|
|
2014-04-13 01:40:36 +02:00
|
|
|
std::wstring JSI_Lobby::LobbyGetPlayerRole(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), std::wstring nickname)
|
|
|
|
{
|
|
|
|
if (!g_XmppClient)
|
|
|
|
return L"";
|
|
|
|
|
|
|
|
std::string role;
|
|
|
|
g_XmppClient->GetRole(utf8_from_wstring(nickname), role);
|
|
|
|
return wstring_from_utf8(role);
|
|
|
|
}
|
|
|
|
|
2013-11-16 19:38:40 +01:00
|
|
|
// Non-public secure PBKDF2 hash function with salting and 1,337 iterations
|
|
|
|
std::string JSI_Lobby::EncryptPassword(const std::string& password, const std::string& username)
|
|
|
|
{
|
|
|
|
const int DIGESTSIZE = SHA_DIGEST_SIZE;
|
|
|
|
const int ITERATIONS = 1337;
|
|
|
|
|
2013-12-14 17:22:48 +01:00
|
|
|
static const unsigned char salt_base[DIGESTSIZE] = {
|
2013-11-16 19:38:40 +01:00
|
|
|
244, 243, 249, 244, 32, 33, 34, 35, 10, 11, 12, 13, 14, 15, 16, 17,
|
|
|
|
18, 19, 20, 32, 33, 244, 224, 127, 129, 130, 140, 153, 133, 123, 234, 123 };
|
|
|
|
|
|
|
|
// initialize the salt buffer
|
2013-12-14 17:22:48 +01:00
|
|
|
unsigned char salt_buffer[DIGESTSIZE] = {0};
|
2013-11-16 19:38:40 +01:00
|
|
|
SHA256 hash;
|
|
|
|
hash.update(salt_base, sizeof(salt_base));
|
|
|
|
hash.update(username.c_str(), username.length());
|
|
|
|
hash.finish(salt_buffer);
|
|
|
|
|
|
|
|
// PBKDF2 to create the buffer
|
2013-12-14 17:22:48 +01:00
|
|
|
unsigned char encrypted[DIGESTSIZE];
|
|
|
|
pbkdf2(encrypted, (unsigned char*)password.c_str(), password.length(), salt_buffer, DIGESTSIZE, ITERATIONS);
|
2013-11-16 19:38:40 +01:00
|
|
|
|
|
|
|
static const char base16[] = "0123456789ABCDEF";
|
|
|
|
char hex[2 * DIGESTSIZE];
|
|
|
|
for (int i = 0; i < DIGESTSIZE; ++i)
|
|
|
|
{
|
2014-01-17 21:14:41 +01:00
|
|
|
hex[i*2] = base16[encrypted[i] >> 4]; // 4 high bits
|
|
|
|
hex[i*2 + 1] = base16[encrypted[i] & 0x0F]; // 4 low bits
|
2013-11-16 19:38:40 +01:00
|
|
|
}
|
|
|
|
return std::string(hex, sizeof(hex));
|
|
|
|
}
|
|
|
|
|
2014-01-04 11:14:53 +01:00
|
|
|
std::wstring JSI_Lobby::EncryptPassword(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), std::wstring pass, std::wstring user)
|
2013-11-16 19:38:40 +01:00
|
|
|
{
|
|
|
|
return wstring_from_utf8(JSI_Lobby::EncryptPassword(utf8_from_wstring(pass), utf8_from_wstring(user)));
|
|
|
|
}
|
|
|
|
|
2014-01-24 19:20:15 +01:00
|
|
|
std::wstring JSI_Lobby::LobbyGetRoomSubject(ScriptInterface::CxPrivate* UNUSED(pCxPrivate))
|
|
|
|
{
|
|
|
|
if (!g_XmppClient)
|
|
|
|
return L"";
|
|
|
|
|
|
|
|
std::string subject;
|
|
|
|
g_XmppClient->GetSubject(subject);
|
|
|
|
return wstring_from_utf8(subject);
|
|
|
|
}
|
|
|
|
|
2013-12-14 17:22:48 +01:00
|
|
|
#endif
|