collapse collapse
* User Info
 
 
Welcome, Guest. Please login or register.
* Search

* Board Stats
  • stats Total Members: 989
  • stats Total Posts: 18363
  • stats Total Topics: 2500
  • stats Total Categories: 7
  • stats Total Boards: 35
  • stats Most Online: 1144

Author Topic: Log playtime from buddys ON/OFF messages [AoC] problem  (Read 3524 times)

0 Members and 1 Guest are viewing this topic.

Offline IKShadow

  • BeBot User
  • **
  • Posts: 35
  • Karma: +0/-0
Log playtime from buddys ON/OFF messages [AoC] problem
« on: November 16, 2008, 07:56:39 am »
I made a custom module that logs into database all log on/off messages so I can query members playtimes.
Code: [Select]
/*
This gets called if a buddy logs on/off  if you previously registered the event 'buddy'
*/
function buddy($name, $msg) .....

There is weird thing that I have multiple log on messages ( status=1 ) with missing log off ones ( status = 0 )

Example:
Quote
id nickname                         status  timestamp from_unixtime(timestamp)
1 Ikshadow                              1 1223476398 8.10.2008 16:33         
13 Ikshadow                              0 1223476414 8.10.2008 16:33         
36 Ikshadow                              1 1223479520 8.10.2008 17:25         
41 Ikshadow                              1 1.223479879 8.10.2008 17:31         
72 Ikshadow                              1 1223481387 8.10.2008 17:56         
85 Ikshadow                              1 1223481481 8.10.2008 17:58         
100 Ikshadow                              0 1223482833 8.10.2008 18:20         
107 Ikshadow                              1 1223484069 8.10.2008 18:41         
123 Ikshadow                              1 1223484170 8.10.2008 18:42         
138 Ikshadow                              1 1223484374 8.10.2008 18:46         
157 Ikshadow                              1 1223484928 8.10.2008 18:55         
183 Ikshadow                              1 1223485323 8.10.2008 19:02         
205 Ikshadow                              1 1223485472 8.10.2008 19:04         
228 Ikshadow                              1 1223485733 8.10.2008 19:08         
267 Ikshadow                              1 1223486327 8.10.2008 19:18         
381 Ikshadow                              1 1223489290 8.10.2008 20:08         
445 Ikshadow                              0 1223.490.463 8.10.2008 20:27         
531 Ikshadow                              1 1223493594 8.10.2008 21:19         
568 Ikshadow                              0 1223494924 8.10.2008 21:42 

I thought BOT do whois on each member in user list every xxx seconds and show notify message only when previous status is changed.
For some wierd reason I have all that data in database however I never notice in guild chat that BOT would spam twice:
[GROUP]   [MSG]   [~Guild] Echo: "Ikshadow" (Lvl 80Ranger)Logged On :: [link]Details[/link]
[GROUP]   [MSG]   [~Guild] Echo: "Ikshadow" (Lvl 80Ranger)Logged On :: [link]Details[/link]
etc..

Bot log file:
Quote
[2008-11-16 02:40:31]   [BUDDY]   [LOG]   Ikshadow changed status [1] (OWNER)
[2008-11-16 02:40:36]   [BUDDY]   [LOG]   Ikshadow changed status [6] (OWNER)
[2008-11-16 02:40:37]   [GROUP]   [MSG]   [~Guild] Echo: "Ikshadow" (Lvl 80Ranger)Logged On :: [link]Details[/link]  ::  Have no fear IKShadow is here :)
[2008-11-16 02:40:37]   [PGRP]   [MSG]   [Echo] Echo: "Ikshadow" (Lvl 80Ranger)Logged On :: [link]Details[/link]  ::  Have no fear IKShadow is here :)
[2008-11-16 02:40:46]   [TELL]   [OUT]   -> Ikshadow: News last updated November 15th, 2008 16:25:: [link]click to view[/link]

Now the problem is that I may get "member 1 logged in 7:00 am" and then "member 1 logged in 23:00 am" the member logged off is missing.

Anyone know what could be the problem ?

Offline Alreadythere

  • BeBot Maintainer
  • BeBot Hero
  • ******
  • Posts: 1288
  • Karma: +0/-0
Re: Log playtime from buddys ON/OFF messages [AoC] problem
« Reply #1 on: November 16, 2008, 08:19:08 pm »
I don't know which buddy events AoC creates when a player logs in. Depending on the way the events happen and are parsed into the table there may happen several events.

Best way would be to add debug-output to the buddy() function.

On a similar note you should make sure that you don't start parsing too soon after startup as the buddy events on bot startup are fairly extensive.

Offline Vhab

  • Contributor
  • *******
  • Posts: 180
  • Karma: +0/-0
    • VhaBot Forum
