sziasztok.
nos, most hogy megjelet a threaded query mysql-ban, elkezdett érdekelni.
most elkezdtem tanulgatni, elég jól haladok függvények terén is, de a logikai részét még nem nagyon értem.
megírtam egy alap regisztrációs rendszert, de sajnos nem megy.
a mysql_tquery sajnos nem akarja meghívni az eljárást.
már utána olvasgattam, de sehol nem találtam rá megoldást.
újra is csináltam az adatbázist és a táblát (videó és tutorialok alapján, hogy biztosabb legyen).
nem tudtam rájönni, ezért most hozzátok fordulok.
íme a kód:
#include <a_samp>
#include <a_mysql>
#define host \"localhost\"
#define user \"root\"
#define database \"hss-samp\"
#define password \"\"
#define DIALOG_REGISTER 357
#define DIALOG_LOGIN 683
#define function%0(%1) forward%0(%1);public%0(%1)
enum pInfo
{
Password[35],
Money,
Score
};
new Info[MAX_PLAYERS][pInfo];
static mysql;
new query[2000];
public OnFilterScriptInit()
{
mysql_log(LOG_ALL,LOG_TYPE_TEXT);
mysql=mysql_connect(host,user,database,password);
if(mysql_errno(mysql)!=0) printf(\"MySQL: Hiba lépett fel a csatlakozáskor: %d.\",mysql_errno(mysql));
else print(\"MySQL: A csatlakozás sikeresen megtörtént.\");
return 1;
}
public OnFilterScriptExit()
{
mysql_close(mysql);
return 1;
}
public OnPlayerConnect(playerid)
{
mysql_format(mysql,query,1000,\"SELECT UserID FROM users WHERE Name=\'%s\' LIMIT 0,1\",Name(playerid));
mysql_tquery(mysql,query,\"User_Connect\",\"i\",playerid);
print(\"connect\");
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
mysql_format(mysql,query,500,\"UPDATE users SET Money=\'%d\',Score=\'%d\' WHERE Name=\'%s\'\",GetPlayerMoney(playerid),GetPlayerScore(playerid),Name(playerid));
mysql_tquery(mysql,query);
print(\"disconnect\");
return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(dialogid==DIALOG_REGISTER)
{
if(!response) return KickEx(playerid,\"nem regisztrált\");
if(strlen(inputtext)<4||strlen(inputtext)>30) return ShowPlayerDialog(playerid,DIALOG_REGISTER,DIALOG_STYLE_INPUT,\"Regisztráció\",\"{FF0000}Hiba: a jelszónak 4 és 30 karakter között kell lennie.\\n\\n{FFFF00}Írj be egy tetszőleges jelszavat,\\namit a belépésnél fogsz használni!\",\"Register\",\"Kick\");
mysql_format(mysql,query,300,\"INSERT INTO users (Name,Password,Money,Score) VALUES (\'%e\',SHA1(\'%e\'),\'0\',\'0\')\'\",Name(playerid),inputtext);
mysql_tquery(mysql,query,\"User_Register\",\"i\",playerid);
print(\"reg\");
}
if(dialogid==DIALOG_LOGIN)
{
if(!response) return KickEx(playerid,\"nem jelentkezett be\");
if(strlen(inputtext)<4||strlen(inputtext)>30) return ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_INPUT,\"Regisztráció\",\"{FF0000}Hiba: a jelszónak 4 és 30 karakter között kell lennie.\\n\\n{FFFF00}Írd be a regisztrálásnál használt jelszavad!\",\"Login\",\"Kick\");
mysql_format(mysql,query,300,\"SELECT * FROM users WHERE Name=\'%e\' AND Password=SHA1(\'%e\')\",Name(playerid),inputtext);
mysql_tquery(mysql,query,\"User_Login\",\"i\",playerid);
print(\"log\");
}
return 1;
}
function User_Connect(playerid)
{
//itt már mindent elkövettem, így hagytam, DIREKT pazaroltam egy kicsit sorokkal.
print(\"called\");
new rows=cache_num_rows();
printf(\"rows: %d\",rows);
if(rows==0)
{
print(\"ez\");
ShowPlayerDialog(playerid,DIALOG_REGISTER,DIALOG_STYLE_INPUT,\"Regisztráció\",\"{FFFF00}Írj be egy tetszőleges jelszavat,\\namit a belépésnél fogsz használni!\",\"Register\",\"Kick\");
}
else
{
print(\"az\");
ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_INPUT,\"Bejelentkezés\",\"{FFFF00}Írd be a regisztrálásnál használt jelszavad!\",\"Login\",\"Kick\");
}
print(\"connect 22222222\");
return 1;
}
function User_Register(playerid)
{
new string[256];
format(string,sizeof(string),\"{ADFF2F}[Register]: {%06x}%s {1E90FF}sikeresen regisztrált a szerverre.\",GetPlayerColor(playerid)>>>8,Name(playerid));
SendClientMessageToAll(-1,string);
Info[playerid][Money]=0;
Info[playerid][score]=0;
print(\"reg 22222222\");
return 1;
}
function User_Login(playerid)
{
new rows=cache_get_row_count(),string[256];
if(rows==0) return ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_INPUT,\"Bejelentkezés\",\"{FF0000}Hiba: a beírt jelszó nem egyezik.\\n\\n{FFFF00}Írd be a regisztrálásnál használt jelszavad!\",\"Login\",\"Kick\");
Info[playerid][Money]=cache_get_field_content_int(0,\"Money\");
Info[playerid][score]=cache_get_field_content_int(0,\"Score\");
cache_get_field_content(0,\"Password\",Info[playerid][Password]);
GivePlayerMoney(playerid,Info[playerid][Money]);
SetPlayerScore(playerid,Info[playerid][score]);
format(string,sizeof(string),\"{ADFF2F}[Login]: {%06x}%s {1E90FF}sikeresen bejelentkezett.\",GetPlayerColor(playerid)>>>8,Name(playerid));
SendClientMessageToAll(-1,string);
print(\"log 22222222\");
return 1;
}
stock Name(playerid)
{
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid,name,MAX_PLAYER_NAME);
return name;
}
stock KickEx(playerid,reason[])
{
new string[256];
format(string,sizeof(string),\"{ADFF2F}[Kick]: {%06x}%s {66CDAA}kickelve lett, mert {FF0000}%s{66CDAA}.\",GetPlayerColor(playerid)>>>8,Name(playerid),reason);
SendClientMessageToAll(-1,string);
SetTimerEx(\"KickPlayer\",25,0,\"i\",playerid);
return 1;
}
function KickPlayer(playerid) Kick(playerid);
ez a server log (figyeljétek a \'print\'-eket):
----------
Loaded log file: \"server_log.txt\".
----------
SA-MP Dedicated Server
----------------------
v0.3z, (C)2005-2014 SA-MP Team
[16:56:13]
[16:56:13] Server Plugins
[16:56:13] --------------
[16:56:13] Loading plugin: sscanf
[16:56:14]
[16:56:14] ===============================
[16:56:14] sscanf plugin loaded.
[16:56:14] Version: 2.8.1
[16:56:14] (c) 2012 Alex \"Y_Less\" Cole
[16:56:14] ===============================
[16:56:14] Loaded.
[16:56:14] Loading plugin: streamer
[16:56:14]
*** Streamer Plugin v2.7.4 by Incognito loaded ***
[16:56:14] Loaded.
[16:56:14] Loading plugin: mysql
[16:56:15] >> plugin.mysql: R39-2 successfully loaded.
[16:56:15] Loaded.
[16:56:15] Loaded 3 plugins.
[16:56:16]
[16:56:16] Filterscripts
[16:56:16] ---------------
[16:56:16] Loading filterscript \'mysql_reg.amx\'...
[16:56:17] MySQL: A csatlakozás sikeresen megtörtént.
[16:56:17] Loaded 1 filterscripts.
[16:56:17]
----------------------------------
[16:56:17] Blank Gamemode by your name here
[16:56:17] ----------------------------------
[16:56:17] Number of vehicle models: 0
[16:57:43] Incoming connection: 1.1.1.89:50284
[16:57:43] [join] mysqlteszt has joined the server (0:1.1.1.89)
[16:57:43] connect
[16:58:14] disconnect
[16:58:14] [part] mysqlteszt has left the server (0:1)
és a mysql log:
[16:56:16] [DEBUG] mysql_connect - host: \"localhost\", user: \"root\", database: \"hss-samp\", password: \"****\", port: 3306, autoreconnect: true, pool_size: 2
[16:56:16] [DEBUG] CMySQLHandle::Create - creating new connection..
[16:56:16] [DEBUG] CMySQLHandle::CMySQLHandle - constructor called
[16:56:16] [DEBUG] CMySQLHandle::Create - connection created (id: 1)
[16:56:16] [DEBUG] CMySQLConnection::Connect - establishing connection to database...
[16:56:17] [DEBUG] CMySQLConnection::Connect - connection was successful
[16:56:17] [DEBUG] CMySQLConnection::Connect - auto-reconnect has been enabled
[16:56:17] [DEBUG] mysql_errno - connection: 1
[16:56:17] [DEBUG] CMySQLConnection::Connect - establishing connection to database...
[16:56:17] [DEBUG] CMySQLConnection::Connect - establishing connection to database...
[16:56:17] [DEBUG] CMySQLConnection::Connect - establishing connection to database...
[16:56:17] [DEBUG] CMySQLConnection::Connect - connection was successful
[16:56:17] [DEBUG] CMySQLConnection::Connect - auto-reconnect has been enabled
[16:56:17] [DEBUG] CMySQLConnection::Connect - connection was successful
[16:56:17] [DEBUG] CMySQLConnection::Connect - auto-reconnect has been enabled
[16:56:17] [DEBUG] CMySQLConnection::Connect - connection was successful
[16:56:17] [DEBUG] CMySQLConnection::Connect - auto-reconnect has been enabled
[16:57:43] [DEBUG] mysql_format - connection: 1, len: 1000, format: \"SELECT UserID FROM users WHERE Name=\'%s\' LIMIT 0,1\"
[16:57:43] [DEBUG] mysql_tquery - connection: 1, query: \"SELECT UserID FROM users WHERE Name=\'mysqlteszt\' LIMIT 0,1\", callback: \"User_Connect\", format: \"i\"
[16:57:43] [DEBUG] CMySQLQuery::Execute[user_Connect] - starting query execution
[16:57:46] [DEBUG] CMySQLQuery::Execute[user_Connect] - query was successfully executed within 3303.840 milliseconds
[16:57:46] [DEBUG] CMySQLResult::CMySQLResult() - constructor called
[16:57:46] [DEBUG] Calling callback \"User_Connect\"..
[16:57:46] [DEBUG] CMySQLResult::~CMySQLResult() - deconstructor called
[16:58:14] [DEBUG] mysql_format - connection: 1, len: 500, format: \"UPDATE users SET Money=\'%d\',Score=\'%d\' WHERE Name=\'%s\'\"
[16:58:14] [DEBUG] mysql_tquery - connection: 1, query: \"UPDATE users SET Money=\'0\',Score=\'0\' WHERE Name=\'mysqlteszt\'\", callback: \"(null)\", format: \"(null)\"
[16:58:14] [DEBUG] CMySQLQuery::Execute[] - starting query execution
[16:58:14] [DEBUG] CMySQLQuery::Execute[] - query was successfully executed within 394.603 milliseconds
[16:58:14] [DEBUG] CMySQLQuery::Execute[] - no callback specified, skipping result saving
remélem tudtok segíteni, várom a válaszotokat.
előre kösz.