public static void RequestAction(Table t, Player p, string gameStage) { // this will wait with the client player and seek an action Message m = new Message("RequestBet", MessageType.PlayerActionRequestBet); m.Content = t.TableNo + ":" + t.GetPotSize().ToString() + ":" + p.getPostedBetSoFar(gameStage) + ":" + t.GetCurrentMinBet().ToString() + ":" + t.GetCurrentMaxRaisingBet().ToString() + ":" + gameStage; // Add more elements like min and max bet size etc later lock (t) // this will synchronize this call with any previous pending call to SendToTablePlayers { SendMessageToPlayer(p, m); } }
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); } } } ); }