Guest User

Untitled

a guest
Mar 22nd, 2013
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scheme 2.90 KB | None | 0 0
  1. #lang racket
  2. ;bind ports, set buffer mode.
  3. (define-values (input-port output-port) (tcp-connect "laserblue.org" 6667))
  4. (file-stream-buffer-mode output-port 'block)
  5.  
  6.  
  7. ;initial send initial connection information.
  8. (write-bytes #"USER Kaylin * laserblue.org :Kaylin\r\n" output-port)
  9. (write-bytes #"NICK Kayscript\r\n" output-port)
  10. (flush-output output-port)
  11.  
  12.  
  13. (define (irc-connect input-port output-port)
  14.   (if (regexp-match-peek #rx".*?\r\n" input-port);if it's a full line
  15.       (cond
  16.         ;reply to ping commands (send the wrong reply so I get an error message)
  17.         [(regexp-match-peek #rx"^PING.*?\r\n" input-port 0 512)
  18.          ((write-bytes (regexp-replace #"PING" (car (regexp-match #rx"^PING.*?\r\n" input-port)) #"WRONGREPLY") output-port)
  19.           (flush-output output-port)(printf "Replied to server PING.\r\n")(irc-connect input-port output-port))]
  20.         ;login when prompted
  21.         [(regexp-try-match #rx"^:NickServ.*?msg NickServ identify <password>.*?\r\n" input-port 0 512)
  22.          ((write-bytes #"PRIVMSG NickServ :identify notreallymypw\r\n" output-port)
  23.           (flush-output output-port)(printf "Identified to NickServ.\r\n")
  24.           (write-bytes #"JOIN #laserblue\r\n" output-port)
  25.           (flush-output output-port)(printf "Joined #laserblue.\r\n")(irc-connect input-port output-port))]
  26.         ;if the server disconnects the client...
  27.         [(regexp-try-match #rx"^ERROR.*?\r\n" input-port 0 512) (close-output-port output-port)
  28.                                                                 (close-input-port input-port)
  29.                                                                 (printf "Server closed the connection.\r\nAttempting to reconnect...\r\n")
  30.                                                                 (sleep 30)
  31.                                                                 (define-values (input-port-a output-port-b) (tcp-connect "laserblue.org" 6667))
  32.                                                                 (irc-connect input-port-a output-port-b) #|ignore the fact that this does not relog it merely connects to the server |#]
  33.        
  34.        
  35.         ;discard all other lines.
  36.         [(regexp-match #rx"^.*?\r\n" input-port 0 512)(irc-connect input-port output-port)]
  37.        
  38.         [else (irc-connect input-port output-port)])
  39.       (error "Not a full line.")))
  40.  
  41. (irc-connect input-port output-port)
  42.  
  43. ;Doesn't get here at the moment...
  44. ;cleanup
  45. ;(write-bytes #"QUIT\r\n" output-port)
  46. ;(flush-output output-port)
  47. ;(close-output-port output-port)
  48. ;(close-input-port input-port)
  49.  
  50.  
  51. ;I get the following output with the error at the end.
  52. ;37
  53. ;16
  54. ;Replied to server PING.
  55. ;
  56. ;Server closed the connection.
  57. ;
  58. ;Attempting to reconnect...
  59. ;
  60. ;. . result arity mismatch;
  61. ; expected number of values not received
  62. ;  expected: 1
  63. ;  received: 2
  64. ;  values...:
  65. ;   #<input-port:laserblue.org>
  66. ;   #<output-port:laserblue.org>
Advertisement
Add Comment
Please, Sign In to add comment