stanley-king %!s(int64=7) %!d(string=hai) anos
pai
achega
eddd8dd47e
Modificáronse 5 ficheiros con 90 adicións e 4 borrados
  1. 10 0
      helper/room/client.php
  2. 22 0
      helper/room/croom.php
  3. 56 3
      helper/room/processor.php
  4. 1 0
      helper/room/proto_type.php
  5. 1 1
      test/TestRoom.php

+ 10 - 0
helper/room/client.php

@@ -72,6 +72,16 @@ class client extends tcp_client
 
     public function invite($roomid,$user)
     {
+        $param = ['room_id' => $roomid,'op' => 'invite','user' => $user];
+        $result = $this->request($param);
+        if(empty($result)) return false;
 
+        $code = intval($result['code']);
+        if($code != 200) {
+            return false;
+        }
+        else {
+            return $result['data'];
+        }
     }
 }

+ 22 - 0
helper/room/croom.php

@@ -17,13 +17,26 @@ abstract class croom
     protected $mParticipants;
     protected $mRoomType;
     protected $mod_room;
+    protected $mAccReq;
 
     protected function __construct($rommid,$participants = [])
     {
+        $this->mAccReq = false;
         $this->mRoomid = $rommid;
         $this->mParticipants = $participants;
         $this->mod_room = Model('room');
     }
+    public function inviteOp($input)
+    {
+        $this->mAccReq = false;
+        $userid = intval($input['user']);
+        if($userid > 0) {
+            $room_key = $this->invite($userid);
+            return ['room_key' => $room_key,'room_id' => $this->mRoomid];
+        } else {
+            return false;
+        }
+    }
 
     public function invite($userid)
     {
@@ -58,6 +71,15 @@ abstract class croom
         return true;
     }
 
+    public function joinOp($participant)
+    {
+        $this->mAccReq = true;
+        return $this->join($participant);
+    }
+    public function acc_req() {
+        return $this->mAccReq;
+    }
+
     public function join($participant)
     {
         $ret = $this->find($participant);

+ 56 - 3
helper/room/processor.php

@@ -36,8 +36,10 @@ class processor implements IProcessor
         if(!empty($act) && $act == proto_type::act_factory) {
             return $this->onFactory($input);
         }
-        else
-        {
+        elseif(!empty($act) && $act == proto_type::act_access) {
+            return $this->onAccess($input);
+        }
+        else {
             return $this->onRoom($input);
         }
 
@@ -59,9 +61,60 @@ class processor implements IProcessor
 
         return $this->error(errcode::ErrRoomCreate);
     }
+
+    private function onAccess($input)
+    {
+        $result['act'] = 'access';
+
+        $op = $input['op'];
+        if($op == 'list')
+        {
+            $result['op'] = 'list';
+            $result['rooms'] = $this->rooms();
+        }
+        else {
+
+        }
+
+        return $this->success($result);
+    }
+
+    private function rooms()
+    {
+        $result = [];
+        foreach ($this->mRooms as $roomid => $room) {
+            $result[] = $roomid;
+        }
+        return $result;
+    }
+
     private function onRoom($input)
     {
-        
+        $roomid = intval($input['room_id']);
+        $room = $this->room($roomid);
+        if($room != false)
+        {
+            $function = $input['op'] . 'Op';
+            if (method_exists($room,$function))
+            {
+                $ret = $room->$function($input);
+                if($ret === false) {
+                    return $this->error(errcode::ErrRoom);
+                } else {
+                    return $this->success($ret);
+                }
+            }
+        }
+    }
+
+    private function room($roomid)
+    {
+        if($roomid <= 0) return false;
+        if(array_key_exists($roomid,$this->mRooms)) {
+            return $this->mRooms[$roomid];
+        } else {
+            return false;
+        }
     }
 
     private function success($datas) {

+ 1 - 0
helper/room/proto_type.php

@@ -19,4 +19,5 @@ class proto_type
     const act_chat    = 'chat';
     const room_chat   = 2;
 
+    const act_access = 'access';
 }

+ 1 - 1
test/TestRoom.php

@@ -27,6 +27,6 @@ class TestRoom extends PHPUnit_Framework_TestCase
         $user = 36490;
         $ret = room\client::instance()->create_chat($user);
         $room_id = $ret['room_id'];
-        room\client::instance()->invite($room_id,36429);
+        $ret = room\client::instance()->invite($room_id,36429);
     }
 }