Advertisement
xXm0dzXx

Untitled

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