1 /* cmd_neonfun_4wins.c - NeonServ v5.4
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_4wins.h"
21 CMD_BIND(neonfun_cmd_4wins) {
22 struct ChanUser *chanuser = getChanUser(user, chan);
24 struct fourwins_game *game;
25 for(game = fourwins_active_games; game; game = game->next) {
26 if(chanuser == game->player[0]) {
28 } else if(chanuser == game->player[1]) {
29 if(game->state == FOURWINS_STATE_WAITING)
36 timeq_del(game->timer);
38 game->state = FOURWINS_STATE_RUNNING;
39 fourwins_reply(game, "NF_4WINS_START", user->nick);
40 if((game->player[0]->user->flags & USERFLAG_ISAUTHED)) {
42 int win_count = ((tmp = getSetting(game->player[0]->user, chan, "4wins_games")) ? atoi(tmp) : 0);
43 int total_win_count = ((tmp = getSetting(game->player[0]->user, NULL, "4wins_games")) ? atoi(tmp) : 0);
47 sprintf(buf, "%d", win_count);
48 setSetting(game->player[0]->user, chan, "4wins_games", buf);
49 sprintf(buf, "%d", total_win_count);
50 setSetting(game->player[0]->user, NULL, "4wins_games", buf);
52 if((game->player[1]->user->flags & USERFLAG_ISAUTHED)) {
54 int win_count = ((tmp = getSetting(game->player[1]->user, chan, "4wins_games")) ? atoi(tmp) : 0);
55 int total_win_count = ((tmp = getSetting(game->player[1]->user, NULL, "4wins_games")) ? atoi(tmp) : 0);
59 sprintf(buf, "%d", win_count);
60 setSetting(game->player[1]->user, chan, "4wins_games", buf);
61 sprintf(buf, "%d", total_win_count);
62 setSetting(game->player[1]->user, NULL, "4wins_games", buf);
64 fourwins_show_matrix(game);
65 fourwins_reply(game, "NF_4WINS_USER_HURRY_UP", game->player[game->active_player]->user->nick);
66 game->timer = timeq_add(120, module_id, fourwins_timeout, game);
69 reply(getTextBot(), user, "NF_4WINS_ENTER_OPPONENT");
72 struct UserNode *opp_user = getUserByNick(argv[0]);
74 reply(getTextBot(), user, "NS_USER_UNKNOWN", argv[0]);
77 struct ChanUser *opponent = getChanUser(opp_user, chan);
79 reply(getTextBot(), user, "NF_4WINS_OPPONENT_NOT_IN_CHAN", opp_user->nick);
82 game = calloc(1,sizeof(*game));
83 game->player[0] = chanuser;
84 game->player[1] = opponent;
85 game->textbot = getTextBot();
86 game->state = FOURWINS_STATE_WAITING;
87 game->timer = timeq_add(120, module_id, fourwins_timeout, game);
88 game->next = fourwins_active_games;
89 fourwins_active_games = game;
90 reply(getTextBot(), user, "NF_4WINS_REQUESTED", opp_user->nick);
91 reply(getTextBot(), opp_user, "NF_4WINS_REQUEST", user->nick);