From 7b7baaea62d19f3249cd1305fd29b60fc9b18c35 Mon Sep 17 00:00:00 2001 From: hide_d Date: Mon, 21 Jan 2019 02:23:23 +0900 Subject: [PATCH] =?UTF-8?q?=EC=99=B8=EA=B5=90=20=EC=84=9C=EC=8B=A0=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20=EA=B8=B0=EB=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwe/j_add_diplomatic_letter.php | 138 ++++++++++++++++++++++++++++++++ hwe/sql/schema.sql | 2 +- 2 files changed, 139 insertions(+), 1 deletion(-) create mode 100644 hwe/j_add_diplomatic_letter.php diff --git a/hwe/j_add_diplomatic_letter.php b/hwe/j_add_diplomatic_letter.php new file mode 100644 index 00000000..56a4aeb0 --- /dev/null +++ b/hwe/j_add_diplomatic_letter.php @@ -0,0 +1,138 @@ +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() +]); \ No newline at end of file diff --git a/hwe/sql/schema.sql b/hwe/sql/schema.sql index 01523d2f..43370f33 100644 --- a/hwe/sql/schema.sql +++ b/hwe/sql/schema.sql @@ -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,