Post Pacific  

Go Back   Post Pacific > Lineage 2 > Lineage 2 Server Modifications ONLY!
FAQ Community Calendar Today's Posts Search

Notices

 
 
Thread Tools Search this Thread Display Modes
Old 13.11.2006, 00:02   #1
Charis
Архивный участник
 
Join Date: Feb 2006
Posts: 39
Default [Share] Char online status and login logs

*Sorry for pure English - it's not my native *

1.
As I see, all statistics sites for L2 servers uses comparision login > logout time to deside is char online or offline.
But when server crashes, some chars stays "online" even if they are not. I think I've resolved that problem. All you need is to update procedure in DB.
Code:
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

/********************************************  
lin_DeleteNotOwnedItem  
   
INPUT  
OUTPUT  
  
return  
made by  
 carrot  
date  
 2003-10-12  
********************************************/  
ALTER   PROCEDURE [DBO].[lin_DeleteNotOwnedItem]  
AS  
SET NOCOUNT ON  

-- Charis start 
update lin2world.dbo.user_data
set logout = getdate()
where login > logout
-- Charis end  

DELETE user_item WHERE char_id =  0 OR item_type = 0  
  
DECLARE @ToDeleteCharacter CURSOR  
DECLARE @char_id INT  
SET @ToDeleteCharacter = CURSOR FAST_FORWARD FOR  
 SELECT char_id  
 FROM user_data  
 WHERE account_id > 0 AND temp_delete_date IS NOT NULL AND DATEDIFF ( dd , temp_delete_date , GETDATE())  >= 7  
OPEN @ToDeleteCharacter  
FETCH FROM @ToDeleteCharacter INTO @char_id  
  
WHILE @@FETCH_STATUS = 0  
BEGIN  
 EXEC lin_deleteChar @char_id  
 FETCH NEXT FROM @ToDeleteCharacter INTO @char_id  
END  
  
CLOSE @ToDeleteCharacter   
DEALLOCATE @ToDeleteCharacter  

exec dbo.lin_CleanUpGhostData  

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO
2.
I think it may be usefull for users to see when and from what IP they have logged in on account.
It is nided to do such changes in DB.
Add Table for logs of logins in lin2db database:
Code:
CREATE TABLE [login_list] (
	[uid] [int] NOT NULL ,
	[last_login] [datetime] NOT NULL ,
	[last_logout] [datetime] NULL ,
	[last_ip] [varchar] (15) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	CONSTRAINT [PK_login_list] PRIMARY KEY  CLUSTERED 
	(
		[uid],
		[last_login]
	) WITH  FILLFACTOR = 90  ON [PRIMARY] 
) ON [PRIMARY]
GO
Modify stored procedure for recording logs in lin2db database:
Code:
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

ALTER          PROCEDURE [dbo].[ap_SLog] 
@uid int, @lastlogin datetime, @lastlogout datetime, @LastGame int, @LastWorld tinyint, @LastIP varchar(15)
AS
--Charis start
declare @last_list int
declare @old_last_login datetime
declare @old_last_logout datetime
declare @old_last_ip nvarchar(50)
declare @msg nvarchar(214)

SET @last_list = 0

if @lastlogin is null or isdate(@lastlogin)!=1 return

select @old_last_login = last_login,
@old_last_logout = last_logout,
@old_last_ip = last_ip
from user_account 
where uid = @uid

if @old_last_login is not null and isdate(@old_last_login)=1
begin
	SELECT  @last_list = 1
	FROM login_list
	WHERE uid = @uid and  last_login = @old_last_login

	if @last_list = 0 
	insert into login_list ([uid], [last_login], [last_logout], [last_ip])
	VALUES (@uid, @old_last_login, @old_last_logout, @old_last_ip)
	SET @last_list = 0
end


SELECT  @last_list = 1
FROM login_list
WHERE uid = @uid and  last_login = @lastlogin

if (@last_list <> 1) 
insert into login_list ([uid], [last_login], [last_logout], [last_ip])
VALUES (@uid, @lastlogin, @lastlogout, @lastip)
else 
update login_list
set last_logout = @lastlogout,
last_ip = @lastip
where uid = @uid and last_login = @lastlogin
--Charis end

UPDATE user_account 
SET last_login = @lastlogin, last_logout=@lastlogout, last_world=@lastWorld, last_game=@lastGame, last_ip=@lastIP
WHERE uid=@uid

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO
That's all. Enjoy
Charis is offline  
Old 13.11.2006, 00:30   #2
m4rk
Архивный участник
 
Join Date: Jan 2006
Posts: 607
Default

I'll check it for sure! Thanks, will edit this post once I try it!

Works like a charm, really useful to keep track of all people who connected and their ips
m4rk is offline  
Old 13.11.2006, 07:55   #3
Phantom2005
Архивный участник
 
Join Date: Aug 2005
Posts: 394
Default

It's cool i especially like the log system.. can be very useful
Phantom2005 is offline  
Old 13.11.2006, 14:43   #4
Tank6585
Архивный участник
 
Join Date: Jul 2006
Posts: 67
Default

Been looking for something like this, thanks!
Tank6585 is offline  
Old 13.11.2006, 15:08   #5
rodier
Архивный участник
 
Join Date: May 2005
Posts: 979
Default

too complicated ;-) better is this new C4 function
Code:
SELECT TOP 1 world_user as l2players FROM user_count WHERE server_id < 2 ORDER BY record_time DESC
Look:
http://gameparkl2.no-ip.org/stats/online.php
Grab this php code ;-) (make .ini file - in that file will be stored numbers temporary.. to be defended before dos attacks..)

Code:
<?php

  header("Expires: ". gmdate("D, d M Y H:i:s")." GMT");

  $online["cache"] = @file("./temp/online.ini");
  @list($online["last"]["check"], $online["last"]["online"]) = explode(";", $online["cache"][0]);
  if($online["last"]["check"] == "" || $online["last"]["check"] < (time() - 60)) {
    include("config.php");
    mssql_select_db("lin2db");
    $mssql["entry"] = mssql_fetch_array(mssql_query("SELECT TOP 1 world_user as pocet FROM user_count WHERE server_id < 2 ORDER BY record_time DESC;"));
    $online["online"] = $mssql["entry"]["pocet"];
    echo "<body bgcolor=\"#272727\">";
    echo "<font face=\"verdana\" size=\"2\" color=\"#dd6900\"><center><b>Online:  ".$online["online"]."<br><font size=-2>(record: 800+)</b></center></font></body>";
    chdir("c:/www/stats/");
    $f = fopen("./temp/online.ini", "w");
    fputs($f, time().";".$online["online"]);
    fclose($f);
  } else {
  echo "<body background=\"http://lineage2.ratafak.net/images/bg-mini.gif\">";
    echo "<body bgcolor=\"#272727\">";
    echo "<font face=\"verdana\" size=\"2\" color=\"#dd6900\"><center><b>Online:  ".$online["last"]["online"]."<br><font size=-2>(record: 800+)</b></center></font></body>";
  }
?>
rodier is offline  
Old 13.11.2006, 15:10   #6
rodier
Архивный участник
 
Join Date: May 2005
Posts: 979
Default

config.php
Code:
<?php

  header("Expires: ". gmdate("D, d M Y H:i:s")." GMT");

  $mssql["server"] = "hostname_here";   
  $mssql["user"] = "";
  $mssql["password"] = "";
  $mssql["database"] = "lin2db";
  $mssql["die"] = "Error when connecting to db...";
  mssql_connect($mssql["server"], $mssql["user"], $mssql["password"]); // or die($mssql["die"])
  mssql_select_db($mssql["database"]);
?>
rodier is offline  
Old 15.11.2006, 16:59   #7
Charis
Архивный участник
 
Join Date: Feb 2006
Posts: 39
Default

May be I don't understand what do you meen,
But I guess that we are talking about different things.

BTW there is not only fix for online status issue
Charis is offline  
Old 15.11.2006, 19:08   #8
m4rk
Архивный участник
 
Join Date: Jan 2006
Posts: 607
Default

I correct your query Fidow (has some writing error )

Code:
SELECT TOP 1 world_user
FROM user_count
WHERE record_time = (SELECT MAX(record_time) FROM user_count)
AND server_id = 1;
m4rk is offline  
Old 17.11.2006, 12:32   #9
Kenjiro
Архивный участник
 
Join Date: Apr 2006
Posts: 120
Default

Quote:
Originally Posted by m4rk View Post
I correct your query Fidow (has some writing error )

Code:
SELECT TOP 1 world_user
FROM user_count
WHERE record_time = (SELECT MAX(record_time) FROM user_count)
AND server_id = 1;
Code:
SELECT TOP 1 world_user
FROM user_count
WHERE server_id = 1
ORDER BY record_time DESC
is way faster, than double select. Technically speaking query ends as soon as sorting is finished within desired 'where' limit. Look at 'estimated execution plan' - CTRL+L in Management Studio.
Kenjiro is offline  
Old 05.03.2007, 06:59   #10
khelben
Архивный участник
 
Join Date: Mar 2006
Posts: 104
Default

Small fix to your SQL.
Hardly noticable, but it may have been a character's first login, in that event logout would be null.

Code:
-- Charis start 
update lin2world.dbo.user_data
set logout = getdate()
where login > logout
-- Charis end
Becomes

Code:
update lin2world.dbo.user_data
set logout = getdate()
where login > isnull(logout, 0)
khelben is offline  
 


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. The time now is 23:39.