1 /* cmd_neonfun_blackjack.c - NeonServ v5.6
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"
19 #include "game_blackjack.h"
21 CMD_BIND(neonfun_cmd_blackjack) {
22 struct ChanUser *chanuser = getChanUser(user, chan);
25 for(game = bj_active_games; game; game = game->next) {
26 if(chan == game->channel)
30 //check if player has already joined
31 struct bj_player *player, *last_player = NULL;
32 for(player = game->player; player; player = player->next) {
33 if(player->chanuser == chanuser) {
34 reply(textclient, user, "NF_BJ_ALREADY_JOINED");
39 if(!last_player) return; //error (game without players?)
40 player = malloc(sizeof(*player));
41 player->chanuser = chanuser;
44 player->prev = last_player;
46 last_player->next = player;
48 bj_reply(game, user, "NF_BJ_USER_JOINED", user->nick);
50 game = malloc(sizeof(*game));
52 game->textbot = textclient;
53 game->state = BJ_STATE_WAITING;
55 struct bj_player *player = malloc(sizeof(*player));
56 player->chanuser = chanuser;
61 game->player = player;
62 game->active_player = NULL;
64 game->timer = timeq_add(30, module_id, bj_game_wait_timeout, game);
65 game->next = bj_active_games;
66 bj_active_games = game;
67 bj_reply(game, user, "NF_BJ_CREATED", user->nick);