_set_dbusername($dbusername))) die($this->error); if (!($this->_set_dbname($dbname))) die($this->error); if (!($this->_set_tablename($tablename))) die($this->error); $this->dbpassword = $dbpassword; $this->allytable = (!empty($allytable)) ? $allytable : "tabelle4"; $this->playertable = (!empty($playertable)) ? $playertable : "tabelle3"; $this->_set_dbhost($dbhost); $this->_db_connection_works(); // Testen der Datenbankverbindung } /** * @return void * @param String $galastring String der in Galaxieansicht kopiert wurde. * @desc Analysiert den String und füllt die DB mit den Daten */ function parseString($galastring,$return=false,$fixnotices=true) { $returnarray = array(); // wird benütigt bei return = true; $allynames = array(); $playernames = array(); $galastring = trim(addslashes(stripslashes($galastring))); $string = $galastring; // "Sonnensystem" suchen $found = false; $i = 0; while (!$found) { $i++; $pos = strpos($string,"Solar system"); $temp = substr($string,$pos+1+strlen("Solar system"),1); if (is_numeric($temp)) $found = true; $string = substr($string,$pos+strlen("Solar system")); if ($i == 10) return false; // um Endlosschleife zu verhindern } $rest = trim($string); $galaxie = substr($rest,0,strpos($rest,":")); $string = strstr($rest,":"); // liefer Rest nach dem Doppelpunkt hinter der Galaxie $system = substr($string,0,4); $system = preg_replace("/([^0-9])/","",$system); $string = strstr($string,"\n"); // liefer Rest nach dem Doppelpunkt hinter der Galaxie $line = explode("\n",$string); $infoarray = array(); for ($i=2;$i<17;$i++) { $ally = ""; $planetname = ""; $planetnummer = ""; $spielername = ""; $spielerstatus = ""; // Prüfen ob IE (keine \t sondern nur Leerzeichen) if (strpos($line[$i],"\t") === false && strlen($line[$i]) > 3) { // IE Handling $content = preg_split("/[\s]+\s/",$line[$i], -1); $planetnummer = (int)trim($content[0]); if (count($content) > 2) { $planetname = trim($content[1]); // Galaxieansicht (activity) ist eine extra Spalte if (substr($content[2],0,1) == "(") { $spielername = trim($content[3]); $ally = trim($content[4]); } elseif ($content[2] == "M") { $mond = 1; } else { $spielername = trim($content[2]); $ally = trim($content[3]); } } } else { // Mozilla, FF, Epiphany etc. $content = explode("\t",$line[$i]); $planetnummer = (int)trim($content[0]); if (count($content) > 2) { $planetname = trim($content[2]); $mond = (substr(trim($content[3]),0,1) == "M") ? 1 : 0; $spielername = trim($content[5]); $ally = trim($content[6]); } } // Planetname ermitteln if (!empty($planetname)) { $pos = strpos($planetname,"("); if ($pos !== false ) $planetname = trim(substr($planetname,0,$pos)); } $playerstatus_noob = 'false'; $playerstatus_vacation = 'false'; $playerstatus_banned = 'false'; $playerstatus_inactive = 'false'; $playerstatus_long_inactive = 'false'; // Spielerstatus ermitteln if (!empty($spielername)) { $pos = strpos($spielername,"("); $pos2 = strpos($spielername,")"); if ((($pos !== false) && ($pos !== false))) { $spielerstatus = trim(substr($spielername,$pos+1,$pos2-$pos-1)); $spielerstatus = str_replace("b","g",$spielerstatus); // english+french+italian+brazilian+greek+korean+romanian+japanese+chinese+finnish banned players if ($_SESSION['lang'] == "balkan") { $spielerstatus = str_replace("k","g",$spielerstatus); // balkan banned players } $spielerstatus = str_replace("c","g",$spielerstatus); // turkish banned players $spielerstatus = str_replace("з","g",$spielerstatus); // russian banned players $spielerstatus = str_replace("v","u",$spielerstatus); // english+spanish+dutch+french+italian+greek+korean+romanian+japanese+chinese+finnish vacation mode $spielerstatus = str_replace("o","u",$spielerstatus); // balkan vacation mode $spielerstatus = str_replace("m","u",$spielerstatus); // portugues, brazilian vacation mode $spielerstatus = str_replace("t","u",$spielerstatus); // turkish vacation players $spielerstatus = str_replace("РО","u",$spielerstatus); // russian vacation players $spielerstatus = str_replace("z","u",$spielerstatus); // czech vacation players // noob players - de,en have "n" if ($_SESSION['lang'] != "polish") $spielerstatus = str_replace("d","n",$spielerstatus); // french+italian+spanish noob players if ($_SESSION['lang'] == "swedish") { $spielerstatus = str_replace("k","n",$spielerstatus); // swedish noob players $spielerstatus = str_replace("s","u",$spielerstatus); // swedish vacation players $spielerstatus = str_replace("b","g",$spielerstatus); // swedish banned players } $spielerstatus = str_replace("z","n",$spielerstatus); // dutch+turkish noob players $spielerstatus = str_replace("f","n",$spielerstatus); // portugues noob players $spielerstatus = str_replace("н","n",$spielerstatus); // russian + bulgarian noob players $spielerstatus = str_replace("в","u",$spielerstatus); // bulgarian vacation mode $spielerstatus = str_replace("б","g",$spielerstatus); // bulgarian banned players if ($_SESSION['lang'] == "balkan" || $_SESSION['lang'] == "polish") // s is strong or "stark" in english and german $spielerstatus = str_replace("s","n",$spielerstatus); // balkan+polish noob players if ($_SESSION['lang'] == "danish") // danish vacation mode $spielerstatus = str_replace("f","u",$spielerstatus); if ($_SESSION['lang'] == "danish") // portugues noob players $spielerstatus = str_replace("f","n",$spielerstatus); if ($_SESSION['lang'] == "spanish") // s is strong or "stark" in english and german $spielerstatus = str_replace("s","g",$spielerstatus); // spanish banned players if ($_SESSION['lang'] == "turkish") // g is banned in german and polish $spielerstatus = str_replace("g","s",$spielerstatus); // turkish strong players mark so (otherwise they would be "banned") $spielerstatus = preg_replace('/[^iIugn]/i','', $spielerstatus); $playerstatus_noob = (strpos($spielerstatus,"n") === false) ? 'false' : 'true'; $playerstatus_vacation = (strpos($spielerstatus,"u") === false) ? 'false' : 'true'; $playerstatus_banned = (strpos($spielerstatus,"g") === false) ? 'false' : 'true'; $playerstatus_inactive = (strpos($spielerstatus,"i") === false) ? 'false' : 'true'; $playerstatus_long_inactive = (strpos($spielerstatus,"I") === false) ? 'false' : 'true'; $spielername = trim(substr($spielername,0,$pos)); } } $infoarray['['.$galaxie.":".$system.":".$planetnummer."]"] = array( "galaxie" => $galaxie, "system" => $system, "planetnummer" => $planetnummer, "ally" => $ally, "planetname" => $planetname, "playername" => $spielername, "playerstatus_noob" => $playerstatus_noob, "playerstatus_vacation" => $playerstatus_vacation, "playerstatus_banned" => $playerstatus_banned, "playerstatus_inactive" => $playerstatus_inactive, "playerstatus_long_inactive" => $playerstatus_long_inactive, ); $infoarray['['.$galaxie.":".$system.":".$planetnummer."]"]['moon'] = (isset($mond) && $mond == 1) ? "true" : "false"; // check if alliance_id is already known if (!isset($this->alliance_names_2_ids[strtolower($ally)]) && !empty($ally)) { array_push($allynames,$ally); } // check if player is already known if (!isset($this->player_names_2_ids[strtolower($spielername)]) && !empty($spielername)) { array_push($playernames,array("name" => $spielername, "ally" => $ally, "playerstatus_noob" => $playerstatus_noob, "playerstatus_vacation" => $playerstatus_vacation, "playerstatus_banned" => $playerstatus_banned, "playerstatus_inactive" => $playerstatus_inactive, "playerstatus_long_inactive" => $playerstatus_long_inactive )); } } // Zusatzinfos sammeln // new english $galastring = str_replace("ranked","Rank",$galastring); // deutsch => englisch erst jetzt, um keine Daten zu verfälschen bei Allynamen, Spielernamen sowie Planetname $galastring = str_replace("Allianz ","Alliance ",$galastring); // Leerzeichen ist wichtig !!! $galastring = str_replace("Platz","Rank",$galastring); $galastring = str_replace("Spieler ","Player ",$galastring); //$galastring = str_replace("Planet ","Planet ",$galastring); $galastring = str_replace("Eigenschaften","Properties",$galastring); $galastring = str_replace("Ressourcen","Resources",$galastring); $galastring = str_replace("Tage Inaktiv I","days inactive I",$galastring); // spanisch => englisch $galastring = str_replace("Alianza ","Alliance ",$galastring); // Leerzeichen ist wichtig !!! $galastring = str_replace("posición","Rank",$galastring); $galastring = str_replace("Jugador ","Player ",$galastring); $galastring = str_replace("Planeta ","Planet ",$galastring); $galastring = str_replace("Propiedades","Properties",$galastring); $galastring = str_replace("Recursos","Resources",$galastring); $galastring = str_replace("Inactivo 28 días I","days inactive I",$galastring); // holländisch => englisch $galastring = str_replace("Alliantie ","Alliance ",$galastring); // Leerzeichen ist wichtig !!! $galastring = str_replace("Rang","Rank",$galastring); $galastring = str_replace("Speler ","Player ",$galastring); $galastring = str_replace("Planeet ","Planet ",$galastring); $galastring = str_replace("Eigenschappen","Properties",$galastring); $galastring = str_replace("Grondstoffen","Resources",$galastring); $galastring = str_replace("28 dagen inactief I","days inactive I",$galastring); $galastring = str_replace("28 dagen inactief I","days inactive I",$galastring); // balkan => englisch $galastring = str_replace("Savez ","Alliance ",$galastring); // Leerzeichen ist wichtig !!! $galastring = str_replace("poziciji","Rank",$galastring); $galastring = str_replace("Igrac ","Player ",$galastring); $galastring = str_replace("Planeta ","Planet ",$galastring); $galastring = str_replace("Osobine","Properties",$galastring); $galastring = str_replace("Resursi","Resources",$galastring); $galastring = str_replace("28 dana inaktivan I","days inactive I",$galastring); $galastring = str_replace("28 dana inaktivan I","days inactive I",$galastring); // french => english $galastring = str_replace("Alliance ","Alliance ",$galastring); // Leerzeichen ist wichtig !!! $galastring = str_replace("classé","Rank",$galastring); $galastring = str_replace("Joueur ","Player ",$galastring); $galastring = str_replace("Planète ","Planet ",$galastring); $galastring = str_replace("Propriétés","Properties",$galastring); $galastring = str_replace("Ressources","Resources",$galastring); $galastring = str_replace("Inactif 28 jours I","days inactive I",$galastring); $galastring = str_replace("Inactif 28 jours I","days inactive I",$galastring); // portugues and brazilian => english $galastring = str_replace("Aliança ","Alliance ",$galastring); // Leerzeichen ist wichtig !!! $galastring = str_replace("posição","Rank",$galastring); $galastring = str_replace("Jogador ","Player ",$galastring); $galastring = str_replace("Planeta ","Planet ",$galastring); $galastring = str_replace("Propriedades","Properties",$galastring); $galastring = str_replace("Recursos","Resources",$galastring); $galastring = str_replace("28 dias inactivo I","days inactive I",$galastring); $galastring = str_replace("28 dias inactivo I","days inactive I",$galastring); // polish => english $galastring = str_replace("Sojusz ","Alliance ",$galastring); // Leerzeichen ist wichtig !!! $galastring = str_replace("miejscu","Rank",$galastring); $galastring = str_replace("Gracz ","Player ",$galastring); $galastring = str_replace("Planeta ","Planet ",$galastring); $galastring = str_replace("Właściwości","Properties",$galastring); $galastring = str_replace("Surowce","Resources",$galastring); $galastring = str_replace("28 dni nieaktywności I","days inactive I",$galastring); $galastring = str_replace("28 dni nieaktywności I","days inactive I",$galastring); // italian => english $galastring = str_replace("Alleanza ","Alliance ",$galastring); // Leerzeichen ist wichtig !!! $galastring = str_replace("posizione","Rank",$galastring); $galastring = str_replace("Giocatore ","Player ",$galastring); $galastring = str_replace("Pianeta ","Planet ",$galastring); $galastring = str_replace("Proprietà","Properties",$galastring); $galastring = str_replace("Risorse","Resources",$galastring); $galastring = str_replace("Inattivo da 28 giorni I","days inactive I",$galastring); $galastring = str_replace("Inattivo da 28 giorni I","days inactive I",$galastring); // turkish => english $galastring = str_replace("ittifak ","Alliance ",$galastring); // Leerzeichen ist wichtig !!! $galastring = str_replace("siradaki","Rank",$galastring); $galastring = str_replace("oyuncu ","Player ",$galastring); $galastring = str_replace("Gezegen ","Planet ",$galastring); $galastring = str_replace(" Özellikler","Properties",$galastring); $galastring = str_replace(" Hammadeler","Resources",$galastring); $galastring = str_replace("28 gündür kullanilmiyor I","days inactive I",$galastring); $galastring = str_replace("28 gündür kullanilmiyor I","days inactive I",$galastring); // danish $galastring = str_replace("Alliance ","Alliance ",$galastring); // Leerzeichen ist wichtig !!! $galastring = str_replace("plads nr","Rank",$galastring); // Alliances have extra text $galastring = str_replace("plads","Rank",$galastring); $galastring = str_replace("Spiller ","Player ",$galastring); $galastring = str_replace("Planet ","Planet ",$galastring); $galastring = str_replace("Egenskaber","Properties",$galastring); $galastring = str_replace("Ressourcen","Resources",$galastring); $galastring = str_replace("28 døgn Inaktiv I","days inactive I",$galastring); $galastring = str_replace("28 døgn Inaktiv I","days inactive I",$galastring); // russian $galastring = str_replace("Альянс ","Alliance ",$galastring); // Leerzeichen ist wichtig !!! $galastring = str_replace("Место в рейтинге - ","Rank",$galastring); $galastring = str_replace("Игрок ","Player ",$galastring); $galastring = str_replace("Планета ","Planet ",$galastring); $galastring = str_replace("Свойства","Properties",$galastring); $galastring = str_replace("Ресурсы","Resources",$galastring); $galastring = str_replace("неактивен 28 дней I","days inactive I",$galastring); $galastring = str_replace("неактивен 28 дней I","days inactive I",$galastring); // swedish $galastring = str_replace("Allians ","Alliance ",$galastring); // Leerzeichen ist wichtig !!! $galastring = str_replace("rankad","Rank",$galastring); $galastring = str_replace("Spelare ","Player ",$galastring); $galastring = str_replace("Planet ","Planet ",$galastring); $galastring = str_replace("Ordentligt","Properties",$galastring); $galastring = str_replace("Resurser","Resources",$galastring); $galastring = str_replace("28 Dagars Inaktivitet I","days inactive I",$galastring); $galastring = str_replace("28 Dagars Inaktivitet I","days inactive I",$galastring); // greek $galastring = str_replace("Συμμαχία ","Alliance ",$galastring); // Leerzeichen ist wichtig !!! $galastring = str_replace("κατάταξη","Rank",$galastring); // Playername is the start of the line, so a replacement is needed $galastring = preg_replace("/([\w]+)\s(στην\sκατάταξη)\s(\d+)/","Player $1 Rank $3",$galastring); $galastring = str_replace("Πλανήτης ","Planet ",$galastring); $galastring = str_replace("Ιδιότητες","Properties",$galastring); $galastring = str_replace("Πόροι","Resources",$galastring); $galastring = str_replace("28 μέρες ανενεργός I","days inactive I",$galastring); $galastring = str_replace("28 μέρες ανενεργός I","days inactive I",$galastring); // romanian $galastring = str_replace("Alianta ","Alliance ",$galastring); // Leerzeichen ist wichtig !!! $galastring = str_replace("clasata","Rank",$galastring); $galastring = preg_replace("/([\w]+)\s(clasat pe)\s(\d+)/","Player $1 Rank $3",$galastring); $galastring = str_replace("Planeta ","Planet ",$galastring); $galastring = str_replace("Proprietati","Properties",$galastring); $galastring = str_replace("Resurse","Resources",$galastring); $galastring = str_replace("28 de zile inactiv I","days inactive I",$galastring); $galastring = str_replace("28 de zile inactiv I","days inactive I",$galastring); // korean $galastring = str_replace("Allians ","Alliance ",$galastring); // Leerzeichen ist wichtig !!! $galastring = str_replace("rankad","Rank",$galastring); $galastring = str_replace("Spelare ","Player ",$galastring); $galastring = str_replace("Planet ","Planet ",$galastring); $galastring = str_replace("Ordentligt","Properties",$galastring); $galastring = str_replace("Resurser","Resources",$galastring); $galastring = str_replace("28 Dagars Inaktivitet I","days inactive I",$galastring); $galastring = str_replace("28 Dagars Inaktivitet I","days inactive I",$galastring); // hungarian + czech not added (since 0.77 these things are not copied any more) $galastring = str_replace("\r","",$galastring); // Windows Linebreaks zu Linux Linebreaks konvertieren $galastring = trim(substr($galastring,strpos($galastring,"days inactive I")+strlen("days inactive I"))); $temp = array(); $line = explode("\n",$galastring); $j = 0; foreach ($line as $var) { // Allyrank $var = trim($var); if ((substr($var,0,8) == "Alliance" && $_SESSION['lang'] != "turkish") || ($_SESSION['lang'] == "turkish" && substr($var,-18) == " üyesi ile koruyor")) { // wont work with turkish $pos = strpos($var,"Rank"); $var = trim(substr($var,$pos+strlen("Rank")+1)); $tmp = explode(" ",$var); if ((isset($temp['allyrank']) || isset($temp['members']) || isset($temp['playerrank'])) && isset($temp['position'])) { // Alten Eintrag sammeln if (isset($temp['moon'])) $infoarray[$temp['position']]['moon'] = $temp['moon']; // IE !!! if (isset($temp['allyrank'])) $infoarray[$temp['position']]['allyrank'] = $temp['allyrank']; if (isset($temp['members'])) $infoarray[$temp['position']]['members'] = $temp['members']; if (isset($temp['playerrank'])) $infoarray[$temp['position']]['playerrank'] = $temp['playerrank']; if (isset($temp['moonsize'])) $infoarray[$temp['position']]['moonsize'] = $temp['moonsize']; if (isset($temp['metal'])) $infoarray[$temp['position']]['metal'] = $temp['metal']; if (isset($temp['crystal'])) $infoarray[$temp['position']]['crystal'] = $temp['crystal']; // Array für neuen Eintrag leeren unset($temp); $temp = array(); } // should not work for turkish if (isset($tmp[0]) && is_numeric(str_replace("#","",$tmp[0]))) $temp['allyrank'] = str_replace("#","",$tmp[0]); if (isset($tmp[2]) && is_numeric(str_replace("#","",$tmp[2]))) $temp['members'] = str_replace("#","",$tmp[2]); } // Player MACHINE on rank 73 || MACHINE ranked 73 (new version) if ((substr($var,0,6) == "Player") || ($_SESSION['lang'] == "turkish" && substr($var,-6) == "Player") || ($_SESSION['lang'] == "english" && !empty($var) && preg_replace("/(\w)+\sRank\s(\d)+/","",$var) == "")) { // for new english version which has not always Player ... at first! // Spielerplatzierung ermitteln $tmp = explode(" ",$var); if (isset($temp['playerrank']) && isset($temp['position'])) { // Alten Eintrag sammeln - greift hier, wenn der Spieler Allylos ist if (isset($temp['moon'])) $infoarray[$temp['position']]['moon'] = $temp['moon']; // IE !!! if (isset($temp['allyrank'])) $infoarray[$temp['position']]['allyrank'] = $temp['allyrank']; if (isset($temp['members'])) $infoarray[$temp['position']]['members'] = $temp['members']; if (isset($temp['playerrank'])) $infoarray[$temp['position']]['playerrank'] = $temp['playerrank']; if (isset($temp['moonsize'])) $infoarray[$temp['position']]['moonsize'] = $temp['moonsize']; if (isset($temp['metal'])) $infoarray[$temp['position']]['metal'] = $temp['metal']; if (isset($temp['crystal'])) $infoarray[$temp['position']]['crystal'] = $temp['crystal']; // Array für neuen Eintrag leeren unset($temp); $temp = array(); } if (is_numeric($tmp[count($tmp)-1])) // wont work with turkish! $temp['playerrank'] = $tmp[count($tmp)-1]; else $temp['playerrank'] = 0; } // Planet Schweiz [1:1:12] if (substr($var,0,6) == "Planet") { // Position ermitteln $tmp = explode(" ",$var); $temp['position'] = trim($tmp[count($tmp)-1]); } if (substr($var,0,10) == "Properties") { // Mondgröße ermitteln // Prüfen ob IE (keine \t sondern nur Leerzeichen) if (strpos($line[$j+1],"\t") === false) { // IE Handling $tmp = explode(" ",$line[$j+1]); $temp['moonsize'] = str_replace(".","",$tmp[1]); $temp['moon'] = "true"; } else { // Mozilla und co. $tmp = explode("\t",$line[$j+1]); $temp['moonsize'] = str_replace(".","",$tmp[1]); } } if (substr($var,0,10) == "Resources:") { // Trümmerfeld ermitteln // Prüfen ob IE (keine \t sondern nur Leerzeichen) if (strpos($line[$j+1],"\t") === false) { // IE Handling $tmp = explode(" ",$line[$j+1]); $temp['metal'] = str_replace(".","",$tmp[1]); $tmp = explode(" ",$line[$j+2]); $temp['crystal'] = str_replace(".","",$tmp[1]); } else { // Mozilla und co. $tmp = explode("\t",$line[$j+1]); $temp['metal'] = str_replace(".","",$tmp[1]); $tmp = explode("\t",$line[$j+2]); $temp['crystal'] = str_replace(".","",$tmp[1]); } } $j++; } if ((isset($temp['moon']) || isset($temp['allyrank']) || isset($temp['members']) || isset($temp['playerrank']) || isset($temp['moonsize']) || isset($temp['metal']) || isset($temp['crystal']))&& isset($temp['position'])) { // Letzten Beitrag speichern, falls er existiert if (isset($temp['moon'])) $infoarray[$temp['position']]['moon'] = $temp['moon']; // IE !!! if (isset($temp['allyrank'])) $infoarray[$temp['position']]['allyrank'] = $temp['allyrank']; if (isset($temp['members'])) $infoarray[$temp['position']]['members'] = $temp['members']; if (isset($temp['playerrank'])) $infoarray[$temp['position']]['playerrank'] = $temp['playerrank']; if (isset($temp['moonsize'])) $infoarray[$temp['position']]['moonsize'] = $temp['moonsize']; if (isset($temp['metal'])) $infoarray[$temp['position']]['metal'] = $temp['metal']; if (isset($temp['crystal'])) $infoarray[$temp['position']]['crystal'] = $temp['crystal']; } // DB Verbindung erstellen mysql_connect($this->dbhost, $this->dbusername, $this->dbpassword) or die(PARSER_ERROR3); mysql_select_db($this->dbname) or die(PARSER_ERROR2); // determine new IDs for alliance names if (count($allynames) > 0) { $this->_set_alliance_array($allynames); } // determine new IDs for player names if (count($playernames) > 0) { $this->_set_player_array($playernames); } // Galaxiedaten eintragen $allystats = array(); $playerstats = array(); if (count($infoarray) > 1) foreach ($infoarray as $data) { // Allystats if (isset($data['allyrank']) && isset($data['ally']) && isset($data['members']) && !empty($data['ally'])) array_push($allystats,array($data['ally'],$data['allyrank'],$data['members'])); // Spielerstats if (isset($data['playerrank']) && isset($data['playername'])) $playerstats[$data['playername']] = $data['playerrank']; $alliance_id = (isset($this->alliance_names_2_ids[strtolower($data['ally'])]["id"])) ? $this->alliance_names_2_ids[strtolower($data['ally'])]["id"] : 0; $player_id = (isset($this->player_names_2_ids[strtolower($data['playername'])]["id"])) ? $this->player_names_2_ids[strtolower($data['playername'])]["id"] : 0; // Galaxieinfos if ($data['galaxie'] > 0 && $data['galaxie'] < 51 && $data['system'] > 0 && $data['system'] < 500 && $data['planetnummer'] > 0 && $data['planetnummer'] < 16) { $query = "REPLACE $this->tablename ". "SET galaxy='".$data['galaxie']."',system='".$data['system']."',planet='".$data['planetnummer']."', moon='".$data['moon']."', ". "planetname='".$data['planetname']."',player_id='".$player_id."', ". "last_update=NOW(), "; if (isset($data['moonsize'])) $query .= "moonsize='".$data['moonsize']."', "; if (isset($data['metal'])) $query .= "metal='".$data['metal']."', "; if (isset($data['crystal'])) $query .= "crystal='".$data['crystal']."', "; $query .= "user_id='".$_SESSION['s_userid']."' "; // extra, damit kein "," am Ende stehen kann if (!$return) { mysql_query($query) or die($query." ".mysql_error()); } else { $returnarray = array_push($query); } } } echo "$galaxie:$system ".PARSER_INFO1."
"; if ($return) return $returnarray; else return true; } function _set_alliance_array($alliance_name_array) { // determine allynames with IDs $query = "SELECT distinct(id),allyname,diplomatic_status FROM $this->allytable WHERE allyname IN ('".implode("','", $alliance_name_array)."')"; $res = mysql_query($query) or die($query." ".mysql_error()); while ($line = mysql_fetch_object($res)) { $this->alliance_names_2_ids[strtolower($line->allyname)] = array(); $this->alliance_names_2_ids[strtolower($line->allyname)]["id"] = $line->id; $this->alliance_names_2_ids[strtolower($line->allyname)]["diplomatic_status"] = $line->diplomatic_status; // delete allyname from array } foreach($alliance_name_array as $key => $allyname) { if (isset($this->alliance_names_2_ids[strtolower($allyname)]) || empty($allyname)) continue; // skip the entry if it already exists at buffer // insert missing alliances $query = "INSERT INTO $this->allytable (allyname) VALUES ('".mysql_real_escape_string($allyname)."')"; $res = mysql_query($query) or die($query." ".mysql_error()); // store alliance -> id relation $this->alliance_names_2_ids[strtolower($allyname)] = array(); $this->alliance_names_2_ids[strtolower($allyname)]["id"] = mysql_insert_id(); $this->alliance_names_2_ids[strtolower($allyname)]["diplomatic_status"] = "nothing"; } } function _set_player_array($player_name_array) { // array("name" => $spielername, "ally" => $ally, "status" => $spielerstatus ) $playernames = array(); foreach ($player_name_array as $key => $value) { array_push($playernames,$value["name"]); } // determine playernames with IDs $query = "SELECT distinct(id),playername,ogame_playerid FROM $this->playertable WHERE playername IN ('".implode("','", $playernames)."')"; $res = mysql_query($query) or die($query." ".mysql_error()); while ($line = mysql_fetch_object($res)) { $this->player_names_2_ids[strtolower($line->playername)]["id"] = $line->id; } foreach ($player_name_array as $key => $playername) { if (empty($playername["name"])) continue; // skip entry if it is empty if (isset($this->player_names_2_ids[strtolower($playername["name"])])) { if (!isset($this->player_names_2_ids[strtolower($playername["name"])]["ally"])) { $player_dipl_status = (isset($playername["ally"]) && isset($this->alliance_names_2_ids[strtolower($playername["ally"])]["diplomatic_status"])) ? $this->alliance_names_2_ids[strtolower($playername["ally"])]["diplomatic_status"] : "nothing"; $player_alliance_id = (isset($playername["ally"]) && isset($this->alliance_names_2_ids[strtolower($playername["ally"])]["id"])) ? $this->alliance_names_2_ids[strtolower($playername["ally"])]["id"] : 0; $query = "UPDATE $this->playertable SET noob='".mysql_real_escape_string($playername["playerstatus_noob"])."',vacation='".mysql_real_escape_string($playername["playerstatus_vacation"])."',banned='".mysql_real_escape_string($playername["playerstatus_banned"])."',inactive='".mysql_real_escape_string($playername["playerstatus_inactive"])."',long_inactive='".mysql_real_escape_string($playername["playerstatus_long_inactive"])."', alliance_id='".mysql_real_escape_string($player_alliance_id)."', diplomatic_status='".mysql_real_escape_string($player_dipl_status)."' ". "WHERE playername='".mysql_real_escape_string($playername["name"])."'"; $res = mysql_query($query) or die($query." ".mysql_error()); } else { // playerdata was already updated and is okay at buffer } } else { // player is not at database yet and must be inserted completely // check diplomatic status of its alliance $player_dipl_status = (isset($playername["ally"]) && isset($this->alliance_names_2_ids[strtolower($playername["ally"])]["diplomatic_status"])) ? $this->alliance_names_2_ids[strtolower($playername["ally"])]["diplomatic_status"] : "nothing"; $player_alliance_id = (isset($playername["ally"]) && isset($this->alliance_names_2_ids[strtolower($playername["ally"])]["id"])) ? $this->alliance_names_2_ids[strtolower($playername["ally"])]["id"] : 0; $query = "INSERT INTO $this->playertable (playername, noob,vacation,banned,inactive,long_inactive, alliance_id, diplomatic_status) VALUES ('".mysql_real_escape_string($playername["name"])."','".mysql_real_escape_string($playername["playerstatus_noob"])."','".mysql_real_escape_string($playername["playerstatus_vacation"])."','".mysql_real_escape_string($playername["playerstatus_banned"])."','".mysql_real_escape_string($playername["playerstatus_inactive"])."','".mysql_real_escape_string($playername["playerstatus_long_inactive"])."','".mysql_real_escape_string($player_alliance_id)."','".mysql_real_escape_string($player_dipl_status)."')"; $res = mysql_query($query) or die($query." ".mysql_error()); // store player -> id relation $this->player_names_2_ids[strtolower($playername["name"])]["id"] = mysql_insert_id(); $this->player_names_2_ids[strtolower($playername["name"])]["ally"] = $playername["ally"]; // just needed to show that it was currently added } } } /** * @return boolean * @param String $tablename Name der Tabelle mit den Downloads * @desc Setzt den Tabellennamen für die Datenbankverbindung */ function _set_tablename($tablename) { if (!empty($tablename)) { $this->tablename = $tablename; return true; } else { $this->error = "Der Tabellenname ist leer!"; return false; } } /** * @return boolean * @param String $dbusername Datenbanknutzername * @desc Setzt den Username für die Datenbankverbindung */ function _set_dbusername($dbusername) { if (!empty($dbusername)) { $this->dbusername = $dbusername; return true; } else { $this->error = "Der Username ist leer!"; return false; } } /** * @return boolean * @param String $dbpassword Datenbankpasswort * @desc Setzt das Passwort für die Datenbankverbindungen */ function _set_dbpassword($dbpassword) { $this->dbpassword = $dbpassword; return true; } /** * @return boolean * @param String $dbname Datenbankname * @desc Setzt den Namen der zu verwendenden Datenbank */ function _set_dbname($dbname) { if (!empty($dbname)) { $this->dbname = $dbname; return true; } else { $this->error = "Der Datenbankname ist leer!"; return false; } } /** * @return boolean * @param String $dbhost Datenbankadresse * @desc Setzt die Host-Adresse für die Datenbank */ function _set_dbhost($dbhost) { $this->dbhost = $dbhost; return true; } /** * @return boolean * @desc Testet ob die Verbindung zur Datenbank funktioniert */ function _db_connection_works() { mysql_connect($this->dbhost, $this->dbusername, $this->dbpassword) or die(PARSER_ERROR3); mysql_select_db($this->dbname) or die(PARSER_ERROR2); return true; } } ?>