Commit 254e8562 authored by Jonathan Michalon's avatar Jonathan Michalon

Fix deadlock when client tries to join a table and it fails

parent 04cdeb3b
......@@ -145,7 +145,7 @@ namespace OVCCClient
/**
* Joins a table asynchronously
*
* @param index The index of the table to join
* @param index The index of the table to join, -1 means any open table
* @param cancellable a Cancellable object or null
* @return The game corresponding to that table
*/
......
......@@ -475,6 +475,17 @@ namespace OVCCClient
/* call the server */
yield send_message (new JoinMessage (index), cancellable);
/* wait for answer */
Message msg = yield receive_type (MessageType.JOIN, cancellable);
JoinMessage join = msg as JoinMessage;
if (join.status != JoinMessage.State.OK) {
if (index == -1) {
throw new ServerError.NO_OPEN_TABLE ("Server said that no open table is available");
} else {
throw new ServerError.NO_OPEN_TABLE ("Server said that the table is not open");
}
}
/* wait for data */
Message msg2 = yield receive_type (MessageType.GAMEDATA, cancellable);
GamedataMessage data = msg2 as GamedataMessage;
......
......@@ -137,16 +137,23 @@ public class Server: ThreadedSocketService
private bool handle_join (JoinMessage msg, Client client)
throws Error
{
/* FIXME handle precise table joins (not only -1/any) */
Game? table = pick_open_table ();
if (table == null) {
warning ("A player tried to join, but there is no open table. " +
"We should tell her, but we just do nothing yet. " +
"She's pretty much fucked.");
var join = new JoinMessage (msg.table_index);
join.status = JoinMessage.State.FAILED;
client.send (join);
return false;
}
debug ("Accepting table join");
var join = new JoinMessage (msg.table_index);
join.status = JoinMessage.State.OK;
client.send (join);
client.join (table);
debug ("Sending game data");
var data = new GamedataMessage (client.game.get_stack_ids(),
client.game.get_player_nicks(),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment