SHOW:
|
|
- or go back to the newest paste.
| 1 | local username=""; | |
| 2 | ||
| 3 | - | local curPos="1" |
| 3 | + | local curPos="1" |
| 4 | local channel="0" | |
| 5 | local x,y=term.getSize() | |
| 6 | local xzentral=x/2 | |
| 7 | local yzentral=y/2 | |
| 8 | ||
| 9 | function joinChannel() | |
| 10 | term.clear() | |
| 11 | term.setCursorPos(xzentral-4,yzentral) | |
| 12 | term.setBackgroundColor(colors.white) | |
| 13 | term.setTextColor(colors.black) | |
| 14 | textutils.slowWrite("Join channel: ")
| |
| 15 | channel=read() | |
| 16 | ||
| 17 | if channel=="" then term.setCursorPos(12,10) term.clearLine() print("Error: Please enter a Channelname ! ") term.setBackgroundColor(colors.black)
| |
| 18 | term.setTextColor(colors.white)os.sleep(1) joinChannel() else | |
| 19 | term.setBackgroundColor(colors.black) | |
| 20 | term.setTextColor(colors.white) | |
| 21 | term.setCursorPos(xzentral-4,yzentral) | |
| 22 | term.clearLine() | |
| 23 | term.setBackgroundColor(colors.white) | |
| 24 | term.setTextColor(colors.black) | |
| 25 | term.setCursorPos(xzentral-4,yzentral) | |
| 26 | textutils.slowWrite("Joining channel...")
| |
| 27 | os.sleep(1) | |
| 28 | rednet.broadcast("*** "..username.." joined the chat ***",channel)
| |
| 29 | term.setBackgroundColor(colors.black) | |
| 30 | term.setTextColor(colors.white) | |
| 31 | ||
| 32 | return | |
| 33 | ||
| 34 | end | |
| 35 | end | |
| 36 | ||
| 37 | ||
| 38 | ||
| 39 | ||
| 40 | ||
| 41 | function menu() | |
| 42 | fs.delete("/chatfolder")
| |
| 43 | term.clear() | |
| 44 | ||
| 45 | ||
| 46 | ||
| 47 | ||
| 48 | ||
| 49 | ||
| 50 | - | if curPos=="1" then |
| 50 | + | if curPos=="1" then |
| 51 | ||
| 52 | - | term.clear() |
| 52 | + | term.clear() |
| 53 | - | term.setCursorPos(xzentral-4,yzentral-1) |
| 53 | + | term.setCursorPos(xzentral-4,yzentral-1) |
| 54 | - | term.setBackgroundColor(colors.white) |
| 54 | + | term.setBackgroundColor(colors.white) |
| 55 | - | term.setTextColor(colors.black) |
| 55 | + | term.setTextColor(colors.black) |
| 56 | - | print("Join channel")
|
| 56 | + | print("Join channel")
|
| 57 | - | term.setCursorPos(xzentral-4,yzentral) |
| 57 | + | term.setCursorPos(xzentral-4,yzentral) |
| 58 | - | term.setBackgroundColor(colors.black) |
| 58 | + | term.setBackgroundColor(colors.black) |
| 59 | - | term.setTextColor(colors.white) |
| 59 | + | term.setTextColor(colors.white) |
| 60 | - | print("Settings")
|
| 60 | + | print("Settings")
|
| 61 | - | term.setCursorPos(xzentral-4,yzentral+1) |
| 61 | + | term.setCursorPos(xzentral-4,yzentral+1) |
| 62 | - | term.setBackgroundColor(colors.black) |
| 62 | + | term.setBackgroundColor(colors.black) |
| 63 | - | term.setTextColor(colors.white) |
| 63 | + | term.setTextColor(colors.white) |
| 64 | - | print("Quit")
|
| 64 | + | print("Quit")
|
| 65 | local event, key=os.pullEvent("key")
| |
| 66 | ||
| 67 | - | if key==208 |
| 67 | + | if key==208 |
| 68 | - | then |
| 68 | + | then |
| 69 | - | |
| 69 | + | |
| 70 | - | |
| 70 | + | |
| 71 | - | curPos="2" menu() |
| 71 | + | curPos="2" menu() |
| 72 | - | |
| 72 | + | |
| 73 | - | elseif key==28 |
| 73 | + | elseif key==28 |
| 74 | - | then |
| 74 | + | then |
| 75 | - | joinChannel() |
| 75 | + | joinChannel() |
| 76 | - | return |
| 76 | + | return |
| 77 | - | else menu() |
| 77 | + | else menu() |
| 78 | - | end |
| 78 | + | end |
| 79 | - | end |
| 79 | + | end |
| 80 | - | |
| 80 | + | |
| 81 | ||
| 82 | - | if curPos=="2" then |
| 82 | + | if curPos=="2" then |
| 83 | - | term.setBackgroundColor(colors.black) |
| 83 | + | term.setBackgroundColor(colors.black) |
| 84 | - | term.clear() |
| 84 | + | term.clear() |
| 85 | - | term.setBackgroundColor(colors.black) |
| 85 | + | term.setBackgroundColor(colors.black) |
| 86 | - | term.setCursorPos(xzentral-4,yzentral-1) |
| 86 | + | term.setCursorPos(xzentral-4,yzentral-1) |
| 87 | - | term.setBackgroundColor(colors.black) |
| 87 | + | term.setBackgroundColor(colors.black) |
| 88 | - | term.setTextColor(colors.white) |
| 88 | + | term.setTextColor(colors.white) |
| 89 | - | print("Join channel")
|
| 89 | + | print("Join channel")
|
| 90 | - | term.setCursorPos(xzentral-4,yzentral) |
| 90 | + | term.setCursorPos(xzentral-4,yzentral) |
| 91 | - | term.setBackgroundColor(colors.white) |
| 91 | + | term.setBackgroundColor(colors.white) |
| 92 | - | term.setTextColor(colors.black) |
| 92 | + | term.setTextColor(colors.black) |
| 93 | - | print("Settings")
|
| 93 | + | print("Settings")
|
| 94 | - | term.setCursorPos(xzentral-4,yzentral+1) |
| 94 | + | term.setCursorPos(xzentral-4,yzentral+1) |
| 95 | - | term.setBackgroundColor(colors.black) |
| 95 | + | term.setBackgroundColor(colors.black) |
| 96 | - | term.setTextColor(colors.white) |
| 96 | + | term.setTextColor(colors.white) |
| 97 | - | print("Quit")
|
| 97 | + | print("Quit")
|
| 98 | - | term.setBackgroundColor(colors.black) |
| 98 | + | term.setBackgroundColor(colors.black) |
| 99 | - | local event, key=os.pullEvent("key")
|
| 99 | + | local event, key=os.pullEvent("key")
|
| 100 | - | if key==200 |
| 100 | + | if key==200 |
| 101 | - | then |
| 101 | + | then |
| 102 | - | curPos="1" menu() |
| 102 | + | curPos="1" menu() |
| 103 | - | |
| 103 | + | |
| 104 | ||
| 105 | - | elseif key==208 |
| 105 | + | elseif key==208 |
| 106 | - | then |
| 106 | + | then |
| 107 | - | term.setBackgroundColor(colors.black) |
| 107 | + | term.setBackgroundColor(colors.black) |
| 108 | - | curPos="3" |
| 108 | + | curPos="3" |
| 109 | - | menu() |
| 109 | + | menu() |
| 110 | ||
| 111 | - | elseif key==28 |
| 111 | + | elseif key==28 |
| 112 | - | then |
| 112 | + | then |
| 113 | - | nickname() |
| 113 | + | nickname() |
| 114 | - | else menu() term.setBackgroundColor(colors.black) |
| 114 | + | else menu() term.setBackgroundColor(colors.black) |
| 115 | - | end |
| 115 | + | end |
| 116 | - | end |
| 116 | + | end |
| 117 | - | |
| 117 | + | |
| 118 | ||
| 119 | - | if curPos=="3" then |
| 119 | + | if curPos=="3" then |
| 120 | - | term.clear() |
| 120 | + | term.clear() |
| 121 | - | term.setCursorPos(xzentral-4,yzentral-1) |
| 121 | + | term.setCursorPos(xzentral-4,yzentral-1) |
| 122 | - | term.setBackgroundColor(colors.black) |
| 122 | + | term.setBackgroundColor(colors.black) |
| 123 | - | term.setTextColor(colors.white) |
| 123 | + | term.setTextColor(colors.white) |
| 124 | - | print("Join channel")
|
| 124 | + | print("Join channel")
|
| 125 | - | term.setCursorPos(xzentral-4,yzentral) |
| 125 | + | term.setCursorPos(xzentral-4,yzentral) |
| 126 | - | term.setBackgroundColor(colors.black) |
| 126 | + | term.setBackgroundColor(colors.black) |
| 127 | - | term.setTextColor(colors.white) |
| 127 | + | term.setTextColor(colors.white) |
| 128 | - | print("Settings")
|
| 128 | + | print("Settings")
|
| 129 | - | term.setCursorPos(xzentral-4,yzentral+1) |
| 129 | + | term.setCursorPos(xzentral-4,yzentral+1) |
| 130 | - | term.setBackgroundColor(colors.white) |
| 130 | + | term.setBackgroundColor(colors.white) |
| 131 | - | term.setTextColor(colors.black) |
| 131 | + | term.setTextColor(colors.black) |
| 132 | - | print("Quit")
|
| 132 | + | print("Quit")
|
| 133 | ||
| 134 | local event, key=os.pullEvent("key")
| |
| 135 | - | if key==200 |
| 135 | + | if key==200 |
| 136 | - | then |
| 136 | + | then |
| 137 | - | curPos="2" menu() |
| 137 | + | curPos="2" menu() |
| 138 | - | |
| 138 | + | |
| 139 | - | elseif key==28 |
| 139 | + | elseif key==28 |
| 140 | - | then |
| 140 | + | then |
| 141 | - | term.setBackgroundColor(colors.black) term.setTextColor(colors.white) term.clear() term.setCursorPos(xzentral-4,yzentral) textutils.slowPrint("Good Bye") term.setCursorPos(1,1) os.sleep(2) os.shutdown()
|
| 141 | + | term.setBackgroundColor(colors.black) term.setTextColor(colors.white) term.clear() term.setCursorPos(xzentral-4,yzentral) textutils.slowPrint("Good Bye") term.setCursorPos(1,1) os.sleep(2) os.shutdown()
|
| 142 | - | |
| 142 | + | |
| 143 | else term.clear() term.setBackgroundColor(colors.black) menu() | |
| 144 | - | end |
| 144 | + | end |
| 145 | - | end |
| 145 | + | end |
| 146 | - | end |
| 146 | + | end |
| 147 | ||
| 148 | ||
| 149 | ||
| 150 | ||
| 151 | ||
| 152 | ||
| 153 | ||
| 154 | function close() | |
| 155 | ||
| 156 | ||
| 157 | ||
| 158 | ||
| 159 | ||
| 160 | local event, button, xPos, yPos = os.pullEvent("mouse_click")
| |
| 161 | ||
| 162 | if xPos==50 and yPos==1 then term.clear() menu() | |
| 163 | - | else |
| 163 | + | else |
| 164 | - | end |
| 164 | + | end |
| 165 | ||
| 166 | ||
| 167 | ||
| 168 | ||
| 169 | end | |
| 170 | ||
| 171 | ||
| 172 | ||
| 173 | function nickname() | |
| 174 | term.clear() | |
| 175 | term.setCursorPos(14,10) | |
| 176 | write("Username:")
| |
| 177 | username=read(); | |
| 178 | if username=="" then term.setCursorPos(12,10) term.clearLine() print("Error: Please enter a Username ! ") os.sleep(2) nickname() else
| |
| 179 | term.clear() | |
| 180 | term.setCursorPos(12,9) | |
| 181 | print("-------------------------------")
| |
| 182 | term.setCursorPos(12,11) | |
| 183 | print("-------------------------------")
| |
| 184 | term.setCursorPos(16,10) | |
| 185 | textutils.slowPrint("Username:"..username.." saved")
| |
| 186 | ||
| 187 | ||
| 188 | os.sleep(2) | |
| 189 | end | |
| 190 | end | |
| 191 | ||
| 192 | ||
| 193 | ------------------------------------------------------------------------------------------------------------------- | |
| 194 | local chat=""; | |
| 195 | ||
| 196 | ||
| 197 | ||
| 198 | function writetoscreen(text) | |
| 199 | term.clear() | |
| 200 | ||
| 201 | local h=fs.open("/chatfolder/chat"..channel,"a")
| |
| 202 | h.writeLine(text); | |
| 203 | h.flush(); | |
| 204 | h.close(); | |
| 205 | ||
| 206 | cursorold() | |
| 207 | local g=fs.open("/chatfolder/chat"..channel,"r");
| |
| 208 | ||
| 209 | print(g.readAll()); | |
| 210 | g.close() | |
| 211 | end | |
| 212 | ||
| 213 | function oldmessages() | |
| 214 | ||
| 215 | ||
| 216 | - | cursorold() |
| 216 | + | cursorold() |
| 217 | local l=fs.open("/chatfolder/chat"..channel,"r");
| |
| 218 | ||
| 219 | print(l.readAll()); | |
| 220 | l.close() | |
| 221 | ||
| 222 | end | |
| 223 | ||
| 224 | function writetoscreen_local(text) | |
| 225 | term.clear() | |
| 226 | ||
| 227 | local h=fs.open("/chatfolder/chat"..channel,"a")
| |
| 228 | h.writeLine("["..username.."]"..":"..text);
| |
| 229 | h.flush(); | |
| 230 | h.close(); | |
| 231 | ||
| 232 | cursorold() | |
| 233 | local g=fs.open("/chatfolder/chat"..channel,"r");
| |
| 234 | ||
| 235 | print(g.readAll()); | |
| 236 | g.close() | |
| 237 | end | |
| 238 | ||
| 239 | ||
| 240 | function cursornew() | |
| 241 | intx, inty= term.getSize(); | |
| 242 | term.setCursorPos(1,inty) | |
| 243 | end | |
| 244 | ||
| 245 | ||
| 246 | function cursorold() | |
| 247 | term.setCursorPos(1,2) | |
| 248 | end | |
| 249 | ||
| 250 | ||
| 251 | ||
| 252 | ||
| 253 | - | function getSide() |
| 253 | + | function getSide() |
| 254 | - | for _,side in ipairs({"top", "bottom", "front", "left", "right", "back"}) do
|
| 254 | + | for _,side in ipairs({"top", "bottom", "front", "left", "right", "back"}) do
|
| 255 | - | if peripheral.isPresent(side) |
| 255 | + | if peripheral.isPresent(side) then if peripheral.getType(side)=="modem" then modemside=side if modemside="" then term.setTextColor(colors.red) term.setCursorPos(xzentral-4,yzentral)print("ERROR:Please attach a modem!") os.shutdown() else rednet.open(modemside)
|
| 256 | - | then |
| 256 | + | end |
| 257 | - | if peripheral.getType(side)=="modem" |
| 257 | + | |
| 258 | - | then |
| 258 | + | |
| 259 | - | modemside=side |
| 259 | + | |
| 260 | - | rednet.open(modemside) |
| 260 | + | |
| 261 | - | end |
| 261 | + | |
| 262 | - | end |
| 262 | + | |
| 263 | - | end |
| 263 | + | |
| 264 | ||
| 265 | function send () | |
| 266 | cursornew() | |
| 267 | term.clearLine() | |
| 268 | term.setCursorPos(1,inty-1) | |
| 269 | term.setCursorPos(1,1) | |
| 270 | term.setBackgroundColor(colors.white) | |
| 271 | term.setTextColor(colors.black) | |
| 272 | write("---You are chatting in channel "..channel.."--- ") term.setCursorPos(x-2,1) write("[X]")
| |
| 273 | term.setBackgroundColor(colors.black) | |
| 274 | term.setTextColor(colors.white) | |
| 275 | term.setCursorPos(1,inty-1) | |
| 276 | print("---------------------------------------------------")
| |
| 277 | cursornew() | |
| 278 | write("Text:")
| |
| 279 | local msg=read(); | |
| 280 | term.clearLine() | |
| 281 | cursornew() | |
| 282 | term.clear() | |
| 283 | if msg=="" then oldmessages() else | |
| 284 | chat=chat..msg | |
| 285 | cursorold() | |
| 286 | --write(chat) | |
| 287 | writetoscreen_local(msg) | |
| 288 | rednet.broadcast("["..username.."]"..":"..msg,channel)
| |
| 289 | cursornew() | |
| 290 | term.clearLine() | |
| 291 | end | |
| 292 | end | |
| 293 | ||
| 294 | function receive() | |
| 295 | id,message,protocol=rednet.receive(channel) | |
| 296 | cursorold() | |
| 297 | chat=chat..message | |
| 298 | --write(chat) | |
| 299 | writetoscreen(message) | |
| 300 | end | |
| 301 | ||
| 302 | fs.delete("chat")
| |
| 303 | getSide(); | |
| 304 | nickname() | |
| 305 | menu() | |
| 306 | ||
| 307 | ||
| 308 | term.clear() | |
| 309 | ||
| 310 | ||
| 311 | while true do | |
| 312 | ||
| 313 | parallel.waitForAny(send,receive,close) | |
| 314 | end | |
| 315 | ---------------------------------------------------------------------------------------------------------------------------------------------- |