Lobby2Message_Steam.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 "Lobby2Message_Steam.h"
  11. #include "steam_api.h"
  12. #include "Lobby2Client_Steam_Impl.h"
  13. using namespace RakNet;
  14. bool Client_Login_Steam::ClientImpl( RakNet::Lobby2Plugin *client)
  15. {
  16. (void) client;
  17. if ( !SteamAPI_Init() )
  18. resultCode=L2RC_GENERAL_ERROR;
  19. else
  20. resultCode=L2RC_SUCCESS;
  21. return true; // Done immediately
  22. }
  23. bool Client_Logoff_Steam::ClientImpl( RakNet::Lobby2Plugin *client)
  24. {
  25. Lobby2Client_Steam_Impl *steam = (Lobby2Client_Steam_Impl *)client;
  26. steam->NotifyLeaveRoom();
  27. resultCode=L2RC_SUCCESS;
  28. SteamAPI_Shutdown();
  29. return true; // Done immediately
  30. }
  31. Console_SearchRooms_Steam::Console_SearchRooms_Steam()
  32. {
  33. m_SteamCallResultLobbyMatchList = RakNet::OP_NEW<CCallResult<Lobby2Client_Steam_Impl, LobbyMatchList_t> > (_FILE_AND_LINE_);
  34. }
  35. Console_SearchRooms_Steam::~Console_SearchRooms_Steam()
  36. {
  37. // Cast to make sure destructor gets called
  38. RakNet::OP_DELETE((CCallResult<Lobby2Client_Steam_Impl, LobbyMatchList_t>*)m_SteamCallResultLobbyMatchList, _FILE_AND_LINE_);
  39. }
  40. bool Console_SearchRooms_Steam::ClientImpl( RakNet::Lobby2Plugin *client)
  41. {
  42. (void) client;
  43. requestId = SteamMatchmaking()->RequestLobbyList();
  44. ((CCallResult<Lobby2Client_Steam_Impl, LobbyMatchList_t>*)m_SteamCallResultLobbyMatchList)->Set( requestId, (RakNet::Lobby2Client_Steam_Impl*) client, &Lobby2Client_Steam_Impl::OnLobbyMatchListCallback );
  45. return false; // Asynch
  46. }
  47. void Console_SearchRooms_Steam::DebugMsg(RakNet::RakString &out) const
  48. {
  49. if (resultCode!=L2RC_SUCCESS)
  50. {
  51. Console_SearchRooms::DebugMsg(out);
  52. return;
  53. }
  54. out.Set("%i rooms found", roomNames.GetSize());
  55. for (DataStructures::DefaultIndexType i=0; i < roomNames.GetSize(); i++)
  56. {
  57. out += RakNet::RakString("\n%i. %s. ID=%" PRINTF_64_BIT_MODIFIER "u", i+1, roomNames[i].C_String(), roomIds[i]);
  58. }
  59. }
  60. bool Console_GetRoomDetails_Steam::ClientImpl( RakNet::Lobby2Plugin *client)
  61. {
  62. (void) client;
  63. SteamMatchmaking()->RequestLobbyData( roomId );
  64. return false; // Asynch
  65. }
  66. Console_CreateRoom_Steam::Console_CreateRoom_Steam()
  67. {
  68. m_SteamCallResultLobbyCreated = RakNet::OP_NEW<CCallResult<Lobby2Client_Steam_Impl, LobbyCreated_t> >(_FILE_AND_LINE_);
  69. }
  70. Console_CreateRoom_Steam::~Console_CreateRoom_Steam()
  71. {
  72. // Cast to make sure destructor gets called
  73. RakNet::OP_DELETE((CCallResult<Lobby2Client_Steam_Impl, LobbyCreated_t>*)m_SteamCallResultLobbyCreated, _FILE_AND_LINE_);
  74. }
  75. bool Console_CreateRoom_Steam::ClientImpl( RakNet::Lobby2Plugin *client)
  76. {
  77. if (roomIsPublic)
  78. requestId = SteamMatchmaking()->CreateLobby( k_ELobbyTypePublic, publicSlots );
  79. else
  80. requestId = SteamMatchmaking()->CreateLobby( k_ELobbyTypeFriendsOnly, publicSlots );
  81. // set the function to call when this completes
  82. ((CCallResult<Lobby2Client_Steam_Impl, LobbyCreated_t>*)m_SteamCallResultLobbyCreated)->Set( requestId, (RakNet::Lobby2Client_Steam_Impl*) client, &Lobby2Client_Steam_Impl::OnLobbyCreated );
  83. return false; // Asynch
  84. }
  85. Console_JoinRoom_Steam::Console_JoinRoom_Steam()
  86. {
  87. m_SteamCallResultLobbyEntered = RakNet::OP_NEW<CCallResult<Lobby2Client_Steam_Impl, LobbyEnter_t> > (_FILE_AND_LINE_);
  88. }
  89. Console_JoinRoom_Steam::~Console_JoinRoom_Steam()
  90. {
  91. // Cast to make sure destructor gets called
  92. RakNet::OP_DELETE((CCallResult<Lobby2Client_Steam_Impl, LobbyEnter_t>*)m_SteamCallResultLobbyEntered, _FILE_AND_LINE_);
  93. }
  94. bool Console_JoinRoom_Steam::ClientImpl( RakNet::Lobby2Plugin *client)
  95. {
  96. requestId = SteamMatchmaking()->JoinLobby( roomId );
  97. // set the function to call when this completes
  98. ((CCallResult<Lobby2Client_Steam_Impl, LobbyEnter_t>*)m_SteamCallResultLobbyEntered)->Set( requestId, (RakNet::Lobby2Client_Steam_Impl*) client, &Lobby2Client_Steam_Impl::OnLobbyJoined );
  99. return false; // Asynch
  100. }
  101. bool Console_LeaveRoom_Steam::ClientImpl( RakNet::Lobby2Plugin *client)
  102. {
  103. SteamMatchmaking()->LeaveLobby( roomId );
  104. Lobby2Client_Steam_Impl *steam = (Lobby2Client_Steam_Impl *)client;
  105. steam->NotifyLeaveRoom();
  106. resultCode=L2RC_SUCCESS;
  107. return true; // Synchronous
  108. }
  109. bool Console_SendRoomChatMessage_Steam::ClientImpl( RakNet::Lobby2Plugin *client)
  110. {
  111. (void) client;
  112. SteamMatchmaking()->SendLobbyChatMsg(roomId, message.C_String(), (int) message.GetLength()+1);
  113. // ISteamMatchmaking.h
  114. /*
  115. // Broadcasts a chat message to the all the users in the lobby
  116. // users in the lobby (including the local user) will receive a LobbyChatMsg_t callback
  117. // returns true if the message is successfully sent
  118. // pvMsgBody can be binary or text data, up to 4k
  119. // if pvMsgBody is text, cubMsgBody should be strlen( text ) + 1, to include the null terminator
  120. virtual bool SendLobbyChatMsg( CSteamID steamIDLobby, const void *pvMsgBody, int cubMsgBody ) = 0;
  121. */
  122. resultCode=L2RC_SUCCESS;
  123. return true; // Synchronous
  124. }
粤ICP备19079148号