Did you know? You may get official Slexy swag and exclusive features when you Donate today!
Author: apples Language: c
Description: No description (v2) Timestamp: 2008-10-11 23:09:52 -0400
View raw paste Reply
  1. /*
  2.  * =================================================================
  3.  * Filename:      m_elmer.c
  4.  * =================================================================
  5.  * Description:   Command /elmer: makes someone talk like Elmer J.
  6.  *                Fudd, that is, letters 'l' and 'r' become 'w', for
  7.  *                example, "Shhhhhh! Be vewy, vewy quiet... I'm
  8.  *                hunting wabbits, heh-heh-heh." (More info at
  9.  *                http://www.geocities.com/Hollywood/Park/2326/
  10.  *                character1.html#elmer.) Install this module
  11.  *                on all servers in order to make it work properly.
  12.  * =================================================================
  13.  * Author:        AngryWolf
  14.  * Email:         angrywolf@flashmail.com
  15.  * =================================================================
  16.  * Feedback:
  17.  *
  18.  * I accept bugreports, ideas and opinions, and if you have any
  19.  * questions, just send an email to me!
  20.  *
  21.  * Thank you for using my module!
  22.  *
  23.  * =================================================================
  24.  * Requirements:
  25.  * =================================================================
  26.  *
  27.  * o Unreal >=3.2-beta18
  28.  * o One of the supported operating systems (see unreal32docs.html)
  29.  *
  30.  * =================================================================
  31.  * Installation:
  32.  * =================================================================
  33.  *
  34.  * See http://angrywolf.linktipp.org/compiling.php?lang=en
  35.  *
  36.  * =================================================================
  37.  * Usage:
  38.  * =================================================================
  39.  *
  40.  * Command ELMER:
  41.  * --------------
  42.  *
  43.  * Syntax: /elmer [+|-]<nickname>
  44.  *
  45.  * Examples:
  46.  *
  47.  * - To make someone talk like Elmer:
  48.  *       /elmer SomeNick
  49.  * - To remove the previous setting from someone:
  50.  *       /elmer -SomeNick
  51.  *
  52.  * =================================================================
  53.  * Mirror files:
  54.  * =================================================================
  55.  *
  56.  * http://angrywolf.linktipp.org/m_elmer.c [Germany]
  57.  * http://angrywolf.uw.hu/m_elmer.c [Hungary]
  58.  * http://angrywolf.fw.hu/m_elmer.c [Hungary]
  59.  *
  60.  * =================================================================
  61.  * Changes:
  62.  * =================================================================
  63.  *
  64.  * $Log: m_elmer.c,v $
  65.  * Revision 1.6  2004/03/12 11:59:30  angrywolf
  66.  * - Made some minor fixes.
  67.  *
  68.  * Revision 1.5  2004/03/08 21:25:12  angrywolf
  69.  * - Fixed some bugs that could cause crash if you compile the module
  70.  *   statically (for example, under Windows).
  71.  *
  72.  * Revision 1.4  2004/02/23 17:37:34  angrywolf
  73.  * - Unoccupied flags are not trustable, CVS .2138 took use
  74.  *   of the one I used before to mark users as Elmers.
  75.  *   Therefore I use a separate list now, even if it's
  76.  *   more memory intensive.
  77.  *
  78.  * Revision 1.3  2004/02/17 10:42:24  angrywolf
  79.  * *** empty log message ***
  80.  *
  81.  * Revision 1.2  2004/02/17 10:35:50  angrywolf
  82.  * - Fixed a letter case problem, reported by MichaelJE2.
  83.  *
  84.  * Revision 1.1  2004/01/29 13:59:28  angrywolf
  85.  * Initial revision
  86.  *
  87.  * =================================================================
  88.  */
  89.  
  90. #include "config.h"
  91. #include "struct.h"
  92. #include "common.h"
  93. #include "sys.h"
  94. #include "numeric.h"
  95. #include "msg.h"
  96. #include "channel.h"
  97. #include <time.h>
  98. #include <sys/stat.h>
  99. #include <stdio.h>
  100. #include <stdlib.h>
  101. #include <string.h>
  102. #ifdef _WIN32
  103. #include <io.h>
  104. #endif
  105. #include <fcntl.h>
  106. #include "h.h"
  107. #ifdef STRIPBADWORDS
  108. #include "badwords.h"
  109. #endif
  110. #ifdef _WIN32
  111. #include "version.h"
  112. #endif
  113.  
  114. extern void             sendto_one(aClient *to, char *pattern, ...);
  115. extern void             sendto_realops(char *pattern, ...);
  116.  
  117. #define MSG_ELMER       "ELMER"
  118. #define TOK_ELMER       "EL"
  119. #define IsParam(x)      (parc > (x) && !BadPtr(parv[(x)]))
  120. #define IsNotParam(x)   (parc <= (x) || BadPtr(parv[(x)]))
  121. #define DelHook(x)      if (x) HookDel(x); x = NULL
  122. #define DelCommand(x)   if (x) CommandDel(x); x = NULL
  123.  
  124. static Command          *AddCommand(Module *module, char *msg, char *token, iFP func);
  125. static int              m_elmer(aClient *, aClient *, int, char *[]);
  126. static char             *cb_privmsg(aClient *, aClient *, aClient *, char *, int);
  127. static char             *cb_chanmsg(aClient *, aClient *, aChannel *, char *, int);
  128. static int              cb_quit(aClient *, char *);
  129. static void             free_elmerflags();
  130.  
  131. static Command          *CmdElmer;
  132. static Hook             *HookPrivMsg = NULL, *HookChanMsg = NULL, *HookQuit = NULL;
  133.  
  134. /*
  135.  * Unoccupied flags are not trustable, they may become used anytime.
  136.  * Therefore I use a separate list.
  137.  */
  138.  
  139. typedef struct _elmerflag ElmerFlag;
  140.  
  141. struct _elmerflag
  142. {
  143.         ElmerFlag       *prev, *next;
  144.         aClient         *cptr;
  145. };
  146.  
  147. static ElmerFlag *ElmerFlags;
  148.  
  149. ModuleHeader MOD_HEADER(m_elmer)
  150.   = {
  151.         "m_elmer",
  152.         "$Id: m_elmer.c,v 1.6 2004/03/12 11:59:30 angrywolf Exp $",
  153.         "Command /elmer",
  154.         "3.2-b8-1",
  155.         NULL
  156.     };
  157.  
  158. DLLFUNC int MOD_INIT(m_elmer)(ModuleInfo *modinfo)
  159. {
  160.         ElmerFlags = NULL;
  161.  
  162.         if (!(CmdElmer = AddCommand(modinfo->handle, MSG_ELMER, TOK_ELMER, m_elmer)))
  163.                 return MOD_FAILED;
  164.  
  165.         HookPrivMsg     = HookAddPCharEx(modinfo->handle, HOOKTYPE_USERMSG, cb_privmsg);
  166.         HookChanMsg     = HookAddPCharEx(modinfo->handle, HOOKTYPE_CHANMSG, cb_chanmsg);
  167.         HookQuit        = HookAddEx(modinfo->handle, HOOKTYPE_LOCAL_QUIT, cb_quit);
  168.  
  169.         return MOD_SUCCESS;
  170. }
  171.  
  172. DLLFUNC int MOD_LOAD(m_elmer)(int module_load)
  173. {
  174.         return MOD_SUCCESS;
  175. }
  176.  
  177. DLLFUNC int MOD_UNLOAD(m_elmer)(int module_unload)
  178. {
  179.         free_elmerflags();
  180.  
  181.         DelHook(HookQuit);
  182.         DelHook(HookChanMsg);
  183.         DelHook(HookPrivMsg);
  184.         DelCommand(CmdElmer);
  185.  
  186.         return MOD_SUCCESS;
  187. }
  188.  
  189. static Command *AddCommand(Module *module, char *msg, char *token, iFP func)
  190. {
  191.         Command *cmd;
  192.  
  193.         if (CommandExists(msg))
  194.         {
  195.                 config_error("Command %s already exists", msg);
  196.                 return NULL;
  197.         }
  198.         if (CommandExists(token))
  199.         {
  200.                 config_error("Token %s already exists", token);
  201.                 return NULL;
  202.         }
  203.  
  204.         cmd = CommandAdd(module, msg, token, func, MAXPARA, 0);
  205.  
  206. #ifndef STATIC_LINKING
  207.         if (ModuleGetError(module) != MODERR_NOERROR || !cmd)
  208. #else
  209.         if (!cmd)
  210. #endif
  211.         {
  212. #ifndef STATIC_LINKING
  213.                 config_error("Error adding command %s: %s", msg,
  214.                         ModuleGetErrorStr(module));
  215. #else
  216.                 config_error("Error adding command %s", msg);
  217. #endif
  218.                 return NULL;
  219.         }
  220.  
  221.         return cmd;
  222. }
  223.  
  224. static ElmerFlag *find_elmer(aClient *cptr)
  225. {
  226.         ElmerFlag *e;
  227.  
  228.         for (e = ElmerFlags; e; e = e->next)
  229.                 if (e->cptr == cptr)
  230.                         break;
  231.  
  232.         return e;
  233. }
  234.  
  235. static void set_elmer(aClient *cptr)
  236. {
  237.         ElmerFlag *e;
  238.  
  239.         e = (ElmerFlag *) MyMalloc(sizeof(cptr));
  240.         e->cptr = cptr;
  241.         AddListItem(e, ElmerFlags);
  242. }
  243.  
  244. static void clear_elmer(ElmerFlag *e)
  245. {
  246.         DelListItem(e, ElmerFlags);
  247.         MyFree(e);
  248. }
  249.  
  250. static void free_elmerflags()
  251. {
  252.         ElmerFlag       *e;
  253.         ListStruct      *next;
  254.  
  255.         for (e = ElmerFlags; e; e = (ElmerFlag *) next)
  256.         {
  257.                 next = (ListStruct *) e->next;
  258.                 DelListItem(e, ElmerFlags);
  259.                 MyFree(e);
  260.         }
  261. }
  262.  
  263. static char *convert_to_elmer(char *str)
  264. {
  265.         char *p;
  266.  
  267.         for (p = str; *p; p++)
  268.                 switch(*p)
  269.                 {
  270.                         case 'l':
  271.                         case 'r':
  272.                                 *p = 'w';
  273.                                 break;
  274.                         case 'L':
  275.                         case 'R':
  276.                                 *p = 'W';
  277.                 }
  278.  
  279.         return str;
  280. }
  281.  
  282. static int cb_quit(aClient *sptr, char *comment)
  283. {
  284.         ElmerFlag *e;
  285.  
  286.         if ((e = find_elmer(sptr)))
  287.                 clear_elmer(e);
  288.  
  289.         return 0;
  290. }
  291.  
  292. static char *cb_privmsg(aClient *cptr, aClient *from, aClient *to, char *str, int notice)
  293. {
  294.         return find_elmer(cptr) ? convert_to_elmer(str) : str;
  295. }
  296.  
  297. static char *cb_chanmsg(aClient *cptr, aClient *from, aChannel *to, char *str, int notice)
  298. {
  299.         return find_elmer(cptr) ? convert_to_elmer(str) : str;
  300. }
  301.  
  302. static int m_elmer(aClient *cptr, aClient *sptr, int parc, char *parv[])
  303. {
  304.         aClient         *acptr          = NULL;
  305.         ElmerFlag       *is_elmer       = NULL;
  306.         char            *nick           = NULL;
  307.         int             add             = 1;
  308.  
  309.         if (IsPerson(sptr) && !IsAnOper(sptr))
  310.         {
  311.                 sendto_one(sptr, err_str(ERR_NOPRIVILEGES), me.name,
  312.                         parv[0]);
  313.                 return -1;
  314.         }
  315.  
  316.         nick = IsParam(1) ? parv[1] : NULL;
  317.  
  318.         if (nick)
  319.         {
  320.                 if (*nick == '+')
  321.                         nick++;
  322.                 else if (*nick == '-')
  323.                 {
  324.                         nick++;
  325.                         add = 0;
  326.                 }
  327.                 if (!*nick)
  328.                         nick = NULL;
  329.         }
  330.  
  331.         if (!nick)
  332.         {
  333.                 if (!IsServer(sptr))
  334.                         sendto_one(sptr, err_str(ERR_NEEDMOREPARAMS),
  335.                                 me.name, sptr->name, MSG_ELMER);
  336.                 return -1;
  337.         }
  338.  
  339.         acptr = find_person(nick, NULL);
  340.  
  341.         if (!acptr)
  342.         {
  343.                 if (!IsServer(sptr))
  344.                         sendto_one(sptr, err_str(ERR_NOSUCHNICK),
  345.                                 me.name, sptr->name, nick);
  346.                 return 0;
  347.         }
  348.  
  349.         if (!MyConnect(acptr))
  350.         {
  351.                 sendto_one(acptr->from, ":%s %s %c%s",
  352.                         sptr->name, IsToken(cptr) ? TOK_ELMER : MSG_ELMER,
  353.                         add ? '+' : '-', acptr->name);
  354.                 return 0;
  355.         }
  356.  
  357.         is_elmer = find_elmer(acptr);
  358.  
  359.         if (add)
  360.         {
  361.                 if (is_elmer)
  362.                 {
  363.                         if (!IsServer(sptr))
  364.                                 sendto_one(sptr,
  365.                                         ":%s %s %s :*** %s is already set to talk like Elmer",
  366.                                         me.name, IsWebTV(sptr) ? "PRIVMSG" : "NOTICE",
  367.                                         sptr->name, acptr->name);
  368.                         return 0;
  369.                 }
  370.  
  371.                 set_elmer(acptr);
  372.  
  373.                 sendto_realops("*** %s made %s!%s@%s talk like Elmer",
  374.                         sptr->name, acptr->name, acptr->user->username,
  375.                         GetHost(acptr));
  376.                 sendto_serv_butone(&me,
  377.                         ":%s SMO o :*** %s made %s!%s@%s talk like Elmer",
  378.                         me.name, sptr->name, acptr->name, acptr->user->username,
  379.                         GetHost(acptr));
  380.  
  381.                 if (MyConnect(sptr) && acptr != sptr)
  382.                         sendto_one(sptr,
  383.                                 ":%s %s %s :*** %s is now talking like Elmer",
  384.                                 me.name, IsWebTV(acptr) ? "PRIVMSG" : "NOTICE",
  385.                                 sptr->name, acptr->name);
  386.         }
  387.         else
  388.         {
  389.                 if (!is_elmer)
  390.                 {
  391.                         if (!IsServer(sptr))
  392.                                 sendto_one(sptr,
  393.                                         ":%s %s %s :*** %s is not talking like Elmer",
  394.                                         me.name, IsWebTV(sptr) ? "PRIVMSG" : "NOTICE",
  395.                                         sptr->name, acptr->name);
  396.                         return 0;
  397.                 }
  398.  
  399.                 clear_elmer(is_elmer);
  400.  
  401.                 sendto_realops("*** %s made %s!%s@%s no longer talk like Elmer",
  402.                         sptr->name, acptr->name,
  403.                         acptr->user->username, GetHost(acptr));
  404.                 sendto_serv_butone(&me,
  405.                         ":%s SMO o :*** %s made %s!%s@%s no longer talk like Elmer",
  406.                         me.name, sptr->name, acptr->name,
  407.                         acptr->user->username, GetHost(acptr));
  408.  
  409.                 if (MyConnect(sptr) && acptr != sptr)
  410.                         sendto_one(sptr,
  411.                                 ":%s %s %s :*** %s is no longer talking like Elmer",
  412.                                 me.name, IsWebTV(acptr) ? "PRIVMSG" : "NOTICE",
  413.                                 sptr->name, acptr->name);
  414.         }
  415.  
  416.         return 0;
  417. }
View raw paste Reply