diff --git a/Scripts/Commands/Decorate.cs b/Scripts/Commands/Decorate.cs index 0407f1884..fe2daf250 100644 --- a/Scripts/Commands/Decorate.cs +++ b/Scripts/Commands/Decorate.cs @@ -1055,7 +1055,7 @@ namespace Server.Commands break; } - if ( line == null || line.Length == 0 ) + if ( string.IsNullOrEmpty( line ) ) return null; DecorationList list = new DecorationList(); diff --git a/Scripts/Gumps/Guilds/New Guild System/GuildInfoGump.cs b/Scripts/Gumps/Guilds/New Guild System/GuildInfoGump.cs index 7925b3d7b..c439fa568 100644 --- a/Scripts/Gumps/Guilds/New Guild System/GuildInfoGump.cs +++ b/Scripts/Gumps/Guilds/New Guild System/GuildInfoGump.cs @@ -63,7 +63,7 @@ namespace Server.Guilds AddButton( 40, 251, 0x4B9, 0x4BA, 4, GumpButtonType.Reply, 0 ); //Charter Edit button s = guild.Website; - if( s == null || s == "" ) + if( string.IsNullOrEmpty( s ) ) s = "Guild website not yet set."; AddHtml( 65, 306, 480, 30, s, true, false ); if( isLeader ) diff --git a/Server/Mobile.cs b/Server/Mobile.cs index 904f20417..5af4d89ac 100644 --- a/Server/Mobile.cs +++ b/Server/Mobile.cs @@ -4666,7 +4666,7 @@ namespace Server text = regArgs.Speech; - if( text == null || text.Length == 0 ) + if( string.IsNullOrEmpty( text ) ) return; if( m_Hears == null ) diff --git a/Server/Network/PacketWriter.cs b/Server/Network/PacketWriter.cs index 00e9a36a7..b90353c0d 100644 --- a/Server/Network/PacketWriter.cs +++ b/Server/Network/PacketWriter.cs @@ -207,7 +207,19 @@ namespace Server.Network value = String.Empty; } - byte[] buffer = Encoding.ASCII.GetBytes( value ); + int length = value.Length; + + m_Stream.SetLength( m_Stream.Length + size ); + + if ( length >= size ) + m_Stream.Position += Encoding.ASCII.GetBytes( value, 0, size, m_Stream.GetBuffer(), (int)m_Stream.Position ); + else + { + Encoding.ASCII.GetBytes( value, 0, length, m_Stream.GetBuffer(), (int)m_Stream.Position ); + m_Stream.Position += size; + } + + /*byte[] buffer = Encoding.ASCII.GetBytes( value ); if ( buffer.Length >= size ) { @@ -217,7 +229,7 @@ namespace Server.Network { m_Stream.Write( buffer, 0, buffer.Length ); Fill( size - buffer.Length ); - } + }*/ } /// @@ -231,10 +243,17 @@ namespace Server.Network value = String.Empty; } - byte[] buffer = Encoding.ASCII.GetBytes( value ); + int length = value.Length; + + m_Stream.SetLength( m_Stream.Length + length + 1 ); + + Encoding.ASCII.GetBytes( value, 0, length, m_Stream.GetBuffer(), (int)m_Stream.Position ); + m_Stream.Position += length + 1; + + /*byte[] buffer = Encoding.ASCII.GetBytes( value ); m_Stream.Write( buffer, 0, buffer.Length ); - m_Stream.WriteByte( 0 ); + m_Stream.WriteByte( 0 );*/ } /// @@ -248,13 +267,20 @@ namespace Server.Network value = String.Empty; } - byte[] buffer = Encoding.Unicode.GetBytes( value ); + int length = value.Length; + + m_Stream.SetLength( m_Stream.Length + ( ( length + 1 ) * 2 ) ); + + m_Stream.Position += Encoding.Unicode.GetBytes( value, 0, length, m_Stream.GetBuffer(), (int)m_Stream.Position ); + m_Stream.Position += 2; + + /*byte[] buffer = Encoding.Unicode.GetBytes( value ); m_Stream.Write( buffer, 0, buffer.Length ); m_Buffer[0] = 0; m_Buffer[1] = 0; - m_Stream.Write( m_Buffer, 0, 2 ); + m_Stream.Write( m_Buffer, 0, 2 );*/ } /// @@ -270,6 +296,20 @@ namespace Server.Network size *= 2; + int length = value.Length; + + m_Stream.SetLength( m_Stream.Length + size ); + + if ( ( length * 2 ) >= size ) + m_Stream.Position += Encoding.Unicode.GetBytes( value, 0, length, m_Stream.GetBuffer(), (int)m_Stream.Position ); + else + { + Encoding.Unicode.GetBytes( value, 0, length, m_Stream.GetBuffer(), (int)m_Stream.Position ); + m_Stream.Position += size; + } + + /*size *= 2; + byte[] buffer = Encoding.Unicode.GetBytes( value ); if ( buffer.Length >= size ) @@ -280,7 +320,7 @@ namespace Server.Network { m_Stream.Write( buffer, 0, buffer.Length ); Fill( size - buffer.Length ); - } + }*/ } /// @@ -294,13 +334,20 @@ namespace Server.Network value = String.Empty; } - byte[] buffer = Encoding.BigEndianUnicode.GetBytes( value ); + int length = value.Length; + + m_Stream.SetLength( m_Stream.Length + ( ( length + 1 ) * 2 ) ); + + m_Stream.Position += Encoding.BigEndianUnicode.GetBytes( value, 0, length, m_Stream.GetBuffer(), (int)m_Stream.Position ); + m_Stream.Position += 2; + + /*byte[] buffer = Encoding.BigEndianUnicode.GetBytes( value ); m_Stream.Write( buffer, 0, buffer.Length ); m_Buffer[0] = 0; m_Buffer[1] = 0; - m_Stream.Write( m_Buffer, 0, 2 ); + m_Stream.Write( m_Buffer, 0, 2 );*/ } /// @@ -316,6 +363,20 @@ namespace Server.Network size *= 2; + int length = value.Length; + + m_Stream.SetLength( m_Stream.Length + size ); + + if ( ( length * 2 ) >= size ) + m_Stream.Position += Encoding.BigEndianUnicode.GetBytes( value, 0, length, m_Stream.GetBuffer(), (int)m_Stream.Position ); + else + { + Encoding.BigEndianUnicode.GetBytes( value, 0, length, m_Stream.GetBuffer(), (int)m_Stream.Position ); + m_Stream.Position += size; + } + + /*size *= 2; + byte[] buffer = Encoding.BigEndianUnicode.GetBytes( value ); if ( buffer.Length >= size ) @@ -326,7 +387,7 @@ namespace Server.Network { m_Stream.Write( buffer, 0, buffer.Length ); Fill( size - buffer.Length ); - } + }*/ } /// diff --git a/Server/Network/Packets.cs b/Server/Network/Packets.cs index a2f676a99..198124228 100644 --- a/Server/Network/Packets.cs +++ b/Server/Network/Packets.cs @@ -477,13 +477,16 @@ namespace Server.Network { string name = info.Crafter.Name; - if ( name == null ) name = ""; - - int length = (ushort)name.Length; - m_Stream.Write( (int) -3 ); - m_Stream.Write( (ushort) length ); - m_Stream.WriteAsciiFixed( name, length ); + + if ( name == null ) + m_Stream.Write( (ushort) 0 ); + else + { + int length = name.Length; + m_Stream.Write( (ushort) length ); + m_Stream.WriteAsciiFixed( name, length ); + } } if ( info.Unidentified ) @@ -695,12 +698,14 @@ namespace Server.Network string question = menu.Question; - if ( question == null ) question = ""; - - int questionLength = (byte)question.Length; - - m_Stream.Write( (byte) questionLength ); - m_Stream.WriteAsciiFixed( question, questionLength ); + if ( question == null ) + m_Stream.Write( (byte) 0 ); + else + { + int questionLength = question.Length; + m_Stream.Write( (byte) questionLength ); + m_Stream.WriteAsciiFixed( question, questionLength ); + } ItemListEntry[] entries = menu.Entries; @@ -717,12 +722,14 @@ namespace Server.Network string name = e.Name; - if ( name == null ) name = ""; - - int nameLength = (byte)name.Length; - - m_Stream.Write( (byte) nameLength ); - m_Stream.WriteAsciiFixed( name, nameLength ); + if ( name == null ) + m_Stream.Write( (byte) 0 ); + else + { + int nameLength = name.Length; + m_Stream.Write( (byte) nameLength ); + m_Stream.WriteAsciiFixed( name, nameLength ); + } } } } @@ -738,12 +745,14 @@ namespace Server.Network string question = menu.Question; - if ( question == null ) question = ""; - - int questionLength = (byte)question.Length; - - m_Stream.Write( (byte) questionLength ); - m_Stream.WriteAsciiFixed( question, questionLength ); + if ( question == null ) + m_Stream.Write( (byte) 0 ); + else + { + int questionLength = question.Length; + m_Stream.Write( (byte) questionLength ); + m_Stream.WriteAsciiFixed( question, questionLength ); + } string[] answers = menu.Answers; @@ -757,12 +766,14 @@ namespace Server.Network string answer = answers[i]; - if ( answer == null ) answer = ""; - - int answerLength = (byte)answer.Length; - - m_Stream.Write( (byte) answerLength ); - m_Stream.WriteAsciiFixed( answer, answerLength ); + if ( answer == null ) + m_Stream.Write( (byte) 0 ); + else + { + int answerLength = answer.Length; + m_Stream.Write( (byte) answerLength ); + m_Stream.WriteAsciiFixed( answer, answerLength ); + } } } } @@ -2889,7 +2900,7 @@ namespace Server.Network { public UnicodeMessage( Serial serial, int graphic, MessageType type, int hue, int font, string lang, string name, string text ) : base( 0xAE ) { - if ( lang == null || lang == "" ) lang = "ENU"; + if ( string.IsNullOrEmpty( lang ) ) lang = "ENU"; if ( name == null ) name = ""; if ( text == null ) text = "";