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

Detecting player connections


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
thatguyyoulove
Member
Join Date: Nov 2010
Location: North Texas
Old 02-05-2012 , 20:30   Detecting player connections
Reply With Quote #1

Quick question on detecting player connections. Can I detect if a player connects to the server, starts downloading files, and then disconnects(hits Cancel) before he even finishes downloading the files.

I want to write a Google Analytics-esque plugin for Source which will let you figure out your server bounce rate (what I am describing above), daily/hourly/monthly/yearly traffic, average connection time, etc. and show them on your website or admin panel. Detecting bounced players (players who quit connecting before they ever actually get into the server) is one of the most metrics as it will help server owners figure out if their copious downloads (custom sounds, skins, etc.) are having an impact on new traffic.
thatguyyoulove is offline
necavi
Veteran Member
Join Date: Sep 2010
Old 02-05-2012 , 21:20   Re: Detecting player connections
Reply With Quote #2

Easiest way would likely be to do OnClientConnected saving a value to a variable, then clearing it OnClientAuthorized (which I believe is fired after they finish downloading, but I could be wrong about that one) and checking the value OnClientDisconnected, if it has one then log it to a database as a bounce. Please excuse the rambling enclosed, I hope it helps you in some way.
necavi is offline
Dr. McKay
Sir Dr. SourceMod Plugin Approver Esq. Ltd. M.D. PhD
Join Date: Aug 2011
Location: Atlantis
Old 02-05-2012 , 22:04   Re: Detecting player connections
Reply With Quote #3

PHP Code:
#pragma semicolon 1

#include <sourcemod>

new bool:connecting[MAXPLAYERS 1] = {false, ...};

public 
OnClientConnected(client) {
    
connecting[client] = true;
}

public 
OnClientInGame(client) {
    
connecting[client] = false;
}

public 
OnClientDisconnect(client) {
    if(
connecting[client]) {
        
// this is a bounced connection, log it!
    
}
    
connecting[client] = false;

__________________

Last edited by Dr. McKay; 02-05-2012 at 22:06.
Dr. McKay is offline
thatguyyoulove
Member
Join Date: Nov 2010
Location: North Texas
Old 02-06-2012 , 00:21   Re: Detecting player connections
Reply With Quote #4

Thank you very much sir! I had overlooked the OnClientInGame function so I wasn't quite sure what stage of joining a server the OnClientConnected was called at. I appreciate the code as well, although I'm not sure what the ellipsis are about. Surely I wouldn't have to hard-code in all of the "false"s right? I thought that new booleans were false by default. I guess if I have to manually set them all to false I would think a for loop would be sufficient.

Last edited by thatguyyoulove; 02-06-2012 at 00:21.
thatguyyoulove is offline
Dr. McKay
Sir Dr. SourceMod Plugin Approver Esq. Ltd. M.D. PhD
Join Date: Aug 2011
Location: Atlantis
Old 02-06-2012 , 01:16   Re: Detecting player connections
Reply With Quote #5

Quote:
Originally Posted by thatguyyoulove View Post
Thank you very much sir! I had overlooked the OnClientInGame function so I wasn't quite sure what stage of joining a server the OnClientConnected was called at. I appreciate the code as well, although I'm not sure what the ellipsis are about. Surely I wouldn't have to hard-code in all of the "false"s right? I thought that new booleans were false by default. I guess if I have to manually set them all to false I would think a for loop would be sufficient.
The ellipsis tells the compiler to initialize all of the values as false. Yes, I'm pretty sure they do initialize as false anyway, but it can't hurt to specify. Likewise, new bool:connecting[MAXPLAYERS + 1] = {true, ...}; would initialize all values as true. You don't need to mess with that line at all.
__________________

Last edited by Dr. McKay; 02-06-2012 at 01:17.
Dr. McKay is offline
Impact123
Veteran Member
Join Date: Oct 2011
Location: Germany
Old 02-06-2012 , 01:46   Re: Detecting player connections
Reply With Quote #6

I've never heard about
PHP Code:
OnClientInGame 
Are you sure that works?

Yours sincerely
Impact
__________________
Impact123 is offline
thatguyyoulove
Member
Join Date: Nov 2010
Location: North Texas
Old 02-06-2012 , 01:58   Re: Detecting player connections
Reply With Quote #7

Oh wow I have never heard of the ellipsis doing that. Very cool!

Impact I didn't see it in the function list and a Google search didn't reveal much. Maybe he meant OnClientPutInServer? I will test it tomorrow either way so I will find out.
thatguyyoulove is offline
DarthNinja
SourceMod Plugin Approver
Join Date: Mar 2009
Location: PreThinkHook()
Old 02-06-2012 , 02:21   Re: Detecting player connections
Reply With Quote #8

PHP Code:
new bool:connecting[MAXPLAYERS+1] = true
Is also totally valid.

Also McKay in your example you have OnClientConnected where what you should have is OnClientConnect.
__________________

Last edited by DarthNinja; 02-06-2012 at 02:24.
DarthNinja is offline
Despirator
Senior Member
Join Date: Jun 2011
Location: Kazakhstan ->Shymkent
Old 02-06-2012 , 02:51   Re: Detecting player connections
Reply With Quote #9

Quote:
Originally Posted by Dr. McKay View Post
PHP Code:
#pragma semicolon 1

#include <sourcemod>

new bool:connecting[MAXPLAYERS 1] = {false, ...};

public 
OnClientConnected(client) {
    
connecting[client] = true;
}

public 
OnClientPutInServer(client) {
    
connecting[client] = false;
}

public 
OnClientDisconnect_Post(client) {
    if(
connecting[client]) {
        
// this is a bounced connection, log it!
    
}
    
connecting[client] = false;

Despirator is offline
Dr. McKay
Sir Dr. SourceMod Plugin Approver Esq. Ltd. M.D. PhD
Join Date: Aug 2011
Location: Atlantis
Old 02-06-2012 , 07:36   Re: Detecting player connections
Reply With Quote #10

I meant OnClientPutInServer. I always get mixed up because of IsClientInGame.
Quote:
Originally Posted by DarthNinja View Post
PHP Code:
new bool:connecting[MAXPLAYERS+1] = true
Is also totally valid.

Also McKay in your example you have OnClientConnected where what you should have is OnClientConnect.
What's wrong with OnClientConnected?
__________________
Dr. McKay 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 10:48.


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