[READ-ONLY] Mirror of https://github.com/andrioid/travian.scrolls.org. Retired project. I got a bit overly engaged in an online game called Travian.
1.7 kB
55 lines
1#!/usr/bin/php
2<?php
3include("config.php");
4$tmpfile = "tmp.sql";
5$structure = "structure.sql";
6
7mysql_connect($DB['host'], $DB['user'], $DB['pass']);
8mysql_select_db("travian");
9chdir("/home/andri/travian.scrolls.org");
10
11$Log = array();
12function logit($text) {
13 global $Log;
14 $Log[] = $text;
15}
16
17foreach ($Servers as $sid => $server) {
18 $dumpfile = $server['dumpfile'];
19 $name = $server['name'];
20 # Get the file
21 $return = 0;
22 $system = sprintf("wget -O %s %s 2>/dev/null 1>/dev/null", $tmpfile, $dumpfile);
23 system($system, $return);
24 echo "Fetching SQL dump for $name\n";
25 #echo "Run: $system \n";
26 if ($return == 1) {
27 logit(sprintf("Database fetching for %s failed", $name));
28 } else {
29 if (file_exists($tmpfile)) {
30 if (filesize($tmpfile) > 0) {
31 $system = sprintf("mysql --host=%s --user=%s --password=%s --default-character-set=utf8 %s < %s", $DB['host'], $DB['user'], $DB['pass'], "travian", $structure);
32 system($system);
33 #echo "Run: $system \n";
34 $system = sprintf("mysql --host=%s --user=%s --password=%s --default-character-set=utf8 %s < tmp.sql", $DB['host'], $DB['user'], $DB['pass'], "travian");
35 system($system);
36 #echo "Run: $system \n"
37 $query = sprintf("DROP TABLE IF EXISTS %s", $name);
38 mysql_query($query) or logit(mysql_error());
39 $query = sprintf("RENAME TABLE %s TO %s", "x_world", $name);
40 mysql_query($query) or logit(mysql_error());
41 logit("Updated database for $name");
42 }
43 }
44 }
45 #echo "wget returned: $return\n";
46 #echo "$name / $dumpfile \n";
47}
48
49foreach ($Log as $logentry) {
50 $query = sprintf("INSERT INTO Events SET details='%s'", $logentry);
51 mysql_query($query) or die(mysql_error());
52 echo "Log: $logentry \n";
53}
54
55?>