コード例 #1
0
    private void SetupServerAndGamelift()
    {
        // start the unet server

        //todo commented by dan
        //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();
                // quit if no player joined within two minutes
                timer.Elapsed  += this.CheckPlayersJoined;
                timer.AutoReset = false;
                timer.Start();
            },
                (updateGameSession) =>
            {
            },
                () =>
            {
                // onProcessTerminate callback
                TerminateSession();
            },
                () =>
            {
                // 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()}.");
        }
    }
コード例 #2
0
    //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());
        }
    }
コード例 #3
0
        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());
            }
        }
コード例 #4
0
ファイル: GameLiftServer.cs プロジェクト: naxxster/agario-mmo
    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);
        }
    }
コード例 #5
0
 void OnGameSession(GameSession 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()
     Debug.Log("ActivateGameSession");
     GameLiftServerAPI.ActivateGameSession();
 }
コード例 #6
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()}.");
        }
    }
コード例 #7
0
        private static void OnGameSession(GameSession gameSession)
        {
            log.ConfigureNewGame(gameSession.GameSessionId);
            appgame = new Game();
            string boardFile = "8 5\nA W W W W W W a\nB W W W W W W b\nW P W W W W p W\nC W W W W W W c\nD W W W W W W d";

            appgame.board         = new Map(boardFile);
            appgame.gameSessionId = gameSession.GameSessionId;
            gameSessionId         = gameSession.GameSessionId;
            GameLiftServerAPI.ActivateGameSession();
        }
コード例 #8
0
    private async void ActivateSession(GameSession gameSession)
    {
        try {
            Debug.Log("server start game session: " + gameSession.GameSessionId);
            server = new DemoServer();
            await server.StartNetworked(AcceptPlayer, HandlePlayerExit, this, settings);

            LogOutcome("activate", GameLiftServerAPI.ActivateGameSession());
        } catch (Exception e) {
            Debug.LogError("Exception on server update");
            Debug.LogError(e);
        }
    }
コード例 #9
0
        private bool ProcessReady(int listenPort, out GameLiftError err)
        {
            var processParameters = new ProcessParameters
            {
                Port = listenPort,
                OnStartGameSession = session =>
                {
                    _logger.InfoFormat("start session: {0}", session.GameSessionId);
                    GameLiftServerAPI.ActivateGameSession();
                    _session = session;
                },
                OnProcessTerminate = () => { _isRunning = false; }
            };

            var outcome = GameLiftServerAPI.ProcessReady(processParameters);

            err = outcome.Error;
            return(outcome.Success);
        }
コード例 #10
0
        //private Thread keepAlive;

        public void start()
        {
            var initSDKOutcome = GameLiftServerAPI.InitSDK();

            if (initSDKOutcome.Success)
            {
                // Set parameters and call ProcessReady
                var processParams = new ProcessParameters(
                    (gameSession) =>
                {
                    Console.WriteLine("HERE");
                    GameLiftServerAPI.ActivateGameSession();
                },
                    this.OnProcessTerminate,
                    this.OnHealthCheck,
                    PORT,
                    new LogParameters(new List <string>()        // Examples of log and error files written by the game server
                {
                    "/local/game/log"
                })
                    );

                var processReadyOutcome = GameLiftServerAPI.ProcessReady(processParams);
                if (processReadyOutcome.Success)
                {
                    Console.WriteLine("ProcessReady success.");
                }
                else
                {
                    Console.WriteLine("ProcessReady failure : " + processReadyOutcome.Error.ToString());
                }
            }
            else
            {
                Console.WriteLine("InitSDK failure : " + initSDKOutcome.Error.ToString());
            }
        }
コード例 #11
0
 //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()
 private void OnStartGameSession(GameSession gameSession)
 {
     Debug.Log(":) GAMELIFT SESSION REQUESTED"); //And then do stuff with it maybe.
     try {
         //Notifies the GameLift service that the server process has activated a game session and is now ready to
         //receive player connections. This action should be called as part of the onStartGameSession() callback
         //function, after all game session initialization has been completed.
         var outcome = GameLiftServerAPI.ActivateGameSession();
         if (outcome.Success)
         {
             Debug.Log(":) GAME SESSION ACTIVATED");
             GameSessionStarted?.Invoke(this, gameSession);
             TerminateIdleGameSession().Forget();
         }
         else
         {
             Debug.Log($":( GAME SESSION ACTIVATION FAILED. ActivateGameSession() returned {outcome.Error}");
         }
     }
     catch (Exception e) {
         Debug.Log(
             $":( GAME SESSION ACTIVATION FAILED. ActivateGameSession() exception \n{e.Message}");
     }
 }
コード例 #12
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
         *
         *
         */
    }
コード例 #13
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);
        }
    // 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());
        }
    }
コード例 #15
0
    private void ProcessReady()
    {
        try
        {
            ProcessParameters prParams = new ProcessParameters(
                /* onStartGameSession */ (gameSession) => {
                Debug.Log(":) GAMELIFT SESSION REQUESTED");  //And then do stuff with it maybe.
                try
                {
                    var outcome = GameLiftServerAPI.ActivateGameSession();
                    if (outcome.Success)
                    {
                        Debug.Log(":) GAME SESSION ACTIVATED");
                    }
                    else
                    {
                        Debug.Log(":( GAME SESSION ACTIVATION FAILED. ActivateGameSession() returned " + outcome.Error.ToString());
                    }
                }
                catch (Exception e)
                {
                    Debug.Log(":( GAME SESSION ACTIVATION FAILED. ActivateGameSession() exception " + Environment.NewLine + e.Message);
                }
            },
                /* onProcessTerminate */ () => {
                Debug.Log(":| GAMELIFT PROCESS TERMINATION REQUESTED (OK BYE)");
                GameLiftRequestedTermination = true;
                gl.TerminateServer();
            },
                /* onHealthCheck */ () => {
                Debug.Log(":) GAMELIFT HEALTH CHECK REQUESTED (HEALTHY)");
                return(true);
            },
                /* port */ port, // tell the GameLift service which port to connect to this process on.
                // unless we manage this there can only be one process per server.
                new LogParameters(new List <string>()
            {
                mLogFilePath
                //@"C:\game\GameLiftUnity_Data\output_log.txt" // must be different for each server if multiple servers on instance
            }));

            var processReadyOutcome = GameLiftServerAPI.ProcessReady(prParams);
            if (processReadyOutcome.Success)
            {
                if (gl != null)
                {
                    gl.gameliftStatus = true;
                }
                Debug.Log(":) PROCESSREADY SUCCESS.");
            }
            else
            {
                if (gl != null)
                {
                    gl.gameliftStatus = false;
                }
                Debug.Log(":( PROCESSREADY FAILED. ProcessReady() returned " + processReadyOutcome.Error.ToString());
            }
        }
        catch (Exception e)
        {
            Debug.Log(":( PROCESSREADY FAILED. ProcessReady() exception " + Environment.NewLine + e.Message);
        }
    }
コード例 #16
0
 void OnActiveGameSessionRequest(GameSession gameSession)
 {
     Console.WriteLine("OnActiveGameSessionRequest called");
     GameLiftServerAPI.ActivateGameSession();
 }