diff --git a/console/src/GameInfo.cs b/console/src/GameInfo.cs index cab72ad5..104301c5 100644 --- a/console/src/GameInfo.cs +++ b/console/src/GameInfo.cs @@ -25,16 +25,23 @@ namespace pokerth_console { class GameInfo { - public GameInfo(string name) + public GameInfo(uint id, string name) { + m_id = id; m_name = name; } + public uint GetId() + { + return m_id; + } + public override string ToString() { return m_name; } + private uint m_id; private string m_name; } } diff --git a/console/src/ServerSettings.cs b/console/src/ServerSettings.cs index dcde909b..037dc63d 100644 --- a/console/src/ServerSettings.cs +++ b/console/src/ServerSettings.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; diff --git a/console/src/Settings.cs b/console/src/Settings.cs index 5ada5eda..e8c6a607 100644 --- a/console/src/Settings.cs +++ b/console/src/Settings.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.Xml; diff --git a/console/src/net/Client.cs b/console/src/net/Client.cs index 18ac4602..11967111 100644 --- a/console/src/net/Client.cs +++ b/console/src/net/Client.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/NetPacket.cs b/console/src/net/NetPacket.cs index 590af1ca..884d1833 100644 --- a/console/src/net/NetPacket.cs +++ b/console/src/net/NetPacket.cs @@ -92,18 +92,25 @@ namespace pokerth_console { PropRequestedVersionMajor, PropRequestedVersionMinor, + PropPlayerId, PropPlayerName, PropPlayerPassword, + PropPlayerFlags, PropLatestGameVersion, PropLatestBetaRevision, PropSessionId, - PropPlayerId, PropGameId, - PropAdminPlayerId, PropGameMode, PropGameName, - PropCurNumPlayers, - PropGameFlags + PropGamePrivacyFlags, + PropGamePassword, + PropAdminPlayerId, + PropCurNumPlayers + } + + public enum ListPropertyType + { + PropPlayerSlots } public static NetPacket Create(int type, int size, BinaryReader reader) @@ -128,6 +135,7 @@ namespace pokerth_console { m_type = type; m_properties = new Dictionary(); + m_listProperties = new Dictionary>(); } public Dictionary Properties @@ -142,6 +150,18 @@ namespace pokerth_console } } + public Dictionary> ListProperties + { + set + { + m_listProperties = value; + } + get + { + return m_listProperties; + } + } + public int Type { get @@ -159,5 +179,6 @@ namespace pokerth_console private int m_type; private Dictionary m_properties; + private Dictionary> m_listProperties; } } diff --git a/console/src/net/NetPacketGameListNew.cs b/console/src/net/NetPacketGameListNew.cs index f88200a9..11d2ca7f 100644 --- a/console/src/net/NetPacketGameListNew.cs +++ b/console/src/net/NetPacketGameListNew.cs @@ -78,16 +78,23 @@ namespace pokerth_console int gameNameLen = IPAddress.NetworkToHostOrder((short)r.ReadUInt16()); - Properties.Add(PropertyType.PropCurNumPlayers, - Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16()))); - Properties.Add(PropertyType.PropGameFlags, + int curNumPlayers = IPAddress.NetworkToHostOrder((short)r.ReadUInt16()); + Properties.Add(PropertyType.PropCurNumPlayers, Convert.ToString(curNumPlayers)); + Properties.Add(PropertyType.PropGamePrivacyFlags, 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, Encoding.UTF8.GetString(tmpName)); + + // Read player ids. + List playerSlots = new List(); + for (int i = 0; i < curNumPlayers; i++) + playerSlots.Add(Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32()))); + ListProperties.Add(ListPropertyType.PropPlayerSlots, playerSlots); } public override byte[] ToByteArray() diff --git a/console/src/net/NetPacketInit.cs b/console/src/net/NetPacketInit.cs index 4a1813ff..ad5c4214 100644 --- a/console/src/net/NetPacketInit.cs +++ b/console/src/net/NetPacketInit.cs @@ -50,6 +50,7 @@ namespace pokerth_console { MemoryStream memStream = new MemoryStream(); BinaryWriter w = new BinaryWriter(memStream); + string playerPassword = Properties[PropertyType.PropPlayerPassword]; byte[] tmpPassword = Encoding.UTF8.GetBytes(playerPassword); int passwordWithPadding = AddPadding(tmpPassword.Length); @@ -58,7 +59,7 @@ namespace pokerth_console int nameWithPadding = AddPadding(tmpName.Length); int size = 16 + passwordWithPadding + nameWithPadding; - w.Write(IPAddress.HostToNetworkOrder((short)NetPacket.NetTypeInit)); + w.Write(IPAddress.HostToNetworkOrder((short)Type)); w.Write(IPAddress.HostToNetworkOrder((short)size)); w.Write(IPAddress.HostToNetworkOrder((short) Convert.ToUInt16(Properties[PropertyType.PropRequestedVersionMajor]))); diff --git a/console/src/net/NetPacketJoinGame.cs b/console/src/net/NetPacketJoinGame.cs new file mode 100644 index 00000000..02dd982d --- /dev/null +++ b/console/src/net/NetPacketJoinGame.cs @@ -0,0 +1,71 @@ +/*************************************************************************** + * 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 NetPacketJoinGameData +{ + NetPacketHeader head; + u_int32_t gameId; + u_int16_t passwordLength; + u_int16_t reserved; +}; +*/ + +namespace pokerth_console +{ + class NetPacketJoinGame : NetPacket + { + public NetPacketJoinGame() + : base(NetPacket.NetTypeJoinGame) + { + } + + public override byte[] ToByteArray() + { + MemoryStream memStream = new MemoryStream(); + BinaryWriter w = new BinaryWriter(memStream); + + string gamePassword = Properties[PropertyType.PropGamePassword]; + byte[] tmpPassword = Encoding.UTF8.GetBytes(gamePassword); + int passwordWithPadding = AddPadding(tmpPassword.Length); + int size = 12 + passwordWithPadding; + + w.Write(IPAddress.HostToNetworkOrder((short)Type)); + w.Write(IPAddress.HostToNetworkOrder((short)size)); + w.Write(IPAddress.HostToNetworkOrder((int) + Convert.ToUInt32(Properties[PropertyType.PropGameId]))); + w.Write(IPAddress.HostToNetworkOrder((short)gamePassword.Length)); + w.Write(IPAddress.HostToNetworkOrder((short)0)); // Reserved. + + // Add padding. + int passwordPadding = passwordWithPadding - tmpPassword.Length; + if (passwordPadding > 0) + w.Write(new byte[passwordPadding]); + + return memStream.ToArray(); + } + } +} diff --git a/console/src/net/NetPacketPlayerInfo.cs b/console/src/net/NetPacketPlayerInfo.cs new file mode 100644 index 00000000..19e4f1c5 --- /dev/null +++ b/console/src/net/NetPacketPlayerInfo.cs @@ -0,0 +1,74 @@ +/*************************************************************************** + * 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 NetPacketPlayerInfoData +{ + NetPacketHeader head; + u_int32_t playerId; + u_int16_t playerFlags; + u_int16_t playerNameLength; + u_int32_t reserved; +}; +*/ + +namespace pokerth_console +{ + class NetPacketPlayerInfo : NetPacket + { + public const int PlayerFlagHuman = 0x01; + public const int PlayerFlagAvatar = 0x02; + + public NetPacketPlayerInfo() + : base(NetPacket.NetTypePlayerInfo) + { + } + + public NetPacketPlayerInfo(int size, BinaryReader r) + : base(NetPacket.NetTypePlayerInfo) + { + if (size < 16) + throw new NetPacketException("NetPacketPlayerInfo invalid size."); + Properties.Add(PropertyType.PropPlayerId, + Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32()))); + int playerFlags = IPAddress.NetworkToHostOrder((short)r.ReadUInt16()); + Properties.Add(PropertyType.PropPlayerFlags, 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, + Encoding.UTF8.GetString(tmpName)); + } + + public override byte[] ToByteArray() + { + throw new NotImplementedException(); + } + } +} diff --git a/console/src/net/NetPacketRetrievePlayerInfo.cs b/console/src/net/NetPacketRetrievePlayerInfo.cs new file mode 100644 index 00000000..38ac43cd --- /dev/null +++ b/console/src/net/NetPacketRetrievePlayerInfo.cs @@ -0,0 +1,57 @@ +/*************************************************************************** + * 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 NetPacketRetrievePlayerInfoData +{ + NetPacketHeader head; + u_int32_t playerId; +}; +*/ + +namespace pokerth_console +{ + class NetPacketRetrievePlayerInfo : NetPacket + { + public NetPacketRetrievePlayerInfo() + : base(NetPacket.NetTypeRetrievePlayerInfo) + { + } + + 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((int) + Convert.ToUInt32(Properties[PropertyType.PropPlayerId]))); + + return memStream.ToArray(); + } + } +} diff --git a/console/src/net/ReceiverThread.cs b/console/src/net/ReceiverThread.cs index c52317e9..f116bb2b 100644 --- a/console/src/net/ReceiverThread.cs +++ b/console/src/net/ReceiverThread.cs @@ -147,6 +147,7 @@ namespace pokerth_console if (p.Type == NetPacket.NetTypeGameListNew) { m_lobbyGameInfoList.AddGameInfo(new GameInfo( + Convert.ToUInt32(p.Properties[NetPacket.PropertyType.PropGameId]), p.Properties[NetPacket.PropertyType.PropGameName])); } }