Pastebin
API
tools
faq
paste
Login
Sign up
Please fix the following errors:
New Paste
Syntax Highlighting
#include <a_samp> #include <a_mysql> #include <foreach> #include <mSelection> #include <streamer> //Configuring MySQL Stuff to set up the connection #define MYSQL_HOST "localhost" // Change this to your MySQL Remote IP or "localhost". #define MYSQL_USER "root" // Change this to your MySQL Database username. #define MYSQL_PASS "password" // Change this to your MySQL Database password. #define MYSQL_DATABASE "san_andreas" // Change this to your MySQL Database name. // Well, don't just enter random information and expect it to work, information // Should be valid and working fine. #define DIALOG_REGISTER (0) #define DIALOG_LOGIN (1) // Make sure the dialog IDs above do not match any dialog ID you're using in your // gamemode otherwise they won't do their job properly. main( ) { } new MySQL: Database, Corrupt_Check[MAX_PLAYERS]; //Creating an enumerator to store player's data for further use (below). //============================================================================== enum ENUM_PLAYER_DATA { ID, Name[25], Password[65], Salt[11], PasswordFails, Kills, Deaths, pSkin, Score, Cash, Cache: Player_Cache, bool:LoggedIn } new pInfo[MAX_PLAYERS][ENUM_PLAYER_DATA]; new skinlist = mS_INVALID_LISTID; //============================================================================== //============================================================================== public OnGameModeInit() { skinlist = LoadModelSelectionMenu("skins.txt"); new MySQLOpt: option_id = mysql_init_options(); mysql_set_option(option_id, AUTO_RECONNECT, true); Database = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASS, MYSQL_DATABASE, option_id); if(Database == MYSQL_INVALID_HANDLE || mysql_errno(Database) != 0) { print("I couldn't connect to the MySQL server, closing."); SendRconCommand("exit"); return 1; } print("I have connected to the MySQL server."); // If the given MySQL details were all okay, this message prints to the log. mysql_tquery(Database, "CREATE TABLE IF NOT EXISTS `PLAYERS` (`ID` int(11) NOT NULL AUTO_INCREMENT,`USERNAME` varchar(24) NOT NULL,`PASSWORD` char(65) NOT NULL,`SALT` char(11) NOT NULL,`SCORE` mediumint(7), `KILLS` mediumint(7), `CASH` mediumint(7) NOT NULL DEFAULT '0',`DEATHS` mediumint(7) NOT NULL DEFAULT '0',`PSKIN` mediumint(7) NOT NULL DEFAULT '0', PRIMARY KEY (`ID`), UNIQUE KEY `USERNAME` (`USERNAME`))"); return 1; } public OnGameModeExit() { foreach(new i: Player) { if(IsPlayerConnected(i)) // Checking if the players stored in "i" are connected. { OnPlayerDisconnect(i, 1); // We do that so players wouldn't lose their data upon server's close. } } mysql_close(Database); // Closing the database. return 1; } public OnPlayerConnect(playerid) { new DB_Query[115]; //Resetting player information. pInfo[playerid][Kills] = 0; pInfo[playerid][Deaths] = 0; pInfo[playerid][PasswordFails] = 0; GetPlayerName(playerid, pInfo[playerid][Name], MAX_PLAYER_NAME); // Getting the player's name. Corrupt_Check[playerid]++; mysql_format(Database, DB_Query, sizeof(DB_Query), "SELECT * FROM `PLAYERS` WHERE `USERNAME` = '%e' LIMIT 1", pInfo[playerid][Name]); mysql_tquery(Database, DB_Query, "OnPlayerDataCheck", "ii", playerid, Corrupt_Check[playerid]); return 1; } public OnPlayerDisconnect(playerid, reason) { Corrupt_Check[playerid]++; new DB_Query[256]; //Running a query to save the player's data using the stored stuff. mysql_format(Database, DB_Query, sizeof(DB_Query), "UPDATE `PLAYERS` SET `SCORE` = %d, `CASH` = %d, `KILLS` = %d, `DEATHS` = %d WHERE `ID` = %d LIMIT 1", pInfo[playerid][Score], pInfo[playerid][Cash], pInfo[playerid][Kills], pInfo[playerid][Deaths], pInfo[playerid][ID]); mysql_tquery(Database, DB_Query); if(cache_is_valid(pInfo[playerid][Player_Cache])) //Checking if the player's cache ID is valid. { cache_delete(pInfo[playerid][Player_Cache]); // Deleting the cache. pInfo[playerid][Player_Cache] = MYSQL_INVALID_CACHE; // Setting the stored player Cache as invalid. } pInfo[playerid][LoggedIn] = false; print("OnPlayerDisconnect has been called."); // Sending message once OnPlayerDisconnect is called. return 1; } public OnPlayerSpawn(playerid) { SetPlayerSkin(playerid, pInfo[playerid][pSkin]); } public OnPlayerDeath(playerid, killerid, reason) { // Increase death if self-death or got killed! pInfo[playerid][Deaths]++; if(killerid != INVALID_PLAYER_ID) // Checking if the killer of the player is valid. { //Increasing the kills of the killer and the deaths of the player. pInfo[killerid][Kills]++; } return 1; } public OnPlayerRequestSpawn(playerid) { if(pInfo[playerid][LoggedIn] == false) return 0; // Ignoring the request incase player isn't logged in. return 1; } public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) { switch (dialogid) { case DIALOG_LOGIN: { if(!response) return Kick(playerid); new Salted_Key[65]; SHA256_PassHash(inputtext, pInfo[playerid][Salt], Salted_Key, 65); if(strcmp(Salted_Key, pInfo[playerid][Password]) == 0) { // Now, password should be correct as well as the strings // Matched with each other, so nothing is wrong until now. // We will activate the cache of player to make use of it e.g. // Retrieve their data. cache_set_active(pInfo[playerid][Player_Cache]); // Okay, we are retrieving the information now.. cache_get_value_int(0, "ID", pInfo[playerid][ID]); cache_get_value_int(0, "KILLS", pInfo[playerid][Kills]); cache_get_value_int(0, "DEATHS", pInfo[playerid][Deaths]); cache_get_value_int(0, "SCORE", pInfo[playerid][Score]); cache_get_value_int(0, "CASH", pInfo[playerid][Cash]); cache_get_value_int(0, "PSKIN", pInfo[playerid][Score]); SetPlayerScore(playerid, pInfo[playerid][Score]); ResetPlayerMoney(playerid); GivePlayerMoney(playerid, pInfo[playerid][Cash]); // So, we have successfully retrieved data? Now deactivating the cache. cache_delete(pInfo[playerid][Player_Cache]); pInfo[playerid][Player_Cache] = MYSQL_INVALID_CACHE; pInfo[playerid][LoggedIn] = true; SendClientMessage(playerid, 0x00FF00FF, "Logged in to the account."); } else { new String[150]; pInfo[playerid][PasswordFails] += 1; printf("%s has been failed to login. (%d)", pInfo[playerid][Name], pInfo[playerid][PasswordFails]); // Printing the message that someone has failed to login to his account. if (pInfo[playerid][PasswordFails] >= 3) // If the fails exceeded the limit we kick the player. { format(String, sizeof(String), "%s has been kicked Reason: {FF0000}(%d/3) Login fails.", pInfo[playerid][Name], pInfo[playerid][PasswordFails]); SendClientMessageToAll(0x969696FF, String); Kick(playerid); } else { // If the player didn't exceed the limits we send him a message that the password is wrong. format(String, sizeof(String), "Wrong password, you have %d out of 3 tries.", pInfo[playerid][PasswordFails]); SendClientMessage(playerid, 0xFF0000FF, String); format(String, sizeof(String), "{FFFFFF}Welcome back, %s.\n\n{0099FF}This account is already registered.\n\ {0099FF}Please, input your password below to proceed to the game.\n\n", pInfo[playerid][Name]); ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Login System", String, "Login", "Leave"); } } } case DIALOG_REGISTER: { if(!response) return Kick(playerid); if(strlen(inputtext) <= 5 || strlen(inputtext) > 60) { // If the password length is less than or equal to 5 and more than 60 // It repeats the process and shows error message as seen below. SendClientMessage(playerid, 0x969696FF, "Invalid password length, should be 5 - 60."); new String[150]; format(String, sizeof(String), "{FFFFFF}Welcome %s.\n\n{0099FF}This account is not registered.\n\ {0099FF}Please, input your password below to proceed.\n\n", pInfo[playerid][Name]); ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "Registration System", String, "Register", "Leave"); } else { // Salting the player's password using SHA256 for a better security. for (new i = 0; i < 10; i++) { pInfo[playerid][Salt][i] = random(79) + 47; } pInfo[playerid][Salt][10] = 0; SHA256_PassHash(inputtext, pInfo[playerid][Salt], pInfo[playerid][Password], 65); // Show Skin Selection SendClientMessage(playerid, 0x00FF00FF, "Please select a skin!"); ShowModelSelectionMenu(playerid, skinlist, "Pick A Skin"); } } } return 1; } forward OnPlayerDataCheck(playerid, corrupt_check); public OnPlayerDataCheck(playerid, corrupt_check) { if (corrupt_check != Corrupt_Check[playerid]) return Kick(playerid); // You'd have asked already what's corrput_check and how it'd benefit me? // Well basically MySQL query takes long, incase a player leaves while its not proceeded // With ID 1 for example, then another player comes as ID 1 it'll basically corrupt the data // So, once the query is done, the player will have the wrong data assigned for himself. new String[150]; if(cache_num_rows() > 0) { // If the player exists, everything is okay and nothing is wrongly detected // The player's password and Saltion key gets stored as seen below // So we won't have to get a headache just to match player's password. cache_get_value(0, "PASSWORD", pInfo[playerid][Password], 65); cache_get_value(0, "SALT", pInfo[playerid][Salt], 11); pInfo[playerid][Player_Cache] = cache_save(); // ^ Storing the cache ID of the player for further use later. format(String, sizeof(String), "{FFFFFF}Welcome back, %s.\n\n{0099FF}This account is already registered.\n\ {0099FF}Please, input your password below to proceed to the game.\n\n", pInfo[playerid][Name]); ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Login System", String, "Login", "Leave"); } else { format(String, sizeof(String), "{FFFFFF}Welcome %s.\n\n{0099FF}This account is not registered.\n\ {0099FF}Please, input your password below to proceed to the game.\n\n", pInfo[playerid][Name]); ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "Registration System", String, "Register", "Leave"); } return 1; } //============================================================================== forward OnPlayerRegister(playerid); public OnPlayerRegister(playerid) { // This gets called only when the player registers a new account. SendClientMessage(playerid, 0x00FF00FF, "You are now registered and has been logged in."); // Player Logged in! pInfo[playerid][LoggedIn] = true; //SetSpawnInfo(playerid, 0, , 2098.5088,1159.1156,11.6484, 65.2418, 0, 0, 0, 0, 0, 0 ); //SpawnPlayer(playerid); return 1; } public OnPlayerModelSelection(playerid, response, listid, modelid) { if(listid == skinlist) { if(response) { SetPlayerSkin(playerid, modelid); // set player skin pInfo[playerid][pSkin] = modelid; new DB_Query[225]; mysql_format(Database, DB_Query, sizeof(DB_Query), "INSERT INTO `PLAYERS` (`USERNAME`, `PASSWORD`, `SALT`, `SCORE`, `KILLS`, `CASH`, `DEATHS`, `PSKIN`)\ VALUES ('%e', '%s', '%e', '20', '0', '5000', '0', %d)", pInfo[playerid][Name], pInfo[playerid][Password], pInfo[playerid][Salt],pInfo[playerid][pSkin]); mysql_tquery(Database, DB_Query, "OnPlayerRegister", "d", playerid); } else if(!response && !pInfo[playerid][LoggedIn]) { SendClientMessage(playerid, 0x00FF00FF, "Please select a skin!"); ShowModelSelectionMenu(playerid, skinlist, "Pick A Skin"); } return 1; } return 1; } //============================================================================== // End of script //
Optional Paste Settings
Category:
None
Cryptocurrency
Cybersecurity
Fixit
Food
Gaming
Haiku
Help
History
Housing
Jokes
Legal
Money
Movies
Music
Pets
Photo
Science
Software
Source Code
Spirit
Sports
Travel
TV
Writing
Tags:
Syntax Highlighting:
None
Bash
C
C#
C++
CSS
HTML
JSON
Java
JavaScript
Lua
Markdown (PRO members only)
Objective C
PHP
Perl
Python
Ruby
Swift
4CS
6502 ACME Cross Assembler
6502 Kick Assembler
6502 TASM/64TASS
ABAP
AIMMS
ALGOL 68
APT Sources
ARM
ASM (NASM)
ASP
ActionScript
ActionScript 3
Ada
Apache Log
AppleScript
Arduino
Asymptote
AutoIt
Autohotkey
Avisynth
Awk
BASCOM AVR
BNF
BOO
Bash
Basic4GL
Batch
BibTeX
Blitz Basic
Blitz3D
BlitzMax
BrainFuck
C
C (WinAPI)
C Intermediate Language
C for Macs
C#
C++
C++ (WinAPI)
C++ (with Qt extensions)
C: Loadrunner
CAD DCL
CAD Lisp
CFDG
CMake
COBOL
CSS
Ceylon
ChaiScript
Chapel
Clojure
Clone C
Clone C++
CoffeeScript
ColdFusion
Cuesheet
D
DCL
DCPU-16
DCS
DIV
DOT
Dart
Delphi
Delphi Prism (Oxygene)
Diff
E
ECMAScript
EPC
Easytrieve
Eiffel
Email
Erlang
Euphoria
F#
FO Language
Falcon
Filemaker
Formula One
Fortran
FreeBasic
FreeSWITCH
GAMBAS
GDB
GDScript
Game Maker
Genero
Genie
GetText
Go
Godot GLSL
Groovy
GwBasic
HQ9 Plus
HTML
HTML 5
Haskell
Haxe
HicEst
IDL
INI file
INTERCAL
IO
ISPF Panel Definition
Icon
Inno Script
J
JCL
JSON
Java
Java 5
JavaScript
Julia
KSP (Kontakt Script)
KiXtart
Kotlin
LDIF
LLVM
LOL Code
LScript
Latex
Liberty BASIC
Linden Scripting
Lisp
Loco Basic
Logtalk
Lotus Formulas
Lotus Script
Lua
M68000 Assembler
MIX Assembler
MK-61/52
MPASM
MXML
MagikSF
Make
MapBasic
Markdown (PRO members only)
MatLab
Mercury
MetaPost
Modula 2
Modula 3
Motorola 68000 HiSoft Dev
MySQL
Nagios
NetRexx
Nginx
Nim
NullSoft Installer
OCaml
OCaml Brief
Oberon 2
Objeck Programming Langua
Objective C
Octave
Open Object Rexx
OpenBSD PACKET FILTER
OpenGL Shading
Openoffice BASIC
Oracle 11
Oracle 8
Oz
PARI/GP
PCRE
PHP
PHP Brief
PL/I
PL/SQL
POV-Ray
ParaSail
Pascal
Pawn
Per
Perl
Perl 6
Phix
Pic 16
Pike
Pixel Bender
PostScript
PostgreSQL
PowerBuilder
PowerShell
ProFTPd
Progress
Prolog
Properties
ProvideX
Puppet
PureBasic
PyCon
Python
Python for S60
QBasic
QML
R
RBScript
REBOL
REG
RPM Spec
Racket
Rails
Rexx
Robots
Roff Manpage
Ruby
Ruby Gnuplot
Rust
SAS
SCL
SPARK
SPARQL
SQF
SQL
SSH Config
Scala
Scheme
Scilab
SdlBasic
Smalltalk
Smarty
StandardML
StoneScript
SuperCollider
Swift
SystemVerilog
T-SQL
TCL
TeXgraph
Tera Term
TypeScript
TypoScript
UPC
Unicon
UnrealScript
Urbi
VB.NET
VBScript
VHDL
VIM
Vala
Vedit
VeriLog
Visual Pro Log
VisualBasic
VisualFoxPro
WHOIS
WhiteSpace
Winbatch
XBasic
XML
XPP
Xojo
Xorg Config
YAML
YARA
Z80 Assembler
ZXBasic
autoconf
jQuery
mIRC
newLISP
q/kdb+
thinBasic
Paste Expiration:
Never
Burn after read
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Paste Exposure:
Public
Unlisted
Private
Folder:
(members only)
Password
NEW
Enabled
Disabled
Burn after read
NEW
Paste Name / Title:
Create New Paste
Hello
Guest
Sign Up
or
Login
Sign in with Facebook
Sign in with Twitter
Sign in with Google
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Public Pastes
Stationeers - Sign Tags from Power Distributi...
HTML | 4 hours ago | 2.00 KB
PM: Shopify Client Edits
8 hours ago | 0.19 KB
PM: Shopify Assigning Design Task 2
8 hours ago | 0.14 KB
PM: Shopify Assigning Design Task 1
8 hours ago | 0.32 KB
Commodore Callback 8020
18 hours ago | 0.18 KB
JOIN ME HERE IN THIS MAGIC PLACE
23 hours ago | 0.07 KB
North - Levitation
1 day ago | 0.26 KB
North - Learning Magic
1 day ago | 1.09 KB
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the
Cookies Policy
.
OK, I Understand
Not a member of Pastebin yet?
Sign Up
, it unlocks many cool features!