Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
BitchX
GitHub Repository: BitchX/BitchX1.3
Path: blob/master/dll/nap/napother.c
1072 views
1
#include "irc.h"
2
#include "struct.h"
3
#include "ircaux.h"
4
#include "misc.h"
5
#include "output.h"
6
#include "module.h"
7
#include "list.h"
8
#include "vars.h"
9
#include "modval.h"
10
#include "napster.h"
11
12
static IgnoreStruct *ignores = NULL;
13
14
int check_nignore(char *nick)
15
{
16
if (ignores && find_in_list((List **)&ignores, nick, 0))
17
return 1;
18
return 0;
19
}
20
21
void ignore_user(IrcCommandDll *intp, char *command, char *args, char *subargs, char *help)
22
{
23
IgnoreStruct *new;
24
char *nick;
25
if (command && !my_stricmp(command, "nignore"))
26
{
27
if (!args || !*args)
28
{
29
char buffer[NAP_BUFFER_SIZE+1];
30
int cols = get_dllint_var("napster_names_columns") ?
31
get_dllint_var("napster_names_columns") :
32
get_int_var(NAMES_COLUMNS_VAR);
33
int count = 0;
34
if (!cols)
35
cols = 1;
36
*buffer = 0;
37
nap_say("%s", cparse("Ignore List:", NULL));
38
for (new = ignores; new; new = new->next)
39
{
40
strcat(buffer, cparse(get_dllstring_var("napster_names_nickcolor"), "%s %d %d", new->nick, 0, 0));
41
strcat(buffer, space);
42
if (count++ >= (cols - 1))
43
{
44
nap_put("%s", buffer);
45
*buffer = 0;
46
count = 0;
47
}
48
}
49
if (*buffer)
50
nap_put("%s", buffer);
51
return;
52
}
53
while ((nick = next_arg(args, &args)))
54
{
55
if (*nick == '-')
56
{
57
nick++;
58
if (!*nick)
59
continue;
60
if ((new = (IgnoreStruct *)remove_from_list((List **)&ignores, nick)))
61
{
62
new_free(&new->nick);
63
new_free(&new);
64
nap_say("Removed %s from ignore list", nick);
65
}
66
}
67
else
68
{
69
new = new_malloc(sizeof(IgnoreStruct));
70
new->nick = m_strdup(nick);
71
new->start = time(NULL);
72
new->next = ignores;
73
ignores = new;
74
nap_say("Added %s to ignore list", new->nick);
75
}
76
}
77
return;
78
}
79
}
80
81
82
void nap_echo(IrcCommandDll *intp, char *command, char *args, char *subargs, char *help)
83
{
84
int (*func)(char *, ...);
85
if (!args || !*args)
86
return;
87
88
func = nap_say;
89
while (args && (*args == '-'))
90
{
91
args++;
92
if (!*args)
93
break;
94
if (tolower(*args) == 'x')
95
{
96
func = nap_put;
97
next_arg(args, &args);
98
}
99
else
100
{
101
args--;
102
break;
103
}
104
}
105
if (args)
106
(func)("%s", args);
107
}
108
109
extern GetFile *napster_sendqueue;
110
111
int count_download(char *nick)
112
{
113
int count = 0;
114
GetFile *gf;
115
for (gf = napster_sendqueue; gf; gf = gf->next)
116
if (!my_stricmp(gf->nick, nick))
117
count++;
118
return count;
119
}
120
121
void compute_soundex (char *d, int dsize, const char *s)
122
{
123
int n = 0;
124
125
/* if it's not big enough to hold one soundex word, quit without
126
doing anything */
127
if (dsize < 4)
128
{
129
if (dsize > 0)
130
*d = 0;
131
return;
132
}
133
dsize--; /* save room for the terminatin nul (\0) */
134
135
while (*s && !isalpha(*s))
136
s++;
137
if (!*s)
138
{
139
*d = 0;
140
return;
141
}
142
143
*d++ = toupper (*s);
144
dsize--;
145
s++;
146
147
while (*s && dsize > 0)
148
{
149
switch (tolower (*s))
150
{
151
case 'b':
152
case 'p':
153
case 'f':
154
case 'v':
155
if (n < 3)
156
{
157
*d++ = '1';
158
dsize--;
159
n++;
160
}
161
break;
162
case 'c':
163
case 's':
164
case 'k':
165
case 'g':
166
case 'j':
167
case 'q':
168
case 'x':
169
case 'z':
170
if (n < 3)
171
{
172
*d++ = '2';
173
dsize--;
174
n++;
175
}
176
break;
177
case 'd':
178
case 't':
179
if (n < 3)
180
{
181
*d++ = '3';
182
dsize--;
183
n++;
184
}
185
break;
186
case 'l':
187
if (n < 3)
188
{
189
*d++ = '4';
190
dsize--;
191
n++;
192
}
193
break;
194
case 'm':
195
case 'n':
196
if (n < 3)
197
{
198
*d++ = '5';
199
dsize--;
200
n++;
201
}
202
break;
203
case 'r':
204
if (n < 3)
205
{
206
*d++ = '6';
207
dsize--;
208
n++;
209
}
210
break;
211
default:
212
if (!isalpha (*s))
213
{
214
/* pad short words with 0's */
215
while (n < 3 && dsize > 0)
216
{
217
*d++ = '0';
218
dsize--;
219
n++;
220
}
221
n = 0; /* reset */
222
/* skip forward until we find the next word */
223
s++;
224
while (*s && !isalpha (*s))
225
s++;
226
if (!*s)
227
{
228
*d = 0;
229
return;
230
}
231
if (dsize > 0)
232
{
233
*d++ = ',';
234
dsize--;
235
if (dsize > 0)
236
{
237
*d++ = toupper (*s);
238
dsize--;
239
}
240
}
241
}
242
/* else it's a vowel and we ignore it */
243
break;
244
}
245
/* skip over duplicate letters */
246
while (*(s+1) == *s)
247
s++;
248
249
/* next letter */
250
s++;
251
}
252
/* pad short words with 0's */
253
while (n < 3 && dsize > 0)
254
{
255
*d++ = '0';
256
dsize--;
257
n++;
258
}
259
*d = 0;
260
}
261
262
263