//This is an example of a simple integration with GameLift server SDK that makes game server
    //processes go active on Amazon GameLift
    public void Start()
    {
        //InitSDK establishes a local connection with the Amazon GameLift agent to enable
        //further communication.
        var initSDKOutcome = GameLiftServerAPI.InitSDK();

        if (initSDKOutcome.Success)
        {
            ProcessParameters processParameters = new ProcessParameters(
                (gameSession) => {
                //Respond to new game session activation request. GameLift sends activation request
                //to the game server along with a game session object containing game properties
                //and other settings. Once the game server is ready to receive player connections,
                //invoke GameLiftServerAPI.ActivateGameSession()
                GameLiftServerAPI.ActivateGameSession();
            },
                () => {
                //OnProcessTerminate callback. GameLift invokes this callback before shutting down
                //an instance hosting this game server. It gives this game server a chance to save
                //its state, communicate with services, etc., before being shut down.
                //In this case, we simply tell GameLift we are indeed going to shut down.
                GameLiftServerAPI.ProcessEnding();
            },
                () => {
                //This is the HealthCheck callback.
                //GameLift invokes this callback every 60 seconds or so.
                //Here, a game server might want to check the health of dependencies and such.
                //Simply return true if healthy, false otherwise.
                //The game server has 60 seconds to respond with its health status.
                //GameLift will default to 'false' if the game server doesn't respond in time.
                //In this case, we're always healthy!
                return(true);
            },
                //Here, the game server tells GameLift what port it is listening on for incoming player
                //connections. In this example, the port is hardcoded for simplicity. Active game
                //that are on the same instance must have unique ports.
                listeningPort,
                new LogParameters(new List <string>()
            {
                //Here, the game server tells GameLift what set of files to upload when the game session ends.
                //GameLift uploads everything specified here for the developers to fetch later.
                "/local/game/logs/myserver.log"
            }));

            //Calling ProcessReady tells GameLift this game server is ready to receive incoming game sessions!
            var processReadyOutcome = GameLiftServerAPI.ProcessReady(processParameters);
            if (processReadyOutcome.Success)
            {
                print("ProcessReady success.");
            }
            else
            {
                print("ProcessReady failure : " + processReadyOutcome.Error.ToString());
            }
        }
        else
        {
            print("InitSDK failure : " + initSDKOutcome.Error.ToString());
        }
    }
        // Called from MLAPI on client disconnect
        // Called on MLAPI connection exception
        public void DisconnectPlayer(ulong clientId)
        {
            // if player slots never re-open, just skip this entire thing.
            try {
                var playerSessionId = playerSessions[clientId];
                try {
                    //Notifies the GameLift service that a player with the specified player session ID has disconnected
                    //from the server process. In response, GameLift changes the player slot to available,
                    //which allows it to be assigned to a new player.
                    var outcome = GameLiftServerAPI.RemovePlayerSession(playerSessionId);
                    GameLiftServerAPI.ProcessEnding(); // For now, killing game session on player leaving.
                    Debug.Log(outcome.Success
            ? ":) PLAYER SESSION REMOVED"
            : $":( PLAYER SESSION REMOVE FAILED. RemovePlayerSession() returned {outcome.Error}");
                }
                catch (Exception e) {
                    Debug.Log($":( PLAYER SESSION REMOVE FAILED. RemovePlayerSession() exception\n{e.Message}");
                    throw;
                }

                playerSessions.Remove(clientId);
            }
            catch (KeyNotFoundException e) {
                Debug.Log($":( INVALID PLAYER SESSION. Exception \n{e.Message}");
                throw; // should never happen
            }
        }
        private void InitializeServerProcess(int listeningPort)
        {
            //InitSDK will establish a local connection with GameLift's agent to enable further communication.
            var initSDKOutcome = GameLiftServerAPI.InitSDK();

            if (initSDKOutcome.Success)
            {
                ProcessParameters processParameters = new ProcessParameters(
                    (gameSession) => {
                    //When a game session is created, GameLift sends an activation request to the game server and passes along the game session object containing game properties and other settings.
                    //Here is where a game server should take action based on the game session object.
                    //Once the game server is ready to receive incoming player connections, it should invoke GameLiftServerAPI.ActivateGameSession()
                    GameLiftServerAPI.ActivateGameSession();
                },
                    (updateGameSession) => {
                    //When a game session is updated (e.g. by FlexMatch backfill), GameLiftsends a request to the game
                    //server containing the updated game session object.  The game server can then examine the provided
                    //matchmakerData and handle new incoming players appropriately.
                    //updateReason is the reason this update is being supplied.
                },
                    () => {
                    //OnProcessTerminate callback. GameLift will invoke this callback before shutting down an instance hosting this game server.
                    //It gives this game server a chance to save its state, communicate with services, etc., before being shut down.
                    //In this case, we simply tell GameLift we are indeed going to shutdown.
                    GameLiftServerAPI.ProcessEnding();
                },
                    () => {
                    //This is the HealthCheck callback.
                    //GameLift will invoke this callback every 60 seconds or so.
                    //Here, a game server might want to check the health of dependencies and such.
                    //Simply return true if healthy, false otherwise.
                    //The game server has 60 seconds to respond with its health status. GameLift will default to 'false' if the game server doesn't respond in time.
                    //In this case, we're always healthy!
                    return(true);
                },
                    listeningPort, //This game server tells GameLift that it will listen on port 7777 for incoming player connections.
                    new LogParameters(new List <string>()
                {
                    //Here, the game server tells GameLift what set of files to upload when the game session ends.
                    //GameLift will upload everything specified here for the developers to fetch later.
                    "/local/game/logs/myserver.log"
                }));

                //Calling ProcessReady tells GameLift this game server is ready to receive incoming game sessions!
                var processReadyOutcome = GameLiftServerAPI.ProcessReady(processParameters);
                if (processReadyOutcome.Success)
                {
                    print("ProcessReady success.");
                }
                else
                {
                    print("ProcessReady failure : " + processReadyOutcome.Error.ToString());
                }
            }
            else
            {
                print("InitSDK failure : " + initSDKOutcome.Error.ToString());
            }
        }
