public static function factory() { if (is_dir(ROOT . self::$_paths['path'])) { if (is_file(ROOT . self::$_paths['config'])) { if (!empty(self::$_instance)) { return self::$_instance; } else { return self::$_instance = new Automate(ROOT . self::$_paths['config']); } } else { self::log('E', 'The script need a file (kingsage.json) on directory (json) to run it'); return FALSE; } } else { self::log('E', 'The script need a folder called "json" to run it'); return FALSE; } }
<?php /** * Autoleveler administration * * @author katan */ include_once dirname(__FILE__) . '/automate.class.php'; // parent $config = Automate::factory()->getConfig(); $paths = Automate::factory()->getPaths(); /** * Controller */ if (!empty($_POST)) { echo "<pre>"; print_r($_POST); echo "</pre>"; /* if ($f = fopen($paths['config'], 'w')) { fwrite($f, json_encode($scheduler_json)); fclose($f); $msg = "The attack have been saved. <a href='{$config['localhost']}config.php'>refresh page</a>"; } else { Automate::factory()->log('E', "You don't have permission to write {$paths['config']} file"); }*/ } /** * View */ if (!$is_ajax) {
} } } if ($sum_points) { array_push($pie_points, array('Others', round(($sum_points - $tracking['total_points']) / $sum_points * 100, 1))); array_push($pie_points, array('name' => $tracking['name'], 'y' => round($tracking['total_points'] / $sum_points * 100, 1), 'sliced' => true, 'selected' => true)); } $pie_points = json_encode($pie_points); // troop points $pie_troops = $pie_ally_troops = $user_data = array(); $sum_troops = $own_troops = 0; foreach ($AlltrackingParsed as $alliance => $tracks) { if ($alliance == $userAlliance) { for ($i = 0; $i < count($tracks); $i++) { foreach ($tracks[$i] as $user_id => $stats) { $_history = Automate::factory()->getTrackingHistory($user_id, $_week, $_year); if ($_history) { foreach ($_history as $_track) { $_temp_troops = 0; foreach ($_track as $unixtime => $values) { $village_points = 0; $village_conquer = $values['total_villages'] > 1 ? 2500 * ($values['total_villages'] - 1) : 0; foreach ($values['villages'] as $village) { $village_points += (int) $village['points']; } if ($id == $user_id) { $own_troops = $values['total_points'] - $village_points - $village_conquer; } $_temp_troops = $values['total_points'] - $village_points - $village_conquer; } }
// don't show errors // Overwrite data $_player_name = $tracking[$player_id]['name']; $_enabled = $tracking[$player_id]['enabled']; $tracking[$player_id] = $res; $tracking[$player_id]['name'] = $_player_name; $tracking[$player_id]['enabled'] = $_enabled; // Update player info if ($f = fopen(dirname(dirname(__FILE__)) . "/{$paths['tracking']}", 'w')) { fwrite($f, json_encode($tracking)); fclose($f); } else { Automate::factory()->log('E', "You don't have permission to write {$paths['tracking']} file"); } } else { Automate::factory()->log('E', "You don't have permission to write on {$filename} file"); } } else { Automate::factory()->log('E', "Parse error when try to catch player info for tracking system"); } } else { continue; } } $_end = microtime(true); $execution_time = round($_end - $_start, 4); print "<br>{$execution_time} seconds<br>"; if (isset($_GET['player'])) { echo '<h3>Updated stats!</h3>'; echo "<a href='{$config['localhost']}admintracking.php'>Go back to tracking users</a>"; }
$res = Automate::factory()->attack($farm['from'], $farm['to'], $farm['troops'], $mode); } } } // If attacks has been sended, save the attack on log and update the attacks list if ($res) { $time = time(); /** * Register attack in attacks.json and xxxx.log */ $mode = $mode == 'espy' ? 'S' : 'A'; // If marked untracked attack, the attack doesn't saved if (!isset($farm['untracked']) || !$farm['untracked']) { Automate::factory()->save_attack($farm['from'], $farm['to'], $farm['troops'], $time, $mode, $id); } $_text = "from {$farm['to']['name']} ({$farm['to']['x']}|{$farm['to']['y']}) to {$farm['to']['name']} ({$farm['to']['x']}|{$farm['to']['y']}) with troops (" . implode(',', $farm['troops']) . ')'; $_text += $farm['iteration'] > 0 ? " x{$farm['iteration']}" : ''; Automate::factory()->log($mode, $_text); } } else { continue; // The attack is disabled } } $end = microtime(true); $execution_time = round($end - $start, 4); echo "{$execution_time} seconds"; if (isset($_GET['start'])) { echo "<br><br>"; echo "<a href='{$config['localhost']}'>Go to index</a>"; }
/** OK !! */ function attackrevision(&$config, &$html, &$bbcode, array &$attacks, &$flag_file, $pages, $servertime, $alliance_email) { $start = 0; $snobs_count = 0; $pages = $pages == 0 ? 1 : $pages; $all_attacks = $attacks; for ($i = 0; $i < $pages; $i++) { unset($attacks['pages'], $attacks['servertime']); foreach ($attacks as $key => $attack) { $from = array('x' => $attack['from']['x'], 'y' => $attack['from']['y']); $to = array('x' => $attack['to']['x'], 'y' => $attack['to']['y']); $kata_speed = (int) Automate::factory()->getDistance($from, $to, $config['troops_speed']['kata']); $snob = $attack['unixtime'] - 40 > $kata_speed; // Snob if ($snob) { // Exists previous attack? if (count($flag_file) > 0) { foreach ($flag_file as $old_attack) { if ($attack['to']['x'] == $old_attack['to']['x'] && $attack['to']['y'] == $old_attack['to']['y'] && $attack['from']['x'] == $old_attack['from']['x'] && $attack['from']['y'] == $old_attack['from']['y'] && $attack['when'] == $old_attack['when']) { continue 2; // Break this loop and continues the $attack loop } } } $_arrival = date('d/m/Y H:i:s', $attack['unixtime'] + $servertime + $config['flag_time']); $html .= "<tr><td>{$attack['to']['player']} - {$attack['to']['colony']}</td><td>{$attack['from']['player']} ({$attack['from']['ally']}) - {$attack['from']['colony']}</td><td>{$_arrival}</td><td>{$attack['countdown']}</td></tr>"; $bbcode .= "<br>[player]{$attack['to']['player']}[/player]<br>[img_snob] [village]{$attack['to']['x']}|{$attack['to']['y']}[/village] [b]{$_arrival}[/b]<br/><br/>Atacante: {$attack['from']['player']} [village]{$attack['from']['x']}|{$attack['from']['y']}[/village]<br/><br/>"; $snobs_count++; $alliance_email = true; // * // Own Auto-Defense for snobs attaks // REVIEW attack flag on barraks from village attacked to take time /* if ((strtolower($attack['to']['player']) == strtolower($config['player'])) && $config['autodefense']) { // Check neighbor villages foreach($villages as $village_id => $village) { foreach ($village as $data) { // Discard village attacked if ($data['x'] != $attack['to']['x'] && $data['y'] != $attack['to']['y']) { // Select only village with defensive troops if (in_array('defense', $data['type'])) { // Used Heavy unit for support $hspeed = Automate::factory()->getDistance(array('x'=>$data['x'], 'y'=>$data['y']), array('x'=>$attack['to']['x'], 'y' => $attack['to']['y']), $config['troops_speed']['heavy']); if ($hspeed < $attack['unixtime']) { // Scheduler support // REVIEW attack flag on barraks from village attacked to take time } } } } } } */ } // Attacks to player KATAN (no snobs) if (strtolower($attack['to']['player']) == strtolower($config['player']) && !$snob) { // CHANGED TO ADD katan player !!! //$_player = strtolower(trim($attack['to']['player'])); //if (($_player == 'katan' || $_player == 'baarman') && !$snob) { // Exists previous attack? if (count($flag_file) > 0) { foreach ($flag_file as $old_attack) { if ($attack['to']['x'] == $old_attack['to']['x'] && $attack['to']['y'] == $old_attack['to']['y'] && $attack['from']['x'] == $old_attack['from']['x'] && $attack['from']['y'] == $old_attack['from']['y'] && $attack['when'] == $old_attack['when']) { continue 2; // Break this loop and continues the $attack loop } } } // Get type of troops are attacking $_speedtroop = array(); foreach ($config['troops_speed'] as $name => $speed) { $_speedtime = (int) Automate::factory()->getDistance($from, $to, $speed); if ($attack['unixtime'] < $_speedtime) { $_speedtroop[] = $name; } } $_speedtroop = implode(" | ", $_speedtroop); $html .= "<tr><td>{$attack['to']['player']} - {$attack['to']['colony']}</td><td>{$attack['from']['player']} ({$attack['from']['ally']}) - {$attack['from']['colony']}</td><td>{$attack['when']}</td><td>{$attack['countdown']} <em>({$_speedtroop})</em></td></tr>"; } } if ($i + 1 < $pages) { $start += 50; $url = "{$config['protocol']}://{$config['server']}.{$config['domain']}/game.php?{$config['flag']}&start={$start}"; $attacks = @Automate::factory()->parser_attack($url); $all_attacks = array_merge($all_attacks, $attacks); } } // if HTML have empty, there aren't new attacks if (!empty($html)) { // Save attacks and sendmail Automate::factory()->save_flagattacks($all_attacks); if ($snobs_count > 0) { Automate::factory()->log('F', "{$snobs_count} snobs has been detected."); } // Save Log // Sendmail $html = "<html><head><style type='text/css'>.center{text-align:center;} table{border:1px solid #ccc;border-spacing:0;} th{background-color:#ccc;border-bottom:1px solid #ccc;text-shadow:1px 1px 0 #eee;} td,th{border-left:1px solid #ccc;padding: 4px 8px;}</style></head><body><table><thead><tr><th>TO</th><th>FROM</th><th>ARRIVAL</th><th class='center'>COUNTDOWN</th></tr></thead><tbody>{$html}</tbody></table><br/>{$bbcode}</body></html>"; $mailer = sendmail($html, $config, $alliance_email); if ($mailer) { echo '<br>email sended<br>'; } else { Automate::factory()->log('E', "The email with flag attacks wasn't sended"); // Save Error echo "<br>The email with flag attacks wasn't sended<br>"; } } else { echo "<br>There aren't new attacks<br>"; } }
$farms_json[$_POST['select'][$i]]['enabled'] = isset($_POST['enable']) ? 'true' : 'false'; } if ($f = fopen($paths['farms'], 'w')) { fwrite($f, json_encode($farms_json)); fclose($f); $msg = "The changes have been saved. <a href='{$config['localhost']}adminfarms.php'>refresh page</a>"; } else { Automate::factory()->log('E', "You don't have permission to write {$paths['farms']} file"); } } } break; case 'get-village': // OK $is_ajax = TRUE; $village_data = Automate::factory()->getVillage($_GET['type'], $id); echo $village_data; break; } /** * View */ if (!$is_ajax) { ?> <!DOCTYPE html> <html lang="en"> <head> <meta name="viewport" content="width=device-width, user-scalable=yes"> <meta http-equiv="X-UA-Compatible" content="IE=EDGE" /> <meta http-equiv="Content-type" content="text/html;charset=UTF-8"/>
?> <img src="<?php echo $config['localhost']; ?> media/img/wood.png"/><?php echo $buildings['buildings'][$name]['wood'][$level - 1]; ?> <img src="<?php echo $config['localhost']; ?> media/img/iron.png"/><?php echo $buildings['buildings'][$name]['iron'][$level - 1]; ?> )</em></span> <span class="separator">Estimated time: <?php echo Automate::factory()->getformatTime($buildings['buildings'][$name]['buildTime'][$level - 1] * ($buildings['buildings']['main']['feature'][$autoleveler[$village_id]['buildings']['main']] / 100) * $buildings['timeMultipler']); ?> </span> <?php } ?> </li> <?php } ?> </ul> <?php } else { ?> There aren't yet buildings queued <?php
$data[$trade['id']]['start'] = time(); // Add time start unset($data[$trade['id']]['id'], $data[$trade['id']]['method'], $data[$trade['id']]['interval'], $data[$trade['id']]['lessthan'], $data[$trade['id']]['to']); $res = Automate::factory()->Trading($data[$trade['id']]); // Send trade if (!$res) { unset($data[$trade['id']]); Automate::factory()->log('E', "The trading with ID {$trade['id']} wasn't sended"); } else { Automate::factory()->log('T', "From {$_villages[$trade['from']]['name']} to {$_villages[$trade['to']]['name']} with: {$trade['stone']} | {$trade['wood']} | {$trade['iron']}"); } } } // Save tradings if (count($data) > 0) { if ($f = fopen(dirname(dirname(__FILE__)) . "/{$paths['trading']}", 'w')) { fwrite($f, json_encode($data)); fclose($f); } else { Automate::factory()->log('E', "You don't have permission to write {$paths['trading']} file"); } } } // End $_end = microtime(true); $execution_time = round($_end - $_start, 4); echo "<br>{$execution_time} seconds"; if (isset($_GET['start'])) { echo "<br><br>"; echo "<a href='{$config['localhost']}'>Go to index</a>"; }
case 'edit': // OK if (!empty($_POST)) { // Save data $scheduler_json[$_POST['mtime']][$_POST['pos']]['troops'] = $_POST['troops']; $scheduler_json[$_POST['mtime']][$_POST['pos']]['iteration'] = $_POST['iteration']; $scheduler_json[$_POST['mtime']][$_POST['pos']]['method'] = $_POST['method']; ksort($scheduler_json, SORT_NUMERIC); //order by departure time ASC // Save file if ($f = fopen($paths['scheduler'], 'w')) { fwrite($f, json_encode($scheduler_json)); fclose($f); $msg = "The scheduler have been saved. <a href='{$config['localhost']}adminattacks.php'>refresh page</a>"; } else { Automate::factory()->log('E', "You don't have permission to write {$paths['scheduler']} file"); } } break; } /** * View */ if (!$is_ajax) { ?> <!DOCTYPE html> <html lang="en"> <head> <meta name="viewport" content="width=device-width, user-scalable=yes"> <meta http-equiv="X-UA-Compatible" content="IE=EDGE" /> <meta http-equiv="Content-type" content="text/html;charset=UTF-8"/>
// If has been error save on log @Automate::factory()->log('E', "Recruit - " . strip_tags($error[0])); } else { // Save recruit data if ($f = fopen(dirname(dirname(__FILE__)) . "/{$paths['recruit']}", 'w')) { fwrite($f, json_encode($recruit, TRUE)); fclose($f); } else { @Automate::factory()->log('E', "Failed save data on file " . dirname(dirname(__FILE__)) . "/{$paths['recruit']}"); } // Save log $_troops_recruited = ''; foreach ($post[$village_id] as $key => $value) { if ($_troops_recruited != '') { $_troops_recruited .= ', '; } $_troops_recruited .= "{$key}: {$value}"; } @Automate::factory()->log('R', " on {$villages[$village_id]['name']} with troops {$_troops_recruited}"); } } } sleep(rand(3, 7)); } $end = microtime(true); $execution_time = round($end - $start, 4); echo "{$execution_time} seconds"; if (isset($_GET['start'])) { echo "<br><br>"; echo "<a href='{$config['localhost']}'>Go to index</a>"; }
.gif" alt="<?php echo $name; ?> " title="<?php echo $name; ?> " style="vertical-align: middle;"/> <?php echo key($temp); ?> </td> <td class="span5"> <span data-time="<?php echo $_times[$i]; ?> "><?php echo Automate::factory()->getformatTime($_times[$i]); ?> </span> </td> </tr> <?php } ?> <?php } ?> </tbody> </table> </li> </ul> </form>
} } // Save edit farm if (!$error) { $edit_village = $_POST; unset($edit_village['who']); // Remove who value foreach ($edit_village as $key => $data) { $villages_json[$_POST['who']][$edit_village['id']][$key] = $data; } if ($f = fopen($paths['villages'], 'w')) { fwrite($f, json_encode($villages_json)); fclose($f); $msg = "The changes have been saved. <a href='{$config['localhost']}adminvillages.php?mode={$mode}'>refresh page</a>"; } else { Automate::factory()->log('E', "You don't have permission to write {$paths['villages']} file"); } } } break; case 'sort': // SORT BY NAME ALL VILLAGES echo 'sort'; break; } // Generate troop stats $attackVillages = 0; $defenseVillages = 0; $spyVillages = 0; $totalVillages = 0; $totalTroopPoints = 45000;
* @author katan */ include_once dirname(__FILE__) . '/automate.class.php'; // parent $config = Automate::factory()->getConfig(); $url = "{$config['protocol']}://{$config['server']}.{$config['domain']}/game.php?s=messages"; $messages = ''; /** * Controller */ $id = null; if (!empty($_GET)) { $id = $_GET['id']; $url = $url . "&m=in&id={$id}"; } $messages = Automate::factory()->getMessages($url); ?> <!DOCTYPE html> <html lang="en"> <head> <meta name="viewport" content="width=device-width, user-scalable=no"> <meta http-equiv="X-UA-Compatible" content="IE=EDGE" /> <meta http-equiv="Content-type" content="text/html;charset=UTF-8"/> <title>Messages</title> </head> <body style="background-color: #444;"> <?php echo print_r($messages); ?> <br> <h4>
$url = $config['protocol'] . '://' . $config['domain'] . '/zjax.php?func=loginToGameround&fclass=asys&serverId=' . $_POST['server'] . '&_=' . $_POST['unixtime']; Automate::factory()->register($url); } $server = $_POST['server']; $username = $_POST['name']; $hash = md5($_POST['password']); } break; case 'step2': echo '<pre>'; print_r($_POST); echo '</pre>'; // Login $url = $config['protocol'] . '://s' . $_POST['server'] . '.' . $config['domain'] . '/game.php?village=0'; unset($_POST['server']); $res = Automate::factory()->register($url, $_POST); echo '<pre>'; print_r($url); echo '</pre>'; echo '<pre>'; print_r($res); echo '</pre>'; break; } ?> <!DOCTYPE html> <html lang="en"> <head> <meta name="viewport" content="width=device-width, user-scalable=yes"> <meta http-equiv="X-UA-Compatible" content="IE=EDGE" /> <meta http-equiv="Content-type" content="text/html;charset=UTF-8"/>
} $i++; usleep(100000); // 0,1 seconds } while (!$break); // Save proof & overwrite if ($proof) { $f = fopen(dirname(dirname(__FILE__)) . "/{$paths['proof']}", 'w+'); if ($f) { fwrite($f, $proof); fclose($f); @chmod(dirname(dirname(__FILE__)) . "/{$paths['proof']}", 0777); } } // Save log at the end if (count($log) > 0) { foreach ($log as $v) { Automate::factory()->log($v[0], $v[1]); } // Make file to alert to others scripts for scheduler running $f = fopen(dirname(dirname(__FILE__)) . "/{$paths['scheduler_flag']}", 'w'); if ($f) { fwrite($f, "running..."); fclose($f); @chmod(dirname(dirname(__FILE__)) . "/{$paths['scheduler_flag']}", 0777); } } } $_end = microtime(true); $execution_time = round($_end - $_start, 4); echo "<br>{$execution_time} seconds<br>";
$message .= "Guía de instalación: [URL=http://www.mediafire.com/view/tiss2cqb3ntenbi/Guía_de_instalación.pdf]http://www.mediafire.com/view/tiss2cqb3ntenbi/Guía_de_instalación.pdf[/URL]\n"; $message .= "La herramienta: [URL=http://www.mediafire.com/download/893wq3vljmtn3hw/automate-kingsage.zip]http://www.mediafire.com/download/893wq3vljmtn3hw/automate-kingsage.zip[/URL]\n\n"; $message .= "Si tienen alguna duda al respecto pueden contactar con [player]Soporte[/player], o bien, en el foro externo.\n\nSaludos a todos,\nSoporte."; while ($flag) { $players = @Automate::factory()->getRankingPlayers("{$_urlranking}{$page}"); if (!empty($players) || count($players) > 0) { for ($i = 0; $i < count($players); $i++) { // Send Messages to exists players and points over 0 if (isset($players[$i]['name']) && $players[$i]['points'] > 0) { $proof = @Automate::factory()->sendMessage("{$_urlmessage}"); if ($proof) { $data = array(); $data["msg_to"] = $players[$i]['name']; $data["msg_subject"] = $subject; $data["msg_text"] = $message; if (@Automate::factory()->sendMessage("{$_urlsend}{$proof}", $data)) { echo "MP sended to: {$players[$i]['name']}<br>"; usleep(125000); // 250ms } } } } // Next page $_start++; $page = $_start * $_limit; usleep(125000); // 250ms } else { // Exist if empty playyers $flag = false;
<?php /** * Farm administration * @author katan */ include_once dirname(__FILE__) . '/automate.class.php'; // parent $config = Automate::factory()->getConfig(); $url = "{$config['protocol']}://{$config['server']}.{$config['domain']}/forum.php"; $output = ''; $output = Automate::factory()->getGame($url . '?' . $_SERVER['QUERY_STRING'], $_POST, true, false); ?> <!DOCTYPE html> <html lang="en"> <head> <meta name="viewport" content="width=device-width, user-scalable=no"> <meta http-equiv="X-UA-Compatible" content="IE=EDGE" /> <meta http-equiv="Content-type" content="text/html;charset=UTF-8"/> <title>Game</title> </head> <style type="text/css"> html { background-color: #111; background-image: none !important; color:#ccc; font-size:11px; } img { opacity: 0.4; }
<span class="block"> <?php if ($value > 0 && isset($own_villages[$village_id]['buildings']['barracks']) && $own_villages[$village_id]['buildings']['barracks'] > 0) { ?> <em class="inline-block"> <?php $_barracks_feature = $buildings['buildings']['barracks']['feature'][$own_villages[$village_id]['buildings']['barracks'] - 1] / 100 * 2; ?> <?php $_recruiting_time = $value * ($buildings['troops'][$troop]['buildTime'] * $_barracks_feature / $config['speed']); ?> (<?php echo date('d/m/Y H:i', $_time + round($_recruiting_time, 0)); ?> - <?php echo Automate::factory()->getformatTime($_recruiting_time); ?> ) </em> <?php } ?> </span> </td> <?php } ?> <?php } ?> <td>
<?php /** * Farm administration * @author katan */ include_once dirname(__FILE__) . '/automate.class.php'; // parent $config = Automate::factory()->getConfig(); $url = "{$config['protocol']}://{$config['server']}.{$config['domain']}/zjax.php"; echo Automate::factory()->getGame($url . '?' . $_SERVER['QUERY_STRING'], $_POST, true, true);