ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_help.c
(Generate patch)

Comparing:
ircd-hybrid-8/modules/m_help.c (file contents), Revision 1243 by michael, Fri Sep 30 10:47:53 2011 UTC vs.
ircd-hybrid/trunk/modules/m_help.c (file contents), Revision 1997 by michael, Sat May 11 17:35:07 2013 UTC

# Line 27 | Line 27
27   #include "ircd.h"
28   #include "numeric.h"
29   #include "send.h"
30 < #include "s_conf.h"
31 < #include "s_log.h"
30 > #include "conf.h"
31   #include "parse.h"
32   #include "modules.h"
33   #include "irc_string.h"
34  
35   #define HELPLEN 400
36  
38 static void dohelp(struct Client *, const char *, char *);
39 static void sendhelpfile(struct Client *, const char *, const char *);
37  
41
42 /*
43 * m_help - HELP message handler
44 *      parv[0] = sender prefix
45 */
38   static void
39 < m_help(struct Client *client_p, struct Client *source_p,
48 <       int parc, char *parv[])
39 > sendhelpfile(struct Client *source_p, const char *path, const char *topic)
40   {
41 <  static time_t last_used = 0;
41 >  FILE *file;
42 >  char line[HELPLEN];
43  
44 <  /* HELP is always local */
53 <  if ((last_used + ConfigFileEntry.pace_wait_simple) > CurrentTime)
44 >  if ((file = fopen(path, "r")) == NULL)
45    {
46 <    /* safe enough to give this on a local connect only */
47 <    sendto_one(source_p,form_str(RPL_LOAD2HI),
57 <               me.name, source_p->name);
46 >    sendto_one(source_p, form_str(ERR_HELPNOTFOUND),
47 >               me.name, source_p->name, topic);
48      return;
49    }
50  
51 <  last_used = CurrentTime;
51 >  if (fgets(line, sizeof(line), file) == NULL)
52 >  {
53 >    sendto_one(source_p, form_str(ERR_HELPNOTFOUND),
54 >               me.name, source_p->name, topic);
55 >    return;
56 >  }
57  
58 <  dohelp(source_p, UHPATH, parv[1]);
59 < }
58 >  line[strlen(line) - 1] = '\0';
59 >  sendto_one(source_p, form_str(RPL_HELPSTART),
60 >             me.name, source_p->name, topic, line);
61  
62 < /*
63 < * mo_help - HELP message handler
64 < *      parv[0] = sender prefix
69 < */
70 < static void
71 < mo_help(struct Client *client_p, struct Client *source_p,
72 <        int parc, char *parv[])
73 < {
74 <  dohelp(source_p, HPATH, parv[1]);
75 < }
62 >  while (fgets(line, sizeof(line), file))
63 >  {
64 >    line[strlen(line) - 1] = '\0';
65  
66 < /*
67 < * mo_uhelp - HELP message handler
68 < * This is used so that opers can view the user help file without deopering
69 < *      parv[0] = sender prefix
70 < */
71 < static void
72 < mo_uhelp(struct Client *client_p, struct Client *source_p,
84 <            int parc, char *parv[])
85 < {
86 <  dohelp(source_p, UHPATH, parv[1]);
66 >    sendto_one(source_p, form_str(RPL_HELPTXT),
67 >               me.name, source_p->name, topic, line);
68 >  }
69 >
70 >  fclose(file);
71 >  sendto_one(source_p, form_str(RPL_ENDOFHELP),
72 >             me.name, source_p->name, topic);
73   }
74  
75   static void
76   dohelp(struct Client *source_p, const char *hpath, char *topic)
77   {
78    char h_index[] = "index";
79 <  char path[PATH_MAX + 1];
79 >  char path[HYB_PATH_MAX + 1];
80    struct stat sb;
81 <  int i;
81 >  unsigned int i;
82  
83 <  if (topic != NULL)
84 <  {
99 <    if (*topic == '\0')
100 <      topic = h_index;
101 <    else
102 <    {
103 <      /* convert to lower case */
104 <      for (i = 0; topic[i] != '\0'; ++i)
105 <        topic[i] = ToLower(topic[i]);
106 <    }
107 <  }
83 >  if (EmptyString(topic))
84 >    topic = h_index;
85    else
86 <    topic = h_index;    /* list available help topics */
86 >    for (i = 0; topic[i] != '\0'; ++i)
87 >      topic[i] = ToLower(topic[i]);
88  
89    if (strpbrk(topic, "/\\"))
90    {
# Line 115 | Line 93 | dohelp(struct Client *source_p, const ch
93      return;
94    }
95  
96 <  if (strlen(hpath) + strlen(topic) + 1 > PATH_MAX)
96 >  if (strlen(hpath) + strlen(topic) + 1 > HYB_PATH_MAX)
97    {
98      sendto_one(source_p, form_str(ERR_HELPNOTFOUND),
99                 me.name, source_p->name, topic);
# Line 141 | Line 119 | dohelp(struct Client *source_p, const ch
119    sendhelpfile(source_p, path, topic);
120   }
121  
122 < static void
123 < sendhelpfile(struct Client *source_p, const char *path, const char *topic)
122 > /*
123 > * m_help - HELP message handler
124 > *      parv[0] = sender prefix
125 > */
126 > static void
127 > m_help(struct Client *client_p, struct Client *source_p,
128 >       int parc, char *parv[])
129   {
130 <  FBFILE *file;
148 <  char line[HELPLEN];
149 <  char started = 0;
150 <  int type;
130 >  static time_t last_used = 0;
131  
132 <  if ((file = fbopen(path, "r")) == NULL)
132 >  /* HELP is always local */
133 >  if ((last_used + ConfigFileEntry.pace_wait_simple) > CurrentTime)
134    {
135 <    sendto_one(source_p, form_str(ERR_HELPNOTFOUND),
136 <               me.name, source_p->name, topic);
135 >    /* safe enough to give this on a local connect only */
136 >    sendto_one(source_p,form_str(RPL_LOAD2HI),
137 >               me.name, source_p->name);
138      return;
139    }
140  
141 <  if (fbgets(line, sizeof(line), file) == NULL)
160 <  {
161 <    sendto_one(source_p, form_str(ERR_HELPNOTFOUND),
162 <               me.name, source_p->name, topic);
163 <    return;
164 <  }
141 >  last_used = CurrentTime;
142  
143 <  else if (line[0] != '#')
144 <  {
168 <    line[strlen(line) - 1] = '\0';        
169 <    sendto_one(source_p, form_str(RPL_HELPSTART),
170 <             me.name, source_p->name, topic, line);
171 <    started = 1;
172 <  }
143 >  dohelp(source_p, UHPATH, parv[1]);
144 > }
145  
146 <  while (fbgets(line, sizeof(line), file))
147 <  {
148 <    line[strlen(line) - 1] = '\0';
149 <    if (line[0] != '#')
150 <    {
151 <      if (!started)
152 <      {
153 <        type = RPL_HELPSTART;
154 <        started = 1;
155 <      }
156 <      else
157 <        type = RPL_HELPTXT;
158 <      
159 <      sendto_one(source_p, form_str(RPL_HELPTXT),
160 <                 me.name, source_p->name, topic, line);
161 <    }
162 <  }
163 <
164 <  fbclose(file);
165 <  sendto_one(source_p, form_str(RPL_HELPTXT),
166 <             me.name, source_p->name, topic, "");
195 <  sendto_one(source_p, form_str(RPL_ENDOFHELP),
196 <             me.name, source_p->name, topic);
146 > /*
147 > * mo_help - HELP message handler
148 > *      parv[0] = sender prefix
149 > */
150 > static void
151 > mo_help(struct Client *client_p, struct Client *source_p,
152 >        int parc, char *parv[])
153 > {
154 >  dohelp(source_p, HPATH, parv[1]);
155 > }
156 >
157 > /*
158 > * mo_uhelp - HELP message handler
159 > * This is used so that opers can view the user help file without deopering
160 > *      parv[0] = sender prefix
161 > */
162 > static void
163 > mo_uhelp(struct Client *client_p, struct Client *source_p,
164 >         int parc, char *parv[])
165 > {
166 >  dohelp(source_p, UHPATH, parv[1]);
167   }
168  
169   static struct Message help_msgtab = {
170 <  "HELP", 0, 0, 0, 0, MFLG_SLOW, 0,
170 >  "HELP", 0, 0, 0, MAXPARA, MFLG_SLOW, 0,
171    {m_unregistered, m_help, m_ignore, m_ignore, mo_help, m_ignore}
172   };
173  
174   static struct Message uhelp_msgtab = {
175 <  "UHELP", 0, 0, 0, 0, MFLG_SLOW, 0,
175 >  "UHELP", 0, 0, 0, MAXPARA, MFLG_SLOW, 0,
176    {m_unregistered, m_help, m_ignore, m_ignore, mo_uhelp, m_ignore}
177   };
178  

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)