public static void DisplayGumpResponse(NetState state, PacketReader pvSrc) { int serial = pvSrc.ReadInt32(); int typeID = pvSrc.ReadInt32(); int buttonID = pvSrc.ReadInt32(); List<Gump> gumps = state.Gumps; for (int i = 0; i < gumps.Count; ++i) { Gump gump = gumps[i]; if (gump.Serial == serial && gump.TypeID == typeID) { int switchCount = pvSrc.ReadInt32(); if (switchCount < 0) { Console.WriteLine("Client: {0}: Invalid gump response, disconnecting...", state); state.Dispose(); return; } int[] switches = new int[switchCount]; for (int j = 0; j < switches.Length; ++j) switches[j] = pvSrc.ReadInt32(); int textCount = pvSrc.ReadInt32(); if (textCount < 0) { Console.WriteLine("Client: {0}: Invalid gump response, disconnecting...", state); state.Dispose(); return; } TextRelay[] textEntries = new TextRelay[textCount]; for (int j = 0; j < textEntries.Length; ++j) { int entryID = pvSrc.ReadUInt16(); int textLength = pvSrc.ReadUInt16(); if (textLength > 239) return; string text = pvSrc.ReadUnicodeStringSafe(textLength); textEntries[j] = new TextRelay(entryID, text); } state.RemoveGump(i); if (!CheckResponse(gump, state.Mobile, buttonID)) return; gump.OnResponse(state, new RelayInfo(buttonID, switches, textEntries)); return; } } if (typeID == 461) // Virtue gump { int switchCount = pvSrc.ReadInt32(); if (buttonID == 1 && switchCount > 0) { Mobile beheld = World.FindMobile(pvSrc.ReadInt32()); if (beheld != null) EventSink.InvokeVirtueGumpRequest(new VirtueGumpRequestEventArgs(state.Mobile, beheld)); } else { Mobile beheld = World.FindMobile(serial); if (beheld != null) EventSink.InvokeVirtueItemRequest(new VirtueItemRequestEventArgs(state.Mobile, beheld, buttonID)); } } }
public static void DisplayGumpResponse( NetState state, PacketReader pvSrc ) { int serial = pvSrc.ReadInt32(); int typeID = pvSrc.ReadInt32(); int buttonID = pvSrc.ReadInt32(); foreach ( Gump gump in state.Gumps ) { if ( gump.Serial == serial && gump.TypeID == typeID ) { int switchCount = pvSrc.ReadInt32(); if ( switchCount < 0 || switchCount > gump.m_Switches ) { state.WriteConsole( "Invalid gump response, disconnecting..." ); state.Dispose(); return; } int[] switches = new int[switchCount]; for ( int j = 0; j < switches.Length; ++j ) switches[j] = pvSrc.ReadInt32(); int textCount = pvSrc.ReadInt32(); if ( textCount < 0 || textCount > gump.m_TextEntries ) { state.WriteConsole( "Invalid gump response, disconnecting..." ); state.Dispose(); return; } TextRelay[] textEntries = new TextRelay[textCount]; for ( int j = 0; j < textEntries.Length; ++j ) { int entryID = pvSrc.ReadUInt16(); int textLength = pvSrc.ReadUInt16(); if ( textLength > 239 ) { state.WriteConsole( "Invalid gump response, disconnecting..." ); state.Dispose(); return; } string text = pvSrc.ReadUnicodeStringSafe( textLength ); textEntries[j] = new TextRelay( entryID, text ); } state.RemoveGump( gump ); GumpProfile prof = GumpProfile.Acquire( gump.GetType() ); if ( prof != null ) { prof.Start(); } gump.OnResponse( state, new RelayInfo( buttonID, switches, textEntries ) ); if ( prof != null ) { prof.Finish(); } return; } } if ( typeID == 461 ) { // Virtue gump int switchCount = pvSrc.ReadInt32(); if ( buttonID == 1 && switchCount > 0 ) { Mobile beheld = World.FindMobile( pvSrc.ReadInt32() ); if ( beheld != null ) { EventSink.InvokeVirtueGumpRequest( new VirtueGumpRequestEventArgs( state.Mobile, beheld ) ); } } else { Mobile beheld = World.FindMobile( serial ); if ( beheld != null ) { EventSink.InvokeVirtueItemRequest( new VirtueItemRequestEventArgs( state.Mobile, beheld, buttonID ) ); } } } }
public static void DisplayGumpResponse( NetState state, PacketReader pvSrc ) { int serial = pvSrc.ReadInt32(); int typeID = pvSrc.ReadInt32(); int buttonID = pvSrc.ReadInt32(); foreach ( Gump gump in state.Gumps ) { if ( gump.Serial == serial && gump.TypeID == typeID ) { int switchCount = pvSrc.ReadInt32(); if ( switchCount < 0 || switchCount > gump.m_Switches ) { log.InfoFormat("Client: {0}: Invalid gump response, disconnecting...", state); state.Dispose(); return; } int[] switches = new int[switchCount]; for ( int j = 0; j < switches.Length; ++j ) switches[j] = pvSrc.ReadInt32(); int textCount = pvSrc.ReadInt32(); if ( textCount < 0 || textCount > gump.m_TextEntries ) { log.InfoFormat("Client: {0}: Invalid gump response, disconnecting...", state ); state.Dispose(); return; } TextRelay[] textEntries = new TextRelay[textCount]; for ( int j = 0; j < textEntries.Length; ++j ) { int entryID = pvSrc.ReadUInt16(); int textLength = pvSrc.ReadUInt16(); if ( textLength > 239 ) return; string text = pvSrc.ReadUnicodeStringSafe( textLength ); textEntries[j] = new TextRelay( entryID, text ); } state.RemoveGump( gump ); try { gump.OnResponse( state, new RelayInfo( buttonID, switches, textEntries ) ); } catch (Exception e) { log.Fatal(String.Format("Exception disarmed in gump response of {0}", gump), e); } return; } } if ( typeID == 461 ) // Virtue gump { int switchCount = pvSrc.ReadInt32(); if ( buttonID == 1 && switchCount > 0 ) { Mobile beheld = World.FindMobile( pvSrc.ReadInt32() ); if ( beheld != null ) EventSink.InvokeVirtueGumpRequest( new VirtueGumpRequestEventArgs( state.Mobile, beheld ) ); } else { Mobile beheld = World.FindMobile( serial ); if ( beheld != null ) EventSink.InvokeVirtueItemRequest( new VirtueItemRequestEventArgs( state.Mobile, beheld, buttonID ) ); } } }
public static void DisplayGumpResponse(NetState state, CircularBufferReader reader) { var serial = reader.ReadUInt32(); var typeID = reader.ReadInt32(); var buttonID = reader.ReadInt32(); foreach (var gump in state.Gumps) { if (gump.Serial != serial || gump.TypeID != typeID) { continue; } var buttonExists = buttonID == 0; // 0 is always 'close' if (!buttonExists) { foreach (var e in gump.Entries) { if (e is GumpButton button && button.ButtonID == buttonID) { buttonExists = true; break; } if (e is GumpImageTileButton tileButton && tileButton.ButtonID == buttonID) { buttonExists = true; break; } } } if (!buttonExists) { state.WriteConsole("Invalid gump response, disconnecting..."); state.Dispose(); return; } var switchCount = reader.ReadInt32(); if (switchCount < 0 || switchCount > gump.m_Switches) { state.WriteConsole("Invalid gump response, disconnecting..."); state.Dispose(); return; } var switches = new int[switchCount]; for (var j = 0; j < switches.Length; ++j) { switches[j] = reader.ReadInt32(); } var textCount = reader.ReadInt32(); if (textCount < 0 || textCount > gump.m_TextEntries) { state.WriteConsole("Invalid gump response, disconnecting..."); state.Dispose(); return; } var textEntries = new TextRelay[textCount]; for (var j = 0; j < textEntries.Length; ++j) { int entryID = reader.ReadUInt16(); int textLength = reader.ReadUInt16(); if (textLength > 239) { state.WriteConsole("Invalid gump response, disconnecting..."); state.Dispose(); return; } var text = reader.ReadBigUniSafe(textLength); textEntries[j] = new TextRelay(entryID, text); } state.RemoveGump(gump); var prof = GumpProfile.Acquire(gump.GetType()); prof?.Start(); gump.OnResponse(state, new RelayInfo(buttonID, switches, textEntries)); prof?.Finish(); return; } if (typeID == 461) { // Virtue gump var switchCount = reader.ReadInt32(); if (buttonID == 1 && switchCount > 0) { var beheld = World.FindMobile(reader.ReadUInt32()); if (beheld != null) { EventSink.InvokeVirtueGumpRequest(state.Mobile, beheld); } } else { var beheld = World.FindMobile(serial); if (beheld != null) { EventSink.InvokeVirtueItemRequest(state.Mobile, beheld, buttonID); } } } }
public static void DisplayGumpResponse(NetState state, CircularBufferReader reader, ref int packetLength) { var serial = (Serial)reader.ReadUInt32(); var typeID = reader.ReadInt32(); var buttonID = reader.ReadInt32(); foreach (var gump in state.Gumps) { if (gump.Serial != serial || gump.TypeID != typeID) { continue; } var buttonExists = buttonID == 0; // 0 is always 'close' if (!buttonExists) { foreach (var e in gump.Entries) { if (e is GumpButton button && button.ButtonID == buttonID) { buttonExists = true; break; } if (e is GumpImageTileButton tileButton && tileButton.ButtonID == buttonID) { buttonExists = true; break; } } } if (!buttonExists) { state.LogInfo("Invalid gump response, disconnecting..."); var exception = new InvalidGumpResponseException($"Button {buttonID} doesn't exist"); exception.SetStackTrace(new StackTrace()); NetState.TraceException(exception); state.Mobile?.SendMessage("Invalid gump response."); // state.Disconnect("Invalid gump response."); return; } var switchCount = reader.ReadInt32(); if (switchCount < 0 || switchCount > gump.m_Switches) { state.LogInfo("Invalid gump response, disconnecting..."); var exception = new InvalidGumpResponseException($"Bad switch count {switchCount}"); exception.SetStackTrace(new StackTrace()); NetState.TraceException(exception); state.Mobile?.SendMessage("Invalid gump response."); // state.Disconnect("Invalid gump response."); return; } var switches = new int[switchCount]; for (var i = 0; i < switches.Length; ++i) { switches[i] = reader.ReadInt32(); } var textCount = reader.ReadInt32(); if (textCount < 0 || textCount > gump.m_TextEntries) { state.LogInfo("Invalid gump response, disconnecting..."); var exception = new InvalidGumpResponseException($"Bad text entry count {textCount}"); exception.SetStackTrace(new StackTrace()); NetState.TraceException(exception); state.Mobile?.SendMessage("Invalid gump response."); // state.Disconnect("Invalid gump response."); return; } var textEntries = new TextRelay[textCount]; for (var i = 0; i < textEntries.Length; ++i) { int entryID = reader.ReadUInt16(); int textLength = reader.ReadUInt16(); if (textLength > 239) { state.LogInfo("Invalid gump response, disconnecting..."); var exception = new InvalidGumpResponseException($"Text entry {i} is too long ({textLength})"); exception.SetStackTrace(new StackTrace()); NetState.TraceException(exception); state.Mobile?.SendMessage("Invalid gump response."); // state.Disconnect("Invalid gump response."); return; } var text = reader.ReadBigUniSafe(textLength); textEntries[i] = new TextRelay(entryID, text); } state.RemoveGump(gump); var prof = GumpProfile.Acquire(gump.GetType()); prof?.Start(); gump.OnResponse(state, new RelayInfo(buttonID, switches, textEntries)); prof?.Finish(); return; } if (typeID == 461) { // Virtue gump var switchCount = reader.Remaining >= 4 ? reader.ReadInt32() : 0; if (buttonID == 1 && switchCount > 0) { var beheld = World.FindMobile((Serial)reader.ReadUInt32()); if (beheld != null) { EventSink.InvokeVirtueGumpRequest(state.Mobile, beheld); } } else { var beheld = World.FindMobile(serial); if (beheld != null) { EventSink.InvokeVirtueItemRequest(state.Mobile, beheld, buttonID); } } } }