00001 <?php
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 @ob_start();
00026 require_once( './general.php' );
00027 @ob_end_clean();
00028
00029
00030 if(isset($_POST['time'])) $intTime = intval( $_POST['time'] );
00031 elseif(isset($_SERVER['HTTP_WDSMAP_TIMESTAMP'])) $intTime = $_SERVER['HTTP_WDSMAP_TIMESTAMP'];
00032 else $intTime = 1;
00033
00034 if(isset($_POST['type'])) $strType = $_POST['type'];
00035 elseif(isset($_GET['type'])) $strType = $_GET['type'];
00036 elseif(isset($_SERVER['HTTP_WDSMAP_TYPE'])) $strType = $_SERVER['HTTP_WDSMAP_TYPE'];
00037 else $strType = '';
00038
00039 $booFile = isset($_POST['file']) || isset($_GET['file']);
00040 $strOut = '';
00041
00042
00043 @set_time_limit(0);
00044
00045 if( $strType == 'update' )
00046 {
00047 if( !$oUser->isAdmin( 'export_update' ) )
00048 {
00049
00050 if( preg_match( '/^WDSMAP\
00051 {
00052 header("phpmap-ReturnCode: 3");
00053 header("phpmap-ErrorMessage: No Access");
00054 }
00055 die("ReturnCode: 3\nErrorMessage: No Access\n");
00056 }
00057
00058 $strFilename = 'update'.$intServerId.'.dat';
00059 $strGuild = '';
00060 $strPlayer = '';
00061 $strTown = '';
00062 $aGuild = array();
00063 $aPlayer = array();
00064 $aPlayerGuild = array();
00065 $aTown = array();
00066 $aSight = array();
00067 $aTownOwner = array();
00068 $intStartTime = time();
00069 $oMysql->query( "SELECT * FROM ".$oMysql->tblGuild." WHERE last_update>".$intTime.";");
00070 if( $oMysql->num_rows() > 0 )
00071 {
00072
00073 $strGuild = ' OR guild_id IN (0';
00074 while( $aRow = $oMysql->fetch_assoc() )
00075 {
00076 $strGuild .= ','.$aRow['guild_id'];
00077 $aGuild[$aRow['guild_id']] = $aRow['tag'];
00078 }
00079 $strGuild .= ')';
00080 }
00081 $oMysql->query( "SELECT * FROM ".$oMysql->tblPlayer." WHERE last_update>'".$intTime."'".$strGuild.";");
00082 if( $oMysql->num_rows() > 0 )
00083 {
00084
00085 $strPlayer = ' OR player_id IN (0';
00086 $strGuild = '';
00087 while( $aRow = $oMysql->fetch_assoc() )
00088 {
00089 $strPlayer .= ','.$aRow['player_id'];
00090 if( !isset( $aGuild[$aRow['guild_id']] ) )
00091 {
00092 $strGuild .= ','.$aRow['guild_id'];
00093 }
00094 $aPlayer[$aRow['player_id']] = $aRow['name'];
00095 $aPlayerGuild[$aRow['player_id']] = $aRow['guild_id'];
00096 }
00097 $strPlayer .= ')';
00098
00099 if( $strGuild != '' )
00100 {
00101
00102 $oMysql->query( "SELECT guild_id, tag FROM ".$oMysql->tblGuild." WHERE guild_id IN (0".$strGuild.");");
00103 while( $aRow = $oMysql->fetch_assoc() )
00104 {
00105 $aGuild[$aRow['guild_id']] = $aRow['tag'];
00106 }
00107 }
00108 }
00109 $oMysql->query( "SELECT * FROM ".$oMysql->tblTown." WHERE last_update>'".$intTime."'".$strPlayer.";");
00110 if( $oMysql->num_rows() > 0 )
00111 {
00112 $strTownPlayer = '';
00113
00114 while( $aRow = $oMysql->fetch_assoc() )
00115 {
00116 $aSight[$aRow['x'].'-'.$aRow['y']] = $aRow['sight'];
00117 $aTown[$aRow['x'].'-'.$aRow['y']] = $aRow['name'];
00118 $aTownOwner[$aRow['x'].'-'.$aRow['y']] = $aRow['player_id'];
00119 if( !isset( $aPlayer[$aRow['player_id']] ) )
00120 {
00121 $strTownPlayer .= ','.$aRow['player_id'];
00122 }
00123 }
00124
00125 if( $strPlayer != '' || $strTownPlayer != '' )
00126 {
00127
00128 $oMysql->query( "SELECT player_id, name, guild_id FROM ".$oMysql->tblPlayer." WHERE player_id IN (0".$strPlayer.$strTownPlayer.");");
00129 while( $aRow = $oMysql->fetch_assoc() )
00130 {
00131 $aPlayer[$aRow['player_id']] = $aRow['name'];
00132 $aPlayerGuild[$aRow['player_id']] = $aRow['guild_id'];
00133 }
00134 }
00135 }
00136
00137 $oMysql->query( "SELECT * FROM ".$oMysql->tblMapData." WHERE (building>-10 OR building IS NULL) AND last_update>'".$intTime."';");
00138
00139 while( $aRow = $oMysql->fetch_assoc() )
00140 {
00141
00142
00143
00144 $intUnit = (((time() - $aRow['last_update']) < $oUser->intUnit*60*60))
00145 ? intval( $aRow['unit'] )
00146 : 0;
00147
00148
00149 $strOut .= intval( $aRow['x'] ).' '.intval( $aRow['y'] );
00150
00151 $strOut .= ' '.intval( $aRow['building'] ).' '.intval( $aRow['border'] ).' '.intval( $aRow['street'] ).' '.$intUnit.' '.intval( $aRow['fow'] );
00152 if( isset( $aSight[$aRow['x'].'-'.$aRow['y']] ) )
00153 {
00154 $strOut .= ' '.intval( $aSight[$aRow['x'].'-'.$aRow['y']] ).' "'.$aTown[$aRow['x'].'-'.$aRow['y']].'"';
00155 if( isset( $aTownOwner[$aRow['x'].'-'.$aRow['y']] ) && $aTownOwner[$aRow['x'].'-'.$aRow['y']]>0
00156 && isset( $aPlayer[$aTownOwner[$aRow['x'].'-'.$aRow['y']]] ) )
00157 {
00158
00159 $strOut .= ' "'.$aPlayer[$aTownOwner[$aRow['x'].'-'.$aRow['y']]].'"';
00160 if( isset( $aPlayerGuild[$aTownOwner[$aRow['x'].'-'.$aRow['y']]] ) && $aPlayerGuild[$aTownOwner[$aRow['x'].'-'.$aRow['y']]]>0 )
00161 {
00162
00163 $strOut .= ' "'.$aGuild[$aPlayerGuild[$aTownOwner[$aRow['x'].'-'.$aRow['y']]]].'"';
00164 }
00165 }
00166 }
00167
00168 $strOut .= "\n";
00169 }
00170
00171
00172 header( "phpmap-ReturnCode: 0" );
00173 header( "phpmap-Version: 1" );
00174 header( "phpmap-Timestamp: ".$intStartTime );
00175 header( "phpmap-DataSize: ".strlen($strOut) );
00176 }
00177 elseif( $strType == 'static' )
00178 {
00179 if( !$oUser->isAdmin( 'export_static' ) )
00180 {
00181
00182 if( preg_match( '/^WDSMAP\
00183 {
00184 header("phpmap-ReturnCode: 3");
00185 header("phpmap-ErrorMessage: No Access");
00186 }
00187 die("ReturnCode: 3\nErrorMessage: No Access\n");
00188 }
00189
00190 $strFilename = 'server'.$intServerId.'.dat';
00191 $sqlResult = $oMysql->query( "SELECT x,y,building,unit,border,street FROM ".$oMysql->tblMapData.";");
00192
00193 $strBuilding = "[buildings]\n";
00194 $strUnit = "\n[units]\n";
00195 $strBorder = "\n[border]\n";
00196 $strStreet = "\n[streets]\n";
00197 $strTown = "\n[towns]\n";
00198
00199 while( $aRow = $oMysql->fetch_assoc($sqlResult) )
00200 {
00201 if( !is_null($aRow['building']) && ( $aRow['building'] > -10) )
00202 {
00203 if( $aRow['building'] < 0 )
00204 {
00205
00206 $aRow['building'] = 97;
00207 }
00208 $strBuilding .= $aRow['x'].' '.$aRow['y'].' '.$aRow['building']."\n";
00209 }
00210 if( !is_null($aRow['unit']) )
00211 {
00212 $strUnit .= $aRow['x'].' '.$aRow['y'].' '.$aRow['unit']."\n";
00213 }
00214 if( !is_null($aRow['border']) )
00215 {
00216 $strBorder .= $aRow['x'].' '.$aRow['y'].' '.$aRow['border']."\n";
00217 }
00218 if( !is_null($aRow['street']) )
00219 {
00220 $strStreet .= $aRow['x'].' '.$aRow['y'].' '.$aRow['street']."\n";
00221 }
00222 }
00223
00224
00225 $sqlResult = $oMysql->query( "SELECT t.x, t.y, t.name AS tname, p.name AS pname, g.tag ".
00226 "FROM ".$oMysql->tblTown." t ".
00227 "LEFT JOIN ".$oMysql->tblPlayer." p USING (player_id) ".
00228 "LEFT JOIN ".$oMysql->tblGuild." g USING (guild_id)" .
00229 "LEFT JOIN `".$oMysql->tblMapData."` m ON (t.x=m.x AND t.y=m.y) ".
00230 "WHERE m.`building` > '-10';" );
00231
00232 while( $aRow = $oMysql->fetch_assoc( $sqlResult ) )
00233 {
00234 $strTown .= $aRow['x'].' '.$aRow['y'].' "'.$aRow['tname'].'" "'.$aRow['pname'].'" "'.$aRow['tag'].'"'."\n";
00235 }
00236
00237 $strOut = $strBuilding.$strUnit.$strBorder.$strStreet.$strTown;
00238 }
00239 else
00240 {
00241
00242 if( preg_match( '/^WDSMAP\
00243 {
00244 header("phpmap-ReturnCode: 2");
00245 header("phpmap-ErrorMessage: Invalid export type");
00246 }
00247 die("ReturnCode: 2\nErrorMessage: Invalid export type\n");
00248 }
00249
00250 if( $booFile )
00251 {
00252 header("Content-Description: File Transfer");
00253 header("Content-Type: application/force-download");
00254 header("Content-Disposition: attachment; filename=".$strFilename);
00255 }
00256 echo $strOut;