13.05.2012, 13:13
(
Последний раз редактировалось Minko; 13.05.2012 в 13:57.
)
Hi, i have a problem with Mysql Registration , i have plugin https://sampforum.blast.hk/showthread.php?tid=56564 ... R7 but
there is new function mysql_function_query .... there is code but it doesnt work and i dont know why please What is wrong ?
nothing in DB ....
Mysql Log:
there is new function mysql_function_query .... there is code but it doesnt work and i dont know why please What is wrong ?
nothing in DB ....
Код:
#include <a_samp> #include <a_mysql> #include <sscanf2> #define USER "samp" #define PASS "159753" #define DB "samp" #define IP "localhost" #define LOGIN_DIALOG 1 #define REGISTER_DIALOG 2 #define COLOR_GRAD 0x6E76ADFF #define COLOR_WHITE 0xFFFFFFFF #define COLOR_BLUE 0x18A4FFFF forward IsUsernameRegistered(playerid, usernm[]); forward OnLoginPlayer(playerid, pas[]); forward SavePlayerStats(playerid); enum pdb { username[MAX_PLAYER_NAME], pass[32], // He use 32 cells because Md5 is based 32 cell encriptation, experience, money, admin, maxexp, logged, } new playerdb[MAX_PLAYERS][pdb]; new mysqlconnection; main() { print("\n----------------------------------"); print(" Blank Gamemode by your name here"); print("----------------------------------\n"); } public OnGameModeInit() { // Don't use these lines if it's a filterscript SetGameModeText("Blank Script"); AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0); mysql_debug(true); print("Register Loading..."); mysqlconnection = mysql_connect(IP, USER, DB, PASS); if(mysql_ping()>=1) { print("MySQL: Connected sucesfull"); } else { print("Cannot connect to MySQL"); SendRconCommand("exit"); } return 1; } public OnGameModeExit() { mysql_close(); return 1; } public OnPlayerRequestClass(playerid, classid) { SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746); SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746); SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746); return 1; } public OnPlayerConnect(playerid) { GetPlayerName(playerid, playerdb[playerid][username], 24); // username is sa-mp defined 24 cells mysql_function_query(mysqlconnection ,"SELECT * FROM users WHERE Name = '%s'", false, "IsUsernameRegistered", "s", playerdb[playerid][username]); IsUsernameRegistered(playerid, playerdb[playerid][username]); return 1; } public OnPlayerDisconnect(playerid, reason) { mysql_function_query(mysqlconnection, "UPDATE users SET Money = %d WHERE Name ='%s'", false, "SavePlayerStats", "ds", GetPlayerMoney(playerid),playerdb[playerid][username]); SavePlayerStats(playerid); return 1; } public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) { if(dialogid == REGISTER_DIALOG) { if(!response) { SendClientMessage(playerid, COLOR_GRAD,"You have been kicked duo the cancelation."); Kick(playerid); } // The register syntax is INSERT INTO destination, the names of the fields and it's values. mysql_function_query(mysqlconnection, "INSERT INTO users (Name,Password,Money) VALUES ('%s',md5('%s'), %d)", false, "ssd", playerdb[playerid][username], inputtext, 50000); ShowPlayerDialog(playerid,LOGIN_DIALOG,DIALOG_STYLE_PASSWORD,"Login to Account.","Enter your password below:","Login","Cancel"); } if(dialogid == LOGIN_DIALOG) { if(!response) { SendClientMessage(playerid, COLOR_GRAD,"You have been kicked duo the cancelation."); Kick(playerid); } mysql_function_query(mysqlconnection,"SELECT * FROM users WHERE Name = '%s' AND Password = md5('%s')", false, "OnLoginPlayer", "ss", playerdb[playerid][username], inputtext); OnLoginPlayer(playerid, inputtext); } return 1; } public IsUsernameRegistered(playerid, usernm[]) { mysql_store_result(); if(mysql_num_rows() != 0) { ShowPlayerDialog(playerid,REGISTER_DIALOG,DIALOG_STYLE_PASSWORD,"Register Account.","Enter your password below:","Register","Cancel"); } else { ShowPlayerDialog(playerid,REGISTER_DIALOG,DIALOG_STYLE_PASSWORD,"Register Account.","Enter your password below:","Register","Cancel"); } mysql_free_result(); return 1; } public OnLoginPlayer(playerid, pas[]) { new result[1000]; mysql_store_result(); if(mysql_num_rows() != 0) { if(mysql_fetch_row_format(result , "|", mysqlconnection)) { sscanf(result,"e<p<|>s[24]s[32]i>", playerdb[playerid]); new str[80]; format(str, sizeof(str),"Welcome %s, you have been logged to your account",playerdb[playerid][username]); SendClientMessage(playerid, COLOR_BLUE, str); SetPlayerInterior(playerid, 0); SetPlayerVirtualWorld(playerid, 0); SpawnPlayer(playerid); playerdb[playerid][logged] = 1; } } else { ShowPlayerDialog(playerid,LOGIN_DIALOG,DIALOG_STYLE_PASSWORD,"Login to Account.","Wrong password:","Login","Cancel"); } mysql_free_result(); return 1; } public SavePlayerStats(playerid) // save player stats { if(playerdb[playerid][logged] == 1) { new pmoney[MAX_PLAYERS]; pmoney[playerid] = GetPlayerMoney(playerid); mysql_free_result(); playerdb[playerid][logged] = 0; } return 1; }
Mysql Log:
Код:
[18:00:47] >> mysql_close( Connection handle: 1 ) [18:00:47] CMySQLHandler::~CMySQLHandler() - deconstructor called. [18:00:47] CMySQLHandler::FreeResult() - Result was successfully free'd. [18:00:47] CMySQLHandler::Disconnect() - Connection was closed. [18:00:47] Unloading Plugin [18:00:47] [18:00:47] ** MySQL Debugging enabled (05/13/12) [18:00:47] [18:00:47] >> mysql_connect(localhost, samp, samp, ******) on port 3306 [18:00:47] CMySQLHandler::CMySQLHandler() - constructor called. [18:00:47] CMySQLHandler::CMySQLHandler() - Connecting to "localhost" | DB: "samp" | Username: "samp" [18:00:47] CMySQLHandler::Connect() - Connection was successful. [18:00:47] CMySQLHandler::Connect() - Auto-Reconnect has been enabled. [18:00:47] >> mysql_ping( Connection handle: 1 ) [18:00:47] CMySQLHandler::Ping() - Connection is still alive. [18:01:10] >> mysql_query_callback( Connection handle: 1 ) [18:01:10] >> mysql_store_result( Connection handle: 1 ) [18:01:10] CMySQLHandler::StoreResult() - No data to store. [18:01:10] >> mysql_num_rows( Connection handle: 1 ) [18:01:10] CMySQLHandler::NumRows() - You cannot call this function now. (Reason: Dead Connection) [18:01:10] >> mysql_free_result( Connection handle: 1 ) [18:01:10] CMySQLHandler::FreeResult() - The result is already empty. [18:01:10] Passing query SELECT * FROM users WHERE Name = '%s' | s [18:01:10] ProcessQueryThread(IsUsernameRegistered) - Query was successful. (SELECT * FROM users WHERE Name = '%s') [18:01:10] CMySQLHandler::ProcessQueryThread() - Data is getting passed to ->ProcessTick() [18:01:10] IsUsernameRegistered(s) - Threaded function called. [18:01:10] >> mysql_store_result( Connection handle: 1 ) [18:01:10] CMySQLHandler::StoreResult() - Result was stored. [18:01:10] >> mysql_num_rows( Connection handle: 1 ) [18:01:10] CMySQLHandler::NumRows() - Returned 0 row(s) [18:01:10] >> mysql_free_result( Connection handle: 1 ) [18:01:10] CMySQLHandler::FreeResult() - Result was successfully free'd. [18:01:18] >> mysql_query_callback( Connection handle: 1 ) [18:01:18] Passing query INSERT INTO users (Name,Password,Money) VALUES ('%s',md5('%s'), %d) | JethroTMrwrw [18:01:18] CMySQLHandler::ProcessQueryThread() - Error will be triggered to OnQueryError() [18:01:20] >> mysql_query_callback( Connection handle: 1 ) [18:01:20] >> mysql_store_result( Connection handle: 1 ) [18:01:20] CMySQLHandler::StoreResult() - No data to store. [18:01:20] >> mysql_num_rows( Connection handle: 1 ) [18:01:20] CMySQLHandler::NumRows() - You cannot call this function now. (Reason: Dead Connection) [18:01:20] >> mysql_fetch_row_format( Connection handle: 1 ) [18:01:20] CMySQLHandler::FetchRow() - You cannot call this function now. (Reason: Empty Result) [18:01:20] >> mysql_free_result( Connection handle: 1 ) [18:01:20] CMySQLHandler::FreeResult() - The result is already empty. [18:01:20] Passing query SELECT * FROM users WHERE Name = '%s' AND Password = md5('%s') | ss [18:01:20] ProcessQueryThread(OnLoginPlayer) - Query was successful. (SELECT * FROM users WHERE Name = '%s' AND Password = md5('%s')) [18:01:20] CMySQLHandler::ProcessQueryThread() - Data is getting passed to ->ProcessTick() [18:01:20] OnLoginPlayer(ss) - Threaded function called. [18:01:20] >> mysql_store_result( Connection handle: 1 ) [18:01:20] CMySQLHandler::StoreResult() - Result was stored. [18:01:20] >> mysql_num_rows( Connection handle: 1 ) [18:01:20] CMySQLHandler::NumRows() - Returned 0 row(s) [18:01:20] >> mysql_free_result( Connection handle: 1 ) [18:01:20] CMySQLHandler::FreeResult() - Result was successfully free'd.