| 08-04-2007, 08:06 AM | #1 |
Hey, I've been wondering if you could convert a player name into hex. What I'm trying to do is create a save/load code that only allows the player who received the code to to redeem it. It took me awhile to explain it to Pyrogasm so let's hope I can get it across to you guys. For staying a finishing a game in the map, the player who came in first will get a powerful item while the other players get slightly inferior items. The problem I have with save codes is that if a player gets a code to a powerful item, he can share it with nubsause players who don't have a clue what to do. Player 1 comes in first so he gets "Kelen's Dagger of Escape". It gives him a code "3333FF". The next time, after Player 1 chooses a hero, he can enter in his code and receive his unique dagger. If rtard Player 2 tries to get a fancy dagger by typing in "3333FF", he will get nothing more than an error message. Each item has a hex value associated with it. To generate the code, the game adds the name of the player converted to hex, we'll use "FF0000". The item's code is "3333FF", "run calc" swich to scientific and add them up. You should get "13233FF". Through a few random letters and number in there to through off those who try to find the item's hex code. "1532B3B3FF" When you go to retrieve your item, the game will only look at the 1st, 3rd, 4th, 6th, 8th, 9th, 10th character, the others are just decoys. When you enter the code in to claim your item, the game will convert your name to hex, add your name to all the possible items you can claim, and if two of the the codes match, it will grant you your item. If this has been done before or in an easier way, then I fail epicly. |
| 08-04-2007, 08:32 AM | #2 |
Make an array of strings and do the following: set SA[0] = "A" set SA[1] = "B" set SA[2] = "C" set SA[3] = "D" then you take one by one letter from player name (using a substring) and compare it with letters in SA, that way you will convert letters to numbers, how you store those numbers in save code is up to you. remember to turn player name to uppercase first NOTE: you don't have to store special characters from player names both Mephisto and --mepHisto-- players will be able to share their save code, but who gives a damn, chance for that is very small. |
| 08-04-2007, 08:43 AM | #3 |
You need a hash of some sort. For warcraft it's kind of nice if it's commutative. Search away. |
| 08-04-2007, 08:54 AM | #4 |
That's what I thought first, but actually he does not, Nothing prevents him to store player names as an array of say 128 integers, if player name is shorter than that he simply pads it with zeroes ... But if for convenience he needs it to be just one integer the best hash would probably be to do i1 + i2*2 + i3*3 ... where ix is the index of player name letters from my previous post. |
| 08-04-2007, 01:25 PM | #5 |
Saving a player's name is not the most awesome idea. It is actually pretty lame, you would have to either crop long names else it would have different sizes for each player which makes things harder, instead, getting a hash from the player name is secure enough and does not increase the size of the code. In fact I just encrypt the data based on the player's name, since data got a checksum, not the same player equals bad checksum, this way the player lock does not increase the size of the code. If you really want to convert the name of the player, then you want to convert it to binary, not hex, but in your code the binary would be "decimal" aka, you simply get an integer from the name, although since it is not a hash you'll need to get a chain of integers. But I really think the hash is much better |
| 08-04-2007, 02:53 PM | #6 |
Is there some function in jass for hashing strings that I don't know of ? As far as I know you can't even get a char from a given index without using a substring function. |
