dictionary(php에선 associative array) 여부 확인하는 코드 추가
메시지 전송 코드를 message에 json을 이용하도록 변경. 외교 서신 등을 위한 $option을 추가
This commit is contained in:
+8
-12
@@ -105,7 +105,7 @@ function getMessage($msgType, $limit=30, $fromTime=NULL){
|
||||
}
|
||||
}
|
||||
|
||||
function sendRawMessage($msgType, $isSender, $mailbox, $src, $dest, $msg, $date){
|
||||
function sendRawMessage($msgType, $isSender, $mailbox, $src, $dest, $msg, $date, $msgOption){
|
||||
|
||||
getDB()->insert('message', array(
|
||||
'address' => $dest,
|
||||
@@ -113,20 +113,16 @@ function sendRawMessage($msgType, $isSender, $mailbox, $src, $dest, $msg, $date)
|
||||
'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
|
||||
'message' => json_encode(eraseNullValue([
|
||||
'src' => $src,
|
||||
'dest' =>$dest,
|
||||
'text' => $msg,
|
||||
'option' => $msgOption
|
||||
]))
|
||||
));
|
||||
}
|
||||
|
||||
function sendMessage($msgType, $src, $dest, $msg, $date = null){
|
||||
function sendMessage($msgType, $src, $dest, $msg, $date = null, $msgOption = null){
|
||||
if($date === null){
|
||||
$date = $datetime->format('Y-m-d H:i:s');
|
||||
}
|
||||
|
||||
+27
-2
@@ -249,7 +249,32 @@ function dictToArray($dict, $keys){
|
||||
return $result;
|
||||
}
|
||||
|
||||
function eraseNullKey(&$dict, $depth=512){
|
||||
function isDict(&$array){
|
||||
if(!is_array($array)){
|
||||
//배열이 아니면 dictionary 조차 아님.
|
||||
return false;
|
||||
}
|
||||
$idx = 0;
|
||||
$jmp = 0;
|
||||
foreach ($arr as $key=>&$value) {
|
||||
if(is_string($key)){
|
||||
return true;
|
||||
}
|
||||
$jmp = $key - $idx - 1;
|
||||
$idx = $key;
|
||||
}
|
||||
|
||||
if ($jmp * 5 >= count($array)){
|
||||
//빈칸이 많으면 dictionary인걸로.
|
||||
return true;
|
||||
}
|
||||
else{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function eraseNullValue(&$dict, $depth=512){
|
||||
//TODO:Test 추가
|
||||
if($depth <= 0){
|
||||
return $dict;
|
||||
@@ -259,7 +284,7 @@ function eraseNullKey(&$dict, $depth=512){
|
||||
if($value === null){
|
||||
unset($dict[$key]);
|
||||
}
|
||||
else if(is_array($value)){
|
||||
else if(isDict($value)){
|
||||
$dict[$key] = eraseNullKey($value, $depth - 1);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user