vendredi 15 juillet 2016

[FilterScript] Register & log-in system using jsql.inc

) which is made to simplify mysql.

This is just an example and/or a way you could start a register & log-in system using mysql through jsql.inc. Explaining the code is not really necessary as it's pretty clear and obvious and jsql.inc is already explained in it's own thread.

As this is just an example, this system doesn't just identify user, but saves and loads the very basic things like money and score.

Code:

#include "a_samp.inc"
#include "jsql.inc"

#define MYSQL_HOST          "yourhost"
#define MYSQL_USER          "yourusername"
#define MYSQL_DATABASE      "yourdatabasse"
#define MYSQL_PASSWORD      "yourpassword"

#define DIALOG_LOGIN        1
#define DIALOG_REGISTER     2

new Playername[MAX_PLAYER_NAME];

main()
{

}

stock Name(playerid)
{
   GetPlayerName(playerid, Playername, sizeof(Playername));
   return Playername;
}

public OnGameModeInit()
{
   jsql_Connect(MYSQL_HOST, MYSQL_USER, MYSQL_DATABASE, MYSQL_PASSWORD);

   return 1;
}

public OnGameModeExit()
{
   return 1;
}

public OnPlayerConnect(playerid)
{
   if(jsql_Exists("Users", "Name", Name(playerid)))
   {
   ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Log-in", "Enter the correct password to log-in:", "Log-in", "Quit");
   }
   else ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "Register", "Enter the password to register:", "Register", "Quit");

   return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
   jsql_SetInt("Users", "Name", Name(playerid), "Money", GetPlayerMoney(playerid));
   jsql_SetInt("Users", "Name", Name(playerid), "Score", GetPlayerScore(playerid));

   return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
  if(dialogid == DIALOG_LOGIN)
  {
      if(!response) Kick(playerid);
        
      if(response)
      {
         if(strcmp(jsql_GetString("Users", "Name", Name(playerid), "Password"), inputtext)) return ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Log-in", "{FF0000}Invalid password.\n\n{FFFFFF}Enter the valid password to log-in:", "Log-in", "Quit");
                        
         GivePlayerMoney(playerid, jsql_GetInt("Users", "Name", Name(playerid), "Money"));
         SetPlayerScore(playerid, jsql_GetInt("Users", "Name", Name(playerid), "Score"));
                        
         SendClientMessage(playerid, -1, "You've successfully logged-in.");
      }
        
   return 1;
   }
    
   if(dialogid == DIALOG_REGISTER)
   {
       if(!response) Kick(playerid);

       if(response)
       {
           if(strlen(inputtext) < 3) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "Register", "{FF0000}Password must be at least 3 characters long.\n\n{FFFFFF}Enter the password to register:", "Register", "Quit");

           new fields[50];
           new values[20];
                            
           format(fields, sizeof(fields), "`Name`, `Password`, `Money`, `Score`");
           format(values, sizeof(values), "'%s', '%s', %i, %i", Name(playerid), inputtext, 0, 0);
                        
           jsql_Add("Users", fields, values);
                                
           SendClientMessage(playerid, -1, "You've successfully registered.");
       }

   return 1;
   }

   return 0;
}

This entry passed through the Full-Text RSS service - if this is your content and you're reading it on someone else's site, please read the FAQ at http://ift.tt/jcXqJW.
Recommended article from FiveFilters.org: Most Labour MPs in the UK Are Revolting.



[FilterScript] Register & log-in system using jsql.inc

Aucun commentaire:

Enregistrer un commentaire