Untitled

 avatar
unknown
c_cpp
4 years ago
3.1 kB
7
Indexable
void AddVip(int client, int time, const char[] szGroup)
{
  if(!g_bIsVipLoaded[client])
  {
    ArrayList data;
    data = CreateArray(32);
    data.Push(GetClientUserId(client));
    data.Push(time);
    data.PushString(szGroup);
    CreateTimer(1.0, Timer_RetryAddVip, data);
    return;
  }

  if(AV_HasAdminVip(client))
  {
    LogToFile(LOGS_PATH, "%L has admin VIP, NOT giving him %s for %d seconds", client, szGroup, time);
    return;
  }

  if(VIP_IsClientVIP(client))
  {
    if(VIP_GetClientID(client) == -1) // if temporary vip
    {
      LogToFile(LOGS_PATH, "%L has temporary VIP, giving him %s for %d seconds", client, szGroup, time);
      VIP_GiveClientVIP(_, client, time, szGroup, true); // seteaza-i VIP
      return;
    }

    if(VIP_GetClientAccessTime(client) == 0)
    {
      LogToFile(LOGS_PATH, "%L has permanent vip, returning", client);
      return;
    }   

    char sCurrentGroup[32];
    VIP_GetClientVIPGroup(client, sCurrentGroup, sizeof(sCurrentGroup));
    int iCurrentTime = VIP_GetClientAccessTime(client) - GetTime();

    switch(IsGroupHigher(sCurrentGroup, szGroup))
    {
      case VIP_GROUP_EQUAL:
      {
        if(iCurrentTime < time) // if his time is lower than newtime, increase it
        {
          VIP_SetClientAccessTime(client,  GetTime() + time, true);
          LogToFile(LOGS_PATH, "%L | CASE VIP_GROUP_EQUAL, INCREASING TIME ONLY", client);
        }
        return;
      }

      case VIP_GROUP_LOWER:
      { 
        if(iCurrentTime < time)
        {
          VIP_SetClientAccessTime(client,  GetTime() + time, true);
          LogToFile(LOGS_PATH, "%L | CASE VIP_GROUP_LOWER with iCurrentTime < newtime, changing his group. New: %s for %d seconds", client, szGroup, time);
        }
        LogToFile(LOGS_PATH, "%L | CASE VIP_GROUP_LOWER with iCurrentTime > newtime, changing his group. New: %s for %d seconds", client, szGroup, iCurrentTime);
        VIP_SetClientVIPGroup(client, szGroup, true);
        return;
      }

      case VIP_GROUP_HIGHER:
      {
        if(iCurrentTime < time)
        {
          VIP_SetClientAccessTime(client,  GetTime() + time, true);
          LogToFile(LOGS_PATH, "%L | CASE VIP_GROUP_HIGHER with iCurrentTime < newtime, Increasing time to %d seconds", client, time);
        }
        return;
      }
      case VIP_GROUP_NOTFOUND:
      {
        SetFailState("Group %s or %s was not found. Error.", szGroup, sCurrentGroup);
      }
    }
  }
  else
  {
    LogToFile(LOGS_PATH, "%L doesn't have VIP, adding him %s for %d seconds", client, szGroup, time);
    VIP_GiveClientVIP(_, client, time, szGroup, true);
  }
}


public Action Timer_RetryAddVip(Handle timer, ArrayList data)
{
  int client = GetClientUserId(data.Get(0));
  if(!IsClientConnected(client))
  {
    delete data;
    return Plugin_Continue;
  }

  char szGroup[32];
  data.GetString(2, szGroup, sizeof(szGroup));
  AddVip(client, data.Get(1), szGroup);
  delete data;
  return Plugin_Continue;
}
Editor is loading...