Cleanup work

This commit is contained in:
lotodore
2008-12-23 17:55:35 +00:00
parent 457ce36a98
commit a46d07f24e
24 changed files with 0 additions and 2116 deletions
-110
View File
@@ -1,110 +0,0 @@
/***************************************************************************
* 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;
namespace pokerth_console
{
class Client
{
public Client(Settings settings, PokerTHData data, ICallback callback)
{
m_tcpClient = new TcpClient();
m_settings = settings;
m_data = data;
m_callback = callback;
}
public void Connect()
{
// Connect to the server.
// Try IPv6 first.
/*IPAddress[] addresses = new IPAddress[2];
addresses[0] = IPAddress.Parse(m_settings.ServerSettings.IPv6Address);
addresses[1] = IPAddress.Parse(m_settings.ServerSettings.IPv4Address);
m_tcpClient.Connect(addresses, m_settings.ServerSettings.Port);*/
m_tcpClient.Connect("localhost", 7234);
}
public void Start()
{
StartSendThread();
StartReceiveThread();
SendInit();
}
public void JoinGame(uint gameId)
{
SendJoinGame(gameId);
}
public void SetTerminateFlag()
{
m_sender.SetTerminateFlag();
m_receiver.SetTerminateFlag();
}
public void WaitTermination()
{
m_sender.WaitTermination();
m_receiver.WaitTermination();
}
protected void StartReceiveThread()
{
m_receiver = new ReceiverThread(m_tcpClient.GetStream(), m_sender, m_data, m_callback);
m_receiver.Run();
}
protected void StartSendThread()
{
m_sender = new SenderThread(m_tcpClient.GetStream());
m_sender.Run();
}
protected void SendInit()
{
NetPacket init = new NetPacketInit();
init.Properties.Add(NetPacket.PropType.RequestedVersionMajor, "5");
init.Properties.Add(NetPacket.PropType.RequestedVersionMinor, "0");
init.Properties.Add(NetPacket.PropType.PlayerName, m_data.MyName);
init.Properties.Add(NetPacket.PropType.PlayerPassword, "");
m_sender.Send(init);
}
protected void SendJoinGame(uint gameId)
{
NetPacket join = new NetPacketJoinGame();
join.Properties.Add(NetPacket.PropType.GameId, Convert.ToString(gameId));
join.Properties.Add(NetPacket.PropType.GamePassword, ""); // no password for now
m_sender.Send(join);
}
private TcpClient m_tcpClient;
private ReceiverThread m_receiver;
private SenderThread m_sender;
private Settings m_settings;
private PokerTHData m_data;
private ICallback m_callback;
}
}
-45
View File
@@ -1,45 +0,0 @@
/***************************************************************************
* 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
{
interface INetPacketVisitor
{
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);
}
}
-264
View File
@@ -1,264 +0,0 @@
/***************************************************************************
* 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;
namespace pokerth_console
{
abstract class NetPacket
{
public const int NetTypeInit = 0x0001;
public const int NetTypeInitAck = 0x0002;
public const int NetTypeRetrieveAvatar = 0x0003;
public const int NetTypeAvatarHeader = 0x0004;
public const int NetTypeAvatarFile = 0x0005;
public const int NetTypeAvatarEnd = 0x0006;
public const int NetTypeUnknownAvatar = 0x0007;
public const int NetTypeGameListNew = 0x0010;
public const int NetTypeGameListUpdate = 0x0011;
public const int NetTypeGameListPlayerJoined = 0x0012;
public const int NetTypeGameListPlayerLeft = 0x0013;
public const int NetTypeGameListAdminChanged = 0x0014;
public const int NetTypeRetrievePlayerInfo = 0x0020;
public const int NetTypePlayerInfo = 0x0021;
public const int NetTypeUnknownPlayerId = 0x0022;
public const int NetTypeUnsubscribeGameList = 0x0023;
public const int NetTypeResubscribeGameList = 0x0024;
public const int NetTypeCreateGame = 0x0030;
public const int NetTypeJoinGame = 0x0031;
public const int NetTypeJoinGameAck = 0x0032;
public const int NetTypeJoinGameFailed = 0x0033;
public const int NetTypePlayerJoined = 0x0034;
public const int NetTypePlayerLeft = 0x0035;
public const int NetTypeGameAdminChanged = 0x0036;
public const int NetTypeKickPlayer = 0x0040;
public const int NetTypeLeaveCurrentGame = 0x0041;
public const int NetTypeStartEvent = 0x0042;
public const int NetTypeStartEventAck = 0x0043;
public const int NetTypeGameStart = 0x0050;
public const int NetTypeHandStart = 0x0051;
public const int NetTypePlayersTurn = 0x0052;
public const int NetTypePlayersAction = 0x0053;
public const int NetTypePlayersActionDone = 0x0054;
public const int NetTypePlayersActionRejected = 0x0055;
public const int NetTypeDealFlopCards = 0x0060;
public const int NetTypeDealTurnCard = 0x0061;
public const int NetTypeDealRiverCard = 0x0062;
public const int NetTypeAllInShowCards = 0x0063;
public const int NetTypeEndOfHandShowCards = 0x0064;
public const int NetTypeEndOfHandHideCards = 0x0065;
public const int NetTypeEndOfGame = 0x0070;
public const int NetTypeAskKickPlayer = 0x0071;
public const int NetTypeAskKickPlayerDenied = 0x0072;
public const int NetTypeStartKickPlayerPetition = 0x0073;
public const int NetTypeVoteKickPlayer = 0x0074;
public const int NetTypeVoteKickPlayerAck = 0x0075;
public const int NetTypeVoteKickPlayerDenied = 0x0076;
public const int NetTypeKickPlayerPetitionUpdate = 0x0077;
public const int NetTypeEndKickPlayerPetition = 0x0078;
public const int NetTypeStatisticsChanged = 0x0080;
public const int NetTypeRemovedFromGame = 0x0100;
public const int NetTypeTimeoutWarning = 0x0101;
public const int NetTypeResetTimeout = 0x0102;
public const int NetTypeSendChatText = 0x0200;
public const int NetTypeChatText = 0x0201;
public const int NetTypeError = 0x0400;
public enum PropType
{
RequestedVersionMajor,
RequestedVersionMinor,
PlayerId,
PlayerName,
PlayerPassword,
PlayerFlags,
PlayerRights,
PlayerAction,
PlayerBet,
PlayerBetTotal,
PlayerMoney,
LatestGameVersion,
LatestBetaRevision,
SessionId,
GameId,
GameMode,
GameName,
GamePrivacyFlags,
GamePassword,
GameState,
AdminPlayerId,
MaxNumPlayers,
RaiseIntervalMode,
RaiseSmallBlindInterval,
RaiseMode,
EndRaiseMode,
ProposedGuiSpeed,
PlayerActionTimeout,
FirstSmallBlind,
EndRaiseSmallBlindValue,
StartMoney,
CurNumPlayers,
StartFlags,
StartDealerPlayerId,
FirstCard,
SecondCard,
SmallBlind,
HighestSet,
MinimumRaise,
ActionRejectReason,
}
public enum ListPropertyType
{
PlayerSlots,
ManualBlindSlots,
}
public static NetPacket Create(int type, int size, BinaryReader reader)
{
NetPacket tmpPacket = null;
switch (type)
{
// Only consider those packets which are sent by the server.
case NetTypeInitAck :
tmpPacket = new NetPacketInitAck(size, reader);
break;
case NetTypeGameListNew :
tmpPacket = new NetPacketGameListNew(size, reader);
break;
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 :
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;
}
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)
{
m_type = type;
m_properties = new Dictionary<PropType, string>();
m_listProperties = new Dictionary<ListPropertyType, List<string>>();
}
public Dictionary<PropType, string> Properties
{
set
{
m_properties = value;
}
get
{
return m_properties;
}
}
public Dictionary<ListPropertyType, List<string>> ListProperties
{
set
{
m_listProperties = value;
}
get
{
return m_listProperties;
}
}
public int Type
{
get
{
return m_type;
}
}
public abstract void Accept(INetPacketVisitor visitor);
public abstract byte[] ToByteArray();
static protected int AddPadding(int size)
{
return ((((size) + 3) / 4) * 4);
}
private int m_type;
private Dictionary<PropType, string> m_properties;
private Dictionary<ListPropertyType, List<string>> m_listProperties;
}
}
-33
View File
@@ -1,33 +0,0 @@
/***************************************************************************
* 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 NetPacketException : Exception
{
public NetPacketException(string message)
: base(message)
{
}
}
}
-114
View File
@@ -1,114 +0,0 @@
/***************************************************************************
* 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 GameInfoData
{
u_int16_t maxNumberOfPlayers;
u_int16_t raiseIntervalMode;
u_int16_t raiseSmallBlindInterval;
u_int16_t raiseMode;
u_int16_t endRaiseMode;
u_int16_t numberOfManualBlinds;
u_int16_t proposedGuiSpeed;
u_int16_t playerActionTimeout;
u_int32_t firstSmallBlind;
u_int32_t endRaiseSmallBlindValue;
u_int32_t startMoney;
};
*/
/*
struct GCC_PACKED NetPacketGameListNewData
{
NetPacketHeader head;
u_int32_t gameId;
u_int32_t adminPlayerId;
u_int16_t gameMode;
u_int16_t gameNameLength;
u_int16_t curNumberOfPlayers;
u_int16_t gameFlags;
GameInfoData gameData;
};
*/
namespace pokerth_console
{
class NetPacketGameListNew : NetPacket
{
public NetPacketGameListNew()
: base(NetPacket.NetTypeGameListNew)
{
}
public NetPacketGameListNew(int size, BinaryReader r)
: base(NetPacket.NetTypeGameListNew)
{
if (size < 20)
throw new NetPacketException("NetPacketGameListNew invalid size.");
Properties.Add(PropType.GameId,
Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32())));
Properties.Add(PropType.AdminPlayerId,
Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32())));
Properties.Add(PropType.GameMode,
Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16())));
int gameNameLen = IPAddress.NetworkToHostOrder((short)r.ReadUInt16());
int curNumPlayers = IPAddress.NetworkToHostOrder((short)r.ReadUInt16());
Properties.Add(PropType.CurNumPlayers, Convert.ToString(curNumPlayers));
Properties.Add(PropType.GamePrivacyFlags,
Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16())));
ScanGameInfoBlock(r);
// Read name of the game.
byte[] tmpName = r.ReadBytes(gameNameLen);
Properties.Add(PropType.GameName,
Encoding.UTF8.GetString(tmpName));
// Skip the padding.
int namePadding = AddPadding(tmpName.Length) - tmpName.Length;
if (namePadding > 0)
r.ReadBytes(namePadding);
// 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.PlayerSlots, playerSlots);
}
public override void Accept(INetPacketVisitor visitor)
{
visitor.VisitGameListNew(this);
}
public override byte[] ToByteArray()
{
throw new NotImplementedException();
}
}
}
@@ -1,67 +0,0 @@
/***************************************************************************
* 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 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(PropType.GameId,
Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32())));
Properties.Add(PropType.GameMode,
Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16())));
}
public override void Accept(INetPacketVisitor visitor)
{
visitor.VisitGameListUpdate(this);
}
public override byte[] ToByteArray()
{
throw new NotImplementedException();
}
}
}
-74
View File
@@ -1,74 +0,0 @@
/***************************************************************************
* 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 NetPacketGameStartData
{
NetPacketHeader head;
u_int32_t startDealerPlayerId;
u_int16_t numberOfPlayers;
u_int16_t reserved;
};
*/
namespace pokerth_console
{
class NetPacketGameStart : NetPacket
{
public NetPacketGameStart()
: base(NetPacket.NetTypeGameStart)
{
}
public NetPacketGameStart(int size, BinaryReader r)
: base(NetPacket.NetTypeGameStart)
{
if (size < 20)
throw new NetPacketException("NetPacketGameStart invalid size.");
Properties.Add(PropType.StartDealerPlayerId,
Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32())));
int curNumPlayers = IPAddress.NetworkToHostOrder((short)r.ReadUInt16());
Properties.Add(PropType.CurNumPlayers, Convert.ToString(curNumPlayers));
r.ReadBytes(2); // reserved
// 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.PlayerSlots, playerSlots);
}
public override void Accept(INetPacketVisitor visitor)
{
visitor.VisitGameStart(this);
}
public override byte[] ToByteArray()
{
throw new NotImplementedException();
}
}
}
-69
View File
@@ -1,69 +0,0 @@
/***************************************************************************
* 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 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(PropType.FirstCard,
Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16())));
Properties.Add(PropType.SecondCard,
Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16())));
Properties.Add(PropType.SmallBlind,
Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32())));
}
public override void Accept(INetPacketVisitor visitor)
{
visitor.VisitHandStart(this);
}
public override byte[] ToByteArray()
{
throw new NotImplementedException();
}
}
}
-93
View File
@@ -1,93 +0,0 @@
/***************************************************************************
* 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 NetPacketInitData
{
NetPacketHeader head;
u_int16_t requestedVersionMajor;
u_int16_t requestedVersionMinor;
u_int16_t passwordLength;
u_int16_t playerNameLength;
u_int16_t privacyFlags;
u_int16_t reserved;
};
*/
namespace pokerth_console
{
class NetPacketInit : NetPacket
{
public NetPacketInit()
: base(NetPacket.NetTypeInit)
{
}
public override void Accept(INetPacketVisitor visitor)
{
visitor.VisitInit(this);
}
public override byte[] ToByteArray()
{
MemoryStream memStream = new MemoryStream();
BinaryWriter w = new BinaryWriter(memStream);
string playerPassword = Properties[PropType.PlayerPassword];
byte[] tmpPassword = Encoding.UTF8.GetBytes(playerPassword);
int passwordWithPadding = AddPadding(tmpPassword.Length);
string playerName = Properties[PropType.PlayerName];
byte[] tmpName = Encoding.UTF8.GetBytes(playerName);
int nameWithPadding = AddPadding(tmpName.Length);
int size = 16 + passwordWithPadding + nameWithPadding;
w.Write(IPAddress.HostToNetworkOrder((short)Type));
w.Write(IPAddress.HostToNetworkOrder((short)size));
w.Write(IPAddress.HostToNetworkOrder((short)
Convert.ToUInt16(Properties[PropType.RequestedVersionMajor])));
w.Write(IPAddress.HostToNetworkOrder((short)
Convert.ToUInt16(Properties[PropType.RequestedVersionMinor])));
w.Write(IPAddress.HostToNetworkOrder((short)playerPassword.Length));
w.Write(IPAddress.HostToNetworkOrder((short)playerName.Length));
w.Write(IPAddress.HostToNetworkOrder((short)0)); // Privacy flags.
w.Write(IPAddress.HostToNetworkOrder((short)0)); // Reserved.
w.Write(tmpPassword);
// Add padding.
int passwordPadding = passwordWithPadding - tmpPassword.Length;
if (passwordPadding > 0)
w.Write(new byte[passwordPadding]);
w.Write(tmpName);
// Add padding.
int namePadding = nameWithPadding - tmpName.Length;
if (namePadding > 0)
w.Write(new byte[namePadding]);
return memStream.ToArray();
}
}
}
-72
View File
@@ -1,72 +0,0 @@
/***************************************************************************
* 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 NetPacketInitAckData
{
NetPacketHeader head;
u_int16_t latestGameVersion;
u_int16_t latestBetaRevision;
u_int32_t sessionId;
u_int32_t playerId;
};
*/
namespace pokerth_console
{
class NetPacketInitAck : NetPacket
{
public NetPacketInitAck()
: base(NetPacket.NetTypeInitAck)
{
}
public NetPacketInitAck(int size, BinaryReader r)
: base(NetPacket.NetTypeInitAck)
{
if (size != 16)
throw new NetPacketException("NetPacketInitAck invalid size.");
Properties.Add(PropType.LatestGameVersion,
Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16())));
Properties.Add(PropType.LatestBetaRevision,
Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16())));
Properties.Add(PropType.SessionId,
Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32())));
Properties.Add(PropType.PlayerId,
Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32())));
}
public override void Accept(INetPacketVisitor visitor)
{
visitor.VisitInitAck(this);
}
public override byte[] ToByteArray()
{
throw new NotImplementedException();
}
}
}
-76
View File
@@ -1,76 +0,0 @@
/***************************************************************************
* 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 void Accept(INetPacketVisitor visitor)
{
visitor.VisitJoinGame(this);
}
public override byte[] ToByteArray()
{
MemoryStream memStream = new MemoryStream();
BinaryWriter w = new BinaryWriter(memStream);
string gamePassword = Properties[PropType.GamePassword];
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[PropType.GameId])));
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();
}
}
}
-72
View File
@@ -1,72 +0,0 @@
/***************************************************************************
* 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 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(PropType.GameId,
Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32())));
Properties.Add(PropType.PlayerRights,
Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16())));
r.ReadUInt16(); // reserved
// Scan game info block
ScanGameInfoBlock(r);
}
public override void Accept(INetPacketVisitor visitor)
{
visitor.VisitJoinGameAck(this);
}
public override byte[] ToByteArray()
{
throw new NotImplementedException();
}
}
}
-79
View File
@@ -1,79 +0,0 @@
/***************************************************************************
* 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(PropType.PlayerId,
Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32())));
int playerFlags = IPAddress.NetworkToHostOrder((short)r.ReadUInt16());
Properties.Add(PropType.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(PropType.PlayerName,
Encoding.UTF8.GetString(tmpName));
}
public override void Accept(INetPacketVisitor visitor)
{
visitor.VisitPlayerInfo(this);
}
public override byte[] ToByteArray()
{
throw new NotImplementedException();
}
}
}
-68
View File
@@ -1,68 +0,0 @@
/***************************************************************************
* 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 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[PropType.GameState])));
w.Write(IPAddress.HostToNetworkOrder((short)
Convert.ToUInt16(Properties[PropType.PlayerAction])));
w.Write(IPAddress.HostToNetworkOrder((int)
Convert.ToUInt32(Properties[PropType.PlayerBet])));
return memStream.ToArray();
}
}
}
@@ -1,81 +0,0 @@
/***************************************************************************
* 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 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(PropType.PlayerId,
Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32())));
Properties.Add(PropType.GameState,
Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16())));
Properties.Add(PropType.PlayerAction,
Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16())));
Properties.Add(PropType.PlayerBetTotal,
Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32())));
Properties.Add(PropType.PlayerMoney,
Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32())));
Properties.Add(PropType.HighestSet,
Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32())));
Properties.Add(PropType.MinimumRaise,
Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32())));
}
public override void Accept(INetPacketVisitor visitor)
{
visitor.VisitPlayersActionDone(this);
}
public override byte[] ToByteArray()
{
throw new NotImplementedException();
}
}
}
@@ -1,73 +0,0 @@
/***************************************************************************
* 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 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(PropType.GameState,
Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16())));
Properties.Add(PropType.PlayerAction,
Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16())));
Properties.Add(PropType.PlayerBet,
Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32())));
Properties.Add(PropType.ActionRejectReason,
Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16())));
}
public override void Accept(INetPacketVisitor visitor)
{
visitor.VisitPlayersActionRejected(this);
}
public override byte[] ToByteArray()
{
throw new NotImplementedException();
}
}
}
-67
View File
@@ -1,67 +0,0 @@
/***************************************************************************
* 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 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(PropType.PlayerId,
Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32())));
Properties.Add(PropType.GameState,
Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16())));
}
public override void Accept(INetPacketVisitor visitor)
{
visitor.VisitPlayersTurn(this);
}
public override byte[] ToByteArray()
{
throw new NotImplementedException();
}
}
}
@@ -1,62 +0,0 @@
/***************************************************************************
* 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 void Accept(INetPacketVisitor visitor)
{
visitor.VisitRetrievePlayerInfo(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((int)
Convert.ToUInt32(Properties[PropType.PlayerId])));
return memStream.ToArray();
}
}
}
-73
View File
@@ -1,73 +0,0 @@
/***************************************************************************
* 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 NetPacketStartEventData
{
NetPacketHeader head;
u_int16_t startFlags;
u_int16_t reserved;
};
*/
namespace pokerth_console
{
class NetPacketStartEvent : NetPacket
{
public NetPacketStartEvent()
: base(NetPacket.NetTypeStartEvent)
{
}
public NetPacketStartEvent(int size, BinaryReader r)
: base(NetPacket.NetTypeStartEvent)
{
if (size != 8)
throw new NetPacketException("NetTypeStartEvent invalid size.");
Properties.Add(PropType.StartFlags,
Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16())));
}
public override void Accept(INetPacketVisitor visitor)
{
visitor.VisitStartEvent(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[PropType.StartFlags])));
w.Write(IPAddress.HostToNetworkOrder((short)0)); // reserved
return memStream.ToArray();
}
}
}
-61
View File
@@ -1,61 +0,0 @@
/***************************************************************************
* 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 NetPacketStartEventAckData
{
NetPacketHeader head;
u_int32_t reserved;
};
*/
namespace pokerth_console
{
class NetPacketStartEventAck : NetPacket
{
public NetPacketStartEventAck()
: base(NetPacket.NetTypeStartEventAck)
{
}
public override void Accept(INetPacketVisitor visitor)
{
visitor.VisitStartEventAck(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((int)0)); // reserved
return memStream.ToArray();
}
}
}
-184
View File
@@ -1,184 +0,0 @@
/***************************************************************************
* 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 NetParser : INetPacketVisitor
{
public NetParser(PokerTHData data, SenderThread sender, ICallback callback)
{
m_data = data;
m_sender = sender;
m_callback = callback;
}
public void VisitInit(NetPacketInit p)
{
throw new NotImplementedException();
}
public void VisitInitAck(NetPacketInitAck p)
{
m_data.MyPlayerId =
Convert.ToUInt32(p.Properties[NetPacket.PropType.PlayerId]);
m_callback.InitDone();
}
public void VisitGameListNew(NetPacketGameListNew p)
{
// Add game to list.
m_data.GameList.AddGameInfo(new GameInfo(
Convert.ToUInt32(p.Properties[NetPacket.PropType.GameId]),
p.Properties[NetPacket.PropType.GameName],
(GameInfo.Mode)Convert.ToInt32(p.Properties[NetPacket.PropType.GameMode]),
p.ListProperties[NetPacket.ListPropertyType.PlayerSlots].
ConvertAll<uint>(Convert.ToUInt32),
Convert.ToUInt32(p.Properties[NetPacket.PropType.StartMoney])));
}
public void VisitGameListUpdate(NetPacketGameListUpdate p)
{
GameInfo.Mode mode =
(GameInfo.Mode)Convert.ToInt32(p.Properties[NetPacket.PropType.GameMode]);
uint id = Convert.ToUInt32(p.Properties[NetPacket.PropType.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)
{
throw new NotImplementedException();
}
public void VisitPlayerInfo(NetPacketPlayerInfo p)
{
// Add player to list.
m_data.PlayerList.AddPlayerInfo(new PlayerInfo(
Convert.ToUInt32(p.Properties[NetPacket.PropType.PlayerId]),
p.Properties[NetPacket.PropType.PlayerName]));
}
public void VisitJoinGame(NetPacketJoinGame p)
{
throw new NotImplementedException();
}
public void VisitJoinGameAck(NetPacketJoinGameAck p)
{
m_data.MyGameId =
Convert.ToUInt32(p.Properties[NetPacket.PropType.GameId]);
m_callback.JoinedGame(m_data.GameList.GetGameInfo(m_data.MyGameId).Name);
}
public void VisitStartEvent(NetPacketStartEvent p)
{
// Request player names for player ids.
List<uint> 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.PropType.PlayerId, Convert.ToString(id));
m_sender.Send(request);
}
}
// Acknowledge start event.
NetPacketStartEventAck ack = new NetPacketStartEventAck();
m_sender.Send(ack);
}
public void VisitStartEventAck(NetPacketStartEventAck p)
{
throw new NotImplementedException();
}
public void VisitGameStart(NetPacketGameStart p)
{
// Generate player list, for gui and as hand data.
List<string> strPlayers = new List<string>();
List<uint> slots = p.ListProperties[NetPacket.ListPropertyType.PlayerSlots].
ConvertAll<uint>(Convert.ToUInt32);
m_players = new Dictionary<uint, Player>();
foreach (uint i in slots)
{
if (m_data.PlayerList.HasPlayer(i))
strPlayers.Add(m_data.PlayerList.GetPlayerInfo(i).Name);
else if (i == m_data.MyPlayerId)
strPlayers.Add(m_data.MyName);
else
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(strPlayers);
}
public void VisitHandStart(NetPacketHandStart p)
{
int[] tmpCards = new int[2];
tmpCards[0] =
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)
{
// TODO
}
public void VisitPlayersAction(NetPacketPlayersAction p)
{
throw new NotImplementedException();
}
public void VisitPlayersActionDone(NetPacketPlayersActionDone p)
{
// TODO
}
public void VisitPlayersActionRejected(NetPacketPlayersActionRejected p)
{
// TODO
}
private PokerTHData m_data;
private SenderThread m_sender;
private ICallback m_callback;
private Dictionary<uint, Player> m_players;
}
}
-87
View File
@@ -1,87 +0,0 @@
/***************************************************************************
* 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.Threading;
using System.Net;
using System.Net.Sockets;
using System.IO;
namespace pokerth_console
{
abstract class NetThread
{
public NetThread(NetworkStream stream)
{
m_thread = new Thread(ThreadProc);
m_terminateFlag = false;
m_terminateFlagMutex = new System.Object();
m_netStream = stream;
}
public void Run()
{
m_thread.Start(this);
}
protected NetworkStream NetStream
{
get
{
return m_netStream;
}
}
protected static void ThreadProc(object obj)
{
NetThread me = (NetThread)obj;
me.Start();
}
protected abstract void Start();
public void WaitTermination()
{
m_thread.Join();
}
public void SetTerminateFlag()
{
lock (m_terminateFlagMutex)
{
m_terminateFlag = true;
}
}
protected bool IsTerminateFlagSet()
{
lock (m_terminateFlagMutex)
{
return m_terminateFlag;
}
}
private Thread m_thread;
private bool m_terminateFlag;
private Object m_terminateFlagMutex;
private NetworkStream m_netStream;
}
}
-124
View File
@@ -1,124 +0,0 @@
/***************************************************************************
* 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.Threading;
using System.Net;
using System.Net.Sockets;
using System.IO;
namespace pokerth_console
{
class ReceiverThread : NetThread
{
const uint MaxPacketSize = 268;
const uint MinPacketSize = 8;
public ReceiverThread(NetworkStream stream, SenderThread sender, PokerTHData data, ICallback callback)
: base(stream)
{
m_recBuf = new byte[8192];
m_recBufOffset = 0;
m_packetList = new List<NetPacket>();
m_sender = sender;
m_parser = new NetParser(data, sender, callback);
}
protected override void Start()
{
while (!IsTerminateFlagSet())
{
ReadFromStream();
ScanPackets();
ParsePackets();
}
}
protected void ReadFromStream()
{
if (NetStream.DataAvailable)
m_recBufOffset += NetStream.Read(m_recBuf, m_recBufOffset, m_recBuf.Length - m_recBufOffset);
else
Thread.Sleep(15);
}
protected void ScanPackets()
{
bool packetFound;
do
{
packetFound = false;
if (m_recBufOffset >= MinPacketSize)
{
// Treat input buffer as memory stream.
MemoryStream memStream = new MemoryStream(m_recBuf);
BinaryReader r = new BinaryReader(memStream);
int type = IPAddress.NetworkToHostOrder((short)r.ReadUInt16());
int size = IPAddress.NetworkToHostOrder((short)r.ReadUInt16());
if (m_recBufOffset >= size)
{
packetFound = true;
if (size > MaxPacketSize)
{
// Ignore packets which are too long.
m_recBufOffset -= size;
}
else
{
// Scan Packet.
NetPacket packet = NetPacket.Create(type, size, r);
if (packet != null)
m_packetList.Add(packet);
// Advance within buf.
if (m_recBufOffset > size)
{
for (int i = size, j = 0; i < m_recBufOffset; i++, j++)
{
m_recBuf[j] = m_recBuf[i];
}
m_recBufOffset -= size;
}
else
m_recBufOffset = 0;
}
}
}
}
while (packetFound);
}
protected void ParsePackets()
{
foreach (NetPacket p in m_packetList)
{
p.Accept(m_parser);
}
m_packetList.Clear();
}
private byte[] m_recBuf;
private int m_recBufOffset;
private List<NetPacket> m_packetList;
private SenderThread m_sender;
private NetParser m_parser;
}
}
-68
View File
@@ -1,68 +0,0 @@
/***************************************************************************
* 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.Threading;
using System.Net;
using System.Net.Sockets;
using System.IO;
namespace pokerth_console
{
class SenderThread : NetThread
{
public SenderThread(NetworkStream stream)
: base(stream)
{
m_packetQueue = new Queue<NetPacket>();
}
public void Send(NetPacket p)
{
lock (m_packetQueue)
{
m_packetQueue.Enqueue(p);
}
}
protected override void Start()
{
while (!IsTerminateFlagSet())
{
bool sleep = false;
lock (m_packetQueue)
{
if (m_packetQueue.Count > 0)
{
byte[] outBuf = m_packetQueue.Dequeue().ToByteArray();
NetStream.Write(outBuf, 0, outBuf.Length);
}
else
sleep = true;
}
if (sleep)
Thread.Sleep(15);
}
}
private Queue<NetPacket> m_packetQueue;
}
}