16.01.2016, 01:27
Fiz um sistema de Registro/Login em Mysql e fui testar com alguns amigos meus, porйm quando um dos jogadores sai do servidor por algum motivo o servidor cai, mas o console continua aberto e os dados salvam normalmente
aqui estб o meu sistema completo, creio que o problema esteja aqui pois o gamemode sу tem esse sistema
e aqui estб o Mysql_log
Server_log
aqui estб o meu sistema completo, creio que o problema esteja aqui pois o gamemode sу tem esse sistema
PHP код:
/* =============== [ Forwards ] =============== */
forward Login_OnGameModeInit();
forward Login_OnGameModeExit();
forward Login_OnPlayerRequestClass(playerid, classid);
forward Login_OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]);
forward CarregarUsuario(playerid);
forward AutenticarUsuario(playerid);
/* =============== [ Callbacks ] =============== */
public Login_OnGameModeInit()
{
ConexaoSQL = mysql_connect(mysql_host, mysql_user, mysql_database, mysql_password);
mysql_query(ConexaoSQL, "CREATE TABLE IF NOT EXISTS `usuarios` ( `ID` INT(11) NOT NULL AUTO_INCREMENT , `Nome` VARCHAR(24) NOT NULL , `Senha` VARCHAR(24) NOT NULL ,\
`Score` INT(11) NOT NULL DEFAULT '0' , `VirtualWorld` INT(11) NOT NULL DEFAULT '0' , `Interior` INT(11) NOT NULL DEFAULT '0' ,\
`pX` FLOAT NOT NULL , `pY` FLOAT NOT NULL , `pZ` FLOAT NOT NULL , PRIMARY KEY (`ID`))");
if(mysql_errno(ConexaoSQL) != 0)
{
print("| ERROR |: Falha ao conectar com o Database");
SendRconCommand("exit");
}
return 1;
}
public Login_OnGameModeExit()
{
mysql_close(ConexaoSQL);
return 1;
}
public Login_OnPlayerRequestClass(playerid, classid)
{
p_Info[playerid][pConectado] = false;
new Query[70];
mysql_format(ConexaoSQL, Query, sizeof(Query), "SELECT * FROM usuarios WHERE Nome='%e'", PegarNome(playerid));
mysql_tquery(ConexaoSQL, Query, "AutenticarUsuario", "d", playerid);
return 1;
}
public Login_OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
switch(dialogid)
{
case D_Registro:
{
if(response)
{
if(strlen(inputtext) < 5 || strlen(inputtext) > 10) return ShowPlayerDialog(playerid, D_Registro, DIALOG_STYLE_INPUT, "(!) Registro", "Sua senha precisa ser maior que 5 e menor que 10 caracteres!, tente novamente.", "Registrar", "Cancelar");
new Query[128];
mysql_format(ConexaoSQL, Query, sizeof(Query), "INSERT INTO usuarios (Nome,Senha) VALUES ('%e','%e')", PegarNome(playerid), inputtext);
mysql_query(ConexaoSQL, Query);
p_Info[playerid][pID] = cache_insert_id();
p_Info[playerid][pRespawn] = true;
ShowPlayerDialog(playerid, D_Login, DIALOG_STYLE_PASSWORD, "(!) Log-in", "Conta cadastrada com sucesso!\nInsira sua senha para jogar.", "Logar", "Sair");
}
else Kick(playerid);
}
case D_Login:
{
if(response)
{
if(!strcmp(p_Info[playerid][pSenha],inputtext,true,24))
{
new Query[70];
mysql_format(ConexaoSQL, Query, sizeof(Query), "SELECT * FROM usuarios WHERE Nome='%e'", PegarNome(playerid));
mysql_tquery(ConexaoSQL, Query, "CarregarUsuario", "d", playerid);
p_Info[playerid][pConectado] = true;
SpawnPlayer(playerid);
}
else
{
ShowPlayerDialog(playerid, D_Login, DIALOG_STYLE_PASSWORD, "(!) Log-in", "Senha Incorreta!\nSe falhar a senha por mais de 3 vezes serб expulso!", "Logar", "Sair");
p_Info[playerid][pTentativas]++;
if(p_Info[playerid][pTentativas] == 3) Kick(playerid);
}
}
}
}
return 1;
}
public AutenticarUsuario(playerid)
{
p_Info[playerid][pConectado] = false;
p_Info[playerid][pTentativas] = 0;
if(cache_get_row_count(ConexaoSQL) != 0)
{
new str[30];
cache_get_field_content(0, "Senha", str), format(p_Info[playerid][pSenha], 24, "%s", str);
ShowPlayerDialog(playerid, D_Login, DIALOG_STYLE_PASSWORD, "(!) Log-in", "Insira sua senha para jogar.", "Logar", "Sair");
}
else ShowPlayerDialog(playerid, D_Registro, DIALOG_STYLE_INPUT, "(!) Registro", "Insira sua senha para cadastrar sua conta em nosso banco de dados.", "Registrar", "Cancelar");
return 1;
}
public CarregarUsuario(playerid)
{
p_Info[playerid][pID] = cache_get_field_content_int(0, "ID", ConexaoSQL);
p_Info[playerid][pScore] = cache_get_field_content_int(0, "Score", ConexaoSQL);
p_Info[playerid][pVirtualW] = cache_get_field_content_int(0, "VirtualWorld", ConexaoSQL);
p_Info[playerid][pInterior] = cache_get_field_content_int(0, "Interior", ConexaoSQL);
p_Info[playerid][pX] = cache_get_field_content_float(0, "pX", ConexaoSQL);
p_Info[playerid][pY] = cache_get_field_content_float(0, "pY", ConexaoSQL);
p_Info[playerid][pZ] = cache_get_field_content_float(0, "pZ", ConexaoSQL);
SetPlayerScore(playerid, p_Info[playerid][pScore]);
for(new i; i < sizeof(PLAYER_HUD); i++) PlayerTextDrawShow(playerid, PLAYER_HUD[playerid][i]);
return 1;
}
stock SalvarUsuario(playerid)
{
new Query[300];
GetPlayerPos(playerid, p_Info[playerid][pX], p_Info[playerid][pY], p_Info[playerid][pZ]);
mysql_format(ConexaoSQL, Query, sizeof(Query), "UPDATE `usuarios` SET `Score`='%i',`VirtualWorld`='%i',`Interior`='%i',`pX`='%f',`pY`='%f',`pZ`='%f' WHERE ID=%i",
GetPlayerScore(playerid), GetPlayerVirtualWorld(playerid), GetPlayerInterior(playerid), p_Info[playerid][pX], p_Info[playerid][pY], p_Info[playerid][pZ],
p_Info[playerid][pID]);
mysql_query(ConexaoSQL, Query);
return 1;
}
Код:
[00:46:35] [ERROR] CMySQLConnection::Connect - (error #2003) Can't connect to MySQL server on '127.0.0.1' (10061) [00:46:35] [ERROR] CMySQLQuery::Execute - (error #2006) MySQL server has gone away [00:46:35] [WARNING] CMySQLConnection::Disconnect - no connection available [00:46:36] [ERROR] CMySQLConnection::Connect - (error #2003) Can't connect to MySQL server on '127.0.0.1' (10061) [00:46:36] [ERROR] CMySQLConnection::Connect - (error #2003) Can't connect to MySQL server on '127.0.0.1' (10061) [00:46:36] [ERROR] CMySQLConnection::Connect - (error #2003) Can't connect to MySQL server on '127.0.0.1' (10061) [00:46:36] [WARNING] CMySQLConnection::Disconnect - no connection available [00:46:36] [WARNING] CMySQLConnection::Disconnect - no connection available [00:46:36] [WARNING] CMySQLConnection::Disconnect - no connection available
Код:
---------- Loaded log file: "server_log.txt". ---------- SA-MP Dedicated Server ---------------------- v0.3.7-R2, ©2005-2015 SA-MP Team [00:10:23] [00:10:23] Server Plugins [00:10:23] -------------- [00:10:23] Loading plugin: mysql [00:10:23] >> plugin.mysql: R39-4 successfully loaded. [00:10:23] Loaded. [00:10:23] Loading plugin: sscanf [00:10:23] [00:10:23] =============================== [00:10:23] sscanf plugin loaded. [00:10:23] Version: 2.8.1 [00:10:23] © 2012 Alex "******" Cole [00:10:23] =============================== [00:10:23] Loaded. [00:10:23] Loading plugin: streamer [00:10:23] *** Streamer Plugin v2.7.8 by Incognito loaded *** [00:10:23] Loaded. [00:10:23] Loaded 3 plugins. [00:10:23] [00:10:23] Filterscripts [00:10:23] --------------- [00:10:23] Loading filterscript 'vspawner.amx'... [00:10:23] --Admin Vehicle Spawner Loaded [00:10:23] Loaded 1 filterscripts. [00:10:23] Survive The Apocalypse - Iniciado com sucesso!! [00:10:23] Number of vehicle models: 0 [00:10:24] [connection] 25.75.94.109:55593 requests connection cookie. [00:10:25] [connection] incoming connection: 25.75.94.109:55593 id: 0 [00:10:29] [join] BobSponja has joined the server (0:25.75.94.109) [00:10:50] [connection] 192.168.25.2:56980 requests connection cookie. [00:10:51] [connection] incoming connection: 192.168.25.2:56980 id: 1 [00:10:51] [join] JPedro has joined the server (1:192.168.25.2) [00:11:00] [connection] 25.126.37.255:57293 requests connection cookie. [00:11:01] [connection] incoming connection: 25.126.37.255:57293 id: 2 [00:11:01] [join] In$pireD has joined the server (2:25.126.37.255) [00:12:29] [part] In$pireD has left the server (2:1) [00:12:59] [connection] 25.126.37.255:57296 requests connection cookie. [00:13:00] [connection] incoming connection: 25.126.37.255:57296 id: 2 [00:13:00] [join] In$pireD has joined the server (2:25.126.37.255) [00:13:54] [part] JPedro has left the server (1:1) [00:14:15] [connection] 192.168.25.2:57007 requests connection cookie. [00:14:16] [connection] incoming connection: 192.168.25.2:57007 id: 1 [00:14:16] [join] JPedro has joined the server (1:192.168.25.2) [00:14:35] [part] BobSponja has left the server (0:1) [00:14:59] RCON (In-Game): Player #1 (JPedro) has logged in.