/
gsdk.h
150 lines (121 loc) · 7.17 KB
/
gsdk.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
// Copyright (C) Microsoft Corporation. All rights reserved.
#pragma once
#include <string>
#include <unordered_map>
#include <functional>
#include <exception>
#include <vector>
namespace Microsoft
{
namespace Azure
{
namespace Gaming
{
class ConnectedPlayer // need to link this to the C# version
{
public:
std::string m_playerId;
ConnectedPlayer(std::string playerId)
{
m_playerId = playerId;
}
};
/// <summary>
/// A class that captures details about a game server port.
/// </summary>
class GamePort
{
public:
/// <summary>
/// The friendly name / identifier for the port, specified by the game developer in the Build configuration.
/// </summary>
std::string m_name;
/// <summary>
/// The port at which the game server should listen on (maps externally to <see cref="m_clientConnectionPort" />).
/// For process based servers, this is determined by Control Plane, based on the ports available on the VM.
/// For containers, this is specified by the game developer in the Build configuration.
/// </summary>
int m_serverListeningPort;
/// <summary>
/// The public port to which clients should connect (maps internally to <see cref="m_serverListeningPort" />).
/// </summary>
int m_clientConnectionPort;
GamePort() {}
GamePort(std::string name, int serverListeningPort, int clientConnectionPort)
{
m_name = name;
m_serverListeningPort = serverListeningPort;
m_clientConnectionPort = clientConnectionPort;
}
};
class GameServerConnectionInfo
{
public:
std::string m_publicIpV4Address;
std::vector<GamePort> m_gamePortsConfiguration;
GameServerConnectionInfo() {}
GameServerConnectionInfo(std::string publicIpV4Address, std::vector<GamePort> gamePortsConfiguration)
{
m_publicIpV4Address = publicIpV4Address;
m_gamePortsConfiguration = gamePortsConfiguration;
}
};
class GSDKInitializationException : public std::runtime_error
{
using std::runtime_error::runtime_error;
};
class GSDK
{
public:
/// <summary>Renamed from WaitForSessionAssignment. Called when the game server is ready to accept clients. If Start() hasn't been called by this point, it will be called implicitly here.</summary>
/// <remarks>Required. This is a blocking call and will only return when this server is either allocated (a player is about to connect) or terminated.</remarks>
/// <returns>True if the server is allocated (will receive players shortly). False if the server is terminated. </returns>
static bool readyForPlayers();
/// <summary>
/// Gets information (ipAddress and ports) for connecting to the game server, as well as the ports the
/// game server should listen on.
/// </summary>
/// <returns></returns>
static const GameServerConnectionInfo &getGameServerConnectionInfo();
/// <summary>Returns all configuration settings</summary>
/// <returns>unordered map of string key:value configuration setting values</returns>
static const std::unordered_map<std::string, std::string> getConfigSettings();
/// <summary>Kicks off communication threads, heartbeats, etc. Called implicitly by ReadyForPlayers if not called beforehand.</summary>
/// <param name="debugLogs">Enables outputting additional logs to the GSDK log file.</param>
static void start(bool debugLogs = false);
/// <summary>Tells the Xcloud service information on who is connected.</summary>
/// <param name="currentlyConnectedPlayers"></param>
static void updateConnectedPlayers(const std::vector<ConnectedPlayer> ¤tlyConnectedPlayers);
/// <summary>Gets called if the server is shutting us down</summary>
static void registerShutdownCallback(std::function<void()> callback);
/// <summary>Gets called when the agent needs to check on the game's health</summary>
static void registerHealthCallback(std::function<bool()> callback);
/// <summary>Gets called if the server is getting a scheduled maintenance, it will get the UTC time of the maintenance event as an argument.</summary>
static void registerMaintenanceCallback(std::function<void(const tm &)> callback);
/// <summary>outputs a message to the log</summary>
static unsigned int logMessage(const std::string &message);
/// <summary>Returns a path to the directory where logs will be mapped to the VM host</summary>
static const std::string getLogsDirectory();
/// <summary>Returns a path to the directory shared by all game servers to cache data.</summary>
static const std::string getSharedContentDirectory();
/// <summary>After allocation, returns a list of the initial players that have access to this game server, used by PlayFab's Matchmaking offering</summary>
static const std::vector<std::string> &getInitialPlayers();
// Keys for the map returned by getConfigSettings
static constexpr const char* HEARTBEAT_ENDPOINT_KEY = "gsmsBaseUrl";
static constexpr const char* SERVER_ID_KEY = "instanceId";
static constexpr const char* LOG_FOLDER_KEY = "logFolder";
static constexpr const char* SHARED_CONTENT_FOLDER_KEY = "sharedContentFolder";
static constexpr const char* CERTIFICATE_FOLDER_KEY = "certificateFolder";
static constexpr const char* TITLE_ID_KEY = "titleId";
static constexpr const char* BUILD_ID_KEY = "buildId";
static constexpr const char* REGION_KEY = "region";
static constexpr const char* VM_ID_KEY = "vmId";
static constexpr const char* PUBLIC_IP_V4_ADDRESS_KEY = "publicIpV4Address";
static constexpr const char* FULLY_QUALIFIED_DOMAIN_NAME_KEY = "fullyQualifiedDomainName";
// These two keys are only available after allocation (once readyForPlayers returns true)
static constexpr const char* SESSION_COOKIE_KEY = "sessionCookie";
static constexpr const char* SESSION_ID_KEY = "sessionId";
};
}
}
}