Esempio n. 4
0
        void OnProcessTerminate()
        {
            // game-specific tasks required to gracefully shut down a game session,
            // such as notifying players, preserving game state data, and other cleanup
            var ProcessEndingOutcome = GameLiftServerAPI.ProcessEnding();

            GameLiftServerAPI.Destroy();
            this.running = false;
        }
Esempio n. 5
0
    public bool GameLiftStart(int listenPort)
    {
        //Debug.Log("GameLift Start with Port:" + listenPort);
        LogModule.WriteToLogFile("[GameLift] GameLift Start with Port:" + listenPort);
        var initSDKOutcome = GameLiftServerAPI.InitSDK();

        if (initSDKOutcome.Success)
        {
            ProcessParameters processParameters = new ProcessParameters(
                (gameSession) =>
            {
                //OnStartGameSession Callback
                LogModule.WriteToLogFile("[GameLift] OnStartGameSession with Parameter=" + gameSession);
                GameLiftServerAPI.ActivateGameSession();
            },
                (gameSession) =>
            {
                //OnUpdateGameSession Callback
                //You can implement custom Match update logics using Backfill Ticket, UpdateReason, GameSession data.
                LogModule.WriteToLogFile("[GameLift] OnUpdateGameSession with Backfill Ticket=" + gameSession.BackfillTicketId + ", UpdateReason=" + gameSession.UpdateReason);
            },
                () =>
            {
                //OnProcessTerminate Callback
                LogModule.WriteToLogFile("[GameLift] ProcessEnding");
                GameLiftServerAPI.ProcessEnding();
            },
                () =>
            {
                //OnHealthCheck Callback
                return(true);
            },
                listenPort,
                new LogParameters(new List <string>()
            {
                "./local/game/logs/myserver.log"
                //"C:\\game\\myserver.log"
            }
                                  ));
            var processReadyOutcome = GameLiftServerAPI.ProcessReady(processParameters);
            if (processReadyOutcome.Success)
            {
                LogModule.WriteToLogFile("[GameLift] ProcessReady Success");
                return(true);
            }
            else
            {
                LogModule.WriteToLogFile("[GameLift] ProcessReady Failure : " + processReadyOutcome.Error.ToString());
                return(false);
            }
        }
        else
        {
            LogModule.WriteToLogFile("[GameLift] InitSDK failure : " + initSDKOutcome.Error.ToString());
            return(false);
        }
    }
 private void OnProcessTerminate()
 {
     //OnProcessTerminate callback. GameLift invokes this callback before shutting down
     //an instance hosting this game server. It gives this game server a chance to save
     //its state, communicate with services, etc., before being shut down.
     //In this case, we simply tell GameLift we are indeed going to shut down.
     Debug.Log(":| GAMELIFT PROCESS TERMINATION REQUESTED (OK BYE)");
     GameLiftServerAPI.ProcessEnding();
 }
 private void HandlePlayerExit(string playerSessionId, int remaining)
 {
     LogOutcome("player term", GameLiftServerAPI.RemovePlayerSession(playerSessionId));
     if (remaining == 0)
     {
         LogOutcome("game term", GameLiftServerAPI.TerminateGameSession());
         LogOutcome("ending", GameLiftServerAPI.ProcessEnding());
         Application.Quit(0);
     }
 }
 // should be called when the server determines the game is over
 // and needs to signal Gamelift to terminate this instance
 public void TerminateSession()
 {
     Debug.Log("** TerminateSession Requested **");
     if (isGameliftServer)
     {
         GameLiftServerAPI.TerminateGameSession();
         GameLiftServerAPI.ProcessEnding();
     }
     Debug.Log("** Process Exit **");
     Application.Quit();
 }
