Lobby2Client.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. #include "Lobby2Client.h"
  11. #include "RakAssert.h"
  12. #include "MessageIdentifiers.h"
  13. using namespace RakNet;
  14. Lobby2Client::Lobby2Client()
  15. {
  16. serverAddress=RakNet::UNASSIGNED_SYSTEM_ADDRESS;
  17. }
  18. Lobby2Client::~Lobby2Client()
  19. {
  20. }
  21. void Lobby2Client::SetServerAddress(SystemAddress addr)
  22. {
  23. serverAddress=addr;
  24. }
  25. SystemAddress Lobby2Client::GetServerAddress(void) const
  26. {
  27. return serverAddress;
  28. }
  29. void Lobby2Client::SendMsg(Lobby2Message *msg)
  30. {
  31. // Callback must be ready to receive reply
  32. RakAssert(callbacks.Size());
  33. msg->resultCode=L2RC_PROCESSING;
  34. RakNet::BitStream bs;
  35. bs.Write((MessageID)ID_LOBBY2_SEND_MESSAGE);
  36. bs.Write((MessageID)msg->GetID());
  37. msg->Serialize(true,false,&bs);
  38. SendUnified(&bs,packetPriority, RELIABLE_ORDERED, orderingChannel, serverAddress, false);
  39. }
  40. void Lobby2Client::SendMsgAndDealloc(Lobby2Message *msg)
  41. {
  42. SendMsg(msg);
  43. msgFactory->Dealloc(msg);
  44. }
  45. PluginReceiveResult Lobby2Client::OnReceive(Packet *packet)
  46. {
  47. RakAssert(packet);
  48. switch (packet->data[0])
  49. {
  50. case ID_LOBBY2_SEND_MESSAGE:
  51. OnMessage(packet);
  52. return RR_STOP_PROCESSING_AND_DEALLOCATE;
  53. }
  54. return RR_CONTINUE_PROCESSING;
  55. }
  56. void Lobby2Client::OnClosedConnection(const SystemAddress &systemAddress, RakNetGUID rakNetGUID, PI2_LostConnectionReason lostConnectionReason )
  57. {
  58. (void)systemAddress;
  59. (void)rakNetGUID;
  60. (void)lostConnectionReason;
  61. // if (systemAddress==serverAddress)
  62. // ClearIgnoreList();
  63. }
  64. void Lobby2Client::OnShutdown(void)
  65. {
  66. // ClearIgnoreList();
  67. }
  68. void Lobby2Client::OnMessage(Packet *packet)
  69. {
  70. RakNet::BitStream bs(packet->data,packet->length,false);
  71. bs.IgnoreBytes(1); // ID_LOBBY2_SEND_MESSAGE
  72. MessageID msgId;
  73. bs.Read(msgId);
  74. Lobby2MessageID lobby2MessageID = (Lobby2MessageID) msgId;
  75. Lobby2Message *lobby2Message = msgFactory->Alloc(lobby2MessageID);
  76. if (lobby2Message)
  77. {
  78. lobby2Message->Serialize(false,true,&bs);
  79. if (lobby2Message->ClientImpl(this))
  80. {
  81. for (unsigned long i=0; i < callbacks.Size(); i++)
  82. {
  83. if (lobby2Message->callbackId==(uint32_t)-1 || lobby2Message->callbackId==callbacks[i]->callbackId)
  84. lobby2Message->CallCallback(callbacks[i]);
  85. }
  86. }
  87. msgFactory->Dealloc(lobby2Message);
  88. }
  89. else
  90. {
  91. RakAssert("Lobby2Client::OnMessage lobby2Message==0" && 0);
  92. }
  93. }
  94. /*
  95. void Lobby2Client::AddToIgnoreList(RakNet::RakString user)
  96. {
  97. ignoreList.Insert(user,user,false);
  98. }
  99. void Lobby2Client::RemoveFromIgnoreList(RakNet::RakString user)
  100. {
  101. ignoreList.RemoveIfExists(user);
  102. }
  103. void Lobby2Client::SetIgnoreList(DataStructures::List<RakNet::RakString> users)
  104. {
  105. for (unsigned int i=0; i < users.Size(); i++)
  106. ignoreList.Insert(users[i],users[i],false);
  107. }
  108. bool Lobby2Client::IsInIgnoreList(RakNet::RakString user) const
  109. {
  110. return ignoreList.HasData(user);
  111. }
  112. void Lobby2Client::ClearIgnoreList(void)
  113. {
  114. ignoreList.Clear(_FILE_AND_LINE_);
  115. }
  116. const DataStructures::OrderedList<RakNet::RakString, RakNet::RakString>* Lobby2Client::GetIgnoreList(void) const
  117. {
  118. return &ignoreList;
  119. }
  120. */
粤ICP备19079148号