edit: Solved. Continue working on the demo..

Ok, I now have plain text, md5 and sha passwords working. Also I figured out how to extract data (strings) from the database, but I have a problem due to bad scripting I guess. So could anyone help me with the inkey problem in the script?

Run program -> press L -> enter username -> press ENTER -> enter password -> press ENTER (done)

The problem i'm having with the inkey thingy is when I login the first time and I enter the correct user+pass, all works no problem. However if I press L to login again it doesn't work anymore. (need to refresh inkey username+password somehow reset it) In the case I enter a wrong username and or password it should be reset too, but I have no luck with the inkey.

How do I reset the login function and inkey to be able to try login again when I enter a wrong username and or password. Or just want to login with another username? When I'm done with this I can upload a little example program for all to download and show how easy using this dll actualy is.

The script is a mess I know, but i'm still working on it and it will be cleaned afterwards removing what is not needed.

Dusty



Code:

plugindir = ".";

//--------------------------------------------------------------------
// DLL Declarations
//--------------------------------------------------------------------
dllfunction mySQL_Connectdb(w,x,y,z); // declaration of a DLL function
dllfunction mySQL_Closedb();
dllfunction mySQL_ExecQuery(string);
dllfunction mySQL_GetVal(x,y);
dllfunction mySQL_GetStr(string,x,y);
dllfunction mySQL_RowNumber();
dllfunction mySQL_IsConnected();

//--------------------------------------------------------------------
// VARIABLES
//--------------------------------------------------------------------

var video_mode = 7; // 800x600
var video_screen = 2; // window mode
var video_depth = 32; // 32bit color

var_nsave mysql_handle;

//--------------------------------------------------------------------
// STRINGS
//--------------------------------------------------------------------

string offline_text = [80]; // max 255 chars
string online_text = [80]; // max 255 chars
string login_text = [80]; // max 255 chars
string player_text = [80]; // max 255 chars
string username;
string password;
string query;

//--------------------------------------------------------------------
// FONTS
//--------------------------------------------------------------------

font standard_font = "Verdana",1,12; // Truetype font

//--------------------------------------------------------------------
// BITMAPS
//--------------------------------------------------------------------

bmap pcxLogin = <login.pcx>; // Skin for login panel

//--------------------------------------------------------------------
// PANELS
//--------------------------------------------------------------------

panel pnlLogin
{
bmap = pcxLogin;
layer = 18;
pos_x = 5;
pos_y = 420;
flags = refresh;
}

//--------------------------------------------------------------------
// TEXT
//--------------------------------------------------------------------

text txtUsername
{
layer = 30;
string = username;
pos_x = 26;
pos_y = 480;
font = standard_font;
red = 75;
green = 100;
blue = 180;
flags = visible;
}

text txtPassword
{
layer = 30;
string = password;
pos_x = 26;
pos_y = 528;
font = standard_font;
red = 75;
green = 100;
blue = 180;
flags = visible;
}

text txtOffline
{
layer = 28;
string = offline_text;
pos_x = 650;
pos_y = 40;
//flags = visible;
}

text txtOnline
{
layer = 28;
string = online_text;
pos_x = 650;
pos_y = 20;
//flags = visible;
}

text txtLogin
{
layer = 28;
string = login_text;
pos_x = 650;
pos_y = 60;
//flags = visible;
}

text txtPlayerMSG
{
layer = 28;
string = player_text;
pos_x = 15;
pos_y = 80;
//flags = visible;
}

//--------------------------------------------------------------------
// HEART OF THE GAME
//--------------------------------------------------------------------

function main()
{
screen_color.blue = 128;
// database,host,user,password
mySQL_Connectdb("gsa6db","www.mydomain.com","gsa6","xs4all");
//mySQL_Connectdb("gsa6db","localhost","gsa6","xs4all");

if(!mySQL_IsConnected()) // Connection failed
{
txtOnline.visible = off;
txtOffline.visible = on;
str_cpy(offline_text, "Connection failed");
//beep;
//exit; // Connection failed, exit to windows.
}
// Do something
while (mySQL_IsConnected()) // Connection established
{
txtOffline.visible = off;
txtOnline.visible = on;
str_cpy(online_text, "Connection established");
wait(1);
}
// mySQL_Closedb();
}

//--------------------------------------------------------------------
// FUNCTIONS
//--------------------------------------------------------------------

function refreshAuth()
{
str_cpy(username, "");
str_cpy(password, "");
}

function dbExtract()
{
//mySQL_ExecQuery("select * from Player where query='player_msg';");
//mySQL_ExecQuery("select * from Player;");
str_cpy(player_text, "Aquiring result");
sleep(1);
mySQL_GetStr(player_text,3,0); // 1,0 = username | 3,0 = welcome message
}

function userlogin()
{
// mySQL_Connectdb("gsa6db","localhost","gsa6","xs4all");
if(!mySQL_IsConnected())
{
beep;
exit; // Connection failed, exit to windows.
}

pnlLogin.visible = on; // Make the login visible with L key
inkey(username);
inkey(password);

// Plain text passwords
/*str_cat(query, "select * from Players WHERE player_nick='");
str_cat(query, username);
str_cat(query, "' AND player_pass='");
str_cat(query, password);
str_cat(query, "';");
*/

// SHA Password Encryption
/*str_cat(query, "select * from Players WHERE player_nick='");
str_cat(query, username);
str_cat(query, "' AND player_pass=SHA('");
str_cat(query, password);
str_cat(query, "');");
*/

// MD5 Password Encryption
str_cat(query, "select * from Players WHERE player_nick='");
str_cat(query, username);
str_cat(query, "' AND player_pass=MD5('");
str_cat(query, password);
str_cat(query, "');");

if(mySQL_ExecQuery(query)&&mySQL_RowNumber()==1)
{
// The query returned true, do something
txtLogin.visible = on;
str_cpy(login_text, "Login accepted");
txtPlayerMSG.visible = on;
//str_cpy(player_text, "extract from db");
str_cpy(player_text, query);
dbExtract();
}
else
{
txtLogin.visible = on;
str_cpy(login_text, "Login failed");
//exit; // No entry or failed, exit to Windows
}
// pnlLogin.visible = off; // Hide the login
// Now you can gather info from the db

//while(1)
//{
// do some more
// wait(1);
//}
//refreshAuth();
//mySQL_Closedb();
}
on_L = userlogin;



SQL
Code:
CREATE TABLE `Players` (
`player_id` int(10) unsigned NOT NULL auto_increment COMMENT 'player id',
`player_nick` varchar(16) NOT NULL default '' COMMENT 'player nick',
`player_pass` varchar(32) NOT NULL default '' COMMENT 'player password',
`player_msg` text NOT NULL COMMENT 'player message',
PRIMARY KEY (`player_id`),
KEY `player_nick` (`player_nick`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='GameStudio A6MySQL Database' AUTO_INCREMENT=2 ;



Username: demo
Password: demo
Code:
INSERT INTO `Players` VALUES (1, 'demo', 'fe01ce2a7fbac8fafaed7c982a04e229', 'Welcome to mydomain.com');






smile