Jump to content
  • 0

variable tied to MAC address (I am using Harmony)


Reducto

Question


  • Group:  Members
  • Topic Count:  75
  • Topics Per Day:  0.02
  • Content Count:  231
  • Reputation:   9
  • Joined:  12/16/11
  • Last Seen:  

I would like to request a script. I have harmony installer. Can you help me making this script. I want a npc that gives item. But, the npc can only give 1 char 1 account. How can I make a sql to check last_mac and last_ip of a player. So, that they cannot abuse the npc. Thanks!

Link to comment
Share on other sites

14 answers to this question

Recommended Posts


  • Group:  Members
  • Topic Count:  75
  • Topics Per Day:  0.02
  • Content Count:  2223
  • Reputation:   593
  • Joined:  10/26/11
  • Last Seen:  

Here you go : set_MAC_variable.txt

These script functions + SQL table allow you to store variables tied to MAC addresses.

  1. execute the SQL query at the top to create the `mac_reg_value` table
  2. replace all 3 occurrences of getmacaddress() with the Harmony script command that returns a player's MAC address (I was not sure what the Harmony script command was named.)
  3. the example script that gives an item once-per-MAC is lines 17-32

$#variable - permanent MAC variable

  • prefix "$#" means permanent MAC variable
  • name identifier consists of underscore and alphanumeric characters (just like other script variables)
  • postfix "$" means string variable
  • variable names are NOT case sensitive (just like other script variables)
  • variable name is limited to 255 characters
  • value is limited to 255 characters (for strings) or 32-bit signed integer (-2,147,483,648 to 2,147,483,647), just like other permanent script variables

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  75
  • Topics Per Day:  0.02
  • Content Count:  2223
  • Reputation:   593
  • Joined:  10/26/11
  • Last Seen:  

Does Harmony have a script command that returns the character's MAC address?

getmacaddress()

Or do we need to create a script command ?

Edited by Brian
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  75
  • Topics Per Day:  0.02
  • Content Count:  231
  • Reputation:   9
  • Joined:  12/16/11
  • Last Seen:  

What do you mean about this?

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  18
  • Topics Per Day:  0.00
  • Content Count:  2044
  • Reputation:   682
  • Joined:  10/09/12
  • Last Seen:  

that fix me! part, we can abuse SQL to calculate numbers above 2^31

select 123456789012345678901 > 123456789012345678900;

return 1

also, consider the fact a negative sign is also count as 1 string

2147xxxxxx is 10 strings

-2147xxxxxx is 11 strings

EDIT: seems you already know this because you used >11

EDIT2:

select 123456789012345678901 > 2147000000 OR 123456789012345678901 < -2147000000;
select 123 > 2147000000 OR 123 < -2147000000;

Edited by AnnieRuru
  • Upvote 1
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  75
  • Topics Per Day:  0.02
  • Content Count:  2223
  • Reputation:   593
  • Joined:  10/26/11
  • Last Seen:  

I wasn't sure how to precisely detect if they try to store an integer less than -2,147,483,648 or greater than 2,147,483,647.

When I did stuff like

set .@test, 2147483647;
npctalk ""+ .@test; // 2147483647

set .@a, 214748364700;
npctalk ""+ .@a; // 28

set .@b, 2147483647000;
npctalk ""+ .@b; // 24

I got 28 and 24. /hmm

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  18
  • Topics Per Day:  0.00
  • Content Count:  2044
  • Reputation:   682
  • Joined:  10/09/12
  • Last Seen:  

I just add new example in previous post

and weird

prontera,158,181,5	script	test int overflow	100,{
.@a = 2147483647;
npctalk ".@a = "+ .@a; // this is correct
.@b = 2147483648;
npctalk ".@b = "+ .@b; // return 0
.@c$ = "2147483648";
.@c = atoi( .@c$ );
npctalk ".@c = "+ .@c; // it says max int no matter how big numbers you have
}

