Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local ServerID = os.getComputerID()
- rednet.open("back")
- root = "disk/Data/"
- function WaitMsg()
- WriteConsole("[SERVER] Server started !")
- while true do
- UnserializeMsg = {}
- a,b,c = rednet.receive()
- msg = textutils.unserialize(b)
- WriteConsole("["..a.."] : CMD = "..msg[1])
- if msg[1]=="Connection" then
- if fs.exists(root..msg[3])==false then
- UnserializeMsg[1] = "UnExistAccount"
- else
- UnserializeMsg[1] = "ExistingAccount"
- end
- elseif msg[1]=="VerifingPassword" then
- DataMDPV = fs.open(root..msg[2].."/MDP.txt","r")
- if (DataMDPV.readAll() == msg[3]) then
- UnserializeMsg[1] = "Accepted"
- else
- UnserializeMsg[1] = "Refused"
- end
- DataMDPV.close()
- elseif msg[1]=="ChangePassword" then
- DataMDP = fs.open(root..msg[2].."/MDP.txt","w")
- DataMDP.write(msg[3])
- DataMDP.close()
- UnserializeMsg[1] = "PasswordChanged"
- elseif msg[1]=="CreatAccount" then
- WriteConsole("Creation du compte pour : "..msg[2])
- fs.makeDir(root..msg[2])
- DataMDP = fs.open(root..msg[2].."/MDP.txt","a")
- DataMDP.write(msg[3])
- DataMDP.close()
- DataMoney = fs.open(root..msg[2].."/Money.txt","a")
- DataMoney.write(1000)
- DataMoney.close()
- UnserializeMsg[1] = "AccountCreated"
- elseif msg[1]=="Somme" then
- DataMoneyReader = fs.open(root..msg[2].."/Money.txt","r")
- Money = DataMoneyReader.readAll()
- DataMoneyReader.close()
- UnserializeMsg[1] = Money
- elseif msg[1]=="addMoney" then
- DataMoneyReader = fs.open(root..msg[2].."/Money.txt","r")
- Money = DataMoneyReader.readAll()
- DataMoneyReader.close()
- DataMoneyWriter = fs.open(root..msg[2].."/Money.txt","w")
- Money = tonumber(Money) + tonumber(msg[3])
- DataMoneyWriter.write(Money)
- DataMoneyWriter.close()
- elseif msg[1]=="PING" then
- UnserializeMsg[1] = "PONG"
- else
- WriteConsole("Commande Inconnue (\""..msg[1].."\")")
- end
- Msg = textutils.serialize(UnserializeMsg)
- rednet.send(tonumber(a),Msg)
- end
- end
- function Environement()
- if fs.isDir("Data")==false then
- WriteConsole("Creating the space for they account")
- fs.makeDir("Data")
- end
- end
- local histoCons = {}
- function Console()
- local x, y = 0, 0
- term.clear()
- for x=1,51 do
- paintutils.drawPixel(x,1,colors.blue)
- paintutils.drawPixel(x,16,colors.blue)
- paintutils.drawPixel(x,19,colors.blue)
- end
- for y=2,18 do
- paintutils.drawPixel(1,y,colors.blue)
- paintutils.drawPixel(51,y,colors.blue)
- end
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.blue)
- term.setCursorPos(2,1)
- term.write("IP : "..ServerID)
- term.setCursorPos(23,1)
- term.write("Console")
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.setCursorPos(2,18)
- term.write(">")
- end
- function WriteConsole(msg)
- table.insert(histoCons,msg)
- yCons = 2
- local x, y = 0,0
- if #histoCons > 14 then
- table.remove(histoCons, 1)
- end
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- for x = 2, 50 do
- for y = 2, 15 do
- term.setCursorPos(x,y)
- term.write(" ")
- end
- end
- term.setCursorPos(3,2)
- for key,value in pairs( histoCons ) do
- term.setCursorPos(3,yCons)
- term.write(value)
- yCons = yCons+1
- end
- end
- function InputCmd()
- sleep(0.5)
- command = ""
- while true do
- local event, p1 = os.pullEvent()
- if event == "char" then
- command = command..p1
- elseif (event == "key") and (p1==14) then
- command = string.sub( command, 1, string.len( command ) - 1 )
- elseif (event == "key") and (p1==28) then
- Treatment(command)
- command = ""
- end
- term.setCursorPos(3,18)
- term.write(" ")
- term.setCursorPos(3,18)
- term.write(command)
- end
- end
- function Treatment(tCommand)
- if string.sub(tCommand, 1,1) == "/" then
- tCommand = string.sub(tCommand, 2,string.len( command ))
- cmd2 = string.sub(tCommand,1,2)
- cmd4 = string.sub(tCommand,1,4)
- cmd5 = string.sub(tCommand,1,5)
- cmd6 = string.sub(tCommand,1,6)
- cmd7 = string.sub(tCommand,1,7)
- if cmd2 == "rm" then
- notaspace = true
- while notaspace do
- letter = string.sub(cmd1,1,1)
- cmd1 = string.sub(cmd1,2,string.len(cmd1))
- --WriteConsole("Args1 = "..args1.." lenght : "..string.len(cmd1))
- args1 = args1..letter
- if (letter == " ") or (string.len(cmd1) == 0) then notaspace = false end
- sleep(0.5)
- end
- if fs.isDir(root..args1) then
- fs.delete(root..args1)
- WriteConsole("Repertoire suprimer ("..args1..")")
- else
- WriteConsole("Repertoire non-trouver")
- end
- elseif cmd4 == "help" then
- --liste des cmd
- WriteConsole("Commande possible :")
- WriteConsole("/stop")
- WriteConsole("/reboot")
- WriteConsole("/creat (pseudo)")
- WriteConsole("/account -permet de savoir tout les comptes")
- WriteConsole("/rm")
- elseif cmd4 == "stop" then
- os.shutdown()
- elseif cmd5 == "creat" then
- args1 = ""
- letter = ""
- cmd1 = string.sub(tCommand,7,string.len(tCommand))
- sleep(1)
- notaspace = true
- while notaspace do
- letter = string.sub(cmd1,1,1)
- cmd1 = string.sub(cmd1,2,string.len(cmd1))
- --WriteConsole("Args1 = "..args1.." lenght : "..string.len(cmd1))
- args1 = args1..letter
- if (letter == " ") or (string.len(cmd1) == 0) then notaspace = false end
- sleep(0.5)
- end
- if fs.isDir(root..args1) == false then
- fs.makeDir(root..args1)
- DataMDP = fs.open(root..args1.."/MDP.txt","a")
- DataMDP.write("0000")
- DataMDP.close()
- DataMoney = fs.open(root..args1.."/Money.txt","a")
- DataMoney.write("1000")
- DataMoney.close()
- WriteConsole("Compte pour "..args1.." creer")
- else
- WriteConsole("Ce compte existe deja !")
- end
- elseif cmd6 == "reboot" then
- os.reboot()
- elseif cmd7 == "account" then
- a = fs.list(root)
- TAccount = nil
- for k,v in pairs(fs.list(root)) do
- if TAccount == nil then
- TAccount = v
- else
- TAccount = TAccount.." , "..v
- end
- end
- WriteConsole(TAccount)
- end
- end
- end
- Console()
- Environement()
- parallel.waitForAll(WaitMsg,InputCmd)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement