StovePCMatchmaking(Native dll): stove_pc_matchmaking_sample.cpp

StovePCMatchmaking(Native dll) 1.0.4.1

- Main Page
- Modules
- Classes
- Files
- Examples

stove_pc_matchmaking_sample.cpp

Console sample program.
This example program demonstrates, step-by-step, how to use the Matchmaking SDK.

1. Registering callbacks
   - StovePCMatchmaking_Init(initialization function) at any time before or after the call.
2. Initialize the SDK with ::StovePCMatchmaking_Init.
3. StovePCMatchmaking_Connect Connect to the matchmaking server.
4. Create/search/enter/exit a lobby.
5. StovePCMatchmaking_DisconnectTerminate your connection to the matchmaking server.
6. StovePCMatchmaking_UnInitTurn off the SDK.
   Warning
     Matchmaking only works with the Stove PC SDK running.
   #include "stdafx.h"
   #include <memory>
   #include <vector>
   #include "stove_pc_matchmaking_sample.h"
   #include <StovePCMatchmakingSDK.h>
   std::wstring myLobby;
   int main(int argc, char* argv[])
   {
   // Called when an asynchronous API execution returns an error or a failure from the server.
   StovePCMatchmakingCallback callbackFunc = {};
   // Each asynchronous API has a 1:1 matched callback.
   callbackFunc. OnConnect = OnConnect;
   callbackFunc. OnDisconnect = OnDisconnect;
   callbackFunc. OnCreateLobby = OnCreateLobby;
   callbackFunc. OnJoinLobby = OnJoinLobby;
   callbackFunc. OnLeaveLobby = OnLeaveLobby;
   // The notification event callback from the server.
   // A callback to notify the lobby of new user entries
   callbackFunc. OnUserJoin = OnUserJoin;
   // A callback to notify users in the lobby that they are leaving
   callbackFunc. OnUserLeave = OnUserLeave;
   // Callbacks for modifying lobby settings
   callbackFunc. OnUpdateLobbyData = OnUpdateLobbyData;
   // Callbacks for modifying the status of a lobby user (user status: rating, user settings data, etc.)
   callbackFunc. OnUpdateLobbyUser = OnUpdateLobbyUser;
   // 1. Register the callback with the SDK. You can register it independently of the initialization function call.
   StovePCMatchmaking_RegisterCallback(callbackFunc);
   // 2. Initializing the SDK
   StovePCMatchmaking_Init( StovePCMatchmakingLogLevel::STOVE_PC_MATCHMAKING_DEBUG);
   // 3. Connect to the matchmaking server
   std::wstring nickname = L"nick18";
   StovePCMatchmaking_Connect(nickname.c_str());
   short abort = 0;
   while ( !abort )
   {
   std::wstring input;
   std::wcout << L">> ";
   while ( std::getline(std::wcin, input) )
   {
   if (0 == input.compare(L"join"))
   {
   // ::StovePCMatchmaking_JoinRandomLobby has the search criteria fixed with the comparison operator "=".
   // "mode = 1"If you search for the lobby
   std::wstring condition1_key = L"mode"; // Keys to use when searching lobbies
   std::wstring condition1_val = L"1"; // Values to use when searching for lobbies
   std::vector<StovePCMatchmakingMetadata> conds;
   conds.emplace_back( StovePCMatchmakingMetadata{
   const_cast<wchar_t*>(condition1_key.c_str()),
   const_cast<wchar_t*>(condition1_val.c_str())
   });
   // If no lobbies are found, create a lobby with a maximum of 2 people.
   int32_t maxUser = 2;
   // 3. Lobby entries matching search criteria,
   // Automatically join one of the searched lobbies. Automatically create a lobby if none is found.
   StovePCMatchmaking_JoinRandomLobby(conds.data(), conds.size(), maxUser);
   break;
   }
   if (0 == input.compare(L"leave"))
   {
   // 5. Leaving the matchmaking lobby
   StovePCMatchmaking_LeaveLobby(myLobby.c_str());
   break;
   }
   if (0 == input.compare(L"disconnect"))
   {
   // 6. Disconnect from the matchmaking server
   StovePCMatchmaking_Disconnect();
   break;
   }
   else if (0 == input.compare(L""))
   {
   // Gets the callback objects in the queue.
   // StovePCMatchmaking_RunCallback callback objects stored in the queue will not be called until the run.
   StovePCMatchmaking_RunCallback();
   break;
   }
   else if (0 == input.compare(L"quit"))
   {
   // 7. Release SDK resources
   StovePCMatchmaking_UnInit();
   // Exit the console program
   abort = 1;
   break;
   }
   else
   {
   std::wcout << L"Unknown Command." << std::endl;
   break;
   }
   std::wcout << std::endl;
   }
   }
   return 0;
   }