새 메시지 시스템 통합 준비 완료
This commit is contained in:
+24
-15
@@ -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),"");
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
include('lib.php');
|
||||
include('func.php');
|
||||
|
||||
use utilphp\util as util;
|
||||
|
||||
$generalID = getGeneralID();
|
||||
|
||||
session_write_close(); // 이제 세션 안 쓴다
|
||||
|
||||
$jsonPost = parseJsonPost();
|
||||
|
||||
$reqSequence = toInt(util::array_get($jsonPost['sequence'], 0));
|
||||
|
||||
|
||||
$nationID = getDB()->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)
|
||||
]);
|
||||
+1
-4
@@ -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
|
||||
;
|
||||
|
||||
";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user