post-8685-0-35707300-1351571774_thumb.jpg

map-server no give any error ... even all numbers above

Edited by AnnieRuru
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  75
  • Topics Per Day:  0.02
  • Content Count:  2223
  • Reputation:   593
  • Joined:  10/26/11
  • Last Seen:  

OH I see what you mean, use SQL to check if the value is bigger/smaller than 32-bit integer.

*fixes script*

Thanks Annie!

Edited by Brian
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  2
  • Topics Per Day:  0.00
  • Content Count:  6
  • Reputation:   0
  • Joined:  10/19/12
  • Last Seen:  

Hi Brian, sorry for reviving an old topic; I came across an issue involving this script and I'm not sure where to go from here.

This is the error I get when trying to load it:

script error on npc/custom/glitch/newplayer.txt line 15
   parse_callfunc: expected ')' to close argument list
   11 : {
   12 :        function get_MAC_variable;
   13 :        function set_MAC_variable;
   14 :
*   15 :        if (get_MAC_variable($'#'lockout)>0) {
   16 :                mes "I already gave a prize to someone from your MAC address.";
   17 :        } else {
   18 :                if (!checkweight(909,1)) {
   19 :                        mes "You are overweight or carrying too many items.";
   20 :                } else {

I also added two more lines after Line 28:

   function get_MAC_variable {
       query_sql "select last_mac from login where account_id = " + getcharid(3),.@MAC$;
       set @MAC$,.@MAC$[0];
       // $#variable = MAC variable

This was to sorta replace getmacaddress() - I'm not sure if that's even a thing lol. I have Harmony and my needs for this NPC's functions are identical to Frost_'s. If you or anyone has a solution for me, it'd help out a lot. Thanks for reading.

Full Script:

prontera,165,164,3	script	Boy#465asesDA	962,{
function get_MAC_variable;
function set_MAC_variable;

if (get_MAC_variable($#lockout) > 0) {
	mes "I already gave a prize to someone from your MAC address.";
} else {
	if (!checkweight(909,1)) {
		mes "You are overweight or carrying too many items.";
	} else {
		getitem 909,1; // Jellopy
		set_MAC_variable $#lockout, 1;
		mes "Here is your prize!";
	}
}
close;

function get_MAC_variable {
	query_sql "select last_mac from login where account_id = " + getcharid(3),.@MAC$;
	set @MAC$,.@MAC$[0];
	// $#variable = MAC variable
	set .@varname$, strtolower(getarg(0, "null"));
	set .@is_string, (charat(.@varname$, getstrlen(.@varname$)-1) == "$");
	if (query_sql("SELECT `value` FROM `mac_reg_value` WHERE `mac`='"+ @MAC$ +"' AND `str`='"+ escape_sql(.@varname$) +"'", .@value$)) {
		return (.@is_string ? .@value$ : atoi(.@value$));
	} else {
		return (.@is_string ? "" : 0);
	}
}

function set_MAC_variable {
	set .@varname$, strtolower(getarg(0, "null"));
	set .@is_string, (charat(.@varname$, getstrlen(.@varname$)-1) == "$");
	set .@value$, getarg(1, (.@is_string ? "" : 0));
	// trim the trailing "$" so name validation is easier
	if (.@is_string) set .@varname$, substr(.@varname$, 0,getstrlen(.@varname$) -1);

	// validate variable name
	if (.@varname$ == "null") {
		debugmes "set_MAC_variable - missing variable name";
		end;
	} else if (getstrlen(.@varname$) < 3 || substr(.@varname$,0,1) != "$#" ) {
		debugmes "set_MAC_variable - MAC variables must start with $#";
		end;
	}
	for (set .@i,2; .@i < getstrlen(.@varname$); set .@i,.@i+1) {
		if (compare("abcdefghijklmnopqrstuvwxyz0123456789_", substr(.@varname$, .@i,.@i)) == 0) {
			debugmes "set_MAC_variable - variable names can only contain '_' and alphanumeric characters";
			end;
		}
	}

	// re-add the trailing "$"
	if (.@is_string) set .@varname$, .@varname$ + "$";

	// check max lengths
	if (getstrlen(.@varname$) > 255) {
		debugmes "set_MAC_variable - variable name longer than 255 characters";
		end;
	}
	if (.@is_string && getstrlen(.@value$) > 255) {
		debugmes "set_MAC_variable - string value longer than 255 characters";
		end;
	} else if (!.@is_string && getstrlen(.@value$) > 9) {
		query_sql "SELECT ('"+ escape_sql(.@value$) +"' BETWEEN -2147483648 AND 2147483647)", .@valid_int;
		if (!.@valid_int) {
			debugmes "set_MAC_variable - integer overflow detected";
			end;
		}
	}

	if ((.@is_string && .@value$=="") || (!.@is_string && .@value$=="0")) {
		// value of "" or 0 --> delete variable
		query_sql "DELETE FROM `mac_reg_value` WHERE `mac`='"+ @MAC$ +"' AND `str`='"+ escape_sql(.@varname$) +"'";
	} else {
		// store the variable!!
		query_sql "REPLACE INTO `mac_reg_value` (`mac`,`str`,`value`) VALUES ('"+@MAC$+"', '"+ escape_sql(.@varname$) +"', '"+ (.@is_string ? escape_sql(.@value$) : atoi(.@value$)) +"')";
	}
	return;
}
}

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  2
  • Topics Per Day:  0.00
  • Content Count:  6
  • Reputation:   0
  • Joined:  10/19/12
  • Last Seen:  

I'm trying to make an NPC that gives players one item per account, and does a MAC address check to see if any other accounts have received an item from the NPC. The MAC address(es) can be found for by checking the last_mac column in the login database, or with some Harmony script command that I'm unaware of; in Brian's post and script, he used getmacaddress() as a filler. I do have Harmony installed.

Edited by Brian
*merged topics*
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  75
  • Topics Per Day:  0.02
  • Content Count:  2223
  • Reputation:   593
  • Joined:  10/26/11
  • Last Seen:  

@Glitch_: I just read your post today, and I will look into it now.

I forgot to put the variable name in quotes ... :( "$#halloween_event"

Here is your script with that fixed: http://rathena.kpaste.net/e752021?raw

Wow, sometimes I look back at my scripts and think "I wrote that??!"

I amaze myself XD

AnnieRuru: now I see what you mean by Script Frenzy Mode /heh

Edited by Brian
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  22
  • Topics Per Day:  0.01
  • Content Count:  59
  • Reputation:   0
  • Joined:  12/13/12
  • Last Seen:  

@Glitch_: I just read your post today, and I will look into it now.

I forgot to put the variable name in quotes ... :("$#halloween_event"

Here is your script with that fixed: http://rathena.kpaste.net/e752021?raw

Wow, sometimes I look back at my scripts and think "I wrote that??!"

I amaze myself XD

AnnieRuru: now I see what you mean by Script Frenzy Mode /heh

I wanna ask. How do i use check on ip and mac, & on the same time give to only new players register from today onwards - example

Lets say i have 1000 accounts register in my sql db.

i want the ACCOUNT_ID from 1001 only can receive the freebies. and also to check mac / ip at the same time?

cause mine is a server that is already launch. and some players already have freebies.

Or any other alternative to do this?

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  112
  • Topics Per Day:  0.03
  • Content Count:  388
  • Reputation:   4
  • Joined:  05/01/12
  • Last Seen:  

it's work if i don't have harmony?

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  75
  • Topics Per Day:  0.02
  • Content Count:  2223
  • Reputation:   593
  • Joined:  10/26/11
  • Last Seen:  

it's work if i don't have harmony?

 

No it will not work. This script requires Harmony or some other modification that allows the client to send its MAC address to the server.

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  0
  • Topics Per Day:  0
  • Content Count:  4
  • Reputation:   0
  • Joined:  09/30/13
  • Last Seen:  

Hi Guys,

I made a Freebies, using the Mac address script by Brian but I am having errors and couldn't find a way to make it smoothly.

Please refer to my attachment, I would gladly appreciate any help.

 

prontera,160,187,4    script    Freedom-RO for Freebies    123,{
    function get_MAC_variable;
    function set_MAC_variable;
    query_sql "SELECT last_mac FROM login WHERE account_id="+ getcharid(3), @my_MAC$;
    
    if (get_MAC_variable("$#lockout") > 0) {
        mes "I already gave items to someone from your MAC address.";
    } else {
        if (!checkweight(909,1)) {
            mes "You are overweight or carrying too many items.";
        } else {
            mes "[Hello, so you left your previous server?]";
            mes "[Here in Freedom-RO, all of the Game Masters went on being a normal player as well.]";
            mes "[That's why we know that new players should have item of what they needed.]";
            mes "[ It is up to you to decide as to what server you will be staying, we're just here serving you and promising that we can be successful]";
            mes "[I can give you a free gift based on your future job.]";
            mes "[Please choose the correct item for the future job]";
    next;
    if(!#Freebie) {
        mes "Select one:";
        next;
        switch(select("Lord Knight:High Wizard:Sniper:Champion:Creator:Assasin Cross:Paladin:Priest:Star Gladiator:Gunslinger:Clown")) {
            case 1:
            getitem2 30000,1,2,7,0,0,0,0,0;
            getitem2 30001,1,2,7,0,0,0,0,0;
            getitem2 30002,1,2,7,0,0,0,0,0;
            getitem2 30003,1,2,7,0,0,0,0,0;
            getitem2 1505,1,1,7,0,0,0,0,0;
            getitem 2830,2;
            getitem 2462,1;
            getitem 2831,2;
            getitem 30005,1;
            getitem 30007,1;
            getitem 30008,1;
            getitem 674,10;//Item for Lord Knight
                set #Freebie, 1;
                warp "prontera", 150, 150;
                savepoint "prontera", 150, 150;
                end;
            case 2:
            getitem2 30000,1,2,7,0,0,0,0,0;
            getitem2 30001,1,2,7,0,0,0,0,0;
            getitem2 30002,1,2,7,0,0,0,0,0;
            getitem2 30003,1,2,7,0,0,0,0,0;
            getitem2 1505,1,1,7,0,0,0,0,0;
            getitem 2830,2;
            getitem 2462,1;
            getitem 2831,2;
            getitem 30005,1;
            getitem 30007,1;
            getitem 30008,1;
            getitem 674,10;//Item for High Wizard
                set #Freebie, 1;
                warp "prontera", 150, 150;
                savepoint "prontera", 150, 150;
                end;
            case 3:
            getitem2 30000,1,2,7,0,0,0,0,0;
            getitem2 30001,1,2,7,0,0,0,0,0;
            getitem2 30002,1,2,7,0,0,0,0,0;
            getitem2 30003,1,2,7,0,0,0,0,0;
            getitem2 1505,1,1,7,0,0,0,0,0;
            getitem 2830,2;
            getitem 2462,1;
            getitem 2831,2;
            getitem 30005,1;
            getitem 30007,1;
            getitem 30008,1;
            getitem 674,10;//Item for Sniper
                set #Freebie, 1;
                warp "prontera", 150, 150;
                savepoint "prontera", 150, 150;
                end;
            case 4:
            getitem2 30000,1,2,7,0,0,0,0,0;
            getitem2 30001,1,2,7,0,0,0,0,0;
            getitem2 30002,1,2,7,0,0,0,0,0;
            getitem2 30003,1,2,7,0,0,0,0,0;
            getitem2 1505,1,1,7,0,0,0,0,0;
            getitem 2830,2;
            getitem 2462,1;
            getitem 2831,2;
            getitem 30005,1;
            getitem 30007,1;
            getitem 30008,1;
            getitem 674,10;//Item for Champion
                set #Freebie, 1;
                warp "prontera", 150, 150;
                savepoint "prontera", 150, 150;
                break;
            case 5:
            getitem2 30000,1,2,7,0,0,0,0,0;
            getitem2 30001,1,2,7,0,0,0,0,0;
            getitem2 30002,1,2,7,0,0,0,0,0;
            getitem2 30003,1,2,7,0,0,0,0,0;
            getitem2 1505,1,1,7,0,0,0,0,0;
            getitem 2830,2;
            getitem 2462,1;
            getitem 2831,2;
            getitem 30005,1;
            getitem 30007,1;
            getitem 30008,1;
            getitem 674,10;//Item for Creator
                set #Freebie, 1;
                warp "prontera", 150, 150;
                savepoint "prontera", 150, 150;
                end;    
            case 6:
            getitem2 30000,1,2,7,0,0,0,0,0;
            getitem2 30001,1,2,7,0,0,0,0,0;
            getitem2 30002,1,2,7,0,0,0,0,0;
            getitem2 30003,1,2,7,0,0,0,0,0;
            getitem2 1505,1,1,7,0,0,0,0,0;
            getitem 2830,2;
            getitem 2462,1;
            getitem 2831,2;
            getitem 30005,1;
            getitem 30007,1;
            getitem 30008,1;
            getitem 674,10;//Item for Assasin Cross
                set #Freebie, 1;
                warp "prontera", 150, 150;
                savepoint "prontera", 150, 150;
            case 7:
                getitem 13758,1;
                getitem 969,20;
                getitem 1108,1;
                getitem 2104,1;
                getitem 4043,4;//Item for Paladin
                set #Freebie, 1;
                warp "prontera", 150, 150;
                savepoint "prontera", 150, 150;
            case 8:
            getitem2 30000,1,2,7,0,0,0,0,0;
            getitem2 30001,1,2,7,0,0,0,0,0;
            getitem2 30002,1,2,7,0,0,0,0,0;
            getitem2 30003,1,2,7,0,0,0,0,0;
            getitem2 1505,1,1,7,0,0,0,0,0;
            getitem 2830,2;
            getitem 2462,1;
            getitem 2831,2;
            getitem 30005,1;
            getitem 30007,1;
            getitem 30008,1;
            getitem 674,10;//Item for Priest
                set #Freebie, 1;
                warp "prontera", 150, 150;
                savepoint "prontera", 150, 150;
            case 9:
            getitem2 30000,1,2,7,0,0,0,0,0;
            getitem2 30001,1,2,7,0,0,0,0,0;
            getitem2 30002,1,2,7,0,0,0,0,0;
            getitem2 30003,1,2,7,0,0,0,0,0;
            getitem2 1505,1,1,7,0,0,0,0,0;
            getitem 2830,2;
            getitem 2462,1;
            getitem 2831,2;
            getitem 30005,1;
            getitem 30007,1;
            getitem 30008,1;
            getitem 674,10;//Item for Star Gladiator
                set #Freebie, 1;
                warp "prontera", 150, 150;
                savepoint "prontera", 150, 150;
            case 10:
            getitem2 30000,1,2,7,0,0,0,0,0;
            getitem2 30001,1,2,7,0,0,0,0,0;
            getitem2 30002,1,2,7,0,0,0,0,0;
            getitem2 30003,1,2,7,0,0,0,0,0;
            getitem2 1505,1,1,7,0,0,0,0,0;
            getitem 2830,2;
            getitem 2462,1;
            getitem 2831,2;
            getitem 30005,1;
            getitem 30007,1;
            getitem 30008,1;
            getitem 674,10;//Item for Gunslinger
                set #Freebie, 1;
                warp "prontera", 150, 150;
                savepoint "prontera", 150, 150;
                end;
            case 11:
            getitem2 30000,1,2,7,0,0,0,0,0;
            getitem2 30001,1,2,7,0,0,0,0,0;
            getitem2 30002,1,2,7,0,0,0,0,0;
            getitem2 30003,1,2,7,0,0,0,0,0;
            getitem2 1505,1,1,7,0,0,0,0,0;
            getitem 2830,2;
            getitem 2462,1;
            getitem 2831,2;
            getitem 30005,1;
            getitem 30007,1;
            getitem 30008,1;
            getitem 674,10;//Item for Clown
                set #Freebie, 1;
                warp "prontera", 150, 150;
                savepoint "prontera", 150, 150;
                end;
                
            }
            close;
    }
   mes "[ROFL! Are you kidding me right now Bro?]";
   mes "You already received your freebies!";
   close;
 
    OnInit:
    waitingroom "Get your freebies here ! ",0;
    end;
}
 
    function get_MAC_variable {
        // $#variable = MAC variable
        set .@varname$, strtolower(getarg(0, "null"));
        set .@is_string, (charat(.@varname$, getstrlen(.@varname$)-1) == "$");
        if (query_sql("SELECT `value` FROM `mac_reg_value` WHERE `mac`='"+ @my_MAC$ +"' AND `str`='"+ escape_sql(.@varname$) +"'", .@value$)) {
            return (.@is_string ? .@value$ : atoi(.@value$));
        } else {
            return (.@is_string ? "" : 0);
        }
    }
    
    function set_MAC_variable {
        set .@varname$, strtolower(getarg(0, "null"));
        set .@is_string, (charat(.@varname$, getstrlen(.@varname$)-1) == "$");
        set .@value$, getarg(1, (.@is_string ? "" : 0));
        // trim the trailing "$" so name validation is easier
        if (.@is_string) set .@varname$, substr(.@varname$, 0,getstrlen(.@varname$) -1);
        
        // validate variable name
        if (.@varname$ == "null") {
            debugmes "set_MAC_variable - missing variable name";
            end;
        } else if (getstrlen(.@varname$) < 3 || substr(.@varname$,0,1) != "$#" ) {
            debugmes "set_MAC_variable - MAC variables must start with $#";
            end;
        }
        for (set .@i,2; .@i < getstrlen(.@varname$); set .@i,.@i+1) {
            if (compare("abcdefghijklmnopqrstuvwxyz0123456789_", substr(.@varname$, .@i,.@i)) == 0) {
                debugmes "set_MAC_variable - variable names can only contain '_' and alphanumeric characters";
                end;
            }
        }
        
        // re-add the trailing "$"
        if (.@is_string) set .@varname$, .@varname$ + "$";
        
        // check max lengths
        if (getstrlen(.@varname$) > 255) {
            debugmes "set_MAC_variable - variable name longer than 255 characters";
            end;
        }
        if (.@is_string && getstrlen(.@value$) > 255) {
            debugmes "set_MAC_variable - string value longer than 255 characters";
            end;
        } else if (!.@is_string && getstrlen(.@value$) > 9) {
            query_sql "SELECT ('"+ escape_sql(.@value$) +"' BETWEEN -2147483648 AND 2147483647)", .@valid_int;
            if (!.@valid_int) {
                debugmes "set_MAC_variable - integer overflow detected";
                end;
            }
        }
        
        if ((.@is_string && .@value$=="") || (!.@is_string && .@value$=="0")) {
            // value of "" or 0 --> delete variable
            query_sql "DELETE FROM `mac_reg_value` WHERE `mac`='"+ @my_MAC$ +"' AND `str`='"+ escape_sql(.@varname$) +"'";
        } else {
            // store the variable!!
            query_sql "REPLACE INTO `mac_reg_value` (`mac`,`str`,`value`) VALUES ('"+@my_MAC$+"', '"+ escape_sql(.@varname$) +"', '"+ (.@is_string ? escape_sql(.@value$) : atoi(.@value$)) +"')";
        }
        return;
    }
}
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...