Lobby2Message_PGSQL_CustomizationExample.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * Copyright (c) 2014, Oculus VR, Inc.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under the BSD-style license found in the
  6. * LICENSE file in the root directory of this source tree. An additional grant
  7. * of patent rights can be found in the PATENTS file in the same directory.
  8. *
  9. */
  10. // You can extend Lobby2 with your own messages, either overriding existing messages
  11. // or adding new ones
  12. // In both cases, you'll need to create a custom class factory to handle this.
  13. #include "Lobby2Message_PGSQL.h"
  14. // --------------------------------------------------------------
  15. // Override an existing message (Platform_Startup) to do user-custom behaviors
  16. // Requires:
  17. // 1. New class factory to create this message, instead of the old one
  18. // --------------------------------------------------------------
  19. namespace RakNet
  20. {
  21. class Platform_Startup_Overridden : public Platform_Startup_PGSQL
  22. {
  23. virtual bool ServerDBImpl( Lobby2ServerCommand *command, void *databaseInterface )
  24. {
  25. printf("Platform_Startup_Overridden");
  26. return false;
  27. }
  28. };
  29. // --------------------------------------------------------------
  30. // Create an entirely new message
  31. // Requires:
  32. // 1. New class factory to create this message, in addition to the old ones
  33. // 2. New custom callback handler to process this message's result
  34. // 3. New enumeration list, which appends your messages to the old list
  35. // --------------------------------------------------------------
  36. // New enumeration list
  37. enum Lobby2MessageID_Custom
  38. {
  39. L2MID_MyCustomMessage=L2MID_COUNT,
  40. };
  41. // Forward declaration(s) of my new message types
  42. struct MyCustomMessage;
  43. // New custom callback handler
  44. struct Lobby2CustomizedHandler : public Lobby2Callbacks
  45. {
  46. virtual void MessageResult(MyCustomMessage *message);
  47. virtual void ExecuteDefaultResult(Lobby2Message *message) {message->DebugPrintf();}
  48. };
  49. // Macro to make things easier, customized for our new callback handler
  50. #define __L2_MSG_MY_CUSTOM_IMPL(__NAME__) \
  51. virtual void CallCallback(Lobby2Callbacks *cb) {((Lobby2CustomizedHandler*)cb)->MessageResult(this);}; \
  52. virtual Lobby2MessageID GetID(void) const {return (Lobby2MessageID) L2MID_##__NAME__;} \
  53. virtual const char* GetName(void) const {return #__NAME__;} \
  54. virtual void DebugMsg(RakNet::RakString &out) const {out.Set(#__NAME__ " result=%s\n", Lobby2ResultCodeDescription::ToEnglish(resultCode));};
  55. // The new message
  56. struct MyCustomMessage : public Lobby2Message
  57. {
  58. __L2_MSG_MY_CUSTOM_IMPL(MyCustomMessage)
  59. virtual bool RequiresAdmin(void) const {return false;}
  60. virtual bool RequiresRankingPermission(void) const {return false;}
  61. virtual bool CancelOnDisconnect(void) const {return true;}
  62. virtual bool RequiresLogin(void) const {return false;}
  63. virtual void Serialize( bool writeToBitstream, bool serializeOutput, RakNet::BitStream *bitStream );
  64. virtual bool PrevalidateInput(void) {return true;}
  65. virtual bool ServerDBImpl( Lobby2ServerCommand *command, void *databaseInterface )
  66. {
  67. printf("MyCustomMessage");
  68. return false;
  69. }
  70. };
  71. // The new class factory
  72. struct Lobby2MessageFactory_Customized : public Lobby2MessageFactory_PGSQL
  73. {
  74. virtual Lobby2Message *Alloc(Lobby2MessageID id)
  75. {
  76. switch (id)
  77. {
  78. case L2MID_Platform_Startup:
  79. return RakNet::OP_NEW<Platform_Startup_Overridden>(__FILE__, __LINE__);
  80. case L2MID_MyCustomMessage:
  81. return RakNet::OP_NEW<MyCustomMessage>(__FILE__, __LINE__);
  82. }
  83. return Lobby2MessageFactory_PGSQL::Alloc(id);
  84. }
  85. };
  86. } // end namespace
粤ICP备19079148号