Merge branch 'master' of http://git.unloze.com/UNLOZE/sm-plugins
This commit is contained in:
		
						commit
						93dcb84f20
					
				| @ -1,18 +1,33 @@ | |||||||
|  | #pragma semicolon 1 | ||||||
|  | 
 | ||||||
| #include <sourcemod> | #include <sourcemod> | ||||||
| 
 | 
 | ||||||
| char g_sAdmGroup[32] = "Game-Donator"; | #pragma newdecls required | ||||||
| 
 | 
 | ||||||
|  | /* STRINGS */ | ||||||
|  | char g_sAdmGroup[32] = "Game-Donator"; | ||||||
|  | char g_sGroup[MAXPLAYERS+1][64]; | ||||||
|  | 
 | ||||||
|  | /* CONVARS */ | ||||||
| ConVar g_cvFreeVIPDuration; | ConVar g_cvFreeVIPDuration; | ||||||
| 
 | 
 | ||||||
|  | /* DATABASE */ | ||||||
|  | Database g_hDatabase; | ||||||
|  | 
 | ||||||
|  | /* BOOLS */ | ||||||
|  | bool g_bPreAdminChecked[MAXPLAYERS+1]; | ||||||
|  | bool g_bResponseFailed[MAXPLAYERS+1]; | ||||||
|  | bool g_bResponsePassed[MAXPLAYERS+1]; | ||||||
|  | 
 | ||||||
| //---------------------------------------------------------------------------------------------------- | //---------------------------------------------------------------------------------------------------- | ||||||
| // Purpose: | // Purpose: | ||||||
| //---------------------------------------------------------------------------------------------------- | //---------------------------------------------------------------------------------------------------- | ||||||
| public Plugin myinfo = | public Plugin myinfo = | ||||||
| { | { | ||||||
| 	name        = "Unloze_VIP_Test", | 	name        = "UNLOZE_VIP_Test", | ||||||
| 	author      = "Neon", | 	author      = "Neon", | ||||||
| 	description = "", | 	description = "", | ||||||
| 	version     = "1.0", | 	version     = "2.0", | ||||||
| 	url         = "https://steamcommunity.com/id/n3ontm" | 	url         = "https://steamcommunity.com/id/n3ontm" | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -26,18 +41,15 @@ public void OnPluginStart() | |||||||
| 	RegConsoleCmd("sm_viptest", Command_VIP, "Activate free VIP period"); | 	RegConsoleCmd("sm_viptest", Command_VIP, "Activate free VIP period"); | ||||||
| 	RegConsoleCmd("sm_testvip", Command_VIP, "Activate free VIP period"); | 	RegConsoleCmd("sm_testvip", Command_VIP, "Activate free VIP period"); | ||||||
| 	RegConsoleCmd("sm_vip", Command_VIP, "Activate free VIP period"); | 	RegConsoleCmd("sm_vip", Command_VIP, "Activate free VIP period"); | ||||||
| } |  | ||||||
| 
 | 
 | ||||||
| //---------------------------------------------------------------------------------------------------- | 	AutoExecConfig(); | ||||||
| // Purpose: |  | ||||||
| //---------------------------------------------------------------------------------------------------- |  | ||||||
| public Action Command_VIP(int iClient, int iArgs) |  | ||||||
| { |  | ||||||
| 	if (!IsValidClient(iClient)) |  | ||||||
| 		return Plugin_Handled; |  | ||||||
| 
 | 
 | ||||||
| 	CheckMYSQL(iClient, true); | 	char sError[256]; | ||||||
| 	return Plugin_Handled; | 	if (SQL_CheckConfig("testvip")) | ||||||
|  | 		g_hDatabase = SQL_Connect("testvip", true, sError, sizeof(sError)); | ||||||
|  | 
 | ||||||
|  | 	if (g_hDatabase == null) | ||||||
|  | 		LogError("Could not connect to database: %s", sError); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| //---------------------------------------------------------------------------------------------------- | //---------------------------------------------------------------------------------------------------- | ||||||
| @ -54,120 +66,169 @@ public void OnRebuildAdminCache(AdminCachePart part) | |||||||
| //---------------------------------------------------------------------------------------------------- | //---------------------------------------------------------------------------------------------------- | ||||||
| // Purpose: | // Purpose: | ||||||
| //---------------------------------------------------------------------------------------------------- | //---------------------------------------------------------------------------------------------------- | ||||||
| public void OnClientPostAdminFilter(int client) | public Action OnRebuildAdminCachePost(Handle hTimer) | ||||||
| { | { | ||||||
| 	CheckMYSQL(client); | 	for (int client = 1; client <= MaxClients; client++) | ||||||
|  | 	{ | ||||||
|  | 		if(g_bResponsePassed[client] && g_bPreAdminChecked[client]) | ||||||
|  | 			ApplyGroupFlags(client); | ||||||
|  | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| //---------------------------------------------------------------------------------------------------- | //---------------------------------------------------------------------------------------------------- | ||||||
| // Purpose: | // Purpose: | ||||||
| //---------------------------------------------------------------------------------------------------- | //---------------------------------------------------------------------------------------------------- | ||||||
| bool CheckMYSQL(int client, bool add = false) | public void OnClientConnected(int client) | ||||||
| { | { | ||||||
| 	if (client == 0) | 	g_bPreAdminChecked[client] = false; | ||||||
| 		return false; | 	g_bResponseFailed[client] = false; | ||||||
|  | 	g_bResponsePassed[client] = false; | ||||||
| 
 | 
 | ||||||
| 	char error[255]; | 	g_sGroup[client][0] = 0; | ||||||
| 	Database db; | } | ||||||
| 
 | 
 | ||||||
| 	if (SQL_CheckConfig("testvip")) | //---------------------------------------------------------------------------------------------------- | ||||||
| 	{ | // Purpose: | ||||||
| 		db = SQL_Connect("testvip", true, error, sizeof(error)); | //---------------------------------------------------------------------------------------------------- | ||||||
| 	} | public void OnClientDisconnect(int client) | ||||||
|  | { | ||||||
|  | 	g_bPreAdminChecked[client] = false; | ||||||
|  | 	g_bResponseFailed[client] = false; | ||||||
|  | 	g_bResponsePassed[client] = false; | ||||||
| 
 | 
 | ||||||
| 	if (db == null) | 	g_sGroup[client][0] = 0; | ||||||
| 	{ | } | ||||||
| 		LogError("Could not connect to database: %s", error); |  | ||||||
| 		delete db; |  | ||||||
| 		return false; |  | ||||||
| 	} |  | ||||||
| 
 | 
 | ||||||
| 	if (!IsFakeClient(client) && !IsClientSourceTV(client)) | //---------------------------------------------------------------------------------------------------- | ||||||
| 	{ | // Purpose: | ||||||
| 		char sSID[64]; | //---------------------------------------------------------------------------------------------------- | ||||||
| 		GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID)); | public void OnClientAuthorized(int client, const char[] sSteamID32) | ||||||
|  | { | ||||||
|  | 	if (IsFakeClient(client)) | ||||||
|  | 		return; | ||||||
| 
 | 
 | ||||||
| 		char sQuery[255]; | 	char sSteamID[32]; | ||||||
| 		Format(sQuery, sizeof(sQuery), "SELECT * FROM testvip_table WHERE steam_auth = '%s'", sSID); | 	GetClientAuthId(client, AuthId_Steam2, sSteamID, sizeof(sSteamID)); | ||||||
| 		DBResultSet rs; |  | ||||||
| 		if ((rs = SQL_Query(db, sQuery)) == null) |  | ||||||
| 		{ |  | ||||||
| 			delete db; |  | ||||||
| 			delete rs; |  | ||||||
| 			LogError("Database Error: %s", error); |  | ||||||
| 			return false; |  | ||||||
| 		} |  | ||||||
| 		int iTimestamp = GetTime(); |  | ||||||
| 		int iTimestampActivated = GetTime(); |  | ||||||
| 		bool bFound = false; |  | ||||||
| 
 | 
 | ||||||
| 		if (!(rs.RowCount > 0)) | 	char sQuery[256]; | ||||||
| 		{ | 	Format(sQuery, sizeof(sQuery), "SELECT * FROM testvip_table WHERE steam_auth = '%s'", sSteamID); | ||||||
| 			if (add) | 	SQL_TQuery(g_hDatabase, TQueryCBConnect, sQuery, GetClientUserId(client)); | ||||||
| 			{ | } | ||||||
| 				bool bHasVIP = false; |  | ||||||
| 				AdminId AdmID; |  | ||||||
| 
 | 
 | ||||||
| 				if ((AdmID = GetUserAdmin(client)) == INVALID_ADMIN_ID) | //---------------------------------------------------------------------------------------------------- | ||||||
| 					bHasVIP = false; | // Purpose: | ||||||
| 				else | //---------------------------------------------------------------------------------------------------- | ||||||
| 				{ | public void TQueryCBConnect(Handle owner, Handle rs, const char[] error, any data) | ||||||
| 					for (int i = 0; i <= GetAdminGroupCount(AdmID); i++) | { | ||||||
| 					{ | 	int client = 0; | ||||||
| 						char sGroup[32]; |  | ||||||
| 						if ((GetAdminGroup(AdmID, i, sGroup, sizeof(sGroup)) != INVALID_GROUP_ID)) |  | ||||||
| 						{ |  | ||||||
| 							if (StrEqual(sGroup, g_sAdmGroup)) |  | ||||||
| 								bHasVIP = true; |  | ||||||
| 						} |  | ||||||
| 					} |  | ||||||
| 				} |  | ||||||
| 
 | 
 | ||||||
| 				if (!bHasVIP) | 	if ((client = GetClientOfUserId(data)) == 0) | ||||||
| 				{ | 		return; | ||||||
| 					Format(sQuery, sizeof(sQuery), "INSERT INTO testvip_table (steam_auth, activated) VALUES ('%s', '%d')", sSID, iTimestamp); |  | ||||||
| 					SQL_FastQuery(db, sQuery); |  | ||||||
| 
 | 
 | ||||||
| 					ApplyGroupFlags(client); | 	if (SQL_GetRowCount(rs) > 0) | ||||||
| 					PrintToChat(client, "[Unloze] Your TEST VIP will expire in %d minutes!", g_cvFreeVIPDuration.IntValue - (iTimestamp - iTimestampActivated) / 60); |  | ||||||
| 					PrintToChat(client, "[Unloze] You have now access to !zclass, !tag and !glow."); |  | ||||||
| 				} |  | ||||||
| 				else |  | ||||||
| 				{ |  | ||||||
| 					PrintToChat(client, "[Unloze] You already have VIP activated!"); |  | ||||||
| 					delete db; |  | ||||||
| 					delete rs; |  | ||||||
| 					return false; |  | ||||||
| 				} |  | ||||||
| 
 |  | ||||||
| 			} |  | ||||||
| 		} |  | ||||||
| 		else |  | ||||||
| 	{ | 	{ | ||||||
| 		int iField; | 		int iField; | ||||||
| 			rs.FetchRow(); | 		SQL_FetchRow(rs); | ||||||
| 			rs.FieldNameToNum("activated", iField); | 		SQL_FieldNameToNum(rs, "activated", iField); | ||||||
| 			iTimestampActivated = rs.FetchInt(iField); | 		int iTimestampActivated = SQL_FetchInt(rs, iField); | ||||||
| 			bFound = true; | 		int iTimestamp = GetTime(); | ||||||
| 		} |  | ||||||
| 		delete rs; | 		delete rs; | ||||||
| 
 | 
 | ||||||
| 		if (bFound) |  | ||||||
| 		{ |  | ||||||
| 		if ((iTimestamp - iTimestampActivated) < g_cvFreeVIPDuration.IntValue *60) | 		if ((iTimestamp - iTimestampActivated) < g_cvFreeVIPDuration.IntValue *60) | ||||||
| 		{ | 		{ | ||||||
|  | 			strcopy(g_sGroup[client], sizeof(g_sGroup[]), g_sAdmGroup); | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	g_bResponsePassed[client] = true; | ||||||
|  | 	if (g_bPreAdminChecked[client]) | ||||||
|  | 		NotifyPostAdminCheck(client); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | //---------------------------------------------------------------------------------------------------- | ||||||
|  | // Purpose: | ||||||
|  | //---------------------------------------------------------------------------------------------------- | ||||||
|  | public Action OnClientPreAdminCheck(int client) | ||||||
|  | { | ||||||
|  | 	g_bPreAdminChecked[client] = true; | ||||||
|  | 
 | ||||||
|  | 	if (g_bResponsePassed[client] || g_bResponseFailed[client]) | ||||||
|  | 		return Plugin_Continue; | ||||||
|  | 
 | ||||||
|  | 	RunAdminCacheChecks(client); | ||||||
|  | 	return Plugin_Handled; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | //---------------------------------------------------------------------------------------------------- | ||||||
|  | // Purpose: | ||||||
|  | //---------------------------------------------------------------------------------------------------- | ||||||
|  | public void OnClientPostAdminFilter(int client) | ||||||
|  | { | ||||||
| 	ApplyGroupFlags(client); | 	ApplyGroupFlags(client); | ||||||
| 				PrintToChat(client, "[Unloze] Your TEST VIP will expire in %d minutes!", g_cvFreeVIPDuration.IntValue - (iTimestamp - iTimestampActivated) / 60); | } | ||||||
|  | 
 | ||||||
|  | //---------------------------------------------------------------------------------------------------- | ||||||
|  | // Purpose: | ||||||
|  | //---------------------------------------------------------------------------------------------------- | ||||||
|  | public Action Command_VIP(int client, int iArgs) | ||||||
|  | { | ||||||
|  | 	if (!IsValidClient(client)) | ||||||
|  | 		return Plugin_Handled; | ||||||
|  | 
 | ||||||
|  | 	char sSteamID[32]; | ||||||
|  | 	GetClientAuthId(client, AuthId_Steam2, sSteamID, sizeof(sSteamID)); | ||||||
|  | 
 | ||||||
|  | 	char sQuery[255]; | ||||||
|  | 	Format(sQuery, sizeof(sQuery), "SELECT * FROM testvip_table WHERE steam_auth = '%s'", sSteamID); | ||||||
|  | 	SQL_TQuery(g_hDatabase, TQueryCBCommand, sQuery, GetClientUserId(client)); | ||||||
|  | 
 | ||||||
|  | 	return Plugin_Handled; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | //---------------------------------------------------------------------------------------------------- | ||||||
|  | // Purpose: | ||||||
|  | //---------------------------------------------------------------------------------------------------- | ||||||
|  | public void TQueryCBCommand(Handle owner, Handle rs, const char[] error, any data) | ||||||
|  | { | ||||||
|  | 	int client = 0; | ||||||
|  | 
 | ||||||
|  | 	if ((client = GetClientOfUserId(data)) == 0) | ||||||
|  | 		return; | ||||||
|  | 
 | ||||||
|  | 	int iTimestamp = GetTime(); | ||||||
|  | 
 | ||||||
|  | 	if (SQL_GetRowCount(rs) > 0) | ||||||
|  | 	{ | ||||||
|  | 		int iField; | ||||||
|  | 		SQL_FetchRow(rs); | ||||||
|  | 		SQL_FieldNameToNum(rs, "activated", iField); | ||||||
|  | 		int iTimestampActivated = SQL_FetchInt(rs, iField); | ||||||
|  | 		delete rs; | ||||||
|  | 
 | ||||||
|  | 		if ((iTimestamp - iTimestampActivated) < g_cvFreeVIPDuration.IntValue *60) | ||||||
|  | 			PrintToChat(client, "[UNLOZE] Your TEST VIP will expire in %d minutes!", g_cvFreeVIPDuration.IntValue - (iTimestamp - iTimestampActivated) / 60); | ||||||
|  | 		else | ||||||
|  | 			PrintToChat(client, "[UNLOZE] Your TEST VIP expired already!"); | ||||||
| 	} | 	} | ||||||
| 	else | 	else | ||||||
| 	{ | 	{ | ||||||
| 				if (add) | 		if (IsVIP(client)) | ||||||
| 					PrintToChat(client, "[Unloze] Your TEST VIP expired already!", g_cvFreeVIPDuration.IntValue - (iTimestamp - iTimestampActivated) / 60); | 		{ | ||||||
|  | 			PrintToChat(client, "[UNLOZE] You already have VIP activated!"); | ||||||
|  | 			return; | ||||||
| 		} | 		} | ||||||
|  | 
 | ||||||
|  | 		char sSteamID[32]; | ||||||
|  | 		GetClientAuthId(client, AuthId_Steam2, sSteamID, sizeof(sSteamID)); | ||||||
|  | 
 | ||||||
|  | 		char sQuery[255]; | ||||||
|  | 		Format(sQuery, sizeof(sQuery), "INSERT INTO testvip_table (steam_auth, activated) VALUES ('%s', '%d')", sSteamID, iTimestamp); | ||||||
|  | 		SQL_FastQuery(g_hDatabase, sQuery); | ||||||
|  | 		strcopy(g_sGroup[client], sizeof(g_sGroup[]), g_sAdmGroup); | ||||||
|  | 		ApplyGroupFlags(client); | ||||||
|  | 		PrintToChat(client, "[UNLOZE] You have now access to !zclass, !tag and !glow and other VIP-Perks."); | ||||||
|  | 		PrintToChat(client, "[UNLOZE] Your TEST VIP will expire in %d minutes!", g_cvFreeVIPDuration.IntValue); | ||||||
| 	} | 	} | ||||||
| 	} |  | ||||||
| 	delete db; |  | ||||||
| 	return true; |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| //---------------------------------------------------------------------------------------------------- | //---------------------------------------------------------------------------------------------------- | ||||||
| @ -175,6 +236,12 @@ bool CheckMYSQL(int client, bool add = false) | |||||||
| //---------------------------------------------------------------------------------------------------- | //---------------------------------------------------------------------------------------------------- | ||||||
| stock void ApplyGroupFlags(int client) | stock void ApplyGroupFlags(int client) | ||||||
| { | { | ||||||
|  | 	if (!g_bResponsePassed[client]) | ||||||
|  | 		return; | ||||||
|  | 
 | ||||||
|  | 	if (g_sGroup[client][0] == 0) | ||||||
|  | 		return; | ||||||
|  | 
 | ||||||
| 	AdminId AdmID; | 	AdminId AdmID; | ||||||
| 	GroupId GrpID; | 	GroupId GrpID; | ||||||
| 
 | 
 | ||||||
| @ -186,27 +253,13 @@ stock void ApplyGroupFlags(int client) | |||||||
| 		SetUserAdmin(client, AdmID, true); | 		SetUserAdmin(client, AdmID, true); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	if ((GrpID = FindAdmGroup(g_sAdmGroup)) != INVALID_GROUP_ID) | 	if ((GrpID = FindAdmGroup(g_sGroup[client])) != INVALID_GROUP_ID) | ||||||
| 	{ | 	{ | ||||||
| 		if (AdminInheritGroup(AdmID, GrpID)) | 		if (AdminInheritGroup(AdmID, GrpID)) | ||||||
| 			LogMessage("%L added to group %s", client, g_sAdmGroup); | 			LogMessage("%L added to group %s", client, g_sGroup[client]); | ||||||
| 	} | 	} | ||||||
| 	else | 	else | ||||||
| 	{ | 		LogMessage("%L group not found %s", client, g_sGroup[client]); | ||||||
| 		LogMessage("%L group not found %s", client, g_sAdmGroup); |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| //---------------------------------------------------------------------------------------------------- |  | ||||||
| // Purpose: |  | ||||||
| //---------------------------------------------------------------------------------------------------- |  | ||||||
| public Action OnRebuildAdminCachePost(Handle hTimer) |  | ||||||
| { |  | ||||||
| 	for (int client = 1; client <= MaxClients; client++) |  | ||||||
| 	{ |  | ||||||
| 		if (IsValidClient(client)) |  | ||||||
| 			CheckMYSQL(client); |  | ||||||
| 	} |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| //---------------------------------------------------------------------------------------------------- | //---------------------------------------------------------------------------------------------------- | ||||||
| @ -215,8 +268,31 @@ public Action OnRebuildAdminCachePost(Handle hTimer) | |||||||
| stock int IsValidClient(int client, bool nobots = true) | stock int IsValidClient(int client, bool nobots = true) | ||||||
| { | { | ||||||
| 	if (client <= 0 || client > MaxClients || !IsClientConnected(client) || (nobots && IsFakeClient(client))) | 	if (client <= 0 || client > MaxClients || !IsClientConnected(client) || (nobots && IsFakeClient(client))) | ||||||
| 	{ |  | ||||||
| 		return false; | 		return false; | ||||||
| 	} | 
 | ||||||
| 	return IsClientInGame(client); | 	return IsClientInGame(client); | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | //---------------------------------------------------------------------------------------------------- | ||||||
|  | // Purpose: | ||||||
|  | //---------------------------------------------------------------------------------------------------- | ||||||
|  | public bool IsVIP(int client) | ||||||
|  | { | ||||||
|  | 	AdminId AdmID; | ||||||
|  | 
 | ||||||
|  | 	if ((AdmID = GetUserAdmin(client)) == INVALID_ADMIN_ID) | ||||||
|  | 		return false; | ||||||
|  | 	else | ||||||
|  | 	{ | ||||||
|  | 		for (int i = 0; i <= GetAdminGroupCount(AdmID); i++) | ||||||
|  | 		{ | ||||||
|  | 			char sGroup[32]; | ||||||
|  | 			if ((GetAdminGroup(AdmID, i, sGroup, sizeof(sGroup)) != INVALID_GROUP_ID)) | ||||||
|  | 			{ | ||||||
|  | 				if (StrEqual(sGroup, g_sAdmGroup)) | ||||||
|  | 					return true; | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 	return false; | ||||||
|  | } | ||||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
		Loading…
	
		Reference in New Issue
	
	Block a user