00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00022 class ImportScan extends ImportBase
00023 {
00024 function import( $strData )
00025 {
00026 global $aRaces, $aTypes;
00027
00028 $strData = str_replace( "\r\n", "\n", $strData );
00029
00030
00031 $strData = str_replace( "\t", ' ', $strData );
00032
00033
00034 $strData = preg_replace( '/ +/', ' ', $strData );
00035
00036 $strData = preg_replace( "/ +\n/", "\n", $strData );
00037
00038 $intX = 0;
00039 $intY = 0;
00040 $strOwner = '';
00041 $strGuild = '';
00042 $strRace = '';
00043 $strType = '';
00044 $strTown = '';
00045 $intTownhall = 0;
00046 $intSight = 0;
00047 $spos = 0;
00048 $intType = -1;
00049 $intRace = -1;
00050 $intBuilding = 0;
00051 $intTerrain = 0;
00052
00053 $strInfo = 'Scan ' . date('d.m.Y H:i:s') . "\n".$strData;
00054
00055
00056 $this->oLog->write( 'Stadtscan-Import', 6 );
00057
00058 $source = explode( "\n", $strData );
00059 for( $x=0; $x<count( $source ); ++$x )
00060 {
00061 $strLine = $source[$x];
00062 if( ( $spos = strpos( $strLine, 'Gelände:') ) !== false )
00063 {
00064 $strTerrain = trim( substr( $strLine, $spos+8, strlen( $strLine ) ) );
00065 foreach( $GLOBALS['aTerrainText'] AS $int => $str )
00066 {
00067 if( $str == $strTerrain || $str == htmlentities( $strTerrain ) )
00068 {
00069 $intTerrain = $int;
00070 }
00071 }
00072 continue;
00073 }
00074 if( ( $spos = strpos( $strLine, 'Position:') ) !== false )
00075 {
00076 $aPosition = explode( ':', trim( substr( $strLine, $spos+9, strlen( $strLine ) ) ) );
00077 $intX = $aPosition[0];
00078 $intY = $aPosition[1];
00079 continue;
00080 }
00081 if( ( $spos = strpos( $strLine, 'Stadt:') ) !== false )
00082 {
00083 $strTown = trim( substr( $strLine, $spos+6, strlen( $strLine ) ) );
00084 continue;
00085 }
00086 if( ( $spos = strpos( $strLine, 'Herrscher:') ) !== false )
00087 {
00088 $strOwner = trim( substr( $strLine, $spos+10, strlen( $strLine ) ) );
00089 continue;
00090 }
00091 if( ( $spos = strpos( $strLine, 'Gilde:') ) !== false )
00092 {
00093 $strGuild = trim( substr( $strLine, $spos+6, strlen( $strLine ) ) );
00094
00095 $strGuild = str_replace( '[', '', str_replace( ']', '', $strGuild ) );
00096 continue;
00097 }
00098 if( ( $spos = strpos( $strLine, 'Rasse:') ) !== false )
00099 {
00100 $strRace = trim( substr( $strLine, $spos+6, strlen( $strLine ) ) );
00101
00102 foreach( $aRaces AS $id => $racename)
00103 {
00104 if( $racename == $strType || $racename == htmlentities( $strRace ) ) $intRace = $id;
00105 }
00106 $intBuilding = $intRace + 96;
00107 continue;
00108 }
00109 if( ( $spos = strpos( $strLine, 'Typus:') ) !== false )
00110 {
00111 $strType = trim( substr( $strLine, $spos+6, strlen( $strLine ) ) );
00112
00113
00114 foreach( $aTypes AS $id => $typname )
00115 {
00116 if( $typname == $strType || $typname == htmlentities( $strType ) ) $intType = $id;
00117 }
00118 continue;
00119 }
00120
00121 if( strpos( $strLine, 'Rathaus' ) !== false )
00122 {
00123 $intTownhall = 1;
00124 }
00125
00126 foreach( $GLOBALS['aSight'] AS $strBuilding => $intView )
00127 {
00128 if( $intView > $intSight && strpos( $strLine, $strBuilding ) !== false )
00129 {
00130 $intSight = $intView;
00131 }
00132 }
00133 }
00134
00135
00136 if( $intX > 0 && $intY > 0 && $intRace >= 0 && $intType >= 0 && $this->oUser->check( $intX, $intY ) && $strOwner != '' )
00137 {
00138 $intGuild = 1;
00139 if( $strGuild != '' )
00140 {
00141 $sqlGuild = $this->oDB->query( "SELECT `guild_id` FROM `".$this->oDB->tblGuild."` WHERE `tag` = '$strGuild';" );
00142 if( $this->oDB->num_rows( $sqlGuild ) == 0 )
00143 {
00144
00145 $this->oDB->query( "INSERT INTO `".$this->oDB->tblGuild."` SET `tag`='$strGuild'".$GLOBALS['strUpdateString'].$GLOBALS['strCreatedString'].";" );
00146 $intGuild = $this->oDB->insert_id();
00147 }
00148 else
00149 {
00150 $intGuild = $this->oDB->fetch_assoc( $sqlGuild );
00151 $intGuild = $intGuild['guild_id'];
00152 }
00153 }
00154
00155 if( $strOwner != '' )
00156 {
00157
00158 $sqlResult = $this->oDB->query( "SELECT * FROM `".$this->oDB->tblPlayer."` WHERE `name` = '$strOwner';" );
00159 if( $this->oDB->num_rows( $sqlResult ) == 0 )
00160 {
00161 $this->oDB->query( "INSERT INTO `".$this->oDB->tblPlayer."` SET `name`='$strOwner', `guild_id`='$intGuild', `typ`='$intType' , `race`='$intRace'".$GLOBALS['strUpdateString'].$GLOBALS['strCreatedString'].";" );
00162 }
00163 $sqlResult = $this->oDB->query("SELECT `player_id` FROM `".$this->oDB->tblPlayer."` WHERE `name` = '$strOwner';" );
00164 $aPlayer = $this->oDB->fetch_assoc( $sqlResult );
00165 $intPlayer = $aPlayer['player_id'];
00166 }
00167 else
00168 {
00169 $intPlayer = 1;
00170 }
00171
00172 $aTown = $this->oTown->get( $intX, $intY );
00173 if( isset( $aTown['town_id'] ) )
00174 {
00175 $this->oTown->set( $aTown['town_id'], $strTown, $intPlayer, $intSight, $intTownhall, $strInfo );
00176 }
00177 else
00178 {
00179 $this->oTown->add( $intX, $intY, $strTown, $intPlayer, $strInfo, $intTownhall, $intSight );
00180 }
00181
00182
00183 $this->oDB->query( "SELECT `x`, `y`, `terrain` FROM `".$this->oDB->tblMap."` WHERE `x`='$intX' AND `y`='$intY';" );
00184 $aRow = $this->oDB->fetch_assoc();
00185
00186 $this->oDB->query( "SELECT `x`, `y` FROM `".$this->oDB->tblMapData."` WHERE `x`='$intX' AND `y`='$intY';" );
00187 $aRow2 = $this->oDB->fetch_assoc();
00188 if( $aRow['terrain'] > 0 && $intTerrain > 0 && $aRow['terrain'] != $intTerrain )
00189 {
00190
00191 return false;
00192 }
00193 elseif( $aRow2['x'] == $intX && $aRow2['y'] == $intY )
00194 {
00195
00196 $this->oDB->query( "UPDATE `".$this->oDB->tblMapData."` SET `building`='$intBuilding'".$GLOBALS['strUpdateString']." WHERE `x` = '$intX' AND `y` = '$intY';" );
00197 if( $aRow['terrain'] == 0 )
00198 {
00199
00200 $this->oDB->query( "UPDATE `".$this->oDB->tblMap."` SET `terrain`='$intTerrain' WHERE `x` = '$intX' AND `y` = '$intY';" );
00201 }
00202 }
00203 else
00204 {
00205
00206 $this->oDB->query( "REPLACE INTO `".$this->oDB->tblMapData."` SET `building`='$intBuilding', `x` = '$intX', `y` = '$intY'".$GLOBALS['strUpdateString'].";" );
00207 if( $aRow['x'] != $intX || $aRow['y'] != $intY )
00208 {
00209
00210 $this->oDB->query( "INSERT INTO `".$this->oDB->tblMap."` SET `terrain`='$intTerrain', `x` = '$intX', `y` = '$intY';" );
00211 }
00212 }
00213
00214 return array( 'map.php?x='.$intX.'&y='.$intY, 'Stadtscan Import erfolgreich' );
00215 }
00216 else
00217 {
00218
00219 $this->oLog->write( "Import: Stadtscan failed on: XY=$intX,$intY R=$intRace T=$intType A=".$this->oUser->check( $intX, $intY ), 10 );
00220 return false;
00221 }
00222 }
00223 }