|
@@ -137,24 +137,26 @@ class Gateway
|
|
|
/**
|
|
|
* 向某个client_id对应的连接发消息
|
|
|
*
|
|
|
- * @param int $client_id
|
|
|
+ * @param string $client_id
|
|
|
* @param string $message
|
|
|
+ * @param bool $raw
|
|
|
* @return void
|
|
|
*/
|
|
|
- public static function sendToClient($client_id, $message)
|
|
|
+ public static function sendToClient($client_id, $message, $raw = false)
|
|
|
{
|
|
|
- return static::sendCmdAndMessageToClient($client_id, GatewayProtocol::CMD_SEND_TO_ONE, $message);
|
|
|
+ return static::sendCmdAndMessageToClient($client_id, GatewayProtocol::CMD_SEND_TO_ONE, $message, $raw);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 向当前客户端连接发送消息
|
|
|
*
|
|
|
* @param string $message
|
|
|
+ * @param bool $raw
|
|
|
* @return bool
|
|
|
*/
|
|
|
- public static function sendToCurrentClient($message)
|
|
|
+ public static function sendToCurrentClient($message, $raw = false)
|
|
|
{
|
|
|
- return static::sendCmdAndMessageToClient(null, GatewayProtocol::CMD_SEND_TO_ONE, $message);
|
|
|
+ return static::sendCmdAndMessageToClient(null, GatewayProtocol::CMD_SEND_TO_ONE, $message, $raw);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -171,7 +173,7 @@ class Gateway
|
|
|
/**
|
|
|
* 判断client_id对应的连接是否在线
|
|
|
*
|
|
|
- * @param int $client_id
|
|
|
+ * @param string $client_id
|
|
|
* @return int 0|1
|
|
|
*/
|
|
|
public static function isOnline($client_id)
|
|
@@ -837,7 +839,7 @@ class Gateway
|
|
|
/**
|
|
|
* 踢掉某个客户端并直接立即销毁相关连接
|
|
|
*
|
|
|
- * @param int $client_id
|
|
|
+ * @param string $client_id
|
|
|
* @return bool
|
|
|
*/
|
|
|
public static function destoryClient($client_id)
|
|
@@ -873,7 +875,7 @@ class Gateway
|
|
|
/**
|
|
|
* 将 client_id 与 uid 绑定
|
|
|
*
|
|
|
- * @param int $client_id
|
|
|
+ * @param string $client_id
|
|
|
* @param int|string $uid
|
|
|
* @return void
|
|
|
*/
|
|
@@ -885,7 +887,7 @@ class Gateway
|
|
|
/**
|
|
|
* 将 client_id 与 uid 解除绑定
|
|
|
*
|
|
|
- * @param int $client_id
|
|
|
+ * @param string $client_id
|
|
|
* @param int|string $uid
|
|
|
* @return void
|
|
|
*/
|
|
@@ -897,7 +899,7 @@ class Gateway
|
|
|
/**
|
|
|
* 将 client_id 加入组
|
|
|
*
|
|
|
- * @param int $client_id
|
|
|
+ * @param string $client_id
|
|
|
* @param int|string $group
|
|
|
* @return void
|
|
|
*/
|
|
@@ -910,7 +912,7 @@ class Gateway
|
|
|
/**
|
|
|
* 将 client_id 离开组
|
|
|
*
|
|
|
- * @param int $client_id
|
|
|
+ * @param string $client_id
|
|
|
* @param int|string $group
|
|
|
*
|
|
|
* @return void
|
|
@@ -944,14 +946,18 @@ class Gateway
|
|
|
*
|
|
|
* @param int|string|array $uid
|
|
|
* @param string $message
|
|
|
+ * @param bool $raw
|
|
|
*
|
|
|
* @return void
|
|
|
*/
|
|
|
- public static function sendToUid($uid, $message)
|
|
|
+ public static function sendToUid($uid, $message, $raw = false)
|
|
|
{
|
|
|
$gateway_data = GatewayProtocol::$empty;
|
|
|
$gateway_data['cmd'] = GatewayProtocol::CMD_SEND_TO_UID;
|
|
|
$gateway_data['body'] = $message;
|
|
|
+ if ($raw) {
|
|
|
+ $gateway_data['flag'] |= GatewayProtocol::FLAG_NOT_CALL_ENCODE;
|
|
|
+ }
|
|
|
|
|
|
if (!is_array($uid)) {
|
|
|
$uid = array($uid);
|
|
@@ -1025,7 +1031,7 @@ class Gateway
|
|
|
/**
|
|
|
* 更新 session,框架自动调用,开发者不要调用
|
|
|
*
|
|
|
- * @param int $client_id
|
|
|
+ * @param string $client_id
|
|
|
* @param string $session_str
|
|
|
* @return bool
|
|
|
*/
|
|
@@ -1037,7 +1043,7 @@ class Gateway
|
|
|
/**
|
|
|
* 设置 session,原session值会被覆盖
|
|
|
*
|
|
|
- * @param int $client_id
|
|
|
+ * @param string $client_id
|
|
|
* @param array $session
|
|
|
*
|
|
|
* @return void
|
|
@@ -1054,7 +1060,7 @@ class Gateway
|
|
|
/**
|
|
|
* 更新 session,实际上是与老的session合并
|
|
|
*
|
|
|
- * @param int $client_id
|
|
|
+ * @param string $client_id
|
|
|
* @param array $session
|
|
|
*
|
|
|
* @return void
|
|
@@ -1071,7 +1077,7 @@ class Gateway
|
|
|
/**
|
|
|
* 获取某个client_id的session
|
|
|
*
|
|
|
- * @param int $client_id
|
|
|
+ * @param string $client_id
|
|
|
* @return mixed false表示出错、null表示用户不存在、array表示具体的session信息
|
|
|
*/
|
|
|
public static function getSession($client_id)
|
|
@@ -1095,13 +1101,14 @@ class Gateway
|
|
|
/**
|
|
|
* 向某个用户网关发送命令和消息
|
|
|
*
|
|
|
- * @param int $client_id
|
|
|
+ * @param string $client_id
|
|
|
* @param int $cmd
|
|
|
* @param string $message
|
|
|
* @param string $ext_data
|
|
|
+ * @param bool $raw
|
|
|
* @return boolean
|
|
|
*/
|
|
|
- protected static function sendCmdAndMessageToClient($client_id, $cmd, $message, $ext_data = '')
|
|
|
+ protected static function sendCmdAndMessageToClient($client_id, $cmd, $message, $ext_data = '', $raw = false)
|
|
|
{
|
|
|
// 如果是发给当前用户则直接获取上下文中的地址
|
|
|
if ($client_id === Context::$client_id || $client_id === null) {
|
|
@@ -1122,6 +1129,9 @@ class Gateway
|
|
|
if (!empty($ext_data)) {
|
|
|
$gateway_data['ext_data'] = $ext_data;
|
|
|
}
|
|
|
+ if ($raw) {
|
|
|
+ $gateway_data['flag'] |= GatewayProtocol::FLAG_NOT_CALL_ENCODE;
|
|
|
+ }
|
|
|
|
|
|
return static::sendToGateway($address, $gateway_data);
|
|
|
}
|