Re: Log playtime from buddys ON/OFF messages [AoC] problem
« Reply #2 on: November 20, 2008, 06:43:24 am »
It's normal for the buddy logon event to fire multiple times while a player is online.
This is due to changing values like which playfield they are in.

Offline IKShadow

  • BeBot User
  • **
  • Posts: 35
  • Karma: +0/-0
Re: Log playtime from buddys ON/OFF messages [AoC] problem
« Reply #3 on: November 20, 2008, 04:20:38 pm »
Yea but the problem is that sometimes it missed log off events aka status 0.

I dont mind multiple online but if off line are missing then its hard to calculate exact time .. now i just skip all status online that are not close with offline one ( and there is lots and lots of them ).

Any chance I could run something in crontab that would recheck all those with status online and give them status offline if they are disconnected.

Offline Temar

  • Contributor
  • *******
  • Posts: 1140
  • Karma: +0/-0
    • AoFiles
Re: Log playtime from buddys ON/OFF messages [AoC] problem
« Reply #4 on: November 20, 2008, 04:33:57 pm »
yes u can
u can check the status of any 1 on the buddy list at any time
with somit like
Code: [Select]
if($this -> bot -> core("chat") -> buddy_exists($name))
 $status = $this -> bot -> core("chat") -> buddy_online($name)

$status will be (bool) TRUE or FALSE
« Last Edit: November 20, 2008, 04:36:07 pm by Temar »

Offline IKShadow

  • BeBot User
  • **
  • Posts: 35
  • Karma: +0/-0
Re: Log playtime from buddys ON/OFF messages [AoC] problem
« Reply #5 on: November 25, 2008, 03:39:05 pm »
yes u can
u can check the status of any 1 on the buddy list at any time
with somit like
Code: [Select]
if($this -> bot -> core("chat") -> buddy_exists($name))
 $status = $this -> bot -> core("chat") -> buddy_online($name)

$status will be (bool) TRUE or FALSE

Thanks
Any chance you can tell me how to put that in cron tab.

I would modify my modul so every 5 minutes I would check for member status and update my log sql table.

p.s. It would be better if I could only re-check those that are marked online so BOT does not get to busy.

Offline Temar

  • Contributor
  • *******
  • Posts: 1140
  • Karma: +0/-0
    • AoFiles
Re: Log playtime from buddys ON/OFF messages [AoC] problem
« Reply #6 on: November 25, 2008, 04:51:00 pm »
1st you need this at top in __construct
$this -> register_event("cron", "5min");

then

Code: [Select]
function cron()
{
$online = $this -> bot -> db -> select("SELECT nickname FROM #___online WHERE status_gc = 1");
if(!empty($online))
{
foreach($online as $user)
{
if($this -> bot -> core("chat") -> buddy_exists($name))
{
if(!$this -> bot -> core("chat") -> buddy_online($name))
{
// do wateva to make user as offline
}
}
}
}
}
 
}

Offline IKShadow

  • BeBot User
  • **
  • Posts: 35
  • Karma: +0/-0
Re: Log playtime from buddys ON/OFF messages [AoC] problem
« Reply #7 on: November 25, 2008, 04:55:33 pm »
thanks for quick response.

Offline Vain

  • BeBot User
  • **
  • Posts: 57
  • Karma: +0/-0
Re: Log playtime from buddys ON/OFF messages [AoC] problem
« Reply #8 on: November 25, 2008, 06:12:12 pm »
I made a custom module that logs into database all log on/off messages so I can query members playtimes.
Code: [Select]
/*
This gets called if a buddy logs on/off  if you previously registered the event 'buddy'
*/
function buddy($name, $msg) .....

There is weird thing that I have multiple log on messages ( status=1 ) with missing log off ones ( status = 0 )

Example:
Quote
id nickname                         status  timestamp from_unixtime(timestamp)
1 Ikshadow                              1 1223476398 8.10.2008 16:33         
13 Ikshadow                              0 1223476414 8.10.2008 16:33         
36 Ikshadow                              1 1223479520 8.10.2008 17:25         
41 Ikshadow                              1 1.223479879 8.10.2008 17:31         
72 Ikshadow                              1 1223481387 8.10.2008 17:56         
85 Ikshadow                              1 1223481481 8.10.2008 17:58         
100 Ikshadow                              0 1223482833 8.10.2008 18:20         
107 Ikshadow                              1 1223484069 8.10.2008 18:41         
123 Ikshadow                              1 1223484170 8.10.2008 18:42         
138 Ikshadow                              1 1223484374 8.10.2008 18:46         
157 Ikshadow                              1 1223484928 8.10.2008 18:55         
183 Ikshadow                              1 1223485323 8.10.2008 19:02         
205 Ikshadow                              1 1223485472 8.10.2008 19:04         
228 Ikshadow                              1 1223485733 8.10.2008 19:08         
267 Ikshadow                              1 1223486327 8.10.2008 19:18         
381 Ikshadow                              1 1223489290 8.10.2008 20:08         
445 Ikshadow                              0 1223.490.463 8.10.2008 20:27         
531 Ikshadow                              1 1223493594 8.10.2008 21:19         
568 Ikshadow                              0 1223494924 8.10.2008 21:42 

