6 #include "helpmod_entries.h"
7 #include "helpmod_user.h"
8 #include "helpmod_alias.h"
10 #include "../localuser/localuser.h"
11 #include "../localuser/localuserchannel.h"
12 #include "../control/control.h"
13 #include "../channel/channel.h"
14 #include "../nick/nick.h"
15 #include "../core/config.h"
16 #include "../core/schedule.h"
18 #define HELPMOD_VERSION "1.05"
20 helpmod_entry helpmod_base
;
21 helpmod_user helpmod_users
;
24 char helpmod_db
[128] = "helpmod/default";
27 void helpreply(nick
*target
, char *message
, ... ) {
31 if (helpmodnick
==NULL
) {
36 vsnprintf(buf
,512,message
,va
);
39 sendmessagetouser(helpmodnick
,target
,"%s",buf
);
42 void helpmod_send_help(nick
* target
, helpmod_user hlp_user
)
46 for (i
=0;i
<hlp_user
->state
->text_lines
;i
++)
47 helpreply(target
, "%s", hlp_user
->state
->text
[i
]->content
);
48 for (i
=0;i
<hlp_user
->state
->option_count
;i
++)
49 helpreply(target
, "%d) %s", i
+1, hlp_user
->state
->options
[i
]->description
->content
);
50 if (!hlp_user
->state
->option_count
)
52 helpreply(target
, "This concludes the help for this topic, if you want to, you can restart the service with the 'help' command, or return to the previous entry by selecting 0");
56 void helpmod_cmd_help (nick
* sender
, char* arg
)
58 helpmod_user hlp_user
= helpmod_get_user(sender
->numeric
);
64 helpreply(sender
, "The help service is not available at this time, please try again later");
70 hlp_user
->state
= helpmod_base
;
71 helpmod_send_help(sender
, hlp_user
);
75 if (!sscanf(arg
, "%d", &hlp_target
))
78 for(i
=0;i
<strlen(arg
);i
++)
84 tmp
= helpmod_get_alias(arg
);
86 helpreply(sender
, "Invalid value. Either use 'help' to restart or give an integer as a valid selection");
89 hlp_user
->state
= tmp
;
90 helpmod_send_help(sender
, hlp_user
);
96 if (!helpmod_valid_selection(hlp_user
->state
, hlp_target
))
98 if (!hlp_user
->state
->option_count
)
99 helpreply(sender
, "There are no more options to choose from, you can restart the service by giving the 'help' command or select 0 to return to previous entry");
100 else if (!hlp_user
->state
->parent
)
101 helpreply(sender
, "Bad selection, please enter your selection as an integer from %d to %d", 1, hlp_user
->state
->option_count
);
103 helpreply(sender
, "Bad selection, please enter your selection as an integer from %d to %d, selecting 0 will take you to the previous entry", 1, hlp_user
->state
->option_count
);
107 hlp_user
->state
= helpmod_make_selection(hlp_user
->state
, hlp_target
);
108 helpmod_send_help(sender
, hlp_user
);
113 void helpmod_cmd_stats (nick
*sender
)
115 helpreply(sender
, "Amount of users: %9ld", helpmod_user_count());
116 helpreply(sender
, " entries: %9ld", helpmod_entry_count(helpmod_base
));
117 helpreply(sender
, " aliases: %9ld", helpmod_alias_count(aliases
));
118 helpreply(sender
, " service use: %9ld", helpmod_usage
);
119 helpreply(sender
, "Using database: %s", helpmod_db
);
123 void helpmod_cmd_load (void *sender
, char* arg
)
126 char buf
[128] = "helpmod/default";
129 helpreply(sender
, "Warning: No config specified, using default");
132 if (strlen(arg
) >= 100)
135 sprintf(buf
, "helpmod/%s", arg
);
138 if (!(tmp_file
= fopen(buf
, "rt")))
140 helpreply(sender
, "File %s not found", buf
);
146 helpmod_clear_aliases(&aliases
);
147 helpmod_clear_all_entries();
148 helpmod_init_entry(&helpmod_base
);
149 helpmod_clear_users();
150 helpmod_load_entries(buf
);
151 strcpy(helpmod_db
, buf
);
152 helpreply(sender
, "New config loaded and system reset");
155 void helpmod_cmd_showcommands (nick
*sender
)
157 helpreply(sender
,"HelpMod %s Commands", HELPMOD_VERSION
);
158 helpreply(sender
,"help Primary command, gives automated help to lusers");
159 helpreply(sender
,"stats Shows some service statistics");
160 helpreply(sender
,"aliases Gives a simple list of aliases currently in use");
161 helpreply(sender
,"load Loads a new help config");
165 void helpmod_cmd_aliases (nick
*sender
)
169 void helpmod_list_aliases(alias_tree node
)
173 helpreply(sender
, buf
);
178 sprintf(buf
+i
,"%.200s ",node
->name
->content
);
179 i
+=(1+strlen(node
->name
->content
));
180 helpmod_list_aliases(node
->left
);
181 helpmod_list_aliases(node
->right
);
183 helpmod_list_aliases(aliases
);
185 helpreply(sender
, buf
);
188 void helpmodmessagehandler(nick
*sender
, int messagetype
, void **args
)
191 char* second_arg
= NULL
;
195 if (messagetype
!= LU_PRIVMSG
)
198 target
= getnickbynick((char*)args
[0]);
201 for (i
=0;i
<strlen(args
[1]);i
++)
202 if (((char*)args
[1])[i
] == ' ')
204 second_arg
= args
[1] + i
+ 1;
205 ((char*)args
[1])[i
] = 0x00;
208 if (!strcmp(first_arg
, "help"))
210 helpmod_cmd_help(target
, second_arg
);
213 if (sscanf(first_arg
, "%d", &useless_var
))
215 helpmod_cmd_help(target
, first_arg
);
220 helpreply(target
, "To access the help service, just type 'help'");
223 if (!strcmp(first_arg
, "stats"))
224 helpmod_cmd_stats(target
);
225 else if (!strcmp(first_arg
, "load"))
226 helpmod_cmd_load(target
, second_arg
);
227 else if (!strcmp(first_arg
,"aliases"))
228 helpmod_cmd_aliases(target
);
229 else if (!strcmp(first_arg
, "showcommands"))
230 helpmod_cmd_showcommands(target
);
231 else if (!strcmp(first_arg
, "help"))
232 helpmod_cmd_help(target
, first_arg
);
234 helpreply(target
, "Unknown command, see 'showcommands'");
237 void helpconnect(void) {
239 /* helpmod offers no channel features, it's merely a decoration */
240 char *helpmod_chans
[] = {"#twilightzone", "#help", "#feds", "#qnet.help"};
241 int i
,helpmod_chan_count
= 4;
243 helpmodnick
=registerlocaluser("H",
246 "NewServ HelpMod, /msg H help",
248 UMODE_DEAF
|UMODE_OPER
|UMODE_ACCOUNT
,&helpmodmessagehandler
);
250 helpmod_init_entry(&helpmod_base
);
251 helpmod_init_users();
252 helpmod_load_entries(NULL
);
254 for (i
=0;i
< helpmod_chan_count
;i
++)
256 cp
= findchannel(helpmod_chans
[i
]);
258 localcreatechannel(helpmodnick
, helpmod_chans
[i
]);
261 localjoinchannel(helpmodnick
, cp
);
262 localgetops(helpmodnick
, cp
);
273 scheduleoneshot(time(NULL
)+1,(ScheduleCallback
)&helpconnect
,NULL
);
274 schedulerecurring(time(NULL
)+1,0,300,(ScheduleCallback
)&helpmod_clear_inactives
,NULL
);
279 deregisterlocaluser(helpmodnick
, "Module unloaded");
280 deleteallschedules((ScheduleCallback
)&helpconnect
);
281 helpmod_clear_aliases(&aliases
);
282 helpmod_clear_all_entries();
283 helpmod_clear_users();