Server shuts down after player login?
#1

Hello people,

I've editted my login system and now the server just shuts down without any error messages whenever a player registers or logs in to the server?

Here's my code:
Код:
public OnPlayerConnect(playerid)
{
	new query[126], pName[MAX_PLAYER_NAME];
	
	GetPlayerName(playerid, pName, sizeof(pName));
	
	format(query, sizeof(query), "SELECT * FROM accounts WHERE Name = '%s'", pName);
	mysql_query(query);
	mysql_store_result();
	new rows = mysql_num_rows();
	
	printf("There are %s rows in table1", rows);
	
	if(mysql_num_rows() ==1)
	{
		SendClientMessage(playerid, -1, "That username is registered!");
		ShowPlayerDialog(playerid, 0, DIALOG_STYLE_PASSWORD, "Login", "Please login with the password you made", "Login", "Cancel");
	}
	else
	{
		SendClientMessage(playerid, -1, "That username is not registered. You may register it");
		ShowPlayerDialog(playerid, 1, DIALOG_STYLE_PASSWORD, "Register", "Please enter a password for your account", "Register", "Cancel");
	}
	return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
	SavePlayer(playerid);
	return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
	switch(dialogid)
	{
		case 0:
		{
			if(response)
			{
				new query[256], EncryptedPass[130];
				
				WP_Hash(EncryptedPass, sizeof(EncryptedPass), inputtext);
				format(query, sizeof(query), "SELECT * FROM accounts WHERE Name = '%s' AND Password = '%s'", GetName(playerid), EncryptedPass);
				mysql_query(query);
				mysql_store_result();
				
				//printf(query);
				//printf(inputtext);
			
				if(mysql_num_rows() == 1)
				{
					LoginPlayer(playerid);
				}
				else
				{
					SendClientMessage(playerid, -1, "Incorrect password!");
					ShowPlayerDialog(playerid, 0, DIALOG_STYLE_PASSWORD, "Login", "Please login with the password you made", "Login", "Cancel");
				}
			}
		}
		case 1:
		{
			if(response)
			{
				RegisterPlayer(playerid, inputtext);
			}
		}
	}
	return 1;
}
	
stock RegisterPlayer(playerid, regpass[])
{
	new query[256], EncryptedPass[130];
				
	WP_Hash(EncryptedPass, sizeof(EncryptedPass), regpass);
				
	format(query, sizeof(query), "INSERT INTO accounts(Name, Password, PlayerPos) VALUES ('%s', '%s', '1.0 2.0 3.0')", GetName(playerid), EncryptedPass);
	mysql_query(query);

	LoginPlayer(playerid);
	
	return 1;
}
	
stock LoginPlayer(playerid)
{
	new query[126];
	format(query, sizeof(query), "SELECT * FROM accounts WHERE Name = '%s'", GetName(playerid));
	mysql_query(query);
	mysql_store_result();

    while(mysql_fetch_row_format(query,"|"))
	{
		mysql_fetch_field_row(query, "id"); Player[playerid][ID] = strval(query);
		mysql_fetch_field_row(Player[playerid][Name], "Name");
		mysql_fetch_field_row(Player[playerid][Password], "Password");
		mysql_fetch_field_row(query, "AdminLevel"); Player[playerid][AdminLevel] = strval(query);
		mysql_fetch_field_row(query, "PlayerPos");
		sscanf(query, "fff", Player[playerid][Position][0], Player[playerid][Position][1], Player[playerid][Position][2]);
		mysql_fetch_field_row(query, "Money"); Player[playerid][Money] = strval(query);
	}
	GivePlayerMoney(playerid, Player[playerid][Money]);
	SetSpawnInfo(playerid, 0, 299, Player[playerid][Position][0], Player[playerid][Position][1], Player[playerid][Position][2], 1, 2, 3, 0, 0, 0, 0, 0, 0, 0);
	SpawnPlayer(playerid);
}

stock SavePlayer(playerid)
{
	new query[356], EncryptedPass[130];
				
	WP_Hash(EncryptedPass, sizeof(EncryptedPass), Player[playerid][Password]);
	
	GetPlayerPos(playerid, Player[playerid][Position][0], Player[playerid][Position][1], Player[playerid][Position][2]);
	
	format(query, sizeof(query), "UPDATE accounts SET Name = '%s', Password = '%s', AdminLevel = %d, PlayerPos = '%f %f %f', Money = %d WHERE id = %d", GetName(playerid), Player[playerid][Password], Player[playerid][AdminLevel], Player[playerid][Position][0], Player[playerid][Position][1], Player[playerid][Position][2], Player[playerid][Money], Player[playerid][ID]);
	mysql_query(query);
	printf("Player ID %d (%s) has been saved", playerid, GetName(playerid));
}

