Skip to content

Commit

Permalink
update version 1.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
walkor committed Oct 5, 2015
1 parent 5b29594 commit 297c7f2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion GatewayWorker/Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Gateway extends Worker
* 版本
* @var string
*/
const VERSION = '1.0.2';
const VERSION = '1.0.3';

/**
* 本机ip
Expand Down
28 changes: 17 additions & 11 deletions GatewayWorker/Lib/Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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));
}

/**
Expand All @@ -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)
Expand All @@ -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);
}
Expand Down

0 comments on commit 297c7f2

Please sign in to comment.