From 297c7f2e20b2f5721e8fca6cbddc8b8d5be03789 Mon Sep 17 00:00:00 2001 From: walkor Date: Mon, 5 Oct 2015 13:26:33 +0800 Subject: [PATCH] update version 1.0.3 --- GatewayWorker/Gateway.php | 2 +- GatewayWorker/Lib/Gateway.php | 28 +++++++++++++++++----------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/GatewayWorker/Gateway.php b/GatewayWorker/Gateway.php index 548107f..4347c43 100644 --- a/GatewayWorker/Gateway.php +++ b/GatewayWorker/Gateway.php @@ -37,7 +37,7 @@ class Gateway extends Worker * 版本 * @var string */ - const VERSION = '1.0.2'; + const VERSION = '1.0.3'; /** * 本机ip diff --git a/GatewayWorker/Lib/Gateway.php b/GatewayWorker/Lib/Gateway.php index 5039736..66fb384 100644 --- a/GatewayWorker/Lib/Gateway.php +++ b/GatewayWorker/Lib/Gateway.php @@ -179,11 +179,7 @@ public static function closeCurrentClient() */ public static function bindUid($client_id, $uid) { - $gateway_data = GatewayProtocol::$empty; - $gateway_data['cmd'] = GatewayProtocol::CMD_BIND_UID; - $gateway_data['client_id'] = $client_id; - $gateway_data['ext_data'] = $uid; - return self::sendToGateway(Context::$local_ip . ':' . Context::$local_port, $gateway_data); + return self::sendCmdAndMessageToClient($client_id, GatewayProtocol::CMD_BIND_UID, '', $uid); } /** @@ -214,11 +210,17 @@ public static function sendToUid($uid, $message) */ public static function updateSocketSession($client_id, $session_str) { - $gateway_data = GatewayProtocol::$empty; - $gateway_data['cmd'] = GatewayProtocol::CMD_UPDATE_SESSION; - $gateway_data['client_id'] = $client_id; - $gateway_data['ext_data'] = $session_str; - return self::sendToGateway(Context::$local_ip . ':' . Context::$local_port, $gateway_data); + return self::sendCmdAndMessageToClient($client_id, GatewayProtocol::CMD_UPDATE_SESSION, '', $session_str); + } + + /** + * 更新session + * @param int $client_id + * @param array $session + */ + public static function updateSession($client_id, array $session) + { + self::updateSocketSession($client_id, Context::sessionEncode($session)); } /** @@ -228,7 +230,7 @@ public static function updateSocketSession($client_id, $session_str) * @param string $message * @return boolean */ - protected static function sendCmdAndMessageToClient($client_id, $cmd , $message) + protected static function sendCmdAndMessageToClient($client_id, $cmd , $message, $ext_data = '') { // 如果是发给当前用户则直接获取上下文中的地址 if($client_id === Context::$client_id || $client_id === null) @@ -247,6 +249,10 @@ protected static function sendCmdAndMessageToClient($client_id, $cmd , $message) $gateway_data['cmd'] = $cmd; $gateway_data['client_id'] = $client_id ? $client_id : Context::$client_id; $gateway_data['body'] = $message; + if(!empty($ext_data)) + { + $gateway_data['ext_data'] = $ext_data; + } return self::sendToGateway($address, $gateway_data); }