#include <fcntl.h>
#include <sys/stat.h>
#include "src/mod/module.h"
#include "src/tandem.h"
#include "notes.h"
#include "cmdsnote.c"
Go to the source code of this file.
Defines | |
#define | MODULE_NAME "notes" |
#define | MAKING_NOTES |
Functions | |
static void | fwd_display (int idx, struct user_entry *e) |
static int | num_notes (char *user) |
static void | notes_change (char *oldnick, char *newnick) |
static void | expire_notes () |
static int | notes_irc_setup (char *mod) |
static int | notes_server_setup (char *mod) |
static char * | notes_close () |
static int | notes_expmem () |
static void | notes_report (int idx, int details) |
char * | notes_start () |
char * | notes_start (Function *global_funcs) |
Variables | |
static int | maxnotes = 50 |
static int | note_life = 60 |
static char | notefile [121] |
static int | allow_fwd = 0 |
static int | notify_users = 0 |
static int | notify_onjoin = 1 |
static Function * | global = 0 |
static struct user_entry_type | USERENTRY_FWD |
static cmd_t | notes_nkch [] |
static cmd_t | notes_away [] |
static cmd_t | notes_chon [] |
static cmd_t | notes_msgs [] |
static tcl_ints | notes_ints [] |
static tcl_strings | notes_strings [] |
static tcl_cmds | notes_tcls [] |
static cmd_t | notes_load [] |
static Function | notes_table [] |
static void expire_notes | ( | ) | [static] |
Definition at line 159 of file notes.c.
References from, get_user_by_handle, LOG_MISC, movefile, newsplit, note_life, notefile, NOTES_EXPIRED, now, NULL, putlog, rmspace, time_t, userfile_perm, and userlist.
00160 { 00161 FILE *f, *g; 00162 char s[513], *to, *from, *ts, *s1; 00163 int tot = 0, lapse; 00164 00165 if (!notefile[0]) 00166 return; 00167 f = fopen(notefile, "r"); 00168 if (f == NULL) 00169 return; 00170 sprintf(s, "%s~new", notefile); 00171 g = fopen(s, "w"); 00172 if (g == NULL) { 00173 fclose(f); 00174 return; 00175 } 00176 chmod(s, userfile_perm); /* Use userfile permissions. */ 00177 while (!feof(f)) { 00178 fgets(s, 512, f); 00179 if (!feof(f)) { 00180 if (s[strlen(s) - 1] == '\n') 00181 s[strlen(s) - 1] = 0; 00182 rmspace(s); 00183 if ((s[0]) && (s[0] != '#') && (s[0] != ';')) { /* Not comment */ 00184 s1 = s; 00185 to = newsplit(&s1); 00186 from = newsplit(&s1); 00187 ts = newsplit(&s1); 00188 lapse = (now - (time_t) atoi(ts)) / 86400; 00189 if (lapse > note_life) 00190 tot++; 00191 else if (!get_user_by_handle(userlist, to)) 00192 tot++; 00193 else 00194 fprintf(g, "%s %s %s %s\n", to, from, ts, s1); 00195 } else 00196 fprintf(g, "%s\n", s); 00197 } 00198 } 00199 fclose(f); 00200 fclose(g); 00201 unlink(notefile); 00202 sprintf(s, "%s~new", notefile); 00203 movefile(s, notefile); 00204 if (tot > 0) 00205 putlog(LOG_MISC, "*", NOTES_EXPIRED, tot, tot == 1 ? "" : "s"); 00206 }
static void fwd_display | ( | int | idx, | |
struct user_entry * | e | |||
) | [static] |
Definition at line 71 of file notes.c.
References dcc, dprintf, NOTES_FORWARD_TO, user_entry::string, user_entry::u, user, and USER_BOTMAST.
00072 { 00073 if (dcc[idx].user && (dcc[idx].user->flags & USER_BOTMAST)) 00074 dprintf(idx, NOTES_FORWARD_TO, e->u.string); 00075 }
static void notes_change | ( | char * | oldnick, | |
char * | newnick | |||
) | [static] |
Definition at line 110 of file notes.c.
References egg_strcasecmp, LOG_MISC, movefile, newsplit, notefile, NOTES_SWITCHED_NOTES, NULL, putlog, rmspace, and userfile_perm.
00111 { 00112 FILE *f, *g; 00113 char s[513], *to, *s1; 00114 int tot = 0; 00115 00116 if (!egg_strcasecmp(oldnick, newnick)) 00117 return; 00118 if (!notefile[0]) 00119 return; 00120 f = fopen(notefile, "r"); 00121 if (f == NULL) 00122 return; 00123 sprintf(s, "%s~new", notefile); 00124 g = fopen(s, "w"); 00125 if (g == NULL) { 00126 fclose(f); 00127 return; 00128 } 00129 chmod(s, userfile_perm); /* Use userfile permissions. */ 00130 while (!feof(f)) { 00131 fgets(s, 512, f); 00132 if (!feof(f)) { 00133 if (s[strlen(s) - 1] == '\n') 00134 s[strlen(s) - 1] = 0; 00135 rmspace(s); 00136 if ((s[0]) && (s[0] != '#') && (s[0] != ';')) { /* Not comment */ 00137 s1 = s; 00138 to = newsplit(&s1); 00139 if (!egg_strcasecmp(to, oldnick)) { 00140 tot++; 00141 fprintf(g, "%s %s\n", newnick, s1); 00142 } else 00143 fprintf(g, "%s %s\n", to, s1); 00144 } else 00145 fprintf(g, "%s\n", s); 00146 } 00147 } 00148 fclose(f); 00149 fclose(g); 00150 unlink(notefile); 00151 sprintf(s, "%s~new", notefile); 00152 movefile(s, notefile); 00153 putlog(LOG_MISC, "*", NOTES_SWITCHED_NOTES, tot, tot == 1 ? "" : "s", 00154 oldnick, newnick); 00155 }
static char* notes_close | ( | ) | [static] |
Definition at line 1159 of file notes.c.
References del_entry_type, del_hook, del_lang_section, find_bind_table, H_away, H_chon, H_dcc, H_load, H_nkch, HOOK_HOURLY, HOOK_MATCH_NOTEREJ, match_note_ignore(), MODULE_NAME, module_undepend, notes_cmds, NULL, rem_builtins, rem_help_reference, rem_tcl_commands, rem_tcl_ints, and rem_tcl_strings.
01160 { 01161 p_tcl_bind_list H_temp; 01162 01163 rem_tcl_ints(notes_ints); 01164 rem_tcl_strings(notes_strings); 01165 rem_tcl_commands(notes_tcls); 01166 if ((H_temp = find_bind_table("msg"))) 01167 rem_builtins(H_temp, notes_msgs); 01168 if ((H_temp = find_bind_table("join"))) 01169 rem_builtins(H_temp, notes_join); 01170 rem_builtins(H_dcc, notes_cmds); 01171 rem_builtins(H_chon, notes_chon); 01172 rem_builtins(H_away, notes_away); 01173 rem_builtins(H_nkch, notes_nkch); 01174 rem_builtins(H_load, notes_load); 01175 rem_help_reference("notes.help"); 01176 del_hook(HOOK_MATCH_NOTEREJ, (Function) match_note_ignore); 01177 del_hook(HOOK_HOURLY, (Function) notes_hourly); 01178 del_entry_type(&USERENTRY_FWD); 01179 del_lang_section("notes"); 01180 module_undepend(MODULE_NAME); 01181 return NULL; 01182 }
static int notes_expmem | ( | ) | [static] |
Definition at line 1184 of file notes.c.
Referenced by notes_report().
static int notes_irc_setup | ( | char * | mod | ) | [static] |
Definition at line 1135 of file notes.c.
References add_builtins, and find_bind_table.
Referenced by notes_start().
01136 { 01137 p_tcl_bind_list H_temp; 01138 01139 if ((H_temp = find_bind_table("join"))) 01140 add_builtins(H_temp, notes_join); 01141 return 0; 01142 }
static void notes_report | ( | int | idx, | |
int | details | |||
) | [static] |
Definition at line 1189 of file notes.c.
References dprintf, notefile, and notes_expmem().
01190 { 01191 if (details) { 01192 int size = notes_expmem(); 01193 01194 if (notefile[0]) 01195 dprintf(idx, " Notes can be stored in: %s\n", notefile); 01196 else 01197 dprintf(idx, " Notes can not be stored.\n"); 01198 dprintf(idx, " Using %d byte%s of memory\n", size, 01199 (size != 1) ? "s" : ""); 01200 } 01201 }
static int notes_server_setup | ( | char * | mod | ) | [static] |
Definition at line 1144 of file notes.c.
References add_builtins, and find_bind_table.
Referenced by notes_start().
01145 { 01146 p_tcl_bind_list H_temp; 01147 01148 if ((H_temp = find_bind_table("msg"))) 01149 add_builtins(H_temp, notes_msgs); 01150 return 0; 01151 }
char* notes_start | ( | Function * | global_funcs | ) |
Definition at line 1213 of file notes.c.
References add_builtins, add_entry_type, add_help_reference, add_hook, add_lang_section, add_tcl_commands, add_tcl_ints, add_tcl_strings, global, H_away, H_chon, H_dcc, H_load, H_nkch, HOOK_HOURLY, HOOK_MATCH_NOTEREJ, match_note_ignore(), module_depend, MODULE_NAME, module_register, module_undepend, my_memcpy, notefile, notes_cmds, notes_irc_setup(), notes_server_setup(), NULL, and USERENTRY_INFO.
01214 { 01215 01216 global = global_funcs; 01217 01218 notefile[0] = 0; 01219 module_register(MODULE_NAME, notes_table, 2, 1); 01220 if (!module_depend(MODULE_NAME, "eggdrop", 106, 0)) { 01221 module_undepend(MODULE_NAME); 01222 return "This module requires Eggdrop 1.6.0 or later."; 01223 } 01224 add_hook(HOOK_HOURLY, (Function) notes_hourly); 01225 add_hook(HOOK_MATCH_NOTEREJ, (Function) match_note_ignore); 01226 add_tcl_ints(notes_ints); 01227 add_tcl_strings(notes_strings); 01228 add_tcl_commands(notes_tcls); 01229 add_builtins(H_dcc, notes_cmds); 01230 add_builtins(H_chon, notes_chon); 01231 add_builtins(H_away, notes_away); 01232 add_builtins(H_nkch, notes_nkch); 01233 add_builtins(H_load, notes_load); 01234 add_help_reference("notes.help"); 01235 add_lang_section("notes"); 01236 notes_server_setup(0); 01237 notes_irc_setup(0); 01238 my_memcpy(&USERENTRY_FWD, &USERENTRY_INFO, sizeof(void *) * 12); 01239 add_entry_type(&USERENTRY_FWD); 01240 return NULL; 01241 }
char* notes_start | ( | ) |
static int num_notes | ( | char * | user | ) | [static] |
Definition at line 79 of file notes.c.
References egg_strcasecmp, newsplit, notefile, NULL, and rmspace.
00080 { 00081 int tot = 0; 00082 FILE *f; 00083 char s[513], *to, *s1; 00084 00085 if (!notefile[0]) 00086 return 0; 00087 f = fopen(notefile, "r"); 00088 if (f == NULL) 00089 return 0; 00090 while (!feof(f)) { 00091 fgets(s, 512, f); 00092 if (!feof(f)) { 00093 if (s[strlen(s) - 1] == '\n') 00094 s[strlen(s) - 1] = 0; 00095 rmspace(s); 00096 if ((s[0]) && (s[0] != '#') && (s[0] != ';')) { /* Not comment */ 00097 s1 = s; 00098 to = newsplit(&s1); 00099 if (!egg_strcasecmp(to, user)) 00100 tot++; 00101 } 00102 } 00103 } 00104 fclose(f); 00105 return tot; 00106 }
int note_life = 60 [static] |
Definition at line 41 of file notes.c.
Referenced by expire_notes().
char notefile[121] [static] |
Definition at line 42 of file notes.c.
Referenced by expire_notes(), notes_change(), notes_report(), notes_start(), and num_notes().
cmd_t notes_away[] [static] |
cmd_t notes_chon[] [static] |
tcl_ints notes_ints[] [static] |
{ {"note-life", ¬e_life}, {"max-notes", &maxnotes}, {"allow-fwd", &allow_fwd}, {"notify-users", ¬ify_users}, {"notify-onjoin", ¬ify_onjoin}, { 0 , 0 } }
cmd_t notes_load[] [static] |
{ {"server", "", notes_server_setup, "notes:server"}, {"irc", "", notes_irc_setup, "notes:irc"}, { 0 , 0 , 0 , 0 } }
cmd_t notes_msgs[] [static] |
cmd_t notes_nkch[] [static] |
{ {"*", "", (IntFunc) notes_change, "notes"}, { 0 , 0 , 0 , 0 } }
tcl_strings notes_strings[] [static] |
Function notes_table[] [static] |
{ (Function) notes_start, (Function) notes_close, (Function) notes_expmem, (Function) notes_report, (Function) cmd_note, }
tcl_cmds notes_tcls[] [static] |
int notify_onjoin = 1 [static] |
int notify_users = 0 [static] |
struct user_entry_type USERENTRY_FWD [static] |
{ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , fwd_display, "FWD" }
Definition at line 51 of file notes.c.
Referenced by cmd_fwd().