Beispiel #1
0
 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);
        }
Beispiel #3
0
        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);
        }
Beispiel #4
0
        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);
        }
Beispiel #5
0
        private void processHandshakeData(JsonData msg)
        {
            //Handshake error
            if (!msg.ContainsKey("code") || !msg.ContainsKey("sys") || Convert.ToInt32(msg["code"].ToString()) != 200)
            {
                throw new Exception("Handshake error! Please check your handshake config.");
            }
            //Debug.Log(msg.ToJson());

            //Set compress data
            JsonData sys = (JsonData)msg["sys"];


            //Init heartbeat service
            int interval = 0;

            if (sys.ContainsKey("heartbeat"))
            {
                interval = Convert.ToInt32(sys["heartbeat"].ToString());
            }
            heartBeatService = new HeartBeatService(interval, this);

            if (interval > 0)
            {
                heartBeatService.start();
            }

            this.InitProtoCache(sys);

            //send ack and change protocol state
            handshake.ack();
            this.state = ProtocolState.working;

            //Invoke handshake callback
            JsonData user = new JsonData();

            if (msg.ContainsKey("user"))
            {
                user = (JsonData)msg["user"];
            }
            handshake.invokeCallback(user);
        }
        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);
        }
        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);
        }
Beispiel #8
0
        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);
        }