userlist.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?PHP
  2. include_once("Source/cachefix.php");
  3. include_once("Source/sql.php");
  4. function UpdateUser($nick,$channel)
  5. {
  6. if($channel[0]=="*")
  7. return; //PMs have no userlist.
  8. $result = sql_query("SELECT * FROM `irc_users` WHERE `username` = '%s' AND `channel` = '%s' AND `online` = 1",$nick,$channel);
  9. if (mysql_num_rows($result))//Update
  10. {
  11. sql_query("UPDATE `irc_users` SET `time`='%s' WHERE `username` = '%s' AND `channel` = '%s' AND `online` = 1",time(),$nick,$channel);
  12. $row = mysql_fetch_array($result);
  13. if ($row['time'] < strtotime('-1 minute')) //First time they joined in a minute.
  14. notifyJoin($nick,$channel);
  15. }
  16. else //Insert
  17. {
  18. sql_query("INSERT INTO `irc_users` (`username`,`channel`,`time`,`online`) VALUES('%s','%s','%s',1)",$nick,$channel,time());
  19. notifyJoin($nick,$channel);
  20. }
  21. }
  22. function getOnlineUsers($channel)
  23. {
  24. $userlist = Array();
  25. if ($channel[0]=="*")
  26. return $userlist; //PMs have no userlist.
  27. $result = sql_query("SELECT * FROM `irc_users` WHERE `channel` = '%s' AND `time` > %s AND `online` = 1",$channel,strtotime('-1 minute')); //Get all users in the last minute(update.php timeout is 30 seconds).
  28. while($row = mysql_fetch_array($result))
  29. $userlist[] = $row['username'];
  30. return $userlist;
  31. }
  32. function notifyJoin($nick,$channel)
  33. {
  34. sql_query("INSERT INTO `irc_lines` (name1,type,channel,time,online) VALUES('%s','join','%s','%s',1)",$nick,$channel,time());
  35. }
  36. function notifyPart($nick,$channel)
  37. {
  38. sql_query("INSERT INTO `irc_lines` (name1,type,channel,time,online) VALUES('%s','part','%s','%s',1)",$nick,$channel,time());
  39. }
  40. function CleanOfflineUsers()
  41. {
  42. $result = sql_query("SELECT * FROM `irc_users` WHERE `time` < %s",strtotime('-1 minute'));
  43. sql_query("DELETE FROM `irc_users` WHERE `time` < %s",strtotime('-1 minute'));
  44. while ($row = mysql_fetch_array($result))
  45. notifyPart($row['username'],$row['channel']);
  46. }
  47. ?>