|
@@ -128,48 +128,54 @@ void LobbyServer::onPacketReceived(const std::shared_ptr<NetworkConnection> & co
|
|
|
JsonNode json(payloadBegin, message.size());
|
|
|
|
|
|
if (json["type"].String() == "sendChatMessage")
|
|
|
- {
|
|
|
- if (activeAccounts.count(connection) == 0)
|
|
|
- return; // unauthenticated
|
|
|
+ return receiveSendChatMessage(connection, json);
|
|
|
|
|
|
- std::string senderName = activeAccounts[connection].accountName;
|
|
|
- std::string messageText = json["messageText"].String();
|
|
|
+ if (json["type"].String() == "authentication")
|
|
|
+ return receiveAuthentication(connection, json);
|
|
|
+}
|
|
|
|
|
|
- database->insertChatMessage(senderName, messageText);
|
|
|
+void LobbyServer::receiveSendChatMessage(const std::shared_ptr<NetworkConnection> & connection, const JsonNode & json)
|
|
|
+{
|
|
|
+ if (activeAccounts.count(connection) == 0)
|
|
|
+ return; // unauthenticated
|
|
|
|
|
|
- JsonNode reply;
|
|
|
- reply["type"].String() = "chatMessage";
|
|
|
- reply["messageText"].String() = messageText;
|
|
|
- reply["senderName"].String() = senderName;
|
|
|
+ std::string senderName = activeAccounts[connection].accountName;
|
|
|
+ std::string messageText = json["messageText"].String();
|
|
|
|
|
|
- for (auto const & connection : activeAccounts)
|
|
|
- sendMessage(connection.first, reply);
|
|
|
- }
|
|
|
+ database->insertChatMessage(senderName, messageText);
|
|
|
|
|
|
- if (json["type"].String() == "authentication")
|
|
|
- {
|
|
|
- std::string accountName = json["accountName"].String();
|
|
|
+ JsonNode reply;
|
|
|
+ reply["type"].String() = "chatMessage";
|
|
|
+ reply["messageText"].String() = messageText;
|
|
|
+ reply["senderName"].String() = senderName;
|
|
|
+
|
|
|
+ for (auto const & connection : activeAccounts)
|
|
|
+ sendMessage(connection.first, reply);
|
|
|
+}
|
|
|
|
|
|
- activeAccounts[connection].accountName = accountName;
|
|
|
+void LobbyServer::receiveAuthentication(const std::shared_ptr<NetworkConnection> & connection, const JsonNode & json)
|
|
|
+{
|
|
|
+ std::string accountName = json["accountName"].String();
|
|
|
|
|
|
- auto history = database->getRecentMessageHistory();
|
|
|
+ activeAccounts[connection].accountName = accountName;
|
|
|
|
|
|
- JsonNode json;
|
|
|
- json["type"].String() = "chatHistory";
|
|
|
+ auto history = database->getRecentMessageHistory();
|
|
|
|
|
|
- for (auto const & message : boost::adaptors::reverse(history))
|
|
|
- {
|
|
|
- JsonNode jsonEntry;
|
|
|
+ JsonNode reply;
|
|
|
+ reply["type"].String() = "chatHistory";
|
|
|
|
|
|
- jsonEntry["messageText"].String() = message.messageText;
|
|
|
- jsonEntry["senderName"].String() = message.sender;
|
|
|
- jsonEntry["ageSeconds"].Integer() = message.messageAgeSeconds;
|
|
|
+ for (auto const & message : boost::adaptors::reverse(history))
|
|
|
+ {
|
|
|
+ JsonNode jsonEntry;
|
|
|
|
|
|
- json["messages"].Vector().push_back(jsonEntry);
|
|
|
- }
|
|
|
+ jsonEntry["messageText"].String() = message.messageText;
|
|
|
+ jsonEntry["senderName"].String() = message.sender;
|
|
|
+ jsonEntry["ageSeconds"].Integer() = message.messageAgeSeconds;
|
|
|
|
|
|
- sendMessage(connection, json);
|
|
|
+ reply["messages"].Vector().push_back(jsonEntry);
|
|
|
}
|
|
|
+
|
|
|
+ sendMessage(connection, reply);
|
|
|
}
|
|
|
|
|
|
LobbyServer::LobbyServer()
|