Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.pullEvent = os.pullEventRaw
- -- "Ready only" definitions
- local settings = ".tardiscoresettings"
- -- Define peripherals.
- local cmd = peripheral.find("command")
- local chat = peripheral.find("chatbox_admin")
- -- Define core settings
- local default_name = "&eTARDIS"
- local core_name = "&9[&eTARDIS&9]"
- local core_exe = "tardis:"
- local inrun = true
- local argdone = ";"
- local history = {}
- local admins = {
- ["Lewisk3"]=true,
- }
- function execute(command)
- cmd.setCommand(command)
- cmd.runCommand()
- end
- function changeTitle(new)
- core_name = "&9["..new.."&9]"
- saveCoreSettings()
- end
- function tell(text,player)
- if not inrun then print(core_name.." -> &eYou &8:> &f"..text) end
- if(inrun)then
- cmd.setCommand("sudo " ..player.. " ping "..core_name.." -> &eYou &8:> &f"..text)
- cmd.runCommand()
- end
- end
- function say(text)
- if not inrun then print(core_name.." &f"..text) end
- if(inrun)then
- cmd.setCommand("sudo @a ping "..core_name.." &f"..text)
- cmd.runCommand()
- end
- end
- function updateStatus(msg)
- table.insert(history,msg)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.lightBlue)
- print(":> " .. msg)
- end
- function clear()
- term.setCursorPos(1,1)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.lightBlue)
- term.clear()
- term.setBackgroundColor(colors.gray)
- term.clearLine()
- print("Tardis Core :> History.")
- term.setBackgroundColor(colors.black)
- term.setCursorPos(1,3)
- end
- core_commands = {
- ["lua"] = {args=1,run = function(p,var)
- local ok, err = pcall( loadstring(var) )
- if(not ok and err)then
- tell("&4Execution Error: " .. var, p)
- elseif(ok)then
- tell("&aExecuted lua: " .. var, p)
- end
- end},
- ["say"] = {args=1,run = function(p,var) say(var) end},
- ["cmd"] = {args=1,run = function(p,var) execute(var) end},
- ["nick"] = {args=1,run = function(p,var) changeTitle(var) end},
- ["reset"] = {args=0,run=function(p) changeTitle(default_name) end},
- ["rawsay"] = {args=1,run=function(p,var) execute("sudo @a ping "..var) end},
- ["clear"] = {args=0,run=function(p) clear() tell("Cleared console.",p) end},
- ["cmds"] = {args=0,run=function(p) tell("Available commands: " .. cmdlist,p) end},
- ["whitelist"] = {args=2,run=function(p,mode,user)
- if(mode == "add")then
- admins[user] = true;
- saveCoreSettings()
- tell("You have been added to the whitelist!",user)
- tell("Added user: " .. user .. " to the whitelist.",p)
- elseif(mode == "del")then
- if(user == "Lewisk3")then
- tell("Nope, how about i remove you instead :P", p)
- return
- end
- table.remove(admins,user)
- tell("You have been removed to the whitelist!",user)
- tell("Removed user: " .. user .. " from the whitelist.",p)
- saveCoreSettings()
- else
- tell("Invalid whitelist mode: " .. mode .. " (add, del)",p)
- end
- end},
- ["shutdown"]= {args=0,run=function(p) tell("Shutting down...",p) saveCoreSettings() error("Core shutdown.") end},
- ["cmd_add"] = {args=3,run=function(p,name,ar,val) addCmd(p,name,ar,val) end},
- ["cmd_sub"] = {args=3,run=function(p,name) remCmd(p,name) end},
- }
- cmdlist = ""
- for k, v in pairs(core_commands) do
- cmdlist = cmdlist .. k .. ", "
- end
- --tardis:cmd_add;test;0;function(p) print("Test?") end
- function addCmd(pl,name,bytes,func)
- if(core_commands[name] ~= nil)then
- tell("&4Existing command: " .. name, pl)
- updateStatus("Tried to add existing command: " .. pl)
- else
- core_commands[name] = {args=bytes,run=function() func() end}
- end
- saveCoreSettings()
- end
- function remCmd(pl,name)
- if(core_commands[name] == nil)then
- tell("&4Non-Existent command: " .. name, pl)
- updateStatus("Tried to remove non-existent command: " .. pl)
- else
- core_commands[name] = nil
- table.remove(core_commands,name)
- end
- end
- function readCoreSettings()
- if(not fs.exists(settings))then
- saveCoreSettings()
- end
- local f = fs.open(settings,"r")
- -- core_name = f.readLine()
- -- core_exe = f.readLine()
- -- argdone = f.readLine()
- admins = textutils.unserialize(f.readAll())
- -- core_commands = textutils.unserialize(f.readLine())
- end
- function saveCoreSettings()
- local f = fs.open(settings,"w")
- -- f.writeLine(core_name)
- -- f.writeLine(core_exe)
- -- f.writeLine(argdone)
- f.write(textutils.serialize(admins))
- -- f.writeLine(core_commands)
- f.close()
- end
- clear()
- function coreloop(pl,msg)
- if(msg:sub(1,#core_exe) == core_exe)then
- -- Calculate length of command
- msg = msg:sub(#core_exe+1,#msg)
- local com = {}
- for word in string.gmatch(msg,"([^"..argdone.."]+)") do
- if(#msg:gsub("%s+","") > 0)then
- table.insert(com,word)
- end
- end
- if(#com == 0)then
- tell("&4Instrution must be ended with a - " .. argdone, pl)
- updateStatus("Malformed command: " .. pl)
- return
- end
- com = com[1]
- if(admins[pl])then
- if(core_commands[com])then
- -- Sub out the length of out command
- msg = msg:sub(#com+1,#msg)
- --msg = msg:gsub("%s+","")
- local args = {}
- local argsind = 0
- for word in string.gmatch(msg,"([^"..argdone.."]+)") do
- if(argsind < core_commands[com].args)then
- table.insert(args,word)
- end
- end
- if(#args == 0)then
- args[1] = ""
- end
- if(#args < core_commands[com].args)then
- tell("&4Invalid Arguments for: &f" .. msg, pl)
- updateStatus(pl .. " entered invalid arguments for command: " .. com)
- else
- core_commands[com].run(pl,unpack(args))
- updateStatus(pl .. " executed command: " .. com .. "(" .. tostring(unpack(args)) .. ")")
- end
- else
- tell("&4Invalid instruction: &f" .. msg, pl)
- end
- else
- tell("&4Unauthorized use of: &f" .. msg, pl)
- updateStatus("Unauthorized user: " .. pl)
- end
- end
- end
- local targs = { ... }
- if(targs[1] == "-n")then
- inrun = false
- end
- print("Loading settings...")
- readCoreSettings()
- while inrun do
- local ev, sd, pl, msg = os.pullEvent("chatbox_command")
- if(msg ~= nil and pl ~= nil)then
- coreloop(pl,msg)
- end
- end
- while not inrun do
- coreloop("Lewisk3",read())
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement