@@ -12,6 +12,11 @@ class PlayerAccount {
1212 public static var AllPlayerAccountsById = new Map <Int , PlayerAccount >();
1313 public static var AccountIdIndex : Int = 1 ;
1414
15+ // Account limiting - anti spam
16+ public static var newAccountsTodayPerIp = new Map <String , Int >(); // IP -> count
17+ public static var totalNewAccountsToday : Int = 0 ;
18+ public static var lastAccountResetTime : Float = 0 ;
19+
1520 // saved
1621 public var id : Int ;
1722 public var isAi : Bool = false ;
@@ -35,7 +40,6 @@ class PlayerAccount {
3540 public var scoreEntries = new Array <ScoreEntry >(); // is used to store prestige boni / mali
3641 public var displayClosePlayers : Bool = true ;
3742 public var displayYum : Bool = true ;
38-
3943 // not saved
4044 public var graves = new Array <ObjectHelper >();
4145
@@ -47,10 +51,31 @@ class PlayerAccount {
4751
4852 private function new () {}
4953
50- public static function GetOrCreatePlayerAccount (email : String , account_key_hash : String , id : Int = 0 ): PlayerAccount {
54+ // if Ip is not set there is no limit to account generation
55+ public static function GetOrCreatePlayerAccount (email : String , account_key_hash : String , id : Int = 0 , clientIp : String = ' ' ): PlayerAccount {
56+ var checkLimit = clientIp != ' ' ;
5157 var account = AllPlayerAccountsByEmail [email ];
5258 if (account != null ) return account ;
5359
60+ // Check if account limit reached
61+ if (checkLimit ) {
62+ // Reset daily counts if it's a new day
63+ ResetDailyAccountCounts ();
64+
65+ // Check IP-specific limit
66+ var ipCount = newAccountsTodayPerIp [clientIp ];
67+ if (ipCount != null && ipCount >= ServerSettings . NewAccountsPerIpPerDay ) {
68+ trace (' PlayerAccount: WARNING: IP account limit reached for $clientIp ( $ipCount / ${ServerSettings . NewAccountsPerIpPerDay } per day)' );
69+ return null ;
70+ }
71+
72+ // Check total server-wide limit
73+ if (totalNewAccountsToday >= ServerSettings . TotalNewAccountsPerDay ) {
74+ trace (' PlayerAccount: WARNING: Total daily account limit reached ( $totalNewAccountsToday / ${ServerSettings . TotalNewAccountsPerDay })' );
75+ return null ;
76+ }
77+ }
78+
5479 account = new PlayerAccount ();
5580 account .id = id > 0 ? id : AccountIdIndex ++ ;
5681 account .email = email ;
@@ -59,11 +84,32 @@ class PlayerAccount {
5984 AllPlayerAccountsByEmail [account .email ] = account ;
6085 AllPlayerAccountsById [account .id ] = account ;
6186
87+ // Track new account creation
88+ if (checkLimit ) {
89+ totalNewAccountsToday ++ ;
90+
91+ var ipCount = newAccountsTodayPerIp [clientIp ];
92+ newAccountsTodayPerIp [clientIp ] = (ipCount != null ? ipCount : 0 ) + 1 ;
93+ trace (' PlayerAccount: New account created: ${account .id } from IP $clientIp (today: $totalNewAccountsToday total, IP: ${newAccountsTodayPerIp [clientIp ]})' );
94+ }
95+
6296 // trace('New account: ${id}-->${account.id} $email');
6397
6498 return account ;
6599 }
66100
101+ public static function ResetDailyAccountCounts () {
102+ var now = Date .now ().getTime ();
103+ var oneDayInMs : Float = 86400000 ; // 24 * 60 * 60 * 1000
104+
105+ if (now - lastAccountResetTime >= oneDayInMs ) {
106+ newAccountsTodayPerIp = new Map <String , Int >();
107+ totalNewAccountsToday = 0 ;
108+ lastAccountResetTime = now ;
109+ trace (' PlayerAccount: Daily account counts reset for day ${Date .now ()}' );
110+ }
111+ }
112+
67113 public static function GetPlayerAccountById (id : Int ): PlayerAccount {
68114 return AllPlayerAccountsById [id ];
69115 }
0 commit comments