unrealircd- supernets unrealircd source & configuration |
git clone git://git.acid.vegas/unrealircd.git |
Log | Files | Refs | Archive | README | LICENSE |
sapart.c (5775B)
1 /* 2 * IRC - Internet Relay Chat, src/modules/sapart.c 3 * (C) 2004 The UnrealIRCd Team 4 * 5 * See file AUTHORS in IRC package for additional names of 6 * the programmers. 7 * 8 * This program is free software; you can redistribute it and/or modify 9 * it under the terms of the GNU General Public License as published by 10 * the Free Software Foundation; either version 1, or (at your option) 11 * any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21 */ 22 23 #include "unrealircd.h" 24 25 CMD_FUNC(cmd_sapart); 26 27 #define MSG_SAPART "SAPART" 28 29 ModuleHeader MOD_HEADER 30 = { 31 "sapart", 32 "5.0", 33 "command /sapart", 34 "UnrealIRCd Team", 35 "unrealircd-6", 36 }; 37 38 MOD_INIT() 39 { 40 CommandAdd(modinfo->handle, MSG_SAPART, cmd_sapart, 3, CMD_USER|CMD_SERVER); 41 MARK_AS_OFFICIAL_MODULE(modinfo); 42 return MOD_SUCCESS; 43 } 44 45 MOD_LOAD() 46 { 47 return MOD_SUCCESS; 48 } 49 50 MOD_UNLOAD() 51 { 52 return MOD_SUCCESS; 53 } 54 55 static void log_sapart(Client *client, MessageTag *mtags, Client *target, const char *channels, const char *comment) 56 { 57 const char *issuer = command_issued_by_rpc(mtags); 58 59 if (issuer) 60 { 61 if (comment) 62 { 63 unreal_log(ULOG_INFO, "sacmds", "SAPART_COMMAND", client, "SAPART: $issuer used SAPART to make $target part $channels ($reason)", 64 log_data_string("issuer", issuer), 65 log_data_client("target", target), 66 log_data_string("channels", channels), 67 log_data_string("reason", comment)); 68 } 69 else 70 { 71 unreal_log(ULOG_INFO, "sacmds", "SAPART_COMMAND", client, "SAPART: $issuer used SAPART to make $target part $channels", 72 log_data_string("issuer", issuer), 73 log_data_client("target", target), 74 log_data_string("channels", channels)); 75 } 76 } else { 77 if (comment) 78 { 79 unreal_log(ULOG_INFO, "sacmds", "SAPART_COMMAND", client, "SAPART: $client used SAPART to make $target part $channels ($reason)", 80 log_data_client("target", target), 81 log_data_string("channels", channels), 82 log_data_string("reason", comment)); 83 } 84 else 85 { 86 unreal_log(ULOG_INFO, "sacmds", "SAPART_COMMAND", client, "SAPART: $client used SAPART to make $target part $channels", 87 log_data_client("target", target), 88 log_data_string("channels", channels)); 89 } 90 } 91 } 92 93 94 /* cmd_sapart() - Lamego - Wed Jul 21 20:04:48 1999 95 Copied off PTlink IRCd (C) PTlink coders team. 96 Coded for Sadmin by Stskeeps 97 also Modified by NiQuiL (niquil@programmer.net) 98 parv[1] - nick to make part 99 parv[2] - channel(s) to part 100 parv[3] - comment 101 */ 102 103 CMD_FUNC(cmd_sapart) 104 { 105 Client *target; 106 Channel *channel; 107 MessageTag *mtags = NULL; 108 Membership *lp; 109 char *name, *p = NULL; 110 int i; 111 const char *comment = (parc > 3 && parv[3] ? parv[3] : NULL); 112 char commentx[512]; 113 char request[BUFSIZE]; 114 char jbuf[BUFSIZE]; 115 int ntargets = 0; 116 int maxtargets = max_targets_for_command("SAPART"); 117 118 if ((parc < 3) || BadPtr(parv[2])) 119 { 120 sendnumeric(client, ERR_NEEDMOREPARAMS, "SAPART"); 121 return; 122 } 123 124 if (!(target = find_user(parv[1], NULL))) 125 { 126 sendnumeric(client, ERR_NOSUCHNICK, parv[1]); 127 return; 128 } 129 130 /* See if we can operate on this vicim/this command */ 131 if (!ValidatePermissionsForPath("sacmd:sapart",client,target,NULL,NULL)) 132 { 133 sendnumeric(client, ERR_NOPRIVILEGES); 134 return; 135 } 136 137 /* Broadcast so other servers can log it appropriately as an SAPART */ 138 if (parv[3]) 139 sendto_server(client, 0, 0, recv_mtags, ":%s SAPART %s %s :%s", client->id, target->id, parv[2], comment); 140 else 141 sendto_server(client, 0, 0, recv_mtags, ":%s SAPART %s %s", client->id, target->id, parv[2]); 142 143 if (!MyUser(target)) 144 { 145 log_sapart(client, recv_mtags, target, parv[2], comment); 146 return; 147 } 148 149 /* 'target' is our client... */ 150 151 *jbuf = 0; 152 strlcpy(request, parv[2], sizeof(request)); 153 for (i = 0, name = strtoken(&p, request, ","); name; name = strtoken(&p, NULL, ",")) 154 { 155 if (++ntargets > maxtargets) 156 { 157 sendnumeric(client, ERR_TOOMANYTARGETS, name, maxtargets, "SAPART"); 158 break; 159 } 160 161 if (!(channel = find_channel(name))) 162 { 163 sendnumeric(client, ERR_NOSUCHCHANNEL, name); 164 continue; 165 } 166 167 /* Validate oper can do this on chan/victim */ 168 if (!IsULine(client) && !ValidatePermissionsForPath("sacmd:sapart",client,target,channel,NULL)) 169 { 170 sendnumeric(client, ERR_NOPRIVILEGES); 171 continue; 172 } 173 174 if (!(lp = find_membership_link(target->user->channel, channel))) 175 { 176 sendnumeric(client, ERR_USERNOTINCHANNEL, target->name, name); 177 continue; 178 } 179 if (*jbuf) 180 strlcat(jbuf, ",", sizeof jbuf); 181 strlncat(jbuf, name, sizeof jbuf, sizeof(jbuf) - i - 1); 182 i += strlen(name) + 1; 183 } 184 185 if (!*jbuf) 186 return; 187 188 strlcpy(request, jbuf, sizeof(request)); 189 190 log_sapart(client, recv_mtags, target, request, comment); 191 192 //if (comment) 193 //{ 194 // snprintf(commentx, sizeof(commentx), "SAPart: %s", comment); 195 // sendnotice(target, "*** You were forced to part %s (%s)", request, commentx); 196 //} else { 197 // sendnotice(target, "*** You were forced to part %s", request); 198 //} 199 200 parv[0] = target->name; // nick 201 parv[1] = request; // chan 202 parv[2] = comment ? commentx : NULL; // comment 203 204 /* Now, do the actual parting: */ 205 mtag_add_issued_by(&mtags, client, recv_mtags); 206 do_cmd(target, mtags, "PART", comment ? 3 : 2, parv); 207 safe_free_message_tags(mtags); 208 209 /* NOTE: target may be killed now due to the part reason @ spamfilter */ 210 }