Inheritance: VMSerializable
示例#1
0
 public override void OnPacket(NetworkClient client, ProcessedPacket packet)
 {
     var cmd = new VMNetCommand();
     try {
         using (var reader = new BinaryReader(packet)) {
             cmd.Deserialize(reader);
         }
     } catch (Exception)
     {
         ClientsToDC.Add(client);
         return;
     }
     if (cmd.Type == VMCommandType.SimJoin)
     {
         if (((VMNetSimJoinCmd)cmd.Command).Version != VMNetSimJoinCmd.CurVer)
         {
             ClientsToDC.Add(client);
             return;
         }
         lock (UIDs)
         {
             UIDs.Add(client, ((VMNetSimJoinCmd)cmd.Command).SimID);
         }
     }
     SendCommand(cmd.Command);
 }
示例#2
0
        public void Deserialize(BinaryReader reader)
        {
            TickID = reader.ReadUInt32();
            RandomSeed = reader.ReadUInt64();

            Commands = new List<VMNetCommand>();
            int length = reader.ReadInt32();
            for (int i=0; i<length; i++)
            {
                var cmd = new VMNetCommand();
                cmd.Deserialize(reader);
                Commands.Add(cmd);
            }
        }
        public void Deserialize(BinaryReader reader)
        {
            TickID     = reader.ReadUInt32();
            RandomSeed = reader.ReadUInt64();

            Commands = new List <VMNetCommand>();
            int length = reader.ReadInt32();

            for (int i = 0; i < length; i++)
            {
                var cmd = new VMNetCommand();
                cmd.Deserialize(reader);
                Commands.Add(cmd);
            }
        }
示例#4
0
 private void SendToServer(VMNetCommandBodyAbstract cmd)
 {
     byte[] data;
     using (var stream = new MemoryStream())
     {
         var cmd2 = new VMNetCommand(cmd);
         using (var writer = new BinaryWriter(stream))
         {
             cmd2.SerializeInto(writer);
         }
         data = stream.ToArray();
     }
     using (var stream = new PacketStream((byte)PacketType.VM_PACKET, 0))
     {
         stream.WriteHeader();
         stream.WriteInt32(data.Length + (int)PacketHeaders.UNENCRYPTED);
         stream.WriteBytes(data);
         Client.Send(stream.ToArray());
     }
 }
示例#5
0
        private void SendState(VM vm)
        {
            if (ClientsToSync.Count == 0) return;
            //Console.WriteLine("== SERIAL: Sending State to Client... ==");

            var watch = new Stopwatch();
            watch.Start();

            var state = vm.Save();
            //Console.WriteLine("== STATE: Intermediate - after save... " + watch.ElapsedMilliseconds + " ms. ==");
            var cmd = new VMNetCommand(new VMStateSyncCmd { State = state });

            //currently just hack this on the tick system. will change when we switch to not gonzonet
            var ticks = new VMNetTickList { Ticks = new List<VMNetTick> {
                new VMNetTick {
                    Commands = new List<VMNetCommand> { cmd },
                    RandomSeed = 0, //will be restored by client from cmd
                    TickID = TickID
                }
            } };

            byte[] data;
            using (var stream = new MemoryStream())
            {
                //Console.WriteLine("== STATE: Intermediate - before serialize... " + watch.ElapsedMilliseconds + " ms. ==");
                using (var writer = new BinaryWriter(stream))
                {
                    ticks.SerializeInto(writer);
                }

                //Console.WriteLine("== STATE: Intermediate - before toArray... " + watch.ElapsedMilliseconds + " ms. ==");
                data = stream.ToArray();
            }
            //Console.WriteLine("== STATE: Intermediate - before send... " + watch.ElapsedMilliseconds + " ms. ==");

            byte[] packet;

            using (var stream = new PacketStream((byte)PacketType.VM_PACKET, 0))
            {
                stream.WriteHeader();
                stream.WriteInt32(data.Length + (int)PacketHeaders.UNENCRYPTED);
                stream.WriteBytes(data);

                packet = stream.ToArray();
            }
            foreach (var client in ClientsToSync) client.Send(packet);
            ClientsToSync.Clear();

            watch.Stop();
            //Console.WriteLine("== SERIAL: DONE! State send took "+watch.ElapsedMilliseconds+" ms. ==");
        }
示例#6
0
        public override void OnPacket(NetworkClient client, ProcessedPacket packet)
        {
            var cmd = new VMNetCommand();
            try {
                using (var reader = new BinaryReader(packet)) {
                    cmd.Deserialize(reader);
                }
            } catch (Exception)
            {
                ClientsToDC.Add(client);
                return;
            }

            if (cmd.Type == VMCommandType.SimJoin)
            {
                if (SandboxBans.Contains(client.RemoteIP))
                {
                    SendGenericMessage(client, "Banned", "You have been banned from this sandbox server!");
                    ClientsToDC.Add(client);
                    return;
                }
                else if (((VMNetSimJoinCmd)cmd.Command).Version != VMNetSimJoinCmd.CurVer)
                {
                    SendGenericMessage(client, "Version Mismatch", "Your game version does not match the server's. Please update your game.");
                    ClientsToDC.Add(client);
                    return;
                }

                ((VMNetSimJoinCmd)cmd.Command).Ticket = client.RemoteIP+":"+((VMNetSimJoinCmd)cmd.Command).Name;
                ((VMNetSimJoinCmd)cmd.Command).Client = client; //remember client so we can bind it to persist id later
                SendCommand(cmd.Command); //just go for it. will start the avatar retrieval process.
                return;
            }
            else if (cmd.Type == VMCommandType.RequestResync)
            {
                lock (ClientsToSync)
                {
                    //todo: throttle
                    ClientsToSync.Add(client);
                }
            }

            lock (ClientToUID)
            {
                if (!ClientToUID.ContainsKey(client)) return; //client hasn't registered yet
                cmd.Command.ActorUID = ClientToUID[client];
            }
            SendCommand(cmd.Command);
        }
示例#7
0
        private void SendState(VM vm)
        {
            if (ClientsToSync.Count == 0) return;
            var state = vm.Save();
            var cmd = new VMNetCommand(new VMStateSyncCmd { State = state });

            //currently just hack this on the tick system. will change when we switch to not gonzonet
            var ticks = new VMNetTickList { Ticks = new List<VMNetTick> {
                new VMNetTick {
                    Commands = new List<VMNetCommand> { cmd },
                    RandomSeed = 0, //will be restored by client from cmd
                    TickID = TickID
                }
            } };

            byte[] data;
            using (var stream = new MemoryStream())
            {
                using (var writer = new BinaryWriter(stream))
                {
                    ticks.SerializeInto(writer);
                }

                data = stream.ToArray();
            }

            using (var stream = new PacketStream((byte)PacketType.VM_PACKET, 0))
            {
                stream.WriteHeader();
                stream.WriteInt32(data.Length + (int)PacketHeaders.UNENCRYPTED);
                stream.WriteBytes(data);

                var packet = stream.ToArray();

                foreach (var client in ClientsToSync) client.Send(packet);
            }
            ClientsToSync.Clear();
        }