diff --git a/twe/func_message.php b/twe/func_message.php index 8832b34a..1da51233 100644 --- a/twe/func_message.php +++ b/twe/func_message.php @@ -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'); } diff --git a/twe/lib.php b/twe/lib.php index 08d47efe..e1adc952 100644 --- a/twe/lib.php +++ b/twe/lib.php @@ -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); } }