Console client: Adding proper termination after the game. Adding missing source files.
This commit is contained in:
@@ -140,11 +140,16 @@ namespace pokerth_console
|
|||||||
Console.WriteLine();
|
Console.WriteLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void PlayerWins(string name, uint moneyWon)
|
public void PlayerWinsHand(string name, uint moneyWon)
|
||||||
{
|
{
|
||||||
Console.WriteLine("{0} wins ${1}.", name, moneyWon);
|
Console.WriteLine("{0} wins ${1}.", name, moneyWon);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void PlayerWinsGame(string name)
|
||||||
|
{
|
||||||
|
Console.WriteLine("\n{0} wins the game.", name);
|
||||||
|
}
|
||||||
|
|
||||||
public void Error(string message)
|
public void Error(string message)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Error: " + message);
|
Console.WriteLine("Error: " + message);
|
||||||
|
|||||||
+36
-17
@@ -21,27 +21,15 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
using System.Net.Sockets;
|
||||||
using pokerth_lib;
|
using pokerth_lib;
|
||||||
|
|
||||||
namespace pokerth_console
|
namespace pokerth_console
|
||||||
{
|
{
|
||||||
class Program
|
class Program
|
||||||
{
|
{
|
||||||
static int Main(string[] args)
|
static void ChooseOpenGame(Client client, PokerTHData data)
|
||||||
{
|
{
|
||||||
Console.WriteLine("pokerth_console V0.1 - Copyright (C) 2008 by Lothar May");
|
|
||||||
Console.WriteLine("See license.txt for license terms.");
|
|
||||||
Console.WriteLine();
|
|
||||||
Console.WriteLine("Enter your nickname:");
|
|
||||||
string name = Console.ReadLine();
|
|
||||||
Console.WriteLine("Connecting to server...");
|
|
||||||
Settings settings = new Settings();
|
|
||||||
PokerTHData data = new PokerTHData(name);
|
|
||||||
ConsoleCallback callback = new ConsoleCallback();
|
|
||||||
Client client = new Client(settings, data, callback);
|
|
||||||
client.Connect();
|
|
||||||
client.Start();
|
|
||||||
Thread.Sleep(2000);
|
|
||||||
string input;
|
string input;
|
||||||
bool joined = false;
|
bool joined = false;
|
||||||
do
|
do
|
||||||
@@ -71,15 +59,18 @@ namespace pokerth_console
|
|||||||
Console.WriteLine("Could not join game.");
|
Console.WriteLine("Could not join game.");
|
||||||
} while (!joined);
|
} while (!joined);
|
||||||
Console.WriteLine("Waiting for admin to start the game...");
|
Console.WriteLine("Waiting for admin to start the game...");
|
||||||
|
}
|
||||||
|
|
||||||
do
|
static void GameLoop(Client client, PokerTHData data)
|
||||||
{
|
{
|
||||||
|
string input;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
while (Console.KeyAvailable)
|
while (Console.KeyAvailable)
|
||||||
Console.ReadKey();
|
Console.ReadKey();
|
||||||
input = Console.ReadLine();
|
input = Console.ReadLine();
|
||||||
} while (input == "");
|
if (input.Length > 0)
|
||||||
|
{
|
||||||
Hand.Action action = Hand.Action.None;
|
Hand.Action action = Hand.Action.None;
|
||||||
uint bet = 0;
|
uint bet = 0;
|
||||||
try
|
try
|
||||||
@@ -113,7 +104,35 @@ namespace pokerth_console
|
|||||||
catch (FormatException)
|
catch (FormatException)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
} while (true);
|
}
|
||||||
|
} while (data.JoinedGame);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int Main(string[] args)
|
||||||
|
{
|
||||||
|
Console.WriteLine("pokerth_console V0.1 - Copyright (C) 2008 by Lothar May");
|
||||||
|
Console.WriteLine("See license.txt for license terms.");
|
||||||
|
Console.WriteLine();
|
||||||
|
Console.WriteLine("Enter your nickname:");
|
||||||
|
string name = Console.ReadLine();
|
||||||
|
Console.WriteLine("Connecting to server...");
|
||||||
|
Settings settings = new Settings();
|
||||||
|
PokerTHData data = new PokerTHData(name);
|
||||||
|
ConsoleCallback callback = new ConsoleCallback();
|
||||||
|
Client client = new Client(settings, data, callback);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
client.Connect();
|
||||||
|
}
|
||||||
|
catch (SocketException)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Unable to connect to server.");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
client.Start();
|
||||||
|
Thread.Sleep(2000);
|
||||||
|
ChooseOpenGame(client, data);
|
||||||
|
GameLoop(client, data);
|
||||||
client.SetTerminateFlag();
|
client.SetTerminateFlag();
|
||||||
client.WaitTermination();
|
client.WaitTermination();
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -41,7 +41,8 @@ namespace pokerth_lib
|
|||||||
void ShowCards(string name, int[] cards);
|
void ShowCards(string name, int[] cards);
|
||||||
void EndOfHandShowCards(string name, int[] cards, int cardsValue, bool allIn);
|
void EndOfHandShowCards(string name, int[] cards, int cardsValue, bool allIn);
|
||||||
void HandResult();
|
void HandResult();
|
||||||
void PlayerWins(string name, uint moneyWon);
|
void PlayerWinsHand(string name, uint moneyWon);
|
||||||
|
void PlayerWinsGame(string name);
|
||||||
void Error(string message);
|
void Error(string message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ namespace pokerth_lib
|
|||||||
void VisitCreateGame(NetPacket p);
|
void VisitCreateGame(NetPacket p);
|
||||||
void VisitJoinGame(NetPacket p);
|
void VisitJoinGame(NetPacket p);
|
||||||
void VisitJoinGameAck(NetPacket p);
|
void VisitJoinGameAck(NetPacket p);
|
||||||
|
void VisitLeaveCurrentGame(NetPacket p);
|
||||||
void VisitStartEvent(NetPacket p);
|
void VisitStartEvent(NetPacket p);
|
||||||
void VisitStartEventAck(NetPacket p);
|
void VisitStartEventAck(NetPacket p);
|
||||||
void VisitGameStart(NetPacket p);
|
void VisitGameStart(NetPacket p);
|
||||||
@@ -50,6 +51,7 @@ namespace pokerth_lib
|
|||||||
void VisitAllInShowCards(NetPacket p);
|
void VisitAllInShowCards(NetPacket p);
|
||||||
void VisitEndOfHandShowCards(NetPacket p);
|
void VisitEndOfHandShowCards(NetPacket p);
|
||||||
void VisitEndOfHandHideCards(NetPacket p);
|
void VisitEndOfHandHideCards(NetPacket p);
|
||||||
|
void VisitEndOfGame(NetPacket p);
|
||||||
void VisitError(NetPacket p);
|
void VisitError(NetPacket p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -218,6 +218,9 @@ namespace pokerth_lib
|
|||||||
case NetTypeEndOfHandHideCards :
|
case NetTypeEndOfHandHideCards :
|
||||||
tmpPacket = new NetPacketEndOfHandHideCards(size, reader);
|
tmpPacket = new NetPacketEndOfHandHideCards(size, reader);
|
||||||
break;
|
break;
|
||||||
|
case NetTypeEndOfGame :
|
||||||
|
tmpPacket = new NetPacketEndOfGame(size, reader);
|
||||||
|
break;
|
||||||
case NetTypeError :
|
case NetTypeError :
|
||||||
tmpPacket = new NetPacketError(size, reader);
|
tmpPacket = new NetPacketError(size, reader);
|
||||||
break;
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -122,6 +122,11 @@ namespace pokerth_lib
|
|||||||
m_data.JoinedGame = true;
|
m_data.JoinedGame = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void VisitLeaveCurrentGame(NetPacket p)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
public void VisitStartEvent(NetPacket p)
|
public void VisitStartEvent(NetPacket p)
|
||||||
{
|
{
|
||||||
// Request player names for player ids.
|
// Request player names for player ids.
|
||||||
@@ -315,6 +320,7 @@ namespace pokerth_lib
|
|||||||
|
|
||||||
m_callback.EndOfHandShowCards(name, tmpCards, curPlayer.CardsValue, false);
|
m_callback.EndOfHandShowCards(name, tmpCards, curPlayer.CardsValue, false);
|
||||||
}
|
}
|
||||||
|
m_callback.HandResult();
|
||||||
foreach (Dictionary<NetPacket.PropType, string> i in tmpList)
|
foreach (Dictionary<NetPacket.PropType, string> i in tmpList)
|
||||||
{
|
{
|
||||||
uint moneyWon = Convert.ToUInt32(i[NetPacket.PropType.MoneyWon]);
|
uint moneyWon = Convert.ToUInt32(i[NetPacket.PropType.MoneyWon]);
|
||||||
@@ -322,7 +328,7 @@ namespace pokerth_lib
|
|||||||
{
|
{
|
||||||
uint playerId = Convert.ToUInt32(i[NetPacket.PropType.PlayerId]);
|
uint playerId = Convert.ToUInt32(i[NetPacket.PropType.PlayerId]);
|
||||||
string name = m_data.PlayerList.GetPlayerInfo(playerId).Name;
|
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];
|
Player curPlayer = m_data.CurHand.Players[playerId];
|
||||||
curPlayer.Money = Convert.ToUInt32(p.Properties[NetPacket.PropType.PlayerMoney]);
|
curPlayer.Money = Convert.ToUInt32(p.Properties[NetPacket.PropType.PlayerMoney]);
|
||||||
|
|
||||||
m_callback.PlayerWins(
|
m_callback.HandResult();
|
||||||
|
m_callback.PlayerWinsHand(
|
||||||
name,
|
name,
|
||||||
Convert.ToUInt32(p.Properties[NetPacket.PropType.MoneyWon]));
|
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)
|
public void VisitError(NetPacket p)
|
||||||
{
|
{
|
||||||
m_callback.Error(p.Properties[NetPacket.PropType.ErrorReason]);
|
m_callback.Error(p.Properties[NetPacket.PropType.ErrorReason]);
|
||||||
|
|||||||
Reference in New Issue
Block a user