StovePCMatchmaking(Native dll): stove_pc_matchmaking_sample.h

StovePCMatchmaking(Native dll) 1.0.4.1

- Main Page
- Modules
- Classes
- Files
- Examples

stove_pc_matchmaking_sample.h

Console sample program written using StovePCMatchmaking64.dll.

#include <iostream>
#include <StovePCMatchmakingDefine.h>
#include <StovePCMatchmakingCallback.h>
#include "MetadataHelper.h"
#include <string>
#include <vector>
#include <codecvt>
extern std::wstring myLobby;
// Server connection callbacks
void OnConnect(const StovePCMatchmakingError error)
{
if ( STOVE_PC_MATCHMAKING_NO_ERROR == error. result)
std::wcout << L"- Success" << std::endl;
else
std::wcout << L"- failed, code = " << error.result << std::endl;
}
// Server connection termination callback
void OnDisconnect(const StovePCMatchmakingError error, const StovePCMatchmakingDisconnectCode code)
{
// Disconnect code (see ::StovePCMatchmakingDisconnectCode)
std::wcout << L"- Disconnect code = " << code << std::endl;
}
// Lobby creation callback
void OnCreateLobby(const StovePCMatchmakingError error, const StovePCMatchmakingCreateLobby createLobby)
{
if (STOVE_PC_MATCHMAKING_NO_ERROR == error.result)
std::wcout << L"- Success" << std::endl;
else
std::wcout << L"- failed, code = " << error.result << std::endl;
// Lobby ID you created
std::wcout << L"- Create Lobby = " << createLobby. lobby << std::endl;
}
// Lobby entry callbacks
void OnJoinLobby(const StovePCMatchmakingError error, const StovePCMatchmakingJoinLobby joinLobby)
{
if (STOVE_PC_MATCHMAKING_NO_ERROR == error.result)
std::wcout << L"- Success" << std::endl;
else
std::wcout << L"- failed, code = " << error.result << std::endl;
// Name of the lobby you entered
std::wcout << L"- Join Lobby = " << joinLobby. lobby << std::endl;
std::wcout << "== config ==";
MetadataHelper config(joinLobby. lobbyDataArray, joinLobby. lobbyDataCount); // Convert a lobby data array to a map
for (auto pair : config)
{
std::wcout << pair.first << " : " << pair.second << std::endl;
}
myLobby = joinLobby.lobby;
}
// Lobby settings update callback
void OnUpdateLobbyData(const StovePCMatchmakingError error, const StovePCMatchmakingUpdateLobbyData updateLobbyData)
{
std::wcout << L"update lobby = " << updateLobbyData. lobby // Lobby Name
<< std::endl;
std::wcout << "== config ==";
MetadataHelper config(updateLobbyData. lobbyDataArray, updateLobbyData. lobbyDataCount); // Convert a lobby data array to a map
for (auto pair : config)
{
std::wcout << pair.first << " : " << pair.second << std::endl;
}
}
// Lobby exit callback
void OnLeaveLobby(const StovePCMatchmakingError error, const StovePCMatchmakingLeaveLobby leaveLobby)
{
std::wcout << L"- Leave Lobby = " << leaveLobby. lobby << std::endl;
// Exit code (see ::StovePCMatchmakingResult)
std::wcout << L"leave lobby code = " << error.result << std::endl;
}
// Lobby user entry callback
void OnUserJoin(const StovePCMatchmakingError error, const StovePCMatchmakingUserJoin userJoin)
{
// Name of the lobby you entered
std::wcout << L"user join lobby = " << userJoin. lobby
<< L"UID = " << userJoin. UID // Entered user ID
<< L"nickname = " << userJoin. nickname // Entered user nickname
<< L"affiliation = " << userJoin. affiliation // Entered user rating
<< std::endl;
std::wcout << "== user data ==";
MetadataHelper config(userJoin. userDataArray, userJoin. userDataCount); // Convert an array of user data to a map
for (auto pair : config)
{
std::wcout << pair.first << " : " << pair.second << std::endl;
}
}
// Lobby User State Value Update Callback
void OnUpdateLobbyUser(const StovePCMatchmakingError error, const StovePCMatchmakingUpdateLobbyUser updateLobbyUser)
{
std::wcout << L"update user lobby = " << updateLobbyUser. lobby // Lobby Name
<< L"UID = " << updateLobbyUser. UID // User ID
<< L"nickname = " << updateLobbyUser. nickname // Entered user nickname
<< L"affiliation = " << updateLobbyUser. affiliation // User ratings
<< std::endl;
std::wcout << "== user data ==";
MetadataHelper config(updateLobbyUser. userDataArray, updateLobbyUser. userDataCount); // Convert an array of user data to a map
for (auto pair : config)
{
std::wcout << pair.first << " : " << pair.second << std::endl;
}
}
// Lobby user exit callback
void OnUserLeave(const StovePCMatchmakingError error, const StovePCMatchmakingUserLeave userLeave)
{
std::wcout << L"user leave lobby = " << userLeave. lobby // Exited lobby name
<< L"UID = " << userLeave. UID // Exited user ID
<< L"nickname = " << userLeave. nickname // Exited user nickname
<< L"leave code = " << error.result // Exit code (see ::StovePCMatchmakingResult)
<< std::endl;
}