示例#1
0
 /**
  * Send Game Loaded message to the Docent. This allows it to update it's view
  * to show the current representation of the game. It's ignored if the docent isn't available.
  */
 private void SendGameLoadedMessageToDocent()
 {
     if (0 != GameInterface.dispatchEvent(KEYWORD_DOCENT, "gameLoaded"))
     {
         Debug.LogWarning("Game loaded message delivery failed!");
     }
 }
示例#2
0
        /**
         * Dispatches the currently stored list of games from the locally generated list
         */
        public void UpdateDocentGamesList()
        {
            EscEvent evt = new EscEvent("games", gamesList);
            string   initPayloadString = evt.ToString();

            GameInterface.dispatchEvent("docent", initPayloadString);
        }
示例#3
0
        //! Dispatches a EscEvent to a controller client to pause.
        private void PauseControllers()
        {
            foreach (Client client in this.clients)
            {
                GameInterface.dispatchEvent(client.Username(), API_KEYWORD_GAME_PAUSED);
//LoadSave.savedData.Add (Time.time.ToString () + " : OUT :" + client.Username () + " " + API_KEYWORD_GAME_PAUSED + "\n");
            }
        }
示例#4
0
        /**
         * Dispatches a EscEvent to a controller client with initial payload attributes provided by the Game class.
         *
         * @param client the client to be initialized
         * @param initPayload the initialization key/value pairs to be dispatched
         */
        public void InitializeController(Client client, Dictionary <string, string> initPayload)
        {
            string   msgInit           = API_KEYWORD_INIT.Substring(0, API_KEYWORD_INIT.Length - 1);
            EscEvent evt               = new EscEvent(msgInit, initPayload);
            string   initPayloadString = evt.ToString();

            WriteToLog(" sending message: " + initPayloadString + " to " + client.Username());
//						LoadSave.savedData.Add (Time.time.ToString () + " : OUT :" + client.Username () + " " + initPayloadString + "\n");
            GameInterface.dispatchEvent(client.Username(), initPayloadString);
        }
示例#5
0
        //! Dispatch a custom Esc Event message to the specified peer
        public int DispatchEventToClient(EscEvent evt, Peer endpoint)
        {
            WriteToLog(" sending message: " + evt.ToString() + " to " + endpoint.Username());

            if (evt.ToString().Length > 256)
            {
                Debug.LogWarning("ServerConnection : DispatchEventToClient EscEvent length exceeds limit!");
            }
            //		LoadSave.savedData.Add (Time.time.ToString () + " : OUT :" + evt.ToString () + "\n");
            return(GameInterface.dispatchEvent(endpoint.Username(), evt.ToString()));
        }
示例#6
0
        /**
         * Invoked by the ESC Launcher application when a Quit action is triggered or when a new game is loaded.
         * Dispatches an event to the plugin which then propagates it to all connected client controllers.
         */
        public void DocentQuitGame(string gameId)
        {
            Dictionary <string, string> dict = new Dictionary <string, string>();

            dict.Add("game", gameId);
            EscEvent evt = new EscEvent("quit", dict);

            GameInterface.dispatchEvent("game-engine", evt.ToString());

            if (null != OnDocentGameEnd)
            {
                OnDocentGameEnd(gameId);
            }
        }
示例#7
0
        //! Dispatches an EscEvent to the game engine to stop game
        public void DocentStopGame(string gameId)
        {
            Dictionary <string, string> dict = new Dictionary <string, string>();

            dict.Add("game", gameId);
            EscEvent evt = new EscEvent("stop", dict);

            GameInterface.dispatchEvent("game-engine", evt.ToString());
            GameInterface.writeLog("stop game");
            if (null != OnDocentGameStop)
            {
                OnDocentGameStop(gameId);
            }
        }
示例#8
0
 //! Command to interface which dispatches start of game event to all controller clients.
 public void StartGame()
 {
     foreach (Client client in this.clients)
     {
         if (!client.IsReady())
         {
             client.SetStatus(5);
             client.SetReadiness(false);
             //	LoadSave.savedData.Add (Time.time.ToString () + " : OUT :" + API_KEYWORD_GAME_END + "\n");
             GameInterface.dispatchEvent(client.Username(), API_KEYWORD_GAME_END);
         }
         else
         {
             //	LoadSave.savedData.Add (Time.time.ToString () + " : OUT :" + API_KEYWORD_GAME_START + "\n");
             GameInterface.dispatchEvent(client.Username(), API_KEYWORD_GAME_START);
         }
     }
 }
