Console client: Several fixes and improvements (thanks to heyn).
This commit is contained in:
@@ -80,9 +80,20 @@ namespace pokerth_console
|
|||||||
player);
|
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()
|
public void ActionRejected()
|
||||||
@@ -90,9 +101,14 @@ namespace pokerth_console
|
|||||||
Console.WriteLine("Your action was rejected by the server.");
|
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)
|
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[0]),
|
||||||
Log.CardToString(cards[1]),
|
Log.CardToString(cards[1]),
|
||||||
Log.CardToString(cards[2]));
|
Log.CardToString(cards[2]));
|
||||||
@@ -100,7 +116,7 @@ namespace pokerth_console
|
|||||||
|
|
||||||
public void ShowTurnCards(int[] cards)
|
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[0]),
|
||||||
Log.CardToString(cards[1]),
|
Log.CardToString(cards[1]),
|
||||||
Log.CardToString(cards[2]),
|
Log.CardToString(cards[2]),
|
||||||
@@ -109,7 +125,7 @@ namespace pokerth_console
|
|||||||
|
|
||||||
public void ShowRiverCards(int[] cards)
|
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[0]),
|
||||||
Log.CardToString(cards[1]),
|
Log.CardToString(cards[1]),
|
||||||
Log.CardToString(cards[2]),
|
Log.CardToString(cards[2]),
|
||||||
|
|||||||
@@ -113,10 +113,14 @@ namespace pokerth_console
|
|||||||
Console.WriteLine("pokerth_console V0.1 - Copyright (C) 2008 by Lothar May");
|
Console.WriteLine("pokerth_console V0.1 - Copyright (C) 2008 by Lothar May");
|
||||||
Console.WriteLine("See COPYING.txt for license terms.");
|
Console.WriteLine("See COPYING.txt for license terms.");
|
||||||
Console.WriteLine();
|
Console.WriteLine();
|
||||||
|
|
||||||
Console.WriteLine("Enter your nickname:");
|
Console.WriteLine("Enter your nickname:");
|
||||||
string name = Console.ReadLine();
|
string name = Console.ReadLine();
|
||||||
Console.WriteLine("Connecting to server...");
|
Console.WriteLine("Connecting to server...");
|
||||||
Settings settings = new Settings();
|
Settings settings = new Settings();
|
||||||
|
// Parse command line options.
|
||||||
|
if (args.Length > 0)
|
||||||
|
settings.ServerSettings.Server = args[0];
|
||||||
PokerTHData data = new PokerTHData(name);
|
PokerTHData data = new PokerTHData(name);
|
||||||
ConsoleCallback callback = new ConsoleCallback();
|
ConsoleCallback callback = new ConsoleCallback();
|
||||||
Client client = new Client(settings, data, callback);
|
Client client = new Client(settings, data, callback);
|
||||||
|
|||||||
@@ -92,6 +92,6 @@ namespace pokerth_lib
|
|||||||
private Object m_mutex;
|
private Object m_mutex;
|
||||||
private Mode m_mode;
|
private Mode m_mode;
|
||||||
private List<uint> m_playerSlots;
|
private List<uint> m_playerSlots;
|
||||||
private uint m_startMoney;
|
readonly private uint m_startMoney;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+18
-2
@@ -53,6 +53,7 @@ namespace pokerth_lib
|
|||||||
m_players = players;
|
m_players = players;
|
||||||
m_myPlayerId = myPlayerId;
|
m_myPlayerId = myPlayerId;
|
||||||
m_smallBlind = smallBlind;
|
m_smallBlind = smallBlind;
|
||||||
|
m_pot = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public State CurState
|
public State CurState
|
||||||
@@ -73,7 +74,10 @@ namespace pokerth_lib
|
|||||||
m_state = value;
|
m_state = value;
|
||||||
// Reset bets.
|
// Reset bets.
|
||||||
foreach (KeyValuePair<uint, Player> player in m_players)
|
foreach (KeyValuePair<uint, Player> player in m_players)
|
||||||
|
{
|
||||||
|
m_pot += player.Value.TotalBet;
|
||||||
player.Value.TotalBet = 0;
|
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 Object m_mutex;
|
||||||
private State m_state;
|
private State m_state;
|
||||||
private Dictionary<uint, Player> m_players;
|
private Dictionary<uint, Player> m_players;
|
||||||
private int[] m_tableCards;
|
private int[] m_tableCards;
|
||||||
private uint m_myPlayerId;
|
readonly private uint m_myPlayerId;
|
||||||
private uint m_smallBlind;
|
readonly private uint m_smallBlind;
|
||||||
private uint m_highestSet;
|
private uint m_highestSet;
|
||||||
private uint m_minimumRaise;
|
private uint m_minimumRaise;
|
||||||
|
private uint m_pot;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,8 +33,9 @@ namespace pokerth_lib
|
|||||||
void BigBlind(string name, uint blind);
|
void BigBlind(string name, uint blind);
|
||||||
void MyTurn(Hand.State state, uint highestSet, uint minimumRaise, uint money);
|
void MyTurn(Hand.State state, uint highestSet, uint minimumRaise, uint money);
|
||||||
void PlayersTurn(Hand.State state, string player);
|
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 ActionRejected();
|
||||||
|
void ShowPot(uint pot);
|
||||||
void ShowFlopCards(int[] cards);
|
void ShowFlopCards(int[] cards);
|
||||||
void ShowTurnCards(int[] cards);
|
void ShowTurnCards(int[] cards);
|
||||||
void ShowRiverCards(int[] cards);
|
void ShowRiverCards(int[] cards);
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ namespace pokerth_lib
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private uint m_id;
|
readonly private uint m_id;
|
||||||
private string m_name;
|
readonly private string m_name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -286,7 +286,7 @@ namespace pokerth_lib
|
|||||||
cardString = "Two Pairs, "
|
cardString = "Two Pairs, "
|
||||||
+ CardCodeToString(secondPart, true)
|
+ CardCodeToString(secondPart, true)
|
||||||
+ " and "
|
+ " and "
|
||||||
+ CardCodeToString(secondPart, true);
|
+ CardCodeToString(thirdPart, true);
|
||||||
break;
|
break;
|
||||||
// One Pair
|
// One Pair
|
||||||
case 1 :
|
case 1 :
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ namespace pokerth_lib
|
|||||||
private Object m_mutex;
|
private Object m_mutex;
|
||||||
private uint m_myPlayerId;
|
private uint m_myPlayerId;
|
||||||
private uint m_myGameId;
|
private uint m_myGameId;
|
||||||
private string m_myName;
|
readonly private string m_myName;
|
||||||
private bool m_joinedGame;
|
private bool m_joinedGame;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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_ipv4Address = "";
|
||||||
private string m_ipv6Address = "";
|
private string m_ipv6Address = "";
|
||||||
|
private string m_server = "";
|
||||||
private int m_port = 0;
|
private int m_port = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,12 +38,19 @@ namespace pokerth_lib
|
|||||||
public void Connect()
|
public void Connect()
|
||||||
{
|
{
|
||||||
// Connect to the server.
|
// Connect to the server.
|
||||||
// Try IPv6 first.
|
// If the user specified a server, try this.
|
||||||
IPAddress[] addresses = new IPAddress[2];
|
if (m_settings.ServerSettings.Server.Length > 0)
|
||||||
addresses[0] = IPAddress.Parse(m_settings.ServerSettings.IPv6Address);
|
m_tcpClient.Connect(
|
||||||
addresses[1] = IPAddress.Parse(m_settings.ServerSettings.IPv4Address);
|
m_settings.ServerSettings.Server, m_settings.ServerSettings.Port);
|
||||||
m_tcpClient.Connect(addresses, m_settings.ServerSettings.Port);
|
else
|
||||||
//m_tcpClient.Connect("localhost", 7234);
|
{
|
||||||
|
// 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()
|
public void Start()
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ namespace pokerth_lib
|
|||||||
public NetPacketPlayersActionRejected(int size, BinaryReader r)
|
public NetPacketPlayersActionRejected(int size, BinaryReader r)
|
||||||
: base(NetPacket.NetTypePlayersActionRejected)
|
: base(NetPacket.NetTypePlayersActionRejected)
|
||||||
{
|
{
|
||||||
if (size != 28)
|
if (size != 16)
|
||||||
throw new NetPacketException("NetPacketPlayersActionRejected invalid size.");
|
throw new NetPacketException("NetPacketPlayersActionRejected invalid size.");
|
||||||
Properties.Add(PropType.GameState,
|
Properties.Add(PropType.GameState,
|
||||||
Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16())));
|
Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16())));
|
||||||
|
|||||||
@@ -236,10 +236,20 @@ namespace pokerth_lib
|
|||||||
}
|
}
|
||||||
else
|
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(
|
m_callback.ActionDone(
|
||||||
name,
|
name,
|
||||||
curPlayer.CurAction,
|
curPlayer.CurAction,
|
||||||
curBet);
|
curBet,
|
||||||
|
curPlayer.Money,
|
||||||
|
nonFoldPlayers);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -256,6 +266,7 @@ namespace pokerth_lib
|
|||||||
tmpCards[1] = Convert.ToInt32(p.Properties[NetPacket.PropType.FlopSecondCard]);
|
tmpCards[1] = Convert.ToInt32(p.Properties[NetPacket.PropType.FlopSecondCard]);
|
||||||
tmpCards[2] = Convert.ToInt32(p.Properties[NetPacket.PropType.FlopThirdCard]);
|
tmpCards[2] = Convert.ToInt32(p.Properties[NetPacket.PropType.FlopThirdCard]);
|
||||||
m_data.CurHand.TableCards = tmpCards;
|
m_data.CurHand.TableCards = tmpCards;
|
||||||
|
m_callback.ShowPot(m_data.CurHand.Pot);
|
||||||
m_callback.ShowFlopCards(tmpCards);
|
m_callback.ShowFlopCards(tmpCards);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -266,6 +277,7 @@ namespace pokerth_lib
|
|||||||
m_data.CurHand.TableCards.CopyTo(tmpCards, 0);
|
m_data.CurHand.TableCards.CopyTo(tmpCards, 0);
|
||||||
tmpCards[3] = Convert.ToInt32(p.Properties[NetPacket.PropType.TurnCard]);
|
tmpCards[3] = Convert.ToInt32(p.Properties[NetPacket.PropType.TurnCard]);
|
||||||
m_data.CurHand.TableCards = tmpCards;
|
m_data.CurHand.TableCards = tmpCards;
|
||||||
|
m_callback.ShowPot(m_data.CurHand.Pot);
|
||||||
m_callback.ShowTurnCards(tmpCards);
|
m_callback.ShowTurnCards(tmpCards);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -276,6 +288,7 @@ namespace pokerth_lib
|
|||||||
m_data.CurHand.TableCards.CopyTo(tmpCards, 0);
|
m_data.CurHand.TableCards.CopyTo(tmpCards, 0);
|
||||||
tmpCards[4] = Convert.ToInt32(p.Properties[NetPacket.PropType.RiverCard]);
|
tmpCards[4] = Convert.ToInt32(p.Properties[NetPacket.PropType.RiverCard]);
|
||||||
m_data.CurHand.TableCards = tmpCards;
|
m_data.CurHand.TableCards = tmpCards;
|
||||||
|
m_callback.ShowPot(m_data.CurHand.Pot);
|
||||||
m_callback.ShowRiverCards(tmpCards);
|
m_callback.ShowRiverCards(tmpCards);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user