public void UpdateLocalMovement() { if (!TheClient.Network.IsAlive) { return; } Location dirro = Direction; if (ServerFlags.HasFlag(YourStatusFlags.NO_ROTATE)) { dirro.Yaw = tyaw; dirro.Pitch = tpitch; } MoveTransmitWaiting += TheClient.Delta; if (MoveTransmitWaiting < MoveTransmitTime) { return; } MoveTransmitWaiting = 0.0; KeysPacketData kpd = (Upward ? KeysPacketData.UPWARD : 0) | (Click ? KeysPacketData.CLICK : 0) | (AltClick ? KeysPacketData.ALTCLICK : 0) | (Downward ? KeysPacketData.DOWNWARD : 0) | (Use ? KeysPacketData.USE : 0) | (ItemLeft ? KeysPacketData.ITEMLEFT : 0) | (ItemRight ? KeysPacketData.ITEMRIGHT : 0) | (ItemUp ? KeysPacketData.ITEMUP : 0) | (ItemDown ? KeysPacketData.ITEMDOWN : 0); if (GTTs[CurrentMovePacketID] >= 0.0) { LagRateLimit += TheClient.Delta; if (LagRateLimit > 2.5) { LagRateLimit = 0.0; SysConsole.Output(OutputType.WARNING, "Lagging: Movement tracker full (" + CurrentMovePacketID + ", " + GTTs[CurrentMovePacketID] + ")"); for (int i = 0; i < PACKET_CAP; i++) { GTTs[i] = -1; // TODO: Temporary! } } return; } Location p = GetPosition(); Location v = GetVelocity(); TheClient.Network.SendPacket(new KeysPacketOut(CurrentMovePacketID, kpd, dirro, XMove, YMove, p, v, SprintOrWalk, ItemDir(), ItemSourceRelative())); Positions[CurrentMovePacketID] = p; Velocities[CurrentMovePacketID] = v; GTTs[CurrentMovePacketID] = CurrentRemoteGTT; CurrentMovePacketID = (CurrentMovePacketID + 1) % PACKET_CAP; if (InVehicle && Vehicle != null) { UpdateVehicle(); } }
public KeysPacketOut(long tID, KeysPacketData data, Location direction, float xmove, float ymove, Location pos, Location vel, float sow) { ID = ClientToServerPacket.KEYS; Data = new byte[8 + 2 + 4 + 4 + 4 + 4 + 24 + 24 + 4]; Utilities.LongToBytes(tID).CopyTo(Data, 0); Utilities.UshortToBytes((ushort)data).CopyTo(Data, 8); Utilities.FloatToBytes((float)direction.Yaw).CopyTo(Data, 8 + 2); Utilities.FloatToBytes((float)direction.Pitch).CopyTo(Data, 8 + 2 + 4); Utilities.FloatToBytes(xmove).CopyTo(Data, 8 + 2 + 4 + 4); Utilities.FloatToBytes(ymove).CopyTo(Data, 8 + 2 + 4 + 4 + 4); int s = 8 + 2 + 4 + 4 + 4 + 4; pos.ToDoubleBytes().CopyTo(Data, s); vel.ToDoubleBytes().CopyTo(Data, s + 24); Utilities.FloatToBytes(sow).CopyTo(Data, s + 24 + 24); }
/// <summary> /// Handles a key input data packet for the server to recognize changes to client data. /// </summary> /// <param name="tID">Temporary packet ID.</param> /// <param name="data">Key press data.</param> /// <param name="direction">View direction.</param> /// <param name="xmove">X-Axis view-relative movement.</param> /// <param name="ymove">Y-Axis view-relative movement.</param> /// <param name="pos">Position.</param> /// <param name="vel">Velocity.</param> /// <param name="sow">Sprint-or-walk.</param> /// <param name="itemDir">Item source direction.</param> /// <param name="isRel">item source relative position.</param> public KeysPacketOut(int tID, KeysPacketData data, Location direction, float xmove, float ymove, Location pos, Location vel, float sow, Location itemDir, Location isRel) { ID = ClientToServerPacket.KEYS; DataStream ds = new DataStream(PACKET_SIZE); DataWriter dw = new DataWriter(ds); dw.WriteInt(tID); dw.WriteUShort((ushort)data); dw.WriteFloat((float)direction.Yaw); dw.WriteFloat((float)direction.Pitch); dw.WriteFloat((float)xmove); dw.WriteFloat((float)ymove); dw.WriteLocation(pos); dw.WriteLocation(vel); dw.WriteFloat(sow); dw.WriteLocation(itemDir); dw.WriteLocation(isRel); Data = ds.ToArray(); }
public void UpdateLocalMovement() { AddUIS(); KeysPacketData kpd = (Upward ? KeysPacketData.UPWARD : 0) | (Click ? KeysPacketData.CLICK : 0) | (AltClick ? KeysPacketData.ALTCLICK : 0) | (Downward ? KeysPacketData.DOWNWARD : 0) | (Use ? KeysPacketData.USE : 0) | (ItemLeft ? KeysPacketData.ITEMLEFT : 0) | (ItemRight ? KeysPacketData.ITEMRIGHT : 0) | (ItemUp ? KeysPacketData.ITEMUP : 0) | (ItemDown ? KeysPacketData.ITEMDOWN : 0); if (ServerFlags.HasFlag(YourStatusFlags.NO_ROTATE)) { Location loc = new Location(); loc.Yaw = tyaw; loc.Pitch = tpitch; TheClient.Network.SendPacket(new KeysPacketOut(lUIS.ID, kpd, loc, lUIS.XMove, lUIS.YMove, GetPosition(), GetVelocity(), lUIS.SprintOrWalk)); } else { TheClient.Network.SendPacket(new KeysPacketOut(lUIS.ID, kpd, Direction, lUIS.XMove, lUIS.YMove, GetPosition(), GetVelocity(), lUIS.SprintOrWalk)); } }
public override bool ParseBytesAndExecute(DataReader data) { int tid = data.ReadInt(); KeysPacketData val = (KeysPacketData)data.ReadUShort(); bool upw = val.HasFlag(KeysPacketData.UPWARD); bool downw = val.HasFlag(KeysPacketData.DOWNWARD); bool click = val.HasFlag(KeysPacketData.CLICK); bool aclick = val.HasFlag(KeysPacketData.ALTCLICK); bool use = val.HasFlag(KeysPacketData.USE); bool ileft = val.HasFlag(KeysPacketData.ITEMLEFT); bool iright = val.HasFlag(KeysPacketData.ITEMRIGHT); bool iup = val.HasFlag(KeysPacketData.ITEMUP); bool idown = val.HasFlag(KeysPacketData.ITEMDOWN); double yaw = data.ReadFloat(); double pitch = data.ReadFloat(); double x = data.ReadFloat(); double y = data.ReadFloat(); Location pos = data.ReadLocation(); Location vel = data.ReadLocation(); double sow = data.ReadFloat(); Location itemdir = data.ReadLocation(); Location isRel = data.ReadLocation(); Vector2 tmove = new Vector2(x, y); if (tmove.LengthSquared() > 1.0) { tmove.Normalize(); } if (itemdir.LengthSquared() != 1.0) { itemdir = itemdir.Normalize(); } if (isRel.LengthSquared() > 3.0 * 3.0) { isRel = isRel.Normalize() * 3.0; } if (Player.Upward != upw || Player.Downward != downw || Player.Click != click || Player.AltClick != aclick || Player.Use != use || Math.Abs(Player.Direction.Yaw - yaw) > 0.05 || Math.Abs(Player.Direction.Pitch - pitch) > 0.05 || Math.Abs(tmove.X - x) > 0.05 || Math.Abs(tmove.Y - y) > 0.05) { Player.NoteDidAction(); } Player.Upward = upw; Player.Downward = downw; Player.Click = click; Player.AltClick = aclick; Player.Use = use; Player.ItemLeft = ileft; Player.ItemRight = iright; Player.ItemUp = iup; Player.ItemDown = idown; Player.LastKPI = Player.TheRegion.GlobalTickTime; Player.SprintOrWalk = sow; Player.ItemDir = itemdir; Player.ItemSourceRelative = isRel; if (Player.Flags.HasFlag(YourStatusFlags.NO_ROTATE)) { Player.AttemptedDirectionChange.Yaw += yaw; Player.AttemptedDirectionChange.Pitch += pitch; } else { Player.Direction.Yaw = yaw; Player.Direction.Pitch = pitch; } Player.XMove = tmove.X; Player.YMove = tmove.Y; if (!Player.SecureMovement) { if (pos.IsNaN() || vel.IsNaN() || pos.IsInfinite() || vel.IsInfinite()) { return(false); } Location up = new Location(0, 0, Player.CBHHeight); Location start = Player.GetPosition(); Location rel = pos - start; double len = rel.Length(); if (len > 50) // TODO: better sanity cap? { return(false); } rel /= len; RayCastResult rcr; if (Player.TheRegion.SpecialCaseConvexTrace(new BoxShape(1.1f, 1.1f, 1.1f), start + up, rel, (double)len, MaterialSolidity.FULLSOLID, Player.IgnoreThis, out rcr)) { Player.Teleport(start); } else { Player.SetPosition(pos); } Player.SetVelocity(vel); // TODO: Validate velocity at all? } Player.Network.SendPacket(new YourPositionPacketOut(Player.TheRegion.GlobalTickTime, tid, Player.GetPosition(), Player.GetVelocity(), new Location(0, 0, 0), Player.CBody.StanceManager.CurrentStance, Player.pup)); return(true); }