2009-07-13 11:39:34 +00:00
|
|
|
#lang scheme/base
|
2009-07-13 15:01:20 +00:00
|
|
|
(require scheme/class openssl (prefix-in xmpp: "xmpp.ss"))
|
2009-07-13 11:39:34 +00:00
|
|
|
(provide (all-defined-out))
|
|
|
|
|
|
|
|
; a class which wraps the xmpp in a thread and allows messages to be picked up
|
|
|
|
; and sent by the game
|
|
|
|
|
|
|
|
(define debug-netloop #f)
|
|
|
|
|
|
|
|
(define jabberer%
|
|
|
|
(class object%
|
|
|
|
(init-field
|
|
|
|
(jid "none@nowhere")
|
|
|
|
(pass "xxxx"))
|
|
|
|
|
|
|
|
(field
|
|
|
|
(incoming '())
|
|
|
|
(outgoing '())
|
|
|
|
(thr 0)
|
|
|
|
(debug-jab #f))
|
|
|
|
|
|
|
|
(define/public (get-incoming)
|
|
|
|
incoming)
|
|
|
|
|
|
|
|
(define/public (clear-incoming)
|
|
|
|
(set! incoming '()))
|
|
|
|
|
|
|
|
(define/public (msg-waiting?)
|
|
|
|
(not (null? incoming)))
|
|
|
|
|
|
|
|
(define/public (get-msg)
|
|
|
|
(let ((msg (car incoming)))
|
|
|
|
(set! incoming (cdr incoming))
|
|
|
|
msg))
|
|
|
|
|
|
|
|
(define/public (send-msg to msg)
|
2009-07-21 16:33:26 +00:00
|
|
|
(set! outgoing (append outgoing (list (list to msg))))
|
|
|
|
#;(printf "~a~n" outgoing))
|
2009-07-13 11:39:34 +00:00
|
|
|
|
|
|
|
(define (message-handler sz)
|
|
|
|
(when debug-jab (printf "rx <---- ~a ~a~n" (xmpp:message-from sz) (xmpp:message-body sz)))
|
|
|
|
(set! incoming (cons (list (xmpp:message-from sz) (xmpp:message-body sz)) incoming)))
|
|
|
|
|
|
|
|
(define/public (start)
|
2009-07-13 15:01:20 +00:00
|
|
|
(set! thr (thread run)))
|
2009-07-13 11:39:34 +00:00
|
|
|
|
|
|
|
(define/public (stop)
|
|
|
|
(kill-thread thr))
|
|
|
|
|
|
|
|
(define (run)
|
|
|
|
(xmpp:with-xmpp-session jid pass
|
|
|
|
(xmpp:set-xmpp-handler 'message message-handler)
|
|
|
|
(let loop ()
|
|
|
|
(when debug-netloop (printf ".~n"))
|
|
|
|
(when (not (null? outgoing))
|
2009-07-24 19:02:49 +00:00
|
|
|
(when debug-jab (printf "tx ----> ~a ~a~n" (car (car outgoing)) (cadr (car outgoing))))
|
2009-07-22 15:35:15 +00:00
|
|
|
(xmpp:send (xmpp:message (car (car outgoing)) (cadr (car outgoing))))
|
|
|
|
(set! outgoing (cdr outgoing)))
|
2009-07-24 19:02:49 +00:00
|
|
|
(sleep 0.1)
|
2009-07-13 11:39:34 +00:00
|
|
|
(loop))))
|
|
|
|
(super-new)))
|