key system mysql
#1

I would like to know how to create a system key in mysql, the administrator type / createkey when he type the command creates a key in the database.

Example: FD6D2-5DAX3-89RKX-X6S6C-5DS3X
Reply
#2

i will help you in making it wait some minutes
Edit : you need to generate a key randomaly ? or he will type a key and the key will be hashed ?
Reply
#3

If you want to generate a random key, take a look at this
https://sampforum.blast.hk/showthread.php?tid=319854
Reply
#4

Quote:
Originally Posted by Eoussama
Посмотреть сообщение
If you want to generate a random key, take a look at this
https://sampforum.blast.hk/showthread.php?tid=319854
Oussema, i wanna ask you a question : how to generate a random string ?
Reply
#5

https://sampforum.blast.hk/showthread.php?tid=276913
Reply
#6

Quote:
Originally Posted by Eoussama
Посмотреть сообщение
If you want to generate a random key, take a look at this
https://sampforum.blast.hk/showthread.php?tid=319854
How do I do this?
kind

PHP код:
CMDnewkey (playerid)
{
GeneratePassword();
SendClientMessage (playerid, -1"new key generate (AVBSADAS-5SAD5A-JOAOSDI-FSDJ322)");
Return 
1;

And saved to the database mysql
Reply
#7

Here is what you want

Код:
COMMAND:activekeys(playerid, params[])
{
	new Cache:result = mysql_query(g_SQL, "SELECT `key`, `score`, `money` FROM keys");
	if(cache_num_rows())
	{
    	new dialog_msg[256], key[25], score, money;
  		format(dialog_msg, sizeof  dialog_msg, "");
		format(dialog_msg, sizeof dialog_msg, "#\tKey\tScore\tMoney\n");
		for(new i = 0; i != cache_num_rows(); i++)
		{
		    cache_get_value_name(i, "key", key, 25);
			cache_get_value_name_int(i, "score", score);
			cache_get_value_name_int(i, "money", money);
			format(dialog_msg, sizeof dialog_msg, "%s%d\t%s\t%d\t%d\n", dialog_msg, i+1, key, score, money);
		}
		ShowPlayerDialog(playerid, 1234, DIALOG_STYLE_TABLIST_HEADERS, "Active Keys", dialog_msg, "Close", "");
	}
	cache_delete(result);
    return 1;
}

COMMAND:addkey(playerid, params[])
{
	new score, money, key[25];
	if(sscanf(params, "dds[25]", score, money, key))
	    return SendClientMessage(playerid, -1, "/addkey <score> <money> <key>");

	format(query, sizeof(query), "INSERT INTO `keys` (key, score, money) VALUES ('%s', %d, %d)", key, score, money);
	mysql_tquery(g_SQL, query);
    return 1;
}

COMMAND:key(playerid, params[])
{
	ShowPlayerDialog(playerid, 1235, DIALOG_STYLE_INPUT, "Input Key", "Enter the what you got", "Okay", "Close");
	return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch(dialogid)
    {
		case 1235:
        {
            new keytxt[256];
  		    mysql_escape_string(inputtext, keytxt);
  		    
			format(query, sizeof(query), "SELECT * FROM `keys` WHERE `key` = '%s'", keytxt);
			new Cache:result = mysql_query(g_SQL, query);
			
			if(cache_num_rows())
			{
				new key_id, score, money;
		  		cache_get_value_int(0, "id", key_id);
		    	cache_get_value_int(0, "score", score);
				cache_get_value_int(0, "money", money);

				GivePlayerMoney(playerid, money);
				GivePlayerScore(playerid, score);

				mysql_format(g_SQL, query, sizeof(query), "DELETE FROM `keys` WHERE `id` = %d", key_id);
				mysql_tquery(g_SQL, query);
		    }
		    else
			{
				SendClientMessage(playerid, -1, "It is used");
		    }

		    cache_delete(result);
			return 1;
		}
	}
	
	return 1;
}

CREATE TABLE `keys` (
  `id` int(3) NOT NULL auto_increment,
  `key` varchar(25) NOT NULL,
  `score` mediumint(6) NOT NULL,
  `money` int(11) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
Reply
#8

Quote:
Originally Posted by Freedom.
Посмотреть сообщение
Here is what you want

Код:
COMMAND:activekeys(playerid, params[])
{
	new Cache:result = mysql_query(g_SQL, "SELECT `key`, `score`, `money` FROM keys");
	if(cache_num_rows())
	{
    	new dialog_msg[256], key[25], score, money;
  		format(dialog_msg, sizeof  dialog_msg, "");
		format(dialog_msg, sizeof dialog_msg, "#\tKey\tScore\tMoney\n");
		for(new i = 0; i != cache_num_rows(); i++)
		{
		    cache_get_value_name(i, "key", key, 25);
			cache_get_value_name_int(i, "score", score);
			cache_get_value_name_int(i, "money", money);
			format(dialog_msg, sizeof dialog_msg, "%s%d\t%s\t%d\t%d\n", dialog_msg, i+1, key, score, money);
		}
		ShowPlayerDialog(playerid, 1234, DIALOG_STYLE_TABLIST_HEADERS, "Active Keys", dialog_msg, "Close", "");
	}
	cache_delete(result);
    return 1;
}

COMMAND:addkey(playerid, params[])
{
	new score, money, key[25];
	if(sscanf(params, "dds[25]", score, money, key))
	    return SendClientMessage(playerid, -1, "/addkey <score> <money> <key>");

	format(query, sizeof(query), "INSERT INTO `keys` (key, score, money) VALUES ('%s', %d, %d)", key, score, money);
	mysql_tquery(g_SQL, query);
    return 1;
}

COMMAND:key(playerid, params[])
{
	ShowPlayerDialog(playerid, 1235, DIALOG_STYLE_INPUT, "Input Key", "Enter the what you got", "Okay", "Close");
	return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch(dialogid)
    {
		case 1235:
        {
            new keytxt[256];
  		    mysql_escape_string(inputtext, keytxt);
  		    
			format(query, sizeof(query), "SELECT * FROM `keys` WHERE `key` = '%s'", keytxt);
			new Cache:result = mysql_query(g_SQL, query);
			
			if(cache_num_rows())
			{
				new key_id, score, money;
		  		cache_get_value_int(0, "id", key_id);
		    	cache_get_value_int(0, "score", score);
				cache_get_value_int(0, "money", money);

				GivePlayerMoney(playerid, money);
				GivePlayerScore(playerid, score);

				mysql_format(g_SQL, query, sizeof(query), "DELETE FROM `keys` WHERE `id` = %d", key_id);
				mysql_tquery(g_SQL, query);
		    }
		    else
			{
				SendClientMessage(playerid, -1, "It is used");
		    }

		    cache_delete(result);
			return 1;
		}
	}
	
	return 1;
}

CREATE TABLE `keys` (
  `id` int(3) NOT NULL auto_increment,
  `key` varchar(25) NOT NULL,
  `score` mediumint(6) NOT NULL,
  `money` int(11) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
How do I generate the key so automatically?

Код:
DBE19-CACCB-ACC3D-F75AD-F5288
The add key command does not work.

i'm using mysql r39-6
Код:
COMMAND:addkey(playerid, params[])
{
	new score, money, key[25], query[128];
	if(sscanf(params, "dds[25]", score, money, key))
	    return SendClientMessage(playerid, -1, "/addkey <score> <money> <key>");

	format(query, sizeof(query), "INSERT INTO `keys` (key, score, money) VALUES ('%s', %d, %d)", key, score, money);
	mysql_tquery(Conexao, query);
    return 1;
}
Reply
#9

Use latest version of MySQL. My example is from R41-2

There is a limitation on addkey command here:

Код:
COMMAND:addkey(playerid, params[])
{
	new score, money, key[25], query[128];
	if(sscanf(params, "dds[25]", score, money, key))
	    return SendClientMessage(playerid, -1, "/addkey <score> <money> <key>");

	format(query, sizeof(query), "INSERT INTO `keys` (key, score, money) VALUES ('%s', %d, %d)", key, score, money);
	mysql_tquery(Conexao, query);
    return 1;
}
Reply
#10

Quote:
Originally Posted by Freedom.
Посмотреть сообщение
Use latest version of MySQL. My example is from R41-2

There is a limitation on addkey command here:

Код:
COMMAND:addkey(playerid, params[])
{
	new score, money, key[25], query[128];
	if(sscanf(params, "dds[25]", score, money, key))
	    return SendClientMessage(playerid, -1, "/addkey <score> <money> <key>");

	format(query, sizeof(query), "INSERT INTO `keys` (key, score, money) VALUES ('%s', %d, %d)", key, score, money);
	mysql_tquery(Conexao, query);
    return 1;
}
I have tested these numbers [25] and yet it is not inserting

Код:
5565556565662566565656565
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)