public static void SendPlayerBankBalanceMessage(PokerUser user)
        {
            Poker.Shared.Message     m    = new Shared.Message("PlayerBankBalance", MessageType.PlayerBankBalance);
            Tuple <decimal, decimal> temp = PlayerBankingService.Instance().GetBankBalance(user.UserName);
            string temp1 = temp.Item1.ToString() + ";" + temp.Item2.ToString();

            m.Content = temp1;
            if ((user != null) && (user.TcpClient != null) && (user.TcpClient.Connected))
            {
                user.SendMessage(m);
            }
        }
Beispiel #2
0
        public void RemovePlayer(Player p)
        {
            // find player where he is seated and remove him
            bool success = false;

            foreach (Seat seat in _seats.Keys)
            {
                if (_seats[seat] == p)
                {
                    _seats[seat] = new Player(null, this, 0);
                    seat.RemovePlayer(p);
                    success = true;
                    //RemovedPlayer = p;
                    break;
                }
            }
            if (success)
            {
                PlayerBankingService.Instance().UpdateBankBalanceInUse(p.UserName, -1 * p.ChipCount);
            }
        }
Beispiel #3
0
        private void ProcessIncomingMessage(Message m)
        {
            //lock (lock_for_ProcessIncomingMessage)
            Task.Run(() =>
            {
                if (m != null)
                {
                    Console.WriteLine("Inside ProcessinomingMessage " + m.Content);
                    if (m.MessageType == MessageType.PlayerSigningIn)
                    {
                        string[] arr = m.Content.Split(':');
                        UserName     = arr[0];
                        MessageFactory.SendCasinoMessage(this);
                        // Also send the Player Bank Balance
                        MessageFactory.SendPlayerBankBalanceMessage(this);
                    }
                    if (m.MessageType == MessageType.PlayerJoiningGame)
                    {
                        string[] arr      = m.Content.Split(':');
                        string tableNo    = arr[0];
                        short seatNo      = Convert.ToInt16(arr[1]);
                        decimal chipCount = Convert.ToDecimal(arr[2]);
                        Table t           = TableManager.Instance.GetTable(tableNo);
                        if (chipCount >= 0)
                        {
                            t.AddPlayer(new Player(this, t, chipCount), seatNo);
                            PlayerBankingService.Instance().UpdateBankBalanceInUse(this.UserName, chipCount);
                            MessageFactory.SendPlayerBankBalanceMessage(this);
                        }
                        else
                        {
                            t.RemovePlayerEx(seatNo);
                        }
                    }
                    if (m.MessageType == MessageType.PlayerAction)
                    {
                        string[] arr     = m.Content.Split(':');
                        string tableNo   = arr[0];
                        decimal betsize  = Convert.ToDecimal(arr[1]);
                        string gameStage = arr[2];

                        Table t = TableManager.Instance.GetTable(tableNo);
                        // set the wait to the receieve action for the player
                        lock (t.SynchronizeGame)
                        {
                            Player p = t.GetPlayer(this);
                            if (betsize < 0)
                            {
                                // player wants to fold the hand.

                                p.FoldHand();
                            }
                            else
                            {
                                // update player bank account
                                PlayerBankingService.Instance().UpdateBankBalanceInUse(this.UserName, betsize);
                                // updated player posted bet
                                p.Bet(betsize, gameStage);
                                //update pot size
                                t.AddToPot(betsize, p);
                                //update calling bet size
                                t.SetCurrentMinBet(p.getPostedBetSoFar(gameStage));
                                //send message to other plaeyrs on the table about the action from this user
                                Message m1 = new Message("Bets " + betsize.ToString(), MessageType.PlayerAction);
                                m1.Content = t.TableNo + ":" + t.GetPlayerSeatNo(p).ToString() + ":" + "Calls " + betsize.ToString() + ":" + t.GetPotSize().ToString();
                                MessageFactory.SendToTablePlayers(t, m1);
                            }
                            Monitor.PulseAll(t.SynchronizeGame);
                        }
                        Console.WriteLine("Received Bet from player " + this.UserName + " for size = " + betsize);
                    }
                }
            }
                     );
        }