Exemple #1
0
 public new static NewUserPacket FromRaw(RealmData realmData, JObject data)
 {
     return(new NewUserPacket
     {
         user = User.FromRaw(realmData, (JObject)data["user"])
     });
 }
Exemple #2
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);
            }
        }
Exemple #3
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");
        }
Exemple #4
0
        public PhiClient(string address)
        {
            this.address   = address;
            this.realmData = new RealmData();

            PhiClient.instance = this;
        }
Exemple #5
0
 public new static ThingReceivedPacket FromRaw(RealmData realmData, JObject data)
 {
     return(new ThingReceivedPacket
     {
         realmThing = RealmThing.FromRaw(realmData, (JObject)data["realmThing"]),
         userFrom = ID.Find(realmData.users, (int)data["userFrom"])
     });
 }
Exemple #6
0
 public static ChatMessage FromRaw(RealmData realmData, JObject data)
 {
     return(new ChatMessage
     {
         user = ID.Find(realmData.users, data.Value <int>("user")),
         message = data.Value <string>("message")
     });
 }
Exemple #7
0
 public new static UserConnectedPacket FromRaw(RealmData realmData, JObject data)
 {
     return(new UserConnectedPacket
     {
         user = ID.Find(realmData.users, (int)data["user"]),
         connected = (bool)data["connected"]
     });
 }
Exemple #8
0
 public new static SendThingPacket FromRaw(RealmData realmData, JObject data)
 {
     return(new SendThingPacket
     {
         realmThing = RealmThing.FromRaw(realmData, (JObject)data["realmThing"]),
         userTo = ID.Find(realmData.users, (int)data["userTo"])
     });
 }
Exemple #9
0
 public override void Apply(User user, RealmData realmData)
 {
     Console.WriteLine(user.name + " sending " + realmThing.stackCount + "x" + realmThing.thingDefLabel + " to " + userTo.name);
     // We rewire the thing to the targeted user
     realmData.NotifyPacket(userTo, new ThingReceivedPacket {
         userFrom = user, realmThing = realmThing
     });
 }
Exemple #10
0
        public static RealmData FromRaw(JObject data)
        {
            RealmData realmData = new RealmData();

            realmData.users = ((JArray)data["users"]).Select(du => User.FromRaw(realmData, (JObject)du)).ToList();
            realmData.chat  = ((JArray)data["chat"]).Select(du => ChatMessage.FromRaw(realmData, (JObject)du)).ToList();
            return(realmData);
        }
Exemple #11
0
 public new static SynchronisationPacket FromRaw(RealmData realmData, JObject data)
 {
     realmData = RealmData.FromRaw((JObject)data["realmData"]);
     return(new SynchronisationPacket
     {
         realmData = realmData,
         user = ID.Find(realmData.users, (int)data["user"])
     });
 }
 // Token: 0x06000051 RID: 81 RVA: 0x00003B2A File Offset: 0x00001D2A
 public override void Apply(User user, RealmData realmData)
 {
     user.preferences = preferences;
     realmData.BroadcastPacketExcept(new UpdatePreferencesNotifyPacket
     {
         user        = user,
         preferences = preferences
     }, user);
 }
Exemple #13
0
 public static User FromRaw(RealmData realmData, JObject data)
 {
     return(new User {
         id = (int)data["id"],
         name = (string)data["name"],
         connected = (bool)data["connected"],
         inGame = (bool)data["inGame"]
     });
 }
Exemple #14
0
        public static Packet Deserialize(byte[] data, RealmData realmData, User user)
        {
            var context = new RealmContext {
                realmData = realmData, user = user
            };

            var bf = new BinaryFormatter(null, new StreamingContext(StreamingContextStates.All, context));
            var ms = new MemoryStream(data);

            return((Packet)bf.Deserialize(ms));
        }
Exemple #15
0
 public static RealmThing FromRaw(RealmData realmData, JObject data)
 {
     return(new RealmThing
     {
         thingDefLabel = data.Value <string>("thingDefLabel"),
         stuffDefLabel = data.Value <string>("stuffDefLabel"),
         stackCount = data.Value <int>("stackCount"),
         compQuality = data.Value <int>("compQuality"),
         hitPoints = data.Value <int>("hitPoints")
     });
 }
Exemple #16
0
        // No way to set trained skills?

        public static RealmAnimal ToRealmAnimal(Pawn pawn, RealmData realmData)
        {
            string name = pawn.Name.ToStringFull;

            return(new RealmAnimal
            {
                name = name,
                kindDefName = pawn.kindDef.defName,
                ageBiologicalTicks = pawn.ageTracker.AgeBiologicalTicks,
                ageChronologicalTicks = pawn.ageTracker.AgeChronologicalTicks,
                gender = pawn.gender
            });
        }
Exemple #17
0
        public static byte[] Serialize(Packet packet, RealmData realmData, User user)
        {
            var context = new RealmContext {
                realmData = realmData, user = user
            };

            var bf = new BinaryFormatter(null, new StreamingContext(StreamingContextStates.All, context));
            var ms = new MemoryStream();

            bf.Serialize(ms, packet);

            return(ms.ToArray());
        }
