1 /* cmd_neonfun_uno.c - NeonServ v5.5
2 * Copyright (C) 2011-2012 Philipp Kreil (pk910)
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #include "cmd_neonfun.h"
21 CMD_BIND(neonfun_cmd_uno) {
22 struct ChanUser *chanuser = getChanUser(user, chan);
24 struct uno_game *game;
25 for(game = uno_active_games; game; game = game->next) {
26 if(chan == game->channel) {
27 if(game->state == UNO_STATE_WAITING)
30 reply(textclient, user, "NF_UNO_ALREADY_RUNNING", chan->name);
36 //check if player has already joined
37 struct uno_player *player, *last_player = NULL;
38 for(player = game->player; player; player = player->next) {
39 if(player->chanuser == chanuser) {
40 reply(textclient, user, "NF_UNO_ALREADY_JOINED");
45 if(!last_player) return; //error (game without players?)
46 player = malloc(sizeof(*player));
47 player->chanuser = chanuser;
51 player->prev = last_player;
53 last_player->next = player;
55 uno_reply(game, user, "NF_UNO_USER_JOINED", user->nick);
57 game = malloc(sizeof(*game));
59 game->textbot = textclient;
60 game->state = UNO_STATE_WAITING;
61 game->reverse_direction = 0;
62 game->take_cards_pending = 0;
64 game->top_card = NULL;
65 struct uno_player *player = malloc(sizeof(*player));
66 player->chanuser = chanuser;
71 game->player = player;
73 game->active_player = NULL;
75 game->active_player = 0;
76 game->timer = timeq_add(30, module_id, uno_game_wait_timeout, game);
77 game->next = uno_active_games;
78 uno_active_games = game;
79 uno_reply(game, user, "NF_UNO_CREATED", user->nick);