#define FILTERSCRIPT
#include <a_samp>
#include <a_mysql>
#include <sscanf2>
//========================= [MySQL Database Settings] ==========================
#define mysql_host \"localhost\"//the IP of the host, should be displayed when created a database
#define mysql_user \"root\"//database username
#define mysql_password \"\"//database password
#define mysql_database \"accounts\"//database name
//========================= [MySQL Database Settings] ==========================
//============================ [Colors] ========================================
#define white 0xFFFFFFFF
#define blue 0x0073FFFF
#define liblue 0x00FFFFFF
#define green 0x00E228FF
#define ligreen 0x00FF28FF
#define green2 0x9BFF00FF
#define limegreen 0x00FF96FF
#define pink 0xFFAFD7FF
#define purple 0xDB00AFFF
#define yellow 0xF5FF00FF
#define orange 0xFFA000FF
#define red 0xFF0000FF
//============================ [Colors] ========================================
//============================ [Hex] ===========================================
#define cwhite \"{FFFFFF}\"
#define cblue \"{00B9FF}\"
#define cliblue \"{00FFFA}\"
#define cgreen \"{05E200}\"
#define cligreen \"{05FF00}\"
#define cgreen2 \"{A5FF00}\"
#define cpink \"{FFA4C3}\"
#define cpurple \"{E500C3}\"
#define cyellow \"{FFFA00}\"
#define cyellow2 \"{FFFF11}\"
#define corange \"{FF9600}\"
#define cred \"{FF0000}\"
//============================ [Hex] ===========================================
#define Logindialog 1
#define Regdialog 2
#define Reginfo 3
enum PlayerData
{
AccID,
Username[24],
Password[129],
Ip[16],
Money,
Score,
Kills,
Deaths,
Logged,
FailedLogins,
FirstSpawn
};
native WP_Hash(buffer[], len, const str[]);
new pData[MAX_PLAYERS][PlayerData];
new Query[450];
public OnFilterScriptInit()
{
mysql_debug(1);
print(\"\\n************************************\");
print(\"BReg - MySQL Registration script by [MWR]Blood - Loaded!\");
print(\"************************************\\n\");
mysql_connect(mysql_host,mysql_user,mysql_database,mysql_password);
mysql_query(
\"CREATE TABLE IF NOT EXISTS `Accounts` (\"\\
\"`AccID` int(10) NOT NULL AUTO_INCREMENT,\"\\
\"`Username` varchar(24) NOT NULL,\"\\
\"`Password` varchar(64) NOT NULL,\"\\
\"`IP` varchar(16) NULL,\"\\
\"`Money` int(15) NULL,\"\\
\"`Score` int(15) NULL,\"\\
\"`Kills` int(15) NULL,\"\\
\"`Deaths` int(15) NULL,\"\\
\"PRIMARY KEY (`AccID`)\"\\
\") ENGINE=InnoDB DEFAULT CHARSET=latin1;\");
if(mysql_ping() > -1) return print(\"::BReg:: MySQL connection to database succeeded!\");
else print(\"::BReg:: MySQL connection to database failed. Please check your database settings!\");
return 1;
}
public OnFilterScriptExit()
{
print(\"\\n************************************\");
print(\"BReg - MySQL Registration script by [MWR]Blood - Unloaded!\");
print(\"************************************\\n\");
return 1;
}
public OnPlayerConnect(playerid)
{
new string[256];
format(Query,sizeof(Query),\"SELECT Username FROM `Accounts` WHERE `Username` = \'%s\'\",GetPName(playerid));
mysql_query(Query);
mysql_store_result();
if(mysql_num_rows() != 0)
{
format(Query,sizeof Query,\"SELECT IP FROM `Accounts` WHERE `Username` = \'%s\' AND `IP` = \'%s\'\",GetPName(playerid),GetIP(playerid));
mysql_query(Query);
mysql_store_result();
if(mysql_num_rows() != 0)
{
LoadStats(playerid);
pData[playerid][Logged] = 1;
PlaySound(playerid,1057);
SendClientMessage(playerid,green,\"» You have been automatically logged in! Welcome back!\");
}
else
{
format(string,sizeof(string),\"\"cblue\"Hey, \"cred\"%s\"cblue\"! \\nYour account is \"cgreen\"registered\"cblue\".\\nPlease enter the \"cred\"password\"cblue\" to log in!\",GetPName(playerid));
ShowPlayerDialog(playerid,Logindialog,DIALOG_STYLE_INPUT,\"\"cgreen2\"Log in\",string,\"Login\",\"\");
}
}
else
{
format(string,sizeof(string),\"\"cblue\"Hey, \"cred\"%s\"cblue\"! \\nYour account is \"cred\"not registered\"cblue\". \\nPlease \"cgreen\"register\"cblue\" to continue!\",GetPName(playerid));
ShowPlayerDialog(playerid,Regdialog,DIALOG_STYLE_INPUT,\"\"cpurple\"Register\",string,\"Register\",\"\");
}
mysql_free_result();
pData[playerid][FirstSpawn] = 1;
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
if(pData[playerid][Logged] == 1) return SaveStats(playerid);
pData[playerid][FailedLogins] = 0;
return 1;
}
public OnPlayerSpawn(playerid)
{
if(pData[playerid][FirstSpawn] == 1 && pData[playerid][Logged] == 1)
{
GivePlayerMoney(playerid,pData[playerid][Money]);
SetPlayerScore(playerid,pData[playerid][score]);
format(pData[playerid][ip],16,\"%s\",GetIP(playerid));
pData[playerid][FirstSpawn] = 0;
}
return 1;
}
public OnPlayerDeath(playerid, killerid, reason)
{
pData[killerid][Kills]++;
pData[playerid][Deaths]++;
return 1;
}
public OnVehicleSpawn(vehicleid)
{
return 1;
}
public OnVehicleDeath(vehicleid, killerid)
{
return 1;
}
public OnPlayerText(playerid, text[])
{
return 1;
}
public OnPlayerCommandText(playerid, cmdtext[])
{
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 Regdialog:
{
new string[220];
if(strlen(inputtext) == 0)
{
ShowPlayerDialog(playerid,Regdialog,DIALOG_STYLE_INPUT,\"\"cblue\"Register - \"cyellow\"Enter your password\",\"\"cblue\"You are about to register a \"cyellow\"new account\"cblue\"! \\nPlease choose the \"corange\"password\"cblue\" for it! \\n\",\"Register!\",\"\");
SendClientMessage(playerid,red,\"Please input a password!\");
}
else
{
new EscapedText[64],buffer[129];
mysql_real_escape_string(inputtext, EscapedText);
WP_Hash(buffer,sizeof(buffer),EscapedText);
format(Query,sizeof(Query),\"INSERT INTO `Accounts` (Username,Password,IP,Money,Score,Kills,Deaths) VALUES(\'%s\',\'%s\',\'%s\',\'0\',\'0\',\'0\',\'0\')\",GetPName(playerid),buffer,GetIP(playerid));
mysql_query(Query);
mysql_store_result();
SendClientMessage(playerid,green2,\"You have been successfully registered!\");
format(string,sizeof(string),\"\"cgreen\"You have been successfully registered! \\n\"cwhite\"» Your username: \"cblue\"%s \\n\"cwhite\"» Your password: \"cblue\"%s \\n\"cwhite\"» Your account ID: \"cblue\"%i \",GetPName(playerid),inputtext,mysql_insert_id());
ShowPlayerDialog(playerid,Reginfo,0,\"Registered!\",string,\"Ok\",\"\");
mysql_free_result();
LoadStats(playerid);
pData[playerid][Logged] = 1;
GivePlayerMoney(playerid,5000);
SetPlayerScore(playerid,1);
PlaySound(playerid,1083);
}
}
case Logindialog:
{
if(!response) return Kick(playerid);
if(strlen(inputtext) == 0)
{
new string[220];
format(string,sizeof(string),\"\"cblue\"Hey, \"cred\"%s\"cblue\"! \\nYour account is \"cgreen\"registered\"cblue\".\\nPlease enter the \"cred\"password\"cblue\" to log in!\",GetPName(playerid));
ShowPlayerDialog(playerid,Logindialog,DIALOG_STYLE_INPUT,\"\"cgreen2\"Log in\",string,\"Login\",\"\");
SendClientMessage(playerid,red,\"Please input a password!\");
}
else
{
LoginPlayer(playerid,inputtext);
}
}
}
return 1;
}
public OnPlayerClickPlayer(playerid, clickedplayerid, source)
{
return 1;
}
GetPName(playerid)
{
new pname[24];
GetPlayerName(playerid,pname,24);
return pname;
}
GetIP(playerid)
{
new ip[16];
GetPlayerIp(playerid,ip,16);
return ip;
}
stock PlaySound(playerid,soundid)
{
new Float:p[3];
GetPlayerPos(playerid, p[0], p[1], p[2]);
PlayerPlaySound(playerid, soundid, p[0], p[1], p[2]);
return 1;
}
stock LoadStats(playerid)
{
format(Query, sizeof(Query), \"SELECT * FROM `Accounts` WHERE `Username` = \'%s\'\", GetPName(playerid));
mysql_query(Query);
mysql_store_result();
mysql_fetch_row_format(Query, \"|\");
sscanf(Query, \"e<p<|>is[24]s[129]s[16]iiii>\", pData[playerid]);//Remember to update this if you are going to add more info!
mysql_free_result();
return 1;
}
stock SaveStats(playerid)
{
format(Query,sizeof(Query),\"UPDATE `Accounts` SET `IP` = \'%s\', `Money` = \'%i\', `Score` = \'%i\', `Kills` = \'%i\', `Deaths` = \'%i\' WHERE `Username` = \'%s\'\",
pData[playerid][ip],
GetPlayerMoney(playerid),
GetPlayerScore(playerid),
pData[playerid][Kills],
pData[playerid][Deaths],
GetPName(playerid));
mysql_query(Query);
mysql_free_result();
return 1;
}
stock LoginPlayer(playerid,const password[])
{
new string[165], buffer[129];
WP_Hash(buffer,sizeof(buffer),password);
format(Query,sizeof(Query),\"SELECT Password FROM `Accounts` WHERE `Username` = \'%s\' AND `Password` = \'%s\'\",GetPName(playerid),buffer);
mysql_query(Query);
mysql_store_result();
if(mysql_num_rows() != 0)
{
format(string,sizeof(string),\"You have been logged in! Welcome back, \"cred\"%s\"cgreen\"!\",GetPName(playerid));
SendClientMessage(playerid,green,string);
LoadStats(playerid);
pData[playerid][Logged] = 1;
PlaySound(playerid,1057);
}
else
{
pData[playerid][FailedLogins]++;
format(string,sizeof(string),\"\"cred\"Attempts left: \"corange\"%i \\n\"cblue\"Hey, \"cred\"%s\"cblue\"! \\nYour account is \"cgreen\"registered\"cblue\".\\nPlease enter the \"cred\"password\"cblue\" to log in!\",3-pData[playerid][FailedLogins],GetPName(playerid));
ShowPlayerDialog(playerid,Logindialog,DIALOG_STYLE_INPUT,\"\"cgreen2\"Log in\",string,\"Login\",\"\");
PlaySound(playerid,1055);
if(pData[playerid][FailedLogins] == 3)
{
format(string,sizeof(string),\"%s has been automatically kicked as he entered the wrong login password 3 times in a row\",GetPName(playerid));
SendClientMessageToAll(red,string);
SendClientMessage(playerid,red,\"*** You have been kicked as you have entered the wrong login password 3 times!\");
PlaySound(playerid,1141);
Kick(playerid);
}
}
mysql_free_result();
return 1;
}
public OnGameModeInit()
{
// People can spawn with either the CJ skin or The Truth skin.
AddPlayerClass( 79, -1510.4670, 2634.7317, 55.8359, 278.2426, 0, 0, 0, 0, 0, 0 );
return 1;
}
main()
{
}
Dupla hozzászólás automatikusan összefûzve. ( 2012. november 26. - 19:33:30 )
itt az egész :DDD , csak egy alap regrendszer. szórakozni akarok vele de így nemjó :/