mirror of
https://github.com/exogen/t2-mapper.git
synced 2026-07-16 00:44:59 +00:00
bug fixes, add player name support
This commit is contained in:
parent
e4ae265184
commit
d9b5e30831
75 changed files with 1139 additions and 544 deletions
|
|
@ -116,6 +116,8 @@ export async function computeGameCRC(
|
|||
let filesFound = 0;
|
||||
let filesMissing = 0;
|
||||
|
||||
const startTime = performance.now();
|
||||
|
||||
console.log(
|
||||
`[crc] starting computation: seed=0x${(seed >>> 0).toString(16)}, ` +
|
||||
`${sorted.length} ShapeBaseData datablocks (of ${datablocks.length} total), ` +
|
||||
|
|
@ -166,9 +168,11 @@ export async function computeGameCRC(
|
|||
|
||||
crc = (crc + totalSize) >>> 0;
|
||||
|
||||
const elapsed = performance.now() - startTime;
|
||||
|
||||
console.log(
|
||||
`[crc] RESULT: ${filesFound} files CRC'd, ${filesMissing} missing, ` +
|
||||
`crc=0x${crc.toString(16)}, totalSize=${totalSize}`,
|
||||
`crc=0x${crc.toString(16)}, totalSize=${totalSize}, elapsed=${elapsed.toFixed(0)}ms`,
|
||||
);
|
||||
|
||||
return { crc, totalSize };
|
||||
|
|
|
|||
|
|
@ -79,11 +79,15 @@ export class GameConnection extends EventEmitter<GameConnectionEvents> {
|
|||
private smoothedPing = 0;
|
||||
private lastPingEmit = 0;
|
||||
|
||||
constructor(address: string) {
|
||||
/** Warrior name to send in the ConnectRequest. */
|
||||
private warriorName: string;
|
||||
|
||||
constructor(address: string, options?: { warriorName?: string }) {
|
||||
super();
|
||||
const [host, portStr] = address.split(":");
|
||||
this.host = host;
|
||||
this.port = parseInt(portStr, 10);
|
||||
this.warriorName = options?.warriorName || "";
|
||||
|
||||
// Wire up packet delivery notifications for event retransmission.
|
||||
this.protocol.onNotify = (packetSeq, acked) => {
|
||||
|
|
@ -316,7 +320,7 @@ export class GameConnection extends EventEmitter<GameConnectionEvents> {
|
|||
|
||||
/** Build the connection argv (name, race/gender, skin, voice, voicePitch). */
|
||||
private buildConnectArgv(): string[] {
|
||||
const name = process.env.T2_ACCOUNT_NAME || "Observer";
|
||||
const name = this.warriorName || process.env.T2_ACCOUNT_NAME || "Observer";
|
||||
return [
|
||||
name, // player name
|
||||
"Male Human", // race/gender
|
||||
|
|
|
|||
|
|
@ -79,6 +79,7 @@ wss.on("connection", (ws) => {
|
|||
|
||||
let gameConnection: GameConnection | null = null;
|
||||
let lastJoinAddress: string | null = null;
|
||||
let lastWarriorName: string | undefined;
|
||||
let retryCount = 0;
|
||||
let retryTimer: ReturnType<typeof setTimeout> | null = null;
|
||||
|
||||
|
|
@ -86,12 +87,12 @@ wss.on("connection", (ws) => {
|
|||
const RETRY_DELAY_MS = 6000;
|
||||
const RETRYABLE_REASONS = ["Server is cycling mission"];
|
||||
|
||||
async function connectToServer(ws: WebSocket, address: string): Promise<void> {
|
||||
async function connectToServer(ws: WebSocket, address: string, warriorName?: string): Promise<void> {
|
||||
if (gameConnection) {
|
||||
gameConnection.disconnect();
|
||||
}
|
||||
|
||||
gameConnection = new GameConnection(address);
|
||||
gameConnection = new GameConnection(address, { warriorName });
|
||||
|
||||
// Set mapName from the cached server list if available.
|
||||
const cachedServer = cachedServers.find(
|
||||
|
|
@ -135,7 +136,7 @@ wss.on("connection", (ws) => {
|
|||
retryTimer = setTimeout(() => {
|
||||
retryTimer = null;
|
||||
if (lastJoinAddress === address && ws.readyState === WebSocket.OPEN) {
|
||||
connectToServer(ws, address);
|
||||
connectToServer(ws, address, lastWarriorName);
|
||||
}
|
||||
}, RETRY_DELAY_MS);
|
||||
return;
|
||||
|
|
@ -242,7 +243,7 @@ wss.on("connection", (ws) => {
|
|||
}
|
||||
|
||||
case "joinServer": {
|
||||
relayLog.info({ address: message.address }, "Join server requested");
|
||||
relayLog.info({ address: message.address, warriorName: message.warriorName }, "Join server requested");
|
||||
if (gameConnection) {
|
||||
relayLog.info("Disconnecting existing game connection");
|
||||
gameConnection.disconnect();
|
||||
|
|
@ -253,8 +254,9 @@ wss.on("connection", (ws) => {
|
|||
}
|
||||
retryCount = 0;
|
||||
lastJoinAddress = message.address;
|
||||
lastWarriorName = message.warriorName;
|
||||
|
||||
await connectToServer(ws, message.address);
|
||||
await connectToServer(ws, message.address, message.warriorName);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/** Messages from browser client to relay server. */
|
||||
export type ClientMessage =
|
||||
| { type: "listServers" }
|
||||
| { type: "joinServer"; address: string }
|
||||
| { type: "joinServer"; address: string; warriorName?: string }
|
||||
| { type: "disconnect" }
|
||||
| { type: "sendMove"; move: ClientMove }
|
||||
| { type: "sendCommand"; command: string; args: string[] }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue