외교 서신 추가 기능

This commit is contained in:
2019-04-07 22:17:13 +09:00
parent 36d83804d0
commit 7b7baaea62
2 changed files with 139 additions and 1 deletions
+138
View File
@@ -0,0 +1,138 @@
<?php
namespace sammo;
include "lib.php";
include "func.php";
//로그인 검사
$session = Session::requireGameLogin()->setReadOnly();
$userID = Session::getUserID();
$db = DB::db();
$destNationNo = Util::getReq('destNation', 'int', 0);
$prevNo = Util::getReq('prevNo', 'int', null);
$textBrief = Util::getReq('textBrief');
$textDetail = Util::getReq('textDetail');
increaseRefresh("외교부", 1);
$me = $db->queryFirstRow('SELECT no, nation, level, permission, con, turntime, belong, penalty FROM general WHERE owner=%i', $userID);
$con = checkLimit($me['con']);
if ($con >= 2) {
Json::die([
'result'=>false,
'reason'=>'접속 제한입니다.'
]);
}
if($destNationNo == $me['nation']){
Json::die([
'result'=>false,
'reason'=>'자국으로 보낼 수 없습니다.'
]);
}
if($textBrief === null || $textDetail === null){
Json::die([
'result'=>false,
'reason'=>'올바르지 않은 입력입니다.'
]);
}
$textBrief = trim($textBrief);
$textDetail = trim($textDetail);
if(!$textBrief){
Json::die([
'result'=>false,
'reason'=>'요약문이 비어있습니다'
]);
}
$permission = checkSecretPermission($me);
if ($permission < 2) {
Json::die([
'result'=>false,
'reason'=>'권한이 부족합니다. 수뇌부가 아닙니다.'
]);
}
$srcNationNo = $me['nation'];
$nations = $db->query('SELECT nation, name, color FROM nation WHERE nation IN (%i, %i)', $srcNationNo, $destNationNo);
if(count($nations) != 2){
Json::die([
'result'=>false,
'reason'=>'올바르지 않은 국가입니다.'
]);
}
if($prevNo !== null){
//state는 체크하지 않는걸로 하자. 파기한 것을 재 송신하는 경우도 있을 수 있음.
$prevLetter = $db->queryFirstRow(
'SELECT no, state, aux FROM ng_diplomacy WHERE no = %i AND src_nation_id IN (%i, %i) AND dest_nation_id IN (%i, %i)',
$prevNo,
$srcNationNo, $destNationNo,
$srcNationNo, $destNationNo
);
if(!$prevLetter){
Json::die([
'result'=>false,
'reason'=>'이전 문서가 없습니다.'
]);
}
if($prevLetter['state'] == 'proposed'){
$prevAux = Json::decode($prevLetter['aux']);
$prevAux['reason'] = [
'who'=>$me['no'],
'action'=>'new_letter'
];
$db->update('ng_diplomacy', [
'state'=>'cancelled',
'aux'=>Json::encode($prevAux)
], 'no=%i', $prevNo);
}
}
if($nations[0]['nation'] == $me['nation']){
//index 순서에 따라 또 모름.
$srcNation = $nations[0];
$destNation = $nations[1];
}
else{
$srcNation = $nations[1];
$destNation = $nations[0];
}
$db->insert('ng_diplomacy', [
'src_nation_id'=>$srcNation['nation'],
'dest_nation_id'=>$destNation['nation'],
'prev_no'=>$prevNo,
'state'=>'proposed',
'text_brief'=>$textBrief,
'text_detail'=>$textDetail,
'date'=>TimeUtil::DatetimeNow(),
'src_signer'=>$me['no'],
'dest_signer'=>null,
'aux'=>Json::encode([
'src'=>[
'nationName'=>$srcNation['name'],
'nationColor'=>$srcNation['color'],
'generalName'=>$me['name']
],
'dest'=>[
'nationName'=>$destNation['name'],
'nationColor'=>$destNation['color']
]
]),
]);
Json::die([
'result'=>false,
'reason'=>'success',
'row_id'=>$db->insertId()
]);
+1 -1
View File
@@ -580,7 +580,7 @@ CREATE TABLE `ng_diplomacy` (
`src_nation_id` INT(11) NOT NULL,
`dest_nation_id` INT(11) NOT NULL,
`prev_no` INT(11) NULL DEFAULT NULL,
`state` ENUM('proposed','activaed','cancelled') NOT NULL DEFAULT 'proposed',
`state` ENUM('proposed','activated','cancelled') NOT NULL DEFAULT 'proposed',
`text_brief` TEXT NOT NULL,
`text_detail` TEXT NOT NULL,
`date` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,