Inheritance: VMSerializable
示例#1
0
        protected void InternalTick(VM vm, VMNetTick tick)
        {
            if (!tick.ImmediateMode && (tick.Commands.Count == 0 || !(tick.Commands[0].Command is VMStateSyncCmd)) && vm.Context.RandomSeed != tick.RandomSeed)
            {
                if (DesyncCooldown == 0)
                {
                    System.Console.WriteLine("DESYNC - Requested state from host");
                    vm.SendCommand(new VMRequestResyncCmd());
                    DesyncCooldown = 30 * 3;
                } else
                {
                    System.Console.WriteLine("WARN - DESYNC - Too soon to try again!");
                }
                ExceptionOnDesync = true;
            }
            vm.Context.RandomSeed = tick.RandomSeed;
            bool doTick = !tick.ImmediateMode;
            foreach(var cmd in tick.Commands)
            {
                if (cmd.Command is VMStateSyncCmd) doTick = false;

                var caller = vm.GetObjectByPersist(cmd.Command.ActorUID);
                if (!(caller is VMAvatar)) caller = null;
                cmd.Command.Execute(vm, (VMAvatar)caller);
            }
            if (doTick && vm.Context.Ready)
            {
                vm.InternalTick();
                if (DesyncCooldown > 0) DesyncCooldown--;
            }
        }
示例#2
0
 public void Deserialize(BinaryReader reader)
 {
     Ticks = new List<VMNetTick>();
     int length = reader.ReadInt32();
     for (int i=0; i<length; i++)
     {
         var cmds = new VMNetTick();
         cmds.Deserialize(reader);
         Ticks.Add(cmds);
     }
 }
示例#3
0
        public void Deserialize(BinaryReader reader)
        {
            Ticks = new List <VMNetTick>();
            int length = reader.ReadInt32();

            for (int i = 0; i < length; i++)
            {
                var cmds = new VMNetTick();
                cmds.Deserialize(reader);
                Ticks.Add(cmds);
            }
        }
示例#4
0
 protected void InternalTick(VM vm, VMNetTick tick)
 {
     if (vm.Context.RandomSeed != tick.RandomSeed)
     {
         System.Console.WriteLine("WARN! desync, tick wrong: " + vm.Context.RandomSeed + " != " + tick.RandomSeed);
         //if (ExceptionOnDesync) throw new Exception("desync, tick wrong: " + vm.Context.RandomSeed + " != " + tick.RandomSeed);
         ExceptionOnDesync = true;
     }
     vm.Context.RandomSeed = tick.RandomSeed;
     bool doTick = true;
     foreach(var cmd in tick.Commands)
     {
         if (cmd.Command is VMStateSyncCmd) doTick = false;
         cmd.Command.Execute(vm);
     }
     if (doTick) vm.InternalTick();
 }
示例#5
0
        //uh, this is a little silly.
        private void SendOneOff(NetworkClient client, VMNetTick tick)
        {
            var ticks = new VMNetTickList { Ticks = new List<VMNetTick>() { tick }, ImmediateMode = true };
            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);
                client.Send(stream.ToArray());
            }
        }
示例#6
0
        public override bool Tick(VM vm)
        {
            HandleClients();

            lock (QueuedCmds) {
                //verify the queued commands. Remove ones which fail (or defer til later)
                for (int i=0; i<QueuedCmds.Count; i++)
                {
                    var caller = vm.GetObjectByPersist(QueuedCmds[i].Command.ActorUID);
                    if (!(caller is VMAvatar)) caller = null;
                    if (!QueuedCmds[i].Command.Verify(vm, (VMAvatar)caller)) QueuedCmds.RemoveAt(i--);
                    else if (QueuedCmds[i].Type == VMCommandType.SimJoin)
                    {
                        var cmd = (VMNetSimJoinCmd)QueuedCmds[i].Command;
                        if (cmd.Client != null)
                        {
                            lock (ClientToUID)
                            {
                                ClientToUID.Add(cmd.Client, cmd.ActorUID);
                                UIDtoClient.Add(cmd.ActorUID, cmd.Client);
                            }
                        }
                    }
                }

                var tick = new VMNetTick();
                tick.Commands = new List<VMNetCommand>(QueuedCmds);
                tick.TickID = TickID++;
                tick.RandomSeed = vm.Context.RandomSeed;
                QueuedCmds.Clear();
                InternalTick(vm, tick);

                TickBuffer.Add(tick);
                if (TickBuffer.Count >= TICKS_PER_PACKET)
                {
                    lock (ClientsToSync)
                    {
                        SendTickBuffer();
                        SendState(vm);
                    }
                }
            }

            return true;
        }
示例#7
0
        public override bool Tick(VM vm)
        {
            HandleClients();

            lock (QueuedCmds) {
                var tick = new VMNetTick();
                tick.Commands = new List<VMNetCommand>(QueuedCmds);
                tick.TickID = TickID++;
                tick.RandomSeed = vm.Context.RandomSeed;

                InternalTick(vm, tick);
                QueuedCmds.Clear();

                TickBuffer.Add(tick);
                if (TickBuffer.Count >= TICKS_PER_PACKET)
                {
                    lock (ClientsToSync)
                    {
                        SendTickBuffer();
                        SendState(vm);
                    }
                }
            }

            return true;
        }