Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #lang racket
- ;bind ports, set buffer mode.
- (define-values (input-port output-port) (tcp-connect "laserblue.org" 6667))
- (file-stream-buffer-mode output-port 'block)
- ;initial send initial connection information.
- (write-bytes #"USER Kaylin * laserblue.org :Kaylin\r\n" output-port)
- (write-bytes #"NICK Kayscript\r\n" output-port)
- (flush-output output-port)
- (define (irc-connect input-port output-port)
- (if (regexp-match-peek #rx".*?\r\n" input-port);if it's a full line
- (cond
- ;reply to ping commands (send the wrong reply so I get an error message)
- [(regexp-match-peek #rx"^PING.*?\r\n" input-port 0 512)
- ((write-bytes (regexp-replace #"PING" (car (regexp-match #rx"^PING.*?\r\n" input-port)) #"WRONGREPLY") output-port)
- (flush-output output-port)(printf "Replied to server PING.\r\n")(irc-connect input-port output-port))]
- ;login when prompted
- [(regexp-try-match #rx"^:NickServ.*?msg NickServ identify <password>.*?\r\n" input-port 0 512)
- ((write-bytes #"PRIVMSG NickServ :identify notreallymypw\r\n" output-port)
- (flush-output output-port)(printf "Identified to NickServ.\r\n")
- (write-bytes #"JOIN #laserblue\r\n" output-port)
- (flush-output output-port)(printf "Joined #laserblue.\r\n")(irc-connect input-port output-port))]
- ;if the server disconnects the client...
- [(regexp-try-match #rx"^ERROR.*?\r\n" input-port 0 512) (close-output-port output-port)
- (close-input-port input-port)
- (printf "Server closed the connection.\r\nAttempting to reconnect...\r\n")
- (sleep 30)
- (define-values (input-port-a output-port-b) (tcp-connect "laserblue.org" 6667))
- (irc-connect input-port-a output-port-b) #|ignore the fact that this does not relog it merely connects to the server |#]
- ;discard all other lines.
- [(regexp-match #rx"^.*?\r\n" input-port 0 512)(irc-connect input-port output-port)]
- [else (irc-connect input-port output-port)])
- (error "Not a full line.")))
- (irc-connect input-port output-port)
- ;Doesn't get here at the moment...
- ;cleanup
- ;(write-bytes #"QUIT\r\n" output-port)
- ;(flush-output output-port)
- ;(close-output-port output-port)
- ;(close-input-port input-port)
- ;I get the following output with the error at the end.
- ;37
- ;16
- ;Replied to server PING.
- ;
- ;Server closed the connection.
- ;
- ;Attempting to reconnect...
- ;
- ;. . result arity mismatch;
- ; expected number of values not received
- ; expected: 1
- ; received: 2
- ; values...:
- ; #<input-port:laserblue.org>
- ; #<output-port:laserblue.org>
Advertisement
Add Comment
Please, Sign In to add comment