1 /* cmd_neonfun_4stone.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_4wins.h"
21 CMD_BIND(neonfun_cmd_4stone) {
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] || chanuser == game->player[1]) {
27 if(game->state == FOURWINS_STATE_WAITING)
34 //check if it's the player's turn
35 if(game->player[game->active_player] != chanuser) {
36 reply(textclient, user, "NF_4WINS_NOT_YOUR_TURN");
39 int x = atoi(argv[0])-1;
40 if(x < 0 || x >= FOURWINS_MATRIX_WIDTH) {
41 reply(textclient, user, "NF_4WINS_INVALID_COLUMN");
44 int y = fourwins_next_free_y(game, x);
46 reply(textclient, user, "NF_4WINS_COLUMN_FULL");
49 timeq_del(game->timer);
51 game->matrix[x][y].field = game->active_player+1;
52 fourwins_show_matrix(game);
53 if(fourwins_check_win(game, x, y)) {
54 fourwins_reply(game, "NF_4WINS_USER_WON", game->player[game->active_player]->user->nick);
55 if((game->player[game->active_player]->user->flags & USERFLAG_ISAUTHED)) {
57 int win_count = ((tmp = getSetting(game->player[game->active_player]->user, chan, "4wins_win")) ? atoi(tmp) : 0);
58 int total_win_count = ((tmp = getSetting(game->player[game->active_player]->user, NULL, "4wins_win")) ? atoi(tmp) : 0);
62 sprintf(buf, "%d", win_count);
63 setSetting(game->player[game->active_player]->user, chan, "4wins_win", buf);
64 sprintf(buf, "%d", total_win_count);
65 setSetting(game->player[game->active_player]->user, NULL, "4wins_win", buf);
67 fourwins_free_game(game);
70 if(game->total_stones == FOURWINS_MAX_STONES) {
71 fourwins_reply(game, "NF_4WINS_DRAW");
72 if((game->player[0]->user->flags & USERFLAG_ISAUTHED)) {
74 int win_count = ((tmp = getSetting(game->player[0]->user, chan, "4wins_draw")) ? atoi(tmp) : 0);
75 int total_win_count = ((tmp = getSetting(game->player[0]->user, NULL, "4wins_draw")) ? atoi(tmp) : 0);
79 sprintf(buf, "%d", win_count);
80 setSetting(game->player[0]->user, chan, "4wins_draw", buf);
81 sprintf(buf, "%d", total_win_count);
82 setSetting(game->player[0]->user, NULL, "4wins_draw", buf);
84 if((game->player[1]->user->flags & USERFLAG_ISAUTHED)) {
86 int win_count = ((tmp = getSetting(game->player[1]->user, chan, "4wins_draw")) ? atoi(tmp) : 0);
87 int total_win_count = ((tmp = getSetting(game->player[1]->user, NULL, "4wins_draw")) ? atoi(tmp) : 0);
91 sprintf(buf, "%d", win_count);
92 setSetting(game->player[1]->user, chan, "4wins_draw", buf);
93 sprintf(buf, "%d", total_win_count);
94 setSetting(game->player[1]->user, NULL, "4wins_draw", buf);
96 fourwins_free_game(game);
99 if(game->active_player)
100 game->active_player = 0;
102 game->active_player = 1;
103 fourwins_reply(game, "NF_4WINS_USER_HURRY_UP", game->player[game->active_player]->user->nick);
104 game->timer = timeq_add(120, module_id, fourwins_timeout, game);