Console client: Output similar to PokerTH log.
This commit is contained in:
@@ -45,5 +45,6 @@ namespace pokerth_lib
|
||||
void VisitDealFlopCards(NetPacket p);
|
||||
void VisitDealTurnCard(NetPacket p);
|
||||
void VisitDealRiverCard(NetPacket p);
|
||||
void VisitEndOfHandHideCards(NetPacket p);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,6 +136,7 @@ namespace pokerth_lib
|
||||
FlopThirdCard,
|
||||
TurnCard,
|
||||
RiverCard,
|
||||
MoneyWon,
|
||||
}
|
||||
|
||||
public enum ListPropType
|
||||
@@ -144,6 +145,11 @@ namespace pokerth_lib
|
||||
ManualBlindSlots,
|
||||
}
|
||||
|
||||
public enum RecordPropType
|
||||
{
|
||||
PlayerResult,
|
||||
}
|
||||
|
||||
public static NetPacket Create(int type, int size, BinaryReader reader)
|
||||
{
|
||||
NetPacket tmpPacket = null;
|
||||
@@ -189,12 +195,76 @@ namespace pokerth_lib
|
||||
case NetTypeDealRiverCard :
|
||||
tmpPacket = new NetPacketDealRiverCard(size, reader);
|
||||
break;
|
||||
case NetTypeEndOfHandHideCards :
|
||||
tmpPacket = new NetPacketEndOfHandHideCards(size, reader);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return tmpPacket;
|
||||
}
|
||||
|
||||
public NetPacket(int type)
|
||||
{
|
||||
m_type = type;
|
||||
m_properties = new Dictionary<PropType, string>();
|
||||
m_listProperties = new Dictionary<ListPropType, List<string>>();
|
||||
m_recordProperties = new Dictionary<RecordPropType, List<Dictionary<PropType, string>>>();
|
||||
}
|
||||
|
||||
public Dictionary<PropType, string> Properties
|
||||
{
|
||||
set
|
||||
{
|
||||
m_properties = value;
|
||||
}
|
||||
get
|
||||
{
|
||||
return m_properties;
|
||||
}
|
||||
}
|
||||
|
||||
public Dictionary<ListPropType, List<string>> ListProperties
|
||||
{
|
||||
set
|
||||
{
|
||||
m_listProperties = value;
|
||||
}
|
||||
get
|
||||
{
|
||||
return m_listProperties;
|
||||
}
|
||||
}
|
||||
|
||||
public Dictionary<RecordPropType, List<Dictionary<PropType, string>>> RecordProperties
|
||||
{
|
||||
set
|
||||
{
|
||||
m_recordProperties = value;
|
||||
}
|
||||
get
|
||||
{
|
||||
return m_recordProperties;
|
||||
}
|
||||
}
|
||||
|
||||
public int Type
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_type;
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void Accept(INetPacketVisitor visitor);
|
||||
|
||||
public abstract byte[] ToByteArray();
|
||||
|
||||
static protected int AddPadding(int size)
|
||||
{
|
||||
return ((((size) + 3) / 4) * 4);
|
||||
}
|
||||
|
||||
protected void ScanGameInfoBlock(BinaryReader r)
|
||||
{
|
||||
Properties.Add(PropType.MaxNumPlayers,
|
||||
@@ -258,56 +328,9 @@ namespace pokerth_lib
|
||||
}
|
||||
}
|
||||
|
||||
public NetPacket(int type)
|
||||
{
|
||||
m_type = type;
|
||||
m_properties = new Dictionary<PropType, string>();
|
||||
m_listProperties = new Dictionary<ListPropType, List<string>>();
|
||||
}
|
||||
|
||||
public Dictionary<PropType, string> Properties
|
||||
{
|
||||
set
|
||||
{
|
||||
m_properties = value;
|
||||
}
|
||||
get
|
||||
{
|
||||
return m_properties;
|
||||
}
|
||||
}
|
||||
|
||||
public Dictionary<ListPropType, List<string>> ListProperties
|
||||
{
|
||||
set
|
||||
{
|
||||
m_listProperties = value;
|
||||
}
|
||||
get
|
||||
{
|
||||
return m_listProperties;
|
||||
}
|
||||
}
|
||||
|
||||
public int Type
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_type;
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void Accept(INetPacketVisitor visitor);
|
||||
|
||||
public abstract byte[] ToByteArray();
|
||||
|
||||
static protected int AddPadding(int size)
|
||||
{
|
||||
return ((((size) + 3) / 4) * 4);
|
||||
}
|
||||
|
||||
private int m_type;
|
||||
private Dictionary<PropType, string> m_properties;
|
||||
private Dictionary<ListPropType, List<string>> m_listProperties;
|
||||
private Dictionary<RecordPropType, List<Dictionary<PropType, string>>> m_recordProperties;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
/***************************************************************************
|
||||
* 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 <http://www.gnu.org/licenses/>. *
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.IO;
|
||||
|
||||
namespace pokerth_lib
|
||||
{
|
||||
class NetPacketEndOfHandHideCards : NetPacket
|
||||
{
|
||||
public NetPacketEndOfHandHideCards()
|
||||
: base(NetPacket.NetTypeEndOfHandHideCards)
|
||||
{
|
||||
}
|
||||
|
||||
public NetPacketEndOfHandHideCards(int size, BinaryReader r)
|
||||
: base(NetPacket.NetTypeEndOfHandHideCards)
|
||||
{
|
||||
if (size != 16)
|
||||
throw new NetPacketException("NetPacketEndOfHandHideCards invalid size.");
|
||||
Properties.Add(PropType.PlayerId,
|
||||
Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32())));
|
||||
Properties.Add(PropType.MoneyWon,
|
||||
Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32())));
|
||||
Properties.Add(PropType.PlayerMoney,
|
||||
Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32())));
|
||||
}
|
||||
|
||||
public override void Accept(INetPacketVisitor visitor)
|
||||
{
|
||||
visitor.VisitEndOfHandHideCards(this);
|
||||
}
|
||||
|
||||
public override byte[] ToByteArray()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/***************************************************************************
|
||||
* 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 <http://www.gnu.org/licenses/>. *
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.IO;
|
||||
|
||||
|
||||
namespace pokerth_lib
|
||||
{
|
||||
class NetPacketEndOfHandShowCards : NetPacket
|
||||
{
|
||||
public NetPacketEndOfHandShowCards()
|
||||
: base(NetPacket.NetTypeEndOfHandShowCards)
|
||||
{
|
||||
}
|
||||
|
||||
public NetPacketEndOfHandShowCards(int size, BinaryReader r)
|
||||
: base(NetPacket.NetTypeEndOfHandShowCards)
|
||||
{
|
||||
if (size < 40)
|
||||
throw new NetPacketException("NetPacketEndOfHandShowCards invalid size.");
|
||||
int numPlayerResults = IPAddress.NetworkToHostOrder((short)r.ReadUInt16());
|
||||
r.ReadUInt16(); //reserved
|
||||
|
||||
List<Dictionary<PropType, string>> tmpRecordList = new List<Dictionary<PropType, string>>();
|
||||
for (int i = 0; i < numPlayerResults; i++)
|
||||
{
|
||||
Dictionary<PropType, string> tmpList = new Dictionary<PropType, string>();
|
||||
tmpList.Add(PropType.PlayerId,
|
||||
Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32())));
|
||||
tmpList.Add(PropType.FirstCard,
|
||||
Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16())));
|
||||
tmpList.Add(PropType.SecondCard,
|
||||
Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16())));
|
||||
}
|
||||
RecordProperties.Add(RecordPropType.PlayerResult, tmpRecordList);
|
||||
}
|
||||
|
||||
public override void Accept(INetPacketVisitor visitor)
|
||||
{
|
||||
visitor.VisitEndOfHandHideCards(this);
|
||||
}
|
||||
|
||||
public override byte[] ToByteArray()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -43,7 +43,7 @@ namespace pokerth_lib
|
||||
Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32())));
|
||||
int curNumPlayers = IPAddress.NetworkToHostOrder((short)r.ReadUInt16());
|
||||
Properties.Add(PropType.CurNumPlayers, Convert.ToString(curNumPlayers));
|
||||
r.ReadBytes(2); // reserved
|
||||
r.ReadUInt16(); // reserved
|
||||
|
||||
// Read player ids.
|
||||
List<string> playerSlots = new List<string>();
|
||||
|
||||
@@ -150,17 +150,23 @@ namespace pokerth_lib
|
||||
|
||||
public void VisitHandStart(NetPacket p)
|
||||
{
|
||||
// Reset players.
|
||||
foreach (KeyValuePair<uint, Player> player in m_players)
|
||||
player.Value.NewHand();
|
||||
|
||||
// Assign own cards.
|
||||
int[] tmpCards = new int[2];
|
||||
tmpCards[0] =
|
||||
Convert.ToInt32(p.Properties[NetPacket.PropType.FirstCard]);
|
||||
tmpCards[1] =
|
||||
Convert.ToInt32(p.Properties[NetPacket.PropType.SecondCard]);
|
||||
m_players[m_data.MyPlayerId].Cards = tmpCards;
|
||||
|
||||
m_data.CurHand = new Hand(
|
||||
m_players,
|
||||
m_data.MyPlayerId,
|
||||
Convert.ToUInt32(p.Properties[NetPacket.PropType.SmallBlind]));
|
||||
m_callback.HandStarted(m_data.CurHand);
|
||||
m_callback.HandStarted(tmpCards);
|
||||
}
|
||||
|
||||
public void VisitPlayersTurn(NetPacket p)
|
||||
@@ -168,7 +174,8 @@ namespace pokerth_lib
|
||||
uint curPlayer = Convert.ToUInt32(p.Properties[NetPacket.PropType.PlayerId]);
|
||||
Hand.State state = (Hand.State)Convert.ToUInt16(p.Properties[NetPacket.PropType.GameState]);
|
||||
if (curPlayer == m_data.MyPlayerId)
|
||||
m_callback.MyTurn(state);
|
||||
m_callback.MyTurn(state, m_data.CurHand.HighestSet,
|
||||
m_data.CurHand.MinimumRaise, m_players[curPlayer].Money);
|
||||
else
|
||||
m_callback.PlayersTurn(state, m_data.PlayerList.GetPlayerInfo(curPlayer).Name);
|
||||
}
|
||||
@@ -182,19 +189,32 @@ namespace pokerth_lib
|
||||
{
|
||||
uint playerId = Convert.ToUInt32(p.Properties[NetPacket.PropType.PlayerId]);
|
||||
Player curPlayer = m_data.CurHand.Players[playerId];
|
||||
string name = m_data.PlayerList.GetPlayerInfo(playerId).Name;
|
||||
curPlayer.CurAction =
|
||||
(Hand.Action)Convert.ToUInt16(p.Properties[NetPacket.PropType.PlayerAction]);
|
||||
curPlayer.Money =
|
||||
Convert.ToUInt32(p.Properties[NetPacket.PropType.PlayerMoney]);
|
||||
curPlayer.TotalBet =
|
||||
Convert.ToUInt32(p.Properties[NetPacket.PropType.PlayerBetTotal]);
|
||||
m_callback.ActionDone(
|
||||
m_data.PlayerList.GetPlayerInfo(playerId).Name,
|
||||
curPlayer.CurAction,
|
||||
curPlayer.TotalBet,
|
||||
curPlayer.Money,
|
||||
Convert.ToUInt32(p.Properties[NetPacket.PropType.HighestSet]),
|
||||
Convert.ToUInt32(p.Properties[NetPacket.PropType.MinimumRaise]));
|
||||
uint curBet = Convert.ToUInt32(p.Properties[NetPacket.PropType.PlayerBetTotal])
|
||||
- curPlayer.TotalBet;
|
||||
curPlayer.TotalBet += curBet;
|
||||
|
||||
m_data.CurHand.HighestSet = Convert.ToUInt32(p.Properties[NetPacket.PropType.HighestSet]);
|
||||
m_data.CurHand.MinimumRaise = Convert.ToUInt32(p.Properties[NetPacket.PropType.MinimumRaise]);
|
||||
|
||||
if (curPlayer.CurAction == Hand.Action.None)
|
||||
{
|
||||
if (curBet == m_data.CurHand.SmallBlind)
|
||||
m_callback.SmallBlind(name, curBet);
|
||||
else
|
||||
m_callback.BigBlind(name, curBet);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_callback.ActionDone(
|
||||
name,
|
||||
curPlayer.CurAction,
|
||||
curBet);
|
||||
}
|
||||
}
|
||||
|
||||
public void VisitPlayersActionRejected(NetPacket p)
|
||||
@@ -204,22 +224,42 @@ namespace pokerth_lib
|
||||
|
||||
public void VisitDealFlopCards(NetPacket p)
|
||||
{
|
||||
m_callback.ShowFlopCards(
|
||||
Convert.ToInt32(p.Properties[NetPacket.PropType.FlopFirstCard]),
|
||||
Convert.ToInt32(p.Properties[NetPacket.PropType.FlopSecondCard]),
|
||||
Convert.ToInt32(p.Properties[NetPacket.PropType.FlopThirdCard]));
|
||||
int[] tmpCards = new int[3];
|
||||
tmpCards[0] = Convert.ToInt32(p.Properties[NetPacket.PropType.FlopFirstCard]);
|
||||
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.ShowFlopCards(tmpCards);
|
||||
}
|
||||
|
||||
public void VisitDealTurnCard(NetPacket p)
|
||||
{
|
||||
m_callback.ShowTurnCard(
|
||||
Convert.ToInt32(p.Properties[NetPacket.PropType.TurnCard]));
|
||||
int[] tmpCards = new int[4];
|
||||
m_data.CurHand.TableCards.CopyTo(tmpCards, 0);
|
||||
tmpCards[3] = Convert.ToInt32(p.Properties[NetPacket.PropType.TurnCard]);
|
||||
m_data.CurHand.TableCards = tmpCards;
|
||||
m_callback.ShowTurnCards(tmpCards);
|
||||
}
|
||||
|
||||
public void VisitDealRiverCard(NetPacket p)
|
||||
{
|
||||
m_callback.ShowRiverCard(
|
||||
Convert.ToInt32(p.Properties[NetPacket.PropType.RiverCard]));
|
||||
int[] tmpCards = new int[5];
|
||||
m_data.CurHand.TableCards.CopyTo(tmpCards, 0);
|
||||
tmpCards[4] = Convert.ToInt32(p.Properties[NetPacket.PropType.RiverCard]);
|
||||
m_data.CurHand.TableCards = tmpCards;
|
||||
m_callback.ShowRiverCards(tmpCards);
|
||||
}
|
||||
|
||||
public void VisitEndOfHandHideCards(NetPacket p)
|
||||
{
|
||||
uint playerId = Convert.ToUInt32(p.Properties[NetPacket.PropType.PlayerId]);
|
||||
string name = m_data.PlayerList.GetPlayerInfo(playerId).Name;
|
||||
Player curPlayer = m_data.CurHand.Players[playerId];
|
||||
curPlayer.Money = Convert.ToUInt32(p.Properties[NetPacket.PropType.PlayerMoney]);
|
||||
|
||||
m_callback.PlayerWinsHideCards(
|
||||
name,
|
||||
Convert.ToUInt32(p.Properties[NetPacket.PropType.MoneyWon]));
|
||||
}
|
||||
|
||||
private PokerTHData m_data;
|
||||
|
||||
Reference in New Issue
Block a user