--- /dev/null
+<?php
+/********************************* PHP-P10 ******************************
+ * P10 uplink class by pk910 (c)2011 pk910 *
+ ************************************************************************
+ * Version 2 (OOP) *
+ * *
+ * PHP-P10 is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with PHP-P10; if not, write to the Free Software Foundation, *
+ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
+ * *
+ ************************************************************************
+ *
+ * Bots/Stats.class.php
+ *
+ * RRD Stats module...
+ *
+ */
+
+class {$_NAME} extends Bot {
+ private $uplink;
+ private $timer;
+
+ public function load($uplink, $old = false) {
+ $this->uplink = $uplink;
+ if(!file_exists("db/network.rrd")) {
+ $fname = "db/network.rrd";
+ $opts = array(
+ "--step", "300", "--start", "0",
+ "DS:users:GAUGE:600:0:U",
+ "DS:channels:GAUGE:600:0:U",
+ "DS:opers:GAUGE:600:0:U",
+ "DS:servers:GAUGE:600:0:U",
+ "RRA:AVERAGE:0.5:1:600",
+ "RRA:AVERAGE:0.5:6:700",
+ "RRA:AVERAGE:0.5:24:775",
+ "RRA:AVERAGE:0.5:288:797",
+ "RRA:MAX:0.5:1:600",
+ "RRA:MAX:0.5:6:700",
+ "RRA:MAX:0.5:24:775",
+ "RRA:MAX:0.5:288:797"
+ );
+ $ret = rrd_create($fname, $opts, count($opts));
+ if(!$ret) {
+ $err = rrd_error();
+ echo "Create error: $err\n";
+ die();
+ }
+ }
+ if(!file_exists("db/network-away.rrd")) {
+ $fname = "db/network-away.rrd";
+ $opts = array(
+ "--step", "300", "--start", "0",
+ "DS:useraway:GAUGE:600:0:U",
+ "DS:userhere:GAUGE:600:0:U",
+ "RRA:AVERAGE:0.5:1:600",
+ "RRA:AVERAGE:0.5:6:700",
+ "RRA:AVERAGE:0.5:24:775",
+ "RRA:AVERAGE:0.5:288:797",
+ "RRA:MAX:0.5:1:600",
+ "RRA:MAX:0.5:6:700",
+ "RRA:MAX:0.5:24:775",
+ "RRA:MAX:0.5:288:797"
+ );
+ $ret = rrd_create($fname, $opts, count($opts));
+ if(!$ret) {
+ $err = rrd_error();
+ echo "Create error: $err\n";
+ die();
+ }
+ }
+ $this->timer = timer(5,array(&$this,"create_stats"),array());
+ }
+
+ public function unload($rehash = false) {
+ kill_timer($this->timer);
+ }
+
+ function create_stats() {
+ $this->timer = timer(5*60,array(&$this,"create_stats"),array());
+ $stats = array(
+ "opers" => 0,
+ "total" => 0,
+ "away" => 0,
+ "here" => 0
+ );
+ foreach(P10_User::getAllUsers() as $num => $user) {
+ $stats['total']++;
+ if($user->isAway()) $stats['away']++;
+ else $stats['here']++;
+ if($user->getModes()->hasMode('o')) $stats['opers']++;
+ }
+ $channels = P10_Channel::getChannelCount();
+ $servers = P10_Server::getServerCount();
+ rrd_update("db/network.rrd", time().":".$stats['total'].":".$channels.":".$stats['opers'].":".$servers);
+ rrd_update("db/network-away.rrd", time().":".$stats['away'].":".$stats['here']);
+ foreach(uplink::$uplink->servers as $snum => $server) {
+ $count = $server->getUserCount();
+ $fname="db/".$server->getName().".rrd";
+ if(!file_exists($fname)) {
+ $opts = array(
+ "--step", "300", "--start", "0",
+ "DS:users:GAUGE:600:0:U",
+ "RRA:AVERAGE:0.5:1:600",
+ "RRA:AVERAGE:0.5:6:700",
+ "RRA:AVERAGE:0.5:24:775",
+ "RRA:AVERAGE:0.5:288:797",
+ "RRA:MAX:0.5:1:600",
+ "RRA:MAX:0.5:6:700",
+ "RRA:MAX:0.5:24:775",
+ "RRA:MAX:0.5:288:797"
+ );
+ $ret = rrd_create($fname, $opts, count($opts));
+ }
+ rrd_update($fname, time().":".$count);
+ }
+ }
+
+}
+
+?>
\ No newline at end of file
public static function getChannels() {
return self::$static_channels;
- }
+ }
+ public static function getChannelCount() {
+ return count(self::$static_channels);
+ }
+
+ public static function recheckAllChannels() {
+ foreach(self::$static_channels as $channel) {
+ $channel->checkChannel();
+ }
+ }
private $name;
private $topic;
$user->addChannel($this);
}
+ private function checkChannel() {
+ if(count($this->users) == 0 && !$this->modes->hasMode('z')) {
+ unset(self::$static_channels[strtolower($name)]); //drop empty channel
+ }
+ }
+
public function quitUser($user) {
if(array_key_exists($user->getNumeric(), $this->users)) {
unset($this->users[$user->getNumeric()]);
unset($this->userPrivs[$user->getNumeric()]);
//$user->delChannel($this) is not necessary because the user quits (the whole Object gets removed later)
+ $this->checkChannel();
} else {
trigger_error("Tried to quit a User from a Channel it is not joined.", E_USER_WARNING);
}
unset($this->users[$user->getNumeric()]);
unset($this->userPrivs[$user->getNumeric()]);
$user->delChannel($this);
+ $this->checkChannel();
} else {
trigger_error("Tried to part a User from a Channel it is not joined.", E_USER_WARNING);
}
case "W":
$this->recv_whois($from, $arguments);
break;
+ case "A":
+ $this->recv_away($from, $arguments);
+ break;
//default
default:
//unknown cmd
private function recv_ping($from, $args) {
$this->send("Z", $args[0]); //simply PONG
+ P10_Channel::recheckAllChannels();
}
private function recv_nick($from, $args) {
$this->send("318", $from, $args[1]);
}
+ private function recv_away($from, $args) {
+ $user = P10_User::getUserByNum($from);
+ if($user == null) {
+ trigger_error("Server tries to send an away command from an user that does not exist or was not found on recv_away.", E_USER_ERROR);
+ return;
+ }
+ if(count($args) > 0) {
+ $user->setAway($args[0]);
+ } else {
+ $user->setAway(null);
+ }
+ }
+
/********************************************************************************************
* SERVER FUNCTIONS *
********************************************************************************************/