Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How I get time and reason ban when player connect with server #404

Closed
MynDoS opened this issue Feb 26, 2018 · 11 comments
Closed

How I get time and reason ban when player connect with server #404

MynDoS opened this issue Feb 26, 2018 · 11 comments
Assignees

Comments

@MynDoS
Copy link

MynDoS commented Feb 26, 2018

Hello,
How I can add new notification when player have ban and connect with server?

public VerifyBan(Handle:owner, Handle:hndl, const String:error[], any:userid)
{
	decl String:clientName[64];
	decl String:clientAuth[64];
	decl String:clientIp[64];
	new client = GetClientOfUserId(userid);

	if (!client)
		return;

	/* Failure happen. Do retry with delay */
	if (hndl == INVALID_HANDLE)
	{
		LogToFile(logFile, "Verify Ban Query Failed: %s", error);
		PlayerRecheck[client] = CreateTimer(RetryTime, ClientRecheck, client);
		return;
	}
	GetClientIP(client, clientIp, sizeof(clientIp));
	GetClientAuthId(client, AuthId_Steam2, clientAuth, sizeof(clientAuth));
	GetClientName(client, clientName, sizeof(clientName));
	if (SQL_GetRowCount(hndl) > 0)
	{
		decl String:buffer[40];
		decl String:Name[128];
		decl String:Query[512];

		SQL_EscapeString(DB, clientName, Name, sizeof(Name));
		if (serverID == -1)
		{
			FormatEx(Query, sizeof(Query), "INSERT INTO %s_banlog (sid ,time ,name ,bid) VALUES  \
				((SELECT sid FROM %s_servers WHERE ip = '%s' AND port = '%s' LIMIT 0,1), UNIX_TIMESTAMP(), '%s', \
				(SELECT bid FROM %s_bans WHERE ((type = 0 AND authid REGEXP '^STEAM_[0-9]:%s$') OR (type = 1 AND ip = '%s')) AND RemoveType IS NULL LIMIT 0,1))",
				DatabasePrefix, DatabasePrefix, ServerIp, ServerPort, Name, DatabasePrefix, clientAuth[8], clientIp);
		}
		else
		{
			FormatEx(Query, sizeof(Query), "INSERT INTO %s_banlog (sid ,time ,name ,bid) VALUES  \
				(%d, UNIX_TIMESTAMP(), '%s', \
				(SELECT bid FROM %s_bans WHERE ((type = 0 AND authid REGEXP '^STEAM_[0-9]:%s$') OR (type = 1 AND ip = '%s')) AND RemoveType IS NULL LIMIT 0,1))",
				DatabasePrefix, serverID, Name, DatabasePrefix, clientAuth[8], clientIp);
		}

		SQL_TQuery(DB, ErrorCheckCallback, Query, client, DBPrio_High);
		FormatEx(buffer, sizeof(buffer), "banid 5 %s", clientAuth);
		ServerCommand(buffer);
		KickClient(client, "%t", "Banned Check Site", WebsiteAddress);
		return;
	}
	#if defined DEBUG
	LogToFile(logFile, "%s is NOT banned.", clientAuth);
	#endif

	PlayerStatus[client] = true;
}

This notification print to player command "You have been banned by this server, check {1} for more info", but I want to add reason, time for this notification

@rumblefrog
Copy link
Member

You would want to fetch the reason & time within RowCount check. For the message, you would want to modify the translation file to update with the new #format and update each locale, and then change KickClient func call to include more args to pass to translation formatter

@MynDoS
Copy link
Author

MynDoS commented Feb 28, 2018

Can You show me, how I can get reason and time from database?
I don't understand how I can get reason and time and Your doesn't help me :(

@MynDoS
Copy link
Author

MynDoS commented Mar 1, 2018

Okej,
This is code, which get reason, time, etc

public VerifyBan(Handle:owner, Handle:hndl, const String:error[], any:userid)
{
	decl String:clientName[64];
	decl String:clientAuth[64];
	decl String:clientIp[64];
	new client = GetClientOfUserId(userid);

	if (!client)
		return;

	/* Failure happen. Do retry with delay */
	if (hndl == INVALID_HANDLE)
	{
		LogToFile(logFile, "Verify Ban Query Failed: %s", error);
		PlayerRecheck[client] = CreateTimer(RetryTime, ClientRecheck, client);
		return;
	}
	GetClientIP(client, clientIp, sizeof(clientIp));
	GetClientAuthId(client, AuthId_Steam2, clientAuth, sizeof(clientAuth));
	GetClientName(client, clientName, sizeof(clientName));
	if (SQL_GetRowCount(hndl) > 0)
	{
		decl String:buffer[40];
		decl String:Name[128];
		decl String:Query[512];

		SQL_EscapeString(DB, clientName, Name, sizeof(Name));
		if (serverID == -1)
		{
			FormatEx(Query, sizeof(Query), "INSERT INTO %s_banlog (sid ,time ,name ,bid) VALUES  \
				((SELECT sid FROM %s_servers WHERE ip = '%s' AND port = '%s' LIMIT 0,1), UNIX_TIMESTAMP(), '%s', \
				(SELECT bid FROM %s_bans WHERE ((type = 0 AND authid REGEXP '^STEAM_[0-9]:%s$') OR (type = 1 AND ip = '%s')) AND RemoveType IS NULL LIMIT 0,1))",
				DatabasePrefix, DatabasePrefix, ServerIp, ServerPort, Name, DatabasePrefix, clientAuth[8], clientIp);
		}
		else
		{
			FormatEx(Query, sizeof(Query), "INSERT INTO %s_banlog (sid ,time ,name ,bid) VALUES  \
				(%d, UNIX_TIMESTAMP(), '%s', \
				(SELECT bid FROM %s_bans WHERE ((type = 0 AND authid REGEXP '^STEAM_[0-9]:%s$') OR (type = 1 AND ip = '%s')) AND RemoveType IS NULL LIMIT 0,1))",
				DatabasePrefix, serverID, Name, DatabasePrefix, clientAuth[8], clientIp);
		}

		SQL_TQuery(DB, ErrorCheckCallback, Query, client, DBPrio_High);
		FormatEx(buffer, sizeof(buffer), "banid 5 %s", clientAuth);
		ServerCommand(buffer);
		/*KickClient(client, "%t", "Banned Check Site", WebsiteAddress);*/

		decl String:buffer1[512];
		Format(buffer1, sizeof(buffer1), "SELECT steam_id, time, start_time, reason, name FROM %s_bans WHERE ((type = 0 AND authid REGEXP '^STEAM_[0-9]:%s$') OR (type = 1 AND ip = '%s'))", DatabasePrefix, clientAuth[8], clientIp);
		SQL_TQuery(SQLiteDB, ProcessVerifyCallback1, buffer1, GetClientUserId(client));
		return;
	}
	#if defined DEBUG
	LogToFile(logFile, "%s is NOT banned.", clientAuth);
	#endif

	PlayerStatus[client] = true;
}

public ProcessVerifyCallback1(Handle:owner, Handle:hndl, const String:error[], any:data)
{
	if (hndl == INVALID_HANDLE || strlen(error) > 0)
	{
		LogToFile(logFile, "Failed, %s", error);
		return;
	}

	decl String:auth[30];
	decl time;
	decl startTime;
	new String:reason[128];
	decl String:name[64];
	decl String:banName[128];
	decl String:banReason[256];
	new client = GetClientOfUserId(data);
	while (SQL_MoreRows(hndl))
	{
		// Oh noes! What happened?!
		if (!SQL_FetchRow(hndl))
			continue;

		// if we get to here then there are rows in the queue pending processing
		SQL_FetchString(hndl, 0, auth, sizeof(auth));
		time = SQL_FetchInt(hndl, 1);
		startTime = SQL_FetchInt(hndl, 2);
		SQL_FetchString(hndl, 3, reason, sizeof(reason));
		SQL_FetchString(hndl, 4, name, sizeof(name));
		SQL_EscapeString(SQLiteDB, name, banName, sizeof(banName));
		SQL_EscapeString(SQLiteDB, reason, banReason, sizeof(banReason));

		char BanEnd[64];
		FormatTime(BanEnd, sizeof(BanEnd), "%d-%m-%Y %H:%M", (GetTime() + time + startTime * 60));
		char sBuffer[256];
		GetConVarString(FindConVar("hostname"), sBuffer,sizeof(sBuffer));
		KickClient(client, "Name: %N\nReason: %s\nBan end: %s\nServer: %s", banName, banReason, BanEnd, sBuffer);

	}
}

Good?

@rumblefrog
Copy link
Member

If it works, it works, but the additional call is not required as the dataset handle is already present in VerifyBan params

@MynDoS
Copy link
Author

MynDoS commented Mar 2, 2018

Ech, this code not work :(
Player have ban, but if he connect with server, not kicked

@rumblefrog
Copy link
Member

rumblefrog commented Mar 3, 2018

Try this gist: https://gist.github.com/RumbleFrog/9b6192de0d81137769229935e99815b2

Note that length is not formatted to be human-friendly, but it'll help you get the gist

@MynDoS
Copy link
Author

MynDoS commented Mar 3, 2018

Thank you very much.
It works

@MynDoS
Copy link
Author

MynDoS commented Mar 3, 2018

Can I delete this code

FormatEx(buffer, sizeof(buffer), "banid 5 %s", clientAuth);
ServerCommand(buffer);

?

@rumblefrog
Copy link
Member

rumblefrog commented Mar 3, 2018

No, that actually is used to prevent them from joining rapidly, sorta like a cache

@rumblefrog rumblefrog self-assigned this Mar 3, 2018
@MynDoS
Copy link
Author

MynDoS commented Mar 4, 2018

Okej,
Thank you very much.

@MynDoS MynDoS closed this as completed Mar 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants