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
"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": {
"google": {
"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",
"name": "Dev 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)
"flags": { // optional feature flags
"test": true, // test server
+4
View File
@@ -19,6 +19,8 @@
}
},
"assetsPath": "assets-source",
"season": "spring",
"holiday": "none",
"servers": [
{
"id": "test",
@@ -26,6 +28,8 @@
"path": "/s00/ws",
"local": "localhost:8090",
"name": "Test server",
"season": "spring",
"holiday": "none",
"desc": "Testing server",
"flags": {
"test": true
+2
View File
@@ -150,6 +150,8 @@ export interface ServerConfig {
name: string;
desc: string;
flag: string;
season?: string;
holiday?: string;
host?: string;
alert?: string;
require?: string;
+1 -1
View File
@@ -1,6 +1,6 @@
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 SECOND = 1000;
+24 -1
View File
@@ -1,6 +1,6 @@
import { HttpErrorResponse } from '@angular/common/http';
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 { ACCESS_ERROR, NOT_FOUND_ERROR, OFFLINE_ERROR, PROTECTION_ERROR } from './errors';
@@ -516,6 +516,29 @@ export function processCommand(text: string) {
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
export type AnyEvent = MouseEvent | PointerEvent | TouchEvent;
+2 -21
View File
@@ -1,6 +1,6 @@
import { range, compact, escapeRegExp } from 'lodash';
import {
MessageType, ChatType, Expression, Eye, Muzzle, Action, Season, Holiday, Weather, toAnnouncementMessageType,
MessageType, ChatType, Expression, Eye, Muzzle, Action, Weather, toAnnouncementMessageType,
} from '../common/interfaces';
import { hasRole } from '../common/accountUtils';
import { butterfly, bat, firefly, cloud, getEntityType, getEntityTypeName } from '../common/entities';
@@ -17,7 +17,7 @@ import {
setEntityExpression, execAction, teleportTo
} from './playerUtils';
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 { logger } from './logger';
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 {
switch (value.toLowerCase()) {
case 'none': return Weather.None;
+2
View File
@@ -29,6 +29,8 @@ export interface AppConfig {
trackingID: string;
};
assetsPath?: string;
season?: string;
holiday?: string;
oauth: { [key: string]: any };
servers: ServerConfig[];
facebookAppId?: string;
+4 -2
View File
@@ -29,6 +29,8 @@ import { liveSettings } from './liveSettings';
import { createIsSuspiciousMessage } from '../common/security';
import { updateCharacterState } from './characterUtils';
import { FriendsService } from './services/friends';
import { config } from './config';
import { parseSeason, parseHoliday } from '../common/utils';
async function refreshSettings(account: IAccount) {
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 logChatMessage: LogChat = (client, text, type, ignored, target) => chat(server, client, text, type, ignored, target);
world.season = SEASON;
world.holiday = HOLIDAY;
world.season = parseSeason(server.season) || parseSeason(config.season) || SEASON;
world.holiday = parseHoliday(server.holiday) || parseHoliday(config.holiday) || HOLIDAY;
try {
const hidingData = fs.readFileSync(hidingDataPath(server.id), 'utf8');