コード例 #1
0
ファイル: AddRoom.cs プロジェクト: zhaoy615/Guizhoule
        public void ExecuteCommand(GameSession session, ProtobufRequestInfo requestInfo)
        {
            if (!Gongyong.userlist.Any(w => w.session.SessionID.Equals(session.SessionID)))
            {
                session.Logger.Debug("AddRoom : 非法连接");
                session.Close();
                return;
            }
            ///定义返回状态码
            string          staut    = "10000";
            var             nowsend  = ReturnAddRoom.CreateBuilder();
            List <Userinfo> listuser = new List <Userinfo>();
            ///当前返回信息
            var getdata = SendAddRoom.ParseFrom(requestInfo.Body);
            ///根据上传信息查找房间
            Room rm      = Gongyong.roomlist.Find(u => u.RoomID == getdata.RoomID);
            var  roommsg = ReturnRoomMsg.CreateBuilder();
            //储存IP
            List <UserInfo> ListUserIP = new List <UserInfo>();

            if (rm != null)
            {
                List <mjuser> mulist = Gongyong.mulist.FindAll(u => u.RoomID == getdata.RoomID);
                mjuser        mjuser = Gongyong.mulist.Find(u => u.RoomID == getdata.RoomID && u.Openid == getdata.Openid);

                if (mulist.Count == rm.room_peo)
                {
                    staut = "10002";
                }
                else
                {
                    List <int> shuzhu = new List <int>()
                    {
                        1, 2, 3, 4
                    };
                    ///移除以坐的方位,并添加以有玩家信息
                    var senddata = ReturnUserInfo.CreateBuilder();

                    //for(int i=0;i< mulist.Count();i++)
                    foreach (mjuser item in mulist)
                    {
                        UserInfo gamer = Gongyong.userlist.Find(u => u.openid == item.Openid);
                        Userinfo users = Userinfo.CreateBuilder().SetHeadimg(gamer.headimg).SetNickname(gamer.nickname).SetOpenid(gamer.openid).SetSex(int.Parse(gamer.sex)).SetUserFW(item.ZS_Fw).SetUserBean(0).SetUserGold(0).SetUserID(gamer.UserID).SetUserIP(gamer.UserIP).Build();
                        listuser.Add(users);
                        shuzhu.Remove(item.ZS_Fw);
                        senddata.AddUserinfo(users);
                        nowsend.AddUserinfo(users);
                    }
                    if (mjuser != null)
                    {
                        return;
                    }
                    else
                    {
                        ///添加新加入玩家信息
                        mjuser mj = new mjuser()
                        {
                            Openid             = getdata.Openid,
                            ZS_Fw              = shuzhu[0],
                            RoomID             = getdata.RoomID,
                            ConfirmationStarts = true,
                            SendData           = new List <ArraySegment <byte> >(),
                            IsGuoHu            = false
                        };
                        Gongyong.mulist.Add(mj);
                    }


                    ///将当前的用户信息添加到下发文件包
                    UserInfo gameuser = Gongyong.userlist.Find(u => u.openid == getdata.Openid);
                    gameuser.Lat = getdata.Latitude;
                    Userinfo newuser = Userinfo.CreateBuilder().SetHeadimg(gameuser.headimg).SetNickname(gameuser.nickname).SetOpenid(gameuser.openid).SetSex(int.Parse(gameuser.sex)).SetUserFW(shuzhu[0]).SetUserGold(0).SetUserBean(0).SetUserID(gameuser.UserID).SetUserIP(gameuser.UserIP).Build();
                    listuser.Add(newuser);
                    senddata.AddUserinfo(newuser);
                    nowsend.AddUserinfo(newuser);
                    List <mjuser> mu       = Gongyong.mulist.FindAll(u => u.RoomID == getdata.RoomID);
                    var           dis      = ReturnDis.CreateBuilder();
                    var           closeGPS = ReturnCloseGPS.CreateBuilder();

                    ///向已有玩家下发信息
                    foreach (mjuser items in mu)
                    {
                        UserInfo gamersend = Gongyong.userlist.Find(u => u.openid == items.Openid);
                        if (gamersend.Lat.Equals("0,0") || string.IsNullOrEmpty(gamersend.Lat))
                        {
                            //Console.WriteLine("AddRoom : " + gamersend.session.Config.Ip + " lat 为 0");
                            //Console.WriteLine(" : " + mjuser.)
                            closeGPS.AddFW(items.ZS_Fw);
                            //gamersend.session.Send(new ArraySegment<byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 7091, dataGPS.Length, requestInfo.MessageNum, dataGPS)));
                        }
                        else if (gameuser.Lat.Equals("0,0") || string.IsNullOrEmpty(gameuser.Lat))
                        {
                            if (items.Openid.Equals(gameuser.openid))
                            {
                                //Console.WriteLine("AddRoom : " + gamersend.session.Config.Ip + " lat 为 0");
                                if (!closeGPS.FWList.Any(w => w == items.ZS_Fw))
                                {
                                    closeGPS.AddFW(items.ZS_Fw);
                                }
                            }
                        }
                        else
                        {
                            var userdis = ReturnDis.CreateBuilder();


                            //double jl = Erth.GetDistance(gamersend.Lat, gameuser.Lat);
                            double jl = 1;  //  测试修改
                            if (shuzhu[0] != items.ZS_Fw)
                            {
                                //if (jl < GameInformationBase.DISTANCE)
                                if (jl < 0.001f) //任光粤测试修改
                                {
                                    Console.WriteLine("距离为 : " + jl + gamersend.nickname + ":" + gamersend.Lat + " , " + gameuser.nickname + " : " + gameuser.Lat);
                                    rm.Is_Jin = true;

                                    rm.Juser1 = shuzhu[0];
                                    rm.Juser2 = items.ZS_Fw;
                                }
                            }
                            dis.SetDis(jl.ToString());
                            dis.SetFW(items.ZS_Fw);
                            userdis.SetFW(shuzhu[0]);
                            userdis.SetDis(jl.ToString());
                            ListUserIP.Add(gamersend);


                            byte[]    dataMJ     = userdis.Build().ToByteArray();
                            byte[]    datauser   = dis.Build().ToByteArray();
                            AppServer userserver = new AppServer();
                            gamersend.session.Send(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 7091, dataMJ.Length, requestInfo.MessageNum, dataMJ)));
                            gameuser.session.Send(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 7091, datauser.Length, requestInfo.MessageNum, datauser)));
                        }
                        System.Threading.Thread.Sleep(100);
                        byte[] data = senddata.Build().ToByteArray();
                        gamersend.session.Send(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 2005, data.Length, requestInfo.MessageNum, data)));
                        ///如果人数满足,下发游戏开始信息
                        if (mu.Count == rm.room_peo)
                        {
                            //牌局回放保存用户信息
                            rm.gameOperationProcess.SetUserInfo(senddata);
                            foreach (var item in Gongyong.mulist.FindAll(u => u.RoomID == rm.RoomID))
                            {
                                if (!item.ConfirmationStarts)
                                {
                                    rm.startgame = 2;
                                }
                            }
                            rm.startgame = rm.startgame == 2 ? 0 : 1;

                            //ReturnStart startgame = ReturnStart.CreateBuilder().SetStart(1).Build();
                            //byte[] bstart = startgame.ToByteArray();
                            //gamersend.session.TrySend(new ArraySegment<byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 2008, bstart.Length, requestInfo.MessageNum, bstart)));
                        }
                    }

                    if (closeGPS.FWCount > 0)
                    {
                        foreach (mjuser items in mu)
                        {
                            var      dataGPS   = closeGPS.Build().ToByteArray();
                            UserInfo gamersend = Gongyong.userlist.Find(u => u.openid == items.Openid);
                            gamersend.session.Send(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 7097, dataGPS.Length, requestInfo.MessageNum, dataGPS)));
                        }
                    }
                }
            }
            else
            {
                staut = "10001";
            }
            ///判断房间不为空 发生房间信息
            if (rm != null)
            {
                roommsg.SetCount(rm.count)
                .SetIsBenji(rm.is_benji == true ? 1 : 0)
                .SetIsShangxiaji(rm.is_shangxiaji == true ? 1 : 0)
                .SetIsWgj(rm.is_wgj == true ? 1 : 0)
                .SetIsXinqiji(rm.is_xinqiji == true ? 1 : 0)
                .SetIsYikousan(rm.is_yikousan == true ? 1 : 0)
                .SetRoomPeo(rm.room_peo)
                .SetIsLianzhuang(rm.is_lianz == true ? 1 : 0)
                .SetIsYuanque(rm.IsYuanQue ? 1 : 0)
                .SetQuickCard(rm.QuickCard?1:0);
                byte[] roommsgb = roommsg.Build().ToByteArray();


                session.TrySend(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 7003, roommsgb.Length, requestInfo.MessageNum, roommsgb)));
            }



            System.Threading.Thread.Sleep(100);
            nowsend.SetState(int.Parse(staut));

            byte[] datanew = nowsend.Build().ToByteArray();
            session.TrySend(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 2004, datanew.Length, requestInfo.MessageNum, datanew)));

            //如果有玩家距离过近,提醒牌桌所有用户,并接受确认
            if (rm.Is_Jin)
            {
                byte[] jusers = ReturnIsJ.CreateBuilder().SetFWO(rm.Juser1).SetFWW(rm.Juser2).Build().ToByteArray();
                rm.startgame = 0;

                SendRoomAllUser(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 7092, jusers.Length, requestInfo.MessageNum, jusers)), getdata.RoomID);
            }
            List <UserInfo> waringList = new List <UserInfo>();

            //如果有玩家IP一样
            foreach (var item in ListUserIP)
            {
                if (ListUserIP.Where(w => w.UserIP.Equals(item.UserIP)).Count() > 1)
                {
                    waringList.Add(item);
                }
            }
            if (waringList.Count > 1)
            {
                var ipSame = ReturnIPSame.CreateBuilder();
                foreach (var item in ListUserIP)
                {
                    var userInfo = Gongyong.mulist.First(w => w.Openid.Equals(item.openid));
                    if (userInfo != null)
                    {
                        ipSame.AddFW(userInfo.ZS_Fw);
                    }
                }
                var jusers = ipSame.Build().ToByteArray();
                rm.startgame = 0;
                SendRoomAllUser(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 7093, jusers.Length, requestInfo.MessageNum, jusers)), getdata.RoomID);
            }
            rm.gameOperationProcess.SetMessage(roommsg);//牌局回放保存房间信息
            session.Logger.Debug("用户请求加入房间:" + getdata.RoomID + ",openid:" + getdata.Openid + "----------" + DateTime.Now);
            if (rm.startgame == 1)
            {
                //将牌桌信息保存
                RedisUtility.Set <RedisGameRoomInfo>(RedisUtility.GetKey(GameInformationBase.COMMUNITYROOMINFO, rm.RoomID.ToString(), ""),
                                                     new RedisGameRoomInfo {
                    room = rm, ServerName = GameInformationBase.serverName
                });
                foreach (var item in Gongyong.mulist.FindAll(u => u.RoomID == rm.RoomID))
                {
                    if (!item.ConfirmationStarts)
                    {
                        return;
                    }
                }
                session.Logger.Debug("发牌");
                ///查找当前玩家集合
                List <mjuser> mjList = Gongyong.mulist.FindAll(u => u.RoomID == rm.RoomID);

                CardsLogic logic  = new CardsLogic();
                int        number = 0;//发牌次数,从0开始计数

                //根据
                ///获取房主信息
                ///


                string homeownerOpenid = "";
                foreach (var item in mjList)
                {
                    if (item.IsHomeowner)
                    {
                        //如果是房主,记录该房主的openid
                        homeownerOpenid = item.Openid;
                    }
                }


                var roominfodal  = new RoomInfoDAL();
                var createuserid = roominfodal.GetCreateUserIdByRoomId(rm.RoomID);
                //var groupid = roominfodal.GetGroupInfoByGroupID(createuserid);
                var groupid = rm.GroupID;

                //不是圈子用户,直接进行扣费
                if (groupid == 0)
                {
                    RoomCardUtility.ReduceRoomCard(createuserid, (rm.count / 4) * 1);
                }
                else
                {
                    GroupInfoDAL groupInfoDAL      = new GroupInfoDAL();
                    var          creategroupuderid = groupInfoDAL.GetUserIDByGuoupID(groupid);
                    var          reducecount       = (rm.count / 8) * 1;
                    RoomCardUtility.ReduceRoomCard(creategroupuderid, reducecount);

                    ////向日志里面添加朋友圈耗卡信息
                    groupInfoDAL.AddCreateRoomRecord(creategroupuderid, groupid, rm.RoomID, reducecount);
                }

                var dcount = rm.Dcount;
                foreach (var item in mjList)
                {
                    ReturnStartGame.Builder    sendmj        = ReturnStartGame.CreateBuilder();
                    ReturnGang.Builder         ReturnGangMSG = ReturnGang.CreateBuilder();
                    List <model.ServerMaJiang> Ruturnjsmj    = new List <model.ServerMaJiang>();
                    item.paixinfs = 5;
                    Gongyong.mulist.Remove(item);
                    if (rm.IsYuanQue)
                    {
                        item.QYM = 3;
                    }
                    logic.GetMyCards(requestInfo, sendmj, ReturnGangMSG, Ruturnjsmj, session, rm.RoomID, item, item.Openid, ref dcount);
                }
            }
        }
