online list, bugfixes

This commit is contained in:
Er2 2022-03-07 18:59:41 +03:00
parent 1e05869bd8
commit 370a6572ad
1 changed files with 19 additions and 8 deletions

View File

@ -53,15 +53,21 @@ end
function forc(fn, t, c)
if c == nil or c == true then
for k, v in pairs(cls) do
local k = 1
while k <= #cls do
local v = cls[k]
fn(v, k)
if v.closed then table.remove(cls, k) end
if v.closed then table.remove(cls, k)
else k = k + 1 end
end
end
if t then
for k, v in pairs(tmp) do
local k = 1
while k <= #tmp do
local v = tmp[k]
fn(v, k)
if v.closed then table.remove(tmp, k) end
if v.closed then table.remove(tmp, k)
else k = k + 1 end
end
end
end
@ -80,9 +86,12 @@ while runs do
elseif v.st == 1 then write (v, 'Username: ')
elseif v.st == 2 then write (v, 'Password: ')
elseif v.st == 3 then writeln(v, 'Welcome, '.. v.user ..'!')
local us = ''
for _, w in pairs(cls) do
writeln(w, '', '-- '.. v.user ..' joined --')
us = us.. w.user ..', '
end
writeln(v, 'Online: '.. us ..v.user)
v.st, v.reads = nil, nil
table.remove(tmp, k)
table.insert(cls, v)
@ -123,14 +132,16 @@ while runs do
elseif l == '/leave' then close(v)
elseif (l or ''):sub(1, 1) == '/'
then writeln(v, 'Unknown command')
end
elseif not (l or ''):match '^%s*$'
then forc(function(w)
if w == v then -- ignore yourself
if not (l or ''):match '^%s*$'
and (not l:sub(1, 1) == '/' or v.closed)
then for j, w in pairs(cls) do
if j == k then -- ignore yourself
elseif v.closed
then writeln(w, '', '-- '.. v.user ..' leaves --')
else writeln(w, '', v.user ..': '.. l)
end
end) end
end end
end, false, true)
end