Console client: Several fixes (mainly mono specific).
This commit is contained in:
+17
-2
@@ -57,22 +57,33 @@ namespace pokerth_console
|
|||||||
Console.WriteLine("Joining game...");
|
Console.WriteLine("Joining game...");
|
||||||
uint gameId = Convert.ToUInt32(input);
|
uint gameId = Convert.ToUInt32(input);
|
||||||
client.JoinGame(gameId);
|
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;
|
joined = true;
|
||||||
else
|
else
|
||||||
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...");
|
||||||
client.WaitStartGame();
|
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
while (Console.KeyAvailable)
|
||||||
|
Console.ReadKey();
|
||||||
input = Console.ReadLine();
|
input = Console.ReadLine();
|
||||||
} while (input == "");
|
} while (input == "");
|
||||||
Hand.Action action = Hand.Action.None;
|
Hand.Action action = Hand.Action.None;
|
||||||
uint bet = 0;
|
uint bet = 0;
|
||||||
|
try
|
||||||
|
{
|
||||||
switch (input[0])
|
switch (input[0])
|
||||||
{
|
{
|
||||||
case 'f':
|
case 'f':
|
||||||
@@ -98,6 +109,10 @@ namespace pokerth_console
|
|||||||
}
|
}
|
||||||
if (action != Hand.Action.None)
|
if (action != Hand.Action.None)
|
||||||
client.MyAction(action, bet);
|
client.MyAction(action, bet);
|
||||||
|
}
|
||||||
|
catch (FormatException)
|
||||||
|
{
|
||||||
|
}
|
||||||
} while (true);
|
} while (true);
|
||||||
client.SetTerminateFlag();
|
client.SetTerminateFlag();
|
||||||
client.WaitTermination();
|
client.WaitTermination();
|
||||||
|
|||||||
@@ -35,8 +35,7 @@ namespace pokerth_lib
|
|||||||
m_myPlayerId = 0;
|
m_myPlayerId = 0;
|
||||||
m_myGameId = 0;
|
m_myGameId = 0;
|
||||||
m_myName = name;
|
m_myName = name;
|
||||||
m_joinGameEvent = new AutoResetEvent(false);
|
m_joinedGame = false;
|
||||||
m_startGameEvent = new AutoResetEvent(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public GameInfoList GameList
|
public GameInfoList GameList
|
||||||
@@ -117,19 +116,21 @@ namespace pokerth_lib
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public EventWaitHandle JoinGameEvent
|
public bool JoinedGame
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return m_joinGameEvent;
|
lock (m_mutex)
|
||||||
|
{
|
||||||
|
return m_joinedGame;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
set
|
||||||
public EventWaitHandle StartGameEvent
|
|
||||||
{
|
{
|
||||||
get
|
lock (m_mutex)
|
||||||
{
|
{
|
||||||
return m_startGameEvent;
|
m_joinedGame = value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,7 +141,6 @@ namespace pokerth_lib
|
|||||||
private uint m_myPlayerId;
|
private uint m_myPlayerId;
|
||||||
private uint m_myGameId;
|
private uint m_myGameId;
|
||||||
private string m_myName;
|
private string m_myName;
|
||||||
private EventWaitHandle m_joinGameEvent;
|
private bool m_joinedGame;
|
||||||
private EventWaitHandle m_startGameEvent;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,11 +39,11 @@ namespace pokerth_lib
|
|||||||
{
|
{
|
||||||
// Connect to the server.
|
// Connect to the server.
|
||||||
// Try IPv6 first.
|
// Try IPv6 first.
|
||||||
IPAddress[] addresses = new IPAddress[2];
|
/*IPAddress[] addresses = new IPAddress[2];
|
||||||
addresses[0] = IPAddress.Parse(m_settings.ServerSettings.IPv6Address);
|
addresses[0] = IPAddress.Parse(m_settings.ServerSettings.IPv6Address);
|
||||||
addresses[1] = IPAddress.Parse(m_settings.ServerSettings.IPv4Address);
|
addresses[1] = IPAddress.Parse(m_settings.ServerSettings.IPv4Address);
|
||||||
m_tcpClient.Connect(addresses, m_settings.ServerSettings.Port);
|
m_tcpClient.Connect(addresses, m_settings.ServerSettings.Port);*/
|
||||||
//m_tcpClient.Connect("localhost", 7234);
|
m_tcpClient.Connect("localhost", 7234);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Start()
|
public void Start()
|
||||||
@@ -58,14 +58,9 @@ namespace pokerth_lib
|
|||||||
SendJoinGame(gameId);
|
SendJoinGame(gameId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool WaitJoinGame(int timeout)
|
public bool HasJoinedGame()
|
||||||
{
|
{
|
||||||
return m_data.JoinGameEvent.WaitOne(timeout);
|
return m_data.JoinedGame;
|
||||||
}
|
|
||||||
|
|
||||||
public bool WaitStartGame()
|
|
||||||
{
|
|
||||||
return m_data.StartGameEvent.WaitOne();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void MyAction(Hand.Action action, uint bet)
|
public void MyAction(Hand.Action action, uint bet)
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ namespace pokerth_lib
|
|||||||
m_data.MyGameId =
|
m_data.MyGameId =
|
||||||
Convert.ToUInt32(p.Properties[NetPacket.PropType.GameId]);
|
Convert.ToUInt32(p.Properties[NetPacket.PropType.GameId]);
|
||||||
m_callback.JoinedGame(m_data.GameList.GetGameInfo(m_data.MyGameId).Name);
|
m_callback.JoinedGame(m_data.GameList.GetGameInfo(m_data.MyGameId).Name);
|
||||||
m_data.JoinGameEvent.Set();
|
m_data.JoinedGame = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void VisitStartEvent(NetPacket p)
|
public void VisitStartEvent(NetPacket p)
|
||||||
@@ -167,7 +167,6 @@ namespace pokerth_lib
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_callback.GameStarted(strPlayers);
|
m_callback.GameStarted(strPlayers);
|
||||||
m_data.StartGameEvent.Set();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void VisitHandStart(NetPacket p)
|
public void VisitHandStart(NetPacket p)
|
||||||
@@ -195,6 +194,7 @@ 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);
|
||||||
|
|||||||
Reference in New Issue
Block a user