*** VERSION 5.5.0 ***
[NeonServV5.git] / src / modules / NeonFun.mod / cmd_neonfun_4view.c
1 /* cmd_neonfun_4view.c - NeonServ v5.5
2  * Copyright (C) 2011-2012  Philipp Kreil (pk910)
3  * 
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.
8  * 
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.
13  * 
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/>. 
16  */
17
18 #include "cmd_neonfun.h"
19 #include "game_4wins.h"
20
21 CMD_BIND(neonfun_cmd_4view) {
22     struct UserNode *gameuser;
23     struct ChanUser *chanuser;
24     if(!argc || !(gameuser = getUserByNick(argv[0])) || !(chanuser = getChanUser(gameuser, chan))) {
25         reply(textclient, user, "NF_4WINS_APPEND_PLAYER");
26         return;
27     }
28     struct fourwins_game *game, *fgame = NULL;
29     struct fourwins_guest *guest;
30     for(game = fourwins_active_games; game; game = game->next) {
31         for(guest = game->guests; guest; guest = guest->next) {
32             if(guest->chanuser->user == user) {
33                 reply(textclient, user, "NF_4WINS_VIEWING_ANOTHER_GAME");
34                 return;
35             }
36         }
37         if(game->player[0]->user == user || game->player[1]->user == user) {
38             reply(textclient, user, "NF_4WINS_VIEWING_ANOTHER_GAME");
39             return;
40         }
41         if(chanuser == game->player[0] || chanuser == game->player[1]) {
42             fgame = game;
43         }
44     }
45     game = fgame;
46     if(game) {
47         guest = malloc(sizeof(*guest));
48         chanuser = getChanUser(user, chan);
49         if(!chanuser) return;
50         guest->chanuser = chanuser;
51         guest->next = game->guests;
52         game->guests = guest;
53         reply(textclient, user, "NF_4WINS_VIEWING_GAME");
54     } else {
55         reply(textclient, user, "NF_4WINS_NO_GAME_FOUND");
56     }
57 }