Esempio n. 9
0
    private void SetupServerAndGamelift()
    {
        // start the unet server
        networkPort = LISTEN_PORT;
        StartServer();
        print($"Server listening on port {networkPort}");

        // initialize GameLift
        print("Starting GameLift initialization.");
        var initSDKOutcome = GameLiftServerAPI.InitSDK();

        if (initSDKOutcome.Success)
        {
            isGameliftServer = true;
            var processParams = new ProcessParameters(
                (gameSession) =>
            {
                // onStartGameSession callback
                GameLiftServerAPI.ActivateGameSession();
            },
                (updateGameSession) =>
            {
            },
                () =>
            {
                // onProcessTerminate callback
                GameLiftServerAPI.ProcessEnding();
            },
                () =>
            {
                // healthCheck callback
                return(true);
            },
                LISTEN_PORT,
                new LogParameters(new List <string>()
            {
                "/local/game/logs/myserver.log"
            })
                );
            var processReadyOutcome = GameLiftServerAPI.ProcessReady(processParams);
            if (processReadyOutcome.Success)
            {
                print("GameLift process ready.");
            }
            else
            {
                print($"GameLift: Process ready failure - {processReadyOutcome.Error.ToString()}.");
            }
        }
        else
        {
            print($"GameLift: InitSDK failure - {initSDKOutcome.Error.ToString()}.");
        }
    }
Esempio n. 10
0
    public void EndProcess()
    {
        var processEndingOutcome = GameLiftServerAPI.ProcessEnding();

        if (processEndingOutcome.Success)
        {
            LogModule.WriteToLogFile("[GameLift] End GameLift Server Process");
        }
        else
        {
            LogModule.WriteToLogFile("[GameLift] Process Ending Failed. Result : " + processEndingOutcome.Error.ToString());
        }
    }
        private void OnApplicationQuit()
        {
            //Notifies the GameLift service that the server process is shutting down. This method should be called
            //AFTER all other cleanup tasks, including shutting down all active game sessions.
            //This method should exit with an exit code of 0;
            //a non-zero exit code results in an event message that the process did not exit cleanly.
            var outcome = GameLiftServerAPI.ProcessEnding();

            Debug.Log(outcome.Success
        ? ":) PROCESSENDING"
        : $":( PROCESSENDING FAILED. ProcessEnding() returned {outcome.Error}");

            //Make sure to call GameLiftServerAPI.Destroy() when the application quits.
            //This resets the local connection with GameLift's agent.
            GameLiftServerAPI.Destroy();
        }
        private async UniTaskVoid TerminateIdleGameSession()
        {
            // Cancel game session after 60 seconds of idle.
            idleCancelTokenSource = new CancellationTokenSource();
            try {
                await UniTask.Delay(TimeSpan.FromSeconds(120), cancellationToken : idleCancelTokenSource.Token);

                Debug.Log(":) OK WE WAITED TOO LONG BYEEE");
                GameLiftServerAPI.ProcessEnding();
            }
            catch (Exception e) when(e is OperationCanceledException)
            {
                // DO NOTHING, it cancelled.
                Debug.Log(":) NOT IDLE ANYMORE, CARRY ON");
            }
        }
Esempio n. 13
0
 private void ProcessEnding()
 {
     try
     {
         var outcome = GameLiftServerAPI.ProcessEnding();
         if (outcome.Success)
         {
             Debug.Log(":) PROCESSENDING");
         }
         else
         {
             Debug.Log(":( PROCESSENDING FAILED. ProcessEnding() returned " + outcome.Error.ToString());
         }
     }
     catch (Exception e)
     {
         Debug.Log(":( PROCESSENDING FAILED. ProcessEnding() exception " + Environment.NewLine + e.Message);
     }
 }
Esempio n. 14
0
    private void FinalizeServerProcessShutdown()
    {
        Debug.Log("GameLiftServer.FinalizeServerProcessShutdown");

        // All game session clean up should be performed before this, as it should be the last thing that
        // is called when terminating a game session. After a successful outcome from ProcessEnding, make
        // sure to call Application.Quit(), otherwise the application does not shutdown properly. see:
        // https://forums.awsgametech.com/t/server-process-exited-without-calling-processending/5762/17

        var outcome = GameLiftServerAPI.ProcessEnding();

        if (outcome.Success)
        {
            Debug.Log("FinalizeServerProcessShutdown: GAME SESSION TERMINATED");
            Application.Quit();
        }
        else
        {
            Debug.Log("FinalizeServerProcessShutdown: GAME SESSION TERMINATION FAILED. ProcessEnding() returned " + outcome.Error.ToString());
        }
    }
    // Ends the game session for all and disconnects the players
    public void TerminateGameSession()
    {
        System.Console.WriteLine("Terminating Game Session");

        //Cleanup (not currently relevant as we just terminate the process)
        GameObject.FindObjectOfType <Server>().DisconnectAll();
        this.gameStarted = false;

        // Stop the backfilling
        if (this.backfillTicketID != null)
        {
            System.Console.WriteLine("Stopping backfill");
            var stopBackfill = new StopMatchBackfillRequest();
            stopBackfill.TicketId = this.backfillTicketID;
            stopBackfill.MatchmakingConfigurationArn = this.matchmakerData.MatchmakingConfigurationArn;
            stopBackfill.GameSessionArn = GameLiftServerAPI.GetGameSessionId().Result;
            GameLiftServerAPI.StopMatchBackfill(stopBackfill);
        }

        // Terminate the process following GameLift best practices. A new one will be started automatically
        System.Console.WriteLine("Terminating process");
        GameLiftServerAPI.ProcessEnding();
        Application.Quit();
    }
Esempio n. 16
0
 private static void OnProcessTerminate()
 {
     GameLiftServerAPI.ProcessEnding();
     GameLiftServerAPI.Destroy();
     System.Environment.Exit(0);
 }
Esempio n. 17
0
 private void ProcessEnding()
 {
     _playerEndPoints.ForEach(pid => GameLiftServerAPI.RemovePlayerSession(pid));
     _peerList.ForEach(p => p.Disconnect());
     GameLiftServerAPI.ProcessEnding();
 }
