SHOW:
|
|
- or go back to the newest paste.
| 1 | <?php | |
| 2 | /******************************** | |
| 3 | ||
| 4 | Author: Tymoteusz `Razor Meister` Bartnik | |
| 5 | ||
| 6 | Contact: [email protected] | |
| 7 | ||
| 8 | Function: client_to_db() | |
| 9 | ||
| 10 | ********************************/ | |
| 11 | ||
| 12 | class client_to_db | |
| 13 | {
| |
| 14 | private static $name; | |
| 15 | private static $cfg; | |
| 16 | ||
| 17 | static public function construct($event_name) | |
| 18 | {
| |
| 19 | global $cfg; | |
| 20 | self::$cfg = $cfg[$event_name]; | |
| 21 | self::$name = $event_name; | |
| 22 | } | |
| 23 | ||
| 24 | static public function check_in_database($client) | |
| 25 | {
| |
| 26 | global $query, $query_sql, $event_info; | |
| 27 | ||
| 28 | $client_info = $query->getElement('data', $query->clientInfo($client['clid']));
| |
| 29 | ||
| 30 | $cldbid = $client['client_database_id']; | |
| 31 | $connections = $client_info['client_totalconnections']; | |
| 32 | $clid = $client['clid']; | |
| 33 | $nick = htmlentities($client['client_nickname'], ENT_QUOTES, "UTF-8"); | |
| 34 | $uid = $client['client_unique_identifier']; | |
| 35 | $server_groups = $client['client_servergroups']; | |
| 36 | $connected_time = $client_info['connection_connected_time']; | |
| 37 | $idle_time = $client_info['client_idle_time']; | |
| 38 | ||
| 39 | $result = $query_sql->query("SELECT `client_dbid` FROM `clients` WHERE `client_dbid` = '$cldbid'");
| |
| 40 | ||
| 41 | if(($result->num_rows) == 0) | |
| 42 | {
| |
| 43 | $query_sql->query("INSERT INTO `clients`
| |
| 44 | (`client_dbid`, `client_clid`, `client_nick`, `client_uid`, `server_groups`, `connections`, `connected_time`, `connected_time_record`, `idle_time_record`, `time_spent`, `idle_time_spent`, `week_start`, `week_start_time`, `last_nicks`) VALUES | |
| 45 | ('$cldbid', '$clid', '$nick', '$uid', '$server_groups', '$connections','$connected_time', '$idle_time', '$connected_time', '$connected_time', '$idle_time', '".date('W')."', 0, '')");
| |
| 46 | } | |
| 47 | else | |
| 48 | {
| |
| 49 | $result = $query_sql->query("SELECT * FROM `clients` WHERE `client_dbid`='$cldbid'")->fetch_assoc();
| |
| 50 | ||
| 51 | if($result['connected_time_record'] < $connected_time) | |
| 52 | $query_sql->query("UPDATE `clients` SET `connected_time_record`='$connected_time' WHERE `client_dbid`='$cldbid'");
| |
| 53 | ||
| 54 | if($result['idle_time_record'] < $idle_time) | |
| 55 | $query_sql->query("UPDATE `clients` SET `idle_time_record`='$idle_time' WHERE `client_dbid`='$cldbid'");
| |
| 56 | ||
| 57 | if($idle_time >= 1000 * self::$cfg['idle_time']) | |
| 58 | {
| |
| 59 | $idle_time_spent = $result['idle_time_spent'] + $event_info['interval'][self::$name]*1000; | |
| 60 | $query_sql->query("UPDATE `clients` SET `idle_time_spent`='$idle_time_spent' WHERE `client_dbid`='$cldbid'");
| |
| 61 | } | |
| 62 | ||
| 63 | if($result['week_start'] != date('W'))
| |
| 64 | $query_sql->query("UPDATE `clients` SET `week_start`='".date('W')."',`week_start_time`='".$result['time_spent']."' WHERE `client_dbid`='$cldbid'");
| |
| 65 | ||
| 66 | if($result['client_nick'] != $nick) | |
| 67 | {
| |
| 68 | if($result['last_nicks'] != "") | |
| 69 | {
| |
| 70 | $nick_change = json_decode($result['last_nicks'], true); | |
| 71 | - | if(count($nick_change) > 30) |
| 71 | + | $nick_change_backup = array(); |
| 72 | - | {
|
| 72 | + | |
| 73 | - | $nick_change_backup = array(); |
| 73 | + | foreach($nick_change as $time => $value) |
| 74 | $nick_change_backup[] = array('time' => $time, 'value' => $value);
| |
| 75 | - | foreach($nick_change as $time => $value) |
| 75 | + | |
| 76 | - | $nick_change_backup[] = array('time' => $time, 'value' => $value);
|
| 76 | + | |
| 77 | ||
| 78 | - | $nick_change = array(); |
| 78 | + | for($i = 0; $i < 10; $i++) |
| 79 | $nick_change[$nick_change_backup[count($nick_change_backup)-10+$i]['time']] = $nick_change_backup[count($nick_change_backup)-10+$i]['value']; | |
| 80 | - | for($i = 0; $i < 10; $i++) |
| 80 | + | |
| 81 | - | $nick_change[$nick_change_backup[count($nick_change_backup)-10+$i]['time']] = $nick_change_backup[count($nick_change_backup)-10+$i]['value']; |
| 81 | + | |
| 82 | - | } |
| 82 | + | |
| 83 | $nick_change = array(); | |
| 84 | ||
| 85 | $nick_change[time()] = $result['client_nick']; | |
| 86 | $query_sql->query("UPDATE `clients` SET `last_nicks`='".json_encode($nick_change)."' WHERE `client_dbid`='$cldbid'");
| |
| 87 | } | |
| 88 | ||
| 89 | $time_spent = $result['time_spent'] + $event_info['interval'][self::$name]*1000; | |
| 90 | $query_sql->query("UPDATE `clients` SET `client_clid`='$clid', `client_nick`='$nick', `server_groups`='$server_groups', `connections`='$connections', `connected_time`='$connected_time',`time_spent`='$time_spent' WHERE `client_dbid`='$cldbid'");
| |
| 91 | } | |
| 92 | } | |
| 93 | } | |
| 94 | ?> |