/[maitretarot]/game_server/src/callbacks.c
ViewVC logotype

Diff of /game_server/src/callbacks.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.10 by ymettier, Sun Apr 27 19:22:36 2003 UTC revision 1.11 by ymettier, Mon Apr 28 00:25:56 2003 UTC
# Line 160  protocol_say_game_cb (int sock_id, GStri Line 160  protocol_say_game_cb (int sock_id, GStri
160                          }                          }
161                        else                        else
162                          {                          {
163                                  protocol_send(sock_id,PROTOCOL_INFO,check->str);                            protocol_send (sock_id, PROTOCOL_INFO, check->str);
164                            g_string_free (check, TRUE);                            g_string_free (check, TRUE);
165                          }                          }
166                      }                      }
# Line 226  protocol_say_game_cb (int sock_id, GStri Line 226  protocol_say_game_cb (int sock_id, GStri
226      }      }
227  }  }
228    
229    int
230    player_get_position (player_t * player)
231    {
232      game_t *g;
233      int i;
234      player_t *p;
235      g = player->game;
236      for (i = 0;
237           (p =
238            g_tree_lookup (config->sock_id,
239                           GINT_TO_POINTER (g_array_index (g->players, int, i))));
240           i++)
241        {
242          if (player == p)
243            break;
244        }
245      return (p ? i : -1);
246    }
247    
248    void
249    protocol_say_bid_cb (int sock_id, GString * line, char **aline,
250                         const char *help_string)
251    {
252      game_t *g;
253      int pos;
254      player_t *p = g_tree_lookup (config->sock_id, GINT_TO_POINTER (sock_id));
255      if (!p)
256        {
257          printf ("Bug\n");
258          exit (EXIT_FAILURE);
259        }
260      g = p->game;
261      pos = player_get_position (p);
262      g_assert (pos >= 0);
263      g->rules->bids[pos] = LIBMT_BID_UNDEF;
264      if (aline[1])
265        {
266          switch (aline[1][0])
267            {
268            case '-':
269              g->rules->bids[pos] = LIBMT_BID_PASSE;
270              break;
271            case 'P':
272              g->rules->bids[pos] = LIBMT_BID_PRISE;
273              break;
274            case 'G':
275              g->rules->bids[pos] = LIBMT_BID_GARDE;
276              break;
277            case 'S':
278              g->rules->bids[pos] = LIBMT_BID_SANS;
279              break;
280            case 'C':
281              g->rules->bids[pos] = LIBMT_BID_CONTRE;
282              break;
283            default:
284              g->rules->bids[pos] = LIBMT_BID_UNDEF;
285            }
286        }
287      if (g->rules->bids[pos] != LIBMT_BID_UNDEF)
288        {
289          if (g->rules->bid == LIBMT_BID_UNDEF)
290            {
291              g->rules->bid = g->rules->bids[pos];
292              p->state = PLAYER_STATE_WAIT_FOR_PLAYERS;
293              p->state_change_date = 0;
294            }
295          else
296            {
297              if (LIBMT_BID_CMP (g->rules->bids[pos], g->rules->bid) > 0)
298                {
299                  g->rules->bid = g->rules->bids[pos];
300                  p->state = PLAYER_STATE_WAIT_FOR_PLAYERS;
301                  p->state_change_date = 0;
302                }
303              else if (!LIBMT_BID_CMP (g->rules->bids[pos], LIBMT_BID_PASSE))
304                {
305                  p->state = PLAYER_STATE_WAIT_FOR_PLAYERS;
306                  p->state_change_date = 0;
307                }
308              else
309                {
310                  protocol_send (sock_id, PROTOCOL_INFO,
311                                 "Bid should be higher or PASSE");
312                  p->state_change_date = 0;
313                }
314            }
315        }
316      if (p->state == PLAYER_STATE_WAIT_FOR_PLAYERS)
317        {
318          int i;
319          for (i = 0; i < g->nb_players_max; i++)
320            {
321              int s1 = g_array_index (g->players, int, i);
322              player_t *p1 = g_tree_lookup (config->sock_id,
323                                            GINT_TO_POINTER (s1));
324              if (p1 != p)
325                send_ask_bids (s1, p1, 1);
326    
327            }
328        }
329    }
330    
331    
332  void  void
333  protocol_foreach_say_help_cb (gpointer a, gpointer b, gpointer c)  protocol_foreach_say_help_cb (gpointer a, gpointer b, gpointer c)
# Line 233  protocol_foreach_say_help_cb (gpointer a Line 335  protocol_foreach_say_help_cb (gpointer a
335    callback_info_t *ci = (callback_info_t *) b;    callback_info_t *ci = (callback_info_t *) b;
336    int sock_id = GPOINTER_TO_INT (c);    int sock_id = GPOINTER_TO_INT (c);
337    
338    protocol_send(sock_id,PROTOCOL_INFO,ci->syntax);    protocol_send (sock_id, PROTOCOL_INFO, ci->syntax);
339  }  }
340    
341  void  void
# Line 277  protocol_foreach_docbook_doc_output_cb ( Line 379  protocol_foreach_docbook_doc_output_cb (
379            "                <entry>%s</entry>\n"            "                <entry>%s</entry>\n"
380            "                <entry>%s</entry>\n"            "                <entry>%s</entry>\n"
381            "                <entry>%s</entry>\n"            "                <entry>%s</entry>\n"
382            "              </row>\n", (char *) a, str,syntax, help);            "              </row>\n", (char *) a, str, syntax, help);
383    g_free (syntax);    g_free (syntax);
384    g_free (help);    g_free (help);
385  }  }
# Line 285  protocol_foreach_docbook_doc_output_cb ( Line 387  protocol_foreach_docbook_doc_output_cb (
387  callback_info_t *  callback_info_t *
388  callback_info_new (void (*cb)  callback_info_new (void (*cb)
389                     (int sock_id, GString * line, char **aline,                     (int sock_id, GString * line, char **aline,
390                      const char *help_string), int nb_args, char*syntax,char *help_string)                      const char *help_string), int nb_args, char *syntax,
391                       char *help_string)
392  {  {
393    callback_info_t *c;    callback_info_t *c;
394    c = g_malloc (sizeof (callback_info_t));    c = g_malloc (sizeof (callback_info_t));
# Line 302  config_protocol_callbacks_init (void) Line 405  config_protocol_callbacks_init (void)
405    
406    g_hash_table_insert (config->protocol_callbacks, "SAY_nick",    g_hash_table_insert (config->protocol_callbacks, "SAY_nick",
407                         callback_info_new (protocol_say_nick_cb, 1,                         callback_info_new (protocol_say_nick_cb, 1,
408                                            "SAY_nick <nick>","Send your nickname to the server"));                                            "SAY_nick <nick>",
409                                              "Send your nickname to the server"));
410    g_hash_table_insert (config->protocol_callbacks, "SAY_game",    g_hash_table_insert (config->protocol_callbacks, "SAY_game",
411                         callback_info_new (protocol_say_game_cb, 4,                         callback_info_new (protocol_say_game_cb, 4,
412                                            "SAY_game <CREATE|JOIN|WATCH> <game type> <nb of players> <game id>", "Create a game, or join it as a player or a watcher"));                                            "SAY_game <CREATE|JOIN|WATCH> <game type> <nb of players> <game id>",
413                                              "Create a game, or join it as a player or a watcher"));
414    g_hash_table_insert (config->protocol_callbacks, "ASK_nick_list",    g_hash_table_insert (config->protocol_callbacks, "ASK_nick_list",
415                         callback_info_new (protocol_ask_nick_list_cb, 0,                         callback_info_new (protocol_ask_nick_list_cb, 0,
416                                            "ASK_nick_list", "Ask the list of nicknames"));                                            "ASK_nick_list",
417                                              "Ask the list of nicknames"));
418    g_hash_table_insert (config->protocol_callbacks, "ASK_game_list",    g_hash_table_insert (config->protocol_callbacks, "ASK_game_list",
419                         callback_info_new (protocol_ask_game_list_cb, 0,                         callback_info_new (protocol_ask_game_list_cb, 0,
420                                            "ASK_game_list","Ask the list of created games"));                                            "ASK_game_list",
421                                              "Ask the list of created games"));
422      g_hash_table_insert (config->protocol_callbacks, "SAY_bid",
423                           callback_info_new (protocol_say_bid_cb, 0, "SAY_bid",
424                                              "Say the bid"));
425    g_hash_table_insert (config->protocol_callbacks, "help",    g_hash_table_insert (config->protocol_callbacks, "help",
426                         callback_info_new (protocol_say_help_cb, -1,                         callback_info_new (protocol_say_help_cb, -1,
427                                            "HELP or HELP <order>","Ask some help on an order, or the list of orders"));                                            "HELP or HELP <order>",
428                                              "Ask some help on an order, or the list of orders"));
429    g_hash_table_insert (config->protocol_callbacks, "HELP",    g_hash_table_insert (config->protocol_callbacks, "HELP",
430                         callback_info_new (protocol_say_help_cb, -1,                         callback_info_new (protocol_say_help_cb, -1,
431                                            "HELP or HELP <order>","Ask some help on an order, or the list of orders"));                                            "HELP or HELP <order>",
432                                              "Ask some help on an order, or the list of orders"));
433  }  }

Legend:
Removed from v.1.10  
changed lines
  Added in v.1.11

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26