Ejemplo n.º 1
0
        public virtual void BeginGame(string userId)
        {
            LinkedListNode <CsGamePlayer> player = FindPlayer(userId);

            if (Players.All(p => p.IsReady) && Players.Count == 4 && this.RoomPeoPleType == 0)
            {
                CardIndex = 0;
                RandCard();
                SendCard(false);
            }
            else if (Players.All(p => p.IsReady) && Players.Count == 3 && this.RoomPeoPleType == 1)
            {
                CardIndex = 0;
                RandCard();
                SendCard(false);
            }
            else
            {
                //DOTO: 待重构,不够人数加入房间因为想只给客户端发一次,将1003与1006合并为一个接口
                int playerLen = this.Players.Count;

                A1003AndA1006Response.Builder responseBase = this.Create1003And1006Req(playerLen);

                var responseArray = responseBase.Build().ToByteArray();

                var tempPlayer = this.Players.First;

                for (int i = 0; i < playerLen; i++)
                {
                    WebSocketServerWrappe.SendPackgeWithUser(tempPlayer.Value.PlayerUser.Uid, 10036, responseArray);
                    tempPlayer = tempPlayer.Next;
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 捉跑
        /// </summary>
        /// <param name="uid"></param>
        /// <param name="desUid"></param>
        /// <param name="huType"></param>
        public void ZhuoPao(string uid, string desUid, int huType, int card, int card1)
        {
            LogManager.Log.Debug("捉炮开始");
            LinkedListNode <CsGamePlayer> node    = FindPlayer(uid);
            LinkedListNode <CsGamePlayer> desNode = FindPlayer(desUid);

            A1014Response.Builder response = A1014Response.CreateBuilder();
            response.Uid     = node.Value.PlayerUser.Uid;
            response.HuType |= huType;
            response.DesUid  = desUid;
            response.Card1   = card;
            response.Card2   = card1;

            var sendByte = response.Build().ToByteArray();

            foreach (var row in this.Players)
            {
                WebSocketServerWrappe.SendPackgeWithUser(row.PlayerUser.Uid, 1014, sendByte);
            }
            node.Value.PaoHuType    |= huType;
            node.Value.DianPaoPlayer = desNode;
            this.OutCardState        = OutCardState.Hu;
            this.Player = node;
            node.Value.ResetEvent.Set();
            LogManager.Log.Debug("捉炮结束");

            actionStorage.PushZhuoPao(uid, card, huType);
        }
Ejemplo n.º 3
0
        private void SendA1013Response(string uid, Tuple <int, int> niao, string niaoUid1, string niaoUid2)
        {
            A1013Response.Builder response = A1013Response.CreateBuilder();
            response.Uid       = uid;
            response.NiaoCard1 = niao.Item1;
            response.NiaoCard2 = niao.Item2;
            response.NiaoUid1  = niaoUid1;
            response.NiaoUid2  = niaoUid2;

            foreach (var row in this.Players)
            {
                var builder = A1013User.CreateBuilder();
                builder.Uid        = row.PlayerUser.Uid;
                builder.Score      = row.AddScore - row.SubScore;
                builder.TotalScore = row.Score;
                builder.HuType     = row.GetAllHuType();
                response.AddUsers(builder);
            }

            var sendByte = response.Build().ToByteArray();

            foreach (var row in this.Players)
            {
                WebSocketServerWrappe.SendPackgeWithUser(row.PlayerUser.Uid, 1013, sendByte);
            }
        }
Ejemplo n.º 4
0
        private void SendA1021Response(Tuple <int, int> niao, string niaoUid1, string niaoUid2, string desUid)
        {
            A1021Response.Builder a1021Response = A1021Response.CreateBuilder();

            a1021Response.NiaoCard1 = niao.Item1;
            a1021Response.NiaoCard2 = niao.Item2;
            a1021Response.DesUid    = desUid;
            a1021Response.NiaoUid1  = niaoUid1;
            a1021Response.NiaoUid2  = niaoUid2;

            foreach (var row in this.Players)
            {
                A1021User.Builder user1 = A1021User.CreateBuilder();
                user1.HuType     = row.GetAllHuType();
                user1.Uid        = row.PlayerUser.Uid;
                user1.Score      = row.AddScore - row.SubScore;
                user1.TotalScore = row.Score;
                a1021Response.AddUsers(user1);
            }


            byte[] a1012Array = a1021Response.Build().ToByteArray();

            foreach (var row in this.Players)
            {
                WebSocketServerWrappe.SendPackgeWithUser(row.PlayerUser.Uid, 1021, a1012Array);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 摸牌
        /// </summary>
        /// <param name="uid"></param>
        public void Mo(string uid)
        {
            LogManager.Log.Debug("开始摸牌");
            LinkedListNode <CsGamePlayer> node = FindPlayer(uid);


            if (CardIndex == cardArray.Length)
            {
                //TODO: 牌已摸完
                return;
            }
            int card = this.ReadCard();

            LogManager.Log.Debug("摸到牌" + card.GetItemValue() + "牌类型" + card.GetItemType());

            node.Value.AddCard(card);


            A1008Response.Builder response = A1008Response.CreateBuilder();
            response.Card = card;
            response.Uid  = uid;
            byte[] responseArray = response.Build().ToByteArray();

            foreach (var row in Players)
            {
                WebSocketServerWrappe.SendPackgeWithUser(row.PlayerUser.Uid, 1008, responseArray);
            }

            actionStorage.PushMo(uid, card);
            LogManager.Log.Debug("摸牌结束");
        }
Ejemplo n.º 6
0
        public void GuoHaidi(string uid)
        {
            this.OutCardState = OutCardState.haidi;
            this.SetAllResetEvent();
            LinkedListNode <CsGamePlayer> node = FindPlayer(uid);

            this.haiGuoNumber++;

            //都没人要留局
            if (this.haiGuoNumber == this.Players.Count)
            {
                A1018Response.Builder rep1018 = A1018Response.CreateBuilder();
                rep1018.Card = this.cardArray[this.CardIndex];;
                var rep1018Array = rep1018.Build().ToByteArray();
                foreach (var row in Players)
                {
                    WebSocketServerWrappe.SendPackgeWithUser(row.PlayerUser.Uid, 1018, rep1018Array);
                }
                this.EndGame();
            }
            else
            {
                A1016Response.Builder rep1016 = A1016Response.CreateBuilder();
                rep1016.Uid = node.NextOrFirst().Value.PlayerUser.Uid;
                var rep1016Array = rep1016.Build().ToByteArray();
                foreach (var row in Players)
                {
                    WebSocketServerWrappe.SendPackgeWithUser(row.PlayerUser.Uid, 1016, rep1016Array);
                }
            }
        }
Ejemplo n.º 7
0
        public void MoHaidi(string uid)
        {
            this.OutCardState = OutCardState.haidi;
            this.SetAllResetEvent();
            LinkedListNode <CsGamePlayer> node = FindPlayer(uid);
            int card = this.cardArray[this.CardIndex];

            node.Value.HaidiPai = card;
            A1017Response.Builder rep1017 = A1017Response.CreateBuilder();
            rep1017.Uid  = node.Value.PlayerUser.Uid;
            rep1017.Card = card;
            var rep1017Array = rep1017.Build().ToByteArray();

            foreach (var row in Players)
            {
                if (row.PlayerUser.Uid != uid)
                {
                    row.HaidiPai = -1;
                }

                WebSocketServerWrappe.SendPackgeWithUser(row.PlayerUser.Uid, 1017, rep1017Array);
            }

            actionStorage.PushMo(uid, card);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 暗杠
        /// </summary>
        /// <param name="uid"></param>
        /// <param name="card"></param>
        public void AnGang(string uid, int card)
        {
            if (this.IsFrist)
            {
                foreach (var row in Players)
                {
                    if ((row.CheckKaiJuHu()) && row.PlayerUser.Uid != uid)
                    {
                        LogManager.Log.Debug("开局胡等待" + row.PlayerUser.Uid + "wait");
                        row.ResetEvent.WaitOne();
                        LogManager.Log.Debug("开局胡等待处理完毕" + row.PlayerUser.Uid + "wait");
                    }
                }
            }

            this.IsFrist = false;

            LinkedListNode <CsGamePlayer> node = FindPlayer(uid);

            node.Value.IsGang = true;

            this.Player = node;

            int modZhang = 108 - (this.CardIndex + 1);

            int dunshu = modZhang / 2;


            int saizi = new Random().Next(2, 12);

            int card1 = -1;
            int card2 = -1;

            //TODO : 筛子随出大于当前墩数
            if (saizi <= dunshu)
            {
                card1 = this.ReadCard();
                card2 = this.ReadCard();
            }

            A1012Response.Builder response = A1012Response.CreateBuilder();
            response.Uid      = node.Value.PlayerUser.Uid;
            response.Card     = card;
            response.Card1    = card1;
            response.Card2    = card2;
            response.GangType = 0;
            var array = response.Build().ToByteArray();

            node.Value.NeedGangDaPai.Add(card1);
            node.Value.NeedGangDaPai.Add(card2);
            foreach (var row in this.Players)
            {
                WebSocketServerWrappe.SendPackgeWithUser(row.PlayerUser.Uid, 1012, array);
            }
            node.Value.AnGang(card);

            actionStorage.PushGang(uid, card, card1, card2);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 杠牌
        /// </summary>
        /// <param name="uid"></param>
        /// <param name="card"></param>
        public void Gang(string uid, string desUid, int card)
        {
            LinkedListNode <CsGamePlayer> node = FindPlayer(uid);

            foreach (var row in Players)
            {
                if ((row.CheckHu(card)) && row.PlayerUser.Uid != uid && row.PlayerUser.Uid != desUid)
                {
                    row.ResetEvent.WaitOne();
                }
            }

            if (node.Value.ResetEvent.WaitOne(0))
            {
                return;
            }


            node.Value.Gang(card);

            //牌未被胡
            if (this.OutCardState == OutCardState.Normal)
            {
                node.Value.IsGang = true;
                this.OutCardState = OutCardState.Gang;

                int modZhang = 108 - (this.CardIndex + 1);

                int dunshu = modZhang / 2;


                int saizi = new Random().Next(2, 12);
                int card1 = -1;
                int card2 = -1;
                //TODO : 筛子随出大于当前墩数
                if (saizi <= dunshu)
                {
                    card1 = this.ReadCard();
                    card2 = this.ReadCard();
                }

                A1012Response.Builder response = A1012Response.CreateBuilder();
                response.Uid   = node.Value.PlayerUser.Uid;
                response.Card  = card;
                response.Card1 = card1;
                response.Card2 = card2;
                var array = response.Build().ToByteArray();
                foreach (var row in this.Players)
                {
                    WebSocketServerWrappe.SendPackgeWithUser(row.PlayerUser.Uid, 1012, array);
                }

                actionStorage.PushGang(uid, card, card1, card2);
            }
            this.Player = node;
            node.Value.ResetEvent.Set();
        }
Ejemplo n.º 10
0
        public void Process()
        {
            A1025Response.Builder response = A1025Response.CreateBuilder();

            response.Uid      = this.Uid;
            response.RoomCard = this.RoomCard;

            WebSocketServerWrappe.SendPackgeWithUser(this.Uid, 1025, response.Build().ToByteArray());
        }
Ejemplo n.º 11
0
    public override byte[] ProcessAction()
    {
        GameUser user = RedisContext.GlobalContext.FindHashEntityByKey <GameUser>(Context.Session.User.Uid);

        int prizeType = int.Parse(Context.HttpQueryString["prizeType"].ToString());

        if (prizeType == 0)
        {
            if ((user.IsLingQu & 1) != 0 && user.FriendNumber >= 1)
            {
                user.RoomCard += 2;
                user.IsLingQu |= 1;
            }
        }
        if (prizeType == 1)
        {
            if ((user.IsLingQu & 2) != 0 && user.FriendNumber >= 2)
            {
                user.RoomCard += 4;
                user.IsLingQu |= 2;
            }
        }
        if (prizeType == 2)
        {
            if ((user.IsLingQu & 4) != 0 && user.FriendNumber >= 3)
            {
                user.RoomCard += 6;
                user.IsLingQu |= 4;
            }
        }
        if (prizeType == 3)
        {
            if ((user.IsLingQu & 8) != 0 && user.FriendNumber >= 4)
            {
                user.RoomCard += 8;
                user.IsLingQu |= 8;
            }
        }
        if (prizeType == 4)
        {
            if ((user.IsLingQu & 16) != 0 && user.FriendNumber >= 5)
            {
                user.RoomCard += 12;
                user.IsLingQu |= 16;
            }
        }
        RedisContext.GlobalContext.AddHashEntity(user);

        A1025Response.Builder response = A1025Response.CreateBuilder();
        response.RoomCard     = user.RoomCard;
        response.FriendNumber = user.FriendNumber;

        WebSocketServerWrappe.SendPackgeWithUser(Context.Session.User.Uid, 1025, response.Build().ToByteArray());


        return(null);
    }
Ejemplo n.º 12
0
 public void SendMessage(string uid, string message, string messageType)
 {
     A1100Response.Builder response = A1100Response.CreateBuilder();
     response.Uid         = uid;
     response.Message     = message;
     response.MessageType = messageType;
     byte[] responseByte = response.Build().ToByteArray();
     foreach (var row in this.Players)
     {
         WebSocketServerWrappe.SendPackgeWithUser(row.PlayerUser.Uid, 1100, responseByte);
     }
 }
Ejemplo n.º 13
0
        public override byte[] ProcessAction()
        {
            CsMjGameRoom room = CsGameRoomManager.JoinRoom(Context.Session.User as GameUser, int.Parse(Context.HttpQueryString["RoomID"]));

            if (room == null)
            {
                A9999DataErrorResponse.Builder error = A9999DataErrorResponse.CreateBuilder();
                error.ErrorCode = 2;
                error.ErrorInfo = ErrorInfo.ErrorDic[2];
                WebSocketServerWrappe.SendPackgeWithUser(Context.Session.User.Uid, 9999, error.Build().ToByteArray());
            }
            return(null);
        }
Ejemplo n.º 14
0
        public void DaHaidi(string uid, int card)
        {
            LinkedListNode <CsGamePlayer> node = FindPlayer(uid);

            this.OutCardState = OutCardState.Normal;

            A1024Response.Builder a1024Response = A1024Response.CreateBuilder();
            a1024Response.Card = card;
            a1024Response.Uid  = uid;

            byte[] responseArray = a1024Response.Build().ToByteArray();

            foreach (var row in Players)
            {
                if (row.PlayerUser.Uid != uid)
                {
                    row.HaidiPai = -1;
                }

                WebSocketServerWrappe.SendPackgeWithUser(row.PlayerUser.Uid, 1024, responseArray);

                actionStorage.PushDa(uid, card);
            }

            foreach (var row in Players)
            {
                if (row.PlayerUser.Uid != uid && row.CheckHu(card))
                {
                    row.ResetEvent.WaitOne();
                }
            }

            if (this.OutCardState != OutCardState.Normal)
            {
                return;
            }

            A1018Response.Builder a1018Response = A1018Response.CreateBuilder();

            byte[] response1018Array = a1018Response.Build().ToByteArray();

            foreach (var row in Players)
            {
                WebSocketServerWrappe.SendPackgeWithUser(row.PlayerUser.Uid, 1018, response1018Array);
            }
            this.EndGame();
        }
Ejemplo n.º 15
0
        /// <summary>
        /// 吃牌
        /// </summary>
        /// <param name="uid"></param>
        /// <param name="card"></param>
        /// <param name="card1"></param>
        /// <param name="card2"></param>
        public void Chi(string uid, string desUid, int card, int card1, int card2)
        {
            LogManager.Log.Debug("吃牌开始");
            LinkedListNode <CsGamePlayer> node = FindPlayer(uid);

            foreach (var row in Players)
            {
                if ((row.CheckGang(card) ||
                     row.CheckPeng(card) ||
                     row.CheckHu(card)) && row.PlayerUser.Uid != uid && row.PlayerUser.Uid != desUid)
                {
                    row.ResetEvent.WaitOne();
                }
            }

            if (node.Value.ResetEvent.WaitOne(0))
            {
                return;
            }

            //牌未被彭吃杠并且打牌的人为当前吃的玩家的上手
            if (this.OutCardState == OutCardState.Normal && this.Player.Value.PlayerUser.Uid == node.PreviousOrLast().Value.PlayerUser.Uid)
            {
                this.OutCardState = OutCardState.Chi;
                LogManager.Log.Debug("牌可以吃");
                node.Value.Chi(card, card1, card2);
                A1010Response.Builder response = A1010Response.CreateBuilder();
                response.Uid   = node.Value.PlayerUser.Uid;
                response.Card  = card;
                response.Card1 = card1;
                response.Card2 = card2;
                var array = response.Build().ToByteArray();
                this.Player = node;
                foreach (var row in this.Players)
                {
                    WebSocketServerWrappe.SendPackgeWithUser(row.PlayerUser.Uid, 1010, array);
                }
                LogManager.Log.Debug(node.Value.PlayerUser.Uid + "吃完手上的牌" + node.Value.PrintCards());

                actionStorage.PushChi(uid, card, card1, card2);
            }
            this.SetAllResetEvent();
            LogManager.Log.Debug("吃牌结束");
        }
Ejemplo n.º 16
0
        public override byte[] ProcessAction()
        {
            A1026Response.Builder response = A1026Response.CreateBuilder();
            foreach (var row in RedisContext.GlobalContext.FindSoredEntityByKey <GameResult>(this.Context.Session.User.Uid, 50))
            {
                A1026GameResult.Builder gr = A1026GameResult.CreateBuilder();
                gr.ResultActionId = row.ActionId.ToString();
                gr.Score          = row.AddScore;
                gr.DateTime       = row.DateTime.ToString();

                response.AddGResult(gr);
            }


            WebSocketServerWrappe.SendPackgeWithUser(this.Context.Session.User.Uid, 1026, response.Build().ToByteArray());


            return(null);
        }
Ejemplo n.º 17
0
        public override byte[] ProcessAction()
        {
            GameUser user = RedisContext.GlobalContext.FindHashEntityByKey <GameUser>(Context.HttpQueryString["Uid"]);

            if (user.RoomCard <= 0)
            {
                A9999DataErrorResponse.Builder error = A9999DataErrorResponse.CreateBuilder();
                error.ErrorCode = 4;
                error.ErrorInfo = ErrorInfo.ErrorDic[4];
                WebSocketServerWrappe.SendPackgeWithUser(Context.Session.User.Uid, 9999, error.Build().ToByteArray());
                return(null);
            }

            CsMjGameRoom room = CsGameRoomManager.CreateRoom(user, int.Parse(Context.HttpQueryString["RoomPeopleType"]));

            A1002Response.Builder response = A1002Response.CreateBuilder();
            response.RoomID   = room.RoomId;
            response.RoomType = int.Parse(Context.HttpQueryString["RoomType"]);

            return(response.Build().ToByteArray());
        }
Ejemplo n.º 18
0
        public void MingBuzhang(string uid, int card, string desUid)
        {
            LinkedListNode <CsGamePlayer> node = FindPlayer(uid);

            foreach (var row in Players)
            {
                if ((row.CheckHu(card)) && row.PlayerUser.Uid != uid && row.PlayerUser.Uid != desUid)
                {
                    row.ResetEvent.WaitOne();
                }
            }

            if (node.Value.ResetEvent.WaitOne(0))
            {
                return;
            }

            //牌未被胡
            if (this.OutCardState == OutCardState.Normal)
            {
                this.OutCardState = OutCardState.Gang;

                node.Value.BuZhang(card);

                int mCard = this.ReadCard();
                node.Value.AddCard(mCard);
                A1022Response.Builder response = new A1022Response.Builder();
                response.Uid   = uid;
                response.Card  = mCard;
                response.BCard = card;

                byte[] responseArray = response.Build().ToByteArray();

                foreach (var row in this.Players)
                {
                    WebSocketServerWrappe.SendPackgeWithUser(row.PlayerUser.Uid, 1022, responseArray);
                }
                actionStorage.PushBuZhang(uid, card, mCard);
            }
        }
Ejemplo n.º 19
0
        /// <summary>
        /// 暗杠补涨
        /// </summary>
        /// <param name="uid"></param>
        /// <param name="card"></param>
        public void AnBuZhang(string uid, int card)
        {
            if (this.IsFrist)
            {
                foreach (var row in Players)
                {
                    if ((row.CheckKaiJuHu()) && row.PlayerUser.Uid != uid)
                    {
                        LogManager.Log.Debug("开局胡等待" + row.PlayerUser.Uid + "wait");
                        row.ResetEvent.WaitOne();
                        LogManager.Log.Debug("开局胡等待处理完毕" + row.PlayerUser.Uid + "wait");
                    }
                }
            }

            this.IsFrist = false;

            LinkedListNode <CsGamePlayer> node = FindPlayer(uid);

            node.Value.AnBuZhang(card);

            int mCard = this.ReadCard();

            node.Value.AddCard(mCard);
            A1022Response.Builder response = new A1022Response.Builder();
            response.Uid         = uid;
            response.Card        = mCard;
            response.BCard       = card;
            response.BuZhangType = 0;

            byte[] responseArray = response.Build().ToByteArray();

            foreach (var row in this.Players)
            {
                WebSocketServerWrappe.SendPackgeWithUser(row.PlayerUser.Uid, 1022, responseArray);
            }

            actionStorage.PushBuZhang(uid, card, mCard);
        }
Ejemplo n.º 20
0
        public override byte[] ProcessAction()
        {
            GameUser user   = RedisContext.GlobalContext.FindHashEntityByKey <GameUser>(Context.HttpQueryString["YaoUid"].ToString());
            GameUser myUser = RedisContext.GlobalContext.FindHashEntityByKey <GameUser>(Context.Session.User.Uid);

            if (user != null)
            {
                if (myUser.YaoUid == null)
                {
                    user.YaoUid.Add(Context.HttpQueryString["YaoUid"].ToString());
                    user.FriendNumber++;

                    RedisContext.GlobalContext.AddHashEntity(user);
                }
                else if (myUser.YaoUid != null && !myUser.YaoUid.Contains(Context.HttpQueryString["YaoUid"].ToString()))
                {
                    user.YaoUid.Add(Context.HttpQueryString["YaoUid"].ToString());
                    user.FriendNumber++;
                    RedisContext.GlobalContext.AddHashEntity(user);
                }
                else
                {
                    A9999DataErrorResponse.Builder error = A9999DataErrorResponse.CreateBuilder();
                    error.ErrorCode = 6;
                    error.ErrorInfo = "该邀请码已输入过";
                    WebSocketServerWrappe.SendPackgeWithUser(Context.Session.User.Uid, 9999, error.Build().ToByteArray());
                    return(null);
                }
            }
            else
            {
                A9999DataErrorResponse.Builder error = A9999DataErrorResponse.CreateBuilder();
                error.ErrorCode = 5;
                error.ErrorInfo = "邀请码不存在";
                WebSocketServerWrappe.SendPackgeWithUser(Context.Session.User.Uid, 9999, error.Build().ToByteArray());
                return(null);
            }
            return(null);
        }
Ejemplo n.º 21
0
        public override byte[] ProcessAction()
        {
            GameActionStoreage ga = RedisContext.GlobalContext.FindHashEntityByKey <GameActionStoreage>(Context.HttpQueryString["ResultActionId"]);

            A1027Response.Builder a1027Respose = A1027Response.CreateBuilder();

            foreach (var row in ga.LPlayer)
            {
                A1027GameUser.Builder gameuser = A1027GameUser.CreateBuilder();

                GameUser user = RedisContext.GlobalContext.FindHashEntityByKey <GameUser>(row.Uid);
                gameuser.Uid      = row.Uid;
                gameuser.HatImage = user.HeadImgurl;
                gameuser.Sex      = user.Sex;
                gameuser.Name     = user.NickName;
                gameuser.AddRangeCards(row.Cards);
                a1027Respose.AddGameUser(gameuser);
            }

            foreach (var row in ga.CmdList)
            {
                A1027CmdList.Builder cmdList = A1027CmdList.CreateBuilder();
                cmdList.Uid    = row.Uid;
                cmdList.AType  = (int)row.AType;
                cmdList.Card   = row.Card;
                cmdList.Card1  = row.Card1;
                cmdList.Card2  = row.Card2;
                cmdList.HuType = row.HuType;
                a1027Respose.AddCmdList(cmdList);
            }

            WebSocketServerWrappe.SendPackgeWithUser(this.Context.Session.User.Uid, 1027, a1027Respose.Build().ToByteArray());



            return(null);
        }
Ejemplo n.º 22
0
        /// <summary>
        /// 开局胡
        /// </summary>
        /// <param name="uid"></param>
        /// <param name="huType"></param>
        public void FistHu(string uid, int huType)
        {
            LinkedListNode <CsGamePlayer> node = FindPlayer(uid);

            if (node.Value.ResetEvent.WaitOne(0))
            {
                return;
            }


            A1015Response.Builder response = A1015Response.CreateBuilder();
            response.HuType         = huType;
            response.Uid            = node.Value.PlayerUser.Uid;
            node.Value.FirstHuType |= huType;

            var sendByte = response.Build().ToByteArray();

            foreach (var row in this.Players)
            {
                WebSocketServerWrappe.SendPackgeWithUser(row.PlayerUser.Uid, 1015, sendByte);
            }
            node.Value.ResetEvent.Set();
            actionStorage.PushFristHu(uid, huType);
        }
Ejemplo n.º 23
0
        /// <summary>
        /// 碰牌
        /// </summary>
        /// <param name="uid"></param>
        /// <param name="card"></param>
        public void Peng(string uid, string desUid, int card)
        {
            LinkedListNode <CsGamePlayer> node = FindPlayer(uid);

            foreach (var row in Players)
            {
                if (row.PlayerUser.Uid != desUid && row.PlayerUser.Uid != uid && (row.CheckGang(card) || row.CheckHu(card)))
                {
                    row.ResetEvent.WaitOne();
                }
            }

            if (node.Value.ResetEvent.WaitOne(0))
            {
                return;
            }

            //牌未被杠或胡
            if (this.OutCardState == OutCardState.Normal)
            {
                this.OutCardState = OutCardState.Peng;
                A1011Response.Builder response = A1011Response.CreateBuilder();
                response.Uid  = node.Value.PlayerUser.Uid;
                response.Card = card;
                var array = response.Build().ToByteArray();

                node.Value.Peng(card);
                this.Player = node;
                foreach (var row in this.Players)
                {
                    WebSocketServerWrappe.SendPackgeWithUser(row.PlayerUser.Uid, 1011, array);
                }
                actionStorage.PushPeng(uid, card);
            }
            this.SetAllResetEvent();
        }
Ejemplo n.º 24
0
        public virtual void ReadyGame(string userId)
        {
            LinkedListNode <CsGamePlayer> player = FindPlayer(userId);

            player.Value.IsReady = true;

            if (Players.All(p => p.IsReady))
            {
                CardIndex = 0;
                RandCard();
                SendCard(true);
            }
            else
            {
                A1005Response.Builder a1005Response = A1005Response.CreateBuilder();
                a1005Response.SetUid(userId);

                byte[] responseArray = a1005Response.Build().ToByteArray();
                foreach (var row in this.Players)
                {
                    WebSocketServerWrappe.SendPackgeWithUser(row.PlayerUser.Uid, 1005, responseArray);
                }
            }
        }
Ejemplo n.º 25
0
        public static CsMjGameRoom Cancel(string uid, int roomID, int cancelType)
        {
            CsMjGameRoom room = GetRoomById(roomID);

            if (room != null)
            {
                LinkedListNode <CsGamePlayer> player = room.FindPlayer(uid);

                if (cancelType == 0)
                {
                    player.Value.Cancel = false;
                }
                else
                {
                    player.Value.Cancel = true;
                }
                player.Value.CancelState = true;
            }

            var listPlayer = room.Players.ToList();

            int count = listPlayer.Count(p => p.Cancel == true);

            int cancelStateCount = listPlayer.Count(p => p.CancelState == true);

            //Cancel类型0为通知,1为解散房间,2为不同意取消
            int isCancel = 0;

            if (count > listPlayer.Count() / 2 && cancelStateCount > listPlayer.Count() / 2)
            {
                rooms.TryRemove(roomID, out room);
                roomRemoveKeyBag.Add(roomID);

                foreach (var row in room.Players)
                {
                    CsMjGameRoom tempRoom = null;
                    userRooms.TryRemove(row.PlayerUser.Uid, out tempRoom);
                    row.Cancel      = false;
                    row.CancelState = false;
                }
                isCancel = 1;
            }
            else if (count < listPlayer.Count() / 2 && cancelStateCount > listPlayer.Count() / 2)
            {
                isCancel = 2;
                foreach (var row in room.Players)
                {
                    row.Cancel      = false;
                    row.CancelState = false;
                }
            }

            A1004Response.Builder response = A1004Response.CreateBuilder();

            foreach (var row in listPlayer.FindAll(p => p.CancelState == true))
            {
                A1004User.Builder user = A1004User.CreateBuilder();
                user.SetUid(row.PlayerUser.Uid);
                user.SetIsCancel(row.Cancel ? 1 : 0);
                user.Name = row.PlayerUser.NickName;
                response.AddUsers(user);
            }
            response.SetCancelType(isCancel);

            byte[] responseArray = response.Build().ToByteArray();

            foreach (var row in room.Players)
            {
                WebSocketServerWrappe.SendPackgeWithUser(row.PlayerUser.Uid, 1004, responseArray);
            }

            return(room);
        }
Ejemplo n.º 26
0
        public override byte[] ProcessAction()
        {
            A1001Response.Builder response = A1001Response.CreateBuilder();
            GameUserMapping       mapping  = RedisContext.GlobalContext.FindHashEntityByKey <GameUserMapping>(Context.HttpQueryString["Uid"].ToString());

            GameUser user = null;

            if (mapping == null)
            {
                user            = new GameUser();
                user.RoomCard   = 8;
                user.OnlimeDate = DateTime.Now;

                mapping = new GameUserMapping();

                mapping.Uid    = Context.HttpQueryString["Uid"].ToString();
                mapping.UserId = RedisContext.GlobalContext.HashLength(mapping);
                RedisContext.GlobalContext.AddHashEntity(mapping);
            }
            else
            {
                user = RedisContext.GlobalContext.FindHashEntityByKey <GameUser>(mapping.UserId.ToString());
                if (int.Parse(user.OnlimeDate.ToString("yyyyMMdd")) < int.Parse(DateTime.Now.ToString("yyyyMMdd")))
                {
                    user.RoomCard += 2;
                }
            }

            user.OnlimeDate = DateTime.Now;
            user.Uid        = mapping.UserId.ToString();
            user.NickName   = Context.HttpQueryString["Nickname"].ToString();
            user.Sex        = int.Parse(Context.HttpQueryString["Sex"].ToString());
            user.Province   = Context.HttpQueryString["Province"].ToString();
            user.City       = Context.HttpQueryString["City"].ToString();
            user.Country    = Context.HttpQueryString["Country"].ToString();
            user.HeadImgurl = Context.HttpQueryString["Headimgurl"].ToString();

            RedisContext.GlobalContext.AddHashEntity(user);


            CsMjGameRoom room = CsGameRoomManager.GetRoomByUserId(user.Uid);

            if (room != null)
            {
                var currentPlayer = room.FindPlayer(user.Uid);
                response.RoomId   = room.RoomId;
                response.RoomType = room.RoomType;

                if (room.Players.Count == 4)
                {
                    response.IsEnd = room.IsEnd ? 1 : 0;
                    if (!room.IsEnd)
                    {
                        response.IsFrist    = room.IsFrist ? 1 : 0;
                        response.CurrentUid = room.Player.Value.PlayerUser.Uid;
                        response.AddRangeNeedGangDaPai(currentPlayer.Value.NeedGangDaPai);
                        response.AddRangeCurrentCard(room.CurrentCard);
                        response.HaidiPai = currentPlayer.Value.HaidiPai;
                    }
                }

                A9997ClientConnectionResponse.Builder a9997Response =
                    A9997ClientConnectionResponse.CreateBuilder();

                a9997Response.Uid = user.Uid;

                byte[] a9997Array = a9997Response.Build().ToByteArray();

                foreach (var row in room.Players)
                {
                    A1001User.Builder roomUser = A1001User.CreateBuilder();
                    roomUser.Uid = row.PlayerUser.Uid;

                    if (row.ChiCards != null && row.ChiCards.Count > 0)
                    {
                        roomUser.AddRangeChiArray(row.ChiCards);
                    }

                    if (row.PengCards != null && row.PengCards.Count > 0)
                    {
                        roomUser.AddRangePengArray(row.PengCards);
                    }
                    if (row.GangCards != null && row.GangCards.Count > 0)
                    {
                        roomUser.AddRangeGangArray(row.GangCards);
                    }
                    if (row.wCards != null && row.wCards.Count > 0)
                    {
                        roomUser.AddRangeWArray(row.wCards);
                        roomUser.WNumber      = row.wNumber;
                        roomUser.WTotalNumber = row.twNumber;
                    }

                    if (row.tCards != null && row.tCards.Count > 0)
                    {
                        roomUser.AddRangeTArray(row.tCards);
                        roomUser.TNumber      = row.tNumber;
                        roomUser.TTotalNumber = row.ttNumber;
                    }


                    if (row.sCards != null && row.sCards.Count > 0)
                    {
                        roomUser.AddRangeSArray(row.sCards);
                        roomUser.SNumber      = row.sNumber;
                        roomUser.STotalNumber = row.tsNumber;
                    }

                    if (row.zhuoCards != null && row.zhuoCards.Count > 0)
                    {
                        roomUser.AddRangeOutCard(row.zhuoCards);
                    }

                    if (row.AnGangCards != null && row.AnGangCards.Count > 0)
                    {
                        roomUser.AddRangeAnGangArray(row.AnGangCards);
                    }
                    if (row.BuZhangCards != null && row.BuZhangCards.Count > 0)
                    {
                        roomUser.AddRangeBuZhangArray(row.BuZhangCards);
                    }


                    roomUser.Name     = row.PlayerUser.NickName;
                    roomUser.HatImage = row.PlayerUser.HeadImgurl;
                    roomUser.Sex      = row.PlayerUser.Sex;
                    roomUser.HuType   = row.HuType;
                    roomUser.Sore     = row.Score;


                    response.AddUsers(roomUser);

                    WebSocketServerWrappe.SendPackgeWithUser(row.PlayerUser.Uid, 9997, a9997Array);
                }

                if (room.JuShu != 0)
                {
                    response.JuShu = room.JuShu;
                }
                if (room.CardIndex != 0)
                {
                    response.ZhangShu = room.CardIndex + 1;
                }
            }


            response.Uid          = user.Uid;
            response.ImageUrl     = user.HeadImgurl;
            response.NickName     = user.NickName;
            response.RoomCard     = user.RoomCard;
            response.FriendNumber = user.FriendNumber;
            response.IsLingQu     = user.IsLingQu;

            Context.Session.User = user;
            GameUserManager.AddOrUpdateUser(user.Uid, Context.Session);
            return(response.Build().ToByteArray());
        }
Ejemplo n.º 27
0
        static void Main(string[] args)
        {
            RedisContext.InitRedisContext("localhost,allowAdmin=true", Assembly.GetAssembly(typeof(Program)));
            ControllerFactory.InitController(Assembly.GetAssembly(typeof(Program)));
            ControllerBase.InitGameUserType <GameUser>();
            WebSocketServerWrappe.Init(ConfigurationManager.AppSettings["ip"], int.Parse(ConfigurationManager.AppSettings["port"]));
            WebSocketServerWrappe.OnErrorMessage = (message, exption) =>
            {
                LogManager.Log.Error(message, exption);
                A9999DataErrorResponse.Builder response = A9999DataErrorResponse.CreateBuilder();
                response.ErrorCode = 9999;
                response.ErrorInfo = "服务器繁忙!";
                return(response.Build().ToByteArray());
            };

            WebSocketServerWrappe.OnRevice = (message) =>
            {
                LogManager.Log.Debug("收到消息:" + message);
            };

            WebSocketServerWrappe.OnSend = (message) =>
            {
                LogManager.Log.Debug("发送消息:" + ByteUtil.ByteToHex(message));
            };

            WebSocketServerWrappe.OnOpen = (message) =>
            {
                LogManager.Log.Debug("收到连接:" + message);
            };

            WebSocketServerWrappe.OnClose = (message, user) =>
            {
                LogManager.Log.Debug("客户端断开:" + message);
                if (user != null)
                {
                    CsMjGameRoom room = CsGameRoomManager.GetRoomByUserId(user.Uid);

                    if (room != null)
                    {
                        A9998ClientCloseResponse.Builder response = A9998ClientCloseResponse.CreateBuilder();
                        response.Uid = user.Uid;

                        var responseArray = response.Build().ToByteArray();

                        foreach (var row in room.Players)
                        {
                            WebSocketServerWrappe.SendPackgeWithUser(row.PlayerUser.Uid, 9998, responseArray);
                        }
                    }
                }
            };

            WebSocketServerWrappe.DesKey  = "f1u2c3k4";
            WebSocketServerWrappe.DesIv   = "N1Q2J3C4";
            WebSocketServerWrappe.SignKey = "3f261d4f2f8941eafffffcf7507f021b";


            MQServer.RunMQ((object o) =>
            {
                SerializerUtil.JavaScriptJosnDeserialize <AddUserRoomCard>(o.ToString()).Process();
            });

            LogManager.Log.Info("服务器启动成功端口9001");



            Console.ReadKey();
        }
Ejemplo n.º 28
0
        /// <summary>
        /// 杠打牌
        /// </summary>
        /// <param name="uid"></param>
        /// <param name="card1"></param>
        /// <param name="card2"></param>
        public void GangDaPai(string uid, int card1, int card2)
        {
            LinkedListNode <CsGamePlayer> node = FindPlayer(uid);

            this.Player       = node;
            this.OutCardState = OutCardState.Normal;

            if (card1 != -1 && card2 != -1)
            {
                A1020Response.Builder response = A1020Response.CreateBuilder();
                response.Card1 = card1;
                response.Card2 = card2;
                response.Uid   = uid;
                byte[] responseArray = response.Build().ToByteArray();

                node.Value.zhuoCards.Add(card1);
                node.Value.zhuoCards.Add(card2);

                node.Value.NeedGangDaPai.Clear();

                this.CurrentCard.Clear();
                this.CurrentCard.Add(card1);
                this.CurrentCard.Add(card2);


                foreach (var row in Players)
                {
                    row.ResetEvent.Reset();
                    WebSocketServerWrappe.SendPackgeWithUser(row.PlayerUser.Uid, 1020, responseArray);
                }

                var prePlayer = this.Player.NextOrFirst();

                if (prePlayer.Value.CheckChi(card1) || prePlayer.Value.CheckChi(card2))
                {
                    prePlayer.Value.ResetEvent.WaitOne();
                    if (this.OutCardState != OutCardState.Normal)
                    {
                        return;
                    }
                }

                foreach (var row in Players)
                {
                    if (row.PlayerUser.Uid != this.Player.Value.PlayerUser.Uid)
                    {
                        if (row.CheckGang(card1) || row.CheckPeng(card1) || row.CheckHu(card1) ||
                            row.CheckGang(card2) || row.CheckPeng(card2) || row.CheckHu(card2))
                        {
                            row.ResetEvent.WaitOne();
                            if (this.OutCardState != OutCardState.Normal)
                            {
                                return;
                            }
                            continue;
                        }
                    }
                }
            }

            this.Player = this.Player.NextOrFirst();
            //是最后一张牌发送海底命令
            if (this.CardIndex == cardArray.Length - 1)
            {
                A1016Response.Builder rep1016 = A1016Response.CreateBuilder();
                rep1016.Uid = this.Player.Value.PlayerUser.Uid;
                var rep1016Array = rep1016.Build().ToByteArray();
                foreach (var row in Players)
                {
                    WebSocketServerWrappe.SendPackgeWithUser(row.PlayerUser.Uid, 1016, rep1016Array);
                }
            }
            else
            {
                Mo(this.Player.Value.PlayerUser.Uid);
            }
        }
Ejemplo n.º 29
0
        /// <summary>
        /// 打牌
        /// </summary>
        /// <param name="uid"></param>
        /// <param name="card"></param>
        public void Da(string uid, int card)
        {
            if (uid != this.Player.Value.PlayerUser.Uid)
            {
                LogManager.Log.Debug("没有轮到" + uid + "打牌");
                return;
            }

            if (this.IsFrist)
            {
                foreach (var row in Players)
                {
                    if ((row.CheckKaiJuHu()) && row.PlayerUser.Uid != uid)
                    {
                        LogManager.Log.Debug("开局胡等待" + row.PlayerUser.Uid + "wait");
                        row.ResetEvent.WaitOne();
                        LogManager.Log.Debug("开局胡等待处理完毕" + row.PlayerUser.Uid + "wait");
                    }
                }
            }

            LogManager.Log.Debug("通过开局胡检查");
            this.IsFrist = false;
            this.Player.Value.DaCard(card);

            actionStorage.PushDa(uid, card);

            //为了记录打出的最后牌,为了断线重连状态保存
            this.CurrentCard.Clear();
            this.CurrentCard.Add(card);

            this.OutCardState = OutCardState.Normal;
            A1007Response.Builder response = A1007Response.CreateBuilder();
            response.Card = card;
            response.Uid  = uid;
            byte[] responseArray = response.Build().ToByteArray();

            foreach (var row in Players)
            {
                row.ResetEvent.Reset();
                WebSocketServerWrappe.SendPackgeWithUser(row.PlayerUser.Uid, 1007, responseArray);
            }

            LogManager.Log.Debug("当前玩家" + this.Player.Value.PlayerUser.Uid + "后续玩家" + this.Player.NextOrFirst().Value.PlayerUser.Uid);
            var prePlayer = this.Player.NextOrFirst();

            LogManager.Log.Debug("检查吃" + prePlayer.Value.PlayerUser.Uid + "是否可以吃" + card.GetItemValue() + "类型" + card.GetItemType());

            if (prePlayer.Value.CheckChi(card))
            {
                LogManager.Log.Debug(prePlayer.Value.PlayerUser.Uid + "手上的牌" + prePlayer.Value.PrintCards());
                LogManager.Log.Debug("吃" + prePlayer.Value.PlayerUser.Uid);
                prePlayer.Value.ResetEvent.WaitOne();
                if (this.OutCardState != OutCardState.Normal)
                {
                    return;
                }
            }

            foreach (var row in Players)
            {
                LogManager.Log.Debug(row.PlayerUser.Uid + "手上的牌" + row.PrintCards());

                if (row.PlayerUser.Uid != this.Player.Value.PlayerUser.Uid)
                {
                    if (row.CheckGang(card) || row.CheckPeng(card) || row.CheckHu(card))
                    {
                        LogManager.Log.Debug("等待玩家操作" + row.PlayerUser.Uid + "牌:" + card.GetItemValue());
                        row.ResetEvent.WaitOne();
                        LogManager.Log.Debug("等待玩家操作完毕" + row.PlayerUser.Uid + "牌:" + card.GetItemValue());
                        if (this.OutCardState != OutCardState.Normal)
                        {
                            return;
                        }
                        continue;
                    }
                }
            }

            this.Player = this.Player.NextOrFirst();
            //是最后一张牌发送海底命令
            if (this.CardIndex == cardArray.Length - 1)
            {
                A1016Response.Builder rep1016 = A1016Response.CreateBuilder();
                rep1016.Uid = this.Player.Value.PlayerUser.Uid;
                var rep1016Array = rep1016.Build().ToByteArray();
                foreach (var row in Players)
                {
                    WebSocketServerWrappe.SendPackgeWithUser(row.PlayerUser.Uid, 1016, rep1016Array);
                }
            }
            else
            {
                Mo(this.Player.Value.PlayerUser.Uid);
            }
        }
Ejemplo n.º 30
0
        protected override void SendCard(Boolean isReady)
        {
            if (this.JuShu == 9)
            {
                GameUser user = RedisContext.GlobalContext.FindHashEntityByKey <GameUser>(this.RoomMagaerUid);


                user.RoomCard--;
                RedisContext.GlobalContext.AddHashEntity(user);

                //房主茶卷不足
                if (user.RoomCard <= 0)
                {
                    A9999DataErrorResponse.Builder error = A9999DataErrorResponse.CreateBuilder();
                    error.ErrorCode = 5;
                    error.ErrorInfo = ErrorInfo.ErrorDic[5];
                    byte[] responseByte = error.Build().ToByteArray();
                    foreach (var row in this.Players)
                    {
                        WebSocketServerWrappe.SendPackgeWithUser(row.PlayerUser.Uid, 9999, responseByte);
                    }
                    return;
                }

                foreach (var row in this.Players)
                {
                    row.HuType   = 0;
                    row.Score    = 1000;
                    row.SubScore = 0;
                    row.AddScore = 0;
                    this.JuShu   = 1;
                }
            }

            if (this.Player == null)
            {
                this.Player = this.Players.First;
            }



            //庄为链表结构,设置庄
            var temp1 = this.Player.Value;
            var temp2 = this.Player.NextOrFirst().Value;
            var temp3 = this.Player.NextOrFirst().NextOrFirst().Value;

            this.Players.First.Value = temp1;
            this.Players.First.NextOrFirst().Value = temp2;
            this.Players.First.NextOrFirst().NextOrFirst().Value = temp3;
            this.Player = this.Players.First;



            var downArray  = cardArray.Take(14).ToArray();
            var rigthArray = cardArray.Skip(14).Take(13).ToArray();
            var topArray   = cardArray.Skip(27).Take(13).ToArray();


            Players.First.Value.InitCard(downArray);
            Players.First.Next.Value.InitCard(rigthArray);
            Players.First.Next.Next.Value.InitCard(topArray);


            var response = A1006Response.CreateBuilder();

            response.ZhuangUid = this.Player.Value.PlayerUser.Uid;
            response.JuShu     = this.JuShu;
            response.Zhangshu  = 55;

            var player1 = ProtoEntity.Player.CreateBuilder();

            player1.AddRangeCard(downArray);
            player1.SetScore(this.Player.Value.Score);
            player1.SetUid(this.Player.Value.PlayerUser.Uid);
            response.AddUsers(player1);

            var player2 = ProtoEntity.Player.CreateBuilder();

            player2.AddRangeCard(rigthArray);
            player2.SetScore(this.Player.NextOrFirst().Value.Score);
            player2.SetUid(this.Player.NextOrFirst().Value.PlayerUser.Uid);
            response.AddUsers(player2);

            var player3 = ProtoEntity.Player.CreateBuilder();

            player3.AddRangeCard(topArray);
            player3.SetScore(this.Player.NextOrFirst().NextOrFirst().Value.Score);
            player3.SetUid(this.Player.NextOrFirst().NextOrFirst().Value.PlayerUser.Uid);
            response.AddUsers(player3);


            A1003AndA1006Response.Builder responseBase = !isReady?this.Create1003And1006Req(this.Players.Count) : A1003AndA1006Response.CreateBuilder();

            responseBase.A1006Req = response.Build();
            foreach (var row in this.Players)
            {
                row.ReLoad();
                WebSocketServerWrappe.SendPackgeWithUser(row.PlayerUser.Uid, 10036, responseBase.Build().ToByteArray());
            }

            this.CardIndex = 40;
            IsFrist        = true;
            dianPaoNumber  = 0;
            haiGuoNumber   = 0;
            this.CurrentCard.Clear();
            this.IsEnd = false;
            this.JuShu++;


            //存储动作
            List <CmdPlayer> lCmdPlayer = new List <CmdPlayer>();

            lCmdPlayer.Add(new CmdPlayer
            {
                Uid   = player1.Uid,
                Cards = downArray.ToList()
            });
            lCmdPlayer.Add(new CmdPlayer
            {
                Uid   = player2.Uid,
                Cards = rigthArray.ToList()
            });

            lCmdPlayer.Add(new CmdPlayer
            {
                Uid   = player3.Uid,
                Cards = topArray.ToList()
            });
            actionStorage = new GameActionStoreage(lCmdPlayer);
        }