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
This commit is contained in:
Kamron Batman 2019-11-11 03:40:16 -08:00 committed by 3HMonkey
parent 7aa8fd3df1
commit 179cb50557
588 changed files with 10843 additions and 16177 deletions

View file

@ -26,7 +26,6 @@ using Server.Accounting;
using Server.ContextMenus;
using Server.Diagnostics;
using Server.Gumps;
using Server.HuePickers;
using Server.Items;
using Server.Menus;
using Server.Prompts;
@ -56,11 +55,6 @@ namespace Server.Network
public static class PacketHandlers
{
public delegate void PlayCharCallback(NetState state, bool val);
private const int BadFood = unchecked((int)0xBAADF00D);
private const int BadUOTD = unchecked((int)0xFFCEFFCE);
private const int m_AuthIDWindowSize = 128;
private static PacketHandler[] m_6017Handlers;
@ -109,43 +103,32 @@ namespace Server.Network
Register(0x01, 5, false, Disconnect);
Register(0x02, 7, true, MovementReq);
Register(0x03, 0, true, AsciiSpeech);
Register(0x04, 2, true, GodModeRequest);
Register(0x05, 5, true, AttackReq);
Register(0x06, 5, true, UseReq);
Register(0x07, 7, true, LiftReq);
Register(0x08, 14, true, DropReq);
Register(0x09, 5, true, LookReq);
Register(0x0A, 11, true, Edit);
Register(0x12, 0, true, TextCommand);
Register(0x13, 10, true, EquipReq);
Register(0x14, 6, true, ChangeZ);
Register(0x22, 3, true, Resynchronize);
Register(0x2C, 2, true, DeathStatusResponse);
Register(0x34, 10, true, MobileQuery);
Register(0x3A, 0, true, ChangeSkillLock);
Register(0x3B, 0, true, VendorBuyReply);
Register(0x47, 11, true, NewTerrain);
Register(0x48, 73, true, NewAnimData);
Register(0x58, 106, true, NewRegion);
Register(0x5D, 73, false, PlayCharacter);
Register(0x61, 9, true, DeleteStatic);
Register(0x6C, 19, true, TargetResponse);
Register(0x6F, 0, true, SecureTrade);
Register(0x72, 5, true, SetWarMode);
Register(0x73, 2, false, PingReq);
Register(0x75, 35, true, RenameRequest);
Register(0x79, 9, true, ResourceQuery);
Register(0x7E, 2, true, GodviewQuery);
Register(0x7D, 13, true, MenuResponse);
Register(0x80, 62, false, AccountLogin);
Register(0x83, 39, false, DeleteCharacter);
Register(0x91, 65, false, GameLogin);
Register(0x95, 9, true, HuePickerResponse);
Register(0x96, 0, true, GameCentralMoniter);
Register(0x98, 0, true, MobileNameRequest);
Register(0x9A, 0, true, AsciiPromptResponse);
Register(0x9B, 258, true, HelpRequest);
Register(0x9D, 51, true, GMSingle);
Register(0x9F, 0, true, VendorSellReply);
Register(0xA0, 3, false, PlayServer);
Register(0xA4, 149, false, SystemInfo);
@ -161,8 +144,6 @@ namespace Server.Network
Register(0xBF, 0, true, ExtendedCommand);
Register(0xC2, 0, true, UnicodePromptResponse);
Register(0xC8, 2, true, SetUpdateRange);
Register(0xC9, 6, true, TripTime);
Register(0xCA, 6, true, UTripTime);
Register(0xCF, 0, false, AccountLogin);
Register(0xD0, 0, true, ConfigurationFile);
Register(0xD1, 2, true, LogoutReq);
@ -214,9 +195,7 @@ namespace Server.Network
public static void Register(int packetID, int length, bool ingame, OnPacketReceive onReceive)
{
Handlers[packetID] = new PacketHandler(packetID, length, ingame, onReceive);
if (m_6017Handlers[packetID] == null)
m_6017Handlers[packetID] = new PacketHandler(packetID, length, ingame, onReceive);
m_6017Handlers[packetID] ??= new PacketHandler(packetID, length, ingame, onReceive);
}
public static PacketHandler GetHandler(int packetID) => Handlers[packetID];
@ -342,6 +321,8 @@ namespace Server.Network
return -1;
}
// Console.WriteLine("Packet Handler {0:X}", handler.PacketID);
long packetLength = handler.Length;
if (handler.Length <= 0 && r.Length >= 3)
{
@ -413,9 +394,9 @@ namespace Server.Network
public static void EncodedCommand(NetState state, PacketReader pvSrc)
{
IEntity e = World.FindEntity(pvSrc.ReadUInt32());
int packetID = pvSrc.ReadUInt16();
int packetId = pvSrc.ReadUInt16();
EncodedPacketHandler ph = GetEncodedHandler(packetID);
EncodedPacketHandler ph = GetEncodedHandler(packetId);
if (ph != null)
{
@ -423,7 +404,7 @@ namespace Server.Network
{
Console.WriteLine(
"Client: {0}: Sent ingame packet (0xD7x{1:X2}) before having been attached to a mobile", state,
packetID);
packetId);
state.Dispose();
}
else if (ph.Ingame && state.Mobile.Deleted)
@ -536,37 +517,30 @@ namespace Server.Network
if (vendor == null)
return;
if (vendor.Deleted || !Utility.RangeCheck(vendor.Location, state.Mobile.Location, 10))
if (vendor.Deleted || !Utility.RangeCheck(vendor.Location, state.Mobile.Location, 10) || flag != 0x02)
{
state.Send(new EndVendorBuy(vendor));
Packets.SendEndVendorBuyOrSell(state, vendor.Serial);
return;
}
if (flag == 0x02)
msgSize -= 1 + 2 + 4 + 1;
if (msgSize / 7 > 100)
return;
List<BuyItemResponse> buyList = new List<BuyItemResponse>(msgSize / 7);
while (msgSize > 0)
{
msgSize -= 1 + 2 + 4 + 1;
pvSrc.ReadByte(); // layer
Serial serial = pvSrc.ReadUInt32();
int amount = pvSrc.ReadInt16();
if (msgSize / 7 > 100)
return;
List<BuyItemResponse> buyList = new List<BuyItemResponse>(msgSize / 7);
while (msgSize > 0)
{
byte layer = pvSrc.ReadByte();
Serial serial = pvSrc.ReadUInt32();
int amount = pvSrc.ReadInt16();
buyList.Add(new BuyItemResponse(serial, amount));
msgSize -= 7;
}
if (buyList.Count > 0 && vendor is IVendor v && v.OnBuyItems(state.Mobile, buyList))
state.Send(new EndVendorBuy(vendor));
}
else
{
state.Send(new EndVendorBuy(vendor));
buyList.Add(new BuyItemResponse(serial, amount));
msgSize -= 7;
}
if (buyList.Count > 0 && vendor is IVendor v && v.OnBuyItems(state.Mobile, buyList))
Packets.SendEndVendorBuyOrSell(state, vendor.Serial);
}
public static void VendorSellReply(NetState state, PacketReader pvSrc)
@ -578,7 +552,7 @@ namespace Server.Network
if (vendor.Deleted || !Utility.RangeCheck(vendor.Location, state.Mobile.Location, 10))
{
state.Send(new EndVendorSell(vendor));
Packets.SendEndVendorBuyOrSell(state, vendor.Serial);
return;
}
@ -590,14 +564,14 @@ namespace Server.Network
for (int i = 0; i < count; i++)
{
Item item = World.FindItem(pvSrc.ReadUInt32());
int Amount = pvSrc.ReadInt16();
int amount = pvSrc.ReadInt16();
if (item != null && Amount > 0)
sellList.Add(new SellItemResponse(item, Amount));
if (item != null && amount > 0)
sellList.Add(new SellItemResponse(item, amount));
}
if (sellList.Count > 0 && vendor is IVendor v && v.OnSellItems(state.Mobile, sellList))
state.Send(new EndVendorSell(vendor));
Packets.SendEndVendorBuyOrSell(state, vendor.Serial);
}
}
@ -609,39 +583,6 @@ namespace Server.Network
EventSink.InvokeDeleteRequest(new DeleteRequestEventArgs(state, index));
}
public static void ResourceQuery(NetState state, PacketReader pvSrc)
{
if (VerifyGC(state))
{
}
}
public static void GameCentralMoniter(NetState state, PacketReader pvSrc)
{
if (VerifyGC(state))
{
int type = pvSrc.ReadByte();
int num1 = pvSrc.ReadInt32();
Console.WriteLine("God Client: {0}: Game central moniter", state);
Console.WriteLine(" - Type: {0}", type);
Console.WriteLine(" - Number: {0}", num1);
pvSrc.Trace(state);
}
}
public static void GodviewQuery(NetState state, PacketReader pvSrc)
{
if (VerifyGC(state)) Console.WriteLine("God Client: {0}: Godview query 0x{1:X}", state, pvSrc.ReadByte());
}
public static void GMSingle(NetState state, PacketReader pvSrc)
{
if (VerifyGC(state))
pvSrc.Trace(state);
}
public static void DeathStatusResponse(NetState state, PacketReader pvSrc)
{
// Ignored
@ -677,7 +618,7 @@ namespace Server.Network
Mobile m = World.FindMobile(pvSrc.ReadUInt32());
if (m != null && Utility.InUpdateRange(state.Mobile, m) && state.Mobile.CanSee(m))
state.Send(new MobileName(m));
Packets.SendMobileName(state, m);
}
public static void RequestScrollWindow(NetState state, PacketReader pvSrc)
@ -714,34 +655,6 @@ namespace Server.Network
}
}
public static void TripTime(NetState state, PacketReader pvSrc)
{
int unk1 = pvSrc.ReadByte();
int unk2 = pvSrc.ReadInt32();
state.Send(new TripTimeResponse(unk1));
}
public static void UTripTime(NetState state, PacketReader pvSrc)
{
int unk1 = pvSrc.ReadByte();
int unk2 = pvSrc.ReadInt32();
state.Send(new UTripTimeResponse(unk1));
}
public static void ChangeZ(NetState state, PacketReader pvSrc)
{
if (VerifyGC(state))
{
int x = pvSrc.ReadInt16();
int y = pvSrc.ReadInt16();
int z = pvSrc.ReadSByte();
Console.WriteLine("God Client: {0}: Change Z ({1}, {2}, {3})", state, x, y, z);
}
}
public static void SystemInfo(NetState state, PacketReader pvSrc)
{
int v1 = pvSrc.ReadByte();
@ -758,83 +671,6 @@ namespace Server.Network
int v8 = pvSrc.ReadInt32();
}
public static void Edit(NetState state, PacketReader pvSrc)
{
if (VerifyGC(state))
{
int type = pvSrc.ReadByte(); // 10 = static, 7 = npc, 4 = dynamic
int x = pvSrc.ReadInt16();
int y = pvSrc.ReadInt16();
int id = pvSrc.ReadInt16();
int z = pvSrc.ReadSByte();
int hue = pvSrc.ReadUInt16();
Console.WriteLine("God Client: {0}: Edit {6} ({1}, {2}, {3}) 0x{4:X} (0x{5:X})", state, x, y, z, id, hue,
type);
}
}
public static void DeleteStatic(NetState state, PacketReader pvSrc)
{
if (VerifyGC(state))
{
int x = pvSrc.ReadInt16();
int y = pvSrc.ReadInt16();
int z = pvSrc.ReadInt16();
int id = pvSrc.ReadUInt16();
Console.WriteLine("God Client: {0}: Delete Static ({1}, {2}, {3}) 0x{4:X}", state, x, y, z, id);
}
}
public static void NewAnimData(NetState state, PacketReader pvSrc)
{
if (VerifyGC(state))
{
Console.WriteLine("God Client: {0}: New tile animation", state);
pvSrc.Trace(state);
}
}
public static void NewTerrain(NetState state, PacketReader pvSrc)
{
if (VerifyGC(state))
{
int x = pvSrc.ReadInt16();
int y = pvSrc.ReadInt16();
int id = pvSrc.ReadUInt16();
int width = pvSrc.ReadInt16();
int height = pvSrc.ReadInt16();
Console.WriteLine("God Client: {0}: New Terrain ({1}, {2})+({3}, {4}) 0x{5:X4}", state, x, y, width, height,
id);
}
}
public static void NewRegion(NetState state, PacketReader pvSrc)
{
if (VerifyGC(state))
{
string name = pvSrc.ReadString(40);
int unk = pvSrc.ReadInt32();
int x = pvSrc.ReadInt16();
int y = pvSrc.ReadInt16();
int width = pvSrc.ReadInt16();
int height = pvSrc.ReadInt16();
int zStart = pvSrc.ReadInt16();
int zEnd = pvSrc.ReadInt16();
string desc = pvSrc.ReadString(40);
int soundFX = pvSrc.ReadInt16();
int music = pvSrc.ReadInt16();
int nightFX = pvSrc.ReadInt16();
int dungeon = pvSrc.ReadByte();
int light = pvSrc.ReadInt16();
Console.WriteLine("God Client: {0}: New Region '{1}' ('{2}')", state, name, desc);
}
}
public static void AccountID(NetState state, PacketReader pvSrc)
{
}
@ -970,12 +806,6 @@ namespace Server.Network
}
}
public static void GodModeRequest(NetState state, PacketReader pvSrc)
{
if (VerifyGC(state))
state.Send(new GodModeReply(pvSrc.ReadBoolean()));
}
public static void AsciiPromptResponse(NetState state, PacketReader pvSrc)
{
uint serial = pvSrc.ReadUInt32();
@ -1200,14 +1030,12 @@ namespace Server.Network
public static void LogoutReq(NetState state, PacketReader pvSrc)
{
state.Send(new LogoutAck());
Packets.SendLogoutAck(state);
}
public static void ChangeSkillLock(NetState state, PacketReader pvSrc)
{
Skill s = state.Mobile.Skills[pvSrc.ReadInt16()];
s?.SetLockNoRelay((SkillLock)pvSrc.ReadByte());
state.Mobile.Skills[pvSrc.ReadInt16()]?.SetLockNoRelay((SkillLock)pvSrc.ReadByte());
}
public static void HelpRequest(NetState state, PacketReader pvSrc)
@ -1218,13 +1046,13 @@ namespace Server.Network
public static void TargetResponse(NetState state, PacketReader pvSrc)
{
int type = pvSrc.ReadByte();
int targetID = pvSrc.ReadInt32();
int targetId = pvSrc.ReadInt32();
int flags = pvSrc.ReadByte();
Serial serial = pvSrc.ReadUInt32();
int x = pvSrc.ReadInt16(), y = pvSrc.ReadInt16(), z = pvSrc.ReadInt16();
int graphic = pvSrc.ReadUInt16();
if (targetID == unchecked((int)0xDEADBEEF))
if (targetId == unchecked((int)0xDEADBEEF))
return;
Mobile from = state.Mobile;
@ -1244,7 +1072,7 @@ namespace Server.Network
// User pressed escape
t.Cancel(from, TargetCancelType.Canceled);
}
else if (t.TargetID != targetID)
else if (t.TargetID != targetId)
{
// Sanity, prevent fake target
}
@ -1267,42 +1095,28 @@ namespace Server.Network
t.Cancel(from, TargetCancelType.Canceled);
return;
}
else
StaticTile[] tiles = map.Tiles.GetStaticTiles(x, y, !t.DisallowMultis);
if (state.HighSeas)
{
StaticTile[] tiles = map.Tiles.GetStaticTiles(x, y, !t.DisallowMultis);
bool valid = false;
if (state.HighSeas)
{
ItemData id = TileData.ItemTable[graphic & TileData.MaxItemValue];
if (id.Surface) z -= id.Height;
}
for (int i = 0; !valid && i < tiles.Length; ++i)
if (tiles[i].Z == z && tiles[i].ID == graphic)
valid = true;
if (!valid)
{
t.Cancel(from, TargetCancelType.Canceled);
return;
}
else
{
toTarget = new StaticTarget(new Point3D(x, y, z), graphic);
}
ItemData id = TileData.ItemTable[graphic & TileData.MaxItemValue];
if (id.Surface) z -= id.Height;
}
if (tiles.All(tile => tile.Z != z || tile.ID != graphic))
{
t.Cancel(from, TargetCancelType.Canceled);
return;
}
toTarget = new StaticTarget(new Point3D(x, y, z), graphic);
}
}
else if (serial.IsMobile)
{
toTarget = World.FindMobile(serial);
}
else if (serial.IsItem)
{
toTarget = World.FindItem(serial);
}
else
{
t.Cancel(from, TargetCancelType.Canceled);
@ -1438,13 +1252,8 @@ namespace Server.Network
{
Mobile m = state.Mobile;
if (state.StygianAbyss)
state.Send(new MobileUpdate(m));
else
state.Send(new MobileUpdateOld(m));
state.Send(MobileIncoming.Create(state, m, m));
Packets.SendMobileUpdate(state, m);
Packets.SendMobileIncoming(state, m, m);
m.SendEverything();
state.Sequence = 0;
@ -1496,24 +1305,24 @@ namespace Server.Network
for (int i = 0; i < count; ++i)
{
int speechID;
int speechId;
if ((i & 1) == 0)
{
hold <<= 8;
hold |= pvSrc.ReadByte();
speechID = hold;
speechId = hold;
hold = 0;
}
else
{
value = pvSrc.ReadInt16();
speechID = (value & 0xFFF0) >> 4;
speechId = (value & 0xFFF0) >> 4;
hold = value & 0xF;
}
if (!keyList.Contains(speechID))
keyList.Add(speechID);
if (!keyList.Contains(speechId))
keyList.Add(speechId);
}
text = pvSrc.ReadUTF8StringSafe();
@ -1550,9 +1359,7 @@ namespace Server.Network
uint value = pvSrc.ReadUInt32();
if ((value & ~0x7FFFFFFF) != 0)
{
from.OnPaperdollRequest();
}
else
{
Serial s = value;
@ -1576,9 +1383,7 @@ namespace Server.Network
from.NextActionTime = Core.TickCount + Mobile.ActionDelay;
}
else
{
from.SendActionMessage();
}
}
public static void LookReq(NetState state, PacketReader pvSrc)
@ -1594,9 +1399,7 @@ namespace Server.Network
if (m != null && from.CanSee(m) && Utility.InUpdateRange(from, m))
{
if (SingleClickProps)
{
m.OnAosSingleClick(from);
}
else
{
if (from.Region.OnSingleClick(from, m))
@ -1612,9 +1415,7 @@ namespace Server.Network
Utility.InUpdateRange(from.Location, item.GetWorldLocation()))
{
if (SingleClickProps)
{
item.OnAosSingleClick(from);
}
else if (from.Region.OnSingleClick(from, item))
{
if (item.Parent is Item item1)
@ -1628,25 +1429,25 @@ namespace Server.Network
public static void PingReq(NetState state, PacketReader pvSrc)
{
state.Send(PingAck.Instantiate(pvSrc.ReadByte()));
Packets.SendPingAck(state, pvSrc.ReadByte());
}
public static void SetUpdateRange(NetState state, PacketReader pvSrc)
{
state.Send(ChangeUpdateRange.Instantiate(18));
Packets.SendChangeUpdateRange(state);
}
public static void MovementReq(NetState state, PacketReader pvSrc)
{
Direction dir = (Direction)pvSrc.ReadByte();
int seq = pvSrc.ReadByte();
int key = pvSrc.ReadInt32();
byte seq = pvSrc.ReadByte();
pvSrc.ReadInt32(); // key
Mobile m = state.Mobile;
if (state.Sequence == 0 && seq != 0 || !m.Move(dir))
{
state.Send(new MovementRej(seq, m));
Packets.SendMovementRej(state, seq, m);
state.Sequence = 0;
m.ClearFastwalkStack();
@ -1655,7 +1456,7 @@ namespace Server.Network
{
++seq;
if (seq == 256)
if (seq == 0)
seq = 1;
state.Sequence = seq;
@ -1688,7 +1489,7 @@ namespace Server.Network
{
int packetID = pvSrc.ReadUInt16();
Console.WriteLine("Extended Packet: {0:X}", packetID);
// Console.WriteLine("Extended Packet: {0:X}", packetID);
PacketHandler ph = GetExtendedHandler(packetID);
if (ph == null)
@ -2062,13 +1863,6 @@ namespace Server.Network
if (m != null)
switch (type)
{
case 0x00: // Unknown, sent by godclient
{
if (VerifyGC(state))
Console.WriteLine("God Client: {0}: Query 0x{1:X2} on {2} '{3}'", state, type, m.Serial, m.Name);
break;
}
case 0x04: // Stats
{
m.OnStatsQuery(from);
@ -2093,47 +1887,17 @@ namespace Server.Network
string name = pvSrc.ReadString(30);
pvSrc.Seek(2, SeekOrigin.Current);
pvSrc.ReadInt16(); // Unknown
int flags = pvSrc.ReadInt32();
/* if (FeatureProtection.DisabledFeatures != 0 && ThirdPartyAuthCallback != null)
{
bool authOK = false;
ulong razorFeatures = ((ulong)pvSrc.ReadUInt32() << 32) | pvSrc.ReadUInt32();
if (razorFeatures == (ulong)FeatureProtection.DisabledFeatures)
{
bool doesNotMatch = false;
for (int i = 0; !doesNotMatch && i < m_ThirdPartyAuthKey.Length; i++)
doesNotMatch = pvSrc.ReadByte() != m_ThirdPartyAuthKey[i];
if (!doesNotMatch)
authOK = true;
}
else
{
pvSrc.Seek(16, SeekOrigin.Current);
}
ThirdPartyAuthCallback(state, authOK);
}*/
/* else
{*/
pvSrc.Seek(24, SeekOrigin.Current);
/* }*/
/* if (ThirdPartyHackedCallback != null)
{
pvSrc.Seek(-2, SeekOrigin.Current);
if (pvSrc.ReadUInt16() == 0xDEAD)
ThirdPartyHackedCallback(state, true);
}*/
pvSrc.Seek(24, SeekOrigin.Current);
if (!state.Running)
return;
int charSlot = pvSrc.ReadInt32();
// TODO: Handle IP address.
int clientIP = pvSrc.ReadInt32();
IAccount a = state.Account;
@ -2152,7 +1916,7 @@ namespace Server.Network
if (check != null && check.Map != Map.Internal && check != m)
{
Console.WriteLine("Login: {0}: Account in use", state);
state.Send(new PopupMessage(PMMessage.CharInWorld));
Packets.SendPopupMessage(state, PMMessage.CharInWorld);
return;
}
}
@ -2167,11 +1931,9 @@ namespace Server.Network
// TODO: Make this wait one tick so we don't have to call it unnecessarily
NetState.ProcessDisposedQueue();
state.Send(new ClientVersionReq());
Packets.SendClientVersionReq(state);
state.BlockAllPackets = true;
state.Flags = (ClientFlags)flags;
state.Mobile = m;
@ -2183,93 +1945,38 @@ namespace Server.Network
public static void DoLogin(NetState state, Mobile m)
{
state.Send(new LoginConfirm(m));
Packets.SendLoginConfirm(state, m);
if (m.Map != null)
state.Send(new MapChange(m));
Packets.SendMapChange(state, m.Map);
state.Send(new MapPatches());
state.Send(SeasonChange.Instantiate(m.GetSeason(), true));
state.Send(SupportedFeatures.Instantiate(state));
Packets.SendMapPatches(state);
Packets.SendSeasonChange(state, m.GetSeason(), 1);
Packets.SendSupportedFeatures(state);
state.Sequence = 0;
if (state.NewMobileIncoming)
{
state.Send(new MobileUpdate(m));
state.Send(new MobileUpdate(m));
// TODO: Verify if we need this twice
Packets.SendMobileUpdate(state, m);
m.CheckLightLevels(true);
Packets.SendMobileUpdate(state, m);
m.CheckLightLevels(true);
Packets.SendMobileIncoming(state, m, m);
Packets.SendMobileStatus(state, m, m);
Packets.SendSetWarMode(state, m.Warmode);
state.Send(new MobileUpdate(m));
m.SendEverything();
state.Send(new MobileIncoming(m, m));
//state.Send( new MobileAttributes( m ) );
state.Send(new MobileStatus(m, m));
state.Send(Network.SetWarMode.Instantiate(m.Warmode));
Packets.SendSupportedFeatures(state);
Packets.SendMobileUpdate(state, m);
Packets.SendMobileStatus(state, m, m);
Packets.SendSetWarMode(state, m.Warmode);
Packets.SendMobileIncoming(state, m, m);
m.SendEverything();
state.Send(SupportedFeatures.Instantiate(state));
state.Send(new MobileUpdate(m));
//state.Send( new MobileAttributes( m ) );
state.Send(new MobileStatus(m, m));
state.Send(Network.SetWarMode.Instantiate(m.Warmode));
state.Send(new MobileIncoming(m, m));
}
else if (state.StygianAbyss)
{
state.Send(new MobileUpdate(m));
state.Send(new MobileUpdate(m));
m.CheckLightLevels(true);
state.Send(new MobileUpdate(m));
state.Send(new MobileIncomingSA(m, m));
//state.Send( new MobileAttributes( m ) );
state.Send(new MobileStatus(m, m));
state.Send(Network.SetWarMode.Instantiate(m.Warmode));
m.SendEverything();
state.Send(SupportedFeatures.Instantiate(state));
state.Send(new MobileUpdate(m));
//state.Send( new MobileAttributes( m ) );
state.Send(new MobileStatus(m, m));
state.Send(Network.SetWarMode.Instantiate(m.Warmode));
state.Send(new MobileIncomingSA(m, m));
}
else
{
state.Send(new MobileUpdateOld(m));
state.Send(new MobileUpdateOld(m));
m.CheckLightLevels(true);
state.Send(new MobileUpdateOld(m));
state.Send(new MobileIncomingOld(m, m));
//state.Send( new MobileAttributes( m ) );
state.Send(new MobileStatus(m, m));
state.Send(Network.SetWarMode.Instantiate(m.Warmode));
m.SendEverything();
state.Send(SupportedFeatures.Instantiate(state));
state.Send(new MobileUpdateOld(m));
//state.Send( new MobileAttributes( m ) );
state.Send(new MobileStatus(m, m));
state.Send(Network.SetWarMode.Instantiate(m.Warmode));
state.Send(new MobileIncomingOld(m, m));
}
state.Send(LoginComplete.Instance);
state.Send(new CurrentTime());
state.Send(SeasonChange.Instantiate(m.GetSeason(), true));
state.Send(new MapChange(m));
Packets.SendLoginComplete(state);
Packets.SendCurrentTime(state);
Packets.SendMapChange(state, m.Map);
Packets.SendSeasonChange(state, m.GetSeason(), 1);
EventSink.InvokeLogin(new LoginEventArgs(m));
@ -2334,20 +2041,14 @@ namespace Server.Network
race = Race.Races[raceID];
}
else
{
race = Race.Races[(byte)(genderRace / 2)];
}
if (race == null)
race = Race.DefaultRace;
race ??= Race.DefaultRace;
CityInfo[] info = state.CityInfo;
IAccount a = state.Account;
if (info == null || a == null || cityIndex < 0 || cityIndex >= info.Length)
{
state.Dispose();
}
else
{
// Check if anyone is using this account
@ -2358,7 +2059,7 @@ namespace Server.Network
if (check != null && check.Map != Map.Internal)
{
Console.WriteLine("Login: {0}: Account in use", state);
state.Send(new PopupMessage(PMMessage.CharInWorld));
Packets.SendPopupMessage(state, PMMessage.CharInWorld);
return;
}
}
@ -2383,7 +2084,7 @@ namespace Server.Network
race
);
state.Send(new ClientVersionReq());
Packets.SendClientVersionReq(state);
state.BlockAllPackets = true;
@ -2453,10 +2154,8 @@ namespace Server.Network
bool female = genderRace % 2 != 0;
Race race;
byte raceID = (byte)(genderRace < 4 ? 0 : genderRace / 2 - 1);
race = Race.Races[raceID] ?? Race.DefaultRace;
byte raceId = (byte)(genderRace < 4 ? 0 : genderRace / 2 - 1);
Race race = Race.Races[raceId] ?? Race.DefaultRace;
CityInfo[] info = state.CityInfo;
IAccount a = state.Account;
@ -2475,7 +2174,7 @@ namespace Server.Network
if (check != null && check.Map != Map.Internal)
{
Console.WriteLine("Login: {0}: Account in use", state);
state.Send(new PopupMessage(PMMessage.CharInWorld));
Packets.SendPopupMessage(state, PMMessage.CharInWorld);
return;
}
}
@ -2501,25 +2200,20 @@ namespace Server.Network
race
);
state.Send(new ClientVersionReq());
state.BlockAllPackets = true;
Packets.SendClientVersionReq(state);
EventSink.InvokeCharacterCreated(args);
Mobile m = args.Mobile;
if (m != null)
{
state.BlockAllPackets = true;
state.Mobile = m;
m.NetState = state;
new LoginTimer(state, m).Start();
}
else
{
state.BlockAllPackets = false;
state.Dispose();
}
}
}
@ -2530,11 +2224,11 @@ namespace Server.Network
int oldestID = 0;
DateTime oldest = DateTime.MaxValue;
foreach (KeyValuePair<int, AuthIDPersistence> kvp in m_AuthIDWindow)
if (kvp.Value.Age < oldest)
foreach (var (key, value) in m_AuthIDWindow)
if (value.Age < oldest)
{
oldestID = kvp.Key;
oldest = kvp.Value.Age;
oldestID = key;
oldest = value.Age;
}
m_AuthIDWindow.Remove(oldestID);
@ -2564,13 +2258,13 @@ namespace Server.Network
}
state.SentFirstPacket = true;
state.UseCompression = true;
int authID = pvSrc.ReadInt32();
if (m_AuthIDWindow.TryGetValue(authID, out AuthIDPersistence ap))
{
m_AuthIDWindow.Remove(authID);
state.Version = ap.Version;
}
else if (ClientVerification)
@ -2604,19 +2298,12 @@ namespace Server.Network
if (e.Accepted)
{
state.CityInfo = e.CityInfo;
state.CompressionEnabled = true;
state.Send(SupportedFeatures.Instantiate(state));
if (state.NewCharacterList)
state.Send(new CharacterList(state.Account, state.CityInfo));
else
state.Send(new CharacterListOld(state.Account, state.CityInfo));
Packets.SendSupportedFeatures(state);
Packets.SendCharacterList(state, state.CityInfo);
}
else
{
state.Dispose();
}
}
public static void PlayServer(NetState state, PacketReader pvSrc)
@ -2626,17 +2313,15 @@ namespace Server.Network
IAccount a = state.Account;
if (info == null || a == null || index < 0 || index >= info.Length)
{
state.Dispose();
}
else
{
ServerInfo si = info[index];
state.m_AuthID = PlayServerAck.m_AuthID = GenerateAuthID(state);
state.m_AuthID = GenerateAuthID(state);
state.SentFirstPacket = false;
state.Send(new PlayServerAck(si));
Packets.SendPlayServerAck(state, si);
}
}
@ -2734,13 +2419,13 @@ namespace Server.Network
state.ServerInfo = info;
state.Send(new AccountLoginAck(info));
Packets.SendAccountLoginAck(state, info);
}
}
public static void AccountLogin_ReplyRej(NetState state, ALRReason reason)
{
state.Send(new AccountLoginRej(reason));
Packets.SendAccountLoginRej(state, reason);
state.Dispose();
}
@ -2758,7 +2443,10 @@ namespace Server.Network
protected override void OnTick()
{
if (m_State == null)
{
Stop();
return;
}
if (m_State.Version != null)
{