示例#1
0
 /**
  * 踢掉某个网关的socket
  * @param string $local_ip
  * @param int $local_port
  * @param int $socket_id
  * @param string $message
  * @param int $uid
  */
 public static function kickAddress($local_ip, $local_port, $socket_id, $message, $uid = null)
 {
     $pack = new GatewayProtocol();
     $pack->header['cmd'] = GatewayProtocol::CMD_KICK;
     $pack->header['series_id'] = Context::$series_id > 0 ? Context::$series_id : 0;
     $pack->header['local_ip'] = $local_ip;
     $pack->header['local_port'] = $local_port;
     $pack->header['socket_id'] = $socket_id;
     if (null !== Context::$client_ip) {
         $pack->header['client_ip'] = Context::$client_ip;
         $pack->header['client_port'] = Context::$client_port;
     }
     $pack->header['uid'] = $uid ? $uid : 0;
     $pack->body = $message;
     return self::sendToGateway("udp://{$pack->header['local_ip']}:{$pack->header['local_port']}", $pack->getBuffer());
 }
示例#2
0
 protected function sendToWorker($cmd, $socket_id, $body = '')
 {
     $address = $this->getRemoteAddress($socket_id);
     list($client_ip, $client_port) = explode(':', $address, 2);
     if (empty($client_port)) {
         $this->notice(new Exception('$address empty :' . var_export($address, true)) . ' $this->connections:' . var_export($this->connections, true) . ' this->protocol:' . $this->protocol);
     }
     $pack = new GatewayProtocol();
     $pack->header['cmd'] = $cmd;
     $pack->header['local_ip'] = $this->lanIp;
     $pack->header['local_port'] = $this->lanPort;
     $pack->header['socket_id'] = $socket_id;
     $pack->header['client_ip'] = $client_ip;
     $pack->header['client_port'] = $client_ip;
     $pack->header['uid'] = $this->getUidByFd($socket_id);
     $pack->body = $body;
     return $this->sendBufferToWorker($pack->getBuffer());
 }