MCPcopy Create free account
hub / github.com/FlashpointProject/launcher / changeServerFactory

Function changeServerFactory

src/back/responses.ts:2835–2866  ·  view source on GitHub ↗
(state: BackState)

Source from the content-addressed store, hash-verified

2833}
2834
2835function changeServerFactory(state: BackState): (server?: string) => Promise<void> {
2836 return async (server?: string) => {
2837 if (state.serviceInfo) {
2838 if (!server) {
2839 // No server name given, assume the default server
2840 server = state.preferences.server;
2841 }
2842 // Cast to fix type error after if check above
2843 const serverInfo = state.serviceInfo.server.find(s => s.name === server || s.aliases.includes(server as string));
2844 if (serverInfo) {
2845 // Found server info, safely stop the server if it's not the correct one, then run the correct one
2846 const runningServer = state.services.get('server');
2847 if (!runningServer || !('name' in runningServer.info) || runningServer.info.name !== serverInfo.name) {
2848 if (runningServer) {
2849 // Wrong server running, stop it
2850 await removeService(state, 'server');
2851 }
2852 // Start the correct server
2853 log.debug('Launcher', `Changing server to: ${serverInfo.name}`);
2854 state.services.delete('server');
2855 runService(state, 'server', 'Server', state.config.flashpointPath, { env: {
2856 ...process.env,
2857 'PATH': state.pathVar ?? process.env.PATH,
2858 } }, serverInfo);
2859 await promiseSleep(1500);
2860 }
2861 } else {
2862 throw new Error(`Server '${server}' not found`);
2863 }
2864 }
2865 };
2866}
2867
2868/**
2869 * Exits the Flashpoint Launcher safely

Callers 1

registerRequestCallbacksFunction · 0.85

Calls 5

removeServiceFunction · 0.90
runServiceFunction · 0.90
promiseSleepFunction · 0.90
getMethod · 0.80
deleteMethod · 0.80

Tested by

no test coverage detected