]> git.pond.sub.org Git - eow/blob - net.lisp
test setup
[eow] / net.lisp
1 (defpackage "emp-net"
2   (:use "SB-BSD-SOCKETS" "CL"))
3
4 (in-package "emp-net")
5
6 ; 2 Empire server ready
7 ; client testclient
8 ; 0 talking to testclient
9 ; coun POGO
10 ; 0 country name POGO
11 ; pass peter
12 ; 0 password ok
13 ; play
14 ; 2 2
15 ; 1 You're not a deity!
16 ; 3 so long...
17 ; Connection closed by foreign host.
18
19 (defvar *socket*)
20 (defvar *s*)
21
22 (defun init ()
23   (setf *socket* (make-instance 'inet-socket :type :stream :protocol :tcp))
24   (let ((address (host-ent-address (get-host-by-name "localhost"))))
25     (socket-connect *socket* address 6665))
26   (setf *s* (socket-make-stream *socket* :input t :output t :buffering :line)))
27
28 (defun read-reply ()
29   (let ((reply (read-line *s*)))
30     (assert (char= (aref reply 1) #\ ))
31     (cons (aref reply 0) (subseq reply 2))))
32
33 (defconstant +C_CMDOK+ "0")
34 (defconstant +C_DATA+ "1")
35 (defconstant +C_INIT+ "2")
36 (defconstant +C_EXIT+ "3")
37 (defconstant +C_FLUSH+ "4")
38 (defconstant +C_NOECHO+ "5")
39 (defconstant +C_PROMPT+ "6")
40 (defconstant +C_ABORT+ "7")
41 (defconstant +C_REDIR+ "8")
42 (defconstant +C_PIPE+ "9")
43 (defconstant +C_CMDERR+ "a")
44 (defconstant +C_BADCMD+ "b")
45 (defconstant +C_EXECUTE+ "c")
46 (defconstant +C_FLASH+ "d")
47 (defconstant +C_INFORM+ "e")
48 ;(defconstant +C_LAST+ "e")
49
50 (defun login (username country password)
51   (user username)
52   (coun country)
53   (pass password))
54
55 (defun user (username)
56   (format *s* "user ~a~%" username)
57   (assert (char= +C_CMDOK+ (car (read-reply)))))
58
59 (defun coun (country)
60   (format *s* "coun ~a~%" country)
61   (assert (char= +C_CMDOK+ (car (read-reply)))))
62
63 (defun pass (password)
64   (format *s* "pass ~a~%" password))
65
66 (defun reader (fd)
67   (declare (ignore fd))
68   (let ((line (read-line *s*)))
69     (format t "< ~a~%" line)
70     (reader)))
71
72 (defun add-reader ()
73   (sb-sys:add-fd-handler (sb-sys:fd-stream-fd *s*)
74                          :input
75                          (lambda (fd)
76                            (format t "input-handler: fd ~a~%" fd))))