|
|
@@ -1078,12 +1078,14 @@ class Gateway
|
|
|
*/
|
|
|
protected static function sendCmdAndMessageToClient($client_id, $cmd, $message, $ext_data = '')
|
|
|
{
|
|
|
+ echo $cmd."\n";
|
|
|
// 如果是发给当前用户则直接获取上下文中的地址
|
|
|
if ($client_id === Context::$client_id || $client_id === null) {
|
|
|
$address = long2ip(Context::$local_ip) . ':' . Context::$local_port;
|
|
|
$connection_id = Context::$connection_id;
|
|
|
} else {
|
|
|
$address_data = Context::clientIdToAddress($client_id);
|
|
|
+ var_dump($address_data);
|
|
|
if (!$address_data) {
|
|
|
return false;
|
|
|
}
|
|
|
@@ -1094,10 +1096,14 @@ class Gateway
|
|
|
$gateway_data['cmd'] = $cmd;
|
|
|
$gateway_data['connection_id'] = $connection_id;
|
|
|
$gateway_data['body'] = $message;
|
|
|
+
|
|
|
if (!empty($ext_data)) {
|
|
|
$gateway_data['ext_data'] = $ext_data;
|
|
|
}
|
|
|
-
|
|
|
+ print_r($gateway_data);
|
|
|
+ $res = static::sendToGateway($address, $gateway_data);
|
|
|
+ var_dump($res);
|
|
|
+ return $res;
|
|
|
return static::sendToGateway($address, $gateway_data);
|
|
|
}
|
|
|
|
|
|
@@ -1418,6 +1424,7 @@ class Context
|
|
|
public static function addressToClientId($local_ip, $local_port, $connection_id)
|
|
|
{
|
|
|
return bin2hex(pack('NnN', $local_ip, $local_port, $connection_id));
|
|
|
+ //return bin2hex(pack('NNnN', time(), $local_ip, $local_port, $connection_id));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -1426,6 +1433,11 @@ class Context
|
|
|
*/
|
|
|
public static function clientIdToAddress($client_id)
|
|
|
{
|
|
|
+// if (strlen($client_id) !== 28) {
|
|
|
+// echo new Exception("client_id $client_id is invalid");
|
|
|
+// return false;
|
|
|
+// }
|
|
|
+// return unpack('Ntime/Nlocal_ip/nlocal_port/Nconnection_id', pack('H*', $client_id));
|
|
|
if(strlen($client_id) !== 20)
|
|
|
{
|
|
|
throw new \Exception("client_id $client_id is invalid");
|