private static void CustomRunebookTravel(NetState state, PacketReader pvSrc) { int RuneBookSerial = pvSrc.ReadInt32(); byte recall = pvSrc.ReadByte(); var X = pvSrc.ReadInt16(); var Y = pvSrc.ReadInt16(); var mapbyte = Convert.ToInt16(pvSrc.ReadByte()); var runebook = World.FindItem(RuneBookSerial) as Runebook; var map = Map.Maps[mapbyte]; if (runebook != null && runebook.RootParentEntity == state.Mobile && runebook.Entries != null) { var findentry = runebook.Entries.FirstOrDefault(x => x.Location.X == X && x.Location.Y == Y); if (findentry != null) { var portentry = findentry.Location; var entry = new RunebookEntry(portentry, findentry.Map, "", null); if (recall == 0) { new RecallSpell(state.Mobile, null, entry, null).Cast(); } else { new GateTravelSpell(state.Mobile, null, entry).Cast(); } } } }
public static void BBClientRequest(NetState state, PacketReader pvSrc) { Mobile from = state.Mobile; int packetID = pvSrc.ReadByte(); BaseBulletinBoard board = World.FindItem(pvSrc.ReadInt32()) as BaseBulletinBoard; if (board == null || !board.CheckRange(from)) return; switch ( packetID ) { case 3: BBRequestContent(from, board, pvSrc); break; case 4: BBRequestHeader(from, board, pvSrc); break; case 5: BBPostMessage(from, board, pvSrc); break; case 6: BBRemoveMessage(from, board, pvSrc); break; } }
public static void OnReceive( GameClient state, PacketReader pvSrc ) { if ( pvSrc.ReadByte() == 0xFF ) state.Send( new UOGInfo( String.Format( ", Name={0}, Age={1}, Clients={2}, Items={3}, Chars={4}, Mem={5}K", Environment.Config.ServerName, (int) ( DateTime.Now - Server.Items.Clock.ServerStart ).TotalHours, GameServer.Instance.ClientCount, World.Instance.ItemCount, World.Instance.MobileCount, (int) ( System.GC.GetTotalMemory( false ) / 1024 ) ) ) ); state.Dispose(); }
public static void DecodeBundledPacket(NetState state, PacketReader pvSrc) { int packetID = pvSrc.ReadByte(); PacketHandler ph = GetHandler(packetID); if (ph != null) { if (ph.Ingame && state.Mobile == null) { Utility.PushColor(ConsoleColor.DarkRed); Console.WriteLine("Client: {0}: Sent ingame packet (0xF0x{1:X2}) before having been attached to a mobile", state, packetID); Utility.PopColor(); state.Dispose(); } else if (ph.Ingame && state.Mobile.Deleted) { state.Dispose(); } else { ph.OnReceive(state, pvSrc); } } }
private static void BountyEntryResponse( NetState ns, PacketReader pvSrc ) { Mobile from = ns.Mobile; if ( from == null ) return; Mobile killer = World.FindMobile( (Serial)pvSrc.ReadInt32() ); byte typeid = pvSrc.ReadByte(); byte index = pvSrc.ReadByte(); bool cancel = pvSrc.ReadByte() == 0; short responseLen = pvSrc.ReadInt16(); string resp = pvSrc.ReadString(); if ( killer != null && !cancel ) { int bounty = Utility.ToInt32( resp ); if ( bounty > 5000 ) bounty = 5000; bounty = from.BankBox.ConsumeUpTo( typeof( Gold ), bounty, true ); killer.Kills++; if ( killer is PlayerMobile && bounty > 0 ) { PlayerMobile kpm = (PlayerMobile)killer; kpm.Bounty += bounty; killer.SendAsciiMessage( "{0} has placed a bounty of {1}gp on your head!", from.Name, bounty ); if ( kpm.Bounty >= 5000 && kpm.Kills > 1 && kpm.BankBox.Items.Count > 0 && kpm.Karma <= (int)Noto.Dark ) { killer.SayTo( killer, true, "A bounty hath been issued for thee, and thy worldly goods are hereby confiscated!" ); kpm.Bounty += EmptyAndGetGold( killer.BankBox.Items ); } } } SendNext( from ); }
public static void HeritageTransform(NetState state, PacketReader reader) { Mobile m = state.Mobile; if (reader.Size == 5) { m.SendLocalizedMessage(1073645); // You may try this again later... HeritageQuester.RemovePending(m); } else if (reader.Size == 15) { if (HeritageQuester.IsPending(m)) { HeritageQuester quester = HeritageQuester.Pending(m); m.Race = quester.Race; m.Hue = reader.ReadUInt16(); m.HairItemID = reader.ReadUInt16(); m.HairHue = reader.ReadUInt16(); m.FacialHairItemID = reader.ReadUInt16(); m.FacialHairHue = reader.ReadUInt16(); HeritageQuester.RemovePending(m); quester.CheckCompleted(m, true); // removes done quests if (m.Race == Race.Elf) m.SendLocalizedMessage(1073653); // You are now fully initiated into the Elven culture. else if (m.Race == Race.Human) m.SendLocalizedMessage(1073654); // You are now fully human. } } }
public static void BuildWalls(MahjongGame game, NetState state, PacketReader pvSrc) { if (game == null || !game.Players.IsInGameDealer(state.Mobile)) return; game.ResetWalls(state.Mobile); }
public static void ExitGame(MahjongGame game, NetState state, PacketReader pvSrc) { if (game == null) return; Mobile from = state.Mobile; game.Players.LeaveGame(from); }
private static void AccountSearch(NetState state, PacketReader pvSrc) { AcctSearchType type = (AcctSearchType)pvSrc.ReadByte(); string term = pvSrc.ReadString(); if (type == AcctSearchType.IP && !Utility.IsValidIP(term)) { state.Send(new MessageBoxMessage("Invalid search term.\nThe IP sent was not valid.", "Invalid IP")); return; } else { term = term.ToUpper(); } ArrayList list = new ArrayList(); foreach (Account a in Accounts.GetAccounts()) { if (!CanAccessAccount(state.Account, a)) continue; switch ( type ) { case AcctSearchType.Username: { if (a.Username.ToUpper().IndexOf(term) != -1) list.Add(a); break; } case AcctSearchType.IP: { for (int i = 0; i < a.LoginIPs.Length; i++) { if (Utility.IPMatch(term, a.LoginIPs[i])) { list.Add(a); break; } } break; } } } if (list.Count > 0) { if (list.Count <= 25) state.Send(AdminNetwork.Compress(new AccountSearchResults(list))); else state.Send(new MessageBoxMessage("There were more than 25 matches to your search.\nNarrow the search parameters and try again.", "Too Many Results")); } else { state.Send(new MessageBoxMessage("There were no results to your search.\nPlease try again.", "No Matches")); } }
public static void AssignDealer(MahjongGame game, NetState state, PacketReader pvSrc) { if (game == null || !game.Players.IsInGameDealer(state.Mobile)) return; int position = pvSrc.ReadByte(); game.Players.AssignDealer(position); }
private static void WorldBroadcast( NetState state, PacketReader pvSrc ) { string message = pvSrc.ReadUTF8String(); int hue = pvSrc.ReadInt16(); bool ascii = pvSrc.ReadBoolean(); World.Broadcast(hue, ascii, message); state.Send( new MessageBoxMessage( "Your message has been broadcasted.", "Message Broadcasted" ) ); }
public static void GivePoints(MahjongGame game, NetState state, PacketReader pvSrc) { if (game == null || !game.Players.IsInGamePlayer(state.Mobile)) return; int to = pvSrc.ReadByte(); int amount = pvSrc.ReadInt32(); game.Players.TransferScore(state.Mobile, to, amount); }
public static void HookedPlayServer(NetState state, PacketReader pvSrc) { // Call the original handler PacketHandlers.PlayServer(state, pvSrc); // Now indicate, that the state has been relayed already. If it's used again, // it means we're entering a special encryption state Encryption context = (Encryption)(state.PacketEncoder); context.m_AlreadyRelayed = true; }
public static void InvokeContentChangeParent(NetState state, PacketReader pvSrc) { if (ContentChangeParent != null) { ContentChangeParent.OnReceive(state, pvSrc); } else { BaseBook.ContentChange(state, pvSrc); } }
public static void InvokeLookReqParent(NetState state, PacketReader pvSrc) { if (LookReqParent != null) { LookReqParent.OnReceive(state, pvSrc); } else { PacketHandlers.LookReq(state, pvSrc); } }
private static void Shutdown( NetState state, PacketReader pvSrc ) { bool restart = pvSrc.ReadBoolean(); bool save = pvSrc.ReadBoolean(); Console.WriteLine( "RemoteAdmin: shutting down server (Restart: {0}) (Save: {1}) [{2}]", restart, save, DateTime.Now ); if ( save && !AutoRestart.Restarting ) Misc.AutoSave.Save(); Core.Kill( restart ); }
public static bool Handle( byte command, NetState state, PacketReader pvSrc ) { if ( m_Handlers[command] == null ) { Console.WriteLine( "ADMIN: Invalid packet 0x{0:X2} from {1}, disconnecting", command, state ); return false; } else { m_Handlers[command]( state, pvSrc ); return true; } }
public static void QueryPartyLocations(NetState state, PacketReader pvSrc) { Mobile from = state.Mobile; Party party = Party.Get(from); if (party != null) { AckPartyLocations ack = new AckPartyLocations(from, party); if (ack.UnderlyingStream.Length > 8) state.Send(ack); } }
private static void OnPartyTrack( NetState state, PacketReader pvSrc ) { Mobile from = state.Mobile; Party party = Party.Get( from ); if ( party != null ) { Packets.PartyTrack packet = new Packets.PartyTrack( from, party ); if ( packet.UnderlyingStream.Length > 8 ) state.Send( packet ); } }
public static void ChangeOption(MahjongGame game, NetState state, PacketReader pvSrc) { if (game == null || !game.Players.IsInGameDealer(state.Mobile)) return; pvSrc.ReadInt16(); pvSrc.ReadByte(); int options = pvSrc.ReadByte(); game.ShowScores = (options & 0x1) != 0; game.SpectatorVision = (options & 0x2) != 0; }
public static bool Handle( byte command, NetState state, PacketReader pvSrc ) { if ( m_Handlers[command] == null ) { log.Warn(String.Format("ADMIN: Invalid packet 0x{0:X2} from {1}, disconnecting", command, state)); return false; } else { m_Handlers[command]( state, pvSrc ); return true; } }
private static void CustomRunebook(NetState state, PacketReader pvSrc) { int RuneBookSerial = pvSrc.ReadInt32(); var runebook = World.FindItem(RuneBookSerial) as Runebook; if (runebook != null) { Packets.SallosRunebook packet = new Packets.SallosRunebook(runebook); if (packet.UnderlyingStream.Length > 7) state.Send(packet); } }
public static void ChatAction( NetState state, PacketReader pvSrc ) { if ( !m_Enabled ) return; try { Mobile from = state.Mobile; ChatUser user = ChatUser.GetChatUser( from ); if ( user == null ) return; /*string lang = */pvSrc.ReadStringSafe( 4 ); int actionID = pvSrc.ReadInt16(); string param = pvSrc.ReadUnicodeString(); ChatActionHandler handler = ChatActionHandlers.GetHandler( actionID ); if ( handler != null ) { Channel channel = user.CurrentChannel; if ( handler.RequireConference && channel == null ) { user.SendMessage( 31 ); /* You must be in a conference to do this. * To join a conference, select one from the Conference menu. */ } else if ( handler.RequireModerator && !user.IsModerator ) { user.SendMessage( 29 ); // You must have operator status to do this. } else { handler.Callback( user, channel, param ); } } else { log.Warn(String.Format("Client: {0}: Unknown chat action 0x{1:X}: {2}", state, actionID, param)); } } catch ( Exception e ) { log.Error( e ); } }
public static void Authenticate( NetState state, PacketReader pvSrc ) { string user = pvSrc.ReadString( 30 ); string pw = pvSrc.ReadString( 30 ); Account a = Accounts.GetAccount( user ); if ( a == null ) { state.Send( new Login( LoginResponse.NoUser ) ); log.Warn(String.Format("ADMIN: Invalid username '{0}' from {1}", user, state)); DelayedDisconnect( state ); } else if ( !a.HasAccess( state ) ) { state.Send( new Login( LoginResponse.BadIP ) ); log.Warn(String.Format("ADMIN: Access to '{0}' from {1} denied.", user, state)); DelayedDisconnect( state ); } else if ( !a.CheckPassword( pw ) ) { state.Send( new Login( LoginResponse.BadPass ) ); log.Warn(String.Format("ADMIN: Invalid password '{0}' for user '{1}' from {2}", pw, user, state)); DelayedDisconnect( state ); } else if ( a.AccessLevel != AccessLevel.Administrator || a.Banned ) { log.Warn(String.Format("ADMIN: Account '{0}' does not have admin access. Connection Denied.", user)); state.Send( new Login( LoginResponse.NoAccess ) ); DelayedDisconnect( state ); } else { log.Warn(String.Format("ADMIN: Access granted to '{0}' from {1}", user, state)); state.Account = a; a.LogAccess( state ); a.LastLogin = DateTime.Now; state.Send( new Login( LoginResponse.OK ) ); state.Send( Compress( new ConsoleData( m_ConsoleData.ToString() ) ) ); m_Auth.Add( state ); } }
public static void TargetResponse( NetState state, PacketReader pvSrc ) { int type = pvSrc.ReadByte(); int targetID = pvSrc.ReadInt32(); int flags = pvSrc.ReadByte(); Serial serial = pvSrc.ReadInt32(); int x = pvSrc.ReadInt16(), y = pvSrc.ReadInt16(); int z = pvSrc.ReadInt16(); int graphic = pvSrc.ReadInt16(); pvSrc.Seek( 1, System.IO.SeekOrigin.Begin ); Mobile from = state.Mobile; if ( from == null || from.Target == null ) return; if ( x == 0 && y == 0 && z == 0 && serial != from.Serial ) { bool ok = false; if ( serial.IsItem ) { Item i = World.FindItem( serial ); if ( i != null && i.Location == Point3D.Zero ) ok = true; } else if ( serial.IsMobile ) { Mobile m = World.FindMobile( serial ); if ( m != null && m.Location == Point3D.Zero ) ok = true; } object o = m_LastTarget[from]; if ( !ok && o != null && o is Serial && serial != (Serial)o ) { from.SendAsciiMessage( "This EasyUO target has been blocked." ); from.Target.Cancel( from, TargetCancelType.Canceled ); return; } } if ( from.Serial != serial ) m_LastTarget[from] = serial; m_Real6C.OnReceive( state, pvSrc ); }
private static void OnGuildTrack( NetState state, PacketReader pvSrc ) { Mobile from = state.Mobile; Guild guild = from.Guild as Guild; if ( guild != null ) { bool locations = pvSrc.ReadByte() != 0; Packets.GuildTrack packet = new Packets.GuildTrack( from, guild, locations ); if ( packet.UnderlyingStream.Length > ( locations ? 9 : 5 ) ) state.Send( packet ); } else state.Send( new Packets.GuildTrack() ); }
public static void RemoveHighlightKRUIElement( GameClient state, PacketReader pvSrc ) { Mobile m = World.Instance.FindMobile( (Serial) pvSrc.ReadInt32() ); int elementID = pvSrc.ReadInt16(); PlayerMobile pm = m as PlayerMobile; if ( pm != null ) { if ( elementID == 0x791F ) pm.CheckKRStartingQuestStep( 15 ); if ( elementID == 0x7919 ) pm.CheckKRStartingQuestStep( 6 ); } }
public static void ChatAction( NetState state, PacketReader pvSrc ) { if ( !Enabled ) return; try { Mobile from = state.Mobile; ChatUser user = ChatUser.GetChatUser( from ); if ( user == null ) return; string lang = pvSrc.ReadStringSafe( 4 ); int actionId = pvSrc.ReadInt16(); string param = pvSrc.ReadUnicodeString(); ChatActionHandler handler = ChatActionHandlers.GetHandler( actionId ); if ( handler != null ) { Channel channel = user.CurrentChannel; if ( handler.RequireConference && channel == null ) { /* You must be in a conference to do this. * To join a conference, select one from the Conference menu. */ user.SendMessage( 31 ); } else { handler.Callback( user, channel, param ); } } else { Console.WriteLine( "Client: {0}: Unknown chat action 0x{1:X}: {2}", state, actionId, param ); } } catch ( Exception e ) { Console.WriteLine(e.ToString()); } }
public static void MultiMouseMovementRequest(NetState state, PacketReader reader) { Serial playerSerial = reader.ReadInt32(); Direction movement = (Direction)reader.ReadByte(); reader.ReadByte(); // movement direction duplicated int speed = reader.ReadByte(); Mobile mob = World.FindMobile(playerSerial); if (mob == null || mob.NetState == null || !mob.Mounted) return; IMount multi = mob.Mount; if (!(multi is BaseBoat)) return; BaseBoat boat = (BaseBoat)multi; boat.OnMousePilotCommand(mob, movement, speed); }
private static void OnHandshakeResponse(NetState state, PacketReader pvSrc) { pvSrc.Trace(state); if (state == null || state.Mobile == null || !state.Running) return; Timer t; Mobile m = state.Mobile; if (m_Dictionary.TryGetValue(m, out t)) { if (t != null) t.Stop(); m_Dictionary.Remove(m); } }
public static void PingReq(NetState state, PacketReader pvSrc) { state.Send(PingAck.Instantiate(pvSrc.ReadByte())); }
public void HandleReceive(NetState ns) { ByteQueue buffer = ns.Buffer; if (buffer == null || buffer.Length <= 0) { return; } lock (buffer) { if (!ns.Seeded && !HandleSeed(ns, buffer)) { return; } int length = buffer.Length; while (length > 0 && ns.Running) { int packetID = buffer.GetPacketID(); if (CheckEncrypted(ns, packetID)) { return; } PacketHandler handler = ns.GetHandler(packetID); if (handler == null) { var data = new byte[length]; length = buffer.Dequeue(data, 0, length); new PacketReader(data, length, false).Trace(ns); return; } int packetLength = handler.Length; if (packetLength <= 0) { if (length >= 3) { packetLength = buffer.GetPacketLength(); if (packetLength < 3) { ns.Dispose(); return; } } else { return; } } if (length < packetLength) { return; } if (handler.Ingame) { if (ns.Mobile == null) { Utility.PushColor(ConsoleColor.DarkRed); Console.WriteLine("Client: {0}: Sent ingame packet (0x{1:X2}) before having been attached to a mobile", ns, packetID); Utility.PopColor(); ns.Dispose(); return; } if (ns.Mobile.Deleted) { ns.Dispose(); break; } } ThrottlePacketCallback throttler = handler.ThrottleCallback; if (throttler != null && !throttler(ns)) { m_Throttled.Enqueue(ns); return; } PacketReceiveProfile prof = null; if (Core.Profiling) { prof = PacketReceiveProfile.Acquire(packetID); } if (prof != null) { prof.Start(); } byte[] packetBuffer; if (BufferSize >= packetLength) { packetBuffer = m_Buffers.AcquireBuffer(); } else { packetBuffer = new byte[packetLength]; } packetLength = buffer.Dequeue(packetBuffer, 0, packetLength); if (packetBuffer != null && packetBuffer.Length > 0 && packetLength > 0) { PacketReader r = new PacketReader(packetBuffer, packetLength, handler.Length != 0); handler.OnReceive(ns, r); if (BufferSize >= packetLength) { m_Buffers.ReleaseBuffer(packetBuffer); } } if (prof != null) { prof.Finish(packetLength); } length = buffer.Length; } } }
public EncodedReader(PacketReader reader) { m_Reader = reader; }
public bool HandleReceive(NetState ns) { ByteQueue queue1; int num1; int num2; int num3; PacketHandler handler1; byte[] buffer1; int num4; ThrottlePacketCallback callback1; PacketProfile profile1; DateTime time1; PacketReader reader1; NetState state1 = ns; lock (ns) { queue1 = ns.Buffer; if (queue1 == null) { return(true); } num1 = queue1.Length; if (ns.Seeded) { goto Label_0250; } if (num1 >= 4) { queue1.Dequeue(this.m_Peek, 0, 4); num2 = ((((this.m_Peek[0] << 24) | (this.m_Peek[1] << 16)) | (this.m_Peek[2] << 8)) | this.m_Peek[3]); if (num2 == 0) { Console.WriteLine("Login: {0}: Invalid client detected, disconnecting", ns); ns.Dispose(); return(false); } ns.m_Seed = num2; ns.Seeded = true; } return(true); Label_009D: queue1.Peek(this.m_Peek, 0, 1); num3 = this.m_Peek[0]; if (((!ns.SentFirstPacket && (num3 != 241)) && ((num3 != 207) && (num3 != 128))) && ((num3 != 145) && (num3 != 164))) { Console.WriteLine("Client: {0}: Encrypted client detected, disconnecting", ns); ns.Dispose(); goto Label_0269; } handler1 = PacketHandlers.GetHandler(num3); if (handler1 == null) { buffer1 = queue1.Dequeue(num1); new PacketReader(buffer1, 0).Trace(ns); goto Label_0269; } num4 = handler1.Length; if (num4 <= 0) { if (num1 < 3) { goto Label_0269; } queue1.Peek(this.m_Peek, 0, 3); num4 = ((this.m_Peek[1] << 8) | this.m_Peek[2]); if (num4 < 3) { ns.Dispose(); goto Label_0269; } } if (num1 < num4) { goto Label_0269; } if (handler1.Ingame && (ns.Mobile == null)) { Console.WriteLine("Client: {0}: Sent ingame packet (0x{1:X2}) before having been attached to a mobile", ns, num3); ns.Dispose(); goto Label_0269; } if (handler1.Ingame && ns.Mobile.Deleted) { ns.Dispose(); goto Label_0269; } callback1 = handler1.ThrottleCallback; if ((callback1 != null) && !callback1.Invoke(ns)) { this.m_Throttled.Enqueue(ns); return(false); } profile1 = PacketProfile.GetIncomingProfile(num3); time1 = ((profile1 == null) ? DateTime.MinValue : DateTime.Now); reader1 = new PacketReader(queue1.Dequeue(num4), (handler1.Length != 0)); handler1.OnReceive(ns, reader1); num1 = queue1.Length; if (profile1 != null) { profile1.Record(num4, ((TimeSpan)(DateTime.Now - time1))); } Label_0250: if (num1 > 0) { if (ns.Running) { goto Label_009D; } } } Label_0269: return(true); }
public bool HandleReceive(NetState ns) { ByteQueue buffer = ns.Buffer; if (buffer == null || buffer.Length <= 0) { return(true); } lock ( buffer ) { int length = buffer.Length; if (!ns.Seeded) { if (buffer.GetPacketID() == 0xEF) { // new packet in client 6.0.5.0 replaces the traditional seed method with a seed packet // 0xEF = 239 = multicast IP, so this should never appear in a normal seed. So this is backwards compatible with older clients. ns.Seeded = true; } else if (buffer.Length >= 4) { buffer.Dequeue(m_Peek, 0, 4); int seed = (m_Peek[0] << 24) | (m_Peek[1] << 16) | (m_Peek[2] << 8) | m_Peek[3]; if (seed == 0) { Console.WriteLine("Login: {0}: Invalid client detected, disconnecting", ns); ns.Dispose(); return(false); } ns.m_Seed = seed; ns.Seeded = true; length = buffer.Length; } else { return(true); } } while (length > 0 && ns.Running) { int packetID = buffer.GetPacketID(); if (!ns.SentFirstPacket && packetID != 0xF0 && packetID != 0xF1 && packetID != 0xCF && packetID != 0x80 && packetID != 0x91 && packetID != 0xA4 && packetID != 0xEF) { Console.WriteLine("Client: {0}: Encrypted client detected, disconnecting", ns); ns.Dispose(); break; } PacketHandler handler = ns.GetHandler(packetID); if (handler == null) { byte[] data = new byte[length]; length = buffer.Dequeue(data, 0, length); new PacketReader(data, length, false).Trace(ns); break; } int packetLength = handler.Length; if (packetLength <= 0) { if (length >= 3) { packetLength = buffer.GetPacketLength(); if (packetLength < 3) { ns.Dispose(); break; } } else { break; } } if (length >= packetLength) { if (handler.Ingame && ns.Mobile == null) { Console.WriteLine("Client: {0}: Sent ingame packet (0x{1:X2}) before having been attached to a mobile", ns, packetID); ns.Dispose(); break; } else if (handler.Ingame && ns.Mobile.Deleted) { ns.Dispose(); break; } else { ThrottlePacketCallback throttler = handler.ThrottleCallback; if (throttler != null && !throttler(ns)) { m_Throttled.Enqueue(ns); return(false); } PacketReceiveProfile prof = PacketReceiveProfile.Acquire(packetID); if (prof != null) { prof.Start(); } byte[] packetBuffer; if (BufferSize >= packetLength) { packetBuffer = m_Buffers.AcquireBuffer(); } else { packetBuffer = new byte[packetLength]; } packetLength = buffer.Dequeue(packetBuffer, 0, packetLength); PacketReader r = new PacketReader(packetBuffer, packetLength, handler.Length != 0); handler.OnReceive(ns, r); length = buffer.Length; if (BufferSize >= packetLength) { m_Buffers.ReleaseBuffer(packetBuffer); } if (prof != null) { prof.Finish(packetLength); } } } else { break; } } } return(true); }
public bool HandleReceive(NetState ns) { lock ( ns ) { ByteQueue buffer = ns.Buffer; if (buffer == null) { return(true); } int length = buffer.Length; if (!ns.Seeded) { if (length >= 4) { buffer.Dequeue(m_Peek, 0, 4); int seed = (m_Peek[0] << 24) | (m_Peek[1] << 16) | (m_Peek[2] << 8) | m_Peek[3]; //Console.WriteLine( "Login: {0}: Seed is 0x{1:X8}", ns, seed ); if (seed == 0) { log.Warn(String.Format("Login: {0}: Invalid client detected, disconnecting", ns)); ns.Dispose(); return(false); } ns.m_Seed = seed; ns.Seeded = true; } return(true); } //Console.WriteLine( "{" ); while (length > 0 && ns.Running) { int packetID = buffer.GetPacketID(); if (!ns.SentFirstPacket && packetID != 0xF1 && packetID != 0xCF && packetID != 0x80 && packetID != 0x91 && packetID != 0xA4 && packetID != 0xBF) { log.Warn(String.Format("Client: {0}: Encrypted client detected, disconnecting", ns)); ns.Dispose(); break; } PacketHandler handler = PacketHandlers.GetHandler(packetID); if (handler == null) { byte[] data = new byte[length]; length = buffer.Dequeue(data, 0, length); new PacketReader(data, length, false).Trace(ns); break; } int packetLength = handler.Length; if (packetLength <= 0) { if (length >= 3) { packetLength = buffer.GetPacketLength(); if (packetLength < 3) { ns.Dispose(); break; } } else { break; } } if (length >= packetLength) { if (handler.Ingame && ns.Mobile == null) { log.Warn(String.Format("Client: {0}: Sent ingame packet (0x{1:X2}) before having been attached to a mobile", ns, packetID)); ns.Dispose(); break; } else if (handler.Ingame && ns.Mobile.Deleted) { ns.Dispose(); break; } else { ThrottlePacketCallback throttler = handler.ThrottleCallback; if (throttler != null && !throttler(ns)) { m_Throttled.Enqueue(ns); //Console.WriteLine( "}" ); return(false); } //Console.WriteLine( handler.OnReceive.Method.Name ); PacketProfile profile = PacketProfile.GetIncomingProfile(packetID); DateTime start = (profile == null ? DateTime.MinValue : DateTime.Now); byte[] packetBuffer; if (BufferSize >= packetLength) { packetBuffer = m_Buffers.AquireBuffer(); } else { packetBuffer = new byte[packetLength]; } packetLength = buffer.Dequeue(packetBuffer, 0, packetLength); PacketReader r = new PacketReader(packetBuffer, packetLength, handler.Length != 0); try { handler.OnReceive(ns, r); } catch (Exception e) { log.Fatal(String.Format("Exception disarmed in HandleReceive from {0}", ns.Address), e); } length = buffer.Length; if (BufferSize >= packetLength) { m_Buffers.ReleaseBuffer(packetBuffer); } if (profile != null) { profile.Record(packetLength, DateTime.Now - start); } //Console.WriteLine( "Client: {0}: Unhandled packet 0x{1:X2}", ns, packetID ); //Utility.FormatBuffer( Console.Out, new System.IO.MemoryStream( r.Buffer ), r.Buffer.Length ); } } else { break; } } //Console.WriteLine( "}" ); } return(true); }