]> jfr.im git - irc/quakenet/newserv.git/blob - noperserv/noperserv_commands.c
Began manual merge.
[irc/quakenet/newserv.git] / noperserv / noperserv_commands.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <stdarg.h>
4 #include <string.h>
5 #include <time.h>
6
7 #include "../control/control.h"
8 #include "../nick/nick.h"
9 #include "../localuser/localuserchannel.h"
10
11 int controlkill(void *sender, int cargc, char **cargv);
12 int controlopchan(void *sender, int cargc, char **cargv);
13 int controlkick(void *sender, int cargc, char **cargv);
14
15 void _init() {
16 registercontrolhelpcmd("kill",NO_OPER,2,&controlkill,"Usage: kill nick <reason>\nKill specificed user.");
17 registercontrolhelpcmd("opchan",NO_OPER,2,&controlopchan,"Usage: opchan channel nick\nGive user +o on channel.");
18 registercontrolhelpcmd("kick",NO_OPER,3,&controlkick,"Usage: kick channel user <reason>\nKick a user from the given channel");
19 }
20
21 void _fini() {
22 deregistercontrolcmd("kill",controlkill);
23 deregistercontrolcmd("opchan",controlopchan);
24 deregistercontrolcmd("kick",controlkick);
25 }
26
27 int controlkick(void *sender, int cargc, char **cargv) {
28 nick *np=(nick *)sender;
29 nick *victim;
30 channel *cp;
31 modechanges changes;
32 nick *target;
33
34 if (cargc<2) {
35 controlreply(sender,"Usage: kick channel user <reason>");
36 return CMD_ERROR;
37 }
38
39 if ((cp=findchannel(cargv[0]))!=NULL) {
40 if (cargv[1][0]=='#') {
41 if (!(target=getnickbynumericstr(cargv[1]+1))) {
42 controlreply(np,"Sorry, couldn't find numeric %s",cargv[0]+1);
43 return CMD_ERROR;
44 }
45 } else {
46 if ((target=getnickbynick(cargv[1]))==NULL) {
47 controlreply(np,"Sorry, couldn't find that user");
48 return CMD_ERROR;
49 }
50 }
51
52 if(cargc > 2) {
53 irc_send("%s K %s %s :%s",mynumeric->content,cp->index->name->content,longtonumeric(target->numeric,5),cargv[2]);
54 } else {
55 irc_send("%s K %s %s :Kicked",mynumeric->content,cp->index->name->content,longtonumeric(target->numeric,5));
56 }
57 delnickfromchannel(cp, target->numeric, 1);
58
59 controlreply(sender,"Put Kick for %s from %s.", target->nick, cp->index->name->content);
60 controlwall(NO_OPER, NL_KICKS, "%s/%s sent KICK for %s!%s@%s from %s", np->nick, np->authname, target->nick, target->ident, target->host->name->content,cp->index->name->content);
61
62 } else {
63 controlreply(np,"Couldn't find channel %s.",cargv[0]);
64 return;
65 }
66
67 return CMD_OK;
68 }
69
70 int controlopchan(void *source, int cargc, char **cargv) {
71 nick *sender=(nick *)source;
72 nick *victim;
73 channel *cp;
74 modechanges changes;
75 nick *target;
76 unsigned long *lp;
77
78 if (cargc<2) {
79 controlreply(sender,"Usage: opchan channel user");
80 return CMD_ERROR;
81 }
82
83 if ((cp=findchannel(cargv[0]))!=NULL) {
84 if (cargv[1][0]=='#') {
85 if (!(target=getnickbynumericstr(cargv[1]+1))) {
86 controlreply(sender,"Sorry, couldn't find numeric %s",cargv[0]+1);
87 return CMD_ERROR;
88 }
89 } else {
90 if ((target=getnickbynick(cargv[1]))==NULL) {
91 controlreply((nick *)sender,"Sorry, couldn't find that user");
92 return CMD_ERROR;
93 }
94 }
95
96 if ((lp=getnumerichandlefromchanhash(cp->users,target->numeric))==NULL) {
97 controlreply((nick *)sender,"Sorry, User not on channel");
98 return CMD_ERROR;
99 }
100
101 (*lp)|=CUMODE_OP;
102 irc_send("%s OM %s +o %s",mynumeric->content,cp->index->name->content,longtonumeric(target->numeric,5));
103 controlreply(sender,"Put mode +o %s on %s.", target->nick, cp->index->name->content);
104 } else {
105 controlreply(sender,"Couldn't find channel %s.",cargv[0]);
106 return;
107 }
108
109 return CMD_OK;
110 }
111
112 int controlkill(void *sender, int cargc, char **cargv) {
113 nick *target;
114 char buf[BUFSIZE];
115 int i;
116 nick *np = (nick *)sender;
117
118 if (cargc<1) {
119 controlreply(np,"Usage: kill <user> <reason>");
120 return CMD_ERROR;
121 }
122
123 if (cargv[0][0]=='#') {
124 if (!(target=getnickbynumericstr(cargv[0]+1))) {
125 controlreply(np,"Sorry, couldn't find numeric %s",cargv[0]+1);
126 return CMD_ERROR;
127 }
128 } else {
129 if ((target=getnickbynick(cargv[0]))==NULL) {
130 controlreply(np,"Sorry, couldn't find that user");
131 return CMD_ERROR;
132 }
133 }
134
135 killuser(NULL, target, (cargc>1)?cargv[1]:"Killed");
136 controlreply(np,"KILL sent.");
137 controlwall(NO_OPER, NL_KILLS, "%s/%s sent KILL for %s!%s@%s (%s)", np->nick, np->authname, target->nick, target->ident, target->host->name->content,(cargc>1)?cargv[1]:"Killed");
138
139 return CMD_OK;
140 }