Newest version, still unable to connect :/ Can anyone help?
local side="back"
local nickname="Terminal"
local users={{nickname, os.computerID()}}
local server="Server"
function change_nickname(a)
nickname=a
return true
end
function change_server(a)
server=a
return true
end
function user_set(a)
users=a
end
function user_print()
for i=1, #users, 1 do
print(users[i][1], users[i][2])
end
end
function user_get()
rednet.broadcast("users")
local a,b,c=os.pullEvent("rednet_message")
while c~="users_list" do a,b,c=os.pullEvent("rednet_message") end
local a, b, c=os.pullEventRaw()
while a~="rednet_message" or b~=user_resolve(server) or c~="messageT" do a, b, c=os.pullEventRaw() end
users=receiveT(user_resolve(server))
return true
end
function user_send(:unsure:/>/>/>
rednet.send(b, "users_list")
sendT(b, users)
end
function user_add(B)/>/>/>
local a,d,c=os.pullEventRaw()
while a~="rednet_message" or d~=b do a,d,c=os.pullEventRaw() end
local tmp={c, b}
table.insert(users, tmp)
return true
end
function user_del(B)/>/>/>
for i=1, #users, 1 do
local tmp=users[i]
if tmp[1]==b then table.remove(users, i)end
end
user_sort()
end
function user_sort()
table.sort(users, tcomp())
end
function user_resolve(B)/>/>/>
for i=1, #users, 1 do
local tmp=users[i]
if tmp[2]==b then return tmp[1] end
end
return false
end
function tcomp(a ,B)/>/>/>
if a[1]<b[1] then return true else return false end
end
function setSide(a)
side=a
return true
end
function join()
rednet.open(side)
rednet.broadcast("join")
sleep(0.1)
rednet.broadcast(nickname)
if nickname~=server then user_get() end
return true
end
function leave()
rednet.broadcast("leave")
rednet.close()
return true
end
function sendS(a, m)
rednet.send(a, "messageS")
sleep(0.1)
rednet.send(a, m)
return true
end
function sendT(a, m)
rednet.send(a, "messageT")
sleep(0.1)
rednet.send(a, #m)
for i=1, #m, 1 do
rednet.send(a, m[i])
end
return true
end
function receive(a,b,c)
while a=="rednet_message" do
if c~="join" and c~="leave" and c~="messageS" and c~="messageT" then return b,c end
if c=="join" then user_add(B)/>/>/> end
if c=="messageS" then coroutine.yield(receiveS(B)/>/>/>) end
if c=="messageT" then coroutine.yield(receiveT(B)/>/>/>) end
if c=="leave" then user_del(B)/>/>/> end
if c=="users" then user_send(B)/>/>/> end
end
end
function receiveS(B)/>/>/>
local a,d,c=os.pullEventRaw()
while a~="rednet_message" or d~=b do local a,d,c=os.pullEventRaw() end
return c
end
function receiveT(B)/>/>/>
local tmp={}
local a,d,c=os.pullEventRaw()
while a~="rednet_message" or d~=b do local a,d,c=os.pullEventRaw() end
for i=1, c, 1 do
table.insert(tmp, e)
local a,d,e=os.pullEventRaw()
while a~="rednet_message" or d~=b do local a,d,c=os.pullEventRaw() end
end
return tmp
end
function send(a, m)
a=user_resolve(a)
sendS(a, m)
end
function run()
while true do
local a, b, c=os.pullEventRaw()
if a=="key" and b==205 then
print("Do you really want to exit?")
if ui.yN() then
return true
end
end
if a=="key" and b==14 then
write("Enter nickname") local tmp1=read() write("Enter Message") local tmp2=read() send(tmp1, tmp2) print("")
end
if a=="rednet_message" then receive(a,b,c) end
end
end
function start()
join()
run()
leave()
end
function startServer()
change_nickname(server)
user_set({{nickname, os.computerID()}})
run()
leave()
end