From 6f9a472818462286c75b99dd87b6388a1a866eea Mon Sep 17 00:00:00 2001 From: Christine Dodrill Date: Wed, 25 Dec 2019 22:48:28 +0000 Subject: [PATCH] Client class --- scripts/dev_ipad_run.sh | 4 ++-- spec/ngircd.conf | 4 ++++ spec/ngircd_harness_spec.moon | 29 +++++------------------ src/ketracel/Tupfile | 3 +++ src/ketracel/test.moon | 44 +++++++++++++++++++++++++++++++++++ 5 files changed, 59 insertions(+), 25 deletions(-) create mode 100644 src/ketracel/Tupfile create mode 100644 src/ketracel/test.moon diff --git a/scripts/dev_ipad_run.sh b/scripts/dev_ipad_run.sh index 975e3fa..09f34ca 100755 --- a/scripts/dev_ipad_run.sh +++ b/scripts/dev_ipad_run.sh @@ -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 diff --git a/spec/ngircd.conf b/spec/ngircd.conf index 3f4c0e8..25da986 100644 --- a/spec/ngircd.conf +++ b/spec/ngircd.conf @@ -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 diff --git a/spec/ngircd_harness_spec.moon b/spec/ngircd_harness_spec.moon index f55b19a..832eb0e 100644 --- a/spec/ngircd_harness_spec.moon +++ b/spec/ngircd_harness_spec.moon @@ -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! diff --git a/src/ketracel/Tupfile b/src/ketracel/Tupfile new file mode 100644 index 0000000..591db9c --- /dev/null +++ b/src/ketracel/Tupfile @@ -0,0 +1,3 @@ +include_rules +.gitignore + diff --git a/src/ketracel/test.moon b/src/ketracel/test.moon new file mode 100644 index 0000000..a0fba57 --- /dev/null +++ b/src/ketracel/test.moon @@ -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 +}