示例#9
0
        /**
         * Dispatches a list of parameters to the docent remote control to initialize it
         *
         * @param gameId the unique game name identifier
         * @param mode1 the first mode toggle integer
         * @param mode2 the second mode toggle integer
         * @param mode3 the third mode toggle integer
         * @param param1 the first custom string paramter
         * @param param2 the second custom string paramter
         * @param param3 the third custom string paramter
         *
         * !DEPRECATED!
         */
        public void DocentApplyAdvancedSettings(string gameId, int mode1, int mode2, int mode3, string param1, string param2, string param3)
        {
            Dictionary <string, string> dict = new Dictionary <string, string>();

            dict.Add("game", gameId);
            if (-1 != mode1)
            {
                dict.Add("mode1", mode1.ToString());
            }

            if (-1 != mode2)
            {
                dict.Add("mode2", mode2.ToString());
            }

            if (-1 != mode3)
            {
                dict.Add("mode3", mode3.ToString());
            }

            if ("" != param1)
            {
                dict.Add("param1", param1.ToString());
            }

            if ("" != param1)
            {
                dict.Add("param2", param1.ToString());
            }

            if ("" != param1)
            {
                dict.Add("param3", param1.ToString());
            }

            EscEvent evt = new EscEvent("start", dict);

            GameInterface.dispatchEvent("game-engine", evt.ToString());

            if (null != OnDocentApplyAdvancedSettings)
            {
                OnDocentApplyAdvancedSettings(gameId);
            }
        }
示例#10
0
        /**
         * Dispatches an EscEvent to the game engine to start the game
         *
         * @param gameId the unique game name identifier
         * @param round the round setting to dispatch
         * @param difficulty the difficulty setting to dispatch
         */
        public void DocentStartGame(string gameId, int round, int difficulty)
        {
            Dictionary <string, string> dict = new Dictionary <string, string>();

            dict.Add("game", gameId);
            if (-1 != round)
            {
                dict.Add("round", round.ToString());
            }
            if (-1 != difficulty)
            {
                dict.Add("difficulty", difficulty.ToString());
            }
            EscEvent evt = new EscEvent("start", dict);

            GameInterface.dispatchEvent("game-engine", evt.ToString());

            if (null != OnDocentGameStart)
            {
                OnDocentGameStart(gameId);
            }
        }
示例#11
0
        /**
         * Sends 1-3 parameter strings to the docent remote to serve as acceptable defaults. This provides an opportunity
         * for a game administrator to custom tailor the game experience to the current audience. Each game should document
         * what parameters they are able to accept and what effect those parameters will have so an administrator will know
         * what to expect of their inputs.
         *
         * @param parameter1 the first string option
         * @param parameter2 the optional second string option
         * @param parameter3 the optional third string option
         * @return TRUE if successfully sent, FALSE otherwise
         */
        public bool SubmitParameterStrings(string parameter1, string parameter2 = "", string parameter3 = "")
        {
            bool eventSent = false;

            if (GameInterface.isConnected())
            {
                //	LoadSave.savedData.Add (Time.time.ToString () + " : SubmitParameterStrings \n");
                string options = API_KEYWORD_APPLY_PARAMS + "param1=" + parameter1 + ",param2=" + parameter2 + ",param3=" + parameter3;
                if (0 != GameInterface.dispatchEvent(KEYWORD_DOCENT, options))
                {
                    Debug.LogWarning("parameter strings message delivery failed.");
                }
                else
                {
                    eventSent = true;
                }
            }
            else
            {
                Debug.LogWarning("game not yet connected");
            }

            return(eventSent);
        }
示例#12
0
 /**
  * Dispatches an EscEvent to a controller client without any special attributes.
  *
  * @param client the client to be initialized
  */
 public void InitializeController(Client client)
 {
     GameInterface.dispatchEvent(client.Username(), API_KEYWORD_INIT);
     //				LoadSave.savedData.Add (Time.time.ToString () + " : OUT :" + client.Username () + " " + API_KEYWORD_INIT + "\n");
 }
示例#13
0
        /**
         * Handles any client connection changes that occur during each frame update.
         * If the state listener is connected, it will call its update function.
         * While the Game Server Interface has status changes, it will attempt to reconnect until connection is successful.
         * When TLS is connected, this class's server object will instantiate with its current IP address.
         * While the Game Server Interface has queued presence events, each event will be marshaled based upon the client's identity.
         * If a client is not yet recognized, it is added to the client collection and a registration message containing the
         * game server IP is dispatched to the controller client. If the client already exists, the presence state received is
         * used to determine connectivity status.
         *
         * While the Game Server Interface has queued events, each event will be marshaled to the client object associated
         * with the sender and its message string parsed for either registration, initialization, or generic events, which
         * are then dispatched directly to the game class.
         *
         * Finally, if any client state changes have been made they are propogated to the clients.
         *
         * @see Esc.GameInterface
         * @see Esc.Server
         * @see Esc.StateListener
         */
        public void Update()
        {
            // Go Full Screen after delay
            if (cumulativeTime > launchDelay && !gameFullScreen)
            {
                if (ServerConnection.developerMode)
                {
                    GameInterface.goFullScreenDevMode();
                    WriteToLog("Set Game Full Screen Dev Mode");
                }
                else
                {
                    GameInterface.goFullScreen();
                    WriteToLog("Set Game Full Screen Production Mode");
                }
                gameFullScreen = true;
            }
            else
            {
                cumulativeTime += Time.deltaTime;
            }

            if (this.stateListener != null)
            {
                if (this.stateListener.IsConnected())
                {
                    this.stateListener.Update();
                }
            }

            if (this.willReconnect)
            {
                this.willReconnect = false;
                GameInterface.startServerInterface();
            }

            // process status changes
            while (GameInterface.hasMoreStatusChanges())
            {
                int stat;
                if (0 == GameInterface.getNextStatusChange(out stat))
                {
                    switch (stat)
                    {
                    case 0:                                                             // connected
                        break;

                    case 1:                                                             // TLS connected
                        break;

                    case 2:                                                             // disconnected
                        if (null != OnDisconnected)
                        {
                            OnDisconnected();
                        }
                        if (this.autoReconnect)
                        {
                            willReconnect = true;
                        }


//						if (this.gameStarted){
//							analytics.TrackGameDisconnected();
//						}
                        break;

                    case 3:                                                             // roster loaded;
                        this.server = new Server(KEYWORD_GAME_ENGINE);
                        this.server.SetRemoteEndpoint("127.0.0.1");
                        if (null != OnConnected)
                        {
                            OnConnected();
                        }
                        SendGameLoadedMessageToDocent();
                        //analytics.TrackGameLoad(GetClientRegisteredCount());

                        break;

                    case 4:                                                             // error
                        break;

                    default:
                        break;
                    }
                }
            }

            // process presence events
            while (GameInterface.hasMorePresenceEvents())
            {
                StringBuilder user = new StringBuilder(64);
                int           presence;
                if (0 == GameInterface.getNextPresenceEvent(user, user.Capacity, out presence))
                {
                    uint   index;
                    string username = user.ToString();
                    if (KEYWORD_DOCENT != username && KEYWORD_GAME_LAUNCHER != username)
                    {
                        if (this.clientUsernameMap.ContainsKey(username))
                        {
                            this.clientUsernameMap.TryGetValue(username, out index);
                            if (index >= 0 && clients.Count > 0 && index < clients.Count)
                            {
                                this.clients [(int)index].SetStatus(presence);
                                if (presence == 5)
                                {
                                    DisconnectClient(this.clients [(int)index]);

//									if (this.gameStarted)
//										analytics.TrackControllerDisconnected();
                                }
                                else if (presence == 0 && !this.gameStarted)
                                {
                                    string registrationMessage = API_KEYWORD_REGISTERED + this.serverIpAddress + "," + index.ToString() + "," + this.gameId;
                                    GameInterface.dispatchEvent(username, registrationMessage);
                                    //	LoadSave.savedData.Add (Time.time.ToString () + " : OUT :" + username + " " + registrationMessage + "\n");
                                    WriteToLog(" 1 registering user: "******"," + index.ToString() + "," + this.gameId;
                                GameInterface.dispatchEvent(username, registrationMessage);
                                //	LoadSave.savedData.Add (Time.time.ToString () + " : OUT :" + username + " " + registrationMessage + "\n");
                                WriteToLog(" 2 registering user: "******" : IN :" + username + " " + msgString + "\n");
                    WriteToLog(" " + username + " sent a message: " + msgString);

                    if (username.Equals(KEYWORD_GAME_LAUNCHER))
                    {
                        EscEvent evt             = EscEvent.FromString(msgString);
                        string   requestedGameID = evt.attributes ["game"];

                        if (msgString.StartsWith(API_KEYWORD_START))
                        {
                            if (requestedGameID.Equals(this.gameId))
                            {
                                this.gameStarted    = true;
                                this.gameStartRound = Convert.ToInt32(evt.attributes ["round"]);
                                this.gameDifficulty = Convert.ToInt32(evt.attributes ["difficulty"]);
                                StartGame();
                                OnGameStart(requestedGameID);

                                // track how many total controllers are registered
                                //analytics.TrackGameLoad(GetClientRegisteredCount());

                                // track the round started
                                //analytics.TrackRoundStart(this.gameStartRound.ToString());

                                // track how many total controllers are ready to play the game
                                //analytics.TrackGameStart(GetClientReadyCount ());
                            }
                        }
                        else if (msgString.StartsWith(API_KEYWORD_PAUSE))
                        {
                            if (requestedGameID.Equals(this.gameId))
                            {
                                this.gamePaused = !this.gamePaused;
                                PauseControllers();
                                OnGamePause(requestedGameID);

                                // track game pause
                                //analytics.TrackGamePause(GetClientReadyCount ());
                            }
                        }
                        else if (msgString.StartsWith(API_KEYWORD_STOP))
                        {
                            if (requestedGameID.Equals(this.gameId))
                            {
                                this.gameStarted = false;
                                OnGameStop(requestedGameID);
                                WriteToLog(msgString);

                                // track the round ended
                                //analytics.TrackRoundEnd(this.gameStartRound.ToString());
                            }
                        }
                        else if (msgString.StartsWith(API_KEYWORD_QUIT))
                        {
                            if (requestedGameID.Equals(this.gameId))
                            {
                                this.gameStarted = false;
                                OnGameEnd(requestedGameID);
                                Application.Quit();
                                WriteToLog(msgString);

                                // track game end
                                //analytics.TrackGameEnd(GetClientReadyCount ());
                            }
                        }
                    }
                    else if (!username.Equals(KEYWORD_DOCENT))
                    {
                        if (this.clientUsernameMap.ContainsKey(username))
                        {
                            this.clientUsernameMap.TryGetValue(username, out index);
                            if (index >= clients.Count)
                            {
                                WriteToLog(" " + username + " has an invalid index: " + index.ToString());

                                continue;
                            }
                            if (msgString.StartsWith(API_KEYWORD_REGISTERED))
                            {
                                string ipAddress = msgString.Substring(API_KEYWORD_REGISTERED.Length);
                                this.clients [(int)index].Register(ipAddress);
                                if (null != OnClientRegistered)
                                {
                                    OnClientRegistered(this.clients [(int)index]);
                                }
                            }
                            else if (msgString.StartsWith(API_KEYWORD_INIT))
                            {
                                this.clients [(int)index].SetReadiness(true);
                                if (null != OnClientInitialized)
                                {
                                    OnClientInitialized(this.clients [(int)index], EscEvent.FromString(msgString));
                                }
                            }
                            else
                            {
                                EscEvent evt = EscEvent.FromString(msgString);
                                this.clients [(int)index].AppendEvent(evt);
                            }
                        }
                    }
                    else if (username.Equals(KEYWORD_DOCENT))
                    {
                        if (msgString.StartsWith(API_KEYWORD_APPLY_PARAMS))
                        {
                            // determine which command it is and parse it...
                            EscEvent evt        = EscEvent.FromString(msgString);
                            int      modeParam1 = 0;
                            int      modeParam2 = 0;
                            int      modeParam3 = 0;

                            try {
                                // WARNING: This won't work if mode3 was sent but mode 2 was not
                                modeParam1 = Int32.Parse(evt.attributes ["mode1"]);
                                modeParam2 = Int32.Parse(evt.attributes ["mode2"]);
                                modeParam3 = Int32.Parse(evt.attributes ["mode3"]);
                            } catch {
                                WriteToLog(" error parsing docent parameters ");
                            }

                            // store parameters locally...
                            this.gameStringParameter1 = evt.attributes ["param1"];
                            this.gameStringParameter2 = evt.attributes ["param2"];
                            this.gameStringParameter3 = evt.attributes ["param3"];
                            this.gameModeParameter1   = modeParam1;
                            this.gameModeParameter2   = modeParam2;
                            this.gameModeParameter3   = modeParam3;

                            // notify listeners that a change was applied
                            if (null != OnParametersUpdated)
                            {
                                OnParametersUpdated();
                            }
                        }
                        else if (msgString.StartsWith(KEYWORD_NEXT))
                        {
                            // notify listeners that the next button was pressed
                            if (null != OnNextScreen)
                            {
                                OnNextScreen();
                            }
                        }
                        else if (msgString.StartsWith(KEYWORD_CHECK_IF_LOADED))
                        {
                            string options = API_KEYWORD_GAME_PREVIOUSLY_LOADED + "gameId=" + this.gameId + ",gameStarted=" + this.gameStarted;
                            GameInterface.dispatchEvent(username, options);
                            //							LoadSave.savedData.Add (Time.time.ToString () + " : OUT :" + username + " " + options + "\n");
                        }
                    }
                }
            }

            if (null != this.server && this.server.StateVarsAreStale())
            {
                this.server.PropagateStateVars();
            }
        }