Console client: Several fixes, added handling of removed from game event.

This commit is contained in:
lotodore
2008-12-26 23:05:45 +00:00
parent 52fc37a8b7
commit 26391b57d1
10 changed files with 87 additions and 6 deletions
+6
View File
@@ -150,6 +150,12 @@ namespace pokerth_console
Console.WriteLine("\n{0} wins the game.", name); Console.WriteLine("\n{0} wins the game.", name);
} }
public void RemovedFromGame()
{
Console.WriteLine("You have left the game.");
System.Environment.Exit(1);
}
public void ChatText(string name, string message) public void ChatText(string name, string message)
{ {
Console.WriteLine("{0}: {1}", Console.WriteLine("{0}: {1}",
+1 -1
View File
@@ -111,7 +111,7 @@ namespace pokerth_console
static int Main(string[] args) static int Main(string[] args)
{ {
Console.WriteLine("pokerth_console V0.1 - Copyright (C) 2008 by Lothar May"); Console.WriteLine("pokerth_console V0.1 - Copyright (C) 2008 by Lothar May");
Console.WriteLine("See license.txt for license terms."); Console.WriteLine("See COPYING.txt for license terms.");
Console.WriteLine(); Console.WriteLine();
Console.WriteLine("Enter your nickname:"); Console.WriteLine("Enter your nickname:");
string name = Console.ReadLine(); string name = Console.ReadLine();
+6
View File
@@ -67,8 +67,14 @@ namespace pokerth_lib
set set
{ {
lock (m_mutex) lock (m_mutex)
{
if (m_state != value)
{ {
m_state = value; m_state = value;
// Reset bets.
foreach (KeyValuePair<uint, Player> player in m_players)
player.Value.TotalBet = 0;
}
} }
} }
} }
+1
View File
@@ -43,6 +43,7 @@ namespace pokerth_lib
void HandResult(); void HandResult();
void PlayerWinsHand(string name, uint moneyWon); void PlayerWinsHand(string name, uint moneyWon);
void PlayerWinsGame(string name); void PlayerWinsGame(string name);
void RemovedFromGame();
void ChatText(string name, string message); void ChatText(string name, string message);
void Error(string message); void Error(string message);
} }
+1
View File
@@ -52,6 +52,7 @@ namespace pokerth_lib
void VisitEndOfHandShowCards(NetPacket p); void VisitEndOfHandShowCards(NetPacket p);
void VisitEndOfHandHideCards(NetPacket p); void VisitEndOfHandHideCards(NetPacket p);
void VisitEndOfGame(NetPacket p); void VisitEndOfGame(NetPacket p);
void VisitRemovedFromGame(NetPacket p);
void VisitChatText(NetPacket p); void VisitChatText(NetPacket p);
void VisitError(NetPacket p); void VisitError(NetPacket p);
} }
+5 -1
View File
@@ -91,7 +91,6 @@ namespace pokerth_lib
public enum PropType public enum PropType
{ {
ErrorReason,
RequestedVersionMajor, RequestedVersionMajor,
RequestedVersionMinor, RequestedVersionMinor,
PlayerId, PlayerId,
@@ -145,6 +144,8 @@ namespace pokerth_lib
BestHandPos5, BestHandPos5,
CardsValue, CardsValue,
ChatText, ChatText,
ErrorReason,
RemoveReason,
} }
public enum ListPropType public enum ListPropType
@@ -222,6 +223,9 @@ namespace pokerth_lib
case NetTypeEndOfGame : case NetTypeEndOfGame :
tmpPacket = new NetPacketEndOfGame(size, reader); tmpPacket = new NetPacketEndOfGame(size, reader);
break; break;
case NetTypeRemovedFromGame :
tmpPacket = new NetPacketRemovedFromGame(size, reader);
break;
case NetTypeChatText : case NetTypeChatText :
tmpPacket = new NetPacketChatText(size, reader); tmpPacket = new NetPacketChatText(size, reader);
break; break;
@@ -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 NetPacketRemovedFromGame : NetPacket
{
public NetPacketRemovedFromGame()
: base(NetPacket.NetTypeRemovedFromGame)
{
}
public NetPacketRemovedFromGame(int size, BinaryReader r)
: base(NetPacket.NetTypeRemovedFromGame)
{
if (size != 8)
throw new NetPacketException("NetPacketRemovedFromGame invalid size.");
Properties.Add(PropType.RemoveReason,
Convert.ToString(IPAddress.NetworkToHostOrder((short)r.ReadUInt16())));
}
public override void Accept(INetPacketVisitor visitor)
{
visitor.VisitRemovedFromGame(this);
}
public override byte[] ToByteArray()
{
throw new NotImplementedException();
}
}
}
+8 -1
View File
@@ -199,7 +199,6 @@ namespace pokerth_lib
{ {
uint curPlayer = Convert.ToUInt32(p.Properties[NetPacket.PropType.PlayerId]); uint curPlayer = Convert.ToUInt32(p.Properties[NetPacket.PropType.PlayerId]);
Hand.State state = (Hand.State)Convert.ToUInt16(p.Properties[NetPacket.PropType.GameState]); Hand.State state = (Hand.State)Convert.ToUInt16(p.Properties[NetPacket.PropType.GameState]);
m_data.CurHand.CurState = state;
if (curPlayer == m_data.MyPlayerId) if (curPlayer == m_data.MyPlayerId)
m_callback.MyTurn(state, m_data.CurHand.HighestSet, m_callback.MyTurn(state, m_data.CurHand.HighestSet,
m_data.CurHand.MinimumRaise, m_players[curPlayer].Money); m_data.CurHand.MinimumRaise, m_players[curPlayer].Money);
@@ -251,6 +250,7 @@ namespace pokerth_lib
public void VisitDealFlopCards(NetPacket p) public void VisitDealFlopCards(NetPacket p)
{ {
m_data.CurHand.CurState = Hand.State.Flop;
int[] tmpCards = new int[3]; int[] tmpCards = new int[3];
tmpCards[0] = Convert.ToInt32(p.Properties[NetPacket.PropType.FlopFirstCard]); tmpCards[0] = Convert.ToInt32(p.Properties[NetPacket.PropType.FlopFirstCard]);
tmpCards[1] = Convert.ToInt32(p.Properties[NetPacket.PropType.FlopSecondCard]); tmpCards[1] = Convert.ToInt32(p.Properties[NetPacket.PropType.FlopSecondCard]);
@@ -261,6 +261,7 @@ namespace pokerth_lib
public void VisitDealTurnCard(NetPacket p) public void VisitDealTurnCard(NetPacket p)
{ {
m_data.CurHand.CurState = Hand.State.Turn;
int[] tmpCards = new int[4]; int[] tmpCards = new int[4];
m_data.CurHand.TableCards.CopyTo(tmpCards, 0); m_data.CurHand.TableCards.CopyTo(tmpCards, 0);
tmpCards[3] = Convert.ToInt32(p.Properties[NetPacket.PropType.TurnCard]); tmpCards[3] = Convert.ToInt32(p.Properties[NetPacket.PropType.TurnCard]);
@@ -270,6 +271,7 @@ namespace pokerth_lib
public void VisitDealRiverCard(NetPacket p) public void VisitDealRiverCard(NetPacket p)
{ {
m_data.CurHand.CurState = Hand.State.River;
int[] tmpCards = new int[5]; int[] tmpCards = new int[5];
m_data.CurHand.TableCards.CopyTo(tmpCards, 0); m_data.CurHand.TableCards.CopyTo(tmpCards, 0);
tmpCards[4] = Convert.ToInt32(p.Properties[NetPacket.PropType.RiverCard]); tmpCards[4] = Convert.ToInt32(p.Properties[NetPacket.PropType.RiverCard]);
@@ -358,6 +360,11 @@ namespace pokerth_lib
m_data.JoinedGame = false; m_data.JoinedGame = false;
} }
public void VisitRemovedFromGame(NetPacket p)
{
m_callback.RemovedFromGame();
}
public void VisitChatText(NetPacket p) public void VisitChatText(NetPacket p)
{ {
uint playerId = Convert.ToUInt32(p.Properties[NetPacket.PropType.PlayerId]); uint playerId = Convert.ToUInt32(p.Properties[NetPacket.PropType.PlayerId]);
+2 -2
View File
@@ -636,8 +636,8 @@ Player Action:
0x05 - Raise 0x05 - Raise
0x06 - All in 0x06 - All in
Player Bet: Player Bet:
0 (ignored) - actions fold, check, all in (optionally call) 0 (ignored) - actions fold, check (optionally call, all in)
> 0 - actions call, bet, raise > 0 - actions call, bet, raise, all in
Server Notification: Player's Action Done Server Notification: Player's Action Done