Console client: Several fixes (mainly mono specific).
This commit is contained in:
+40
-25
@@ -57,47 +57,62 @@ namespace pokerth_console
|
||||
Console.WriteLine("Joining game...");
|
||||
uint gameId = Convert.ToUInt32(input);
|
||||
client.JoinGame(gameId);
|
||||
if (client.WaitJoinGame(5000))
|
||||
// Hack this, because Mono does not support WaitOne(...).
|
||||
DateTime cur = DateTime.Now;
|
||||
while (!client.HasJoinedGame())
|
||||
{
|
||||
Thread.Sleep(15);
|
||||
if (DateTime.Now.Subtract(cur).Seconds > 5)
|
||||
break;
|
||||
}
|
||||
if (client.HasJoinedGame())
|
||||
joined = true;
|
||||
else
|
||||
Console.WriteLine("Could not join game.");
|
||||
} while (!joined);
|
||||
Console.WriteLine("Waiting for admin to start the game...");
|
||||
client.WaitStartGame();
|
||||
|
||||
do
|
||||
{
|
||||
do
|
||||
{
|
||||
while (Console.KeyAvailable)
|
||||
Console.ReadKey();
|
||||
input = Console.ReadLine();
|
||||
} while (input == "");
|
||||
Hand.Action action = Hand.Action.None;
|
||||
uint bet = 0;
|
||||
switch (input[0])
|
||||
try
|
||||
{
|
||||
switch (input[0])
|
||||
{
|
||||
case 'f':
|
||||
action = Hand.Action.Fold;
|
||||
break;
|
||||
case 'c':
|
||||
action = Hand.Action.Check;
|
||||
break;
|
||||
case 'l':
|
||||
action = Hand.Action.Call;
|
||||
break;
|
||||
case 'b':
|
||||
action = Hand.Action.Bet;
|
||||
bet = Convert.ToUInt32(input.Substring(1));
|
||||
break;
|
||||
case 'r':
|
||||
action = Hand.Action.Raise;
|
||||
bet = Convert.ToUInt32(input.Substring(1));
|
||||
break;
|
||||
case 'a':
|
||||
action = Hand.Action.AllIn;
|
||||
break;
|
||||
}
|
||||
if (action != Hand.Action.None)
|
||||
client.MyAction(action, bet);
|
||||
}
|
||||
catch (FormatException)
|
||||
{
|
||||
case 'f':
|
||||
action = Hand.Action.Fold;
|
||||
break;
|
||||
case 'c':
|
||||
action = Hand.Action.Check;
|
||||
break;
|
||||
case 'l':
|
||||
action = Hand.Action.Call;
|
||||
break;
|
||||
case 'b':
|
||||
action = Hand.Action.Bet;
|
||||
bet = Convert.ToUInt32(input.Substring(1));
|
||||
break;
|
||||
case 'r':
|
||||
action = Hand.Action.Raise;
|
||||
bet = Convert.ToUInt32(input.Substring(1));
|
||||
break;
|
||||
case 'a':
|
||||
action = Hand.Action.AllIn;
|
||||
break;
|
||||
}
|
||||
if (action != Hand.Action.None)
|
||||
client.MyAction(action, bet);
|
||||
} while (true);
|
||||
client.SetTerminateFlag();
|
||||
client.WaitTermination();
|
||||
|
||||
@@ -35,8 +35,7 @@ namespace pokerth_lib
|
||||
m_myPlayerId = 0;
|
||||
m_myGameId = 0;
|
||||
m_myName = name;
|
||||
m_joinGameEvent = new AutoResetEvent(false);
|
||||
m_startGameEvent = new AutoResetEvent(false);
|
||||
m_joinedGame = false;
|
||||
}
|
||||
|
||||
public GameInfoList GameList
|
||||
@@ -117,19 +116,21 @@ namespace pokerth_lib
|
||||
}
|
||||
}
|
||||
|
||||
public EventWaitHandle JoinGameEvent
|
||||
public bool JoinedGame
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_joinGameEvent;
|
||||
lock (m_mutex)
|
||||
{
|
||||
return m_joinedGame;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public EventWaitHandle StartGameEvent
|
||||
{
|
||||
get
|
||||
set
|
||||
{
|
||||
return m_startGameEvent;
|
||||
lock (m_mutex)
|
||||
{
|
||||
m_joinedGame = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,7 +141,6 @@ namespace pokerth_lib
|
||||
private uint m_myPlayerId;
|
||||
private uint m_myGameId;
|
||||
private string m_myName;
|
||||
private EventWaitHandle m_joinGameEvent;
|
||||
private EventWaitHandle m_startGameEvent;
|
||||
private bool m_joinedGame;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,11 +39,11 @@ namespace pokerth_lib
|
||||
{
|
||||
// Connect to the server.
|
||||
// Try IPv6 first.
|
||||
IPAddress[] addresses = new IPAddress[2];
|
||||
/*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);
|
||||
m_tcpClient.Connect(addresses, m_settings.ServerSettings.Port);*/
|
||||
m_tcpClient.Connect("localhost", 7234);
|
||||
}
|
||||
|
||||
public void Start()
|
||||
@@ -58,14 +58,9 @@ namespace pokerth_lib
|
||||
SendJoinGame(gameId);
|
||||
}
|
||||
|
||||
public bool WaitJoinGame(int timeout)
|
||||
public bool HasJoinedGame()
|
||||
{
|
||||
return m_data.JoinGameEvent.WaitOne(timeout);
|
||||
}
|
||||
|
||||
public bool WaitStartGame()
|
||||
{
|
||||
return m_data.StartGameEvent.WaitOne();
|
||||
return m_data.JoinedGame;
|
||||
}
|
||||
|
||||
public void MyAction(Hand.Action action, uint bet)
|
||||
|
||||
@@ -119,7 +119,7 @@ namespace pokerth_lib
|
||||
m_data.MyGameId =
|
||||
Convert.ToUInt32(p.Properties[NetPacket.PropType.GameId]);
|
||||
m_callback.JoinedGame(m_data.GameList.GetGameInfo(m_data.MyGameId).Name);
|
||||
m_data.JoinGameEvent.Set();
|
||||
m_data.JoinedGame = true;
|
||||
}
|
||||
|
||||
public void VisitStartEvent(NetPacket p)
|
||||
@@ -167,7 +167,6 @@ namespace pokerth_lib
|
||||
}
|
||||
|
||||
m_callback.GameStarted(strPlayers);
|
||||
m_data.StartGameEvent.Set();
|
||||
}
|
||||
|
||||
public void VisitHandStart(NetPacket p)
|
||||
@@ -195,6 +194,7 @@ namespace pokerth_lib
|
||||
{
|
||||
uint curPlayer = Convert.ToUInt32(p.Properties[NetPacket.PropType.PlayerId]);
|
||||
Hand.State state = (Hand.State)Convert.ToUInt16(p.Properties[NetPacket.PropType.GameState]);
|
||||
m_data.CurHand.CurState = state;
|
||||
if (curPlayer == m_data.MyPlayerId)
|
||||
m_callback.MyTurn(state, m_data.CurHand.HighestSet,
|
||||
m_data.CurHand.MinimumRaise, m_players[curPlayer].Money);
|
||||
|
||||
Reference in New Issue
Block a user