22using System ;
33using System . Collections . Generic ;
44using System . Globalization ;
5+ using System . Linq ;
56using System . Text ;
67
78namespace Atlasd . Battlenet . Protocols . Game . ChatCommands
@@ -21,7 +22,8 @@ public override void Invoke(ChatCommandContext context)
2122
2223 if ( Arguments . Count < 1 )
2324 {
24- new ChatEvent ( ChatEvent . EventIds . EID_ERROR , gs . ChannelFlags , gs . Client . RemoteIPAddress , gs . Ping , gs . OnlineName , Resources . StatsCommandInvalid ) . WriteTo ( gs . Client ) ;
25+ foreach ( var line in Resources . StatsCommandInvalid . Split ( Battlenet . Common . NewLine ) )
26+ new ChatEvent ( ChatEvent . EventIds . EID_ERROR , gs . ChannelFlags , gs . Client . RemoteIPAddress , gs . Ping , gs . OnlineName , line ) . WriteTo ( gs . Client ) ;
2527 return ;
2628 }
2729
@@ -31,21 +33,25 @@ public override void Invoke(ChatCommandContext context)
3133 RawBuffer = RawBuffer [ ( Encoding . UTF8 . GetByteCount ( targetStr ) + ( Arguments . Count > 0 ? 1 : 0 ) ) ..] ;
3234
3335 Product . ProductCode code = Product . ProductCode . None ;
36+ string codeStr = string . Empty ;
37+
3438 if ( Arguments . Count == 0 )
3539 {
3640 code = gs . Product ;
3741 }
38- else if ( Arguments . Count > 0 )
42+ else
3943 {
40- var codeStr = Arguments [ 0 ] ;
44+ codeStr = Arguments [ 0 ] ;
4145 Arguments . RemoveAt ( 0 ) ;
4246 // Calculates and removes (codeStr+' ') from (raw) which prints into (newRaw):
4347 RawBuffer = RawBuffer [ ( Encoding . UTF8 . GetByteCount ( codeStr ) + ( Arguments . Count > 0 ? 1 : 0 ) ) ..] ;
4448
45- while ( codeStr . Length < 4 ) codeStr += 0x00 ;
49+ while ( codeStr . Length < 4 ) codeStr += ( char ) 0x00 ;
4650 code = Product . FromBytes ( Encoding . UTF8 . GetBytes ( codeStr [ 0 ..Math . Min ( 4 , codeStr . Length ) ] ) , true ) ;
4751 }
52+ codeStr = Encoding . UTF8 . GetString ( BitConverter . GetBytes ( ( uint ) code ) . Reverse ( ) . ToArray ( ) ) ;
4853
54+ // Verify product code is a record-keeping type
4955 bool valid = code switch
5056 {
5157 Product . ProductCode . StarcraftOriginal => true ,
@@ -55,10 +61,10 @@ public override void Invoke(ChatCommandContext context)
5561 Product . ProductCode . WarcraftIIIFrozenThrone => true ,
5662 _ => false ,
5763 } ;
58-
5964 if ( ! valid )
6065 {
61- new ChatEvent ( ChatEvent . EventIds . EID_ERROR , gs . ChannelFlags , gs . Client . RemoteIPAddress , gs . Ping , gs . OnlineName , Resources . StatsCommandInvalid ) . WriteTo ( gs . Client ) ;
66+ foreach ( var line in Resources . StatsCommandInvalid . Split ( Battlenet . Common . NewLine ) )
67+ new ChatEvent ( ChatEvent . EventIds . EID_ERROR , gs . ChannelFlags , gs . Client . RemoteIPAddress , gs . Ping , gs . OnlineName , line ) . WriteTo ( gs . Client ) ;
6268 return ;
6369 }
6470
@@ -67,16 +73,31 @@ public override void Invoke(ChatCommandContext context)
6773 buffer += Battlenet . Common . NewLine + Resources . StatsCommandLadder ;
6874 if ( code == Product . ProductCode . WarcraftIIBNE ) buffer += Battlenet . Common . NewLine + Resources . StatsCommandIronMan ;
6975
70- buffer = buffer . Replace ( "{ironManDraws}" , "0" , true , CultureInfo . InvariantCulture ) ;
71- buffer = buffer . Replace ( "{ironManLosses}" , "0" , true , CultureInfo . InvariantCulture ) ;
72- buffer = buffer . Replace ( "{ironManWins}" , "0" , true , CultureInfo . InvariantCulture ) ;
73- buffer = buffer . Replace ( "{ladderDraws}" , "0" , true , CultureInfo . InvariantCulture ) ;
74- buffer = buffer . Replace ( "{ladderLosses}" , "0" , true , CultureInfo . InvariantCulture ) ;
75- buffer = buffer . Replace ( "{ladderWins}" , "0" , true , CultureInfo . InvariantCulture ) ;
76- buffer = buffer . Replace ( "{normalDraws}" , "0" , true , CultureInfo . InvariantCulture ) ;
77- buffer = buffer . Replace ( "{normalLosses}" , "0" , true , CultureInfo . InvariantCulture ) ;
78- buffer = buffer . Replace ( "{normalWins}" , "0" , true , CultureInfo . InvariantCulture ) ;
76+ int normal = 0 ;
77+ int ladder = 1 ;
78+ int ironMan = 3 ;
79+
80+ int normalWins = context . GameState . ActiveAccount . Get ( $ "record\\ { codeStr } \\ { normal } \\ wins", 0 ) ;
81+ int normalLosses = context . GameState . ActiveAccount . Get ( $ "record\\ { codeStr } \\ { normal } \\ losses", 0 ) ;
82+ int normalDraws = context . GameState . ActiveAccount . Get ( $ "record\\ { codeStr } \\ { normal } \\ disconnects", 0 ) ;
83+ int ladderWins = context . GameState . ActiveAccount . Get ( $ "record\\ { codeStr } \\ { ladder } \\ wins", 0 ) ;
84+ int ladderLosses = context . GameState . ActiveAccount . Get ( $ "record\\ { codeStr } \\ { ladder } \\ losses", 0 ) ;
85+ int ladderDraws = context . GameState . ActiveAccount . Get ( $ "record\\ { codeStr } \\ { ladder } \\ disconnects", 0 ) ;
86+ int ironManWins = context . GameState . ActiveAccount . Get ( $ "record\\ { codeStr } \\ { ironMan } \\ wins", 0 ) ;
87+ int ironManLosses = context . GameState . ActiveAccount . Get ( $ "record\\ { codeStr } \\ { ironMan } \\ losses", 0 ) ;
88+ int ironManDraws = context . GameState . ActiveAccount . Get ( $ "record\\ { codeStr } \\ { ironMan } \\ disconnects", 0 ) ;
89+
90+ buffer = buffer . Replace ( "{ironManDraws}" , $ "{ ironManDraws } ", true , CultureInfo . InvariantCulture ) ;
91+ buffer = buffer . Replace ( "{ironManLosses}" , $ "{ ironManLosses } ", true , CultureInfo . InvariantCulture ) ;
92+ buffer = buffer . Replace ( "{ironManWins}" , $ "{ ironManWins } ", true , CultureInfo . InvariantCulture ) ;
93+ buffer = buffer . Replace ( "{ladderDraws}" , $ "{ ladderDraws } ", true , CultureInfo . InvariantCulture ) ;
94+ buffer = buffer . Replace ( "{ladderLosses}" , $ "{ ladderLosses } ", true , CultureInfo . InvariantCulture ) ;
95+ buffer = buffer . Replace ( "{ladderWins}" , $ "{ ladderWins } ", true , CultureInfo . InvariantCulture ) ;
96+ buffer = buffer . Replace ( "{normalDraws}" , $ "{ normalDraws } ", true , CultureInfo . InvariantCulture ) ;
97+ buffer = buffer . Replace ( "{normalLosses}" , $ "{ normalLosses } ", true , CultureInfo . InvariantCulture ) ;
98+ buffer = buffer . Replace ( "{normalWins}" , $ "{ normalWins } ", true , CultureInfo . InvariantCulture ) ;
7999 buffer = buffer . Replace ( "{user}" , targetStr , true , CultureInfo . InvariantCulture ) ;
100+ buffer = buffer . Replace ( "{userName}" , targetStr , true , CultureInfo . InvariantCulture ) ;
80101
81102 foreach ( var line in buffer . Split ( Battlenet . Common . NewLine ) )
82103 new ChatEvent ( ChatEvent . EventIds . EID_INFO , gs . ChannelFlags , gs . Client . RemoteIPAddress , gs . Ping , gs . OnlineName , line ) . WriteTo ( gs . Client ) ;
0 commit comments