예제 #1
0
        /// <summary>
        /// 离开房间
        /// </summary>
        /// <param name="rid">房间id</param>
        public void LeaveRoom(string rid)
        {
            MqttHelper mqttHelper = ChooseMqtt(rid);

            if (mqttHelper == null)
            {
                return;
            }

            //mqttHelper.UnSubscribeMsg(rid);
            //mqttHelper.UnSubscribeMsg(uid);

            LeaveRoom leaveRoom = new LeaveRoom();

            leaveRoom.id       = (int)NetCmdId.LeaveRoom;
            leaveRoom.data     = new LeaveRoom.ResultBean();
            leaveRoom.data.rid = rid;
            leaveRoom.data.uid = uid;

            string json = JsonConvert.SerializeObject(leaveRoom);

            mqttHelper.PublishMsg(MessageType.System, SystemTargetId, json, new MqttSendMsgDelegate((bool res) =>
            {
                mqttHelper.Disconnect();
                mqttHelper = null;
            }));
        }
예제 #2
0
        private void SendCmdMessage(MqttHelper mqttHelper, string rid, NetCmdIdClient cid, byte[] cmd)
        {
            //SendCommend sendCommend = new SendCommend();
            //sendCommend.id = (int)NetCmdId.SendCmmond;
            //sendCommend.data = new SendCommend.ResultBean();
            //sendCommend.data.cmd = cmd;
            //string json = JsonConvert.SerializeObject(sendCommend);
            byte[] bId = BitConverter.GetBytes((int)cid);

            byte[] sendBuf = new byte[4 + cmd.Length];
            Array.Copy(bId, 0, sendBuf, 0, bId.Length);
            Array.Copy(cmd, 0, sendBuf, 4, cmd.Length);
            bId = null;
            cmd = null;

            mqttHelper.PublishMsg(MessageType.Group, rid, sendBuf, new MqttSendMsgDelegate((bool res) =>
            {
            }));
        }
예제 #3
0
        public void GetRoomCacheFromServer(SyncType type)
        {
            string     rid;
            MqttHelper mqttHelper = ChooseMqtt(type, out rid);

            if (mqttHelper == null)
            {
                return;
            }


            GetRoomCache getRoomCache = new GetRoomCache();

            getRoomCache.id       = (int)NetCmdId.GetRoomCache;
            getRoomCache.data     = new GetRoomCache.ResultBean();
            getRoomCache.data.rid = rid;
            getRoomCache.data.uid = this.uid;
            string json = JsonConvert.SerializeObject(getRoomCache);

            mqttHelper.PublishMsg(MessageType.System, SystemTargetId, json, new MqttSendMsgDelegate((bool res) =>
            {
            }));
        }
예제 #4
0
        public void SaveRoomCacheToServer(SyncType type, string key, string value)
        {
            string     rid;
            MqttHelper mqttHelper = ChooseMqtt(type, out rid);

            if (mqttHelper == null)
            {
                return;
            }

            SaveRoomCache saveRoomCache = new SaveRoomCache();

            saveRoomCache.id         = (int)NetCmdId.SaveRoomCache;
            saveRoomCache.data       = new SaveRoomCache.ResultBean();
            saveRoomCache.data.rid   = rid;
            saveRoomCache.data.key   = key;
            saveRoomCache.data.value = value;

            string json = JsonConvert.SerializeObject(saveRoomCache);

            mqttHelper.PublishMsg(MessageType.System, SystemTargetId, json, new MqttSendMsgDelegate((bool res) =>
            {
            }));
        }
예제 #5
0
        public void SaveSVRoomCacheToServer(string key, string value)
        {
            string     rid        = spectatorViewRid;
            MqttHelper mqttHelper = spectatorViewMqtt;

            if (spectatorViewNetState != NetState.Connect)
            {
                return;
            }

            SaveRoomCache saveRoomCache = new SaveRoomCache();

            saveRoomCache.id         = (int)NetCmdId.SaveRoomCache;
            saveRoomCache.data       = new SaveRoomCache.ResultBean();
            saveRoomCache.data.rid   = rid;
            saveRoomCache.data.key   = key;
            saveRoomCache.data.value = value;

            string json = JsonConvert.SerializeObject(saveRoomCache);

            mqttHelper.PublishMsg(MessageType.System, SystemTargetId, json, new MqttSendMsgDelegate((bool res) =>
            {
            }));
        }