Console client: Several fixes and improvements (thanks to heyn).

This commit is contained in:
lotodore
2008-12-27 16:24:49 +00:00
parent ef8e277295
commit e4ead9e706
12 changed files with 91 additions and 21 deletions
+21 -5
View File
@@ -80,9 +80,20 @@ namespace pokerth_console
player);
}
public void ActionDone(string name, Hand.Action action, uint curBet)
public void ActionDone(string name, Hand.Action action, uint curBet, uint money, List<string> nonFoldPlayers)
{
Console.WriteLine("{0} {1}.", name, Log.ActionToString(action, curBet));
Console.WriteLine("{0} {1}. Cash: {2}.", name, Log.ActionToString(action, curBet), money);
if (action == Hand.Action.Fold)
{
string outPlayers = "";
foreach (string s in nonFoldPlayers)
{
if (outPlayers.Length != 0)
outPlayers += ", ";
outPlayers += s;
}
Console.WriteLine("Remaining players: {0}", outPlayers);
}
}
public void ActionRejected()
@@ -90,9 +101,14 @@ namespace pokerth_console
Console.WriteLine("Your action was rejected by the server.");
}
public void ShowPot(uint pot)
{
Console.WriteLine("\nPot is now {0}.", pot);
}
public void ShowFlopCards(int[] cards)
{
Console.WriteLine("\n--- Flop --- [{0}, {1}, {2}]",
Console.WriteLine("--- Flop --- [{0}, {1}, {2}]",
Log.CardToString(cards[0]),
Log.CardToString(cards[1]),
Log.CardToString(cards[2]));
@@ -100,7 +116,7 @@ namespace pokerth_console
public void ShowTurnCards(int[] cards)
{
Console.WriteLine("\n--- Turn --- [{0}, {1}, {2}, {3}]",
Console.WriteLine("--- Turn --- [{0}, {1}, {2}, {3}]",
Log.CardToString(cards[0]),
Log.CardToString(cards[1]),
Log.CardToString(cards[2]),
@@ -109,7 +125,7 @@ namespace pokerth_console
public void ShowRiverCards(int[] cards)
{
Console.WriteLine("\n--- River --- [{0}, {1}, {2}, {3}, {4}]",
Console.WriteLine("--- River --- [{0}, {1}, {2}, {3}, {4}]",
Log.CardToString(cards[0]),
Log.CardToString(cards[1]),
Log.CardToString(cards[2]),
+4
View File
@@ -113,10 +113,14 @@ namespace pokerth_console
Console.WriteLine("pokerth_console V0.1 - Copyright (C) 2008 by Lothar May");
Console.WriteLine("See COPYING.txt for license terms.");
Console.WriteLine();
Console.WriteLine("Enter your nickname:");
string name = Console.ReadLine();
Console.WriteLine("Connecting to server...");
Settings settings = new Settings();
// Parse command line options.
if (args.Length > 0)
settings.ServerSettings.Server = args[0];
PokerTHData data = new PokerTHData(name);
ConsoleCallback callback = new ConsoleCallback();
Client client = new Client(settings, data, callback);
+1 -1
View File
@@ -92,6 +92,6 @@ namespace pokerth_lib
private Object m_mutex;
private Mode m_mode;
private List<uint> m_playerSlots;
private uint m_startMoney;
readonly private uint m_startMoney;
}
}
+18 -2
View File
@@ -53,6 +53,7 @@ namespace pokerth_lib
m_players = players;
m_myPlayerId = myPlayerId;
m_smallBlind = smallBlind;
m_pot = 0;
}
public State CurState
@@ -73,7 +74,10 @@ namespace pokerth_lib
m_state = value;
// Reset bets.
foreach (KeyValuePair<uint, Player> player in m_players)
{
m_pot += player.Value.TotalBet;
player.Value.TotalBet = 0;
}
}
}
}
@@ -163,13 +167,25 @@ namespace pokerth_lib
}
}
public uint Pot
{
get
{
lock (m_mutex)
{
return m_pot;
}
}
}
private Object m_mutex;
private State m_state;
private Dictionary<uint, Player> m_players;
private int[] m_tableCards;
private uint m_myPlayerId;
private uint m_smallBlind;
readonly private uint m_myPlayerId;
readonly private uint m_smallBlind;
private uint m_highestSet;
private uint m_minimumRaise;
private uint m_pot;
}
}
+2 -1
View File
@@ -33,8 +33,9 @@ namespace pokerth_lib
void BigBlind(string name, uint blind);
void MyTurn(Hand.State state, uint highestSet, uint minimumRaise, uint money);
void PlayersTurn(Hand.State state, string player);
void ActionDone(string name, Hand.Action action, uint curBet);
void ActionDone(string name, Hand.Action action, uint curBet, uint money, List<string> nonFoldPlayers);
void ActionRejected();
void ShowPot(uint pot);
void ShowFlopCards(int[] cards);
void ShowTurnCards(int[] cards);
void ShowRiverCards(int[] cards);
+2 -2
View File
@@ -49,7 +49,7 @@ namespace pokerth_lib
}
}
private uint m_id;
private string m_name;
readonly private uint m_id;
readonly private string m_name;
}
}
+1 -1
View File
@@ -286,7 +286,7 @@ namespace pokerth_lib
cardString = "Two Pairs, "
+ CardCodeToString(secondPart, true)
+ " and "
+ CardCodeToString(secondPart, true);
+ CardCodeToString(thirdPart, true);
break;
// One Pair
case 1 :
+1 -1
View File
@@ -140,7 +140,7 @@ namespace pokerth_lib
private Object m_mutex;
private uint m_myPlayerId;
private uint m_myGameId;
private string m_myName;
readonly private string m_myName;
private bool m_joinedGame;
}
}
+13
View File
@@ -65,8 +65,21 @@ namespace pokerth_lib
}
}
public string Server
{
get
{
return m_server;
}
set
{
m_server = value;
}
}
private string m_ipv4Address = "";
private string m_ipv6Address = "";
private string m_server = "";
private int m_port = 0;
}
}
+13 -6
View File
@@ -38,12 +38,19 @@ namespace pokerth_lib
public void Connect()
{
// Connect to the server.
// Try IPv6 first.
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);
// If the user specified a server, try this.
if (m_settings.ServerSettings.Server.Length > 0)
m_tcpClient.Connect(
m_settings.ServerSettings.Server, m_settings.ServerSettings.Port);
else
{
// Try IPv6 first.
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);
}
}
public void Start()
@@ -37,7 +37,7 @@ namespace pokerth_lib
public NetPacketPlayersActionRejected(int size, BinaryReader r)
: base(NetPacket.NetTypePlayersActionRejected)
{
if (size != 28)
if (size != 16)
throw new NetPacketException("NetPacketPlayersActionRejected invalid size.");
Properties.Add(PropType.GameState,
Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16())));
+14 -1
View File
@@ -236,10 +236,20 @@ namespace pokerth_lib
}
else
{
// Collect non-fold players.
List<string> nonFoldPlayers = new List<string>();
foreach (KeyValuePair<uint, Player> player in m_players)
{
if (player.Value.CurAction != Hand.Action.Fold)
nonFoldPlayers.Add(m_data.PlayerList.GetPlayerInfo(player.Key).Name);
}
// Inform about action.
m_callback.ActionDone(
name,
curPlayer.CurAction,
curBet);
curBet,
curPlayer.Money,
nonFoldPlayers);
}
}
@@ -256,6 +266,7 @@ namespace pokerth_lib
tmpCards[1] = Convert.ToInt32(p.Properties[NetPacket.PropType.FlopSecondCard]);
tmpCards[2] = Convert.ToInt32(p.Properties[NetPacket.PropType.FlopThirdCard]);
m_data.CurHand.TableCards = tmpCards;
m_callback.ShowPot(m_data.CurHand.Pot);
m_callback.ShowFlopCards(tmpCards);
}
@@ -266,6 +277,7 @@ namespace pokerth_lib
m_data.CurHand.TableCards.CopyTo(tmpCards, 0);
tmpCards[3] = Convert.ToInt32(p.Properties[NetPacket.PropType.TurnCard]);
m_data.CurHand.TableCards = tmpCards;
m_callback.ShowPot(m_data.CurHand.Pot);
m_callback.ShowTurnCards(tmpCards);
}
@@ -276,6 +288,7 @@ namespace pokerth_lib
m_data.CurHand.TableCards.CopyTo(tmpCards, 0);
tmpCards[4] = Convert.ToInt32(p.Properties[NetPacket.PropType.RiverCard]);
m_data.CurHand.TableCards = tmpCards;
m_callback.ShowPot(m_data.CurHand.Pot);
m_callback.ShowRiverCards(tmpCards);
}