Raised This Month: $32 Target: $400
 8% 

Solved I need help in (player_disconnect)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
dr_lex
Member
Join Date: Dec 2014
Old 11-28-2020 , 15:15   I need help in (player_disconnect)
Reply With Quote #1

Good time of day
Need help with the player_disconnect event

Little is known about the events themselves
Can someone provide a sample code to study and understand

1. How to find out why a player left the server?
Attempt 1:
Code:
#pragma semicolon 1
#include <sourcemod>
#pragma newdecls required

char sg_log[160];

public void OnPluginStart()
{
    HookEvent("player_disconnect", Event_PlayerDisconnect);
    BuildPath(Path_SM, sg_log, sizeof(sg_log)-1, "logs/hm_disconnect.log");
}

public Action Event_PlayerDisconnect(Event event, const char[] name, bool dontBroadcast)
{
    int client = GetClientOfUserId(event.GetInt("userid"));
    if ((client != 0) && !IsFakeClient(client))
    {
        char reason[100];
        event.GetString("reason", reason, sizeof(reason));
        if (StrContains(reason, "self", false) != -1)
        {
            strcopy(reason, sizeof(reason), "self");
            LogToFileEx(sg_log, "self");
        }
        else if (StrContains(reason, "kick", false) != -1)
        {
            strcopy(reason, sizeof(reason), "kick");
            LogToFileEx(sg_log, "Kicked");
        }
        else if (StrContains(reason, "ban", false) != -1)
        {
            strcopy(reason, sizeof(reason), "ban");
            LogToFileEx(sg_log, "ban");
        }
        else if (StrContains(reason, "cheat", false) != -1)
        {
            strcopy(reason, sizeof(reason), "cheat");
            LogToFileEx(sg_log, "cheat");
        }
        else if (StrContains(reason, "error", false) != -1)
        {
            strcopy(reason, sizeof(reason), "error");
            LogToFileEx(sg_log, "error");
        }
        else
        {
            strcopy(reason, sizeof(reason), "???");
            LogToFileEx(sg_log, "???");
        }
     
        char player_name[MAX_NAME_LENGTH];
        event.GetString("name", player_name, sizeof(player_name));
        LogToFileEx(sg_log, "[%s] Disconnect (%s)", player_name, reason);
        if (!dontBroadcast)
        {
            SetEventBroadcast(event, true);
        }
    }
    return Plugin_Continue;
}
Attempt 2:
Code:
#pragma semicolon 1
#include <sourcemod>
#pragma newdecls required

char sg_log[160];

public void OnPluginStart()
{
	HookEvent("player_disconnect", Event_PlayerDisconnect);
	BuildPath(Path_SM, sg_log, sizeof(sg_log)-1, "logs/hm_disconnect.log");
}

public Action Event_PlayerDisconnect(Event event, const char[] name, bool dontBroadcast)
{
	int client = GetClientOfUserId(event.GetInt("userid"));
	if ((client != 0) && !IsFakeClient(client))
	{
		char reason[100];
		event.GetString("reason", reason, sizeof(reason));
		if(StrContains(reason, "connection rejected", false) != -1)
		{
			strcopy(reason, sizeof(reason), "connection rejected");
		}
		else if(StrContains(reason, "timed out", false) != -1)
		{
			strcopy(reason, sizeof(reason), "timed out");
		}
		else if(StrContains(reason, "by console", false) != -1)
		{
			strcopy(reason, sizeof(reason), "by console");
		}
		else if(StrContains(reason, "by user", false) != -1)
		{
			strcopy(reason, sizeof(reason), "by user");
		}
		else if(StrContains(reason, "ping is too high", false) != -1)
		{
			strcopy(reason, sizeof(reason), "ping is too high");
		}
		else if(StrContains(reason, "No Steam logon", false) != -1)
		{
			strcopy(reason, sizeof(reason), "No Steam logon);
		}
		else if(StrContains(reason, "Steam account is being used in another", false) != -1)
		{
			strcopy(reason, sizeof(reason), "Steam account is being used in another");
		}
		else if(StrContains(reason, "Steam Connection lost", false) != -1)
		{
			strcopy(reason, sizeof(reason), "Steam Connection lost");
		}
		else if(StrContains(reason, "This Steam account does not own this game", false) != -1)
		{
			strcopy(reason, sizeof(reason), "This Steam account does not own this game");
		}
		else if(StrContains(reason, "Validation Rejected", false) != -1)
		{
			strcopy(reason, sizeof(reason), "Validation Rejected");
		}
		else if(StrContains(reason, "Certificate Length", false) != -1)
		{
			strcopy(reason, sizeof(reason), "Certificate Length");
		}
		else if(StrContains(reason, "Pure server", false) != -1)
		{
			strcopy(reason, sizeof(reason), "Pure server");
		}
		else
		{
			strcopy(reason, sizeof(reason), "???");
		}
		
		char player_name[MAX_NAME_LENGTH];
		event.GetString("name", player_name, sizeof(player_name));
		LogToFileEx(sg_log, "[%s] Disconnect (%s)", player_name, reason);
		if (!dontBroadcast)
		{
			SetEventBroadcast(event, true);
		}
	}
	return Plugin_Continue;
}
2. How to know player xvid?
Code:
"xuid"        "uint64"    // player xuid
__________________

Last edited by dr_lex; 11-30-2020 at 10:25.
dr_lex is offline
PC Gamer
Veteran Member
Join Date: Mar 2014
Old 11-30-2020 , 01:27   Re: I need help in (player_disconnect)
Reply With Quote #2

Here's information on the player disconnect event: https://wiki.alliedmods.net/Generic_...yer_disconnect

The information you want to log is available during the event (player name, steamid, reason for disconnect).
PC Gamer is offline
dr_lex
Member
Join Date: Dec 2014
Old 11-30-2020 , 06:21   Re: I need help in (player_disconnect)
Reply With Quote #3

Quote:
Originally Posted by PC Gamer View Post
Here's information on the player disconnect event: https://wiki.alliedmods.net/Generic_...yer_disconnect
New information (in l4d2):
Code:
    "player_disconnect"            // a client was disconnected
    {
        "userid"    "short"        // user ID on server
        "reason"    "string"    // "self", "kick", "ban", "cheat", "error"
        "name"        "string"    // player name
        "xuid"        "uint64"    // player xuid
        "networkid"    "string"    // player network (i.e steam) id
        "bot"        "bool"        // is this a bot
        "reliable"  "1"            // this event is reliable
    }
Quote:
Originally Posted by PC Gamer View Post
The information you want to log is available during the event (player name, steamid, reason for disconnect).
I know, and I want to use "reason" for information about the reason for the player's exit

The hlmod forum gave me this example:
Code:
#pragma semicolon 1
#pragma newdecls required

public void OnPluginStart()
{
    HookEvent("player_disconnect", Event_Disconnect);
}

public void Event_Disconnect(Event event, const char[] name, bool dontBroadcast)
{
    if(event.GetBool("bot")) return;

    static char path[PLATFORM_MAX_PATH], reason[PLATFORM_MAX_PATH], nick[PLATFORM_MAX_PATH], netid[PLATFORM_MAX_PATH];

    if(!path[0]) BuildPath(Path_SM, path, sizeof(path), "logs/hm_disconnect.log");

    event.GetString("name", nick, sizeof(nick));
    event.GetString("networkid", netid, sizeof(netid));
    event.GetString("reason", reason, sizeof(reason));
    LogToFileEx(path, "'%s' (%s) disconnected (reason: '%s')", nick, netid, reason);
}
But it also does not show the reason for the exit in the logs
Code:
L 11/29/2020 - 'dr lex' (STEAM_1:1:**************) disconnected (reason: '')
__________________
dr_lex is offline
MAGNAT2645
Senior Member
Join Date: Nov 2015
Location: AlliedMods.net
Old 11-30-2020 , 06:38   Re: I need help in (player_disconnect)
Reply With Quote #4

Try to use EventHookMode_Pre:
Code:
HookEvent( "player_disconnect", Event_Disconnect, EventHookMode_Pre );

public Action Event_Disconnect(Event event, const char[] name, bool dontBroadcast)
{
    if(event.GetBool("bot")) return Plugin_Continue;

    static char path[PLATFORM_MAX_PATH], reason[PLATFORM_MAX_PATH], nick[PLATFORM_MAX_PATH], netid[PLATFORM_MAX_PATH];

    if(!path[0]) BuildPath(Path_SM, path, sizeof(path), "logs/hm_disconnect.log");

    event.GetString("name", nick, sizeof(nick));
    event.GetString("networkid", netid, sizeof(netid));
    event.GetString("reason", reason, sizeof(reason));
    LogToFileEx(path, "'%s' (%s) disconnected (reason: '%s')", nick, netid, reason);
    return Plugin_Continue;
}
if this wouldn't help then probably your mod doesn't support "reason" key for this event.
__________________

Last edited by MAGNAT2645; 11-30-2020 at 06:39.
MAGNAT2645 is offline
dr_lex
Member
Join Date: Dec 2014
Old 11-30-2020 , 06:59   Re: I need help in (player_disconnect)
Reply With Quote #5

Quote:
Originally Posted by MAGNAT2645 View Post
Try to use EventHookMode_Pre:
Code:
HookEvent( "player_disconnect", Event_Disconnect, EventHookMode_Pre );

public Action Event_Disconnect(Event event, const char[] name, bool dontBroadcast)
{
    if(event.GetBool("bot")) return Plugin_Continue;

    static char path[PLATFORM_MAX_PATH], reason[PLATFORM_MAX_PATH], nick[PLATFORM_MAX_PATH], netid[PLATFORM_MAX_PATH];

    if(!path[0]) BuildPath(Path_SM, path, sizeof(path), "logs/hm_disconnect.log");

    event.GetString("name", nick, sizeof(nick));
    event.GetString("networkid", netid, sizeof(netid));
    event.GetString("reason", reason, sizeof(reason));
    LogToFileEx(path, "'%s' (%s) disconnected (reason: '%s')", nick, netid, reason);
    return Plugin_Continue;
}
if this wouldn't help then probably your mod doesn't support "reason" key for this event.
nothing has changed
__________________
dr_lex is offline
MAGNAT2645
Senior Member
Join Date: Nov 2015
Location: AlliedMods.net
Old 12-01-2020 , 09:25   Re: I need help in (player_disconnect)
Reply With Quote #6

Add default value for reason:
Code:
event.GetString("reason", reason, sizeof(reason), "_NOREASON_");
If you will see "_NOREASON_" as reason in logs then probably your game doesn't support this key for player_disconnect event.
__________________
MAGNAT2645 is offline
dr_lex
Member
Join Date: Dec 2014
Old 12-02-2020 , 08:48   Re: I need help in (player_disconnect)
Reply With Quote #7

Quote:
Originally Posted by MAGNAT2645 View Post
Add default value for reason:
Code:
event.GetString("reason", reason, sizeof(reason), "_NOREASON_");
If you will see "_NOREASON_" as reason in logs then probably your game doesn't support this key for player_disconnect event.
It also doesn't show anything. Rather, I agree that the game does not support this feature.
__________________
dr_lex is offline
Balimbanana
Member
Join Date: Jan 2017
Old 12-02-2020 , 12:09   Re: I need help in (player_disconnect)
Reply With Quote #8

You could always try running on the server
Code:
developer 4
and join, then disconnect, it will show each of the events running and the I/O. You will want to change it back to 0 right after as it is a bit spammy. You should be able to find relevant events with 4.

It looks like L4D2 also uses the event "player_team" for disconnects, but there is no reason attached:
PHP Code:
"player_team"                // player change his team
{
    
"userid"    "short"        // user ID on server
    
"team"        "byte"        // team id
    
"oldteam" "byte"        // old team id
    
"disconnect" "bool"    // team change because player disconnects
    
"name"    "string"
    "isbot"    "bool"

It is odd that player_disconnect doesn't show a reason, do you have any plugins that modify join/disconnect messages? I can test a few things on a vanilla SM server later on today and see if I get any info.
Balimbanana is offline
dr_lex
Member
Join Date: Dec 2014
Old 12-02-2020 , 14:10   Re: I need help in (player_disconnect)
Reply With Quote #9

Quote:
Originally Posted by Balimbanana View Post
You could always try running on the server
Code:
developer 4
and join, then disconnect, it will show each of the events running and the I/O. You will want to change it back to 0 right after as it is a bit spammy. You should be able to find relevant events with 4.

It looks like L4D2 also uses the event "player_team" for disconnects, but there is no reason attached:
PHP Code:
"player_team"                // player change his team
{
    
"userid"    "short"        // user ID on server
    
"team"        "byte"        // team id
    
"oldteam" "byte"        // old team id
    
"disconnect" "bool"    // team change because player disconnects
    
"name"    "string"
    "isbot"    "bool"

It is odd that player_disconnect doesn't show a reason, do you have any plugins that modify join/disconnect messages? I can test a few things on a vanilla SM server later on today and see if I get any info.
Most likely, there is another plugin that hides the display of messages in the chat.

If it is not difficult to check (L4D2 game)
__________________
dr_lex is offline
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine on fire
Old 12-02-2020 , 14:24   Re: I need help in (player_disconnect)
Reply With Quote #10

I think we can do it by hooking CBaseClient:: PerformDisconnection, responsible for logging the message in console.log:

PHP Code:
CBaseClient *__cdecl CBaseClient::PerformDisconnection(CBaseClient *this, const char *a2)
{
...
ConMsg("Dropped %s from server (%s)\n"v5a2); 
But I don't know how to do it correctly. Maybe, somebody help?

My attempt:
Spoiler


PS. The topic is marked "Solved" when actually is not at all.
__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch & FreeZone)
[My plugins] [My tools] [GitHub] [Articles] [HiJackThis+] [Donate]

Last edited by Dragokas; 12-02-2020 at 14:26.
Dragokas is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 00:59.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode