Raised This Month: $51 Target: $400
 12% 

Get CommunityID (SteamID64) String


Post New Thread Reply   
 
Thread Tools Display Modes
11530
Veteran Member
Join Date: Sep 2011
Location: Underworld
Old 12-18-2012 , 18:00   Re: Get CommunityID (SteamID64) String
Reply With Quote #21

I had that thought too, but thinking more of FormatEx rather than Format, but to be honest, I rather like the simple mathematics of my version even if I say so myself.
__________________

Last edited by 11530; 12-18-2012 at 18:01.
11530 is offline
Zephyrus
Cool Pig B)
Join Date: Jun 2010
Location: Hungary
Old 12-19-2012 , 19:22   Re: Get CommunityID (SteamID64) String
Reply With Quote #22

its berni's code from like 1.5 years ago from the originhal communityid thread and yes it can easily be further optimized
__________________
Taking private C++/PHP/SourcePawn requests, PM me.
Zephyrus is offline
minimoney1
SourceMod Donor
Join Date: Dec 2010
Old 12-19-2012 , 22:18   Re: Get CommunityID (SteamID64) String
Reply With Quote #23

Quote:
Originally Posted by Zephyrus View Post
its berni's code from like 1.5 years ago from the originhal communityid thread and yes it can easily be further optimized
I don't think it would still, even when completely optimized, be "way better" than the provided method.
__________________
Need help? PM me or add me on Steam.
My Steam




Quote:
Originally Posted by Rp.KryptoNite View Post
For some reason his Plugin never worked for me ,
@credits were added
im not stealing any plugins dude its my THING

Last edited by minimoney1; 12-19-2012 at 22:18.
minimoney1 is offline
11530
Veteran Member
Join Date: Sep 2011
Location: Underworld
Old 12-20-2012 , 13:41   Re: Get CommunityID (SteamID64) String
Reply With Quote #24

Curiosity got the better of me, so I've just tested my version against Zephyrus's - including the optimizations that he failed to do. Ran both 10 million times, twice.

Results (in seconds):
Zephyrus's code - Average Time: 6.781233 then 6.865508 (Total Average: 6.8233705)
My code - Average Time: 6.725708 then 6.860354 (Total Average: 6.793031)

Conclusion:
My code is faster by a fraction, but for all intents and purposes, they are identical. Both second trials, running 10 million times in 6.86 seconds - it pretty much renders this entire argument that Zephyrus started as obsolete - but then again, we always knew it would end up pointless anyway. This isn't the "be-the-fastest-and-win-a-cookie" thread Zeph, - this is to convert SteamIDs to CommunityIDs.

Both do the same thing. Will I switch to Zephyrus's barely slower code (well, berni's, since Zephyrus is just super at copy/pasting 1.5 year-old code)? Not at all. Will I stick to my shorter code? Yes - and I love the simple mathematical syntax.

Hopefully (though I'm sure I'll be mistaken), this will be the end of this week's drama.
__________________
11530 is offline
Zephyrus
Cool Pig B)
Join Date: Jun 2010
Location: Hungary
Old 12-21-2012 , 09:50   Re: Get CommunityID (SteamID64) String
Reply With Quote #25

heres MY version:

Code:
bool:GetFriendID(String:AuthID[], String:FriendID[], size)
{
    if(AuthID[6]=='I' || size < 18)
    {
        FriendID[0] = 0;
        return false;
    }

    new iUpper = 765611979;
    new iFriendID = StringToInt(AuthID[10])*2 + 60265728 + AuthID[8]-48;

    if(iFriendID >= 39734271)
        ++iUpper;
    if(iFriendID >= 139734271)
        ++iUpper;

    new iDiv = iFriendID/100000000;
    IntToString(iFriendID, FriendID[9-iDiv], size-9-iDiv);
    IntToString(iUpper, FriendID, size);

    return true;
}
I ran both 10 million times:

My version: 1. 2.923248 2. 2.910583 3. 2.927520 Total avg: 2.92045033
Your version: 1. 7.414703 2. 7.334228 3. 7.284574 Total avg: 7.34450167

Difference: mine is faster 2.51485245 times

Length of code:

My version: 21 lines can be decreased to 17 lines if I remove the blank lines
Your version: 23 lines can be decreased to 20 lines if you remove the blank lines
__________________
Taking private C++/PHP/SourcePawn requests, PM me.

Last edited by asherkin; 12-21-2012 at 15:04.
Zephyrus is offline
psychonic

BAFFLED
Join Date: May 2008
Old 12-21-2012 , 10:50   Re: Get CommunityID (SteamID64) String
Reply With Quote #26

psychonic is offline
11530
Veteran Member
Join Date: Sep 2011
Location: Underworld
Old 12-21-2012 , 13:51   Re: Get CommunityID (SteamID64) String
Reply With Quote #27

@Zephyrus, Thanks for attempting to post improvements. We're always encouraging you guys to post when you can. Your speed boosts might be stemming from incorrect code however. I ran your function against some examples of SteamIDs to see their results. Whilst they are incorrect, I can still concede that your code, when fixed, might be faster. As of yet, your code will error if the output length is smaller than 18, which should be allowed, and also crashes my test server when an output string larger than 18 is used.

