[Half-Life AMXX] / admin.sma Repository:
ViewVC logotype

Diff of /admin.sma

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 16, Fri Nov 16 15:12:40 2007 UTC revision 17, Fri Nov 16 15:29:57 2007 UTC
# Line 41  Line 41 
41  #include <sqlx>  #include <sqlx>
42  #endif  #endif
43    
44  #define MAX_ADMINS 64  //new Vector:AdminList;
45    
46    new AdminCount;
47    
48  new PLUGINNAME[] = "AMX Mod X"  new PLUGINNAME[] = "AMX Mod X"
49    
50  #define ADMIN_LOOKUP    (1<<0)  #define ADMIN_LOOKUP    (1<<0)
# Line 50  Line 53 
53  #define ADMIN_IPADDR    (1<<3)  #define ADMIN_IPADDR    (1<<3)
54  #define ADMIN_NAME              (1<<4)  #define ADMIN_NAME              (1<<4)
55    
 new g_aPassword[MAX_ADMINS][32]  
 new g_aName[MAX_ADMINS][32]  
 new g_aFlags[MAX_ADMINS]  
 new g_aAccess[MAX_ADMINS]  
 new g_aNum = 0  
56  new g_cmdLoopback[16]  new g_cmdLoopback[16]
57    
58    
59    // pcvars
60    new amx_mode;
61    new amx_password_field;
62    new amx_default_access;
63    
64  public plugin_init()  public plugin_init()
65  {  {
66  #if defined USING_SQL  #if defined USING_SQL
# Line 66  Line 70 
70  #endif  #endif
71          register_dictionary("admin.txt")          register_dictionary("admin.txt")
72          register_dictionary("common.txt")          register_dictionary("common.txt")
73          register_cvar("amx_mode", "1")          amx_mode=register_cvar("amx_mode", "1")
74          register_cvar("amx_password_field", "_pw")          amx_password_field=register_cvar("amx_password_field", "_pw")
75          register_cvar("amx_default_access", "")          amx_default_access=register_cvar("amx_default_access", "")
76    
77          register_cvar("amx_vote_ratio", "0.02")          register_cvar("amx_vote_ratio", "0.02")
78          register_cvar("amx_vote_time", "10")          register_cvar("amx_vote_time", "10")
# Line 106  Line 110 
110    
111          server_cmd("exec %s/amxx.cfg", configsDir)      // Execute main configuration file          server_cmd("exec %s/amxx.cfg", configsDir)      // Execute main configuration file
112          server_cmd("exec %s/sql.cfg", configsDir)          server_cmd("exec %s/sql.cfg", configsDir)
113    
114            // Create a vector of 5 cells to store the info.
115            //AdminList=vector_create(5);
116    
117    
118  #if defined USING_SQL  #if defined USING_SQL
119          server_cmd("amx_sqladmins")          server_cmd("amx_sqladmins")
120  #else  #else
# Line 155  Line 164 
164                  if (containi(arg, "STEAM_0:") == -1)                  if (containi(arg, "STEAM_0:") == -1)
165                  {                  {
166                          idtype |= ADMIN_LOOKUP                          idtype |= ADMIN_LOOKUP
167                          player = cmd_target(id, arg, 10)                          player = cmd_target(id, arg, CMDTARGET_ALLOW_SELF | CMDTARGET_NO_BOTS)
168                  } else {                  } else {
169                          new _steamid[24]                          new _steamid[44]
170                          static _players[32], _num, _pv                          static _players[32], _num, _pv
171                          get_players(_players, _num)                          get_players(_players, _num)
172                          for (new _i=0; _i<_num; _i++)                          for (new _i=0; _i<_num; _i++)
173                          {                          {
174                                  _pv = _players[_i]                                  _pv = _players[_i]
175                                  get_user_authid(_pv, _steamid, 23)                                  get_user_authid(_pv, _steamid, sizeof(_steamid)-1)
176                                  if (!_steamid[0])                                  if (!_steamid[0])
177                                          continue                                          continue
178                                  if (equal(_steamid, arg))                                  if (equal(_steamid, arg))
# Line 180  Line 189 
189          }          }
190          else if (idtype & ADMIN_NAME)          else if (idtype & ADMIN_NAME)
191          {          {
192                  player = cmd_target(id, arg, 10)                  player = cmd_target(id, arg, CMDTARGET_ALLOW_SELF | CMDTARGET_NO_BOTS)
193    
194                  if (player)                  if (player)
195                          idtype |= ADMIN_LOOKUP                          idtype |= ADMIN_LOOKUP
# Line 229  Line 238 
238                  read_argv(3, password, 63)                  read_argv(3, password, 63)
239    
240          new auth[33]          new auth[33]
241            new Comment[33]; // name of player to pass to comment field
242          if (idtype & ADMIN_LOOKUP)          if (idtype & ADMIN_LOOKUP)
243          {          {
244                    get_user_name(player, Comment, sizeof(Comment)-1)
245                  if (idtype & ADMIN_STEAM)                  if (idtype & ADMIN_STEAM)
246                  {                  {
247                          get_user_authid(player, auth, 32)                          get_user_authid(player, auth, 32)
# Line 259  Line 270 
270          else          else
271                  len += format(type[len], 15-len, "e")                  len += format(type[len], 15-len, "e")
272    
273          AddAdmin(id, auth, flags, password, type)          AddAdmin(id, auth, flags, password, type, Comment)
274          cmdReload(id, ADMIN_CFG, 0)          cmdReload(id, ADMIN_CFG, 0)
275    
276          if (player > 0)          if (player > 0)
# Line 272  Line 283 
283          return PLUGIN_HANDLED          return PLUGIN_HANDLED
284  }  }
285    
286  AddAdmin(id, auth[], accessflags[], password[], flags[])  AddAdmin(id, auth[], accessflags[], password[], flags[], comment[]="")
287  {  {
288  #if defined USING_SQL  #if defined USING_SQL
289          new error[128], errno          new error[128], errno
# Line 322  Line 333 
333                  // If we came here, steamid doesn't exist in users.ini. Add it.                  // If we came here, steamid doesn't exist in users.ini. Add it.
334                  new linetoadd[512]                  new linetoadd[512]
335    
336                    if (comment[0]==0)
337                    {
338                  formatex(linetoadd, 511, "^r^n^"%s^" ^"%s^" ^"%s^" ^"%s^"", auth, password, accessflags, flags)                  formatex(linetoadd, 511, "^r^n^"%s^" ^"%s^" ^"%s^" ^"%s^"", auth, password, accessflags, flags)
339                    }
340                    else
341                    {
342                            formatex(linetoadd, 511, "^r^n^"%s^" ^"%s^" ^"%s^" ^"%s^" ; %s", auth, password, accessflags, flags, comment)
343                    }
344                  console_print(id, "Adding:^n%s", linetoadd)                  console_print(id, "Adding:^n%s", linetoadd)
345    
346                  if (!write_file(configsDir, linetoadd))                  if (!write_file(configsDir, linetoadd))
# Line 357  Line 375 
375  }  }
376  public plugin_cfg()  public plugin_cfg()
377  {  {
378          new configFile[64], curMap[32]          set_task(6.1, "delayed_load")
379    }
380    
381    public delayed_load()
382    {
383            new configFile[128], curMap[64], configDir[128]
384    
385          get_configsdir(configFile, 31)          get_configsdir(configDir, sizeof(configDir)-1)
386          get_mapname(curMap, 31)          get_mapname(curMap, sizeof(curMap)-1)
387    
388          new len = format(configFile, 63, "%s/maps/%s.cfg", configFile, curMap)          new i=0;
389    
390            while (curMap[i] != '_' && curMap[i++] != '^0') {/*do nothing*/}
391    
392            if (curMap[i]=='_')
393            {
394                    // this map has a prefix
395                    curMap[i]='^0';
396                    formatex(configFile, sizeof(configFile)-1, "%s/maps/prefix_%s.cfg", configDir, curMap);
397    
398          if (file_exists(configFile))          if (file_exists(configFile))
399                  set_task(6.1, "delayed_load", 0, configFile, len + 1)                  {
400                            server_cmd("exec %s", configFile);
401                    }
402  }  }
403    
404  public delayed_load(configFile[])          get_mapname(curMap, sizeof(curMap)-1)
405    
406    
407            formatex(configFile, sizeof(configFile)-1, "%s/maps/%s.cfg", configDir, curMap)
408    
409            if (file_exists(configFile))
410  {  {
411          server_cmd("exec %s", configFile)          server_cmd("exec %s", configFile)
412  }  }
413    
414    }
415    
416  loadSettings(szFilename[])  loadSettings(szFilename[])
417  {  {
418          if (!file_exists(szFilename))          new File=fopen(szFilename,"r");
                 return 0  
419    
420          new szText[256], szFlags[32], szAccess[32]          if (File)
421          new a, pos = 0          {
422                    new Text[512];
423                    new Flags[32];
424                    new Access[32]
425                    new AuthData[44];
426                    new Password[32];
427    
428          while (g_aNum < MAX_ADMINS && read_file(szFilename, pos++, szText, 255, a))                  while (!feof(File))
429          {          {
430                  if (szText[0] == ';')                          fgets(File,Text,sizeof(Text)-1);
                         continue  
431    
432                  if (parse(szText, g_aName[g_aNum], 31, g_aPassword[g_aNum], 31, szAccess, 31, szFlags, 31) < 2)                          trim(Text);
433                          continue  
434                            // comment
435                            if (Text[0]==';')
436                            {
437                                    continue;
438                            }
439    
440                            Flags[0]=0;
441                            Access[0]=0;
442                            AuthData[0]=0;
443                            Password[0]=0;
444    
445                            // not enough parameters
446                            if (parse(Text,AuthData,sizeof(AuthData)-1,Password,sizeof(Password)-1,Access,sizeof(Access)-1,Flags,sizeof(Flags)-1) < 2)
447                            {
448                                    continue;
449                            }
450    
451                            admins_push(AuthData,Password,read_flags(Access),read_flags(Flags));
452    
453                            AdminCount++;
454                    }
455    
456                  g_aAccess[g_aNum] = read_flags(szAccess)                  fclose(File);
                 g_aFlags[g_aNum] = read_flags(szFlags)  
                 ++g_aNum  
457          }          }
458    
459          if (g_aNum == 1)          if (AdminCount == 1)
460                  server_print("[AMXX] %L", LANG_SERVER, "LOADED_ADMIN")          {
461                    server_print("[AMXX] %L", LANG_SERVER, "LOADED_ADMIN");
462            }
463          else          else
464                  server_print("[AMXX] %L", LANG_SERVER, "LOADED_ADMINS", g_aNum)          {
465                    server_print("[AMXX] %L", LANG_SERVER, "LOADED_ADMINS", AdminCount);
466            }
467    
468          return 1          return 1;
469  }  }
470    
471  #if defined USING_SQL  #if defined USING_SQL
# Line 450  Line 516 
516          } else if (!SQL_NumResults(query)) {          } else if (!SQL_NumResults(query)) {
517                  server_print("[AMXX] %L", LANG_SERVER, "NO_ADMINS")                  server_print("[AMXX] %L", LANG_SERVER, "NO_ADMINS")
518          } else {          } else {
                 new szFlags[32], szAccess[32]  
519    
520                  g_aNum = 0                  AdminCount = 0
521    
522                  /** do this incase people change the query order and forget to modify below */                  /** do this incase people change the query order and forget to modify below */
523                  new qcolAuth = SQL_FieldNameToNum(query, "auth")                  new qcolAuth = SQL_FieldNameToNum(query, "auth")
# Line 460  Line 525 
525                  new qcolAccess = SQL_FieldNameToNum(query, "access")                  new qcolAccess = SQL_FieldNameToNum(query, "access")
526                  new qcolFlags = SQL_FieldNameToNum(query, "flags")                  new qcolFlags = SQL_FieldNameToNum(query, "flags")
527    
528                  while ((g_aNum < MAX_ADMINS) && (SQL_MoreResults(query)))                  new AuthData[44];
529                  {                  new Password[44];
530                          SQL_ReadResult(query, qcolAuth, g_aName[g_aNum], 31)                  new Access[32];
531                          SQL_ReadResult(query, qcolPass, g_aPassword[g_aNum], 31)                  new Flags[32];
                         SQL_ReadResult(query, qcolAccess, szAccess, 31)  
                         SQL_ReadResult(query, qcolFlags, szFlags, 31)  
532    
533                          g_aAccess[g_aNum] = read_flags(szAccess)                  while (SQL_MoreResults(query))
534                    {
535                            SQL_ReadResult(query, qcolAuth, AuthData, sizeof(AuthData)-1);
536                            SQL_ReadResult(query, qcolPass, Password, sizeof(Password)-1);
537                            SQL_ReadResult(query, qcolAccess, Access, sizeof(Access)-1);
538                            SQL_ReadResult(query, qcolFlags, Flags, sizeof(Flags)-1);
539    
540                          g_aFlags[g_aNum] = read_flags(szFlags)                          admins_push(AuthData,Password,read_flags(Access),read_flags(Flags));
541    
542                          ++g_aNum                          ++AdminCount;
543                          SQL_NextRow(query)                          SQL_NextRow(query)
544                  }                  }
545    
546                  if (g_aNum == 1)                  if (AdminCount == 1)
547                    {
548                          server_print("[AMXX] %L", LANG_SERVER, "SQL_LOADED_ADMIN")                          server_print("[AMXX] %L", LANG_SERVER, "SQL_LOADED_ADMIN")
549                    }
550                  else                  else
551                          server_print("[AMXX] %L", LANG_SERVER, "SQL_LOADED_ADMINS", g_aNum)                  {
552                            server_print("[AMXX] %L", LANG_SERVER, "SQL_LOADED_ADMINS", AdminCount)
553                    }
554    
555                  SQL_FreeHandle(query)                  SQL_FreeHandle(query)
556                  SQL_FreeHandle(sql)                  SQL_FreeHandle(sql)
# Line 497  Line 569 
569          //strip original flags (patch submitted by mrhunt)          //strip original flags (patch submitted by mrhunt)
570          remove_user_flags(0, read_flags("z"))          remove_user_flags(0, read_flags("z"))
571    
572            admins_flush();
573    
574  #if !defined USING_SQL  #if !defined USING_SQL
575          new filename[128]          new filename[128]
576    
577          get_configsdir(filename, 127)          get_configsdir(filename, 127)
578          format(filename, 63, "%s/users.ini", filename)          format(filename, 63, "%s/users.ini", filename)
579    
580          g_aNum = 0          AdminCount = 0;
581          loadSettings(filename)          // Re-Load admins accounts          loadSettings(filename);         // Re-Load admins accounts
582    
583          if (id != 0)          if (id != 0)
584          {          {
585                  if (g_aNum == 1)                  if (AdminCount == 1)
586                          console_print(id, "[AMXX] %L", LANG_SERVER, "LOADED_ADMIN")                  {
587                            console_print(id, "[AMXX] %L", LANG_SERVER, "LOADED_ADMIN");
588                    }
589                  else                  else
590                          console_print(id, "[AMXX] %L", LANG_SERVER, "LOADED_ADMINS", g_aNum)                  {
591                            console_print(id, "[AMXX] %L", LANG_SERVER, "LOADED_ADMINS", AdminCount);
592                    }
593          }          }
594  #else  #else
595          g_aNum = 0          AdminCount = 0
596          adminSql()          adminSql()
597    
598          if (id != 0)          if (id != 0)
599          {          {
600                  if (g_aNum == 1)                  if (AdminCount == 1)
601                          console_print(id, "[AMXX] %L", LANG_SERVER, "SQL_LOADED_ADMIN")                          console_print(id, "[AMXX] %L", LANG_SERVER, "SQL_LOADED_ADMIN")
602                  else                  else
603                          console_print(id, "[AMXX] %L", LANG_SERVER, "SQL_LOADED_ADMINS", g_aNum)                          console_print(id, "[AMXX] %L", LANG_SERVER, "SQL_LOADED_ADMINS", AdminCount)
604          }          }
605  #endif  #endif
606    
# Line 544  Line 622 
622          new index = -1          new index = -1
623          new result = 0          new result = 0
624    
625          for (new i = 0; i < g_aNum; ++i)          static Count;
626            static Flags;
627            static Access;
628            static AuthData[44];
629            static Password[32];
630    
631            Count=admins_num();
632            for (new i = 0; i < Count; ++i)
633          {          {
634                  if (g_aFlags[i] & FLAG_AUTHID)                  Flags=admins_lookup(i,AdminProp_Flags);
635                    admins_lookup(i,AdminProp_Auth,AuthData,sizeof(AuthData)-1);
636    
637                    if (Flags & FLAG_AUTHID)
638                  {                  {
639                          if (equal(authid, g_aName[i]))                          if (equal(authid, AuthData))
640                          {                          {
641                                  index = i                                  index = i
642                                  break                                  break
643                          }                          }
644                  }                  }
645                  else if (g_aFlags[i] & FLAG_IP)                  else if (Flags & FLAG_IP)
646                  {                  {
647                          new c = strlen(g_aName[i])                          new c = strlen(AuthData)
648    
649                          if (g_aName[i][c - 1] == '.')           /* check if this is not a xxx.xxx. format */                          if (AuthData[c - 1] == '.')             /* check if this is not a xxx.xxx. format */
650                          {                          {
651                                  if (equal(g_aName[i], ip, c))                                  if (equal(AuthData, ip, c))
652                                  {                                  {
653                                          index = i                                          index = i
654                                          break                                          break
655                                  }                                  }
656                          }                                                                       /* in other case an IP must just match */                          }                                                                       /* in other case an IP must just match */
657                          else if (equal(ip, g_aName[i]))                          else if (equal(ip, AuthData))
658                          {                          {
659                                  index = i                                  index = i
660                                  break                                  break
661                          }                          }
662                  } else {                  }
663                          if (g_aFlags[i] & FLAG_TAG)                  else
664                    {
665                            if (Flags & FLAG_TAG)
666                          {                          {
667                                  if (containi(name, g_aName[i]) != -1)                                  if (containi(name, AuthData) != -1)
668                                  {                                  {
669                                          index = i                                          index = i
670                                          break                                          break
671                                  }                                  }
672                          }                          }
673                          else if (equali(name, g_aName[i]))                          else if (equali(name, AuthData))
674                          {                          {
675                                  index = i                                  index = i
676                                  break                                  break
# Line 590  Line 680 
680    
681          if (index != -1)          if (index != -1)
682          {          {
683                  if (g_aFlags[index] & FLAG_NOPASS)                  Access=admins_lookup(index,AdminProp_Access);
684    
685                    if (Flags & FLAG_NOPASS)
686                  {                  {
687                          result |= 8                          result |= 8
688                          new sflags[32]                          new sflags[32]
689    
690                          get_flags(g_aAccess[index], sflags, 31)                          get_flags(Access, sflags, 31)
691                          set_user_flags(id, g_aAccess[index])                          set_user_flags(id, Access)
692    
693                          log_amx("Login: ^"%s<%d><%s><>^" became an admin (account ^"%s^") (access ^"%s^") (address ^"%s^")", name, get_user_userid(id), authid, g_aName[index], sflags, ip)                          log_amx("Login: ^"%s<%d><%s><>^" became an admin (account ^"%s^") (access ^"%s^") (address ^"%s^")", name, get_user_userid(id), authid, AuthData, sflags, ip)
694                  }                  }
695                  else if (equal(password, g_aPassword[index]))                  else
696                    {
697    
698                            admins_lookup(index,AdminProp_Password,Password,sizeof(Password)-1);
699    
700                            if (equal(password, Password))
701                  {                  {
702                          result |= 12                          result |= 12
703                          set_user_flags(id, g_aAccess[index])                                  set_user_flags(id, Access)
704    
705                          new sflags[32]                          new sflags[32]
706                          get_flags(g_aAccess[index], sflags, 31)                                  get_flags(Access, sflags, 31)
707    
708                          log_amx("Login: ^"%s<%d><%s><>^" became an admin (account ^"%s^") (access ^"%s^") (address ^"%s^")", name, get_user_userid(id), authid, g_aName[index], sflags, ip)                                  log_amx("Login: ^"%s<%d><%s><>^" became an admin (account ^"%s^") (access ^"%s^") (address ^"%s^")", name, get_user_userid(id), authid, AuthData, sflags, ip)
709                  } else {                          }
710                            else
711                            {
712                          result |= 1                          result |= 1
713    
714                          if (g_aFlags[index] & FLAG_KICK)                                  if (Flags & FLAG_KICK)
715                          {                          {
716                                  result |= 2                                  result |= 2
717                                  log_amx("Login: ^"%s<%d><%s><>^" kicked due to invalid password (account ^"%s^") (address ^"%s^")", name, get_user_userid(id), authid, g_aName[index], ip)                                          log_amx("Login: ^"%s<%d><%s><>^" kicked due to invalid password (account ^"%s^") (address ^"%s^")", name, get_user_userid(id), authid, AuthData, ip)
718                                    }
719                          }                          }
720                  }                  }
721          }          }
722          else if (get_cvar_float("amx_mode") == 2.0)          else if (get_pcvar_float(amx_mode) == 2.0)
723          {          {
724                  result |= 2                  result |= 2
725          } else {          }
726            else
727            {
728                  new defaccess[32]                  new defaccess[32]
729    
730                  get_cvar_string("amx_default_access", defaccess, 31)                  get_pcvar_string(amx_default_access, defaccess, 31)
731    
732                  if (!strlen(defaccess))                  if (!strlen(defaccess))
733                    {
734                          copy(defaccess, 32, "z")                          copy(defaccess, 32, "z")
735                    }
736    
737                  new idefaccess = read_flags(defaccess)                  new idefaccess = read_flags(defaccess)
738    
# Line 660  Line 764 
764                  get_user_name(id, username, 31)                  get_user_name(id, username, 31)
765          }          }
766    
767          get_cvar_string("amx_password_field", passfield, 31)          get_pcvar_string(amx_password_field, passfield, 31)
768          get_user_info(id, passfield, password, 31)          get_user_info(id, passfield, password, 31)
769    
770          new result = getAccess(id, username, userauthid, userip, password)          new result = getAccess(id, username, userauthid, userip, password)
# Line 691  Line 795 
795    
796  public client_infochanged(id)  public client_infochanged(id)
797  {  {
798          if (!is_user_connected(id) || !get_cvar_num("amx_mode"))          if (!is_user_connected(id) || !get_pcvar_num(amx_mode))
799          {          {
800                  return PLUGIN_CONTINUE                  return PLUGIN_CONTINUE
801          }          }
# Line 712  Line 816 
816  public ackSignal(id)  public ackSignal(id)
817  {  {
818          server_cmd("kick #%d ^"%L^"", get_user_userid(id), id, "NO_ENTRY")          server_cmd("kick #%d ^"%L^"", get_user_userid(id), id, "NO_ENTRY")
819            return PLUGIN_HANDLED
820  }  }
821    
822  public client_authorized(id)  public client_authorized(id)
823          return get_cvar_num("amx_mode") ? accessUser(id) : PLUGIN_CONTINUE          return get_pcvar_num(amx_mode) ? accessUser(id) : PLUGIN_CONTINUE
824    
825  public client_putinserver(id)  public client_putinserver(id)
826  {  {
827          if (!is_dedicated_server() && id == 1)          if (!is_dedicated_server() && id == 1)
828                  return get_cvar_num("amx_mode") ? accessUser(id) : PLUGIN_CONTINUE                  return get_pcvar_num(amx_mode) ? accessUser(id) : PLUGIN_CONTINUE
829    
830          return PLUGIN_CONTINUE          return PLUGIN_CONTINUE
831  }  }

Legend:
Removed from v.16  
changed lines
  Added in v.17

Contact
ViewVC Help
Powered by ViewVC 1.0.4