void Awake()
 {
     if (_instance == null)
     {
         _instance = this;
         DontDestroyOnLoad(this.gameObject);
     }
 }
Ejemplo n.º 2
0
    public void DoCreateGameSession(int maxPlayers, string GameSessionData)
    {
        CreateGameSessionData CGSD = new CreateGameSessionData();

        CGSD.maxPlayers      = maxPlayers;
        CGSD.GameSessionData = GameSessionData;


        NotAmazonUnityMainThreadDispatcher.Instance().Enqueue(GetRandomNumberThousand());

        Thread t = new Thread(new ParameterizedThreadStart(CreateGameSession));

        t.Start(CGSD);
    }
Ejemplo n.º 3
0
 public static void LogToMyConsole(string text)
 {
     staticData.consoleText.text += "\n" + text;
     NotAmazonUnityMainThreadDispatcher.Instance().Enqueue(() => Debug.Log(text));
 }
Ejemplo n.º 4
0
 public static void LogToMyConsoleMainThread(string text)
 {
     NotAmazonUnityMainThreadDispatcher.Instance().Enqueue(
         GameLiftServerExampleBehavior.LogToMyConsoleEnum(text));
 }
Ejemplo n.º 5
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
         *
         *
         */
    }
 void OnDestroy()
 {
     _instance = null;
 }