diff --git a/README.md b/README.md index 4b11969..c3cfe1e 100644 --- a/README.md +++ b/README.md @@ -164,6 +164,8 @@ Add `config.json` file in root directory with following content. You can use `co }, "facebookAppId": "", // optional facebook app link "assetsPath": "", // 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": "", @@ -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 diff --git a/config-template.json b/config-template.json index b46dab9..33aeb87 100644 --- a/config-template.json +++ b/config-template.json @@ -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 diff --git a/src/ts/common/adminInterfaces.ts b/src/ts/common/adminInterfaces.ts index ed8f2e5..c6939c8 100644 --- a/src/ts/common/adminInterfaces.ts +++ b/src/ts/common/adminInterfaces.ts @@ -150,6 +150,8 @@ export interface ServerConfig { name: string; desc: string; flag: string; + season?: string; + holiday?: string; host?: string; alert?: string; require?: string; diff --git a/src/ts/common/constants.ts b/src/ts/common/constants.ts index 98440ec..bf684b1 100644 --- a/src/ts/common/constants.ts +++ b/src/ts/common/constants.ts @@ -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; diff --git a/src/ts/common/utils.ts b/src/ts/common/utils.ts index 66f0891..5a9fce8 100644 --- a/src/ts/common/utils.ts +++ b/src/ts/common/utils.ts @@ -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; diff --git a/src/ts/server/commands.ts b/src/ts/server/commands.ts index 1e4ede2..cac00c0 100644 --- a/src/ts/server/commands.ts +++ b/src/ts/server/commands.ts @@ -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; diff --git a/src/ts/server/config.ts b/src/ts/server/config.ts index e76cbb9..8c1f494 100644 --- a/src/ts/server/config.ts +++ b/src/ts/server/config.ts @@ -29,6 +29,8 @@ export interface AppConfig { trackingID: string; }; assetsPath?: string; + season?: string; + holiday?: string; oauth: { [key: string]: any }; servers: ServerConfig[]; facebookAppId?: string; diff --git a/src/ts/server/serverActionsManager.ts b/src/ts/server/serverActionsManager.ts index 2235cbe..d165fee 100644 --- a/src/ts/server/serverActionsManager.ts +++ b/src/ts/server/serverActionsManager.ts @@ -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(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');