Skip to content

Commit 297c7f2

Browse files
committed
update version 1.0.3
1 parent 5b29594 commit 297c7f2

2 files changed

Lines changed: 18 additions & 12 deletions

File tree

GatewayWorker/Gateway.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class Gateway extends Worker
3737
* 版本
3838
* @var string
3939
*/
40-
const VERSION = '1.0.2';
40+
const VERSION = '1.0.3';
4141

4242
/**
4343
* 本机ip

GatewayWorker/Lib/Gateway.php

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,7 @@ public static function closeCurrentClient()
179179
*/
180180
public static function bindUid($client_id, $uid)
181181
{
182-
$gateway_data = GatewayProtocol::$empty;
183-
$gateway_data['cmd'] = GatewayProtocol::CMD_BIND_UID;
184-
$gateway_data['client_id'] = $client_id;
185-
$gateway_data['ext_data'] = $uid;
186-
return self::sendToGateway(Context::$local_ip . ':' . Context::$local_port, $gateway_data);
182+
return self::sendCmdAndMessageToClient($client_id, GatewayProtocol::CMD_BIND_UID, '', $uid);
187183
}
188184

189185
/**
@@ -214,11 +210,17 @@ public static function sendToUid($uid, $message)
214210
*/
215211
public static function updateSocketSession($client_id, $session_str)
216212
{
217-
$gateway_data = GatewayProtocol::$empty;
218-
$gateway_data['cmd'] = GatewayProtocol::CMD_UPDATE_SESSION;
219-
$gateway_data['client_id'] = $client_id;
220-
$gateway_data['ext_data'] = $session_str;
221-
return self::sendToGateway(Context::$local_ip . ':' . Context::$local_port, $gateway_data);
213+
return self::sendCmdAndMessageToClient($client_id, GatewayProtocol::CMD_UPDATE_SESSION, '', $session_str);
214+
}
215+
216+
/**
217+
* 更新session
218+
* @param int $client_id
219+
* @param array $session
220+
*/
221+
public static function updateSession($client_id, array $session)
222+
{
223+
self::updateSocketSession($client_id, Context::sessionEncode($session));
222224
}
223225

224226
/**
@@ -228,7 +230,7 @@ public static function updateSocketSession($client_id, $session_str)
228230
* @param string $message
229231
* @return boolean
230232
*/
231-
protected static function sendCmdAndMessageToClient($client_id, $cmd , $message)
233+
protected static function sendCmdAndMessageToClient($client_id, $cmd , $message, $ext_data = '')
232234
{
233235
// 如果是发给当前用户则直接获取上下文中的地址
234236
if($client_id === Context::$client_id || $client_id === null)
@@ -247,6 +249,10 @@ protected static function sendCmdAndMessageToClient($client_id, $cmd , $message)
247249
$gateway_data['cmd'] = $cmd;
248250
$gateway_data['client_id'] = $client_id ? $client_id : Context::$client_id;
249251
$gateway_data['body'] = $message;
252+
if(!empty($ext_data))
253+
{
254+
$gateway_data['ext_data'] = $ext_data;
255+
}
250256

251257
return self::sendToGateway($address, $gateway_data);
252258
}

0 commit comments

Comments
 (0)