Raised This Month: $32 Target: $400
 8% 

Changed name persistent over Mapchange


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
sil_El_mot
Member
Join Date: Jan 2015
Old 09-19-2018 , 07:44   Changed name persistent over Mapchange
Reply With Quote #1

Hello there,
i have a small script where players can register their name with a password, which is then stored in a database. so every name is unique. you than can login with your name and password.
the problem now is, that after a mapchange the name is resetted to the original one.
how can i make the namechange persistent till the client logs out?

i tried it with setting the name to an array, because i read that this will persist, but i am not able to read that one on map start.

i tried it this way:

Code:
public OnPluginStart()
{
	new String:Error[70];
	DB = SQL_Connect("login-system", true, Error, sizeof(Error));
	if (DB == INVALID_HANDLE)
	{
		PrintToServer("Cannot connect to MySQL Server: %s", Error);
	} 
	else 
	{
		PrintToServer("Connection Successful");
	}
	
	RegConsoleCmd("login", Command_Login);
	RegConsoleCmd("register", Command_Register);
}
 
public Action Command_Login(int client, int args)
{
	char arg1[32]
	char arg2[32]
 
	/* By default, we set damage = 0 */
 

	if (args < 1)
        {
                ReplyToCommand(client, "[SM] You need to enter a name!");
                return Plugin_Handled;
        }
	else if (args < 2)
	{
		ReplyToCommand(client, "[SM] You need to enter a password!");
		return Plugin_Handled;
	}
	 

	new String:query[150];
	
	Format(query, sizeof(query), "SELECT passwort FROM hlstats_logins WHERE name='%s'", arg1);
	decl String:new_name[MAXPLAYERS+1][64];
	new Handle:queryH = SQL_Query(DB, query);
	
	if(queryH != INVALID_HANDLE)
	{
		if(SQL_FetchRow(queryH))
		{
			new String:passwort[120];
			new String:md5pass[256];
			
			SQL_FetchString(queryH, 0,passwort, sizeof(passwort));
			
			Crypt_MD5(arg2,md5pass,256)
			if(StrEqual(md5pass,passwort))
			{
				SetClientName(client, arg1);
				ReplyToCommand(client, "[SM] Your new name is %s", arg1);
				new_name[client] = arg1; 
								
			} 
			else 
			{
				ReplyToCommand(client, "[SM] Your password is wrongh! ");
			}
		}
		else
		{
			ReplyToCommand(client, "[SM] The name %s is already taken!", arg1);
		}
		
	}
	else
	{
		ReplyToCommand(client, "error with mysql");
	}	

 
	return Plugin_Handled;
}

Last edited by sil_El_mot; 09-19-2018 at 08:13.
sil_El_mot is offline
ThatKidWhoGames
Veteran Member
Join Date: Jun 2013
Location: IsValidClient()
Old 09-19-2018 , 07:45   Re: Changed name persistent over Mapchange
Reply With Quote #2

Post the entire code. We need to know where you are calling this function.

Last edited by ThatKidWhoGames; 09-19-2018 at 07:45.
ThatKidWhoGames is offline
sil_El_mot
Member
Join Date: Jan 2015
Old 09-19-2018 , 08:14   Re: Changed name persistent over Mapchange
Reply With Quote #3

ok. did so
sil_El_mot is offline
mug1wara
AlliedModders Donor
Join Date: Jun 2018
Old 09-19-2018 , 09:58   Re: Changed name persistent over Mapchange
Reply With Quote #4

It doesn't even compile.

Judging by "/* By default, we set damage = 0 */", and the mixed syntax, I believe you just copied everything and expect us to fix it for you.
mug1wara is offline
sil_El_mot
Member
Join Date: Jan 2015
Old 09-19-2018 , 10:51   Re: Changed name persistent over Mapchange
Reply With Quote #5

i am very new to this and sure i copied over from some tutorials at the beginning.
but it compiles here and i am already using it
i can login and register names and they are stored in the database, so please no false asumptions.
i only have no idea how i can check at map start if an array exists and if the clients name is in it.

in theory, if i have the name stored in the array like in the code above, can i get it back after map reload?
or is this part already wrong?
sil_El_mot is offline
mug1wara
AlliedModders Donor
Join Date: Jun 2018
Old 09-19-2018 , 11:02   Re: Changed name persistent over Mapchange
Reply With Quote #6

Quote:
Originally Posted by sil_El_mot View Post
i am very new to this and sure i copied over from some tutorials at the beginning.
but it compiles here and i am already using it
i can login and register names and they are stored in the database, so please no false asumptions.
i only have no idea how i can check at map start if an array exists and if the clients name is in it.

in theory, if i have the name stored in the array like in the code above, can i get it back after map reload?
or is this part already wrong?
Listen, I don't even have to try it.

It... does... not... work.

And everything is wrong. If I were you, I would throw this in the trash bin.
mug1wara is offline
Cruze
Veteran Member
Join Date: May 2017
Old 09-19-2018 , 12:38   Re: Changed name persistent over Mapchange
Reply With Quote #7

Quote:
Originally Posted by mug1wara View Post
It doesn't even compile.
Maybe because he hasn't posted full code.
__________________
Taking paid private requests! Contact me
Cruze is offline
mug1wara
AlliedModders Donor
Join Date: Jun 2018
Old 09-19-2018 , 12:45   Re: Changed name persistent over Mapchange
Reply With Quote #8

Quote:
Originally Posted by ThatKidWhoGames View Post
Post the entire code. We need to know where you are calling this function.
Quote:
Originally Posted by sil_El_mot View Post
ok. did so
mug1wara is offline
Ilusion9
Veteran Member
Join Date: Jun 2018
Location: Romania
Old 09-19-2018 , 13:21   Re: Changed name persistent over Mapchange
Reply With Quote #9

Quote:
Originally Posted by sil_El_mot View Post
ok. did so
no, you didn't
i can see some custom functions in your code

also, use the new syntax. your code looks like windows vista in 2018.
Ilusion9 is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 09-19-2018 , 20:19   Re: Changed name persistent over Mapchange
Reply With Quote #10

What's the use case for this? I ask because Steam IDs are usually unique and kinda make usernames and passwords redundant.
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 17:18.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode