aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Laprade <jesselaprade@gmail.com>2021-03-30 23:20:31 -0400
committerJesse Laprade <jesselaprade@gmail.com>2021-03-30 23:20:31 -0400
commit8fae2f770dea9df1f87812c064132661c217feed (patch)
treeec9fa07d6126c192e074fe58bfd4e507d970c541
parentfbd3c95752a0abf0453881f4e509cee793d4de03 (diff)
downloadruth-8fae2f770dea9df1f87812c064132661c217feed.tar.gz
ruth-8fae2f770dea9df1f87812c064132661c217feed.tar.bz2
ruth-8fae2f770dea9df1f87812c064132661c217feed.zip
Added SSL and password support!
-rw-r--r--src/config.rkt2
-rw-r--r--src/ruth.rkt16
2 files changed, 15 insertions, 3 deletions
diff --git a/src/config.rkt b/src/config.rkt
index 1857370..48b5ece 100644
--- a/src/config.rkt
+++ b/src/config.rkt
@@ -5,6 +5,8 @@
(define config
(hash 'host "127.0.0.1"
'port 6667
+ 'ssl #f
+ 'pass #f
'nickname "ruth" ;; This one shows up in chat and can be registered
'username "m455s-bot" ;; This one shows up in join and leave messages
'realname "m455s-bot" ;; This one shows up somewhere?
diff --git a/src/ruth.rkt b/src/ruth.rkt
index 4d72d96..a2dbe4e 100644
--- a/src/ruth.rkt
+++ b/src/ruth.rkt
@@ -1,6 +1,7 @@
#lang racket/base
-(require racket/tcp
+(require openssl
+ racket/tcp
racket/list
racket/string
racket/file
@@ -124,8 +125,11 @@
;; returns two values: an input-port (from-server) and an output port
;; (to-server)
(define-values (from-server to-server)
- (tcp-connect (config-ref 'host)
- (config-ref 'port)))
+ (let ([host (config-ref 'host)]
+ [port (config-ref 'port)])
+ (if (config-ref 'ssl)
+ (ssl-connect host port 'secure)
+ (tcp-connect host port))))
;; The (flush-output ...) here is required because we are using TCP ports,
;; and according to the Racket docs on (flush-output ...), TCP ports use
@@ -148,6 +152,10 @@
(define (send-action channel action)
(send-bytes/utf-8 (format "PRIVMSG ~a :\x01ACTION ~a\x01" channel action)))
+(define (send-pass)
+ (send-bytes/utf-8
+ (format "PASS ~a" (config-ref 'pass))))
+
(define (send-nick)
(send-bytes/utf-8
(format "NICK ~a" (config-ref 'nickname))))
@@ -240,6 +248,8 @@
(check-for-e channel nickname message-joined)))))
(define (initialize-connection)
+ (when (config-ref 'pass)
+ (send-pass))
(send-nick)
(send-user)
(join-channels)