@@ -265,66 +265,73 @@ public async Task<string> GetPlayerList()
265
265
/// </summary>
266
266
/// <param name="name">Case insensitive name of player.</param>
267
267
/// <returns>Returns account.</returns>
268
- public async Task < AccountDTO > GetAccountByName ( string name , int appId )
268
+ public async Task < AccountDTO > GetAccountByName ( string name , int appId , bool forceRpcnCheck = false )
269
269
{
270
270
AccountDTO result = null ;
271
271
272
272
try
273
273
{
274
274
if ( _settings . SimulatedMode )
275
275
{
276
- if ( name == "gameRecorder_r2_pubeta_master" && appId == 21731 )
276
+ if ( name != null )
277
277
{
278
- AccountDTO R2PuBeta ;
279
- _simulatedAccounts . Add ( R2PuBeta = new AccountDTO ( )
278
+ if ( name == "gameRecorder_r2_pubeta_master" && appId == 21731 )
280
279
{
281
- AccountId = 2 ,
282
- AccountName = "gameRecorder_r2_pubeta_master" ,
283
- AccountPassword = string . Empty ,
284
- AccountWideStats = new int [ Constants . LADDERSTATSWIDE_MAXLEN ] ,
285
- AccountCustomWideStats = new int [ 1000 ] ,
286
- AppId = 21731 ,
287
- MachineId = string . Empty ,
288
- MediusStats = string . Empty ,
289
- Friends = Array . Empty < AccountRelationDTO > ( ) ,
290
- Ignored = Array . Empty < AccountRelationDTO > ( ) ,
291
- IsBanned = false
292
- } ) ;
293
-
294
- return R2PuBeta ;
295
- }
296
- else if ( name == "ftb3 Moderator_0" && appId == 21694 )
297
- {
298
- AccountDTO ftb3Mod ;
299
- _simulatedAccounts . Add ( ftb3Mod = new AccountDTO ( )
280
+ AccountDTO R2PuBeta ;
281
+ _simulatedAccounts . Add ( R2PuBeta = new AccountDTO ( )
282
+ {
283
+ AccountId = 2 ,
284
+ AccountName = "gameRecorder_r2_pubeta_master" ,
285
+ AccountPassword = string . Empty ,
286
+ AccountWideStats = new int [ Constants . LADDERSTATSWIDE_MAXLEN ] ,
287
+ AccountCustomWideStats = new int [ 1000 ] ,
288
+ AppId = 21731 ,
289
+ MachineId = string . Empty ,
290
+ MediusStats = string . Empty ,
291
+ Friends = Array . Empty < AccountRelationDTO > ( ) ,
292
+ Ignored = Array . Empty < AccountRelationDTO > ( ) ,
293
+ IsBanned = false
294
+ } ) ;
295
+
296
+ return R2PuBeta ;
297
+ }
298
+ else if ( name == "ftb3 Moderator_0" && appId == 21694 )
300
299
{
301
- AccountId = 2 ,
302
- AccountName = "ftb3 Moderator_0" ,
303
- AccountPassword = string . Empty ,
304
- AccountWideStats = new int [ Constants . LADDERSTATSWIDE_MAXLEN ] ,
305
- AccountCustomWideStats = new int [ 1000 ] ,
306
- AppId = 21694 ,
307
- MachineId = string . Empty ,
308
- MediusStats = string . Empty ,
309
- Friends = Array . Empty < AccountRelationDTO > ( ) ,
310
- Ignored = Array . Empty < AccountRelationDTO > ( ) ,
311
- IsBanned = false
312
- } ) ;
313
-
314
- return ftb3Mod ;
300
+ AccountDTO ftb3Mod ;
301
+ _simulatedAccounts . Add ( ftb3Mod = new AccountDTO ( )
302
+ {
303
+ AccountId = 2 ,
304
+ AccountName = "ftb3 Moderator_0" ,
305
+ AccountPassword = string . Empty ,
306
+ AccountWideStats = new int [ Constants . LADDERSTATSWIDE_MAXLEN ] ,
307
+ AccountCustomWideStats = new int [ 1000 ] ,
308
+ AppId = 21694 ,
309
+ MachineId = string . Empty ,
310
+ MediusStats = string . Empty ,
311
+ Friends = Array . Empty < AccountRelationDTO > ( ) ,
312
+ Ignored = Array . Empty < AccountRelationDTO > ( ) ,
313
+ IsBanned = false
314
+ } ) ;
315
+
316
+ return ftb3Mod ;
317
+ }
318
+ else
319
+ result = _simulatedAccounts . FirstOrDefault ( x =>
320
+ x . AppId == appId &&
321
+ x . AccountName != null &&
322
+ ( forceRpcnCheck
323
+ ? x . AccountName . ToLower ( ) == name . ToLower ( )
324
+ : ( x . AccountName . EndsWith ( "@RPCN" , StringComparison . OrdinalIgnoreCase )
325
+ ? x . AccountName . Substring ( 0 , x . AccountName . Length - "@RPCN" . Length )
326
+ : x . AccountName ) . ToLower ( ) == name . ToLower ( )
327
+ )
328
+ ) ;
315
329
}
316
- else
317
- result = _simulatedAccounts . FirstOrDefault ( x => x . AppId == appId &&
318
- x . AccountName != null &&
319
- name != null &&
320
- ( x . AccountName . EndsWith ( "@RPCN" )
321
- ? x . AccountName . Substring ( 0 , x . AccountName . Length - "@RPCN" . Length )
322
- : x . AccountName ) . ToLower ( ) == name . ToLower ( ) ) ;
323
330
}
324
331
else
325
332
{
326
333
name = HttpUtility . UrlEncode ( name ) ;
327
- string route = $ "Account/searchAccountByName?AccountName={ name } &AppId={ appId } ";
334
+ string route = $ "Account/searchAccountByName?AccountName={ name } &AppId={ appId } &ForceRpcnCheck= { forceRpcnCheck } ";
328
335
result = await GetDbAsync < AccountDTO > ( route ) ;
329
336
}
330
337
}
@@ -397,7 +404,7 @@ public async Task<AccountDTO> CreateAccount(CreateAccountDTO createAccount, ICha
397
404
{
398
405
if ( _settings . SimulatedMode )
399
406
{
400
- var checkExisting = await GetAccountByName ( createAccount . AccountName , createAccount . AppId ) ;
407
+ var checkExisting = await GetAccountByName ( createAccount . AccountName , createAccount . AppId , true ) ;
401
408
if ( checkExisting == null )
402
409
{
403
410
_simulatedAccounts . Add ( result = new AccountDTO ( )
@@ -712,24 +719,22 @@ public async Task<bool> PostAccountIp(int accountId, string ip)
712
719
/// <summary>
713
720
/// Gets whether or not the ip is banned.
714
721
/// </summary>
715
- public async Task < bool > GetIsIpBanned ( string ip )
722
+ public async Task < bool > GetIsIpBanned ( IPAddress ip )
716
723
{
717
724
bool result = false ;
718
725
719
726
try
720
727
{
721
728
if ( _settings . SimulatedMode )
722
729
{
723
- if ( IPAddress . TryParse ( ip , out IPAddress Parsedip ) && Parsedip != null && Parsedip != IPAddress . None )
730
+ if ( ip != null && ip != IPAddress . None && ip != IPAddress . Any && ip != IPAddress . IPv6Any )
724
731
{
725
- ( string , bool ) ResultItem = JsonDatabaseController . ReadFromJsonFile ( directoryPath , "IPAddress" , InternetProtocolUtils . GetIPAddressAsUInt ( Parsedip ) . ToString ( ) ) ;
732
+ ( string , bool ) ResultItem = JsonDatabaseController . ReadFromJsonFile ( directoryPath , "IPAddress" , InternetProtocolUtils . GetIPAddressAsUInt ( ip ) . ToString ( ) ) ;
726
733
727
734
switch ( ResultItem . Item1 )
728
735
{
729
736
case "OK" :
730
737
return ResultItem . Item2 ;
731
- default :
732
- return false ;
733
738
}
734
739
}
735
740
@@ -879,11 +884,11 @@ public async Task<bool> PostMachineId(int accountId, string machineId)
879
884
/// Posts the given ip to ban to the database.
880
885
/// </summary>
881
886
/// <param name="ipToBan">client ip.</param>
882
- public async Task < bool > BanIp ( string ipToBan )
887
+ public async Task < bool > BanIp ( IPAddress ipToBan )
883
888
{
884
889
bool result = false ;
885
890
886
- if ( string . IsNullOrEmpty ( ipToBan ) )
891
+ if ( ipToBan == null || ipToBan == IPAddress . None || ipToBan == IPAddress . Any || ipToBan == IPAddress . IPv6Any )
887
892
return result ;
888
893
889
894
try
0 commit comments