View module: Whoisingame
<?php
/*
Who is in game module
* make upload / post to web site
*/
$whoisingame = new Whoisingame($bot);
/*
class
*/
class Whoisingame extends BaseActiveModule {
public $bot;
private $authkey;
// how much minutes bwtween online check and upload / post
private $user_agent = 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-GB; rv:1.8.1.20) Gecko/20081217 Firefox/2.0.0.20';
// link for where to send characters online
private $characters_online_link = 'http://www.yourweb.com/recive_online_chars.php';# your choice
private $ping_check = true;# should web be looked up
private $ping_check_link = 'http://www.yourweb.com/ping.php';# your choice on what file to lookup. in file put this adress you type
/*
class constructior
*/
public function __construct(&$bot) {
parent::__construct(&$bot, get_class($this));
// settings
$this->bot->core('settings')->create('Whoisingame', 'updatepost', 'yes', 'Should it be posted in guild when update is done?', 'yes;no', false, 1);
$this->bot->core('settings')->create('Whoisingame', 'updatetime', 15, 'How much time between updates? (needs restart of bot)', '5;10;15;30;45;60', false, 2);
// authkey for web
$this->authkey = sha1('some-text-or-numbers-or-whatever');// i suggest you use this for auth on your web
$this->help['description'] = 'Who is online in game and upload / post it on web.';
$this->help['notice'] = 'There are no commands for this module!';
// register cron event every $this->inverval
$i = (int) $this->bot->core('settings')->get('Whoisingame', 'updatetime');
$this->register_event('cron', $i.'minutes');
}
/*
command handler (is not needed)
*/
public function command_handler($name, $msg, $origin) {
return;
}
/*
do cron job (upload / post) every $interval minutes
*/
public function cron() {
// if ping is ok
if ($this->ping()) {
$data = array(
'key' => $this->authkey,
'characters' => array()
);
// all characters curently online
$data['characters'] = $this->list_users();
// there MUST be atleast one user online to send data
if (count($data['characters']) > 0) {
$data['characters'] = implode(';', $data['characters']);
// character data is sent like: char1;char2;char3
$data = $this->curl_send($this->characters_online_link, $data);
if ($this->bot->core('settings')->get('Whoisingame', 'updatepost') == 'yes') {
$this->bot->send_gc('Web update complete.');
}
}
unset($data);
}
return true;
}
/*
online user list
*/
private function list_users() {
$data = array();
$online = $this -> bot -> db -> select("SELECT t1.nickname FROM #___online AS t1 LEFT JOIN #___whois AS t2 ON t1.nickname = t2.nickname WHERE status_gc = '1' ORDER BY t1.nickname ASC");
if (!empty($online)) {
foreach ($online as $user) {
$data[] = $user[0];
unset($user);
}
}
unset($online);
return $data;
}
/*
ping for web
*/
private function ping() {
$ok = false;
if ($this->pink_check) {
if ($data = @file_get_contents($this->ping_check_link)) {
$data = trim($data);
if ($data == $this->ping_check_link) {
$ok = true;
}
}
}
else {
$ok = true;
}
return $ok;
}
/*
send data using curl
and return something
*/
private function curl_send($link, $data) {
if ($this->ping()) {
$cu = curl_init();
curl_setopt($cu, CURLOPT_URL, $link);
curl_setopt($cu, CURLOPT_HEADER, true);
curl_setopt($cu, CURLOPT_POSTFIELDS, $data);
curl_setopt($cu, CURLOPT_USERAGENT, $this->user_agent);
curl_setopt($cu, CURLOPT_RETURNTRANSFER, true);
$return_data = curl_exec($cu);
if (curl_errno($cu)) {$return_data = false;}
// close cURL
else {curl_close($cu);}
unset($cu, $link, $data);
return $return_data;
}
return false;
}
}
?>
Recruitment
Assasinnone | |
Barbariannone | |
Bear Shamannone | |
Conquerornone | |
Dark Templarnone | |
Demonologistnone | |
Guardiannone | |
Herald of Xotlinone | |
Necromancernone | |
Priest of Mitranone | |
Rangernone | |
Tempest Of Setnone |
If we are not recruiting it does not mean we are not taking new members. Register on forum and apply at this LINK