Exemple #18
0
        // Token: 0x0600001B RID: 27 RVA: 0x00002370 File Offset: 0x00000570
        public static Packet Deserialize(byte[] data, RealmData realmData, User user)
        {
            var realmContext = new RealmContext
            {
                realmData = realmData,
                user      = user
            };
            var binaryFormatter =
                new BinaryFormatter(null, new StreamingContext(StreamingContextStates.All, realmContext));
            var serializationStream = new MemoryStream(data);

            return((Packet)binaryFormatter.Deserialize(serializationStream));
        }
Exemple #19
0
 // Token: 0x06000008 RID: 8 RVA: 0x00002268 File Offset: 0x00000468
 private void ProcessPacket(Packet packet)
 {
     if (packet is SynchronisationPacket synchronisationPacket)
     {
         realmData   = synchronisationPacket.realmData;
         currentUser = synchronisationPacket.user;
         realmData.PacketToServer += PacketToServerCallback;
         realmData.Log            += Log;
         SaveCredentials();
         OnUsable?.Invoke();
     }
     else
     {
         packet.Apply(currentUser, realmData);
     }
 }
Exemple #20
0
        public override void Apply(User user, RealmData realmData)
        {
            // Is this nick available ?
            if (realmData.users.Any((u) => u.name == name))
            {
                realmData.NotifyPacket(user, new ErrorPacket {
                    error = "Nickname " + name + " is already taken"
                });
                return;
            }

            user.name = name;
            realmData.BroadcastPacket(new ChangeNicknameNotifyPacket {
                user = user, name = name
            });
        }
Exemple #21
0
        public void TryConnect()
        {
            // We clean the old states
            if (this.client != null)
            {
                this.client.Disconnect();
                this.realmData = null;
            }

            this.client                = new Client(this.address, PORT);
            this.client.Connection    += this.ConnectionCallback;
            this.client.Message       += this.MessageCallback;
            this.client.Disconnection += this.DisconnectCallback;

            Log.Message("Try connecting to " + this.address);
            client.Connect();
        }
Exemple #22
0
        public override void Apply(User user, RealmData realmData)
        {
            // We spawn the object with a DropPod
            Log.Message("Drop pod to spawn !");
            Thing thing = realmData.FromRealmThing(realmThing);

            IntVec3 position = DropCellFinder.RandomDropSpot();

            DropPodUtility.DropThingsNear(position, new Thing[] { thing });

            Find.LetterStack.ReceiveLetter(
                "Ship pod",
                "A pod was sent from " + userFrom.name + " containing " + thing.Label,
                LetterType.Good,
                position
                );
        }
Exemple #23
0
        public Pawn FromRealmAnimal(RealmData realmData)
        {
            PawnKindDef kindDef = DefDatabase <PawnKindDef> .GetNamed(kindDefName);

            Pawn pawn = (Pawn)ThingMaker.MakeThing(kindDef.race);

            pawn.kindDef = kindDef;
            pawn.SetFactionDirect(Faction.OfPlayer);
            PawnComponentsUtility.CreateInitialComponents(pawn);
            pawn.gender = gender;

            pawn.ageTracker.AgeBiologicalTicks    = ageBiologicalTicks;
            pawn.ageTracker.AgeChronologicalTicks = ageChronologicalTicks;

            pawn.Name = new NameSingle(name);

            return(pawn);
        }
Exemple #24
0
        public override void Apply(User user, RealmData realmData)
        {
            string filteredName = TextHelper.StripRichText(name, TextHelper.SIZE);

            filteredName = TextHelper.Clamp(filteredName, User.MIN_NAME_LENGTH, User.MAX_NAME_LENGTH);

            // Is this nick available ?
            if (realmData.users.Any((u) => u.name == filteredName))
            {
                realmData.NotifyPacket(user, new ErrorPacket {
                    error = "Nickname " + filteredName + " is already taken"
                });
                return;
            }

            user.name = filteredName;
            realmData.BroadcastPacket(new ChangeNicknameNotifyPacket {
                user = user, name = user.name
            });
        }
Exemple #25
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);
            }
        }
Exemple #26
0
        // Token: 0x0600000A RID: 10 RVA: 0x000020F0 File Offset: 0x000002F0
        public override void Apply(User user, RealmData realmData)
        {
            var filteredName = TextHelper.StripRichText(name, "size");

            filteredName = TextHelper.Clamp(filteredName, 4, 32);
            if (realmData.users.Any(u => u.name == filteredName))
            {
                realmData.NotifyPacket(user, new ErrorPacket
                {
                    error = "Nickname " + filteredName + " is already taken"
                });
                return;
            }

            user.name = filteredName;
            realmData.BroadcastPacket(new ChangeNicknameNotifyPacket
            {
                user = user,
                name = user.name
            });
        }
Exemple #27
0
        public override void Apply(User user, RealmData realmData)
        {
            Dialog_Confirm d = new Dialog_Confirm(error, () => { });

            Find.WindowStack.Add(d);
        }
Exemple #28
0
 // Token: 0x06000005 RID: 5 RVA: 0x00002180 File Offset: 0x00000380
 public void Disconnect()
 {
     client.Disconnect();
     client    = null;
     realmData = null;
 }
Exemple #29
0
 public override void Apply(User user, RealmData realmData)
 {
     // Since Authentification packets are special, they are handled in Programm.cs
 }
Exemple #30
0
 public override void Apply(User user, RealmData realmData)
 {
     realmData.ServerPostMessage(user, this.message);
 }