/*********************************************************
 *    Bugblatter Auto Default Access Extension - V3.1    *
 *********************************************************
 *                                                       *
 * This plug-in is linux & win32 friendly.               *
 *                                                       *
 * Version history                                       *
 *                                                       *
 *                                                       *
 * Version 3.1:                                          *
 *                                                       *
 *  -  Initial Version                                   *
 *                                                       *
 * Version 2.6:                                          *
 *                                                       *
 *  -  Initial Version                                   *
 *********************************************************/
 
#include <admin>
#include <plugin>
#include <adminlib>
 
new g_Version[]="2.6";
new g_DefaultAccess[10];
 
forward checkforadmins(Timer,Repeat,HLUserName,HLParam);
 
public plugin_init() {
  plugin_registerinfo("Bugblatter's Auto Default Access Plugin","Disables public commands when an admin is connected",g_Version);
 
  numtostr(getvar("default_access"),g_DefaultAccess);
  set_timer("checkforadmins",10,99999,"");
  return PLUGIN_CONTINUE;
}
 
public checkforadmins(Timer,Repeat,HLUserName,HLParam) {
  new i;
  new c=maxplayercount();
  new name[MAX_NAME_LENGTH];
  new current=getvar("default_access");
 
  for (i=1;i<=c;i++) {
    if (playerinfo(i,name,MAX_NAME_LENGTH)!=0) {
      if (access(ACCESS_MAP,name) || access(ACCESS_KICK,name)) {
        if (current>0) {
          log("Setting default_access to 0");
          setstrvar("default_access","0");
          reload();
        }
        return PLUGIN_HANDLED;
      }
    }
  }
 
  if (current==0) {
    log("Setting default_access to 1");
    setstrvar("default_access",g_DefaultAccess);
    reload();
  }
 
  return PLUGIN_HANDLED;
}