Exemplo n.º 1
0
    public static PlayerTick Deserialize(Stream stream)
    {
        PlayerTick playerTick = Pool.Get <PlayerTick>();

        PlayerTick.Deserialize(stream, playerTick, false);
        return(playerTick);
    }
Exemplo n.º 2
0
 public static PlayerTick Deserialize(byte[] buffer, PlayerTick instance, bool isDelta = false)
 {
     using (MemoryStream memoryStream = new MemoryStream(buffer))
     {
         PlayerTick.Deserialize(memoryStream, instance, isDelta);
     }
     return(instance);
 }
Exemplo n.º 3
0
    public static PlayerTick Deserialize(byte[] buffer)
    {
        PlayerTick playerTick = Pool.Get <PlayerTick>();

        using (MemoryStream memoryStream = new MemoryStream(buffer))
        {
            PlayerTick.Deserialize(memoryStream, playerTick, false);
        }
        return(playerTick);
    }
Exemplo n.º 4
0
//        private int spend = 0;
        public bool OnTick(Message packet)
        {
            using (PlayerTick playerTick = PlayerTick.Deserialize(packet.read, previousRecievedTick, true))
            {
                previousRecievedTick = playerTick.Copy();
                ViewAngles           = playerTick.inputState.aimAngles;
                EyePos = playerTick.eyePos;
//                spend++;
//                if (spend < 8)
//                {
//                    return true;
//                }
//                spend = 0;

                if (IsServerAdmin)
                {
                    return(false);
                }
                if (playerTick.modelState.flying)
                {
                    playerTick.modelState.flying = false;

                    lastFlying = true;
                }
                else
                {
                    if (lastFlying)
                    {
                        previousTick.modelState.flying = true;
                    }
                    lastFlying = false;
                }


                if (VirtualServer.BaseClient.write.Start())
                {
                    VirtualServer.BaseClient.write.PacketID(Message.Type.Tick);
                    playerTick.WriteToStreamDelta(VirtualServer.BaseClient.write, previousTick);
                    previousTick = playerTick.Copy();

                    VirtualServer.BaseClient.Send();
                }
                return(true);
            }
        }
Exemplo n.º 5
0
        public void OnReceivedTick(Message _message)
        {
            bool needUpdateFlags = false;

            PlayerTick msg = PlayerTick.Deserialize(_message.read, this.m_lastPlayerTickPacket, true);

            this.PlayerOwner.PlayerButtons = (E_PlayerButton)msg.inputState.buttons;
            if (ModelState.Equal(this.PlayerOwner.PlayerModelState, msg.modelState) == false)
            {
                this.PlayerOwner.PlayerModelState = msg.modelState;
                needUpdateFlags = true;
            }

            if (this.PlayerOwner.IsSleeping)
            {
                if (this.PlayerOwner.HasPlayerButton(E_PlayerButton.FIRE_PRIMARY) || this.PlayerOwner.HasPlayerButton(E_PlayerButton.FIRE_SECONDARY) || this.PlayerOwner.HasPlayerButton(E_PlayerButton.JUMP))
                {
                    this.PlayerOwner.SetPlayerFlag(E_PlayerFlags.Sleeping, false);
                    needUpdateFlags = true;
                }
            }
            else
            {
                if ((this.PlayerOwner.ActiveItem?.UID ?? 0) != msg.activeItem)
                {
                    this.PlayerOwner.OnChangeActiveItem(Item.ListItemsInWorld.TryGetValue(msg.activeItem, out Item item) ? item : null);
                    needUpdateFlags = true;
                }
                if (this.PlayerOwner.Position != msg.position || this.PlayerOwner.Rotation != msg.inputState.aimAngles)
                {
                    this.PlayerOwner.Position = msg.position;
                    this.PlayerOwner.Rotation = msg.inputState.aimAngles;
                    this.PlayerOwner.OnPositionChanged();
                }
            }

            if (needUpdateFlags == true)
            {
                this.PlayerOwner.SendNetworkUpdate_PlayerFlags();
            }
            this.m_lastPlayerTickPacket = msg.Copy();
        }
Exemplo n.º 6
0
 public void FromProto(Stream stream, bool isDelta = false)
 {
     PlayerTick.Deserialize(stream, this, isDelta);
 }
Exemplo n.º 7
0
 public Tick(Packet p)
 {
     protobuf   = PlayerTick.Deserialize(p);
     modelState = new BaseModelState(protobuf.modelState);
     inputState = new Input_Message(protobuf.inputState);
 }
Exemplo n.º 8
0
            public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
            {
                serializer.ContractResolver = new JsonResolver();
                var packet = (Packet)value;

                writer.WriteStartObject();
                Action <string, object> Serialize = (string name, object obj) => {
                    writer.WritePropertyName(name);
                    serializer.Serialize(writer, obj);
                };

                if (Informative)
                {
                    Serialize("ID", packet.packetID);
                    Serialize("Name", packet.GetName());
                    Serialize("Type", packet.GetPacketTypeName());
                    Serialize("Origin", packet.GetOrigin());
                    Serialize("Delay", packet.delay);
                }
                else
                {
                    Serialize("ID", packet.packetID);
                    Serialize("TypeID", packet.type);
                    Serialize("Length", packet.incomingLength);
                    Serialize("GUID", packet.incomingGUID);
                    Serialize("Data", packet.baseStream.ToArray());
                }
                if (packet.length > 1 && Informative)
                {
                    if (packet.type == Packet.PacketType.RUST)
                    {
                        writer.WritePropertyName("Content");
                        writer.WriteStartObject();
                        packet.Position = 1;
                        switch (packet.rustID)
                        {
                        case Packet.Rust.Approved:
                            Serialize("ProtoBuf", ProtoBuf.Approval.Deserialize(packet));
                            break;

                        case Packet.Rust.Auth:
                            var bytes = packet.BytesWithSize();
                            Serialize("AuthData", BitConverter.ToString(bytes).Replace("-", ""));
                            break;

                        case Packet.Rust.ConsoleCommand:
                            Serialize("Command", packet.String());
                            break;

                        case Packet.Rust.ConsoleMessage:
                            Serialize("Message", packet.String());
                            break;

                        case Packet.Rust.DisconnectReason:
                            Serialize("Reason", packet.String());
                            break;

                        case Packet.Rust.Effect:
                            Serialize("ProtoBuf", EffectData.Deserialize(packet));
                            break;

                        case Packet.Rust.Entities:
                            Serialize("Num", packet.UInt32());
                            Serialize("ProtoBuf", ProtoBuf.Entity.Deserialize(packet));
                            break;

                        case Packet.Rust.EntityDestroy:
                            Serialize("UID", packet.UInt32());
                            Serialize("Destroy Mode", packet.UInt8());
                            break;

                        case Packet.Rust.EntityPosition:
                            writer.WritePropertyName("Entity Positions");
                            writer.WriteStartArray();
                            while (packet.unread >= 28L)
                            {
                                writer.WriteStartObject();
                                Serialize("Entity ID", packet.EntityID());
                                Serialize("Position", packet.Vector3());
                                Serialize("Rotation", packet.Vector3());
                                writer.WriteEndObject();
                            }
                            writer.WriteEndArray();
                            break;

                        case Packet.Rust.GiveUserInformation:
                            Serialize("ProtocolVersion", packet.UInt8());
                            Serialize("Steam ID", packet.UInt64());
                            Serialize("Protocol", packet.UInt32());
                            Serialize("OS Name", packet.String());
                            Serialize("Steam Name", packet.String());
                            Serialize("Branch", packet.String());
                            break;

                        case Packet.Rust.GroupChange:
                            Serialize("Entity ID", packet.EntityID());
                            Serialize("Group ID", packet.GroupID());
                            break;

                        case Packet.Rust.GroupDestroy:
                            Serialize("Group ID", packet.GroupID());

                            break;

                        case Packet.Rust.GroupEnter:
                            Serialize("Group ID", packet.GroupID());
                            break;

                        case Packet.Rust.GroupLeave:
                            Serialize("Group ID", packet.GroupID());
                            break;

                        case Packet.Rust.Message:
                            Serialize("String 1 (PlayerName?)", packet.String());
                            Serialize("String 2 (PlayerMsg?)", packet.String());
                            break;

                        case Packet.Rust.RPCMessage:
                            Serialize("UID", packet.UInt32());
                            Serialize("Name ID", packet.UInt32());
                            Serialize("Source Connection", packet.UInt64());
                            break;

                        case Packet.Rust.Ready:
                            Serialize("ProtoBuf", ProtoBuf.ClientReady.Deserialize(packet));
                            break;

                        case Packet.Rust.Tick:
                            Serialize("ProtoBuf", PlayerTick.Deserialize(packet));
                            break;

                        default:
                            break;
                        }
                        writer.WriteEndObject();
                    }
                }

                writer.WriteEndObject();
            }