SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Filterscripts

Reply
 
Thread Tools Display Modes
Old 11/09/2012, 03:03 PM   #1
marquezsanchez
Little Clucker
 
marquezsanchez's Avatar
 
Join Date: Jun 2012
Posts: 46
Reputation: 1
Default Registration/Login System

hello I have developed a small system for Registration/Login , I have used mysql to save account and plugin "regex"

table mysql :
Code:
/*
MySQL Data Transfer
Source Host: localhost
Source Database: rp_ls
Target Host: localhost
Target Database: rp_ls
Date: 2012-09-11 11:09:07
*/

SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for accounts
-- ----------------------------
CREATE TABLE `accounts` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(26) NOT NULL,
  `password` varchar(26) NOT NULL,
  `skin` smallint(5) unsigned NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records 
-- ----------------------------
INSERT INTO `accounts` VALUES ('1', 'Karim_Squalli', '123456as', '4');
pawn Code:
#include <a_samp>
#include <regex>
#include <a_mysql>

#define     COLOR_RED               10

#define     MYSQL_HOST              "localhost"
#define     MYSQL_USER              "root"
#define     MYSQL_PASS              ""
#define     MYSQL_DB                "rp_ls"

#define     DIALOG_LOGIN            0
#define     DIALOG_REGISTER         1


#define     DIALOG_LOGIN_CAP        "Login Menu"
#define     DIALOG_LOGIN_CONTENT    "Hello, please insert your password :"
#define     DIALOG_REGISTER_CAP     "Registration Menu"
#define     DIALOG_REGISTER_CONTENT "hi, your are new player.\n For register please insert your password"


forward IsValidRpName(playerName[]);
forward KickPlayer(playerid);

forward CheckPlayerRegistration(playerid);
forward LoadPlayerData(playerid);

enum E_PLAYER_DATA
{
    pName[MAX_PLAYER_NAME],
    pSkin,
}

new gConnection;
new gPlayerData[MAX_PLAYERS][E_PLAYER_DATA];
public OnFilterScriptInit()
{
    gConnection = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_DB, MYSQL_PASS);
    print("\n--------------------------------------");
    print(" ****** AccountSystem -- By SqualliKarim  *****");
    print("--------------------------------------\n");
    return 1;
}

public OnPlayerConnect(playerid)
{
    new playerName[MAX_PLAYER_NAME];
    GetPlayerName(playerid, playerName, MAX_PLAYER_NAME);

    if(!IsValidRpName(playerName))
        SetTimerEx("KickPlayer", 1000, false, "%i", playerid);

    new escapedQuery[256];
    mysql_format(gConnection, escapedQuery, "SELECT * FROM accounts WHERE name = '%s'", playerName);
    mysql_function_query(gConnection, escapedQuery, true, "CheckPlayerRegistration", "i", playerid);
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch(dialogid)
    {
        case DIALOG_LOGIN :
        {
            if(!response) return Kick(playerid);
            new escapedQuery[256];
            mysql_format(gConnection, escapedQuery, "SELECT * FROM accounts WHERE name = '%s' AND password = '%e'",
                        GetPlayerNameEx(playerid), inputtext);
            mysql_function_query(gConnection, escapedQuery, true, "LoadPlayerData", "i", playerid);
        }
       
        case DIALOG_REGISTER :
        {
            if(!response) return Kick(playerid);
            if( strlen(inputtext) > 6 && strlen(inputtext) < 26 )
            {
                new escapedQuery[256];
                mysql_format(gConnection, escapedQuery, "INSERT INTO accounts(name, password, skin) VALUES('%s', '%e', '%i')",
                            GetPlayerNameEx(playerid), inputtext, random(300));
                mysql_function_query(gConnection, escapedQuery, false, "", "");
            }
            else
            {
                SendClientMessage(playerid, COLOR_RED, "please tip a password betwen 6 and 26 caractére");
                ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, DIALOG_REGISTER_CAP, DIALOG_REGISTER_CONTENT, "Accept", "Cancel");
            }
        }
    }
    return 1;
}

public CheckPlayerRegistration(playerid)
{
    new rows, fields;
    cache_get_data(rows, fields);
    printf("%i, %i", rows, fields);
    if(rows) ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, DIALOG_LOGIN_CAP, DIALOG_LOGIN_CONTENT, "Login", "Cancel");
    else ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, DIALOG_REGISTER_CAP, DIALOG_REGISTER_CONTENT, "Accept", "Cancel");
}

