/** * Overwrites the Awake method in ServerConnection. * Starts the connection interface and load/parse Info.plist * * @see Esc.GameInterface */ public new void Awake() { gamesList = new Dictionary <string, string>(); GameInterface.startLauncherInterface(); GameInterface.setHidden(); this.oscTransmitter = new OscTransmitter(MEDIALON_ENDPOINT_IP, MEDIALON_ENDPOINT_PORT); }
/** * Handles docent connection messages that occur during each frame update. * * @see Esc.ServerConnection */ public new void Update() { // Read games plist every once second if (GameInterface.isConnected()) { if (cumulativeTime > CHECK_GAMES_LIST_INTERVAL) { cumulativeTime = 0.0f; ReadGamesPlist(); } else { cumulativeTime += Time.deltaTime; } } // Dispatch heartbeat ping to Medialon system if necessary if (medialonTime > MEDIALON_PING_INTERVAL) { medialonTime = 0.0f; DispatchMedialonPing(); } else { medialonTime += Time.deltaTime; } // Reconnect if necessary if (this.willReconnect) { this.willReconnect = false; GameInterface.startLauncherInterface(); } while (GameInterface.hasMoreStatusChanges()) { int stat; if (0 == GameInterface.getNextStatusChange(out stat)) { switch (stat) { case 0: // connected //GameInterface.writeLog("socket connection established"); break; case 1: // TLS connected break; case 2: // disconnected if (null != OnDisconnected) { OnDisconnected(); } if (this.autoReconnect) { willReconnect = true; } break; case 3: // roster loaded; if (null != OnConnected) { OnConnected(); } break; case 4: // error break; default: break; } } } while (GameInterface.hasMoreEvents()) { StringBuilder user = new StringBuilder(64); StringBuilder message = new StringBuilder(256); if (user == null || user.Capacity == null || message == null || message.Capacity == null) { return; } if (0 == GameInterface.getNextEvent(user, (uint)user.Capacity, message, (uint)message.Capacity)) { string username = user.ToString(); string msgString = message.ToString(); if (username.Equals("docent")) { if (msgString.StartsWith(API_KEYWORD_GAME)) { EscEvent evt = EscEvent.FromString(msgString); //Debug.Log("message: " + msgString); string gameIdValue = ""; string option = ""; int round = -1; int difficulty = -1; //! advance settings strings int mode1 = -1; int mode2 = -1; int mode3 = -1; string param1 = ""; string param2 = ""; string param3 = ""; foreach (KeyValuePair <string, string> pair in evt.attributes) { switch (pair.Key) { case "game": gameIdValue = pair.Value; break; case "option": option = pair.Value; break; case "round": round = Convert.ToInt32(pair.Value); break; case "difficulty": difficulty = Convert.ToInt32(pair.Value); break; case "mode1": mode1 = Convert.ToInt32(pair.Value); break; case "mode2": mode2 = Convert.ToInt32(pair.Value); break; case "mode3": mode3 = Convert.ToInt32(pair.Value); break; case "param1": param1 = pair.Value; break; case "param2": param2 = pair.Value; break; case "param3": param3 = pair.Value; break; } } switch (option) { case "load": if (!this.currentLoadedGame.Equals("")) { DocentQuitGame(this.currentLoadedGame); } this.currentLoadedGame = gameIdValue; DocentLoadGame(gameIdValue); break; case "start": DocentStartGame(gameIdValue, round, difficulty); break; case "pause": DocentPauseGame(gameIdValue); break; case "stop": DocentStopGame(gameIdValue); break; case "apply": DocentApplyAdvancedSettings(gameIdValue, mode1, mode2, mode3, param1, param2, param3); break; case "quit": DocentQuitGame(gameIdValue); break; } } else if (msgString.StartsWith(API_KEYWORD_INIT)) { UpdateDocentGamesList(); } } } } }