SocialController.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #include "Base.h"
  2. #include "SocialController.h"
  3. #include "Game.h"
  4. #include "social/ScoreloopSocialSession.h"
  5. #include "social/GooglePlaySocialSession.h"
  6. namespace gameplay
  7. {
  8. SocialController::SocialController()
  9. : _session(NULL)
  10. {
  11. }
  12. SocialController::~SocialController()
  13. {
  14. }
  15. void SocialController::initialize()
  16. {
  17. }
  18. void SocialController::finalize()
  19. {
  20. if (_session)
  21. _session->synchronizeAchievements();
  22. }
  23. void SocialController::pause()
  24. {
  25. if (_session)
  26. _session->synchronizeAchievements();
  27. }
  28. void SocialController::resume()
  29. {
  30. }
  31. void SocialController::update(float elapsedTime)
  32. {
  33. }
  34. bool SocialController::handleEvent(void *event)
  35. {
  36. if (_session)
  37. return _session->handleEvent(event);
  38. return false;
  39. }
  40. void SocialController::authenticate(SocialSessionListener* listener)
  41. {
  42. #ifdef GP_USE_SOCIAL
  43. #if defined(__QNX__)
  44. Properties* socialProperties = Game::getInstance()->getConfig()->getNamespace("social", true);
  45. const char* providerStr = "";
  46. if (socialProperties)
  47. {
  48. providerStr = socialProperties->getString("provider");
  49. }
  50. if (strcmp(providerStr, "Scoreloop") == 0)
  51. {
  52. _session = ScoreloopSocialSession::authenticate(listener, socialProperties);
  53. }
  54. else
  55. {
  56. listener->authenticateEvent(SocialSessionListener::ERROR_INITIALIZATION, NULL);
  57. }
  58. #elif defined(__ANDROID__)
  59. Properties* socialProperties = Game::getInstance()->getConfig()->getNamespace("social", true);
  60. const char* providerStr = "";
  61. if (socialProperties)
  62. {
  63. providerStr = socialProperties->getString("provider");
  64. }
  65. if (strcmp(providerStr, "GooglePlay") == 0)
  66. {
  67. _session = GoogleGamesSocialSession::authenticate(listener, socialProperties);
  68. }
  69. else
  70. {
  71. listener->authenticateEvent(SocialSessionListener::ERROR_INITIALIZATION, NULL);
  72. }
  73. #endif
  74. #endif
  75. }
  76. }