Esempio n. 1
0
 public function get($cfg_key, $cfg_type = 'config')
 {
     $cacheFile = BASEPATH . "../application/cache/" . $this->w . "_" . $cfg_type . ".xml";
     if (!file_exists($cacheFile)) {
         $host = Tw_import::get_tw_host($this->w);
         $data = @file($host . "/interface.php?func=get_" . $cfg_type);
         if (!$data) {
             die('Error: Could not read configs for ' . $this->host . ' type: ' . $cfg_type);
         }
         $fp = @fopen($cacheFile, 'w+');
         if (!$fp) {
             die('Error: Could not write config cache file.');
         }
         fwrite($fp, implode('', $data));
         fclose($fp);
     }
     if (!isset(self::$cfg_cache[$this->w][$cfg_type])) {
         $xml = new SimpleXMLElement($cacheFile, NULL, TRUE);
         self::$cfg_cache[$this->w][$cfg_type] = (array) $xml;
         array_walk_recursive(self::$cfg_cache[$this->w][$cfg_type], function (&$val) {
             if (is_object($val)) {
                 $val = (array) $val;
             }
         });
         array_walk_recursive(self::$cfg_cache[$this->w][$cfg_type], function (&$val) {
             if (is_numeric($val)) {
                 $val = (double) $val;
             }
         });
     }
     return isset(self::$cfg_cache[$this->w][$cfg_type][$cfg_key]) ? self::$cfg_cache[$this->w][$cfg_type][$cfg_key] : false;
 }
Esempio n. 2
0
echo ui_error(lang('accounts_connect_new_text'));
?>
    
    <p><?php 
echo lang('general_current_world');
?>
: <?php 
echo $this->User->selected_world;
?>
 (<?php 
echo anchor('usercp/change_world', lang('general_change'));
?>
)</p>
    
    <a id="link_add" href="<?php 
echo Tw_import::get_tw_base_host($this->User->selected_world);
?>
external_auth.php?sid=<?php 
echo $this->User->selected_world;
?>
|<?php 
echo $this->User->api_hash;
?>
&client=dsconn">
        <?php 
echo ui_ficon('link_add', lang('accounts_connect_new_account'));
?>
 
        <?php 
echo lang('accounts_connect_new_account');
?>
Esempio n. 3
0
 public function generate_conquer_posts()
 {
     $this->output->set_content_type('text/plain');
     set_time_limit(0);
     ini_set("memory_limit", "512M");
     ignore_user_abort(1);
     $this->load->library('Redis');
     $this->redis->connect();
     $servers = $this->config->item("tw_worlds");
     $this->load->model('Posts_model', 'Posts');
     $this->load->library('tw_import');
     $minTime = time() - 23 * 3600;
     foreach ($servers as $server) {
         $l = substr($server, 0, 2) == 'de' || substr($server, 0, 2) == 'ch' ? 'german' : 'english';
         $lang_data = $this->lang->load('backend', $l, true);
         $count = 0;
         $q = $this->db->query('SELECT time FROM last_conquer_import WHERE world = "' . $server . '"');
         if ($q->num_rows() == 0) {
             $time = $minTime;
             $this->db->insert('last_conquer_import', array('world' => $server, 'time' => 0));
         } else {
             $row = $q->row_array();
             $time = $row['time'] < $minTime ? $minTime : $row['time'];
         }
         $q->free_result();
         // api call
         $host = Tw_import::get_tw_host($server);
         if ($host == '' || $host == null || $host == false) {
             continue;
         }
         $lines = file($host . "/interface.php?func=get_conquer&since=" . $time);
         foreach ($lines as $line) {
             $count++;
             // $village_id, $unix_timestamp, $new_owner, $old_owner
             $parts = explode(",", trim($line));
             // add to database
             $this->db->insert($server . '_conquer', array('village_id' => $parts[0], 'unix_timestamp' => $parts[1], 'new_owner' => $parts[2], 'old_owner' => $parts[3]));
             if ($parts[2] == $parts[3]) {
                 continue;
             }
             // get name of village
             $query = $this->db->query('SELECT id, name FROM ' . $server . '_village WHERE id = ?', array($parts[0]));
             $village = $query->row_array();
             $query->free_result();
             // post on village wall
             $this->Posts->make_post(-1, sprintf($lang_data['backend_village_owner_change'], $parts[3], $parts[2]), $server, $village['id'], urldecode($village['name']), 'village', 0, -1, -1, $parts[1]);
             // post on new owner wall
             $query = $this->db->query('SELECT id, name, ally FROM ' . $server . '_player WHERE id = ?', array($parts[2]));
             $owner = $query->row_array();
             $query->free_result();
             $this->Posts->make_post(-1, sprintf($lang_data['backend_player_win_village'], $village['id'], $parts[3]), $server, $owner['id'], urldecode($owner['name']), 'player', 0, -1, -1, $parts[1]);
             if ($owner['ally'] != 0) {
                 $query = $this->db->query('SELECT id, name FROM ' . $server . '_ally WHERE id = ?', array($owner['ally']));
                 if ($query->num_rows() > 0) {
                     $ally = $query->row_array();
                     $query->free_result();
                     $this->Posts->make_post(-1, sprintf($lang_data['backend_ally_win_village'], $parts[2], $village['id'], $parts[3]), $server, $ally['id'], urldecode($ally['name']), 'ally', 0, -1, -1, $parts[1]);
                 }
             }
             // post on old owner wall
             if ($parts[3] != 0) {
                 $query = $this->db->query('SELECT id, name, ally FROM ' . $server . '_player WHERE id = ?', array($parts[3]));
                 $owner = $query->row_array();
                 $query->free_result();
                 if (isset($owner['id'])) {
                     $this->Posts->make_post(-1, sprintf($lang_data['backend_player_loose_village'], $village['id'], $parts[2]), $server, $owner['id'], urldecode($owner['name']), 'player', 0, -1, -1, $parts[1]);
                     #
                     if ($owner['ally'] != 0) {
                         $query = $this->db->query('SELECT id, name FROM ' . $server . '_ally WHERE id = ?', array($owner['ally']));
                         if ($query->num_rows() > 0) {
                             $ally = $query->row_array();
                             $query->free_result();
                             $this->Posts->make_post(-1, sprintf($lang_data['backend_ally_loose_village'], $parts[3], $village['id'], $parts[2]), $server, $ally['id'], urldecode($ally['name']), 'ally', 0, -1, -1, $parts[1]);
                         }
                     }
                 }
             }
             // update village table
             $this->db->where('id', $parts[0]);
             $this->db->update($server . '_village', array('tribe' => $parts[2]));
         }
         $this->db->where('world', $server);
         $this->db->update('last_conquer_import', array('time' => time()));
         $this->output->append_output("Server " . $server . " (Lang: " . $l . ") imported " . $count . " conquers since " . date('d.m.Y - H:i:s', $time) . "\n");
     }
     $this->redis->disconnect();
 }