Browse Source

add member_talk

stanley-king 6 năm trước cách đây
mục cha
commit
1f073b5937

+ 10 - 0
client_req.puml

@@ -0,0 +1,10 @@
+@startuml
+UI -> TalkEngine: Authentication Request
+TalkEngine -> Accessor
+Accessor -> TalkEngine : result,message
+
+TalkEngine -> Observer : Protocol,message->database
+
+
+
+@enduml

+ 6 - 6
helper/room/bargain_room.php

@@ -119,14 +119,14 @@ class bargain_room extends base_room
 
             if($success)
             {
-                $this->add_return([$room_key],'ret_bargain',['from' => $userinfo,'value' => $value,'discount' => $discount,'user_num' => $user_num]);
-                $this->add_broad('bargain',['from' => $userinfo,'value' => $value,'discount' => $discount,'user_num' => $user_num]);
+                $this->relay_users([$room_key],'ret_bargain',['from' => $userinfo,'value' => $value,'discount' => $discount,'user_num' => $user_num]);
+                $this->relay_broadcast('bargain',['from' => $userinfo,'value' => $value,'discount' => $discount,'user_num' => $user_num]);
                 if($state == bargain_manager::closing) {
-                    $this->add_broad('bargain_close',['from' => $userinfo]);
+                    $this->relay_broadcast('bargain_close',['from' => $userinfo]);
                 }
             }
             else {
-                $this->add_return([$room_key],'ret_bargain',['from' => $userinfo,'value' => $value,'discount' => $discount,'user_num' => $user_num]);
+                $this->relay_users([$room_key],'ret_bargain',['from' => $userinfo,'value' => $value,'discount' => $discount,'user_num' => $user_num]);
             }
             return true;
         }
@@ -152,8 +152,8 @@ class bargain_room extends base_room
 
         if($result)
         {
-            $this->add_return([$room_key],'ret_close',['from' => $userinfo]);
-            $this->add_broad('bargain_close',['from' => $userinfo]);
+            $this->relay_users([$room_key],'ret_close',['from' => $userinfo]);
+            $this->relay_broadcast('bargain_close',['from' => $userinfo]);
             return true;
         }
         else

+ 19 - 17
helper/room/base_room.php

@@ -18,15 +18,15 @@ abstract class base_room extends base_info
     protected $mParticipants;
     protected $mRoomType;
     protected $mod_room;
-    protected $mCurRespMsgs;
+    protected $mRelayMsgs;
 
     public function __construct($cinfos, $participants = [])
     {
         parent::__construct($cinfos);
 
         $this->mRoomid = $this->room_id();
-        $this->mCurRespMsgs['return'] = [];
-        $this->mCurRespMsgs['broadcast'] = [];
+        $this->mRelayMsgs['users'] = [];
+        $this->mRelayMsgs['broadcast'] = [];
 
         $this->mParticipants = $participants;
         $this->mod_room = Model('room');
@@ -128,8 +128,8 @@ abstract class base_room extends base_info
         if($type == false || $content == false) return false;
 
         $this->record_message($userinfo['userid'],$type,$content);
-        $this->add_broad('message',['from' => $userinfo,'type' => $input['type'],'content' => $content]);
-        $this->add_return([$user],'message',['from' => $userinfo,'type' => $input['type'],'content' => $content]);
+        $this->relay_broadcast('message',['from' => $userinfo,'type' => $input['type'],'content' => $content]);
+        $this->relay_users([$user],'message',['from' => $userinfo,'type' => $input['type'],'content' => $content]);
 
         return true;
     }
@@ -161,27 +161,28 @@ abstract class base_room extends base_info
         $mod_room->addRoomMsg(['room_id' => $this->mRoomid,'member_id' => $userid, 'type' => $type,'msg' => $content,'add_time' => time()]);
     }
 
-    public function return_msgs()
+    public function relay_users_msgs()
     {
-        return $this->mCurRespMsgs['return'];
+        return $this->mRelayMsgs['users'];
     }
-    public function broadcast_msgs()
+    public function relay_broadcast_msgs()
     {
-        return $this->mCurRespMsgs['broadcast'];
+        return $this->mRelayMsgs['broadcast'];
     }
 
     protected function clear()
     {
-        $this->mCurRespMsgs['return'] = [];
-        $this->mCurRespMsgs['broadcast'] = [];
+        $this->mRelayMsgs['users'] = [];
+        $this->mRelayMsgs['broadcast'] = [];
     }
 
-    protected function add_return(array $users, $op, $content)
+    protected function relay_users(array $users, $op, $content)
     {
         $msg = [];
 
         $msg['act']  = "room";
         $msg['op']   = "relay";
+        $msg['msgtype']   = "message";
         $msg['relay_type'] = "roomusers";
         $msg['receivers'] = $users;
         $msg['room'] = $this->mRoomid;
@@ -192,28 +193,29 @@ abstract class base_room extends base_info
         $msg['body']['room'] = $this->mRoomid;
         $msg['body']['content'] = $content;
 
-        $this->mCurRespMsgs['return'][] = $msg;
+        $this->mRelayMsgs['users'][] = $msg;
     }
 
-    protected function add_broad($op,$content)
+    protected function relay_broadcast($op, $content)
     {
         $msg = [];
 
         $msg['act']  = "room";
         $msg['op']   = "relay";
+        $msg['msgtype']   = "message";
         $msg['relay_type'] = "room";
-        $msg['receivers'] = [];
         $msg['room'] = $this->mRoomid;
+        $msg['receivers'] = [];
         $msg['receiver_type'] = $this->room_type();
 
-
         $msg['body']['act']  = 'room';
         $msg['body']['op']   = $op;
         $msg['body']['room'] = $this->mRoomid;
         $msg['body']['content'] = $content;
 
-        $this->mCurRespMsgs['broadcast'][] = $msg;
+        $this->mRelayMsgs['broadcast'][] = $msg;
     }
+
     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     protected function find($userid)
     {

+ 1 - 0
helper/room/chatwo.php

@@ -49,6 +49,7 @@ class chatwo
     {
         $msg = [];
 
+        $msg['msgtype'] = proto_type::msgtype_message;
         $msg['act']  = "room";
         $msg['op']   = "relay";
         $msg['relay_type'] = "users";

+ 1 - 1
helper/room/group_room.php

@@ -27,7 +27,7 @@ class shake_room extends base_room
         $type = $input['type'];
         $content = $input['content'];
 
-        $this->add_broad('message',['from' => $userinfo,'type' => $type,'content' => $content]);
+        $this->relay_broadcast('message',['from' => $userinfo,'type' => $type,'content' => $content]);
         return true;
     }
 }

+ 3 - 0
helper/room/proto_type.php

@@ -18,6 +18,9 @@ class proto_type
     const act_chatwo  = 'chatwo';
     const act_push    = 'push';
 
+    const msgtype_reply   = "reply";
+    const msgtype_message = "message";
+
     //房间类型
     const sroom_bargain  = 'bargain_goods';
     const room_bargain = 1;

+ 12 - 7
helper/room/room_processor.php

@@ -48,6 +48,7 @@ class room_processor implements IProcessor
         }
         elseif($act == proto_type::act_access) {
             $ret = $this->onAccess($bufid,$input);
+            room_server::instance()->write($bufid,$ret);
             return $ret;
         }
         elseif($act == proto_type::act_room) {
@@ -174,8 +175,8 @@ class room_processor implements IProcessor
         $op = $input['op'];
         if($op == 'list') {
             $this->add_acc($bufid);
-            $this->write_accmsg($bufid,"list",['rooms' => $this->rooms()]);
-            return true;
+            $reply = ['act' => 'access','op' => $op,'rooms' => $this->rooms()];
+            return $this->success($reply);
         }
         else {
             return $this->error(errcode::ErrRoomAccessOp);
@@ -266,16 +267,16 @@ class room_processor implements IProcessor
 
     private function write_roomsg($bufid,$room)
     {
-        $retmsgs = $room->return_msgs();
+        $retmsgs = $room->relay_users_msgs();
         foreach ($retmsgs as $msg) {
-            $body = $this->success($msg);
+            $body = json_encode($msg);
             room_server::instance()->write($bufid,$body);
         }
 
-        $broad_msgs = $room->broadcast_msgs();
+        $broad_msgs = $room->relay_broadcast_msgs();
         foreach ($broad_msgs as $msg)
         {
-            $body = $this->success($msg);
+            $body = json_encode($msg);
             foreach ($this->mAccConnes as $conn) {
                 room_server::instance()->write($conn,$body);
             }
@@ -313,12 +314,15 @@ class room_processor implements IProcessor
         }
         return true;
     }
+
+    ////////////////////////////////返回包///////////////////////////////////////////////////////////////////////////////
     private function success($val)
     {
         $code = errcode::Success;
         $data['code'] = $code;
         $data['message'] = errcode::msg($code);
         $data['data'] = $val;
+        $data['msgtype'] = "reply";
 
         return json_encode($data);
     }
@@ -329,10 +333,11 @@ class room_processor implements IProcessor
             $message = errcode::msg($code);
         }
 
-        $data = array();
         $data['code'] = $code;
         $data['message'] = $message;
         $data['data'] = null;
+        $data['msgtype'] = "reply";
+
         return json_encode($data);
     }
 }

+ 13 - 1
mobile/control/member_talk.php

@@ -6,15 +6,27 @@
  * Time: 上午11:29
  */
 
+require_once(BASE_ROOT_PATH . '/helper/search/tcp_client.php');
+require_once(BASE_ROOT_PATH . '/helper/room/factory_client.php');
+require_once(BASE_ROOT_PATH . '/helper/room/proto_type.php');
+require_once(BASE_ROOT_PATH . '/helper/room/author.php');
+
 class member_talkControl extends mbMemberControl
 {
+    private $mAccaddr;
     public function __construct()
     {
         parent::__construct();
+
+        global $config;
+        $this->mAccaddr = $config['access_addr'];
     }
 
     public function authonOp()
     {
-        
+        $result = [];
+        $result['addr'] = $this->mAccaddr;
+        $result['token'] = room\author::sign_native(session_helper::memberid());
+        return self::outsuccess($result);
     }
 }

+ 4 - 1
mobile/templates/default/game/test_shake.php

@@ -33,7 +33,8 @@
             act: 'access',
             op: 'login',
             seq : seq++,
-            token: token
+            token: token,
+            msgtype: 'message',
         };
         client.send(JSON.stringify(msg));
     };
@@ -62,6 +63,7 @@
         var msg = {
             act: 'room',
             op:  'message',
+            msgtype: 'message',
             seq : seq++,
             room:room,
             user:user,
@@ -87,6 +89,7 @@
         var msg = {
             act: 'chatwo',
             op:  'message',
+            msgtype: 'message',
             seq : seq++,
             from:user,
             to: to_user,