From 26391b57d1899bb2bf0fcb5cb12eef6d0b9771d5 Mon Sep 17 00:00:00 2001 From: lotodore Date: Fri, 26 Dec 2008 23:05:45 +0000 Subject: [PATCH] Console client: Several fixes, added handling of removed from game event. --- console/{COPYING => COPYING.txt} | 0 console/src/ConsoleCallback.cs | 6 ++ console/src/Program.cs | 2 +- console/src/lib/Hand.cs | 8 ++- console/src/lib/ICallback.cs | 1 + console/src/lib/net/INetPacketVisitor.cs | 1 + console/src/lib/net/NetPacket.cs | 6 +- .../src/lib/net/NetPacketRemovedFromGame.cs | 56 +++++++++++++++++++ console/src/lib/net/NetParser.cs | 9 ++- docs/net_protocol.txt | 4 +- 10 files changed, 87 insertions(+), 6 deletions(-) rename console/{COPYING => COPYING.txt} (100%) create mode 100644 console/src/lib/net/NetPacketRemovedFromGame.cs diff --git a/console/COPYING b/console/COPYING.txt similarity index 100% rename from console/COPYING rename to console/COPYING.txt diff --git a/console/src/ConsoleCallback.cs b/console/src/ConsoleCallback.cs index 849177b2..047f41c9 100644 --- a/console/src/ConsoleCallback.cs +++ b/console/src/ConsoleCallback.cs @@ -150,6 +150,12 @@ namespace pokerth_console Console.WriteLine("\n{0} wins the game.", name); } + public void RemovedFromGame() + { + Console.WriteLine("You have left the game."); + System.Environment.Exit(1); + } + public void ChatText(string name, string message) { Console.WriteLine("{0}: {1}", diff --git a/console/src/Program.cs b/console/src/Program.cs index 7a321d46..8d907cd7 100644 --- a/console/src/Program.cs +++ b/console/src/Program.cs @@ -111,7 +111,7 @@ namespace pokerth_console static int Main(string[] args) { Console.WriteLine("pokerth_console V0.1 - Copyright (C) 2008 by Lothar May"); - Console.WriteLine("See license.txt for license terms."); + Console.WriteLine("See COPYING.txt for license terms."); Console.WriteLine(); Console.WriteLine("Enter your nickname:"); string name = Console.ReadLine(); diff --git a/console/src/lib/Hand.cs b/console/src/lib/Hand.cs index 539315fd..c5baaf38 100644 --- a/console/src/lib/Hand.cs +++ b/console/src/lib/Hand.cs @@ -68,7 +68,13 @@ namespace pokerth_lib { lock (m_mutex) { - m_state = value; + if (m_state != value) + { + m_state = value; + // Reset bets. + foreach (KeyValuePair player in m_players) + player.Value.TotalBet = 0; + } } } } diff --git a/console/src/lib/ICallback.cs b/console/src/lib/ICallback.cs index e56786a6..bf074998 100644 --- a/console/src/lib/ICallback.cs +++ b/console/src/lib/ICallback.cs @@ -43,6 +43,7 @@ namespace pokerth_lib void HandResult(); void PlayerWinsHand(string name, uint moneyWon); void PlayerWinsGame(string name); + void RemovedFromGame(); void ChatText(string name, string message); void Error(string message); } diff --git a/console/src/lib/net/INetPacketVisitor.cs b/console/src/lib/net/INetPacketVisitor.cs index 4002a298..441868ca 100644 --- a/console/src/lib/net/INetPacketVisitor.cs +++ b/console/src/lib/net/INetPacketVisitor.cs @@ -52,6 +52,7 @@ namespace pokerth_lib void VisitEndOfHandShowCards(NetPacket p); void VisitEndOfHandHideCards(NetPacket p); void VisitEndOfGame(NetPacket p); + void VisitRemovedFromGame(NetPacket p); void VisitChatText(NetPacket p); void VisitError(NetPacket p); } diff --git a/console/src/lib/net/NetPacket.cs b/console/src/lib/net/NetPacket.cs index bbf53757..0f63b422 100644 --- a/console/src/lib/net/NetPacket.cs +++ b/console/src/lib/net/NetPacket.cs @@ -91,7 +91,6 @@ namespace pokerth_lib public enum PropType { - ErrorReason, RequestedVersionMajor, RequestedVersionMinor, PlayerId, @@ -145,6 +144,8 @@ namespace pokerth_lib BestHandPos5, CardsValue, ChatText, + ErrorReason, + RemoveReason, } public enum ListPropType @@ -222,6 +223,9 @@ namespace pokerth_lib case NetTypeEndOfGame : tmpPacket = new NetPacketEndOfGame(size, reader); break; + case NetTypeRemovedFromGame : + tmpPacket = new NetPacketRemovedFromGame(size, reader); + break; case NetTypeChatText : tmpPacket = new NetPacketChatText(size, reader); break; diff --git a/console/src/lib/net/NetPacketRemovedFromGame.cs b/console/src/lib/net/NetPacketRemovedFromGame.cs new file mode 100644 index 00000000..c442cb5f --- /dev/null +++ b/console/src/lib/net/NetPacketRemovedFromGame.cs @@ -0,0 +1,56 @@ +/*************************************************************************** + * Copyright (C) 2008 by Lothar May * + * * + * This file is part of pokerth_console. * + * pokerth_console is free software: you can redistribute it and/or * + * modify it under the terms of the GNU Affero General Public License * + * as published by the Free Software Foundation, either version 3 of * + * the License, or (at your option) any later version. * + * * + * pokerth_console is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the * + * GNU Affero General Public License along with pokerth_console. * + * If not, see . * + ***************************************************************************/ + +using System; +using System.Collections.Generic; +using System.Text; +using System.Net; +using System.Net.Sockets; +using System.IO; + + +namespace pokerth_lib +{ + class NetPacketRemovedFromGame : NetPacket + { + public NetPacketRemovedFromGame() + : base(NetPacket.NetTypeRemovedFromGame) + { + } + + public NetPacketRemovedFromGame(int size, BinaryReader r) + : base(NetPacket.NetTypeRemovedFromGame) + { + if (size != 8) + throw new NetPacketException("NetPacketRemovedFromGame invalid size."); + Properties.Add(PropType.RemoveReason, + Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16()))); + } + + public override void Accept(INetPacketVisitor visitor) + { + visitor.VisitRemovedFromGame(this); + } + + public override byte[] ToByteArray() + { + throw new NotImplementedException(); + } + } +} diff --git a/console/src/lib/net/NetParser.cs b/console/src/lib/net/NetParser.cs index 50a36ddf..a1070815 100644 --- a/console/src/lib/net/NetParser.cs +++ b/console/src/lib/net/NetParser.cs @@ -199,7 +199,6 @@ namespace pokerth_lib { uint curPlayer = Convert.ToUInt32(p.Properties[NetPacket.PropType.PlayerId]); Hand.State state = (Hand.State)Convert.ToUInt16(p.Properties[NetPacket.PropType.GameState]); - m_data.CurHand.CurState = state; if (curPlayer == m_data.MyPlayerId) m_callback.MyTurn(state, m_data.CurHand.HighestSet, m_data.CurHand.MinimumRaise, m_players[curPlayer].Money); @@ -251,6 +250,7 @@ namespace pokerth_lib public void VisitDealFlopCards(NetPacket p) { + m_data.CurHand.CurState = Hand.State.Flop; int[] tmpCards = new int[3]; tmpCards[0] = Convert.ToInt32(p.Properties[NetPacket.PropType.FlopFirstCard]); tmpCards[1] = Convert.ToInt32(p.Properties[NetPacket.PropType.FlopSecondCard]); @@ -261,6 +261,7 @@ namespace pokerth_lib public void VisitDealTurnCard(NetPacket p) { + m_data.CurHand.CurState = Hand.State.Turn; int[] tmpCards = new int[4]; m_data.CurHand.TableCards.CopyTo(tmpCards, 0); tmpCards[3] = Convert.ToInt32(p.Properties[NetPacket.PropType.TurnCard]); @@ -270,6 +271,7 @@ namespace pokerth_lib public void VisitDealRiverCard(NetPacket p) { + m_data.CurHand.CurState = Hand.State.River; int[] tmpCards = new int[5]; m_data.CurHand.TableCards.CopyTo(tmpCards, 0); tmpCards[4] = Convert.ToInt32(p.Properties[NetPacket.PropType.RiverCard]); @@ -358,6 +360,11 @@ namespace pokerth_lib m_data.JoinedGame = false; } + public void VisitRemovedFromGame(NetPacket p) + { + m_callback.RemovedFromGame(); + } + public void VisitChatText(NetPacket p) { uint playerId = Convert.ToUInt32(p.Properties[NetPacket.PropType.PlayerId]); diff --git a/docs/net_protocol.txt b/docs/net_protocol.txt index 48803acb..8484ea37 100644 --- a/docs/net_protocol.txt +++ b/docs/net_protocol.txt @@ -636,8 +636,8 @@ Player Action: 0x05 - Raise 0x06 - All in Player Bet: - 0 (ignored) - actions fold, check, all in (optionally call) - > 0 - actions call, bet, raise + 0 (ignored) - actions fold, check (optionally call, all in) + > 0 - actions call, bet, raise, all in Server Notification: Player's Action Done