From 128c917a5b5f522014f794a8957b0af2d99ea4bd Mon Sep 17 00:00:00 2001 From: lotodore Date: Sun, 28 Dec 2008 01:37:59 +0000 Subject: [PATCH] Console client: Adding support for password protected games. Fixed issue with custom blinds. Cosmetic changes. --- console/src/ConsoleCallback.cs | 4 ++-- console/src/Program.cs | 13 ++++++++++--- console/src/lib/GameInfo.cs | 15 ++++++++++++++- console/src/lib/GameInfoList.cs | 8 ++++++++ console/src/lib/net/Client.cs | 14 +++++++------- console/src/lib/net/NetPacket.cs | 2 +- console/src/lib/net/NetPacketJoinGame.cs | 1 + console/src/lib/net/NetParser.cs | 3 ++- 8 files changed, 45 insertions(+), 15 deletions(-) diff --git a/console/src/ConsoleCallback.cs b/console/src/ConsoleCallback.cs index 7b776e9a..247a236e 100644 --- a/console/src/ConsoleCallback.cs +++ b/console/src/ConsoleCallback.cs @@ -82,7 +82,7 @@ namespace pokerth_console public void ActionDone(string name, Hand.Action action, uint curBet, uint money, List nonFoldPlayers) { - Console.WriteLine("{0} {1}. Cash: {2}.", name, Log.ActionToString(action, curBet), money); + Console.WriteLine("{0} {1}. Cash: ${2}.", name, Log.ActionToString(action, curBet), money); if (action == Hand.Action.Fold) { string outPlayers = ""; @@ -103,7 +103,7 @@ namespace pokerth_console public void ShowPot(uint pot) { - Console.WriteLine("\nPot is now {0}.", pot); + Console.WriteLine("\nPot is now ${0}.", pot); } public void ShowFlopCards(int[] cards) diff --git a/console/src/Program.cs b/console/src/Program.cs index 6d34e671..08b232c1 100644 --- a/console/src/Program.cs +++ b/console/src/Program.cs @@ -42,9 +42,16 @@ namespace pokerth_console Console.WriteLine("Enter game id (or press enter to refresh)"); input = Console.ReadLine(); } while (input == "" || !Char.IsDigit(input[0])); - Console.WriteLine("Joining game..."); uint gameId = Convert.ToUInt32(input); - client.JoinGame(gameId); + string password = ""; + if (data.GameList.HasGame(gameId) + && data.GameList.GetGameInfo(gameId).PasswordProtected) + { + Console.WriteLine("Enter game password:"); + password = Console.ReadLine(); + } + Console.WriteLine("Joining game..."); + client.JoinGame(gameId, password); // Hack this, because Mono does not support WaitOne(...). DateTime cur = DateTime.Now; while (!client.HasJoinedGame()) @@ -110,7 +117,7 @@ namespace pokerth_console static int Main(string[] args) { - Console.WriteLine("pokerth_console V0.1 - Copyright (C) 2008 by Lothar May"); + Console.WriteLine("pokerth_console V0.1.2 - Copyright (C) 2008 by Lothar May"); Console.WriteLine("See COPYING.txt for license terms."); Console.WriteLine(); diff --git a/console/src/lib/GameInfo.cs b/console/src/lib/GameInfo.cs index 8ddc1156..8a6b56fe 100644 --- a/console/src/lib/GameInfo.cs +++ b/console/src/lib/GameInfo.cs @@ -32,13 +32,14 @@ namespace pokerth_lib Closed } - public GameInfo(uint id, string name, Mode mode, List playerSlots, uint startMoney) + public GameInfo(uint id, string name, Mode mode, List playerSlots, uint startMoney, bool passwordProtected) : base(id, name) { m_mutex = new Object(); m_mode = mode; m_playerSlots = playerSlots; m_startMoney = startMoney; + m_passwordProtected = passwordProtected; } public List PlayerSlots @@ -89,9 +90,21 @@ namespace pokerth_lib } } + public bool PasswordProtected + { + get + { + lock (m_mutex) + { + return m_passwordProtected; + } + } + } + private Object m_mutex; private Mode m_mode; private List m_playerSlots; readonly private uint m_startMoney; + bool m_passwordProtected; } } diff --git a/console/src/lib/GameInfoList.cs b/console/src/lib/GameInfoList.cs index e5f989c6..d5fe4cf8 100644 --- a/console/src/lib/GameInfoList.cs +++ b/console/src/lib/GameInfoList.cs @@ -50,6 +50,14 @@ namespace pokerth_lib } } + public bool HasGame(uint id) + { + lock (m_list) + { + return m_list.ContainsKey(id); + } + } + public void SetGameInfo(uint id, GameInfo info) { lock (m_list) diff --git a/console/src/lib/net/Client.cs b/console/src/lib/net/Client.cs index de2aa3b7..34553dfb 100644 --- a/console/src/lib/net/Client.cs +++ b/console/src/lib/net/Client.cs @@ -45,11 +45,11 @@ namespace pokerth_lib else { // Try IPv6 first. - IPAddress[] addresses = new IPAddress[2]; + /*IPAddress[] addresses = new IPAddress[2]; addresses[0] = IPAddress.Parse(m_settings.ServerSettings.IPv6Address); addresses[1] = IPAddress.Parse(m_settings.ServerSettings.IPv4Address); - m_tcpClient.Connect(addresses, m_settings.ServerSettings.Port); - //m_tcpClient.Connect("localhost", 7234); + m_tcpClient.Connect(addresses, m_settings.ServerSettings.Port);*/ + m_tcpClient.Connect("localhost", 7234); } } @@ -60,9 +60,9 @@ namespace pokerth_lib SendInit(); } - public void JoinGame(uint gameId) + public void JoinGame(uint gameId, string password) { - SendJoinGame(gameId); + SendJoinGame(gameId, password); } public bool HasJoinedGame() @@ -119,11 +119,11 @@ namespace pokerth_lib m_sender.Send(init); } - protected void SendJoinGame(uint gameId) + protected void SendJoinGame(uint gameId, string password) { NetPacket join = new NetPacketJoinGame(); join.Properties.Add(NetPacket.PropType.GameId, Convert.ToString(gameId)); - join.Properties.Add(NetPacket.PropType.GamePassword, ""); // no password for now + join.Properties.Add(NetPacket.PropType.GamePassword, password); m_sender.Send(join); } diff --git a/console/src/lib/net/NetPacket.cs b/console/src/lib/net/NetPacket.cs index 8a2006c0..7401e5c1 100644 --- a/console/src/lib/net/NetPacket.cs +++ b/console/src/lib/net/NetPacket.cs @@ -314,7 +314,7 @@ namespace pokerth_lib Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16()))); Properties.Add(PropType.EndRaiseMode, Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16()))); - int numManualBlinds = r.ReadUInt16(); + int numManualBlinds = IPAddress.NetworkToHostOrder((short)r.ReadUInt16()); Properties.Add(PropType.ProposedGuiSpeed, Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16()))); Properties.Add(PropType.PlayerActionTimeout, diff --git a/console/src/lib/net/NetPacketJoinGame.cs b/console/src/lib/net/NetPacketJoinGame.cs index 4ebd39d2..b3abd3c3 100644 --- a/console/src/lib/net/NetPacketJoinGame.cs +++ b/console/src/lib/net/NetPacketJoinGame.cs @@ -56,6 +56,7 @@ namespace pokerth_lib w.Write(IPAddress.HostToNetworkOrder((short)gamePassword.Length)); w.Write(IPAddress.HostToNetworkOrder((short)0)); // Reserved. + w.Write(tmpPassword); // Add padding. int passwordPadding = passwordWithPadding - tmpPassword.Length; if (passwordPadding > 0) diff --git a/console/src/lib/net/NetParser.cs b/console/src/lib/net/NetParser.cs index a11aee32..f2d27c4c 100644 --- a/console/src/lib/net/NetParser.cs +++ b/console/src/lib/net/NetParser.cs @@ -57,7 +57,8 @@ namespace pokerth_lib (GameInfo.Mode)Convert.ToInt32(p.Properties[NetPacket.PropType.GameMode]), p.ListProperties[NetPacket.ListPropType.PlayerSlots]. ConvertAll(Convert.ToUInt32), - Convert.ToUInt32(p.Properties[NetPacket.PropType.StartMoney]))); + Convert.ToUInt32(p.Properties[NetPacket.PropType.StartMoney]), + Convert.ToUInt16(p.Properties[NetPacket.PropType.GamePrivacyFlags]) == 1)); } public void VisitGameListUpdate(NetPacket p)