From ea2a1288be03f046a82efbcb1509adce62e224ff Mon Sep 17 00:00:00 2001 From: lotodore Date: Mon, 22 Dec 2008 23:03:15 +0000 Subject: [PATCH] Console client: Support for additional network packets. Preparing game. --- console/src/GameInfo.cs | 61 ++++++++++++- console/src/GameInfoList.cs | 24 ++++++ console/src/IdObject.cs | 2 + console/src/PokerTHData.cs | 42 +++++++++ console/src/net/Client.cs | 12 +-- console/src/net/INetPacketVisitor.cs | 7 ++ console/src/net/NetPacket.cs | 73 +++++++++++----- console/src/net/NetPacketGameListNew.cs | 12 +-- console/src/net/NetPacketGameListUpdate.cs | 67 +++++++++++++++ console/src/net/NetPacketGameStart.cs | 6 +- console/src/net/NetPacketHandStart.cs | 69 +++++++++++++++ console/src/net/NetPacketInit.cs | 8 +- console/src/net/NetPacketInitAck.cs | 8 +- console/src/net/NetPacketJoinGame.cs | 4 +- console/src/net/NetPacketJoinGameAck.cs | 70 +++++++++++++++ console/src/net/NetPacketPlayerInfo.cs | 6 +- console/src/net/NetPacketPlayersAction.cs | 68 +++++++++++++++ console/src/net/NetPacketPlayersActionDone.cs | 81 ++++++++++++++++++ .../src/net/NetPacketPlayersActionRejected.cs | 73 ++++++++++++++++ console/src/net/NetPacketPlayersTurn.cs | 67 +++++++++++++++ .../src/net/NetPacketRetrievePlayerInfo.cs | 2 +- console/src/net/NetPacketStartEvent.cs | 4 +- console/src/net/NetPacketStartEventAck.cs | 21 ++++- console/src/net/NetParser.cs | 85 +++++++++++++++---- docs/net_protocol.txt | 4 +- 25 files changed, 802 insertions(+), 74 deletions(-) create mode 100644 console/src/net/NetPacketGameListUpdate.cs create mode 100644 console/src/net/NetPacketHandStart.cs create mode 100644 console/src/net/NetPacketJoinGameAck.cs create mode 100644 console/src/net/NetPacketPlayersAction.cs create mode 100644 console/src/net/NetPacketPlayersActionDone.cs create mode 100644 console/src/net/NetPacketPlayersActionRejected.cs create mode 100644 console/src/net/NetPacketPlayersTurn.cs diff --git a/console/src/GameInfo.cs b/console/src/GameInfo.cs index e5eaa9cc..47423c56 100644 --- a/console/src/GameInfo.cs +++ b/console/src/GameInfo.cs @@ -25,9 +25,68 @@ namespace pokerth_console { class GameInfo : IdObject { - public GameInfo(uint id, string name) + public enum Mode + { + Created = 1, + Started, + Closed + } + + public enum State + { + Preflop = 0, + Flop, + Turn, + River + } + + public GameInfo(uint id, string name, Mode mode, List playerSlots) : base(id, name) { + m_mode = mode; + m_mutex = new Object(); + m_playerSlots = playerSlots; } + + public List PlayerSlots + { + get + { + lock (m_playerSlots) + { + // returns a copy(!) + return new List(m_playerSlots); + } + } + set + { + lock (m_playerSlots) + { + m_playerSlots = value; + } + } + } + + public Mode CurrentMode + { + get + { + lock (m_mutex) + { + return m_mode; + } + } + set + { + lock (m_mutex) + { + m_mode = value; + } + } + } + + Mode m_mode; + Object m_mutex; + List m_playerSlots; } } diff --git a/console/src/GameInfoList.cs b/console/src/GameInfoList.cs index 1534681b..372746e5 100644 --- a/console/src/GameInfoList.cs +++ b/console/src/GameInfoList.cs @@ -42,6 +42,30 @@ namespace pokerth_console } } + public GameInfo GetGameInfo(uint id) + { + lock (m_list) + { + return m_list[id]; + } + } + + public void SetGameInfo(uint id, GameInfo info) + { + lock (m_list) + { + m_list[id] = info; + } + } + + public void RemoveGameInfo(uint id) + { + lock (m_list) + { + m_list.Remove(id); + } + } + public override string ToString() { string outString = ""; diff --git a/console/src/IdObject.cs b/console/src/IdObject.cs index 6d0e997c..09ea3b95 100644 --- a/console/src/IdObject.cs +++ b/console/src/IdObject.cs @@ -35,6 +35,7 @@ namespace pokerth_console { get { + // No lock because only read access. return m_id; } } @@ -43,6 +44,7 @@ namespace pokerth_console { get { + // No lock because only read access. return m_name; } } diff --git a/console/src/PokerTHData.cs b/console/src/PokerTHData.cs index 99929fe7..0c10fbc3 100644 --- a/console/src/PokerTHData.cs +++ b/console/src/PokerTHData.cs @@ -29,6 +29,9 @@ namespace pokerth_console { m_gameInfoList = new GameInfoList(); m_playerInfoList = new PlayerInfoList(); + m_mutex = new Object(); + m_myPlayerId = 0; + m_myGameId = 0; } public GameInfoList GameList @@ -47,7 +50,46 @@ namespace pokerth_console } } + public uint MyPlayerId + { + get + { + lock (m_mutex) + { + return m_myPlayerId; + } + } + set + { + lock (m_mutex) + { + m_myPlayerId = value; + } + } + } + + public uint MyGameId + { + get + { + lock (m_mutex) + { + return m_myGameId; + } + } + set + { + lock (m_mutex) + { + m_myGameId = value; + } + } + } + private GameInfoList m_gameInfoList; private PlayerInfoList m_playerInfoList; + private Object m_mutex; + private uint m_myPlayerId; + private uint m_myGameId; } } diff --git a/console/src/net/Client.cs b/console/src/net/Client.cs index e43fcd67..5db031f2 100644 --- a/console/src/net/Client.cs +++ b/console/src/net/Client.cs @@ -84,18 +84,18 @@ namespace pokerth_console protected void SendInit() { NetPacket init = new NetPacketInit(); - init.Properties.Add(NetPacket.PropertyType.PropRequestedVersionMajor, "4"); - init.Properties.Add(NetPacket.PropertyType.PropRequestedVersionMinor, "2"); - init.Properties.Add(NetPacket.PropertyType.PropPlayerName, "Testuser"); - init.Properties.Add(NetPacket.PropertyType.PropPlayerPassword, ""); + init.Properties.Add(NetPacket.PropertyType.RequestedVersionMajor, "5"); + init.Properties.Add(NetPacket.PropertyType.RequestedVersionMinor, "0"); + init.Properties.Add(NetPacket.PropertyType.PlayerName, "Testuser1"); + init.Properties.Add(NetPacket.PropertyType.PlayerPassword, ""); m_sender.Send(init); } protected void SendJoinGame(uint gameId) { NetPacket join = new NetPacketJoinGame(); - join.Properties.Add(NetPacket.PropertyType.PropGameId, Convert.ToString(gameId)); - join.Properties.Add(NetPacket.PropertyType.PropGamePassword, ""); // no password for now + join.Properties.Add(NetPacket.PropertyType.GameId, Convert.ToString(gameId)); + join.Properties.Add(NetPacket.PropertyType.GamePassword, ""); // no password for now m_sender.Send(join); } diff --git a/console/src/net/INetPacketVisitor.cs b/console/src/net/INetPacketVisitor.cs index d5ea6f40..1056a7e0 100644 --- a/console/src/net/INetPacketVisitor.cs +++ b/console/src/net/INetPacketVisitor.cs @@ -28,11 +28,18 @@ namespace pokerth_console void VisitInit(NetPacketInit p); void VisitInitAck(NetPacketInitAck p); void VisitGameListNew(NetPacketGameListNew p); + void VisitGameListUpdate(NetPacketGameListUpdate p); void VisitRetrievePlayerInfo(NetPacketRetrievePlayerInfo p); void VisitPlayerInfo(NetPacketPlayerInfo p); void VisitJoinGame(NetPacketJoinGame p); + void VisitJoinGameAck(NetPacketJoinGameAck p); void VisitStartEvent(NetPacketStartEvent p); void VisitStartEventAck(NetPacketStartEventAck p); void VisitGameStart(NetPacketGameStart p); + void VisitHandStart(NetPacketHandStart p); + void VisitPlayersTurn(NetPacketPlayersTurn p); + void VisitPlayersAction(NetPacketPlayersAction p); + void VisitPlayersActionDone(NetPacketPlayersActionDone p); + void VisitPlayersActionRejected(NetPacketPlayersActionRejected p); } } diff --git a/console/src/net/NetPacket.cs b/console/src/net/NetPacket.cs index a07b7e8c..5bc36058 100644 --- a/console/src/net/NetPacket.cs +++ b/console/src/net/NetPacket.cs @@ -90,24 +90,36 @@ namespace pokerth_console public enum PropertyType { - PropRequestedVersionMajor, - PropRequestedVersionMinor, - PropPlayerId, - PropPlayerName, - PropPlayerPassword, - PropPlayerFlags, - PropLatestGameVersion, - PropLatestBetaRevision, - PropSessionId, - PropGameId, - PropGameMode, - PropGameName, - PropGamePrivacyFlags, - PropGamePassword, - PropAdminPlayerId, - PropCurNumPlayers, - PropStartFlags, - PropStartDealerPlayerId + RequestedVersionMajor, + RequestedVersionMinor, + PlayerId, + PlayerName, + PlayerPassword, + PlayerFlags, + PlayerRights, + PlayerAction, + PlayerBet, + PlayerBetTotal, + PlayerMoney, + LatestGameVersion, + LatestBetaRevision, + SessionId, + GameId, + GameMode, + GameName, + GamePrivacyFlags, + GamePassword, + GameState, + AdminPlayerId, + CurNumPlayers, + StartFlags, + StartDealerPlayerId, + FirstCard, + SecondCard, + SmallBlind, + HighestSet, + MinimumRaise, + ActionRejectReason, } public enum ListPropertyType @@ -121,18 +133,33 @@ namespace pokerth_console switch (type) { // Only consider those packets which are sent by the server. - case NetTypeInitAck: + case NetTypeInitAck : tmpPacket = new NetPacketInitAck(size, reader); break; - case NetTypeGameListNew: + case NetTypeGameListNew : tmpPacket = new NetPacketGameListNew(size, reader); break; - case NetTypePlayerInfo: + case NetTypeGameListUpdate : + tmpPacket = new NetPacketGameListUpdate(size, reader); + break; + case NetTypeJoinGameAck : + tmpPacket = new NetPacketJoinGameAck(size, reader); + break; + case NetTypePlayerInfo : tmpPacket = new NetPacketPlayerInfo(size, reader); break; - case NetTypeStartEvent: + case NetTypeStartEvent : tmpPacket = new NetPacketStartEvent(size, reader); break; + case NetTypeGameStart : + tmpPacket = new NetPacketGameStart(size, reader); + break; + case NetTypeHandStart : + tmpPacket = new NetPacketHandStart(size, reader); + break; + case NetTypePlayersTurn : + tmpPacket = new NetPacketPlayersTurn(size, reader); + break; default: break; } @@ -182,7 +209,7 @@ namespace pokerth_console public abstract byte[] ToByteArray(); - protected int AddPadding(int size) + static protected int AddPadding(int size) { return ((((size) + 3) / 4) * 4); } diff --git a/console/src/net/NetPacketGameListNew.cs b/console/src/net/NetPacketGameListNew.cs index fcbee8fd..1e74724b 100644 --- a/console/src/net/NetPacketGameListNew.cs +++ b/console/src/net/NetPacketGameListNew.cs @@ -69,25 +69,25 @@ namespace pokerth_console { if (size < 20) throw new NetPacketException("NetPacketGameListNew invalid size."); - Properties.Add(PropertyType.PropGameId, + Properties.Add(PropertyType.GameId, Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32()))); - Properties.Add(PropertyType.PropAdminPlayerId, + Properties.Add(PropertyType.AdminPlayerId, Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32()))); - Properties.Add(PropertyType.PropGameMode, + Properties.Add(PropertyType.GameMode, Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16()))); int gameNameLen = IPAddress.NetworkToHostOrder((short)r.ReadUInt16()); int curNumPlayers = IPAddress.NetworkToHostOrder((short)r.ReadUInt16()); - Properties.Add(PropertyType.PropCurNumPlayers, Convert.ToString(curNumPlayers)); - Properties.Add(PropertyType.PropGamePrivacyFlags, + Properties.Add(PropertyType.CurNumPlayers, Convert.ToString(curNumPlayers)); + Properties.Add(PropertyType.GamePrivacyFlags, Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16()))); r.ReadBytes(28); // Skip game info block for now. // Read name of the game. byte[] tmpName = r.ReadBytes(gameNameLen); - Properties.Add(PropertyType.PropGameName, + Properties.Add(PropertyType.GameName, Encoding.UTF8.GetString(tmpName)); // Skip the padding. int namePadding = AddPadding(tmpName.Length) - tmpName.Length; diff --git a/console/src/net/NetPacketGameListUpdate.cs b/console/src/net/NetPacketGameListUpdate.cs new file mode 100644 index 00000000..c0ddae62 --- /dev/null +++ b/console/src/net/NetPacketGameListUpdate.cs @@ -0,0 +1,67 @@ +/*************************************************************************** + * 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 . * + ***************************************************************************/ + +using System; +using System.Collections.Generic; +using System.Text; +using System.Net; +using System.Net.Sockets; +using System.IO; + +/* +struct GCC_PACKED NetPacketGameListUpdateData +{ + NetPacketHeader head; + u_int32_t gameId; + u_int16_t gameMode; + u_int16_t reserved; +}; +*/ + +namespace pokerth_console +{ + class NetPacketGameListUpdate : NetPacket + { + public NetPacketGameListUpdate() + : base(NetPacket.NetTypeGameListUpdate) + { + } + + public NetPacketGameListUpdate(int size, BinaryReader r) + : base(NetPacket.NetTypeGameListUpdate) + { + if (size != 12) + throw new NetPacketException("NetPacketGameListUpdate invalid size."); + Properties.Add(PropertyType.GameId, + Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32()))); + Properties.Add(PropertyType.GameMode, + Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16()))); + } + + public override void Accept(INetPacketVisitor visitor) + { + visitor.VisitGameListUpdate(this); + } + + public override byte[] ToByteArray() + { + throw new NotImplementedException(); + } + } +} diff --git a/console/src/net/NetPacketGameStart.cs b/console/src/net/NetPacketGameStart.cs index 8e71b5eb..9be0f39a 100644 --- a/console/src/net/NetPacketGameStart.cs +++ b/console/src/net/NetPacketGameStart.cs @@ -44,14 +44,14 @@ namespace pokerth_console } public NetPacketGameStart(int size, BinaryReader r) - : base(NetPacket.NetTypeGameListNew) + : base(NetPacket.NetTypeGameStart) { if (size < 20) throw new NetPacketException("NetPacketGameStart invalid size."); - Properties.Add(PropertyType.PropStartDealerPlayerId, + Properties.Add(PropertyType.StartDealerPlayerId, Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32()))); int curNumPlayers = IPAddress.NetworkToHostOrder((short)r.ReadUInt16()); - Properties.Add(PropertyType.PropCurNumPlayers, Convert.ToString(curNumPlayers)); + Properties.Add(PropertyType.CurNumPlayers, Convert.ToString(curNumPlayers)); r.ReadBytes(2); // reserved // Read player ids. diff --git a/console/src/net/NetPacketHandStart.cs b/console/src/net/NetPacketHandStart.cs new file mode 100644 index 00000000..1332a864 --- /dev/null +++ b/console/src/net/NetPacketHandStart.cs @@ -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 . * + ***************************************************************************/ + +using System; +using System.Collections.Generic; +using System.Text; +using System.Net; +using System.Net.Sockets; +using System.IO; + +/* +struct GCC_PACKED NetPacketHandStartData +{ + NetPacketHeader head; + u_int16_t yourCard1; + u_int16_t yourCard2; + u_int32_t smallBlind; +}; +*/ + +namespace pokerth_console +{ + class NetPacketHandStart : NetPacket + { + public NetPacketHandStart() + : base(NetPacket.NetTypeHandStart) + { + } + + public NetPacketHandStart(int size, BinaryReader r) + : base(NetPacket.NetTypeHandStart) + { + if (size != 12) + throw new NetPacketException("NetPacketHandStart invalid size."); + Properties.Add(PropertyType.FirstCard, + Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16()))); + Properties.Add(PropertyType.SecondCard, + Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16()))); + Properties.Add(PropertyType.SmallBlind, + Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt32()))); + } + + public override void Accept(INetPacketVisitor visitor) + { + visitor.VisitHandStart(this); + } + + public override byte[] ToByteArray() + { + throw new NotImplementedException(); + } + } +} diff --git a/console/src/net/NetPacketInit.cs b/console/src/net/NetPacketInit.cs index 265ee15b..1b5d0430 100644 --- a/console/src/net/NetPacketInit.cs +++ b/console/src/net/NetPacketInit.cs @@ -56,10 +56,10 @@ namespace pokerth_console MemoryStream memStream = new MemoryStream(); BinaryWriter w = new BinaryWriter(memStream); - string playerPassword = Properties[PropertyType.PropPlayerPassword]; + string playerPassword = Properties[PropertyType.PlayerPassword]; byte[] tmpPassword = Encoding.UTF8.GetBytes(playerPassword); int passwordWithPadding = AddPadding(tmpPassword.Length); - string playerName = Properties[PropertyType.PropPlayerName]; + string playerName = Properties[PropertyType.PlayerName]; byte[] tmpName = Encoding.UTF8.GetBytes(playerName); int nameWithPadding = AddPadding(tmpName.Length); int size = 16 + passwordWithPadding + nameWithPadding; @@ -67,9 +67,9 @@ namespace pokerth_console w.Write(IPAddress.HostToNetworkOrder((short)Type)); w.Write(IPAddress.HostToNetworkOrder((short)size)); w.Write(IPAddress.HostToNetworkOrder((short) - Convert.ToUInt16(Properties[PropertyType.PropRequestedVersionMajor]))); + Convert.ToUInt16(Properties[PropertyType.RequestedVersionMajor]))); w.Write(IPAddress.HostToNetworkOrder((short) - Convert.ToUInt16(Properties[PropertyType.PropRequestedVersionMinor]))); + Convert.ToUInt16(Properties[PropertyType.RequestedVersionMinor]))); w.Write(IPAddress.HostToNetworkOrder((short)playerPassword.Length)); w.Write(IPAddress.HostToNetworkOrder((short)playerName.Length)); w.Write(IPAddress.HostToNetworkOrder((short)0)); // Privacy flags. diff --git a/console/src/net/NetPacketInitAck.cs b/console/src/net/NetPacketInitAck.cs index 7c50e482..e08015d9 100644 --- a/console/src/net/NetPacketInitAck.cs +++ b/console/src/net/NetPacketInitAck.cs @@ -49,13 +49,13 @@ namespace pokerth_console { if (size != 16) throw new NetPacketException("NetPacketInitAck invalid size."); - Properties.Add(PropertyType.PropLatestGameVersion, + Properties.Add(PropertyType.LatestGameVersion, Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16()))); - Properties.Add(PropertyType.PropLatestBetaRevision, + Properties.Add(PropertyType.LatestBetaRevision, Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16()))); - Properties.Add(PropertyType.PropSessionId, + Properties.Add(PropertyType.SessionId, Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32()))); - Properties.Add(PropertyType.PropPlayerId, + Properties.Add(PropertyType.PlayerId, Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32()))); } diff --git a/console/src/net/NetPacketJoinGame.cs b/console/src/net/NetPacketJoinGame.cs index b0c2f06c..8f3896c4 100644 --- a/console/src/net/NetPacketJoinGame.cs +++ b/console/src/net/NetPacketJoinGame.cs @@ -53,7 +53,7 @@ namespace pokerth_console MemoryStream memStream = new MemoryStream(); BinaryWriter w = new BinaryWriter(memStream); - string gamePassword = Properties[PropertyType.PropGamePassword]; + string gamePassword = Properties[PropertyType.GamePassword]; byte[] tmpPassword = Encoding.UTF8.GetBytes(gamePassword); int passwordWithPadding = AddPadding(tmpPassword.Length); int size = 12 + passwordWithPadding; @@ -61,7 +61,7 @@ namespace pokerth_console w.Write(IPAddress.HostToNetworkOrder((short)Type)); w.Write(IPAddress.HostToNetworkOrder((short)size)); w.Write(IPAddress.HostToNetworkOrder((int) - Convert.ToUInt32(Properties[PropertyType.PropGameId]))); + Convert.ToUInt32(Properties[PropertyType.GameId]))); w.Write(IPAddress.HostToNetworkOrder((short)gamePassword.Length)); w.Write(IPAddress.HostToNetworkOrder((short)0)); // Reserved. diff --git a/console/src/net/NetPacketJoinGameAck.cs b/console/src/net/NetPacketJoinGameAck.cs new file mode 100644 index 00000000..2e4c38cb --- /dev/null +++ b/console/src/net/NetPacketJoinGameAck.cs @@ -0,0 +1,70 @@ +/*************************************************************************** + * 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 . * + ***************************************************************************/ + +using System; +using System.Collections.Generic; +using System.Text; +using System.Net; +using System.Net.Sockets; +using System.IO; + +/* +struct GCC_PACKED NetPacketJoinGameAckData +{ + NetPacketHeader head; + u_int32_t gameId; + u_int16_t playerRights; + u_int16_t reserved; + GameInfoData gameData; +}; +*/ + +namespace pokerth_console +{ + class NetPacketJoinGameAck : NetPacket + { + public NetPacketJoinGameAck() + : base(NetPacket.NetTypeJoinGameAck) + { + } + + public NetPacketJoinGameAck(int size, BinaryReader r) + : base(NetPacket.NetTypeJoinGameAck) + { + if (size < 12) + throw new NetPacketException("NetTypeJoinGameAck invalid size."); + Properties.Add(PropertyType.GameId, + Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32()))); + Properties.Add(PropertyType.PlayerRights, + Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16()))); + + // skip game info block + } + + public override void Accept(INetPacketVisitor visitor) + { + visitor.VisitJoinGameAck(this); + } + + public override byte[] ToByteArray() + { + throw new NotImplementedException(); + } + } +} diff --git a/console/src/net/NetPacketPlayerInfo.cs b/console/src/net/NetPacketPlayerInfo.cs index 356b891f..5d27cc28 100644 --- a/console/src/net/NetPacketPlayerInfo.cs +++ b/console/src/net/NetPacketPlayerInfo.cs @@ -52,17 +52,17 @@ namespace pokerth_console { if (size < 16) throw new NetPacketException("NetPacketPlayerInfo invalid size."); - Properties.Add(PropertyType.PropPlayerId, + Properties.Add(PropertyType.PlayerId, Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32()))); int playerFlags = IPAddress.NetworkToHostOrder((short)r.ReadUInt16()); - Properties.Add(PropertyType.PropPlayerFlags, Convert.ToString(playerFlags)); + Properties.Add(PropertyType.PlayerFlags, Convert.ToString(playerFlags)); int playerNameLen = IPAddress.NetworkToHostOrder((short)r.ReadUInt16()); r.ReadUInt32(); // reserved if ((playerFlags & PlayerFlagAvatar) == PlayerFlagAvatar) r.ReadBytes(16); // Skip avatar md5. byte[] tmpName = r.ReadBytes(playerNameLen); - Properties.Add(PropertyType.PropPlayerName, + Properties.Add(PropertyType.PlayerName, Encoding.UTF8.GetString(tmpName)); } diff --git a/console/src/net/NetPacketPlayersAction.cs b/console/src/net/NetPacketPlayersAction.cs new file mode 100644 index 00000000..e4d2befe --- /dev/null +++ b/console/src/net/NetPacketPlayersAction.cs @@ -0,0 +1,68 @@ +/*************************************************************************** + * 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 . * + ***************************************************************************/ + +using System; +using System.Collections.Generic; +using System.Text; +using System.Net; +using System.Net.Sockets; +using System.IO; + +/* +struct GCC_PACKED NetPacketPlayersActionData +{ + NetPacketHeader head; + u_int16_t gameState; + u_int16_t playerAction; + u_int32_t playerBet; +}; +*/ + +namespace pokerth_console +{ + class NetPacketPlayersAction : NetPacket + { + public NetPacketPlayersAction() + : base(NetPacket.NetTypePlayersAction) + { + } + + public override void Accept(INetPacketVisitor visitor) + { + visitor.VisitPlayersAction(this); + } + + public override byte[] ToByteArray() + { + MemoryStream memStream = new MemoryStream(); + BinaryWriter w = new BinaryWriter(memStream); + + w.Write(IPAddress.HostToNetworkOrder((short)Type)); + w.Write(IPAddress.HostToNetworkOrder((short)8)); + w.Write(IPAddress.HostToNetworkOrder((short) + Convert.ToUInt16(Properties[PropertyType.GameState]))); + w.Write(IPAddress.HostToNetworkOrder((short) + Convert.ToUInt16(Properties[PropertyType.PlayerAction]))); + w.Write(IPAddress.HostToNetworkOrder((int) + Convert.ToUInt32(Properties[PropertyType.PlayerBet]))); + + return memStream.ToArray(); + } + } +} diff --git a/console/src/net/NetPacketPlayersActionDone.cs b/console/src/net/NetPacketPlayersActionDone.cs new file mode 100644 index 00000000..14be2e25 --- /dev/null +++ b/console/src/net/NetPacketPlayersActionDone.cs @@ -0,0 +1,81 @@ +/*************************************************************************** + * 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 . * + ***************************************************************************/ + +using System; +using System.Collections.Generic; +using System.Text; +using System.Net; +using System.Net.Sockets; +using System.IO; + +/* +struct GCC_PACKED NetPacketPlayersActionDoneData +{ + NetPacketHeader head; + u_int32_t playerId; + u_int16_t gameState; + u_int16_t playerAction; + u_int32_t totalPlayerBet; + u_int32_t playerMoney; + u_int32_t highestSet; + u_int32_t minimumRaise; +}; +*/ + +namespace pokerth_console +{ + class NetPacketPlayersActionDone : NetPacket + { + public NetPacketPlayersActionDone() + : base(NetPacket.NetTypePlayersActionDone) + { + } + + public NetPacketPlayersActionDone(int size, BinaryReader r) + : base(NetPacket.NetTypePlayersActionDone) + { + if (size != 28) + throw new NetPacketException("NetPacketPlayersActionDone invalid size."); + Properties.Add(PropertyType.PlayerId, + Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32()))); + Properties.Add(PropertyType.GameState, + Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16()))); + Properties.Add(PropertyType.PlayerAction, + Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16()))); + Properties.Add(PropertyType.PlayerBetTotal, + Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt32()))); + Properties.Add(PropertyType.PlayerMoney, + Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt32()))); + Properties.Add(PropertyType.HighestSet, + Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt32()))); + Properties.Add(PropertyType.MinimumRaise, + Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt32()))); + } + + public override void Accept(INetPacketVisitor visitor) + { + visitor.VisitPlayersActionDone(this); + } + + public override byte[] ToByteArray() + { + throw new NotImplementedException(); + } + } +} diff --git a/console/src/net/NetPacketPlayersActionRejected.cs b/console/src/net/NetPacketPlayersActionRejected.cs new file mode 100644 index 00000000..c39ec02f --- /dev/null +++ b/console/src/net/NetPacketPlayersActionRejected.cs @@ -0,0 +1,73 @@ +/*************************************************************************** + * 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 . * + ***************************************************************************/ + +using System; +using System.Collections.Generic; +using System.Text; +using System.Net; +using System.Net.Sockets; +using System.IO; + +/* +struct GCC_PACKED NetPacketPlayersActionRejectedData +{ + NetPacketHeader head; + u_int16_t gameState; + u_int16_t playerAction; + u_int32_t playerBet; + u_int16_t rejectionReason; + u_int16_t reserved; +}; +*/ + +namespace pokerth_console +{ + class NetPacketPlayersActionRejected : NetPacket + { + public NetPacketPlayersActionRejected() + : base(NetPacket.NetTypePlayersActionRejected) + { + } + + public NetPacketPlayersActionRejected(int size, BinaryReader r) + : base(NetPacket.NetTypePlayersActionRejected) + { + if (size != 28) + throw new NetPacketException("NetPacketPlayersActionRejected invalid size."); + Properties.Add(PropertyType.GameState, + Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16()))); + Properties.Add(PropertyType.PlayerAction, + Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16()))); + Properties.Add(PropertyType.PlayerBet, + Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt32()))); + Properties.Add(PropertyType.ActionRejectReason, + Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16()))); + } + + public override void Accept(INetPacketVisitor visitor) + { + visitor.VisitPlayersActionRejected(this); + } + + public override byte[] ToByteArray() + { + throw new NotImplementedException(); + } + } +} diff --git a/console/src/net/NetPacketPlayersTurn.cs b/console/src/net/NetPacketPlayersTurn.cs new file mode 100644 index 00000000..0374fbe3 --- /dev/null +++ b/console/src/net/NetPacketPlayersTurn.cs @@ -0,0 +1,67 @@ +/*************************************************************************** + * 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 . * + ***************************************************************************/ + +using System; +using System.Collections.Generic; +using System.Text; +using System.Net; +using System.Net.Sockets; +using System.IO; + +/* +struct GCC_PACKED NetPacketPlayersTurnData +{ + NetPacketHeader head; + u_int32_t playerId; + u_int16_t gameState; + u_int16_t reserved; +}; +*/ + +namespace pokerth_console +{ + class NetPacketPlayersTurn : NetPacket + { + public NetPacketPlayersTurn() + : base(NetPacket.NetTypePlayersTurn) + { + } + + public NetPacketPlayersTurn(int size, BinaryReader r) + : base(NetPacket.NetTypePlayersTurn) + { + if (size != 12) + throw new NetPacketException("NetPacketPlayersTurn invalid size."); + Properties.Add(PropertyType.PlayerId, + Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32()))); + Properties.Add(PropertyType.GameState, + Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16()))); + } + + public override void Accept(INetPacketVisitor visitor) + { + visitor.VisitPlayersTurn(this); + } + + public override byte[] ToByteArray() + { + throw new NotImplementedException(); + } + } +} diff --git a/console/src/net/NetPacketRetrievePlayerInfo.cs b/console/src/net/NetPacketRetrievePlayerInfo.cs index 6f5d0f2b..71fcdb20 100644 --- a/console/src/net/NetPacketRetrievePlayerInfo.cs +++ b/console/src/net/NetPacketRetrievePlayerInfo.cs @@ -54,7 +54,7 @@ namespace pokerth_console w.Write(IPAddress.HostToNetworkOrder((short)Type)); w.Write(IPAddress.HostToNetworkOrder((short)8)); w.Write(IPAddress.HostToNetworkOrder((int) - Convert.ToUInt32(Properties[PropertyType.PropPlayerId]))); + Convert.ToUInt32(Properties[PropertyType.PlayerId]))); return memStream.ToArray(); } diff --git a/console/src/net/NetPacketStartEvent.cs b/console/src/net/NetPacketStartEvent.cs index 2b5cc505..aa498a2c 100644 --- a/console/src/net/NetPacketStartEvent.cs +++ b/console/src/net/NetPacketStartEvent.cs @@ -47,7 +47,7 @@ namespace pokerth_console { if (size != 8) throw new NetPacketException("NetTypeStartEvent invalid size."); - Properties.Add(PropertyType.PropStartFlags, + Properties.Add(PropertyType.StartFlags, 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)8)); w.Write(IPAddress.HostToNetworkOrder((short) - Convert.ToUInt16(Properties[PropertyType.PropStartFlags]))); + Convert.ToUInt16(Properties[PropertyType.StartFlags]))); w.Write(IPAddress.HostToNetworkOrder((short)0)); // reserved return memStream.ToArray(); diff --git a/console/src/net/NetPacketStartEventAck.cs b/console/src/net/NetPacketStartEventAck.cs index de9d6d69..85f565e4 100644 --- a/console/src/net/NetPacketStartEventAck.cs +++ b/console/src/net/NetPacketStartEventAck.cs @@ -1,4 +1,23 @@ -using System; +/*************************************************************************** + * 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 . * + ***************************************************************************/ + +using System; using System.Collections.Generic; using System.Text; using System.Net; diff --git a/console/src/net/NetParser.cs b/console/src/net/NetParser.cs index dd085c25..b4a2a776 100644 --- a/console/src/net/NetParser.cs +++ b/console/src/net/NetParser.cs @@ -38,15 +38,30 @@ namespace pokerth_console public void VisitInitAck(NetPacketInitAck p) { - // TODO + m_data.MyPlayerId = + Convert.ToUInt32(p.Properties[NetPacket.PropertyType.PlayerId]); } public void VisitGameListNew(NetPacketGameListNew p) { // Add game to list. m_data.GameList.AddGameInfo(new GameInfo( - Convert.ToUInt32(p.Properties[NetPacket.PropertyType.PropGameId]), - p.Properties[NetPacket.PropertyType.PropGameName])); + Convert.ToUInt32(p.Properties[NetPacket.PropertyType.GameId]), + p.Properties[NetPacket.PropertyType.GameName], + (GameInfo.Mode)Convert.ToInt32(p.Properties[NetPacket.PropertyType.GameMode]), + p.ListProperties[NetPacket.ListPropertyType.PropPlayerSlots]. + ConvertAll(Convert.ToUInt32))); + } + + public void VisitGameListUpdate(NetPacketGameListUpdate p) + { + GameInfo.Mode mode = + (GameInfo.Mode)Convert.ToInt32(p.Properties[NetPacket.PropertyType.GameMode]); + uint id = Convert.ToUInt32(p.Properties[NetPacket.PropertyType.GameId]); + if (mode == GameInfo.Mode.Closed) // Remove game if it is has been closed. + m_data.GameList.RemoveGameInfo(id); + else + m_data.GameList.GetGameInfo(id).CurrentMode = mode; } public void VisitRetrievePlayerInfo(NetPacketRetrievePlayerInfo p) @@ -58,8 +73,8 @@ namespace pokerth_console { // Add player to list. m_data.PlayerList.AddPlayerInfo(new PlayerInfo( - Convert.ToUInt32(p.Properties[NetPacket.PropertyType.PropPlayerId]), - p.Properties[NetPacket.PropertyType.PropPlayerName])); + Convert.ToUInt32(p.Properties[NetPacket.PropertyType.PlayerId]), + p.Properties[NetPacket.PropertyType.PlayerName])); } public void VisitJoinGame(NetPacketJoinGame p) @@ -67,8 +82,25 @@ namespace pokerth_console throw new NotImplementedException(); } + public void VisitJoinGameAck(NetPacketJoinGameAck p) + { + m_data.MyGameId = + Convert.ToUInt32(p.Properties[NetPacket.PropertyType.GameId]); + } + public void VisitStartEvent(NetPacketStartEvent p) { + // Request player names for player ids. + List playerSlots = m_data.GameList.GetGameInfo(m_data.MyGameId).PlayerSlots; + foreach (uint id in playerSlots) + { + if (!m_data.PlayerList.HasPlayer(id)) + { + NetPacketRetrievePlayerInfo request = new NetPacketRetrievePlayerInfo(); + request.Properties.Add(NetPacket.PropertyType.PlayerId, Convert.ToString(id)); + m_sender.Send(request); + } + } // Acknowledge start event. NetPacketStartEventAck ack = new NetPacketStartEventAck(); m_sender.Send(ack); @@ -81,17 +113,38 @@ namespace pokerth_console public void VisitGameStart(NetPacketGameStart p) { - // Request player names for player ids. - List playerList = p.ListProperties[NetPacket.ListPropertyType.PropPlayerSlots]; - foreach (string player in playerList) - { - if (!m_data.PlayerList.HasPlayer(Convert.ToUInt32(player))) - { - NetPacketRetrievePlayerInfo request = new NetPacketRetrievePlayerInfo(); - request.Properties.Add(NetPacket.PropertyType.PropPlayerId, player); - m_sender.Send(request); - } - } + throw new NotImplementedException(); + // TODO + } + + public void VisitHandStart(NetPacketHandStart p) + { + throw new NotImplementedException(); + // TODO + } + + public void VisitPlayersTurn(NetPacketPlayersTurn p) + { + throw new NotImplementedException(); + // TODO + } + + public void VisitPlayersAction(NetPacketPlayersAction p) + { + throw new NotImplementedException(); + // TODO + } + + public void VisitPlayersActionDone(NetPacketPlayersActionDone p) + { + throw new NotImplementedException(); + // TODO + } + + public void VisitPlayersActionRejected(NetPacketPlayersActionRejected p) + { + throw new NotImplementedException(); + // TODO } private PokerTHData m_data; diff --git a/docs/net_protocol.txt b/docs/net_protocol.txt index 1851036a..02446c86 100644 --- a/docs/net_protocol.txt +++ b/docs/net_protocol.txt @@ -636,8 +636,8 @@ Player Action: 0x05 - Raise 0x06 - All in Player Bet: - 0 (ignored) - states fold, check, - > 0 - states call, bet, raise, all in + 0 (ignored) - actions fold, check, + > 0 - atcions call, bet, raise, all in Server Notification: Player's Action Done