diff --git a/hwe/sammo/Message.php b/hwe/sammo/Message.php index 086cc179..466766aa 100644 --- a/hwe/sammo/Message.php +++ b/hwe/sammo/Message.php @@ -19,9 +19,9 @@ class Message protected $sendCnt = 0; public $msgType; - /** @var MessageTarget */ + /** @var \sammo\MessageTarget */ public $src; - /** @var MessageTarget */ + /** @var \sammo\MessageTarget */ public $dest; public $msg; /** @var \DateTime */ diff --git a/hwe/sammo/ScoutMessage.php b/hwe/sammo/ScoutMessage.php index 7295f422..35c94ca5 100644 --- a/hwe/sammo/ScoutMessage.php +++ b/hwe/sammo/ScoutMessage.php @@ -3,6 +3,11 @@ namespace sammo; class ScoutMessage extends Message{ + const ACCEPTED = 1; + const DECLINED = -1; + const INVALID = 0; + protected $validScout = true; + public function __construct( string $msgType, MessageTarget $src, @@ -16,12 +21,44 @@ class ScoutMessage extends Message{ if ($msgType !== self::MSGTYPE_PRIVATE){ throw new \InvalidArgumentException('DiplomaticMessage msgType'); } - parent::__construct(...func_get_args()); - //TODO: 누가, 누구에게 보낸 건지 파싱 + if(Util::array_get($msgOption['action']) !== 'scout'){ + throw new \InvalidArgumentException('Action !== scout'); + } + + parent::__construct(...func_get_args()); + + if(Util::array_get($msgOption['used'])){ + $this->validScout = false; + } } - public static function generateScoutMessage(int $srcGeneralID, int $destGeneralID, &$reason = null, \DateTime $date = null): Message{ + /** + * @return int 수행 결과 반환, ACCEPTED(등용장 소모), DECLINED(등용장 소모), INVALID 중 반환 + */ + public function agreeMessage(string &$reason=null):int{ + //NOTE: 올바른 유저가 agreeMessage() 호출을 한건지는 외부에서 체크 필요(Session->userID 등) + + if(!$this->validScout){ + if($reason !== null){ + $reason = '이미 사용한 등용장입니다'; + } + return self::INVALID; + } + if($this->mailbox !== $this->dest->generalID){ + if($reason !== null){ + $reason = '송신자가 등용장을 수락할 수 없습니다'; + } + return self::INVALID; + } + + + $db = DB::db(); + $general = $db->queryFirstRow('SELECT nation, `no`, city, nations FROM general WHERE `no`=%i', $this->dest->generalID); + + } + + public static function buildScoutMessage(int $srcGeneralID, int $destGeneralID, &$reason = null, \DateTime $date = null): Message{ if($srcGeneralID == $destGeneralID){ if($reason !== null){ $reason = '같은 장수에게 등용장을 보낼 수 없습니다'; @@ -84,8 +121,5 @@ class ScoutMessage extends Message{ return new ScoutMessage(Message::MSGTYPE_PRIVATE, $src, $dest, $msg, $date, $validUntil, $msgOption); } - public function send(){ - $this->sendToReceiver(); - } } \ No newline at end of file