Raised This Month: $51 Target: $400
 12% 

About Event Hook player_disconnect


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
chaithresh
Member
Join Date: Oct 2016
Location: Mangalore
Old 03-29-2018 , 03:29   About Event Hook player_disconnect
Reply With Quote #1

1) Is there is any difference between Player Getting dropped from server and Disconnecting from the server. If there is any, how can i hook both Player Disconnect and Player Dropped Events.

2) The event "player_disconnect" does it fire when a player gets dropped from the server.
chaithresh is offline
MasterMind420
BANNED
Join Date: Nov 2010
Old 03-29-2018 , 11:05   Re: About Event Hook player_disconnect
Reply With Quote #2

Quote:
Originally Posted by chaithresh View Post
1) Is there is any difference between Player Getting dropped from server and Disconnecting from the server. If there is any, how can i hook both Player Disconnect and Player Dropped Events.

2) The event "player_disconnect" does it fire when a player gets dropped from the server.
as far as i know player_disconnect event...onclientdisconnect(int client) forward and player_team event (checking the diconnect bool) will all fire no matter how a client disconnects...the only way i know of telling the actual difference as to how they disconnect is using player_disconnect event and printtochat the reason string....doing this u can see how a client disconnected, wether its no steam logon, timeout, kicked...etc.what exactly are u trying to do?

Last edited by MasterMind420; 03-29-2018 at 11:13.
MasterMind420 is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 03-29-2018 , 11:07   Re: About Event Hook player_disconnect
Reply With Quote #3

It should be noted that the OnClientDisconnect(int client) will fire every time the map changes also.
Mitchell is offline
MasterMind420
BANNED
Join Date: Nov 2010
Old 03-29-2018 , 11:09   Re: About Event Hook player_disconnect
Reply With Quote #4

Quote:
Originally Posted by Mitchell View Post
It should be noted that the OnClientDisconnect(int client) will fire every time the map changes also.
Very good point, i forgot thats why i never use it lol
MasterMind420 is offline
dustinandband
Senior Member
Join Date: May 2015
Old 03-29-2018 , 21:28   Re: About Event Hook player_disconnect
Reply With Quote #5

Quote:
Originally Posted by Mitchell View Post
It should be noted that the OnClientDisconnect(int client) will fire every time the map changes also.
Is there a better function for determining a proper disconnect (not triggered during a map change)?

I have a plugin that reboots a L4D2 server when all players disconnect but the map change thing was a real hassle to get around (we ended up using timers and boolean handles). The original plugin would shut down the server mid map-change.

Last edited by dustinandband; 03-29-2018 at 21:30.
dustinandband is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 03-29-2018 , 22:04   Re: About Event Hook player_disconnect
Reply With Quote #6

player_disconnect even doesn't fire on mapstart, im sure that's how it is in l4d also.
Mitchell is offline
dustinandband
Senior Member
Join Date: May 2015
Old 03-30-2018 , 02:16   Re: About Event Hook player_disconnect
Reply With Quote #7

Quote:
Originally Posted by Mitchell View Post
player_disconnect even doesn't fire on mapstart, im sure that's how it is in l4d also.
Ok I wrote a series of tests and discovered that's true (was testing for OnMapEnd).

Wrote a new plugin from scratch to try to reset the server when all players DC. After a series of tests I discovered that the event's getting spammed a bit (when I'm the only one on the server and I disconnected, the test showed myself and every bot disconnecting twice). Not only that but it's not functioning properly.

Plugins for L4D2. Any tips for optimizing this code?

PHP Code:
#include <sourcemod>
#define RESTART_TIMER 6.0

public Plugin myinfo =
{
    
name "server restarter",
    
author "dustin",
    
description "restarts server when all players disconnect",
    
version "1.0.0",
    
url ""
};

public 
OnPluginStart()
{
    
HookEvent("player_disconnect"PlayerDisconnect_Event);
}


public 
Action:PlayerDisconnect_Event(Handle:event, const String:name[], bool:dontBroadcast
{
    
decl String:networkID[22];
    
GetEventString(event"networkid"networkIDsizeof(networkID));
    if (
StrContains(networkID"BOT"false) != -1) return;
    
    if (
GetHumanCount() == 0)
    {
        
CreateTimer(RESTART_TIMERRestart_Server);
    }
}

public 
Action:Restart_Server(Handle timerany data)
{
    
// check human count one more time
    
if (GetHumanCount() == 0ServerCommand("_restart");
}


int GetHumanCount()
{
    
int count;
    for (
int i 1<= MaxClientsi++)
    {
        if (
IsClientInGame(i) && !IsFakeClient(i))
        {
            
count++;
        }
    }
    
    return 
count;

dustinandband is offline
chaithresh
Member
Join Date: Oct 2016
Location: Mangalore
Old 03-30-2018 , 03:42   Re: About Event Hook player_disconnect
Reply With Quote #8

Quote:
Originally Posted by MasterMind420 View Post
as far as i know player_disconnect event...onclientdisconnect(int client) forward and player_team event (checking the diconnect bool) will all fire no matter how a client disconnects...the only way i know of telling the actual difference as to how they disconnect is using player_disconnect event and printtochat the reason string....doing this u can see how a client disconnected, wether its no steam logon, timeout, kicked...etc.what exactly are u trying to do?
Yeah you are right... OnClientdisconnect fires even when the player gets timeout or dropped.


I did a test by running a local server and tried connecting with another pc and disconnecting players lan cable.

Ran this small plugin to print to server whenever a player disconnects.

PHP Code:
public OnPluginStart(){

HookEvent("player_disconnect"Event_PlayerDisconnectEventHookMode_Pre);
}


public 
Action  Event_PlayerDisconnect(Handle event, const char[] namebool dontBroadcast){

PrintToServer("A Player Has Disconnected.");

1st Test: When a Player Gets Normally disconnects it fires the event normally and prints the player has disconnected.

2nd Test: When i disconnect players Lan Cable its kinda random, some time it fires the event right away and some time it fires the event after like 20 to 30 seconds.

It may be kinda hard if you are trying write plugin which punishes the player on disconnect.

P.S. Sorry for my englando

Last edited by chaithresh; 03-30-2018 at 03:55. Reason: forgot to add php tag....
chaithresh is offline
MasterMind420
BANNED
Join Date: Nov 2010
Old 03-30-2018 , 09:15   Re: About Event Hook player_disconnect
Reply With Quote #9

Quote:
Originally Posted by chaithresh View Post
Yeah you are right... OnClientdisconnect fires even when the player gets timeout or dropped.


I did a test by running a local server and tried connecting with another pc and disconnecting players lan cable.

Ran this small plugin to print to server whenever a player disconnects.

PHP Code:
public OnPluginStart(){

HookEvent("player_disconnect"Event_PlayerDisconnectEventHookMode_Pre);
}


public 
Action  Event_PlayerDisconnect(Handle event, const char[] namebool dontBroadcast){

PrintToServer("A Player Has Disconnected.");

1st Test: When a Player Gets Normally disconnects it fires the event normally and prints the player has disconnected.

2nd Test: When i disconnect players Lan Cable its kinda random, some time it fires the event right away and some time it fires the event after like 20 to 30 seconds.

It may be kinda hard if you are trying write plugin which punishes the player on disconnect.

P.S. Sorry for my englando
Unplugging the lan cable will cause the disconnect reason to be a timeout, which would be based on what the server or client has set for there timeout setting...i'm not sure which would control this, look for server convar that could speed it up a bit(I know theres on that controls this for a client, server i'm not sure about). Im not sure what consequences may arise from decreasing the timeout on the server/client either, may have unintended side effects, like kicking everyone if theres a slight delay in the servers network maybe, i dunno...If the timeout convar is client only then theres not much u can do that i know of...
MasterMind420 is offline
cravenge
Veteran Member
Join Date: Nov 2015
Location: Chocolate Factory
Old 03-30-2018 , 09:37   Re: About Event Hook player_disconnect
Reply With Quote #10

Quote:
Originally Posted by dustinandband View Post
[...]
You haven't set a default value for the variable.
Code:
int count = 0;

Last edited by cravenge; 03-30-2018 at 09:39.
cravenge is offline
Reply



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 21:35.


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