public LoadPlayerData(playerid)
{
    new rows, fields;
    cache_get_data(rows, fields);
    if(rows)
    {
        new temp[256];
        gPlayerData[playerid][pName] = GetPlayerNameEx(playerid);
        cache_get_field_content(0, "skin", temp); gPlayerData[playerid][pSkin] = strval(temp);
            DeletePVar(playerid, "ATTEMPS");
    }
    else
    {
        new str[128];
        SetPVarInt(playerid, "ATTEMPS", GetPVarInt(playerid, "ATTEMPS") +1);
        format(str, sizeof(str), "Attempts remaining : %i", 3 - GetPVarInt(playerid, "ATTEMPS"));
        SendClientMessage(playerid, COLOR_RED, str);
        ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, DIALOG_LOGIN_CAP, DIALOG_LOGIN_CONTENT, "Login", "Cancel");
        if(GetPVarInt(playerid, "ATTEMPS") == 3)
        {
            SendClientMessage(playerid, COLOR_RED, "you have been kicked");
            SendClientMessage(playerid, COLOR_RED, "Reason : Attemps Connection Remain");
            Kick(playerid);
        }
    }
}

public IsValidRpName(playerName[])
{
    if( regex_match(playerName, "^[A-Z]{1}[a-z]{2,8}_[A-Z]{1}[a-z]{2,8}")) return 1;
    return 0;
}

public KickPlayer(playerid)
{
    Kick(playerid);
}

stock GetPlayerNameEx(playerid)
{
    new playerName[MAX_PLAYER_NAME];
    GetPlayerName(playerid, playerName, MAX_PLAYER_NAME);
    return playerName;
}
__________________
Sorry For my bad english.
marquezsanchez is offline   Reply With Quote
Old 11/09/2012, 03:06 PM   #2
Lordzy
High-roller
 
Join Date: Mar 2012
Location: NetherRealm
Posts: 2,371
Reputation: 759
Default Re: Registration/Login System

Not bad.
__________________

Looking for affordable VPS with DDOS protection? Check out blackbirdhost.com
Interested on building something with me? Click here.
Lordzy is offline   Reply With Quote
Old 11/09/2012, 03:10 PM   #3
Glint
Guest
 
Posts: n/a
Default Re: Registration/Login System

Why are you using [php] tags why don't you just use [pawn] ?
  Reply With Quote
Old 11/09/2012, 03:12 PM   #4
DeadLy™
Gangsta
 
DeadLy™'s Avatar
 
Join Date: May 2012
Location: New Delhi,India
Posts: 502
Reputation: 102
Default Re: Registration/Login System

Umm, Average 2.5/10
__________________
LEFT
DeadLy™ is offline   Reply With Quote
Old 11/09/2012, 05:02 PM   #5
marquezsanchez
Little Clucker
 
marquezsanchez's Avatar
 
Join Date: Jun 2012
Posts: 46
Reputation: 1
Default Re: Registration/Login System

its a simple registration/login with dialog.
__________________
Sorry For my bad english.
marquezsanchez is offline   Reply With Quote
Old 11/09/2012, 05:31 PM   #6
Qu3esL
Big Clucker
 
Qu3esL's Avatar
 
Join Date: Sep 2012
Location: India, Chandigarh
Posts: 137
Reputation: 7
Default Re: Registration/Login System

Not Bad
__________________
MY RELEASES
[Filterscript] Qbank System (v2)
[Gamemode] Zombie Outbreak
_________________
(C) Copyright 2012 - Qu3esL - India
Skype: ghost-group
Proud COD5 Member - [COD5]Qu3esL - Since 2 years
Qu3esL is offline   Reply With Quote
Old 11/09/2012, 11:35 PM   #7
Mark Shade
Huge Clucker
 
Mark Shade's Avatar
 
Join Date: Mar 2012
Posts: 282
Reputation: 67
Default Re: Registration/Login System

Wrong section bro - http://forum.sa-mp.com/showthread.php?t=281
__________________
Universal Roleplay: 178.33.211.228:7787 -- Click To Play!
Mark Shade is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Help] Auto login + Registration system mickos Scripting Help 0 20/08/2012 01:31 PM
Need help with my registration + login system mickos Scripting Help 6 07/08/2012 08:40 PM
Problem with Registration + (auto)Login system mickos Scripting Help 12 05/08/2012 12:13 PM
I need help with a registration/login system. omgkillerzambies Help Archive 9 24/06/2011 05:12 AM
Login & Registration system wrong [SWE]Alexzz Help Archive 4 25/03/2011 09:29 PM


All times are GMT. The time now is 04:39 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.