00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00035 class Admin
00036 {
00037 var $oDB;
00038 var $oLog;
00039
00046 function Admin ( &$oDB, &$oLog )
00047 {
00048 $this->oDB =& $oDB;
00049 $this->oLog =& $oLog;
00050 }
00051
00062 function addUser ( $strName, $strPass, $intHomeX, $intHomeY, $intGroup )
00063 {
00064 if ( $strName == '' || $strPass == '' )
00065 {
00066 return false;
00067 }
00068
00069 $aRow = $this->oDB->query_first("SELECT COUNT(user_id) FROM `".$this->oDB->tblUser."` WHERE `name`='$strName';");
00070 if ( $aRow[0] > 0 )
00071 {
00072 return false;
00073 }
00074 $this->oDB->query("INSERT INTO `".$this->oDB->tblUser."` SET `name`='$strName', `pass`='".md5($strPass)."', `home_x`='$intHomeX', `home_y`='$intHomeY', `last_x`='$intHomeX', `last_y`='$intHomeY', usergroup_id='$intGroup';");
00075 return intval ( $this->oDB->insert_id() );
00076 }
00077
00086 function editUser( $intUser, $strPlayer, $intHomeX, $intHomeY, $intGroup )
00087 {
00088 $strUpdatePlayer = '';
00089 $aPlayer = $this->oDB->query_first( "SELECT player_id FROM ".$this->oDB->tblPlayer." WHERE name LIKE '".$strPlayer."' LIMIT 1;" );
00090 if( $aPlayer['player_id'] )
00091 {
00092 $strUpdatePlayer = ", player_id='".$aPlayer['player_id']."'";
00093 }
00094 elseif( $strPlayer == '' )
00095 {
00096 $strUpdatePlayer = ", player_id='0'";
00097 }
00098
00099 $this->oDB->query("UPDATE `".$this->oDB->tblUser."` SET `home_x`='$intHomeX', `home_y`='$intHomeY', usergroup_id='$intGroup'".$strUpdatePlayer." WHERE user_id='".$intUser."';");
00100 return true;
00101 }
00102
00108 function getUser( $intUser )
00109 {
00110 $aReturn = array();
00111 $sqlResult = $this->oDB->query( "SELECT u.*, p.name AS pname ".
00112 "FROM `".$this->oDB->tblUser."` u ".
00113 "LEFT JOIN ".$this->oDB->tblPlayer." p ON (u.player_id=p.player_id) ".
00114 "WHERE user_id='".$intUser."';");
00115 if( $this->oDB->num_rows( $sqlResult ) != 1 )
00116 {
00117 return false;
00118 }
00119 return $this->oDB->fetch_assoc( $sqlResult );
00120 }
00121
00128 function delUser ( $intUser )
00129 {
00130 $this->oDB->query("DELETE FROM `".$this->oDB->tblUser."` WHERE user_id='$intUser' AND usergroup_id!=1 LIMIT 1;");
00131 if ( $this->oDB->affected_rows() == 1 )
00132 {
00133 return true;
00134 }
00135 return false;
00136 }
00137
00144 function getUsers( $strOrder )
00145 {
00146 $aReturn = array();
00147 $sqlResult = $this->oDB->query("SELECT * FROM `".$this->oDB->tblUser."` ORDER BY ".$strOrder);
00148 while ( $aRow = $this->oDB->fetch_assoc( $sqlResult ) )
00149 {
00150 $aReturn[] = $aRow;
00151 }
00152 return $aReturn;
00153 }
00154
00161 function getGroups( $strOrder = 'name' )
00162 {
00163 $aReturn = array();
00164 $sqlResult = $this->oDB->query("SELECT * FROM `".$this->oDB->tblUsergroup."` ORDER BY ".$strOrder);
00165 while ( $aRow = $this->oDB->fetch_assoc( $sqlResult ) )
00166 {
00167 if( $strOrder == 'usergroup_id' )
00168 {
00169 $aReturn[$aRow['usergroup_id']] = $aRow;
00170 }
00171 else
00172 {
00173 $aReturn[] = $aRow;
00174 }
00175 }
00176 return $aReturn;
00177 }
00178
00186 function getLogStat ( $strOrder, $intStart = 0, $intEnd = 50 )
00187 {
00188 $aReturn = array();
00189
00190
00191
00192
00193
00194
00195
00196 $this->oDB->query('SELECT u.lastlogin AS lastseen, COUNT(a.actionlog_id) AS aktionen, u.name '.
00197 'FROM '.$this->oDB->tblUser.' u '.
00198 'LEFT JOIN '.$this->oDB->tblActionlog.' a ON u.user_id = a.user_id AND a.message != "Kartenquelltext (,)" AND a.flag !=3 AND a.flag < 10 '.
00199 'GROUP BY u.name '.
00200 'ORDER BY '.$strOrder);
00201 $aReturn['max'] = $this->oDB->affected_rows();
00202 while ( $aRow = $this->oDB->fetch_assoc() )
00203 {
00204 $aReturn[] = $aRow;
00205 }
00206 return $aReturn;
00207 }
00208
00217 function getLogList ( $strOrder, $intStart = 0, $intEnd = 50 )
00218 {
00219 $aReturn = array();
00220 $this->oDB->query("SELECT COUNT(actionlog_id) FROM ".$this->oDB->tblActionlog.";");
00221 $aRow = $this->oDB->fetch_row();
00222 $aReturn['max'] = $aRow[0];
00223
00224 $strLimit = ($intStart != -1) ? " LIMIT $intStart, $intEnd" : '';
00225 $this->oDB->query("SELECT a.*, u.name FROM ".$this->oDB->tblActionlog." a LEFT JOIN ".$this->oDB->tblUser." u USING (user_id) ORDER BY $strOrder$strLimit;");
00226 while ( $aRow = $this->oDB->fetch_assoc() )
00227 {
00228 $aReturn[] = $aRow;
00229 }
00230 return $aReturn;
00231 }
00232
00239 function deleteLogs ( $aLogIds, $intTime = 0 )
00240 {
00241 $strIds = '(0';
00242 if ( is_array ( $aLogIds ) && count ( $aLogIds ) > 0 )
00243 {
00244 $strIds .= ','.implode ( ',', $aLogIds );
00245 }
00246 $strIds .= ')';
00247 $this->oDB->query("DELETE FROM ".$this->oDB->tblActionlog." WHERE actionlog_id IN $strIds OR `time`<'$intTime';");
00248 return intval ( $this->oDB->affected_rows() );
00249 }
00250
00255 function getDeadList()
00256 {
00257 $aReturn = array ( 'players' => array(), 'guilds' => array() );
00258
00259
00260 $this->oDB->query("SELECT p.player_id, p.name FROM `".$this->oDB->tblPlayer."` p LEFT JOIN `".$this->oDB->tblTown."` t USING (player_id) WHERE p.player_id>1 AND t.town_id IS NULL;");
00261
00262 while ( $aRow = $this->oDB->fetch_assoc() )
00263 {
00264 $aReturn['players'][] = $aRow;
00265 }
00266
00267
00268 $this->oDB->query("SELECT DISTINCT g.guild_id, g.name, g.tag FROM `".$this->oDB->tblGuild."` g LEFT JOIN `".$this->oDB->tblPlayer."` p USING (guild_id) WHERE p.player_id IS NULL AND g.guild_id>1;");
00269
00270 while ( $aRow = $this->oDB->fetch_assoc() )
00271 {
00272 $aReturn['guilds'][] = $aRow;
00273 }
00274 return $aReturn;
00275 }
00276
00282 function deletePlayers ( $aPlayers )
00283 {
00284 $strIds = '(0';
00285 if ( is_array ( $aPlayers ) && count ( $aPlayers ) > 0 )
00286 {
00287 $strIds .= ','.implode ( ',', $aPlayers );
00288 }
00289 $strIds .= ')';
00290 $this->oDB->query("DELETE FROM ".$this->oDB->tblPlayer." WHERE player_id IN $strIds AND player_id > 1;");
00291 $this->oDB->query("UPDATE ".$this->oDB->tblUser." SET player_id=0 WHERE player_id IN $strIds;");
00292 return intval ( $this->oDB->affected_rows() );
00293 }
00294
00299 function optimizeDb()
00300 {
00301 $aReturn = array();
00302 $this->oDB->query('ANALYZE TABLE `'.$this->oDB->tblActionlog.'`, `'.$this->oDB->tblGuild.'`, `'.$this->oDB->tblMap.'`, `'.$this->oDB->tblMapData.'`, `'.$this->oDB->tblPlayer.'`, `'.$this->oDB->tblTown.'`, `'.$this->oDB->tblUser.'`;');
00303 while ( $aRow = $this->oDB->fetch_assoc() )
00304 {
00305 $aReturn[] = $aRow;
00306 }
00307 return $aReturn;
00308 }
00309
00314 function countMapMerge()
00315 {
00316 $aCnt = $this->oDB->query_first( 'SELECT COUNT(x) AS cnt FROM `'.$this->oDB->tblMapData.'` GROUP BY x, y HAVING cnt>1' );
00317
00318 return intval( $aCnt['cnt'] );
00319 }
00320
00325 function mergeMap()
00326 {
00327 $intCount = 0;
00328
00329
00330 $intQueryID = $this->oDB->query( 'SELECT COUNT(x) AS cnt, m.* FROM `'.$this->oDB->tblMapData.'` m GROUP BY x, y HAVING cnt>1' );
00331 while ( $aRow = $this->oDB->fetch_assoc( $intQueryID ) )
00332 {
00333 if( $aRow['x'] > 0 && $aRow['y'] > 0 && $aRow['last_update'] > 0 )
00334 {
00335
00336 $aDest = $this->oDB->query_first( "SELECT last_update,street,building,unit,fow FROM `".$this->oDB->tblMapData."` WHERE x='".$aRow['x']."' AND y='".$aRow['y']."' ORDER BY last_update DESC LIMIT 1" );
00337
00338 if( isset( $aDest['last_update'] ) )
00339 {
00340 $fieldcount = 0;
00341 $strQuery = 'UPDATE `'.$this->oDB->tblMapData.'` SET';
00342
00343
00344 if( $aRow['street'] != 0 && intval($aDest['street']) == 0 )
00345 {
00346 $fieldcount++;
00347 $strQuery .= ' street=\''.$aRow['street'].'\',';
00348 }
00349 if( $aRow['building'] != 0 && intval($aDest['building']) == 0 )
00350 {
00351 $fieldcount++;
00352 $strQuery .= ' building=\''.$aRow['building'].'\',';
00353 }
00354 if( $aRow['unit'] != 0 && intval($aDest['unit']) == 0 )
00355 {
00356 $fieldcount++;
00357 $strQuery .= ' unit=\''.$aRow['unit'].'\',';
00358 }
00359 if( $aRow['fow'] ==0 && intval($aDest['fow']) == 1 )
00360 {
00361 $fieldcount++;
00362 $strQuery .= ' fow=\'1\',';
00363 }
00364
00365
00366 if( $fieldcount > 0 )
00367 {
00368 $this->oDB->query( substr($strQuery, 0, -1) . ' WHERE x=\''.$aRow['x'].'\' AND y=\''.$aRow['y'].'\' AND last_update=\''.$aDest['last_update'].'\'' );
00369 $intCount+=2;
00370 }
00371
00372
00373 $this->oDB->query( 'DELETE FROM `'.$this->oDB->tblMapData.'` WHERE x=\''.$aRow['x'].'\' AND y=\''.$aRow['y'].'\' AND last_update=\''.$aRow['last_update'].'\'' );
00374 }
00375 }
00376 }
00377
00378
00379
00380
00381 return $intCount;
00382 }
00383 }