From 246751b4dd021e001409566217d1b0c990135363 Mon Sep 17 00:00:00 2001 From: Hide_D Date: Tue, 11 Jul 2023 22:43:09 +1000 Subject: [PATCH] =?UTF-8?q?feat:=20=EB=93=B1=EC=9A=A9=EC=9E=A5=20=EC=9D=BC?= =?UTF-8?q?=EA=B4=84=20=EB=AC=B4=ED=9A=A8=ED=99=94=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwe/sammo/ScoutMessage.php | 104 ++++++++++++++++++++++++------------- 1 file changed, 68 insertions(+), 36 deletions(-) diff --git a/hwe/sammo/ScoutMessage.php b/hwe/sammo/ScoutMessage.php index 0a5ffe23..bf954234 100644 --- a/hwe/sammo/ScoutMessage.php +++ b/hwe/sammo/ScoutMessage.php @@ -1,9 +1,11 @@ validScout = false; } - if($this->validUntil <= new \DateTime()){ + if ($this->validUntil <= new \DateTime()) { $this->validScout = false; } } - protected function checkScoutMessageValidation(int $receiverID){ - if(!$this->validScout){ + protected function checkScoutMessageValidation(int $receiverID) + { + if (!$this->validScout) { return [self::INVALID, '유효하지 않은 등용장입니다.']; } - if($this->mailbox !== $this->dest->generalID){ + if ($this->mailbox !== $this->dest->generalID) { return [self::INVALID, '송신자가 등용장을 처리할 수 없습니다.']; } - if($this->mailbox !== $receiverID){ + if ($this->mailbox !== $receiverID) { return [self::INVALID, '올바른 수신자가 아닙니다.']; } @@ -57,10 +59,11 @@ class ScoutMessage extends Message{ /** * @return int 수행 결과 반환, ACCEPTED(등용장 소모), DECLINED(등용장 소모), INVALID 중 반환 */ - public function agreeMessage(int $receiverID, string &$reason):int{ + public function agreeMessage(int $receiverID, string &$reason): int + { //NOTE: 올바른 유저가 agreeMessage() 호출을 한건지는 외부에서 체크 필요(Session->userID 등) - if(!$this->id){ + if (!$this->id) { throw new \RuntimeException('전송되지 않은 메시지에 수락 진행 중'); } @@ -71,20 +74,20 @@ class ScoutMessage extends Message{ list($result, $reason) = $this->checkScoutMessageValidation($receiverID); - if($result !== self::ACCEPTED){ + if ($result !== self::ACCEPTED) { $logger->pushGeneralActionLog("{$reason} 등용 수락 불가."); - if($result === self::DECLINED){ + if ($result === self::DECLINED) { $this->_declineMessage(); } return $result; } $commandObj = buildGeneralCommandClass('che_등용수락', $general, $gameStor->getAll(true), [ - 'destNationID'=>$this->src->nationID, - 'destGeneralID'=>$this->src->generalID, + 'destNationID' => $this->src->nationID, + 'destGeneralID' => $this->src->generalID, ]); - if(!$commandObj->hasFullConditionMet()){ + if (!$commandObj->hasFullConditionMet()) { $logger->pushGeneralActionLog($commandObj->getFailString()); $reason = $commandObj->getFailString(); return self::DECLINED; @@ -96,6 +99,7 @@ class ScoutMessage extends Message{ //메시지 비 활성화 $this->msgOption['used'] = true; $this->invalidate(); + static::invalidateAll($this->src->generalID, $this->id); $this->validScout = false; $josaRo = JosaUtil::pick($this->src->nationName, '로'); @@ -107,7 +111,7 @@ class ScoutMessage extends Message{ new \DateTime(), new \DateTime('9999-12-31'), [ - 'delete'=>$this->id + 'delete' => $this->id ] ); $newMsg->send(true); @@ -115,7 +119,33 @@ class ScoutMessage extends Message{ return self::ACCEPTED; } - protected function _declineMessage(){ + public static function invalidateAll(int $generalID, ?int $exceptMsgID = null) + { + $db = DB::db(); + $now = TimeUtil::now(); + //XXX: 뭔가 기존 쿼리가 애매하다. invalid 관련해서 다른 옵션이 가능한가? + $rawMsgList = Util::convertArrayToDict($db->query( + 'SELECT * FROM `message` WHERE + `mailbox` = %i AND `type` = "private" AND `dest` = `mailbox` AND `valid_until` > %s AND + JSON_VALUE(message, "$.option.action") = %s', + $generalID, + $now, + 'scout', + ), 'id'); + if ($exceptMsgID && key_exists($exceptMsgID, $rawMsgList)) { + unset($rawMsgList[$exceptMsgID]); + } + if (!$rawMsgList) { + return; + } + foreach ($rawMsgList as $rawMsg) { + $msg = static::buildFromArray($rawMsg); + $msg->invalidate(); + } + } + + protected function _declineMessage() + { $this->msgOption['used'] = true; $this->invalidate(); $this->validScout = false; @@ -129,7 +159,7 @@ class ScoutMessage extends Message{ new \DateTime(), new \DateTime('9999-12-31'), [ - 'delete'=>$this->id + 'delete' => $this->id ] ); $newMsg->send(true); @@ -137,8 +167,9 @@ class ScoutMessage extends Message{ return self::DECLINED; } - public function declineMessage(int $receiverID, string &$reason):int{ - if(!$this->id){ + public function declineMessage(int $receiverID, string &$reason): int + { + if (!$this->id) { throw new \RuntimeException('전송되지 않은 메시지에 거절 진행 중'); } @@ -148,7 +179,7 @@ class ScoutMessage extends Message{ list($result, $reason) = $this->checkScoutMessageValidation($receiverID); - if($result === self::INVALID){ + if ($result === self::INVALID) { (new ActionLogger($receiverID, 0, $year, $month))->pushGeneralActionLog("{$reason} 등용 취소 불가.", ActionLogger::PLAIN); return $result; } @@ -162,9 +193,10 @@ class ScoutMessage extends Message{ return self::DECLINED; } - public static function buildScoutMessage(int $srcGeneralID, int $destGeneralID, &$reason = null, \DateTime $date = null):?self{ - if($srcGeneralID == $destGeneralID){ - if($reason !== null){ + public static function buildScoutMessage(int $srcGeneralID, int $destGeneralID, &$reason = null, \DateTime $date = null): ?self + { + if ($srcGeneralID == $destGeneralID) { + if ($reason !== null) { $reason = '같은 장수에게 등용장을 보낼 수 없습니다'; } return null; @@ -173,26 +205,26 @@ class ScoutMessage extends Message{ $db = DB::db(); $srcGeneral = $db->queryFirstRow('SELECT `name`, nation FROM general WHERE `no`=%i', $srcGeneralID); $destGeneral = $db->queryFirstRow('SELECT `name`, nation, `officer_level` FROM general WHERE `no`=%i', $destGeneralID); - if($date === null){ + if ($date === null) { $date = new \DateTime(); } - if($destGeneral['officer_level'] == 12){ - if($reason !== null){ + if ($destGeneral['officer_level'] == 12) { + if ($reason !== null) { $reason = '군주에게 등용장을 보낼 수 없습니다'; } return null; } - if(!$srcGeneral['nation']){ - if($reason !== null){ + if (!$srcGeneral['nation']) { + if ($reason !== null) { $reason = '재야 상태일 때에는 등용장을 보낼 수 없습니다'; } return null; } - if($srcGeneral['nation'] === $destGeneral['nation']){ - if($reason !== null){ + if ($srcGeneral['nation'] === $destGeneral['nation']) { + if ($reason !== null) { $reason = '같은 소속의 장수에게 등용장을 보낼 수 없습니다'; } return null; @@ -222,9 +254,9 @@ class ScoutMessage extends Message{ $validUntil = new \DateTime("9999-12-31 12:59:59"); $msgOption = [ - 'action'=>'scout' + 'action' => 'scout' ]; return new ScoutMessage(MessageType::private, $src, $dest, $msg, $date, $validUntil, $msgOption); } -} \ No newline at end of file +}