stock GetName(playerid)
{
	new playerName[MAX_PLAYER_NAME];
	
	GetPlayerName(playerid, playerName, sizeof(playerName));
	
	return playerName;
}
And this is the server log:
Код:
----------
Loaded log file: "server_log.txt".
----------

SA-MP Dedicated Server
----------------------
v0.3x-R2, ©2005-2013 SA-MP Team

[09:59:03] filterscripts = ""  (string)
[09:59:03] 
[09:59:03] Server Plugins
[09:59:03] --------------
[09:59:03]  Loading plugin: mysql
[09:59:03] 

  > MySQL plugin R5 successfully loaded.

[09:59:03]   Loaded.
[09:59:03]  Loading plugin: sscanf
[09:59:03] 

[09:59:03]  ===============================

[09:59:03]       sscanf plugin loaded.     

[09:59:03]          Version:  2.8.1        

[09:59:03]    © 2012 Alex "******" Cole  

[09:59:03]  ===============================

[09:59:03]   Loaded.
[09:59:03]  Loading plugin: Whirlpool
[09:59:03]  
[09:59:03]  ==================
[09:59:03]  
[09:59:03]   Whirlpool loaded
[09:59:03]  
[09:59:03]  ==================
[09:59:03]  
[09:59:03]   Loaded.
[09:59:03]  Loaded 3 plugins.

[09:59:03] 
[09:59:03] Filterscripts
[09:59:03] ---------------
[09:59:03]   Loaded 0 filterscripts.

[09:59:03] n---Connectie met de database is gelukt! ---
[09:59:03] 
-------------------------------
[09:59:03]  Blank Gamemode by dragonslife
[09:59:03] -------------------------------

[09:59:03] Number of vehicle models: 0
[09:59:24] Incoming connection: 127.0.0.1:52233
[09:59:24] [join] Asmenia_Barrow has joined the server (0:127.0.0.1)
[09:59:24] There are Asmenia_Barrow rows in table1
Reply
#2

Is server using mysql database?
Reply
#3

Yep, it does save the player to the database correctly after registering, but right after that the server just shuts down. Same goes with login.
Reply
#4

MySQL R5 is outdated why don't you use R34? Also you forgot to put mysql_free_result()
Reply
#5

But that can't be the problem here right? Before it worked with mysql r5 too.
Reply
#6

I'd recommend you to use the latest version of the MySQL plugin too because threaded queries are faster/better (if you're interested a useful tutorial can be found: https://sampforum.blast.hk/showthread.php?tid=337810).

But you decide, so if you want to use R5 - just use it.

As Mellnik said, you forgot to free the results. That can cause memory leaks (something you don't want to!) and you need to load crashdetect so we can be able to see what caused the crash. So load the plugin (it can be found: https://github.com/Zeex/samp-plugin-...ases/tag/v4.12) and the next time it will close the server, post the server log.
Reply
#7

Okay so I have managed to stop the crashing of the server. But now when I login or register a player, it doesn't spawn them. You just fill in the password and then it does nothing other than staying in the starting screen of SAMP. So that makes me things that something is wrong in my LoginPlayer function with the spawning of the player. However and I checked (and with my little knowledge I know of this programming/scripting) I couldn't find anything wrong with the code?

Код:
stock LoginPlayer(playerid)
{
	new query[126];
	format(query, sizeof(query), "SELECT * FROM accounts WHERE Name = '%s'", GetName(playerid));
	mysql_query(query);
	mysql_store_result();

    while(mysql_fetch_row_format(query,"|"))
	{
		mysql_fetch_field_row(query, "id"); Player[playerid][ID] = strval(query);
		mysql_fetch_field_row(Player[playerid][Name], "Name");
		mysql_fetch_field_row(Player[playerid][Password], "Password");
		mysql_fetch_field_row(query, "AdminLevel"); Player[playerid][AdminLevel] = strval(query);
		mysql_fetch_field_row(query, "PlayerPos");
		sscanf(query, "fff", Player[playerid][Position][0], Player[playerid][Position][1], Player[playerid][Position][2]);
		mysql_fetch_field_row(query, "Money"); Player[playerid][Money] = strval(query);
	}
	GivePlayerMoney(playerid, Player[playerid][Money]);
	SetSpawnInfo(playerid, 0, 299, Player[playerid][Position][0], Player[playerid][Position][1], Player[playerid][Position][2], 1, 2, 3, 0, 0, 0, 0, 0, 0, 0);
	SpawnPlayer(playerid);
	mysql_free_result();
}
Reply
#8

Anyone seeing the problem here?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)