국방,임관권유문을 KVStorage로 분리

This commit is contained in:
2020-05-05 19:55:59 +09:00
parent 6ac12d42fe
commit d0fa094d04
10 changed files with 75 additions and 36 deletions
+1 -1
View File
@@ -86,7 +86,7 @@ $sel2[$type2] = "selected";
<select name=nation size=1 style=color:white;background-color:black>"; <select name=nation size=1 style=color:white;background-color:black>";
<option value=0>재야</option>"; <option value=0>재야</option>";
<?php <?php
$query = "select nation,name,color,scout,scoutmsg,gennum from nation order by power"; $query = "select nation,name,color,scout,gennum from nation order by power";
$result = MYDB_query($query, $connect) or Error("aaa_processing.php " . MYDB_error($connect), ""); $result = MYDB_query($query, $connect) or Error("aaa_processing.php " . MYDB_error($connect), "");
$count = MYDB_num_rows($result); $count = MYDB_num_rows($result);
for ($i = 1; $i <= $count; $i++) { for ($i = 1; $i <= $count; $i++) {
+8 -4
View File
@@ -9,14 +9,14 @@ $userID = Session::getUserID();
$db = DB::db(); $db = DB::db();
$gameStor = KVStorage::getStorage($db, 'game_env'); $gameStor = KVStorage::getStorage($db, 'game_env');
$connect=$db->get(); $nationStor = KVStorage::getStorage($db, 'nation_env');
increaseRefresh("내무부", 1); increaseRefresh("내무부", 1);
$me = $db->queryFirstRow('SELECT no, nation, officer_level, con, turntime, belong, permission, penalty FROM general WHERE owner=%i', $userID); $me = $db->queryFirstRow('SELECT no, nation, officer_level, con, turntime, belong, permission, penalty FROM general WHERE owner=%i', $userID);
$nationID = $me['nation']; $nationID = $me['nation'];
$nation = $db->queryFirstRow('SELECT nation,level,name,color,type,gold,rice,bill,rate,scout,war,secretlimit,msg,scoutmsg,capital FROM nation WHERE nation = %i', $nationID); $nation = $db->queryFirstRow('SELECT nation,level,name,color,type,gold,rice,bill,rate,scout,war,secretlimit,capital FROM nation WHERE nation = %i', $nationID);
$con = checkLimit($me['con']); $con = checkLimit($me['con']);
if ($con >= 2) { if ($con >= 2) {
@@ -42,6 +42,10 @@ if ($me['officer_level'] >= 5) {
$read = "readonly"; $read = "readonly";
} }
$noticeKey = "nation_notice_{$nationID}";
$scoutKey = "nation_scout_msg_{$nationID}";
$nationStor->cacheValues([$noticeKey, $scoutKey]);
?> ?>
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
@@ -52,8 +56,8 @@ if ($me['officer_level'] >= 5) {
<title><?=UniqueConst::$serverName?>: 내무부</title> <title><?=UniqueConst::$serverName?>: 내무부</title>
<script> <script>
var editable = <?=(($me['officer_level']>=5||$permission==4)?'true':'false')?>; var editable = <?=(($me['officer_level']>=5||$permission==4)?'true':'false')?>;
var nationMsg = <?=Json::encode($nation['msg']??'')?>; var nationMsg = <?=Json::encode($nationStor->{$noticeKey}??'')?>;
var scoutmsg = <?=Json::encode($nation['scoutmsg']??'')?>; var scoutmsg = <?=Json::encode($nationStor->{$scoutKey}??'')?>;
</script> </script>
<?=WebUtil::printJS('../e_lib/jquery-3.3.1.min.js')?> <?=WebUtil::printJS('../e_lib/jquery-3.3.1.min.js')?>
<?=WebUtil::printJS('../e_lib/bootstrap.bundle.min.js')?> <?=WebUtil::printJS('../e_lib/bootstrap.bundle.min.js')?>
+14 -13
View File
@@ -31,48 +31,49 @@ else if ($me['officer_level'] < 5 && $permission != 4) {
exit(); exit();
} }
$nationStor = KVStorage::getStorage($db, 'nation_env');
$nationID = $me['nation'];
$noticeKey = "nation_notice_{$nationID}";
$scoutKey = "nation_scout_msg_{$nationID}";
if($btn == "국가방침 수정") { if($btn == "국가방침 수정") {
$msg = mb_substr($msg, 0, 16384); $msg = mb_substr($msg, 0, 16384);
//$msg = StringUtil:: //$msg = StringUtil::
$db->update('nation', [ $nationStor->{$noticeKey} = WebUtil::htmlPurify($msg);
'msg'=>WebUtil::htmlPurify($msg)
], 'nation=%i',$me['nation']);
} elseif($btn == "임관 권유문 수정") { } elseif($btn == "임관 권유문 수정") {
$scoutmsg = mb_substr($scoutmsg, 0, 1000); $scoutmsg = mb_substr($scoutmsg, 0, 1000);
$db->update('nation', [ $nationStor->{$scoutKey} = WebUtil::htmlPurify($scoutmsg);
'scoutmsg'=>WebUtil::htmlPurify($scoutmsg)
], 'nation=%i',$me['nation']);
} elseif($btn == "세율") { } elseif($btn == "세율") {
$rate = Util::valueFit($rate, 5, 30); $rate = Util::valueFit($rate, 5, 30);
$db->update('nation', [ $db->update('nation', [
'rate'=>$rate, 'rate'=>$rate,
], 'nation=%i', $me['nation']); ], 'nation=%i', $nationID);
} elseif($btn == "지급률") { } elseif($btn == "지급률") {
$bill = Util::valueFit($bill, 20, 200); $bill = Util::valueFit($bill, 20, 200);
$db->update('nation', [ $db->update('nation', [
'bill'=>$bill 'bill'=>$bill
], 'nation=%i',$me['nation']); ], 'nation=%i',$nationID);
} elseif($btn == "기밀권한") { } elseif($btn == "기밀권한") {
$secretlimit = Util::valueFit($secretlimit, 1, 99); $secretlimit = Util::valueFit($secretlimit, 1, 99);
$db->update('nation', [ $db->update('nation', [
'secretlimit'=>$secretlimit 'secretlimit'=>$secretlimit
], 'nation=%i',$me['nation']); ], 'nation=%i',$nationID);
} elseif($btn == "임관 금지") { } elseif($btn == "임관 금지") {
$db->update('nation', [ $db->update('nation', [
'scout'=>1 'scout'=>1
], 'nation=%i',$me['nation']); ], 'nation=%i',$nationID);
} elseif($btn == "임관 허가") { } elseif($btn == "임관 허가") {
$db->update('nation', [ $db->update('nation', [
'scout'=>0 'scout'=>0
], 'nation=%i',$me['nation']); ], 'nation=%i',$nationID);
} elseif($btn == "전쟁 금지") { } elseif($btn == "전쟁 금지") {
$db->update('nation', [ $db->update('nation', [
'war'=>1 'war'=>1
], 'nation=%i',$me['nation']); ], 'nation=%i',$nationID);
} elseif($btn == "전쟁 허가") { } elseif($btn == "전쟁 허가") {
$db->update('nation', [ $db->update('nation', [
'war'=>0 'war'=>0
], 'nation=%i',$me['nation']); ], 'nation=%i',$nationID);
} }
header('location:b_dipcenter.php'); header('location:b_dipcenter.php');
+6 -7
View File
@@ -193,7 +193,7 @@ function myNationInfo()
$result = MYDB_query($query, $connect) or Error(__LINE__ . MYDB_error($connect), ""); $result = MYDB_query($query, $connect) or Error(__LINE__ . MYDB_error($connect), "");
$me = MYDB_fetch_array($result); $me = MYDB_fetch_array($result);
$query = "select nation,name,color,power,msg,gold,rice,bill,rate,scout,war,strategic_cmd_limit,surlimit,tech,level,type from nation where nation='{$me['nation']}'"; $query = "select nation,name,color,power,gold,rice,bill,rate,scout,war,strategic_cmd_limit,surlimit,tech,level,type from nation where nation='{$me['nation']}'";
$result = MYDB_query($query, $connect) or Error(__LINE__ . MYDB_error($connect), ""); $result = MYDB_query($query, $connect) or Error(__LINE__ . MYDB_error($connect), "");
$nation = MYDB_fetch_array($result); $nation = MYDB_fetch_array($result);
@@ -898,12 +898,11 @@ function onlinegen()
function nationMsg(General $general) function nationMsg(General $general)
{ {
$db = DB::db(); $db = DB::db();
$msg = $db->queryFirstField( $nationStor = KVStorage::getStorage($db, 'nation_env');
'SELECT msg FROM nation WHERE nation = %i', $nationID = $general->getNationID();
$general->getNationID() $noticeKey = "nation_notice_{$nationID}";
);
return $nationStor->{$noticeKey}??'';
return $msg ?: '';
} }
function banner() function banner()
+12 -1
View File
@@ -76,7 +76,18 @@ if ($gencount >= $admin['maxgeneral']) {
exit(); exit();
} }
$nationList = $db->query('SELECT nation,`name`,color,scout,scoutmsg FROM nation ORDER BY rand()'); $nationList = $db->query('SELECT nation,`name`,color,scout FROM nation');
shuffle($nationList);
$nationList = Util::convertArrayToDict($nationList, 'nation');
$nationStor = KVStorage::getStorage($db, 'nation_env');
//NOTE: join 안할것임
$scoutMsgs = $nationStor->getValues(array_map(function($nationID){
return "nation_scout_msg_{$nationID}";
}, array_keys($nationList)));
foreach($scoutMsgs as $nationIDPack=>$scoutMsg){
$nationID = Util::toInt(Util::array_last(explode('_', $nationIDPack)));
$nationList[$nationID]['scoutmsg'] = $scoutMsg;
}
echo getInvitationList($nationList); echo getInvitationList($nationList);
?> ?>
+16 -3
View File
@@ -8,7 +8,8 @@ use \sammo\{
GameConst, GameUnitConst, GameConst, GameUnitConst,
LastTurn, LastTurn,
Command, Command,
Json Json,
KVStorage
}; };
@@ -217,8 +218,18 @@ class che_임관 extends Command\GeneralCommand{
$joinedNations = $generalObj->getAuxVar('joinedNations')??[]; $joinedNations = $generalObj->getAuxVar('joinedNations')??[];
$nationList = $db->query('SELECT nation,`name`,color,scout,scoutmsg,gennum FROM nation'); $nationList = $db->query('SELECT nation,`name`,color,scout,gennum FROM nation');
shuffle($nationList); shuffle($nationList);
$nationList = Util::convertArrayToDict($nationList, 'nation');
$nationStor = KVStorage::getStorage($db, 'nation_env');
//NOTE: join 안할것임
$scoutMsgs = $nationStor->getValues(array_map(function($nationID){
return "nation_scout_msg_{$nationID}";
}, array_keys($nationList)));
foreach($scoutMsgs as $nationIDPack=>$scoutMsg){
$nationID = Util::toInt(Util::array_last(explode('_', $nationIDPack)));
$nationList[$nationID]['scoutmsg'] = $scoutMsg;
}
foreach($nationList as &$nation){ foreach($nationList as &$nation){
if($env['year'] < $env['startyear']+3 && $nation['gennum'] >= GameConst::$initialNationGenLimit){ if($env['year'] < $env['startyear']+3 && $nation['gennum'] >= GameConst::$initialNationGenLimit){
@@ -234,6 +245,8 @@ class che_임관 extends Command\GeneralCommand{
if(in_array($nation['nation'], $joinedNations)){ if(in_array($nation['nation'], $joinedNations)){
$nation['availableJoin'] = false; $nation['availableJoin'] = false;
} }
} }
unset($nation); unset($nation);
ob_start(); ob_start();
@@ -246,7 +259,7 @@ class che_임관 extends Command\GeneralCommand{
<?php foreach($nationList as $nation): ?> <?php foreach($nationList as $nation): ?>
<option <option
value='<?=$nation['nation']?>' value='<?=$nation['nation']?>'
style='color:<?=$nation['color']?><?=$nation['availableJoin']?'':'background-color:red;'?>' style='<?=$nation['availableJoin']?'':'background-color:red;'?>'
>【<?=$nation['name']?> 】</option> >【<?=$nation['name']?> 】</option>
<?php endforeach; ?> <?php endforeach; ?>
<input type=button id="commonSubmit" value="<?=$this->getName()?>"> <input type=button id="commonSubmit" value="<?=$this->getName()?>">
+5 -2
View File
@@ -3,6 +3,7 @@ namespace sammo\Scenario;
use \sammo\DB; use \sammo\DB;
use \sammo\GameConst; use \sammo\GameConst;
use \sammo\Util; use \sammo\Util;
use \sammo\KVStorage;
use function \sammo\getNationChiefLevel; use function \sammo\getNationChiefLevel;
class Nation{ class Nation{
@@ -82,6 +83,7 @@ class Nation{
} }
$db = DB::db(); $db = DB::db();
$nationStor = KVStorage::getStorage($db, 'nation_env');
$otherNations = $db->queryFirstColumn('SELECT nation FROM nation'); $otherNations = $db->queryFirstColumn('SELECT nation FROM nation');
$db->insert('nation', [ $db->insert('nation', [
@@ -98,7 +100,6 @@ class Nation{
'war'=>0, 'war'=>0,
'strategic_cmd_limit'=>24, 'strategic_cmd_limit'=>24,
'surlimit'=>72, 'surlimit'=>72,
'scoutmsg'=>$this->infoText,
'tech'=>$this->tech, 'tech'=>$this->tech,
'level'=>$this->nationLevel, 'level'=>$this->nationLevel,
'type'=>$type, 'type'=>$type,
@@ -109,7 +110,9 @@ class Nation{
'nation'=>$this->id 'nation'=>$this->id
], 'city IN %li', $cities); ], 'city IN %li', $cities);
} }
$scoutKey = "nation_scout_msg_{$this->id}";
$nationStor->{$scoutKey} = $this->infoText;
$diplomacy = []; $diplomacy = [];
+12 -1
View File
@@ -18,7 +18,18 @@ if(!$npcmode) {
$gencount = $db->queryFirstField('SELECT count(`no`) FROM general WHERE npc<2'); $gencount = $db->queryFirstField('SELECT count(`no`) FROM general WHERE npc<2');
$nationList = $db->query('SELECT nation,`name`,color,scout,scoutmsg FROM nation ORDER BY rand()'); $nationList = $db->query('SELECT nation,`name`,color,scout FROM nation');
shuffle($nationList);
$nationList = Util::convertArrayToDict($nationList, 'nation');
$nationStor = KVStorage::getStorage($db, 'nation_env');
//NOTE: join 안할것임
$scoutMsgs = $nationStor->getValues(array_map(function($nationID){
return "nation_scout_msg_{$nationID}";
}, array_keys($nationList)));
foreach($scoutMsgs as $nationIDPack=>$scoutMsg){
$nationID = Util::toInt(Util::array_last(explode('_', $nationIDPack)));
$nationList[$nationID]['scoutmsg'] = $scoutMsg;
}
?> ?>
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
-3
View File
@@ -117,7 +117,6 @@ CREATE TABLE `nation` (
`name` VARCHAR(64) NOT NULL COLLATE 'utf8mb4_bin', `name` VARCHAR(64) NOT NULL COLLATE 'utf8mb4_bin',
`color` CHAR(10) NOT NULL, `color` CHAR(10) NOT NULL,
`onlinegen` TEXT NULL DEFAULT '', `onlinegen` TEXT NULL DEFAULT '',
`msg` TEXT NULL DEFAULT '',
`capital` INT(1) NULL DEFAULT '0', `capital` INT(1) NULL DEFAULT '0',
`capset` INT(6) NULL DEFAULT '0', `capset` INT(6) NULL DEFAULT '0',
`gennum` INT(3) NULL DEFAULT '1', `gennum` INT(3) NULL DEFAULT '1',
@@ -132,13 +131,11 @@ CREATE TABLE `nation` (
`war` INT(1) NULL DEFAULT '0', `war` INT(1) NULL DEFAULT '0',
`strategic_cmd_limit` INT(4) NULL DEFAULT '36', `strategic_cmd_limit` INT(4) NULL DEFAULT '36',
`surlimit` INT(4) NULL DEFAULT '72', `surlimit` INT(4) NULL DEFAULT '72',
`scoutmsg` TEXT NULL DEFAULT '',
`tech` float NULL DEFAULT '0', `tech` float NULL DEFAULT '0',
`power` INT(8) NULL DEFAULT '0', `power` INT(8) NULL DEFAULT '0',
`spy` TEXT NOT NULL DEFAULT '{}' CHECK (json_valid(`spy`)), `spy` TEXT NOT NULL DEFAULT '{}' CHECK (json_valid(`spy`)),
`level` INT(1) NULL DEFAULT '0', `level` INT(1) NULL DEFAULT '0',
`type` VARCHAR(20) NOT NULL DEFAULT 'che_중립', `type` VARCHAR(20) NOT NULL DEFAULT 'che_중립',
`rule` TEXT NULL DEFAULT '',
`aux` LONGTEXT NOT NULL DEFAULT '{}' CHECK (json_valid(`aux`)), `aux` LONGTEXT NOT NULL DEFAULT '{}' CHECK (json_valid(`aux`)),
PRIMARY KEY (`nation`) PRIMARY KEY (`nation`)
) )
+1 -1
View File
@@ -11,7 +11,7 @@
<td style="width:130px;text-align:center;" <td style="width:130px;text-align:center;"
><?=$nation['name']?></td> ><?=$nation['name']?></td>
<td><div style="width:870px;max-width:870px;max-height:200px;overflow:hidden;" <td><div style="width:870px;max-width:870px;max-height:200px;overflow:hidden;"
><?=$nation['scoutmsg']?:'-'?></div></td> ><?=$nation['scoutmsg']??'-'?></div></td>
</tr> </tr>
<?php endforeach; ?> <?php endforeach; ?>
</tbody> </tbody>