toosweettobereal

  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
#
# простой irc client.
#
irc.server.node(name, addr, port, user, fd) type;
irc.server(name, addr, port, user)
{
node = new irc.server.node(name, addr, port, user, 0);
return node;
connect(node)
{
node.fd = posix.net.connect(node.addr, node.port);
std.echo("fd: ", string(node.fd));
if ( node.fd )
return true;
return false;
}
send(node, data)
{
crlf = new[2];
crlf[0] = 13;
crlf[1] = 10;
msg = data + crlf;
posix.io.write(node.fd, msg, sizeof(msg));
}
recv(node)
return posix.io.read(node.fd, 100);
login(node)
{
send(node, "NICK " + node.user.nick);
send(node, "USER " + node.user.nick +
" none none :" + node.user.nick);
}
}
irc.user.node(nick) type;
irc.user(nick)
return new irc.user.node(nick);
irc.channel.node(server, name) type;
irc.channel(server, name)
{
return new irc.channel.node(server, name);
join(channel)
irc.server.send(channel.server, "JOIN " + channel.name);
part(channel)
irc.server.send(channel.server, "PART " + channel.name);
say(channel, text)
irc.server.send(channel.server, "PRIVMSG " +
channel.name + " :" + text);
}
irc.client.node(user, server, channels) type;
irc.client(nickname, sname, addr, port)
{
client = new irc.client.node(null, null, null);
client.user = new irc.user(nickname);
client.server =
new irc.server(sname, addr, port, client.user);
client.channels = new std.list();
return client;
join(client, name)
{
if ( match(client, name) )
return false;
channel = new irc.channel(client.server, name);
irc.channel.join(channel);
std.list.add(client.channels, channel);
return true;
}
connect(client)
{
if ( !irc.server.connect(client.server) )
return false;
irc.server.login(client.server);
return true;
}
say(client, channel, text)
{
c = match(client, channel);
if ( c == null )
return false;
irc.channel.say(c, text);
return true;
}
match(client, name)
{
iter = new std.list.iter(client.channels);
while ( !std.list.iter.end(iter) )
if ( std.list.iter.get(iter).name == name )
return std.list.iter.get(iter);
}
}
main() agent
{
client = new irc.client("tswttt",
"wenet", "78.108.81.133", 6667);
if ( !irc.client.connect(client) )
oops("failed to connect to " + client.server.addr);
std.echo("joined");
irc.client.join(client, "#ripland");
irc.client.say(client, "#ripland", "hello \o/");
while ( 1 )
irc.server.recv(client.server);
oops(reason)
{
std.echo("oops: " + reason);
posix.sys.halt(0);
}
}
# vim:syntax=edge