aboutsummaryrefslogtreecommitdiff
path: root/servers/experiments/cl-async/server.lisp
blob: 4c46ea00ebef77418bba3cf41e4e72543b0d1c2c (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
; Reference implementation of Internet Delay Chat servers
; Copyright (C) 2022  Andrew Yu <https://www.andrewyu.org>
; 
; This program is free software: you can redistribute it and/or modify
; it under the terms of the GNU Affero General Public License as
; published by the Free Software Foundation, either version 3 of the
; License, or (at your option) any later version.
; 
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
; GNU Affero General Public License for more details.
; 
; You should have received a copy of the GNU Affero General Public
; License along with this program.  If not,
; see <https://www.gnu.org/licenses/>.


(ql:quickload 'cl-async)

; users are alists
; '()

(defparameter *users* '(("andrew@andrewyu.org" . ((username . "andrew@andrewyu.org")
                                                  (password . "hunter2")))
                        ("luk3yx@andrewyu.org" . ((username . "luk3yx@andrewyu.org")
                                                  (password . "hunter2")))
                        ("hax@andrewyu.org" . ((username . "hax@andrewyu.org")
                                               (password . "hunter2")))))

(defun echo-server ()
  (as:tcp-server nil 5000
    (lambda (sock data) ; When a socket gets data
            (print data)
            (as:write-socket-data sock data))
    (lambda (ev) ; An event, such as an EOF or reset
            (format t "Event: ~a~%" ev)))

  (as:signal-handler as:+sigint+
    (lambda (sig)
            (declare (ignore sig))
            (as:exit-event-loop))))


(as:start-event-loop #'echo-server)