-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.l
executable file
·92 lines (68 loc) · 1.79 KB
/
client.l
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/picolisp /usr/lib/picolisp/lib.l
#
# picoSIP Internet Chat Client
#
# (c) Alexander Sharikhin
# 21 june 17
(load "@lib/misc.l")
# Starting params
(setq *Host (opt))
(setq *Port 4004)
(setq *Nick (opt))
(setq *Online NIL)
# Misc funcs
(de usage NIL
(prinl "client.l <host> <nick>")
(bye) )
(de get-line NIL
(pack (reverse *Line)) )
(de backspace NIL
(prin "^H ^H") )
(de clean-line NIL
(do (length *Line)
(backspace) ) )
(de termlog (Line)
(clean-line)
(prinl (tim$ (time)) " " Line)
(prin (get-line))
(flush) )
(de is-get (What)
(= What (in *Connection (line T))) )
(de send-message (Line)
(out *Connection (prinl Line))
(setq Splitted (chop Line))
(if (= "@" (car Splitted))
(termlog (cons "@" (cdr Splitted)))
(termlog (cons "Me> " Line)) ) )
(unless (and *Host *Nick) (usage))
(setq *Connection (connect *Host *Port))
(unless *Connection (quit (cons "Can't connect to " *Host)))
# AUTH state
(de auth-wait-loop NIL
(ifn (is-get "AUTH") (auth-wait-loop)) )
(auth-wait-loop)
(out *Connection (prinl *Nick) (flush))
(in *Connection (unless (is-get "OK") (quit "Auth failed")))
# Chatting state
(setq *Line NIL)
# Received messages
(task
*Connection
(in @
(setq
*In (chop (line T))
*Cmd (car *In)
*Str (pack (cdr *In)) )
(case *Cmd
("*" (termlog *Str))
("@" (termlog (pack "@" *Str)))
("+" (termlog (cons *Str " is online")) (push '*Online *Str))
("-" (termlog (cons *Str " is offline")) (del *Str '*Online)) ) ) )
(loop
(case (key)
("^[" (bye))
(("^H" "^?") (when *Line (backspace) (pop '*Line)))
(("^J" "^M")
(when *Line (send-message (get-line)) (clean-line) (off *Line)) )
(T (prin (push '*Line @))) ) )
(bye)