private void OnServerActive() { //Fires Start server event so listners can perform startup //playFabServerActiveEvent.Raise(); Debug.Log("Server Started From Agent Activation"); GameserverSDK.LogMessage("GameServer has become active"); }
private void Start() { //Retrieves the EntityToken GetEntityToken(); // Get all the configuration values config = GameserverSDK.getConfigSettings(); Debug.Log("[PlayFabServerInstance] Received PlayFab Config"); connectionInfo = GameserverSDK.GetGameServerConnectionInfo(); //Retrieve a particular configuration value if (config.TryGetValue(GameserverSDK.SessionCookieKey, out string sessionCookie)) { //sessionCookie contains the value } _connectedPlayers = new List <Microsoft.Playfab.Gaming.GSDK.CSharp.ConnectedPlayer>(); // This will add your log line the GSDK log file, alongside other information logged by the GSDK GameserverSDK.LogMessage("[PlayFabServerInstance] GameServer Starting"); Debug.Log("[PlayFabServerInstance] GameServer Starting"); // Alternatively, you can log your own files to the log directory string logFolder = GameserverSDK.GetLogsDirectory(); // Call this while your game is initializing, it will start heartbeating to our agent and put the game server in an Initializing state GameserverSDK.Start(); GameserverSDK.RegisterShutdownCallback(OnShutdown); GameserverSDK.RegisterMaintenanceCallback(OnMaintenanceScheduled); GameserverSDK.RegisterHealthCallback(IsHealthy); /* Add any other initializion code your game server needs before players can connect */ }
private static void LogMessage(string message, bool enableGSDKLogging = true) { Console.WriteLine(message); if (enableGSDKLogging) { GameserverSDK.LogMessage(message); } }
private void OnShutdown() { Debug.Log("[PlayFabServerInstance] Server is Shutting down"); GameserverSDK.LogMessage("Shutting down..."); OnShutDown.Invoke(); StartCoroutine(Shutdown()); }
public void OnPlayerAdded(string playfabId) { if (_connectedPlayers != null) { _connectedPlayers.Add(new ConnectedPlayer(playfabId)); GameserverSDK.UpdateConnectedPlayers(_connectedPlayers); GameserverSDK.LogMessage("GameServer added player: " + playfabId); } }
public void OnPlayerRemoved(string playfabId) { if (_connectedPlayers != null) { ConnectedPlayer player = _connectedPlayers.Find(x => x.PlayerId.Equals(playfabId, StringComparison.OrdinalIgnoreCase)); _connectedPlayers.Remove(player); GameserverSDK.UpdateConnectedPlayers(_connectedPlayers); GameserverSDK.LogMessage("GameServer removed player: " + player.PlayerId); //PlayFabMultiplayerAgentAPI.UpdateConnectedPlayers(_connectedPlayers); } }
// This method will be called in case #3, when Azure will perform maintenance on the virtual machine void OnMaintenanceScheduled(DateTimeOffset time) { /* Perform any necessary cleanup, notify your players, etc. */ Debug.LogFormat("Maintenance Scheduled for: {0}", time.UtcDateTime.ToLongDateString()); GameserverSDK.LogMessage("GameServer Maintenance Scheduled for: " + time.UtcDateTime.ToLongDateString()); //foreach (NetworkConnection conn in manager.Connections) //{ // conn.Send(CustomGameServerMessageTypes.ShutdownMessage, new MaintenanceMessage // { // ScheduledMaintenanceUTC = time.UtcDateTime // }); //} }
private IEnumerator ReadyForPlayers() { yield return(new WaitForSeconds(.5f)); // Call this when your game is done initializing and players can connect // Note: This is a blocking call, and will return when this game server is either allocated or terminated GameserverSDK.ReadyForPlayers(); if (showDebugMessages) { Debug.Log("[PlayFabServerInstance] Ready For Players"); } // Call this when your game is done initializing and players can connect // Note: This is a blocking call, and will return when this game server is either allocated or terminated if (GameserverSDK.ReadyForPlayers()) { // readyForPlayers returns true when an allocation call has been done, a player is about to connect! GameserverSDK.LogMessage("GameServer is ready for players"); } else { // readyForPlayers returns false when the server is being terminated GameserverSDK.LogMessage("GameServer is NOT ready for players"); } }
private static void LogMessage(string message) { Console.WriteLine(message); // This will add your log line to the GSDK log file, alongside other information logged by the GSDK GameserverSDK.LogMessage(message); }
private static void LogMessage(string message) { GameserverSDK.LogMessage(message); Console.WriteLine(message); }
// starts main game process and wait for it to complete public static void InitiateAndWaitForGameProcess(string gameserverExe, IEnumerable <string> args) { // Here we're starting the script that initiates the game process activeConfig = GameserverSDK.getConfigSettings(); // When Wrapper is running in a container, Port Information (Port Name, Port Number, and Protocol) is already set as build configuration. // For example, if you already set port number as 80 in container build configuration, activeConfig will return 80 as port number. // But if Wrapper is running as a process, port will be mapped internally by MPS, so different number will be dynamically assigned. if (activeConfig.TryGetValue(portName, out string listeningPortString)) { GameserverSDK.LogMessage($"{portName}:{listeningPortString} was found in GSDK Config Settings."); _listeningPort = listeningPortString; } else { LogMessage($"Cannot find {portName} in GSDK Config Settings. Please make sure the LocalMultiplayerAgent is running " + $"and that the MultiplayerSettings.json file includes correct {portName} as a GamePort Name."); return; } // Check if there is any process already using the port (_listeningPort). This will only work for Windows. if (CheckIfPortIsUsed(gameserverExe)) { return; } ; // We pass port number as a 3rd argument when we start fakegame.exe // Port number is grabbed via GSDK and will be passed to fake game as a listening port. gameProcess = StartProcess(gameserverExe, string.Join(' ', args.Append(_listeningPort))); // as part of wrapping the main game server executable, // we create event handlers to process the output from the game (standard output/standard error) // based on this output, we will activate the server and process connected players gameProcess.OutputDataReceived += DataReceived; gameProcess.ErrorDataReceived += DataReceived; // start reading output (stdout/stderr) from the game gameProcess.BeginOutputReadLine(); gameProcess.BeginErrorReadLine(); // Call this when your game is done initializing and players can connect // Note: This is a blocking call, and will return when this game server is either allocated or terminated if (GameserverSDK.ReadyForPlayers()) { // After allocation, we can grab the session cookie from the config activeConfig = GameserverSDK.getConfigSettings(); var connectedPlayers = new List <ConnectedPlayer>(); // initial players includes the list of the players that are allowed to connect to the game // they might or might not end up connecting // in this sample we're nevertheless adding them to the list foreach (var player in GameserverSDK.GetInitialPlayers()) { connectedPlayers.Add(new ConnectedPlayer(player)); } GameserverSDK.UpdateConnectedPlayers(connectedPlayers); if (activeConfig.TryGetValue(GameserverSDK.SessionCookieKey, out string sessionCookie)) { LogMessage($"The session cookie from the allocation call is: {sessionCookie}"); } } else { // No allocation happened, the server is getting terminated (likely because there are too many already in standing by) LogMessage("Server is getting terminated."); gameProcess?.Kill(); // we still need to call WaitForExit https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.process.kill?view=netcore-3.1#remarks } // wait till it exits or crashes gameProcess.WaitForExit(); }