Szerző Téma: MYSQL, Login-Register cucc  (Megtekintve 2354 alkalommal)

MYSQL, Login-Register cucc
« Dátum: 2012. December 25. - 13:10:16 »
0 Show voters
Sziasztok, keresgéltem a neten, egy MYSQL alapú regisztrálós belépõs rendszert. ámbár sikeresen megcsináltam mindent (picit értek a mysql-hez) de ennek nem a mysql el van baja hanem valami mással ime a kód:
KÓD:
 
/*
            ===================================
              Advanced MySQL registration system.
                     By Carlton.
            ===================================
*/
#include <a_samp>
#include <a_mysql>
#include <zcmd>
#define BLUE 0x0000FFFF
#define SQL_HOST \"\"
#define SQL_USER \"\"
#define SQL_PASSWORD \"\"
#define SQL_DB \"\"
#define SQL_TABLE \"\" // The table to store the users in.
#define SQL_CHECK_ACCOUNT 1
#define SQL_CHECK_IP 2
#define SQL_CHECK_LOGIN 3
#define SQL_REGISTER_PLAYER 4
#define SQL_SAVE_ACCOUNT 5
#define ERROR_MESSAGE1 \"The autologin failed, because your IP address didn\'t match the name.\"
#define ERROR_MESSAGE2 \"The password you have given does not match.\"
#define REGMSSG \"You have registered a account.\"
#define LOGINMSSG1 \"You have logged in.\"
#define LOGINMSSG2 \"You have autologged in\"
#define function%0(%1) stock%0(%1)
//#define AutoLogin // - Remove the // if you want a autologin when a player spawns.
//#define Force_Login // - Remove the // if you want to force a player to login and register when that player joins.
// Do not use AutoLogin and Force_Login at the same time!
new RegistrationSystemConnection, stringsize[256], pname[MAX_PLAYER_NAME];
enum Accinfo {
bool:Account,
bool:Logged,
pip[16],
Float: pHealth,
Float: pArmour,
}
new AccountData[MAX_PLAYERS][Accinfo];
enum PA {
IP[30],
Money,
AdminLevel,
Float: Health,
Float: Armour,
Bank
}
new PlayerAccount[MAX_PLAYERS][PA];
enum Esc
{
Escape[128]
}
new SQL_Escape[Esc];
function SavePlayerAccount(playerid) {
    GetPlayerName(playerid, pname, sizeof(pname));
    GetPlayerHealth(playerid, AccountData[playerid][pHealth]);
    GetPlayerArmour(playerid, AccountData[playerid][pArmour]);
    format(stringsize, sizeof(stringsize), \"UPDATE \"SQL_TABLE\" SET Money = %d, AdminLevel = %d, Health = %f, Armour = %f, Bank = %d WHERE Name = \'%s\'\",
GetPlayerMoney(playerid), PlayerAccount[playerid][AdminLevel], AccountData[playerid][pHealth], AccountData[playerid][pArmour], PlayerAccount[playerid][bank], pname);
mysql_query(stringsize, SQL_SAVE_ACCOUNT, playerid, RegistrationSystemConnection);
}
function OnPlayerLogin(playerid) {
  // In this function you can make a user forcespawn. This is called after someone logged in..
  GivePlayerMoney(playerid, PlayerAccount[playerid][Money]);
  SetPlayerHealth(playerid, PlayerAccount[playerid][Health]);
  SetPlayerArmour(playerid, PlayerAccount[playerid][Armour]);
  AccountData[playerid][Logged] = true;
}
function OnPlayerRegister(playerid) {
    // In this function you can make a user forcespawn. This is called after someone registered.
    AccountData[playerid][Account] = true;
    #if defined Force_Login
{
    ShowPlayerDialog(playerid,1,DIALOG_STYLE_INPUT,\"Login\",\"Enter your password below:\",\"Login\",\"Cancel\"); }
#endif
}
function ConnectToDB() {
mysql_debug(1);
    RegistrationSystemConnection = mysql_connect(SQL_HOST, SQL_USER, SQL_DB, SQL_PASSWORD);
    if(mysql_ping(RegistrationSystemConnection) == -1) {
        mysql_reconnect(RegistrationSystemConnection);
    }
}
function LoginPlayer(playerid, reason) {
    GetPlayerName(playerid, pname, sizeof(pname));
    format(stringsize, sizeof(stringsize), \"SELECT * FROM \"SQL_TABLE\"\", pname);
mysql_query(stringsize, -1, -1, RegistrationSystemConnection);
mysql_store_result();
new playerfilesplit[8][128], playerloadingarray[128];
mysql_fetch_row_format(playerloadingarray,\"|\", RegistrationSystemConnection);
split(playerloadingarray, playerfilesplit, \'|\');
PlayerAccount[playerid][Money] = strval(playerfilesplit[3]);
PlayerAccount[playerid][AdminLevel] = strval(playerfilesplit[4]);
PlayerAccount[playerid][Health] = floatstr(playerfilesplit[5]);
PlayerAccount[playerid][Armour] = floatstr(playerfilesplit[6]);
PlayerAccount[playerid][bank] = strval(playerfilesplit[7]);
mysql_free_result(RegistrationSystemConnection);
switch(reason) {
case 1: {
    SendClientMessage(playerid, BLUE, LOGINMSSG1);
}
case 2: {
    SendClientMessage(playerid, BLUE, LOGINMSSG2);
}
}
OnPlayerLogin(playerid);
}
function RegisterPlayer(playerid, inputtedpassword[]) {
    GetPlayerName(playerid, pname, sizeof(pname));
    //GetPlayerIp(playerid, AccountData[playerid][pip], sizeof(AccountData[playerid][pip]) );
    new plrIP[20];
    GetPlayerIp(playerid, plrIP, sizeof(plrIP));
    GetPlayerHealth(playerid, AccountData[playerid][pHealth]);
    GetPlayerArmour(playerid, AccountData[playerid][pArmour]);
    format(stringsize, sizeof(stringsize), \"INSERT INTO \"SQL_TABLE\" (Name, Password, IP, Money, AdminLevel, Health, Armour, Bank) VALUES(\'%s\', md5(\'%s\'), \'%s\', %d, 0, \'%f\', \'%f\', 0)\", pname, inputtedpassword, plrIP,
GetPlayerMoney(playerid), AccountData[playerid][pHealth], AccountData[playerid][pArmour]);
mysql_query(stringsize, SQL_REGISTER_PLAYER, playerid, RegistrationSystemConnection);
OnPlayerRegister(playerid);
}
function split(const strsrc[], strdest[][], delimiter)
{
new i, li;
new aNum;
new len;
while(i <= strlen(strsrc)){
    if(strsrc==delimiter || i==strlen(strsrc)){
        len = strmid(strdest[aNum], strsrc, li, i, 128);
        strdest[aNum][len] = 0;
        li = i+1;
        aNum++;
}
i++;
}
return 1;
}
 
public OnFilterScriptInit() {
    ConnectToDB();
}
public OnFilterScriptExit() {
mysql_close(RegistrationSystemConnection);
}
public OnPlayerConnect(playerid) {
GetPlayerName(playerid, pname, sizeof(pname));
format(stringsize, sizeof(stringsize), \"SELECT * FROM \"SQL_TABLE\" WHERE Name = \'%s\'\", pname);
//   mysql_query(stringsize, SQL_CHECK_ACCOUNT, playerid, RegistrationSystemConnection);
mysql_query(stringsize, -1,-1, RegistrationSystemConnection);
    mysql_store_result(RegistrationSystemConnection);
if(mysql_num_rows(RegistrationSystemConnection) > 0) {
AccountData[playerid][Account] = true;
}
else AccountData[playerid][Account] = false;
mysql_free_result(RegistrationSystemConnection);
#if defined AutoLogin
{
if(AccountData[playerid][Account] == true) {
   new plrIP[20];
       GetPlayerIp(playerid, plrIP, sizeof(plrIP));
    format(stringsize, sizeof(stringsize), \"SELECT * FROM \"SQL_TABLE\" WHERE Name = \'%s\' AND IP = \'%s\'\", pname, plrIP);
   mysql_query(stringsize, -1, -1, RegistrationSystemConnection);
   mysql_store_result(RegistrationSystemConnection);
   if(mysql_num_rows(RegistrationSystemConnection) > 0) {
      LoginPlayer(playerid, 2);
   }
   else return SendClientMessage(playerid, BLUE, ERROR_MESSAGE1);
   mysql_free_result(RegistrationSystemConnection);
}
}
#endif
#if defined Force_Login
{
if(AccountData[playerid][Account] == true) {
    ShowPlayerDialog(playerid,1,DIALOG_STYLE_INPUT,\"Login\",\"Enter your password below:\",\"Login\",\"Cancel\");
}
else ShowPlayerDialog(playerid,2,DIALOG_STYLE_INPUT,\"Register\",\"Enter your password below:\",\"Register\",\"Cancel\");
}
#endif
return 1;
}
public OnPlayerDisconnect(playerid) {
    SavePlayerAccount(playerid);
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
switch(dialogid) {
case 1: {
    if(!strlen(inputtext)) return ShowPlayerDialog(playerid,1,DIALOG_STYLE_INPUT,\"Login\",\"Enter your password below:\",\"Login\",\"Cancel\");
    if(!response) return ShowPlayerDialog(playerid,1,DIALOG_STYLE_INPUT,\"Login\",\"Enter your password below:\",\"Login\",\"Cancel\");
   mysql_real_escape_string(inputtext, SQL_Escape[Escape], RegistrationSystemConnection);
    format(stringsize, sizeof(stringsize), \"SELECT * FROM \"SQL_TABLE\" WHERE Name = \'%s\' AND Password = md5(\'%s\') LIMIT 1\", pname, SQL_Escape[Escape]);
   mysql_query(stringsize, -1, -1, RegistrationSystemConnection);
   mysql_store_result(RegistrationSystemConnection);
   if(mysql_num_rows(RegistrationSystemConnection) > 0) {
      LoginPlayer(playerid, 1);
   }
   else return SendClientMessage(playerid, BLUE, ERROR_MESSAGE2);
}
case 2: {
    if(!strlen(inputtext)) return ShowPlayerDialog(playerid,2,DIALOG_STYLE_INPUT,\"Register\",\"Enter your password below:\",\"Register\",\"Cancel\");
    if(!response) return ShowPlayerDialog(playerid,2,DIALOG_STYLE_INPUT,\"Register\",\"Enter your password below:\",\"Register\",\"Cancel\");
   mysql_real_escape_string(inputtext, SQL_Escape[Escape], RegistrationSystemConnection);
    RegisterPlayer(playerid, SQL_Escape[Escape]);
}
}
    return 0;
}
public OnQueryFinish( query[], resultid, extraid, connectionHandle )
{
switch(resultid) {
/*   case SQL_CHECK_ACCOUNT: {
   mysql_store_result(RegistrationSystemConnection);
   if(mysql_num_rows(RegistrationSystemConnection) > 0) {
      AccountData[extraid][Account] = true;
   }
   else AccountData[extraid][Account] = false;
   mysql_free_result(RegistrationSystemConnection);
}
case SQL_CHECK_LOGIN: {
   mysql_store_result(RegistrationSystemConnection);
   if(mysql_num_rows(RegistrationSystemConnection) > 1) {
      LoginPlayer(extraid, 1);
   }
   else return SendClientMessage(extraid, BLUE, ERROR_MESSAGE2);
   mysql_free_result(RegistrationSystemConnection);
}
case SQL_CHECK_IP: {
   mysql_store_result(RegistrationSystemConnection);
   if(mysql_num_rows(RegistrationSystemConnection) > 0) {
      LoginPlayer(extraid, 2);
   }
   else return SendClientMessage(extraid, BLUE, ERROR_MESSAGE1);
   mysql_free_result(RegistrationSystemConnection);
}*/
case SQL_REGISTER_PLAYER: {
    SendClientMessage(extraid, BLUE, REGMSSG);
}
case SQL_SAVE_ACCOUNT: {
}
}
return 1;
}
command(register, playerid, params[]) {
    if(AccountData[playerid][Account] == false && AccountData[playerid][Logged] == false) {
    ShowPlayerDialog(playerid,2,DIALOG_STYLE_INPUT,\"Register\",\"Enter your password below:\",\"Register\",\"Cancel\");
}
return 1;
}
command(login, playerid, params[]) {
if(AccountData[playerid][Account] == true && AccountData[playerid][Logged] == false) {
    ShowPlayerDialog(playerid,1,DIALOG_STYLE_INPUT,\"Login\",\"Enter your password below:\",\"Login\",\"Cancel\");
}
return 1;
}

 
AZ ERROR - WARNING:
 
C:\\Users\\Peter\\Desktop\\Sa-MP\\gamemodes\\mysql.pwn(72) : warning 236: unknown parameter in substitution (incorrect #define pattern)
C:\\Users\\Peter\\Desktop\\Sa-MP\\gamemodes\\mysql.pwn(72) : warning 236: unknown parameter in substitution (incorrect #define pattern)
C:\\Users\\Peter\\Desktop\\Sa-MP\\gamemodes\\mysql.pwn(72) : warning 236: unknown parameter in substitution (incorrect #define pattern)
C:\\Users\\Peter\\Desktop\\Sa-MP\\gamemodes\\mysql.pwn(72) : warning 236: unknown parameter in substitution (incorrect #define pattern)
C:\\Users\\Peter\\Desktop\\Sa-MP\\gamemodes\\mysql.pwn(72) : warning 236: unknown parameter in substitution (incorrect #define pattern)
C:\\Users\\Peter\\Desktop\\Sa-MP\\gamemodes\\mysql.pwn(72) : warning 236: unknown parameter in substitution (incorrect #define pattern)
C:\\Users\\Peter\\Desktop\\Sa-MP\\gamemodes\\mysql.pwn(72) : warning 236: unknown parameter in substitution (incorrect #define pattern)
C:\\Users\\Peter\\Desktop\\Sa-MP\\gamemodes\\mysql.pwn(72) : error 029: invalid expression, assumed zero
C:\\Users\\Peter\\Desktop\\Sa-MP\\gamemodes\\mysql.pwn(72) : warning 215: expression has no effect
C:\\Users\\Peter\\Desktop\\Sa-MP\\gamemodes\\mysql.pwn(72) : error 029: invalid expression, assumed zero
C:\\Users\\Peter\\Desktop\\Sa-MP\\gamemodes\\mysql.pwn(72) : warning 215: expression has no effect
C:\\Users\\Peter\\Desktop\\Sa-MP\\gamemodes\\mysql.pwn(72) : error 029: invalid expression, assumed zero
C:\\Users\\Peter\\Desktop\\Sa-MP\\gamemodes\\mysql.pwn(72) : fatal error 107: too many error messages on one line
Compilation aborted.Pawn compiler 3.2.3664           Copyright (c) 1997-2006, ITB CompuPhase
 
4 Errors.
« Utoljára szerkesztve: 2012. December 25. - 13:34:50 írta cserko93 »

MYSQL, Login-Register cucc
« Válasz #1 Dátum: 2012. December 25. - 13:14:36 »
0 Show voters
72-es sorral van problema please ragd a rendszert pawn kodeba mert a sima
 elotag nem szamlalja a sorokat

 
Sor:
   mysql_query(stringsize, SQL_SAVE_ACCOUNT, playerid, RegistrationSystemConnection);

 

de ennek nem a mysql el van baja hanem valami mással
Bisztos vagy benne hogy nem mysql el van baj?
[/quote]
« Utoljára szerkesztve: 2012. December 25. - 13:36:35 írta [SDW]BlackJack »

MYSQL, Login-Register cucc
« Válasz #2 Dátum: 2012. December 25. - 13:33:55 »
0 Show voters
Eddig rá jöttem én is, hogy a 72-es sorral van baja. De nem tudom mi! Hogy érted, hogy rakjam PAWN-oba?:D
E: rájöttem beraktam pawno kódba!:D
« Utoljára szerkesztve: 2012. December 25. - 13:36:46 írta cserko93 »

MYSQL, Login-Register cucc
« Válasz #3 Dátum: 2012. December 25. - 13:39:37 »
0 Show voters
Latom,dolgozok a soron de meg semmi fejlemeny ki probaltam maskepp kiadott 3 errort  :confused:
Fel adom sajnalom nem tudok mit tenni egyre tobb errort add ide Gabor kell :)
« Utoljára szerkesztve: 2012. December 25. - 13:43:03 írta [SDW]BlackJack »

MYSQL, Login-Register cucc
« Válasz #4 Dátum: 2012. December 25. - 13:49:07 »
0 Show voters
Gábor gyere!! SEGÍTS RAJTam/unk!!:D

Nem elérhető Gabor..

  • 1883
  • Gabor..
    • Profil megtekintése
MYSQL, Login-Register cucc
« Válasz #5 Dátum: 2012. December 25. - 15:58:29 »
0 Show voters
Véletlen pont ebbe a témába keveredtem. :D
Nálam csak sorteltolódásokat jelzett a pawno, de próbáld meg így:
 
mysql_query( stringsize );

MYSQL, Login-Register cucc
« Válasz #6 Dátum: 2012. December 25. - 16:22:55 »
0 Show voters
ugyan az..

 

SimplePortal 2.3.7 © 2008-2024, SimplePortal