public string ReadUnicodeStringSafe() { if (m_Reader.ReadByte() != 2) { return(""); } int length = m_Reader.ReadUInt16(); return(m_Reader.ReadUnicodeStringSafe(length)); }
public static void OpenChatWindowRequest( NetState state, PacketReader pvSrc ) { Mobile from = state.Mobile; if ( !Enabled ) { from.SendMessage( "The chat system has been disabled." ); return; } pvSrc.Seek( 2, System.IO.SeekOrigin.Begin ); /*string chatName = */ pvSrc.ReadUnicodeStringSafe( ( 0x40 - 2 ) >> 1 ).Trim(); string chatName = from.Name; SendCommandTo( from, ChatCommand.OpenChatWindow, chatName ); ChatUser.AddChatUser( from ); }
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 PartyMessage_PublicMessage( NetState state, PacketReader pvSrc ) { if ( PartyCommands.Handler != null ) PartyCommands.Handler.OnPublicMessage( state.Mobile, pvSrc.ReadUnicodeStringSafe() ); }
public static void PartyMessage_PrivateMessage( NetState state, PacketReader pvSrc ) { if ( PartyCommands.Handler != null ) PartyCommands.Handler.OnPrivateMessage( state.Mobile, World.FindMobile( pvSrc.ReadInt32() ), pvSrc.ReadUnicodeStringSafe() ); }
public static void UnicodeSpeech( NetState state, PacketReader pvSrc ) { Mobile from = state.Mobile; MessageType type = (MessageType)pvSrc.ReadByte(); int hue = pvSrc.ReadInt16(); pvSrc.ReadInt16(); // font string lang = pvSrc.ReadString( 4 ); string text; bool isEncoded = (type & MessageType.Encoded) != 0; int[] keywords; if ( isEncoded ) { int value = pvSrc.ReadInt16(); int count = (value & 0xFFF0) >> 4; int hold = value & 0xF; if ( count < 0 || count > 50 ) return; KeywordList keyList = m_KeywordList; for ( int i = 0; i < count; ++i ) { int speechID; if ( (i & 1) == 0 ) { hold <<= 8; hold |= pvSrc.ReadByte(); speechID = hold; hold = 0; } else { value = pvSrc.ReadInt16(); speechID = (value & 0xFFF0) >> 4; hold = value & 0xF; } if ( !keyList.Contains( speechID ) ) keyList.Add( speechID ); } text = pvSrc.ReadUTF8StringSafe(); keywords = keyList.ToArray(); } else { text = pvSrc.ReadUnicodeStringSafe(); keywords = m_EmptyInts; } text = text.Trim(); if ( text.Length <= 0 || text.Length > 128 ) return; type &= ~MessageType.Encoded; if ( !Enum.IsDefined( typeof( MessageType ), type ) ) type = MessageType.Regular; from.Language = lang; from.DoSpeech( text, keywords, type, Utility.ClipDyedHue( hue ) ); }
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 OpenChatWindowRequest( NetState state, PacketReader pvSrc ) { Mobile from = state.Mobile; if ( !m_Enabled ) { from.SendMessage( "The chat system has been disabled." ); return; } pvSrc.Seek( 2, System.IO.SeekOrigin.Begin ); string chatName = pvSrc.ReadUnicodeStringSafe( ( 0x40 - 2 ) >> 1 ).Trim(); Account acct = state.Account as Account; string accountChatName = null; if ( acct != null ) accountChatName = acct.GetTag( "ChatName" ); if ( accountChatName != null ) accountChatName = accountChatName.Trim(); if ( accountChatName != null && accountChatName.Length > 0 ) { if ( chatName.Length > 0 && chatName != accountChatName ) from.SendMessage( "You cannot change chat nickname once it has been set." ); } else { if ( chatName == null || chatName.Length == 0 ) { SendCommandTo( from, ChatCommand.AskNewNickname ); return; } if ( NameVerification.Validate( chatName, 2, 31, true, true, true, 0, NameVerification.SpaceDashPeriodQuote ) && chatName.ToLower().IndexOf( "system" ) == -1 ) { // TODO: Optimize this search foreach ( Account checkAccount in Accounts.Table.Values ) { string existingName = checkAccount.GetTag( "ChatName" ); if ( existingName != null ) { existingName = existingName.Trim(); if ( Insensitive.Equals( existingName, chatName ) ) { from.SendMessage( "Nickname already in use." ); SendCommandTo( from, ChatCommand.AskNewNickname ); return; } } } accountChatName = chatName; if ( acct != null ) acct.AddTag( "ChatName", chatName ); } else { from.SendLocalizedMessage( 501173 ); // That name is disallowed. SendCommandTo( from, ChatCommand.AskNewNickname ); return; } } SendCommandTo( from, ChatCommand.OpenChatWindow, accountChatName ); ChatUser.AddChatUser( from ); }