ModernUO/Projects/Server/Network/Packets/Accounts.cs
Kamron Batman 179cb50557 Updates Packets & Randomizer (#43)
* Fixes a bug with the main loop. Removes unnecessary optimizations for RDRand.

* WIP - Rewriting packets.

* Cleanup and updates README

* Converts more packets

* Fixes header

* Converts Effects packets.

* Forgot the send command

* Adds the start of containers packets.

* Adds message packets with caching

* Extends the send methods

* Starts to add Acquire methods

* Converted the packets

* Cleanup

* Cleanup

* Adds more packets

* Adds more packets

* Fixes clearing arrays from pool. Adds Mobile Incoming

* Converts more packets.

* Moves more packets

* Moves more packets

* Test compression

* Merges

* Migrating to an idiomatic syntax that also supports compression, and proxying.

* Optimize the stack alloc. Changes attributes

* Converted container packets

* Visual Studio doesn't auto save files. I am still getting used to subpar IDEs.

* Adds static packet caching. Will profile later. Converts more packets

* Fixes packets and changes how compression is configured

* WIP - Adds basics for Gumps. Not finished though.

* Fix file

* Fixes formatting

* Changed SpanWriter to be more idiomatic.

* Fixes Span vs RawSpan and missing stackallocs

* Converts over some more gumps

* WIP - Deletes 32bit support.

* Drops RDRand32 support.

* Fixes gump compilation

* Converting gump components

* Removes old huffman compression function

* Revert signature for backwards compatibility

* WIP - Converting more gump components

* Creates ArraySet for the strings. Updates AppendTo to reference that.

* Converts the maining gump components

* Cleans up gump components

* Cleans up directives

* Cleans up ArraySet and moves it. Adds null-coalescing-assignment

* Cleanup, Target Packets, and C# 8 changes.

* Removed OPL Packet

* World packets

* Fixing packet uses

* Cleans up code. Fixes packet uses in various places.

* More cleanup for packets

* Code cleanup

* Converts more packet uses and cleans up more code

* More code cleanup

* Finishes fixing the packets in Item

* Updates secure trade packets

* Updates core and gets it to compile.

* Moved packets to scripts. Fixed account handler use of packets

* Code cleanup

* Updates chat packets

* Code cleanuo

* Adds party packets, but need to implement them.

* Party packets WIP

* Finishes party packets

* Rearrange movement namespaces and classes

* Finishes plant packets

* Code Formatting

* Fixes moving effects

* Code cleanup, eliminates equipinfo

* Adds more packets. Fixes bugs with various packets.

* Finishes mahjon packets

* Fixes mahjong packet

* Code cleanup

* Finishes mahjong packets

* Adds Map packets

* Add multifacet maps and charts

* Cleans up some packets with UTF8

* Optimizes packets

* Cleans up more packets. Moves the MessageHelper

* Removes assistant support. Removes extended protocol. Incorporates MapUO packets as normal packets.

* Updates protocol extensions packet receiver

* Fixes a few bugs. Fixes a few more packets.

* Code cleanup and fixing more packets

* Fixes packet effects

* Cleaned up more code

* Buff Icon cleanup

* Removed unused constructors

* Code Cleanup. Adds BoatHS Packets

* Moves house files. Updates house foundation packets.

* Deployment cleanup

* Fixes:

* Code cleanup

* More code cleanup

* More code cleanup

* Cleaned up BaseHouse

* Enforces styling

* Converts foreach to linq where possible.

* Dont need that

* Goals/Readme updates

* Removes 32bit support at the highest level. Turns on HRT by default.

* Code cleanup. Fixes extended features packet.

* Fixes various bugs

* Code cleanup

* Code cleanup

* Code cleanup. Fixes gump X/Y assignment.

* Code cleanup using |= operator

* More code cleanup

* Cleanup

* Fixes spacing issues. Thanks Visual Studio. You suck.

* Compiler error

* Fixes NPE from RunUO 2.7

* Renames ScriptCompiler to AssemblyHandler. Fixes packets. Updates README

* Fixes more packets. Stupid trailing nulls.

* Fixes various bugs.

* Fixes for gumps

* Fixes more gump stuff. Going to split it out later since it is getting insane

* Recoded the gump writing

* WIP

* *Added output path of scripts project to dev branch
*Activated debugging in code
2019-11-11 12:40:16 +01:00

325 lines
8 KiB
C#

using System;
using Server.Buffers;
namespace Server.Network
{
public enum DeleteResultType : byte
{
PasswordInvalid,
CharNotExist,
CharBeingPlayed,
CharTooYoung,
CharQueued,
BadRequest
}
public enum PMMessage : byte
{
CharNoExist = 1,
CharExists = 2,
CharInWorld = 5,
LoginSyncError = 6,
IdleWarning = 7
}
public enum ALRReason : byte
{
Invalid = 0x00,
InUse = 0x01,
Blocked = 0x02,
BadPass = 0x03,
Idle = 0xFE,
BadComm = 0xFF
}
public static partial class Packets
{
public static void SendDeleteResult(NetState ns, DeleteResultType res)
{
if (ns == null)
return;
Span<byte> span = ns.SendPipe.Writer.GetSpan(2);
span[0] = 0x85; // Packet ID
span[1] = (byte)res;
// Not compressed with Huffman
_ = ns.Flush(2);
}
public static void SendPopupMessage(NetState ns, PMMessage msg)
{
ns?.Send(stackalloc byte[]
{
0x53, // Packet ID
(byte)msg
});
}
public static void SendAccountLoginRej(NetState ns, ALRReason reason)
{
if (ns == null)
return;
Span<byte> span = ns.SendPipe.Writer.GetSpan(2);
span[0] = 0x82; // Packet ID
span[1] = (byte)reason;
// Not compressed with Huffman
_ = ns.Flush(2);
}
public static void SendSupportedFeatures(NetState ns)
{
if (ns == null)
return;
int length = ns.ExtendedSupportedFeatures ? 5 : 3;
Span<byte> bytes = stackalloc byte[length];
SpanWriter w = new SpanWriter(bytes);
w.Write((byte)0xB9); // Packet ID
FeatureFlags flags = ExpansionInfo.CoreExpansion.SupportedFeatures;
if (ns.Account?.Limit >= 6)
{
flags &= ~FeatureFlags.UOTD;
flags |= FeatureFlags.LiveAccount |
(ns.Account.Limit > 6 ? FeatureFlags.SeventhCharacterSlot : FeatureFlags.SixthCharacterSlot);
}
if (ns.ExtendedSupportedFeatures)
w.Write((uint)flags);
else
w.Write((ushort)flags);
ns.Send(w.RawSpan);
}
public static void SendCharacterList(NetState ns, CityInfo[] info)
{
if (ns == null)
return;
if (ns.NewCharacterList)
SendCharacterListNew(ns, ns.Account, info);
else
SendCharacterListOld(ns, ns.Account, info);
}
public static void SendCharacterListNew(NetState ns, IAccount a, CityInfo[] info)
{
if (ns == null)
return;
int highSlot = -1;
for (int i = 0; i < a.Length; ++i)
if (a[i] != null)
highSlot = i;
int count = Math.Max(Math.Max(highSlot + 1, a.Limit), 5);
int length = 11 + count * 60 + info.Length * 89;
SpanWriter w = new SpanWriter(stackalloc byte[length]);
w.Write((byte)0xA9); // Packet ID
w.Write((short)length); // Length
w.Write((byte)count);
for (int i = 0; i < count; ++i)
if (a[i] != null)
{
w.WriteAsciiFixed(a[i].Name, 30);
w.Position += 30;
}
else
w.Position += 60;
w.Write((byte)info.Length);
for (int i = 0; i < info.Length; ++i)
{
CityInfo ci = info[i];
w.Write((byte)i);
w.WriteAsciiFixed(ci.City, 32);
w.WriteAsciiFixed(ci.Building, 32);
w.Write(ci.X);
w.Write(ci.Y);
w.Write(ci.Z);
w.Write(ci.Map.MapID);
w.Write(ci.Description);
w.Position += 4; // w.Write(0);
}
CharacterListFlags flags = ExpansionInfo.CoreExpansion.CharacterListFlags;
if (count > 6)
flags |= CharacterListFlags.SeventhCharacterSlot |
CharacterListFlags.SixthCharacterSlot; // 7th Character Slot - TODO: Is SixthCharacterSlot Required?
else if (count == 6)
flags |= CharacterListFlags.SixthCharacterSlot; // 6th Character Slot
else if (a.Limit == 1)
flags |= CharacterListFlags.SlotLimit &
CharacterListFlags.OneCharacterSlot; // Limit Characters & One Character
w.Write((int)flags);
w.Write((short)-1);
ns.Send(w.Span);
// TODO: Razor support?
}
public static void SendCharacterListOld(NetState ns, IAccount a, CityInfo[] info)
{
if (ns == null)
return;
int highSlot = -1;
for (int i = 0; i < a.Length; ++i)
if (a[i] != null)
highSlot = i;
int count = Math.Max(Math.Max(highSlot + 1, a.Limit), 5);
int length = 9 + count * 60 + info.Length * 63;
SpanWriter w = new SpanWriter(stackalloc byte[length]);
w.Write((byte)0xA9); // Packet ID
w.Write((short)length); // Length
w.Write((byte)count);
for (int i = 0; i < count; ++i)
if (a[i] != null)
{
w.WriteAsciiFixed(a[i].Name, 30);
w.Position += 30;
}
else
w.Position += 60;
w.Write((byte)info.Length);
for (int i = 0; i < info.Length; ++i)
{
CityInfo ci = info[i];
w.Write((byte)i);
w.WriteAsciiFixed(ci.City, 31);
w.WriteAsciiFixed(ci.Building, 31);
}
CharacterListFlags flags = ExpansionInfo.CoreExpansion.CharacterListFlags;
if (count > 6)
flags |= CharacterListFlags.SeventhCharacterSlot |
CharacterListFlags.SixthCharacterSlot; // 7th Character Slot - TODO: Is SixthCharacterSlot Required?
else if (count == 6)
flags |= CharacterListFlags.SixthCharacterSlot; // 6th Character Slot
else if (a.Limit == 1)
flags |= CharacterListFlags.SlotLimit &
CharacterListFlags.OneCharacterSlot; // Limit Characters & One Character
w.Write((int)flags);
ns.Send(w.RawSpan);
// TODO: Razor support?
}
public static void SendCharacterListUpdate(NetState ns, IAccount a)
{
if (ns == null)
return;
int highSlot = -1;
for (int i = 0; i < a.Length; ++i)
if (a[i] != null)
highSlot = i;
int count = Math.Max(Math.Max(highSlot + 1, a.Limit), 5);
int length = 4 + count * 60;
SpanWriter w = new SpanWriter(stackalloc byte[length]);
w.Write((byte)0x86); // Packet ID
w.Write((short)length); // Length
w.Write((byte)count);
for (int i = 0; i < count; ++i)
{
Mobile m = a[i];
if (m != null)
{
w.WriteAsciiFixed(m.Name, 30);
w.Position += 30;
}
else
w.Position += 60;
}
ns.Send(w.RawSpan);
}
public static void SendPlayServerAck(NetState ns, ServerInfo si)
{
if (ns == null)
return;
SpanWriter w = new SpanWriter(ns.SendPipe.Writer.GetSpan(11));
w.Write((byte)0x8C); // Packet ID
int addr = Utility.GetAddressValue(si.Address.Address);
w.Write((byte)addr);
w.Write((byte)(addr >> 8));
w.Write((byte)(addr >> 16));
w.Write((byte)(addr >> 24));
w.Write((short)si.Address.Port);
w.Write(ns.m_AuthID);
// Not compressed with Huffman
_ = ns.Flush(11);
}
public static void SendAccountLoginAck(NetState ns, ServerInfo[] info)
{
if (ns == null)
return;
int length = 6 + info.Length * 40;
SpanWriter w = new SpanWriter(ns.SendPipe.Writer.GetSpan(length));
w.Write((byte)0xA8); // Packet ID
w.Write((short)length);
w.Write((byte)0x5D); // Unknown
w.Write((ushort)info.Length);
for (int i = 0; i < info.Length; ++i)
{
ServerInfo si = info[i];
w.Write((ushort)i);
w.WriteAsciiFixed(si.Name, 32, true);
w.Write((byte)si.FullPercent);
w.Write((sbyte)si.TimeZone);
w.Write(Utility.GetAddressValue(si.Address.Address));
}
// Not compressed with Huffman
_ = ns.Flush(length);
}
}
}