mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
Move account login details from settings to persistent storage, with
separate entries depending on server hostname for more convenient testing
This commit is contained in:
parent
2deca842de
commit
8f0236f046
@ -85,14 +85,9 @@ void GlobalLobbyClient::receiveAccountCreated(const JsonNode & json)
|
||||
throw std::runtime_error("lobby connection finished without active login window!");
|
||||
|
||||
{
|
||||
Settings configID = settings.write["lobby"]["accountID"];
|
||||
configID->String() = json["accountID"].String();
|
||||
|
||||
Settings configName = settings.write["lobby"]["displayName"];
|
||||
configName->String() = json["displayName"].String();
|
||||
|
||||
Settings configCookie = settings.write["lobby"]["accountCookie"];
|
||||
configCookie->String() = json["accountCookie"].String();
|
||||
setAccountID(json["accountID"].String());
|
||||
setAccountDisplayName(json["displayName"].String());
|
||||
setAccountCookie(json["accountCookie"].String());
|
||||
}
|
||||
|
||||
sendClientLogin();
|
||||
@ -105,17 +100,15 @@ void GlobalLobbyClient::receiveOperationFailed(const JsonNode & json)
|
||||
if(loginWindowPtr)
|
||||
loginWindowPtr->onConnectionFailed(json["reason"].String());
|
||||
|
||||
logGlobal->warn("Operation failed! Reason: %s", json["reason"].String());
|
||||
// TODO: handle errors in lobby menu
|
||||
}
|
||||
|
||||
void GlobalLobbyClient::receiveClientLoginSuccess(const JsonNode & json)
|
||||
{
|
||||
{
|
||||
Settings configCookie = settings.write["lobby"]["accountCookie"];
|
||||
configCookie->String() = json["accountCookie"].String();
|
||||
|
||||
Settings configName = settings.write["lobby"]["displayName"];
|
||||
configName->String() = json["displayName"].String();
|
||||
setAccountDisplayName(json["displayName"].String());
|
||||
setAccountCookie(json["accountCookie"].String());
|
||||
}
|
||||
|
||||
auto loginWindowPtr = loginWindow.lock();
|
||||
@ -288,8 +281,8 @@ void GlobalLobbyClient::receiveJoinRoomSuccess(const JsonNode & json)
|
||||
CSH->resetStateForLobby(EStartMode::NEW_GAME, ESelectionScreen::newGame, EServerMode::LOBBY_GUEST, {});
|
||||
CSH->loadMode = ELoadMode::MULTI;
|
||||
|
||||
std::string hostname = settings["lobby"]["hostname"].String();
|
||||
uint16_t port = settings["lobby"]["port"].Integer();
|
||||
std::string hostname = getServerHost();
|
||||
uint16_t port = getServerPort();
|
||||
CSH->connectToServer(hostname, port);
|
||||
}
|
||||
|
||||
@ -324,8 +317,8 @@ void GlobalLobbyClient::sendClientLogin()
|
||||
{
|
||||
JsonNode toSend;
|
||||
toSend["type"].String() = "clientLogin";
|
||||
toSend["accountID"] = settings["lobby"]["accountID"];
|
||||
toSend["accountCookie"] = settings["lobby"]["accountCookie"];
|
||||
toSend["accountID"].String() = getAccountID();
|
||||
toSend["accountCookie"].String() = getAccountCookie();
|
||||
toSend["language"].String() = CGI->generaltexth->getPreferredLanguage();
|
||||
toSend["version"].String() = VCMI_VERSION_STRING;
|
||||
sendMessage(toSend);
|
||||
@ -370,7 +363,7 @@ void GlobalLobbyClient::sendOpenRoom(const std::string & mode, int playerLimit)
|
||||
{
|
||||
JsonNode toSend;
|
||||
toSend["type"].String() = "activateGameRoom";
|
||||
toSend["hostAccountID"] = settings["lobby"]["accountID"];
|
||||
toSend["hostAccountID"].String() = getAccountID();
|
||||
toSend["roomType"].String() = mode;
|
||||
toSend["playerLimit"].Integer() = playerLimit;
|
||||
sendMessage(toSend);
|
||||
@ -378,8 +371,8 @@ void GlobalLobbyClient::sendOpenRoom(const std::string & mode, int playerLimit)
|
||||
|
||||
void GlobalLobbyClient::connect()
|
||||
{
|
||||
std::string hostname = settings["lobby"]["hostname"].String();
|
||||
uint16_t port = settings["lobby"]["port"].Integer();
|
||||
std::string hostname = getServerHost();
|
||||
uint16_t port = getServerPort();
|
||||
CSH->getNetworkHandler().connectToRemote(*this, hostname, port);
|
||||
}
|
||||
|
||||
@ -479,12 +472,55 @@ void GlobalLobbyClient::activateRoomInviteInterface()
|
||||
GH.windows().createAndPushWindow<GlobalLobbyInviteWindow>();
|
||||
}
|
||||
|
||||
void GlobalLobbyClient::setAccountID(const std::string & accountID)
|
||||
{
|
||||
Settings configID = persistentStorage.write["lobby"][getServerHost()]["accountID"];
|
||||
configID->String() = accountID;
|
||||
}
|
||||
|
||||
void GlobalLobbyClient::setAccountCookie(const std::string & accountCookie)
|
||||
{
|
||||
Settings configCookie = persistentStorage.write["lobby"][getServerHost()]["accountCookie"];
|
||||
configCookie->String() = accountCookie;
|
||||
}
|
||||
|
||||
void GlobalLobbyClient::setAccountDisplayName(const std::string & accountDisplayName)
|
||||
{
|
||||
Settings configName = persistentStorage.write["lobby"][getServerHost()]["displayName"];
|
||||
configName->String() = accountDisplayName;
|
||||
}
|
||||
|
||||
const std::string & GlobalLobbyClient::getAccountID() const
|
||||
{
|
||||
return persistentStorage["lobby"][getServerHost()]["accountID"].String();
|
||||
}
|
||||
|
||||
const std::string & GlobalLobbyClient::getAccountCookie() const
|
||||
{
|
||||
return persistentStorage["lobby"][getServerHost()]["accountCookie"].String();
|
||||
}
|
||||
|
||||
const std::string & GlobalLobbyClient::getAccountDisplayName() const
|
||||
{
|
||||
return persistentStorage["lobby"][getServerHost()]["displayName"].String();
|
||||
}
|
||||
|
||||
const std::string & GlobalLobbyClient::getServerHost() const
|
||||
{
|
||||
return settings["lobby"]["hostname"].String();
|
||||
}
|
||||
|
||||
uint16_t GlobalLobbyClient::getServerPort() const
|
||||
{
|
||||
return settings["lobby"]["port"].Integer();
|
||||
}
|
||||
|
||||
void GlobalLobbyClient::sendProxyConnectionLogin(const NetworkConnectionPtr & netConnection)
|
||||
{
|
||||
JsonNode toSend;
|
||||
toSend["type"].String() = "clientProxyLogin";
|
||||
toSend["accountID"] = settings["lobby"]["accountID"];
|
||||
toSend["accountCookie"] = settings["lobby"]["accountCookie"];
|
||||
toSend["accountID"].String() = getAccountID();
|
||||
toSend["accountCookie"].String() = getAccountCookie();
|
||||
toSend["gameRoomID"].String() = currentGameRoomUUID;
|
||||
|
||||
assert(JsonUtils::validate(toSend, "vcmi:lobbyProtocol/" + toSend["type"].String(), toSend["type"].String() + " pack"));
|
||||
@ -510,6 +546,8 @@ void GlobalLobbyClient::sendMatchChatMessage(const std::string & messageText)
|
||||
toSend["channelName"].String() = currentGameRoomUUID;
|
||||
toSend["messageText"].String() = messageText;
|
||||
|
||||
assert(TextOperations::isValidUnicodeString(messageText));
|
||||
|
||||
CSH->getGlobalLobby().sendMessage(toSend);
|
||||
}
|
||||
|
||||
|
@ -58,6 +58,10 @@ class GlobalLobbyClient final : public INetworkClientListener, boost::noncopyabl
|
||||
std::shared_ptr<GlobalLobbyLoginWindow> createLoginWindow();
|
||||
std::shared_ptr<GlobalLobbyWindow> createLobbyWindow();
|
||||
|
||||
void setAccountID(const std::string & accountID);
|
||||
void setAccountCookie(const std::string & accountCookie);
|
||||
void setAccountDisplayName(const std::string & accountDisplayName);
|
||||
|
||||
public:
|
||||
explicit GlobalLobbyClient();
|
||||
~GlobalLobbyClient();
|
||||
@ -68,6 +72,12 @@ public:
|
||||
const std::vector<GlobalLobbyRoom> & getMatchesHistory() const;
|
||||
const std::vector<GlobalLobbyChannelMessage> & getChannelHistory(const std::string & channelType, const std::string & channelName) const;
|
||||
|
||||
const std::string & getAccountID() const;
|
||||
const std::string & getAccountCookie() const;
|
||||
const std::string & getAccountDisplayName() const;
|
||||
const std::string & getServerHost() const;
|
||||
uint16_t getServerPort() const;
|
||||
|
||||
/// Activate interface and pushes lobby UI as top window
|
||||
void activateInterface();
|
||||
void activateRoomInviteInterface();
|
||||
|
@ -272,7 +272,7 @@ GlobalLobbyMatchCard::GlobalLobbyMatchCard(GlobalLobbyWindow * window, const Glo
|
||||
|
||||
if (matchDescription.participants.size() == 2)
|
||||
{
|
||||
std::string ourAccountID = settings["lobby"]["accountID"].String();
|
||||
std::string ourAccountID = CSH->getGlobalLobby().getAccountID();
|
||||
|
||||
opponentDescription.appendTextID("vcmi.lobby.match.duel");
|
||||
// Find display name of our one and only opponent in this game
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "../../lib/CConfigHandler.h"
|
||||
#include "../../lib/Languages.h"
|
||||
#include "../../lib/MetaString.h"
|
||||
#include "../../lib/TextOperations.h"
|
||||
|
||||
GlobalLobbyWindow::GlobalLobbyWindow()
|
||||
: CWindowObject(BORDERED)
|
||||
@ -33,7 +34,7 @@ GlobalLobbyWindow::GlobalLobbyWindow()
|
||||
pos = widget->pos;
|
||||
center();
|
||||
|
||||
widget->getAccountNameLabel()->setText(settings["lobby"]["displayName"].String());
|
||||
widget->getAccountNameLabel()->setText(CSH->getGlobalLobby().getAccountDisplayName());
|
||||
doOpenChannel("global", "english", Languages::getLanguageOptions("english").nameNative);
|
||||
|
||||
widget->getChannelListHeader()->setText(MetaString::createFromTextID("vcmi.lobby.header.channels").toString());
|
||||
@ -54,7 +55,7 @@ void GlobalLobbyWindow::doOpenChannel(const std::string & channelType, const std
|
||||
|
||||
auto history = CSH->getGlobalLobby().getChannelHistory(channelType, channelName);
|
||||
|
||||
for (auto const & entry : history)
|
||||
for(const auto & entry : history)
|
||||
onGameChatMessage(entry.displayName, entry.messageText, entry.timeFormatted, channelType, channelName);
|
||||
|
||||
MetaString text;
|
||||
@ -80,6 +81,8 @@ void GlobalLobbyWindow::doSendChatMessage()
|
||||
toSend["channelName"].String() = currentChannelName;
|
||||
toSend["messageText"].String() = messageText;
|
||||
|
||||
assert(TextOperations::isValidUnicodeString(messageText));
|
||||
|
||||
CSH->getGlobalLobby().sendMessage(toSend);
|
||||
|
||||
widget->getMessageInput()->setText("");
|
||||
|
@ -122,8 +122,8 @@ void GlobalLobbyProcessor::onConnectionEstablished(const std::shared_ptr<INetwor
|
||||
JsonNode toSend;
|
||||
toSend["type"].String() = "serverLogin";
|
||||
toSend["gameRoomID"].String() = owner.uuid;
|
||||
toSend["accountID"] = settings["lobby"]["accountID"];
|
||||
toSend["accountCookie"] = settings["lobby"]["accountCookie"];
|
||||
toSend["accountID"].String() = getHostAccountID();
|
||||
toSend["accountCookie"].String() = getHostAccountCookie();
|
||||
toSend["version"].String() = VCMI_VERSION_STRING;
|
||||
|
||||
sendMessage(connection, toSend);
|
||||
@ -140,7 +140,7 @@ void GlobalLobbyProcessor::onConnectionEstablished(const std::shared_ptr<INetwor
|
||||
toSend["type"].String() = "serverProxyLogin";
|
||||
toSend["gameRoomID"].String() = owner.uuid;
|
||||
toSend["guestAccountID"].String() = guestAccountID;
|
||||
toSend["accountCookie"] = settings["lobby"]["accountCookie"];
|
||||
toSend["accountCookie"].String() = getHostAccountCookie();
|
||||
|
||||
sendMessage(connection, toSend);
|
||||
|
||||
@ -170,3 +170,24 @@ void GlobalLobbyProcessor::sendMessage(const NetworkConnectionPtr & targetConnec
|
||||
assert(JsonUtils::validate(toSend, "vcmi:lobbyProtocol/" + toSend["type"].String(), toSend["type"].String() + " pack"));
|
||||
targetConnection->sendPacket(toSend.toBytes());
|
||||
}
|
||||
|
||||
//FIXME: consider whether these methods should be replaced with some other way to define our account ID / account cookie
|
||||
static const std::string & getServerHost()
|
||||
{
|
||||
return settings["lobby"]["hostname"].String();
|
||||
}
|
||||
|
||||
const std::string & GlobalLobbyProcessor::getHostAccountID() const
|
||||
{
|
||||
return persistentStorage["lobby"][getServerHost()]["accountID"].String();
|
||||
}
|
||||
|
||||
const std::string & GlobalLobbyProcessor::getHostAccountCookie() const
|
||||
{
|
||||
return persistentStorage["lobby"][getServerHost()]["accountCookie"].String();
|
||||
}
|
||||
|
||||
const std::string & GlobalLobbyProcessor::getHostAccountDisplayName() const
|
||||
{
|
||||
return persistentStorage["lobby"][getServerHost()]["displayName"].String();
|
||||
}
|
||||
|
@ -35,6 +35,10 @@ class GlobalLobbyProcessor : public INetworkClientListener
|
||||
|
||||
void establishNewConnection();
|
||||
void sendMessage(const NetworkConnectionPtr & targetConnection, const JsonNode & payload);
|
||||
|
||||
const std::string & getHostAccountID() const;
|
||||
const std::string & getHostAccountCookie() const;
|
||||
const std::string & getHostAccountDisplayName() const;
|
||||
public:
|
||||
void sendChangeRoomDescription(const std::string & description);
|
||||
void sendGameStarted();
|
||||
|
Loading…
Reference in New Issue
Block a user