mHost = $host; $this->mPort = $port; $this->mRooms = []; parent::__construct(); $this->mBodyType = tcp_client::JsonType; $this->init(); } public function __destruct() { parent::__destruct(); } public function init() { $ret = $this->list_room(); if($ret != false) { $rooms = $ret['rooms']; foreach ($rooms as $roomid) { $this->add_room($roomid); } } } public function contain_room($roomid) { $roomid = intval($roomid); return algorithm::binary_search($this->mRooms,$roomid); } public function add_room($roomid) { $room = intval($roomid); if(algorithm::binary_search($this->mRooms,$room) == false) { $pos = algorithm::lower_bonud($this->mRooms,$room); algorithm::array_insert($this->mRooms,$pos,$room); } } private function list_room() { $param = ["act" => 'factory','op' => 'list_room']; $result = $this->request($param); if(empty($result)) return false; $code = intval($result['code']); if($code != 200) { return false; } else { return $result['data']; } } public function remote_addr() { return "{$this->mHost}:{$this->mPort}"; } public function invite($roomid,$user) { $param = ["act" => 'factory','op' => 'invite','room' => $roomid,'user' => $user]; $result = $this->request($param); if(empty($result)) return false; $code = intval($result['code']); if($code != 200) { return false; } else { return $result['data']; } } }