Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Basic websites by PaymentOption for NeXuS --
- VERSION = "ALPHA 0.0.1"
- -----------------------------------------------
- -- VARS --
- iConnections = 0
- tConnected = {}
- sCodePath = "NeXuS/Web/Server/code"
- ----------
- rednet.open("top")
- rednet.open("right")
- rednet.open("left")
- rednet.open("back")
- rednet.open("bottom")
- shell.run("mkdir", "NeXuS/Web/Server/")
- -- Helper Functions --
- function cPrint(height, string)
- local w, h = term.getSize()
- local xPosition = w/2 - string.len(string)/2
- term.setCursorPos(xPosition, height)
- term.write(string)
- end
- function rPrint(height, string)
- local w,h = term.getSize()
- local xPos = w - string.len(string)
- term.setCursorPos(xPos, height)
- term.write(string)
- end
- function clear()
- term.clear()
- term.setCursorPos(1,1)
- end
- -----------------------
- -- Menues and other screens --
- function printMenu()
- rPrint(17, "Version: "..VERSION)
- cPrint(1, "NeXuS Website BETA")
- term.setCursorPos(1,1)
- write("Status: ")
- term.setCursorPos(1,3)
- write("Connected users: "..iConnections)
- cPrint(6, "Awaiting requests...")
- end
- ------------------------------
- -- Networking related functions --
- function connectHANDLE(connection) -- Connection being the userID who is trying to connect
- local file = fs.open(sCodePath, "r") -- Get the code that the user will be running to interact with the server
- local fileContents = file.readAll()
- file.close()
- rednet.send(connection, fileContents) -- tostring() just to make sure that rednet doesn't through a fit
- iConnections = iConnections+1
- tConnected[iConnections] = tonumber(connection)
- term.setCursorPos(1,2)
- write("User "..connection.." connected")
- end
- function disconnectHANDLE(connection)
- for i=1, #tConnected do
- if tConnected[i] == connection then
- iConnections = iConnections-1
- tConnected[i] = nil
- end
- end
- term.setCursorPos(1,2)
- write("User "..connection.." disconnected")
- sleep(0.9)
- end
- ----------------------------------
- while true do
- clear()
- printMenu()
- sender, message = rednet.receive()
- if message == "connect" then
- connectHANDLE(sender)
- end
- if message == "disconnect" then
- disconnectHANDLE(sender)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement