Login
#31
To get the values out, you just use a SELECT sql command:
Code:
SELECT * FROM password WHERE name='Niels';

Then, there's the Lua binding, which dictates how to get to the values that the SQL database returns. It turns out the binding is pretty straightforward. You call the "exec" function on the database object, it has three parameters, the sql command, callback and userdata. It then calls the callback for each row of data that the sql command produced. The userdata parameter is given to the callback as well, it is a way to pass any kind of information through. So, for example, this will be a skeleton code for you:
-- Somewhere global:
PwdDB = {};  -- The password database object

-- In the Initialize function:
PwdDB, ErrCode, ErrMsg = sqlite3.open("pwd.sqlite");
-- TODO: Handle errors in ErrCode

-- In the login hook:
local UserName = ...;  -- Username of the player logging in
local PasswordGiven = ...;  -- What password is the user logging in with?
local ShouldAllowLogin = false;
local function ProcessRow(UserData, NumCols, Values, Names)
	for i = 1, NumCols do
		if (Names[i] == "Password") then  -- "Password" is the column name
			ShouldAllowLogin = (Values[i] == PasswordGiven);
		end
	end
	return 0;
end
local Res = PwdDB:exec("SELECT * FROM Passwords WHERE Username=\"" .. UserName .."\"", ProcessRow, nil);
if (Res ~= sqlite3.OK) then
	LOG("SQL query failed: " .. Res .. " (" .. PwdDB:errmsg() .. ")");
end;
-- ShouldAllowLogin now has the bool value saying whether to allow the user in or not
Reply
Thanks given by: NiLSPACE
#32
Hurray I have SQLite ( kinda ) working Wink You can now register ;D
Reply
Thanks given by:
#33
I've commited the first versionBig Grin It is in beta stage and its very ugly Wink
https://github.com/STRWarrior/Login/tree/Dev
Reply
Thanks given by:
#34
Cool!
Reply
Thanks given by:
#35
Code:
[13:42:04] cWebPlugin::cWebPlugin()
[13:42:04] -- Plugins/Login/main.lua:23: error in function 'AddHook'.
     argument #3 is 'nil'; 'number' expected.

[13:42:04] Error in plugin Plugins/Login calling function Initialize()
[13:42:04] ~cWebPlugin::cWebPlugin()
[13:42:04] Core
[13:42:04] Login-master
[13:42:04] Got nil! NOOOO
[13:42:08] Path: /webadmin/Core/Manage_Plugins
[13:42:09] Path: /webadmin/Core/Manage_Plugins
not working
Reply
Thanks given by:
#36
does a reload fix it?
Reply
Thanks given by:
#37
No, a lot of times it rebooted the same thing
Reply
Thanks given by:
#38
What MCServer version are you using? If it's an older release, the API might have changed.
Reply
Thanks given by: NiLSPACE
#39
Yes, apparently this problem, and what should I use?
Reply
Thanks given by:
#40
You can find the latest version for windows here: http://mc-server.xoft.cz/
The latest version is r1581
Reply
Thanks given by:




Users browsing this thread: 10 Guest(s)