Esempio n. 18
0
    public void DoStartStuff()
    {
        if (started == true)
        {
            LogToMyConsoleMainThread("GameLift Server Already Started");
            return;
        }

        started = true;

        LogToMyConsoleMainThread("GameLift Server Starting");



        Test1();
        Debug.Log("Port: " + listeningPort);

        //InitSDK establishes a local connection with the Amazon GameLift agent to enable
        //further communication.
        var initSDKOutcome = GameLiftServerAPI.InitSDK();

        if (initSDKOutcome.Success)
        {
            ProcessParameters processParameters = new ProcessParameters(
                (gameSession) =>
            {
                //Respond to new game session activation request. GameLift sends activation request
                //to the game server along with a game session object containing game properties
                //and other settings. Once the game server is ready to receive player connections,
                //invoke GameLiftServerAPI.ActivateGameSession()
                GameLiftServerAPI.ActivateGameSession();

                //TODO: We should call "ActivateGameSession" after Bolt is done starting
                myID        = gameSession.GameSessionId;
                SceneToLoad = gameSession.GameSessionData;



                NotAmazonUnityMainThreadDispatcher.Instance().Enqueue(Test0());
                //UnityMainThreadDispatcher.Instance().Enqueue(Test0());

                LogToMyConsoleMainThread(
                    "Starting game with " + gameSession.MaximumPlayerSessionCount + " players");
            },
                (updateGameSession) =>
            {
                LogToMyConsoleMainThread("updateGameSession");

                /*    updateGameSession.BackfillTicketId
                 *
                 *        MATCHMAKING_DATA_UPDATED = 0,
                 *        BACKFILL_FAILED = 1,
                 *        BACKFILL_TIMED_OUT = 2,
                 *        BACKFILL_CANCELLED = 3,
                 *        UNKNOWN = 4
                 */
            },
                () =>
            {
                //OnProcessTerminate callback. GameLift invokes this callback before shutting down
                //an instance hosting this game server. It gives this game server a chance to save
                //its state, communicate with services, etc., before being shut down.
                //In this case, we simply tell GameLift we are indeed going to shut down.
                GameLiftServerAPI.ProcessEnding();

                //TODO: We should save all data and shutdown Bolt before calling "ProcessEnding"
            },
                () =>
            {
                //This is the HealthCheck callback.
                //GameLift invokes this callback every 60 seconds or so.
                //Here, a game server might want to check the health of dependencies and such.
                //Simply return true if healthy, false otherwise.
                //The game server has 60 seconds to respond with its health status.
                //GameLift will default to 'false' if the game server doesn't respond in time.
                //In this case, we're always healthy!
                return(true);

                //TODO: maybe we should report unhealthy if performance is bad
            },
                //Here, the game server tells GameLift what port it is listening on for incoming player
                //connections. In this example, the port is hardcoded for simplicity. Active game
                //that are on the same instance must have unique ports.
                listeningPort,
                new LogParameters(new List <string>()
            {
                //Here, the game server tells GameLift what set of files to upload when the game session ends.
                //GameLift uploads everything specified here for the developers to fetch later.
                //TODO: put stuff in the log?
                "C:/Users/gl-user-server/AppData/LocalLow/DefaultCompany/GameLiftTest2"
                //"/local/game/logs/myserver.log"
            })
                );



            //Calling ProcessReady tells GameLift this game server is ready to receive incoming game sessions!
            var processReadyOutcome = GameLiftServerAPI.ProcessReady(processParameters);
            if (processReadyOutcome.Success)
            {
                LogToMyConsoleMainThread("ProcessReady success.");
            }
            else
            {
                LogToMyConsoleMainThread("ProcessReady failure : " + processReadyOutcome.Error.ToString());
            }
        }
        else
        {
            LogToMyConsoleMainThread("InitSDK failure : " + initSDKOutcome.Error.ToString());
            LogToMyConsoleMainThread("If testing locally, are you running the Server .jar?");
        }

        /*
         * https://docs.aws.amazon.com/gamelift/latest/developerguide/gamelift-sdk-server-api.html#gamelift-sdk-server-initialize
         * https://docs.aws.amazon.com/gamelift/latest/developerguide/integration-server-sdk-cpp-ref-actions.html#integration-server-sdk-cpp-ref-processreadyasync
         * GameLiftServerAPI:
         *
         * AcceptPlayerSession (used)
         * respond to  CreatePlayerSession() with an User ID and session ID
         *
         *
         * ActivateGameSession (used)
         *
         * DescribePlayerSessions
         *
         * GetGameSessionId
         *
         * GetSdkVersion
         *
         * GetTerminationTime
         * how much time is left to save data, move players to other game sessions
         *
         * InitSDK (used)
         *
         * ProcessEnding (used)
         *
         * ProcessReady (used)
         *
         * RemovePlayerSession (used)
         * kick someone out? or when someone left
         * "Notifies the Amazon GameLift service that a player with the specified
         * player session ID has disconnected from the server process. In response,
         * Amazon GameLift changes the player slot to available,
         * which allows it to be assigned to a new player."
         *
         *
         * StartMatchBackfill
         *
         * StopMatchBackfill
         *
         * TerminateGameSession
         * "call this at the end of game session shutdown process"
         * "After calling this action, the server process can call ProcessReady()
         * //to signal its availability to host a new game session.
         * //Alternatively it can call ProcessEnding() to shut down
         * //the server process and terminate the instance."
         *
         * UpdatePlayerSessionCreationPolicy
         *
         *
         * GetGameSessionLogUrl: Get logs from a game session, they are stored for 14 days
         *
         *
         */
    }
Esempio n. 19
0
 void OnTerminateProcessRequest()
 {
     GameLiftServerAPI.ProcessEnding();
 }
 private void EndServerProcess()
 {
     GameLiftServerAPI.ProcessEnding();
 }
 // should be called when the server determines the game is over
 // and needs to signal Gamelift to terminate this instance
 public void TerminateSession()
 {
     Debug.Log("** TerminateSession Requested **");
     GameLiftServerAPI.TerminateGameSession();
     GameLiftServerAPI.ProcessEnding();
 }
Esempio n. 22
0
        static int Main(string[] args)
        {
            var listeningPort = 7777;
            var waitHandle    = new AutoResetEvent(false);

            var initSDKOutcome = GameLiftServerAPI.InitSDK();

            if (initSDKOutcome.Success)
            {
                ProcessParameters processParameters = new ProcessParameters(
                    // OnGameSession callback
                    (gameSession) =>
                {
                    Console.WriteLine("OnGameSession received.");
                    var activateGameSessionOutcome = GameLiftServerAPI.ActivateGameSession();
                    if (activateGameSessionOutcome.Success)
                    {
                        Console.WriteLine("ActivateGameSession success.");
                    }
                    else
                    {
                        Console.WriteLine("ActivateGameSession failure : " + activateGameSessionOutcome.Error.ToString());
                    }
                },

                    // OnProcessTerminate callback
                    () =>
                {
                    Console.WriteLine("OnProcessTerminate received.");
                    waitHandle.Set();
                },

                    // OnHealthCheck
                    () =>
                {
                    Console.WriteLine("OnHealthCheck received.");
                    return(true);
                },

                    listeningPort,

                    new LogParameters(new List <string>()
                {
                    "/local/game/logs/myserver.log"
                })
                    );

                var processReadyOutcome = GameLiftServerAPI.ProcessReady(processParameters);
                if (processReadyOutcome.Success)
                {
                    Console.WriteLine("ProcessReady success.");
                }
                else
                {
                    Console.WriteLine("ProcessReady failure : " + processReadyOutcome.Error.ToString());
                }
            }
            else
            {
                Console.WriteLine("InitSDK failure : " + initSDKOutcome.Error.ToString());
            }

            Console.CancelKeyPress += new ConsoleCancelEventHandler(
                (object sender, ConsoleCancelEventArgs eventArgs) =>
            {
                Console.WriteLine("The read operation has been interrupted.");
                Console.WriteLine($"  Key pressed: {eventArgs.SpecialKey}");
                Console.WriteLine($"  Cancel property: {eventArgs.Cancel}");

                Console.WriteLine("Setting the Cancel property to true...");
                eventArgs.Cancel = true;

                Console.WriteLine($"  Cancel property: {eventArgs.Cancel}");
                Console.WriteLine("The read operation will resume...");
                waitHandle.Set();
            }
                );

            waitHandle.WaitOne();

            var processEndingOutcome = GameLiftServerAPI.ProcessEnding();

            if (processEndingOutcome.Success)
            {
                Console.WriteLine("ProcessEnding success.");
            }
            else
            {
                Console.WriteLine("ProcessEnding failure : " + processEndingOutcome.Error.ToString());
            }

            GameLiftServerAPI.Destroy();

            return(0);
        }
