From de4c2e0678a0b4d023aa85f2374136d0642e7f32 Mon Sep 17 00:00:00 2001 From: hide_d Date: Thu, 1 Mar 2018 18:36:29 +0900 Subject: [PATCH] =?UTF-8?q?=EC=83=88=20=EB=A9=94=EC=8B=9C=EC=A7=80=20?= =?UTF-8?q?=EC=8B=9C=EC=8A=A4=ED=85=9C=20=ED=86=B5=ED=95=A9=20=EC=A4=80?= =?UTF-8?q?=EB=B9=84=20=EC=99=84=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- twe/func_message.php | 39 ++++++++++++++++++++++++--------------- twe/j_get_new_msg.php | 35 +++++++++++++++++++++++++++++++++++ twe/schema.php | 5 +---- 3 files changed, 60 insertions(+), 19 deletions(-) create mode 100644 twe/j_get_new_msg.php diff --git a/twe/func_message.php b/twe/func_message.php index 70a051d0..7f8f8c51 100644 --- a/twe/func_message.php +++ b/twe/func_message.php @@ -46,15 +46,14 @@ class Message{ -function getRawMessage($mailbox, $limit=30, $fromTime=NULL){ - //'select * from `message` where `mailbox` = 90 and `time` < "2018-01-21 04:47:20" ORDER BY `time` desc LIMIT 3 '; - +function getRawMessage($mailbox, $msgType, $limit=30, $fromSeq=NULL){ - $sql = 'select * from `message` where `mailbox` = %i_mailbox'; - if($fromTime !== NULL){ - $sql .= ' and `time` <= %s_time'; + + $sql = 'select * from `message` where `mailbox` = %i_mailbox and `type` = %s_type and `valid_until` > now()'; + if($fromSeq !== NULL){ + $sql .= ' and `id` > %i_id'; } - $sql .= ' ORDER BY `time` desc'; + $sql .= ' ORDER BY `id` desc'; if($limit > 0){ $sql .= ' LIMIT %i_limit'; } @@ -62,6 +61,7 @@ function getRawMessage($mailbox, $limit=30, $fromTime=NULL){ //TODO: table 네임의 prefix를 처리할 수 있도록 개선 $result = getDB()->query($sql, [ 'mailbox' => $mailbox, + 'type' => $msgType, 'limit' => $limit, 'time' => $fromTime ]); @@ -72,24 +72,31 @@ function getRawMessage($mailbox, $limit=30, $fromTime=NULL){ }, $result); } -function getMessage($msgType, $limit=30, $fromTime=NULL){ +function getMessage($msgType, $nationID=null, $limit=30, $fromSeq=NULL){ $generalID = getGeneralID(false); if($generalID === NULL){ return []; } if($msgType === 'public'){ - return getRawMessage(9999, $limit, $fromTime); + return getRawMessage(9999, 'public', $limit, $fromSeq); } else if($msgType === 'private'){ - return getRawMessage($generalID, $limit, $fromTime); + return getRawMessage($generalID, 'private', $limit, $fromSeq); } else if($msgType === 'national'){ - $nationID = getDB()->queryFirstField( - 'select `nation` from `general` where no = %i', - $generalID - ); - return getRawMessage(9000 + $nationID, $limit, $fromTime); + if($nationID === null){ + return []; + } + + return getRawMessage($nationID + 9000, 'national', $limit, $fromSeq); + } + else if($msgType === 'diplomacy'){ + if($nationID === null){ + return []; + } + + return getRawMessage($nationID + 9000, 'diplomacy', $limit, $fromSeq); } else{ return []; @@ -244,6 +251,8 @@ function getMailboxList(){ } + +//Legacy function genList($connect) { $query = "select no,nation,level,msgindex,userlevel from general where owner='{$_SESSION['noMember']}'"; $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); diff --git a/twe/j_get_new_msg.php b/twe/j_get_new_msg.php new file mode 100644 index 00000000..641a6164 --- /dev/null +++ b/twe/j_get_new_msg.php @@ -0,0 +1,35 @@ +queryFirstField( + 'select `nation` from `general` where no = %i', + $generalID +); + + +if($nationID === null){ + returnJson([ + 'result'=>false, + 'reason'=>'소속 국가가 없습니다' + ]); +} + +returnJson([ + 'result'=>true, + 'private'=>getMessage('private', $nationID, 10, $reqSequence), + 'public'=>getMessage('public', $nationID, 20, $reqSequence), + 'national'=>getMessage('national', $nationID, 30, $reqSequence), + 'diplomacy'=>getMessage('diplomacy', $nationID, 10, $reqSequence) +]); \ No newline at end of file diff --git a/twe/schema.php b/twe/schema.php index ee992685..ea696f1e 100644 --- a/twe/schema.php +++ b/twe/schema.php @@ -503,13 +503,10 @@ CREATE TABLE `message` ( `valid_until` DATETIME NOT NULL DEFAULT '9999-12-31 23:59:59', `message` TEXT NOT NULL COMMENT 'json', PRIMARY KEY (`id`), - INDEX `by_owner` (`mailbox`, `time`), - INDEX `by_dest` (`dest`, `time`), - INDEX `by_full` (`src`, `dest`, `time`) + INDEX `by_mailbox` (`mailbox`, `type`, `time`) ) COLLATE='utf8_general_ci' ENGINE=InnoDB -; ";