(defpackage "emp-net" (:use "SB-BSD-SOCKETS" "CL")) (in-package "emp-net") ; 2 Empire server ready ; client testclient ; 0 talking to testclient ; coun POGO ; 0 country name POGO ; pass peter ; 0 password ok ; play ; 2 2 ; 1 You're not a deity! ; 3 so long... ; Connection closed by foreign host. (defvar *socket*) (defvar *s*) (defun init () (setf *socket* (make-instance 'inet-socket :type :stream :protocol :tcp)) (let ((address (host-ent-address (get-host-by-name "localhost")))) (socket-connect *socket* address 6665)) (setf *s* (socket-make-stream *socket* :input t :output t :buffering :line))) (defun read-reply () (let ((reply (read-line *s*))) (assert (char= (aref reply 1) #\ )) (cons (aref reply 0) (subseq reply 2)))) (defconstant +C_CMDOK+ "0") (defconstant +C_DATA+ "1") (defconstant +C_INIT+ "2") (defconstant +C_EXIT+ "3") (defconstant +C_FLUSH+ "4") (defconstant +C_NOECHO+ "5") (defconstant +C_PROMPT+ "6") (defconstant +C_ABORT+ "7") (defconstant +C_REDIR+ "8") (defconstant +C_PIPE+ "9") (defconstant +C_CMDERR+ "a") (defconstant +C_BADCMD+ "b") (defconstant +C_EXECUTE+ "c") (defconstant +C_FLASH+ "d") (defconstant +C_INFORM+ "e") ;(defconstant +C_LAST+ "e") (defun login (username country password) (user username) (coun country) (pass password)) (defun user (username) (format *s* "user ~a~%" username) (assert (char= +C_CMDOK+ (car (read-reply))))) (defun coun (country) (format *s* "coun ~a~%" country) (assert (char= +C_CMDOK+ (car (read-reply))))) (defun pass (password) (format *s* "pass ~a~%" password)) (defun reader (fd) (declare (ignore fd)) (let ((line (read-line *s*))) (format t "< ~a~%" line) (reader))) (defun add-reader () (sb-sys:add-fd-handler (sb-sys:fd-stream-fd *s*) :input (lambda (fd) (format t "input-handler: fd ~a~%" fd))))