Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

importguild.php

Go to the documentation of this file.
00001 <?php
00002 /***************************************************************************
00003  This program is free software; you can redistribute it and/or
00004  modify it under the terms of the GNU General Public License
00005  as published by the Free Software Foundation; either version 2
00006  of the License, or (at your option) any later version.
00007 
00008  This program is distributed in the hope that it will be useful,
00009  but WITHOUT ANY WARRANTY; without even the implied warranty of
00010  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011  GNU General Public License for more details.
00012 
00013  You should have received a copy of the GNU General Public License
00014  along with this program; if not, write to the Free Software
00015  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00016  ***************************************************************************/
00017 
00021 class ImportGuild extends ImportBase
00022 {
00023     var $intPlayerUpdated = 0;
00024     var $intPlayerAdded   = 0;
00025     var $intTownsUpdated  = 0;
00026     var $intTownsAdded    = 0;
00027     var $intFieldsAdded   = 0;
00028 
00029     function import( $strData )
00030     {
00031         // Log-Eintrag schreiben
00032         $this->oLog->write( 'Gilden-Import', 6 );
00033 
00034         // Gildenkoords importieren, falls vorhanden
00035         if( $strData == '' || strlen( $strData ) < 40 )
00036         {
00037             return false;
00038         }
00039 
00040         $strData = str_replace( "\n", ' ', $strData );
00041         $strData = str_replace( "\r", ' ', $strData );
00042         $strData = str_replace( "\t", ' ', $strData );
00043         $strGuildTag = '';
00044         if( preg_match( "-\[GILDE=(.*)\]-Uis", $strData, $aMatches ) )
00045         {
00046             $strGuildTag = $aMatches[1];
00047         }
00048         if( $strGuildTag == '' || $strGuildTag == 'gildentag' )
00049         {
00050             return false;
00051         }
00052 
00053         // existiert Gilde?
00054         $sqlGuild = $this->oDB->query( "SELECT `guild_id` FROM `".$this->oDB->tblGuild."` WHERE `tag`='$strGuildTag';" );
00055         if( $this->oDB->num_rows( $sqlGuild ) == 0 )
00056         {
00057             // Gilde existiert noch nicht... -> anlegen
00058             $this->oDB->query( "INSERT INTO `".$this->oDB->tblGuild."` SET `tag`='$strGuildTag';" );
00059             $intGuild = $this->oDB->insert_id();
00060         }
00061         else
00062         {
00063             $aGuild = $this->oDB->fetch_assoc( $sqlGuild );
00064             $intGuild = $aGuild['guild_id'];
00065             // Alle Gildenmitglieder freisetzen, sie werden später wieder hinzugefügt
00066             $this->oDB->query( "UPDATE ".$this->oDB->tblPlayer." SET guild_id=1 WHERE guild_id='".$intGuild."';" );
00067         }
00068 
00069         // GildenTag rauslöschen
00070         $strData = preg_replace("-\[GILDE=(.*)\]-Uis", '', $strData);
00071         $strRegRace = 'Menschen|Elfen|Zwerge|Orks';
00072         $strRegType = 'Feldherr|Händler|Philosoph';
00073         //beliebg viele Whitespaces (WS), Name des Spielers, WS, Gildenrang, WS, Rasse, WS, beliebig viele Staedte, WS, Punktzahl
00074         preg_replace("/\s{0,}([0-9a-zA-Z_-]{1,})\s{1,}.*[\s]*($strRegRace)[\s]*($strRegType)[\s]*(.*)\s{1,}\d{2,6}\s{1,}/Uies", '$this->parse_data("$1", "$2", "$3", "$4", "$intGuild")', $strData);
00075         $strMessage = 'St&auml;dte: '.($this->intTownsAdded + $this->intTownsUpdated).'<br />Spieler added: '.$this->intPlayerAdded.'<br />Spieler updated: '.$this->intPlayerUpdated.'<br />St&auml;dte added: '.$this->intTownsAdded.'<br />St&auml;dte updated: '.$this->intTownsUpdated.'<br />Felder added: '.$this->intFieldsAdded;
00076         return array( 'worldmap.php', $strMessage );
00077     }
00078 
00087     function parse_data( $strName, $strRace, $strType, $strTowns, $intGuild )
00088     {
00089         global $aRaces, $aTypes;
00090         // leerzeichen vor und nach Städten entfernen
00091         $strTowns = trim( $strTowns );
00092         // Rassenid holen
00093         $intRace = 0;
00094         foreach( $aRaces AS $intId => $strRaceName )
00095         {
00096             if( $strRaceName == $strRace )  $intRace = $intId;
00097         }
00098         // Typid holen
00099         $intType = 0;
00100         foreach( $aTypes AS $intId => $strTypeName)
00101         {
00102             if( $strTypeName == $strType ) $intType = $intId;
00103         }
00104         @preg_replace("-((?U).*)\s*(\d{1,}:\d{1,4})-ies", '$this->save_data("$1", "$2", "$strName", "$intRace", "$intType", "$intGuild", "", "")', $strTowns );
00105     }
00106 
00107     function save_data( $strTown, $strCoords, $strName, $intRace, $intType, $intGuild, $strComment, $intTime )
00108     {
00109         $aCoords = explode( ':', $strCoords );
00110         $x = intval( $aCoords[0] );
00111         $y = intval( $aCoords[1] );
00112         if( !$this->oUser->check( $x, $y ) )
00113         {
00114             // user has no access to this field
00115             return;
00116         }
00117         $strTown = trim( $strTown );
00118         if( $intTime == 0 )
00119         {
00120             $intTime = time();
00121         }
00122         // Stadt/spieler schon vorhanden
00123         $sqlPlayer = $this->oDB->query( "SELECT `player_id`, `name` FROM `".$this->oDB->tblPlayer."` WHERE `name`='$strName';" );
00124         $aTown     = $this->oTown->get( $x, $y );
00125         // Spieler prüfen
00126         if( $this->oDB->num_rows( $sqlPlayer ) != 0 )
00127         {
00128             $aPlayer = $this->oDB->fetch_assoc( $sqlPlayer );
00129             $intPlayer = $aPlayer['player_id'];
00130 
00131             $booUpdate = false;
00132             $strQuery = "UPDATE `".$this->oDB->tblPlayer."` SET ";
00133             if( $intRace != 0 )
00134             {
00135                 if( $booUpdate ) $strQuery .= ', ';
00136                 $strQuery .= "`race`='$intRace'";
00137                 $booUpdate = true;
00138             }
00139             if( $intType != 0 )
00140             {
00141                 if( $booUpdate ) $strQuery .= ', ';
00142                 $strQuery .= "`typ`='$intType'";
00143                 $booUpdate = true;
00144             }
00145             if( $intGuild != 1 )
00146             {
00147                 if( $booUpdate ) $strQuery .= ', ';
00148                 $strQuery .= "`guild_id`='$intGuild'";
00149                 $booUpdate = true;
00150             }
00151             $strQuery .= $GLOBALS['strUpdateString']." WHERE `player_id`='$intPlayer' LIMIT 1;";
00152 
00153             // spieler updaten
00154             if( $booUpdate )
00155             {
00156                 $this->oDB->query( $strQuery );
00157             }
00158             $this->intPlayerUpdated++;
00159         }
00160         else
00161         {
00162             // neuen Spieler anlegen
00163             if( $strName == '' )
00164             {
00165                 die( 'Fehler... Parsing Error bei Koords '.$x.':'.$y.'<br />' );
00166             }
00167             $this->oDB->query( "INSERT INTO `".$this->oDB->tblPlayer."` SET `name`='$strName', `race`='$intRace', `typ`='$intType', `guild_id`='$intGuild'".$GLOBALS['strUpdateString'].$GLOBALS['strCreatedString'].";" );
00168             $intPlayer = $this->oDB->insert_id();
00169             $this->intPlayerAdded++;
00170         }
00171         // Stadt prüfen
00172         if( !empty( $aTown ) )
00173         {
00174             $intTown = intval( $aTown['town_id'] );
00175             $intTownUpdate = $aTown['last_update'];
00176             $strComment = ( $strComment != '' ) ? 'Imported Comment: ' . $strComment . "\n" : '';
00177 
00178             if( $intTown > 0 && $intTime > $intTownUpdate )
00179             {
00180                 // Stadt updaten
00181                 $this->oTown->set( $intTown, $strTown, $intPlayer, -1, -1, 'Script update on '.date('d.m.Y H:i')."\n".$strComment, true );
00182                 $this->intTownsUpdated++;
00183             }
00184         }
00185         else
00186         {
00187             // neue Stadt anlegen
00188             $intTown = $this->oTown->add( $x, $y, $strTown, $intPlayer, 'Autocreated on '.date('d.m.Y H:i')."\n".$strComment );
00189             $this->intTownsAdded++;
00190             // prüfen, ob das Feld
00191             $sqlResult = $this->oDB->query( "SELECT * FROM `".$this->oDB->tblMap."` WHERE `x`='$x' AND `y`='$y'" );
00192             if( $this->oDB->num_rows( $sqlResult ) == 0 )
00193             {
00194                 // terrain und details fehlen
00195                 $this->oDB->query("REPLACE INTO `".$this->oDB->tblMapData."` SET `building`='-1', `x`='$x', `y`='$y'".$GLOBALS['strUpdateString'].";");
00196                 $this->oDB->query("INSERT INTO `".$this->oDB->tblMap."` SET `terrain`='0', `x`='$x', `y`='$y';");
00197                 $this->intFieldsAdded++;
00198             }
00199             else
00200             {
00201                 $sqlResult = $this->oDB->query( "SELECT * FROM `".$this->oDB->tblMapData."` WHERE `x`='$x' AND `y`='$y'" );
00202                 if( $this->oDB->num_rows( $sqlResult ) == 0 )
00203                 {
00204                     // terrain vorhanden, details fehlen
00205                     $this->oDB->query("REPLACE INTO `".$this->oDB->tblMapData."` SET `building`='-1', `x`='$x', `y`='$y'".$GLOBALS['strUpdateString'].";");
00206                     $this->intFieldsAdded++;
00207                 }
00208             }
00209         }
00210     }
00211 }

Generated on Sun May 8 19:29:45 2005 for PhpMap by  doxygen 1.4.2