I thought BOT do whois on each member in user list every xxx seconds and show notify message only when previous status is changed.
For some wierd reason I have all that data in database however I never notice in guild chat that BOT would spam twice:
[GROUP]   [MSG]   [~Guild] Echo: "Ikshadow" (Lvl 80Ranger)Logged On :: [link]Details[/link]
[GROUP]   [MSG]   [~Guild] Echo: "Ikshadow" (Lvl 80Ranger)Logged On :: [link]Details[/link]
etc..

Bot log file:
Quote
[2008-11-16 02:40:31]   [BUDDY]   [LOG]   Ikshadow changed status [1] (OWNER)
[2008-11-16 02:40:36]   [BUDDY]   [LOG]   Ikshadow changed status [6] (OWNER)
[2008-11-16 02:40:37]   [GROUP]   [MSG]   [~Guild] Echo: "Ikshadow" (Lvl 80Ranger)Logged On :: [link]Details[/link]  ::  Have no fear IKShadow is here :)
[2008-11-16 02:40:37]   [PGRP]   [MSG]   [Echo] Echo: "Ikshadow" (Lvl 80Ranger)Logged On :: [link]Details[/link]  ::  Have no fear IKShadow is here :)
[2008-11-16 02:40:46]   [TELL]   [OUT]   -> Ikshadow: News last updated November 15th, 2008 16:25:: [link]click to view[/link]

Now the problem is that I may get "member 1 logged in 7:00 am" and then "member 1 logged in 23:00 am" the member logged off is missing.

Anyone know what could be the problem ?

Sound interesting... mind sharing the code?

Offline IKShadow

  • BeBot User
  • **
  • Posts: 35
  • Karma: +0/-0
Re: Log playtime from buddys ON/OFF messages [AoC] problem
« Reply #9 on: December 02, 2008, 12:48:12 pm »
Nothing to share really .. its just store info in DB


So far I only do manual queries to check play times ( mostly to catch the spies )

Code: [Select]
<?php
$this_buddy_status_logger 
= new buddy_status_logger($bot);

class 
buddy_status_logger extends BaseActiveModule
{
function __construct (&$bot)
{
//Initialize the base module
parent::__construct(&$botget_class($this));

$this->register_event('buddy');

    
$this -> bot -> db -> query("CREATE TABLE IF NOT EXISTS " $this -> bot -> db -> define_tablename("buddy_status_log""true") . "
      (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, nickname VARCHAR(25), status TINYINT(1), timestamp INT)"
);

}

/*
Unified message handler
$source: The originating player
$msg: The actual message, including command prefix and all
$type: The channel the message arrived from. This can be either "tell", "pgmsg" or "gc"
*/
function command_handler($source$msg$origin)
{
//ALWAYS reset the error handler before parsing the commands to prevent stale errors from giving false reports
$this->error->reset();
}


/*
This gets called if a buddy logs on/off  if you previously registered the event 'buddy'
*/
function buddy($name$msg)
{
$sql "INSERT INTO hyborian_buddy_status_log (nickname, status, timestamp) ";
$sql .= "VALUES ('$name', '$msg', UNIX_TIMESTAMP(NOW()))";
$result $this -> bot -> db -> query($sql);

if ($result===false)
{
$this->error->set("An unknown error occurred inserting buddy status log.");
return ($this->error);
}
}
}
?>

 

* Recent Posts
[AoC] special char for items module by bitnykk
[February 09, 2024, 09:41:18 pm]


0.8.x updates for AoC by bitnykk
[January 30, 2024, 11:16:08 pm]


0.8.x updates for AO by bitnykk
[January 30, 2024, 11:15:37 pm]


BeBot still alive & kicking ! by bitnykk
[December 17, 2023, 12:58:44 am]


Bebot and Rasberry by bitnykk
[November 29, 2023, 11:04:14 pm]

* Who's Online
  • Dot Guests: 552
  • Dot Hidden: 0
  • Dot Users: 0

There aren't any users online.
* Forum Staff
bitnykk admin bitnykk
Administrator
Khalem admin Khalem
Administrator
WeZoN gmod WeZoN
Global Moderator
SimplePortal 2.3.7 © 2008-2024, SimplePortal