DelChat features
2 way and conference chat.
the ability to send and recieve multiple messages (dosent require a send then recieve)
auto adjusting screen size
user names
v1.1.0
Spoiler
CodeSpoiler
local functionStack = {}
local chat = {}
local users = {}
-- config
chat[0] = "Welcome To DelChat"
local bar = "-" --character the header/footer of input section
-- end
local hScreen, vScreen = term.getSize()
local update = true
local loc = vScreen - 1
local cache = 1
local devider = bar
local localuser
function menu()
term.clear()
term.setCursorPos(1, 1)
print("Enter Your Username:")
localuser = read()
end
function clear()
for i=2, hScreen do
devider = devider .. bar
end
header = vScreen - 2
term.clear()
term.setCursorPos(1, header)
term.write(devider)
term.setCursorPos(1, vScreen)
term.write(devider)
term.setCursorPos(1, loc)
end
function openModem()
sides = rs.getSides()
for index, side in pairs(sides) do
if peripheral.isPresent(sides[index]) and peripheral.getType(sides[index]) == "modem" then
rednet.open(sides[index])
return
end
end
error("No modem found to perform rednet reception.")
end
function getUser(i)
if users[i] == nil then
rednet.send(i, "/userRequest")
id, msg = rednet.receive(10)
if id == nil then
error("No response from client")
else
users[i] = msg
end
end
return users[i]
end
function receiveChat()
while true do
id, message = rednet.receive()
if message == "/userRequest" then
rednet.send(id, tostring(localuser))
else
uName = getUser(id)
if uName == nil then
chat[cache] = "From " .. id .. ": " .. message
else
chat[cache] = uName .. ": " .. message
end
cache = cache + 1
update = true
end
end
end
function sendChat()
while true do
term.setCursorPos(1, loc)
term.clearLine()
send = read()
rednet.broadcast(send)
chat[cache] = localuser .. ": " .. send
cache = cache + 1
update = true
end
end
function display()
while true do
if update == true then
term.setCursorPos(1, 1)
screen = vScreen - 4
line = cache - screen
if line < 0 then
line = 0
end
for i=0, screen do
term.clearLine()
print(chat[line + i])
end
term.setCursorPos(1, loc)
update = false
else
sleep(0.25)
end
end
end
table.insert(functionStack, receiveChat)
table.insert(functionStack, sendChat)
table.insert(functionStack, display)
menu()
openModem()
clear()
while true do
parallel.waitForAny(unpack(functionStack))
end
Download
Spoiler
http://pastebin.com/79YqqanFScreenshots
Spoiler
codeSpoiler
local functionStack = {}
local chat = {}
-- config
chat[0] = "Welcome To DelChat"
local bar = "-" --character the header/footer of input section
-- end
local screensizeh, screensizev = term.getSize()
local update = true
local location = screensizev - 1
local cache = 1
local devider = bar
function clear()
for i=2, screensizeh do
devider = devider .. bar
end
header = screensizev - 2
term.clear()
term.setCursorPos(1, header)
term.write(devider)
term.setCursorPos(1, screensizev)
term.write(devider)
end
function openModem()
local sides = rs.getSides()
for index, side in pairs(sides) do
if peripheral.isPresent(sides[index]) and peripheral.getType(sides[index]) == "modem" then
rednet.open(sides[index])
return
end
end
error("No modem found to perform rednet reception.")
end
function receiveChat()
while true do
id, message = rednet.receive()
chat[cache] = "From " .. id .. ": " .. message
cache = cache + 1
update = true
end
end
function sendChat()
while true do
term.setCursorPos(1, location)
term.clearLine()
send = read()
rednet.broadcast(send)
chat[cache] = "Sent: " .. send
cache = cache + 1
update = true
end
end
function display()
while true do
if update == true then
term.setCursorPos(1, 1)
screen = screensizev - 4
line = cache - screen
if line &lt; 0 then
line = 0
end
for i=0, screen do
term.clearLine()
print(chat[line + i])
end
term.setCursorPos(1, location)
update = false
else
sleep(0.25)
end
end
end
--table.insert(functionStack, function() shell.run("shell") end)
table.insert(functionStack, receiveChat)
table.insert(functionStack, sendChat)
table.insert(functionStack, display)
clear()
openModem()
while true do
parallel.waitForAny(unpack(functionStack))
end
Screenshot
Secure private chat
A exit button (any tips on this would be helpful)
Advanced computer compatibility