/
debugclient.pl
executable file
·246 lines (202 loc) · 8.59 KB
/
debugclient.pl
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
#!/usr/bin/debugperl
#
# This is an attempt to work from a more top-down perspective on the
# Net::SILC::Client perl modules. this script will strive to
# embody the typical usage of this low-level module in the manner of the
# "synopsis" given on most perl module doc pages.
# eventually, a new debugging script should support this one, illustrating
# the net-irc-like interface that is the next major step in development ;)
use strict;
use Devel::Peek;
use lib "lib/";
use Net::SILC;
use Net::SILC::Client;
my @user = ( username => "example",
realname => "example user",
hostname => "example.com",
keyfile => "example.pub"
); # example.prv is assumed
my $callbacks = { silc_say => \&say, # called when server says something
silc_channel_message => \&channel_message, # when channel message is received
silc_private_message => \&private_message, # when private message is received
silc_notify => \¬ify, # called when server sends notify of server event
silc_command => \&command, # gets notice when commands are sent
silc_command_reply => \&command_reply, # gets notice when server replies
silc_connected => \&connected, # sent when server connects
silc_disconnected => \&disconnected, # sent when server disconnects
silc_failure => \&failure, # called whenever any server failure occurs
silc_key_agreement => \&key_agreement, # ignored (for now)
silc_ftp => \&ftp, # not implemented
silc_detach => \&detach, # not (yet) useful (to me)
};
printf("creating new Client.pm object..\n");
#my $client = new Net::SILC::Client($callbacks,$user);
my $client = new Net::SILC::Client(@user);
my $server = "silc.icore.at";
printf("connecting to $server..\n");
$client->connect($server); # will cause the 'connected' callback to be triggered
#$client->add_handler(['connect'], \&on_connect);
# i realize increasingly that my focus on bots probly informs my
# decision about what's 'relevant' to include from the (extremely rich)
# silc library toolkit interface. fortunately, this only serves to
# (further) motivate my desire for this project to be taken up by an
# "opensource community" of folks who, making various demands on this code,
# thereby ensure it's vitality and (appropriate) richness :)
# so the api for Net::IRC looks more like 'join', 'privmsg', 'nick', and
# possibly 'away', and 'schedule' are the key methods to provide, in
# addition to the connection creation and handler management interface
# to run forever:
#$client->run();
# do sumfin smart here, so i can send a signal here, and change the $run flag ;p
# to run once in a loop
# this doesn't work yet
#print "waiting for debugclient.pl to connect..\n";
#until ($client->state() > 0) { $client->run_once(); } # do nothing until the connected callback returns (thus chanigng the state)
#print "state changed!\n";
print "connected!\n";
while ($client->state() > 0) { $client->run_once(); }; # wait for further events
sub on_connect {
print "debugclient's on_connect routine is called!\n";
}
# callback routines
# many of these will need a means to re-access the Net::SILC::Client object, so
# they can call methods on it.. (like 'command', 'join', etc)
sub say { # server messages
my($self,$msg) = @_;
print "Server Says: $msg\n";
}
sub channel_message { # public messages
my ($self,$nick,$channel,$msg,$fmsg,$action) = @_;
print "$channel: $fmsg";
$self->chanmsg($channel,"hi there, ".$nick);
if ( ($channel =~ /#comms/) && ($msg =~ /get out/) ) {
$self->command("LEAVE $channel");
}
}
sub private_message { # private messages
my ($self,$nick,$msg,$fmsg) = @_;
print "$fmsg";
$self->privmsg($nick,"replying to yer ".$msg);
$self->command("WHOIS $nick");
}
# these should ultimately translate into events..
sub notify {
my ($silc) = shift;
my ($type) = shift;
if ($type =~ /NONE/) {
print shift;
} elsif ($type =~ /JOIN/) {
my $nick = shift;
my $channel = shift;
printf("Server Notify: $nick has JOINed $channel\n");
} elsif ($type =~ /INVITE/) {
my $channel = shift; my $nick = shift;
printf("Server Notify: $nick has been INVITEd to $channel\n");
} elsif ($type =~ /LEAVE/) {
my $nick = shift; my $channel = shift;
printf("Server Notify: $nick has LEFT $channel\n");
} elsif ($type =~ /SIGNOFF/) {
my $nick = shift; my $msg = shift;
printf("Server Notify: $nick has SIGNEDOFF ($msg)\n");
} elsif ($type =~ /TOPIC/) {
my $changer = shift; my $topic = shift; my $channel = shift;
printf("Server Notify: $changer has changed TOPIC of $channel to $topic\n");
} elsif ($type =~ /NICK/) {
my $old = shift; my $new = shift;
printf("Server Notify: $old has changed their NICK to $new\n") unless (!$old && !$new);
} elsif ($type =~ /CMODE/) {
my $changer = shift; my $mode = shift; my $channel = shift;
printf("Server Notify: $changer changed CMODE of $channel ($mode)\n");
} elsif ($type =~ /CUMODE/) {
my $changer = shift; my $mode = shift;
my $nick = shift; my $channel = shift;
printf("Server Notify: $changer changed CUMODE of $nick on $channel ($mode)\n");
$silc->command("TOPIC $channel Wheee!");
} elsif ($type =~ /UMODE/) {
my $clientid = shift; my $mode = shift;
printf("Server Notify: $clientid changed UMODE ($mode)\n");
} elsif ($type =~ /MOTD/) {
printf("Server Notify: got MOTD: %s\n", shift);
} elsif ($type =~ /CHANNEL/) {
printf("Server Notify: %s changed it's ID (safely ignored)\n", shift);
} elsif ($type =~ /KICK/) {
my $kicked = shift; my $msg = shift;
my $kicker = shift; my $channel = shift;
printf("Server Notify: $kicked has been KICKed from $channel by $kicker ($msg)\n");
} elsif ($type =~ /KILL/) {
my $killed = shift; my $msg = shift;
my $killer = shift; my $channel = shift;
printf("Server Notify: $killed has been KILLed from $channel by $killer ($msg)\n");
} elsif ($type =~ /WATCH/) {
my $nick = shift; my $mode = shift;
printf("Server Notify: watched client $nick ($mode)\n");
} elsif ($type =~ /ERROR/) {
printf("Server Notify: ERROR\n");
} else {
my $msg = shift;
printf("(uncaught)Server Notify: %s (%s)\n", $type,$msg);
}
}
sub command {}
sub command_reply {
my ($self,$type) = @_[0,1];
printf("debugclient got command_reply: $type\n");
if ($type =~ /NONE/) {
} elsif ($type =~ /WHOIS/) {
my ($nick,$user,$real,$chanlist,$umode,$idletime,$fingerprint) = @_[2..8];
printf("debugclient got a reply from WHOIS command for $nick ($umode):\n");
printf("Real Name: $real\n");
printf("Channels: $chanlist\n");
printf("Idle: $idletime\n");
printf("Fingerprint: $fingerprint\n");
} elsif ($type =~ /NICK/) {
my ($nick) = @_[2];
printf("debugclient successfully changed its NICK to $nick\n");
} elsif ($type =~ /LIST/) {
my ($channel, $topic, $count) = @_[2..4];
printf("Channel LIST: $channel ($count users)\t$topic\n");
} elsif ($type =~ /TOPIC/) {
my ($channel, $topic) = @_[2,3];
printf("debugclient changed TOPIC on $channel: $topic\n");
} elsif ($type =~ /INVITE/) {
} elsif ($type =~ /KILL/) {
} elsif ($type =~ /INFO/) {
} elsif ($type =~ /OPER/) {
printf("debugclient.pl successfully became silcoper\n");
} elsif ($type =~ /JOIN/) {
my ($channel,$mode,$topic) = @_[2..4];
printf("debugclient JOINed $channel ($mode)\n");
printf("Topic on $channel is: $topic\n");
} elsif ($type =~ /MOTD/) {
} elsif ($type =~ /UMODE/) {
} elsif ($type =~ /CMODE/) {
} elsif ($type =~ /CUMODE/) {
} elsif ($type =~ /KICK/) {
} elsif ($type =~ /BAN/) {
} elsif ($type =~ /SILCOPER/) {
} elsif ($type =~ /LEAVE/) {
my $channel = @_[2];
printf("debugclient has LEFT $channel\n");
} elsif ($type =~ /USERS/) {
} # leaving a few out here, cuz they're likely not implemented (yet)
else { printf("debugclient.pl got an unhandled command_reply event: $type\n"); }
}
# this gets triggered once the underlying library handles the verify_public_key and get_auth_method pieces
sub connected {
my ($self,$server) = @_;
print "debugclient.pl is connected to the server ($server)!\n";
$self->command("LIST");
$self->join("#commstest");
$self->command("JOIN #commsmanifesto");
$self->nick("spidey");
}
sub disconnected {}
# not really handling these either, really ;p
sub failure {}
sub key_agreement {}
sub ftp {}
sub detach {}
# abstracting these out for simplicity (for now)
#sub get_auth_method {}
#sub verify_public_key {}
#sub ask_passphrase {}