Pages: [1] :: one page |
|
Author |
Thread Statistics | Show CCP posts - 0 post(s) |
deadmeet
|
Posted - 2008.07.14 10:20:00 -
[1]
Hi,
I'm looking for a system that would automatically give some right on a website depending on members roles in the game.
As the new Empirean age API can retrieve roles depending on the title, I will be able to do it.
the problem is that I don't find informations about the data retrieved about the roles. It return a big number, and I don't know how to know what this number mean.
Is there a documentation around here about that ?
thanks
deadmeet
|
deadmeet
|
Posted - 2008.07.14 10:20:00 -
[2]
Hi,
I'm looking for a system that would automatically give some right on a website depending on members roles in the game.
As the new Empirean age API can retrieve roles depending on the title, I will be able to do it.
the problem is that I don't find informations about the data retrieved about the roles. It return a big number, and I don't know how to know what this number mean.
Is there a documentation around here about that ?
thanks
deadmeet
|
Matalino
Gallente Ki Tech Industries
|
Posted - 2008.07.14 15:10:00 -
[3]
About 3/4's of the way down this page you will see a complete break down of the Roles. Search that page for "Director" and it will jump strait to that table.
|
deadmeet
|
Posted - 2008.07.14 18:25:00 -
[4]
Hmm ok, so you need to add the values to obtain the total that is retrieved in membertracking.
So my next question, what would be the best way to calculate the attributed roles ?
square ? modulo ? I don't find a quick and easy solution to divide my huge number and to retrieve the roles.
|
Matalino
Gallente Ki Tech Industries
|
Posted - 2008.07.14 18:28:00 -
[5]
Depends on what language you are using. It is not a problem if you are using any language that supports 64 bit integers such as the .NET frame work.
|
deadmeet
|
Posted - 2008.07.15 11:53:00 -
[6]
Hi,
This is not what I mean, it's not a variable length problem it's an algorythmic problem.
Example :
Imagine a player that have 3 rights : accountant (256), can take from division 1 hangar (8192), can query from division 1 (1048576).
So, the Api retrieve the number : 1057024
Now, with that number, how can you know that it's the addition of 256 + 8192 + 104857.
In a quick brainstorming, I would make a loop that substract all roles 1 by 1, by beggining with the higher. If the substraction don't give a negative number, add the role in an array, and repeat the operation while you don't obtain 0.
Maybe there is a better solution, that is the reason of that post.
|
Yorick Downe
Caldari Agony Unleashed Agony Empire
|
Posted - 2008.07.15 12:36:00 -
[7]
Edited by: Yorick Downe on 15/07/2008 12:39:02 Edited by: Yorick Downe on 15/07/2008 12:37:05 Right above your post - he's right with the AND operator. Don't think of these as numbers, think of them as bit positions. "If bit 9 is set, the accountant role has been granted". The table makes that easy for you with 2^x listed. So, to take your example, it doesn't matter what the absolute value is - the bitwise AND will still return true if that bit is set, and false otherwise.
That takes care of querying for a specific role. If what you want to know is "which roles are assigned to this egger", then one way to do that is with a loop. I'll give you some code - mind you, this is crude, feel free to adjust to your needs or prettify.
$roles = array_fill(0,64,null); // Create an initialized array, with indizes from 0 through 63 $roles[0] = 'Director'; $roles[7] = 'Personnel Manager'; $roles[8] = 'Accountant'; // etc, you get the idea, fill the array with the values, and use the bit-position as an index // This is a bit silly, really, you're more likely to not do that and instead have some values in here that correspond to // attributes of an object to set - too much for Monday morning, though. Just printing strings will do nicely for now. // $toonrole is the value we got from the API, somehow // 64-bits are nice, but who says my server is running on a 64-bit platform? I don't control that. So my ints may only be 32-bit. In which // case, $toonrole would hopefully be a string, and we can do some clever stuff to break it up. That having been said, that's too much // brain for monday morning as well, so I'll assume we're running this on a 64-bit platform. Adjusting to 32-bit platforms is left as an // exercise for the reader.
for ($i = 0; $i<64; $i++) { if ($roles[$i] && ($toonrole & pow(2,$i))) // This role exists (non-null) and a bit-wise AND of the bit-position with our $toonrole is 1, not 0. print ("Yay, we have the $roles[$i] role<br>"); }
Code hasn't been tested, won't work on 32-bit servers, yada. And is PHP, if that's not painfully obvious :)
|
Matalino
Gallente Ki Tech Industries
|
Posted - 2008.07.15 15:15:00 -
[8]
Edited by: Matalino on 15/07/2008 15:16:41
Originally by: deadmeet Maybe there is a better solution, that is the reason of that post.
As I tried to point out in my earlier post and as Yorick repeated, using the bitwise AND operator is likely to be the best way to do it.
Using your example role of 1057024.
1057024 & 8192 = 8192
1057024 & 256 = 256
1057024 & 1 = 0
Basicly you just pick the role that you want to test for, bitwise AND it with the character's role. Your result will be 0 if the character doesn't have that role and will be value of the role if they do.
You can also use this to test for several roles at once. For example, if you wanted to test to see if a character can access any hanger you can use this method:
8192 + 16384 + 32768 + 65536 + 131072 + 262144 + 524288 = 1040384
1057024 & 1040384 = 8192
If he did not have access to any hanger, the result would be 0. As he did have access to a hanger, the result was the sum of the hanger access roles that he had.
BTW - The basic windows calculator has a AND function when in scientific mode that you can play with to test different roles.
|
deadmeet
|
Posted - 2008.07.15 16:33:00 -
[9]
Edited by: deadmeet on 15/07/2008 16:33:14 Thank you all, it is exactly what I need. I didn't know this operator, that's why I broke my head trying to do it with table or addition.
By using the & operator in PHP like the last post explain, it is very easy to retrieve the roles of a member.
However, the list in the database seems incomplete, where are the junior accountant roles etc.... it is the list in the website that is incomplete or does CCP don't give us all roles ?
|
Matalino
Gallente Ki Tech Industries
|
Posted - 2008.07.15 17:37:00 -
[10]
Originally by: deadmeet However, the list in the database seems incomplete, where are the junior accountant roles etc.... it is the list in the website that is incomplete or does CCP don't give us all roles ?
Some of the roles might be hybrids of different roles.
For example, AFAIK, junior accountant is simply all of the "Can query division account" roles.
|
|
deadmeet
|
Posted - 2008.07.16 16:08:00 -
[11]
Hi,
I think I speak a little too quickly when I said it works.
I tried with the windows calc, it worked well, I saw that there was an "and" operator in PHP (written &), I thought it was the same thing.
However when I try :
$role_test = $member['roles'] & $key; ($key is the number of the role : ex 128). it always return the $key as the result.
I don't find the equivalent of the and function in the calc windows in PHP, can somebody help me ?
|
deadmeet
|
Posted - 2008.07.16 16:36:00 -
[12]
Ahhh, I begin to understand the 64 bit problem.
The & operator can only work with int, if I directly use the $member['roles'] variable retrieved from the API, it is as string.
so I try to convert it in an integer by doing (int)$member['roles'];
the problem is that the original value is : 4503599627370496
and after making the (int), it's : 2147483647
So how can I pass out this problem ?
|
Matalino
Gallente Ki Tech Industries
|
Posted - 2008.07.16 17:11:00 -
[13]
Originally by: deadmeet So how can I pass out this problem ?
Basicly you need to right out some code that will do division on strings.
You need to divide the value by 2147483648. Put the modulo in one int variable and put the quotient in another.
In any case, it is not likely to be much fun.
I don't use PhP, but maybe someone who does might already have a code snippet that makes the conversion.
|
deadmeet
|
Posted - 2008.07.20 01:59:00 -
[14]
Edited by: deadmeet on 20/07/2008 01:59:06 After several days of trying, I really don't find how can I play with members roles with PHP and 32 bit server.
If the role is considered as a string, it's ok. But if I try to make an operation (and, modulo, whatever) the number is converted to 32 bit and so, the values are altered.
I'm out of idea how could I solve this problem, if somebody have a magic function, he will enjoy my week end ;)
|
MrRx7
Amarr Cutting Edge Incorporated RAZOR Alliance
|
Posted - 2008.07.20 08:46:00 -
[15]
Originally by: deadmeet Edited by: deadmeet on 20/07/2008 01:59:06 After several days of trying, I really don't find how can I play with members roles with PHP and 32 bit server.
If the role is considered as a string, it's ok. But if I try to make an operation (and, modulo, whatever) the number is converted to 32 bit and so, the values are altered.
I'm out of idea how could I solve this problem, if somebody have a magic function, he will enjoy my week end ;)
If you want to escape the max int (2147483647) issue you can always change the percision of php
ini_set("precision",90); #will raise more than enought.
if you want a function to split it up in php, here you go
/** * Correct the variables stored in array. * @param integer $mask Integer of the bit * @return array */ function bitMask($mask = 0) { if(!is_numeric($mask)) { return array(); } $return = array(); while ($mask > 0) { for($i = 0, $n = 0; $i <= $mask; $i = 1 * pow(2, $n), $n++) { $end = $i; } $return[] = $end; $mask = $mask - $end; } sort($return); return $return; }
basically, you send it your role bitmask $whatever = bitMask($roles);
and it will return a array of the bitmasks.
like
[array] => [1] = xxxxx, [2] = xxxxx and so on.
I have enabled the debugging output on my api dummy site if you want to play with it. http://www.eve-razor.com/testing/roles.html?apikey=XXXX&userid=XXXX&characterID=XXXXX
You need a full director api to view it sadly. if you want I can post the full code later on. Your signature exceeds the maximum allowed filesize of 24000 bytes -Navigator ([email protected]) |
VheroKai
Vhero' Multipurpose Corp
|
Posted - 2008.07.20 23:10:00 -
[16]
Originally by: deadmeet Ahhh, I begin to understand the 64 bit problem.
The & operator can only work with int, if I directly use the $member['roles'] variable retrieved from the API, it is as string.
so I try to convert it in an integer by doing (int)$member['roles'];
the problem is that the original value is : 4503599627370496
and after making the (int), it's : 2147483647
So how can I pass out this problem ?
Your real problem is that you are using "&" (binary AND) operator instead of "&&" (logical AND). Logical AND is enough to check if given member has this or that role. If you want to break the list into separate roles, use BCMath library. --sig--
Originally by: Bunyip The LOLqual is a capital-sized joke
|
Immersive
Immersive Technology Solutions
|
Posted - 2008.07.21 01:26:00 -
[17]
The correct way to test for a set bitfield is:
((input & testmask) != 0)
This returns true if your testmask matches, false if it doesn't. --- New to the API? GrabRaw XML
It's coming...
|
Dragonaire
|
Posted - 2008.07.21 18:48:00 -
[18]
You might try finding the old IGBClass 2 from Patrick D Hall it had function in it to check roles that should work with just a few updates. I don't have a good link for it any more but think I found it on Eve-files. It uses BCD code which has been in php by default for a few years now so most hosting sites should have it
|
VheroKai
Vhero' Multipurpose Corp
|
Posted - 2008.07.21 20:46:00 -
[19]
Originally by: Immersive The correct way to test for a set bitfield is:
((input & testmask) != 0)
This returns true if your testmask matches, false if it doesn't.
kk, I was wrong in explanation. but anyway, you can't check bitmask greater than (2^32-1) in PHP.
<?php
$a = 134359738398; $c = 34359738368; echo "{$a}:{$c}\n";
if($a & $c) { echo "Match\n"; } else { echo "Not match\n"; }
?>
It does "not match", but checking with better calculator revealing the truth:
134359738398 & 34359738368 = (int64) 0x800000000
Possible solution:
<?php
function hasRole($pattern, $role) { $cut = bcpow(2, 32); $roleLow = intval(bcmod($role, $cut)); $roleHigh = intval(bcdiv($role, $cut));
$pattLow = intval(bcmod($pattern, $cut)); $pattHigh = intval(bcdiv($pattern, $cut));
$resLow = $roleLow & $pattLow; $resHigh = $roleHigh & $pattHigh;
if($resLow || $resHigh) { $result = bcadd(bcmul($resHigh, $cut), $resLow); } else { $result = false; }
return $result; }
if(hasRole($c, $a)) { echo "Match\n"; } else { echo "Not match\n"; }
?> --sig--
Originally by: Bunyip The LOLqual is a capital-sized joke
|
Immersive
Immersive Technology Solutions
|
Posted - 2008.07.22 01:01:00 -
[20]
Originally by: VheroKai
Originally by: Immersive The correct way to test for a set bitfield is:
((input & testmask) != 0)
This returns true if your testmask matches, false if it doesn't.
kk, I was wrong in explanation. but anyway, you can't check bitmask greater than (2^32-1) in PHP.
Well, that's gotta suck I've never dealt with PHP stuff. They dont have a long integer type? --- New to the API? GrabRaw XML
It's coming...
|
|
Dragonaire
|
Posted - 2008.07.24 07:47:00 -
[21]
No think they are adding 64 to php6 but easy to work around it using BC Math functions that work on strings. That was approach the class I talked about above uses to work around problem. BC Math started being built in by default some time in the php4 series but no one seems to have paid much attention to it The class above was designed to be used for IGB stuff but can easily be adapted for other uses or methods extracted and converted to stand-alone functions to do want you need.
|
deadmeet
|
Posted - 2008.07.24 11:45:00 -
[22]
Hi,
I finally found a solution, it's to use SQL to make the calculation :
'SELECT 4512365643102 & 46932145652'; (number mean nothing, it's just for the idea).
It seems to work, SQL can play with 64 bit integer.
|
Matalino
Gallente Ki Tech Industries
|
Posted - 2008.07.24 15:36:00 -
[23]
Edited by: Matalino on 24/07/2008 15:36:17
Originally by: deadmeet I finally found a solution, it's to use SQL to make the calculation :
'SELECT 4512365643102 & 46932145652'; (number mean nothing, it's just for the idea).
Sounds simple enough.
However, you might not want to make too many calls to SQL so as to avoid the overhead of external calls.
If you are testing for one role, use your example above.
If you want to test for multiple roles, you might want to use SQL to break the 64bit value into seperate 32bit blocks so that you can work with it within PhP without making external calls to SQL.
Or perhaps run multiple checks in a single query. For example: 'SELECT role, bitMask & 4512365643102 FROM roles' with the table 'roles' containing the information in that table I linked earlier and add more filters to get just the roles you are interested in.
|
Dragonaire
|
Posted - 2008.07.24 19:24:00 -
[24]
Here's a small php5 class I put together that should be helpful. Haven't fully tested it to make sure everything works right yet but should be good. EveApiRoles.class.zip
|
|
|
|
Pages: [1] :: one page |
First page | Previous page | Next page | Last page |