Skip to content

Commit

Permalink
Merge pull request #1068 from solaris-games/fix/misc-hotfixes
Browse files Browse the repository at this point in the history
Misc hotfixes for 240
  • Loading branch information
SpacialCircumstances authored Jul 5, 2024
2 parents 169a6f6 + 2e3107d commit f11c232
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
8 changes: 8 additions & 0 deletions server/api/requests/star.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ export const mapToScheduledStarUpgradeInfrastructureBulkRequest = (body: any): S
body.amount = +body.amount;
body.tick = +body.tick;

if (body.amount < 0) {
errors.push('Amount must be greater than 0.');
}

if (body.tick < 0) {
errors.push('Tick must be greater than 0.');
}

return {
infrastructureType: body.infrastructureType,
buyType: body.buyType,
Expand Down
28 changes: 16 additions & 12 deletions server/services/waypoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default class WaypointService {
}

async saveWaypoints(game: Game, player: Player, carrierId: DBObjectId, waypoints: CarrierWaypointBase[], looped: boolean) {
let carrier = this.carrierService.getById(game, carrierId);
const carrier = this.carrierService.getById(game, carrierId);

if (!carrier) {
throw new ValidationError(`Could not find carrier with id ${carrierId}`);
Expand All @@ -61,8 +61,8 @@ export default class WaypointService {
return await this.saveWaypointsForCarrier(game, player, carrier, waypoints, looped);
}

async saveWaypointsForCarrier(game: Game, player: Player, carrier: Carrier, waypoints: CarrierWaypointBase[], looped: boolean, writeToDB: boolean = true) {
if (looped == null) {
async saveWaypointsForCarrier(game: Game, player: Player, carrier: Carrier, waypoints: CarrierWaypointBase[], looped: boolean | null, writeToDB: boolean = true) {
if (looped === null) {
looped = false;
}

Expand All @@ -81,8 +81,8 @@ export default class WaypointService {
// If the carrier is currently in transit then double check that the first waypoint
// matches the source and destination.
if (!carrier.orbiting) {
let currentWaypoint = carrier.waypoints[0];
let newFirstWaypoint = waypoints[0];
const currentWaypoint = carrier.waypoints[0];
const newFirstWaypoint = waypoints[0];

if (!newFirstWaypoint
|| currentWaypoint.source.toString() !== newFirstWaypoint.source.toString()
Expand All @@ -93,16 +93,20 @@ export default class WaypointService {
if (+newFirstWaypoint.delayTicks) {
throw new ValidationError('The first waypoint cannot have delay ticks if mid-flight.');
}
} else {
if (carrier.orbiting.toString() !== waypoints[0].source.toString()) {
throw new ValidationError('The source star does not match the carrier location.');
}
}

// Validate new waypoints.
for (let i = 0; i < waypoints.length; i++) {
let waypoint = waypoints[i];
const waypoint = waypoints[i];

let sourceStar = this.starService.getById(game, waypoint.source);
let destinationStar = this.starService.getById(game, waypoint.destination);
const sourceStar = this.starService.getById(game, waypoint.source);
const destinationStar = this.starService.getById(game, waypoint.destination);

let sourceStarName = sourceStar == null ? 'Unknown' : sourceStar.name; // Could be travelling from a destroyed star.
const sourceStarName = sourceStar == null ? 'Unknown' : sourceStar.name; // Could be travelling from a destroyed star.

// Make sure the user isn't being a dumbass.
waypoint.actionShips = waypoint.actionShips || 0;
Expand Down Expand Up @@ -185,11 +189,11 @@ export default class WaypointService {
}

_waypointRouteIsWithinHyperspaceRange(game: Game, carrier: Carrier, waypoint: CarrierWaypointBase) {
let sourceStar = this.starService.getById(game, waypoint.source);
let destinationStar = this.starService.getById(game, waypoint.destination);
const sourceStar = this.starService.getById(game, waypoint.source);
const destinationStar = this.starService.getById(game, waypoint.destination);

// Stars may have been destroyed.
if (sourceStar == null || destinationStar == null) {
if (!sourceStar || !destinationStar) {
return false;
}

Expand Down

0 comments on commit f11c232

Please sign in to comment.