0) { $line = mysql_fetch_object($res); $userid = $line->id; $allow_insert = $line->caninsert; $allowed_allyhistory = $line->allyhistory; $ogame_playerid = $line->ogame_playerid; if (isset($_POST['typ']) && $_POST['typ']=="stats" && isset($_POST['content']) && !empty($_POST['content']) && isset($_POST['who']) && is_numeric($_POST['who']) && isset($_POST['what']) && is_numeric($_POST['what']) && $allow_insert == "true" ) { echo "stats...\n"; // stats $statstext = stripslashes($_POST['content']); $who = (int)$_POST['who']; $what = (int)$_POST['what']; echo "test:\n".$_POST['content']."\n\n"; if ($who == 0) { echo "playerstats...\n"; // Playerstats $newarray = preg_split("/&\w+=/",$statstext); $stats_array['rank'] = explode("|",str_replace(".","",$newarray[1])); $stats_array['playername'] = explode("|",$newarray[2]); $stats_array['pID'] = explode("|",$newarray[3]); $stats_array['alliance'] = explode("|",$newarray[4]); $stats_array['points'] = explode("|",str_replace(".","",$newarray[5])); unset($newarray); // remove empty lines from the toolbar for($i=0; $i < count($stats_array['rank']); $i++) { if (empty($stats_array['rank'][$i])) { array_splice($stats_array['rank'], $i); array_splice($stats_array['playername'], $i); array_splice($stats_array['pID'], $i); array_splice($stats_array['alliance'], $i); array_splice($stats_array['points'], $i); break; } } if (count($stats_array['rank']) > 0) { // allybuffer $alliance_names_2_ids = array(); // determine all alliance IDs $query = "SELECT id, allyname FROM $allytable WHERE allyname IN ("; $run_query = false; foreach ($stats_array['alliance'] as $allyname) { $allyname = trim($allyname); if (!empty($allyname)) { $query .= "'".mysql_real_escape_string($allyname)."', "; $alliance_names_2_ids[strtolower($allyname)] = ""; $run_query = true; } } if ($run_query === true) { $query = substr($query,0,strlen($query)-2).")"; $res = mysql_query($query); if (!$res) { echo $query."\n".mysql_error()."\n"; $content = ob_get_clean(); return_result(622,$content); } while ($line = mysql_fetch_object($res)) { $alliance_names_2_ids[strtolower($line->allyname)] = $line->id; } } // determine all players which are in the database and have an ogame playerid $query = "SELECT id,playername,ogame_playerid FROM $playertable WHERE (ogame_playerid IS NOT NULL OR ogame_playerid != 0) AND ogame_playerid IN ("; for ($i=0; $i < count($stats_array['pID']); $i++) { if ($i < (count($stats_array['pID']) - 1)) { $query .= "'".mysql_real_escape_string($stats_array['pID'][$i])."',"; } else { $query .= "'".mysql_real_escape_string($stats_array['pID'][$i])."'"; } } $query .= ")"; echo $query." \n"; $res = mysql_query($query); echo mysql_num_rows($res)." Entries with ogame playerid found\n"; if (!$res) { echo $query."\n".mysql_error()."\n"; $content = ob_get_clean(); return_result(622,$content); } while ($line = mysql_fetch_object($res)) { $player_names_2_ids[strtolower($line->playername)]["id"] = $line->id; $player_names_2_ids[strtolower($line->playername)]["ogame_id"] = $line->ogame_playerid; } // determine the player itself as he might have no ogame playerid at stats (but possibly at the galaxytool) $query = "SELECT id,playername,ogame_playerid FROM $playertable WHERE playername IN ("; $j = 0; for ($i=0; $i < count($stats_array['playername']); $i++) { $stats_array['playername'][$i] = trim($stats_array['playername'][$i]); if ($stats_array['pID'][$i] == 0) { $query .= "'".mysql_real_escape_string($stats_array['playername'][$i])."',"; $j++; } } if ($j > 0) { // remove the , behind the last query part $query = substr($query,0,strlen($query)-1); $query .= ")"; echo $query." \n"; $res = mysql_query($query); echo mysql_num_rows($res)." Entries without ogame playerid found\n"; if (!$res) { echo $query."\n".mysql_error()."\n"; $content = ob_get_clean(); return_result(622,$content); } while ($line = mysql_fetch_object($res)) { $player_names_2_ids[strtolower($line->playername)]["id"] = $line->id; $player_names_2_ids[strtolower($line->playername)]["ogame_id"] = $line->ogame_playerid; } } $query_1 = false; $query_2 = false; switch ($what) { case 0: $query_collection = "INSERT INTO $playertable (id,user_id,rank,alliance_id,points,last_stats_update,playername,ogame_playerid) VALUES "; $query_collection2 = "INSERT INTO $playertable (id,user_id,rank,alliance_id,points,last_stats_update,playername) VALUES "; break; case 1: $query_collection = "INSERT INTO $playertable (id,user_id,frank,alliance_id,fpoints,last_stats_update,playername,ogame_playerid) VALUES "; $query_collection2 = "INSERT INTO $playertable (id,user_id,frank,alliance_id,fpoints,last_stats_update,playername) VALUES "; break; case 2: $query_collection = "INSERT INTO $playertable (id,user_id,rrank,alliance_id,rpoints,last_stats_update,playername,ogame_playerid) VALUES "; $query_collection2 = "INSERT INTO $playertable (id,user_id,rrank,alliance_id,rpoints,last_stats_update,playername) VALUES "; break; } echo "Eintraege: ".count($stats_array)." mit je ".count($stats_array['rank'])."\n"; for ($i=0; $i < count($stats_array['playername']); $i++) { // determine alliance ID $allyname = trim($stats_array['alliance'][$i]); if (empty($alliance_names_2_ids[strtolower($allyname)]) && !empty($allyname)) { // insert Alliance first $query = "INSERT INTO $allytable (allyname) VALUES ('".mysql_real_escape_string($allyname)."')"; $res = mysql_query($query,$mysqlcon); if (!$res) { echo $query."\n".mysql_error()."\n"; $content = ob_get_clean(); return_result(622,$content); } // set alliance ID $alliance_names_2_ids[strtolower($allyname)] = mysql_insert_id($mysqlcon); } elseif (trim($allyname) == "") { // Allyname is empty $alliance_names_2_ids[""] = 0; } if (empty($stats_array['pID'][$i]) && $ogame_playerid > 0) { $stats_array['pID'][$i] = $ogame_playerid; } // add query data (id,(x)rank,alliance_id,points,last_stats_update,playername,ogame_playerid) if (!empty($stats_array['pID'][$i])) { // ogame playerid known here if (isset($player_names_2_ids[strtolower($stats_array['playername'][$i])]["ogame_id"])) { // database contains that player with ogame playerid //echo "database contains that player with ogame playerid\n"; $query_2 = true; $query_collection2 .= " (".$player_names_2_ids[strtolower($stats_array['playername'][$i])]["id"].", $userid, '".mysql_real_escape_string($stats_array['rank'][$i])."','".mysql_real_escape_string($alliance_names_2_ids[strtolower($allyname)])."','".mysql_real_escape_string($stats_array['points'][$i])."',NOW(),'".mysql_real_escape_string($stats_array['playername'][$i])."'), "; } elseif (isset($player_names_2_ids[strtolower($stats_array['playername'][$i])]["id"])) { // player is included without ogame playerid //echo "player is included without ogame playerid\n"; $query_1 = true; $query_collection .= " (".$player_names_2_ids[strtolower($stats_array['playername'][$i])]["id"].",$userid,'".mysql_real_escape_string($stats_array['rank'][$i])."','".mysql_real_escape_string($alliance_names_2_ids[strtolower($allyname)])."','".mysql_real_escape_string($stats_array['points'][$i])."',NOW(),'".mysql_real_escape_string($stats_array['playername'][$i])."','".intval($stats_array['pID'][$i])."'), "; } else { // player new to database //echo "player new to database\n"; $query_1 = true; $query_collection .= " (NULL,$userid,'".mysql_real_escape_string($stats_array['rank'][$i])."','".mysql_real_escape_string($alliance_names_2_ids[strtolower($allyname)])."','".mysql_real_escape_string($stats_array['points'][$i])."',NOW(),'".mysql_real_escape_string($stats_array['playername'][$i])."','".intval($stats_array['pID'][$i])."'), "; } } else { // ogame playerid unknown (player itself) if (isset($player_names_2_ids[strtolower($stats_array['playername'][$i])]["id"])) { // player already at database //echo "player already at database\n"; $query_2 = true; $query_collection2 .= " (".$player_names_2_ids[strtolower($stats_array['playername'][$i])]["id"].",$userid, '".mysql_real_escape_string($stats_array['rank'][$i])."','".mysql_real_escape_string($alliance_names_2_ids[strtolower($allyname)])."','".mysql_real_escape_string($stats_array['points'][$i])."',NOW(),'".mysql_real_escape_string($stats_array['playername'][$i])."'), "; } else { // player new to database //echo "player new to database\n"; $query_2 = true; $query_collection2 .= " (NULL,$userid,'".mysql_real_escape_string($stats_array['rank'][$i])."','".mysql_real_escape_string($alliance_names_2_ids[strtolower($allyname)])."','".mysql_real_escape_string($stats_array['points'][$i])."',NOW(),'".mysql_real_escape_string($stats_array['playername'][$i])."'), "; } } } // remove last "," at the queries $query_collection = substr($query_collection,0,strlen($query_collection)-2); $query_collection2 = substr($query_collection2,0,strlen($query_collection2)-2); switch ($what) { case 0: $query_collection .= " ON DUPLICATE KEY UPDATE user_id=VALUES(user_id), rank=VALUES(rank), alliance_id=VALUES(alliance_id), points=VALUES(points), last_stats_update=NOW(), playername=VALUES(playername), ogame_playerid=VALUES(ogame_playerid) "; $query_collection2 .= " ON DUPLICATE KEY UPDATE user_id=VALUES(user_id), rank=VALUES(rank), alliance_id=VALUES(alliance_id), points=VALUES(points), last_stats_update=NOW(), playername=VALUES(playername) "; break; case 1: $query_collection .= " ON DUPLICATE KEY UPDATE user_id=VALUES(user_id),frank=VALUES(frank), alliance_id=VALUES(alliance_id), fpoints=VALUES(fpoints), last_stats_update=NOW(), playername=VALUES(playername), ogame_playerid=VALUES(ogame_playerid) "; $query_collection2 .= " ON DUPLICATE KEY UPDATE user_id=VALUES(user_id),frank=VALUES(frank), alliance_id=VALUES(alliance_id), fpoints=VALUES(fpoints), last_stats_update=NOW(), playername=VALUES(playername) "; break; case 2: $query_collection .= " ON DUPLICATE KEY UPDATE user_id=VALUES(user_id),rrank=VALUES(rrank), alliance_id=VALUES(alliance_id), rpoints=VALUES(rpoints), last_stats_update=NOW(), playername=VALUES(playername), ogame_playerid=VALUES(ogame_playerid) "; $query_collection2 .= " ON DUPLICATE KEY UPDATE user_id=VALUES(user_id),rrank=VALUES(rrank), alliance_id=VALUES(alliance_id), rpoints=VALUES(rpoints), last_stats_update=NOW(), playername=VALUES(playername) "; break; } if ($query_1 === true) { echo $query_collection."\n"; $res = mysql_query($query_collection); if (!$res) { echo $query_collection."\n".mysql_error()."\n"; $content = ob_get_clean(); return_result(622,$content); } } if ($query_2 === true) { echo $query_collection2."\n"; $res = mysql_query($query_collection2); if (!$res) { echo $query_collection."\n".mysql_error()."\n"; $content = ob_get_clean(); return_result(622,$content); } } if (!empty($playerhistory)) { // now the alliances has been updated, now update the alliance history $query = "INSERT INTO $playerhistory (player_id,alliance_id,year,month,day,rank,points,frank,fpoints,rrank,rpoints) SELECT id, alliance_id, DATE_FORMAT(NOW(),'%Y') , DATE_FORMAT(NOW(),'%m') , DATE_FORMAT(NOW(),'%e') , rank, points, frank, fpoints, rrank, rpoints FROM $playertable p WHERE p.last_stats_update > DATE_SUB(CURRENT_TIMESTAMP( ),INTERVAL 5 SECOND) ON DUPLICATE KEY UPDATE $playerhistory.alliance_id=VALUES(alliance_id), $playerhistory.rank=VALUES(rank), $playerhistory.points=VALUES(points), $playerhistory.frank=VALUES(frank), $playerhistory.fpoints=VALUES(fpoints), $playerhistory.rrank=VALUES(rrank), $playerhistory.rpoints=VALUES(rpoints)"; echo $query."\n"; $res = mysql_query($query); if (!$res) { echo $query."\n".mysql_error()."\n"; $content = ob_get_clean(); return_result(622,$content); } } $content = ob_get_clean(); echo "Content:\n"+$content."\n"; return_result(621,$content); } else { // no entries found return_result(622,"No entries found\n"); } } elseif ($who == 1) { echo "allystats...\n"; // Allystats $newarray = preg_split("/&\w+=/",$statstext); $stats_array['rank'] = explode("|",str_replace(".","",$newarray[1])); $stats_array['alliance'] = explode("|",$newarray[2]); $stats_array['member'] = explode("|",$newarray[3]); $stats_array['points'] = explode("|",str_replace(".","",$newarray[4])); unset($newarray); echo "Einträge: ".count($stats_array)." mit je ".count($stats_array['rank'])."\n"; switch ($what) { case 0: $query_collection = "INSERT INTO $allytable (user_id,rank, points, members, last_update, allyname) VALUES "; $query_end = " ON DUPLICATE KEY UPDATE rank=VALUES(rank), points=VALUES(points), last_update=VALUES(last_update), members=VALUES(members)"; break; case 1: $query_collection = "INSERT INTO $allytable (user_id,frank, fpoints, members, last_update, allyname) VALUES "; $query_end = " ON DUPLICATE KEY UPDATE frank=VALUES(frank), fpoints=VALUES(fpoints), last_update=NOW(), members=VALUES(members)"; break; case 2: $query_collection = "INSERT INTO $allytable (user_id,rrank, rpoints, members, last_update, allyname) VALUES "; $query_end = " ON DUPLICATE KEY UPDATE rrank=VALUES(rrank), rpoints=VALUES(rpoints), last_update=NOW(), members=VALUES(members)"; break; } $alliances_added = 0; for ($i=0; $i < count($stats_array['alliance']); $i++) { if (is_numeric($stats_array['rank'][$i])) { $alliances_added++; $query_collection .= "($userid,'".mysql_real_escape_string($stats_array['rank'][$i])."', '".mysql_real_escape_string($stats_array['points'][$i])."', '".mysql_real_escape_string($stats_array['member'][$i])."', NOW(), '".mysql_real_escape_string($stats_array['alliance'][$i])."' ), "; } } if ($alliances_added > 0) { $query_collection = substr($query_collection,0,strlen($query_collection)-2); $query_collection .= $query_end; echo $query_collection."\n"; $res = mysql_query($query_collection); if (!$res) { echo $query."\n".mysql_error()."\n"; $content = ob_get_clean(); return_result(622,$content); } if (!empty($allyhistory)) { // now the alliances has been updated, now update the alliance history $query = "INSERT INTO $allyhistory (alliance_id,year,month,day,rank,points,frank,fpoints,rrank,rpoints,members) SELECT id, DATE_FORMAT(NOW(),'%Y') , DATE_FORMAT(NOW(),'%m') , DATE_FORMAT(NOW(),'%e') , rank, points, frank, fpoints, rrank, rpoints, members FROM $allytable WHERE $allytable.last_update > DATE_SUB(CURRENT_TIMESTAMP( ),INTERVAL 5 SECOND) ON DUPLICATE KEY UPDATE $allyhistory.rank=VALUES(rank), $allyhistory.points=VALUES(points), $allyhistory.frank=VALUES(frank), $allyhistory.fpoints=VALUES(fpoints), $allyhistory.rrank=VALUES(rrank), $allyhistory.rpoints=VALUES(rpoints), $allyhistory.members=VALUES(members)"; echo $query."\n"; $res = mysql_query($query); if (!$res) { echo $query."\n".mysql_error()."\n"; $content = ob_get_clean(); return_result(622,$content); } } $content = ob_get_clean(); return_result(621,$content); } else { // no entries found return_result(622,"No entries found\n"); } } } elseif (isset($_POST['typ']) && $_POST['typ']=="galaxy" && isset($_POST['content']) && !empty($_POST['content']) && isset($_POST['galaxy']) && is_numeric($_POST['galaxy']) && isset($_POST['system']) && is_numeric($_POST['system']) && $allow_insert == "true" ) { echo "galaxyview...\n"; echo $_POST['content']."\n"; // Galaxy view $galaxy = (int)$_POST['galaxy']; $system = (int)$_POST['system']; $gv_source = str_replace(" "," ",stripslashes($_POST['content'])); $gv_array = explode("\n",$gv_source); $solarstring = $gv_array[0]; unset ($gv_array[1]); unset ($gv_array[0]); $ogame_playerids = array(); $ogame_playernames = array(); $ogame_allynames = array(); $playername_wo_ogameid = array(); $players_to_insert = false; foreach ($gv_array as $gv_row) { $gv_entries = explode("|",$gv_row); if ($gv_entries[8] > 0) { array_push($ogame_playerids ,$gv_entries[8]); // ogame playerid } elseif ($gv_entries[8] == 0 && trim($gv_entries[5]) != "") { array_push($playername_wo_ogameid,trim($gv_entries[5])); // no ogame playerid } if (!empty($gv_entries[5])) { $players_to_insert = true; array_push($ogame_playernames ,trim($gv_entries[5])); // playername } if (!empty($gv_entries[7])) array_push($ogame_allynames ,trim($gv_entries[7])); // allyname } // handle alliance names if (count($ogame_allynames) > 0) { // remove duplicates $ogame_allynames = array_unique($ogame_allynames); // try to insert all those alliances - ignore existing entries $allyinserts = "INSERT IGNORE INTO $allytable (allyname, last_update) VALUES ('".implode("',NOW()),('", $ogame_allynames)."',NOW())"; $res = mysql_query($allyinserts); if (!$res) { echo $allyinserts."\n".mysql_error()."\n"; } if (!$res) { echo $query."\n".mysql_error()."\n"; } // determine allynames $query = "SELECT distinct(id),allyname,diplomatic_status FROM $allytable WHERE allyname IN ('".implode("','", $ogame_allynames)."')"; $res = mysql_query($query); if (!$res) { echo $query."\n".mysql_error()."\n"; } unset($ogame_allynames); while ($line = mysql_fetch_object($res)) { $ogame_allynames[strtolower($line->allyname)]["id"] = $line->id; $ogame_allynames[strtolower($line->allyname)]["diplomatic_status"] = $line->diplomatic_status; } // echo "ID and diplomatic status are read\n"; // echo "starting to loop the gv_array with ".count($gv_array)."entries\n"; } else { $ogame_allynames = array(); } // try to insert all players - update them in case of existency $own_ogame_playerid = ""; $own_playertable_id = ""; if ($players_to_insert) { $query = "INSERT INTO $playertable (id,playername, ogame_playerid, alliance_id, noob,vacation,banned,inactive,long_inactive,diplomatic_status) VALUES "; foreach ($gv_array as $gv_row) { $gv_entries = explode("|",$gv_row); if (empty($gv_entries[5])) { // no player = nothing to do here continue; } // ogame_playerid handling $player_dipl_status = "'nothing'"; if ($gv_entries[8] > 0) { $ogame_playerid_at_query = $gv_entries[8]; // $player_dipl_status still not clarified - do not update the status then $player_dipl_status = "NULL"; } else { if ($own_ogame_playerid == "") { // check if there is an ogame playerid for this player (can only happen in case of an update of an own planet/moon) $playerquery = "SELECT id,ogame_playerid,diplomatic_status FROM $playertable WHERE playername='".mysql_real_escape_string(trim($gv_entries[5]))."' LIMIT 1"; $result = mysql_query($playerquery); if (!$res) { echo $playerquery."\n".mysql_error()."\n"; } if (mysql_num_rows($result) == 1) { // one entry returned $line = mysql_fetch_object($result); if (is_numeric($line->ogame_playerid)) { echo "Numeric ogame_playerid found
"; $own_ogame_playerid = $line->ogame_playerid; $player_dipl_status = "'".$line->diplomatic_status."'"; } else { echo "NO numeric ogame_playerid found
"; $own_ogame_playerid = "NULL"; $own_playertable_id = $line->id; $player_dipl_status = "'".$line->diplomatic_status."'"; } } else { // no entry returned $own_ogame_playerid = "DOES_NOT_EXIST"; } } $ogame_playerid_at_query = $own_ogame_playerid; } // determine alliance ID $ally_id = (trim($gv_entries[7]) != "") ? $ogame_allynames[strtolower(trim($gv_entries[7]))]["id"] : 0; // player status handling // "translate" playerstatus to german $playerstatus = $gv_entries[6]; $playerstatus = str_replace("b","g",$playerstatus); // english+french+italian+greek+romanian+japanese+finnish banned players $playerstatus = str_replace("v","u",$playerstatus); // english+spanish+dutch+french+italian+greek+romanian+japanese+finnish vacation mode $playerstatus = str_replace("o","u",$playerstatus); // balkan vacation mode $playerstatus = str_replace("a","u",$playerstatus); // latvian vacation mode $playerstatus = str_replace("m","u",$playerstatus); // portugues vacation mode $playerstatus = str_replace("k","g",$playerstatus); // balkan banned players $playerstatus = str_replace("t","u",$playerstatus); // turkish vacation players $playerstatus = str_replace("c","g",$playerstatus); // turkish banned players $playerstatus = str_replace("н","n",$playerstatus); // russian + bulgarian noob players $playerstatus = str_replace("РО","u",$playerstatus); // russian vacation players $playerstatus = str_replace("z","u",$playerstatus); // czech vacation players $playerstatus = str_replace("з","g",$playerstatus); // russian banned players $playerstatus = str_replace("в","u",$playerstatus); // bulgarian vacation mode $playerstatus = str_replace("б","g",$playerstatus); // bulgarian banned players if (strpos($gv_source,"Solsystem") !== false) { $playerstatus = str_replace("f","u",$playerstatus); // danish vacation mode } if (strpos($gv_source,"Teckenförklaring") !== false) { $playerstatus = str_replace("k","n",$playerstatus); // swedish noob players $playerstatus = str_replace("s","u",$playerstatus); // swedish vacation players $playerstatus = str_replace("b","g",$playerstatus); // swedish banned players $playerstatus = str_replace("f","s",$playerstatus); // swedish strong players } // noob players - de,en have "n" if (!preg_match("/Uk\D{1}ad S\D{1}oneczny/",$gv_source)) { // except polish "d" (strong player) $playerstatus = str_replace("d","n",$playerstatus); // french+italian+spanish noob players } $playerstatus = str_replace("z","n",$playerstatus); // dutch+turkey noob players if (preg_match("/Uk\D{1}ad S\D{1}oneczny/",$gv_source) || strpos($gv_source,"Günes Sistemi") !== false) { $playerstatus = str_replace("s","n",$playerstatus); // balkan+polish noob players } if (strpos($gv_source,"Sistema Solar") !== false) { $playerstatus = str_replace("f","n",$playerstatus); // portugues noob players } if (strpos($gv_source,"Sistema solar") !== false) { $playerstatus = str_replace("s","g",$playerstatus); // spanish banned players } if (strpos($gv_source,"Günes Sistemi") !== false) { $playerstatus = str_replace("g","s",$playerstatus); // turkish strong players (otherwise they would get "banned") } $playerstatus = preg_replace('/[^iIugn]/i','', $playerstatus); $playerstatus_noob = (strpos($playerstatus,"n") === false) ? 'false' : 'true'; $playerstatus_vacation = (strpos($playerstatus,"u") === false) ? 'false' : 'true'; $playerstatus_banned = (strpos($playerstatus,"g") === false) ? 'false' : 'true'; $playerstatus_inactive = (strpos($playerstatus,"i") === false) ? 'false' : 'true'; $playerstatus_long_inactive = (strpos($playerstatus,"I") === false) ? 'false' : 'true'; if ($ogame_playerid_at_query == "DOES_NOT_EXIST") { // insert the own player now and set the own playerid thereafter $insertquery = "INSERT INTO $playertable (playername, alliance_id, noob,vacation,banned,inactive,long_inactive,diplomatic_status) VALUES "; $insertquery .= "('".mysql_real_escape_string(trim($gv_entries[5]))."',".$ally_id.", '$playerstatus_noob','$playerstatus_vacation','$playerstatus_banned','$playerstatus_inactive','$playerstatus_long_inactive', $player_dipl_status)"; $res = mysql_query($insertquery); if (!$res) { echo $insertquery."\n".mysql_error()."\n"; } else { $own_ogame_playerid = ""; // to load the ID in a separate query (somehow mysql_insert_id did not work here) } } elseif ($ogame_playerid_at_query == "NULL" && is_numeric($own_playertable_id)) { $query .= "($own_playertable_id,'".mysql_real_escape_string(trim($gv_entries[5]))."',$ogame_playerid_at_query,".$ally_id.", '$playerstatus_noob','$playerstatus_vacation','$playerstatus_banned','$playerstatus_inactive','$playerstatus_long_inactive', $player_dipl_status), "; } else { $query .= "(NULL,'".mysql_real_escape_string(trim($gv_entries[5]))."',$ogame_playerid_at_query,".$ally_id.", '$playerstatus_noob','$playerstatus_vacation','$playerstatus_banned','$playerstatus_inactive','$playerstatus_long_inactive', $player_dipl_status), "; } } // now insert all collected players and update them accordingly $query = substr($query,0,strlen($query)-2); $query .= " ON DUPLICATE KEY UPDATE playername=VALUES(playername), alliance_id=VALUES(alliance_id), noob=VALUES(noob), vacation=VALUES(vacation), banned=VALUES(banned), inactive=VALUES(inactive), long_inactive=VALUES(long_inactive) "; // do not overwrite diplomatic stats - NULL would also not work here echo $query."
"; $res = mysql_query($query); if (!$res) { echo $query."\n".mysql_error()."\n"; } // now we know all players in our database - get their IDs $query = "SELECT p.id,playername,ogame_playerid,noob,vacation,banned,inactive,long_inactive,a.allyname FROM $playertable p LEFT JOIN $allytable a ON (p.alliance_id = a.id) WHERE playername IN ('".implode("','", $ogame_playernames)."')"; $res = mysql_query($query); if (!$res) { echo $query."\n".mysql_error()."\n"; } $ogame_playernames = array(); while ($line = mysql_fetch_object($res)) { if (!empty($line->ogame_playerid)) { $ogame_playernames[$line->ogame_playerid] = $line->id; } $ogame_playernames[strtolower($line->playername)] = $line->id; } } $query_collection = "INSERT INTO $dbtablename (galaxy,system,planet,moon,moonsize,planetname,last_update,metal,crystal,player_id,user_id) VALUES "; foreach ($gv_array as $gv_row) { $gv_entries = explode("|",$gv_row); // determine moonsize $moon = ($gv_entries[2] > 0) ? "true" : "false"; if ($gv_entries[0] < 1 || $gv_entries[0] > 15) { continue; } // insert row into database $query_collection .= " ("; $query_collection .= "'".mysql_real_escape_string($galaxy)."', "; $query_collection .= "'".mysql_real_escape_string($system)."', "; $query_collection .= "'".mysql_real_escape_string($gv_entries[0])."', "; $query_collection .= "'".mysql_real_escape_string($moon)."', "; // moon $query_collection .= "'".mysql_real_escape_string(str_replace(".","",$gv_entries[2]))."', "; // moonsize $query_collection .= "'".mysql_real_escape_string($gv_entries[1])."', "; // planetname $query_collection .= "NOW(), "; // last update $query_collection .= "'".mysql_real_escape_string($gv_entries[3])."', "; // metal $query_collection .= "'".mysql_real_escape_string($gv_entries[4])."', "; // crystal if (empty($gv_entries[5])) { $query_collection .= "'0',"; // no player at all } elseif ($gv_entries[8] > 0) { $query_collection .= "'".$ogame_playernames[trim($gv_entries[8])]."', "; // playerid by ogame_playerid } else { $query_collection .= "'".$ogame_playernames[strtolower(trim($gv_entries[5]))]."',"; // playerid by playername (may cause conflicts with UTF8 names or so) } $query_collection .= "'".$userid."'"; // store userid of the player who updated the system $query_collection .= "), "; } echo "galaxy: ".$galaxy." system: ".$system."\n"; $query_collection = substr($query_collection,0,strlen($query_collection)-2); $query_collection .= " ON DUPLICATE KEY UPDATE moon=VALUES(moon), moonsize=VALUES(moonsize),planetname=VALUES(planetname), last_update=VALUES(last_update),metal=VALUES(metal), crystal=VALUES(crystal),player_id=VALUES(player_id), user_id=VALUES(user_id)"; $res = mysql_query($query_collection); if (!$res) { echo mysql_error()."\n"; echo "gv not updated...\n"; $content = ob_get_clean(); return_result(602,$content); } else { echo "gv updated...\n"; $content = ob_get_clean(); return_result(601,$content); } echo "positions wrong...\n"; $content = ob_get_clean(); return_result(602,$content); } elseif (isset($_POST['typ']) && $_POST['typ']=="reports" && isset($_POST['content']) && !empty($_POST['content']) && $allow_insert == "true" ) { echo "reports...\n"; include_once "spioparser.inc.php"; $parser = new Probeparser($dbusername,$dbpassword,$dbname,$reporttable,$dbtablename,$playertable,$dbhost); $reportstring = str_replace(" "," ",stripslashes($_POST['content'])); $reportstring = str_replace(""," ",$reportstring); $reportstring = str_replace("\n","",$reportstring); $reportstring = str_replace("","\n",$reportstring); if (strpos($reportstring,"Flottbefällhavare") > 0) { // swedish ogame bug $reportstring = preg_replace("/\(\d+\-\d+\s\d+\:\d+\:\d+)\<\/th\>[\s]+\(Flottbefällhavare)\s*<\/th\>[\s]+\\(Spionagerapport av\s+[\w\s\_\-]+)[\]*(\[\d+\:\d+\:\d+\])/"," $2 $3 $4 $1 ",$reportstring); // Swedish $reportarray = explode("Flottbefällhavare",$reportstring); echo "Reportstring:\n$reportstring\n"; } else { //$reportarray = explode("",$reportstring); - ogame //$reportarray = explode("",$reportstring); - ogamescript $reportarray = preg_split("/\/i",$reportstring); } unset($reportarray[0]); $reportarray = array_reverse($reportarray); echo "Anzahl im Reportarray: ".count($reportarray)."\n"; $error = false; if (!isset($korean_resources_on)) exit("FATAL ERROR!"); foreach ($reportarray as $row) { $row = html_entity_decode($row); $row = strip_tags($row); $found = true; if (strpos($row,"Rohstoffe auf") !== false) { $_SESSION['lang'] = "german"; } elseif (strpos($row,"Resources on") !== false) { $_SESSION['lang'] = "english"; } elseif (strpos($row,"Recursos en") !== false) { $_SESSION['lang'] = "spanish"; } elseif (strpos($row,"Grondstoffen op") !== false) { $_SESSION['lang'] = "dutch"; } elseif (strpos($row,"Sirovine na") !== false) { $_SESSION['lang'] = "balkan"; } elseif (strpos($row,"Matières premières sur") !== false) { $_SESSION['lang'] = "french"; } elseif (strpos($row,"Recursos em") !== false) { $_SESSION['lang'] = "portugues"; } elseif (strpos($row,"Surowce na") !== false) { $_SESSION['lang'] = "polish"; } elseif (strpos($row,"Risorse su") !== false) { $_SESSION['lang'] = "italian"; } elseif (strpos($row,"itibariyle mevcut olan hammadde") !== false) { $_SESSION['lang'] = "turkish"; } elseif (strpos($row,"Råstoffer") !== false) { $_SESSION['lang'] = "danish"; } elseif (strpos($row,"Сырьё на") !== false) { $_SESSION['lang'] = "russian"; } elseif (strpos($row,"Resurser på") !== false) { $_SESSION['lang'] = "swedish"; } elseif (strpos($row,"Πόροι στο") !== false) { $_SESSION['lang'] = "greek"; } elseif ($default_language == "brazilian") { $_SESSION['lang'] = "brazilian"; } elseif (strpos($row,"Resursele pe") !== false) { $_SESSION['lang'] = "romanian"; } elseif (strpos($row,"Erőforrások a") !== false) { $_SESSION['lang'] = "hungarian"; } elseif (strpos($row,"Suroviny na") !== false) { $_SESSION['lang'] = "czech"; } elseif (strpos($row,$korean_resources_on) !== false) { $_SESSION['lang'] = "korean"; } elseif (strpos($row,"Ressurser på") !== false) { $_SESSION['lang'] = "norwegian"; } elseif (strpos($row,$taiwan_resources_on) !== false) { $_SESSION['lang'] = "taiwan"; } elseif (strpos($row,$japan_resources_on) !== false) { $_SESSION['lang'] = "japan"; } elseif (strpos($row,$chinese_resources_on) !== false) { $_SESSION['lang'] = "chinese"; } elseif (strpos($row,"Ресирси на") !== false) { $_SESSION['lang'] = "bulgarian"; } elseif (strpos($row,"Resursai") !== false) { $_SESSION['lang'] = "lithuanian"; } elseif (strpos($row,"Resursi uz") !== false) { $_SESSION['lang'] = "latvian"; } elseif (strpos($row,"Resurssit") !== false) { $_SESSION['lang'] = "finnish"; } else { $found = false; } echo "Found: $found\n"; if ($found === true) { echo "starting to parse entry...\n"; $tmp = $parser->parseEntry($row,$userid,false); // no flush! if ($tmp === true) { echo "true\n"; } else { echo "false".print_r($tmp)."\n"; } if ($tmp === false) { echo "we got an error\n"; $error = true; foreach($parser->error as $error_message) { echo $error_message."\n"; } } } } if ($error) { echo "Fehler aufgetreten: ".print_r($parser->error)."\n"; $content = ob_get_clean(); return_result(612,$content); } echo "okay\n"; $content = ob_get_clean(); return_result(611,$content); } elseif (isset($_POST['typ']) && $_POST['typ']=="allyhistory" && isset($_POST['content']) && !empty($_POST['content']) && $allowed_allyhistory == "true" ) { echo "allyhistory...\n"; // Allyhistory $return = false; if (!empty($playerhistory)) { include_once "allyparser.inc.php"; $allyparser = new Ally($dbusername,$dbpassword,$dbname,$playerhistory,$playertable,$utablename,$dbhost); $return = $allyparser->set_current_stats(utf8_decode(stripslashes($_POST['content']))); echo "return: $return\n"; echo ob_get_clean()."\n"; } ob_end_clean(); if (!$return) { echo $allyparser->error."\n"; return_result(632,$allyparser->error); } else { return_result(631,$allyparser->error); } } elseif (isset($_POST['typ']) && isset($_POST['content']) && !empty($_POST['content']) && $allow_insert == "true" && ($_POST['typ']=="fleet" || $_POST['typ']=="defense" || $_POST['typ']=="buildings" || $_POST['typ']=="techs")) { $temp = explode("&",$_POST['content']); $data = str_replace($_POST['typ']."=","",$temp[1]); $data = urldecode($data); $data = explode("|",$data); $amount = str_replace("amount=","",$temp[2]); $amount = urldecode($amount); $amount = explode("|",$amount); $planetname = $_POST['planet']; // split this string to get coordinates + planetname $pos = strpos($planetname,"["); if ($pos === false) { echo "No coordinates found at planetname"; $debug = ob_get_clean(); return_result(612,$debug); } $coordinates = substr($planetname,$pos); // get parts starting at [ $planetname = trim(substr($planetname,0,$pos-1)); // get parts before [ $coordinates = str_replace("[","",$coordinates); $coordinates = trim(str_replace("]","",$coordinates)); $metall = intval(str_replace(".","",$_POST['metal'])); $crystal = intval(str_replace(".","",$_POST['crystal'])); $deut = intval(str_replace(".","",$_POST['deut'])); $energy = intval(str_replace(".","",$_POST['energy'])); $moon = ($_POST['moon_or_planet'] == "moon") ? true : false; // determine language $language = $_POST['language']; switch ($language) { case "de" : $language = "german"; break; case "org" : $language = "english"; break; case "com.es" : $language = "spanish"; break; case "nl" : $language = "dutch"; break; case "com.hr" : $language = "balkan"; break; case "fr" : $language = "french"; break; case "com.pt" : $language = "portugues"; break; case "pl" : $language = "polish"; break; case "it" : $language = "italian"; break; case "com.tr" : $language = "turkish"; break; case "dk" : $language = "danish"; break; case "com.br" : $language = "brazilian"; break; case "ru" : $language = "russian"; break; case "se" : $language = "swedish"; break; case "gr" : $language = "greek"; break; case "ro" : $language = "romanian"; break; case "co.kr" : $language = "korean"; break; case "kr" : $language = "korean"; break; case "hu" : $language = "hungarian"; break; case "cz" : $language = "czech"; break; case "no" : $language = "norwegian"; break; case "com.tw" : $language = "taiwan"; break; case "tw" : $language = "taiwan"; break; case "jp" : $language = "japan"; break; case "com.cn" : $language = "chinese"; break; case "cn" : $language = "chinese"; break; case "bg.org" : $language = "bulgarian"; break; case "lt" : $language = "lithuanian"; break; case "lv" : $language = "latvian"; break; case "fi" : $language = "finnish"; break; default: $language = $default_language; break; } include_once "spioparser.inc.php"; $parser = new Probeparser($dbusername,$dbpassword,$dbname,$reporttable,$dbtablename,$playertable,$dbhost); // insert data echo "Using language $language
"; $result = $parser->insert_screen_data($planetname,$coordinates,$moon,$metall,$crystal,$deut,$energy,$data,$amount,$language,$_POST['typ']); if (!$result) { echo "
";
				print_r($parser->error);
				echo "
"; $debug = ob_get_clean(); return_result(612,$debug); } $debug = ob_get_clean(); return_result(611,$debug); } else { echo "nothing found...\n"; $debug = ob_get_clean(); return_result(700,"Nothing done at the galaxytool
".$debug); } } else { // echo "permission denied...\n"; ob_end_clean(); header("HTTP/1.0 403 Forbidden"); exit(); } } else { echo "username not set...\n"; } //fclose($fp); function return_result($resultcode,$debug_text = "") { if (empty($debug_text)) $debug_text = " "; // at least one blank for the toolbar regexp $result_text = ' Toolbar results
'.$resultcode.'
'.str_replace("\n","
",$debug_text) .'
'; $result_text = str_replace("\n","",$result_text); exit($result_text); } ?>