Advertisement
PaymentOption

m0dzPaste

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