Client class
This commit is contained in:
parent
559df11d41
commit
6f9a472818
|
@ -1,7 +1,7 @@
|
|||
#!/bin/sh
|
||||
|
||||
moonc-5.3 `find -type f | grep 'moon$'`
|
||||
ngircd -f ./spec/ngircd.conf
|
||||
moonc-5.3 `find -type f | grep -v spec | grep 'moon$'`
|
||||
ngircd -f `pwd`/spec/ngircd.conf
|
||||
|
||||
function trap_ctrlc () {
|
||||
killall ngircd
|
||||
|
|
|
@ -34,6 +34,10 @@ Name = #lobby
|
|||
Topic = Welcome to the new ShadowNET!
|
||||
Modes = tn
|
||||
|
||||
[Operator]
|
||||
Name = Cadey
|
||||
Password = hunter2
|
||||
|
||||
[Server]
|
||||
Name = ketracel.akua
|
||||
Passive = yes
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
irce = require "irce"
|
||||
socket = require "socket"
|
||||
test = require "ketracel.test"
|
||||
|
||||
describe "ngircd protocol support", ->
|
||||
local file
|
||||
|
@ -42,27 +43,9 @@ describe "ngircd protocol support", ->
|
|||
print "[server] " .. msg
|
||||
irc\process msg
|
||||
|
||||
irc\clear_callback "376"
|
||||
@irc\clear_callback "376"
|
||||
|
||||
it "can do a normal client connection", ->
|
||||
irc_client = socket.tcp!
|
||||
ircce = irce.new!
|
||||
ircce\set_send_func (message) =>
|
||||
print "[client] > " .. message
|
||||
irc_client\send message
|
||||
running = true
|
||||
ircce\set_callback "005", =>
|
||||
running = false
|
||||
|
||||
ircce\load_module require "irce.modules.base"
|
||||
irc_client\connect "127.0.0.1", 6667
|
||||
ircce\NICK "test"
|
||||
ircce\USER "test", "hunter2"
|
||||
|
||||
while running
|
||||
msg = irc_client\receive!
|
||||
print "[client] < " .. msg
|
||||
ircce\process msg
|
||||
|
||||
ircce\QUIT "bye"
|
||||
irc_client\close!
|
||||
it "can use the Client class", ->
|
||||
cli = test.Client "test_user"
|
||||
cli\wait_for "005"
|
||||
cli\quit!
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
include_rules
|
||||
.gitignore
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
irce = require "irce"
|
||||
socket = require "socket"
|
||||
|
||||
get_client_modules = (irc) ->
|
||||
irc\load_module require "irce.modules.base"
|
||||
irc\load_module require "irce.modules.message"
|
||||
irc\load_module require "irce.modules.channel"
|
||||
|
||||
class Client
|
||||
new: (nick) =>
|
||||
@nick = nick
|
||||
socket = socket.tcp!
|
||||
irc = irce.new!
|
||||
get_client_modules irc
|
||||
irc\set_send_func (message) =>
|
||||
print string.format "[client %s] > %s", nick, message
|
||||
socket\send message
|
||||
|
||||
socket\connect "127.0.0.1", 6667
|
||||
irc\NICK nick
|
||||
irc\USER nick, nick
|
||||
|
||||
@socket = socket
|
||||
@irc = irc
|
||||
|
||||
wait_for: (event) =>
|
||||
running = true
|
||||
nick = @nick
|
||||
@irc\set_callback event, =>
|
||||
print string.format "[client %s] ! got event %s", nick, event
|
||||
running = false
|
||||
|
||||
while running
|
||||
msg = @socket\receive!
|
||||
print string.format "[client %s] < %s", nick, msg
|
||||
@irc\process msg
|
||||
|
||||
quit: =>
|
||||
@irc\QUIT "bye"
|
||||
@socket\close!
|
||||
|
||||
{
|
||||
:Client
|
||||
}
|
Loading…
Reference in New Issue