18.10.2012, 18:13
Heey all,
I am new at Mysql and testing an account system.
But when i join my server and then i am joined and then the server is restarting.
So the script dont let me connect.
Script:
How can i fix this?
I am using R7.
Admigo
I am new at Mysql and testing an account system.
But when i join my server and then i am joined and then the server is restarting.
So the script dont let me connect.
Script:
pawn Код:
#include <a_samp>
#include <a_mysql>
forward CheckPlayer(playerid);
forward LoginPlayer(playerid,password);
forward OnQueryFinish(gQuery[]);
new gConnectionHandle,Query[1000],string[256];
enum pInfo
{
pAdmin,
pKills,
pDeaths
};
new PlayerInfo[MAX_PLAYERS][pInfo];
#if defined FILTERSCRIPT
public OnFilterScriptInit()
{
print("\n--------------------------------------");
print(" Blank Filterscript by your name here");
print("--------------------------------------\n");
return 1;
}
public OnFilterScriptExit()
{
return 1;
}
#else
main()
{
print("\n----------------------------------");
print(" Blank Gamemode by your name here");
print("----------------------------------\n");
}
#endif
public OnGameModeInit()
{
// Don't use these lines if it's a filterscript
gConnectionHandle = mysql_connect("localhost","admigo","test","test");
mysql_debug(1);
SetGameModeText("Blank Script");
AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
return 1;
}
public OnGameModeExit()
{
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)
{
mysql_format(gConnectionHandle,Query, "SELECT * FROM `users` WHERE 'Username' = '%e'", GetName(playerid));
mysql_function_query(gConnectionHandle,Query, false, "CheckPlayer","d", playerid);
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
mysql_format(gConnectionHandle,Query, "UPDATE `users` SET `Money` = %d,`Score` = %d,`Admin` = %d,`Kills` = %d,`Deaths` = %d WHERE 'Username' = '%e'",GetPlayerMoney(playerid),GetPlayerScore(playerid),PlayerInfo[playerid][pAdmin],PlayerInfo[playerid][pKills],PlayerInfo[playerid][pDeaths],GetName(playerid));
mysql_function_query(gConnectionHandle,Query,false,"OnQueryFinish","s",Query);
return 1;
}
public OnPlayerSpawn(playerid)
{
return 1;
}
public OnPlayerDeath(playerid, killerid, reason)
{
if(killerid != INVALID_PLAYER_ID) PlayerInfo[killerid][pKills]++;
PlayerInfo[playerid][pDeaths]++;
return 1;
}
public OnVehicleSpawn(vehicleid)
{
return 1;
}
public OnVehicleDeath(vehicleid, killerid)
{
return 1;
}
public OnPlayerText(playerid, text[])
{
return 1;
}
public OnPlayerCommandText(playerid, cmdtext[])
{
if (strcmp("/test", cmdtext, true, 10) == 0)
{
return 1;
}
return 0;
}
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
return 1;
}
public OnPlayerExitVehicle(playerid, vehicleid)
{
return 1;
}
public OnPlayerStateChange(playerid, newstate, oldstate)
{
return 1;
}
public OnPlayerEnterCheckpoint(playerid)
{
return 1;
}
public OnPlayerLeaveCheckpoint(playerid)
{
return 1;
}
public OnPlayerEnterRaceCheckpoint(playerid)
{
return 1;
}
public OnPlayerLeaveRaceCheckpoint(playerid)
{
return 1;
}
public OnRconCommand(cmd[])
{
return 1;
}
public OnPlayerRequestSpawn(playerid)
{
return 1;
}
public OnObjectMoved(objectid)
{
return 1;
}
public OnPlayerObjectMoved(playerid, objectid)
{
return 1;
}
public OnPlayerPickUpPickup(playerid, pickupid)
{
return 1;
}
public OnVehicleMod(playerid, vehicleid, componentid)
{
return 1;
}
public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
{
return 1;
}
public OnVehicleRespray(playerid, vehicleid, color1, color2)
{
return 1;
}
public OnPlayerSelectedMenuRow(playerid, row)
{
return 1;
}
public OnPlayerExitedMenu(playerid)
{
return 1;
}
public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
{
return 1;
}
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
return 1;
}
public OnRconLoginAttempt(ip[], password[], success)
{
return 1;
}
public OnPlayerUpdate(playerid)
{
return 1;
}
public OnPlayerStreamIn(playerid, forplayerid)
{
return 1;
}
public OnPlayerStreamOut(playerid, forplayerid)
{
return 1;
}
public OnVehicleStreamIn(vehicleid, forplayerid)
{
return 1;
}
public OnVehicleStreamOut(vehicleid, forplayerid)
{
return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
switch(dialogid)
{
case 0:
{
if(!response) return Kick(playerid);
mysql_format(gConnectionHandle,Query,"SELECT * FROM `users` WHERE Username = '%e' AND Password = '%e'",GetName(playerid),inputtext);
mysql_function_query(gConnectionHandle,Query,false,"LoginPlayer","ds",playerid,inputtext);
}
case 1:
{
if(!response) return Kick(playerid);
new IP[50];
GetPlayerIp(playerid, IP, sizeof(IP));
mysql_format(gConnectionHandle,Query,"INSERT INTO `users` (`Username`, `Password`, `Money`, `Score`, `Kills`, `Deaths`, `IP`) VALUES('%e', md5('%e'), 5000, 0, 0, 0, 0, '%e')", GetName(playerid),inputtext, IP);
mysql_function_query(gConnectionHandle,Query, false,"OnQueryFinish","s",Query);
GivePlayerMoney(playerid,5000);
}
}
return 0;
}
public OnPlayerClickPlayer(playerid, clickedplayerid, source)
{
return 1;
}
public OnQueryFinish(gQuery[])
{
printf("Query %s",Query);
return 1;
}
public CheckPlayer(playerid)
{
mysql_store_result();
if(mysql_num_rows() == 1)
{
format(string,sizeof(string), "Login %s",GetName(playerid));
ShowPlayerDialog(playerid, 0,DIALOG_STYLE_PASSWORD,"Login",string,"Ok","Quit");
}
else
{
format(string,sizeof(string), "Register %s",GetName(playerid));
ShowPlayerDialog(playerid, 1,DIALOG_STYLE_PASSWORD,"Register",string,"Ok","Quit");
}
mysql_free_result();
return 1;
}
public LoginPlayer(playerid,password)
{
mysql_store_result();
if(mysql_num_rows(gConnectionHandle) == 1)
{
if(mysql_retrieve_row())
{
mysql_fetch_field_row(string, "Money"); GivePlayerMoney(playerid,strval(string));
mysql_fetch_field_row(string, "Score"); SetPlayerScore(playerid,strval(string));
mysql_fetch_field_row(string, "Admin"); PlayerInfo[playerid][pAdmin] = strval(string);
mysql_fetch_field_row(string, "Kills"); PlayerInfo[playerid][pKills] = strval(string);
mysql_fetch_field_row(string, "Deaths"); PlayerInfo[playerid][pDeaths] = strval(string);
SendClientMessage(playerid,-1,"Succesfull logged in");
}
}
else
{
SetPVarInt(playerid, "WrongPassword", GetPVarInt(playerid, "WrongPassword") + 1);
if(GetPVarInt(playerid,"WrongPassword")== 3)
{
SendClientMessage(playerid,-1,"Kicked:Wrong Password");
return Kick(playerid);
}
format(string,sizeof(string), "Login %s",GetName(playerid));
ShowPlayerDialog(playerid, 0,DIALOG_STYLE_PASSWORD,"Login",string,"Ok","Quit");
SendClientMessage(playerid,-1,"Wrong Password");
}
mysql_free_result();
return 1;
}
stock GetName(playerid)
{
new PlayerName[MAX_PLAYER_NAME];
GetPlayerName(playerid,PlayerName,MAX_PLAYER_NAME);
return PlayerName;
}
I am using R7.
Admigo