Console client: Added console callback, display more information. Cache hand state.

This commit is contained in:
lotodore
2008-12-23 14:24:37 +00:00
parent 28e7accd90
commit 04616ef89c
25 changed files with 495 additions and 104 deletions
+44
View File
@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace pokerth_console
{
class ConsoleCallback : ICallback
{
public void InitDone()
{
Console.WriteLine("Init successful.");
}
public void JoinedGame(string name)
{
Console.WriteLine("Successfully joined game \"{0}\".", name);
}
public void GameStarted(List<string> players)
{
string outPlayers = "";
foreach (string s in players)
{
if (outPlayers.Length != 0)
outPlayers += ", ";
outPlayers += s;
}
Console.WriteLine("Game was started. Players: {0}", outPlayers);
}
public void HandStarted(Hand h)
{
Console.WriteLine("New hand. Your cards: {0} {1}. Your money: {2}.",
Log.CardToString(h.Players[h.MyPlayerId].Cards[0]),
Log.CardToString(h.Players[h.MyPlayerId].Cards[1]),
h.Players[h.MyPlayerId].Money);
}
public void Error(string message)
{
Console.WriteLine("Error: " + message);
}
}
}
+18 -13
View File
@@ -32,20 +32,13 @@ namespace pokerth_console
Closed Closed
} }
public enum State public GameInfo(uint id, string name, Mode mode, List<uint> playerSlots, uint startMoney)
{
Preflop = 0,
Flop,
Turn,
River
}
public GameInfo(uint id, string name, Mode mode, List<uint> playerSlots)
: base(id, name) : base(id, name)
{ {
m_mode = mode;
m_mutex = new Object(); m_mutex = new Object();
m_mode = mode;
m_playerSlots = playerSlots; m_playerSlots = playerSlots;
m_startMoney = startMoney;
} }
public List<uint> PlayerSlots public List<uint> PlayerSlots
@@ -85,8 +78,20 @@ namespace pokerth_console
} }
} }
Mode m_mode; public uint StartMoney
Object m_mutex; {
List<uint> m_playerSlots; get
{
lock (m_mutex)
{
return m_startMoney;
}
}
}
private Object m_mutex;
private Mode m_mode;
private List<uint> m_playerSlots;
private uint m_startMoney;
} }
} }
+92
View File
@@ -0,0 +1,92 @@
/***************************************************************************
* 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;
namespace pokerth_console
{
class Hand
{
public const int MaxPlayers = 7;
public enum State
{
Preflop = 0,
Flop,
Turn,
River
}
public Hand(Dictionary<uint, Player> players, uint myPlayerId, uint smallBlind)
{
m_mutex = new Object();
m_state = State.Preflop;
m_players = players;
m_myPlayerId = myPlayerId;
}
public State CurState
{
get
{
lock (m_mutex)
{
return m_state;
}
}
set
{
lock (m_mutex)
{
m_state = value;
}
}
}
public Dictionary<uint, Player> Players
{
get
{
lock (m_mutex)
{
// Should not be modified. This is actually a const return ;-).
return m_players;
}
}
}
public uint MyPlayerId
{
get
{
lock (m_mutex)
{
return m_myPlayerId;
}
}
}
private Object m_mutex;
private State m_state;
private Dictionary<uint, Player> m_players;
uint m_myPlayerId;
}
}
+15
View File
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace pokerth_console
{
interface ICallback
{
void InitDone();
void JoinedGame(string name);
void GameStarted(List<string> players);
void HandStarted(Hand h);
void Error(string message);
}
}
+81
View File
@@ -0,0 +1,81 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace pokerth_console
{
class Log
{
public static string CardToString(int card)
{
int cardValue = card % 13;
int cardColor = card / 13;
string cardString;
switch (cardValue)
{
case 0:
cardString = "2";
break;
case 1:
cardString = "3";
break;
case 2:
cardString = "4";
break;
case 3:
cardString = "5";
break;
case 4:
cardString = "6";
break;
case 5:
cardString = "7";
break;
case 6:
cardString = "8";
break;
case 7:
cardString = "9";
break;
case 8:
cardString = "T";
break;
case 9:
cardString = "J";
break;
case 10:
cardString = "Q";
break;
case 11:
cardString = "K";
break;
case 12:
cardString = "A";
break;
default:
cardString = "Invalid Card ";
break;
}
switch (cardColor)
{
case 0 :
cardString += "d";
break;
case 1 :
cardString += "h";
break;
case 2 :
cardString += "s";
break;
case 3:
cardString += "c";
break;
default:
cardString += " Invalid Color";
break;
}
return cardString;
}
}
}
+74
View File
@@ -0,0 +1,74 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace pokerth_console
{
class Player
{
public Player()
{
m_mutex = new Object();
}
public int[] Cards
{
get
{
lock (m_mutex)
{
// Return a copy of the array.
return (int[])m_cards.Clone();
}
}
set
{
lock (m_mutex)
{
m_cards = value;
}
}
}
public uint Money
{
get
{
lock (m_mutex)
{
return m_money;
}
}
set
{
lock (m_mutex)
{
m_money = value;
}
}
}
private uint TotalBet
{
get
{
lock (m_mutex)
{
return m_totalBet;
}
}
set
{
lock (m_mutex)
{
m_totalBet = value;
}
}
}
private Object m_mutex;
private int[] m_cards;
private uint m_money;
private uint m_totalBet;
}
}
+19
View File
@@ -51,6 +51,24 @@ namespace pokerth_console
} }
} }
public Hand CurHand
{
get
{
lock (m_mutex)
{
return m_curHand;
}
}
set
{
lock (m_mutex)
{
m_curHand = value;
}
}
}
public string MyName public string MyName
{ {
get get
@@ -97,6 +115,7 @@ namespace pokerth_console
private GameInfoList m_gameInfoList; private GameInfoList m_gameInfoList;
private PlayerInfoList m_playerInfoList; private PlayerInfoList m_playerInfoList;
private Hand m_curHand;
private Object m_mutex; private Object m_mutex;
private uint m_myPlayerId; private uint m_myPlayerId;
private uint m_myGameId; private uint m_myGameId;
+6 -6
View File
@@ -85,18 +85,18 @@ namespace pokerth_console
protected void SendInit() protected void SendInit()
{ {
NetPacket init = new NetPacketInit(); NetPacket init = new NetPacketInit();
init.Properties.Add(NetPacket.PropertyType.RequestedVersionMajor, "5"); init.Properties.Add(NetPacket.PropType.RequestedVersionMajor, "5");
init.Properties.Add(NetPacket.PropertyType.RequestedVersionMinor, "0"); init.Properties.Add(NetPacket.PropType.RequestedVersionMinor, "0");
init.Properties.Add(NetPacket.PropertyType.PlayerName, m_data.MyName); init.Properties.Add(NetPacket.PropType.PlayerName, m_data.MyName);
init.Properties.Add(NetPacket.PropertyType.PlayerPassword, ""); init.Properties.Add(NetPacket.PropType.PlayerPassword, "");
m_sender.Send(init); m_sender.Send(init);
} }
protected void SendJoinGame(uint gameId) protected void SendJoinGame(uint gameId)
{ {
NetPacket join = new NetPacketJoinGame(); NetPacket join = new NetPacketJoinGame();
join.Properties.Add(NetPacket.PropertyType.GameId, Convert.ToString(gameId)); join.Properties.Add(NetPacket.PropType.GameId, Convert.ToString(gameId));
join.Properties.Add(NetPacket.PropertyType.GamePassword, ""); // no password for now join.Properties.Add(NetPacket.PropType.GamePassword, ""); // no password for now
m_sender.Send(join); m_sender.Send(join);
} }
+49 -6
View File
@@ -20,6 +20,8 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
using System.Net;
using System.Net.Sockets;
using System.IO; using System.IO;
namespace pokerth_console namespace pokerth_console
@@ -87,8 +89,7 @@ namespace pokerth_console
public const int NetTypeError = 0x0400; public const int NetTypeError = 0x0400;
public enum PropType
public enum PropertyType
{ {
RequestedVersionMajor, RequestedVersionMajor,
RequestedVersionMinor, RequestedVersionMinor,
@@ -111,6 +112,16 @@ namespace pokerth_console
GamePassword, GamePassword,
GameState, GameState,
AdminPlayerId, AdminPlayerId,
MaxNumPlayers,
RaiseIntervalMode,
RaiseSmallBlindInterval,
RaiseMode,
EndRaiseMode,
ProposedGuiSpeed,
PlayerActionTimeout,
FirstSmallBlind,
EndRaiseSmallBlindValue,
StartMoney,
CurNumPlayers, CurNumPlayers,
StartFlags, StartFlags,
StartDealerPlayerId, StartDealerPlayerId,
@@ -124,7 +135,8 @@ namespace pokerth_console
public enum ListPropertyType public enum ListPropertyType
{ {
PropPlayerSlots PlayerSlots,
ManualBlindSlots,
} }
public static NetPacket Create(int type, int size, BinaryReader reader) public static NetPacket Create(int type, int size, BinaryReader reader)
@@ -166,14 +178,45 @@ namespace pokerth_console
return tmpPacket; return tmpPacket;
} }
public void ScanGameInfoBlock(BinaryReader r)
{
Properties.Add(PropType.MaxNumPlayers,
Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16())));
Properties.Add(PropType.RaiseIntervalMode,
Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16())));
Properties.Add(PropType.RaiseSmallBlindInterval,
Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16())));
Properties.Add(PropType.RaiseMode,
Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16())));
Properties.Add(PropType.EndRaiseMode,
Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16())));
int numManualBlinds = r.ReadUInt16();
Properties.Add(PropType.ProposedGuiSpeed,
Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16())));
Properties.Add(PropType.PlayerActionTimeout,
Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16())));
Properties.Add(PropType.FirstSmallBlind,
Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32())));
Properties.Add(PropType.EndRaiseSmallBlindValue,
Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32())));
Properties.Add(PropType.StartMoney,
Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32())));
// Scan manual blinds.
List<string> blindSlots = new List<string>();
for (int i = 0; i < numManualBlinds; i++)
blindSlots.Add(Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32())));
ListProperties.Add(ListPropertyType.ManualBlindSlots, blindSlots);
}
public NetPacket(int type) public NetPacket(int type)
{ {
m_type = type; m_type = type;
m_properties = new Dictionary<PropertyType, string>(); m_properties = new Dictionary<PropType, string>();
m_listProperties = new Dictionary<ListPropertyType, List<string>>(); m_listProperties = new Dictionary<ListPropertyType, List<string>>();
} }
public Dictionary<PropertyType, string> Properties public Dictionary<PropType, string> Properties
{ {
set set
{ {
@@ -215,7 +258,7 @@ namespace pokerth_console
} }
private int m_type; private int m_type;
private Dictionary<PropertyType, string> m_properties; private Dictionary<PropType, string> m_properties;
private Dictionary<ListPropertyType, List<string>> m_listProperties; private Dictionary<ListPropertyType, List<string>> m_listProperties;
} }
} }
+8 -8
View File
@@ -69,25 +69,25 @@ namespace pokerth_console
{ {
if (size < 20) if (size < 20)
throw new NetPacketException("NetPacketGameListNew invalid size."); throw new NetPacketException("NetPacketGameListNew invalid size.");
Properties.Add(PropertyType.GameId, Properties.Add(PropType.GameId,
Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32()))); Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32())));
Properties.Add(PropertyType.AdminPlayerId, Properties.Add(PropType.AdminPlayerId,
Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32()))); Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32())));
Properties.Add(PropertyType.GameMode, Properties.Add(PropType.GameMode,
Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16()))); Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16())));
int gameNameLen = IPAddress.NetworkToHostOrder((short)r.ReadUInt16()); int gameNameLen = IPAddress.NetworkToHostOrder((short)r.ReadUInt16());
int curNumPlayers = IPAddress.NetworkToHostOrder((short)r.ReadUInt16()); int curNumPlayers = IPAddress.NetworkToHostOrder((short)r.ReadUInt16());
Properties.Add(PropertyType.CurNumPlayers, Convert.ToString(curNumPlayers)); Properties.Add(PropType.CurNumPlayers, Convert.ToString(curNumPlayers));
Properties.Add(PropertyType.GamePrivacyFlags, Properties.Add(PropType.GamePrivacyFlags,
Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16()))); Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16())));
r.ReadBytes(28); // Skip game info block for now. ScanGameInfoBlock(r);
// Read name of the game. // Read name of the game.
byte[] tmpName = r.ReadBytes(gameNameLen); byte[] tmpName = r.ReadBytes(gameNameLen);
Properties.Add(PropertyType.GameName, Properties.Add(PropType.GameName,
Encoding.UTF8.GetString(tmpName)); Encoding.UTF8.GetString(tmpName));
// Skip the padding. // Skip the padding.
int namePadding = AddPadding(tmpName.Length) - tmpName.Length; int namePadding = AddPadding(tmpName.Length) - tmpName.Length;
@@ -98,7 +98,7 @@ namespace pokerth_console
List<string> playerSlots = new List<string>(); List<string> playerSlots = new List<string>();
for (int i = 0; i < curNumPlayers; i++) for (int i = 0; i < curNumPlayers; i++)
playerSlots.Add(Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32()))); playerSlots.Add(Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32())));
ListProperties.Add(ListPropertyType.PropPlayerSlots, playerSlots); ListProperties.Add(ListPropertyType.PlayerSlots, playerSlots);
} }
public override void Accept(INetPacketVisitor visitor) public override void Accept(INetPacketVisitor visitor)
+2 -2
View File
@@ -48,9 +48,9 @@ namespace pokerth_console
{ {
if (size != 12) if (size != 12)
throw new NetPacketException("NetPacketGameListUpdate invalid size."); throw new NetPacketException("NetPacketGameListUpdate invalid size.");
Properties.Add(PropertyType.GameId, Properties.Add(PropType.GameId,
Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32()))); Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32())));
Properties.Add(PropertyType.GameMode, Properties.Add(PropType.GameMode,
Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16()))); Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16())));
} }
+3 -3
View File
@@ -48,17 +48,17 @@ namespace pokerth_console
{ {
if (size < 20) if (size < 20)
throw new NetPacketException("NetPacketGameStart invalid size."); throw new NetPacketException("NetPacketGameStart invalid size.");
Properties.Add(PropertyType.StartDealerPlayerId, Properties.Add(PropType.StartDealerPlayerId,
Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32()))); Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32())));
int curNumPlayers = IPAddress.NetworkToHostOrder((short)r.ReadUInt16()); int curNumPlayers = IPAddress.NetworkToHostOrder((short)r.ReadUInt16());
Properties.Add(PropertyType.CurNumPlayers, Convert.ToString(curNumPlayers)); Properties.Add(PropType.CurNumPlayers, Convert.ToString(curNumPlayers));
r.ReadBytes(2); // reserved r.ReadBytes(2); // reserved
// Read player ids. // Read player ids.
List<string> playerSlots = new List<string>(); List<string> playerSlots = new List<string>();
for (int i = 0; i < curNumPlayers; i++) for (int i = 0; i < curNumPlayers; i++)
playerSlots.Add(Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32()))); playerSlots.Add(Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32())));
ListProperties.Add(ListPropertyType.PropPlayerSlots, playerSlots); ListProperties.Add(ListPropertyType.PlayerSlots, playerSlots);
} }
public override void Accept(INetPacketVisitor visitor) public override void Accept(INetPacketVisitor visitor)
+4 -4
View File
@@ -48,12 +48,12 @@ namespace pokerth_console
{ {
if (size != 12) if (size != 12)
throw new NetPacketException("NetPacketHandStart invalid size."); throw new NetPacketException("NetPacketHandStart invalid size.");
Properties.Add(PropertyType.FirstCard, Properties.Add(PropType.FirstCard,
Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16()))); Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16())));
Properties.Add(PropertyType.SecondCard, Properties.Add(PropType.SecondCard,
Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16()))); Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16())));
Properties.Add(PropertyType.SmallBlind, Properties.Add(PropType.SmallBlind,
Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt32()))); Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32())));
} }
public override void Accept(INetPacketVisitor visitor) public override void Accept(INetPacketVisitor visitor)
+4 -4
View File
@@ -56,10 +56,10 @@ namespace pokerth_console
MemoryStream memStream = new MemoryStream(); MemoryStream memStream = new MemoryStream();
BinaryWriter w = new BinaryWriter(memStream); BinaryWriter w = new BinaryWriter(memStream);
string playerPassword = Properties[PropertyType.PlayerPassword]; string playerPassword = Properties[PropType.PlayerPassword];
byte[] tmpPassword = Encoding.UTF8.GetBytes(playerPassword); byte[] tmpPassword = Encoding.UTF8.GetBytes(playerPassword);
int passwordWithPadding = AddPadding(tmpPassword.Length); int passwordWithPadding = AddPadding(tmpPassword.Length);
string playerName = Properties[PropertyType.PlayerName]; string playerName = Properties[PropType.PlayerName];
byte[] tmpName = Encoding.UTF8.GetBytes(playerName); byte[] tmpName = Encoding.UTF8.GetBytes(playerName);
int nameWithPadding = AddPadding(tmpName.Length); int nameWithPadding = AddPadding(tmpName.Length);
int size = 16 + passwordWithPadding + nameWithPadding; int size = 16 + passwordWithPadding + nameWithPadding;
@@ -67,9 +67,9 @@ namespace pokerth_console
w.Write(IPAddress.HostToNetworkOrder((short)Type)); w.Write(IPAddress.HostToNetworkOrder((short)Type));
w.Write(IPAddress.HostToNetworkOrder((short)size)); w.Write(IPAddress.HostToNetworkOrder((short)size));
w.Write(IPAddress.HostToNetworkOrder((short) w.Write(IPAddress.HostToNetworkOrder((short)
Convert.ToUInt16(Properties[PropertyType.RequestedVersionMajor]))); Convert.ToUInt16(Properties[PropType.RequestedVersionMajor])));
w.Write(IPAddress.HostToNetworkOrder((short) w.Write(IPAddress.HostToNetworkOrder((short)
Convert.ToUInt16(Properties[PropertyType.RequestedVersionMinor]))); Convert.ToUInt16(Properties[PropType.RequestedVersionMinor])));
w.Write(IPAddress.HostToNetworkOrder((short)playerPassword.Length)); w.Write(IPAddress.HostToNetworkOrder((short)playerPassword.Length));
w.Write(IPAddress.HostToNetworkOrder((short)playerName.Length)); w.Write(IPAddress.HostToNetworkOrder((short)playerName.Length));
w.Write(IPAddress.HostToNetworkOrder((short)0)); // Privacy flags. w.Write(IPAddress.HostToNetworkOrder((short)0)); // Privacy flags.
+4 -4
View File
@@ -49,13 +49,13 @@ namespace pokerth_console
{ {
if (size != 16) if (size != 16)
throw new NetPacketException("NetPacketInitAck invalid size."); throw new NetPacketException("NetPacketInitAck invalid size.");
Properties.Add(PropertyType.LatestGameVersion, Properties.Add(PropType.LatestGameVersion,
Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16()))); Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16())));
Properties.Add(PropertyType.LatestBetaRevision, Properties.Add(PropType.LatestBetaRevision,
Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16()))); Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16())));
Properties.Add(PropertyType.SessionId, Properties.Add(PropType.SessionId,
Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32()))); Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32())));
Properties.Add(PropertyType.PlayerId, Properties.Add(PropType.PlayerId,
Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32()))); Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32())));
} }
+2 -2
View File
@@ -53,7 +53,7 @@ namespace pokerth_console
MemoryStream memStream = new MemoryStream(); MemoryStream memStream = new MemoryStream();
BinaryWriter w = new BinaryWriter(memStream); BinaryWriter w = new BinaryWriter(memStream);
string gamePassword = Properties[PropertyType.GamePassword]; string gamePassword = Properties[PropType.GamePassword];
byte[] tmpPassword = Encoding.UTF8.GetBytes(gamePassword); byte[] tmpPassword = Encoding.UTF8.GetBytes(gamePassword);
int passwordWithPadding = AddPadding(tmpPassword.Length); int passwordWithPadding = AddPadding(tmpPassword.Length);
int size = 12 + passwordWithPadding; int size = 12 + passwordWithPadding;
@@ -61,7 +61,7 @@ namespace pokerth_console
w.Write(IPAddress.HostToNetworkOrder((short)Type)); w.Write(IPAddress.HostToNetworkOrder((short)Type));
w.Write(IPAddress.HostToNetworkOrder((short)size)); w.Write(IPAddress.HostToNetworkOrder((short)size));
w.Write(IPAddress.HostToNetworkOrder((int) w.Write(IPAddress.HostToNetworkOrder((int)
Convert.ToUInt32(Properties[PropertyType.GameId]))); Convert.ToUInt32(Properties[PropType.GameId])));
w.Write(IPAddress.HostToNetworkOrder((short)gamePassword.Length)); w.Write(IPAddress.HostToNetworkOrder((short)gamePassword.Length));
w.Write(IPAddress.HostToNetworkOrder((short)0)); // Reserved. w.Write(IPAddress.HostToNetworkOrder((short)0)); // Reserved.
+5 -3
View File
@@ -49,12 +49,14 @@ namespace pokerth_console
{ {
if (size < 12) if (size < 12)
throw new NetPacketException("NetTypeJoinGameAck invalid size."); throw new NetPacketException("NetTypeJoinGameAck invalid size.");
Properties.Add(PropertyType.GameId, Properties.Add(PropType.GameId,
Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32()))); Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32())));
Properties.Add(PropertyType.PlayerRights, Properties.Add(PropType.PlayerRights,
Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16()))); Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16())));
r.ReadUInt16(); // reserved
// skip game info block // Scan game info block
ScanGameInfoBlock(r);
} }
public override void Accept(INetPacketVisitor visitor) public override void Accept(INetPacketVisitor visitor)
+3 -3
View File
@@ -52,17 +52,17 @@ namespace pokerth_console
{ {
if (size < 16) if (size < 16)
throw new NetPacketException("NetPacketPlayerInfo invalid size."); throw new NetPacketException("NetPacketPlayerInfo invalid size.");
Properties.Add(PropertyType.PlayerId, Properties.Add(PropType.PlayerId,
Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32()))); Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32())));
int playerFlags = IPAddress.NetworkToHostOrder((short)r.ReadUInt16()); int playerFlags = IPAddress.NetworkToHostOrder((short)r.ReadUInt16());
Properties.Add(PropertyType.PlayerFlags, Convert.ToString(playerFlags)); Properties.Add(PropType.PlayerFlags, Convert.ToString(playerFlags));
int playerNameLen = IPAddress.NetworkToHostOrder((short)r.ReadUInt16()); int playerNameLen = IPAddress.NetworkToHostOrder((short)r.ReadUInt16());
r.ReadUInt32(); // reserved r.ReadUInt32(); // reserved
if ((playerFlags & PlayerFlagAvatar) == PlayerFlagAvatar) if ((playerFlags & PlayerFlagAvatar) == PlayerFlagAvatar)
r.ReadBytes(16); // Skip avatar md5. r.ReadBytes(16); // Skip avatar md5.
byte[] tmpName = r.ReadBytes(playerNameLen); byte[] tmpName = r.ReadBytes(playerNameLen);
Properties.Add(PropertyType.PlayerName, Properties.Add(PropType.PlayerName,
Encoding.UTF8.GetString(tmpName)); Encoding.UTF8.GetString(tmpName));
} }
+3 -3
View File
@@ -56,11 +56,11 @@ namespace pokerth_console
w.Write(IPAddress.HostToNetworkOrder((short)Type)); w.Write(IPAddress.HostToNetworkOrder((short)Type));
w.Write(IPAddress.HostToNetworkOrder((short)8)); w.Write(IPAddress.HostToNetworkOrder((short)8));
w.Write(IPAddress.HostToNetworkOrder((short) w.Write(IPAddress.HostToNetworkOrder((short)
Convert.ToUInt16(Properties[PropertyType.GameState]))); Convert.ToUInt16(Properties[PropType.GameState])));
w.Write(IPAddress.HostToNetworkOrder((short) w.Write(IPAddress.HostToNetworkOrder((short)
Convert.ToUInt16(Properties[PropertyType.PlayerAction]))); Convert.ToUInt16(Properties[PropType.PlayerAction])));
w.Write(IPAddress.HostToNetworkOrder((int) w.Write(IPAddress.HostToNetworkOrder((int)
Convert.ToUInt32(Properties[PropertyType.PlayerBet]))); Convert.ToUInt32(Properties[PropType.PlayerBet])));
return memStream.ToArray(); return memStream.ToArray();
} }
+11 -11
View File
@@ -52,20 +52,20 @@ namespace pokerth_console
{ {
if (size != 28) if (size != 28)
throw new NetPacketException("NetPacketPlayersActionDone invalid size."); throw new NetPacketException("NetPacketPlayersActionDone invalid size.");
Properties.Add(PropertyType.PlayerId, Properties.Add(PropType.PlayerId,
Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32()))); Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32())));
Properties.Add(PropertyType.GameState, Properties.Add(PropType.GameState,
Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16()))); Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16())));
Properties.Add(PropertyType.PlayerAction, Properties.Add(PropType.PlayerAction,
Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16()))); Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16())));
Properties.Add(PropertyType.PlayerBetTotal, Properties.Add(PropType.PlayerBetTotal,
Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt32()))); Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32())));
Properties.Add(PropertyType.PlayerMoney, Properties.Add(PropType.PlayerMoney,
Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt32()))); Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32())));
Properties.Add(PropertyType.HighestSet, Properties.Add(PropType.HighestSet,
Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt32()))); Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32())));
Properties.Add(PropertyType.MinimumRaise, Properties.Add(PropType.MinimumRaise,
Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt32()))); Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32())));
} }
public override void Accept(INetPacketVisitor visitor) public override void Accept(INetPacketVisitor visitor)
@@ -50,13 +50,13 @@ namespace pokerth_console
{ {
if (size != 28) if (size != 28)
throw new NetPacketException("NetPacketPlayersActionRejected invalid size."); throw new NetPacketException("NetPacketPlayersActionRejected invalid size.");
Properties.Add(PropertyType.GameState, Properties.Add(PropType.GameState,
Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16()))); Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16())));
Properties.Add(PropertyType.PlayerAction, Properties.Add(PropType.PlayerAction,
Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16()))); Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16())));
Properties.Add(PropertyType.PlayerBet, Properties.Add(PropType.PlayerBet,
Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt32()))); Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32())));
Properties.Add(PropertyType.ActionRejectReason, Properties.Add(PropType.ActionRejectReason,
Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16()))); Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16())));
} }
+2 -2
View File
@@ -48,9 +48,9 @@ namespace pokerth_console
{ {
if (size != 12) if (size != 12)
throw new NetPacketException("NetPacketPlayersTurn invalid size."); throw new NetPacketException("NetPacketPlayersTurn invalid size.");
Properties.Add(PropertyType.PlayerId, Properties.Add(PropType.PlayerId,
Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32()))); Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32())));
Properties.Add(PropertyType.GameState, Properties.Add(PropType.GameState,
Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16()))); Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16())));
} }
@@ -54,7 +54,7 @@ namespace pokerth_console
w.Write(IPAddress.HostToNetworkOrder((short)Type)); w.Write(IPAddress.HostToNetworkOrder((short)Type));
w.Write(IPAddress.HostToNetworkOrder((short)8)); w.Write(IPAddress.HostToNetworkOrder((short)8));
w.Write(IPAddress.HostToNetworkOrder((int) w.Write(IPAddress.HostToNetworkOrder((int)
Convert.ToUInt32(Properties[PropertyType.PlayerId]))); Convert.ToUInt32(Properties[PropType.PlayerId])));
return memStream.ToArray(); return memStream.ToArray();
} }
+2 -2
View File
@@ -47,7 +47,7 @@ namespace pokerth_console
{ {
if (size != 8) if (size != 8)
throw new NetPacketException("NetTypeStartEvent invalid size."); throw new NetPacketException("NetTypeStartEvent invalid size.");
Properties.Add(PropertyType.StartFlags, Properties.Add(PropType.StartFlags,
Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16()))); Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16())));
} }
@@ -64,7 +64,7 @@ namespace pokerth_console
w.Write(IPAddress.HostToNetworkOrder((short)Type)); w.Write(IPAddress.HostToNetworkOrder((short)Type));
w.Write(IPAddress.HostToNetworkOrder((short)8)); w.Write(IPAddress.HostToNetworkOrder((short)8));
w.Write(IPAddress.HostToNetworkOrder((short) w.Write(IPAddress.HostToNetworkOrder((short)
Convert.ToUInt16(Properties[PropertyType.StartFlags]))); Convert.ToUInt16(Properties[PropType.StartFlags])));
w.Write(IPAddress.HostToNetworkOrder((short)0)); // reserved w.Write(IPAddress.HostToNetworkOrder((short)0)); // reserved
return memStream.ToArray(); return memStream.ToArray();
+38 -22
View File
@@ -40,7 +40,7 @@ namespace pokerth_console
public void VisitInitAck(NetPacketInitAck p) public void VisitInitAck(NetPacketInitAck p)
{ {
m_data.MyPlayerId = m_data.MyPlayerId =
Convert.ToUInt32(p.Properties[NetPacket.PropertyType.PlayerId]); Convert.ToUInt32(p.Properties[NetPacket.PropType.PlayerId]);
m_callback.InitDone(); m_callback.InitDone();
} }
@@ -48,18 +48,19 @@ namespace pokerth_console
{ {
// Add game to list. // Add game to list.
m_data.GameList.AddGameInfo(new GameInfo( m_data.GameList.AddGameInfo(new GameInfo(
Convert.ToUInt32(p.Properties[NetPacket.PropertyType.GameId]), Convert.ToUInt32(p.Properties[NetPacket.PropType.GameId]),
p.Properties[NetPacket.PropertyType.GameName], p.Properties[NetPacket.PropType.GameName],
(GameInfo.Mode)Convert.ToInt32(p.Properties[NetPacket.PropertyType.GameMode]), (GameInfo.Mode)Convert.ToInt32(p.Properties[NetPacket.PropType.GameMode]),
p.ListProperties[NetPacket.ListPropertyType.PropPlayerSlots]. p.ListProperties[NetPacket.ListPropertyType.PlayerSlots].
ConvertAll<uint>(Convert.ToUInt32))); ConvertAll<uint>(Convert.ToUInt32),
Convert.ToUInt32(p.Properties[NetPacket.PropType.StartMoney])));
} }
public void VisitGameListUpdate(NetPacketGameListUpdate p) public void VisitGameListUpdate(NetPacketGameListUpdate p)
{ {
GameInfo.Mode mode = GameInfo.Mode mode =
(GameInfo.Mode)Convert.ToInt32(p.Properties[NetPacket.PropertyType.GameMode]); (GameInfo.Mode)Convert.ToInt32(p.Properties[NetPacket.PropType.GameMode]);
uint id = Convert.ToUInt32(p.Properties[NetPacket.PropertyType.GameId]); uint id = Convert.ToUInt32(p.Properties[NetPacket.PropType.GameId]);
if (mode == GameInfo.Mode.Closed) // Remove game if it is has been closed. if (mode == GameInfo.Mode.Closed) // Remove game if it is has been closed.
m_data.GameList.RemoveGameInfo(id); m_data.GameList.RemoveGameInfo(id);
else else
@@ -75,8 +76,8 @@ namespace pokerth_console
{ {
// Add player to list. // Add player to list.
m_data.PlayerList.AddPlayerInfo(new PlayerInfo( m_data.PlayerList.AddPlayerInfo(new PlayerInfo(
Convert.ToUInt32(p.Properties[NetPacket.PropertyType.PlayerId]), Convert.ToUInt32(p.Properties[NetPacket.PropType.PlayerId]),
p.Properties[NetPacket.PropertyType.PlayerName])); p.Properties[NetPacket.PropType.PlayerName]));
} }
public void VisitJoinGame(NetPacketJoinGame p) public void VisitJoinGame(NetPacketJoinGame p)
@@ -87,7 +88,7 @@ namespace pokerth_console
public void VisitJoinGameAck(NetPacketJoinGameAck p) public void VisitJoinGameAck(NetPacketJoinGameAck p)
{ {
m_data.MyGameId = m_data.MyGameId =
Convert.ToUInt32(p.Properties[NetPacket.PropertyType.GameId]); Convert.ToUInt32(p.Properties[NetPacket.PropType.GameId]);
m_callback.JoinedGame(m_data.GameList.GetGameInfo(m_data.MyGameId).Name); m_callback.JoinedGame(m_data.GameList.GetGameInfo(m_data.MyGameId).Name);
} }
@@ -100,7 +101,7 @@ namespace pokerth_console
if (!m_data.PlayerList.HasPlayer(id)) if (!m_data.PlayerList.HasPlayer(id))
{ {
NetPacketRetrievePlayerInfo request = new NetPacketRetrievePlayerInfo(); NetPacketRetrievePlayerInfo request = new NetPacketRetrievePlayerInfo();
request.Properties.Add(NetPacket.PropertyType.PlayerId, Convert.ToString(id)); request.Properties.Add(NetPacket.PropType.PlayerId, Convert.ToString(id));
m_sender.Send(request); m_sender.Send(request);
} }
} }
@@ -116,29 +117,43 @@ namespace pokerth_console
public void VisitGameStart(NetPacketGameStart p) public void VisitGameStart(NetPacketGameStart p)
{ {
// Generate player list. // Generate player list, for gui and as hand data.
List<string> players = new List<string>(); List<string> strPlayers = new List<string>();
List<uint> slots = p.ListProperties[NetPacket.ListPropertyType.PropPlayerSlots]. List<uint> slots = p.ListProperties[NetPacket.ListPropertyType.PlayerSlots].
ConvertAll<uint>(Convert.ToUInt32); ConvertAll<uint>(Convert.ToUInt32);
m_players = new Dictionary<uint, Player>();
foreach (uint i in slots) foreach (uint i in slots)
{ {
if (m_data.PlayerList.HasPlayer(i)) if (m_data.PlayerList.HasPlayer(i))
players.Add(m_data.PlayerList.GetPlayerInfo(i).Name); strPlayers.Add(m_data.PlayerList.GetPlayerInfo(i).Name);
else if (i == m_data.MyPlayerId) else if (i == m_data.MyPlayerId)
players.Add(m_data.MyName); strPlayers.Add(m_data.MyName);
else else
players.Add(Convert.ToString(i)); strPlayers.Add(Convert.ToString(i));
// Set player data.
Player tmpPlayer = new Player();
tmpPlayer.Money = m_data.GameList.GetGameInfo(m_data.MyGameId).StartMoney;
m_players.Add(i, tmpPlayer);
} }
m_callback.GameStarted(players); m_callback.GameStarted(strPlayers);
} }
public void VisitHandStart(NetPacketHandStart p) public void VisitHandStart(NetPacketHandStart p)
{ {
m_callback.HandStarted( int[] tmpCards = new int[2];
Convert.ToInt32(p.Properties[NetPacket.PropertyType.FirstCard]), tmpCards[0] =
Convert.ToInt32(p.Properties[NetPacket.PropertyType.SecondCard])); 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);
} }
public void VisitPlayersTurn(NetPacketPlayersTurn p) public void VisitPlayersTurn(NetPacketPlayersTurn p)
@@ -164,5 +179,6 @@ namespace pokerth_console
private PokerTHData m_data; private PokerTHData m_data;
private SenderThread m_sender; private SenderThread m_sender;
private ICallback m_callback; private ICallback m_callback;
private Dictionary<uint, Player> m_players;
} }
} }