37 posts
Location
Germany, Osnabrueck
Posted 11 December 2013 - 05:25 PM
Hello there,
I'm playing on a rather small Tekkit Classic server and I'd like to create a login-system for my house and its counterparts.
I was wondering how I could setup a database on a disk, connected to my server and access that through other computers.
Thanks in advance!
1852 posts
Location
Sweden
Posted 12 December 2013 - 01:47 PM
Well here's some APIs you should check out that will help you
-
Rednet -
FsDo you have any current code? What is it you know and don't know?
37 posts
Location
Germany, Osnabrueck
Posted 12 December 2013 - 03:55 PM
I was thinking of doing something similar to this (This is Java code)
private void start() {
System.out.prinln("Welcome to BLoginv1.0!");
System.out.println("Please enter a command");
String input = System.in.read();
if (input.equals("login") | input.equals("Login")) {
login();
} else if (input.equals("createUser") | input.equals("CreateUser")) {
createUser();
} else if (input.equals("delUser") | input.equals("DelUser")) {
deluser();
} else {
System.out.prinlt("Unknown command!");
Thread.sleep(3000);
start();
}
}
private void login() {
System.out.println("Please enter your username:");
String in = System.in.read();
BufferedReader reader = new BufferedReader(new InputStreamReader("<File>").getStream())));
String line;
while ((line = reader.ReadLine()) != null) {
if (line == in) {
System.out.prinln("Username is valid...");
password();
}
}
}
private void password() {
}
And so on, if you get what I mean.
I just don't know how I could access files (if that's even a possibility) on a disk, and then access that disk, connected to a central computer, via rednet.
I'll check out the APIs. Any further assistance would be much appreciated. It's getting real annoying that everyone's just popping into my house when I don't want them to
1852 posts
Location
Sweden
Posted 12 December 2013 - 05:54 PM
Well if you want you could have it pretty simple, Something like this
-- Preventing CTRL + T --
os.pullEvent = os.pullEventRaw
local admin = {
name = "<Admin Name>",
pass = "<Admin Pass>",
}
local function clear( color )
if color ~= nil then
term.setBackgroundColor( color )
end
term.clear()
term.setCursorPos(1,1)
end
local function saveTable( file, table)
local f = fs.open( shell.resolve( file ), "w")
f.writeLine(textutils.serialize(table))
f.close()
end
local function getTable( file )
local f = fs.open( shell.resolve( file ), "r")
local t = textutils.unserialize( f.readAll() )
f.close()
return t
end
local users = {}
if fs.exists(shell.resolve(".users")) then
users = getTable(".users")
end
local function checkName( str )
for i = 1,#users do
if str == users[i].name then
return true
end
end
return false
end
local function checkPassword( str )
for i = 1,#users do
if str == users[i].pass then
return true
end
end
return false
end
while true do
clear()
print("Welcome to BLoginv1.0!")
print("\n\nCommands\nCreateUser | DelUser | Login")
write("Command: ")
local command = read()
if string.lower(command) == "createuser" then
clear()
write("Admin: ")
local name = read()
if name == admin.name then
write("\nPassword: ")
local pass = read("*")
if pass == admin.pass then
print("Success!")
sleep(.5)
clear()
local nUser = {}
write("New User: ")
nUser.name = read()
write("Password: ")
nUser.pass = read("*")
table.insert(users, nUser)
saveTable(".users", users)
else
print("Wrong password!")
end
else
print("Wrong name!")
end
elseif string.lower(command) == "deluser" then
clear()
write("Admin: ")
local name = read()
if name == admin.name then
write("\nPassword: ")
local pass = read("*")
if pass == admin.pass then
print("Success!")
sleep(.5)
clear()
write("User: ")
local name = read()
for i = 1,#users do
if string.lower(name) == string.lower(users[i].name) then
table.remove(users, i)
print("Successfully removed: " .. name)
os.pullEvent()
break
end
end
else
print("Wrong password!")
end
else
print("Wrong name!")
end
elseif string.lower(command) == "login" then
clear()
write("Username: ")
local username = read()
if checkName( username ) then
write("\nPassword: ")
local password = read("*")
if checkPassword( password) then
print("Successfully logged in!")
sleep(.5)
-- Do what you want when you're logged in here
else
print("Wrong password!")
sleep(.5)
end
else
print("No such user! D:")
sleep(.5)
end
end
end
37 posts
Location
Germany, Osnabrueck
Posted 12 December 2013 - 10:58 PM
Well if you want you could have it pretty simple, Something like this
-- Preventing CTRL + T -- os.pullEvent = os.pullEventRaw local admin = { name = "", pass = "", } local function clear( color ) if color ~= nil then term.setBackgroundColor( color ) end term.clear() term.setCursorPos(1,1) end local function saveTable( file, table) local f = fs.open( shell.resolve( file ), "w") f.writeLine(textutils.serialize(table)) f.close() end local function getTable( file ) local f = fs.open( shell.resolve( file ), "r") local t = textutils.unserialize( f.readAll() ) f.close() return t end local users = {} if fs.exists(shell.resolve(".users")) then users = getTable(".users") end local function checkName( str ) for i = 1,#users do if str == users[i].name then return true end end return false end local function checkPassword( str ) for i = 1,#users do if str == users[i].pass then return true end end return false end while true do clear() print("Welcome to BLoginv1.0!") print("\n\nCommands\nCreateUser | DelUser | Login") write("Command: ") local command = read() if string.lower(command) == "createuser" then clear() write("Admin: ") local name = read() if name == admin.name then write("\nPassword: ") local pass = read("*") if pass == admin.pass then print("Success!") sleep(.5) clear() local nUser = {} write("New User: ") nUser.name = read() write("Password: ") nUser.pass = read("*") table.insert(users, nUser) saveTable(".users", users) else print("Wrong password!") end else print("Wrong name!") end elseif string.lower(command) == "deluser" then clear() write("Admin: ") local name = read() if name == admin.name then write("\nPassword: ") local pass = read("*") if pass == admin.pass then print("Success!") sleep(.5) clear() write("User: ") local name = read() for i = 1,#users do if string.lower(name) == string.lower(users[i].name) then table.remove(users, i) print("Successfully removed: " .. name) os.pullEvent() break end end else print("Wrong password!") end else print("Wrong name!") end elseif string.lower(command) == "login" then clear() write("Username: ") local username = read() if checkName( username ) then write("\nPassword: ") local password = read("*") if checkPassword( password) then print("Successfully logged in!") sleep(.5) -- Do what you want when you're logged in here else print("Wrong password!") sleep(.5) end else print("No such user! D:") sleep(.5) end end end
Awesome, thanks!
Now all I have to do is get it to run off a server.
Luckily I have coding experience in C#, Java and VB :D/>