2021-09-16 01:50:44 +02:00
|
|
|
import { ITerminal } from "../ITerminal";
|
2021-09-17 08:58:02 +02:00
|
|
|
import { IRouter } from "../../ui/Router";
|
2021-09-16 01:50:44 +02:00
|
|
|
import { IPlayer } from "../../PersonObjects/IPlayer";
|
|
|
|
import { BaseServer } from "../../Server/BaseServer";
|
|
|
|
import { getServerOnNetwork } from "../../Server/ServerHelpers";
|
2021-12-20 21:48:26 +01:00
|
|
|
import { GetServer } from "../../Server/AllServers";
|
2022-01-05 02:44:14 +01:00
|
|
|
import { Server } from "../../Server/Server";
|
2021-09-16 01:50:44 +02:00
|
|
|
|
|
|
|
export function connect(
|
|
|
|
terminal: ITerminal,
|
2021-09-17 08:58:02 +02:00
|
|
|
router: IRouter,
|
2021-09-16 01:50:44 +02:00
|
|
|
player: IPlayer,
|
|
|
|
server: BaseServer,
|
2021-12-03 20:44:32 +01:00
|
|
|
args: (string | number | boolean)[],
|
2021-09-16 01:50:44 +02:00
|
|
|
): void {
|
|
|
|
// Disconnect from current server in terminal and connect to new one
|
|
|
|
if (args.length !== 1) {
|
2021-12-20 21:48:26 +01:00
|
|
|
terminal.error("Incorrect usage of connect command. Usage: connect [hostname]");
|
2021-09-16 01:50:44 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-10-07 23:55:49 +02:00
|
|
|
const hostname = args[0] + "";
|
2021-09-16 01:50:44 +02:00
|
|
|
|
|
|
|
for (let i = 0; i < server.serversOnNetwork.length; i++) {
|
|
|
|
const other = getServerOnNetwork(server, i);
|
|
|
|
if (other === null) throw new Error(`Server on network should not be null`);
|
2021-10-07 23:55:49 +02:00
|
|
|
if (other.hostname == hostname) {
|
|
|
|
terminal.connectToServer(player, hostname);
|
2021-09-16 01:50:44 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-05 02:44:14 +01:00
|
|
|
const other = GetServer(hostname);
|
|
|
|
if (other !== null) {
|
|
|
|
if (other instanceof Server && other.backdoorInstalled) {
|
|
|
|
terminal.connectToServer(player, hostname);
|
|
|
|
return;
|
|
|
|
}
|
2022-04-07 01:30:08 +02:00
|
|
|
terminal.error(
|
|
|
|
`Cannot directly connect to ${hostname}. Make sure the server is backdoored or adjacent to your current Server`,
|
|
|
|
);
|
2021-12-20 21:48:26 +01:00
|
|
|
} else {
|
|
|
|
terminal.error("Host not found");
|
|
|
|
}
|
2021-09-16 01:50:44 +02:00
|
|
|
}
|