Data used: "STEAM_0:0:131785", "STEAM_ID_PENDING", "STEAM_0:0:12341111", "BOT", "STEAM_0:1:1" with the usual output size:

Output:
PHP Code:
765611980 should be 76561197960529298 (returns 1)
[
blankshould be [blank] (returns 0)
765611980 should be 76561197984947950 (returns 1)
765611980 should be [blank] (returns 0)
765611980 should be 76561197960265731 (returns 1
Note: [blank] here implies an empty string.
__________________

Last edited by 11530; 12-21-2012 at 13:57.
11530 is offline
Zephyrus
Cool Pig B)
Join Date: Jun 2010
Location: Hungary
Old 12-21-2012 , 13:58   Re: Get CommunityID (SteamID64) String
Reply With Quote #28

Quote:
Originally Posted by 11530 View Post
@Zephyrus, Thanks for attempting to post improvements. We're always encouraging you guys to post when you can. Your speed boosts might be stemming from incorrect code however. I ran your function against some examples of SteamIDs to see their results. Whilst they are incorrect, I can still concede that your code, when fixed, might be faster. As of yet, your code will error if the output length is smaller than 18, which should be allowed, and also crashes my test server when a larger buffer than 18 is used.

Data used: "STEAM_0:0:131785", "STEAM_ID_PENDING", "STEAM_0:0:12341111", "BOT", "STEAM_0:1:1":

Output:
PHP Code:
765611980 should be 76561197960529298 (returns 1)
[
blankshould be [blank] (returns 0)
765611980 should be 76561197984947950 (returns 1)
765611980 should be [blank] (returns 0)
765611980 should be 76561197960265731 (returns 1
Note: [blank] here implies an empty string.
PHP Code:
stock bool:GetClientCommunityID(String:AuthID[], String:FriendID[], size)
{
    if(
AuthID[0]!='S' || AuthID[6]=='I' || size 18)
    {
        
FriendID[0] = 0;
        return 
false;
    }

    new 
iUpper 765611979;
    new 
iFriendID StringToInt(AuthID[10])*60265728 AuthID[8]-48;

    if(
iFriendID >= 100000000)
        ++
iUpper;
    if(
iFriendID >= 200000000)
        ++
iUpper;

    new 
iDiv = (iFriendID/100000000?1:0);
    
IntToString(iUpperFriendIDsize);
    
IntToString(iFriendIDFriendID[9-iDiv], size-9-iDiv);

    return 
true;

here, this one should be correct for all your cases, problem was that i didnt add 60265728 to those numbers that i checked iFriendID against and having only the upper was caused by the wrong order of inttostrings, code should be the same speed tho as i didnt add anything new except +1 byte check for BOT ids

Edit: confirmed, ive tried all your test cases, all work and time is still under 3 secs on my PC for 10 million runs
__________________
Taking private C++/PHP/SourcePawn requests, PM me.

Last edited by Zephyrus; 12-21-2012 at 14:19.
Zephyrus is offline
11530
Veteran Member
Join Date: Sep 2011
Location: Underworld
Old 12-21-2012 , 14:16   Re: Get CommunityID (SteamID64) String
Reply With Quote #29

Quote:
Originally Posted by Zephyrus View Post
here, this one should be correct for all your cases, problem was that i didnt add 60265728 to those numbers that i checked iFriendID against and having only the upper was caused by the wrong order of inttostrings, code should be the same speed tho as i didnt add anything new except +1 byte check for BOT ids
Yea, that one works better now, but still exits early when an output string less than 18 is given. In my head, it should just truncate the string. But then you'd need a different check maybe.
__________________
11530 is offline
Zephyrus
Cool Pig B)
Join Date: Jun 2010
Location: Hungary
Old 12-21-2012 , 14:26   Re: Get CommunityID (SteamID64) String
Reply With Quote #30

Quote:
Originally Posted by 11530 View Post
Yea, that one works better now, but still exits early when an output string less than 18 is given. In my head, it should just truncate the string. But then you'd need a different check maybe.
you can simply remove that check, it even makes the code measurably faster altho i didnt find any useful case for a truncated communityid thats why i added that check, tested and works

PHP Code:
stock bool:GetCommunityID(String:AuthID[], String:FriendID[], size)
{
    if(
AuthID[0]!='S' || AuthID[6]=='I')
    {
        
FriendID[0] = 0;
        return 
false;
    }

    new 
iUpper 765611979;
    new 
iFriendID StringToInt(AuthID[10])*60265728 AuthID[8]-48;

    if(
iFriendID >= 100000000)
        ++
iUpper;
    if(
iFriendID >= 200000000)
        ++
iUpper;

    new 
iDiv = (iFriendID/100000000?1:0);
    
IntToString(iUpperFriendIDsize);
    
IntToString(iFriendIDFriendID[9-iDiv], size-9-iDiv);

    return 
true;

__________________
Taking private C++/PHP/SourcePawn requests, PM me.

Last edited by Zephyrus; 12-21-2012 at 14:26.
Zephyrus is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 18:35.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode