Exemplo n.º 1
0
        public override bool OnHandleMessage(IMessage message, IServerPeer sPeer)
        {
            Log.DebugFormat("TexasDepositSuccessHandler");


            var serverPeer = sPeer as ServerOutbouncePeer;

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

            if (!operation.IsValid)
            {
                Log.DebugFormat("TexasDepositSuccessHandler no Good :: " + operation.GetErrorMessage());


                return(false);
            }

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

            var facade = GameApplicationBase.GetRoom(roomId);

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

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

            if (userItem == null)
            {
                Log.DebugFormat("TexasDepositSuccessHandler user not found ");
                return(false);
            }

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

            var userKey = userItem.UserKey;

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

            Slot player = texasModel.getSlot(userKey);

            if (player != null)
            {
                player.CurrentCredit -= amount;
            }

            var param = new Dictionary <byte, object>()
            {
                { (byte)ServerParameterCode.PeerId, message.Parameters[(byte)ServerParameterCode.PeerId] },
                { (byte)ServerParameterCode.SubOperationCode, message.Parameters[(byte)ServerParameterCode.SubOperationCode] },
                { (byte)RoomParameterCode.RoomID, roomId },
                { (byte)RoomParameterCode.DepositAmount, amount },
                { (byte)RoomParameterCode.GameCredit, player.CurrentCredit },

                { (byte)RoomParameterCode.RoomUser, JsonConvert.SerializeObject(userItem) }
            };

            serverPeer.SendMessage(new Response((byte)RoomOperationCode.Deposit, null, param, "Deposit Success", (int)RoomErrorCode.OK));
            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;
             */
        }
        public override bool OnHandleMessage(IMessage message, IServerPeer sPeer)
        {
            Log.DebugFormat("TexasBuyinSuccessHandler");

            var serverPeer = sPeer as ServerOutbouncePeer;

            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;

            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)
            {
                player.CurrentCredit += amount;
                Dictionary <byte, object> param = new Dictionary <byte, object>()
                {
                    { (byte)ServerParameterCode.PeerId, message.Parameters[(byte)ServerParameterCode.PeerId] },
                    { (byte)ServerParameterCode.SubOperationCode, message.Parameters[(byte)ServerParameterCode.SubOperationCode] },
                    { (byte)RoomParameterCode.RoomID, roomId },
                    { (byte)RoomParameterCode.WithdrawAmount, amount },
                    { (byte)RoomParameterCode.GameCredit, player.CurrentCredit },

                    { (byte)RoomParameterCode.RoomUser, JsonConvert.SerializeObject(userItem) }
                };
                serverPeer.SendMessage(new Response((byte)RoomOperationCode.Withdraw, null, param, "Buyin Success", (int)RoomErrorCode.OK));

                TexasBuyin texasBuyIn = new TexasBuyin();
                texasBuyIn.BuyinInfo           = new BuyinInfo();
                texasBuyIn.BuyinInfo.AvatarKey = player.AvatarKey;
                texasBuyIn.BuyinInfo.Credit    = player.CurrentCredit;
                texasBuyIn.BuyinInfo.Index     = texasModel.getSlotIndex(player);
                texasBuyIn.BuyinInfo.UserKey   = player.UserKey;
                texasBuyIn.BuyinInfo.UserName  = player.UserName;

                param = new Dictionary <byte, object>()
                {
                    { (byte)ParameterCode.TexasBuyin, JsonConvert.SerializeObject(texasBuyIn) },
                };

                var eevent = new Event((byte)TexasEventCode.BuyIn, null, param);

                facade.SendNotification(RoomNotification.SEND_EVENT_TO_ALL_USER, eevent);
            }
            return(true);
        }