125 lines
3.3 KiB
PHP
125 lines
3.3 KiB
PHP
<?php
|
|
namespace sammo;
|
|
|
|
function getHistory($year, $month) {
|
|
$db = DB::db();
|
|
|
|
$texts = [];
|
|
foreach(
|
|
$db->queryFirstColumn(
|
|
'SELECT `text` from full_history where year = %i and month = %i order by id desc',
|
|
$year,
|
|
$month
|
|
) as $text
|
|
){
|
|
$texts[] = ConvertLog($text);
|
|
}
|
|
|
|
if(!$texts){
|
|
return ConvertLog("<C>●</>{$year}년 {$month}월: 기록 없음");
|
|
}
|
|
|
|
return join('<br>', $texts);
|
|
}
|
|
|
|
function getGenHistory($count, $year, $month, $isFirst=0) {
|
|
$fp = @fopen("logs/_alllog.txt", "r");
|
|
@fseek($fp, -$count*300, SEEK_END);
|
|
$file = @fread($fp, $count*300);
|
|
@fclose($fp);
|
|
$log = explode("\n",$file);
|
|
|
|
$str = "";
|
|
$prefix = "</>{$month}월:";
|
|
$year -= 1;
|
|
$prefixYear = "</>{$month}월:<C>{$year}</>";
|
|
for($i=0; $i < $count; $i++) {
|
|
$line = $log[count($log)-2-$i];
|
|
if($line == "") {
|
|
continue;
|
|
}
|
|
|
|
if(strpos($line, $prefixYear)) {
|
|
break;
|
|
} elseif(strpos($line, $prefix) || $isFirst == 1) {
|
|
$str = ConvertLog($line).'<br>'.$str;
|
|
} else {
|
|
break;
|
|
}
|
|
}
|
|
if($str == "") {
|
|
$str = "<C>●</>{$month}월: 기록 없음";
|
|
$str = ConvertLog($str);
|
|
}
|
|
return $str;
|
|
}
|
|
|
|
function LogHistory($isFirst=0) {
|
|
if(STEP_LOG) pushStepLog(date('Y-m-d H:i:s').', LogHistory Start');
|
|
|
|
$db = DB::db();
|
|
$obj = $db->queryFirstRow('SELECT year, month, startyear FROM game limit 1');
|
|
|
|
//TODO: 새롭게 추가할 지도 값 받아오는 함수를 이용하여 재구성
|
|
$map = getWorldMap([
|
|
'year'=>null,
|
|
'month'=>null,
|
|
'neutralView'=>true,
|
|
'showMe'=>false,
|
|
'aux'=>[]
|
|
]);
|
|
|
|
|
|
$map['month'] = $obj['month'];
|
|
$map['year'] = $obj['year'];
|
|
$map['startYear'] = $obj['startyear'];
|
|
if($isFirst == 1){
|
|
$map['month'] -= 1;
|
|
if($map['month'] == 0){
|
|
$map['month'] = 12;
|
|
$map['year'] -= 1;
|
|
}
|
|
}
|
|
|
|
$startYear = $obj['startyear'];
|
|
$year = $map['year'];
|
|
$month = $map['month'];
|
|
|
|
$map_json = json_encode($map, JSON_UNESCAPED_UNICODE);
|
|
|
|
$log = getHistory($year, $month);
|
|
$genlog = getGenHistory(50, $year, $month, $isFirst);
|
|
|
|
$nationStr = "";
|
|
$powerStr = "";
|
|
$genStr = "";
|
|
$cityStr = "";
|
|
|
|
|
|
foreach($db->query('select nation,color,name,power,gennum from nation where level>0 order by power desc') as $nation){
|
|
$cityCount = $db->queryFirstField('select count(*) from city where nation = %i',$nation['nation']);
|
|
|
|
$nationStr .= "<font color=cyan>◆</font> <font style=color:".newColor($nation['color']).";background-color:{$nation['color']};>{$nation['name']}</font><br>";
|
|
$powerStr .= "국력 {$nation['power']}<br>";
|
|
$genStr .= "장수 {$nation['gennum']}<br>";
|
|
$cityStr .= "속령 $citycount<br>";
|
|
}
|
|
|
|
if(STEP_LOG) pushStepLog(date('Y-m-d H:i:s').', contents collected');
|
|
|
|
$db->insert('history', [
|
|
'year' => $year,
|
|
'month' => $month,
|
|
'map' => $map_json,
|
|
'log' => $log,
|
|
'genlog' => $genlog,
|
|
'nation' => $nationStr,
|
|
'power' => $powerStr,
|
|
'gen' => $genStr,
|
|
'city' => $cityStr
|
|
]);
|
|
|
|
if(STEP_LOG) pushStepLog(date('Y-m-d H:i:s').', LogHistory Finish');
|
|
return true;
|
|
}
|