Advertisement
xXm0dzXx

Untitled

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