コード例 #2
0
ファイル: CreateRoom.cs プロジェクト: zhaoy615/Guizhoule
        // public string Name => "CreateRoom";

        public void ExecuteCommand(GameSession session, ProtobufRequestInfo requestInfo)
        {
            if (!Gongyong.userlist.Any(w => w.session.SessionID.Equals(session.SessionID)))
            {
                session.Logger.Debug("CreateRoom : 非法连接");
                session.Close();
                return;
            }
            session.Logger.Debug("创建sssionID--------" + session.SessionID);

            var info = SendCreateRoom.ParseFrom(requestInfo.Body);
            ///当前用户信息
            UserInfo user = Gongyong.userlist.Find(u => u.openid.Equals(info.Openid));

            if (user == null)
            {
                session.Logger.Debug("CREATEROOM user == nulll");
                session.Close();
                return;
            }
            if (Gongyong.mulist.Any(w => w.Openid.Equals(info.Openid)))
            {
                var muInfo = Gongyong.mulist.Find(w => w.Openid.Equals(info.Openid));
                if (Gongyong.roomlist.Any(w => w.RoomID == muInfo.RoomID))
                {
                    // ReturnServerIP.CreateBuilder().SetIp
                }
                else
                {
                    Gongyong.mulist.Remove(muInfo);
                }
            }
            ///更具房间信息创建房间
            int roomid = GetRoomID();

            if (info.Count != 8 && info.Count != 16 && info.Count != 32)
            {
                return;
            }
            Room room = new Room()
            {
                count = info.Count,
                //count = 1,
                is_benji      = info.IsBenji == 1 ? true : false,
                is_wgj        = info.IsWgj == 1 ? true : false,
                is_xinqiji    = info.IsXinqiji == 1 ? true : false,
                is_yikousan   = info.IsYikousan == 1 ? true : false,
                is_shangxiaji = info.IsShangxiaji == 1 ? true : false,
                room_peo      = info.RoomPeo,
                Dcount        = 1,
                RoomID        = roomid,
                GroupID       = info.GroupID,
                startgame     = 0,
                is_lianz      = info.IsYikousan == 3 ? true : false,
                CreateDate    = DateTime.Now,
                IsYuanQue     = info.HasRoomPeo ? (info.RoomPeo == 4 ? false : (info.HasIsYuanque ? info.IsYuanque == 1 : false)) : false, //如果是4人桌 不能是原缺。
                QuickCard     = info.HasQuickCard ? (info.QuickCard == 1) : false                                                          //十秒快速出牌
                                                                                                                                           // RoomPai = new CreateMj().CreateMJ()
            };

            //Console.WriteLine("roomid : " + roomid);
            try
            {
                new RoomInfoDAL().Add(CardsLogic.SetRoomInfoTb(room, user.UserID), info.GroupID);
            }
            catch (Exception ex)
            {
                session.Logger.Error(ex);
            }
            Gongyong.roomlist.Add(room);

            user.Lat = info.Latitude;

            //将用户游戏信息更新
            RedisUtility.Set <RedisGameModel>(RedisUtility.GetKey(GameInformationBase.COMMUNITYUSERGAME, user.openid, user.unionid),
                                              new RedisGameModel {
                Openid = user.openid, RoomID = roomid, ServerName = GameInformationBase.serverName, Unionid = user.unionid
            });
            //将牌桌信息保存
            RedisUtility.Set <RedisGameRoomInfo>(RedisUtility.GetKey(GameInformationBase.COMMUNITYROOMINFO, roomid.ToString(), ""),
                                                 new RedisGameRoomInfo {
                room = room, ServerName = GameInformationBase.serverName
            });


            ///麻将玩家操作类
            mjuser mu = new mjuser()
            {
                ZS_Fw              = 1,
                Openid             = user.openid,
                RoomID             = roomid,
                SendData           = new List <ArraySegment <byte> >(),
                ConfirmationStarts = true,
                IsGuoHu            = false
            };

            Gongyong.mulist.Add(mu);


            if (mu.ByteData == requestInfo.Key)
            {
                return;
            }
            else
            {
                mu.ByteData = requestInfo.Key;
            }
            mu.IsHomeowner = true;
            ///当前返回用户信息
            Userinfo uinfo = Userinfo.CreateBuilder().SetHeadimg(user.headimg).SetNickname(user.nickname).SetOpenid(user.openid).SetSex(int.Parse(user.sex)).SetUserFW(1).SetUserBean(0).SetUserGold(0).SetUserID(user.UserID).SetUserIP(user.UserIP).Build();
            ///返回数值
            ReturnCreateRoom cr = ReturnCreateRoom.CreateBuilder().SetRoomID(roomid).SetUserinfo(uinfo).Build();

            byte[] data = cr.ToByteArray();
            session.TrySend(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 2002, data.Length, requestInfo.MessageNum, data)));

            var roommsg = ReturnRoomMsg.CreateBuilder();

            roommsg.SetCount(room.count).SetIsBenji(room.is_benji ? 1 : 0)
            .SetIsShangxiaji(room.is_shangxiaji ? 1 : 0)
            .SetIsWgj(room.is_wgj ? 1 : 0)
            .SetIsXinqiji(room.is_xinqiji ? 1 : 0)
            .SetIsYikousan(room.is_yikousan ? 1 : 0).SetRoomPeo(room.room_peo)
            .SetIsLianzhuang(room.is_lianz ? 1 : 0)
            .SetIsYuanque(room.IsYuanQue ? 1 : 0)
            .SetQuickCard(room.QuickCard ? 1 : 0)
            ;
            byte[] roommsgb = roommsg.Build().ToByteArray();
            session.TrySend(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 7003, roommsgb.Length, requestInfo.MessageNum, roommsgb)));
            session.Logger.Debug("参数data" + cr + "----------" + DateTime.Now);
            session.Logger.Debug("当前用户创建房间----" + roomid + "------" + DateTime.Now);
        }
コード例 #3
0
        /// <summary>
        /// 解散牌桌
        /// </summary>
        /// <param name="roomId"></param>
        /// <param name="MessageNum"></param>
        public void DisbandTable(object state)
        {
            var countdownInfo = state as CountdownInfo;

            RoomClear r = Gongyong.roomclear.Find(u => u.RoomID == countdownInfo.roomID);

            if (r == null)
            {
                return;
            }
            ThreadUtility.RemoveManagedThreadByRoomID(countdownInfo.roomID);//取消托管
            List <mjuser> listmj      = Gongyong.mulist.FindAll(u => u.RoomID == countdownInfo.roomID);
            var           senddjs     = ReturnDJS.CreateBuilder();
            CardUser      card        = Gongyong.FKUser.Find(u => u.roomid == countdownInfo.roomID);
            string        userWinLose = string.Empty;

            foreach (var item in listmj)
            {
                UserInfo gamer = Gongyong.userlist.Find(u => u.openid == item.Openid);
                if (gamer == null)
                {
                    continue;
                }
                var users = Userinfo.CreateBuilder().SetHeadimg(gamer.headimg).SetNickname(gamer.nickname).SetOpenid(gamer.openid).SetSex(int.Parse(gamer.sex)).SetUserFW(item.ZS_Fw).SetUserBean(0).SetUserGold(0).SetUserID(gamer.UserID).Build();
                var jsddr = UserAJS.CreateBuilder();
                jsddr.SetUser(users);
                jsddr.SetZdou(item.zwd_count);
                jsddr.SetZimo(item.zm_count);
                jsddr.SetAndou(item.ad_count);
                jsddr.SetMdou(item.MD_count);
                jsddr.SetDianpao(item.dp_count);

                switch (item.ZS_Fw)
                {
                case 1:
                    jsddr.SetScare(card == null ? 0 : card.dong);
                    break;

                case 2:
                    jsddr.SetScare(card == null ? 0 : card.nan);
                    break;

                case 3:
                    jsddr.SetScare(card == null ? 0 : card.xi);
                    break;

                case 4:
                    jsddr.SetScare(card == null ? 0 : card.bei);
                    break;

                default:
                    break;
                }
                senddjs.AddUserjs(jsddr);
                senddjs.SetState(2);
                if (!string.IsNullOrEmpty(userWinLose))
                {
                    userWinLose += "|";
                }
                userWinLose += gamer.UserID + "," + jsddr.Scare;
            }
            senddjs.SetState(2);
            Gongyong.mulist.RemoveAll(u => u.RoomID == countdownInfo.roomID);
            var roomInfo = Gongyong.roomlist.Find(w => w.RoomID == countdownInfo.roomID);

            Gongyong.roomlist.RemoveAll(u => u.RoomID == countdownInfo.roomID);
            var alldata = ReturnAllIdea.CreateBuilder().SetState(1).SetMessgaeType(3).Build();

            byte[] bytesss  = alldata.ToByteArray();
            byte[] bsenddjs = senddjs.Build().ToByteArray();
            foreach (var item in listmj)
            {
                UserInfo user = Gongyong.userlist.Find(u => u.openid == item.Openid);
                if (user != null)
                {
                    user.session.TrySend(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 5007, bytesss.Length, countdownInfo.MessageNum, bytesss)));//yi
                    user.session.TrySend(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 5014, bsenddjs.Length, countdownInfo.MessageNum, bsenddjs)));
                    RedisUtility.Remove(RedisUtility.GetKey(GameInformationBase.COMMUNITYUSERGAME, user.openid, user.unionid));
                }
            }
            foreach (var item in Gongyong.msg.FindAll(w => w.RoomID == r.RoomID))
            {
                Gongyong.msg.Remove(item);
            }

            RedisUtility.Remove(RedisUtility.GetKey(GameInformationBase.COMMUNITYROOMINFO, r.RoomID.ToString(), ""));

            new RoomInfoDAL().UpdateEndRoomInfoByRoomInfoID(new RoomInfo {
                RoomInfoID = roomInfo.RoomInfoID, EndTime = DateTime.Now, EndStatus = 3, UserWinLose = userWinLose
            });
            foreach (var item in listmj)
            {
                UserInfo user = Gongyong.userlist.Find(u => u.openid == item.Openid);
                new userRecordLOGDAL().Add(new userRecordlogLOG {
                    UserID = user.UserID, RoomInfoID = roomInfo.RoomInfoID, UserWinLose = userWinLose, EndTime = DateTime.Now, CreateDate = roomInfo.CreateDate, RoomID = r.RoomID
                });
            }
        }
コード例 #4
0
ファイル: GetH.cs プロジェクト: zhaoy615/Guizhoule
        public void ExecuteCommand(GameSession session, ProtobufRequestInfo requestInfo)
        {
            string userWinLose = string.Empty;//玩家输赢记录。房间信息表


            if (!Gongyong.userlist.Any(w => w.session.SessionID.Equals(session.SessionID)))
            {
                session.Logger.Debug("GetH : 非法连接");
                session.Close();
                return;
            }
            var getdata = SendHu.ParseFrom(requestInfo.Body);

            Room r = Gongyong.roomlist.Find(u => u.RoomID == getdata.Roomid);

            if (r == null)
            {
                return;
            }
            if (!r.Is_Hu)
            {
                session.Logger.Debug("房间并无胡牌");
                return;
            }
            ThreadUtility.RemoveManagedThreadByRoomID(r.RoomID);
            CardUser card = Gongyong.FKUser.Find(u => u.roomid == getdata.Roomid);

            model.ServerMaJiang mjfh = new model.ServerMaJiang();
            var jp     = ReturnFJ.CreateBuilder();
            var muuser = Gongyong.mulist.Find(u => u.Openid.Equals(getdata.Openid) && u.RoomID == getdata.Roomid);

            if (muuser == null)
            {
                return;
            }
            muuser.Is_jiao = true;
            if (muuser.ByteData == requestInfo.Key)
            {
                return;
            }
            else
            {
                muuser.ByteData = requestInfo.Key;
            }

            var huType = ReturnHType.CreateBuilder().SetFWZ(getdata.FWZ).SetFWB(getdata.FWB).SetMJ(getdata.MJ).SetType(getdata.Type);

            if (getdata.DXInfoCount > 1)
            {
                huType.AddRangeDXInfo(getdata.DXInfoList);
            }
            byte[] HType = huType.Build().ToByteArray();
            if (getdata.Type != 1 && getdata.Type != 5)
            {
                model.ServerMaJiang mjh = new model.ServerMaJiang()
                {
                    PaiHs = getdata.MJ.PaiHS,
                    PaiId = getdata.MJ.PaiID
                };

                var roomUsers = Gongyong.mulist.FindAll(u => u.RoomID == getdata.Roomid);
                if (getdata.DXInfoCount > 1)
                {
                    for (int i = 0; i < getdata.DXInfoList.Count; i++)
                    {
                        foreach (var item in roomUsers)
                        {
                            if (item.ZS_Fw == getdata.DXInfoList[i].DXFW)//如果当期玩家为一炮多响的玩家之一,则在手牌中加上 放炮的牌
                            {
                                item.majiangs.Add(mjh);
                            }
                        }
                    }
                }
                else
                {
                    roomUsers.Find(u => u.ZS_Fw == getdata.FWZ).majiangs.Add(mjh);
                }
            }

            if (getdata.Type == 1 || getdata.Type == 5)
            {
                Gongyong.mulist.Find(u => u.ZS_Fw == getdata.FWZ && u.RoomID == getdata.Roomid).zm_count += 1;
            }
            else
            {
                var mjInfo = Gongyong.mulist.Find(u => u.ZS_Fw == getdata.FWB && u.RoomID == getdata.Roomid);
                mjInfo.dp_count += 1;
                mjInfo.chuda.RemoveAll(w => w.PaiHs == getdata.MJ.PaiHS && w.PaiId == getdata.MJ.PaiID);
            }


            ///没有翻鸡牌
            if (r.RoomPai.Count == 0)
            {
                mjfh.PaiHs = -1;
                mjfh.PaiId = 0;
            }
            else
            {
                mjfh = r.RoomPai[0];
            }



            jp.SetHS(mjfh.PaiHs);
            ///清除牌
            r.RoomPai.Clear();

            List <mjuser>     mjlist      = Gongyong.mulist.FindAll(u => u.RoomID == getdata.Roomid);
            var               settle      = ReturnJS.CreateBuilder();
            var               returnallmj = ReturnUserSPai.CreateBuilder();
            List <UserSettle> listjs      = new List <UserSettle>();

            listjs = new Ting().Settle(r.RoomID, mjfh, getdata);
            var senddjs = ReturnDJS.CreateBuilder();

            if (getdata.DXInfoCount <= 1)
            {
                if (getdata.FWZ != card.win)
                {
                    card.win        = getdata.FWZ;
                    card.lianzCount = 1;
                }
                else// (getdata.FWZ == card.win)
                {
                    card.lianzCount += 1;
                }
            }
            else
            {//连庄情况 ,庄家放炮,胡牌的庄, 一炮多响情况 就是 胡牌的最近的人是庄
             //一炮多响非连庄,  谁放炮 谁是庄
                if (r.is_lianz)
                {
                    int zhuang = 0;
                    if (getdata.FWB == card.win)
                    {
                        if (getdata.FWB == 4)
                        {
                            zhuang = 1;
                        }
                        else
                        {
                            zhuang = getdata.FWB + 1;
                        }
                        for (int i = 1; i <= 4; i++)
                        {
                            if (getdata.FWB == 4)
                            {
                                zhuang = 1;
                            }
                            if (getdata.DXInfoList.Any(w => w.DXFW == zhuang))
                            {
                                card.win = zhuang;
                                break;
                            }
                            zhuang++;
                        }
                    }
                    else
                    {
                        card.lianzCount += 1;
                    }
                }
                else
                {
                    card.win = getdata.FWB;
                }                               //非连庄谁放炮谁 是庄
            }

            foreach (var item in mjlist)
            {
                var jsddr = UserAJS.CreateBuilder();
                #region 旧代码
                //if (item.ZS_Fw == getdata.FWZ)
                //{
                //    ///判断清一色
                //    //if (item.majiangs[item.majiangs.Count - 1].PaiHs - item.majiangs[0].PaiHs < 8)
                //    //{
                //    //    int paihs = item.majiangs[0].PaiHs;
                //    //    int qyshs = 0;
                //    //    int qy = 0;
                //    //    if (paihs < 10)
                //    //    {
                //    //        qyshs = 1;
                //    //    }
                //    //    else if (paihs > 10 && paihs < 20)
                //    //    {
                //    //        qyshs = 2;
                //    //    }
                //    //    else
                //    //    {
                //    //        qyshs = 3;
                //    //    }

                //    //    switch (qyshs)
                //    //    {

                //    //        case 1:
                //    //            int count = item.Peng.FindAll(u => u.PaiHs > 10).Count;
                //    //            if (count > 0)
                //    //            {
                //    //                qy++;
                //    //            }
                //    //            if (!string.IsNullOrEmpty(item.Gong))
                //    //            {
                //    //                string gong = string.Copy(item.Gong);
                //    //                string[] arr = gong.Remove(gong.Length - 1, 1).Split(',');
                //    //                foreach (var itemgong in arr)
                //    //                {
                //    //                    if (int.Parse(itemgong[0].ToString()) > 10)
                //    //                    {
                //    //                        qy++;
                //    //                    }
                //    //                }
                //    //            }

                //    //            break;
                //    //        case 2:

                //    //            int countt = item.Peng.FindAll(u => u.PaiHs < 10 || u.PaiHs > 20).Count;
                //    //            if (countt > 0)
                //    //            {
                //    //                qy++;
                //    //            }
                //    //            if (!string.IsNullOrEmpty(item.Gong))
                //    //            {
                //    //                string gong = string.Copy(item.Gong);
                //    //                string[] arr = gong.Remove(gong.Length - 1, 1).Split(',');
                //    //                foreach (var itemgong in arr)
                //    //                {
                //    //                    if (int.Parse(itemgong[0].ToString()) < 10 || int.Parse(itemgong[0].ToString()) > 20)
                //    //                    {
                //    //                        qy++;
                //    //                    }
                //    //                }
                //    //            }

                //    //            break;
                //    //        case 3:

                //    //            int countw = item.Peng.FindAll(u => u.PaiHs < 20).Count;
                //    //            if (countw > 0)
                //    //            {
                //    //                qy++;
                //    //            }
                //    //            if (!string.IsNullOrEmpty(item.Gong))
                //    //            {
                //    //                string gong = string.Copy(item.Gong);
                //    //                string[] arr = gong.Remove(gong.Length - 1, 1).Split(',');
                //    //                foreach (var itemgong in arr)
                //    //                {
                //    //                    if (int.Parse(itemgong[0].ToString()) < 20)
                //    //                    {
                //    //                        qy++;
                //    //                    }
                //    //                }
                //    //            }

                //    //            break;
                //    //        default:
                //    //            break;
                //    //    }
                //    //    if (qy == 0)
                //    //    {
                //    //        item.paixinfs = 10;
                //    //    }

                //    //}
                //}
                #endregion


                UserInfo user    = Gongyong.userlist.Find(u => u.openid == item.Openid);
                var      usermjs = UserSPai.CreateBuilder();
                usermjs.SetFw(item.ZS_Fw);
                var returnmj = MaJiang.CreateBuilder();
                foreach (var itemmj in item.majiangs)
                {
                    returnmj.SetPaiHS(itemmj.PaiHs);
                    returnmj.SetPaiID(itemmj.PaiId);
                    usermjs.AddMj(returnmj);
                }
                returnallmj.AddUsp(usermjs);
                UserInfo gamer = Gongyong.userlist.Find(u => u.openid == item.Openid);
                var      users = Userinfo.CreateBuilder().SetHeadimg(gamer.headimg).SetNickname(gamer.nickname).SetOpenid(gamer.openid).SetSex(int.Parse(gamer.sex)).SetUserFW(item.ZS_Fw).SetUserBean(0).SetUserGold(0).SetUserID(gamer.UserID).Build();
                ///分数加减
                foreach (var items in listjs)
                {
                    if (items.openid == item.Openid)
                    {
                        var usersone = UserJS.CreateBuilder();

                        foreach (var itrmj in items.jp)
                        {
                            var jpone = JiPaiF.CreateBuilder().SetPaiHS(itrmj.PaiHS).SetType(itrmj.type).SetCount(itrmj.PaiScare);
                            usersone.AddJp(jpone);
                        }
                        foreach (var itemD in items.gang)
                        {
                            var jpdou = Dou.CreateBuilder().SetCount(itemD.DScare).SetType(itemD.DType);
                            usersone.AddDc(jpdou);
                        }
                        if (getdata.HasFWB)
                        {
                            var info = mjlist.Find(w => w.ZS_Fw == getdata.FWB && w.Openid.Equals(items.openid));
                            if (info != null)
                            {
                                if (items.pai_type != 11)
                                {
                                    items.pai_type = 11;
                                }
                            }
                        }
                        usersone.SetIsPao(items.pai_type);
                        usersone.SetIsJiao(items.is_jiao);
                        usersone.SetFS(items.scare);
                        usersone.SetUserinfo(users);
                        usersone.SetDyFs(items.dy_fs);
                        var HuLeiXin = getdata.DXInfoList.FirstOrDefault(w => w.DXFW == item.ZS_Fw);
                        if (HuLeiXin != null)
                        {
                            usersone.SetHuType(HuLeiXin.DXType);
                        }

                        settle.AddJs(usersone);


                        switch (item.ZS_Fw)
                        {
                        case 1:
                            card.dong += items.scare;
                            break;

                        case 2:
                            card.nan += items.scare;
                            break;

                        case 3:
                            card.xi += items.scare;
                            break;

                        case 4:
                            card.bei += items.scare;
                            break;

                        default:
                            break;
                        }
                    }
                }



                ///牌局结束,返回大结算
                if (r.Dcount == r.count)
                {
                    new CardsLogic().Clear(item, r);
                    jsddr.SetUser(users);
                    jsddr.SetZdou(item.zwd_count);
                    jsddr.SetZimo(item.zm_count);
                    jsddr.SetAndou(item.ad_count);
                    jsddr.SetMdou(item.MD_count);
                    jsddr.SetDianpao(item.dp_count);

                    //switch (item.ZS_Fw)
                    //{
                    //    case 1:
                    //        jsddr.SetScare(card.dong);
                    //        break;
                    //    case 2:
                    //        jsddr.SetScare(card.nan);
                    //        break;
                    //    case 3:
                    //        jsddr.SetScare(card.xi);
                    //        break;
                    //    case 4:
                    //        jsddr.SetScare(card.bei);
                    //        break;
                    //    default:
                    //        break;
                    //}
                    jsddr.SetScare(card.GetScoreByPosition(item.ZS_Fw));
                    senddjs.AddUserjs(jsddr);
                    senddjs.SetState(1);

                    RedisUtility.Remove(RedisUtility.GetKey(GameInformationBase.COMMUNITYUSERGAME, gamer.openid, gamer.unionid));

                    if (!string.IsNullOrEmpty(userWinLose))
                    {
                        userWinLose += "|";
                    }
                    userWinLose += user.UserID + "," + jsddr.Scare;
                }
            }
            //牌局回放 翻鸡
            var gameOperationInfoFJ = GameOperationInfo.CreateBuilder().AddMJ(MaJiang.CreateBuilder().SetPaiHS(jp.HS).SetPaiID(0)).SetOperationType(9);

            StringBuilder logtxt = new StringBuilder();

            logtxt.Append("胡牌" + getdata.ToString());
            foreach (var item in mjlist)
            {
                item.SendData.Clear();
                logtxt.Append(string.Join(",", item.majiangs.Select(w => w.PaiHs)));
                UserInfo user         = Gongyong.userlist.Find(u => u.openid == item.Openid);
                var      sendData5021 = new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 5021, HType.Length, requestInfo.MessageNum, HType));
                item.SendData.Add(sendData5021);

                byte[] allsp = returnallmj.Build().ToByteArray();

                byte[] jpr = jp.Build().ToByteArray();
                //7005 返回翻鸡牌
                var sendData7005 = new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 7005, jpr.Length, requestInfo.MessageNum, jpr));
                item.SendData.Add(sendData7005);

                //7008 : 玩家手牌集合
                var sendData7008 = new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 7008, allsp.Length, requestInfo.MessageNum, allsp));
                item.SendData.Add(sendData7008);

                byte[] settlebyte = settle.Build().ToByteArray();
                r.gameOperationProcess.SetJieSuanInfo(ByteString.CopyFrom(settlebyte));
                //7009 : 返回结算信息(全体)
                var sendData = new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 7009, settlebyte.Length, requestInfo.MessageNum, settlebyte));
                item.SendData.Add(sendData);

                if (r.Dcount == r.count)
                {
                    byte[] senddjsbyte = senddjs.Build().ToByteArray();
                    //5014 : 大结算信息
                    var sendData5014 = new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 5014, senddjsbyte.Length, requestInfo.MessageNum, senddjsbyte));
                    item.SendData.Add(sendData5014);
                }
                foreach (var senddata in item.SendData)
                {
                    user.session.TrySend(senddata);
                }
            }
            session.Logger.Debug(logtxt);
            //牌局回放 胡牌
            var gameOperationInfo = GameOperationInfo.CreateBuilder()
                                    .SetSerialNumber(r.gameOperationProcess.GameOperationInfoCount)
                                    .SetOperationFW(huType.FWZ)
                                    .SetOperationType(5)
                                    .SetTingHuType(muuser.Is_tianHu ? 1 : 0)
                                    .SetPaoFW(huType.FWB);

            if (getdata.DXInfoCount > 1)
            {
                gameOperationInfo.AddRangeDXInfo(getdata.DXInfoList);
            }
            r.gameOperationProcess.AddGameOperationInfo(gameOperationInfo);
            gameOperationInfoFJ.SetSerialNumber(r.gameOperationProcess.GameOperationInfoCount).SetOperationFW(0);
            r.gameOperationProcess.AddGameOperationInfo(gameOperationInfoFJ);
            try
            {
                CardsLogic.AddboarddetailsTB(r);
            }
            catch (Exception ex)
            {
                session.Logger.Error(ex);
            }
            ///对局结束 清空所有信息
            if (r.Dcount == r.count)
            {
                Gongyong.mulist.RemoveAll(u => u.RoomID == r.RoomID);
                Gongyong.FKUser.RemoveAll(u => u.roomid == r.RoomID);
                Gongyong.roomlist.RemoveAll(u => u.RoomID == r.RoomID);
                RedisUtility.Remove(RedisUtility.GetKey(GameInformationBase.COMMUNITYROOMINFO, r.RoomID.ToString(), ""));
                new RoomInfoDAL().UpdateEndRoomInfoByRoomInfoID(new RoomInfo {
                    RoomInfoID = r.RoomInfoID, EndTime = DateTime.Now, EndStatus = 0, UserWinLose = userWinLose
                });
                foreach (var item in mjlist)
                {
                    UserInfo user = Gongyong.userlist.Find(u => u.openid == item.Openid);
                    new userRecordLOGDAL().Add(new userRecordlogLOG {
                        UserID = user.UserID, RoomInfoID = r.RoomInfoID, UserWinLose = userWinLose, EndTime = DateTime.Now, CreateDate = r.CreateDate, RoomID = r.RoomID
                    });
                }
                r.startgame = 0;
            }
            else
            {
                if (r != null)
                {
                    r.RoomPai   = new CreateMj().CreateMJ(r.IsYuanQue);
                    r.Dcount   += 1;
                    r.startgame = 2;
                }
            }
        }
