Skip to content

Commit

Permalink
Merge pull request #1125 from solaris-games/dev
Browse files Browse the repository at this point in the history
Update 244
  • Loading branch information
SpacialCircumstances authored Aug 7, 2024
2 parents 539202e + caab7dc commit 1c0174e
Show file tree
Hide file tree
Showing 27 changed files with 475 additions and 55 deletions.
12 changes: 9 additions & 3 deletions client/src/views/game/Create.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@

<p class="mb-1 text-warning" v-if="!(possibleTeamCounts.length || 0)">Warning: It's not possible to form equally sized teams with your current number of player slots.</p>

<select v-if="(possibleTeamCounts.length || 0) > 0" class="form-control" id="teamConquestTeamCount" v-model="settings.conquest.teamsCount" @change="onMaxAllianceTriggerChanged" :disabled="isCreatingGame">
<select v-if="(possibleTeamCounts.length || 0) > 0" class="form-control" id="teamConquestTeamCount" v-model="settings.conquest.teamsCount" @change="onTeamCountChanged" :disabled="isCreatingGame">
<option v-for="opt in possibleTeamCounts" v-bind:key="opt" v-bind:value="opt">
{{ opt }}
</option>
Expand Down Expand Up @@ -977,12 +977,14 @@ export default {
},
onMaxAllianceTriggerChanged (e) {
this.settings.diplomacy.maxAlliances = this.calcMaxAllianceLimit();
this.updatePossibleTeamCounts();
console.warn("Max alliances changed to: " + this.settings.diplomacy.maxAlliances);
},
onTeamCountChanged (e) {
this.settings.diplomacy.maxAlliances = this.calcMaxAllianceLimit();
},
calcMaxAllianceLimit () {
if (this.settings.general.mode === 'teamConquest') {
this.updatePossibleTeamCounts();
const playersPerTeam = this.settings.general.playerLimit / this.settings.conquest.teamsCount;
return playersPerTeam - 1;
}
Expand Down Expand Up @@ -1018,6 +1020,10 @@ export default {
}
},
updatePossibleTeamCounts () {
if (this.settings.general.mode !== 'teamConquest') {
return;
}
const players = this.settings.general.playerLimit;
if (players < 4) {
Expand Down
10 changes: 10 additions & 0 deletions docker-compose.requirements.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
services:

mongo:
image: mongo:6
ports:
- "27017:27017"
volumes:
- "dbdata:/data/db"
volumes:
dbdata:
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ services:
- database

database:
image: mongo
image: mongo:6
volumes:
- ./database_data:/data/db
ports:
Expand Down
7 changes: 3 additions & 4 deletions server/api/controllers/admin.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import ValidationError from '../../errors/validation';
import { DependencyContainer } from '../../services/types/DependencyContainer';
import {AnnouncementRequest} from "../requests/announcements";
import {AnnouncementRequest, parseAnnouncementRequest} from "../requests/announcements";

export default (container: DependencyContainer) => {
return {
Expand Down Expand Up @@ -242,9 +242,8 @@ export default (container: DependencyContainer) => {
},
createAnnouncement: async (req, res, next) => {
try {
// TODO: Validation
const body = req.body as AnnouncementRequest;
await container.announcementService.createAnnouncement(body.title, new Date(body.date), body.content);
const body = parseAnnouncementRequest(req.body);
await container.announcementService.createAnnouncement(body.title, body.date, body.content);

res.sendStatus(201);
return next();
Expand Down
12 changes: 10 additions & 2 deletions server/api/requests/announcements.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import {date, object, string, Validator} from "../validate";

export type AnnouncementRequest = {
title: string;
content: string;
date: string;
};
date: Date;
};

export const parseAnnouncementRequest: Validator<AnnouncementRequest> = object({
title: string,
content: string,
date: date
});
137 changes: 137 additions & 0 deletions server/api/validate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
import ValidationError from "../errors/validation";

export type Validator<T> = (value: any) => T;

const failed = (expected: string, value: any) => {
return new ValidationError(`Expected ${expected}, but got: ${typeof value}`);
}

const primitive = (t: string) => (value: any) => {
if (value === null || value === undefined || typeof value !== t) {
throw failed(t, value);
}

return value;
}

export const string: Validator<string> = primitive("string");

export const number: Validator<number> = primitive("number");

export const boolean: Validator<boolean> = primitive("boolean");

export const bigInt: Validator<BigInt> = primitive("bigint")

export const anyObject: Validator<Object> = primitive("object");

export const date: Validator<Date> = v => {
if (typeof v === "string") {
return new Date(v);
}

throw failed("date", v);
}


export const map = <A, B>(mapper: (a: A) => B, validator: Validator<A>): Validator<B> => {
return v => mapper(validator(v));
}

export const bind = <A, B>(binder: (a: A) => Validator<B>, validator: Validator<A>): Validator<B> => {
return v => {
const res: A = validator(v);
const bi: Validator<B> = binder(res);
return bi(v);
}
}

export const named = <A>(name: string, validator: Validator<A>) => {
return v => {
try {
return validator(v);
} catch (e) {
throw new ValidationError(`${name} validation failed: ${e}`);
}
}
}

export const andR = <A, B>(a: Validator<A>, b: Validator<B>): Validator<B> => {
return v => {
a(v);
return b(v);
}
}

export const andL = <A, B>(a: Validator<A>, b: Validator<B>): Validator<A> => {
return v => {
b(v);
return a(v);
}
}

export const or = <A, B>(a: Validator<A>, b: Validator<B>): Validator<A | B> => {
return v => {
try {
return a(v);
} catch (e) {
return b(v);
}
}
}

export const just = <A>(value: A): Validator<A> => {
return v => {
if (v !== value) {
throw failed(`${value}`, v);
}

return value;
}
}

export const record = <A>(validator: Validator<A>): Validator<Record<string, A>> => {
return v => {
if (typeof v !== "object") {
throw failed("object", v);
}

const res: Record<string, A> = {};

for (const key in v) {
res[key] = validator(v[key]);
}

return res;
}
}

export const array = <A>(validator: Validator<A>): Validator<A[]> => {
return v => {
if (!Array.isArray(v)) {
throw failed("array", v);
}

return v.map(validator);
}
}

export type ObjectValidator<T> = {
[Property in keyof T]: Validator<T[Property]>
}

export const object = <T>(objValidator: ObjectValidator<T>): Validator<T> => {
return v => {
if (typeof v !== "object") {
throw failed("object", v);
}

let n: any = {};

for (const key of Object.keys(objValidator)) {
const validator: Validator<any> = objValidator[key];
n[key] = validator(v[key]);
}

return n;
}
}
2 changes: 1 addition & 1 deletion server/config/game/settings/official/1v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
},
"gameTime": {
"gameType": "realTime",
"speed": 1800,
"speed": 3600,
"isTickLimited": "disabled",
"startDelay": 240,
"afk": {
Expand Down
2 changes: 1 addition & 1 deletion server/config/game/settings/official/newPlayer.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
},
"gameTime": {
"gameType": "realTime",
"speed": 1800,
"speed": 3600,
"isTickLimited": "disabled",
"startDelay": 60,
"afk": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
},
"gameTime": {
"gameType": "realTime",
"speed": 1800,
"speed": 3600,
"isTickLimited": "disabled",
"startDelay": 240,
"afk": {
Expand Down
2 changes: 1 addition & 1 deletion server/config/game/settings/official/special_arcade.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
},
"gameTime": {
"gameType": "realTime",
"speed": 1800,
"speed": 3600,
"isTickLimited": "disabled",
"tickLimit": 1000,
"startDelay": 240,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
},
"gameTime": {
"gameType": "realTime",
"speed": 1800,
"speed": 3600,
"isTickLimited": "disabled",
"startDelay": 240,
"afk": {
Expand Down
2 changes: 1 addition & 1 deletion server/config/game/settings/official/special_dark.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
},
"gameTime": {
"gameType": "realTime",
"speed": 1800,
"speed": 3600,
"isTickLimited": "disabled",
"startDelay": 240,
"afk": {
Expand Down
2 changes: 1 addition & 1 deletion server/config/game/settings/official/special_fog.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
},
"gameTime": {
"gameType": "realTime",
"speed": 1800,
"speed": 3600,
"isTickLimited": "disabled",
"startDelay": 240,
"afk": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
},
"gameTime": {
"gameType": "realTime",
"speed": 1800,
"speed": 3600,
"isTickLimited": "disabled",
"startDelay": 240,
"afk": {
Expand Down
2 changes: 1 addition & 1 deletion server/config/game/settings/official/special_homeStar.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
},
"gameTime": {
"gameType": "realTime",
"speed": 1800,
"speed": 3600,
"isTickLimited": "disabled",
"startDelay": 240,
"afk": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
},
"gameTime": {
"gameType": "realTime",
"speed": 1800,
"speed": 3600,
"isTickLimited": "disabled",
"startDelay": 240,
"afk": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
},
"gameTime": {
"gameType": "realTime",
"speed": 1800,
"speed": 3600,
"isTickLimited": "disabled",
"startDelay": 240,
"afk": {
Expand Down
2 changes: 1 addition & 1 deletion server/config/game/settings/official/special_orbital.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
},
"gameTime": {
"gameType": "realTime",
"speed": 1800,
"speed": 3600,
"isTickLimited": "disabled",
"startDelay": 240,
"afk": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
},
"gameTime": {
"gameType": "realTime",
"speed": 1800,
"speed": 3600,
"isTickLimited": "disabled",
"startDelay": 240,
"afk": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
},
"gameTime": {
"gameType": "realTime",
"speed": 1800,
"speed": 3600,
"isTickLimited": "disabled",
"startDelay": 240,
"afk": {
Expand Down
2 changes: 1 addition & 1 deletion server/config/game/settings/official/standard.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
},
"gameTime": {
"gameType": "realTime",
"speed": 1800,
"speed": 3600,
"isTickLimited": "disabled",
"tickLimit": 1000,
"startDelay": 240,
Expand Down
4 changes: 2 additions & 2 deletions server/config/game/settings/official/turnBased.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@
"gameType": "turnBased",
"isTickLimited": "disabled",
"turnJumps": 6,
"maxTurnWait": 1440,
"maxTurnWait": 720,
"afk": {
"lastSeenTimeout": 2,
"cycleTimeout": 3,
"turnTimeout": 3
"turnTimeout": 5
}
}
}
Loading

0 comments on commit 1c0174e

Please sign in to comment.