channel ownership base, part 1
Fleshing out the new channel ownership feature, along with a typo fix and small syntax updates.
A claim can now be staked with /claimchannel, a channel owner may change a trip's level using /setlevel
To do: unclaimchannel, setmotd, makeprivate, makepublic, renewclaim, garbage keeping, update mod commands to accept channelOwner and channelModerator, etc
2024-01-05 16:30:28 +08:00
|
|
|
import {
|
|
|
|
existsSync,
|
|
|
|
readFileSync,
|
|
|
|
} from 'node:fs';
|
|
|
|
import {
|
|
|
|
Low,
|
|
|
|
JSONFile,
|
|
|
|
} from 'lowdb';
|
|
|
|
import {
|
|
|
|
CoreApp,
|
|
|
|
} from 'hackchat-server';
|
2024-01-18 01:19:06 +08:00
|
|
|
import {
|
|
|
|
ChannelCheckInterval,
|
|
|
|
} from './commands/utility/_Constants.js';
|
|
|
|
import {
|
|
|
|
purgeInactiveChannels,
|
|
|
|
} from './commands/utility/_Channels.js';
|
2022-06-23 00:32:51 +08:00
|
|
|
|
|
|
|
// required file paths
|
|
|
|
const SessionLocation = './session.key';
|
|
|
|
const SaltLocation = './salt.key';
|
|
|
|
const AppConfigLocation = './config.json';
|
|
|
|
|
|
|
|
// verify required files exist
|
channel ownership base, part 1
Fleshing out the new channel ownership feature, along with a typo fix and small syntax updates.
A claim can now be staked with /claimchannel, a channel owner may change a trip's level using /setlevel
To do: unclaimchannel, setmotd, makeprivate, makepublic, renewclaim, garbage keeping, update mod commands to accept channelOwner and channelModerator, etc
2024-01-05 16:30:28 +08:00
|
|
|
if (existsSync(SessionLocation) === false) {
|
2022-06-23 00:32:51 +08:00
|
|
|
throw Error('Missing session key, you may need to run: npm run config');
|
|
|
|
}
|
|
|
|
|
channel ownership base, part 1
Fleshing out the new channel ownership feature, along with a typo fix and small syntax updates.
A claim can now be staked with /claimchannel, a channel owner may change a trip's level using /setlevel
To do: unclaimchannel, setmotd, makeprivate, makepublic, renewclaim, garbage keeping, update mod commands to accept channelOwner and channelModerator, etc
2024-01-05 16:30:28 +08:00
|
|
|
if (existsSync(SaltLocation) === false) {
|
2022-06-23 00:32:51 +08:00
|
|
|
throw Error('Missing salt key, you may need to run: npm run config');
|
|
|
|
}
|
|
|
|
|
channel ownership base, part 1
Fleshing out the new channel ownership feature, along with a typo fix and small syntax updates.
A claim can now be staked with /claimchannel, a channel owner may change a trip's level using /setlevel
To do: unclaimchannel, setmotd, makeprivate, makepublic, renewclaim, garbage keeping, update mod commands to accept channelOwner and channelModerator, etc
2024-01-05 16:30:28 +08:00
|
|
|
if (existsSync(AppConfigLocation) === false) {
|
2022-06-23 00:32:51 +08:00
|
|
|
throw Error('Missing config, you may need to run: npm run config');
|
|
|
|
}
|
|
|
|
|
|
|
|
// build main hack chat server
|
|
|
|
const server = new CoreApp({
|
|
|
|
configPath: './.hcserver.json',
|
|
|
|
logErrDetailed: true,
|
|
|
|
lang: 'en',
|
|
|
|
});
|
|
|
|
|
|
|
|
// load sessoin key data
|
channel ownership base, part 1
Fleshing out the new channel ownership feature, along with a typo fix and small syntax updates.
A claim can now be staked with /claimchannel, a channel owner may change a trip's level using /setlevel
To do: unclaimchannel, setmotd, makeprivate, makepublic, renewclaim, garbage keeping, update mod commands to accept channelOwner and channelModerator, etc
2024-01-05 16:30:28 +08:00
|
|
|
server.sessionKey = readFileSync(SessionLocation);
|
2022-06-23 00:32:51 +08:00
|
|
|
|
|
|
|
// load salt key data
|
channel ownership base, part 1
Fleshing out the new channel ownership feature, along with a typo fix and small syntax updates.
A claim can now be staked with /claimchannel, a channel owner may change a trip's level using /setlevel
To do: unclaimchannel, setmotd, makeprivate, makepublic, renewclaim, garbage keeping, update mod commands to accept channelOwner and channelModerator, etc
2024-01-05 16:30:28 +08:00
|
|
|
server.saltKey = readFileSync(SaltLocation);
|
2022-06-23 00:32:51 +08:00
|
|
|
|
|
|
|
// load the configuration data
|
|
|
|
const adapter = new JSONFile(AppConfigLocation);
|
|
|
|
server.appConfig = new Low(adapter);
|
|
|
|
await server.appConfig.read();
|
|
|
|
|
2024-01-18 01:19:06 +08:00
|
|
|
// create channel memory management job
|
|
|
|
setInterval(() => {
|
|
|
|
purgeInactiveChannels(server.appConfig.data);
|
|
|
|
}, ChannelCheckInterval);
|
|
|
|
|
|
|
|
// @todo create storage management job
|
|
|
|
|
|
|
|
// start the server
|
2022-06-23 00:32:51 +08:00
|
|
|
server.init();
|
|
|
|
|
|
|
|
console.log('Websocket server ready');
|