Arcana / node-dota2

A node-steam plugin for Dota 2.
MIT License
545 stars 191 forks source link

getting server steam3ID value #263

Closed c00kie17 closed 8 years ago

c00kie17 commented 8 years ago

how can I get the server steam3ID value to use in the watch_server command form the "steam server id " which returns a low and high value . The steam3ID value needed looks like this [A:1:value:value]. I am getting the steam server id from the list of sourcetv games .I know its not a issue with the system but I did not know where else to ask the question.

jimmydorry commented 8 years ago

The object you are getting is the high and low 32 bits of a 64 bit unsigned int. NodeJS can't work with 64bits natively, so you need to treat it as a string or use a bigint package to do operations on it.

@Crazy-Duck can elaborate on this, as I may be totally wrong... but this is an object type which can be stringified. So you can basically do ""+steam_id or JSON.stringify(steam_id) to get the value. If you go through the code you'll see where this has been used in several places to compare unsigned int's.

Once you have a number to work with, rather that re-invent the wheel... try using one of the multitude of packages out there to help you.

https://github.com/DoctorMcKay/node-steamid

var SteamID = require('steamid');

var sid = new SteamID('76561198006409530');
console.log(sid.getSteam3RenderedID()); // [U:1:46143802]

var gid = new SteamID('103582791434202956');
console.log(gid.getSteam3RenderedID()); // [g:1:4681548]

This hopefully gives you somewhere to start.

c00kie17 commented 8 years ago

Hi jimmydorry thanks for helping out. I used to JSON.stringify to print the value of the object which gives me the high and low 32 bit values of the 64bit unsigned int. The package that you sent me needs like 64 bit value. Do you know any way to convert it ? I will try to search for a package that does the same if you have any more suggestion I would really appreciate it .Thank you for your help

Crazy-Duck commented 8 years ago

You can't use JSON.stringify, cause that, well, stringifies the JSON. You need to use string concatenation with the empty string to get the full 64bit steamID. Just do something like this ""+jsonThingy and you should get the proper result

c00kie17 commented 8 years ago

Thanks a lot I figured it out. I know that this wasnt the right place to post this question but still thank you for the help. Ill be closing the issue now.

Crazy-Duck commented 8 years ago

alright, glad we could help