Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- config--
- local channel = 210
- local my_chan = 0
- modem = peripheral.wrap("back")
- local user_name = ""
- local from_l = {}
- local msg_l = {}
- -- load api
- shell.run("delete caAPI")
- shell.run("pastebin get EDLdR1nF caAPI")
- os.loadAPI("caAPI")
- --set monitor
- function set_monitor()
- local monitor_number = caAPI.get_hardware("monitor")
- local found = fs.exists("config/monitor.cfg")
- if found == true then
- file = fs.open("config/monitor.cfg","r")
- local fileData = {}
- local line = file.readLine()
- repeat
- table.insert(fileData,line)
- line = file.readLine()
- until line == nil
- file.close()
- monitor_number = fileData[1]
- end
- mon = peripheral.wrap(monitor_number)
- end
- --set back chan
- function set_chan()
- my_chan = 1
- my_chan = my_chan + channel
- end
- --draw screen
- function draw_screen()
- mon.setBackgroundColor(colors.white)
- mon.setTextColor(colors.white)
- mon.clear()
- mon.setBackgroundColor(colors.white)
- mon.setCursorPos(1,1)
- mon.setBackgroundColor(colors.blue)
- mon.write("Mail Client 1.0 ")
- mon.setCursorPos(20,1)
- mon.write(user_name.."'s Mailbox")
- mon.setCursorPos(50,1)
- mon.setBackgroundColor(colors.red)
- mon.setTextColor(colors.black)
- mon.write("X")
- end
- --wr
- function wr()
- mon.setBackgroundColor(colors.black)
- mon.setCursorPos(1,4)
- mon.write(" ")
- mon.setCursorPos(1,26)
- mon.write(" ")
- mon.setCursorPos(1,6)
- mon.write(" ")
- mon.setCursorPos(1,8)
- mon.write(" ")
- for yi = 5,25 do
- mon.setCursorPos(1,yi)
- mon.write(" ")
- mon.setCursorPos(50,yi)
- mon.write(" ")
- yi = yi + 1
- end
- mon.setBackgroundColor(colors.black)
- mon.setTextColor(colors.white)
- mon.setCursorPos(18,4)
- mon.write("Write a mail")
- mon.setBackgroundColor(colors.white)
- mon.setTextColor(colors.black)
- mon.setCursorPos(2,5)
- mon.write("To:")
- to_s = read()
- mon.setCursorPos(2,7)
- from_s = user_name
- mon.write("From:"..from_s)
- mon.setCursorPos(2,9)
- mon.write("Message:")
- msg_s = read()
- msg_send = "send#"..to_s.."-"..from_s..":"..msg_s
- modem.transmit(channel,my_chan,msg_send)
- event, modemside, sendchan, replaychan, message, dist = os.pullEvent("modem_message")
- if message == "mail send" then
- mon.setBackgroundColor(colors.gray)
- mon.setCursorPos(14,9)
- mon.write(" ")
- mon.setCursorPos(14,10)
- mon.write(" ")
- mon.setCursorPos(14,11)
- mon.write(" ")
- mon.setCursorPos(17,10)
- mon.write("Mail was send")
- sleep(5)
- draw_screen()
- menu()
- end
- end
- -- load mail text
- function load_mail(ya)
- mon.setBackgroundColor(colors.gray)
- mon.setCursorPos(5,9)
- mon.write(" X")
- mon.setCursorPos(5,10)
- mon.write(" ")
- mon.setCursorPos(5,11)
- mon.write(" ")
- nx = ya - 5
- mon.setCursorPos(6,10)
- mon.write(msg_l[nx])
- sleep(5)
- powerb = true
- event,side,x,y = os.pullEvent()
- mon.setCursorPos(5,12)
- mon.write(x.."|"..y)
- if event == "monitor_touch" then
- if x == 50 and y == 1 then
- powerb = false
- ende()
- elseif x >= 4 and x <= 50 and y >= 4 and y <= 25 then
- powerb = false
- mon.setCursorPos(5,12)
- mon.write("Loading.....")
- sleep(5)
- draw_screen()
- menu()
- end
- if powerb == true then
- --error------------------------------------------------------
- load_mail(ya)
- end
- end
- end
- --delete all
- function delete_all()
- mon.setCursorPos(3,24)
- mon.write("Delete")
- msg_send = "delete#"..user_name
- modem.transmit(channel,my_chan,msg_send)
- event, modemside, sendchan, replaychan, message, dist = os.pullEvent("modem_message")
- if message == "deleted" then
- mon.setBackgroundColor(colors.gray)
- mon.setCursorPos(14,9)
- mon.write(" ")
- mon.setCursorPos(14,10)
- mon.write(" ")
- mon.setCursorPos(14,11)
- mon.write(" ")
- mon.setCursorPos(17,10)
- mon.write("All Mails deleted")
- sleep(5)
- draw_screen()
- menu()
- end
- end
- --inb
- function inb()
- from_l = {}
- msg_l = {}
- mon.setCursorPos(15,4)
- mon.write("Inbox")
- mon.setBackgroundColor(colors.black)
- mon.setCursorPos(1,4)
- mon.write(" ")
- mon.setCursorPos(1,26)
- mon.write(" ")
- for yi = 5,25 do
- mon.setCursorPos(1,yi)
- mon.write(" ")
- mon.setCursorPos(50,yi)
- mon.write(" ")
- yi = yi + 1
- end
- mon.setBackgroundColor(colors.black)
- mon.setTextColor(colors.white)
- mon.setCursorPos(18,4)
- mon.write("Inbox")
- mon.setBackgroundColor(colors.white)
- mon.setTextColor(colors.black)
- msg_send = "ask#"..user_name
- modem.transmit(channel,my_chan,msg_send)
- event, modemside, sendchan, replaychan, message, dist = os.pullEvent("modem_message")
- mon.setCursorPos(40,5)
- mon.write("Delete all")
- data = caAPI.split(message,"#")
- if #data >= 0 then
- for yi = 1,#data do
- dataB = caAPI.split(data[yi],":")
- table.insert(from_l,dataB[1])
- table.insert(msg_l,dataB[2])
- yi = yi + 1
- end
- local start_line = 6
- for xi = 1,#from_l do
- mon.setCursorPos(3,start_line)
- mon.write(from_l[xi])
- start_line = start_line + 1
- xi = xi + 1
- end
- end
- powerc = true
- event,side,x,y = os.pullEvent()
- if event == "monitor_touch" then
- if x == 50 and y == 1 then
- powerc = false
- ende()
- elseif x >= 1 and x <= 6 and y == 2 then
- powerc = false
- inb()
- elseif x >= 1 and x <= 14 and y == 3 then
- powerc = false
- wr()
- elseif y == 5 then
- delete_all()
- else
- load_mail(y)
- end
- end
- end
- --menu
- function menu()
- mon.setBackgroundColor(colors.white)
- mon.setCursorPos(1,2)
- mon.write("Inbox")
- mon.setCursorPos(1,3)
- mon.write("Write a Mail")
- touch()
- end
- --touch
- function touch()
- powera = true
- event,side,x,y = os.pullEvent()
- if event == "monitor_touch" then
- if x == 50 and y == 1 then
- powera = false
- ende()
- elseif x >= 1 and x <= 6 and y == 2 then
- powera = false
- inb()
- elseif x >= 1 and x <= 14 and y == 3 then
- powera = false
- wr()
- end
- if powera == true then
- --error------------------------------------------------------
- menu()
- end
- end
- end
- --ende
- function ende()
- shell.run("clear")
- end
- --login
- function login()
- mon.setBackgroundColor(colors.gray)
- mon.setCursorPos(14,9)
- mon.write(" ")
- mon.setCursorPos(14,10)
- mon.write(" ")
- mon.setCursorPos(14,11)
- mon.write(" ")
- mon.setCursorPos(14,12)
- mon.write(" ")
- mon.setCursorPos(14,13)
- mon.write(" ")
- mon.setCursorPos(20,9)
- mon.write("Login")
- mon.setCursorPos(15,10)
- mon.write("User Name:")
- nam = read()
- mon.setCursorPos(15,11)
- mon.write("Password:")
- pwd = read("*")
- mon.setCursorPos(15,12)
- mon.write("R=Register L=Login:")
- mode = read()
- local l_s = ""
- if mode == "R" then
- l_s = "reg#"..nam..":"..pwd
- elseif mode == "L" then
- l_s = "log#"..nam..":"..pwd
- end
- modem.transmit(channel,my_chan,l_s)
- user_name = nam
- mon.setBackgroundColor(colors.white)
- event, modemside, sendchan, replaychan, message, dist = os.pullEvent("modem_message")
- if message == "Register OK" then
- sleep(2)
- draw_screen()
- login()
- elseif message == "not found" then
- draw_screen()
- login()
- elseif message == "ok" then
- sleep(2)
- draw_screen()
- menu()
- end
- end
- --program--
- set_monitor()
- set_chan()
- modem.open(my_chan)
- draw_screen()
- login()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement