コード例 #1
0
        private void ProcessPacket(Packet packet)
        {
            if (packet is SynchronisationPacket)
            {
                // This is the first packet that we receive
                // It contains all the data of the server
                SynchronisationPacket syncPacket = (SynchronisationPacket)packet;

                this.realmData   = syncPacket.realmData;
                this.currentUser = syncPacket.user;

                this.realmData.PacketToServer += PacketToServerCallback;
                this.realmData.Log            += Log;

                SaveCredentials();

                if (OnUsable != null)
                {
                    OnUsable();
                }
            }
            else
            {
                packet.Apply(this.currentUser, this.realmData);
            }
        }
コード例 #2
0
        public static Packet FromRaw(RealmData realmData, JObject data)
        {
            string classType = (string)data["type"];

            switch (classType)
            {
            case AuthentificationPacket.TYPE_CLASS:
                return(AuthentificationPacket.FromRaw(realmData, data));

            case PostMessagePacket.TYPE_CLASS:
                return(PostMessagePacket.FromRaw(realmData, data));

            case SynchronisationPacket.TYPE_CLASS:
                return(SynchronisationPacket.FromRaw(realmData, data));

            case ChatMessagePacket.TYPE_CLASS:
                return(ChatMessagePacket.FromRaw(realmData, data));

            case NewUserPacket.TYPE_CLASS:
                return(NewUserPacket.FromRaw(realmData, data));

            case UserConnectedPacket.TYPE_CLASS:
                return(UserConnectedPacket.FromRaw(realmData, data));

            case ThingReceivedPacket.TYPE_CLASS:
                return(ThingReceivedPacket.FromRaw(realmData, data));

            case SendThingPacket.TYPE_CLASS:
                return(SendThingPacket.FromRaw(realmData, data));
            }

            throw new Exception("Packet type not found");
        }
コード例 #3
0
        private void MessageCallback(string data)
        {
            Packet packet = Packet.FromRaw(this.realmData, JObject.Parse(data));

            Log.Message("Received packet from server: " + packet);

            if (packet is SynchronisationPacket)
            {
                // This is the first packet that we receive
                // It contains all the data of the server
                SynchronisationPacket syncPacket = (SynchronisationPacket)packet;

                this.realmData   = syncPacket.realmData;
                this.currentUser = syncPacket.user;
            }
            else
            {
                packet.Apply(this.currentUser, this.realmData);
            }
        }