Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add „token/password“ and „username“ as optional parameters #525

Closed
Vito0912 opened this issue Jan 30, 2024 · 5 comments
Closed

add „token/password“ and „username“ as optional parameters #525

Vito0912 opened this issue Jan 30, 2024 · 5 comments

Comments

@Vito0912
Copy link
Contributor

Currently, Gamedig primarily supports fetching information from public game servers. However, there is the need to access private or "semi-public" APIs for some games. These APIs, unlike public ones, require specific credentials for access.

Examples: Specific Game Examples and Requirements
Factorio: This game does not support standard server querying methods (Afaik). However, it is possible to fetch server information through the game's server list API, which requires a username and token for access. Incorporating this functionality into Gamedig would significantly enhance our ability to interact with Factorio servers.
Farming Simulator: Similar to Factorio, Farming Simulator servers allow extraction of certain information via an API, but this again necessitates a token provided by the server owner. (As far as I know. I did not try this one)

Proposed Solution
I propose to extend Gamedig's capabilities to include support for these types of semi-public APIs. This would involve:

  • Implementing a method to allow the use of required credentials (like username and token for Factorio, token for Farming Simulator) in the server query process. My idea would be to add a „token“ and „username“ as an optional parameter.

Impact and Benefits
By integrating this feature, Gamedig would become more versatile and useful for a broader range of games, especially those that rely on private or semi-public APIs for server information.

@podrivo
Copy link
Contributor

podrivo commented Jan 30, 2024

Hey @Vito0912!

Do you have documentation about this for Factorio or Farming Simulator?

There's an ongoing issue for Factorio (#331) and it seems there is a public querying option, but not sure it's working on all servers. Also, we couldn't find any documentation about this on the internet, so if you could send us to where you found this info, it would be crucial for us to implement.

Thank you!

@Vito0912
Copy link
Contributor Author

This is the code I currently use. My hope is that I can use it gamedig rather than creating a new own logic for such games. I have no example for Farming Simulator (but I saw that there is an API-Key for it too) - I don´t find the link to the screenshot.

import fetch from 'node-fetch';

function getApiUrl() {
    return `https://multiplayer.factorio.com/get-games?username=${process.env.FCUSERNAME}&token=${process.env.FCTOKEN}`;
}

export async function findGameByName(gameName: string) {
    try {
        const response = await fetch(getApiUrl());
        const gamesJson = await response.json();
        const games: { name: string; }[] = gamesJson as { name: string; }[]; // explicitly type gamesJson as an array of objects with a name property
        return games.find((game: { name: string; }) => game.name === gameName);
    } catch (error) {
        console.error('Error fetching games:', error);
        return undefined;
    }
}

I'd like to mention that my expertise in Node.js/TypeScript is limited, as I primarily use them occasionally for creating Discord bots. Consequently, my code may not be optimized. Thats why I cannot (or more don´t want) to add it myself, because the chance that I break something is high

@Vito0912
Copy link
Contributor Author

I just came across the issue you pointed out. Interestingly, the link mentioned there seems more useful since it bypasses the need for any authorization. I'm curious, why wasn't this option pursued? - Even if it does not contain ALL servers.

I stumbled upon it in a forum (my link), though it appears to be somewhat of a hidden gem – not really meant for widespread public use, or outside the game, I believe. While I don't have any official documentation on hand, my understanding is that to operate and validate a server, a connection to their main server is necessary. This leads me to think that it probably covers all the public servers too. To be listed, you need to connect to their servers I assume from the logs of my server.

  56.305 Info UDPSocket.cpp:33: Opening socket at (IP ADDR:({0.0.0.0:34197}))
  56.306 Hosting game at IP ADDR:({0.0.0.0:34197})
  56.306 Info HttpSharedState.cpp:58: Downloading https://auth.factorio.com/generate-server-padlock-2?api_version=6
  56.451 Info AuthServerConnector.cpp:96: Obtained serverPadlock for serverHash (SOMEHASH) from the auth server.
  56.452 Info ServerMultiplayerManager.cpp:816: updateTick(5040001) changing state from(CreatingGame) to(InGame)
  56.459 Info ServerRouter.cpp:668: Asking pingpong servers (pingpong1.factorio.com:34197, pingpong2.factorio.com:34197, pingpong3.factorio.com:34197, pingpong4.factorio.com:34197) for own address
  56.459 Info UDPSocket.cpp:45: Opening socket for broadcast
  56.460 Info CommandLineMultiplayer.cpp:301: Maximum segment size = 100; minimum segment size = 25; maximum-segment-size peer count = 10; minimum-segment-size peer count = 20

By the way, I managed to locate my server using the method outlined in post #331.

@CosminPerRam
Copy link
Member

I'm curious, why wasn't this option pursued?

Multiple factors could have affected this, but my personal one is lack of time.
It indeed is a partial solution and isn't too hard to implement, contributions would be welcome if you'd want to take a try at it (:

@CosminPerRam
Copy link
Member

CosminPerRam commented Jan 31, 2024

Hello, as far as I understand this PR suggests to add these mentioned optional parameters when we'll add an api that will use them?
Cause if so this is already the case with Terraria (TShock) and nonetheless, if feasible, we will add apis that'll require extra user-provided informations (such as token/logins).

The details provided and further down the comments were suggesting you were more interested in the Factorio support (which would be out of the scope of this issue and more inline with #331 (also thanks for taking care of it!)).

@Vito0912 Vito0912 closed this as completed Feb 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants