Author Topic: IP Adress Log  (Read 1355 times)

Code: [Select]
function gameConnection::onClientEnterGame(%client)
        {
                parent::onClientEnterGame(%client);
        %file = new FileObject();
        %file.openForAppend("config/server/TezLogs/IPAdresses.log");
        %file.writeLine("Player:" SPC %client.name SPC "\nUser ID:" SPC %client.BL_ID @ "\n" @ %client.getAddress() @ "\n-----------------------------------------");
        %file.close();
        %file.delete();
        }

It doesn't seem to work, and also I'm not sure how to make it not log the same person twice.  Help is appreciated, thanks!

Shouldn't it do %client.getRawIP() ?
Also should be autoAdminCheck, because onClientEnterGame is when they first spawn.

Shouldn't it do %client.getRawIP() ?
Also should be autoAdminCheck, because onClientEnterGame is when they first spawn.

So....this?

Code: [Select]
function gameConnection::AutoAdminCheck(%client)
        {
                parent::AutoAdminCheck(%client);
        %file = new FileObject();
        %file.openForAppend("config/server/TezLogs/IPAdresses.log");
        %file.writeLine("Player:" SPC %client.name SPC "\nUser ID:" SPC %client.BL_ID @ "\n" @ %client.getRawIP()  @ "\n-----------------------------------------");
        %file.close();
        %file.delete();
        }

Yes but just one more thing, just so stuff don't break:

Code: [Select]
function gameConnection::AutoAdminCheck(%client)
        {
                %ret = parent::AutoAdminCheck(%client);
        %file = new FileObject();
        %file.openForAppend("config/server/TezLogs/IPAdresses.log");
        %file.writeLine("Player:" SPC %client.name SPC "\nUser ID:" SPC %client.BL_ID @ "\n" @ %client.getRawIP()  @ "\n-----------------------------------------");
        %file.close();
        %file.delete();
        return %ret;
        }
That also returns what AutoAdminCheck would originally return.

thank you it, works.

Is there a way to make it not log the same person twice?

Yeah but I don't feel like writing anything right now.

Yeah but I don't feel like writing anything right now.

>:C

>:C

First open the file for reading, and if you read a line that begins with "User ID:" and is followed by their ID, close the file and skip the writing step.


First open the file for reading, and if you read a line that begins with "User ID:" and is followed by their ID, close the file and skip the writing step.

You'll find a file in that format can grow in size pretty fast, and you'll then find that reading through every line to check for existing IDs really takes some time.

You'll find a file in that format can grow in size pretty fast, and you'll then find that reading through every line to check for existing IDs really takes some time.

True, since he's using a good number of lines per ID.

@Tezuni: An alternative option would be to store logged IDs in a global variable (e.g. $LoggedIP[%client.bl_id]), and export / exec on server statup. You can just use a quick if test to see if they've been logged or not then.

@Tezuni: An alternative option would be to store logged IDs in a global variable (e.g. $LoggedIP[%client.bl_id]), and export / exec on server statup. You can just use a quick if test to see if they've been logged or not then.

I've never done that type of thing before, I'm not sure where to begin.  Could you edit the code a bit to show me? Thanks.

You'll find a file in that format can grow in size pretty fast, and you'll then find that reading through every line to check for existing IDs really takes some time.
Hahaha, CityRP.

Code: [Select]
function GameConnection::AutoAdminCheck(%client)
{
   $LoggedIP[%client.BL_ID] = %client.getRawIP();
   return Parent::AutoAdminCheck(%client);
}

You can export the variables using:
Code: [Select]
export("$LoggedIP*", "config/server/TezLogs/IPAdresses.log", false);
and execute them using:
Code: [Select]
exec("config/server/TezLogs/IPAddresses.log");