00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
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
00032 $this->oLog->write( 'Gilden-Import', 6 );
00033
00034
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
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
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
00066 $this->oDB->query( "UPDATE ".$this->oDB->tblPlayer." SET guild_id=1 WHERE guild_id='".$intGuild."';" );
00067 }
00068
00069
00070 $strData = preg_replace("-\[GILDE=(.*)\]-Uis", '', $strData);
00071 $strRegRace = 'Menschen|Elfen|Zwerge|Orks';
00072 $strRegType = 'Feldherr|Händler|Philosoph';
00073
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ädte: '.($this->intTownsAdded + $this->intTownsUpdated).'<br />Spieler added: '.$this->intPlayerAdded.'<br />Spieler updated: '.$this->intPlayerUpdated.'<br />Städte added: '.$this->intTownsAdded.'<br />Stä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
00091 $strTowns = trim( $strTowns );
00092
00093 $intRace = 0;
00094 foreach( $aRaces AS $intId => $strRaceName )
00095 {
00096 if( $strRaceName == $strRace ) $intRace = $intId;
00097 }
00098
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
00115 return;
00116 }
00117 $strTown = trim( $strTown );
00118 if( $intTime == 0 )
00119 {
00120 $intTime = time();
00121 }
00122
00123 $sqlPlayer = $this->oDB->query( "SELECT `player_id`, `name` FROM `".$this->oDB->tblPlayer."` WHERE `name`='$strName';" );
00124 $aTown = $this->oTown->get( $x, $y );
00125
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
00154 if( $booUpdate )
00155 {
00156 $this->oDB->query( $strQuery );
00157 }
00158 $this->intPlayerUpdated++;
00159 }
00160 else
00161 {
00162
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
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
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
00188 $intTown = $this->oTown->add( $x, $y, $strTown, $intPlayer, 'Autocreated on '.date('d.m.Y H:i')."\n".$strComment );
00189 $this->intTownsAdded++;
00190
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
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
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 }