mirror of
https://github.com/vcmi/vcmi.git
synced 2025-05-13 22:06:58 +02:00
Split method into smaller segments
This commit is contained in:
parent
11c2708d83
commit
ee797cb245
@ -128,7 +128,14 @@ void LobbyServer::onPacketReceived(const std::shared_ptr<NetworkConnection> & co
|
|||||||
JsonNode json(payloadBegin, message.size());
|
JsonNode json(payloadBegin, message.size());
|
||||||
|
|
||||||
if (json["type"].String() == "sendChatMessage")
|
if (json["type"].String() == "sendChatMessage")
|
||||||
{
|
return receiveSendChatMessage(connection, json);
|
||||||
|
|
||||||
|
if (json["type"].String() == "authentication")
|
||||||
|
return receiveAuthentication(connection, json);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LobbyServer::receiveSendChatMessage(const std::shared_ptr<NetworkConnection> & connection, const JsonNode & json)
|
||||||
|
{
|
||||||
if (activeAccounts.count(connection) == 0)
|
if (activeAccounts.count(connection) == 0)
|
||||||
return; // unauthenticated
|
return; // unauthenticated
|
||||||
|
|
||||||
@ -144,18 +151,18 @@ void LobbyServer::onPacketReceived(const std::shared_ptr<NetworkConnection> & co
|
|||||||
|
|
||||||
for (auto const & connection : activeAccounts)
|
for (auto const & connection : activeAccounts)
|
||||||
sendMessage(connection.first, reply);
|
sendMessage(connection.first, reply);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (json["type"].String() == "authentication")
|
void LobbyServer::receiveAuthentication(const std::shared_ptr<NetworkConnection> & connection, const JsonNode & json)
|
||||||
{
|
{
|
||||||
std::string accountName = json["accountName"].String();
|
std::string accountName = json["accountName"].String();
|
||||||
|
|
||||||
activeAccounts[connection].accountName = accountName;
|
activeAccounts[connection].accountName = accountName;
|
||||||
|
|
||||||
auto history = database->getRecentMessageHistory();
|
auto history = database->getRecentMessageHistory();
|
||||||
|
|
||||||
JsonNode json;
|
JsonNode reply;
|
||||||
json["type"].String() = "chatHistory";
|
reply["type"].String() = "chatHistory";
|
||||||
|
|
||||||
for (auto const & message : boost::adaptors::reverse(history))
|
for (auto const & message : boost::adaptors::reverse(history))
|
||||||
{
|
{
|
||||||
@ -165,11 +172,10 @@ void LobbyServer::onPacketReceived(const std::shared_ptr<NetworkConnection> & co
|
|||||||
jsonEntry["senderName"].String() = message.sender;
|
jsonEntry["senderName"].String() = message.sender;
|
||||||
jsonEntry["ageSeconds"].Integer() = message.messageAgeSeconds;
|
jsonEntry["ageSeconds"].Integer() = message.messageAgeSeconds;
|
||||||
|
|
||||||
json["messages"].Vector().push_back(jsonEntry);
|
reply["messages"].Vector().push_back(jsonEntry);
|
||||||
}
|
}
|
||||||
|
|
||||||
sendMessage(connection, json);
|
sendMessage(connection, reply);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LobbyServer::LobbyServer()
|
LobbyServer::LobbyServer()
|
||||||
|
@ -59,6 +59,9 @@ class LobbyServer : public INetworkServerListener
|
|||||||
void onTimer() override;
|
void onTimer() override;
|
||||||
|
|
||||||
void sendMessage(const std::shared_ptr<NetworkConnection> & target, const JsonNode & json);
|
void sendMessage(const std::shared_ptr<NetworkConnection> & target, const JsonNode & json);
|
||||||
|
|
||||||
|
void receiveSendChatMessage(const std::shared_ptr<NetworkConnection> & connection, const JsonNode & json);
|
||||||
|
void receiveAuthentication(const std::shared_ptr<NetworkConnection> & connection, const JsonNode & json);
|
||||||
public:
|
public:
|
||||||
LobbyServer();
|
LobbyServer();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user