Advertisement
xXm0dzXx

Untitled

Apr 15th, 2012
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.71 KB | None | 0 0
  1. rednet.open("right")
  2. rednet.open("left")
  3. rednet.open("bottom")
  4. rednet.open("top")
  5. rednet.open("back")
  6. rednet.open("front")
  7.  
  8. local channel = "";
  9. local user = "";
  10. local ip = os.computerID()
  11. local x2,y2 = term.getCursorPos()
  12. local channelID = 0;
  13. local chatHistory = ""
  14. local messages = 4;
  15. local opmode = false;
  16. local kkmode = false;
  17. local isChatter = false;
  18. local deopmode = false;
  19. local oldUser = ""
  20. local function cPrint(text)
  21. local x,y = term.getSize()
  22. x2,y2 = term.getCursorPos()
  23. term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2)
  24. write(text)
  25. end
  26.  
  27. term.clear()
  28. term.setCursorPos(1,1)
  29.  
  30. function status()
  31. print("Status: " ..channel)
  32. print("--------------------------------")
  33. end
  34.  
  35. function chatbox()
  36. term.clear()
  37. term.setCursorPos(1,1)
  38. status()
  39. print("[" ..channel.. "] "..user.." joined the server!")
  40. while true do
  41. local e, pie, test = os.pullEvent()
  42. if e == "rednet_message" then
  43. if test == "ping" then
  44. rednet.send(pie, channel)
  45. elseif test == "pinged " ..channel then
  46. rednet.send(pie, "hehehoohoohaha")
  47. else
  48. rednet.send(pie, "ping")
  49. id, message = rednet.receive()
  50. if message == channel then
  51. if(test == "["..channel.."] /op " ..user)then
  52. oldUser = user
  53. user = "@" .. user
  54. isChatter = true
  55. rednet.broadcast("*" ..user.. " is now OP!")
  56. term.setCursorPos(1, messages)
  57. messages = messages +1
  58. print("You are now OP!")
  59. elseif(test == "["..channel.."] /deop " ..user)then
  60. rednet.broadcast("*" ..user.. " is no longer OP!")
  61. user = oldUser
  62. isChatter = false
  63. term.setCursorPos(1, messages)
  64. messages = messages +1
  65. print("You are no longer OP!")
  66. elseif(test == "["..channel.."] /kick " ..user)then
  67. rednet.broadcast("*" ..user.. " left.")
  68. menu()
  69. elseif(test == "["..channel.."] /ls")then
  70. rednet.send(pie, "[List:] " ..user)
  71. end
  72. local x,y = term.getSize()
  73. if messages < y then
  74. term.setCursorPos(1, messages)
  75. messages = messages +1
  76. print(test)
  77. else
  78. term.clear()
  79. term.setCursorPos(1,1)
  80. status()
  81. messages = 3
  82. term.setCursorPos(1, messages)
  83. messages = messages +1
  84. print(test)
  85. end
  86. end
  87. end
  88. elseif e == "char" then
  89. local x,y = term.getSize()
  90. term.setCursorPos(1, y)
  91. chatHistory = chatHistory.. "" ..pie
  92. term.clearLine()
  93. write(chatHistory)
  94. elseif e == "key" and pie == 28 or pie == 14 then
  95. if pie == 28 then
  96. if chatHistory == "/exit" then
  97. rednet.broadcast("*" ..user.. " left.")
  98. channel = ""
  99. user = ""
  100. messages = 4;
  101. chatHistory = ""
  102. menu()
  103. elseif chatHistory == "/ping" then
  104. term.setCursorPos(1, messages)
  105. messages = messages +1
  106. print("[" ..channel.. "] Pong")
  107. elseif chatHistory == "/help" then
  108. term.setCursorPos(1, messages)
  109. messages = messages +1
  110. if isChatter == true then
  111. print("[" ..channel.. "] Commands: /help, /ping, /exit, /op, /kick, /ls")
  112. else
  113. print("[" ..channel.. "] Commands: /help, /ping, /exit, /ls")
  114. end
  115. else
  116. if isChatter == true then
  117. if opmode == true then
  118. rednet.broadcast("["..channel.."] " ..chatHistory)
  119. term.setCursorPos(1, messages)
  120. messages = messages +1
  121. print("["..channel.."] " ..chatHistory)
  122. elseif kkmode == true then
  123. rednet.broadcast("["..channel.."] " ..chatHistory)
  124. term.setCursorPos(1, messages)
  125. messages = messages +1
  126. print("["..channel.."] " ..chatHistory)
  127. elseif deopmode == true then
  128. rednet.broadcast("["..channel.."] " ..chatHistory)
  129. term.setCursorPos(1, messages)
  130. messages = messages +1
  131. print("["..channel.."] " ..chatHistory)
  132. else
  133. rednet.broadcast("[" ..user.. "] " ..chatHistory)
  134. term.setCursorPos(1, messages)
  135. messages = messages +1
  136. print("[" ..user.. "] " ..chatHistory)
  137. end
  138. else
  139. rednet.broadcast("<" ..user.. "> " ..chatHistory)
  140. term.setCursorPos(1, messages)
  141. messages = messages +1
  142. print("<" ..user.. "> " ..chatHistory)
  143. end
  144. end
  145. end
  146.  
  147. if chatHistory == "/ls" then
  148. term.setCursorPos(1, messages)
  149. messages = messages +1
  150. print("[List:] " ..user)
  151. rednet.broadcast("["..channel.."] /ls")
  152. end
  153. chatHistory = ""
  154. local x,y = term.getSize()
  155. term.setCursorPos(1, y)
  156. term.clearLine()
  157. opmode = false
  158. kkmode = false
  159. deopmode = false
  160. elseif e == "key" and pie == 57 then
  161. if chatHistory == "/op" or chatHistory == "/op " then
  162. opmode = true
  163. elseif chatHistory == "/kick" or chatHistory == "/kick " then
  164. kkmode = true
  165. elseif chatHistory == "/deop" or chatHistory == "/deop " then
  166. deopmode = true
  167. end
  168. end
  169. end
  170. end
  171.  
  172. function connector()
  173. term.clear()
  174. term.setCursorPos(1,1)
  175. status()
  176. print("Logging in...")
  177. print(user.. " ["..ip.."] logged in to N-IRC!")
  178. print("Connecting to " ..channel.."...")
  179. rednet.broadcast("pinged " ..channel)
  180. id, message = rednet.receive(1)
  181. if message == "hehehoohoohaha" then
  182. print("Connected! Joining...")
  183. rednet.broadcast("[" ..channel.. "] "..user.." joined the server!")
  184. sleep(0.5)
  185. channelID = id
  186. chatbox()
  187. else
  188. print("Server not existing... Hosting")
  189. print("Connected! Joining...")
  190. isChatter = true
  191. user = "@" ..user
  192. rednet.broadcast("[" ..channel.. "] "..user.." joined the server!")
  193. sleep(0.5)
  194. channelID = id
  195. chatbox()
  196. end
  197. end
  198.  
  199. function login()
  200. term.clear()
  201. term.setCursorPos(1,1)
  202. cPrint("NeXuS IRC \n")
  203. cPrint("Nickname: ")
  204. nick = read()
  205. cPrint("Channel: #")
  206. chan = read()
  207.  
  208. channel = "#" ..chan
  209. user = nick
  210. connector()
  211. end
  212.  
  213. function menu()
  214. term.clear()
  215. term.setCursorPos(1,1)
  216. cPrint("NeXuS IRC \n \n")
  217. cPrint("1:) Login\n")
  218. cPrint("2:) Exit \n")
  219. cPrint(" ")
  220. cPrint("Selection: ")
  221. input = read()
  222. if input == "1" or input == 1 then
  223. login()
  224. elseif input == "2" or input == 2 then
  225. shell.run("NeXoS")
  226. else
  227. menu()
  228. end
  229. end
  230.  
  231. menu()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement