fix(core): Converts some player packets (#372)
- [X] Converts some player packets Note: - Not caching weather packet because it is copying directly from stackalloc using aggressive inlining. Don't need to do more optimizations.
This commit is contained in:
parent
67c23bf9ad
commit
a59fda6a3a
12 changed files with 350 additions and 276 deletions
|
|
@ -321,7 +321,7 @@ namespace Server.Network
|
|||
|
||||
public static void LogoutReq(NetState state, CircularBufferReader reader)
|
||||
{
|
||||
state.Send(new LogoutAck());
|
||||
state.SendLogoutAck();
|
||||
}
|
||||
|
||||
public static void ChangeSkillLock(NetState state, CircularBufferReader reader)
|
||||
|
|
@ -488,7 +488,7 @@ namespace Server.Network
|
|||
|
||||
public static void SetUpdateRange(NetState state, CircularBufferReader reader)
|
||||
{
|
||||
state.Send(ChangeUpdateRange.Instantiate(18));
|
||||
state.SendChangeUpdateRange(18);
|
||||
}
|
||||
|
||||
public static void MobileQuery(NetState state, CircularBufferReader reader)
|
||||
|
|
|
|||
126
Projects/Server/Network/Packets/OutgoingPlayerPackets.cs
Normal file
126
Projects/Server/Network/Packets/OutgoingPlayerPackets.cs
Normal file
|
|
@ -0,0 +1,126 @@
|
|||
/*************************************************************************
|
||||
* ModernUO *
|
||||
* Copyright (C) 2019-2020 - ModernUO Development Team *
|
||||
* Email: hi@modernuo.com *
|
||||
* File: OutgoingPlayerPackets.cs *
|
||||
* *
|
||||
* This program is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation, either version 3 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
*************************************************************************/
|
||||
|
||||
using System.Buffers;
|
||||
using System.IO;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace Server.Network
|
||||
{
|
||||
public enum LRReason : byte
|
||||
{
|
||||
CannotLift,
|
||||
OutOfRange,
|
||||
OutOfSight,
|
||||
TryToSteal,
|
||||
AreHolding,
|
||||
Inspecific
|
||||
}
|
||||
|
||||
public static class OutgoingPlayerPackets
|
||||
{
|
||||
public static void SendStatLockInfo(this NetState ns, Mobile m)
|
||||
{
|
||||
if (ns == null || !ns.GetSendBuffer(out var buffer))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var writer = new CircularBufferWriter(buffer);
|
||||
writer.Write((byte)0xBF); // Packet ID
|
||||
writer.Write((ushort)12);
|
||||
writer.Write((short)0x19);
|
||||
writer.Write((byte)2);
|
||||
writer.Write(m.Serial);
|
||||
writer.Write((byte)0);
|
||||
|
||||
var lockBits = ((int)m.StrLock << 4) | ((int)m.DexLock << 2) | (int)m.IntLock;
|
||||
|
||||
writer.Write((byte)lockBits);
|
||||
|
||||
ns.Send(ref buffer, writer.Position);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void SendChangeUpdateRange(this NetState ns, byte range)
|
||||
{
|
||||
ns?.Send(stackalloc byte[] { 0xC8, range });
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void SendDeathStatus(this NetState ns, bool dead)
|
||||
{
|
||||
ns?.Send(stackalloc byte[] { 0x2C, dead ? 0 : 2 });
|
||||
}
|
||||
|
||||
public static void SendToggleSpecialAbility(this NetState ns, int abilityId, bool active)
|
||||
{
|
||||
if (ns == null || !ns.GetSendBuffer(out var buffer))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var writer = new CircularBufferWriter(buffer);
|
||||
writer.Write((byte)0xBF); // Packet ID
|
||||
writer.Write((ushort)8);
|
||||
writer.Write((short)0x25);
|
||||
writer.Write((short)abilityId);
|
||||
writer.Write(active);
|
||||
|
||||
ns.Send(ref buffer, writer.Position);
|
||||
}
|
||||
|
||||
public static void SendDisplayProfile(this NetState ns, Serial m, string header, string body, string footer)
|
||||
{
|
||||
if (ns == null || !ns.GetSendBuffer(out var buffer))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
header ??= "";
|
||||
body ??= "";
|
||||
footer ??= "";
|
||||
|
||||
var writer = new CircularBufferWriter(buffer);
|
||||
writer.Write((byte)0xB8); // Packet ID
|
||||
writer.Seek(2, SeekOrigin.Current);
|
||||
writer.Write(m);
|
||||
writer.WriteAsciiNull(header);
|
||||
writer.WriteBigUniNull(footer);
|
||||
writer.WriteBigUniNull(body);
|
||||
|
||||
writer.WritePacketLength();
|
||||
ns.Send(ref buffer, writer.Position);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void SendLiftReject(this NetState ns, LRReason reason)
|
||||
{
|
||||
ns?.Send(stackalloc byte[] { 0x27, (byte)reason });
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void SendLogoutAck(this NetState ns)
|
||||
{
|
||||
ns?.Send(stackalloc byte[] { 0xD1, 0x01 });
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void SendWeather(this NetState ns, byte type, byte density, byte temp)
|
||||
{
|
||||
ns?.Send(stackalloc byte[] { 0x65, type, density, temp });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,151 +1,8 @@
|
|||
/*************************************************************************
|
||||
* ModernUO *
|
||||
* Copyright 2019-2020 - ModernUO Development Team *
|
||||
* Email: hi@modernuo.com *
|
||||
* File: PlayerPackets.cs *
|
||||
* *
|
||||
* This program is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation, either version 3 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
*************************************************************************/
|
||||
|
||||
using System;
|
||||
using Server.HuePickers;
|
||||
|
||||
namespace Server.Network
|
||||
{
|
||||
public enum LRReason : byte
|
||||
{
|
||||
CannotLift = 0,
|
||||
OutOfRange = 1,
|
||||
OutOfSight = 2,
|
||||
TryToSteal = 3,
|
||||
AreHolding = 4,
|
||||
Inspecific = 5
|
||||
}
|
||||
|
||||
public sealed class StatLockInfo : Packet
|
||||
{
|
||||
public StatLockInfo(Mobile m) : base(0xBF)
|
||||
{
|
||||
EnsureCapacity(12);
|
||||
|
||||
Stream.Write((short)0x19);
|
||||
Stream.Write((byte)2);
|
||||
Stream.Write(m.Serial);
|
||||
Stream.Write((byte)0);
|
||||
|
||||
var lockBits = ((int)m.StrLock << 4) | ((int)m.DexLock << 2) | (int)m.IntLock;
|
||||
|
||||
Stream.Write((byte)lockBits);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class ChangeUpdateRange : Packet
|
||||
{
|
||||
private static readonly ChangeUpdateRange[] m_Cache = new ChangeUpdateRange[0x100];
|
||||
|
||||
public ChangeUpdateRange(int range) : base(0xC8, 2)
|
||||
{
|
||||
Stream.Write((byte)range);
|
||||
}
|
||||
|
||||
public static ChangeUpdateRange Instantiate(int range)
|
||||
{
|
||||
var idx = (byte)range;
|
||||
var p = m_Cache[idx];
|
||||
|
||||
if (p == null)
|
||||
{
|
||||
m_Cache[idx] = p = new ChangeUpdateRange(range);
|
||||
p.SetStatic();
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class DeathStatus : Packet
|
||||
{
|
||||
public static readonly Packet Dead = SetStatic(new DeathStatus(true));
|
||||
public static readonly Packet Alive = SetStatic(new DeathStatus(false));
|
||||
|
||||
public DeathStatus(bool dead) : base(0x2C, 2)
|
||||
{
|
||||
Stream.Write((byte)(dead ? 0 : 2));
|
||||
}
|
||||
|
||||
public static Packet Instantiate(bool dead) => dead ? Dead : Alive;
|
||||
}
|
||||
|
||||
public sealed class ToggleSpecialAbility : Packet
|
||||
{
|
||||
public ToggleSpecialAbility(int abilityID, bool active) : base(0xBF)
|
||||
{
|
||||
EnsureCapacity(7);
|
||||
|
||||
Stream.Write((short)0x25);
|
||||
|
||||
Stream.Write((short)abilityID);
|
||||
Stream.Write(active);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class DisplayProfile : Packet
|
||||
{
|
||||
public DisplayProfile(Serial m, string header, string body, string footer) : base(0xB8)
|
||||
{
|
||||
header ??= "";
|
||||
body ??= "";
|
||||
footer ??= "";
|
||||
|
||||
EnsureCapacity(12 + header.Length + footer.Length * 2 + body.Length * 2);
|
||||
|
||||
Stream.Write(m);
|
||||
Stream.WriteAsciiNull(header);
|
||||
Stream.WriteBigUniNull(footer);
|
||||
Stream.WriteBigUniNull(body);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class LiftRej : Packet
|
||||
{
|
||||
public LiftRej(LRReason reason) : base(0x27, 2)
|
||||
{
|
||||
Stream.Write((byte)reason);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class LogoutAck : Packet
|
||||
{
|
||||
public LogoutAck() : base(0xD1, 2)
|
||||
{
|
||||
Stream.Write((byte)0x01);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class Weather : Packet
|
||||
{
|
||||
public Weather(int type, int density, int temp) : base(0x65, 4)
|
||||
{
|
||||
Stream.Write((byte)type);
|
||||
Stream.Write((byte)density);
|
||||
Stream.Write((byte)temp);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class RemoveEntity : Packet
|
||||
{
|
||||
public RemoveEntity(Serial entity) : base(0x1D, 5)
|
||||
{
|
||||
Stream.Write(entity);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class ServerChange : Packet
|
||||
{
|
||||
public ServerChange(Point3D p, Map map) : base(0x76, 16)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue