@@ -25,14 +25,18 @@ void CLuaAccountDefs::LoadFunctions ()
25
25
CLuaCFunctions::AddFunction ( " getAllAccountData" , GetAllAccountData );
26
26
CLuaCFunctions::AddFunction ( " getAccount" , GetAccount );
27
27
CLuaCFunctions::AddFunction ( " getAccounts" , GetAccounts );
28
+ CLuaCFunctions::AddFunction ( " getAccountsByData" , GetAccountsByData );
28
29
CLuaCFunctions::AddFunction ( " getAccountSerial" , GetAccountSerial );
29
30
CLuaCFunctions::AddFunction ( " getAccountsBySerial" , GetAccountsBySerial );
31
+ CLuaCFunctions::AddFunction ( " getAccountIP" , GetAccountIP );
32
+ CLuaCFunctions::AddFunction ( " getAccountsByIP" , GetAccountsByIP );
30
33
31
34
// Account set functions
32
35
CLuaCFunctions::AddFunction ( " addAccount" , AddAccount );
33
36
CLuaCFunctions::AddFunction ( " removeAccount" , RemoveAccount );
34
37
CLuaCFunctions::AddFunction ( " setAccountPassword" , SetAccountPassword );
35
38
CLuaCFunctions::AddFunction ( " setAccountData" , SetAccountData );
39
+ CLuaCFunctions::AddFunction ( " setAccountName" , SetAccountName );
36
40
CLuaCFunctions::AddFunction ( " copyAccountData" , CopyAccountData );
37
41
}
38
42
@@ -41,7 +45,9 @@ void CLuaAccountDefs::AddClass ( lua_State* luaVM )
41
45
lua_newclass ( luaVM );
42
46
43
47
lua_classfunction ( luaVM, " getAll" , " getAccounts" );
48
+ lua_classfunction ( luaVM, " getAllByData" , " getAccountsByData" );
44
49
lua_classfunction ( luaVM, " getAllBySerial" , " getAccountsBySerial" );
50
+ lua_classfunction ( luaVM, " getAllByIP" , " getAccountsByIP" );
45
51
lua_classfunction ( luaVM, " getFromPlayer" , " getPlayerAccount" );
46
52
lua_classfunction ( luaVM, " logPlayerOut" , " logOut" );
47
53
@@ -52,16 +58,19 @@ void CLuaAccountDefs::AddClass ( lua_State* luaVM )
52
58
53
59
lua_classfunction ( luaVM, " setData" , " setAccountData" );
54
60
lua_classfunction ( luaVM, " setPassword" , " setAccountPassword" );
61
+ lua_classfunction ( luaVM, " setName" , " setAccountName" );
55
62
56
63
lua_classfunction ( luaVM, " getSerial" , " getAccountSerial" );
64
+ lua_classfunction ( luaVM, " getIP" , " getAccountIP" );
57
65
lua_classfunction ( luaVM, " getData" , " getAccountData" );
58
66
lua_classfunction ( luaVM, " getAllData" , " getAllAccountData" );
59
67
lua_classfunction ( luaVM, " getName" , " getAccountName" );
60
68
lua_classfunction ( luaVM, " getPlayer" , " getAccountPlayer" );
61
69
lua_classfunction ( luaVM, " isGuest" , " isGuestAccount" );
62
70
63
71
lua_classvariable ( luaVM, " serial" , NULL , " getAccountSerial" );
64
- lua_classvariable ( luaVM, " name" , NULL , " getAccountName" );
72
+ lua_classvariable ( luaVM, " name" , " setAccountName" , " getAccountName" );
73
+ lua_classvariable ( luaVM, " ip" , NULL , " getAccountIP" );
65
74
lua_classvariable ( luaVM, " player" , NULL , " getAccountPlayer" );
66
75
lua_classvariable ( luaVM, " guest" , NULL , " isGuestAccount" );
67
76
lua_classvariable ( luaVM, " password" , " setAccountPassword" , NULL );
@@ -229,6 +238,37 @@ int CLuaAccountDefs::GetAccounts ( lua_State* luaVM )
229
238
return 1 ;
230
239
}
231
240
241
+ int CLuaAccountDefs::GetAccountsByData ( lua_State* luaVM )
242
+ {
243
+ // table GetAccountsByData ( string dataName, string value )
244
+ SString dataName;
245
+ SString value;
246
+
247
+ CScriptArgReader argStream ( luaVM );
248
+ argStream.ReadString ( dataName );
249
+ argStream.ReadString ( value );
250
+
251
+ if ( !argStream.HasErrors () )
252
+ {
253
+ lua_newtable ( luaVM );
254
+ std::vector<CAccount*> accounts;
255
+
256
+ CStaticFunctionDefinitions::GetAccountsByData ( dataName, value, accounts );
257
+ for ( unsigned int i = 0 ; i < accounts.size (); ++i )
258
+ {
259
+ lua_pushnumber ( luaVM, i + 1 );
260
+ lua_pushaccount ( luaVM, accounts[i] );
261
+ lua_settable ( luaVM, -3 );
262
+ }
263
+ return 1 ;
264
+ }
265
+ else
266
+ m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );
267
+
268
+ lua_pushboolean ( luaVM, false );
269
+ return 1 ;
270
+ }
271
+
232
272
int CLuaAccountDefs::GetAccountSerial ( lua_State* luaVM )
233
273
{
234
274
// string getAccountSerial ( account theAccount )
@@ -282,6 +322,58 @@ int CLuaAccountDefs::GetAccountsBySerial ( lua_State* luaVM )
282
322
return 1 ;
283
323
}
284
324
325
+ int CLuaAccountDefs::GetAccountIP ( lua_State* luaVM ) {
326
+ // string getAccountSerial ( account theAccount )
327
+ CAccount* pAccount;
328
+
329
+ CScriptArgReader argStream ( luaVM );
330
+ argStream.ReadUserData ( pAccount );
331
+
332
+ if ( !argStream.HasErrors () )
333
+ {
334
+ SString strIP;
335
+ if ( CStaticFunctionDefinitions::GetAccountIP ( pAccount, strIP ) )
336
+ {
337
+ lua_pushstring ( luaVM, strIP );
338
+ return 1 ;
339
+ }
340
+ }
341
+ else
342
+ m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );
343
+
344
+ lua_pushboolean ( luaVM, false );
345
+ return 1 ;
346
+ }
347
+
348
+ int CLuaAccountDefs::GetAccountsByIP ( lua_State* luaVM )
349
+ {
350
+ // table getAccountsByIP ( string ip )
351
+ SString strIP;
352
+
353
+ CScriptArgReader argStream ( luaVM );
354
+ argStream.ReadString ( strIP );
355
+
356
+ if ( !argStream.HasErrors () )
357
+ {
358
+ lua_newtable ( luaVM );
359
+ std::vector<CAccount*> accounts;
360
+
361
+ CStaticFunctionDefinitions::GetAccountsByIP ( strIP, accounts );
362
+ for ( unsigned int i = 0 ; i < accounts.size (); ++i )
363
+ {
364
+ lua_pushnumber ( luaVM, i + 1 );
365
+ lua_pushaccount ( luaVM, accounts[i] );
366
+ lua_settable ( luaVM, -3 );
367
+ }
368
+ return 1 ;
369
+ }
370
+ else
371
+ m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );
372
+
373
+ lua_pushboolean ( luaVM, false );
374
+ return 1 ;
375
+ }
376
+
285
377
int CLuaAccountDefs::AddAccount ( lua_State* luaVM )
286
378
{
287
379
// account addAccount ( string name, string pass[, bool allowCaseVariations = false ] )
@@ -340,6 +432,34 @@ int CLuaAccountDefs::RemoveAccount ( lua_State* luaVM )
340
432
}
341
433
342
434
435
+ int CLuaAccountDefs::SetAccountName ( lua_State* luaVM )
436
+ {
437
+ // bool setAccountPassword ( account theAccount, string name[, bool allowCaseVariations = false ] )
438
+ CAccount* pAccount;
439
+ SString strNewName;
440
+ bool bAllowCaseVariations;
441
+
442
+ CScriptArgReader argStream ( luaVM );
443
+ argStream.ReadUserData ( pAccount );
444
+ argStream.ReadString ( strNewName );
445
+ argStream.ReadBool ( bAllowCaseVariations, false );
446
+
447
+ SString strError;
448
+ if ( !argStream.HasErrors () )
449
+ {
450
+ if ( CStaticFunctionDefinitions::SetAccountName ( pAccount, strNewName, bAllowCaseVariations, strError ) )
451
+ {
452
+ lua_pushboolean ( luaVM, true );
453
+ return 1 ;
454
+ }
455
+ }
456
+ else
457
+ m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );
458
+ lua_pushboolean ( luaVM, false );
459
+ return 1 ;
460
+ }
461
+
462
+
343
463
int CLuaAccountDefs::SetAccountPassword ( lua_State* luaVM )
344
464
{
345
465
// bool setAccountPassword ( account theAccount, string password )
0 commit comments