Advertisement
xXm0dzXx

Untitled

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