|
@@ -18,12 +18,14 @@ class room_processor implements IProcessor
|
|
|
private $mAccConnes;
|
|
|
private $mFactory;
|
|
|
private $mRooms;
|
|
|
+ private $mChatwo;
|
|
|
|
|
|
public function __construct()
|
|
|
{
|
|
|
$this->mAccConnes = [];
|
|
|
$this->mFactory = new factory();
|
|
|
$this->mRooms = [];
|
|
|
+ $this->mChatwo = new chatwo();
|
|
|
}
|
|
|
|
|
|
public function onRequest($bufid, $body)
|
|
@@ -37,19 +39,25 @@ class room_processor implements IProcessor
|
|
|
}
|
|
|
|
|
|
$act = $input['act'];
|
|
|
- if(!empty($act) && $act == proto_type::act_factory) {
|
|
|
+ if(empty($act)) return false;
|
|
|
+
|
|
|
+ if($act == proto_type::act_factory) {
|
|
|
$ret = $this->onFactory($bufid,$input);
|
|
|
room_server::instance()->write($bufid,$ret);
|
|
|
return true;
|
|
|
}
|
|
|
- elseif(!empty($act) && $act == proto_type::act_access) {
|
|
|
+ elseif($act == proto_type::act_access) {
|
|
|
$ret = $this->onAccess($bufid,$input);
|
|
|
return $ret;
|
|
|
}
|
|
|
- else {
|
|
|
+ elseif($act == proto_type::act_room) {
|
|
|
$ret = $this->onRoom($bufid,$input);
|
|
|
return $ret;
|
|
|
}
|
|
|
+ elseif($act == proto_type::act_chatwo) {
|
|
|
+ $ret = $this->onChatwo($bufid,$input);
|
|
|
+ return $ret;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public function onClose($bufid)
|
|
@@ -149,6 +157,11 @@ class room_processor implements IProcessor
|
|
|
|
|
|
return $this->error(errcode::ErrRoomLeave);
|
|
|
}
|
|
|
+ elseif($op == 'push') {
|
|
|
+ $content = $input['content'];
|
|
|
+ $this->write_push($content);
|
|
|
+ return $this->success(NULL);
|
|
|
+ }
|
|
|
else
|
|
|
{
|
|
|
return $this->error(errcode::ErrRoomFactoryOp);
|
|
@@ -186,37 +199,58 @@ class room_processor implements IProcessor
|
|
|
if($room != false)
|
|
|
{
|
|
|
$function = $input['op'] . 'Op';
|
|
|
- $roomkey = $input['room_key'];
|
|
|
-
|
|
|
if (method_exists($room,$function))
|
|
|
{
|
|
|
$success = $room->$function($input);
|
|
|
if($success) {
|
|
|
$this->write_roomsg($bufid,$room);
|
|
|
}
|
|
|
- else {
|
|
|
- $this->del_user($bufid,$room->room_id(), [$roomkey]);
|
|
|
- }
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return false;
|
|
|
}
|
|
|
+ ////////////////////////////////////////Peer Message Handler////////////////////////////////////////////////////////
|
|
|
+ private function onChatwo($bufid, $input)
|
|
|
+ {
|
|
|
+ $function = $input['op'] . 'Op';
|
|
|
+ if (method_exists($this->mChatwo,$function))
|
|
|
+ {
|
|
|
+ $msg = $this->mChatwo->$function($input);
|
|
|
+ if($msg != false)
|
|
|
+ {
|
|
|
+ $body = $this->success($msg);
|
|
|
+ foreach ($this->mAccConnes as $conn) {
|
|
|
+ room_server::instance()->write($conn,$body);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
- private function del_user($bufid,$room_id,$roomkeys)
|
|
|
+ private function write_push($content)
|
|
|
{
|
|
|
$msg = [];
|
|
|
- $msg['receivers'] = ['type' => 'roomkey', 'users' => $roomkeys];
|
|
|
- $msg['room'] = $room_id;
|
|
|
- $msg['act'] = 'room';
|
|
|
- $msg['op'] = 'deluser';
|
|
|
|
|
|
- $body = $this->success(['msg' => $msg]);
|
|
|
- room_server::instance()->write($bufid,$body);
|
|
|
- }
|
|
|
+ $msg['act'] = "room";
|
|
|
+ $msg['op'] = "relay";
|
|
|
+ $msg['relay_type'] = "alluser";
|
|
|
+ $msg['receivers'] = [];
|
|
|
+ $msg['room'] = 0;
|
|
|
+ $msg['receiver_type'] = proto_type::sroom_push;
|
|
|
+
|
|
|
+ $msg['body']['act'] = proto_type::act_push;
|
|
|
+ $msg['body']['op'] = 'message';
|
|
|
+ $msg['body']['content'] = $content;
|
|
|
|
|
|
+ $body = $this->success($msg);
|
|
|
+ foreach ($this->mAccConnes as $conn) {
|
|
|
+ room_server::instance()->write($conn,$body);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
protected function write_accmsg($bufid,$op,$content)
|
|
|
{
|
|
|
$msg['act'] = "access";
|
|
@@ -225,7 +259,7 @@ class room_processor implements IProcessor
|
|
|
$msg['body']['act'] = 'access';
|
|
|
$msg['body']['op'] = $op;
|
|
|
$msg['body']['content'] = $content;
|
|
|
- $body = $this->success(['msg' => $msg]);
|
|
|
+ $body = $this->success($msg);
|
|
|
|
|
|
room_server::instance()->write($bufid,$body);
|
|
|
}
|
|
@@ -234,20 +268,20 @@ class room_processor implements IProcessor
|
|
|
{
|
|
|
$retmsgs = $room->return_msgs();
|
|
|
foreach ($retmsgs as $msg) {
|
|
|
- $body = $this->success(['msg' => $msg]);
|
|
|
+ $body = $this->success($msg);
|
|
|
room_server::instance()->write($bufid,$body);
|
|
|
}
|
|
|
|
|
|
$broad_msgs = $room->broadcast_msgs();
|
|
|
foreach ($broad_msgs as $msg)
|
|
|
{
|
|
|
- $body = $this->success(['msg' => $msg]);
|
|
|
+ $body = $this->success($msg);
|
|
|
foreach ($this->mAccConnes as $conn) {
|
|
|
room_server::instance()->write($conn,$body);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
private function room($roomid)
|
|
|
{
|
|
|
if($roomid <= 0) return false;
|
|
@@ -279,12 +313,12 @@ class room_processor implements IProcessor
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
- private function success($datas)
|
|
|
+ private function success($val)
|
|
|
{
|
|
|
$code = errcode::Success;
|
|
|
$data['code'] = $code;
|
|
|
$data['message'] = errcode::msg($code);
|
|
|
- $data['data'] = $datas;
|
|
|
+ $data['data'] = $val;
|
|
|
|
|
|
return json_encode($data);
|
|
|
}
|
|
@@ -298,7 +332,7 @@ class room_processor implements IProcessor
|
|
|
$data = array();
|
|
|
$data['code'] = $code;
|
|
|
$data['message'] = $message;
|
|
|
- $data['datas'] = null;
|
|
|
+ $data['data'] = null;
|
|
|
return json_encode($data);
|
|
|
}
|
|
|
}
|