Advertisement
cyber_Ahn

Mail Client

Feb 8th, 2016
593
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.25 KB | None | 0 0
  1. -- config--
  2. local channel = 210
  3. local my_chan = 0
  4. modem = peripheral.wrap("back")
  5. local user_name = ""
  6. local from_l = {}
  7. local msg_l = {}
  8. -- load api
  9. shell.run("delete caAPI")
  10. shell.run("pastebin get EDLdR1nF caAPI")
  11. os.loadAPI("caAPI")
  12. --set monitor
  13. function set_monitor()
  14. local monitor_number = caAPI.get_hardware("monitor")
  15. local found = fs.exists("config/monitor.cfg")
  16. if found == true then
  17. file = fs.open("config/monitor.cfg","r")
  18. local fileData = {}
  19. local line = file.readLine()
  20. repeat
  21. table.insert(fileData,line)
  22. line = file.readLine()
  23. until line == nil
  24. file.close()
  25. monitor_number = fileData[1]
  26. end
  27. mon = peripheral.wrap(monitor_number)
  28. end
  29. --set back chan
  30. function set_chan()
  31. my_chan = 1
  32. my_chan = my_chan + channel
  33. end
  34. --draw screen
  35. function draw_screen()
  36. mon.setBackgroundColor(colors.white)
  37. mon.setTextColor(colors.white)
  38. mon.clear()
  39. mon.setBackgroundColor(colors.white)
  40. mon.setCursorPos(1,1)
  41. mon.setBackgroundColor(colors.blue)
  42. mon.write("Mail Client 1.0                                  ")
  43. mon.setCursorPos(20,1)
  44. mon.write(user_name.."'s Mailbox")
  45. mon.setCursorPos(50,1)
  46. mon.setBackgroundColor(colors.red)
  47. mon.setTextColor(colors.black)
  48. mon.write("X")
  49. end
  50. --wr
  51. function wr()
  52. mon.setBackgroundColor(colors.black)
  53. mon.setCursorPos(1,4)
  54. mon.write("                                                  ")
  55. mon.setCursorPos(1,26)
  56. mon.write("                                                  ")
  57. mon.setCursorPos(1,6)
  58. mon.write("                                                  ")
  59. mon.setCursorPos(1,8)
  60. mon.write("                                                  ")
  61. for yi = 5,25 do
  62. mon.setCursorPos(1,yi)
  63. mon.write(" ")
  64. mon.setCursorPos(50,yi)
  65. mon.write(" ")
  66. yi = yi + 1
  67. end
  68. mon.setBackgroundColor(colors.black)
  69. mon.setTextColor(colors.white)
  70. mon.setCursorPos(18,4)
  71. mon.write("Write a mail")
  72. mon.setBackgroundColor(colors.white)
  73. mon.setTextColor(colors.black)
  74. mon.setCursorPos(2,5)
  75. mon.write("To:")
  76. to_s = read()
  77. mon.setCursorPos(2,7)
  78. from_s = user_name
  79. mon.write("From:"..from_s)
  80. mon.setCursorPos(2,9)
  81. mon.write("Message:")
  82. msg_s = read()
  83. msg_send = "send#"..to_s.."-"..from_s..":"..msg_s
  84. modem.transmit(channel,my_chan,msg_send)
  85. event, modemside, sendchan, replaychan, message, dist = os.pullEvent("modem_message")
  86. if message == "mail send" then
  87. mon.setBackgroundColor(colors.gray)
  88. mon.setCursorPos(14,9)
  89. mon.write("                     ")
  90. mon.setCursorPos(14,10)
  91. mon.write("                     ")
  92. mon.setCursorPos(14,11)
  93. mon.write("                     ")
  94. mon.setCursorPos(17,10)
  95. mon.write("Mail was send")
  96. sleep(5)
  97. draw_screen()
  98. menu()
  99. end
  100. end
  101. -- load mail text
  102. function load_mail(ya)
  103. mon.setBackgroundColor(colors.gray)
  104. mon.setCursorPos(5,9)
  105. mon.write("                                           X")
  106. mon.setCursorPos(5,10)
  107. mon.write("                                            ")
  108. mon.setCursorPos(5,11)
  109. mon.write("                                            ")
  110. nx = ya - 5
  111. mon.setCursorPos(6,10)
  112. mon.write(msg_l[nx])
  113. sleep(5)
  114. powerb = true
  115. event,side,x,y = os.pullEvent()
  116. mon.setCursorPos(5,12)
  117. mon.write(x.."|"..y)
  118. if event == "monitor_touch" then
  119. if x == 50 and y == 1 then
  120. powerb = false
  121. ende()
  122. elseif x >= 4 and x <= 50 and y >= 4 and y <= 25 then
  123. powerb = false
  124. mon.setCursorPos(5,12)
  125. mon.write("Loading.....")
  126. sleep(5)
  127. draw_screen()
  128. menu()
  129. end
  130. if powerb == true then
  131. --error------------------------------------------------------
  132. load_mail(ya)
  133. end
  134. end
  135. end
  136. --delete all
  137. function delete_all()
  138. mon.setCursorPos(3,24)
  139. mon.write("Delete")
  140. msg_send = "delete#"..user_name
  141. modem.transmit(channel,my_chan,msg_send)
  142. event, modemside, sendchan, replaychan, message, dist = os.pullEvent("modem_message")
  143. if message == "deleted" then
  144. mon.setBackgroundColor(colors.gray)
  145. mon.setCursorPos(14,9)
  146. mon.write("                     ")
  147. mon.setCursorPos(14,10)
  148. mon.write("                     ")
  149. mon.setCursorPos(14,11)
  150. mon.write("                     ")
  151. mon.setCursorPos(17,10)
  152. mon.write("All Mails deleted")
  153. sleep(5)
  154. draw_screen()
  155. menu()
  156. end
  157. end
  158. --inb
  159. function inb()
  160. from_l = {}
  161. msg_l = {}
  162. mon.setCursorPos(15,4)
  163. mon.write("Inbox")
  164. mon.setBackgroundColor(colors.black)
  165. mon.setCursorPos(1,4)
  166. mon.write("                                                  ")
  167. mon.setCursorPos(1,26)
  168. mon.write("                                                  ")
  169. for yi = 5,25 do
  170. mon.setCursorPos(1,yi)
  171. mon.write(" ")
  172. mon.setCursorPos(50,yi)
  173. mon.write(" ")
  174. yi = yi + 1
  175. end
  176. mon.setBackgroundColor(colors.black)
  177. mon.setTextColor(colors.white)
  178. mon.setCursorPos(18,4)
  179. mon.write("Inbox")
  180. mon.setBackgroundColor(colors.white)
  181. mon.setTextColor(colors.black)
  182. msg_send = "ask#"..user_name
  183. modem.transmit(channel,my_chan,msg_send)
  184. event, modemside, sendchan, replaychan, message, dist = os.pullEvent("modem_message")
  185. mon.setCursorPos(40,5)
  186. mon.write("Delete all")
  187. data = caAPI.split(message,"#")
  188. if #data >= 0 then
  189. for yi = 1,#data do
  190. dataB = caAPI.split(data[yi],":")
  191. table.insert(from_l,dataB[1])
  192. table.insert(msg_l,dataB[2])
  193. yi = yi + 1
  194. end
  195. local start_line = 6
  196. for xi = 1,#from_l do
  197. mon.setCursorPos(3,start_line)
  198. mon.write(from_l[xi])
  199. start_line = start_line + 1
  200. xi = xi + 1
  201. end
  202. end
  203. powerc = true
  204. event,side,x,y = os.pullEvent()
  205. if event == "monitor_touch" then
  206. if x == 50 and y == 1 then
  207. powerc = false
  208. ende()
  209. elseif x >= 1 and x <= 6 and y == 2 then
  210. powerc = false
  211. inb()
  212. elseif x >= 1 and x <= 14 and y == 3 then
  213. powerc = false
  214. wr()
  215. elseif y == 5 then
  216. delete_all()
  217. else
  218. load_mail(y)
  219. end
  220. end
  221. end
  222. --menu
  223. function menu()
  224. mon.setBackgroundColor(colors.white)
  225. mon.setCursorPos(1,2)
  226. mon.write("Inbox")
  227. mon.setCursorPos(1,3)
  228. mon.write("Write a Mail")
  229. touch()
  230. end
  231. --touch
  232. function touch()
  233. powera = true
  234. event,side,x,y = os.pullEvent()
  235. if event == "monitor_touch" then
  236. if x == 50 and y == 1 then
  237. powera = false
  238. ende()
  239. elseif x >= 1 and x <= 6 and y == 2 then
  240. powera = false
  241. inb()
  242. elseif x >= 1 and x <= 14 and y == 3 then
  243. powera = false
  244. wr()
  245. end
  246. if powera == true then
  247. --error------------------------------------------------------
  248. menu()
  249. end
  250. end
  251. end
  252. --ende
  253. function ende()
  254. shell.run("clear")
  255. end
  256. --login
  257. function login()
  258. mon.setBackgroundColor(colors.gray)
  259. mon.setCursorPos(14,9)
  260. mon.write("                     ")
  261. mon.setCursorPos(14,10)
  262. mon.write("                     ")
  263. mon.setCursorPos(14,11)
  264. mon.write("                     ")
  265. mon.setCursorPos(14,12)
  266. mon.write("                     ")
  267. mon.setCursorPos(14,13)
  268. mon.write("                     ")
  269. mon.setCursorPos(20,9)
  270. mon.write("Login")
  271. mon.setCursorPos(15,10)
  272. mon.write("User Name:")
  273. nam = read()
  274. mon.setCursorPos(15,11)
  275. mon.write("Password:")
  276. pwd = read("*")
  277. mon.setCursorPos(15,12)
  278. mon.write("R=Register L=Login:")
  279. mode = read()
  280. local l_s = ""
  281. if mode == "R" then
  282. l_s = "reg#"..nam..":"..pwd
  283. elseif mode == "L" then
  284. l_s = "log#"..nam..":"..pwd
  285. end
  286. modem.transmit(channel,my_chan,l_s)
  287. user_name = nam
  288. mon.setBackgroundColor(colors.white)
  289. event, modemside, sendchan, replaychan, message, dist = os.pullEvent("modem_message")
  290. if message == "Register OK" then
  291. sleep(2)
  292. draw_screen()
  293. login()
  294. elseif message == "not found" then
  295. draw_screen()
  296. login()
  297. elseif message == "ok" then
  298. sleep(2)
  299. draw_screen()
  300. menu()
  301. end
  302. end
  303. --program--
  304. set_monitor()
  305. set_chan()
  306. modem.open(my_chan)
  307. draw_screen()
  308. login()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement