226 |
} |
} |
227 |
} |
} |
228 |
|
|
|
int |
|
|
player_get_position (player_t * player) |
|
|
{ |
|
|
game_t *g; |
|
|
int i; |
|
|
player_t *p; |
|
|
g = player->game; |
|
|
for (i = 0; |
|
|
(p = |
|
|
g_tree_lookup (config->sock_id, |
|
|
GINT_TO_POINTER (g_array_index (g->players, int, i)))); |
|
|
i++) |
|
|
{ |
|
|
if (player == p) |
|
|
break; |
|
|
} |
|
|
return (p ? i : -1); |
|
|
} |
|
|
|
|
229 |
void |
void |
230 |
protocol_say_bid_cb (int sock_id, GString * line, char **aline, |
protocol_say_bid_cb (int sock_id, GString * line, char **aline, |
231 |
const char *help_string) |
const char *help_string) |
311 |
} |
} |
312 |
} |
} |
313 |
|
|
314 |
|
void |
315 |
|
protocol_say_chien_cb (int sock_id, GString * line, char **aline, |
316 |
|
const char *help_string) |
317 |
|
{ |
318 |
|
game_t *g; |
319 |
|
int pos; |
320 |
|
int r; |
321 |
|
player_t *p = g_tree_lookup (config->sock_id, GINT_TO_POINTER (sock_id)); |
322 |
|
if (!p) |
323 |
|
{ |
324 |
|
printf ("Bug\n"); |
325 |
|
exit (EXIT_FAILURE); |
326 |
|
} |
327 |
|
g = p->game; |
328 |
|
pos = player_get_position (p); |
329 |
|
g_assert (pos >= 0); |
330 |
|
r = read_chien (aline, g); |
331 |
|
if (r == READ_CHIEN_OK) |
332 |
|
{ |
333 |
|
g->state = GAME_STATE_ASKING_CHIEN_DONE; |
334 |
|
|
335 |
|
} |
336 |
|
else if (r == READ_CHIEN_TOO_FEW_ARGUMENTS) |
337 |
|
{ |
338 |
|
gchar *msg = g_strdup_printf ("Syntax error: %s", help_string); |
339 |
|
protocol_send (sock_id, PROTOCOL_ERROR, msg); |
340 |
|
g_free (msg); |
341 |
|
} |
342 |
|
else if (r == READ_CHIEN_BAD_ARGUMENT) |
343 |
|
{ |
344 |
|
gchar *msg = g_strdup_printf ("Bad argument: %s", help_string); |
345 |
|
protocol_send (sock_id, PROTOCOL_ERROR, msg); |
346 |
|
g_free (msg); |
347 |
|
} |
348 |
|
else if (r == READ_CHIEN_WRONG_CHIEN) |
349 |
|
{ |
350 |
|
gchar *msg = g_strdup_printf ("Wrong chien"); |
351 |
|
protocol_send (sock_id, PROTOCOL_ERROR, msg); |
352 |
|
g_free (msg); |
353 |
|
send_ask_chien (sock_id, p); |
354 |
|
} |
355 |
|
} |
356 |
|
|
357 |
void |
void |
358 |
protocol_foreach_say_help_cb (gpointer a, gpointer b, gpointer c) |
protocol_foreach_say_help_cb (gpointer a, gpointer b, gpointer c) |
447 |
g_hash_table_insert (config->protocol_callbacks, "SAY_bid", |
g_hash_table_insert (config->protocol_callbacks, "SAY_bid", |
448 |
callback_info_new (protocol_say_bid_cb, 0, "SAY_bid", |
callback_info_new (protocol_say_bid_cb, 0, "SAY_bid", |
449 |
"Say the bid")); |
"Say the bid")); |
450 |
|
g_hash_table_insert (config->protocol_callbacks, "SAY_chien", |
451 |
|
callback_info_new (protocol_say_chien_cb, 0, |
452 |
|
"SAY_chien <nb of cards> <card1> .. <card n>", |
453 |
|
"Say the chien")); |
454 |
g_hash_table_insert (config->protocol_callbacks, "help", |
g_hash_table_insert (config->protocol_callbacks, "help", |
455 |
callback_info_new (protocol_say_help_cb, -1, |
callback_info_new (protocol_say_help_cb, -1, |
456 |
"HELP or HELP <order>", |
"HELP or HELP <order>", |