3 if [ -f "$chatfile" ]; then
4 read -r channelkey x <"$chatfile"
5 channelkey="$( printf '%s-%s' "$channelkey" "$SESSION_ID" |sha256sum)"
10 if mkdir "${_DATA}/${LOCATION}"; then
11 { randomid; printf ' '; STRING "$nickname"; echo; } >"$chatfile"
13 REDIRECT "$(URL "/$LOCATION")"
16 read lasttime x <<-EOFread
17 $(tail -n 50 "$chatfile" |grep -F " $(STRING "$nickname"): " |tail -n1)
19 if [ "$lasttime" ]; then
20 lasttime="$(date -d "${lasttime%_*} ${lasttime#*_}" +%s)"
24 if [ -f "$chatfile" -a "$channelkey" = "$(POST channelkey)" -a "$(POST timenonce)" -ge "$lasttime" ]; then
25 printf "%s %s: %s\n" "$(date +%F_%T)" "$(STRING "$nickname")" "$(POST message |STRING)" >>"$chatfile"
27 REDIRECT "$(URL "/$LOCATION")"
32 local nickfile="${chatfile%/channel}/nicks"
35 trap 'nicklist leave' INT QUIT
36 sed -i -E "/^${SESSION_KEY%%-*} /d" "$nickfile"
37 printf '%s %i %s\n' "${SESSION_KEY%%-*}" "$$" "$nickname" >>"$nickfile"
40 sed -i -E "/^${SESSION_KEY%%-*} $$ /d" "$nickfile"
44 nicklist='NICKNAMES: '
45 while read -r s p nick; do
46 [ -d "/proc/$p" ] && nicklist="${nicklist}/$nick/" \
47 || sed -i -E "/^$s $p /d" "$nickfile"
49 if ! tail -n20 "$chatfile" |tac |grep -m1 '^NICKNAMES: ' |grep -qxF "$nicklist"; then
50 printf '%s\n' "$nicklist" >>"$chatfile"
54 if [ ! -f "$chatfile" ]; then
55 yield_page create <<-EOF
56 [form #nonexist method="POST"
57 There is no channel named $(HTML "$LOCATION")
58 [submit "action" "create" Create]
64 printf '%s: %s\r\n' Refresh 1
66 [form #channel method="POST"
67 [submit "action" "submit" style="display: none;"]
68 [hidden "session_key" "%s"][hidden "channelkey" "%s"][hidden "timenonce" "%s"]
69 [a .settings href="?settings#nick" Settings][input autocomplete="off" name="message" autofocus=true][submit "action" "submit" Send!]
71 ' "$SESSION_KEY" "$channelkey" "$_DATE"
72 SHESCAPE='s;[]&<>#."[];\\&;g;'
74 while sleep 10; do printf '\n'; done &
76 tail --pid $$ -n50 -f "$chatfile" \
78 /^[0-9-]{10}_[0-9:]{8}+ [^ ]+ [^ ]+$/{
79 h; s;^([^ ]+) ([^ ]+) ([^ ]+)$;\1;; s;.*_;;; s;.+;[p .message [span .date &];p;
80 g; s;^([^ ]+) ([^ ]+) ([^ ]+)$;a\2;; bESC; :A s;.;;; s;(.)(.+);[span .nick [span .indicator \1]\2];p;
81 g; s;^([^ ]+) ([^ ]+) ([^ ]+)$;b\3;; bESC; :B s;.;;; s;.+;[span .message &]];p;
85 s;^NICKNAMES: ;;; h; s;^.*$;[div .nicklist [h2 Nicknames];p; g;
87 h; s;^/([^/]+)/.*$;c\1;; bESC :C
88 s;^.([^?])(.*)$;[a .nick href="/~\1\2" \1\2];p;
89 s;^.(\?)(.*)$;[span .nick [span .indcator \1]\2];p;
90 g; s;/[^/]+/;;; /.+/bNICKLIST s;^.*$;];p;
94 '"$UNSTRING"' '"$SHESCAPE"'
95 /^a/bA; /^b/bB; /^c/bC;