]> arthur.barton.de Git - ngircd-alex.git/blob - src/ngircd/irc-op.c
- include <sys/types.h>, if available.
[ngircd-alex.git] / src / ngircd / irc-op.c
1 /*
2  * ngIRCd -- The Next Generation IRC Daemon
3  * Copyright (c)2001,2002 by Alexander Barton (alex@barton.de)
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  * Please read the file COPYING, README and AUTHORS for more information.
10  *
11  * Channel operator commands
12  */
13
14
15 #include "portab.h"
16
17 static char UNUSED id[] = "$Id: irc-op.c,v 1.11 2002/12/12 12:24:18 alex Exp $";
18
19 #include "imp.h"
20 #include <assert.h>
21 #include <string.h>
22 #include <stdio.h>
23
24 #include "conn.h"
25 #include "client.h"
26 #include "channel.h"
27 #include "defines.h"
28 #include "irc-write.h"
29 #include "lists.h"
30 #include "log.h"
31 #include "messages.h"
32 #include "parse.h"
33
34 #include "exp.h"
35 #include "irc-op.h"
36
37
38 GLOBAL BOOLEAN
39 IRC_KICK( CLIENT *Client, REQUEST *Req )
40 {
41         CLIENT *target, *from;
42         
43         assert( Client != NULL );
44         assert( Req != NULL );
45
46         /* Falsche Anzahl Parameter? */
47         if(( Req->argc < 2) || ( Req->argc > 3 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
48
49         if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
50         else from = Client;
51         if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
52         
53         /* Ziel-User suchen */
54         target = Client_Search( Req->argv[1] );
55         if( ! target ) return IRC_WriteStrClient( from, ERR_NOSUCHNICK_MSG, Client_ID( from ), Req->argv[1] );
56
57         Channel_Kick( target, from, Req->argv[0], Req->argc == 3 ? Req->argv[2] : Client_ID( from ));
58         return CONNECTED;
59 } /* IRC_KICK */        
60
61
62 GLOBAL BOOLEAN
63 IRC_INVITE( CLIENT *Client, REQUEST *Req )
64 {
65         CHANNEL *chan;
66         CLIENT *target, *from;
67         BOOLEAN remember = FALSE;
68
69         assert( Client != NULL );
70         assert( Req != NULL );
71
72         /* Falsche Anzahl Parameter? */
73         if( Req->argc != 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
74
75         if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
76         else from = Client;
77         if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
78         
79         /* User suchen */
80         target = Client_Search( Req->argv[0] );
81         if(( ! target ) || ( Client_Type( target ) != CLIENT_USER )) return IRC_WriteStrClient( from, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->argv[0] );
82
83         chan = Channel_Search( Req->argv[1] );
84
85         if( chan )
86         {
87                 /* Der Channel existiert bereits; ist der User Mitglied? */
88                 if( ! Channel_IsMemberOf( chan, from )) return IRC_WriteStrClient( from, ERR_NOTONCHANNEL_MSG, Client_ID( Client ), Req->argv[1] );
89
90                 /* Ist der Channel "invite-only"? */
91                 if( strchr( Channel_Modes( chan ), 'i' ))
92                 {
93                         /* Ja. Der User muss Channel-Operator sein! */
94                         if( ! strchr( Channel_UserModes( chan, from ), 'o' )) return IRC_WriteStrClient( from, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( from ), Channel_Name( chan ));
95                         remember = TRUE;
96                 }
97
98                 /* Ist der Ziel-User bereits Mitglied? */
99                 if( Channel_IsMemberOf( chan, target )) return IRC_WriteStrClient( from, ERR_USERONCHANNEL_MSG, Client_ID( from ), Req->argv[0], Req->argv[1] );
100         }
101
102         /* Wenn der User gebanned ist, so muss das Invite auch gespeichert werden */
103         if( Lists_CheckBanned( target, chan )) remember = TRUE;
104
105         Log( LOG_DEBUG, "User \"%s\" invites \"%s\" to \"%s\" ...", Client_Mask( from ), Req->argv[0], Req->argv[1] );
106         if( remember )
107         {
108                 if( ! Lists_AddInvited( from, Client_Mask( target ), chan, TRUE )) return CONNECTED;
109         }
110         
111         /* an Ziel-Client forwarden ... */
112         IRC_WriteStrClientPrefix( target, from, "INVITE %s %s", Req->argv[0], Req->argv[1] );
113
114         if( Client_Conn( target ) > NONE )
115         {
116                 /* lokaler Ziel-Client, Status-Code melden */
117                 if( ! IRC_WriteStrClientPrefix( from, target, RPL_INVITING_MSG, Client_ID( from ), Req->argv[0], Req->argv[1] )) return DISCONNECTED;
118         }
119         
120         return CONNECTED;
121 } /* IRC_INVITE */
122
123
124 /* -eof- */