Magic World game server
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
1.9 KiB

5 years ago
  1. #include <Ice/Ice.h>
  2. #include <MWSessionManagerI.h>
  3. // #include <PollingChatSessionFactoryI.h>
  4. using namespace std;
  5. class MWServer : public Ice::Service
  6. {
  7. public:
  8. virtual bool start(int argc, char* argv[], int&) override;
  9. virtual bool stop() override;
  10. private:
  11. shared_ptr<Ice::ObjectAdapter> _adapter;
  12. };
  13. bool
  14. MWServer::start(int, char*[], int& status)
  15. {
  16. // int timeout = communicator()->getProperties()->getPropertyAsIntWithDefault("PollingChatSessionTimeout", 10);
  17. bool traceEnabled = communicator()->getProperties()->getPropertyAsIntWithDefault("Server.Trace", 0) != 0;
  18. auto logger = communicator()->getLogger();
  19. try
  20. {
  21. _adapter = communicator()->createObjectAdapter("MWServer");
  22. auto mwmap = make_shared<MWMap>(traceEnabled, logger);
  23. if(traceEnabled)
  24. {
  25. Ice::Trace out(logger, "info");
  26. out << "MW room created ok.";
  27. }
  28. _adapter->add(make_shared<MWSessionManagerI>(mwmap, traceEnabled, logger),
  29. Ice::stringToIdentity("MWSessionManager"));
  30. if(traceEnabled)
  31. {
  32. Ice::Trace out(logger, "info");
  33. out << "MW session manager created ok.";
  34. }
  35. // _adapter->add(make_shared<PollingChatSessionFactoryI>(chatRoom, timeout, traceEnabled, logger),
  36. // Ice::stringToIdentity("PollingChatSessionFactory"));
  37. // if(traceEnabled)
  38. // {
  39. // Ice::Trace out(logger, "info");
  40. // out << "Polling chat session factory created ok.";
  41. // }
  42. _adapter->activate();
  43. if(traceEnabled)
  44. {
  45. Ice::Trace out(logger, "info");
  46. out << "MW server started ok.";
  47. }
  48. }
  49. catch(const Ice::LocalException&)
  50. {
  51. status = 1;
  52. throw;
  53. }
  54. status = 0;
  55. return true;
  56. }
  57. bool
  58. MWServer::stop()
  59. {
  60. return true;
  61. }
  62. int
  63. main(int argc, char* argv[])
  64. {
  65. #ifdef ICE_STATIC_LIBS
  66. Ice::registerIceSSL();
  67. Ice::registerIceWS();
  68. #endif
  69. MWServer app;
  70. return app.main(argc, argv);
  71. }