Legebatterie

Apps--sms

Dec 28th, 2018
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.55 KB | None | 0 0
  1. os.loadAPI("maxintosh/mAPI")
  2.  
  3. --Design
  4. term.setBackgroundColor(colors[col])
  5. term.clear()
  6.  
  7.  
  8. mAPI.drawWindow(2,2,colWind)
  9.  
  10. term.setBackgroundColor(colors[colWind])
  11. term.setTextColor(colors[colText])
  12. paintutils.drawBox(3,3,49,3,colors.white)
  13. paintutils.drawPixel(25,3,colors.black)
  14. term.setBackgroundColor(colors.white)
  15. term.setCursorPos(10,3)
  16. write("contacts")
  17. term.setCursorPos(35,3)
  18. write("chats")
  19.  
  20.  
  21.  
  22. --Click test
  23.  
  24. while true do
  25. event,n,x,y=os.pullEvent("mouse_click")
  26.  
  27. if x==50 and y==2 then
  28. error()
  29. end
  30.  
  31.  
  32. --Contacts
  33. if y==3 and x<25 then
  34.  
  35. paintutils.drawFilledBox(3,4,49,17,colors[colWind])
  36. term.setCursorPos(48,4)
  37. term.setTextColor(colors.black)
  38. term.setBackgroundColor(colors.green)
  39. write("+")
  40. term.setBackgroundColor(colors[colWind])
  41. term.setCursorPos(4,4)
  42. write("name")
  43. term.setCursorPos(21,4)
  44. write("ingame name")
  45. term.setCursorPos(44,4)
  46. write("ID")
  47.  
  48. --loading contacts
  49. Count=6
  50. yContact={}
  51. for id=1,100 do
  52. if fs.exists("maxintosh/"..currentUser.."/contacts/"..id) then
  53. file=fs.open("maxintosh/"..currentUser.."/contacts/"..id,"r")
  54. name=file.readLine()
  55. name=file.readLine()
  56. ingameName=file.readLine()
  57.  
  58. term.setCursorPos(4,Count)
  59. write(name)
  60. term.setCursorPos(22,Count)
  61. write(ingameName)
  62. term.setCursorPos(44,Count)
  63. write(id)
  64. term.setCursorPos(48,Count)
  65. write("x")
  66. yContact[Count]=id
  67. Count=Count+1
  68. file.close()
  69. end
  70. end
  71.  
  72. --click
  73. while true do
  74. event,n,x,y=os.pullEvent("mouse_click")
  75.  
  76. if x==50 and y==2 then
  77. error()
  78. end
  79.  
  80. if y==3 then
  81. shell.run(shell.getRunningProgram())
  82. error()
  83. end
  84.  
  85. if x==48 and not(y==4) then
  86. if yContact[y]==nil then
  87. else
  88.  
  89.  
  90. mAPI.drawWindow(4,4,colWind)
  91.  
  92. term.setTextColor(colors[colText])
  93. term.setBackgroundColor(colors[colWind])
  94.  
  95. term.setCursorPos(6,6)
  96. write("new name:")
  97. term.setCursorPos(6,8)
  98. write("new ingame name:")
  99. term.setCursorPos(6,10)
  100. write("new ID:")
  101. term.setCursorPos(23,14)
  102. write("delete")
  103.  
  104. file=fs.open("maxintosh/"..currentUser.."/contacts/"..yContact[y],"r")
  105. newID=file.readLine()
  106. oldID=newID
  107. newName=file.readLine()
  108. newIngame=file.readLine()
  109. file.close()
  110.  
  111. while true do
  112. event,n,x,y=os.pullEvent("mouse_click")
  113.  
  114. if x==48 and y==4 then
  115. fs.delete("maxintosh/"..currentUser.."/contacts/"..oldID)
  116. file=fs.open("maxintosh/"..currentUser.."/contacts/"..newID,"w")
  117. file.writeLine(newID)
  118. file.writeLine(newName)
  119. file.writeLine(newIngame)
  120. file.close()
  121. shell.run(shell.getRunningProgram())
  122. error()
  123. end
  124.  
  125. if y==6 then
  126. paintutils.drawBox(16,6,47,6,colors[colWind])
  127. term.setCursorPos(16,6)
  128. newName=read()
  129. end
  130.  
  131. if y==8 then
  132. paintutils.drawFilledBox(23,8,47,8,colors[colWind])
  133. term.setCursorPos(23,8)
  134. newIngame=read()
  135. end
  136.  
  137. if y==10 then
  138. paintutils.drawBox(14,10,47,10)
  139. term.setCursorPos(14,10)
  140. newID=read()
  141. end
  142.  
  143. if y==14 then
  144. fs.delete("maxintosh/"..currentUser.."/contacts/"..oldID)
  145. shell.run(shell.getRunningProgram())
  146. error()
  147. end
  148. end
  149. end
  150. end
  151.  
  152. if x==48 and y==4 then
  153.  
  154. if not(fs.exists("maxintosh/"..currentUser.."/contacts")) then
  155. fs.makeDir("maxintosh/"..currentUser.."/contacts")
  156. end
  157.  
  158.  
  159. mAPI.drawWindow(4,4,colWind)
  160.  
  161. term.setTextColor(colors[colText])
  162. term.setBackgroundColor(colors[colWind])
  163. term.setCursorPos(6,6)
  164. write("name:")
  165. term.setCursorPos(6,8)
  166. write("ingame name:")
  167. term.setCursorPos(6,10)
  168. write("ID:")
  169. term.setCursorPos(23,14)
  170. write("finish")
  171.  
  172. while true do
  173. event,n,x,y=os.pullEvent("mouse_click")
  174.  
  175. if x==48 and y==4 then
  176. shell.run(shell.getRunningProgram())
  177. error()
  178. end
  179.  
  180. if y==6 then
  181. paintutils.drawBox(12,6,47,6,colors[colWind])
  182. term.setCursorPos(12,6)
  183. newName=read()
  184. end
  185.  
  186. if y==8 then
  187. paintutils.drawBox(19,8,47,8,colors[colWind])
  188. term.setCursorPos(19,8)
  189. newIngame=read()
  190. end
  191.  
  192. if y==10 then
  193. paintutils.drawBox(10,10,47,10,colors[colWind])
  194. term.setCursorPos(10,10)
  195. newID=read()
  196. end
  197.  
  198. if y==14 then
  199. file=fs.open("maxintosh/"..currentUser.."/contacts/"..newID,"w")
  200. file.writeLine(newID)
  201. file.writeLine(newName)
  202. file.writeLine(newIngame)
  203. file.close()
  204. shell.run(shell.getRunningProgram())
  205. error()
  206. end
  207.  
  208. end
  209. end
  210. end
  211.  
  212.  
  213. end
  214.  
  215.  
  216.  
  217.  
  218. --Chats
  219. paintutils.drawFilledBox(3,4,49,17,colors[colWind])
  220. paintutils.drawFilledBox(3,4,18,17,colors.lightGray)
  221. paintutils.drawBox(18,4,18,17,colors.black)
  222. paintutils.drawBox(3,4,49,4,colors.black)
  223. term.setTextColor(colors.black)
  224.  
  225. --checking for new messages
  226. found=false
  227. notification={}
  228.  
  229. timer=os.startTimer(3)
  230. rednet.open("top")
  231. rednet.send(server,"receive")
  232.  
  233. while found==false do
  234. event,a,b=os.pullEvent()
  235.  
  236. if event=="timer" then
  237. term.setCursorPos(28,7)
  238. term.setBackgroundColor(colors.red)
  239. term.setTextColor(colors.black)
  240. write("no connection")
  241. found=true
  242.  
  243. elseif a==server and b=="noMsg" then
  244. found=true
  245. term.setCursorPos(27,7)
  246. term.setBackgroundColor(colors.green)
  247. term.setTextColor(colors.black)
  248. write("no new Messages")
  249.  
  250.  
  251. elseif a==server and not(b=="noMsg") then
  252. found=true
  253.  
  254. text={}
  255. text=b
  256.  
  257. event,a,b=os.pullEvent("rednet_message")
  258. fromid={}
  259. fromid=b
  260.  
  261. l=table.maxn(fromid)
  262. i=1
  263.  
  264. term.setCursorPos(27,7)
  265. term.setBackgroundColor(colors.green)
  266. term.setTextColor(colors.black)
  267. write(l.." new Messages")
  268.  
  269. while i<=l do
  270. file=fs.open("maxintosh/"..currentUser.."/contacts/chats/"..(tonumber(fromid[i])+0),"a")
  271. file.writeLine("r")
  272. file.writeLine(text[i])
  273. file.close()
  274. notification[fromid[i]+0]=true
  275. i=i+1
  276.  
  277. end
  278. end
  279. end
  280. rednet.close("top")
  281.  
  282. --loading contacts on left side
  283. yToID={}
  284. yCount=5
  285. for i=1,100 do
  286. if fs.exists("maxintosh/"..currentUser.."/contacts/"..i) then
  287. file=fs.open("maxintosh/"..currentUser.."/contacts/"..i,"r")
  288. name=file.readLine()
  289. name=file.readLine()
  290. file.close()
  291.  
  292. if notification[i]==true then
  293. paintutils.drawPixel(2,yCount,colors.green)
  294. else
  295. paintutils.drawPixel(2,yCount,colors.black)
  296. end
  297.  
  298. if math.fmod(yCount,2)==0 then
  299. term.setBackgroundColor(colors.blue)
  300. paintutils.drawBox(3,yCount,17,yCount,colors.blue)
  301. else
  302. term.setBackgroundColor(colors.lightBlue)
  303. paintutils.drawBox(3,yCount,17,yCount,colors.lightBlue)
  304. end
  305.  
  306. term.setCursorPos(3.5,yCount)
  307. write(name)
  308. yToID[yCount]=i
  309. yCount=yCount+1
  310. end
  311. end
  312.  
  313.  
  314. --click
  315.  
  316. while true do
  317. event,n,x,y=os.pullEvent("mouse_click")
  318.  
  319. --X
  320. if x==50 and y==2 then
  321. error()
  322. end
  323.  
  324. --Oben
  325. if y==3 then
  326. shell.run(shell.getRunningProgram())
  327. error()
  328. end
  329.  
  330. --chat-Leiste links
  331. if x>2 and x<19 then
  332.  
  333. paintutils.drawPixel(2,y,colors.black)
  334.  
  335. id=yToID[y]
  336. f=fs.open("maxintosh/"..currentUser.."/contacts/"..id,"r")
  337. cID=f.readLine()
  338. cName=f.readLine()
  339. cIngame=f.readLine()
  340. f.close()
  341.  
  342. paintutils.drawFilledBox(19,5,49,17,colors[colWind])
  343.  
  344. paintutils.drawBox(19,5,49,5,colors.white)
  345. lenght=string.len(cName)
  346. term.setCursorPos((math.floor((30-lenght)/2)+19),5)
  347. term.setBackgroundColor(colors.white)
  348. term.setTextColor(colors.orange)
  349. write(cName)
  350.  
  351. term.setCursorPos(44,5)
  352. term.setTextColor(colors.red)
  353. write("clear")
  354.  
  355. paintutils.drawBox(19,17,49,17,colors.lightGray)
  356. term.setTextColor(colors.white)
  357. term.setBackgroundColor(colors.lightGray)
  358. term.setCursorPos(30,17)
  359. write("--type--")
  360.  
  361. if fs.exists("maxintosh/"..currentUser.."/contacts/chats/"..cID) then
  362. else
  363. file=fs.open("maxintosh/"..currentUser.."/contacts/chats/"..cID,"a")
  364. file.writeLine("a")
  365. file.writeLine("start of the chat")
  366. file.close()
  367. end
  368.  
  369. chatDataFrom={}
  370. chatDataText={}
  371.  
  372. f=fs.open("maxintosh/"..currentUser.."/contacts/chats/"..cID,"r")
  373.  
  374. chatDataFrom[1]=f.readLine()
  375. chatDataText[1]=f.readLine()
  376. i=2
  377.  
  378. while not(chatDataFrom[i-1]==nil) do
  379. chatDataFrom[i]=f.readLine()
  380. chatDataText[i]=f.readLine()
  381. i=i+1
  382. end
  383. f.close()
  384.  
  385. maxMsg=i-2
  386.  
  387. while maxMsg>0 do
  388.  
  389. if chatDataFrom[maxMsg]=="s" then
  390. term.setBackgroundColor(colors.green)
  391. textLenght=string.len(chatDataText[maxMsg])
  392. add=31-textLenght
  393. elseif chatDataFrom[maxMsg]=="r" then
  394. term.setBackgroundColor(colors.white)
  395. add=0
  396. else
  397. term.setBackgroundColor(colors.red)
  398. add=7
  399. end
  400.  
  401. term.setCursorPos(19+add,maxMsg+5)
  402. term.setTextColor(colors.black)
  403. write(chatDataText[maxMsg])
  404. maxMsg=maxMsg-1
  405.  
  406. end
  407.  
  408.  
  409. event,n,x,y=os.pullEvent("mouse_click")
  410.  
  411. if x>18 and y==17 then
  412. paintutils.drawBox(19,17,49,17,colors.white)
  413. term.setBackgroundColor(colors.white)
  414. term.setTextColor(colors.black)
  415. term.setCursorPos(20,17)
  416. insertedMsg=read()
  417. rednet.open("top")
  418. rednet.send(server,"send")
  419. rednet.send(server,cID)
  420. rednet.send(server,insertedMsg)
  421. rednet.close("top")
  422. paintutils.drawBox(19,17,49,17,colors.lightGray)
  423.  
  424. f=fs.open("maxintosh/"..currentUser.."/contacts/chats/"..cID,"a")
  425. f.writeLine("s")
  426. f.writeLine(insertedMsg)
  427. f.close()
  428. end
  429.  
  430. if x==50 and y==2 then
  431. error()
  432. end
  433.  
  434. if x>43 and y==5 then
  435. fs.delete("maxintosh/"..currentUser.."/contacts/chats/"..cID)
  436. end
  437.  
  438.  
  439.  
  440.  
  441. end
  442. end
  443.  
  444.  
  445. end
Advertisement
Add Comment
Please, Sign In to add comment