Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
BitchX
GitHub Repository: BitchX/BitchX1.3
Path: blob/master/dll/aim/aim.c
1072 views
1
/*
2
* AOL Instant Messanger Module for BitchX
3
*
4
* By Nadeem Riaz ([email protected])
5
*
6
* aim.c
7
*
8
* Window, Init, Cleanup, and Version Routines
9
*/
10
11
12
#include <irc.h>
13
#include <struct.h>
14
#include <hook.h>
15
#include <ircaux.h>
16
#include <output.h>
17
#include <lastlog.h>
18
#include <status.h>
19
#include <vars.h>
20
#include <window.h>
21
#include <input.h>
22
#include <module.h>
23
#define INIT_MODULE
24
#include <modval.h>
25
26
#include <string.h>
27
#include <stdlib.h>
28
#include <stdio.h>
29
#include "toc.h"
30
#include "aim.h"
31
32
33
char *name = "aim";
34
char *timer_id;
35
36
#ifdef BITCHX_PATCH
37
struct tab_key_struct tks;
38
39
int do_aim_tabkey_overwrite(int x, char *p, int *c, char **s) {
40
if ( get_dllint_var("aim_window") && current_window == get_window_by_name("AIM") )
41
return 1;
42
else
43
return 0;
44
}
45
46
char * get_next_buddy_complete() {
47
char *bud = NULL;
48
int a;
49
LLE t;
50
/*
51
* This is about as badly written as humany possible
52
* ^- some would say its even worse than that
53
*/
54
while ( 1 ) {
55
if ( tks.list == 1 ) {
56
/* We traverse the buddy list forwards */
57
LL mems;
58
if ( tks.pos > groups->items ) {
59
break;
60
}
61
t = groups->head;
62
for (a=0; a < tks.pos; a++)
63
t = t->next;
64
mems = ((struct group *)t->data)->members;
65
if ( tks.subpos == -1 )
66
tks.subpos = 1;
67
if ( tks.subpos > mems->items ) {
68
tks.pos++;
69
continue;
70
}
71
t = mems->head;
72
for (a=0; a<tks.subpos; a++)
73
t = t->next;
74
tks.subpos++;
75
bud = t->key;
76
break;
77
} else {
78
/* Traverse the msd'd them list in reverse (last msg'd = first completed) */
79
t = msgdthem->head;
80
tks.list = 0;
81
/* If we haven't msg'd anyone yet, go through the buddy list */
82
if ( msgdthem == NULL || msgdthem->items == 0) {
83
debug_printf("msgdthem == null or has no items");
84
tks.list = 1;
85
tks.pos = 1;
86
tks.subpos = -1;
87
continue;
88
}
89
/* Initilization */
90
if ( tks.pos == -1 ) {
91
debug_printf("set tks.pos to %d",msgdthem->items);
92
tks.pos = msgdthem->items;
93
}
94
for (a=0; a < tks.pos; a++) {
95
t = t->next;
96
}
97
bud = t->key;
98
debug_printf("tks.pos == %d name = %s",tks.pos,t->key);
99
tks.pos--;
100
/* No more msg'd them nicks, next call we switch over to buddy list */
101
if ( tks.pos == 0 ) {
102
tks.list = 1;
103
tks.pos = 1;
104
tks.subpos = -1;
105
}
106
break;
107
}
108
}
109
return bud;
110
}
111
112
char * aim_tabkey_overwrite(int x, char *p, int *c, char **s) {
113
char *z = NULL;
114
char *bud = NULL;
115
char *t;
116
(*c) = 0;
117
118
if ( state != STATE_ONLINE )
119
return NULL;
120
121
bud = get_next_buddy_complete();
122
123
if ( bud == NULL )
124
return NULL;
125
debug_printf("bud = %s",bud);
126
t = (char *) malloc(strlen(bud)+50);
127
sprintf(t,"/amsg %s ",bud);
128
m_s3cat(&z,space,t);
129
(*c) = 1;
130
return z;
131
}
132
133
char * amsg_complete_func(int x, char *p, int *c, char **s) {
134
/* statusprintf("x = %d",x); */
135
char *z = NULL;
136
char *inp;
137
int wc;
138
LLE g,m;
139
LL l;
140
(*c) = 0;
141
if ( state != STATE_ONLINE )
142
return NULL;
143
144
145
l = CreateLL();
146
147
debug_printf("possible = '%s' len = %d",p,strlen(p));
148
inp = m_strdup( get_input() ? get_input() : empty_string);
149
wc = word_count(inp);
150
debug_printf("input = %s wc = %d",inp,wc);
151
new_free(&inp);
152
if ( wc > 2 )
153
return NULL;
154
155
/* First go through people we've msg'd already */
156
for ( TLL(msgdus,g) ) {
157
if ( p && my_strnicmp(p, g->key, strlen(p)) )
158
continue;
159
AddToLL(l,g->key,NULL);
160
}
161
162
/* Then people who msg'd us */
163
for ( TLL(msgdthem,g) ) {
164
if ( p && my_strnicmp(p, g->key, strlen(p)) )
165
continue;
166
if ( ! FindInLL(l,g->key) )
167
AddToLL(l,g->key,NULL);
168
}
169
170
/* And last, the Buddy */
171
for ( TLL(groups,g) ) {
172
struct group *grp = (struct group *)g->data;
173
for ( TLL(grp->members,m) ) {
174
struct buddy *bud = (struct buddy *)m->data;
175
if ( p && my_strnicmp(p, bud->name, strlen(p)) )
176
continue;
177
if ( ! FindInLL(l,bud->name) )
178
AddToLL(l,bud->name,NULL);
179
}
180
}
181
182
if ( l->items == 1 && ! strcasecmp(l->head->next->key,p) ) {
183
char *bud = NULL;
184
(*c) = 1;
185
bud = get_next_buddy_complete();
186
debug_printf("We are going to go to get_next_buddy_comp!");
187
if ( bud )
188
m_s3cat(&z,space,bud);
189
else
190
debug_printf("set z to null because bud is null");
191
} else {
192
for( TLL(l,g) ) {
193
(*c)++;
194
debug_printf("adding %s",g->key);
195
m_s3cat(&z,space,g->key);
196
}
197
}
198
199
debug_printf("in test func!, p = %s",p);
200
FreeLL(l);
201
return (z);
202
}
203
#endif /* BITCHX_PATCH */
204
205
/* Window code, straight from nap module by panasync */
206
207
void update_aim_window(Window *tmp) {
208
char statbuff[1024];
209
char st[1024];
210
char *t;
211
char s[80];
212
int numbuds_online, numbuds_total;
213
214
if ( state == STATE_ONLINE ) {
215
t= ctime(&login_time);
216
t[strlen(t)-6] = '\0'; /* remove \n, year, & space -- NOT Y10K READY !@! */
217
sprintf(st,"Online since: %s", t);
218
} else
219
strcpy(st,"Offline");
220
221
if ( is_idle ) {
222
strcpy(s,"(Idle)");
223
} else if ( is_away ) {
224
strcpy(s,"(Away)");
225
} else {
226
strcpy(s,"");
227
}
228
229
/* Find the number of buddies online */
230
numbuds_online = numbuds_total = 0;
231
if ( groups != NULL ) {
232
LLE g,b;
233
struct group *grp;
234
struct buddy *bud;
235
for ( TLL(groups,g) ) {
236
grp = (struct group *) g->data;
237
numbuds_total += grp->members->items;
238
for( TLL(grp->members,b) ) {
239
bud = (struct buddy *) b->data;
240
if ( bud->present)
241
numbuds_online++;
242
}
243
}
244
}
245
sprintf(statbuff, " Buddies: %d/%d Lag: %d Evil: %d %s %%>%s ", numbuds_online, numbuds_total,(lag_ms / 1000000),my_evil,s,st);
246
set_wset_string_var(tmp->wset, STATUS_FORMAT1_WSET, statbuff);
247
248
sprintf(statbuff, " %%>%s ", st);
249
set_wset_string_var(tmp->wset, STATUS_FORMAT2_WSET, statbuff);
250
251
update_window_status(tmp, 1);
252
}
253
254
int build_aim_status(Window *tmp)
255
{
256
Window *tmp1;
257
if (!(tmp1 = tmp))
258
tmp1 = get_window_by_name("AIM");
259
if (tmp1)
260
{
261
update_aim_window(tmp1);
262
build_status(tmp1, NULL, 0);
263
update_all_windows();
264
return 1;
265
}
266
return 0;
267
}
268
269
270
void toggle_aimwin_hide (Window *win, char *unused, int onoff) {
271
Window *tmp;
272
if ((tmp = get_window_by_name("AIM")))
273
{
274
if (onoff)
275
{
276
if (tmp->screen)
277
hide_window(tmp);
278
build_aim_status(tmp);
279
update_all_windows();
280
cursor_to_input();
281
}
282
else
283
{
284
show_window(tmp);
285
resize_window(2, tmp, 6);
286
build_aim_status(tmp);
287
update_all_windows();
288
cursor_to_input();
289
}
290
}
291
}
292
293
void toggle_aimwin (Window *win, char *unused, int onoff){
294
Window *tmp;
295
if (onoff)
296
{
297
if ((tmp = get_window_by_name("AIM")))
298
return;
299
if ((tmp = new_window(win->screen)))
300
{
301
resize_window(2, tmp, 6);
302
tmp->name = m_strdup("AIM");
303
#undef query_cmd
304
tmp->query_cmd = m_strdup("asay");
305
tmp->double_status = 0;
306
tmp->absolute_size = 1;
307
tmp->update_status = update_aim_window;
308
tmp->server = -2;
309
set_wset_string_var(tmp->wset, STATUS_FORMAT1_WSET, NULL);
310
set_wset_string_var(tmp->wset, STATUS_FORMAT2_WSET, NULL);
311
set_wset_string_var(tmp->wset, STATUS_FORMAT3_WSET, NULL);
312
set_wset_string_var(tmp->wset, STATUS_FORMAT_WSET, NULL);
313
314
if (get_dllint_var("aim_window_hidden"))
315
hide_window(tmp);
316
else
317
set_screens_current_window(tmp->screen, tmp);
318
build_aim_status(tmp);
319
update_all_windows();
320
cursor_to_input();
321
}
322
}
323
else
324
{
325
if ((tmp = get_window_by_name("AIM")))
326
{
327
if (tmp == target_window)
328
target_window = NULL;
329
delete_window(tmp);
330
update_all_windows();
331
cursor_to_input();
332
333
}
334
}
335
}
336
337
338
char *Aim_Version(IrcCommandDll *intp) {
339
return AIM_VERSION;
340
}
341
342
int Aim_Cleanup(IrcCommandDll **interp, Function_ptr *global_table) {
343
if ( state == STATE_ONLINE )
344
toc_signoff();
345
#ifdef BITCHX_PATCH
346
overwrite_tabkey_comp(NULL,NULL);
347
debug_printf("Didn't remove completions, thats probably gonna cause problems");
348
#endif
349
remove_module_proc(VAR_PROC, name, NULL, NULL);
350
remove_module_proc(COMMAND_PROC,name,NULL,NULL);
351
remove_module_proc(ALIAS_PROC,name,NULL,NULL);
352
return 3;
353
}
354
355
356
int Aim_Init(IrcCommandDll **interp, Function_ptr *global_table) {
357
char buffer[BIG_BUFFER_SIZE+1];
358
char *p;
359
initialize_module(name);
360
361
add_module_proc(VAR_PROC, name, "aim_user", NULL, STR_TYPE_VAR, 0, NULL, NULL);
362
add_module_proc(VAR_PROC, name, "aim_pass", NULL, STR_TYPE_VAR, 0, NULL, NULL);
363
add_module_proc(VAR_PROC, name, "aim_prompt", (char *)convert_output_format("%K[%YAIM%K]%n ", NULL, NULL), STR_TYPE_VAR, 0, NULL, NULL);
364
add_module_proc(VAR_PROC, name, "aim_permdeny_mode", NULL, INT_TYPE_VAR, 1, NULL, NULL);
365
add_module_proc(VAR_PROC, name, "aim_toc_host", TOC_HOST, STR_TYPE_VAR, 0, NULL, NULL);
366
add_module_proc(VAR_PROC, name, "aim_toc_port", NULL, INT_TYPE_VAR, TOC_PORT, NULL, NULL);
367
add_module_proc(VAR_PROC, name, "aim_auth_host", AUTH_HOST, STR_TYPE_VAR, 0, NULL, NULL);
368
add_module_proc(VAR_PROC, name, "aim_auth_port", NULL, INT_TYPE_VAR, AUTH_PORT, NULL, NULL);
369
add_module_proc(VAR_PROC, name, "aim_permdeny_mode", NULL, INT_TYPE_VAR, 1, NULL, NULL);
370
add_module_proc(VAR_PROC, name, "aim_minutes_to_idle", NULL, INT_TYPE_VAR, time_to_idle/60, achange_idle, NULL);
371
add_module_proc(VAR_PROC, name, "aim_window", NULL, BOOL_TYPE_VAR, 0, toggle_aimwin, NULL);
372
add_module_proc(VAR_PROC, name, "aim_window_hidden", NULL, BOOL_TYPE_VAR, 0, toggle_aimwin_hide, NULL);
373
374
375
add_module_proc(COMMAND_PROC, name, "amsg", "amsg", 0, 0, amsg, "<screen name|buddy chat> <message> instant messages");
376
add_module_proc(COMMAND_PROC, name, "asignon", "asignon", 0, 0, asignon, "logs into aol instant messanger");
377
add_module_proc(COMMAND_PROC, name, "asignoff", "asignoff", 0, 0, asignoff, "logs off of aol instant messanger");
378
add_module_proc(COMMAND_PROC, name, "abl", "abl", 0, 0, abl, "<command> <args...> Modify your buddy list\n/abl show -- Shows buddy list\n/abl add [group] <buddy> -- Adds buddy to group in buddy list\n/abl del <buddy> Removes buddy from buddy llist\n/abl addg <group> Create group group\n/abl delg <group> <newgroup|1> delete group group");
379
add_module_proc(COMMAND_PROC, name, "apd", "apd", 0, 0, apd, "<command> <args...> Modify your permit/deny lists\n/apd show -- Shows your permit & deny list\n/apd mode <permitall|denyall|permitsome|denysome> -- change your mode\n/apd addp <sn> -- Adds sn to your permit list\n/apd delp <sn> -- Removes sn from your permit list\n/apd addd <sn> -- Adds <sn> to your deny list\n/apd deld <sn> -- Removes sn from your deny list");
380
add_module_proc(COMMAND_PROC, name, "adir", "adir", 0, 0, adir, "<command> <args...> Use the user directory\n/adir get <sn> Get sn's dir info\n/adir search -- Not implemented yet\n/adir set <first name> <middle name> <last name> <maiden name> <city> <state> <country> <email> <allow web searches? 1|0>");
381
add_module_proc(COMMAND_PROC, name, "awarn", "awarn", 0, 0, awarn, "<aim screen name> [anon] warns user");
382
add_module_proc(COMMAND_PROC, name, "awhois", "awhois", 0, 0, awhois, "<screen name> displays info on sn (sn has to be in buddy list)");
383
add_module_proc(COMMAND_PROC, name, "asave", "asave", 0, 0, asave, "Saves AIM settings");
384
add_module_proc(COMMAND_PROC, name, "asay", "asay", 0, 0, achat, "<message> send a message to the current buddy chat");
385
add_module_proc(COMMAND_PROC, name, "apart", "apart", 0, 0, achat, "<buddy chat> leave buddy chat");
386
add_module_proc(COMMAND_PROC, name, "ajoin", "ajoin", 0, 0, achat, "<buddy chat> join buddy chat (first searches invite list, if its in it then joins that one, otherwise creats anew)");
387
add_module_proc(COMMAND_PROC, name, "achats", "achats", 0, 0, achat, "display buddy chats you are on");
388
add_module_proc(COMMAND_PROC, name, "ainvite", "ainvite", 0, 0, achat, "<screen name> <buddy chat> <msg> invite user to buddy chat with msg");
389
add_module_proc(COMMAND_PROC, name, "anames", "anames", 0, 0, achat, "<buddy chat>");
390
add_module_proc(COMMAND_PROC, name, "acwarn", "acwarn", 0, 0, achat, "<buddy chat> <screen name> <anon>");
391
add_module_proc(COMMAND_PROC, name, "aaway", "aaway", 0, 0, aaway, "<away msg> Go away or come back if away");
392
add_module_proc(COMMAND_PROC, name, "aquery", "aquery", 0, 0, aquery, "query user");
393
add_module_proc(COMMAND_PROC, name, "ainfo", "ainfo", 0, 0, ainfo, "<command> <args>\n/ainfo set <your info...> Sets your info\n/ainfo get <screen name> Retreives sn's info");
394
395
#ifdef BITCHX_PATCH
396
add_completion_type("amsg", 2, CUSTOM_COMPLETION, &amsg_complete_func);
397
overwrite_tabkey_comp(&do_aim_tabkey_overwrite,&aim_tabkey_overwrite);
398
#endif
399
400
statusprintf("Aol Instant Messanger Module Loaded");
401
sprintf(buffer, "$0+AIM %s by panasync - $2 $3", AIM_VERSION);
402
fset_string_var(FORMAT_VERSION_FSET, buffer);
403
snprintf(buffer, BIG_BUFFER_SIZE, "%s/AIM.sav", get_string_var(CTOOLZ_DIR_VAR));
404
p = expand_twiddle(buffer);
405
load("LOAD", p, empty_string, NULL);
406
new_free(&p);
407
bx_init_toc();
408
return 0;
409
}
410
411