mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-13 05:23:52 +00:00
Inject server env vars into index.html, including instance id (#2888)
## Description: Should fix the broken 1v1 on staging. The issue was that we had multiple staging environments, and the matchmaker would often route a player to a game on a different staging server, so the client couldn't find the game. So now each deployment has a unique id, and the matchmaker only connects players & servers that have the same instance id. ## Please complete the following: - [x] I have added screenshots for all UI updates - [x] I process any text displayed to the user through translateText() and I've added it to the en.json file - [x] I have added relevant tests to the test directory - [x] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced ## Please put your Discord username so you can be contacted if a bug or regression is found: evan
This commit is contained in:
@@ -524,22 +524,12 @@ export class JoinPrivateLobbyModal extends BaseModal {
|
||||
private async checkArchivedGame(
|
||||
lobbyId: string,
|
||||
): Promise<"success" | "not_found" | "version_mismatch" | "error"> {
|
||||
const archivePromise = fetch(`${getApiBase()}/game/${lobbyId}`, {
|
||||
const archiveResponse = await fetch(`${getApiBase()}/game/${lobbyId}`, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
const gitCommitPromise = fetch(`/commit.txt`, {
|
||||
method: "GET",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
cache: "no-cache",
|
||||
});
|
||||
|
||||
const [archiveResponse, gitCommitResponse] = await Promise.all([
|
||||
archivePromise,
|
||||
gitCommitPromise,
|
||||
]);
|
||||
|
||||
if (archiveResponse.status === 404) {
|
||||
return "not_found";
|
||||
@@ -554,19 +544,11 @@ export class JoinPrivateLobbyModal extends BaseModal {
|
||||
return "version_mismatch";
|
||||
}
|
||||
|
||||
let myGitCommit = "";
|
||||
if (gitCommitResponse.status === 404) {
|
||||
// commit.txt is not found when running locally
|
||||
myGitCommit = "DEV";
|
||||
} else if (gitCommitResponse.status === 200) {
|
||||
myGitCommit = (await gitCommitResponse.text()).trim();
|
||||
} else {
|
||||
console.error("Error getting git commit:", gitCommitResponse.status);
|
||||
return "error";
|
||||
}
|
||||
|
||||
// Allow DEV to join games created with a different version for debugging.
|
||||
if (myGitCommit !== "DEV" && parsed.data.gitCommit !== myGitCommit) {
|
||||
if (
|
||||
window.GIT_COMMIT !== "DEV" &&
|
||||
parsed.data.gitCommit !== window.GIT_COMMIT
|
||||
) {
|
||||
const safeLobbyId = this.sanitizeForLog(lobbyId);
|
||||
console.warn(
|
||||
`Git commit hash mismatch for game ${safeLobbyId}`,
|
||||
|
||||
@@ -160,6 +160,8 @@ function updateAccountNavButton(userMeResponse: UserMeResponse | false) {
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
GIT_COMMIT: string;
|
||||
INSTANCE_ID: string;
|
||||
turnstile: any;
|
||||
enableAds: boolean;
|
||||
PageOS: {
|
||||
|
||||
@@ -120,7 +120,9 @@ export class MatchmakingModal extends BaseModal {
|
||||
private async connect() {
|
||||
const config = await getServerConfigFromClient();
|
||||
|
||||
this.socket = new WebSocket(`${config.jwtIssuer()}/matchmaking/join`);
|
||||
this.socket = new WebSocket(
|
||||
`${config.jwtIssuer()}/matchmaking/join?instance_id=${window.INSTANCE_ID}`,
|
||||
);
|
||||
this.socket.onopen = async () => {
|
||||
console.log("Connected to matchmaking server");
|
||||
setTimeout(() => {
|
||||
|
||||
Reference in New Issue
Block a user