unrealircd- supernets unrealircd source & configuration |
git clone git://git.acid.vegas/unrealircd.git |
Log | Files | Refs | Archive | README | LICENSE |
pingpong.c (5034B)
1 /* 2 * Unreal Internet Relay Chat Daemon, src/modules/pingpong.c 3 * (C) 2000-2001 Carsten V. Munk and the UnrealIRCd Team 4 * Moved to modules by Fish (Justin Hammond) 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 1, or (at your option) 9 * any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 */ 20 21 #include "unrealircd.h" 22 23 CMD_FUNC(cmd_ping); 24 CMD_FUNC(cmd_pong); 25 CMD_FUNC(cmd_nospoof); 26 27 /* Place includes here */ 28 #define MSG_PING "PING" /* PING */ 29 #define MSG_PONG "PONG" /* PONG */ 30 31 ModuleHeader MOD_HEADER 32 = { 33 "pingpong", /* Name of module */ 34 "5.0", /* Version */ 35 "ping, pong and nospoof", /* Short description of module */ 36 "UnrealIRCd Team", 37 "unrealircd-6", 38 }; 39 /* This is called on module init, before Server Ready */ 40 MOD_INIT() 41 { 42 CommandAdd(modinfo->handle, MSG_PING, cmd_ping, MAXPARA, CMD_USER|CMD_SERVER|CMD_SHUN); 43 CommandAdd(modinfo->handle, MSG_PONG, cmd_pong, MAXPARA, CMD_UNREGISTERED|CMD_USER|CMD_SERVER|CMD_SHUN|CMD_VIRUS); 44 MARK_AS_OFFICIAL_MODULE(modinfo); 45 return MOD_SUCCESS; 46 } 47 48 /* Is first run when server is 100% ready */ 49 MOD_LOAD() 50 { 51 return MOD_SUCCESS; 52 } 53 54 55 /* Called when module is unloaded */ 56 MOD_UNLOAD() 57 { 58 return MOD_SUCCESS; 59 } 60 61 /* 62 ** cmd_ping 63 ** parv[1] = origin 64 ** parv[2] = destination 65 */ 66 CMD_FUNC(cmd_ping) 67 { 68 Client *target; 69 const char *origin, *destination; 70 71 if (parc < 2 || BadPtr(parv[1])) 72 { 73 sendnumeric(client, ERR_NOORIGIN); 74 return; 75 } 76 77 origin = parv[1]; 78 destination = parv[2]; /* Will get NULL or pointer (parc >= 2!!) */ 79 80 if (!MyUser(client)) 81 origin = client->name; 82 83 if (!BadPtr(destination) && mycmp(destination, me.name) != 0 && mycmp(destination, me.id) != 0) 84 { 85 if (MyUser(client)) 86 origin = client->name; /* Make sure origin is not spoofed */ 87 if ((target = find_server_quick(destination)) && (target != &me)) 88 sendto_one(target, NULL, ":%s PING %s :%s", client->name, origin, destination); 89 else 90 { 91 sendnumeric(client, ERR_NOSUCHSERVER, destination); 92 return; 93 } 94 } 95 else 96 { 97 MessageTag *mtags = NULL; 98 new_message(&me, recv_mtags, &mtags); 99 sendto_one(client, mtags, ":%s PONG %s :%s", me.name, 100 (destination) ? destination : me.name, origin); 101 free_message_tags(mtags); 102 } 103 } 104 105 /* 106 ** cmd_nospoof - allows clients to respond to no spoofing patch 107 ** parv[1] = code 108 */ 109 CMD_FUNC(cmd_nospoof) 110 { 111 unsigned long result; 112 113 if (IsNotSpoof(client)) 114 return; 115 if (IsRegistered(client)) 116 return; 117 if (!*client->name) 118 return; 119 if (BadPtr(parv[1])) 120 { 121 sendnotice(client, "ERROR: Invalid PING response. Your client must respond back with PONG :<cookie>"); 122 return; 123 } 124 125 result = strtoul(parv[1], NULL, 16); 126 127 if (result != client->local->nospoof) 128 { 129 /* Apparently we also accept PONG <irrelevant> <cookie>... */ 130 if (BadPtr(parv[2])) 131 { 132 sendnotice(client, "ERROR: Invalid PING response. Your client must respond back with PONG :<cookie>"); 133 return; 134 } 135 result = strtoul(parv[2], NULL, 16); 136 if (result != client->local->nospoof) 137 { 138 sendnotice(client, "ERROR: Invalid PING response. Your client must respond back with PONG :<cookie>"); 139 return; 140 } 141 } 142 143 client->local->nospoof = 0; 144 145 if (USE_BAN_VERSION && MyConnect(client)) 146 sendto_one(client, NULL, ":IRC!IRC@%s PRIVMSG %s :\1VERSION\1", 147 me.name, client->name); 148 149 if (is_handshake_finished(client)) 150 register_user(client); 151 } 152 153 /* 154 ** cmd_pong 155 ** parv[1] = origin 156 ** parv[2] = destination 157 */ 158 CMD_FUNC(cmd_pong) 159 { 160 Client *target; 161 const char *origin, *destination; 162 163 if (!IsRegistered(client)) 164 { 165 CALL_CMD_FUNC(cmd_nospoof); 166 return; 167 } 168 169 if (parc < 2 || *parv[1] == '\0') 170 { 171 sendnumeric(client, ERR_NOORIGIN); 172 return; 173 } 174 175 origin = parv[1]; 176 destination = parv[2]; 177 ClearPingSent(client); 178 ClearPingWarning(client); 179 180 /* Remote pongs for clients? uhh... */ 181 if (MyUser(client) || !IsRegistered(client)) 182 return; 183 184 /* PONG from a server - either for us, or needs relaying.. */ 185 if (!BadPtr(destination) && mycmp(destination, me.name) != 0) 186 { 187 if ((target = find_client(destination, NULL)) || 188 (target = find_server_quick(destination))) 189 { 190 if (IsUser(client) && !IsServer(target)) 191 { 192 sendnumeric(client, ERR_NOSUCHSERVER, destination); 193 return; 194 } else 195 { 196 MessageTag *mtags = NULL; 197 new_message(client, recv_mtags, &mtags); 198 sendto_one(target, mtags, ":%s PONG %s %s", client->name, origin, destination); 199 free_message_tags(mtags); 200 } 201 } 202 else 203 { 204 sendnumeric(client, ERR_NOSUCHSERVER, destination); 205 return; 206 } 207 } 208 }