Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Clients_LoadVIPFeatures(int iClient)
- {
- DebugMessage("LoadVIPFeatures %N", iClient)
- DebugMessage("AreClientCookiesCached %b", AreClientCookiesCached(iClient))
- if (!AreClientCookiesCached(iClient))
- {
- CreateTimer(0.5, Timer_CheckCookies, UID(iClient), TIMER_FLAG_NO_MAPCHANGE);
- }
- DebugMessage("AreClientCookiesCached %b", AreClientCookiesCached(iClient))
- int iFeatures = g_hFeaturesArray.Length;
- DebugMessage("FeaturesArraySize: %d", iFeatures)
- if (iFeatures > 0)
- {
- char sFeatureName[FEATURE_NAME_LENGTH];
- g_hFeatures[iClient].GetString(KEY_GROUP, SZF(sFeatureName));
- if (UTIL_CheckValidVIPGroup(sFeatureName))
- {
- char sBuffer[4];
- Handle hCookie;
- VIP_ToggleState Status;
- ArrayList hArray;
- for (int i = 0; i < iFeatures; ++i)
- {
- g_hFeaturesArray.GetString(i, SZF(sFeatureName));
- if (GLOBAL_TRIE.GetValue(sFeatureName, hArray))
- {
- DebugMessage("LoadClientFeature: %d - %s", i, sFeatureName)
- if (GetValue(iClient, view_as<VIP_ValueType>(hArray.Get(FEATURES_VALUE_TYPE)), sFeatureName))
- {
- DebugMessage("GetValue: == true")
- if (view_as<VIP_FeatureType>(hArray.Get(FEATURES_ITEM_TYPE)) == TOGGLABLE)
- {
- hCookie = view_as<Handle>(hArray.Get(FEATURES_COOKIE));
- GetClientCookie(iClient, hCookie, SZF(sBuffer));
- Status = view_as<VIP_ToggleState>(StringToInt(sBuffer));
- DebugMessage("GetFeatureCookie: '%s'", sBuffer)
- if (sBuffer[0] == '\0' || (view_as<int>(Status) > 2 || view_as<int>(Status) < 0))
- {
- if(hArray.Length == 6)
- {
- Status = hArray.Get(FEATURES_DEF_STATUS) ? ENABLED:DISABLED;
- }
- else
- {
- Status = g_CVAR_bDefaultStatus ? ENABLED:DISABLED;
- }
- IntToString(view_as<int>(Status), SZF(sBuffer));
- SetClientCookie(iClient, hCookie, sBuffer);
- // Features_SaveStatus(iClient, sFeatureName, hCookie, Status);
- }
- }
- else
- {
- Status = ENABLED;
- }
- Features_SetStatus(iClient, sFeatureName, Status);
- // Function_OnItemToggle(view_as<Handle>(hArray.Get(FEATURES_PLUGIN)), Function:hArray.Get(FEATURES_ITEM_SELECT), iClient, sFeatureName, NO_ACCESS, ENABLED);
- }
- }
- }
- }
- }
- DebugMessage("Clients_OnVIPClientLoaded: %d %N", iClient, iClient)
- Clients_OnVIPClientLoaded(iClient);
- }
- void Clients_LoadVIPFeature(int iClient, const char[] sFeatureName)
- {
- DebugMessage("LoadVIPFeature %N", iClient)
- DebugMessage("AreClientCookiesCached %b", AreClientCookiesCached(iClient))
- if (!AreClientCookiesCached(iClient))
- {
- DataPack hDataPack = new DataPack();
- hDataPack.WriteCell(UID(iClient));
- hDataPack.WriteString(sFeatureName);
- CreateTimer(0.5, Timer_CheckCookies2, hDataPack, TIMER_FLAG_NO_MAPCHANGE|TIMER_DATA_HNDL_CLOSE);
- }
- DebugMessage("AreClientCookiesCached %b", AreClientCookiesCached(iClient))
- int iFeatures = g_hFeaturesArray.Length;
- DebugMessage("FeaturesArraySize: %d", iFeatures)
- if (iFeatures > 0)
- {
- char sGroup[FEATURE_NAME_LENGTH];
- g_hFeatures[iClient].GetString(KEY_GROUP, SZF(sGroup));
- if (UTIL_CheckValidVIPGroup(sGroup))
- {
- char sBuffer[4];
- Handle hCookie;
- VIP_ToggleState Status;
- ArrayList hArray;
- if (GLOBAL_TRIE.GetValue(sFeatureName, hArray))
- {
- DebugMessage("LoadClientFeature: %d - %s", i, sFeatureName)
- if (GetValue(iClient, view_as<VIP_ValueType>(hArray.Get(FEATURES_VALUE_TYPE)), sFeatureName))
- {
- DebugMessage("GetValue: == true")
- if (view_as<VIP_FeatureType>(hArray.Get(FEATURES_ITEM_TYPE)) == TOGGLABLE)
- {
- hCookie = view_as<Handle>(hArray.Get(FEATURES_COOKIE));
- GetClientCookie(iClient, hCookie, SZF(sBuffer));
- Status = view_as<VIP_ToggleState>(StringToInt(sBuffer));
- DebugMessage("GetFeatureCookie: '%s'", sBuffer)
- if (sBuffer[0] == '\0' || (view_as<int>(Status) > 2 || view_as<int>(Status) < 0))
- {
- if(hArray.Length == 6)
- {
- Status = hArray.Get(FEATURES_DEF_STATUS) ? ENABLED:DISABLED;
- }
- else
- {
- Status = g_CVAR_bDefaultStatus ? ENABLED:DISABLED;
- }
- IntToString(view_as<int>(Status), SZF(sBuffer));
- SetClientCookie(iClient, hCookie, sBuffer);
- // Features_SaveStatus(iClient, sFeatureName, hCookie, Status);
- }
- }
- else
- {
- Status = ENABLED;
- }
- Features_SetStatus(iClient, sFeatureName, Status);
- // Function_OnItemToggle(view_as<Handle>(hArray.Get(FEATURES_PLUGIN)), Function:hArray.Get(FEATURES_ITEM_SELECT), iClient, sFeatureName, NO_ACCESS, ENABLED);
- }
- }
- }
- }
- DebugMessage("Clients_OnVIPClientLoaded: %d %N", iClient, iClient)
- Clients_OnVIPClientLoaded(iClient);
- }
- bool GetValue(int iClient, VIP_ValueType ValueType, const char[] sFeatureName)
- {
- DebugMessage("GetValue: %d - %s", ValueType, sFeatureName)
- switch (ValueType)
- {
- case VIP_NULL:
- {
- return false;
- }
- case BOOL:
- {
- if (g_hGroups.GetNum(sFeatureName))
- {
- DebugMessage("value: 1")
- return g_hFeatures[iClient].SetValue(sFeatureName, true);
- }
- return false;
- }
- case INT:
- {
- int iValue;
- iValue = g_hGroups.GetNum(sFeatureName);
- if (iValue != 0)
- {
- DebugMessage("value: %d", iValue)
- return g_hFeatures[iClient].SetValue(sFeatureName, iValue);
- }
- return false;
- }
- case FLOAT:
- {
- float fValue;
- fValue = g_hGroups.GetFloat(sFeatureName);
- if (fValue != 0.0)
- {
- DebugMessage("value: %f", fValue)
- return g_hFeatures[iClient].SetValue(sFeatureName, fValue);
- }
- return false;
- }
- case STRING:
- {
- char sBuffer[256];
- g_hGroups.GetString(sFeatureName, SZF(sBuffer));
- if (sBuffer[0])
- {
- DebugMessage("value: %s", sBuffer)
- return g_hFeatures[iClient].SetString(sFeatureName, sBuffer);
- }
- return false;
- }
- default:
- {
- return false;
- }
- }
- return false;
- }
- public Action Timer_CheckCookies(Handle hTimer, any UserID)
- {
- int iClient = CID(UserID);
- DebugMessage("Timer_CheckCookies -> UserID: %d, iClient: %d, IsClientVIP: %b,", UserID, iClient, view_as<bool>(g_iClientInfo[iClient] & IS_VIP))
- if (iClient && g_iClientInfo[iClient] & IS_VIP)
- {
- Clients_LoadVIPFeatures(iClient);
- }
- return Plugin_Stop;
- }
- public Action Timer_CheckCookies2(Handle hTimer, Handle hDP)
- {
- DataPack hDataPack = view_as<DataPack>(hDP);
- int iClient = CID(hDataPack.ReadCell());
- DebugMessage("Timer_CheckCookies -> UserID: %d, iClient: %d, IsClientVIP: %b,", UserID, iClient, view_as<bool>(g_iClientInfo[iClient] & IS_VIP))
- if (iClient && g_iClientInfo[iClient] & IS_VIP)
- {
- char sFeatureName[FEATURE_NAME_LENGTH];
- hDataPack.ReadString(SZF(sFeatureName));
- Clients_LoadVIPFeature(iClient, sFeatureName);
- }
- return Plugin_Stop;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement