Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("NetSphere")
- local h = http.get("http://pastebin.com/raw/9mQiK4PX")
- local DerniereVersion = textutils.unserialise(h.readAll())
- h.close()
- local MaVersion = {["Serveur"]=0}
- if fs.exists("Version") then
- local h = fs.open("Version","r")
- MaVersion = textutils.unserialise(h.readAll())
- h.close()
- end
- if MaVersion["Serveur"] ~= DerniereVersion["Serveur"] then
- fs.delete("install")
- shell.run("pastebin get NfQk01Ex install")
- shell.run("install")
- end
- local ATM = {}
- print("Veuillez placer un modem quelque part !")
- while true do
- local modem = peripheral.find("modem",function(name,object) return object.isWireless() end)
- if modem then
- modem.open(os.getComputerID())
- modem.open(65535)
- break
- else
- shell.run("clear")
- print("Veuillez placer un modem quelque part !")
- os.pullEvent("peripheral")
- end
- end
- function AddATM(id)
- ATM[id+0]=true
- if fs.exists("Banque/IDATM/"..id.."/") == false then
- fs.makeDir("Banque/IDATM/"..id.."/")
- end
- end
- function DelATM(id)
- ATM[id+0]=nil
- if fs.exists("Banque/IDATM/"..id.."/") then
- fs.delete("Banque/IDATM/"..id.."/")
- end
- end
- function ListeATM()
- return fs.list("Banque/IDATM/")
- end
- shell.run("clear")
- rednet.host("Serveur_Banque","Serveur_Banque")
- local IDConnecter = {}
- function send(id, texte)
- NetSphere.send(id, texte)
- end
- function EffHistorique(Pseudo)
- if fs.exists("Banque/Compte/"..Pseudo.."/Historique") then
- h = fs.open("Banque/Compte/"..Pseudo.."/Historique","w")
- h.write("")
- h.close()
- end
- end
- function HaveAModem()
- while true do
- local event, side = os.pullEvent("peripheral_detach")
- local f = peripheral.find("modem",function(name, object) return object.isWireless() end)
- if not f or #f == 0 then
- os.reboot()
- end
- end
- end
- function CompteExist(Pseudo)
- if Pseudo == nil then
- return false
- else
- if fs.exists("Banque/Compte/"..Pseudo) then
- return true
- else
- return false
- end
- end
- end
- function DecomposeJson(Fichier)
- if fs.exists(Fichier) then
- local tableau={}
- h = fs.open(Fichier,"r")
- while true do
- result = h.readLine()
- if result == nil then
- break
- else
- a1 = replace(result," ","")
- a2 = replace(a1,'"',"")
- a3 = replace(a2,',',"")
- if string.find(a2,"name:") then
- a4 = replace(a3,"name:","")
- tableau[#tableau+1] = a4
- end
- end
- end
- h.close()
- return tableau
- end
- end
- function replace(texte,mot,apres)
- if string.find(texte,mot) then
- return string.gsub(texte, mot, apres)
- else
- return texte
- end
- end
- function error(erreur, menu,id)
- info = {Act="Erreur",Menu=menu,Message=erreur}
- infos = textutils.serialise(info)
- send(id, infos)
- end
- function Succes(Succes,menu, id)
- info = {Act="Succes",Menu=menu,Message=Succes}
- infos = textutils.serialise(info)
- send(id, infos)
- end
- function CreateCompte(Pseudo)
- if fs.exists("Banque/Compte/"..Pseudo) == false then
- h = fs.open("Banque/Compte/"..Pseudo.."/Solde","w")
- h.write(1000)
- h.close()
- h = fs.open("Banque/Compte/"..Pseudo.."/Historique","w")
- h.write("")
- h.close()
- h = fs.open("Banque/Compte/"..Pseudo.."/HistoriqueSave","w")
- h.write("")
- h.close()
- h = fs.open("Banque/Compte/"..Pseudo.."/Mdp","w")
- h.write(Pseudo)
- h.close()
- h = fs.open("Banque/Compte/"..Pseudo.."/Statut","w")
- h.write("PLAYER")
- h.close()
- h = fs.open("Banque/Compte/"..Pseudo.."/Entreprises","w")
- h.write("")
- h.close()
- Liste = ListeCompte()
- fs.delete("ListeCompte")
- h = fs.open("ListeCompte","w")
- for i =1, #Liste do
- h.write(Liste[i].."\n")
- end
- h.close()
- end
- end
- function DeleteCompte(Pseudo)
- if fs.exists("Banque/Compte/"..Pseudo) == true then
- fs.delete("Banque/Compte/"..Pseudo)
- Liste = ListeCompte()
- h = fs.open("ListeCompte","w")
- for i =1, #Liste do
- if Liste[i] == Pseudo then
- else
- h.write(Liste[i].."\n")
- end
- end
- h.close()
- end
- end
- function ListeCompte()
- if fs.exists("ListeCompte") then
- local Comptes=fs.list("Banque/Compte/")
- return Comptes
- end
- end
- function ListeEntreprise()
- if fs.exists("Banque/Entreprise/") then
- local Comptes=fs.list("Banque/Entreprise/")
- return Comptes
- end
- end
- function ActualiserC(Pseudo, Id)
- if fs.exists("Banque/Compte/"..Pseudo.."/Solde") then
- h = fs.open("Banque/Compte/"..Pseudo.."/Solde","r")
- soldeP = h.readAll()
- h.close()
- h = fs.open("Banque/Compte/"..Pseudo.."/Statut","r")
- statut = h.readAll()
- h.close()
- hst = textutils.serialise(HistoriqueCR(Pseudo))
- entp = textutils.serialise(EntrepriseCR(Pseudo))
- Ninfo = {Act="Actualiser",Solde=soldeP+0,Historique=hst,Entreprises=entp,Statut=statut}
- Ninfos = textutils.serialise(Ninfo)
- send(Id, Ninfos)
- Liste = ListeCompte()
- Ninfo = {Act="ListeComptesTab",Liste=Liste,ListeEnt=ListeEntreprise()}
- Ninfos = textutils.serialise(Ninfo)
- send(id, Ninfos)
- end
- end
- function ActualiserE(Entreprise, Id)
- if fs.exists("Banque/Entreprise/"..Entreprise.."/Solde") then
- h = fs.open("Banque/Entreprise/"..Entreprise.."/Solde","r")
- soldeP = h.readAll()
- h.close()
- hst = textutils.serialise(EHistoriqueCR(Entreprise))
- Ninfo = {Act="ActualiserE",Solde=soldeP+0,Historique=hst}
- Ninfos = textutils.serialise(Ninfo)
- send(Id, Ninfos)
- Liste = ListeCompte()
- Ninfo = {Act="ListeComptesTab",Liste=Liste,ListeEnt=ListeEntreprise()}
- Ninfos = textutils.serialise(Ninfo)
- send(Id, Ninfos)
- end
- end
- function HistoriqueCW(Pseudo,txt)
- if fs.exists("Banque/Compte/"..Pseudo.."/Historique") then
- h = fs.open("Banque/Compte/"..Pseudo.."/Historique","r")
- hst = h.readAll()
- h.close()
- h = fs.open("Banque/Compte/"..Pseudo.."/Historique","w")
- h.write(txt.."\n"..hst)
- h.close()
- end
- if fs.exists("Banque/Compte/"..Pseudo.."/HistoriqueSave") then
- h = fs.open("Banque/Compte/"..Pseudo.."/HistoriqueSave","r")
- hst = h.readAll()
- h.close()
- h = fs.open("Banque/Compte/"..Pseudo.."/HistoriqueSave","w")
- h.write(txt.."\n"..hst)
- h.close()
- end
- end
- function HistoriqueCR(Pseudo)
- if fs.exists("Banque/Compte/"..Pseudo.."/Historique") then
- local historique={}
- h = fs.open("Banque/Compte/"..Pseudo.."/Historique","r")
- while true do
- result = h.readLine()
- if result == nil then
- break
- else
- if result ~= "" then
- historique[#historique+1] = result
- end
- end
- end
- h.close()
- return historique
- end
- end
- function EHistoriqueCW(Entreprise,txt)
- if fs.exists("Banque/Entreprise/"..Entreprise.."/Historique") then
- h = fs.open("Banque/Entreprise/"..Entreprise.."/Historique","r")
- hst = h.readAll()
- h.close()
- h = fs.open("Banque/Entreprise/"..Entreprise.."/Historique","w")
- h.write(txt.."\n"..hst)
- h.close()
- end
- end
- function EHistoriqueCR(Entreprise)
- if fs.exists("Banque/Entreprise/"..Entreprise.."/Historique") then
- local historique={}
- h = fs.open("Banque/Entreprise/"..Entreprise.."/Historique","r")
- while true do
- result = h.readLine()
- if result == nil then
- break
- else
- if result ~= "" then
- historique[#historique+1] = result
- end
- end
- end
- h.close()
- return historique
- end
- end
- function EntrepriseCR(Pseudo)
- if fs.exists("Banque/Compte/"..Pseudo.."/Entreprises") then
- local entreprises = {}
- h = fs.open("Banque/Compte/"..Pseudo.."/Entreprises","r")
- while true do
- result = h.readLine()
- if result == nil then
- break
- else
- if result ~= "" then
- entreprises[#entreprises+1] = result
- end
- end
- end
- h.close()
- return entreprises
- end
- end
- function EntrepriseAddMembre(Entreprise,Pseudo)
- if Pseudo ~= "" and Entreprise ~= nil then
- if fs.exists("Banque/Compte/"..Pseudo.."/Entreprises") then
- h = fs.open("Banque/Entreprise/"..Entreprise.."/Permissions/"..Pseudo,"w")
- nTable = {ModifPerm=false,Depos=true,Retrait=false,AddMembre=false,DeleteEntrep=false,DeleteMembre=false}
- h.write(textutils.serialise(nTable))
- h.close()
- h = fs.open("Banque/Entreprise/"..Entreprise.."/Membres","a")
- h.write("\n"..Pseudo)
- h.close()
- h = fs.open("Banque/Compte/"..Pseudo.."/Entreprises","a")
- h.write("\n"..Entreprise)
- h.close()
- end
- end
- end
- function EntreReadMember(Entreprise)
- if fs.exists("Banque/Entreprise/"..infos.Entreprise) then
- local membres = {}
- h = fs.open("Banque/Entreprise/"..Entreprise.."/Membres","r")
- while true do
- result = h.readLine()
- if result == nil then
- break
- else
- if result ~= "" then
- membres[#membres+1] = result
- end
- end
- end
- h.close()
- return membres
- end
- end
- function DeleteEntrepPlayer(Entreprise,Pseudo)
- if fs.exists("Banque/Compte/"..Pseudo.."/Entreprises") then
- local entreprises = {}
- h = fs.open("Banque/Compte/"..Pseudo.."/Entreprises","r")
- while true do
- result = h.readLine()
- if result == nil then
- break
- else
- if result == Entreprise then
- else
- if result ~= "" then
- entreprises[#entreprises+1] = result
- end
- end
- end
- end
- h.close()
- h = fs.open("Banque/Compte/"..Pseudo.."/Entreprises","w")
- for i = 1, #entreprises do
- h.write("\n"..entreprises[i])
- end
- h.close()
- membres = EntreReadMember(Entreprise)
- h = fs.open("Banque/Entreprise/"..Entreprise.."/Membres","w")
- for i = 1, #membres do
- if membres[i] == Pseudo then
- else
- h.write("\n"..membres[i])
- end
- end
- h.close()
- end
- end
- function EntreReadPermMember(Entreprise, Pseudo)
- if fs.exists("Banque/Entreprise/"..infos.Entreprise) then
- local Perm = {}
- h = fs.open("Banque/Entreprise/"..Entreprise.."/Permissions/"..Pseudo,"r")
- Perm = h.readAll()
- h.close()
- return textutils.unserialise(Perm)
- end
- end
- function isOp(pseudo)
- if fs.exists("Banque/Compte/"..pseudo.."/Statut") then
- local h = fs.open("Banque/Compte/"..pseudo.."/Statut","r")
- local statut = h.readAll()
- h.close()
- if statut == "OP" then
- return true
- else
- return false
- end
- end
- end
- function compareMDP(pseudo, mdp)
- if CompteExist(pseudo) then
- local h =fs.open("Banque/Compte/"..pseudo.."/Solde","r")
- nMdp = h.readAll()
- h.close()
- if mdp == nMdp then
- return true
- else
- return false
- end
- end
- end
- function GenKey(id,pseudo,somme,mdp)
- if type(id) == "number" and type(pseudo) == "string" and type(somme) == "number" and type(mdp) == "string" and fs.exists("Banque/Compte/"..pseudo) and somme > 0 then
- local h = fs.open("Banque/Compte/"..pseudo.."/Mdp","r")
- local nMdp = h.readAll()
- h.close()
- if mdp == nMdp then
- local lst = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
- local cle = ""
- if not fs.exists("Banque/Compte/"..pseudo.."/Keys/") then
- fs.makeDir("Banque/Compte/"..pseudo.."/Keys/")
- end
- while true do
- cle = ""
- for i=1,10 do
- rnd = math.random(1,#lst)
- rnd = (rnd + os.day() + os.time() + os.clock())%#lst
- cle = cle..lst:sub(rnd,rnd)
- end
- if #fs.find("Banque/Compte/*/Keys/"..cle) == 0 then
- break
- end
- end
- local h = fs.open("Banque/Compte/"..pseudo.."/Keys/"..cle,"w")
- h.write(somme)
- h.close()
- send(id, textutils.serialise({Act="KeyGen",Cle=cle}))
- end
- end
- end
- function UseKey(id,pseudo,somme,cle)
- if type(id) == "number" and type(pseudo) == "string" and type(somme) == "number" and type(cle) == "string" and fs.exists("Banque/Compte/"..pseudo) and somme > 0 then
- local lien = fs.find("Banque/Compte/*/Keys/"..cle)
- if #lien > 0 then
- local compte = fs.getDir(fs.getDir(lien[1]))
- if fs.getName(compte) ~= pseudo then
- local h = fs.open(compte.."/Solde","r")
- local soldeC = tonumber(h.readAll())
- h.close()
- h = fs.open("Banque/Compte/"..pseudo.."/Solde","r")
- local soldeD = tonumber(h.readAll())
- h.close()
- h = fs.open(lien[1],"r")
- local soldeK = tonumber(h.readAll())
- h.close()
- if soldeC >= somme and somme == soldeK then
- soldeD = soldeD + somme
- soldeC = soldeC - somme
- h = fs.open("Banque/Compte/"..pseudo.."/Solde","w")
- h.write(soldeD)
- h.close()
- h = fs.open(compte.."/Solde","w")
- h.write(soldeC)
- h.close()
- HistoriqueCW(pseudo,fs.getName(compte).."->"..pseudo..":"..infos.Somme..":UseKey")
- HistoriqueCW(fs.getName(compte),fs.getName(compte).."->"..pseudo..":"..infos.Somme..":UseKey")
- Succes("Somme transferé sur votre compte","MenuCle",id)
- else
- error("Somme incorrecte, supression de la cle","MenuCle",id)
- end
- fs.delete(lien[1])
- else
- HistoriqueCW(pseudo,fs.getName(compte).."->"..pseudo..":"..infos.Somme..":UseKey")
- Succes("Somme transferé sur votre compte","MenuCle",id)
- end
- else
- error("Cle inexistante","MenuCle",id)
- end
- elseif type(id) == "number" and type(pseudo) == "string" and type(somme) == "number" and type(cle) == "string" and fs.exists("Banque/Entreprise/"..pseudo) and somme > 0 then
- local lien = fs.find("Banque/Compte/*/Keys/"..cle)
- if #lien > 0 then
- local compte = fs.getDir(fs.getDir(lien[1]))
- local h = fs.open(compte.."/Solde","r")
- local soldeC = tonumber(h.readAll())
- h.close()
- h = fs.open("Banque/Entreprise/"..pseudo.."/Solde","r")
- local soldeD = tonumber(h.readAll())
- h.close()
- h = fs.open(lien[1],"r")
- local soldeK = tonumber(h.readAll())
- h.close()
- if soldeC >= somme and somme == soldeK then
- soldeD = soldeD + somme
- soldeC = soldeC - somme
- h = fs.open("Banque/Entreprise/"..pseudo.."/Solde","w")
- h.write(soldeD)
- h.close()
- h = fs.open(compte.."/Solde","w")
- h.write(soldeC)
- h.close()
- EHistoriqueCW(pseudo,fs.getName(compte).."->"..pseudo..":"..infos.Somme..":UseKey")
- HistoriqueCW(fs.getName(compte),fs.getName(compte).."->"..pseudo..":"..infos.Somme..":UseKey")
- Succes("Somme transferé sur votre compte","MenuCle",id)
- else
- error("Somme incorrecte, supression de la cle","MenuCle",id)
- end
- fs.delete(lien[1])
- else
- error("Cle inexistante","MenuCle",id)
- end
- else
- error("Donnée invalides","MenuCle",id)
- end
- end
- function startup()
- local ATMliste = ListeATM()
- if ATMliste == nil then
- else
- for k, v in pairs(ATMliste) do
- ATM[v+0]=true
- end
- end
- if fs.exists("whitelist.json") then
- whitelist = DecomposeJson("whitelist.json")
- for i = 1, #whitelist do
- CreateCompte(whitelist[i])
- end
- end
- if fs.exists("ops.json") then
- ops = DecomposeJson("ops.json")
- for i = 1, #ops do
- if fs.exists("Banque/Compte/"..ops[i]) then
- h = fs.open("Banque/Compte/"..ops[i].."/Statut","w")
- h.write("OP")
- h.close()
- end
- end
- end
- while true do
- local CompteValide=false
- id, message = NetSphere.receive()
- print(id, message)
- infos = textutils.unserialise(message)
- if type(infos) == "nil" then
- else
- if infos.Act == "Connection" then
- if fs.exists("Banque/Compte/"..infos.Pseudo.."/") then
- if fs.exists("Banque/Compte/"..infos.Pseudo.."/Mdp") then
- h = fs.open("Banque/Compte/"..infos.Pseudo.."/Mdp","r")
- local motdepasse = h.readAll()
- h.close()
- if infos.Mdp == motdepasse then
- CompteValide=true
- else
- CompteValide=false
- end
- else
- CompteValide=false
- end
- else
- CompteValide=false
- end
- if CompteValide == true then
- if fs.exists("Banque/Compte/"..infos.Pseudo.."/Solde") then
- h = fs.open("Banque/Compte/"..infos.Pseudo.."/Solde","r")
- sld = h.readAll()
- h.close()
- else
- h = fs.open("Banque/Compte/"..infos.Pseudo.."/Solde","w")
- h.write(1000)
- h.close()
- sld = 1000
- end
- if fs.exists("Banque/Compte/"..infos.Pseudo.."/Statut") then
- h = fs.open("Banque/Compte/"..infos.Pseudo.."/Statut","r")
- statut = h.readAll()
- h.close()
- else
- h = fs.open("Banque/Compte/"..infos.Pseudo.."/Statut","w")
- h.write("PLAYER")
- h.close()
- statut = "PLAYER"
- end
- histo = textutils.serialise(HistoriqueCR(infos.Pseudo))
- entp = textutils.serialise(EntrepriseCR(infos.Pseudo))
- Ninfo = {Act="CompteValide",Solde=sld,Historique=histo,Entreprises=entp,Statut=statut}
- Ninfos = textutils.serialise(Ninfo)
- send(id, Ninfos)
- IDConnecter[infos.Pseudo] = id
- else
- Ninfo = {Act="CompteNValide"}
- Ninfos = textutils.serialise(Ninfo)
- send(id, Ninfos)
- end
- elseif infos.Act == "GenKey" then
- GenKey(id,infos.psd,infos.Somme,infos.mdp)
- elseif infos.Act == "UseKey" then
- UseKey(id,infos.psd,infos.Somme,infos.Cle)
- elseif infos.Act == "ModifMdpPlayer" then
- if fs.exists("Banque/Compte/"..infos.Pseudo) then
- h = fs.open("Banque/Compte/"..infos.Pseudo.."/Mdp","r")
- AncienMdp = h.readAll()
- h.close()
- if AncienMdp == infos.AncienMdp then
- h = fs.open("Banque/Compte/"..infos.Pseudo.."/Mdp","w")
- h.write(infos.NouveauMdp)
- h.close()
- Ninfo = {Act="NvmdpOk"}
- Ninfos = textutils.serialise(Ninfo)
- send(id, Ninfos)
- else
- Ninfo = {Act="AncMdpInco"}
- Ninfos = textutils.serialise(Ninfo)
- send(id, Ninfos)
- end
- end
- elseif infos.Act == "RecupHistorique" then
- if CompteExist(infos.Pseudo) then
- if fs.exists("Banque/Compte/"..infos.Pseudo.."/HistoriqueSave") then
- h = fs.open("Banque/Compte/"..infos.Pseudo.."/HistoriqueSave","r")
- hst = h.readAll()
- h.close()
- h = fs.open("Banque/Compte/"..infos.Pseudo.."/Historique","w")
- h.write(hst)
- h.close()
- ActualiserC(infos.Pseudo,id)
- end
- end
- elseif infos.Act == "AddMemberConnection" then
- if fs.exists("Banque/Entreprise/"..infos.Entreprise) then
- Membres = EntreReadMember(infos.Entreprise)
- admit = false
- for i = 1, #Membres do
- if infos.Demandeur == Membres[i] then
- admit = true
- end
- end
- if admit == true then
- nMembres = textutils.serialise(EntreReadMember(infos.Entreprise))
- Ninfo = {Act="AddMemberConnecAut",membres=nMembres}
- Ninfos = textutils.serialise(Ninfo)
- send(id, Ninfos)
- else
- error("Vous ne faite pas parti de l'entreprise !","MenuEntreprise",id)
- end
- else
- Ninfo = {Act="EntrepriseNExist"}
- Ninfos = textutils.serialise(Ninfo)
- send(id, Ninfos)
- end
- elseif infos.Act == "AddMember" then
- if fs.exists("Banque/Entreprise/"..infos.Entreprise) then
- if fs.exists("Banque/Entreprise/"..infos.Entreprise.."/Permissions/"..infos.Demandeur) then
- h = fs.open("Banque/Entreprise/"..infos.Entreprise.."/Permissions/"..infos.Demandeur,"r")
- nTableB = h.readAll()
- h.close()
- nTable = textutils.unserialise(nTableB)
- nMembres = EntreReadMember(infos.Entreprise)
- local dejaMit = false
- for i = 1, #nMembres do
- if nMembres[i] == infos.pseudo then
- dejaMit = true
- end
- end
- if dejaMit == false then
- if nTable["AddMembre"] == true then
- if fs.exists("Banque/Compte/"..infos.pseudo) then
- EntrepriseAddMembre(infos.Entreprise,infos.pseudo)
- nMembres = EntreReadMember(infos.Entreprise)
- Ninfo = {Act="AddMemberConnecAut",membres=textutils.serialise(nMembres)}
- Ninfos = textutils.serialise(Ninfo)
- send(id, Ninfos)
- else
- Ninfo = {Act="CompteNExist"}
- Ninfos = textutils.serialise(Ninfo)
- send(id, Ninfos)
- end
- else
- Ninfo = {Act="AddMemberConnecRef"}
- Ninfos = textutils.serialise(Ninfo)
- send(id, Ninfos)
- end
- end
- end
- else
- Ninfo = {Act="EntrepriseNExist"}
- Ninfos = textutils.serialise(Ninfo)
- send(id, Ninfos)
- end
- elseif infos.Act == "ReplyPerm" then
- if fs.exists("Banque/Entreprise/"..infos.Entreprise) then
- if fs.exists("Banque/Entreprise/"..infos.Entreprise.."/Permissions/"..infos.pseudo) then
- h = fs.open("Banque/Entreprise/"..infos.Entreprise.."/Permissions/"..infos.pseudo,"w")
- h.write(infos.permissions)
- h.close()
- end
- end
- elseif infos.Act == "PermMember" then
- if fs.exists("Banque/Entreprise/"..infos.Entreprise) then
- if fs.exists("Banque/Entreprise/"..infos.Entreprise.."/Permissions/"..infos.Demandeur) then
- h = fs.open("Banque/Entreprise/"..infos.Entreprise.."/Permissions/"..infos.Demandeur,"r")
- nTableB = h.readAll()
- h.close()
- nTable = textutils.unserialise(nTableB)
- if nTable["ModifPerm"] == true then
- if fs.exists("Banque/Entreprise/"..infos.Entreprise.."/Permissions/"..infos.pseudo) then
- h = fs.open("Banque/Entreprise/"..infos.Entreprise.."/Permissions/"..infos.pseudo,"r")
- perm = h.readAll()
- h.close()
- Ninfo = {Act="PermEdit",permissions=perm,pseudo=infos.pseudo,entrep=infos.Entreprise}
- Ninfos = textutils.serialise(Ninfo)
- send(id, Ninfos)
- else
- Ninfo = {Act="CompteNExist"}
- Ninfos = textutils.serialise(Ninfo)
- send(id, Ninfos)
- end
- else
- Ninfo = {Act="PermMemberConnecRef"}
- Ninfos = textutils.serialise(Ninfo)
- send(id, Ninfos)
- end
- end
- else
- Ninfo = {Act="EntrepriseNExist"}
- Ninfos = textutils.serialise(Ninfo)
- send(id, Ninfos)
- end
- elseif infos.Act == "DelMember" then
- if fs.exists("Banque/Entreprise/"..infos.Entreprise) then
- if fs.exists("Banque/Entreprise/"..infos.Entreprise.."/Permissions/"..infos.Demandeur) then
- if infos.pseudo == infos.Demandeur then
- Ninfo = {Act="DelMemberImpossible"}
- Ninfos = textutils.serialise(Ninfo)
- send(id, Ninfos)
- else
- h = fs.open("Banque/Entreprise/"..infos.Entreprise.."/Permissions/"..infos.Demandeur,"r")
- nTableB = h.readAll()
- h.close()
- nTable = textutils.unserialise(nTableB)
- if nTable["DeleteMembre"] == true then
- if fs.exists("Banque/Compte/"..infos.pseudo) then
- DeleteEntrepPlayer(infos.Entreprise,infos.pseudo)
- nMembres = EntreReadMember(infos.Entreprise)
- Ninfo = {Act="AddMemberConnecAut",membres=textutils.serialise(nMembres)}
- Ninfos = textutils.serialise(Ninfo)
- send(id, Ninfos)
- else
- Ninfo = {Act="CompteNExist"}
- Ninfos = textutils.serialise(Ninfo)
- send(id, Ninfos)
- end
- else
- Ninfo = {Act="DelMemberConnecRef"}
- Ninfos = textutils.serialise(Ninfo)
- send(id, Ninfos)
- end
- end
- end
- else
- Ninfo = {Act="EntrepriseNExist"}
- Ninfos = textutils.serialise(Ninfo)
- send(id, Ninfos)
- end
- elseif infos.Act == "SupprEntreprise" then
- if fs.exists("Banque/Entreprise/"..infos.Entreprise) then
- if fs.exists("Banque/Entreprise/"..infos.Entreprise.."/Permissions/"..infos.Demandeur) then
- h = fs.open("Banque/Entreprise/"..infos.Entreprise.."/Permissions/"..infos.Demandeur,"r")
- nTableB = h.readAll()
- h.close()
- nTable = textutils.unserialise(nTableB)
- if nTable["DeleteEntrep"] == true then
- Membres = EntreReadMember(infos.Entreprise)
- for i = 1, #Membres do
- h = fs.open("Banque/Compte/"..Membres[i].."/Solde","r")
- solde = h.readAll()
- h.close()
- h = fs.open("Banque/Entreprise/"..infos.Entreprise.."/Solde","r")
- soldeE = h.readAll()
- h.close()
- solde = solde + (soldeE/#Membres)
- h = fs.open("Banque/Compte/"..Membres[i].."/Solde","w")
- h.write(solde)
- h.close()
- DeleteEntrepPlayer(infos.Entreprise,Membres[i])
- end
- fs.delete("Banque/Entreprise/"..infos.Entreprise)
- ActualiserC(infos.Demandeur, id)
- else
- Ninfo = {Act="DeleteEntrepRef"}
- Ninfos = textutils.serialise(Ninfo)
- send(id, Ninfos)
- end
- else
- Ninfo = {Act="DeleteEntrepRef"}
- Ninfos = textutils.serialise(Ninfo)
- send(id, Ninfos)
- end
- else
- Ninfo = {Act="EntrepriseNExist"}
- Ninfos = textutils.serialise(Ninfo)
- send(id, Ninfos)
- end
- elseif infos.Act == "CreeEntreprise" then
- if fs.exists("Banque/Entreprise/"..infos.Nom) then
- Ninfo = {Act="ErreurCreeEntreprise"}
- Ninfos = textutils.serialise(Ninfo)
- send(id, Ninfos)
- else
- h = fs.open("Banque/Entreprise/"..infos.Nom.."/Solde","w")
- h.write(0)
- h.close()
- h = fs.open("Banque/Entreprise/"..infos.Nom.."/Historique","w")
- h.write("")
- h.close()
- h = fs.open("Banque/Entreprise/"..infos.Nom.."/Permissions/"..infos.Proprio,"w")
- nTable = {ModifPerm=true,Depos=true,Retrait=true,AddMembre=true,DeleteEntrep=true,DeleteMembre=true}
- h.write(textutils.serialise(nTable))
- h.close()
- h = fs.open("Banque/Entreprise/"..infos.Nom.."/Membres","w")
- h.write(infos.Proprio)
- h.close()
- h = fs.open("Banque/Compte/"..infos.Proprio.."/Entreprises","a")
- h.write("\n"..infos.Nom)
- h.close()
- ActualiserC(infos.Proprio, id)
- end
- elseif infos.Act == "EntrepriseTransfers" then
- if fs.exists("Banque/Entreprise/"..infos.Entreprise) then
- Membres = EntreReadMember(infos.Entreprise)
- admit = false
- for i = 1, #Membres do
- if infos.Demandeur == Membres[i] then
- admit = true
- end
- end
- if admit == true then
- h = fs.open("Banque/Entreprise/"..infos.Entreprise.."/Solde","r")
- solde = h.readAll()
- h.close()
- histo = EHistoriqueCR(infos.Entreprise)
- Ninfo = {Act="TransferConnecAut",Solde=solde,Historique=histo}
- Ninfos = textutils.serialise(Ninfo)
- send(id, Ninfos)
- end
- end
- elseif infos.Act == "RetraitToEntreprise" then
- if infos.Somme > 0 then
- if fs.exists("Banque/Compte/"..infos.Proprio.."/Solde") then
- if fs.exists("Banque/Entreprise/"..infos.Entreprise.."/Solde") then
- h = fs.open("Banque/Entreprise/"..infos.Entreprise.."/Permissions/"..infos.Proprio,"r")
- nTableB = h.readAll()
- h.close()
- nTable = textutils.unserialise(nTableB)
- if nTable["Retrait"] == true then
- h = fs.open("Banque/Entreprise/"..infos.Entreprise.."/Solde","r")
- soldeP = h.readAll()
- h.close()
- if infos.Somme+0 <= soldeP+0 then
- h = fs.open("Banque/Compte/"..infos.Proprio.."/Solde","r")
- soldeD = h.readAll()
- h.close()
- soldeP = soldeP - infos.Somme
- soldeD = soldeD + infos.Somme
- h = fs.open("Banque/Compte/"..infos.Proprio.."/Solde","w")
- h.write(soldeD)
- h.close()
- h = fs.open("Banque/Entreprise/"..infos.Entreprise.."/Solde","w")
- h.write(soldeP)
- h.close()
- HistoriqueCW(infos.Proprio,infos.Entreprise.."->"..infos.Proprio..":"..infos.Somme..":V")
- EHistoriqueCW(infos.Entreprise,infos.Entreprise.."->"..infos.Proprio..":"..infos.Somme..":V")
- ActualiserC(infos.Proprio,id)
- ActualiserE(infos.Entreprise,id)
- if IDConnecter[infos.Entreprise] == nil then
- else
- ActualiserC(infos.Entreprise,IDConnecter[infos.Entreprise]+0)
- end
- end
- else
- Ninfo = {Act="RetraitEntrepRef"}
- Ninfos = textutils.serialise(Ninfo)
- send(id, Ninfos)
- end
- else
- EHistoriqueCW(infos.Proprio,infos.Entreprise.."->"..infos.Proprio..":"..infos.Somme..":X")
- ActualiserE(infos.Entreprise, id)
- end
- end
- end
- elseif infos.Act == "setPLAYER" then
- if fs.exists("Banque/Compte/"..infos.Pseudo) then
- if infos.Pseudo == "" then
- error("Compte Inexistant !","MenuOP",id)
- else
- h = fs.open("Banque/Compte/"..infos.Pseudo.."/Statut","w")
- h.write("PLAYER")
- h.close()
- Succes("Compte mit PLAYER","MenuOP",id)
- end
- else
- error("Compte Inexistant !", "MenuOP",id)
- end
- elseif infos.Act == "setOP" then
- if fs.exists("Banque/Compte/"..infos.Pseudo) then
- if infos.Pseudo == "" then
- error("Compte Inexistant !","MenuOP",id)
- else
- h = fs.open("Banque/Compte/"..infos.Pseudo.."/Statut","w")
- h.write("OP")
- h.close()
- Succes("Compte mit OP","MenuOP",id)
- end
- else
- error("Compte Inexistant !","MenuOP",id)
- end
- elseif infos.Act == "ChangerMdp" then
- if fs.exists("Banque/Compte/"..infos.Pseudo) then
- h = fs.open("Banque/Compte/"..infos.Pseudo.."/Mdp","w")
- h.write(infos.Mdp)
- h.close()
- Succes("Mot de passe modifié","MenuOP",id)
- else
- error("Compte Inexistant !","MenuOP",id)
- end
- elseif infos.Act == "ListeComptes" then
- Liste = ListeCompte()
- Ninfo = {Act="ListeComptesTab",Liste=Liste,ListeEnt=ListeEntreprise()}
- Ninfos = textutils.serialise(Ninfo)
- send(id, Ninfos)
- elseif infos.Act == "ListeComptesD" then
- Liste = ListeCompte()
- fs.delete("ListeCompte")
- h = fs.open("ListeCompte","w")
- for i =1, #Liste do
- h.write(Liste[i].."\n")
- end
- h.close()
- h = fs.open("ListeCompte","r")
- lst = h.readAll()
- h.close()
- Ninfo = {Act="ListesDComptes",Liste=lst}
- Ninfos = textutils.serialise(Ninfo)
- send(id, Ninfos)
- elseif infos.Act == "StealPercent" then
- ComptesR = ListeCompte()
- for i=1, #ComptesR do
- if fs.exists("Banque/Compte/"..ComptesR[i].."/Solde") then
- h = fs.open("Banque/Compte/"..ComptesR[i].."/Solde","r")
- solde = h.readAll()
- h.close()
- pourcent = infos.Pourcent * solde / 100
- solde = solde - pourcent
- h = fs.open("Banque/Compte/"..ComptesR[i].."/Solde","w")
- h.write(solde)
- h.close()
- end
- end
- Succes("Pourcentage retiré a *","MenuOP",id)
- elseif infos.Act == "AddPercent" then
- ComptesR = ListeCompte()
- for i=1, #ComptesR do
- if fs.exists("Banque/Compte/"..ComptesR[i].."/Solde") then
- h = fs.open("Banque/Compte/"..ComptesR[i].."/Solde","r")
- solde = h.readAll()
- h.close()
- pourcent = infos.Pourcent * solde / 100
- solde = solde + pourcent
- h = fs.open("Banque/Compte/"..ComptesR[i].."/Solde","w")
- h.write(solde)
- h.close()
- end
- end
- Succes("Pourcentage ajouté a *","MenuOP",id)
- elseif infos.Act == "AddATM" then
- AddATM(infos.ATMID.."")
- Succes("ID ATM Ajouté","MenuOP",id)
- elseif infos.Act == "DelATM" then
- DelATM(infos.ATMID.."")
- Succes("ID ATM Retiré","MenuOP",id)
- elseif infos.Act == "StealMonney" then
- if fs.exists("Banque/Compte/"..infos.Pseudo.."/Solde") then
- h = fs.open("Banque/Compte/"..infos.Pseudo.."/Solde","r")
- solde = h.readAll()
- h.close()
- solde = solde - infos.Somme
- h = fs.open("Banque/Compte/"..infos.Pseudo.."/Solde","w")
- h.write(solde)
- h.close()
- Succes("Compte Débité","MenuOP",id)
- else
- error("Compte Inexistant !","MenuOP",id)
- end
- elseif infos.Act == "AddMonney" then
- if fs.exists("Banque/Compte/"..infos.Pseudo.."/Solde") then
- h = fs.open("Banque/Compte/"..infos.Pseudo.."/Solde","r")
- solde = h.readAll()
- h.close()
- solde = solde + infos.Somme
- h = fs.open("Banque/Compte/"..infos.Pseudo.."/Solde","w")
- h.write(solde)
- h.close()
- Succes("Compte Créditer","MenuOP",id)
- else
- error("Compte Inexistant !","MenuOP",id)
- end
- elseif infos.Act == "DelCompte" then
- if CompteExist(infos.Pseudo) then
- if infos.Pseudo == "" then
- error("Compte Inexistant !","MenuOP",id)
- else
- DeleteCompte(infos.Pseudo)
- for nPseudo, nID in pairs(IDConnecter) do
- Liste = ListeCompte()
- Ninfo = {Act="ListeComptesTab",Liste=Liste,ListeEnt=ListeEntreprise()}
- Ninfos = textutils.serialise(Ninfo)
- send(nID, Ninfos)
- end
- Succes("Compte supprimé !","MenuOP",id)
- end
- else
- error("Compte Inexistant !","MenuOP",id)
- end
- elseif infos.Act == "CreeCompte" then
- if CompteExist(infos.Pseudo) == false then
- CreateCompte(infos.Pseudo)
- for nPseudo, nID in pairs(IDConnecter) do
- Liste = ListeCompte()
- Ninfo = {Act="ListeComptesTab",Liste=Liste,ListeEnt=ListeEntreprise()}
- Ninfos = textutils.serialise(Ninfo)
- send(nID, Ninfos)
- end
- Succes("Compte Crée !","MenuOP",id)
- else
- error("Compte déja existant !","MenuOP",id)
- end
- elseif infos.Act == "TransferToEntreprise" then
- if infos.Somme > 0 then
- if fs.exists("Banque/Compte/"..infos.Proprio.."/Solde") then
- if fs.exists("Banque/Entreprise/"..infos.Entreprise.."/Solde") then
- Membres = EntreReadMember(infos.Entreprise)
- admit = false
- for i = 1, #Membres do
- if infos.Proprio == Membres[i] then
- admit = true
- end
- end
- if admit == true then
- h = fs.open("Banque/Entreprise/"..infos.Entreprise.."/Permissions/"..infos.Proprio,"r")
- nTableB = h.readAll()
- h.close()
- nTable = textutils.unserialise(nTableB)
- if nTable["Depos"] == true then
- h = fs.open("Banque/Compte/"..infos.Proprio.."/Solde","r")
- soldeP = h.readAll()
- h.close()
- if infos.Somme+0 <= soldeP+0 then
- h = fs.open("Banque/Entreprise/"..infos.Entreprise.."/Solde","r")
- soldeD = h.readAll()
- h.close()
- soldeP = soldeP - infos.Somme
- soldeD = soldeD + infos.Somme
- h = fs.open("Banque/Compte/"..infos.Proprio.."/Solde","w")
- h.write(soldeP)
- h.close()
- h = fs.open("Banque/Entreprise/"..infos.Entreprise.."/Solde","w")
- h.write(soldeD)
- h.close()
- HistoriqueCW(infos.Proprio,infos.Proprio.."->"..infos.Entreprise..":"..infos.Somme..":V")
- EHistoriqueCW(infos.Entreprise,infos.Proprio.."->"..infos.Entreprise..":"..infos.Somme..":V")
- ActualiserC(infos.Proprio,id)
- ActualiserE(infos.Entreprise,id)
- if IDConnecter[infos.Entreprise] == nil then
- else
- ActualiserC(infos.Entreprise,IDConnecter[infos.Entreprise]+0)
- end
- end
- else
- Ninfo = {Act="DeposEntrepRef"}
- Ninfos = textutils.serialise(Ninfo)
- send(id, Ninfos)
- end
- else
- EHistoriqueCW(infos.Proprio,infos.Proprio.."->"..infos.Entreprise..":"..infos.Somme..":X")
- ActualiserE(infos.Entreprise, id)
- end
- else
- end
- end
- end
- elseif infos.Act == "RecupHisto" then
- if CompteExist(infos.Pseudo) then
- if fs.exists("Banque/Compte/"..infos.Pseudo.."/HistoriqueSave") then
- h = fs.open("Banque/Compte/"..infos.Pseudo.."/HistoriqueSave","r")
- hst = h.readAll()
- h.close()
- Ninfo = {Act="ReplyHisto",Historique=hst}
- Ninfos = textutils.serialise(Ninfo)
- send(id, Ninfos)
- end
- else
- error("Compte Inexistant !","MenuOP",id)
- end
- elseif infos.Act == "Transfer" then
- if infos.Somme > 0 then
- if fs.exists("Banque/Compte/"..infos.Proprio.."/Solde") then
- if fs.exists("Banque/Compte/"..infos.Destinataire.."/Solde") then
- if infos.Proprio == infos.Destinataire then
- else
- h = fs.open("Banque/Compte/"..infos.Proprio.."/Solde","r")
- soldeP = h.readAll()
- h.close()
- if infos.Somme+0 <= soldeP+0 then
- h = fs.open("Banque/Compte/"..infos.Destinataire.."/Solde","r")
- soldeD = h.readAll()
- h.close()
- soldeP = soldeP - infos.Somme
- soldeD = soldeD + infos.Somme
- h = fs.open("Banque/Compte/"..infos.Proprio.."/Solde","w")
- h.write(soldeP)
- h.close()
- h = fs.open("Banque/Compte/"..infos.Destinataire.."/Solde","w")
- h.write(soldeD)
- h.close()
- HistoriqueCW(infos.Proprio,infos.Proprio.."->"..infos.Destinataire..":"..infos.Somme..":V")
- HistoriqueCW(infos.Destinataire,infos.Proprio.."->"..infos.Destinataire..":"..infos.Somme..":V")
- ActualiserC(infos.Proprio,id)
- if IDConnecter[infos.Destinataire] == nil then
- else
- ActualiserC(infos.Destinataire,IDConnecter[infos.Destinataire]+0)
- end
- end
- end
- elseif fs.exists("Banque/Entreprise/"..infos.Destinataire.."/Solde") then
- h = fs.open("Banque/Compte/"..infos.Proprio.."/Solde","r")
- soldeP = h.readAll()
- h.close()
- if infos.Somme+0 <= soldeP+0 then
- h = fs.open("Banque/Entreprise/"..infos.Destinataire.."/Solde","r")
- soldeD = h.readAll()
- h.close()
- soldeP = soldeP - infos.Somme
- soldeD = soldeD + infos.Somme
- h = fs.open("Banque/Compte/"..infos.Proprio.."/Solde","w")
- h.write(soldeP)
- h.close()
- h = fs.open("Banque/Entreprise/"..infos.Destinataire.."/Solde","w")
- h.write(soldeD)
- h.close()
- HistoriqueCW(infos.Proprio,infos.Proprio.."->"..infos.Destinataire..":"..infos.Somme..":V")
- ActualiserC(infos.Proprio,id)
- if IDConnecter[infos.Destinataire] == nil then
- else
- ActualiserC(infos.Destinataire,IDConnecter[infos.Destinataire]+0)
- end
- end
- else
- HistoriqueCW(infos.Proprio,infos.Proprio.."->"..infos.Destinataire..":"..infos.Somme..":X")
- ActualiserC(infos.Proprio, id)
- end
- end
- end
- elseif infos.Act == "ActualiserC" then
- ActualiserC(infos.Proprio, id)
- elseif infos.Act == "ActualiserE" then
- ActualiserE(infos.Entreprise, id)
- elseif infos.Act == "EffHistorique" then
- EffHistorique(infos.Pseudo)
- ActualiserC(infos.Pseudo, id)
- elseif infos.Act == "Deconnection" then
- local nTempo = {}
- for pseudo, IDn in pairs(IDConnecter) do
- if IDn == id then
- nTempo[#nTempo+1] = pseudo
- end
- end
- for i=1,#nTempo do
- IDConnecter[nTempo[i]]= nil
- end
- end
- end
- end
- end
- function diskEject()
- while true do
- event, side = os.pullEvent("disk")
- disk.eject(side)
- end
- end
- parallel.waitForAll(startup,diskEject,HaveAModem)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement