Season and holiday configuration options (#138)

* Added configuration options to change the season and holiday (per-server and globally) in config.json
* Added documentation on newly added configuration options
* Updated parseHoliday to recognize all current holidays
* Moved parseSeason and parseHoliday functions from server/commands.ts to common/utils.ts
This commit is contained in:
Thorn-Rose
2019-09-26 18:49:22 -05:00
committed by Eliot Partridge
parent a7d6a9f1e5
commit 8a4c8198b8
8 changed files with 43 additions and 25 deletions
+4
View File
@@ -164,6 +164,8 @@ Add `config.json` file in root directory with following content. You can use `co
}, },
"facebookAppId": "<facebook_id>", // optional facebook app link "facebookAppId": "<facebook_id>", // optional facebook app link
"assetsPath": "<path_to_graphics_assets>", // optional, for asset generation "assetsPath": "<path_to_graphics_assets>", // optional, for asset generation
"season": "spring", // optional, defaults to spring; season for all servers, seasons are "spring", "summer", "autumn" and "winter"
"holiday": "none", // optional, defaults to none; holiday for all servers, holidays are "none", "halloween", "christmas", "stpatricks" and "easter"
"oauth": { "oauth": {
"google": { "google": {
"clientID": "<CLIENT_ID_HERE>", "clientID": "<CLIENT_ID_HERE>",
@@ -179,6 +181,8 @@ Add `config.json` file in root directory with following content. You can use `co
"local": "localhost:8090", "local": "localhost:8090",
"name": "Dev server", "name": "Dev server",
"desc": "Development server", "desc": "Development server",
"season": "summer", // optional, defaults to summer, seasons are "spring", "summer", "autumn" and "winter"
"holiday": "none", // optional, defaults to none, holidays are "none", "halloween", "christmas", "stpatricks" and "easter"
"flag": "test", // optional flag ("test", "star" or space separated list of country flags) "flag": "test", // optional flag ("test", "star" or space separated list of country flags)
"flags": { // optional feature flags "flags": { // optional feature flags
"test": true, // test server "test": true, // test server
+4
View File
@@ -19,6 +19,8 @@
} }
}, },
"assetsPath": "assets-source", "assetsPath": "assets-source",
"season": "spring",
"holiday": "none",
"servers": [ "servers": [
{ {
"id": "test", "id": "test",
@@ -26,6 +28,8 @@
"path": "/s00/ws", "path": "/s00/ws",
"local": "localhost:8090", "local": "localhost:8090",
"name": "Test server", "name": "Test server",
"season": "spring",
"holiday": "none",
"desc": "Testing server", "desc": "Testing server",
"flags": { "flags": {
"test": true "test": true
+2
View File
@@ -150,6 +150,8 @@ export interface ServerConfig {
name: string; name: string;
desc: string; desc: string;
flag: string; flag: string;
season?: string;
holiday?: string;
host?: string; host?: string;
alert?: string; alert?: string;
require?: string; require?: string;
+1 -1
View File
@@ -1,6 +1,6 @@
import { Season, Holiday } from './interfaces'; import { Season, Holiday } from './interfaces';
export const SEASON: Season = Season.Autumn; export const SEASON: Season = Season.Spring;
export const HOLIDAY: Holiday = Holiday.None; export const HOLIDAY: Holiday = Holiday.None;
export const SECOND = 1000; export const SECOND = 1000;
+24 -1
View File
@@ -1,6 +1,6 @@
import { HttpErrorResponse } from '@angular/common/http'; import { HttpErrorResponse } from '@angular/common/http';
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
import { Point, Rect, Entity, Dict } from './interfaces'; import { Point, Rect, Entity, Dict, Holiday, Season } from './interfaces';
import { tileWidth, tileHeight, SECOND, MINUTE, HOUR, DAY } from './constants'; import { tileWidth, tileHeight, SECOND, MINUTE, HOUR, DAY } from './constants';
import { ACCESS_ERROR, NOT_FOUND_ERROR, OFFLINE_ERROR, PROTECTION_ERROR } from './errors'; import { ACCESS_ERROR, NOT_FOUND_ERROR, OFFLINE_ERROR, PROTECTION_ERROR } from './errors';
@@ -516,6 +516,29 @@ export function processCommand(text: string) {
return { command, args }; return { command, args };
} }
export function parseSeason(value?: string): Season | undefined {
if (!value) return undefined;
switch (value.toLowerCase()) {
case 'spring': return Season.Spring;
case 'summer': return Season.Summer;
case 'autumn': return Season.Autumn;
case 'winter': return Season.Winter;
default: return undefined;
}
}
export function parseHoliday(value?: string): Holiday | undefined {
if (!value) return undefined;
switch (value.toLowerCase()) {
case 'none': return Holiday.None;
case 'halloween': return Holiday.Halloween;
case 'christmas': return Holiday.Christmas;
case 'stpatricks': return Holiday.StPatricks;
case 'easter': return Holiday.Easter;
default: return undefined;
}
}
// events // events
export type AnyEvent = MouseEvent | PointerEvent | TouchEvent; export type AnyEvent = MouseEvent | PointerEvent | TouchEvent;
+2 -21
View File
@@ -1,6 +1,6 @@
import { range, compact, escapeRegExp } from 'lodash'; import { range, compact, escapeRegExp } from 'lodash';
import { import {
MessageType, ChatType, Expression, Eye, Muzzle, Action, Season, Holiday, Weather, toAnnouncementMessageType, MessageType, ChatType, Expression, Eye, Muzzle, Action, Weather, toAnnouncementMessageType,
} from '../common/interfaces'; } from '../common/interfaces';
import { hasRole } from '../common/accountUtils'; import { hasRole } from '../common/accountUtils';
import { butterfly, bat, firefly, cloud, getEntityType, getEntityTypeName } from '../common/entities'; import { butterfly, bat, firefly, cloud, getEntityType, getEntityTypeName } from '../common/entities';
@@ -17,7 +17,7 @@ import {
setEntityExpression, execAction, teleportTo setEntityExpression, execAction, teleportTo
} from './playerUtils'; } from './playerUtils';
import { ServerLiveSettings, GameServerSettings } from '../common/adminInterfaces'; import { ServerLiveSettings, GameServerSettings } from '../common/adminInterfaces';
import { isCommand, processCommand, clamp, flatten, includes, randomPoint } from '../common/utils'; import { isCommand, processCommand, clamp, flatten, includes, randomPoint, parseSeason, parseHoliday } from '../common/utils';
import { createNotifyUpdate, createShutdownServer } from './api/internal'; import { createNotifyUpdate, createShutdownServer } from './api/internal';
import { logger } from './logger'; import { logger } from './logger';
import { pathTo } from './paths'; import { pathTo } from './paths';
@@ -83,25 +83,6 @@ function adminModChat(names: string[], help: string, role: string, type: Message
}); });
} }
function parseSeason(value: string): Season | undefined {
switch (value.toLowerCase()) {
case 'spring': return Season.Spring;
case 'summer': return Season.Summer;
case 'autumn': return Season.Autumn;
case 'winter': return Season.Winter;
default: return undefined;
}
}
function parseHoliday(value: string): Holiday | undefined {
switch (value.toLowerCase()) {
case 'none': return Holiday.None;
case 'halloween': return Holiday.Halloween;
case 'christmas': return Holiday.Christmas;
default: return undefined;
}
}
function parseWeather(value: string): Weather | undefined { function parseWeather(value: string): Weather | undefined {
switch (value.toLowerCase()) { switch (value.toLowerCase()) {
case 'none': return Weather.None; case 'none': return Weather.None;
+2
View File
@@ -29,6 +29,8 @@ export interface AppConfig {
trackingID: string; trackingID: string;
}; };
assetsPath?: string; assetsPath?: string;
season?: string;
holiday?: string;
oauth: { [key: string]: any }; oauth: { [key: string]: any };
servers: ServerConfig[]; servers: ServerConfig[];
facebookAppId?: string; facebookAppId?: string;
+4 -2
View File
@@ -29,6 +29,8 @@ import { liveSettings } from './liveSettings';
import { createIsSuspiciousMessage } from '../common/security'; import { createIsSuspiciousMessage } from '../common/security';
import { updateCharacterState } from './characterUtils'; import { updateCharacterState } from './characterUtils';
import { FriendsService } from './services/friends'; import { FriendsService } from './services/friends';
import { config } from './config';
import { parseSeason, parseHoliday } from '../common/utils';
async function refreshSettings(account: IAccount) { async function refreshSettings(account: IAccount) {
const a = await Account.findOne({ _id: account._id }, 'settings').exec(); const a = await Account.findOne({ _id: account._id }, 'settings').exec();
@@ -59,8 +61,8 @@ export function createServerActionsFactory(
const statesCounter = new CounterService<CharacterState>(10 * SECOND); const statesCounter = new CounterService<CharacterState>(10 * SECOND);
const logChatMessage: LogChat = (client, text, type, ignored, target) => chat(server, client, text, type, ignored, target); const logChatMessage: LogChat = (client, text, type, ignored, target) => chat(server, client, text, type, ignored, target);
world.season = SEASON; world.season = parseSeason(server.season) || parseSeason(config.season) || SEASON;
world.holiday = HOLIDAY; world.holiday = parseHoliday(server.holiday) || parseHoliday(config.holiday) || HOLIDAY;
try { try {
const hidingData = fs.readFileSync(hidingDataPath(server.id), 'utf8'); const hidingData = fs.readFileSync(hidingDataPath(server.id), 'utf8');