blob: d9de3b0f6ffc4483190d156e6a106532c73c95a4 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
(defvar *terminate-program* nil)
(defconstant +bold+ "[1m")
(defconstant +unbold+ "[0m")
(defconstant +q+ #\")
(defclass <avatar> () ((name :accessor name)
(playing :reader playing :initform nil)
(password :accessor password)))
(defvar *avatars* '())
(defvar *write-avatars* nil)
(defclass <connection> () ((g :reader g)
(socket :reader socket)
(parser :reader parser)
(avatar :reader avatar)
(r :reader r)))
(defvar *connections* '())
(defconstant +port-number+ 6565)
(defconstant +vd-type+ (vector 'n 's 'e 'w
'u 'd))
(defclass <room> () ((name :reader name)
(desc :reader desc)
(exits :reader exits)))
(defvar *rooms* '())
(defvar *write-rooms* nil)
(defconstant +command-type+ (vector 'say 'help 'quit 'look
'rooms 'make-room 'make-door 'teleport
'n 's 'e 'w
'u 'd 'password 'shutdown))
(defconstant +name-prompt+ "Please enter your character name:")
(defconstant +rdb+ "room.tam")
(defconstant +adb+ "avatar.tam")
;; TODO: should I use print-object & the reader for serialisation?
(defun read-room-database ()
(with-open-file (file +rdb+ :direction :input)
))
(defun write-room-database ()
(with-open-file (file +rdb+ :direction output)
(mapcar (lambda (r)
(format file "~A~%"
(defun read-avatar-database ()
(setq *avatars* '())
(with-open-file (file +adb+ :direction :input)
(do ((name (read-line file nil nil))
(password (read-line file nil nil)))
((or (null name) (null password)))
(let ((a (make-instance (find-class '<avatar>))))
(setf (name a) name)
(setf (password a) password)
(setq *avatars* (cons a *avatars*)))))
(setq *write-avatars* nil))
(defun write-avatar-database ()
(with-open-file (file +adb+ :direction output)
(mapcar (lambda (a) (format file "~A~%~A~%" (name a) (password a))) *avatars*)))
(read-avatar-database)
(read-room-database)
(while (not *terminate-program*)
(check-for-inputs))
|