new mysql; forward saveAll(); public saveAll() { new query[128], name[MAX_PLAYER_NAME]; for(new a=0; a<MAX_PLAYERS; a++) { if(IsPlayerConnected(a)) { GetPlayerName(a, name, MAX_PLAYER_NAME); format(query, sizeof(query), "UPDATE `contas` SET `skin` = '%d' WHERE `usuario` = '%s'", GetPlayerSkin(a), name); mysql_function_query(mysql, query, false, "", ""); } } } main() { } public OnGameModeInit() { mysql_debug(1); mysql = mysql_connect("127.0.0.1", "user", "sampserver", "senha"); SetTimer("saveAll", 5000, true); return 1; } public OnGameModeExit() { return 1; } public OnPlayerRequestClass(playerid, classid) { return 1; } public OnPlayerConnect(playerid) { new nome[MAX_PLAYER_NAME], query[1024]; GetPlayerName(playerid, nome, MAX_PLAYER_NAME); format(query, sizeof(query), "SELECT * FROM `contas` WHERE usuario = '%s'", nome); mysql_function_query(mysql, query, true, "q_loginRequest", "d", playerid); return 1; } forward q_loginRequest(playerid); public q_loginRequest(playerid) { new rows, fields, tmp[64], skn; cache_get_data(rows, fields); if(rows) { cache_get_field_content(0, "skin", tmp); skn = strval(tmp); SetSpawnInfo(playerid, 0, skn, 1958.33, 1343.12, 15.36, 269.15, 0, 0, 0, 0, 0, 0 ); ShowPlayerDialog(playerid, DIALOG01, DIALOG_STYLE_PASSWORD, "Seja Bem-vindo ao servidor !", "Digite sua senha", "Login", "Kick"); //Usuario Existe } else { ShowPlayerDialog(playerid, DIALOG02, DIALOG_STYLE_PASSWORD, "Voce nгo tem uma conta", "Primeira vez? Registre-se", "Registrar", "Kick"); //Usuario Nгo existe ! } return 1; } public OnPlayerDisconnect(playerid, reason) { return 1; } public OnPlayerSpawn(playerid) { return 1; } public OnPlayerDeath(playerid, killerid, reason) { return 1; } public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) { switch(dialogid){ case DIALOG01: { new query[1024], nome[MAX_PLAYER_NAME]; GetPlayerName(playerid, nome, MAX_PLAYER_NAME); format(query, sizeof(query), "SELECT * FROM `contas` WHERE (usuario) = '%s' AND (senha) = '%s'", nome, inputtext); mysql_function_query(mysql, query, true, "q_verify_Pass", "d", playerid); SpawnPlayer(playerid); } // Usuario nгo existe ! case DIALOG02: { if(strlen(inputtext) < 5) { ShowPlayerDialog(playerid, DIALOG02, DIALOG_STYLE_PASSWORD, "Voce nгo tem uma conta", "{ff0000}Insira uma senha maior que 5 digitos !", "Registrar", "Kick"); } else { new query[1024], nome[MAX_PLAYER_NAME]; GetPlayerName(playerid, nome, MAX_PLAYER_NAME); format(query, sizeof(query), "INSERT INTO `contas` (usuario, senha) VALUES ('%s', '%s')", nome, inputtext); mysql_function_query(mysql, query, false, "", ""); //Spawn SetSpawnInfo(playerid, 0, 0, 1958.33, 1343.12, 15.36, 269.15, 0, 0, 0, 0, 0, 0 ); SpawnPlayer(playerid); return 1; } } } return 1; } forward q_verify_Pass(playerid); public q_verify_Pass(playerid) { new rows, fields, tmp[64], skin; cache_get_data(rows, fields); if(rows) { cache_get_field_content(0, "skin", tmp); skin = strval(tmp); SetSpawnInfo(playerid, 0, skin, 1958.33, 1343.12, 15.36, 269.15, 0, 0, 0, 0, 0, 0 ); SpawnPlayer(playerid); // Senha correta } else { ShowPlayerDialog(playerid, DIALOG01, DIALOG_STYLE_PASSWORD, "Seja Bem-vindo ao servidor !", "{fff700}Senha invalida", "Login", "Kick"); // Senha errada } }
Primeiro, vocк tem um timer que a cada 5 segundos salva as skins de todo mundo que estб conectado, hб necessidade disso ? E provavelmente й isso mesmo que estб bugando, pois apartir do momento que o cara connecta a skin dele й a ID 0, levando em consideraзгo seu timer, se o cara ficar 5 segundos sem dar spawn vai salvar a skin ID 0 no banco de dados. |
forward q_loginRequest(playerid); public q_loginRequest(playerid) { new row, skn[MAX_PLAYERS], name[MAX_PLAYER_NAME]; GetPlayerName(playerid, name, MAX_PLAYER_NAME); mysql_format(conexao, query, sizeof(query), "SELECT * FROM tabelausuarios WHERE usuario='%e'", name); mysql_query(conexao, query, true); cache_get_row_count(row); if(row >0) { cache_get_value_name_int(0, "skin", skn[playerid]); SetSpawnInfo(playerid, 0, skn[playerid], 1958.33, 1343.12, 15.36, 269.15, 0, 0, 0, 0, 0, 0 ); ShowPlayerDialog(playerid, DIALOG01, DIALOG_STYLE_PASSWORD, "Seja Bem-vindo ao servidor !", "Digite sua senha", "Login", "Kick"); //Usuario Existe } else { ShowPlayerDialog(playerid, DIALOG02, DIALOG_STYLE_PASSWORD, "Voce nгo tem uma conta", "Primeira vez? Registre-se", "Registrar", "Kick"); //Usuario Nгo existe ! } return 1; }