Console client: Adding proper termination after the game. Adding missing source files.

This commit is contained in:
lotodore
2008-12-26 18:27:48 +00:00
parent 8de66094f3
commit 6f9129818c
12 changed files with 456 additions and 54 deletions
+2 -1
View File
@@ -41,7 +41,8 @@ namespace pokerth_lib
void ShowCards(string name, int[] cards);
void EndOfHandShowCards(string name, int[] cards, int cardsValue, bool allIn);
void HandResult();
void PlayerWins(string name, uint moneyWon);
void PlayerWinsHand(string name, uint moneyWon);
void PlayerWinsGame(string name);
void Error(string message);
}
}
+2
View File
@@ -36,6 +36,7 @@ namespace pokerth_lib
void VisitCreateGame(NetPacket p);
void VisitJoinGame(NetPacket p);
void VisitJoinGameAck(NetPacket p);
void VisitLeaveCurrentGame(NetPacket p);
void VisitStartEvent(NetPacket p);
void VisitStartEventAck(NetPacket p);
void VisitGameStart(NetPacket p);
@@ -50,6 +51,7 @@ namespace pokerth_lib
void VisitAllInShowCards(NetPacket p);
void VisitEndOfHandShowCards(NetPacket p);
void VisitEndOfHandHideCards(NetPacket p);
void VisitEndOfGame(NetPacket p);
void VisitError(NetPacket p);
}
}
+3
View File
@@ -218,6 +218,9 @@ namespace pokerth_lib
case NetTypeEndOfHandHideCards :
tmpPacket = new NetPacketEndOfHandHideCards(size, reader);
break;
case NetTypeEndOfGame :
tmpPacket = new NetPacketEndOfGame(size, reader);
break;
case NetTypeError :
tmpPacket = new NetPacketError(size, reader);
break;
@@ -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;
namespace pokerth_lib
{
class NetPacketAllInShowCards : NetPacket
{
public NetPacketAllInShowCards()
: base(NetPacket.NetTypeAllInShowCards)
{
}
public NetPacketAllInShowCards(int size, BinaryReader r)
: base(NetPacket.NetTypeAllInShowCards)
{
if (size < 16)
throw new NetPacketException("NetPacketAllInShowCards invalid size.");
int numPlayerCards = IPAddress.NetworkToHostOrder((short)r.ReadUInt16());
r.ReadUInt16(); //reserved
List<Dictionary<PropType, string>> tmpRecordList = new List<Dictionary<PropType, string>>();
for (int i = 0; i < numPlayerCards; i++)
{
Dictionary<PropType, string> tmpList = new Dictionary<PropType, string>();
tmpList.Add(PropType.PlayerId,
Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32())));
tmpList.Add(PropType.FirstCard,
Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16())));
tmpList.Add(PropType.SecondCard,
Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16())));
tmpRecordList.Add(tmpList);
}
RecordProperties.Add(RecordPropType.PlayerCards, tmpRecordList);
}
public override void Accept(INetPacketVisitor visitor)
{
visitor.VisitAllInShowCards(this);
}
public override byte[] ToByteArray()
{
throw new NotImplementedException();
}
}
}
+56
View File
@@ -0,0 +1,56 @@
/***************************************************************************
* 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_lib
{
class NetPacketEndOfGame : NetPacket
{
public NetPacketEndOfGame()
: base(NetPacket.NetTypeEndOfGame)
{
}
public NetPacketEndOfGame(int size, BinaryReader r)
: base(NetPacket.NetTypeEndOfGame)
{
if (size != 8)
throw new NetPacketException("NetPacketEndOfGame invalid size.");
Properties.Add(PropType.PlayerId,
Convert.ToString(IPAddress.NetworkToHostOrder((int)r.ReadUInt32())));
}
public override void Accept(INetPacketVisitor visitor)
{
visitor.VisitEndOfGame(this);
}
public override byte[] ToByteArray()
{
throw new NotImplementedException();
}
}
}
+56
View File
@@ -0,0 +1,56 @@
/***************************************************************************
* 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_lib
{
class NetPacketError : NetPacket
{
public NetPacketError()
: base(NetPacket.NetTypeError)
{
}
public NetPacketError(int size, BinaryReader r)
: base(NetPacket.NetTypeError)
{
if (size != 8)
throw new NetPacketException("NetPacketError invalid size.");
Properties.Add(PropType.ErrorReason,
Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16())));
}
public override void Accept(INetPacketVisitor visitor)
{
visitor.VisitError(this);
}
public override byte[] ToByteArray()
{
throw new NotImplementedException();
}
}
}
@@ -0,0 +1,58 @@
/***************************************************************************
* 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_lib
{
class NetPacketGameListPlayerJoined : NetPacket
{
public NetPacketGameListPlayerJoined()
: base(NetPacket.NetTypeGameListPlayerJoined)
{
}
public NetPacketGameListPlayerJoined(int size, BinaryReader r)
: base(NetPacket.NetTypeGameListPlayerJoined)
{
if (size != 12)
throw new NetPacketException("NetPacketGameListPlayerJoined invalid size.");
Properties.Add(PropType.GameId,
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.VisitGameListPlayerJoined(this);
}
public override byte[] ToByteArray()
{
throw new NotImplementedException();
}
}
}
@@ -0,0 +1,58 @@
/***************************************************************************
* 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_lib
{
class NetPacketGameListPlayerLeft : NetPacket
{
public NetPacketGameListPlayerLeft()
: base(NetPacket.NetTypeGameListPlayerLeft)
{
}
public NetPacketGameListPlayerLeft(int size, BinaryReader r)
: base(NetPacket.NetTypeGameListPlayerLeft)
{
if (size != 12)
throw new NetPacketException("NetPacketGameListPlayerLeft invalid size.");
Properties.Add(PropType.GameId,
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.VisitGameListPlayerLeft(this);
}
public override byte[] ToByteArray()
{
throw new NotImplementedException();
}
}
}
@@ -0,0 +1,54 @@
/***************************************************************************
* 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_lib
{
class NetPacketLeaveCurrentGame : NetPacket
{
public NetPacketLeaveCurrentGame()
: base(NetPacket.NetTypeLeaveCurrentGame)
{
}
public override void Accept(INetPacketVisitor visitor)
{
visitor.VisitLeaveCurrentGame(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();
}
}
}
+21 -2
View File
@@ -122,6 +122,11 @@ namespace pokerth_lib
m_data.JoinedGame = true;
}
public void VisitLeaveCurrentGame(NetPacket p)
{
throw new NotImplementedException();
}
public void VisitStartEvent(NetPacket p)
{
// Request player names for player ids.
@@ -315,6 +320,7 @@ namespace pokerth_lib
m_callback.EndOfHandShowCards(name, tmpCards, curPlayer.CardsValue, false);
}
m_callback.HandResult();
foreach (Dictionary<NetPacket.PropType, string> i in tmpList)
{
uint moneyWon = Convert.ToUInt32(i[NetPacket.PropType.MoneyWon]);
@@ -322,7 +328,7 @@ namespace pokerth_lib
{
uint playerId = Convert.ToUInt32(i[NetPacket.PropType.PlayerId]);
string name = m_data.PlayerList.GetPlayerInfo(playerId).Name;
m_callback.PlayerWins(name, moneyWon);
m_callback.PlayerWinsHand(name, moneyWon);
}
}
}
@@ -334,11 +340,24 @@ namespace pokerth_lib
Player curPlayer = m_data.CurHand.Players[playerId];
curPlayer.Money = Convert.ToUInt32(p.Properties[NetPacket.PropType.PlayerMoney]);
m_callback.PlayerWins(
m_callback.HandResult();
m_callback.PlayerWinsHand(
name,
Convert.ToUInt32(p.Properties[NetPacket.PropType.MoneyWon]));
}
public void VisitEndOfGame(NetPacket p)
{
uint playerId = Convert.ToUInt32(p.Properties[NetPacket.PropType.PlayerId]);
string name = m_data.PlayerList.GetPlayerInfo(playerId).Name;
m_callback.PlayerWinsGame(name);
NetPacket leave = new NetPacketLeaveCurrentGame();
m_sender.Send(leave);
m_data.JoinedGame = false;
}
public void VisitError(NetPacket p)
{
m_callback.Error(p.Properties[NetPacket.PropType.ErrorReason]);