|
@@ -10,111 +10,111 @@ namespace room;
|
|
|
|
|
|
use member_info;
|
|
use member_info;
|
|
use Log;
|
|
use Log;
|
|
|
|
+use Exception;
|
|
|
|
|
|
abstract class base_room extends base_info
|
|
abstract class base_room extends base_info
|
|
{
|
|
{
|
|
protected $mRoomid;
|
|
protected $mRoomid;
|
|
- protected $mRoomkeys; //每个人都有一个唯一的roomkey
|
|
|
|
|
|
+ protected $mParticipants; //每个人都有一个唯一的roomkey
|
|
protected $mRoomType;
|
|
protected $mRoomType;
|
|
protected $mod_room;
|
|
protected $mod_room;
|
|
- protected $mAccReq;
|
|
|
|
protected $mCurRespMsgs;
|
|
protected $mCurRespMsgs;
|
|
|
|
|
|
- public function __construct($cinfos, $roomkeys = [])
|
|
|
|
|
|
+ public function __construct($cinfos, $participants = [])
|
|
{
|
|
{
|
|
parent::__construct($cinfos);
|
|
parent::__construct($cinfos);
|
|
|
|
|
|
- $this->mAccReq = false;
|
|
|
|
$this->mRoomid = $this->room_id();
|
|
$this->mRoomid = $this->room_id();
|
|
$this->mCurRespMsgs['return'] = [];
|
|
$this->mCurRespMsgs['return'] = [];
|
|
$this->mCurRespMsgs['broadcast'] = [];
|
|
$this->mCurRespMsgs['broadcast'] = [];
|
|
|
|
|
|
- $this->mRoomkeys = $roomkeys;
|
|
|
|
|
|
+ $this->mParticipants = $participants;
|
|
$this->mod_room = Model('room');
|
|
$this->mod_room = Model('room');
|
|
}
|
|
}
|
|
|
|
|
|
- public function inviteOp($input)
|
|
|
|
|
|
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
+ public function invite($inviter,$invitees)
|
|
{
|
|
{
|
|
- $this->clear();
|
|
|
|
- $userid = intval($input['user']);
|
|
|
|
- if($userid > 0) {
|
|
|
|
- $room_key = $this->invite($userid);
|
|
|
|
- $ret = ['room_key' => $room_key,'room' => $this->mRoomid];
|
|
|
|
- return true;
|
|
|
|
- } else {
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public function invite($userid)
|
|
|
|
- {
|
|
|
|
- $item = Model('member')->getMemberInfo(['member_id' => $userid]);
|
|
|
|
- if(empty($item)) return false;
|
|
|
|
-
|
|
|
|
- $uinfo = new member_info($item);
|
|
|
|
- $participant = $this->room_key($uinfo->unionid());
|
|
|
|
- $ret = $this->find($participant);
|
|
|
|
- if($ret == false)
|
|
|
|
|
|
+ if($this->verify_inviter($inviter))
|
|
{
|
|
{
|
|
- $ret = $this->mod_room->invite($this->room_id(),$userid,$participant);
|
|
|
|
- if($ret == false) {
|
|
|
|
- Log::record(__METHOD__ . " invite error",Log::ERR);
|
|
|
|
- return false;
|
|
|
|
|
|
+ $users = $this->add($inviter,$invitees);
|
|
|
|
+ if($users === false) {
|
|
|
|
+ $ret = ['room' => $this->mRoomid,'invitees' => []];
|
|
}
|
|
}
|
|
else {
|
|
else {
|
|
- $this->mRoomkeys[$participant] = ['active' => false,
|
|
|
|
- 'nickname' => $uinfo->nickname(),'avatar' => $uinfo->avatar(),'userid' => intval($userid)];
|
|
|
|
|
|
+ $ret = ['room' => $this->mRoomid,'invitees' => $users];
|
|
}
|
|
}
|
|
|
|
+ return $ret;
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ return false;
|
|
}
|
|
}
|
|
- return $participant;
|
|
|
|
}
|
|
}
|
|
-
|
|
|
|
- public function reject($roomkey)
|
|
|
|
|
|
+ private function verify_inviter($inviter)
|
|
{
|
|
{
|
|
- $ret = $this->find($roomkey);
|
|
|
|
- if($ret != false) {
|
|
|
|
- unset($this->mRoomkeys[$roomkey]);
|
|
|
|
|
|
+ if($this->creator() == $inviter) {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ $ret = $this->find($inviter);
|
|
|
|
+ return ($ret === false) ? false : true;
|
|
}
|
|
}
|
|
- return true;
|
|
|
|
}
|
|
}
|
|
-
|
|
|
|
- protected function room_info($roomkey)
|
|
|
|
|
|
+ private function add($inviter,$invitees)
|
|
{
|
|
{
|
|
- $result = [];
|
|
|
|
- $result['room'] = $this->mRoomid;
|
|
|
|
- $result['users'] = [];
|
|
|
|
- foreach ($this->mRoomkeys as $key => $item)
|
|
|
|
|
|
+ $invitees = array_unique($invitees);
|
|
|
|
+ $items = Model('member')->getMemberList(['member_id' => ['in',$invitees]]);
|
|
|
|
+ if(empty($items)) return false;
|
|
|
|
+
|
|
|
|
+ $users = [];
|
|
|
|
+ foreach ($items as $item) {
|
|
|
|
+ $userid = intval($item['member_id']);
|
|
|
|
+ $users[$userid] = $item;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $result = [];
|
|
|
|
+ foreach ($invitees as $invitee)
|
|
{
|
|
{
|
|
- $result['users'][] = $item;
|
|
|
|
- if($key == $roomkey) {
|
|
|
|
- $result['me'] = $item['userid'];
|
|
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ if(!array_key_exists($invitee,$users)) continue;
|
|
|
|
+ $result[] = $invitee;
|
|
|
|
+
|
|
|
|
+ $ret = $this->find($invitee);
|
|
|
|
+ if($ret !== false) continue;
|
|
|
|
+
|
|
|
|
+ $ret = $this->mod_room->invite($this->room_id(),$invitee,$inviter);
|
|
|
|
+ if($ret == false) {
|
|
|
|
+ Log::record(__METHOD__ . " room invite user fail on db Error",Log::ERR);
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ $user = $users[$invitee];
|
|
|
|
+ $uinfo = new member_info($user);
|
|
|
|
+ $this->mParticipants[$invitee] = ['nickname' => $uinfo->nickname(),'avatar' => $uinfo->avatar(),'userid' => intval($invitee)];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ catch (Exception $ex) {
|
|
|
|
+ Log::record($ex->getMessage(),Log::ERR);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
return $result;
|
|
return $result;
|
|
}
|
|
}
|
|
-
|
|
|
|
- public function joinOp($input)
|
|
|
|
|
|
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
+ public function leave($userid)
|
|
{
|
|
{
|
|
- $this->clear();
|
|
|
|
-
|
|
|
|
- $room_key = $input['room_key'];
|
|
|
|
- if(empty($room_key)) {
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if($this->join($room_key))
|
|
|
|
- {
|
|
|
|
-// $this->add_return([$room_key],'ret_join',$this->room_info($room_key));
|
|
|
|
- $this->add_return([$room_key],'ret_join',[]);
|
|
|
|
- $this->add_broad('join',$this->mRoomkeys[$room_key]);
|
|
|
|
|
|
+ $ret = $this->find($userid);
|
|
|
|
+ if($ret != false) {
|
|
|
|
+ unset($this->mParticipants[$userid]);
|
|
|
|
+ $this->mod_room->leave($this->room_id(),$userid);
|
|
return true;
|
|
return true;
|
|
- }
|
|
|
|
- else {
|
|
|
|
|
|
+ } else {
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
public function leaveOp($input)
|
|
public function leaveOp($input)
|
|
{
|
|
{
|
|
$this->clear();
|
|
$this->clear();
|
|
@@ -132,7 +132,7 @@ abstract class base_room extends base_info
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
public function messageOp($input)
|
|
public function messageOp($input)
|
|
{
|
|
{
|
|
$this->clear();
|
|
$this->clear();
|
|
@@ -151,10 +151,10 @@ abstract class base_room extends base_info
|
|
|
|
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
- protected function validate_type($type,$content)
|
|
|
|
|
|
+ //////////////////////////////////////消息验证、返回、广播//////////////////////////////////////////////////////////////
|
|
|
|
+ protected function validate_type($type)
|
|
{
|
|
{
|
|
$stype = strtolower($type);
|
|
$stype = strtolower($type);
|
|
-
|
|
|
|
if($stype == proto_type::msg_stype_text) {
|
|
if($stype == proto_type::msg_stype_text) {
|
|
return proto_type::msg_type_text;
|
|
return proto_type::msg_type_text;
|
|
}
|
|
}
|
|
@@ -225,69 +225,39 @@ abstract class base_room extends base_info
|
|
|
|
|
|
$this->mCurRespMsgs['broadcast'][] = $msg;
|
|
$this->mCurRespMsgs['broadcast'][] = $msg;
|
|
}
|
|
}
|
|
-
|
|
|
|
- public function join($participant)
|
|
|
|
|
|
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
+ protected function find($userid)
|
|
{
|
|
{
|
|
- $ret = $this->find($participant);
|
|
|
|
- if($ret != false) {
|
|
|
|
- $this->mRoomkeys[$participant]['active'] = true;
|
|
|
|
- return true;
|
|
|
|
- } else {
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ if($userid <= 0) return false;
|
|
|
|
|
|
- public function leave($participant)
|
|
|
|
- {
|
|
|
|
- $ret = $this->find($participant);
|
|
|
|
- if($ret != false) {
|
|
|
|
- $this->mRoomkeys[$participant]['active'] = false;
|
|
|
|
- return true;
|
|
|
|
- } else {
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- protected function find($participant)
|
|
|
|
- {
|
|
|
|
- if(empty($participant)) return false;
|
|
|
|
- if(array_key_exists($participant,$this->mRoomkeys)) {
|
|
|
|
- return $this->mRoomkeys[$participant];
|
|
|
|
|
|
+ if(array_key_exists($userid,$this->mParticipants)) {
|
|
|
|
+ return $this->mParticipants[$userid];
|
|
} else {
|
|
} else {
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- protected function room_key($unionid)
|
|
|
|
- {
|
|
|
|
- return md5("{$this->mRoomType}_{$this->mRoomid}_{$unionid}");
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
public function room_type() {
|
|
public function room_type() {
|
|
return $this->mRoomType;
|
|
return $this->mRoomType;
|
|
}
|
|
}
|
|
|
|
|
|
- public function cur_msgs() {
|
|
|
|
- return $this->mCurRespMsgs;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- protected function times($room_key)
|
|
|
|
|
|
+ protected function times($userid)
|
|
{
|
|
{
|
|
- $userinfo = $this->find($room_key);
|
|
|
|
|
|
+ $userinfo = $this->find($userid);
|
|
if($userinfo == false) {
|
|
if($userinfo == false) {
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
else {
|
|
else {
|
|
- return intval($this->mRoomkeys[$room_key]['times']);
|
|
|
|
|
|
+ return intval($this->mParticipants[$userid]['times']);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- protected function increase_times($room_key)
|
|
|
|
|
|
+ protected function increase_times($userid)
|
|
{
|
|
{
|
|
- $userinfo = $this->find($room_key);
|
|
|
|
|
|
+ $userinfo = $this->find($userid);
|
|
if($userinfo != false) {
|
|
if($userinfo != false) {
|
|
- $times = intval($this->mRoomkeys[$room_key]['times']) + 1;
|
|
|
|
- $this->mRoomkeys[$room_key]['times'] = $times;
|
|
|
|
|
|
+ $times = intval($this->mParticipants[$userid]['times']) + 1;
|
|
|
|
+ $this->mParticipants[$userid]['times'] = $times;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|