treason icon indicating copy to clipboard operation
treason copied to clipboard

gamestats api?

Open js802025 opened this issue 3 years ago • 13 comments

I was wondering if there was a way to obstain the statistics from a game, I see that you do collect them. Is this a feature or maybe something that you'd be open to?

js802025 avatar Mar 09 '21 23:03 js802025

What kind of statistics are you talking about? How would you like to obtain them?

octachrome avatar Mar 10 '21 07:03 octachrome

I was thinking about different ways of doing this but like a way to get like a players total wins and successful challenges, i don’t know if you kept the ranking feature enabled tho. I was going to try and export each game as it happens but it’s probably better to retrieve that information through the database for a specific player and then return it

Sent from my iPhone

On Mar 10, 2021, at 1:31 AM, Chris Brown @.***> wrote:

 What kind of statistics are you talking about? How would you like to obtain them?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

js802025 avatar Mar 10 '21 13:03 js802025

I stopped collecting player statistics and computing ranks etc because the database was causing the server to become unstable. So the database is disabled and this information is not available at the moment.

octachrome avatar Mar 10 '21 17:03 octachrome

I’ll try and look into a better way and if I find something I’ll let you know

Sent from my iPhone

On Mar 10, 2021, at 11:07 AM, Chris Brown @.***> wrote:

 I stopped collecting player statistics and computing ranks etc because the database was causing the server to become unstable. So the database is disabled and this information is not available at the moment.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

js802025 avatar Mar 10 '21 21:03 js802025

Do you particularly want an API for this, rather than just displaying a player's stats in the UI? If so, why?

octachrome avatar Mar 10 '21 21:03 octachrome

UI stats would be cool too, I was just thinking of ways to use the game information (perhaps a discord stats bot.

Sent from my iPhone

On Mar 10, 2021, at 3:27 PM, Chris Brown @.***> wrote:

 Do you particularly want an API for this, rather than just displaying a player's stats in the UI? If so, why?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

js802025 avatar Mar 10 '21 21:03 js802025

Is playerId a constant in between sessions, or is it generated every time

js802025 avatar Mar 20 '21 18:03 js802025

playerId is a unique constant identifier for the current player. It is stored in your local storage, so that the server can remember who you are. If I remember correctly, you never see another player's id, only your own, because it is effectively a login token. Knowing another player's id would allow you to impersonate them.

octachrome avatar Mar 20 '21 19:03 octachrome

Is there a way to “login” on multiple devices, I’m trying to implement a player base stats database. I currently have a working one based on name but for a major scale that would not be effective

Sent from my iPhone

On Mar 20, 2021, at 2:18 PM, Chris Brown @.***> wrote:

 playerId is a unique constant identifier for the current player. It is stored in your local storage, so that the server can remember who you are. If I remember correctly, you never see another player's id, only your own, because it is effectively a login token. Knowing another player's id would allow you to impersonate them.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

js802025 avatar Mar 20 '21 20:03 js802025

You can hack it for testing, if this is what you mean, by using the browser dev tools to modify your player id in local storage. There is currently no way for regular players to log in from different devices.

You can't query a player's stats by his player id because ids are secret. You can't query by his name because it is not unique. There is no persistent database, so there is no way to enforce that all players have unique names.

If I were making a player stats api I would start by assigning every player who logs in a public id, i.e. a username, which would be discoverable in the ui. When you log in, your private id would be used to look up your username in the database, and one would be created if it did not exist. For simplicity I would generate the usernames e.g. as random number/letter sequences, instead of making each player pick a username. The username would then be used in any api queries.

To be completely honest I am not very keen on this feature and I would only merge it into the public game if it is rock solid. The previous stats tracking code caused big performance issues so anything new must be fast with a low memory overhead. Just giving you fair warning before you invest a lot of time.

octachrome avatar Mar 20 '21 21:03 octachrome

I’m aware which is why I am sorting by player and not by game. I also am running this for friends so we can track. As for username and stuff I have an idea that might work. I’ll let you know if I find a way. Thanks!

Sent from my iPhone

On Mar 20, 2021, at 4:00 PM, Chris Brown @.***> wrote:

 You can hack it for testing, if this is what you mean, by using the browser dev tools to modify your player id in local storage. There is currently no way for regular players to log in from different devices.

You can't query a player's stats by his player id because ids are secret. You can't query by his name because it is not unique. There is no persistent database, so there is no way to enforce that all players have unique names.

If I were making a player stats api I would start by assigning every player who logs in a public id, i.e. a username, which would be discoverable in the ui. When you log in, your private id would be used to look up your username in the database, and one would be created if it did not exist. For simplicity I would generate the usernames e.g. as random number/letter sequences, instead of making each player pick a username. The username would then be used in any api queries.

To be completely honest I am not very keen on this feature and I would only merge it into the public game if it is rock solid. The previous stats tracking code caused big performance issues so anything new must be fast with a low memory overhead. Just giving you fair warning before you invest a lot of time.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

js802025 avatar Mar 20 '21 23:03 js802025

Where is playerId first defined?

js802025 avatar Mar 21 '21 19:03 js802025

ID is sent to the server from the browser if it exists in local storage. If null, it is generated here: https://github.com/octachrome/treason/blob/master/dataaccess-fake.js#L7

Called from here: https://github.com/octachrome/treason/blob/bee4d21493c85ebb1e1699594a0cadafb9c766f8/server.js#L93

octachrome avatar Mar 21 '21 20:03 octachrome