123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225 |
- <?php
- /**
- * Created by PhpStorm.
- * User: stanley-king
- * Date: 2017/12/14
- * Time: 上午11:43
- */
- namespace room;
- use search\tcp_client;
- class factory_client extends tcp_client
- {
- protected static $stInstance;
- public function __construct()
- {
- parent::__construct();
- $this->mBodyType = tcp_client::JsonType;
- }
- public static function instance()
- {
- if(self::$stInstance == null) {
- self::$stInstance = new factory_client();
- }
- return self::$stInstance;
- }
- public function __destruct()
- {
- parent::__destruct();
- }
- public function remote_addr()
- {
- global $config;
- $host = $config['room_factory']['host'];
- $port = $config['room_factory']['port'];
- return "tcp://{$host}:{$port}";
- }
- //////////////////////////////////////fcgi//////////////////////////////////////////////////////////////////////////
- public function create_bargain($goods_id,$user,$lowest_price,$usable_days,$random = true,$total_num = 10,$finvite = true)
- {
- $random = $random ? 1 : 0;
- $param = ["act" => 'fcgi','op' => 'create', "type" => 'bargain_goods','creator' => $user,'invite' => $finvite,
- 'goods_id' => $goods_id,
- 'lowest_price' => $lowest_price,
- 'usable_days' => $usable_days,
- 'random' => $random,'total_num' => $total_num];
- $result = $this->request($param);
- if(empty($result)) return false;
- $code = intval($result['code']);
- if($code != 200) {
- return false;
- }
- else {
- return $result['data'];
- }
- }
- public function create_chat($creator,$finvite = true)
- {
- $param = ["act" => 'fcgi','op' => 'create', "type" => proto_type::sroom_chat,'creator' => $creator,'invite' => $finvite];
- $result = $this->request($param);
- if(empty($result)) return false;
- $code = intval($result['code']);
- if($code != 200) {
- return false;
- }
- else {
- return $result['data'];
- }
- }
- public function create_shake($creator,$finvite = true)
- {
- $param = ["act" => 'fcgi','op' => 'create', "type" => 'shake_bonus','creator' => $creator,'invite' => $finvite];
- $result = $this->request($param);
- if(empty($result)) return false;
- $code = intval($result['code']);
- if($code != 200) {
- return false;
- }
- else {
- return $result['data'];
- }
- }
- //////////////////////////////////////fcgi//////////////////////////////////////////////////////////////////////////
- public function invite($roomid, $inviter,$invitees)
- {
- $users = [];
- foreach ($invitees as $user) {
- $users[] = intval($user);
- }
- $users = array_unique($users);
- if(empty($users)) return false;
- $param = ["act" => 'fcgi','op' => 'invite','room' => $roomid,'inviter' => $inviter,'invitees' => $users];
- $result = $this->request($param);
- if(empty($result)) return false;
- $code = intval($result['code']);
- if($code != 200 || empty($result['data']['invitees'])) {
- return false;
- }
- else {
- return $result['data'];
- }
- }
- public function leave($roomid, $user)
- {
- $param = ["act" => 'fcgi','op' => 'leave','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'];
- }
- }
- public function kickout($roomid,$user,$kicks)
- {
- $users = [];
- foreach ($kicks as $kick) {
- $uid = intval($kick);
- if($uid > 0) $users[] = $uid;
- }
- if(empty($kicks)) return false;
- $param = ["act" => 'fcgi','op' => 'kickout','room' => $roomid,'user' => $user,'kicks' => $users];
- $result = $this->request($param);
- if(empty($result)) return false;
- $code = intval($result['code']);
- if($code != 200) {
- return false;
- } else {
- return $result['data'];
- }
- }
- public function change($roomid)
- {
- $param = ["act" => 'fcgi','op' => 'change','room' => $roomid];
- $result = $this->request($param);
- if(empty($result)) return false;
- $code = intval($result['code']);
- if($code != 200) {
- return false;
- } else {
- return $result['data'];
- }
- }
- public function notice_all($type,$content,$msg)
- {
- $param = ["act" => 'fcgi','op' => 'notice_all','type' => $type,'content' => $content,'msg' => $msg];
- $result = $this->request($param);
- if(empty($result)) return false;
- $code = intval($result['code']);
- if($code != 200) {
- return false;
- } else {
- return true;
- }
- }
- public function notice_users($users,$type,$content,$msg)
- {
- $receivers = [];
- foreach ($users as $user) {
- $receivers[] = intval($user);
- }
- $param = ["act" => 'fcgi','op' => 'notice_users','users' => $receivers,'type' => $type,'content' => $content,'msg' => $msg];
- $result = $this->request($param);
- if(empty($result)) return false;
- $code = intval($result['code']);
- if($code != 200) {
- return false;
- } else {
- return true;
- }
- }
- public function notice_room($room, $sender, $type, $content)
- {
- $param = ["act" => 'fcgi','op' => 'notice_room','room' => $room,'type' => $type,'content' => $content,'user' => $sender];
- $result = $this->request($param);
- if(empty($result)) return false;
- $code = intval($result['code']);
- if($code != 200) {
- return false;
- } else {
- return true;
- }
- }
- //////////////////////////////////////access////////////////////////////////////////////////////////////////////////
- public function access()
- {
- $param = ["act" => 'access','op' => 'who'];
- $result = $this->request($param);
- if(empty($result)) return false;
- $code = intval($result['code']);
- if($code != 200) {
- return false;
- }
- else {
- return true;
- }
- }
- }
|