07.04.2017, 19:35
Well, I tried to make a registering / login system via mysql after reading a tutorial, but I still do get a lot of warnings and errors. Would be really helpful if someone could explain where I went wrong and correct my mistake.
Code:
Warnings:C:\Users\KKRandev\Desktop\Samp Server\gamemodes\Basic.pwn(47) : error 017: undefined symbol "LOG_ALL"
C:\Users\KKRandev\Desktop\Samp Server\gamemodes\Basic.pwn(4 : warning 213: tag mismatch
C:\Users\KKRandev\Desktop\Samp Server\gamemodes\Basic.pwn(81) : warning 213: tag mismatch
C:\Users\KKRandev\Desktop\Samp Server\gamemodes\Basic.pwn(82) : warning 213: tag mismatch
C:\Users\KKRandev\Desktop\Samp Server\gamemodes\Basic.pwn(92) : error 017: undefined symbol "cache_get_data"
C:\Users\KKRandev\Desktop\Samp Server\gamemodes\Basic.pwn(96) : error 017: undefined symbol "cache_get_field_content"
C:\Users\KKRandev\Desktop\Samp Server\gamemodes\Basic.pwn(97) : error 017: undefined symbol "cache_get_field_content_int"
C:\Users\KKRandev\Desktop\Samp Server\gamemodes\Basic.pwn(91) : warning 203: symbol is never used: "field"
C:\Users\KKRandev\Desktop\Samp Server\gamemodes\Basic.pwn(135) : warning 213: tag mismatch
C:\Users\KKRandev\Desktop\Samp Server\gamemodes\Basic.pwn(136) : warning 213: tag mismatch
C:\Users\KKRandev\Desktop\Samp Server\gamemodes\Basic.pwn(161) : warning 213: tag mismatch
C:\Users\KKRandev\Desktop\Samp Server\gamemodes\Basic.pwn(162) : warning 213: tag mismatch
C:\Users\KKRandev\Desktop\Samp Server\gamemodes\Basic.pwn(171) : error 017: undefined symbol "cache_get_field_content_int"
C:\Users\KKRandev\Desktop\Samp Server\gamemodes\Basic.pwn(172) : error 017: undefined symbol "cache_get_field_content_int"
C:\Users\KKRandev\Desktop\Samp Server\gamemodes\Basic.pwn(173) : error 017: undefined symbol "cache_get_field_content_int"
C:\Users\KKRandev\Desktop\Samp Server\gamemodes\Basic.pwn(184) : warning 235: public function lacks forward declaration (symbol "OnAccounrRegister")
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase
7 Errors.
Code:
PHP код:
#include <a_samp>
#include <a_mysql>
#define MYSQL_HOST "localhost"
#define MYSQL_USER "root"
#define MYSQL_DATABASE "myserver"
#define MYSQL_PASSWORD ""
enum
{
LoginDialog,
RegisterDialog
};
new
mysql;
native WP_Hash(buffer[], len, const str[]);
enum PlayerData
{
ID,
Name[MAX_PLAYER_NAME],
Password[129],
IP[16],
Admin,
VIP,
Money
};
new Player[MAX_PLAYERS][PlayerData];
main()
{
print("\n----------------------------------");
print(" Blank Gamemode by your name here");
print("----------------------------------\n");
}
public OnGameModeInit()
{
mysql_log(LOG_ALL);
mysql = mysql_connect(MYSQL_HOST,MYSQL_USER, MYSQL_DATABASE, MYSQL_PASSWORD);
if(mysql_errno() !=0)
{
printf("[MySQL] The connection to the database failed.");
}
else
{
printf("[MySQL] The connection to the database was success!");
}
return true;
}
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)
{
TogglePlayerSpectating(playerid, true);
new
query[128],
playername[MAX_PLAYER_NAME];
GetPlayerName(playerid, playername, sizeof(playername));
mysql_format(mysql, query, sizeof(query), "SELECT `Password`, `ID` FROM `accounts` WHERE `Name` = `%e` LIMIT 1", playername);
mysql_tquery(mysql, query, "OnAccountCheck", "i", playerid);
return true;
}
forward OnAccountCheck(playerid);
public OnAccountCheck(playerid)
{
new
rows,
field;
cache_get_data(rows, fields, mysql);
if(rows)
{
cache_get_field_content(0, "Password", Player[playerid][Password], mysql, 129);
Player[playerid][ID] = cache_get_field_content_int(0, "ID");
ShowPlayerDialog(playerid, LoginDialog, DIALOG_STYLE_INPUT, "Login", "Welcome Player!\nYour account has been found in our database. Please fill in your password:", "Login", "Quit");
}
else
{
ShowPlayerDialog(playerid, RegisterDialog, DIALOG_STYLE_INPUT, "Register", "Welcome player!\nYour account has not been registered yet. Please fill in your desired password:", "Register", "Quit");
}
return true;
}
public OnPlayerCommandText(playerid, cmdtext[])
{
if (strcmp("/mycommand", cmdtext, true, 10) == 0)
{
// Do something here
return 1;
}
return 0;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
switch(dialogid)
{
case LoginDialog:
{
if(!response) return Kick(playerid);
new
hashpass[129],
query[100],
playername[MAX_PLAYER_NAME];
GetPlayerName(playerid, playername, sizeof(playername));
WP_Hash(hashpass, sizeof(hashpass), inputtext);
if(!strcmp(hashpass, Player[playerid][Password]))
{
mysql_format(mysql, query, sizeof(query), "SELECT * FROM `accounts` WHERE `Name` = '%e' LIMIT 1", playername);
mysql_tquery(mysql, query, "OnAccountLoad", "i", playerid);
}
else
{
SendClientMessage(playerid, -1, "You have specified an incorrect password!");
ShowPlayerDialog(playerid, LoginDialog, DIALOG_STYLE_INPUT, "Login", "Welcome player!\nYour account has been found in our database. Please fill in your password:", "Login", "Quit");
}
}
case RegisterDialog:
{
if(!response) return Kick(playerid);
if(strlen(inputtext) < 5)
{
SendClientMessage(playerid, -1, "Your password must atleast contain more than 4 letters");
return ShowPlayerDialog(playerid, RegisterDialog, DIALOG_STYLE_INPUT, "Register", "Welcome player!\nYour account has not been registered yet. Please fill in your desired password:", "Register", "Quit");
}
new
query[512],
playername[MAX_PLAYER_NAME],
playerip[16];
GetPlayerName(playerid, playername, sizeof(playername));
GetPlayerIp(playerid, playerip, sizeof(playerip));
WP_Hash(Player[playerid][Password], 129, inputtext);
mysql_format(mysql, query, sizeof(query), "INSERT INTO `accounts` (`Name`, `Password`, `IP`, `Admin`, `VIP`, `Money`) VALUES ('%e', '%e', '%e', 0, 0, 0)", playername, Player[playerid][Password], playerip);
mysql_tquery(mysql, query, "OnAccountRegister", "i", playerid);
}
}
return false;
}
forward OnAccountLoad(playerid);
public OnAccountLoad(playerid)
{
Player[playerid][Admin] = cache_get_field_content_int(0, "Admin");
Player[playerid][VIP] = cache_get_field_content_int(0, "VIP");
Player[playerid][Money] = cache_get_field_content_int(0, "Money");
TogglePlayerSpectating(playerid, false);
GivePlayerMoney(playerid, Player[playerid][Money]);
SendClientMessage(playerid, -1, "You have successfully logged in.");
return true;
}
forward OnAccountRegister(playerid);
public OnAccounrRegister(playerid)
{
Player[playerid][ID] = cache_insert_id();
printf("[Registeration] New account registered. Database ID: [%d]", Player[playerid][ID]);
TogglePlayerSpectating(playerid, false);
return true;
}
Warnings:C:\Users\KKRandev\Desktop\Samp Server\gamemodes\Basic.pwn(47) : error 017: undefined symbol "LOG_ALL"
C:\Users\KKRandev\Desktop\Samp Server\gamemodes\Basic.pwn(4 : warning 213: tag mismatch
C:\Users\KKRandev\Desktop\Samp Server\gamemodes\Basic.pwn(81) : warning 213: tag mismatch
C:\Users\KKRandev\Desktop\Samp Server\gamemodes\Basic.pwn(82) : warning 213: tag mismatch
C:\Users\KKRandev\Desktop\Samp Server\gamemodes\Basic.pwn(92) : error 017: undefined symbol "cache_get_data"
C:\Users\KKRandev\Desktop\Samp Server\gamemodes\Basic.pwn(96) : error 017: undefined symbol "cache_get_field_content"
C:\Users\KKRandev\Desktop\Samp Server\gamemodes\Basic.pwn(97) : error 017: undefined symbol "cache_get_field_content_int"
C:\Users\KKRandev\Desktop\Samp Server\gamemodes\Basic.pwn(91) : warning 203: symbol is never used: "field"
C:\Users\KKRandev\Desktop\Samp Server\gamemodes\Basic.pwn(135) : warning 213: tag mismatch
C:\Users\KKRandev\Desktop\Samp Server\gamemodes\Basic.pwn(136) : warning 213: tag mismatch
C:\Users\KKRandev\Desktop\Samp Server\gamemodes\Basic.pwn(161) : warning 213: tag mismatch
C:\Users\KKRandev\Desktop\Samp Server\gamemodes\Basic.pwn(162) : warning 213: tag mismatch
C:\Users\KKRandev\Desktop\Samp Server\gamemodes\Basic.pwn(171) : error 017: undefined symbol "cache_get_field_content_int"
C:\Users\KKRandev\Desktop\Samp Server\gamemodes\Basic.pwn(172) : error 017: undefined symbol "cache_get_field_content_int"
C:\Users\KKRandev\Desktop\Samp Server\gamemodes\Basic.pwn(173) : error 017: undefined symbol "cache_get_field_content_int"
C:\Users\KKRandev\Desktop\Samp Server\gamemodes\Basic.pwn(184) : warning 235: public function lacks forward declaration (symbol "OnAccounrRegister")
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase
7 Errors.