#include <adminlib>

#define SHOWACCESS 0

#if SHOWACCESS != 0
 #define ADMIN_BITS 17
 #define ACCESS_CHAR '.'
#endif

forward HandleSay(HLCommand,HLData,HLUserName,UserIndex);
#if SHOWACCESS != 0
 forward get_accesslevel(UserName[MAX_NAME_LENGTH],Level[MAX_DATA_LENGTH]);
#endif

new g_Version[] = "2.50.50";

public HandleSay(HLCommand,HLData,HLUserName,UserIndex) {
   static Data[MAX_DATA_LENGTH];
   convert_string(HLData,Data,MAX_DATA_LENGTH);
   strstripquotes(Data);
   if(strncasecmp(Data,"admin",5)) {
      return PLUGIN_CONTINUE;
   } else {
      new Name[MAX_NAME_LENGTH];
      new Menutext[512];
      new maxplayers = maxplayercount() + 1;
      new Admins = 0;
      new i;
      strcpy(Menutext,"\yAdmins on Server:^n^n\d-------------------------",512);
      for(i=1;i<maxplayers;i++) {
         if(playerinfo(i,Name,MAX_NAME_LENGTH) == 1) {
            if(auth(Name)) {
#if SHOWACCESS != 0
               get_accesslevel(Name,Data);
               snprintf(Data,MAX_DATA_LENGTH,"^n\w%s^n       %s^n\d-------------------------",Name,Data);
#else
               snprintf(Data,MAX_DATA_LENGTH,"^n\w%s",Name);
#endif
               strcat(Menutext,Data,512);
               Admins++;
            }
         }
      }
      if(Admins) {
         snprintf(Data,MAX_DATA_LENGTH,"^n^n\y%i Admins",Admins);
         strcat(Menutext,Data,512);
      } else {
         strcpy(Menutext,"^n^n^n^n^n^n^n^n\yThere are no admins present at the moment.",512);
      }
      convert_string(HLUserName,Name,MAX_NAME_LENGTH);
      menu(Name,Menutext,1023,0);
   }
   return PLUGIN_HANDLED;
}

#if SHOWACCESS != 0
get_accesslevel(UserName[MAX_NAME_LENGTH],Level[]) {
   new i,j = 1<<(ADMIN_BITS),k = 0;
   new color = 0;
   for(i=0;i<ADMIN_BITS;i++) {
      j >>= 1;
      if(access(j,UserName)) {
          if(!color) {
              Level[k++] = '\';
              Level[k++] = 'y';
              color = 1;
          }
      } else {
          if(color) {
              Level[k++] = '\';
              Level[k++] = 'd';
              color = 0;
          }
      }
      Level[k++] = ACCESS_CHAR;
   }
   Level[k] = '^0';
}
#endif

public plugin_init() {
   plugin_registerinfo("Rinde's Admin Plugin","Returns all admins on server",g_Version);
   plugin_registercmd("say","HandleSay",ACCESS_ALL,"say admin: Prints all admins and their adminlevels.");
   return PLUGIN_CONTINUE;
}