Skip to content

Commit

Permalink
Readd udp endpoint fix
Browse files Browse the repository at this point in the history
  • Loading branch information
hickorysb committed May 2, 2024
1 parent 651eb21 commit 68dc3b3
Showing 1 changed file with 56 additions and 45 deletions.
101 changes: 56 additions & 45 deletions src/StayInTarkovMod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export class StayInTarkovMod implements IPreAkiLoadMod, IPostDBLoadMod
return CoopMatch.CoopMatches[serverId];
}

private InitializeVariables(container: DependencyContainer): void {
private InitializeVariables(container: DependencyContainer): void {
// ----------------------------------------------------------------
// Initialize & resolve variables
StayInTarkovMod.container = container;
Expand All @@ -113,7 +113,7 @@ export class StayInTarkovMod implements IPreAkiLoadMod, IPostDBLoadMod
this.coopConfig = new CoopConfig();
this.sitConfig = new SITConfig();
this.sitConfig.routeHandler(container);

// Relay server
this.webSocketHandler = new WebSocketHandler(this.coopConfig.webSocketPort, logger);

Expand All @@ -122,7 +122,7 @@ export class StayInTarkovMod implements IPreAkiLoadMod, IPostDBLoadMod

// this.traders.push(new SITCustomTraders(), new CoopGroupTrader(), new UsecTrader(), new BearTrader());
// this.traders.push(new SITCustomTraders());

// UPNP Helper (UPNP map the ports used by AKI and SIT)
new UPNPHelper(this.httpConfig.ip, this.httpConfig.port);
}
Expand Down Expand Up @@ -353,7 +353,7 @@ export class StayInTarkovMod implements IPreAkiLoadMod, IPostDBLoadMod
{
url: "/coop/server/exist",
action: (url, info, sessionId, output) => {

let coopMatch: CoopMatch = null;
for (let cm in CoopMatch.CoopMatches)
{
Expand Down Expand Up @@ -383,7 +383,7 @@ export class StayInTarkovMod implements IPreAkiLoadMod, IPostDBLoadMod
)
return output;
}

if(CoopMatch.CoopMatches[cm].Password !== info.password)
{
output = JSON.stringify(
Expand All @@ -393,18 +393,18 @@ export class StayInTarkovMod implements IPreAkiLoadMod, IPostDBLoadMod
)
return output;
}
}
}

coopMatch = CoopMatch.CoopMatches[cm];
}
logger.info(coopMatch !== null ? "match exists" : "match doesn't exist!");