Esempio n. 23
0
 void OnApplicationQuit()
 {
     //Make sure to call GameLiftServerAPI.ProcessEnding() when the application quits.
     //This resets the local connection with GameLift's agent.
     GameLiftServerAPI.ProcessEnding();
 }
    // Called when the monobehaviour is created
    public void Awake()
    {
        //Initiate the simple statsD client
        this.statsdClient = new SimpleStatsdClient("localhost", 8125);

        //Get the port from command line args
        listeningPort = this.GetPortFromArgs();

        System.Console.WriteLine("Will be running in port: " + this.listeningPort);

        //InitSDK establishes a local connection with the Amazon GameLift agent to enable
        //further communication.
        var initSDKOutcome = GameLiftServerAPI.InitSDK();

        if (initSDKOutcome.Success)
        {
            ProcessParameters processParameters = new ProcessParameters(
                (gameSession) => {
                //Respond to new game session activation request. GameLift sends activation request
                //to the game server along with a game session object containing game properties
                //and other settings.

                // Activate the session
                GameLiftServerAPI.ActivateGameSession();

                //Start waiting for players
                this.gameSessionInfoReceived = true;
                this.gameSessionId           = gameSession.GameSessionId;

                //Set the game session tag (CloudWatch dimension) for custom metrics
                string justSessionId = this.gameSessionId.Split('/')[2];
                this.statsdClient.SetCommonTagString("#gamesession:" + justSessionId);

                //Send session started to CloudWatch just for testing
                this.statsdClient.SendCounter("game.SessionStarted", 1);

                System.Console.WriteLine("Matchmaker data New session:" + gameSession.MatchmakerData);
                this.matchmakerData   = MatchmakerData.FromJson(gameSession.MatchmakerData);
                this.backfillTicketID = this.matchmakerData.AutoBackfillTicketId;
            },
                (gameSession) => {
                //Respond to game session updates

                System.Console.WriteLine("backfill ticked ID update session:" + gameSession.BackfillTicketId);

                if (gameSession.BackfillTicketId != null)
                {
                    System.Console.WriteLine("Updating backfill ticked ID: " + gameSession.BackfillTicketId);
                    this.backfillTicketID = gameSession.BackfillTicketId;
                }
            },
                () => {
                //OnProcessTerminate callback. GameLift invokes this callback before shutting down
                //an instance hosting this game server. It gives this game server a chance to save
                //its state, communicate with services, etc., before being shut down.
                //In this case, we simply tell GameLift we are indeed going to shut down.
                GameLiftServerAPI.ProcessEnding();
                Application.Quit();
            },
                () => {
                //This is the HealthCheck callback.
                //GameLift invokes this callback every 60 seconds or so.
                //Here, a game server might want to check the health of dependencies and such.
                //Simply return true if healthy, false otherwise.
                //The game server has 60 seconds to respond with its health status.
                //GameLift will default to 'false' if the game server doesn't respond in time.
                //In this case, we're always healthy!
                return(true);
            },
                //Here, the game server tells GameLift what port it is listening on for incoming player
                //connections. We will use the port received from command line arguments
                listeningPort,
                new LogParameters(new List <string>()
            {
                //Let GameLift know where our logs are stored. We are expecting the command line args to specify the server with the port in log file
                "/local/game/logs/myserver" + listeningPort + ".log"
            }));

            //Calling ProcessReady tells GameLift this game server is ready to receive incoming game sessions
            var processReadyOutcome = GameLiftServerAPI.ProcessReady(processParameters);

            if (processReadyOutcome.Success)
            {
                print("ProcessReady success.");
            }
            else
            {
                print("ProcessReady failure : " + processReadyOutcome.Error.ToString());
            }
        }
        else
        {
            print("InitSDK failure : " + initSDKOutcome.Error.ToString());
        }
    }