static CallbackResult OnLoginConfirm(byte[] data, CallbackResult prevResult) { lock (World.SyncRoot) { if (data[0] != 0x1B) { throw new Exception("Invalid packet passed to OnLoginConfirm."); } bool expected = (World.PlayerSerial == World.InvalidSerial); uint serial = ByteConverter.BigEndian.ToUInt32(data, 1); if (!expected && World.PlayerSerial != serial) { Trace.WriteLine("Invalid serial in LoginConfirm! Packet ignored.", "World"); return(CallbackResult.Normal); } World.PlayerSerial = serial; RealCharacter chr = World.FindRealCharacter(World.PlayerSerial); if (chr == null) { chr = new RealCharacter(World.PlayerSerial); World.Add(chr); } chr.Graphic = ByteConverter.BigEndian.ToUInt16(data, 9); chr.X = ByteConverter.BigEndian.ToUInt16(data, 11); chr.Y = ByteConverter.BigEndian.ToUInt16(data, 13); chr.Z = ByteConverter.BigEndian.ToSByte(data, 16); chr.Direction = ByteConverter.BigEndian.ToByte(data, 17); WalkHandling.ClearStack(); if (expected) { Trace.WriteLine(String.Format("Player logged in. ({0}).", chr), "World"); } else { Trace.WriteLine("Unexpected LoginConfirm packet.", "World"); } return(CallbackResult.Normal); } }
static CallbackResult OnPlayerSync(byte[] data, CallbackResult prevResult) { lock (World.SyncRoot) { if (data[0] != 0x20) { throw new Exception("Invalid packet passed to OnPlayerSync."); } uint serial = ByteConverter.BigEndian.ToUInt32(data, 1); if (World.RealPlayer == null) { Trace.WriteLine(String.Format("LoginConfirm packet not received yet."), "World"); return(CallbackResult.Normal); } if (World.PlayerSerial != serial) { throw new InvalidOperationException("Invalid serial in 0x20 packet."); } World.RealPlayer.Graphic = ByteConverter.BigEndian.ToUInt16(data, 5); World.RealPlayer.Status = data[7]; World.RealPlayer.Color = ByteConverter.BigEndian.ToUInt16(data, 8); World.RealPlayer.Flags = ByteConverter.BigEndian.ToByte(data, 10); World.RealPlayer.X = ByteConverter.BigEndian.ToUInt16(data, 11); World.RealPlayer.Y = ByteConverter.BigEndian.ToUInt16(data, 13); World.RealPlayer.Z = ByteConverter.BigEndian.ToSByte(data, 18); World.RealPlayer.Direction = ByteConverter.BigEndian.ToByte(data, 17); WalkHandling.ClearStack(); Trace.WriteLine(String.Format("Player updated ({0}).", World.RealPlayer), "World"); ObjectChanged(serial, ObjectChangeType.CharUpdated); return(CallbackResult.Normal); } }