Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --@version 1.2
- local version = 1.2
- local ht_up = http.get("https://pastebin.com/raw/nQ7rSYbN")
- local up_A = ht_up.readLine()
- local up_B = ht_up.readAll()
- local up = up_A .. up_B
- ht_up.close()
- local their_version = tonumber(up_A:sub(12))
- if (their_version > version) then
- local fi_up = fs.open(shell.getRunningProgram(), "w")
- fi_up.write(up)
- fi_up.close()
- shell.run(shell.getRunningProgram())
- return
- end
- local name = "NONAME"
- local output = nil
- local password = nil
- if not fs.exists("/.rc_name") then
- repeat
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.clear()
- term.setCursorPos(1, 1)
- write("Server name (min 3 length): ")
- name = tostring(read())
- sleep(0.1)
- until name ~= "nil" and #name > 2
- local rc = fs.open("/.rc_name", "w")
- rc.write(name)
- rc.close()
- else
- local rc = fs.open("/.rc_name", "r")
- name = tostring(rc.readAll())
- rc.close()
- end
- if not fs.exists("/.rc_key") then
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.clear()
- term.setCursorPos(1, 1)
- write("Password (blank for none): ")
- password = tostring(read())
- if password == "" or password == nil or password == "blank" then --yeah i know you smartasses will enter blank
- local f = fs.open("/.rc_key", "w")
- f.write("blank")
- f.close()
- else
- local f = fs.open("/.rc_key", "w")
- f.write(password)
- f.close()
- end
- else
- local f = fs.open("/.rc_key", "r")
- password = f.readAll()
- f.close()
- if password == "blank" then
- password = nil
- end
- end
- local pingdata_channel = 895
- local connect_channel = 885
- local our_connections = {}
- local chatLog = {}
- for i = 1, 18 do
- table.insert(chatLog, "")
- end
- local d = false
- local mod = nil
- for k, v in pairs(peripheral.getNames()) do
- if peripheral.getType(v) == "modem" then
- rednet.open(v)
- mod = peripheral.wrap(v)
- d = true
- end
- end
- if not d or not mod then
- error("A modem is required!")
- end
- local function download_file(url, target)
- local ht = http.get(url)
- local data = ht.readAll()
- ht.close()
- local file = fs.open(target, "w")
- file.write(data)
- file.close()
- end
- local function read_file(target)
- local file = fs.open(target, "r")
- local data = file.readAll()
- file.close()
- return data
- end
- -- API Loading
- local function getAPI(name, url)
- local apiloc = "/" .. name
- if (not fs.exists(apiloc)) then
- local newapiloc = shell and shell.resolveProgram(name) or nil
- if type(newapiloc) ~= "string" then
- download_file(url, apiloc)
- else
- apiloc = newapiloc
- end
- end
- return apiloc
- end
- local function tFind(a, b)
- for k, v in pairs(a) do
- if b == v then
- return k
- end
- end
- return nil
- end
- local function add_chat(mes)
- table.remove(chatLog, 1)
- table.insert(chatLog, mes)
- end
- local names = {}
- local ringnet = require(getAPI("ringnet", "https://pastebin.com/raw/tUe94t9J"))
- getAPI("aeslua", "https://git.io/aeslua")
- os.loadAPI("aeslua")
- --ringnet.setDebug(true)
- ringnet.openChannel(pingdata_channel)
- ringnet.openChannel(connect_channel)
- local challenge_string = nil
- if password ~= nil and password ~= "" and password ~= "blank" then
- challenge_string = aeslua.encrypt(password, "_A_COMMON_ENCRYPTION_STRING", aeslua.AES128, aeslua.CFBMODE)
- end
- local function name_exists(n)
- for k, v in pairs(names) do
- if v == n then
- return true
- end
- end
- return fase
- end
- local function sendData(a, b)
- if password then
- b = aeslua.encrypt(password, b, aeslua.AES128, aeslua.CFBMODE)
- end
- ringnet.sendData(a, b)
- end
- parallel.waitForAll(
- ringnet.connectionHandler,
- function()
- while true do
- local _, side, sfrq, rfrq, mes, dist = os.pullEvent()
- if (_ == "modem_message") then
- if (type(mes) == "string") then
- mes = textutils.unserialize(mes)
- end
- if (type(mes) == "table") then
- if (mes.type == "SERVER_DATA" and type(mes.rid) == "number") then
- mod.transmit(
- sfrq,
- sfrq,
- textutils.serialize(
- {
- type = "SERVER_RETURNDATA",
- to = mes.rid,
- name = name,
- fingerprint = ringnet.get_fingerprint(),
- hid = ringnet.get_handshakeID(),
- locked = challenge_string
- }
- )
- )
- end
- end
- elseif (_ == "tunnel_finish") then
- table.insert(our_connections, side)
- elseif (_ == "secure_receive") then
- local data = sfrq
- local cid = side
- if (type(data) == "string") then
- data = textutils.unserialize(data)
- end
- if (type(data) == "table") then
- if (data.type == "CHAT_LOGIN" and type(data.name) == "string") then
- local current_num = 1
- local actual_name = data.name
- if (name_exists(data.name)) then
- repeat
- actual_name = tostring(data.name) .. tostring(current_num)
- current_num = current_num + 1
- until (not name_exists(actual_name))
- end
- names[cid] = actual_name
- add_chat(
- {
- mes = actual_name .. " has joined.",
- raw = true
- }
- )
- sendData(
- cid,
- textutils.serialize(
- {
- type = "CHAT_LOG",
- log = chatLog
- }
- )
- )
- elseif (data.type == "CHAT_LOGOUT" and type(names[cid]) == "string") then
- add_chat(
- {
- mes = tostring(names[cid]) .. " has left.",
- raw = true
- }
- )
- for k, v in pairs(our_connections) do
- sendData(
- v,
- textutils.serialize(
- {
- type = "CHAT_LOG",
- log = chatLog
- }
- )
- )
- end
- names[cid] = nil
- local ccid = tFind(our_connections, cid)
- if ccid then
- table.remove(our_connections, ccid)
- end
- elseif (data.type == "CHAT_CHAT" and type(names[cid]) == "string" and type(data.message) == "string") then
- local name = names[cid]
- add_chat(
- {
- name = name,
- mes = tostring(data.message)
- }
- )
- local prefix = (name .. ": ")
- local dje = (tostring(data.message) .. "\n")
- local combined = (prefix .. dje)
- term.blit(combined, (string.rep("0", #prefix) .. string.rep("8", #dje)), string.rep("f", #combined))
- --print("ALLCONNECTIONS!")
- --print(textutils.serialize(our_connections))
- for k, v in pairs(our_connections) do
- sendData(
- v,
- textutils.serialize(
- {
- type = "CHAT_LOG",
- log = chatLog
- }
- )
- )
- end
- end
- end
- end
- end
- end
- )
Advertisement
Add Comment
Please, Sign In to add comment