private void processHandshakeData(JsonObject msg) { if (!msg.ContainsKey("code") || !msg.ContainsKey("sys") || Convert.ToInt32(msg["code"]) != 200) throw new Exception("Handshake error! Please check your handshake config."); JsonObject jsonObject1 = (JsonObject)msg["sys"]; JsonObject dict = new JsonObject(); if (jsonObject1.ContainsKey("dict")) dict = (JsonObject)jsonObject1["dict"]; JsonObject jsonObject2 = new JsonObject(); JsonObject serverProtos = new JsonObject(); JsonObject clientProtos = new JsonObject(); if (jsonObject1.ContainsKey("protos")) { JsonObject jsonObject3 = (JsonObject)jsonObject1["protos"]; serverProtos = (JsonObject)jsonObject3["server"]; clientProtos = (JsonObject)jsonObject3["client"]; } this.messageProtocol = new MessageProtocol(dict, serverProtos, clientProtos); int interval = 0; if (jsonObject1.ContainsKey("heartbeat")) interval = Convert.ToInt32(jsonObject1["heartbeat"]); this.heartBeatService = new HeartBeatService(interval, this); if (interval > 0) this.heartBeatService.start(); this.handshake.ack(); this.state = ProtocolState.working; JsonObject data = new JsonObject(); if (msg.ContainsKey("user")) data = (JsonObject)msg["user"]; this.handshake.invokeCallback(data); }
private void processHandshakeData(JsonObject msg) { //Handshake error if (!msg.ContainsKey("code") || !msg.ContainsKey("sys") || Convert.ToInt32(msg["code"]) != 200) { throw new Exception("Handshake error! Please check your handshake config."); } Trace.TraceInformation("processHandshakeData"); //Set compress data JsonObject sys = (JsonObject)msg["sys"]; JsonObject dict = new JsonObject(); if (sys.ContainsKey("dict")) { dict = (JsonObject)sys["dict"]; } JsonObject protos = new JsonObject(); JsonObject serverProtos = new JsonObject(); JsonObject clientProtos = new JsonObject(); if (sys.ContainsKey("protos")) { protos = (JsonObject)sys["protos"]; serverProtos = (JsonObject)protos["server"]; clientProtos = (JsonObject)protos["client"]; } messageProtocol = new MessageProtocol(dict, serverProtos, clientProtos); //Init heartbeat service int interval = 0; if (sys.ContainsKey("heartbeat")) { interval = Convert.ToInt32(sys["heartbeat"]); Trace.TraceInformation("heartbeat = " + interval); } heartBeatService = new HeartBeatService(interval, this); if (interval > 0) { heartBeatService.start(); } //send ack and change protocol state handshake.ack(); this.state = ProtocolState.working; //Invoke handshake callback JsonObject user = new JsonObject(); if (msg.ContainsKey("user")) { user = (JsonObject)msg["user"]; } handshake.invokeCallback(user); }
private void processHandshakeData(JsonNode msg) { //Handshake error if (!msg.ContainsKey("code") || !msg.ContainsKey("sys") || msg["code"].AsInt != 200) { UnityEngine.Debug.LogError("Handshake error! Please check your handshake config."); } //Set compress data JsonNode sys = msg["sys"]; JsonNode dict = new JsonClass(); if (sys.ContainsKey("dict")) { dict = sys["dict"]; } JsonNode protos = new JsonClass(); JsonNode serverProtos = new JsonClass(); JsonNode clientProtos = new JsonClass(); if (sys.ContainsKey("protos")) { protos = sys["protos"]; serverProtos = protos["server"]; clientProtos = protos["client"]; } messageProtocol = new MessageProtocol(dict, serverProtos, clientProtos); //Init heartbeat service int interval = 0; if (sys.ContainsKey("heartbeat")) { interval = sys["heartbeat"].AsInt; } heartBeatService = new HeartBeatService(interval, this); if (interval > 0) { heartBeatService.start(); } //send ack and change protocol state handshake.ack(); this.state = ProtocolState.working; //Invoke handshake callback JsonNode user = new JsonClass(); if (msg.ContainsKey("user")) { user = msg["user"]; } handshake.invokeCallback(user); }
private void processHandshakeData(JsonObject msg) { if ((!msg.ContainsKey("code") || !msg.ContainsKey("sys")) || (Convert.ToInt32(msg["code"]) != 200)) { throw new Exception("Handshake error! Please check your handshake config."); } JsonObject obj2 = (JsonObject)msg["sys"]; JsonObject dict = new JsonObject(); if (obj2.ContainsKey("dict")) { dict = (JsonObject)obj2["dict"]; } JsonObject obj4 = new JsonObject(); JsonObject serverProtos = new JsonObject(); JsonObject clientProtos = new JsonObject(); if (obj2.ContainsKey("protos")) { obj4 = (JsonObject)obj2["protos"]; serverProtos = (JsonObject)obj4["server"]; clientProtos = (JsonObject)obj4["client"]; } this.messageProtocol = new MessageProtocol(dict, serverProtos, clientProtos); int timeout = 0; if (obj2.ContainsKey("heartbeat")) { timeout = Convert.ToInt32(obj2["heartbeat"]); } this.heartBeatService = new HeartBeatService(timeout, this); if (timeout > 0) { this.heartBeatService.start(); } this.handshake.ack(); this.state = ProtocolState.working; JsonObject data = new JsonObject(); if (msg.ContainsKey("user")) { data = (JsonObject)msg["user"]; } this.handshake.invokeCallback(data); }
private void processHandshakeData(JsonObject msg) { //Handshake error if(!msg.ContainsKey("code") || !msg.ContainsKey("sys") || Convert.ToInt32(msg["code"]) != 200){ throw new Exception("Handshake error! Please check your handshake config."); } //Set compress data JsonObject sys = (JsonObject)msg["sys"]; JsonObject dict = new JsonObject(); if(sys.ContainsKey("dict")) dict = (JsonObject)sys["dict"]; JsonObject protos = new JsonObject(); JsonObject serverProtos = new JsonObject(); JsonObject clientProtos = new JsonObject(); if(sys.ContainsKey("protos")){ protos = (JsonObject)sys["protos"]; serverProtos = (JsonObject)protos["server"]; clientProtos = (JsonObject)protos["client"]; } messageProtocol = new MessageProtocol (dict, serverProtos, clientProtos); //Init heartbeat service int interval = 0; if(sys.ContainsKey("heartbeat")) interval = Convert.ToInt32(sys["heartbeat"]); heartBeatService = new HeartBeatService(interval, this); if(interval > 0){ heartBeatService.start(); } //send ack and change protocol state handshake.ack(); this.state = ProtocolState.working; //Invoke handshake callback JsonObject user = new JsonObject(); if(msg.ContainsKey("user")) user = (JsonObject)msg["user"]; handshake.invokeCallback(user); }
public static void protocolProcess(byte[] bytes) { JsonObject dict = new JsonObject(); JsonObject serverProtos = new JsonObject(); JsonObject clientProtos = new JsonObject(); MessageProtocol messageProtocol = new MessageProtocol(dict, serverProtos, clientProtos); Package pkg = PackageProtocol.decode(bytes); messageProtocol.decode(pkg.body); }
private void InitProtoCache(JsonData sys) { JsonData dict = new JsonData(); //JsonData routeToCode = new JsonData(); //JsonData codeToRoute = new JsonData(); if (sys.ContainsKey("dict")) { dict = (JsonData)sys["dict"]; } //if (sys.ContainsKey("routeToCode")) routeToCode = (JsonData)sys["routeToCode"]; //if (sys.ContainsKey("codeToRoute")) codeToRoute = (JsonData)sys["codeToRoute"]; string dictVersion = ""; if (sys.ContainsKey("dictVersion")) { dictVersion = sys["dictVersion"].ToString(); } JsonData protos = new JsonData(); JsonData serverProtos = new JsonData(); JsonData clientProtos = new JsonData(); string protoVersion = ""; if (sys.ContainsKey("protos")) { protos = (JsonData)sys["protos"]; serverProtos = (JsonData)protos["server"]; clientProtos = (JsonData)protos["client"]; if (protos.ContainsKey("version")) { protoVersion = protos["version"].ToString(); } } if (messageProtocol != null) { if ((dictVersion != "" && messageProtocol.dictVersion != dictVersion) || (protoVersion != "" && messageProtocol.protoVersion != protoVersion)) { //update cache JsonData sysNew = JsonMapper.ToObject(this.HandShakeCache); if (sys.ContainsKey("dict")) { sysNew["dict"] = new JsonData(); sysNew["dict"] = sys["dict"]; } if (sys.ContainsKey("dictVersion")) { sysNew["dictVersion"] = sys["dictVersion"]; } if (sys.ContainsKey("protos")) { sysNew["protos"] = new JsonData(); sysNew["protos"] = sys["protos"]; } this.HandShakeCache = sysNew.ToJson(); this.messageProtocol = null; this.InitProtoCache(this.HandShakeCache); //MessageProtocol messageProtocolNew = new MessageProtocol(dict, serverProtos, clientProtos, dictVersion, protoVersion); //if (dictVersion == "" && !sys.ContainsKey("dict")) //{ // messageProtocolNew.dict = messageProtocol.dict; // messageProtocolNew.abbrs = messageProtocol.abbrs; // messageProtocolNew.dictVersion = messageProtocol.dictVersion; //} //if(protoVersion == "" && !sys.ContainsKey("protos")) //{ // messageProtocolNew.encodeProtos = messageProtocol.encodeProtos; // messageProtocolNew.decodeProtos = messageProtocol.decodeProtos; // messageProtocolNew.protoVersion = messageProtocol.protoVersion; //} //messageProtocol = messageProtocolNew; } } else { messageProtocol = new MessageProtocol(dict, serverProtos, clientProtos, dictVersion, protoVersion); this.HandShakeCache = sys.ToJson(); } }
private void ProcessHandshakeData(JsonObject msg) { // Handshake error if (!msg.ContainsKey("code") || !msg.ContainsKey("sys") || Convert.ToInt32(msg["code"]) != 200) { throw new Exception("Handshake error! Please check your handshake config."); } // Set compress data JsonObject sys = (JsonObject)msg["sys"]; JsonObject dict = new JsonObject(); if (sys.ContainsKey("useDict")) { if (sys.ContainsKey("dict")) { dict = (JsonObject)sys["dict"]; PlayerPrefs.SetString("PomeloDict", dict.ToString()); } else { dict = SimpleJson.SimpleJson.DeserializeObject <JsonObject>(PlayerPrefs.GetString("PomeloDict")); } } JsonObject protos = new JsonObject(); JsonObject serverProtos = new JsonObject(); JsonObject clientProtos = new JsonObject(); if (sys.ContainsKey("useProto")) { if (sys.ContainsKey("protos")) { protos = (JsonObject)sys["protos"]; serverProtos = (JsonObject)protos["server"]; clientProtos = (JsonObject)protos["client"]; PlayerPrefs.SetString("PomeloServerProtos", serverProtos.ToString()); PlayerPrefs.SetString("PomeloClientProtos", clientProtos.ToString()); } else { serverProtos = SimpleJson.SimpleJson.DeserializeObject <JsonObject>(PlayerPrefs.GetString("PomeloServerProtos")); clientProtos = SimpleJson.SimpleJson.DeserializeObject <JsonObject>(PlayerPrefs.GetString("PomeloClientProtos")); } } this.messageProtocol = new MessageProtocol(dict, serverProtos, clientProtos); // Init heartbeat service int interval = 0; if (sys.ContainsKey("heartbeat")) { interval = Convert.ToInt32(sys["heartbeat"]); } this.heartBeatService = new HeartBeatService(interval, this); if (interval > 0) { this.heartBeatService.Start(); } // send ack and change protocol state this.handshake.Ack(); this.state = ProtocolState.working; // Invoke handshake callback JsonObject user = new JsonObject(); if (msg.ContainsKey("user")) { user = (JsonObject)msg["user"]; } this.handshake.InvokeCallback(user); }
private void processHandshakeData(JSONNode msg) { Debug.Log(msg.GetType().ToString() + "THE MESSAGE:" + msg.ToString()); //Handshake error if (!msg.ContainsKey("code") || !msg.ContainsKey("sys") || Convert.ToInt32(msg["code"]) != 200) { throw new Exception("Handshake error! Please check your handshake config."); } //Set compress data JSONNode sys = msg["sys"]; JSONNode dict = new JSONNode(); if (sys.ContainsKey("dict")) { dict = sys["dict"]; } JSONClass protos = new JSONClass(); JSONClass serverProtos = new JSONClass(); JSONClass clientProtos = new JSONClass(); if (sys.ContainsKey("protos")) { protos.Add(sys["protos"]); serverProtos.Add(protos["server"]); clientProtos.Add(protos["client"]); //protos = (JSONClass)sys["protos"]; //serverProtos = (JSONClass)protos["server"]; //clientProtos = (JSONClass)protos["client"]; } messageProtocol = new MessageProtocol(dict, serverProtos, clientProtos); //messageProtocol = new MessageProtocol(msg["sys"]["dict"],msg["protos"]["server"],msg["protos"]["client"]); //Init heartbeat service int interval = 0; if (msg["sys"].ContainsKey("heartbeat")) { interval = Convert.ToInt32(msg["sys"]["heartbeat"]); } heartBeatService = new HeartBeatService(interval, this); if (interval > 0) { heartBeatService.start(); } //send ack and change protocol state handshake.ack(); this.state = ProtocolState.working; //Invoke handshake callback JSONClass user = new JSONClass(); if (msg.ContainsKey("user")) { user.Add(msg["user"]); } handshake.invokeCallback(user); }