11using Atlasd . Battlenet . Exceptions ;
22using Atlasd . Daemon ;
33using System ;
4+ using System . Linq ;
45using System . Collections . Generic ;
56using System . IO ;
67using System . Text ;
@@ -51,17 +52,10 @@ public override bool Invoke(MessageContext context)
5152
5253 var productId = ( UInt32 ) gameState . Product ;
5354
54- // Statstring length is either 0 bytes or 4- 128 bytes, not including the null-terminator.
55- if ( statstring . Length != 0 && ( statstring . Length < 4 || statstring . Length > 128 ) )
55+ // Statstring has a maximum length of 128 bytes
56+ if ( statstring . Length > 128 )
5657 throw new GameProtocolViolationException ( context . Client , $ "Client sent invalid statstring size in { MessageName ( Id ) } ") ;
5758
58- if ( statstring . Length < 4 ) statstring = new byte [ 4 ] ;
59-
60- using var _m = new MemoryStream ( statstring ) ;
61- using var _w = new BinaryWriter ( _m ) ;
62- _w . BaseStream . Position = 0 ;
63- _w . Write ( productId ) ; // ensure first 4 bytes of statstring always matches their agreed upon productId
64-
6559 return new SID_ENTERCHAT ( ) . Invoke ( new MessageContext ( context . Client , MessageDirection . ServerToClient ,
6660 new Dictionary < string , dynamic > ( ) { { "username" , username } , { "statstring" , statstring } } )
6761 ) ;
@@ -74,7 +68,7 @@ public override bool Invoke(MessageContext context)
7468
7569 // Do not use client-provided statstring if config.battlenet.emulation.statstring_updates is not enabled for this product.
7670 // Blizzard servers allowed statstring updates for Diablo, Diablo II (changing characters), Warcraft III (changing icons), and Shareware variants.
77- if ( ! GameState . CanStatstringUpdate ( gameState . Product ) ) statstring = gameState . GenerateStatstring ( ) ;
71+ if ( ! GameState . CanStatstringUpdate ( gameState . Product ) || statstring . Length == 0 ) statstring = gameState . GenerateStatstring ( ) ;
7872
7973 /**
8074 * (STRING) Unique name
0 commit comments