Skip to content

Commit

Permalink
makes majority of the entrylist fields optional (#278)
Browse files Browse the repository at this point in the history
* makes majority of the entrylist fields optional

valid entrylist entries can be quite small, e.g.

```
     {
       "drivers": [
         {
           "playerID": "...."
         }
       ],
       "isServerAdmin": 1
     }
```

the above valid entrylist entry is from a simgrid entrylist where all admins are added to the entrylist
even though they've not signed up for the race.

currently if these entrylists were imported as-is either via the GUI or API the result would end up as:

```
    {
      "drivers": [
        {
          "firstName": "",
          "lastName": "",
          "shortName": "",
          "driverCategory": 0,
          "playerID": "...",
          "nationality": 0
        }
      ],
      "raceNumber": 0,
      "forcedCarModel": 0,
      "overrideDriverInfo": 0,
      "isServerAdmin": 1,
      "customCar": "",
      "overrideCarModelForCustomCar": 0,
      "ballastKg": 0,
      "restrictor": 0,
      "defaultGridPosition": 0
    }
```

The main obvious problem here is '0' for the ForcedCarModel is a porsche car, whilst in reality the entrylist
from simgrid isn't forcing a car model, similar issues exist for some of the other settings which are not
defaulting to `-1` and instead defaulting to `0`.

The ideal scenario is for the entrylist to be exactly the same once imported via accweb, however due to the
checkboxes this is not really possible (checkboxes are either unchecked or checked via the GUI).

You could import via the API and get:

```
     {
       "drivers": [
         {
           "playerID": "...."
         }
       ],
       "isServerAdmin": 1
     }
```

However if you import via the GUI you will get:

```
    {
      "drivers": [
        {
          "playerID": "..."
        }
      ],
      "overrideDriverInfo": 0,
      "isServerAdmin": 1,
      "overrideCarModelForCustomCar": 0
    }
```

To be consistent I've instead opted to not set `omitempty` on `OverrideDriverInfo` and `OverrideCarModelForCustomCar`
which will keep the API and GUI consistent with each other to make future debugging/understanding easier. I don't
foresee any issues with importing a simgrid entrylist and having `overrideDriverInfo` and `overrideCarModelForCustomCar`
added by accweb unless ACC defaults in the future changes (very unlikely).

* save config json without empty fields

---------

Co-authored-by: Pedro Faria <[email protected]>
  • Loading branch information
klj613 and pedrofaria authored Apr 29, 2024
1 parent 40ca7d2 commit 014eb8e
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 119 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 1.25.1
* makes majority of the entrylist fields optional [#278](https://github.com/assetto-corsa-web/accweb/pull/278)
* sorting nationalities, tracks and cars lists

## 1.25.0
* html adjustments on server password [#273](https://github.com/assetto-corsa-web/accweb/pull/273)
* New track nurburgring_24h
Expand Down
26 changes: 13 additions & 13 deletions internal/pkg/instance/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,24 +149,24 @@ type EntrylistJson struct {

type EntrySettings struct {
Drivers []DriverSettings `json:"drivers"`
RaceNumber int `json:"raceNumber"`
ForcedCarModel int `json:"forcedCarModel"`
RaceNumber *int `json:"raceNumber,omitempty"`
ForcedCarModel *int `json:"forcedCarModel,omitempty"`
OverrideDriverInfo int `json:"overrideDriverInfo"`
IsServerAdmin int `json:"isServerAdmin"`
CustomCar string `json:"customCar"`
IsServerAdmin *int `json:"isServerAdmin,omitempty"`
CustomCar *string `json:"customCar,omitempty"`
OverrideCarModelForCustomCar int `json:"overrideCarModelForCustomCar"`
BallastKg int `json:"ballastKg"`
Restrictor int `json:"restrictor"`
DefaultGridPosition int `json:"defaultGridPosition"`
BallastKg *int `json:"ballastKg,omitempty"`
Restrictor *int `json:"restrictor,omitempty"`
DefaultGridPosition *int `json:"defaultGridPosition,omitempty"`
}

type DriverSettings struct {
FirstName string `json:"firstName"`
LastName string `json:"lastName"`
ShortName string `json:"shortName"`
DriverCategory int `json:"driverCategory"`
PlayerID string `json:"playerID"`
Nationality int `json:"nationality"`
FirstName *string `json:"firstName,omitempty"`
LastName *string `json:"lastName,omitempty"`
ShortName *string `json:"shortName,omitempty"`
DriverCategory *int `json:"driverCategory,omitempty"`
PlayerID string `json:"playerID"`
Nationality *int `json:"nationality,omitempty"`
}

type BopJson struct {
Expand Down
2 changes: 1 addition & 1 deletion public/src/components/server_config/bopsession.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default {
props: ["entry"],
data() {
return {
tracks: tracks,
tracks: _.orderBy(tracks, "label", "asc"),
track: "barcelona",
carModels: _.sortBy(
_.mapValues(cars, function(o) { return {value: o.id.toString(), label: o.model, brand: o.brand}; }),
Expand Down
22 changes: 11 additions & 11 deletions public/src/components/server_config/driver.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,45 +25,45 @@ export default {
props: ["driver"],
watch: {
firstName(value) {
this.driver.firstName = value;
this.driver.firstName = value == '' ? undefined : value;
this.$emit("update", this.driver);
},
lastName(value) {
this.driver.lastName = value;
this.driver.lastName = value == '' ? undefined : value;;
this.$emit("update", this.driver);
},
shortName(value) {
this.driver.shortName = value;
this.driver.shortName = value == '' ? undefined : value;;
this.$emit("update", this.driver);
},
driverCategory(value) {
this.driver.driverCategory = parseInt(value);
this.driver.driverCategory = parseInt(value) == 0 ? undefined : parseInt(value);
this.$emit("update", this.driver);
},
playerID(value) {
this.driver.playerID = value;
this.$emit("update", this.driver);
},
nationality(value) {
this.driver.nationality = parseInt(value);
this.driver.nationality = parseInt(value) == 0 ? undefined : parseInt(value);
this.$emit("update", this.driver);
}
},
data() {
return {
firstName: "",
lastName: "",
shortName: "",
firstName: undefined,
lastName: undefined,
shortName: undefined,
driverCategoryTypes: [
{value: 0, label: "Bronze"},
{value: 1, label: "Silver"},
{value: 2, label: "Gold"},
{value: 3, label: "Platinum"}
],
driverCategory: 0,
driverCategory: undefined,
playerID: "",
nationalities: _.mapValues(nationalities, function(o) { return {value: o.id, label: o.country}; }),
nationality: 0,
nationalities: _.mapValues(_.orderBy(nationalities, "country", "asc"), function(o) { return {value: o.id, label: o.country}; }),
nationality: undefined,
};
},
mounted() {
Expand Down
10 changes: 5 additions & 5 deletions public/src/components/server_config/entry.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ export default {
addDriver() {
this.drivers.push({
index: this.driverIndex,
firstName: "",
lastName: "",
shortName: "",
driverCategory: 0,
firstName: undefined,
lastName: undefined,
shortName: undefined,
driverCategory: undefined,
playerID: "",
nationality: 0,
nationality: undefined,
});
this.driverIndex++;
},
Expand Down
2 changes: 1 addition & 1 deletion public/src/components/server_config/event.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default {
components: {collapsible, field, selection, session, checkbox},
data() {
return {
tracks: tracks,
tracks: _.orderBy(tracks, "label", "asc"),
track: "barcelona",
preRaceWaitingTimeSeconds: 15,
sessionOverTimeSeconds: 120,
Expand Down
176 changes: 88 additions & 88 deletions public/src/data/nationalities.js
Original file line number Diff line number Diff line change
@@ -1,91 +1,91 @@
const nationalities = {
"0": {id: 0, country: "Other"},
"49": {id: 49, country: "Andorra"},
"14": {id: 14, country: "Argentina"},
"28": {id: 28, country: "Armenia"},
"41": {id: 41, country: "Australia"},
"9": {id: 9, country: "Austria"},
"50": {id: 50, country: "Azerbaijan"},
"79": {id: 79, country: "Bahrain"},
"7": {id: 7, country: "Belgium"},
"17": {id: 17, country: "Brazil"},
"51": {id: 51, country: "Bulgaria"},
"34": {id: 34, country: "Canada"},
"82": {id: 82, country: "Chile"},
"35": {id: 35, country: "China"},
"81": {id: 81, country: "Chinese Taipei"},
"47": {id: 47, country: "Colombia"},
"33": {id: 33, country: "Croatia"},
"52": {id: 52, country: "Cuba"},
"53": {id: 53, country: "Czech Republic"},
"32": {id: 32, country: "Denmark"},
"86": {id: 86, country: "England"},
"54": {id: 54, country: "Estonia"},
"31": {id: 31, country: "Finland"},
"3": {id: 3, country: "France"},
"55": {id: 55, country: "Georgia"},
"2": {id: 2, country: "Germany"},
"5": {id: 5, country: "Great Britain"},
"22": {id: 22, country: "Greece"},
"46": {id: 46, country: "Hong Kong"},
"6": {id: 6, country: "Hungary"},
"56": {id: 56, country: "India"},
"38": {id: 38, country: "Indonesia"},
"78": {id: 78, country: "Iran"},
"16": {id: 16, country: "Ireland"},
"57": {id: 57, country: "Israel"},
"1": {id: 1, country: "Italy"},
"58": {id: 58, country: "Jamaica"},
"48": {id: 48, country: "Japan"},
"45": {id: 45, country: "Kuwait"},
"59": {id: 59, country: "Latvia"},
"27": {id: 27, country: "Lebanon"},
"60": {id: 60, country: "Lithuania"},
"44": {id: 44, country: "Luxembourg"},
"61": {id: 61, country: "Macao"},
"84": {id: 84, country: "Madagascar"},
"62": {id: 62, country: "Malaysia"},
"85": {id: 85, country: "Malta"},
"29": {id: 29, country: "Mexico"},
"15": {id: 15, country: "Monaco"},
"88": {id: 88, country: "Morocco"},
"63": {id: 63, country: "Nepal"},
"12": {id: 12, country: "Netherlands"},
"64": {id: 64, country: "New Caledonia"},
"40": {id: 40, country: "New Zealand"},
"65": {id: 65, country: "Nigeria"},
"66": {id: 66, country: "Northern Ireland"},
"24": {id: 24, country: "Norway"},
"21": {id: 21, country: "Oman"},
"67": {id: 67, country: "Papua New Guinea"},
"68": {id: 68, country: "Philippines"},
"13": {id: 13, country: "Poland"},
"36": {id: 36, country: "Portugal"},
"19": {id: 19, country: "Puerto Rico"},
"69": {id: 69, country: "Qatar"},
"70": {id: 70, country: "Romania"},
"10": {id: 10, country: "Russia"},
"42": {id: 42, country: "San Marino"},
"23": {id: 23, country: "Saudi Arabia"},
"71": {id: 71, country: "Scotland"},
"72": {id: 72, country: "Serbia"},
"37": {id: 37, country: "Singapore"},
"20": {id: 20, country: "Slovakia"},
"73": {id: 73, country: "Slovenia"},
"18": {id: 18, country: "South Africa"},
"26": {id: 26, country: "South Korea"},
"4": {id: 4, country: "Spain"},
"30": {id: 30, country: "Sweden"},
"8": {id: 8, country: "Switzerland"},
"74": {id: 74, country: "Taiwan"},
"11": {id: 11, country: "Thailand"},
"25": {id: 25, country: "Turkey"},
"75": {id: 75, country: "Ukraine"},
"43": {id: 43, country: "United Arab Emirates"},
"83": {id: 83, country: "Uruguay"},
"39": {id: 39, country: "USA"},
"76": {id: 76, country: "Venezuela"},
"77": {id: 77, country: "Wales"},
"80": {id: 80, country: "Zimbabwe"}
"0": { id: 0, country: "-- Other --" },
"49": { id: 49, country: "Andorra" },
"14": { id: 14, country: "Argentina" },
"28": { id: 28, country: "Armenia" },
"41": { id: 41, country: "Australia" },
"9": { id: 9, country: "Austria" },
"50": { id: 50, country: "Azerbaijan" },
"79": { id: 79, country: "Bahrain" },
"7": { id: 7, country: "Belgium" },
"17": { id: 17, country: "Brazil" },
"51": { id: 51, country: "Bulgaria" },
"34": { id: 34, country: "Canada" },
"82": { id: 82, country: "Chile" },
"35": { id: 35, country: "China" },
"81": { id: 81, country: "Chinese Taipei" },
"47": { id: 47, country: "Colombia" },
"33": { id: 33, country: "Croatia" },
"52": { id: 52, country: "Cuba" },
"53": { id: 53, country: "Czech Republic" },
"32": { id: 32, country: "Denmark" },
"86": { id: 86, country: "England" },
"54": { id: 54, country: "Estonia" },
"31": { id: 31, country: "Finland" },
"3": { id: 3, country: "France" },
"55": { id: 55, country: "Georgia" },
"2": { id: 2, country: "Germany" },
"5": { id: 5, country: "Great Britain" },
"22": { id: 22, country: "Greece" },
"46": { id: 46, country: "Hong Kong" },
"6": { id: 6, country: "Hungary" },
"56": { id: 56, country: "India" },
"38": { id: 38, country: "Indonesia" },
"78": { id: 78, country: "Iran" },
"16": { id: 16, country: "Ireland" },
"57": { id: 57, country: "Israel" },
"1": { id: 1, country: "Italy" },
"58": { id: 58, country: "Jamaica" },
"48": { id: 48, country: "Japan" },
"45": { id: 45, country: "Kuwait" },
"59": { id: 59, country: "Latvia" },
"27": { id: 27, country: "Lebanon" },
"60": { id: 60, country: "Lithuania" },
"44": { id: 44, country: "Luxembourg" },
"61": { id: 61, country: "Macao" },
"84": { id: 84, country: "Madagascar" },
"62": { id: 62, country: "Malaysia" },
"85": { id: 85, country: "Malta" },
"29": { id: 29, country: "Mexico" },
"15": { id: 15, country: "Monaco" },
"88": { id: 88, country: "Morocco" },
"63": { id: 63, country: "Nepal" },
"12": { id: 12, country: "Netherlands" },
"64": { id: 64, country: "New Caledonia" },
"40": { id: 40, country: "New Zealand" },
"65": { id: 65, country: "Nigeria" },
"66": { id: 66, country: "Northern Ireland" },
"24": { id: 24, country: "Norway" },
"21": { id: 21, country: "Oman" },
"67": { id: 67, country: "Papua New Guinea" },
"68": { id: 68, country: "Philippines" },
"13": { id: 13, country: "Poland" },
"36": { id: 36, country: "Portugal" },
"19": { id: 19, country: "Puerto Rico" },
"69": { id: 69, country: "Qatar" },
"70": { id: 70, country: "Romania" },
"10": { id: 10, country: "Russia" },
"42": { id: 42, country: "San Marino" },
"23": { id: 23, country: "Saudi Arabia" },
"71": { id: 71, country: "Scotland" },
"72": { id: 72, country: "Serbia" },
"37": { id: 37, country: "Singapore" },
"20": { id: 20, country: "Slovakia" },
"73": { id: 73, country: "Slovenia" },
"18": { id: 18, country: "South Africa" },
"26": { id: 26, country: "South Korea" },
"4": { id: 4, country: "Spain" },
"30": { id: 30, country: "Sweden" },
"8": { id: 8, country: "Switzerland" },
"74": { id: 74, country: "Taiwan" },
"11": { id: 11, country: "Thailand" },
"25": { id: 25, country: "Turkey" },
"75": { id: 75, country: "Ukraine" },
"43": { id: 43, country: "United Arab Emirates" },
"83": { id: 83, country: "Uruguay" },
"39": { id: 39, country: "USA" },
"76": { id: 76, country: "Venezuela" },
"77": { id: 77, country: "Wales" },
"80": { id: 80, country: "Zimbabwe" }
}
export default nationalities;

0 comments on commit 014eb8e

Please sign in to comment.