public override bool OnHandleMessage(IMessage message, IServerPeer sPeer)
        {
            Log.DebugFormat("OnHandleMessage:TexasSitHandler");

            var errorParam = new Dictionary <byte, object>
            {
                { (byte)ServerParameterCode.PeerId, message.Parameters[(byte)ServerParameterCode.PeerId] },
                { (byte)ClientParameterCode.SubOperationCode, message.Parameters[(byte)ClientParameterCode.SubOperationCode] },
            };

            var serverPeer = sPeer as ServerOutbouncePeer;
            var operation  = new SitOperator(serverPeer.Protocol, message);

            if (!operation.IsValid)
            {
                serverPeer.SendMessage(new Response((byte)TexasOperationCode.Sit, null, errorParam, operation.GetErrorMessage(), (int)RoomErrorCode.OperationInvalid));
                return(false);
            }
            var peerId = new Guid((Byte[])operation.PeerId);

            var roomID = operation.RoomID;

            errorParam.Add((byte)RoomParameterCode.RoomID, roomID);

            var facade = TexasApplication.GetRoom(roomID);

            if (facade == null)
            {
                serverPeer.SendMessage(new Response((byte)TexasOperationCode.Sit, null, errorParam, "RoomId Not Found", (int)RoomErrorCode.RoomIdNotFound));
                return(false);
            }
            var userItem = TexasApplication.GetRoomUser(roomID, peerId);

            if (userItem == null)
            {
                serverPeer.SendMessage(new Response((byte)TexasOperationCode.Sit, null, errorParam, "User Not Yet Join Room", (int)RoomErrorCode.UserNotYetJoinRoom));
                return(false);
            }

            var          json         = operation.TexasSitDown;
            TexasSitDown texasSitDown = JsonConvert.DeserializeObject <TexasSitDown>(json) as TexasSitDown;

            texasSitDown.sisDownInfo.UserKey  = userItem.UserKey;
            texasSitDown.sisDownInfo.UserName = userItem.UserName;

            var texasRoomItem = TexasApplication.GetRoomItem(roomID);

            if (userItem.BankBalance < texasRoomItem.WithdrawMin && texasSitDown.sisDownInfo.IsSitDown)
            {
                serverPeer.SendMessage(new Response((byte)TexasOperationCode.Sit, null, errorParam, "Need $" + texasRoomItem.WithdrawMin + " to play", (int)RoomErrorCode.AmountTooLow));
                return(false);
            }

            var stateMachine = facade.RetrieveMediator(TexasStateMachine.NAME) as TexasStateMachine;

            stateMachine.Sit(texasSitDown);

            return(true);
        }
        public override bool OnHandleMessage(IMessage message, IServerPeer sPeer)
        {
            Log.DebugFormat("OnHandleMessage:TexasStatusHandler");

            var errorParam = new Dictionary <byte, object>
            {
                { (byte)ServerParameterCode.PeerId, message.Parameters[(byte)ServerParameterCode.PeerId] },
                { (byte)ClientParameterCode.SubOperationCode, message.Parameters[(byte)ClientParameterCode.SubOperationCode] },
            };

            var serverPeer = sPeer as ServerOutbouncePeer;
            var operation  = new StatusOperator(serverPeer.Protocol, message);


            if (!operation.IsValid)
            {
                serverPeer.SendMessage(new Response((byte)TexasOperationCode.Status, null, errorParam, operation.GetErrorMessage(), (int)RoomErrorCode.OperationInvalid));
                return(false);
            }
            var peerId = new Guid((Byte[])operation.PeerId);

            var roomID = operation.RoomID;

            errorParam.Add((byte)RoomParameterCode.RoomID, roomID);
            var facade = TexasApplication.GetRoom(roomID);

            if (facade == null)
            {
                serverPeer.SendMessage(new Response((byte)TexasOperationCode.Status, null, errorParam, "RoomId Not Found", (int)RoomErrorCode.RoomIdNotFound));
                return(false);
            }
            var userItem = TexasApplication.GetRoomUser(roomID, peerId);

            if (userItem == null)
            {
                serverPeer.SendMessage(new Response((byte)TexasOperationCode.Status, null, errorParam, "User Not Yet Join Room", (int)RoomErrorCode.UserNotYetJoinRoom));
                return(false);
            }

            var texasModel  = facade.RetrieveProxy(TexasModel.NAME) as TexasModel;
            var texasStatus = texasModel.buildTexasHoldemStatus();


            var param = new Dictionary <byte, object>
            {
                { (byte)ServerParameterCode.PeerId, message.Parameters[(byte)ServerParameterCode.PeerId] },
                { (byte)ClientParameterCode.SubOperationCode, message.Parameters[(byte)ClientParameterCode.SubOperationCode] },
                { (byte)RoomParameterCode.RoomID, roomID },
                { (byte)ParameterCode.TexasStatus, JsonConvert.SerializeObject(texasStatus) },
            };

            serverPeer.SendMessage(new Response((byte)TexasOperationCode.Status, null, param, "Texas Status Success", (int)RoomErrorCode.OK));

            return(true);
        }
