Console client: New packet types. Preparing to join game.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.Text;
|
||||
|
||||
|
||||
+20
-1
@@ -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.Text;
|
||||
using System.Xml;
|
||||
|
||||
@@ -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.Text;
|
||||
using System.Net;
|
||||
|
||||
@@ -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<PropertyType, string>();
|
||||
m_listProperties = new Dictionary<ListPropertyType, List<string>>();
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
get
|
||||
@@ -159,5 +179,6 @@ namespace pokerth_console
|
||||
|
||||
private int m_type;
|
||||
private Dictionary<PropertyType, string> m_properties;
|
||||
private Dictionary<ListPropertyType, List<string>> m_listProperties;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<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()
|
||||
|
||||
@@ -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])));
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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]));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user