From b4ac34864519ecfbb53b11be9a8e9a4245e79abf Mon Sep 17 00:00:00 2001 From: Hide_D Date: Tue, 29 Nov 2022 01:53:55 +0900 Subject: [PATCH] =?UTF-8?q?Refac:=20=EB=A9=94=EC=8B=9C=EC=A7=80=20?= =?UTF-8?q?=ED=83=80=EC=9E=85=20=EC=A7=80=EC=A0=95=EC=9C=BC=EB=A1=9C=20Mes?= =?UTF-8?q?sageType=20Enum=20=EC=82=AC=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwe/_admin2_submit.php | 18 +-- hwe/_admin4_submit.php | 6 +- hwe/j_diplomacy_destroy_letter.php | 4 +- hwe/j_diplomacy_respond_letter.php | 6 +- hwe/j_diplomacy_rollback_letter.php | 4 +- hwe/j_diplomacy_send_letter.php | 4 +- hwe/j_msg_get_old.php | 10 +- hwe/j_msg_get_recent.php | 10 +- hwe/j_msg_submit.php | 30 ++--- hwe/j_myBossInfo.php | 4 +- hwe/sammo/Auction.php | 5 +- hwe/sammo/AuctionBasicResource.php | 3 +- hwe/sammo/Command/Nation/che_몰수.php | 3 +- hwe/sammo/Command/Nation/che_불가침제의.php | 3 +- .../Command/Nation/che_불가침파기제의.php | 3 +- hwe/sammo/Command/Nation/che_선전포고.php | 3 +- hwe/sammo/Command/Nation/che_종전제의.php | 3 +- hwe/sammo/DiplomaticMessage.php | 10 +- hwe/sammo/Event/Action/OpenNationBetting.php | 3 +- hwe/sammo/GeneralAI.php | 3 +- hwe/sammo/Message.php | 118 ++++++------------ hwe/sammo/ScoutMessage.php | 12 +- 22 files changed, 126 insertions(+), 139 deletions(-) diff --git a/hwe/_admin2_submit.php b/hwe/_admin2_submit.php index 660c204b..a5359528 100644 --- a/hwe/_admin2_submit.php +++ b/hwe/_admin2_submit.php @@ -2,6 +2,8 @@ namespace sammo; +use sammo\Enums\MessageType; + include "lib.php"; include "func.php"; @@ -111,7 +113,7 @@ switch ($btn) { case "경험치1000": $text = $btn . " 지급!"; foreach ($genlist as $generalID) { - $msg = new Message(Message::MSGTYPE_PRIVATE, $src, MessageTarget::buildQuick($generalID), $text, new \DateTime(), new \DateTime('9999-12-31'), []); + $msg = new Message(MessageType::private, $src, MessageTarget::buildQuick($generalID), $text, new \DateTime(), new \DateTime('9999-12-31'), []); $msg->send(true); } $db->update('general', [ @@ -122,7 +124,7 @@ switch ($btn) { case "공헌치1000": $text = $btn . " 지급!"; foreach ($genlist as $generalID) { - $msg = new Message(Message::MSGTYPE_PRIVATE, $src, MessageTarget::buildQuick($generalID), $text, new \DateTime(), new \DateTime('9999-12-31'), []); + $msg = new Message(MessageType::private, $src, MessageTarget::buildQuick($generalID), $text, new \DateTime(), new \DateTime('9999-12-31'), []); $msg->send(true); } $db->update('general', [ @@ -133,7 +135,7 @@ switch ($btn) { case "보숙10000": $text = "보병숙련도+10000 지급!"; foreach ($genlist as $generalID) { - $msg = new Message(Message::MSGTYPE_PRIVATE, $src, MessageTarget::buildQuick($generalID), $text, new \DateTime(), new \DateTime('9999-12-31'), []); + $msg = new Message(MessageType::private, $src, MessageTarget::buildQuick($generalID), $text, new \DateTime(), new \DateTime('9999-12-31'), []); $msg->send(true); } $db->update('general', [ @@ -143,7 +145,7 @@ switch ($btn) { case "궁숙10000": $text = "궁병숙련도+10000 지급!"; foreach ($genlist as $generalID) { - $msg = new Message(Message::MSGTYPE_PRIVATE, $src, MessageTarget::buildQuick($generalID), $text, new \DateTime(), new \DateTime('9999-12-31'), []); + $msg = new Message(MessageType::private, $src, MessageTarget::buildQuick($generalID), $text, new \DateTime(), new \DateTime('9999-12-31'), []); $msg->send(true); } $db->update('general', [ @@ -154,7 +156,7 @@ switch ($btn) { $src = MessageTarget::buildQuick($session->generalID); $text = "기병숙련도+10000 지급!"; foreach ($genlist as $generalID) { - $msg = new Message(Message::MSGTYPE_PRIVATE, $src, MessageTarget::buildQuick($generalID), $text, new \DateTime(), new \DateTime('9999-12-31'), []); + $msg = new Message(MessageType::private, $src, MessageTarget::buildQuick($generalID), $text, new \DateTime(), new \DateTime('9999-12-31'), []); $msg->send(true); } $db->update('general', [ @@ -165,7 +167,7 @@ switch ($btn) { $src = MessageTarget::buildQuick($session->generalID); $text = "귀병숙련도+10000 지급!"; foreach ($genlist as $generalID) { - $msg = new Message(Message::MSGTYPE_PRIVATE, $src, MessageTarget::buildQuick($generalID), $text, new \DateTime(), new \DateTime('9999-12-31'), []); + $msg = new Message(MessageType::private, $src, MessageTarget::buildQuick($generalID), $text, new \DateTime(), new \DateTime('9999-12-31'), []); $msg->send(true); } $db->update('general', [ @@ -176,7 +178,7 @@ switch ($btn) { $src = MessageTarget::buildQuick($session->generalID); $text = "차병숙련도+10000 지급!"; foreach ($genlist as $generalID) { - $msg = new Message(Message::MSGTYPE_PRIVATE, $src, MessageTarget::buildQuick($generalID), $text, new \DateTime(), new \DateTime('9999-12-31'), []); + $msg = new Message(MessageType::private, $src, MessageTarget::buildQuick($generalID), $text, new \DateTime(), new \DateTime('9999-12-31'), []); $msg->send(true); } $db->update('general', [ @@ -196,7 +198,7 @@ switch ($btn) { case "메세지 전달": $text = $msg ?? ''; foreach ($genlist as $generalID) { - $msg = new Message(Message::MSGTYPE_PRIVATE, $src, MessageTarget::buildQuick($generalID), $text, new \DateTime(), new \DateTime('9999-12-31'), []); + $msg = new Message(MessageType::private, $src, MessageTarget::buildQuick($generalID), $text, new \DateTime(), new \DateTime('9999-12-31'), []); $msg->send(true); } break; diff --git a/hwe/_admin4_submit.php b/hwe/_admin4_submit.php index 6bff17bb..91e9dff7 100644 --- a/hwe/_admin4_submit.php +++ b/hwe/_admin4_submit.php @@ -2,6 +2,8 @@ namespace sammo; +use sammo\Enums\MessageType; + include "lib.php"; include "func.php"; //로그인 검사 @@ -18,7 +20,7 @@ $msg = Util::getPost('msg', 'string', '메시지'); $db = DB::db(); -//NOTE: 왜 기능이 admin2와 admin4가 같이 있는가? +//NOTE: 왜 기능이 admin2와 admin4가 같이 있는가? //NOTE: 왜 블럭 시 admin4에선 금쌀을 없애지 않는가? switch ($btn) { case "블럭 해제": @@ -66,7 +68,7 @@ switch ($btn) { $src = MessageTarget::buildQuick($session->generalID); foreach($genlist as $generalID){ $msgObj = new Message( - Message::MSGTYPE_PRIVATE, + MessageType::private, $src, MessageTarget::buildQuick($generalID), $msg, diff --git a/hwe/j_diplomacy_destroy_letter.php b/hwe/j_diplomacy_destroy_letter.php index 1deb04db..fec91ff8 100644 --- a/hwe/j_diplomacy_destroy_letter.php +++ b/hwe/j_diplomacy_destroy_letter.php @@ -1,6 +1,8 @@ send(); $msg = new Message( - Message::MSGTYPE_NATIONAL, + MessageType::national, $src, $dest, $msgText, diff --git a/hwe/j_diplomacy_rollback_letter.php b/hwe/j_diplomacy_rollback_letter.php index 06c3a032..5908776d 100644 --- a/hwe/j_diplomacy_rollback_letter.php +++ b/hwe/j_diplomacy_rollback_letter.php @@ -1,6 +1,8 @@ update('ng_diplomacy', [ $msgText = "외교 서신(#{$letterNo})이 회수되었습니다."; $msg = new Message( - Message::MSGTYPE_DIPLOMACY, + MessageType::diplomacy, $src, $dest, $msgText, diff --git a/hwe/j_diplomacy_send_letter.php b/hwe/j_diplomacy_send_letter.php index ad987993..728759bd 100644 --- a/hwe/j_diplomacy_send_letter.php +++ b/hwe/j_diplomacy_send_letter.php @@ -1,6 +1,8 @@ id; } return $msg->toArray(); - }, Message::getMessagesFromMailBoxOld($generalID, Message::MSGTYPE_PRIVATE, $reqTo, 15)); + }, Message::getMessagesFromMailBoxOld($generalID, MessageType::private, $reqTo, 15)); } else if($reqType == 'public'){ $result['public'] = array_map(function(Message $msg)use (&$nextSequence){ @@ -91,7 +93,7 @@ else if($reqType == 'public'){ $nextSequence = $msg->id; } return $msg->toArray(); - }, Message::getMessagesFromMailBoxOld(Message::MAILBOX_PUBLIC, Message::MSGTYPE_PUBLIC, $reqTo, 15)); + }, Message::getMessagesFromMailBoxOld(Message::MAILBOX_PUBLIC, MessageType::public, $reqTo, 15)); } else if($reqType == 'national'){ $result['national'] = array_map(function(Message $msg)use (&$nextSequence){ @@ -99,7 +101,7 @@ else if($reqType == 'national'){ $nextSequence = $msg->id; } return $msg->toArray(); - }, Message::getMessagesFromMailBoxOld(Message::MAILBOX_NATIONAL + $nationID, Message::MSGTYPE_NATIONAL, $reqTo, 15)); + }, Message::getMessagesFromMailBoxOld(Message::MAILBOX_NATIONAL + $nationID, MessageType::national, $reqTo, 15)); } else{ $result['diplomacy'] = array_map(function(Message $msg)use (&$nextSequence, $permission){ @@ -112,7 +114,7 @@ else{ $values['option']['invalid'] = true; } return $values; - }, Message::getMessagesFromMailBoxOld(Message::MAILBOX_NATIONAL + $nationID, Message::MSGTYPE_DIPLOMACY, $reqTo, 15)); + }, Message::getMessagesFromMailBoxOld(Message::MAILBOX_NATIONAL + $nationID, MessageType::diplomacy, $reqTo, 15)); } Json::die($result); \ No newline at end of file diff --git a/hwe/j_msg_get_recent.php b/hwe/j_msg_get_recent.php index addfcc1e..9f6afee3 100644 --- a/hwe/j_msg_get_recent.php +++ b/hwe/j_msg_get_recent.php @@ -1,6 +1,8 @@ toArray(); -}, Message::getMessagesFromMailBox($generalID, Message::MSGTYPE_PRIVATE, 15, $reqSequence)); +}, Message::getMessagesFromMailBox($generalID, MessageType::private, 15, $reqSequence)); $result['public'] = array_map(function(Message $msg)use (&$nextSequence, &$minSequence, &$lastType){ if($msg->id > $nextSequence){ @@ -77,7 +79,7 @@ $result['public'] = array_map(function(Message $msg)use (&$nextSequence, &$minSe $lastType = 'public'; } return $msg->toArray(); -}, Message::getMessagesFromMailBox(Message::MAILBOX_PUBLIC, Message::MSGTYPE_PUBLIC, 15, $reqSequence)); +}, Message::getMessagesFromMailBox(Message::MAILBOX_PUBLIC, MessageType::public, 15, $reqSequence)); $result['national'] = array_map(function(Message $msg)use (&$nextSequence, &$minSequence, &$lastType){ if($msg->id > $nextSequence){ @@ -88,7 +90,7 @@ $result['national'] = array_map(function(Message $msg)use (&$nextSequence, &$min $lastType = 'national'; } return $msg->toArray(); -}, Message::getMessagesFromMailBox(Message::MAILBOX_NATIONAL + $nationID, Message::MSGTYPE_NATIONAL, 15, $reqSequence)); +}, Message::getMessagesFromMailBox(Message::MAILBOX_NATIONAL + $nationID, MessageType::national, 15, $reqSequence)); $result['diplomacy']= array_map(function(Message $msg)use (&$nextSequence, &$minSequence, &$lastType, $permission){ if($msg->id > $nextSequence){ @@ -104,7 +106,7 @@ $result['diplomacy']= array_map(function(Message $msg)use (&$nextSequence, &$min $values['option']['invalid'] = true; } return $values; -}, Message::getMessagesFromMailBox(Message::MAILBOX_NATIONAL + $nationID, Message::MSGTYPE_DIPLOMACY, 15, $reqSequence)); +}, Message::getMessagesFromMailBox(Message::MAILBOX_NATIONAL + $nationID, MessageType::diplomacy, 15, $reqSequence)); if($lastType !== null){ array_pop($result[$lastType]); diff --git a/hwe/j_msg_submit.php b/hwe/j_msg_submit.php index 89e1d162..0d8d8860 100644 --- a/hwe/j_msg_submit.php +++ b/hwe/j_msg_submit.php @@ -1,6 +1,8 @@ null -]); +]); $userID = Session::getUserID(); //NOTE: 전송 메시지 시간 계산을 위해 Session을 쓰기 가능 상태로 열어둠. @@ -43,7 +45,7 @@ if(getBlockLevel() == 1 || getBlockLevel() == 3) { /** * 메시지 전송 코드. - * + * * TODO: 장기적으로 ajax는 한곳에 모을 필요가 있을 듯. */ @@ -63,7 +65,7 @@ if(!$me){ } $con = checkLimit($me['con']); -if($con >= 2) { +if($con >= 2) { Json::die([ 'result' => false, 'reason' => '접속 제한입니다.', @@ -80,12 +82,12 @@ $src = new MessageTarget($me['no'], $me['name'], $srcNation['nation'], $srcNatio // 전체 메세지 if($mailbox == Message::MAILBOX_PUBLIC) { $msg = new Message( - Message::MSGTYPE_PUBLIC, - $src, + MessageType::public, $src, - $text, - $now, - $unlimited, + $src, + $text, + $now, + $unlimited, [] ); $msgID = $msg->send(); @@ -96,7 +98,7 @@ if($mailbox == Message::MAILBOX_PUBLIC) { ]); -} +} // 국가 메세지 if($mailbox >= Message::MAILBOX_NATIONAL) { @@ -109,10 +111,10 @@ if($mailbox >= Message::MAILBOX_NATIONAL) { } if($destNationID == $me['nation']){ - $msgType = Message::MSGTYPE_NATIONAL; + $msgType = MessageType::national; } else{ - $msgType = Message::MSGTYPE_DIPLOMACY; + $msgType = MessageType::diplomacy; } $destNation = getNationStaticInfo($destNationID); @@ -149,11 +151,11 @@ if($mailbox > 0) { 'msgID' => null ]); } - + $session->lastMsg = $now->format('Y-m-d H:i:s'); $destUser = $db->queryFirstRow('SELECT `no`,`name`,`nation`,`officer_level`,`con`,`picture`,`imgsvr`,permission,penalty FROM general WHERE `no`=%i',$mailbox); - + if(!$destUser){ Json::die([ 'result' => false, @@ -183,7 +185,7 @@ if($mailbox > 0) { ); $msg = new Message( - Message::MSGTYPE_PRIVATE, + MessageType::private, $src, $dest, $text, diff --git a/hwe/j_myBossInfo.php b/hwe/j_myBossInfo.php index 91fda855..7c3c7674 100644 --- a/hwe/j_myBossInfo.php +++ b/hwe/j_myBossInfo.php @@ -1,6 +1,8 @@ getVar('imgsvr'), $general->getVar('picture')) ); $msg = new Message( - Message::MSGTYPE_PUBLIC, + MessageType::public, $src, $src, $str, diff --git a/hwe/sammo/Auction.php b/hwe/sammo/Auction.php index 9c5dc3f8..7c393d84 100644 --- a/hwe/sammo/Auction.php +++ b/hwe/sammo/Auction.php @@ -10,6 +10,7 @@ use sammo\DTO\AuctionBidItemData; use sammo\DTO\AuctionInfo; use sammo\Enums\AuctionType; use sammo\Enums\InheritanceKey; +use sammo\Enums\MessageType; use sammo\Enums\RankColumn; use sammo\Enums\ResourceType; @@ -245,7 +246,7 @@ abstract class Auction //TODO: 전역 알림이 나타나야한다. 일반 메시지보다는 중요하고, 메시지보단 약하게.. //TODO: 바로가기를 제공하는 편이 좋을 것 같다. $msg = new Message( - Message::MSGTYPE_PRIVATE, + MessageType::private, $src, $dest, $reason, @@ -509,7 +510,7 @@ abstract class Auction //TODO: 전역 알림이 나타나야한다. 일반 메시지보다는 중요하고, 메시지보단 약하게.. //TODO: 바로가기를 제공하는 편이 좋을 것 같다. $msg = new Message( - Message::MSGTYPE_PRIVATE, + MessageType::private, $src, $dest, $failReason, diff --git a/hwe/sammo/AuctionBasicResource.php b/hwe/sammo/AuctionBasicResource.php index cf359160..dbc5dce5 100644 --- a/hwe/sammo/AuctionBasicResource.php +++ b/hwe/sammo/AuctionBasicResource.php @@ -7,6 +7,7 @@ use sammo\DTO\AuctionBidItem; use sammo\DTO\AuctionInfo; use sammo\DTO\AuctionInfoDetail; use sammo\Enums\AuctionType; +use sammo\Enums\MessageType; use sammo\Enums\ResourceType; abstract class AuctionBasicResource extends Auction @@ -145,7 +146,7 @@ abstract class AuctionBasicResource extends Auction //TODO: 전역 알림이 나타나야한다. 일반 메시지보다는 중요하고, 메시지보단 약하게.. //TODO: 바로가기를 제공하는 편이 좋을 것 같다. $msg = new Message( - Message::MSGTYPE_PRIVATE, + MessageType::private, $src, $dest, "{$this->auctionID}번 {$hostResName} 경매에 입찰이 없어 취소되었습니다.", diff --git a/hwe/sammo/Command/Nation/che_몰수.php b/hwe/sammo/Command/Nation/che_몰수.php index 2d563afb..092b68bf 100644 --- a/hwe/sammo/Command/Nation/che_몰수.php +++ b/hwe/sammo/Command/Nation/che_몰수.php @@ -19,6 +19,7 @@ use function \sammo\GetImageURL; use \sammo\Constraint\Constraint; use \sammo\Constraint\ConstraintHelper; +use sammo\Enums\MessageType; class che_몰수 extends Command\NationCommand { @@ -186,7 +187,7 @@ class che_몰수 extends Command\NationCommand GetImageURL($destGeneral->getVar('imgsvr'), $destGeneral->getVar('picture')) ); $msg = new Message( - Message::MSGTYPE_PUBLIC, + MessageType::public, $src, $src, $text, diff --git a/hwe/sammo/Command/Nation/che_불가침제의.php b/hwe/sammo/Command/Nation/che_불가침제의.php index ba8fe753..33232e30 100644 --- a/hwe/sammo/Command/Nation/che_불가침제의.php +++ b/hwe/sammo/Command/Nation/che_불가침제의.php @@ -22,6 +22,7 @@ use function \sammo\getNationStaticInfo; use \sammo\Constraint\Constraint; use \sammo\Constraint\ConstraintHelper; +use sammo\Enums\MessageType; class che_불가침제의 extends Command\NationCommand { @@ -202,7 +203,7 @@ class che_불가침제의 extends Command\NationCommand $josaWa = JosaUtil::pick($nationName, '와'); $msg = new DiplomaticMessage( - Message::MSGTYPE_DIPLOMACY, + MessageType::diplomacy, $src, $dest, "{$nationName}{$josaWa} {$year}년 {$month}월까지 불가침 제의 서신", diff --git a/hwe/sammo/Command/Nation/che_불가침파기제의.php b/hwe/sammo/Command/Nation/che_불가침파기제의.php index 9a22b215..82b489f0 100644 --- a/hwe/sammo/Command/Nation/che_불가침파기제의.php +++ b/hwe/sammo/Command/Nation/che_불가침파기제의.php @@ -20,6 +20,7 @@ use function \sammo\GetImageURL; use \sammo\Constraint\Constraint; use \sammo\Constraint\ConstraintHelper; +use sammo\Enums\MessageType; class che_불가침파기제의 extends Command\NationCommand{ static protected $actionName = '불가침 파기 제의'; @@ -150,7 +151,7 @@ class che_불가침파기제의 extends Command\NationCommand{ $validUntil->add(new \DateInterval("PT{$validMinutes}M")); $msg = new DiplomaticMessage( - Message::MSGTYPE_DIPLOMACY, + MessageType::diplomacy, $src, $dest, "{$nationName}의 불가침 파기 제의 서신", diff --git a/hwe/sammo/Command/Nation/che_선전포고.php b/hwe/sammo/Command/Nation/che_선전포고.php index 69d90988..42c2a057 100644 --- a/hwe/sammo/Command/Nation/che_선전포고.php +++ b/hwe/sammo/Command/Nation/che_선전포고.php @@ -21,6 +21,7 @@ use function \sammo\GetImageURL; use \sammo\Constraint\Constraint; use \sammo\Constraint\ConstraintHelper; +use sammo\Enums\MessageType; class che_선전포고 extends Command\NationCommand { @@ -175,7 +176,7 @@ class che_선전포고 extends Command\NationCommand $destNation['color'] ); $msg = new Message( - Message::MSGTYPE_NATIONAL, + MessageType::national, $src, $dest, $text, diff --git a/hwe/sammo/Command/Nation/che_종전제의.php b/hwe/sammo/Command/Nation/che_종전제의.php index 63370d8b..f3462239 100644 --- a/hwe/sammo/Command/Nation/che_종전제의.php +++ b/hwe/sammo/Command/Nation/che_종전제의.php @@ -20,6 +20,7 @@ use function \sammo\GetImageURL; use \sammo\Constraint\Constraint; use \sammo\Constraint\ConstraintHelper; +use sammo\Enums\MessageType; class che_종전제의 extends Command\NationCommand{ static protected $actionName = '종전 제의'; @@ -148,7 +149,7 @@ class che_종전제의 extends Command\NationCommand{ $validUntil->add(new \DateInterval("PT{$validMinutes}M")); $msg = new DiplomaticMessage( - Message::MSGTYPE_DIPLOMACY, + MessageType::diplomacy, $src, $dest, "{$nationName}의 종전 제의 서신", diff --git a/hwe/sammo/DiplomaticMessage.php b/hwe/sammo/DiplomaticMessage.php index dc53bbe5..96afcc65 100644 --- a/hwe/sammo/DiplomaticMessage.php +++ b/hwe/sammo/DiplomaticMessage.php @@ -1,6 +1,8 @@ src->nationName, '이'); $newMsg = new Message( - self::MSGTYPE_NATIONAL, + MessageType::national, $this->dest, $this->src, "【외교】{$year}년 {$month}월: {$this->src->nationName}{$josaYi} {$this->dest->nationName}에게 제안한 {$this->diplomacyDetail}", @@ -224,7 +226,7 @@ class DiplomaticMessage extends Message{ $newMsg->send(); $newMsg = new Message( - self::MSGTYPE_DIPLOMACY, + MessageType::diplomacy, $this->dest, $this->src, "【외교】{$year}년 {$month}월: {$this->src->nationName}{$josaYi} {$this->dest->nationName}에게 제안한 {$this->diplomacyDetail}", diff --git a/hwe/sammo/Event/Action/OpenNationBetting.php b/hwe/sammo/Event/Action/OpenNationBetting.php index f051ab27..faec3be3 100644 --- a/hwe/sammo/Event/Action/OpenNationBetting.php +++ b/hwe/sammo/Event/Action/OpenNationBetting.php @@ -9,6 +9,7 @@ use \sammo\Util; use \sammo\DB; use sammo\DTO\BettingInfo; use sammo\DTO\SelectItem; +use sammo\Enums\MessageType; use sammo\Json; use sammo\KVStorage; use sammo\Message; @@ -138,7 +139,7 @@ class OpenNationBetting extends \sammo\Event\Action GetImageURL($general['imgsvr'], $general['picture']) ); $msg = new Message( - Message::MSGTYPE_PRIVATE, + MessageType::private, $src, $dest, $text, diff --git a/hwe/sammo/GeneralAI.php b/hwe/sammo/GeneralAI.php index a22b2e6d..122bda5f 100644 --- a/hwe/sammo/GeneralAI.php +++ b/hwe/sammo/GeneralAI.php @@ -4,6 +4,7 @@ namespace sammo; use sammo\Command\GeneralCommand; use sammo\Command\NationCommand; +use sammo\Enums\MessageType; use sammo\Enums\RankColumn; use sammo\Scenario\NPC; @@ -3703,7 +3704,7 @@ class GeneralAI GetImageURL($general->getVar('imgsvr'), $general->getVar('picture')) ); $msg = new Message( - Message::MSGTYPE_PUBLIC, + MessageType::public, $src, $src, $general->getVar('npcmsg'), diff --git a/hwe/sammo/Message.php b/hwe/sammo/Message.php index cf810e0d..ea3f41b6 100644 --- a/hwe/sammo/Message.php +++ b/hwe/sammo/Message.php @@ -1,16 +1,13 @@ msgType = $msgType; - $this->src = $src; - $this->dest = $dest; - $this->msg = $msg; - $this->date = $date; - $this->validUntil = $validUntil; - $this->msgOption = $msgOption; } public function setSentInfo(int $mailbox, int $messageID) : self @@ -61,19 +34,19 @@ class Message do{ if($mailbox === Message::MAILBOX_PUBLIC){ - if($this->msgType !== Message::MSGTYPE_PUBLIC){ - throw new \InvalidArgumentException('올바르지 않은 mailbox, msgType !== MSGTYPE_PUBLIC'); + if($this->msgType !== MessageType::public){ + throw new \InvalidArgumentException('올바르지 않은 mailbox, msgType !== MessageType::public'); } $this->isInboxMail = true; break; } if($mailbox >= Message::MAILBOX_NATIONAL){ - if($this->msgType === Message::MSGTYPE_DIPLOMACY){ + if($this->msgType === MessageType::diplomacy){ $this->isInboxMail = true; break; } - if ($this->msgType !== Message::MSGTYPE_NATIONAL) { - throw new \InvalidArgumentException('올바르지 않은 mailbox, msgType not in (MSGTYPE_DIPLOMACY, MSGTYPE_NATIONAL)'); + if ($this->msgType !== MessageType::national) { + throw new \InvalidArgumentException('올바르지 않은 mailbox, msgType not in (MessageType::diplomacy, MessageType::national)'); } if($this->dest->nationID + Message::MAILBOX_NATIONAL === $mailbox){ $this->isInboxMail = true; @@ -85,7 +58,7 @@ class Message } throw new \InvalidArgumentException('송신, 수신국 둘 중의 어느 메일함도 아닙니다'); } - if($this->msgType !== Message::MSGTYPE_PRIVATE){ + if($this->msgType !== MessageType::private){ throw new \InvalidArgumentException('올바르지 않은 mailbox, msgType !== MSGTYPE_PRIVATE'); } if($this->dest->generalID === $mailbox){ @@ -105,11 +78,11 @@ class Message } public function toArray():array{ - if($this->msgType === Message::MSGTYPE_PUBLIC){ + if($this->msgType === MessageType::public){ $src = $this->src->toArray(); $dest = null; } - else if($this->msgType === Message::MSGTYPE_NATIONAL || $this->msgType === Message::MSGTYPE_DIPLOMACY){ + else if($this->msgType === MessageType::national || $this->msgType === MessageType::diplomacy){ $src = $this->src->toArray(); $dest = $this->dest->toArray(); } @@ -120,7 +93,7 @@ class Message return [ 'id'=>$this->id, - 'msgType'=>$this->msgType, + 'msgType'=>$this->msgType->value, 'src'=>$src, 'dest'=>$dest, 'text'=>$this->msg, @@ -133,7 +106,7 @@ class Message { $dbMessage = Json::decode($row['message']); - $msgType = $row['type']; + $msgType = MessageType::from($row['type']); $src = MessageTarget::buildFromArray($dbMessage['src']); $dest = MessageTarget::buildFromArray($dbMessage['dest']); $option = Util::array_get($dbMessage['option'], []); @@ -149,7 +122,7 @@ class Message ]; $action = Util::array_get($option['action'], null); - if ($msgType === self::MSGTYPE_DIPLOMACY && $action !== null) { + if ($msgType === MessageType::diplomacy && $action !== null) { $objMessage = new DiplomaticMessage(...$args); } elseif ($action === 'scout') { $objMessage = new ScoutMessage(...$args); @@ -164,7 +137,7 @@ class Message protected static function isValidMailBox(int $mailbox): bool { - if ($mailbox > self::MAILBOX_PUBLIC) { + if ($mailbox > MessageType::public) { return false; } if ($mailbox <= 0) { @@ -173,17 +146,6 @@ class Message return true; } - protected static function isValidMsgType(string $msgType): bool - { - switch ($msgType) { - case static::MSGTYPE_PUBLIC: return true; - case static::MSGTYPE_PRIVATE: return true; - case static::MSGTYPE_NATIONAL: return true; - case static::MSGTYPE_DIPLOMACY: return true; - } - return false; - } - public static function getMessageByID(int $messageID) : ?Message { $db = DB::db(); @@ -197,24 +159,20 @@ class Message /** * @param int $mailbox 메일 사서함. - * @param string $msgType 메일 타입. MSGTYPE 중 하나. + * @param MessageType $msgType 메일 타입. * @param int $limit 가져오고자 하는 수. 0 이하의 값이면 모두. * @param int $fromSeq 가져오고자 하는 위치. $fromSeq보다 '큰' seq만 가져온다. 따라서 0 이하이면 모두 가져옴. * @return Message[] */ - public static function getMessagesFromMailBox(int $mailbox, string $msgType, int $limit=30, int $fromSeq = 0) + public static function getMessagesFromMailBox(int $mailbox, MessageType $msgType, int $limit=30, int $fromSeq = 0) { $db = DB::db(); - if (!static::isValidMsgType($msgType)) { - throw new \InvalidArgumentException('올바르지 않은 $msgType'); - } - $date = (new \DateTime())->format('Y-m-d H:i:s'); $where = new \WhereClause('and'); $where->add('mailbox = %i', $mailbox); - $where->add('type = %s', $msgType); + $where->add('type = %s', $msgType->value); $where->add('valid_until > %s', $date); if ($fromSeq > 0) { $where->add('id >= %i', $fromSeq); @@ -233,24 +191,20 @@ class Message /** * @param int $mailbox 메일 사서함. - * @param string $msgType 메일 타입. MSGTYPE 중 하나. + * @param MessageType $msgType 메일 타입. * @param int $toSeq 가져오고자 하는 위치. $toSeq보다 '작은' seq만 가져온다. * @param int $limit 가져오고자 하는 수. * @return Message[] */ - public static function getMessagesFromMailBoxOld(int $mailbox, string $msgType, int $toSeq, int $limit = 20) + public static function getMessagesFromMailBoxOld(int $mailbox, MessageType $msgType, int $toSeq, int $limit = 20) { $db = DB::db(); - if (!static::isValidMsgType($msgType)) { - throw new \InvalidArgumentException('올바르지 않은 $msgType'); - } - $date = (new \DateTime())->format('Y-m-d H:i:s'); $where = new \WhereClause('and'); $where->add('mailbox = %i', $mailbox); - $where->add('type = %s', $msgType); + $where->add('type = %s', $msgType->value); $where->add('valid_until > %s', $date); $where->add('id < %i', $toSeq); @@ -296,7 +250,7 @@ class Message 'overwrite'=>[$msgObj->id] ]; - if($msgObj->msgType == Message::MSGTYPE_PRIVATE || $msgObj->msgType == Message::MSGTYPE_NATIONAL){ + if($msgObj->msgType === MessageType::private || $msgObj->msgType === MessageType::national){ $receiveID = $msgObj->msgOption['receiverMessageID']??null; if($receiveID !== null){ $msgObj2 = static::getMessageByID($receiveID); @@ -345,7 +299,7 @@ class Message $db = DB::db(); $db->insert('message', [ 'mailbox' => $mailbox, - 'type' => $this->msgType, + 'type' => $this->msgType->value, 'src' => $src_id, 'dest' => $dest_id, 'time' => $this->date->format('Y-m-d H:i:s'), @@ -364,13 +318,13 @@ class Message if($this->sendCnt > 1){ throw new \RuntimeException('이미 전송한 메일입니다.'); } - if($this->msgType === self::MSGTYPE_PRIVATE && $this->src->generalID !== $this->dest->generalID){ + if($this->msgType === MessageType::private && $this->src->generalID !== $this->dest->generalID){ return $this->sendRaw($this->src->generalID); } - if($this->msgType === self::MSGTYPE_NATIONAL && $this->src->nationID !== $this->dest->nationID){ + if($this->msgType === MessageType::national && $this->src->nationID !== $this->dest->nationID){ return $this->sendRaw($this->src->nationID + self::MAILBOX_NATIONAL); } - if($this->msgType === self::MSGTYPE_DIPLOMACY){ + if($this->msgType === MessageType::diplomacy){ if(key_exists('action', $this->msgOption)){ $tmp = $this->msgOption; $this->msgOption = null; @@ -391,7 +345,7 @@ class Message throw new \RuntimeException('이미 전송한 메일입니다.'); } - if($this->msgType === self::MSGTYPE_PRIVATE){ + if($this->msgType === MessageType::private){ if(!($this->msgOption['silence']??false)){ //XXX: 알림을 이런식으로 보내는게 맞는가에 대한 의문 있음 DB::db()->update('general', [ @@ -401,11 +355,11 @@ class Message return $this->sendRaw($this->dest->generalID); } - if($this->msgType === self::MSGTYPE_NATIONAL){ + if($this->msgType === MessageType::national){ return $this->sendRaw($this->dest->nationID + self::MAILBOX_NATIONAL); } - if($this->msgType === self::MSGTYPE_DIPLOMACY){ + if($this->msgType === MessageType::diplomacy){ if(!($this->msgOption['silence']??false)){ //XXX: 알림을 이런식으로 보내는게 맞는가에 대한 의문 있음 DB::db()->update('general', [ @@ -415,7 +369,7 @@ class Message return $this->sendRaw($this->dest->nationID + self::MAILBOX_NATIONAL); } - if($this->msgType === self::MSGTYPE_PUBLIC){ + if($this->msgType === MessageType::public){ return $this->sendRaw(self::MAILBOX_PUBLIC); } diff --git a/hwe/sammo/ScoutMessage.php b/hwe/sammo/ScoutMessage.php index b3ffe536..76a54d48 100644 --- a/hwe/sammo/ScoutMessage.php +++ b/hwe/sammo/ScoutMessage.php @@ -1,6 +1,8 @@ src->nationName, '로'); $newMsg = new Message( - self::MSGTYPE_PRIVATE, + MessageType::private, $this->src, $this->dest, "{$this->src->nationName}{$josaRo} 등용 제의 수락", @@ -120,7 +122,7 @@ class ScoutMessage extends Message{ $josaRo = JosaUtil::pick($this->src->nationName, '로'); $newMsg = new Message( - self::MSGTYPE_PRIVATE, + MessageType::private, $this->src, $this->dest, "{$this->src->nationName}{$josaRo} 등용 제의 거부", @@ -223,6 +225,6 @@ class ScoutMessage extends Message{ 'action'=>'scout' ]; - return new ScoutMessage(Message::MSGTYPE_PRIVATE, $src, $dest, $msg, $date, $validUntil, $msgOption); + return new ScoutMessage(MessageType::private, $src, $dest, $msg, $date, $validUntil, $msgOption); } } \ No newline at end of file