tslint changes

This commit is contained in:
Jeremy Simpson
2019-08-30 01:52:40 -07:00
parent 7603879d35
commit 7f7efbb94b
446 changed files with 70650 additions and 70661 deletions
+56 -56
View File
@@ -10,85 +10,85 @@ import { isServerOffline } from '../serverUtils';
import { getAccountAlertMessage } from '../accountUtils';
export interface Config {
version: string;
host: string;
debug: boolean;
local: boolean;
version: string;
host: string;
debug: boolean;
local: boolean;
}
export type FindServer = (id: string) => InternalGameServerState | undefined;
export type Join = (server: InternalGameServerState, account: IAccount, pony: ICharacter) => Promise<string>;
export type AddOrigin = (account: IAccount, origin: IOriginInfo) => Promise<void>;
export type JoinGame = (
account: IAccount, characterId: string, serverId: string, clientVersion: string, url: string, alert: unknown,
origin: IOriginInfo
account: IAccount, characterId: string, serverId: string, clientVersion: string, url: string, alert: unknown,
origin: IOriginInfo
) => Promise<JoinResponse>;
export const createJoinGame =
(
findServer: FindServer, { version, host, debug, local }: Config, findCharacter: FindCharacter, join: Join,
addOrigin: AddOrigin, hasInvites: HasActiveSupporterInvites
): JoinGame => {
const waiting = new Map<string, { time: Date; characterId: string; }>();
(
findServer: FindServer, { version, host, debug, local }: Config, findCharacter: FindCharacter, join: Join,
addOrigin: AddOrigin, hasInvites: HasActiveSupporterInvites
): JoinGame => {
const waiting = new Map<string, { time: Date; characterId: string; }>();
return async (account, characterId, serverId, clientVersion, url, hasAlert, origin) => {
const accountId = account._id.toString();
return async (account, characterId, serverId, clientVersion, url, hasAlert, origin) => {
const accountId = account._id.toString();
try {
const [server, supporterInvited] = await Promise.all([
findServer(serverId),
hasInvites(account._id),
]);
try {
const [server, supporterInvited] = await Promise.all([
findServer(serverId),
hasInvites(account._id),
]);
if (clientVersion !== version)
throw new UserError(VERSION_ERROR);
if (clientVersion !== version)
throw new UserError(VERSION_ERROR);
if (parse(url).host !== parse(host).host && !debug && !local)
throw new UserError('Invalid data', { message: 'Invalid host', desc: url });
if (parse(url).host !== parse(host).host && !debug && !local)
throw new UserError('Invalid data', { message: 'Invalid host', desc: url });
if (!server)
throw new UserError('Invalid data');
if (!server)
throw new UserError('Invalid data');
if (isServerOffline(server))
throw new UserError('Server is offline');
if (isServerOffline(server))
throw new UserError('Server is offline');
if (server.state.settings.blockJoining)
throw new UserError('Cannot join to the server');
if (server.state.settings.blockJoining)
throw new UserError('Cannot join to the server');
if (!meetsRequirement({ roles: account.roles, supporter: supporterLevel(account), supporterInvited }, server.state.require))
throw new UserError('Server is restricted');
if (!meetsRequirement({ roles: account.roles, supporter: supporterLevel(account), supporterInvited }, server.state.require))
throw new UserError('Server is restricted');
if (!characterId || typeof characterId !== 'string')
throw new UserError('Invalid data', { message: 'Invalid pony ID', desc: `"${characterId}"` });
if (!characterId || typeof characterId !== 'string')
throw new UserError('Invalid data', { message: 'Invalid pony ID', desc: `"${characterId}"` });
const req = waiting.get(accountId);
const time = new Date();
const req = waiting.get(accountId);
const time = new Date();
if (req) {
throw new UserError('Already waiting for join request');
}
if (req) {
throw new UserError('Already waiting for join request');
}
const alert = getAccountAlertMessage(account);
const alert = getAccountAlertMessage(account);
if (alert && !hasAlert) {
return { alert };
}
if (alert && !hasAlert) {
return { alert };
}
waiting.set(accountId, { characterId, time });
waiting.set(accountId, { characterId, time });
const character = await findCharacter(characterId, account._id);
const character = await findCharacter(characterId, account._id);
if (!character) {
throw new UserError('Character does not exist', {
desc: `(join) (account: ${accountId} pony: ${characterId})`
});
}
if (!character) {
throw new UserError('Character does not exist', {
desc: `(join) (account: ${accountId} pony: ${characterId})`
});
}
await addOrigin(account, origin);
const token = await join(server, account, character!);
return { token };
} finally {
waiting.delete(accountId);
}
};
};
await addOrigin(account, origin);
const token = await join(server, account, character!);
return { token };
} finally {
waiting.delete(accountId);
}
};
};