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.

66 lines
1.8 KiB

5 years ago
  1. #include <ChatSessionManagerI.h>
  2. #include <ChatSessionI.h>
  3. #include <ChatUtils.h>
  4. using namespace std;
  5. ChatSessionManagerI::ChatSessionManagerI(const shared_ptr<ChatRoom>& chatRoom, bool trace,
  6. const shared_ptr<Ice::Logger>& logger) :
  7. _chatRoom(chatRoom),
  8. _trace(trace),
  9. _logger(logger)
  10. {
  11. }
  12. shared_ptr<Glacier2::SessionPrx>
  13. ChatSessionManagerI::create(string name,
  14. shared_ptr<Glacier2::SessionControlPrx> sessionControl,
  15. const Ice::Current& current)
  16. {
  17. string vname;
  18. try
  19. {
  20. vname = validateName(name);
  21. _chatRoom->reserve(vname);
  22. }
  23. catch(const exception& ex)
  24. {
  25. if(_trace)
  26. {
  27. Ice::Trace out(_logger, "info");
  28. out << "Cannot create push session:\n" << ex;
  29. }
  30. throw Glacier2::CannotCreateSessionException(ex.what());
  31. }
  32. shared_ptr<Glacier2::SessionPrx> proxy;
  33. try
  34. {
  35. auto session = make_shared<ChatSessionI>(_chatRoom, vname, _trace, _logger);
  36. proxy = Ice::uncheckedCast<Glacier2::SessionPrx>(current.adapter->addWithUUID(session));
  37. Ice::IdentitySeq ids;
  38. ids.push_back(proxy->ice_getIdentity());
  39. sessionControl->identities()->add(ids);
  40. }
  41. catch(const Ice::LocalException& ex)
  42. {
  43. if(_trace)
  44. {
  45. Ice::Trace out(_logger, "info");
  46. out << "Cannot create push session for user '" << vname << "':\n" << ex;
  47. }
  48. if(proxy)
  49. {
  50. proxy->destroy();
  51. }
  52. throw Glacier2::CannotCreateSessionException("internal server error");
  53. }
  54. if(_trace)
  55. {
  56. Ice::Trace out(_logger, "info");
  57. out << "Push session created for user '" << vname << "'.";
  58. }
  59. return proxy;
  60. }