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 'sed -i -E "/^${SESSION_KEY%%-*} $$ /d" "$nickfile"' 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 nicklist="${nicklist}/$nick/"
48 if ! tail -n20 "$chatfile" |grep -qxF "$nicklist"; then
49 printf '%s\n' "$nicklist" >>"$chatfile"
53 if [ ! -f "$chatfile" ]; then
54 yield_page create <<-EOF
55 [form #nonexist method="POST"
56 There is no channel named $(HTML "$LOCATION")
57 [submit "action" "create" Create]
63 printf '%s: %s\r\n' Refresh 1
65 [form #channel method="POST"
66 [submit "action" "submit" style="display: none;"]
67 [hidden "session_key" "%s"][hidden "channelkey" "%s"][hidden "timenonce" "%s"]
68 [a .settings href="?settings#nick" Settings][input autocomplete="off" name="message" autofocus=true][submit "action" "submit" Send!]
70 ' "$SESSION_KEY" "$channelkey" "$_DATE"
71 SHESCAPE='s;[]&<>#."[];\\&;g;'
73 while sleep 10; do printf '\n'; done &
75 tail --pid $$ -n50 -f "$chatfile" \
77 /^[0-9-]{10}_[0-9:]{8}+ [^ ]+ [^ ]+$/{
78 h; s;^([^ ]+) ([^ ]+) ([^ ]+)$;\1;; s;.*_;;; s;.+;[p .message [span .date &];p;
79 g; s;^([^ ]+) ([^ ]+) ([^ ]+)$;a\2;; bESC; :A s;.;;; s;(.)(.+);[span .nick [span .indicator \1]\2];p;
80 g; s;^([^ ]+) ([^ ]+) ([^ ]+)$;b\3;; bESC; :B s;.;;; s;.+;[span .message &]];p;
84 s;^NICKNAMES: ;;; h; s;^.*$;[div .nicklist [h2 Nicknames];p; g;
86 h; s;^/([^/]+)/.*$;c\1;; bESC :C
87 s;^.([^?])(.*)$;[a .nick href="/~\1\2" \1\2];p;
88 s;^.(\?)(.*)$;[span .nick [span .indcator \1]\2];p;
89 g; s;/[^/]+/;;; /.+/bNICKLIST s;^.*$;];p;
93 '"$UNSTRING"' '"$SHESCAPE"'
94 /^a/bA; /^b/bB; /^c/bC;