pushHistory를 DB기반으로 변경

This commit is contained in:
2018-04-01 05:18:17 +09:00
parent d062fac671
commit 74390602d8
22 changed files with 125 additions and 98 deletions
+1 -1
View File
@@ -114,7 +114,7 @@ if($ok == "수락") {
pushGenLog($me, $mylog);
pushGenLog($you, $youlog);
//pushAllLog($alllog);
//pushHistory($history);
//pushHistory($history, $admin['year'], $admin['month']);
echo "<script>location.replace('msglist.php');</script>";
+1 -1
View File
@@ -93,7 +93,7 @@ if($ok == "수락") {
pushGenLog($me, $mylog);
pushGenLog($you, $youlog);
pushAllLog($alllog);
pushHistory($history);
pushHistory($history, $admin['year'], $admin['month']);
echo "<script>location.replace('msglist.php');</script>";
+1 -1
View File
@@ -98,7 +98,7 @@ if($ok == "수락") {
pushGenLog($me, $mylog);
pushGenLog($you, $youlog);
pushAllLog($alllog);
pushHistory($history);
pushHistory($history, $admin['year'], $admin['month']);
echo "<script>location.replace('msglist.php');</script>";
+1 -1
View File
@@ -132,7 +132,7 @@ if($ok == "수락") {
pushGenLog($me, $mylog);
pushGenLog($you, $youlog);
pushAllLog($alllog);
pushHistory($history);
pushHistory($history, $admin['year'], $admin['month']);
echo "<script>location.replace('msglist.php');</script>";
+1 -1
View File
@@ -164,7 +164,7 @@ if($ok == "수락" && $me['level'] < 12 && $nation['level'] > 0 && $nation['scou
pushGenLog($me, $mylog);
pushGenLog($you, $youlog);
pushAllLog($alllog);
pushHistory($history);
pushHistory($history, $admin['year'], $admin['month']);
echo "<script>location.replace('msglist.php');</script>";
+1 -1
View File
@@ -122,7 +122,7 @@ if($ok == "수락") {
pushGenLog($me, $mylog);
pushGenLog($you, $youlog);
pushAllLog($alllog);
pushHistory($history);
pushHistory($history, $admin['year'], $admin['month']);
echo "<script>location.replace('msglist.php');</script>";
+20 -18
View File
@@ -1243,9 +1243,17 @@ function pushAllLog($log) {
file_put_contents(__dir__.'/logs/_alllog.txt', $text, FILE_APPEND);
}
function pushHistory($history) {
$text = join("\n", $history)."\n";
file_put_contents(__dir__.'/logs/_history.txt', $text, FILE_APPEND);
function pushHistory($history, $year=null, $month=null) {
$db = DB::db();
if($year === null || $month === null){
$game = $db->queryFirstRow('SELECT year, month FROM game LIMIT 1');
$year = $game['year'];
$month = $game['month'];
}
$request = array_map(function($text) use ($year, $month) {
return ['year'=>$year, 'month'=>$month, 'text'=>$text];
}, $history);
$db->insert('full_history', $history);
}
function getRawLog($path, $count, $line_length){
@@ -1305,19 +1313,13 @@ function AuctionLog($count) {
}
function History($count) {
if(!file_exists("logs/_history.txt")){
return '';
$db = DB::db();
$texts = [];
foreach($db->queryFirstColumn('SELECT `text` from full_history order by id desc limit %i', $count) as $text){
$texts[] = ConvertLog($text);
}
$fp = @fopen("logs/_history.txt", "r");
@fseek($fp, -300*$count, SEEK_END); //
$file = @fread($fp, $count*300);
@fclose($fp);
$log = explode("\n",$file);
$str = "";
for($i=0; $i < $count; $i++) {
$str .= isset($log[count($log)-2-$i]) ? ConvertLog($log[count($log)-2-$i])."<br>" : "<br>";
}
echo $str;
return join('<br>', $texts);
}
function MyLog($no, $count) {
@@ -2536,7 +2538,7 @@ function uniqueItem($connect, $general, $log, $vote=0) {
break;
}
pushAllLog($alllog);
pushHistory($history);
pushHistory($history, $admin['year'], $admin['month']);
}
}
return $log;
@@ -2690,7 +2692,7 @@ function deleteNation($connect, $general) {
$query = "delete from diplomacy where me='{$general['nation']}' or you='{$general['nation']}'";
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
pushHistory($history);
pushHistory($history, $admin['year'], $admin['month']);
refreshNationStaticInfo();
}
@@ -2755,7 +2757,7 @@ function nextRuler($connect, $general) {
$history[] = "<C>●</>{$admin['year']}{$admin['month']}월:<C><b>【유지】</b></><Y>{$nextruler['name']}</>(이)가 <D><b>{$nation['name']}</b></>의 유지를 이어 받았습니다";
pushHistory($history);
pushHistory($history, $admin['year'], $admin['month']);
addNationHistory($nation, "<C>●</>{$admin['year']}{$admin['month']}월:<C><b>【유지】</b></><Y>{$nextruler['name']}</>(이)가 <D><b>{$nation['name']}</b></>의 유지를 이어 받음.");
// 장수 삭제 및 부대처리는 checkTurn에서
}
+2 -2
View File
@@ -83,7 +83,7 @@ function registerAuction($connect) {
$alllog[0] = "<C>●</>{$admin['month']}월:<C>".GetStuffName($stuff)."</>(이)가 거래장에 등장했습니다!";
$history[0] = "<C>●</>{$admin['year']}년 {$admin['month']}월:<C><b>【암시장】</b></><Y>ⓝ암시장상인</>(이)가 <C>".GetStuffName($stuff)."</>(을)를 판다는 소문이 돌고 있습니다!";
pushAllLog($alllog);
pushHistory($history);
pushHistory($history, $admin['year'], $admin['month']);
}
}
*/
@@ -206,7 +206,7 @@ function processAuction($connect) {
$alllog[0] = "<C>●</>{$admin['month']}월:<Y>{$auction['name2']}</>(이)가 <C>".GetStuffName($auction['stuff'])."</>(을)를 구매했습니다!";
$history[0] = "<C>●</>{$admin['year']}{$admin['month']}월:<C><b>【암시장】</b></><Y>{$auction['name2']}</>(이)가 <C>".GetStuffName($auction['stuff'])."</>(을)를 구매했습니다!";
pushAllLog($alllog);
pushHistory($history);
pushHistory($history, $admin['year'], $admin['month']);
}
pushGenLog($trader, $traderLog);
pushGenLog($bidder, $bidderLog);
+1 -1
View File
@@ -137,7 +137,7 @@ function acceptScout($messageInfo, $general, $msgResponse){
pushGenLog($me, $mylog);
pushGenLog($you, $youlog);
pushAllLog($alllog);
pushHistory($alllog);
pushHistory($alllog, $year, $month);
return [true, 'success'];
}
+6 -6
View File
@@ -386,7 +386,7 @@ function preUpdateMonthly($connect) {
$history[] = "<C>●</>{$admin['year']}{$admin['month']}월:<R><b>【고립】</b></><G><b>{$city['name']}</b></>(이)가 보급이 끊겨 <R>미지배</> 도시가 되었습니다.";
}
pushHistory($history);
pushHistory($history, $admin['year'], $admin['month']);
//민심30이하 공백지 처리
$query = "update city set nation='0',gen1='0',gen2='0',gen3='0',conflict='',conflict2='',term=0,front=0 where rate<='30' and supply='0'";
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
@@ -608,7 +608,7 @@ group by A.nation
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
}
}
pushHistory($history);
pushHistory($history, $admin['year'], $admin['month']);
//사상자 초기화
$query = "update diplomacy set dead=0";
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
@@ -781,7 +781,7 @@ function checkMerge($connect) {
pushGenLog($me, $mylog);
pushGenLog($you, $youlog);
pushHistory($history);
pushHistory($history, $admin['year'], $admin['month']);
unset($mylog);
unset($youlog);
unset($history);
@@ -901,7 +901,7 @@ function checkSurrender($connect) {
pushGenLog($me, $mylog);
pushGenLog($you, $youlog);
pushHistory($history);
pushHistory($history, $admin['year'], $admin['month']);
unset($mylog);
unset($youlog);
unset($history);
@@ -985,7 +985,7 @@ function updateNationState($connect) {
$query = "update nation set tech=totaltech/'$gencount',gennum='$gennum' where nation='{$nation['nation']}'";
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
}
pushHistory($history);
pushHistory($history, $admin['year'], $admin['month']);
}
function checkStatistic($connect) {
@@ -1279,7 +1279,7 @@ function checkEmperior($connect) {
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
$history[] = "<C>●</>{$admin['year']}{$admin['month']}월:<Y><b>【통일】</b></><D><b>{$nation['name']}</b></>(이)가 전토를 통일하였습니다.";
pushHistory($history);
pushHistory($history, $admin['year'], $admin['month']);
//연감 월결산
LogHistory();
+35 -29
View File
@@ -1,32 +1,25 @@
<?php
namespace sammo;
function getHistory($count, $year, $month, $isFirst=0) {
$fp = @fopen("logs/_history.txt", "r");
@fseek($fp, -$count*300, SEEK_END);
$file = @fread($fp, $count*300);
@fclose($fp);
$log = explode("\r\n",$file);
function getHistory($year, $month) {
$db = DB::db();
$str = "";
$prefix = "</>{$year}{$month}월:";
for($i=0; $i < $count; $i++) {
$line = $log[count($log)-2-$i];
if($line == "") {
continue;
}
if(strpos($line, $prefix) || $isFirst == 1) {
$str = ConvertLog($line).'<br>'.$str;
} else {
break;
}
$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($str == "") {
$str = "<C>●</>{$year}{$month}월: 기록 없음";
$str = ConvertLog($str);
if(!$texts){
return ConvertLog("<C>●</>{$year}{$month}월: 기록 없음");
}
return $str;
return join('<br>', $texts);
}
function getGenHistory($count, $year, $month, $isFirst=0) {
@@ -64,24 +57,37 @@ function getGenHistory($count, $year, $month, $isFirst=0) {
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
'showMe'=>false,
'aux'=>[]
]);
$map['month'] = $obj['month'];
$map['year'] = $obj['year'];
$map['startYear'] = $obj['startyear'];
if($isFirst == 1){
$map['year'] -= 1;
$map['month'] = 12;
$map['month'] -= 1;
if($map['month'] == 0){
$map['month'] = 12;
$map['year'] -= 1;
}
}
$startYear = $map['startYear'];
$startYear = $obj['startyear'];
$year = $map['year'];
$month = $map['month'];
$map_json = json_encode($map, JSON_UNESCAPED_UNICODE);
$log = getHistory(20, $year, $month, $isFirst);
$log = getHistory($year, $month);
$genlog = getGenHistory(50, $year, $month, $isFirst);
$nationStr = "";
@@ -89,7 +95,7 @@ function LogHistory($isFirst=0) {
$genStr = "";
$cityStr = "";
$db = DB::db();
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']);
+4 -4
View File
@@ -7,10 +7,10 @@ class MapRequest{
public $neutralView;
public $showMe;
function __construct($obj){
$this->year = $obj['year'];
$this->month = $obj['month'];
$this->aux = $obj['aux'];
$this->neutralView = $obj['neutralView'];
$this->year = Util::array_get($obj['year']);
$this->month = Util::array_get($obj['month']);
$this->aux = Util::array_get($obj['aux'],[]);
$this->neutralView = Util::array_get($obj['neutralView'], false);
$this->showMe = $obj['showMe'];
}
}
+15 -15
View File
@@ -443,7 +443,7 @@ function process_52($connect, &$general) {
// $log = checkAbility($connect, $general, $log);
}
pushHistory($history);
pushHistory($history, $admin['year'], $admin['month']);
pushGenLog($general, $log);
}
@@ -681,7 +681,7 @@ function process_62($connect, &$general) {
PushMsg(3, $younation['nation'], $general['picture'], $general['imgsvr'], "{$general['name']}:{$nation['name']}", $nation['color'], $younation['name'], $younation['color'], $youmsg);
}
pushHistory($history);
pushHistory($history, $admin['year'], $admin['month']);
pushAllLog($alllog);
pushGenLog($general, $log);
}
@@ -899,7 +899,7 @@ function process_65($connect, &$general) {
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
}
pushHistory($history);
pushHistory($history, $admin['year'], $admin['month']);
pushAllLog($alllog);
pushGenLog($general, $log);
}
@@ -985,7 +985,7 @@ function process_66($connect, &$general) {
refreshNationStaticInfo();
}
pushHistory($history);
pushHistory($history, $admin['year'], $admin['month']);
pushAllLog($alllog);
pushGenLog($general, $log);
}
@@ -1072,7 +1072,7 @@ function process_67($connect, &$general) {
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
}
pushHistory($history);
pushHistory($history, $admin['year'], $admin['month']);
pushAllLog($alllog);
pushGenLog($general, $log);
}
@@ -1171,7 +1171,7 @@ function process_68($connect, &$general) {
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
}
pushHistory($history);
pushHistory($history, $admin['year'], $admin['month']);
pushAllLog($alllog);
pushGenLog($general, $log);
}
@@ -1271,7 +1271,7 @@ function process_71($connect, &$general) {
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
}
// pushHistory($history);
// pushHistory($history, $admin['year'], $admin['month']);
// pushAllLog($alllog);
pushTrickLog($tricklog);
pushGenLog($general, $log);
@@ -1381,7 +1381,7 @@ function process_72($connect, &$general) {
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
}
// pushHistory($history);
// pushHistory($history, $admin['year'], $admin['month']);
// pushAllLog($alllog);
pushTrickLog($tricklog);
pushGenLog($general, $log);
@@ -1507,7 +1507,7 @@ function process_73($connect, &$general) {
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
}
// pushHistory($history);
// pushHistory($history, $admin['year'], $admin['month']);
// pushAllLog($alllog);
pushTrickLog($tricklog);
pushGenLog($general, $log);
@@ -1645,7 +1645,7 @@ function process_74($connect, &$general) {
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
}
// pushHistory($history);
// pushHistory($history, $admin['year'], $admin['month']);
// pushAllLog($alllog);
pushTrickLog($tricklog);
pushGenLog($general, $log);
@@ -1766,7 +1766,7 @@ function process_75($connect, &$general) {
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
}
// pushHistory($history);
// pushHistory($history, $admin['year'], $admin['month']);
// pushAllLog($alllog);
pushTrickLog($tricklog);
pushGenLog($general, $log);
@@ -1980,7 +1980,7 @@ function process_76($connect, &$general) {
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
}
// pushHistory($history);
// pushHistory($history, $admin['year'], $admin['month']);
// pushAllLog($alllog);
pushTrickLog($tricklog);
pushGenLog($general, $log);
@@ -2103,7 +2103,7 @@ function process_77($connect, &$general) {
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
}
// pushHistory($history);
// pushHistory($history, $admin['year'], $admin['month']);
// pushAllLog($alllog);
pushTrickLog($tricklog);
pushGenLog($general, $log);
@@ -2223,7 +2223,7 @@ function process_78($connect, &$general) {
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
}
// pushHistory($history);
// pushHistory($history, $admin['year'], $admin['month']);
// pushAllLog($alllog);
pushTrickLog($tricklog);
pushGenLog($general, $log);
@@ -2292,7 +2292,7 @@ function process_81($connect, &$general) {
refreshNationStaticInfo();
}
pushHistory($history);
pushHistory($history, $admin['year'], $admin['month']);
pushAllLog($alllog);
pushGenLog($general, $log);
}
+5 -5
View File
@@ -618,7 +618,7 @@ function process_46($connect, &$general) {
$log = uniqueItem($connect, $general, $log, 3);
}
pushHistory($history);
pushHistory($history, $admin['year'], $admin['month']);
pushAllLog($alllog);
pushGenLog($general, $log);
}
@@ -676,7 +676,7 @@ function process_47($connect, &$general) {
$query = "update diplomacy set state='2',term='0' where me='{$general['nation']}' or you='{$general['nation']}'";
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
pushHistory($history);
pushHistory($history, $admin['year'], $admin['month']);
refreshNationStaticInfo();
}
@@ -742,7 +742,7 @@ function process_54($connect, &$general) {
}
pushGenLog($general, $log);
pushGenLog($nextruler, $youlog);
pushHistory($history);
pushHistory($history, $admin['year'], $admin['month']);
}
function process_55($connect, &$general) {
@@ -826,7 +826,7 @@ function process_55($connect, &$general) {
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
}
}
pushHistory($history);
pushHistory($history, $admin['year'], $admin['month']);
pushAllLog($alllog);
pushGenLog($general, $log);
}
@@ -942,5 +942,5 @@ function process_57($connect, &$general) {
pushGenLog($general, $log);
pushGenLog($ruler, $youlog);
pushAllLog($alllog);
pushHistory($history);
pushHistory($history, $admin['year'], $admin['month']);
}
+4 -4
View File
@@ -37,7 +37,7 @@ function processSpring($connect) {
$admin = MYDB_fetch_array($result);
$history[0] = "<R>★</>{$admin['year']}{$admin['month']}월: <S>모두들 즐거운 게임 하고 계신가요? ^^ <Y>삼국일보</> 애독해 주시고, <M>훼접</>은 삼가주세요~</>";
pushHistory($history);
pushHistory($history, $admin['year'], $admin['month']);
}
function processGoldIncome($connect) {
@@ -109,7 +109,7 @@ function processGoldIncome($connect) {
}
$history[0] = "<C>●</>{$admin['year']}{$admin['month']}월:<W><b>【지급】</b></>봄이 되어 봉록에 따라 자금이 지급됩니다.";
pushHistory($history);
pushHistory($history, $admin['year'], $admin['month']);
pushAdminLog($adminLog);
}
@@ -401,7 +401,7 @@ function processRiceIncome($connect) {
}
$history[0] = "<C>●</>{$admin['year']}{$admin['month']}월:<W><b>【지급】</b></>가을이 되어 봉록에 따라 군량이 지급됩니다.";
pushHistory($history);
pushHistory($history, $admin['year'], $admin['month']);
pushAdminLog($adminLog);
}
@@ -676,5 +676,5 @@ function disaster($connect) {
}
}
pushHistory($disaster);
pushHistory($disaster, $admin['year'], $admin['month']);
}
+2 -2
View File
@@ -276,7 +276,7 @@ function startTournament($connect, $auto, $type) {
case 2: $history[0] = "<S>◆</>{$admin['year']}{$admin['month']}월: <C>일기토</> 대회가 개최됩니다! 천하의 <span class='ev_highlight'>용사</span>들을 모집하고 있습니다!"; break;
case 3: $history[0] = "<S>◆</>{$admin['year']}{$admin['month']}월: <C>설전</> 대회가 개최됩니다! 천하의 <span class='ev_highlight'>책사</span>들을 모집하고 있습니다!"; break;
}
pushHistory($history);
pushHistory($history, $admin['year'], $admin['month']);
}
function fillLowGenAll($connect) {
@@ -646,7 +646,7 @@ function setGift($connect, $tnmt_type, $tnmt, $phase) {
$cost2 = $admin['develcost'] * 12;
$history[0] = "<S>◆</>{$admin['year']}{$admin['month']}월: <C>{$tp}</> 대회에서 <Y>{$general['name']}</>(이)가 <C>우승</>, <Y>{$general2['name']}</>(이)가 <C>준우승</>을 차지하여 천하에 이름을 떨칩니다!";
$history[1] = "<S>◆</>{$admin['year']}{$admin['month']}월: <C>{$tp}</> 대회의 <S>우승자</>에게는 <C>{$cost}</>, <S>준우승자</>에겐 <C>{$cost2}</>의 <S>상금</>과 약간의 <S>명성</>이 주어집니다!";
pushHistory($history);
pushHistory($history, $admin['year'], $admin['month']);
for($i=0; $i < count($genNo); $i++) {
$general['no'] = $genNo[$i];
+2
View File
@@ -207,6 +207,8 @@ $db->update('plock', [
'plock'=>0
], true);
LogHistory(1);
Json::die([
'result'=>true
]);
+1 -1
View File
@@ -235,7 +235,7 @@ if($id_num) {
$log[1] = "<C>●</>{$admin['month']}월:<C>".getGenSpecial($special2)."</> 특기를 가진 <C>천재</>의 등장으로 온 천하가 떠들썩합니다.";
$history[0] = "<C>●</>{$admin['year']}{$admin['month']}월:<L><b>【천재】</b></><G><b>{$cityname['name']}</b></>에 천재가 등장했습니다.";
pushHistory($history);
pushHistory($history, $admin['year'], $admin['month']);
} else {
$log[0] = "<C>●</>{$admin['month']}월:<G><b>{$cityname['name']}</b></>에서 <Y>{$me['name']}</>(이)라는 호걸이 천하에 이름을 알립니다.";
}
+1 -1
View File
@@ -339,7 +339,7 @@ class Scenario{
pushHistory($this->history);
pushHistory($this->history, $env['year'], $env['month']);
refreshNationStaticInfo();
foreach(getAllNationStaticInfo() as $nation){
+1 -1
View File
@@ -85,7 +85,7 @@ class NPC{
$db = DB::db();
if($age == \sammo\GameConst::$adultAge && $month == 1){//FIXME: 14가 어디서 튀어나왔나?
\sammo\pushHistory(["<C>●</>1월:<Y>$name</>(이)가 성인이 되어 <S>등장</>했습니다."]);
\sammo\pushHistory(["<C>●</>1월:<Y>$name</>(이)가 성인이 되어 <S>등장</>했습니다."], $year, $month);
}
if($this->ego == null){
+5 -2
View File
@@ -37,5 +37,8 @@ DROP TABLE IF EXISTS statistic;
#
DROP TABLE IF EXISTS history;
#
DROP TABLE IF EXISTS event;
#
DROP TABLE IF EXISTS event;
# ( ?)
DROP TABLE IF EXISTS full_history;
+15 -1
View File
@@ -605,4 +605,18 @@ CREATE TABLE `event` (
PRIMARY KEY (`id`)
)
DEFAULT CHARSET=utf8mb4
ENGINE=InnoDB;
ENGINE=InnoDB;
##
CREATE TABLE `full_history` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`year` INT(4) NOT NULL,
`month` INT(2) NOT NULL,
`text` TEXT NOT NULL,
PRIMARY KEY (`id`),
INDEX `date` (`year`, `month`, `id`)
)
DEFAULT CHARSET=utf8mb4
ENGINE=InnoDB
;