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);
        }
        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());
        }
Esempio n. 3
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);
        }
        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);
        }
Esempio n. 5
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();
        }