Jump to content
  • 0

Problema Register/Login Help!!!!!!!!!!!!!


SkyLeAs

Question

Problema intalnita (descriere):Mam apucat sa fac un server dela 0 si am inceput prin sistemul de register login facut de WID lam bagat in gm iam fkt baza de date tot lam modificat iam facut down la mysql r34 ca pe asta imi place sa-l folosesc. Intru pe server sa testez daca salveaza conturile si nu imi apare nimic nu apare dialogul cu register deloc.. Nu stiu ce sa-i mai fac.. Ero(area / rile) / warning-(ul / urile):Nici o eroare. Liniile de cod / sursa / script-ul(obligatoriu): Mai jos aveti si gm-ul si ce am facut in baza de date

#if defined Header
|++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++|
|------------------------------------------------------------------------------|
|        Romania eXtreme Stunt | V1 |  15/09/2015                              |
|------------------------------------------------------------------------------|
|	     by JohnnyYz ([email protected]). All rights reserverd. (c)            |
|------------------------------------------------------------------------------|
|++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++|
#endif
//******************************************************************************
#include												 " a_samp   "
#include 												 " a_mysql  "
#include 												 " dini     "
#include 												 " foreach  "
#include 												 " sscanf2  "
#include 												 " zcmd     "
//******************************************************************************
#define SERVER_HOST										"localhost"
#define SERVER_USER										"zp_rxs2015"
#define SERVER_PASS										"zp_rxs2015"
#define SERVER_DB										"zp_rxs2015"
//******************************************************************************
enum
{
    DIALOG_LOGIN,
    DIALOG_REGISTER
};
//******************************************************************************
enum pInfo
{
    pParola,
    pID
};
//******************************************************************************
new handle;
new P_Data[MAX_PLAYERS][pInfo];
//******************************************************************************
main()
{
	print("\n----------------------------------");
	print("  	RXS - Loading\n");
	print("----------------------------------\n");
}
//******************************************************************************
public OnPlayerConnect(playerid)
{
    new query[100];
    new rows, fields;
    mysql_format(handle, query, sizeof(query), "SELECT * FROM Players WHERE Name = '%s'", GetName(playerid));
    cache_get_data(rows, fields);
    if(rows)
    {
        ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Logheaza-te!", "Te rog sa-ti introduci parola contuului mai jos!", "Logare", "Exit");
    }
    else
    {
        ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Inregistrare", "Trebuie sa iti creezi un cont ca sa joci pe server. nTasteaza mai jos o parola, pentru a te inregistra!", "Inregistreaza", "Exit");
    }
	return 1;
}
//******************************************************************************
public OnPlayerCommandText(playerid, cmdtext[])
{
	new idx;
	new cmd[256];
	
	cmd = strtok(cmdtext, idx);

	if(strcmp(cmd, "/yadayada", true) == 0) {
    	return 1;
	}

	return 0;
}
//******************************************************************************
public OnPlayerSpawn(playerid)
{
	SetPlayerInterior(playerid,0);
	TogglePlayerClock(playerid,0);
	return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
   	return 1;
}
//******************************************************************************
SetupPlayerForClassSelection(playerid)
{
 	SetPlayerInterior(playerid,14);
	SetPlayerPos(playerid,258.4893,-41.4008,1002.0234);
	SetPlayerFacingAngle(playerid, 270.0);
	SetPlayerCameraPos(playerid,256.0815,-43.0475,1004.0234);
	SetPlayerCameraLookAt(playerid,258.4893,-41.4008,1002.0234);
}
//******************************************************************************
public OnPlayerRequestClass(playerid, classid)
{
	SetupPlayerForClassSelection(playerid);
	return 1;
}
//******************************************************************************
public OnGameModeInit()
{
	SetGameModeText("Bare Script"); ShowPlayerMarkers(1); ShowNameTags(1);
	AllowAdminTeleport(1);
	//--------------------------------------------------------------------------
	MySQLConnect();
	//--------------------------------------------------------------------------
	AddPlayerClass(265,1958.3783,1343.1572,15.3746,270.1425,0,0,0,0,-1,-1);
	//--------------------------------------------------------------------------

	return 1;
}
//******************************************************************************
public OnGameModeExit()
{
    mysql_close( handle ) ;
    return 1;
}
//******************************************************************************
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    new query[128], ip[25];
    switch(dialogid)
    {
        case DIALOG_REGISTER:
        {
            if(!response)
                    return Kick(playerid);
            if(response)
            {
                if(!strlen(inputtext))
                        return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "Parola incorecta!", "Introdu-ti o parola pentru a te inregistra pe server! n", "Inregistreaza", "Exit");
                GetPlayerIp(playerid, ip, sizeof(ip));
                mysql_format(handle, query, sizeof(query), "INSERT INTO Players (Name, Password, IP) VALUES ('%s', '%e', '%s')", GetName(playerid), inputtext, ip);
                mysql_query(handle, query);
                SpawnPlayer(playerid);
            }
            return 1;
        }
        case DIALOG_LOGIN:
        {
            if(!response) return Kick(playerid);
            if(response)
            {
                if(!strlen(inputtext))
                        return ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Parola incorecta!", "Te rog sa iti introduci parola corecta, pentru a te loga pe server.", "Logare", "Exit");
                mysql_format(handle, query, sizeof(query), "SELECT * FROM `Players` WHERE `Name`='%e' AND `Passowrd` = '%e'", GetName(playerid),inputtext);
				mysql_tquery(handle, query, "OnLogin", "i", playerid);
            }
            return 1;
        }
    }
    return 1;
}
//******************************************************************************
forward OnLogin(playerid);
public OnLogin(playerid)
{
    new rows, fields,temporar[200];
    cache_get_data(rows, fields);
    if(rows)
    {
        //deci daca are randuri
        P_Data[playerid][pParola] = cache_get_field_content(0, "Passowrd",temporar);
        P_Data[playerid][pID] = cache_get_field_content_int(0, "ID");

        SpawnPlayer(playerid);
    }
    else
    {
        ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Parola incorecta!", "Te rog sa iti introduci parola corecta, pentru a te loga pe server.", "Logare", "Exit");
    }
    return 1;
}
//******************************************************************************
forward MySQLConnect();
//SERVER_HOST SERVER_USER SERVER_PASS SERVER_DB
public MySQLConnect()
{
    handle = mysql_connect(SERVER_HOST, SERVER_USER, SERVER_PASS, SERVER_DB);
    if(mysql_errno() != 0)
    {
        printf("Conexiunea la baza de date %s a esuat ---> Server Inchis ~~~", SERVER_DB);
        SendRconCommand("exit");
    }
    else
    {
        printf("Conexiunea la baza de date '%s' cu user-ul '%s' a reusit!!!", SERVER_DB, SERVER_USER);
    }
    return 1;
}
//******************************************************************************
//******************************************************************************
stock GetName(playerid)
{
	new Name[MAX_PLAYER_NAME];

	GetPlayerName(playerid, Name, sizeof(Name));
	return Name;
}
//******************************************************************************
strtok(const string[], &index)
{
	new length = strlen(string);
	while ((index < length) && (string[index] <= ' '))
	{
		index++;
	}

	new offset = index;
	new result[20];
	while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
	{
		result[index - offset] = string[index];
		index++;
	}
	result[index - offset] = EOS;
	return result;
}
-- phpMyAdmin SQL Dump
-- version 3.3.9
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Sep 15, 2015 at 02:37 PM
-- Server version: 5.5.8
-- PHP Version: 5.3.5

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";


/*!40101 SET @[email protected]@CHARACTER_SET_CLIENT */;
/*!40101 SET @[email protected]@CHARACTER_SET_RESULTS */;
/*!40101 SET @[email protected]@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

--
-- Database: `zp_rxs2015`
--

-- --------------------------------------------------------

--
-- Table structure for table `players`
--

CREATE TABLE IF NOT EXISTS `players` (
  `ID` int(10) NOT NULL AUTO_INCREMENT,
  `Name` varchar(25) NOT NULL,
  `Password` varchar(25) NOT NULL,
  `IP` varchar(16) NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

--
-- Dumping data for table `players`
--

Imagini / Video (optional):N/a
Ati incercat sa rezolvati singur?:Da am incercat si nimic...
Help...!!!!!!!!!
Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0

Ai facut o mica greseala cand te-ai inspirat din tutorialul lui WiDuAlK.

Dupa

mysql_format(handle, query, sizeof(query), "SELECT * FROM Players WHERE Name = '%s'", GetName(playerid));

pui

mysql_tquery(handle, query, "VerifyAccount", "d", playerid);

 

Apoi creezi un public

forward VerifyAccount(playerid);
public VerifyAccount(playerid)
{
    new rows, fields;
    cache_get_data(rows, fields, handle);
    if(rows)
    {
        ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Logheaza-te!", "Te rog sa-ti introduci parola contuului mai jos!", "Logare", "Exit");
    }
    else
    {
        ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Inregistrare", "Trebuie sa iti creezi un cont ca sa joci pe server. nTasteaza mai jos o parola, pentru a te inregistra!", "Inregistreaza", "Exit");
    }
    return 1;
}

 

Edited by KnowN

Singura modalitate prin care ma puteti contacta:

http://steamcommunity.com/id/known_main

Link to comment
Share on other sites

  • 0
  • 0
new query[100];
    new rows, fields;
    mysql_format(handle, query, sizeof(query), "SELECT * FROM Players WHERE Name = '%s'", GetName(playerid));
    cache_get_data(rows, fields);

Inainte sa copiezi codurile incearca sa le verifici.

Transforma OnPlayerConnect in asta

	new query[100];
	mysql_format(aHandle, query, sizeof(query), "SELECT * FROM accounts WHERE Name = '%s'", GetName(playerid));
	mysql_tquery(aHandle, query, "OnPlayerLogin", "i", playerid);

si faci un callback corespunzator

forward OnPlayerLogin(playerid);
public OnPlayerLogin(playerid)
{
	new rows, fields;
	cache_get_data(rows, fields);
	if(rows)
	{
	    ShowPlayerDialog(playerid, logindialog, DIALOG_STYLE_PASSWORD, "Logheaza-te!", "Te rog sa-ti introduci parola contului mai jos!", "Logare", "Exit");
	}
	else
	{
	    ShowPlayerDialog(playerid, registerdialog, DIALOG_STYLE_INPUT, "Inregistrare", "Trebuie sa iti creezi un cont ca sa joci pe server.\nTasteaza mai jos o parola, pentru a te inregistra!", "Inregistreaza", "Exit");
	}
	return 1;
}

Sau

public OnPlayerConnect(playerid)
{
    new query[100];
    new rows, fields;
    mysql_format(handle, query, sizeof(query), "SELECT * FROM Players WHERE Name = '%s'", GetName(playerid));
    mysql_query(handle, query);
    cache_get_data(rows, fields);
    if(rows)
    {
        ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Logheaza-te!", "Te rog sa-ti introduci parola contuului mai jos!", "Logare", "Exit");
    }
    else
    {
        ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Inregistrare", "Trebuie sa iti creezi un cont ca sa joci pe server. nTasteaza mai jos o parola, pentru a te inregistra!", "Inregistreaza", "Exit");
    }
	return 1;
}

P.S: Daca iti transformi OnPlayerConnect, schimba variabilele pentru ca ti-am dat din scriptul meu si nu am stat sa schimb.

Edited by cristyifrim
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. For more details you can also review our Terms of Use and Privacy Policy.