sammo를 쓰는 일부 파일을 getRootDB()를 이용하도록 수정

메시지 DB 형태 변경.

메시지를 전송하는 별도의 함수 sendMessage(), sendRawMessage() 생성

j_msgsubmit.php 전면 수정

가능한 메일함을 구해오는 getMailboxList() 함수 추가

CheckBlock를 getBlockLevel로 변경하고, 내부 구현 수정
This commit is contained in:
2018-01-29 02:14:41 +09:00
parent 6d30e40cd3
commit b7923e04a4
10 changed files with 201 additions and 240 deletions
+2 -8
View File
@@ -28,10 +28,7 @@ switch($btn) {
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
break;
case "블럭 해제":
for($i=0; $i < sizeof($genlist); $i++) {
$query = "update general set block=0 where no='$genlist[$i]'";
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
}
getDB()->query('update general set block=0 where no IN %li', $genlist);
break;
case "1단계 블럭":
$date = date('Y-m-d H:i:s');
@@ -60,10 +57,7 @@ switch($btn) {
break;
case "강제 사망":
$date = date('Y-m-d H:i:s');
for($i=0; $i < sizeof($genlist); $i++) {
$query = "update general set turn0=0,killturn=0,turntime='$date' where no='$genlist[$i]'";
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
}
getDB()->query('update general set turn0=0,killturn=0,turntime=%s where no IN %li',$date, $genlist);
break;
case "특기 부여":
$query = "select year,month from game where no=1";
+18 -57
View File
@@ -14,79 +14,40 @@ if($me['userlevel'] < 5) {
echo '_admin4.php';//TODO:debug all and replace
}
//NOTE: 왜 기능이 admin2와 admin4가 같이 있는가?
//NOTE: 왜 블럭 시 admin4에선 금쌀을 없애지 않는가?
switch($btn) {
case "블럭 해제":
for($i=0; $i < sizeof($genlist); $i++) {
$query = "update general set block=0 where no='$genlist[$i]'";
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
}
getDB()->query('update general set block=0 where no IN %li', $genlist);
break;
case "1단계 블럭":
for($i=0; $i < sizeof($genlist); $i++) {
$query = "update general set block=1,killturn=24 where no='$genlist[$i]'";
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
$query = "select user_id from general where no='$genlist[$i]'";
$result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
$gen = MYDB_fetch_array($result);
$uid[$i] = $gen['user_id'];
}
$connect = dbConn("sammo");
$date = date('Y-m-d H:i:s');
for($i=0; $i < sizeof($uid); $i++) {
//블럭정보
$query = "update MEMBER set block_num=block_num+1,block_date='$date' where id='$uid[$i]'";
$result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
}
$db = getDB();
$db->query('update general set block=1,killturn=24 where no IN %li',$genlist);
//FIXME: subquery로 하는게 더 빠를 듯.
$uid = $db->queryFirstColumn('select user_id from general where no IN %li', $genlist);
getRootDB()->query('update MEMBER set block_num=block_num+1,block_date=%s where id IN %ls', $date, $uid);
break;
case "2단계 블럭":
for($i=0; $i < sizeof($genlist); $i++) {
$query = "update general set block=2,killturn=24 where no='$genlist[$i]'";
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
$query = "select user_id from general where no='$genlist[$i]'";
$result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
$gen = MYDB_fetch_array($result);
$uid[$i] = $gen['user_id'];
}
$connect = dbConn("sammo");
$date = date('Y-m-d H:i:s');
for($i=0; $i < sizeof($uid); $i++) {
//블럭정보
$query = "update MEMBER set block_num=block_num+1,block_date='$date' where id='$uid[$i]'";
$result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
}
$db = getDB();
$db->query('update general set block=2,killturn=24 where no IN %li',$genlist);
$uid = $db->queryFirstColumn('select user_id from general where no IN %li', $genlist);
getRootDB()->query('update MEMBER set block_num=block_num+1,block_date=%s where id IN %ls', $date, $uid);
break;
case "3단계 블럭":
for($i=0; $i < sizeof($genlist); $i++) {
$query = "update general set block=3,killturn=24 where no='$genlist[$i]'";
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
$query = "select user_id from general where no='$genlist[$i]'";
$result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
$gen = MYDB_fetch_array($result);
$uid[$i] = $gen['user_id'];
}
$connect = dbConn("sammo");
$date = date('Y-m-d H:i:s');
for($i=0; $i < sizeof($uid); $i++) {
//블럭정보
$query = "update MEMBER set block_num=block_num+1,block_date='$date' where id='$uid[$i]'";
$result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
}
$db = getDB();
$db->query('update general set block=3,killturn=24 where no IN %li',$genlist);
$uid = $db->queryFirstColumn('select user_id from general where no IN %li', $genlist);
getRootDB()->query('update MEMBER set block_num=block_num+1,block_date=%s where id IN %ls', $date, $uid);
break;
case "무한삭턴":
for($i=0; $i < sizeof($genlist); $i++) {
$query = "update general set killturn=8000 where no='$genlist[$i]'";
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
}
getDB()->query('update general set killturn=8000 where no IN %li',$genlist);
break;
case "강제 사망":
$date = date('Y-m-d H:i:s');
for($i=0; $i < sizeof($genlist); $i++) {
$query = "update general set turn0=0,killturn=0,turntime='$date' where no='$genlist[$i]'";
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
}
getDB()->query('update general set turn0=0,killturn=0,turntime=%s where no IN %li',$date, $genlist);
break;
case "메세지 전달":
$date = date('Y-m-d H:i:s');
+1 -1
View File
@@ -7,7 +7,7 @@ include "func.php";
CheckLogin();
$connect = dbConn();
if(CheckBlock($connect) != 1 && CheckBlock($connect) != 3) {
if(getBlockLevel() != 1 && getBlockLevel() != 3) {
$query = "select no,nation from general where user_id='{$_SESSION['p_id']}'";
$result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
$me = MYDB_fetch_array($result);
+1 -1
View File
@@ -8,7 +8,7 @@ CheckLogin(1);
$connect = dbConn();
increaseRefresh($connect, "서신전달", 1);
if(CheckBlock($connect) == 1 || CheckBlock($connect) == 3) {
if(getBlockLevel() == 1 || getBlockLevel() == 3) {
$msg = "";
$genlist = 0;
}
+1 -1
View File
@@ -7,7 +7,7 @@ include "func.php";
CheckLogin();
$connect = dbConn();
if(CheckBlock($connect) != 1 && CheckBlock($connect) != 3) {
if(getBlockLevel() != 1 && getBlockLevel() != 3) {
$query = "select no,nation from general where user_id='{$_SESSION['p_id']}'";
$result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
$me = MYDB_fetch_array($result);
+3 -6
View File
@@ -19,7 +19,7 @@ function randF(){
return mt_rand() / mt_getrandmax();
}
/// $_SESSION['p_id'] 의 값을 받아옴
function getGeneralID(){
//TODO: 서버마다 p_id가 다를 수 있도록 조치
if(!isset($_SESSION['p_id'])){
@@ -67,11 +67,8 @@ function checkLimit($userlevel, $con, $conlimit) {
}
}
function CheckBlock($connect) {
$query = "select block from general where user_id='{$_SESSION['p_id']}'";
$result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
$me = MYDB_fetch_array($result);
return $me['block'];
function getBlockLevel() {
return getDB()->queryFirstField('select block from general where user_id= %i', getGeneralID());
}
function getRandGenName() {
+1 -1
View File
@@ -76,7 +76,7 @@ function LogHistory($connect, $isFirst=0) {
$current_url = util::get_current_url();
$map_path = explode('/',parse_url($current_url, PHP_URL_PASS));
array_pop($map_path);
array_push($map_path, 'map.php?type=2&graphic=0');
$map_path[] = 'map.php?type=2&graphic=0';
$map_path = join('/', $map_path);
$client = new GuzzleHttp\Client();
+107 -22
View File
@@ -7,51 +7,43 @@ class Message{
public $id;
public $mailbox;
public $type;
public $isSender;
public $src;
public $dest;
public $time;
public $message;
public $rawType;
function __construct($row){
$this->raw_type = $row['type'];
$this->id = $row['id'];
$this->mailbox = $row['mailbox'];
if($this->rawType === 'public'){
$this->type = 'public';
}
else if(util::ends_with($this->rawType, 'national')){
$this->type = 'national';
}
else{
$this->type = 'private';
}
$this->type = $row['type'];
$this->isSender = $row['is_sender'] != 0;
$this->src = [
'id' => $row['src'],
'name' => $row['src_name'],
'nation' => $row['src_nation'],
'color' => $row['src_color']
'color' => $row['src_color'],
'nation_id' => $row['src_nation_id']
];
if($this->src['nation'] === NULL){
if($this->src['nation'] === null){
$this->src['nation'] = '재야';
$this->src['color'] = '#FFFFFF';
$this->src['nation_id'] = null;
}
$this->dest = [
'id' => $row['dest'],
'name' => $row['dest_name'],
'nation' => $row['dest_nation'],
'color' => $row['dest_color']
'color' => $row['dest_color'],
'nation_id' => $row['dest_nation_id']
];
if($this->dest['nation'] === NULL){
if($this->dest['nation'] === null){
$this->dest['nation'] = '재야';
$this->dest['color'] = '#FFFFFF';
$this->dest['nation_id'] = null;
}
$this->datetime = $row['time'];
@@ -88,7 +80,7 @@ function getRawMessage($mailbox, $limit=30, $fromTime=NULL){
}
function getMessage($msgType, $limit=30, $fromTime=NULL){
$generalID = genID();
$generalID = getGeneralID();
if($generalID === NULL){
return [];
}
@@ -109,10 +101,103 @@ function getMessage($msgType, $limit=30, $fromTime=NULL){
else{
return [];
}
}
function sendRawMessage($msgType, $isSender, $mailbox, $src, $dest, $msg, $date){
getDB()->insert('message', array(
'address' => $dest,
'type' => 'receive',
'src' => $src['id'],
'dest' => $dest['id'],
'time' => $date,
'src_nation_id' => util::array_get($src['nation_id'], null),
'src_name' => util::array_get($src['name'], null),
'src_nation' => util::array_get($src['nation'], null),
'src_color' => util::array_get($src['color'], null),
'src_icon' => util::array_get($src['icon'], null),
'dest_nation_id' => util::array_get($dest['nation_id'], null),
'dest_name' => util::array_get($dest['name'], null),
'dest_nation' => util::array_get($dest['nation'], null),
'dest_color' => util::array_get($dest['color'], null),
'message' => $msg
));
}
function sendMessage($msgType, $src, $dest, $msg, $date = null){
if($date === null){
$date = $datetime->format('Y-m-d H:i:s');
}
if($msgType === 'public'){
//dest는 필요하지 않음
$srcMailbox = null;
$destMailbox = 9999;
$dest['id'] = 9999;
}
else if($msgType === 'national'){
//dest는 nation_id만 필요함
$dest['id'] = $dest['nation_id'] + 9000;
if($src['nation_id'] === $dest['nation_id']){
$srcMailbox = null;
}
else{
$srcMailbox = $src['nation_id'] + 9000;
}
$destMailbox = $dest['nation_id'] + 9000;
}
else{
//dest는 id, name이 필수
$srcMailbox = $src['id'];
$destMailbox = $dest['id'];
}
if($srcMailbox !== null){
sendRawMessage($msgType, true, $srcMailbox, $src, $dest, $msg, $date);
}
sendRawMessage($msgType, false, $destMailbox, $src, $dest, $msg, $date);
}
function getMailboxList(){
$result = [];
$generalID = getGeneralID();
$db = getDB();
$me = $db->queryFirstRow('select no,nation,level from general where user_id=%i', $generalID);
//가장 최근에 주고 받은 사람.
$latestMessage = util::array_get(getMessage('private', 1)[0], null);
if($latestMessage !== null){
if($latestMessage->src == $generalID){
$latestMessage = $latestMessage->dest;
}
else{
$latestMessage = $latestMessage->src;
}
}
$nations = [];
foreach ($db->query('select nation, name, color from nation') as $nation) {
$nations[$nation['nation']] = $nation;
}
$nations[0] = [
'nation' => 0,
'name' => '재야',
'color' => '#ffffff'
];
$generals = $db->query('select no, nation, name, level from general where npc < 2 and no != %i order by name asc', $generalID);
foreach ($generals as $general) {
$nations[$general['nation']] = $general;
}
return [
'me' => $me,
'latest' => $latestMessage,
'nations' => $nations
];
}
function genList($connect) {
$query = "select no,nation,level,msgindex,userlevel from general where user_id='{$_SESSION['p_id']}'";
+53 -139
View File
@@ -3,9 +3,6 @@ include 'lib.php';
include 'func.php';
require_once('func_message.php');
// $msg, $genlist
$post = parseJsonPost();
if(!isset($post['genlist']) || !isset($post['msg'])){
@@ -18,7 +15,7 @@ if(!isset($post['genlist']) || !isset($post['msg'])){
}
$dest = $post['dest'];
$destMailbox = $post['dest_mailbox'];
$msg = $post['msg'];
$datetime = new DateTime();
$date = $datetime->format('Y-m-d H:i:s');
@@ -39,9 +36,7 @@ $db = getDB();
$connect = dbConn();
increaseRefresh($connect, '서신전달', 1);
//$msg,$genlist 두가지 값을 받
if(CheckBlock($connect) == 1 || CheckBlock($connect) == 3) {
if(getBlockLevel() == 1 || getBlockLevel() == 3) {
header('Content-Type: application/json');
die(json_encode([
'result' => false,
@@ -50,9 +45,6 @@ if(CheckBlock($connect) == 1 || CheckBlock($connect) == 3) {
]));
}
$conlimit = $db->queryFirstField('select conlimit from game where no=1');
$me = $db->queryFirstRow('select `no`,`name`,`nation`,`level`,`msgindex`,`userlevel`,`con`,`picture`,`imgsvr` from `general` where `user_id` = %s_p_id',
@@ -89,106 +81,55 @@ if($msg == ''){
]));
}
$src = $me['no'];
$src_name = $me['name'];
$src_icon = $me['picture'];
$src_nation_id = $me['nation'];
if($src_nation_id == 0) {
$src_nation = '재야';
$src_color = '#FFFFFF';
}
else{
$src = [
'id' => $me['no'],
'name' => $me['name'],
'icon' => $me['picture'],
'nation_id' => $me['nation'],
'nation' => null
];
if($src['nation_id'] != 0) {
$nation = $db->queryFirstRow('select nation,name,color from nation where nation=%i',$src_nation_id);
$src_nation = $nation['name'];
$src_color = '#'.$nation['color'];
$src_color = str_replace('##', '#', $src_color); //FIXME: nation table에서 color가 #포함된 걸로 바뀔 경우를 대비
$src['nation'] = $nation['name'];
$src['color'] = '#'.$nation['color'];
$src['color'] = str_replace('##', '#', $src['color']); //FIXME: nation table에서 color가 #포함된 걸로 바뀔 경우를 대비
}
// 전체 메세지
if($dest == 9999) {
$db->insert('message', array(
'address' => $dest,
'type' => 'global',
'src' => $src,
'dest' => $dest,
'time' => $date,
'src_name' => $src_name,
'src_nation' => $src_nation,
'src_color' => $src_color,
'src_icon' => $src_icon,
'message' => $msg
));
if($destMailbox == 9999) {
sendMessage('public', $src, [], $msg, $date);
// 국가 메세지
} elseif($dest >= 9000) {
$real_nation = $dest - 9000;
} elseif($destMailbox >= 9000) {
if($me['level'] < 5){
$real_nation = $me['nation_id'];
}
else{
$real_nation = $dest - 9000;
}
$nation = $db->queryFirstRow('select nation,name,color from nation where nation=%i',$real_nation);
if($nation === NULL || empty($nation)){
$dest = 9998;
$dest_nation = '재야';
$dest_color = '#FFFFFF';
$dest = ['nation_id' => 0];
}
else{
$dest_nation = $nation['name'];
$dest_color = '#'.$nation['color'];
$dest_color = str_replace('##', '#', $dest_color); //FIXME: nation table에서 color가 #포함된 걸로 바뀔 경우를 대비
$color = '#'.$nation['color'];
$color = str_replace('##', '#', $color);
//FIXME: nation table에서 color가 #포함된 걸로 바뀔 경우를 대비
$dest = [
'nation_id' => $nation['nation'],
'color' => $color
];
}
if($nation['nation'] == $me['nation'] || $me['level'] < 5){
$db->insert('message', array(
'address' => $dest,
'type' => 'receive_nation',
'src' => $src,
'dest' => $dest,
'time' => $date,
'src_name' => $src_name,
'src_nation' => $src_nation,
'src_color' => $src_color,
'src_icon' => $src_icon,
'dest_nation' => $dest_nation,
'dest_color' => $dest_color,
'message' => $msg
));
}
else{
$db->insert('message', array(
'address' => $src_nation_id + 9000,
'type' => 'send_nation',
'src' => $src,
'dest' => $dest,
'time' => $date,
'src_name' => $src_name,
'src_nation' => $src_nation,
'src_color' => $src_color,
'src_icon' => $src_icon,
'dest_nation' => $dest_nation,
'dest_color' => $dest_color,
'message' => $msg
));
$db->insert('message', array(
'address' => $dest,
'type' => 'receive_nation',
'src' => $src,
'dest' => $dest,
'time' => $date,
'src_name' => $src_name,
'src_nation' => $src_nation,
'src_color' => $src_color,
'src_icon' => $src_icon,
'dest_nation' => $dest_nation,
'dest_color' => $dest_color,
'message' => $msg
));
}
sendMessage('national', $src, $dest, $msg, $date);
// 개인 메세지
} elseif($dest > 0) {
} elseif($destMailbox > 0) {
$last_msg = new DateTime(util::array_get($_SESSION['last_msg'], '0000-00-00'));
$msg_interval = $datetime->getTimestamp() - $last_msg->getTimestamp();
//NOTE: 여기서 유저 레벨을 구별할 코드가 필요할까?
if($msg_interval < 2){
header('Content-Type: application/json');
die(json_encode([
@@ -198,11 +139,10 @@ if($dest == 9999) {
]));
}
$_SESSION['last_msg'] = $date;
$destUser = $db->queryFirstRow('select `no`,`name`,`nation` from `general` where `user_id` = %s',$destMailbox);
$dest_user = $db->queryFirstRow('select `no`,`name`,`nation` from `general` where `user_id` = %s',$dest);
if($dest_user == NULL || empty($dest_user)){
if($destUser == NULL || empty($destUser)){
header('Content-Type: application/json');
die(json_encode([
'result' => false,
@@ -211,49 +151,23 @@ if($dest == 9999) {
]));
}
$dest_name = $dest_user['name'];
if($dest_user['nation'] == 0){
$dest_nation = $nation['name'];
$dest_color = '#'.$nation['color'];
$dest_color = str_replace('##', '#', $dest_color);
}
else{
$nation = $db->queryFirstRow('select nation,name,color from nation where nation=%i',$dest_user['nation']);
$dest_nation = $nation['name'];
$dest_color = '#'.$nation['color'];
$dest_color = str_replace('##', '#', $dest_color); //FIXME: nation table에서 color가 #포함된 걸로 바뀔 경우를 대비
}
$_SESSION['last_msg'] = $date;
$db->insert('message', array(
'address' => $src_nation_id + 9000,
'type' => 'send',
'src' => $src,
'dest' => $dest,
'time' => $date,
'src_name' => $src_name,
'src_nation' => $src_nation,
'src_color' => $src_color,
'src_icon' => $src_icon,
'dest_name' => $dest_name,
'dest_nation' => $dest_nation,
'dest_color' => $dest_color,
'message' => $msg
));
$db->insert('message', array(
'address' => $dest,
'type' => 'receive',
'src' => $src,
'dest' => $dest,
'time' => $date,
'src_name' => $src_name,
'src_nation' => $src_nation,
'src_color' => $src_color,
'src_icon' => $src_icon,
'dest_name' => $dest_name,
'dest_nation' => $dest_nation,
'dest_color' => $dest_color,
'message' => $msg
));
$dest = [
'id' => $destMailbox,
'name' => $dest_user['name']
];
if($dest_user['nation'] != 0){
$nation = $db->queryFirstRow('select nation,name,color from nation where nation=%i',$dest_user['nation']);
$color = $nation['color'];
$color = str_replace('##', '#', $color);
//FIXME: nation table에서 color가 #포함된 걸로 바뀔 경우를 대비
$dest['color'] = $color;
$dest['nation'] = $nation['name'];
$dest['nation_id'] = $nation['nation'];
}
sendMessage('private', $src, $dest, $msg, $date);
}
else{
header('Content-Type: application/json');
+14 -4
View File
@@ -432,14 +432,24 @@ $game_schema = "
$message_schema = "
CREATE TABLE `message` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`address` INT(11) NOT NULL,
`type` ENUM('send','receive') NOT NULL,
`mailbox` INT(11) NOT NULL COMMENT '9999 == public, >= 9000 national',
`type` ENUM('private','national','public') NOT NULL,
`is_sender` BIT(1) NOT NULL,
`src` INT(11) NOT NULL,
`dest` INT(11) NOT NULL,
`time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
`src_nation_id` INT(11) NULL DEFAULT NULL,
`src_name` VARCHAR(15) NOT NULL,
`src_nation` VARCHAR(15) NULL DEFAULT NULL,
`src_color` VARCHAR(15) NULL DEFAULT NULL,
`src_icon` VARCHAR(15) NULL DEFAULT NULL,
`dest_nation_id` INT(11) NULL DEFAULT NULL,
`dest_name` VARCHAR(15) NULL DEFAULT NULL,
`dest_nation` VARCHAR(15) NULL DEFAULT NULL,
`dest_color` VARCHAR(15) NULL DEFAULT NULL,
`message` TEXT NOT NULL,
PRIMARY KEY (`id`),
INDEX `by_owner` (`address`, `time`),
INDEX `by_owner` (`mailbox`, `time`),
INDEX `by_dest` (`dest`, `time`),
INDEX `by_full` (`src`, `dest`, `time`)
)