GlobalLobbyWindow.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * GlobalLobbyWindow.cpp, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #include "StdInc.h"
  11. #include "GlobalLobbyWindow.h"
  12. #include "GlobalLobbyWidget.h"
  13. #include "GlobalLobbyClient.h"
  14. #include "../gui/CGuiHandler.h"
  15. #include "../widgets/TextControls.h"
  16. #include "../CServerHandler.h"
  17. #include "../../lib/MetaString.h"
  18. #include "../../lib/CConfigHandler.h"
  19. GlobalLobbyWindow::GlobalLobbyWindow():
  20. CWindowObject(BORDERED)
  21. {
  22. OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
  23. widget = std::make_shared<GlobalLobbyWidget>(this);
  24. pos = widget->pos;
  25. center();
  26. widget->getAccountNameLabel()->setText(settings["lobby"]["displayName"].String());
  27. }
  28. void GlobalLobbyWindow::doSendChatMessage()
  29. {
  30. std::string messageText = widget->getMessageInput()->getText();
  31. JsonNode toSend;
  32. toSend["type"].String() = "sendChatMessage";
  33. toSend["messageText"].String() = messageText;
  34. CSH->getGlobalLobby().sendMessage(toSend);
  35. widget->getMessageInput()->setText("");
  36. }
  37. void GlobalLobbyWindow::doCreateGameRoom()
  38. {
  39. // TODO:
  40. // start local server and supply our UUID / client credentials to it
  41. // server logs into lobby ( uuid = client, mode = server ). This creates 'room' in mode 'empty'
  42. // server starts accepting connections from players (including host)
  43. // client connects to local server
  44. // client sends createGameRoom query to lobby with own / server UUID and mode 'direct' (non-proxy)
  45. // client requests to change room status to private or public
  46. }
  47. void GlobalLobbyWindow::onGameChatMessage(const std::string & sender, const std::string & message, const std::string & when)
  48. {
  49. MetaString chatMessageFormatted;
  50. chatMessageFormatted.appendRawString("[%s] {%s}: %s\n");
  51. chatMessageFormatted.replaceRawString(when);
  52. chatMessageFormatted.replaceRawString(sender);
  53. chatMessageFormatted.replaceRawString(message);
  54. chatHistory += chatMessageFormatted.toString();
  55. widget->getGameChat()->setText(chatHistory);
  56. }