Console client: New packet types. Preparing to join game.

This commit is contained in:
lotodore
2008-12-21 01:37:17 +00:00
parent 4f78b32f9d
commit 2aec6c8534
11 changed files with 308 additions and 12 deletions
+8 -1
View File
@@ -25,16 +25,23 @@ namespace pokerth_console
{ {
class GameInfo class GameInfo
{ {
public GameInfo(string name) public GameInfo(uint id, string name)
{ {
m_id = id;
m_name = name; m_name = name;
} }
public uint GetId()
{
return m_id;
}
public override string ToString() public override string ToString()
{ {
return m_name; return m_name;
} }
private uint m_id;
private string m_name; private string m_name;
} }
} }
+20 -1
View File
@@ -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 <http://www.gnu.org/licenses/>. *
***************************************************************************/
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
+20 -1
View File
@@ -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 <http://www.gnu.org/licenses/>. *
***************************************************************************/
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
using System.Xml; using System.Xml;
+20 -1
View File
@@ -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 <http://www.gnu.org/licenses/>. *
***************************************************************************/
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
using System.Net; using System.Net;
+25 -4
View File
@@ -92,18 +92,25 @@ namespace pokerth_console
{ {
PropRequestedVersionMajor, PropRequestedVersionMajor,
PropRequestedVersionMinor, PropRequestedVersionMinor,
PropPlayerId,
PropPlayerName, PropPlayerName,
PropPlayerPassword, PropPlayerPassword,
PropPlayerFlags,
PropLatestGameVersion, PropLatestGameVersion,
PropLatestBetaRevision, PropLatestBetaRevision,
PropSessionId, PropSessionId,
PropPlayerId,
PropGameId, PropGameId,
PropAdminPlayerId,
PropGameMode, PropGameMode,
PropGameName, PropGameName,
PropCurNumPlayers, PropGamePrivacyFlags,
PropGameFlags PropGamePassword,
PropAdminPlayerId,
PropCurNumPlayers
}
public enum ListPropertyType
{
PropPlayerSlots
} }
public static NetPacket Create(int type, int size, BinaryReader reader) public static NetPacket Create(int type, int size, BinaryReader reader)
@@ -128,6 +135,7 @@ namespace pokerth_console
{ {
m_type = type; m_type = type;
m_properties = new Dictionary<PropertyType, string>(); m_properties = new Dictionary<PropertyType, string>();
m_listProperties = new Dictionary<ListPropertyType, List<string>>();
} }
public Dictionary<PropertyType, string> Properties public Dictionary<PropertyType, string> Properties
@@ -142,6 +150,18 @@ namespace pokerth_console
} }
} }
public Dictionary<ListPropertyType, List<string>> ListProperties
{
set
{
m_listProperties = value;
}
get
{
return m_listProperties;
}
}
public int Type public int Type
{ {
get get
@@ -159,5 +179,6 @@ namespace pokerth_console
private int m_type; private int m_type;
private Dictionary<PropertyType, string> m_properties; private Dictionary<PropertyType, string> m_properties;
private Dictionary<ListPropertyType, List<string>> m_listProperties;
} }
} }
+10 -3
View File
@@ -78,16 +78,23 @@ namespace pokerth_console
int gameNameLen = IPAddress.NetworkToHostOrder((short)r.ReadUInt16()); int gameNameLen = IPAddress.NetworkToHostOrder((short)r.ReadUInt16());
Properties.Add(PropertyType.PropCurNumPlayers, int curNumPlayers = IPAddress.NetworkToHostOrder((short)r.ReadUInt16());
Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16()))); Properties.Add(PropertyType.PropCurNumPlayers, Convert.ToString(curNumPlayers));
Properties.Add(PropertyType.PropGameFlags, Properties.Add(PropertyType.PropGamePrivacyFlags,
Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16()))); Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16())));
r.ReadBytes(28); // Skip game info block for now. r.ReadBytes(28); // Skip game info block for now.
// Read name of the game.
byte[] tmpName = r.ReadBytes(gameNameLen); byte[] tmpName = r.ReadBytes(gameNameLen);
Properties.Add(PropertyType.PropGameName, Properties.Add(PropertyType.PropGameName,
Encoding.UTF8.GetString(tmpName)); Encoding.UTF8.GetString(tmpName));
// Read player ids.
List<string> playerSlots = new List<string>();
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() public override byte[] ToByteArray()
+2 -1
View File
@@ -50,6 +50,7 @@ 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.PropPlayerPassword]; string playerPassword = Properties[PropertyType.PropPlayerPassword];
byte[] tmpPassword = Encoding.UTF8.GetBytes(playerPassword); byte[] tmpPassword = Encoding.UTF8.GetBytes(playerPassword);
int passwordWithPadding = AddPadding(tmpPassword.Length); int passwordWithPadding = AddPadding(tmpPassword.Length);
@@ -58,7 +59,7 @@ namespace pokerth_console
int nameWithPadding = AddPadding(tmpName.Length); int nameWithPadding = AddPadding(tmpName.Length);
int size = 16 + passwordWithPadding + nameWithPadding; 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)size));
w.Write(IPAddress.HostToNetworkOrder((short) w.Write(IPAddress.HostToNetworkOrder((short)
Convert.ToUInt16(Properties[PropertyType.PropRequestedVersionMajor]))); Convert.ToUInt16(Properties[PropertyType.PropRequestedVersionMajor])));
+71
View File
@@ -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 <http://www.gnu.org/licenses/>. *
***************************************************************************/
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();
}
}
}
+74
View File
@@ -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 <http://www.gnu.org/licenses/>. *
***************************************************************************/
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();
}
}
}
@@ -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 <http://www.gnu.org/licenses/>. *
***************************************************************************/
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();
}
}
}
+1
View File
@@ -147,6 +147,7 @@ namespace pokerth_console
if (p.Type == NetPacket.NetTypeGameListNew) if (p.Type == NetPacket.NetTypeGameListNew)
{ {
m_lobbyGameInfoList.AddGameInfo(new GameInfo( m_lobbyGameInfoList.AddGameInfo(new GameInfo(
Convert.ToUInt32(p.Properties[NetPacket.PropertyType.PropGameId]),
p.Properties[NetPacket.PropertyType.PropGameName])); p.Properties[NetPacket.PropertyType.PropGameName]));
} }
} }