unrealircd

- supernets unrealircd source & configuration
git clone git://git.acid.vegas/unrealircd.git
Log | Files | Refs | Archive | README | LICENSE

help.c (3287B)

      1 /*
      2  *   IRC - Internet Relay Chat, src/modules/out.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_help);
     26 
     27 #define MSG_HELP 	"HELP"	
     28 #define MSG_HELPOP	"HELPOP"
     29 
     30 ModuleHeader MOD_HEADER
     31   = {
     32 	"help",
     33 	"5.0",
     34 	"command /help", 
     35 	"UnrealIRCd Team",
     36 	"unrealircd-6",
     37     };
     38 
     39 MOD_INIT()
     40 {
     41 	CommandAdd(modinfo->handle, MSG_HELP, cmd_help, 1, CMD_USER);
     42 	CommandAdd(modinfo->handle, MSG_HELPOP, cmd_help, 1, CMD_USER);
     43 	MARK_AS_OFFICIAL_MODULE(modinfo);
     44 	return MOD_SUCCESS;
     45 }
     46 
     47 MOD_LOAD()
     48 {
     49 	return MOD_SUCCESS;
     50 }
     51 
     52 MOD_UNLOAD()
     53 {
     54 	return MOD_SUCCESS;
     55 }
     56 
     57 #define HDR(str) sendto_one(client, NULL, ":%s 290 %s :%s", me.name, client->name, str);
     58 #define SND(str) sendto_one(client, NULL, ":%s 292 %s :%s", me.name, client->name, str);
     59 
     60 ConfigItem_help *find_Help(const char *command)
     61 {
     62 	ConfigItem_help *help;
     63 
     64 	if (!command)
     65 	{
     66 		for (help = conf_help; help; help = help->next)
     67 		{
     68 			if (help->command == NULL)
     69 				return help;
     70 		}
     71 		return NULL;
     72 	}
     73 	for (help = conf_help; help; help = help->next)
     74 	{
     75 		if (help->command == NULL)
     76 			continue;
     77 		else if (!strcasecmp(command,help->command))
     78 			return help;
     79 	}
     80 	return NULL;
     81 }
     82 
     83 void parse_help(Client *client, const char *help)
     84 {
     85 	ConfigItem_help *helpitem;
     86 	MOTDLine *text;
     87 	if (BadPtr(help))
     88 	{
     89 		helpitem = find_Help(NULL);
     90 		if (!helpitem)
     91 			return;
     92 		SND(" -");
     93 		HDR("        ***** UnrealIRCd Help System *****");
     94 		SND(" -");
     95 		text = helpitem->text;
     96 		while (text) {
     97 			SND(text->line);
     98 			text = text->next;
     99 		}
    100 		SND(" -");
    101 		return;
    102 		
    103 	}
    104 	helpitem = find_Help(help);
    105 	if (!helpitem) {
    106 		SND(" -");
    107 		HDR("        ***** No Help Available *****");
    108 		SND(" -");
    109 		SND("   We're sorry, we don't have help available for the command you requested.");
    110 		SND(" -");
    111 		sendto_one(client, NULL, ":%s 292 %s : ***** Go to %s if you have any further questions *****",
    112 		    me.name, client->name, HELP_CHANNEL);
    113 		SND(" -");
    114 		return;
    115 	}
    116 	text = helpitem->text;
    117 	SND(" -");
    118 	sendto_one(client, NULL, ":%s 290 %s :***** %s *****",
    119 	    me.name, client->name, helpitem->command);
    120 	SND(" -");
    121 	while (text) {
    122 		SND(text->line);
    123 		text = text->next;
    124 	}
    125 	SND(" -");
    126 }
    127 
    128 /*
    129 ** cmd_help (help/write to +h currently online) -Donwulff
    130 **	parv[1] = optional message text
    131 */
    132 CMD_FUNC(cmd_help)
    133 {
    134 	const char *helptopic;
    135 
    136 	if (!MyUser(client))
    137 		return; /* never remote */
    138 
    139 	helptopic = parc > 1 ? parv[1] : NULL;
    140 	
    141 	if (helptopic && (*helptopic == '?'))
    142 		helptopic++;
    143 
    144 	parse_help(client, BadPtr(helptopic) ? NULL : helptopic);
    145 }