Example #3
0
        protected override void Setup()
        {
            base.Setup();

            var defaultRooms = Container.Resolve <IEnumerable <GameDefaultRoomConfig> >();

            foreach (var roomItem in defaultRooms)
            {
                TexasApplication.CreateRoom(ServerApplication, roomItem.Room);
                Log.InfoFormat("Default Room" + roomItem.Room.RoomID);
            }
        }
Example #4
0
        public override bool OnHandleMessage(IMessage message, IServerPeer sPeer)
        {
            Log.DebugFormat("OnHandleMessage:TexasStartGameHandler");

            var errorParam = new Dictionary <byte, object>
            {
                { (byte)ServerParameterCode.PeerId, message.Parameters[(byte)ServerParameterCode.PeerId] },
                { (byte)ClientParameterCode.SubOperationCode, message.Parameters[(byte)ClientParameterCode.SubOperationCode] },
            };

            var serverPeer = sPeer as ServerOutbouncePeer;
            var operation  = new StartGameOperator(serverPeer.Protocol, message);


            if (!operation.IsValid)
            {
                serverPeer.SendMessage(new Response((byte)TexasOperationCode.StartGame, null, errorParam, operation.GetErrorMessage(), (int)RoomErrorCode.OperationInvalid));
                return(false);
            }
            var peerId = new Guid((Byte[])operation.PeerId);

            var roomID = operation.RoomID;

            errorParam.Add((byte)RoomParameterCode.RoomID, roomID);
            var facade = TexasApplication.GetRoom(roomID);

            if (facade == null)
            {
                serverPeer.SendMessage(new Response((byte)TexasOperationCode.StartGame, null, errorParam, "RoomId Not Found", (int)RoomErrorCode.RoomIdNotFound));
                return(false);
            }
            var userItem = TexasApplication.GetRoomUser(roomID, peerId);

            if (userItem == null)
            {
                serverPeer.SendMessage(new Response((byte)TexasOperationCode.StartGame, null, errorParam, "User Not Yet Join Room", (int)RoomErrorCode.UserNotYetJoinRoom));
                return(false);
            }

            // check 4 man
            string         json           = operation.TexasStartGame;
            TexasStartGame texasStartGame = JsonConvert.DeserializeObject <TexasStartGame>(json) as TexasStartGame;

            // Log.DebugFormat("TEXAS GAME VALIDATE");

            // var stateMachine = facade.RetrieveMediator(TexasStateMachine.NAME) as TexasStateMachine;

            var stateMachine = facade.RetrieveMediator(TexasStateMachine.NAME) as TexasStateMachine;

            stateMachine.StartGame(texasStartGame);
            return(true);
        }
        public override bool OnHandleMessage(IMessage message, IServerPeer serverPeer)
        {
            if (base.OnHandleMessage(message, serverPeer))
            {
                Log.InfoFormat("CreateRoomTexasHandler :: " + roomItem.Name);

                //create room handle in application
                if (TexasApplication.CreateRoom(ServerApplication, roomItem))
                {
                    var param = new Dictionary <byte, object>()
                    {
                        { (byte)ServerParameterCode.PeerId, message.Parameters[(byte)ServerParameterCode.PeerId] },
                        { (byte)ClientParameterCode.SubOperationCode, message.Parameters[(byte)ClientParameterCode.SubOperationCode] },
                        { (byte)RoomParameterCode.Item, JsonConvert.SerializeObject(roomItem) },
                        { (byte)ClientParameterCode.ModuleId, message.Parameters[(byte)ClientParameterCode.ModuleId] },
                    };
                    var responseMessage = new Response((byte)RoomOperationCode.Create, null, param, "Room Create Success", (byte)ErrorCode.OK);
                    serverPeer.SendMessage(responseMessage);
                }
            }

            return(true);
        }
        public override bool OnHandleMessage(IMessage message, IServerPeer sPeer)
        {
            Log.DebugFormat("TEXASWithdrawRoomHandler  ");
            var serverPeer = sPeer as ServerOutbouncePeer;
            var errorParam = new Dictionary <byte, object>
            {
                { (byte)ServerParameterCode.PeerId, message.Parameters[(byte)ServerParameterCode.PeerId] },
                { (byte)ClientParameterCode.SubOperationCode, message.Parameters[(byte)ClientParameterCode.SubOperationCode] },
            };

            var operation = new BuyinSuccessOperator(serverPeer.Protocol, message);

            if (!operation.IsValid)
            {
                return(false);
            }

            var roomId = operation.RoomID;
            var peerId = new Guid((Byte[])operation.PeerId);
            var amount = operation.Amount;

            errorParam.Add((byte)RoomParameterCode.RoomID, roomId);

            Log.DebugFormat("TexasBuyinSuccessHandler: " + roomId + "|" + peerId + "|" + amount);

            var facade = GameApplicationBase.GetRoom(roomId);

            if (facade == null)
            {
                return(false);
            }

            var userItem = GameApplicationBase.GetRoomUser(roomId, peerId);

            if (userItem == null)
            {
                return(false);
            }

            Log.DebugFormat("TexasBuyinSuccessHandler Good :: " + peerId + " " + userItem.UserKey);

            var userKey = userItem.UserKey;

            var texasModel = facade.RetrieveProxy(TexasModel.NAME) as TexasModel;

            Slot player = texasModel.getSlot(userKey);

            if (player == null)
            {
                serverPeer.SendMessage(new Response((byte)RoomOperationCode.Withdraw, null, errorParam, "Player not yet on table", (int)TexasRoomErrorCode.UserNotYetOnTable));
                return(false);
            }
            if (player.isOnGame)
            {
                serverPeer.SendMessage(new Response((byte)RoomOperationCode.Withdraw, null, errorParam, "Player is playing", (int)TexasRoomErrorCode.UserPlaying));
                return(false);
            }

            var texasRoomItem = TexasApplication.GetRoomItem(roomId);

            if (player.CurrentCredit > 30 * texasRoomItem.WithdrawMax / 100)
            {
                serverPeer.SendMessage(new Response((byte)RoomOperationCode.Withdraw, null, errorParam, "Credit is not yet low to withdraw", (int)TexasRoomErrorCode.CreditNotYetLow));
                return(false);
            }
            return(base.OnHandleMessage(message, sPeer));

            /*
             * Log.DebugFormat("WithdrawRoomHandler  ");
             *
             *
             * var serverPeer = sPeer as ServerOutbouncePeer;
             *
             *
             * var errorParam = new Dictionary<byte, object>
             * {
             *  { (byte)ServerParameterCode.PeerId, message.Parameters[(byte)ServerParameterCode.PeerId] },
             *  { (byte)ClientParameterCode.SubOperationCode,message.Parameters[(byte)ClientParameterCode.SubOperationCode]},
             * };
             *
             *
             * var operation = new WithdrawRoomOperator(serverPeer.Protocol, message);
             * if (!operation.IsValid)
             * {
             *
             *  serverPeer.SendMessage(new Response((byte)RoomOperationCode.Withdraw, null, errorParam, operation.GetErrorMessage(), (int)RoomErrorCode.OperationInvalid));
             *  return false;
             * }
             *
             * var roomID = operation.RoomID;
             * var peerId = new Guid((Byte[])operation.PeerId);
             * var amount = operation.Amount;
             * var serverCode = message.Parameters[(byte)ServerParameterCode.SubOperationCode];
             *
             * errorParam.Add((byte)RoomParameterCode.RoomID, roomID);
             *
             * if (amount < 1)
             * {
             *  serverPeer.SendMessage(new Response((byte)RoomOperationCode.Withdraw, null, errorParam, "Amount Withdraw too Low", (int)RoomErrorCode.AmountTooLow));
             *  return false;
             * }
             *
             *
             * var facade = GameApplicationBase.GetRoom(roomID);
             *
             * if (facade == null)
             * {
             *  serverPeer.SendMessage(new Response((byte)RoomOperationCode.Withdraw, null, errorParam, "RoomId Not Found", (int)RoomErrorCode.RoomIdNotFound));
             *  return false;
             *
             * }
             *
             * var userItem = GameApplicationBase.GetRoomUser(roomID, peerId);
             *
             * if (userItem == null)
             * {
             *  serverPeer.SendMessage(new Response((byte)RoomOperationCode.Withdraw, null, errorParam, "User Not Yet Join Room", (int)RoomErrorCode.UserNotYetJoinRoom));
             *  return false;
             * }
             *
             * Log.DebugFormat("WithdrawRoomHandler Good :: " + peerId);
             *
             * var param = new Dictionary<byte, object>
             * {
             *  { (byte)ServerParameterCode.SubOperationCode, serverCode },
             *  { (byte)ServerParameterCode.PeerId, peerId.ToByteArray() },
             *  { (byte)RoomParameterCode.RoomID, roomID },
             *  { (byte)RoomParameterCode.WithdrawAmount, amount },
             *
             * };
             *
             * //send message back to proxy server
             * serverPeer.SendMessage(new Request((byte)ServerOperationCode.Withdraw, null, param));
             *
             * return true;
             */
        }