diff options
Diffstat (limited to 'src/irc/dcc.lua')
-rw-r--r-- | src/irc/dcc.lua | 42 |
1 files changed, 20 insertions, 22 deletions
diff --git a/src/irc/dcc.lua b/src/irc/dcc.lua index 6e8537e..6d9b347 100644 --- a/src/irc/dcc.lua +++ b/src/irc/dcc.lua @@ -1,26 +1,22 @@ --- -- Implementation of the DCC protocol -- initialization {{{ -local base = _G -local irc = require 'irc' -local ctcp = require 'irc.ctcp' +local irc = libs.irc +local ctcp = libs.ctcp local c = ctcp._ctcp_quote -local irc_debug = require 'irc.debug' -local misc = require 'irc.misc' -local socket = require 'socket' -local coroutine = require 'coroutine' -local io = require 'io' -local string = require 'string' +local irc_debug = libs.debug +local misc = libs.misc +local socket = libs.socket -- }}} --- -- This module implements the DCC protocol. File transfers (DCC SEND) are -- handled, but DCC CHAT is not, as of yet. -module 'irc.dcc' +local dcc = {} -- defaults {{{ -FIRST_PORT = 1028 -LAST_PORT = 5000 +dcc.FIRST_PORT = 1028 +dcc.LAST_PORT = 5000 -- }}} -- private functions {{{ @@ -138,13 +134,13 @@ end -- @param address IP address of the remote user in low level int form -- @param port Port to connect to at the remote user -- @param packet_size Size of the packets the remote user will be sending -function _accept(filename, address, port, packet_size) +function dcc._accept(filename, address, port, packet_size) debug_dcc("Accepting a DCC SEND request from " .. address .. ":" .. port) packet_size = packet_size or 1024 - local sock = base.assert(socket.tcp()) - base.assert(sock:connect(address, port)) + local sock = assert(socket.tcp()) + assert(sock:connect(address, port)) sock:settimeout(0.1) - local file = base.assert(io.open(misc._get_unique_filename(filename), "w")) + local file = assert(io.open(misc._get_unique_filename(filename), "w")) irc._register_socket(sock, 'r', coroutine.wrap(function(s) return accept_file(s, file, packet_size) @@ -162,17 +158,17 @@ end -- @param port Port to accept connections on (optional, defaults to -- choosing an available port between FIRST_PORT and LAST_PORT -- above) -function send(nick, filename, port) - port = port or FIRST_PORT +function dcc.send(nick, filename, port) + port = port or dcc.FIRST_PORT local sock repeat - sock = base.assert(socket.tcp()) + sock = assert(socket.tcp()) err, msg = sock:bind('*', port) port = port + 1 - until msg ~= "address already in use" and port <= LAST_PORT + 1 + until msg ~= "address already in use" and port <= dcc.LAST_PORT + 1 port = port - 1 - base.assert(err, msg) - base.assert(sock:listen(1)) + assert(err, msg) + assert(sock:listen(1)) local ip = misc._ip_str_to_int(irc.get_ip()) local file, err = io.open(filename) if not file then @@ -194,3 +190,5 @@ function send(nick, filename, port) end -- }}} -- }}} + +return dcc |