1 /* cmd_neonfun_4wins.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"
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 if((game->player[0]->user->flags & USERFLAG_ISAUTHED) && (game->player[1]->user->flags & USERFLAG_ISAUTHED) && !stricmp(game->player[0]->user->auth, game->player[1]->user->auth)) {
40 fourwins_reply(game, "NF_4WINS_SELF");
41 fourwins_free_game(game);
44 fourwins_reply(game, "NF_4WINS_START", user->nick);
45 if((game->player[0]->user->flags & USERFLAG_ISAUTHED)) {
47 int win_count = ((tmp = getSetting(game->player[0]->user, chan, "4wins_games")) ? atoi(tmp) : 0);
48 int total_win_count = ((tmp = getSetting(game->player[0]->user, NULL, "4wins_games")) ? atoi(tmp) : 0);
52 sprintf(buf, "%d", win_count);
53 setSetting(game->player[0]->user, chan, "4wins_games", buf);
54 sprintf(buf, "%d", total_win_count);
55 setSetting(game->player[0]->user, NULL, "4wins_games", buf);
57 if((game->player[1]->user->flags & USERFLAG_ISAUTHED)) {
59 int win_count = ((tmp = getSetting(game->player[1]->user, chan, "4wins_games")) ? atoi(tmp) : 0);
60 int total_win_count = ((tmp = getSetting(game->player[1]->user, NULL, "4wins_games")) ? atoi(tmp) : 0);
64 sprintf(buf, "%d", win_count);
65 setSetting(game->player[1]->user, chan, "4wins_games", buf);
66 sprintf(buf, "%d", total_win_count);
67 setSetting(game->player[1]->user, NULL, "4wins_games", buf);
69 fourwins_show_matrix(game);
70 fourwins_reply(game, "NF_4WINS_USER_HURRY_UP", game->player[game->active_player]->user->nick);
71 game->timer = timeq_add(120, module_id, fourwins_timeout, game);
74 reply(textclient, user, "NF_4WINS_ENTER_OPPONENT");
77 struct UserNode *opp_user = getUserByNick(argv[0]);
79 reply(textclient, user, "NS_USER_UNKNOWN", argv[0]);
82 if(opp_user == user) {
83 reply(textclient, user, "NF_4WINS_SELF");
86 struct ChanUser *opponent = getChanUser(opp_user, chan);
88 reply(textclient, user, "NF_4WINS_OPPONENT_NOT_IN_CHAN", opp_user->nick);
91 game = calloc(1,sizeof(*game));
92 game->player[0] = chanuser;
93 game->player[1] = opponent;
94 game->textbot = textclient;
95 game->state = FOURWINS_STATE_WAITING;
96 game->timer = timeq_add(120, module_id, fourwins_timeout, game);
97 game->next = fourwins_active_games;
98 fourwins_active_games = game;
99 reply(textclient, user, "NF_4WINS_REQUESTED", opp_user->nick);
100 reply(textclient, opp_user, "NF_4WINS_REQUEST", user->nick);