output = JSON.stringify(coopMatch !== null ?
{
output = JSON.stringify(coopMatch !== null ?
{
ServerId: coopMatch.ServerId
, timestamp: coopMatch.Timestamp
, expectedNumberOfPlayers: coopMatch.ExpectedNumberOfPlayers
, sitVersion: coopMatch.SITVersion
, expectedNumberOfPlayers: coopMatch.ExpectedNumberOfPlayers
, sitVersion: coopMatch.SITVersion
, gameVersion: coopMatch.GameVersion
} : null);
return output;
Expand All @@ -413,7 +413,7 @@ export class StayInTarkovMod implements IPreAkiLoadMod, IPostDBLoadMod
{
url: "/coop/server/join",
action: (url, info, sessionId, output) => {

let coopMatch: CoopMatch = CoopMatch.CoopMatches[info.serverId];
logger.info(coopMatch !== null ? "match exists" : "match doesn't exist!");

Expand All @@ -433,7 +433,7 @@ export class StayInTarkovMod implements IPreAkiLoadMod, IPostDBLoadMod
)
return output;
}

if(coopMatch.Password !== info.password)
{
output = JSON.stringify(
Expand All @@ -444,21 +444,21 @@ export class StayInTarkovMod implements IPreAkiLoadMod, IPostDBLoadMod
return output;
}
}

if(coopMatch.ConnectedUsers.findIndex(x => x == info.profileId) !== -1)
{
if(WebSocketHandler.Instance.webSockets[info.profileId] !== undefined)
{
if(WebSocketHandler.Instance.webSockets[info.profileId].readyState == WebSocket.OPEN)
{
logger.info(`JoinMatch failed: ${info.profileId} is already connected!`);

output = JSON.stringify(
{
alreadyConnected: true
}
)

return output;
}
}
Expand All @@ -470,8 +470,8 @@ export class StayInTarkovMod implements IPreAkiLoadMod, IPostDBLoadMod
logger.info(`Added authorized user: ${info.profileId} in server: ${coopMatch.ServerId}`);
}

output = JSON.stringify(coopMatch !== null ?
{
output = JSON.stringify(coopMatch !== null ?
{
serverId: coopMatch.ServerId,
timestamp: coopMatch.Timestamp,
expectedNumberOfPlayers: coopMatch.ExpectedNumberOfPlayers,
Expand All @@ -490,15 +490,15 @@ export class StayInTarkovMod implements IPreAkiLoadMod, IPostDBLoadMod
{
url: "/coop/server/read/players",
action: (url, info, sessionId, output) => {

// ---------------------------------------------------------------------------------------------------
// This call requires the client to pass what players/bots it knows about to filter the response back!

let coopMatch = this.getCoopMatch(info.serverId);
if(coopMatch == null || coopMatch == undefined)
{
output = JSON.stringify([{ notFound: true }]);
return output;
return output;
}

//
Expand Down Expand Up @@ -529,7 +529,7 @@ export class StayInTarkovMod implements IPreAkiLoadMod, IPostDBLoadMod
coopMatch.ProcessData(item, logger);
}
output = JSON.stringify({});
return output;
return output;
}

console.error("/coop/server/update -- no info or serverId provided");
Expand All @@ -546,7 +546,7 @@ export class StayInTarkovMod implements IPreAkiLoadMod, IPostDBLoadMod
console.error("/coop/server/update -- no coopMatch found to update");

output = JSON.stringify({});
return output;
return output;
}

if(info.m == "PlayerSpawn" && info.isAI)
Expand All @@ -555,9 +555,9 @@ export class StayInTarkovMod implements IPreAkiLoadMod, IPostDBLoadMod
}

coopMatch.ProcessData(info, logger);


//

//
// console.log(Date.now() - timeCheck);


Expand All @@ -569,7 +569,7 @@ export class StayInTarkovMod implements IPreAkiLoadMod, IPostDBLoadMod
url: "/coop/server/delete",
action: (url, info, sessionId, output) => {
logger.debug(`Request to delete Coop Server ${info.serverId}`);

const response = { response: "NOT_EXIST" };
if(CoopMatch.CoopMatches[info.serverId] !== undefined) {

Expand Down Expand Up @@ -598,7 +598,7 @@ export class StayInTarkovMod implements IPreAkiLoadMod, IPostDBLoadMod
},
{
url: "/coop/get-invites",
action: (url: string, info: any, sessionID: string, output: string): any =>
action: (url: string, info: any, sessionID: string, output: string): any =>
{
logger.info("Getting Coop Server Invites")
const obj = {
Expand All @@ -613,24 +613,35 @@ export class StayInTarkovMod implements IPreAkiLoadMod, IPostDBLoadMod
},
{
url: "/coop/server-status",
action: (url, info, sessionId, output) =>
action: (url, info, sessionId, output) =>
{
logger.info("Getting Coop Server Match Status")
return "";
}
},
{
url: "/coop/raid/udp/join",
action: (url, info, sessionId, output) =>
{
const match = CoopMatch.CoopMatches[info.serverId]
if(match !== undefined) {
match.PlayerJoined(info.profileId)
}
return JSON.stringify({});
}
},
],
"sit-coop"
// "aki"
);

// Hook up to existing AKI static route
staticRouterModService.registerStaticRouter(
"MatchStaticRouter-SIT",
[
{
url: "/client/match/group/status",
action: (url: string, info: any, sessionID: string, output: string): any =>
action: (url: string, info: any, sessionID: string, output: string): any =>
{
logger.info("/client/match/group/status")
logger.info("Getting Coop Server Match Status")
Expand All @@ -645,15 +656,15 @@ export class StayInTarkovMod implements IPreAkiLoadMod, IPostDBLoadMod
},
{
url: "/client/game/start",
action: (url: string, info: any, sessionID: string, output: string): any =>
action: (url: string, info: any, sessionID: string, output: string): any =>
{
new SITHelpers().fixProfileEquipmentId(container, sessionID);
return StayInTarkovMod.Instance.gameCallbacks.gameStart(url, info, sessionID);
}
},
{
url: "/client/game/profile/create",
action: (url: string, info: any, sessionID: string, output: string): any =>
action: (url: string, info: any, sessionID: string, output: string): any =>
{
const profileC = StayInTarkovMod.Instance.profileCallbacks.createProfile(url, info, sessionID);
new SITHelpers().fixProfileEquipmentId(container, sessionID);
Expand All @@ -663,7 +674,7 @@ export class StayInTarkovMod implements IPreAkiLoadMod, IPostDBLoadMod
},
{
url: "/client/match/group/exit_from_menu",
action: (url: string, info: any, sessionID: string, output: string): any =>
action: (url: string, info: any, sessionID: string, output: string): any =>
{
logger.info("exit_from_menu")
output = JSON.stringify({});
Expand All @@ -672,7 +683,7 @@ export class StayInTarkovMod implements IPreAkiLoadMod, IPostDBLoadMod
}
,{
url: "/client/match/group/exit_from_menu",
action: (url: string, info: any, sessionID: string, output: string): any =>
action: (url: string, info: any, sessionID: string, output: string): any =>
{
logger.info("exit_from_menu")
output = JSON.stringify({});
Expand All @@ -681,7 +692,7 @@ export class StayInTarkovMod implements IPreAkiLoadMod, IPostDBLoadMod
},
{
url: "/client/raid/person/killed",
action: (url: string, info: any, sessionID: string, output: string): any =>
action: (url: string, info: any, sessionID: string, output: string): any =>
{
logger.info("Person has been Killed!")
console.log(info);
Expand All @@ -691,7 +702,7 @@ export class StayInTarkovMod implements IPreAkiLoadMod, IPostDBLoadMod
},
{
url: "/client/raid/createFriendlyAI",
action: (url: string, info: any, sessionID: string, output: string): any =>
action: (url: string, info: any, sessionID: string, output: string): any =>
{
// logger.info("Person has been Killed!")
console.log(info);
Expand All @@ -701,7 +712,7 @@ export class StayInTarkovMod implements IPreAkiLoadMod, IPostDBLoadMod
},
{
url: "/client/match/raid/ready",
action: (url: string, info: any, sessionID: string, output: string): any =>
action: (url: string, info: any, sessionID: string, output: string): any =>
{
console.log(url);
console.log(info);
Expand All @@ -712,7 +723,7 @@ export class StayInTarkovMod implements IPreAkiLoadMod, IPostDBLoadMod
},
{
url: "/client/match/raid/not-ready",
action: (url: string, info: any, sessionID: string, output: string): any =>
action: (url: string, info: any, sessionID: string, output: string): any =>
{
console.log(url);
console.log(info);
Expand All @@ -723,7 +734,7 @@ export class StayInTarkovMod implements IPreAkiLoadMod, IPostDBLoadMod
},
{
url: "/client/match/group/invite/cancel-all",
action: (url: string, info: any, sessionID: string, output: string): any =>
action: (url: string, info: any, sessionID: string, output: string): any =>
{
console.log(url);
console.log(info);
Expand All @@ -734,7 +745,7 @@ export class StayInTarkovMod implements IPreAkiLoadMod, IPostDBLoadMod
},
{
url: "/client/match/available",
action: (url: string, info: any, sessionID: string, output: string): any =>
action: (url: string, info: any, sessionID: string, output: string): any =>
{
console.log(url);
console.log(info);
Expand All @@ -749,18 +760,18 @@ export class StayInTarkovMod implements IPreAkiLoadMod, IPostDBLoadMod

}



postDBLoad(container: DependencyContainer): void {
StayInTarkovMod.container = container;

const dbTables = StayInTarkovMod.container.resolve<DatabaseServer>("DatabaseServer").getTables();
dbTables.locales.global["en"]["Attention! This is a Beta version of Escape from Tarkov for testing purposes."]
dbTables.locales.global["en"]["Attention! This is a Beta version of Escape from Tarkov for testing purposes."]
= "Welcome to Stay in Tarkov. The OFFLINE Coop mod for SPT-Aki.";

dbTables.locales.global["en"]["NDA free warning"]
dbTables.locales.global["en"]["NDA free warning"]
= "To Host/Join a game. You must select a map and go to the last screen to use the Server Browser. Have fun!";

const locations = dbTables.locations;

// Open All Exfils. This is a SIT >mod< feature. Has nothing to do with the Coop module. Can be turned off in config/SITConfig.json
Expand Down Expand Up @@ -791,7 +802,7 @@ export class StayInTarkovMod implements IPreAkiLoadMod, IPostDBLoadMod
"woods",
"sandbox"
];

// Loop through each location
for (const location of locationNames)
{
Expand All @@ -806,8 +817,8 @@ export class StayInTarkovMod implements IPreAkiLoadMod, IPostDBLoadMod
{
locations[location].base.exits[extract].EntryPoints = newEntryPoint;
}


// If this is a train extract... Move on to the next extract.
if (locations[location].base.exits[extract].PassageRequirement === "Train")
{
Expand Down

0 comments on commit 68dc3b3

Please sign in to comment.