Bez tytułu

z k4be, 4 lata temu, napisane w C, wyświetlone 458 razy. Ta wklejka jest odpowiedzią na Bez tytułu z k4be - Pokaż różnice
URL https://pastebin.k4be.pl/view/25e0c71a Udostępnij
Pobierz wklejkę lub Pokaż surowy tekst
  1. /*
  2.  *   Created by k4be, based on setname.c
  3.  *   IRC - Internet Relay Chat
  4.  *   (c) 1999-2001 Dominick Meglio (codemastr) <codemastr@unrealircd.com>
  5.  *
  6.  *   See file AUTHORS in IRC package for additional names of
  7.  *   the programmers.
  8.  *
  9.  *   This program is free software; you can redistribute it and/or modify
  10.  *   it under the terms of the GNU General Public License as published by
  11.  *   the Free Software Foundation; either version 1, or (at your option)
  12.  *   any later version.
  13.  *
  14.  *   This program is distributed in the hope that it will be useful,
  15.  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.  *   GNU General Public License for more details.
  18.  *
  19.  *   You should have received a copy of the GNU General Public License
  20.  *   along with this program; if not, write to the Free Software
  21.  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22.  */
  23.  
  24. /*** <<<MODULE MANAGER START>>>
  25. module
  26. {
  27.         documentation "https://github.com/pirc-pl/unrealircd-modules/blob/master/README.md#setname";
  28.         troubleshooting "In case of problems, contact k4be on irc.pirc.pl.";
  29.         min-unrealircd-version "5.*";
  30.         post-install-text {
  31.                 "The module is installed. Now all you need to do is add a loadmodule line:";
  32.                 "loadmodule \"third/setname\";";
  33.                                 "And /REHASH the IRCd.";
  34.                                 "The module does not need any configuration.";
  35.                                 "Please note that the implemented feature is still \"Work In Progress\".";
  36.         }
  37. }
  38. *** <<<MODULE MANAGER END>>>
  39. */
  40.  
  41. #include "unrealircd.h"
  42.  
  43. CMD_OVERRIDE_FUNC(cmd_setname);
  44. char *setname_isupport_param(void);
  45.  
  46. long CAP_SETNAME = 0L;
  47.  
  48. #define MSG_SETNAME     "SETNAME"       /* setname */
  49. #define STR_HELPER(x) #x
  50. #define STR(x) STR_HELPER(x)
  51.  
  52. ModuleHeader MOD_HEADER
  53.   = {
  54.         "third/setname",        /* Name of module */
  55.         "5.0", /* Version */
  56.         "IRCv3-compatible command /setname (CAP draft/setname)", /* Short description of module */
  57.         "k4be@PIRC",
  58.         "unrealircd-5",
  59.     };
  60.  
  61. MOD_INIT(){
  62.         ClientCapabilityInfo cap;
  63.         ClientCapability *c;
  64.  
  65.         memset(&cap, 0, sizeof(cap));
  66.         cap.name = "draft/setname";
  67.         c = ClientCapabilityAdd(modinfo->handle, &cap, &CAP_SETNAME);
  68.  
  69.         return MOD_SUCCESS;
  70. }
  71.  
  72. MOD_LOAD(){
  73.         if(!CommandOverrideAddEx(modinfo->handle, MSG_SETNAME, 0, cmd_setname)){
  74.                 config_error("[%s] Crritical: Failed to request command override for SETNAME: %s", MOD_HEADER.name, ModuleGetErrorStr(modinfo->handle));
  75.         }
  76.         ISupportAdd(modinfo->handle, "NAMELEN", setname_isupport_param());
  77.         return MOD_SUCCESS;
  78. }
  79.  
  80. char *setname_isupport_param(void){
  81.         return STR(REALLEN);
  82. }
  83.  
  84. MOD_UNLOAD(){
  85.         return MOD_SUCCESS;
  86. }
  87.  
  88. /* cmd_setname - 12/05/1999 - Stskeeps
  89.  * :prefix SETNAME :gecos
  90.  * parv[1] - gecos
  91.  * D: This will set your gecos to be <x> (like (/setname :The lonely wanderer))
  92.    yes it is experimental but anyways ;P
  93.     FREEDOM TO THE USERS! ;)
  94. */
  95. CMD_OVERRIDE_FUNC(cmd_setname){
  96.         int xx;
  97.         char tmpinfo[REALLEN + 1];
  98.         char spamfilter_user[NICKLEN + USERLEN + HOSTLEN + REALLEN + 64];
  99.         ConfigItem_ban *bconf;
  100.  
  101.         if(!HasCapabilityFast(client, CAP_SETNAME)){
  102.                 CallCommandOverride(ovr, client, recv_mtags, parc, parv); // the original command
  103.                 sendto_local_common_channels(client, client, CAP_SETNAME, recv_mtags, ":%s!%s@%s SETNAME :%s", client->name, client->user->username, GetHost(client), parv[1]);
  104.                 return;
  105.         }
  106.  
  107.         if ((parc < 2) || BadPtr(parv[1])){
  108.                 sendnumeric(client, ERR_NEEDMOREPARAMS, "SETNAME");
  109.                 return;
  110.         }
  111.  
  112.         if (strlen(parv[1]) > REALLEN){
  113.                 if (MyConnect(client)){
  114.                         sendto_one(client, recv_mtags, ":%s FAIL SETNAME INVALID_REALNAME :\"Real names\" may maximum be %i characters of length", me.name, REALLEN);
  115.                 }
  116.                 return;
  117.         }
  118.  
  119.         if (MyUser(client)){
  120.                 /* set temp info for spamfilter check*/
  121.                 strcpy(tmpinfo, client->info);
  122.                 /* set the new name before we check, but don't send to servers unless it is ok */
  123.                 strcpy(client->info, parv[1]);
  124.                 spamfilter_build_user_string(spamfilter_user, client->name, client);
  125.                 if (match_spamfilter(client, spamfilter_user, SPAMF_USER, NULL, 0, NULL)){
  126.                         /* Was rejected by spamfilter, restore the realname */
  127.                         strcpy(client->info, tmpinfo);
  128.                         return;
  129.                 }
  130.  
  131.                 /* Check for realname bans here too */
  132.                 if (!ValidatePermissionsForPath("immune:server-ban:ban-realname",client,NULL,NULL,NULL) &&
  133.                     ((bconf = find_ban(NULL, client->info, CONF_BAN_REALNAME)))){
  134.                         banned_client(client, "realname", bconf->reason?bconf->reason:"", 0, 0);
  135.                         return;
  136.                 }
  137.         } else {
  138.                 /* remote user */
  139.                 strcpy(client->info, parv[1]);
  140.         }
  141.  
  142.         sendto_server(client, 0, 0, NULL, ":%s SETNAME :%s", client->id, parv[1]);
  143.  
  144.         if(MyConnect(client)){
  145.                 sendto_one(client, recv_mtags, ":%s!%s@%s SETNAME :%s", client->name, client->user->username, GetHost(client), parv[1]);
  146.         }
  147.         sendto_local_common_channels(client, client, CAP_SETNAME, recv_mtags, ":%s!%s@%s SETNAME :%s", client->name, client->user->username, GetHost(client), parv[1]);
  148. }
  149.  

odpowiedź "Bez tytułu"

Tutaj możesz odpowiedzieć na wklejkę z góry

captcha