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; } } ?>