Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
BitchX
GitHub Repository: BitchX/BitchX1.3
Path: blob/master/dll/pkga/pkga.c
1072 views
1
/*
2
* pkga.c --
3
*
4
* This file contains a simple Tcl package "pkga" that is intended
5
* for testing the Tcl dynamic loading facilities.
6
*
7
* CopyRight Colten Edwards aka panasync@efnet Jan 1997
8
*/
9
/* compile with
10
* gcc -o -I../include -fPIC -o pkga.o pkga.c
11
* gcc -shared -o pkga.so pkga.o
12
*/
13
14
#include "irc.h"
15
#include "struct.h"
16
#include "dcc.h"
17
#include "server.h"
18
#include "ircaux.h"
19
#include "alias.h"
20
#include "ctcp.h"
21
#include "list.h"
22
#include "struct.h"
23
#include "numbers.h"
24
#include "output.h"
25
#include "commands.h"
26
#include "vars.h"
27
#include "module.h"
28
#define INIT_MODULE
29
#include "modval.h"
30
31
/*
32
* Prototypes for procedures defined later in this file:
33
*/
34
static void Pkga_EqCmd (IrcCommandDll *, char *, char *, char *);
35
static char *Pkga_newctcp (CtcpEntryDll *, char *, char *, char *);
36
static char *Pkga_ctcppage (CtcpEntryDll *, char *, char *, char *);
37
static char *Pkga_alias (char *);
38
39
static int Pkga_numeric (char *, char *, char **);
40
/*
41
*----------------------------------------------------------------------
42
*
43
* Pkga_EqCmd --
44
*
45
* This procedure is invoked to process the "pkga_eq" Tcl command.
46
* It expects two arguments and returns 1 if they are the same,
47
* 0 if they are different.
48
*
49
* Results:
50
* A standard Tcl result.
51
*
52
* Side effects:
53
* See the user documentation.
54
*
55
*----------------------------------------------------------------------
56
*/
57
58
void Pkga_EqCmd(intp, command, args, subargs)
59
IrcCommandDll *intp; /* Current interpreter. */
60
char *command;
61
char *args; /* Number of arguments. */
62
char *subargs; /* Argument strings. */
63
{
64
char *arg1, *arg2;
65
arg1 = next_arg(args, &args);
66
arg2 = next_arg(args, &args);
67
if (!arg1 || !arg2)
68
return;
69
put_it("arg1 %s arg2", !my_stricmp(arg1, arg2)?"eq":"!eq");
70
return;
71
}
72
73
static char *Pkga_newctcp (CtcpEntryDll *dll, char *from, char *to, char *args)
74
{
75
char putbuf[500];
76
sprintf(putbuf, "%c%s %s%c", CTCP_DELIM_CHAR, dll->name, my_ctime(time(NULL)), CTCP_DELIM_CHAR);
77
send_text(from, putbuf, "NOTICE", 0, 0);
78
return NULL;
79
}
80
81
static char *Pkga_ctcppage (CtcpEntryDll *dll, char *from, char *to, char *args)
82
{
83
char putbuf[500];
84
sprintf(putbuf, "%c%s %s%c", CTCP_DELIM_CHAR, dll->name, my_ctime(time(NULL)), CTCP_DELIM_CHAR);
85
send_text(from, putbuf, "NOTICE", 0, 0);
86
put_it(" %s is paging you", from);
87
return NULL;
88
}
89
90
static char *Pkga_alias (char *word)
91
{
92
if (!word || !*word)
93
return m_strdup("no string passed");
94
/* caller free's this string */
95
return m_strdup(word);
96
}
97
98
static int Pkga_numeric (char *from, char *user, char **args)
99
{
100
put_it("Server numeric 1 being handled");
101
return 1;
102
}
103
104
static int Pkga_raw (char *comm, char *from, char *userhost, char **args)
105
{
106
if (*args[1] && !strncasecmp(args[1], "test", 4))
107
{
108
PasteArgs(args, 1);
109
put_it("PRIVMSG from %s!%s [%s]", from, userhost, args[1]);
110
send_to_server("%s %s :You sent me a privmsg [%s]", comm, from, args[1]);
111
return 1;
112
}
113
return 0;
114
}
115
116
char *Pkga_Version(IrcCommandDll **intp)
117
{
118
return "99.9";
119
}
120
121
int new_dcc_output(int type, int s, char *buf, int len)
122
{
123
if (type == DCC_CHAT)
124
{
125
put_it("handler new dcc chat");
126
write(s, buf, len);
127
}
128
return 0;
129
}
130
131
int Pkga_Init(IrcCommandDll **intp, Function_ptr *global_table)
132
{
133
int i;
134
Server *sptr;
135
initialize_module("pkga");
136
sptr = get_server_list();
137
for (i = 0; i < server_list_size(); i++)
138
put_it("server%d -> %s", i, sptr[i].name);
139
140
add_module_proc(COMMAND_PROC, "pkga", "pkga_eq", NULL, 0, 0, Pkga_EqCmd, NULL);
141
add_module_proc(CTCP_PROC, "pkga", "blah", "New ctcp Type", -1, CTCP_SPECIAL | CTCP_TELLUSER, Pkga_newctcp, NULL);
142
add_module_proc(CTCP_PROC, "pkga", "page", "Page User", -1, CTCP_SPECIAL | CTCP_TELLUSER, Pkga_ctcppage, NULL);
143
add_module_proc(ALIAS_PROC, "pkga", "blah", NULL, 0, 0, Pkga_alias, NULL);
144
add_module_proc(HOOK_PROC, "pkga", NULL, NULL, 1, 0, Pkga_numeric, NULL);
145
add_module_proc(VAR_PROC, "pkga", "new_variable", "TEST VALUE", STR_TYPE_VAR, 0, NULL, NULL);
146
add_module_proc(RAW_PROC, "pkga", "PRIVMSG", NULL, 0, 0, Pkga_raw, NULL);
147
add_dcc_bind("CHAT", "pkga", NULL, NULL, NULL, new_dcc_output, NULL);
148
return 0;
149
}
150
151