コード例 #5
0
ファイル: ConnData.cs プロジェクト: zhaoy615/Guizhoule
        public void ExecuteCommand(GameSession session, ProtobufRequestInfo requestInfo)
        {
            if (!Gongyong.userlist.Any(w => w.session.SessionID.Equals(session.SessionID)))
            {
                session.Logger.Debug("ConnData : 非法连接");
                session.Close();
                return;
            }
            var getinfo = SendConnData.ParseFrom(requestInfo.Body);

            var userInfo = Gongyong.userlist.Find(u => u.openid == getinfo.Openid);

            if (userInfo == null)
            {
                session.Close();
            }
            userInfo.session = session;

            mjuser mj = Gongyong.mulist.Find(u => u.Openid == getinfo.Openid);

            if (mj == null)
            {
                return;
            }
            List <mjuser> mjlist  = Gongyong.mulist.FindAll(u => u.RoomID == mj.RoomID);
            var           roommsg = ReturnRoomMsg.CreateBuilder();

            Room rm = Gongyong.roomlist.Find(u => u.RoomID == mj.RoomID);

            if (rm == null)
            {
                return;
            }
            var userinfo = Userinfo.CreateBuilder();
            ///返回重连状态
            //  var ifconn = ReturnRecon.CreateBuilder().SetState(1).Build();
            ///返回房间用户信息
            var userinfobyroom = ReturnUserInfo.CreateBuilder();
            var mjhy           = MaJiang.CreateBuilder();
            var hyyh           = ReturnHyUser.CreateBuilder();

            if (!string.IsNullOrEmpty(rm.DQHY.ToString()))
            {
                hyyh.SetFw(rm.DQHY);
            }
            else
            {
                hyyh.SetFw(0);
            }


            if (!string.IsNullOrEmpty(rm.DQcz))
            {
                hyyh.SetCz(rm.DQcz);
            }
            else
            {
                hyyh.SetCz("");
            }

            if (rm.PaiHSCZ != null)
            {
                mjhy.SetPaiID(rm.PaiHSCZ.PaiId);
                mjhy.SetPaiHS(rm.PaiHSCZ.PaiHs);
            }
            else
            {
                mjhy.SetPaiID(0);
                mjhy.SetPaiHS(0);
            }
            hyyh.SetMj(mjhy);

            var         returndata   = ReturnConnData.CreateBuilder();
            List <byte> returnzhuang = new List <byte>();
            List <model.ServerMaJiang> Ruturnjsmj = new List <model.ServerMaJiang>();
            int myFW = 0;

            foreach (mjuser mjuseritem in mjlist)
            {
                var MJ = MaJiang.CreateBuilder();
                ///手牌集合
                var shoupai = UserShou.CreateBuilder();
                //碰牌集合
                var pengpai = UserPeng.CreateBuilder();
                ///出牌集合
                var chupai = UserChu.CreateBuilder();
                ///杠
                var gangpai = UserGang.CreateBuilder();


                var userzrj = JpConn.CreateBuilder();
                userzrj.SetFW(mjuseritem.ZS_Fw);
                if (mjuseritem.Is_cfj == true)
                {
                    userzrj.SetCFJ(1);
                }

                if (mjuseritem.Is_zrj == -1)
                {
                    userzrj.SetCFJ(2);
                }


                if (mjuseritem.is_cfwg == true)
                {
                    userzrj.SetWGJ(1);
                }

                if (mjuseritem.is_zrwg == -1)
                {
                    userzrj.SetWGJ(2);
                }

                /**********************返回房间用户信息************************************************/
                UserInfo user = Gongyong.userlist.Find(u => u.openid == mjuseritem.Openid);
                userinfo.SetOpenid(user.openid);
                userinfo.SetNickname(user.nickname);
                userinfo.SetHeadimg(user.headimg);
                userinfo.SetSex(int.Parse(user.sex));
                userinfo.SetUserBean(0);
                userinfo.SetUserGold(0);
                userinfo.SetUserFW(mjuseritem.ZS_Fw);
                userinfo.SetUserID(user.UserID);
                CardUser card = Gongyong.FKUser.Find(u => u.roomid == mjuseritem.RoomID);
                if (card != null)
                {
                    userinfo.SetCumulativeScore(card.GetScoreByPosition(mjuseritem.ZS_Fw));
                    //if (returnzhuang.Count == 0)
                    //    returnzhuang.AddRange(ReturnZhuang.CreateBuilder().SetZhuang(card.win).Build().ToByteArray());
                    if (!returndata.HasZhuang)
                    {
                        returndata.SetZhuang(ReturnZhuang.CreateBuilder().SetZhuang(card.win).SetSeizi(card.Points).SetZhuangCount(card.lianzCount));
                    }
                    shoupai.SetScare(card.GetScoreByPosition(mjuseritem.ZS_Fw));
                }
                else
                {
                    shoupai.SetScare(0);
                }
                userinfobyroom.AddUserinfo(userinfo);
                /***********************返回手牌集合***************************************/
                // int paicount = 0;
                if (mjuseritem.Openid == getinfo.Openid)
                {
                    //foreach (var item in mjuseritem.majiangs)
                    //{
                    //    paicount++;
                    //    MJ.SetPaiHS(item.PaiHs);
                    //    MJ.SetPaiID(item.PaiId);
                    //    shoupai.AddMj(MJ);
                    //}
                    myFW = mjuseritem.ZS_Fw;
                    shoupai.AddRangeMj(mjuseritem.majiangs.Select(w => MaJiang.CreateBuilder().SetPaiHS(w.PaiHs).SetPaiID(w.PaiId).Build()));
                    List <model.ServerMaJiang> majongList = new List <model.ServerMaJiang>();
                    majongList.AddRange(mjuseritem.majiangs.ToArray());
                    if (mjuseritem.majiangs.Count == 14 && mjuseritem.MopaiNumber <= 1 && mjuseritem.Peng.Count == 0 && string.IsNullOrEmpty(mjuseritem.Gong))
                    {
                        Ruturnjsmj = new Ting().ReturnJMJ(majongList);
                    }
                }
                else
                {
                    //foreach (var item in mjuseritem.majiangs)
                    //{
                    //    paicount++;
                    //    MJ.SetPaiHS(0);
                    //    MJ.SetPaiID(0);
                    //    shoupai.AddMj(MJ);
                    //}
                    shoupai.AddRangeMj(mjuseritem.majiangs.Select(w => MaJiang.CreateBuilder().SetPaiHS(0).SetPaiID(0).Build()));
                }
                shoupai.SetFW(mjuseritem.ZS_Fw);
                shoupai.SetPcount(mjuseritem.majiangs.Count);
                shoupai.SetQYM(mjuseritem.QYM);
                shoupai.SetTianting(mjuseritem.Is_tiantX);
                shoupai.SetBaoting(mjuseritem.Is_baotin ? 1 : 0);
                /*****碰牌集合*****************************/
                foreach (var itemP in mjuseritem.Peng)
                {
                    MJ.SetPaiHS(itemP.PaiHs);
                    MJ.SetPaiID(itemP.PaiId);
                    pengpai.AddMj(MJ);
                }
                pengpai.SetFW(mjuseritem.ZS_Fw);

                /****************出牌集合*********************************/
                foreach (var itemC in mjuseritem.chuda)
                {
                    MJ.SetPaiHS(itemC.PaiHs);
                    MJ.SetPaiID(itemC.PaiId);
                    chupai.AddMj(MJ);
                }
                chupai.SetFW(mjuseritem.ZS_Fw);

                gangpai.SetFW(mjuseritem.ZS_Fw);
                if (!string.IsNullOrEmpty(mjuseritem.Gong))
                {
                    gangpai.SetGang(mjuseritem.Gong);
                }
                else
                {
                    gangpai.SetGang("");
                }
                returndata.AddChu(chupai);
                returndata.AddPeng(pengpai);
                returndata.AddGang(gangpai);
                returndata.AddShoupai(shoupai);
                returndata.AddJp(userzrj);


                //chupai.Clear();
                //pengpai.Clear();
                //gangpai.Clear();
                //shoupai.Clear();
            }
            roommsg.SetCount(rm.count).SetIsBenji(rm.is_benji == true ? 1 : 0).SetIsShangxiaji(rm.is_shangxiaji == true ? 1 : 0).SetIsWgj(rm.is_wgj == true ? 1 : 0).SetIsXinqiji(rm.is_xinqiji == true ? 1 : 0).SetIsYikousan(rm.is_yikousan == true ? 1 : 0).SetRoomPeo(rm.room_peo).SetIsLianzhuang(rm.is_lianz == true ? 1 : 0).SetIsYuanque(rm.IsYuanQue?1:0);
            returndata.SetRoomID(mj.RoomID);

            returndata.SetHyUser(hyyh);
            returndata.SetMessage(roommsg);
            returndata.SetUserInfo(userinfobyroom);
            //byte[] hyczall = hyyh.Build().ToByteArray();
            //session.TrySend(new ArraySegment<byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 7004, hyczall.Length, requestInfo.MessageNum, hyczall)));
            //byte[] roommsgb = roommsg.Build().ToByteArray();
            //session.TrySend(new ArraySegment<byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 7003, roommsgb.Length, requestInfo.MessageNum, roommsgb)));


            //byte[] cState = ifconn.ToByteArray();
            //session.TrySend(new ArraySegment<byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 6001, cState.Length, requestInfo.MessageNum, cState)));

            //byte[] uData = userinfobyroom.Build().ToByteArray();
            //session.TrySend(new ArraySegment<byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 2005, uData.Length, requestInfo.MessageNum, uData)));
            if (Ruturnjsmj.Count > 0)
            {
                var returntp = ReturnTP.CreateBuilder();
                var tmj      = MaJiang.CreateBuilder();
                foreach (var mjItem in Ruturnjsmj)
                {
                    tmj.SetPaiHS(mjItem.PaiHs);
                    tmj.SetPaiID(mjItem.PaiId);
                    returntp.AddMj(tmj);
                }
                returndata.SetTp(returntp);
                //byte[] tmjsr = returntp.Build().ToByteArray();
                //session.TrySend(new ArraySegment<byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 2009, tmjsr.Length, requestInfo.MessageNum, tmjsr)));
            }

            // session.TrySend(new ArraySegment<byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 5020, returnzhuang.Count, GameInformationBase.BASEAGREEMENTNUMBER + 7093, returnzhuang.ToArray())));
            //if (mj.SendData != null)
            //    session.TrySend(mj.SendData);
            if (mj.SendData != null)
            {
                returndata.AddRangeSendData(mj.SendData.Select(w => ByteString.CopyFrom(w.ToArray())));
            }
            if (rm.LastMoMJ != null)
            {
                returndata.SetLastMomj(MaJiang.CreateBuilder().SetPaiHS(rm.LastMoMJ.PaiHs).SetPaiID(rm.LastMoMJ.PaiId));
            }
            if (rm.LastChuMJ != null)
            {
                returndata.SetLastChumj(MaJiang.CreateBuilder().SetPaiHS(rm.LastChuMJ.PaiHs).SetPaiID(rm.LastChuMJ.PaiId));
            }
            returndata.SetGameNumber(rm.Dcount);
            var jxRoom = Gongyong.room_JX.Find(u => u.room_id == returndata.RoomID);

            if (jxRoom == null)
            {
                returndata.SetJiXuYouXi(0);
            }
            else
            {
                returndata.SetJiXuYouXi(jxRoom.UsersFW.Any(w => w == myFW) ? 1 : 0);
            }
            returndata.SetPaiCount(rm.RoomPai.Count);
            if (!returndata.HasZhuang)
            {
                returndata.SetZhuang(ReturnZhuang.CreateBuilder().SetZhuang(1).SetSeizi("").SetZhuangCount(1));
            }
            byte[] rData = returndata.Build().ToByteArray();
            session.TrySend(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 7001, rData.Length, requestInfo.MessageNum, rData)));
            Gongyong.msg.RemoveAll(w => w.openid.Equals(userInfo.openid));
            session.Logger.Debug("断线重连结束" + userInfo.openid);
        }