From 6a4e896cd4fef3c892c91b37a9b5af991e94ae09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dawid=20Wysoki=C5=84ski?= Date: Sat, 10 Feb 2024 13:28:41 +0100 Subject: [PATCH] feat: api - add 3 new endpoints --- api/openapi3.yml | 647 ++++++++++++++++++++++ internal/bun/bunmodel/building_info.go | 20 +- internal/bun/bunmodel/server_config.go | 100 ++-- internal/bun/bunmodel/unit_info.go | 10 +- internal/domain/building_info.go | 20 +- internal/domain/server_config.go | 100 ++-- internal/domain/unit_info.go | 10 +- internal/port/handler_http_api_error.go | 10 +- internal/port/handler_http_api_server.go | 30 + internal/port/internal/apimodel/server.go | 83 ++- internal/tw/building_info.go | 20 +- internal/tw/server_config.go | 100 ++-- internal/tw/unit_info.go | 10 +- 13 files changed, 958 insertions(+), 202 deletions(-) diff --git a/api/openapi3.yml b/api/openapi3.yml index 8d2dac2..4e80810 100644 --- a/api/openapi3.yml +++ b/api/openapi3.yml @@ -82,6 +82,51 @@ paths: $ref: "#/components/responses/GetServerResponse" default: $ref: "#/components/responses/ErrorResponse" + /v2/versions/{versionCode}/servers/{serverKey}/config: + get: + operationId: getServerConfig + tags: + - versions + - servers + description: Get server config + parameters: + - $ref: "#/components/parameters/VersionCodePathParam" + - $ref: "#/components/parameters/ServerKeyPathParam" + responses: + 200: + $ref: "#/components/responses/GetServerConfigResponse" + default: + $ref: "#/components/responses/ErrorResponse" + /v2/versions/{versionCode}/servers/{serverKey}/building-info: + get: + operationId: getBuildingInfo + tags: + - versions + - servers + description: Get building info + parameters: + - $ref: "#/components/parameters/VersionCodePathParam" + - $ref: "#/components/parameters/ServerKeyPathParam" + responses: + 200: + $ref: "#/components/responses/GetBuildingInfoResponse" + default: + $ref: "#/components/responses/ErrorResponse" + /v2/versions/{versionCode}/servers/{serverKey}/unit-info: + get: + operationId: getUnitInfo + tags: + - versions + - servers + description: Get unit info + parameters: + - $ref: "#/components/parameters/VersionCodePathParam" + - $ref: "#/components/parameters/ServerKeyPathParam" + responses: + 200: + $ref: "#/components/responses/GetUnitInfoResponse" + default: + $ref: "#/components/responses/ErrorResponse" components: schemas: Error: @@ -176,6 +221,575 @@ components: createdAt: type: string format: date-time + ServerConfig: + type: object + required: + - ally + - build + - buildings + - commands + - coord + - game + - misc + - moral + - newbie + - night + - sitter + - sleep + - snob + - speed + - unitSpeed + - win + properties: + ally: + $ref: "#/components/schemas/ServerConfigAlly" + build: + $ref: "#/components/schemas/ServerConfigBuild" + buildings: + $ref: "#/components/schemas/ServerConfigBuildings" + commands: + $ref: "#/components/schemas/ServerConfigCommands" + coord: + $ref: "#/components/schemas/ServerConfigCoord" + game: + $ref: "#/components/schemas/ServerConfigGame" + misc: + $ref: "#/components/schemas/ServerConfigMisc" + moral: + type: integer + newbie: + $ref: "#/components/schemas/ServerConfigNewbie" + night: + $ref: "#/components/schemas/ServerConfigNight" + sitter: + $ref: "#/components/schemas/ServerConfigSitter" + sleep: + $ref: "#/components/schemas/ServerConfigSleep" + snob: + $ref: "#/components/schemas/ServerConfigSnob" + speed: + type: number + format: double + unitSpeed: + type: number + format: double + win: + $ref: "#/components/schemas/ServerConfigWin" + ServerConfigAlly: + type: object + required: + - allytimeSupport + - fixedAllies + - levels + - limit + - noHarm + - noJoin + - noLeave + - noOtherSupport + - noOtherSupportType + - pointsMemberCount + - warsAutoacceptDays + - warsMemberRequirement + - warsPointsRequirement + - xpRequirements + properties: + allytimeSupport: + type: integer + fixedAllies: + type: integer + levels: + type: integer + limit: + type: integer + noHarm: + type: integer + noJoin: + type: integer + noLeave: + type: integer + noOtherSupport: + type: integer + noOtherSupportType: + type: integer + pointsMemberCount: + type: integer + warsAutoacceptDays: + type: integer + warsMemberRequirement: + type: integer + warsPointsRequirement: + type: integer + xpRequirements: + type: string + ServerConfigBuild: + type: object + required: + - destroy + properties: + destroy: + type: integer + ServerConfigBuildings: + type: object + required: + - customBarracks + - customChurch + - customFarm + - customGarage + - customHide + - customIron + - customMain + - customMarket + - customPlace + - customSmith + - customSnob + - customStable + - customStatue + - customStone + - customStorage + - customWall + - customWatchtower + - customWood + properties: + customBarracks: + type: integer + customChurch: + type: integer + customFarm: + type: integer + customGarage: + type: integer + customHide: + type: integer + customIron: + type: integer + customMain: + type: integer + customMarket: + type: integer + customPlace: + type: integer + customSmith: + type: integer + customSnob: + type: integer + customStable: + type: integer + customStatue: + type: integer + customStone: + type: integer + customStorage: + type: integer + customWall: + type: integer + customWatchtower: + type: integer + customWood: + type: integer + ServerConfigCommands: + type: object + required: + - commandCancelTime + - millisArrival + properties: + commandCancelTime: + type: integer + millisArrival: + type: integer + ServerConfigCoord: + type: object + required: + - bonusNew + - bonusVillages + - emptyVillages + - func + - inner + - mapSize + - nobleRestart + - selectStart + - startVillages + - villageMoveWait + properties: + bonusNew: + type: integer + bonusVillages: + type: integer + emptyVillages: + type: integer + func: + type: integer + inner: + type: integer + mapSize: + type: integer + nobleRestart: + type: integer + selectStart: + type: integer + startVillages: + type: integer + villageMoveWait: + type: integer + ServerConfigGame: + type: object + required: + - archer + - barbarianMaxPoints + - barbarianRise + - barbarianShrink + - baseProduction + - buildtimeFormula + - church + - event + - fakeLimit + - farmLimit + - hauls + - haulsBase + - haulsMax + - knight + - knightNewItems + - scavenging + - stronghold + - suppressEvents + - tech + - watchtower + properties: + archer: + type: integer + barbarianMaxPoints: + type: integer + barbarianRise: + type: number + format: double + barbarianShrink: + type: integer + baseProduction: + type: integer + buildtimeFormula: + type: integer + church: + type: integer + event: + type: integer + fakeLimit: + type: number + format: double + farmLimit: + type: integer + hauls: + type: integer + haulsBase: + type: integer + haulsMax: + type: integer + knight: + type: integer + knightNewItems: + type: integer + scavenging: + type: integer + stronghold: + type: integer + suppressEvents: + type: integer + tech: + type: integer + watchtower: + type: integer + ServerConfigMisc: + type: object + required: + - killRanking + - tradeCancelTime + - tutorial + properties: + killRanking: + type: integer + tradeCancelTime: + type: integer + tutorial: + type: integer + ServerConfigNewbie: + type: object + required: + - days + - ratio + - ratioDays + - removeNewbieVillages + properties: + days: + type: integer + ratio: + type: integer + ratioDays: + type: integer + removeNewbieVillages: + type: integer + ServerConfigNight: + type: object + required: + - active + - defFactor + - duration + - endHour + - startHour + properties: + active: + type: integer + defFactor: + type: number + format: double + duration: + type: integer + endHour: + type: integer + startHour: + type: integer + ServerConfigSitter: + type: object + required: + - allow + properties: + allow: + type: integer + ServerConfigSleep: + type: object + required: + - active + - delay + - max + - maxAwake + - min + - minAwake + - warnTime + properties: + active: + type: integer + delay: + type: integer + max: + type: integer + maxAwake: + type: integer + min: + type: integer + minAwake: + type: integer + warnTime: + type: integer + ServerConfigSnob: + type: object + required: + - cheapRebuild + - coinIron + - coinStone + - coinWood + - factor + - gold + - maxDist + - noBarbConquer + - rise + properties: + cheapRebuild: + type: integer + coinIron: + type: integer + coinStone: + type: integer + coinWood: + type: integer + factor: + type: number + format: double + gold: + type: integer + maxDist: + type: integer + noBarbConquer: + type: integer + rise: + type: integer + ServerConfigWin: + type: object + required: + - check + properties: + check: + type: integer + Unit: + type: object + required: + - attack + - buildTime + - carry + - defense + - defenseArcher + - defenseCavalry + - pop + - speed + properties: + attack: + type: integer + buildTime: + type: number + format: double + carry: + type: integer + defense: + type: integer + defenseArcher: + type: integer + defenseCavalry: + type: integer + pop: + type: integer + speed: + type: number + format: double + UnitInfo: + type: object + required: + - archer + - axe + - catapult + - heavy + - knight + - light + - marcher + - militia + - ram + - snob + - spear + - spy + - sword + properties: + archer: + $ref: "#/components/schemas/Unit" + axe: + $ref: "#/components/schemas/Unit" + catapult: + $ref: "#/components/schemas/Unit" + heavy: + $ref: "#/components/schemas/Unit" + knight: + $ref: "#/components/schemas/Unit" + light: + $ref: "#/components/schemas/Unit" + marcher: + $ref: "#/components/schemas/Unit" + militia: + $ref: "#/components/schemas/Unit" + ram: + $ref: "#/components/schemas/Unit" + snob: + $ref: "#/components/schemas/Unit" + spear: + $ref: "#/components/schemas/Unit" + spy: + $ref: "#/components/schemas/Unit" + sword: + $ref: "#/components/schemas/Unit" + Building: + type: object + required: + - buildTime + - buildTimeFactor + - iron + - ironFactor + - maxLevel + - minLevel + - pop + - popFactor + - stone + - stoneFactor + - wood + - woodFactor + properties: + buildTime: + type: number + format: double + buildTimeFactor: + type: number + format: double + iron: + type: integer + ironFactor: + type: number + format: double + maxLevel: + type: integer + minLevel: + type: integer + pop: + type: integer + popFactor: + type: number + format: double + stone: + type: integer + stoneFactor: + type: number + format: double + wood: + type: integer + woodFactor: + type: number + format: double + BuildingInfo: + type: object + required: + - barracks + - farm + - garage + - hide + - iron + - main + - market + - place + - smith + - snob + - stable + - statue + - stone + - storage + - wall + - watchtower + - wood + properties: + barracks: + $ref: "#/components/schemas/Building" + farm: + $ref: "#/components/schemas/Building" + garage: + $ref: "#/components/schemas/Building" + hide: + $ref: "#/components/schemas/Building" + iron: + $ref: "#/components/schemas/Building" + main: + $ref: "#/components/schemas/Building" + market: + $ref: "#/components/schemas/Building" + place: + $ref: "#/components/schemas/Building" + smith: + $ref: "#/components/schemas/Building" + snob: + $ref: "#/components/schemas/Building" + stable: + $ref: "#/components/schemas/Building" + statue: + $ref: "#/components/schemas/Building" + stone: + $ref: "#/components/schemas/Building" + storage: + $ref: "#/components/schemas/Building" + wall: + $ref: "#/components/schemas/Building" + watchtower: + $ref: "#/components/schemas/Building" + wood: + $ref: "#/components/schemas/Building" Cursor: type: object x-go-type-skip-optional-pointer: true @@ -279,6 +893,39 @@ components: properties: data: $ref: "#/components/schemas/Server" + GetServerConfigResponse: + description: "" + content: + application/json: + schema: + type: object + required: + - data + properties: + data: + $ref: "#/components/schemas/ServerConfig" + GetUnitInfoResponse: + description: "" + content: + application/json: + schema: + type: object + required: + - data + properties: + data: + $ref: "#/components/schemas/UnitInfo" + GetBuildingInfoResponse: + description: "" + content: + application/json: + schema: + type: object + required: + - data + properties: + data: + $ref: "#/components/schemas/BuildingInfo" ErrorResponse: description: Default error response. content: diff --git a/internal/bun/bunmodel/building_info.go b/internal/bun/bunmodel/building_info.go index cd116e5..21c98cc 100644 --- a/internal/bun/bunmodel/building_info.go +++ b/internal/bun/bunmodel/building_info.go @@ -7,18 +7,18 @@ import ( ) type Building struct { - MaxLevel int - MinLevel int - Wood int - Stone int - Iron int - Pop int - WoodFactor float64 - StoneFactor float64 - IronFactor float64 - PopFactor float64 BuildTime float64 BuildTimeFactor float64 + Iron int + IronFactor float64 + MaxLevel int + MinLevel int + Pop int + PopFactor float64 + Stone int + StoneFactor float64 + Wood int + WoodFactor float64 } type BuildingInfo struct { diff --git a/internal/bun/bunmodel/server_config.go b/internal/bun/bunmodel/server_config.go index 19b7760..25e21ab 100644 --- a/internal/bun/bunmodel/server_config.go +++ b/internal/bun/bunmodel/server_config.go @@ -12,106 +12,106 @@ type ServerConfigBuild struct { type ServerConfigMisc struct { KillRanking int - Tutorial int TradeCancelTime int + Tutorial int } type ServerConfigCommands struct { - MillisArrival int CommandCancelTime int + MillisArrival int } type ServerConfigNewbie struct { Days int - RatioDays int Ratio int + RatioDays int RemoveNewbieVillages int } type ServerConfigGame struct { - BuildtimeFormula int - Knight int - KnightNewItems int Archer int - Tech int - FarmLimit int - Church int - Watchtower int - Stronghold int - FakeLimit float64 + BarbarianMaxPoints int BarbarianRise float64 BarbarianShrink int - BarbarianMaxPoints int - Scavenging int + BaseProduction int + BuildtimeFormula int + Church int + Event int + FakeLimit float64 + FarmLimit int Hauls int HaulsBase int HaulsMax int - BaseProduction int - Event int + Knight int + KnightNewItems int + Scavenging int + Stronghold int SuppressEvents int + Tech int + Watchtower int } type ServerConfigBuildings struct { - CustomMain int - CustomFarm int - CustomStorage int - CustomPlace int CustomBarracks int CustomChurch int - CustomSmith int - CustomWood int - CustomStone int - CustomIron int - CustomMarket int - CustomStable int - CustomWall int + CustomFarm int CustomGarage int CustomHide int + CustomIron int + CustomMain int + CustomMarket int + CustomPlace int + CustomSmith int CustomSnob int + CustomStable int CustomStatue int + CustomStone int + CustomStorage int + CustomWall int CustomWatchtower int + CustomWood int } type ServerConfigSnob struct { - Gold int CheapRebuild int - Rise int - MaxDist int - Factor float64 - CoinWood int - CoinStone int CoinIron int + CoinStone int + CoinWood int + Factor float64 + Gold int + MaxDist int NoBarbConquer int + Rise int } type ServerConfigAlly struct { + AllytimeSupport int + FixedAllies int + Levels int + Limit int NoHarm int + NoJoin int + NoLeave int NoOtherSupport int NoOtherSupportType int - AllytimeSupport int - NoLeave int - NoJoin int - Limit int - FixedAllies int PointsMemberCount int + WarsAutoacceptDays int WarsMemberRequirement int WarsPointsRequirement int - WarsAutoacceptDays int - Levels int XpRequirements string } type ServerConfigCoord struct { - MapSize int - Func int - EmptyVillages int - BonusVillages int BonusNew int + BonusVillages int + EmptyVillages int + Func int Inner int - SelectStart int - VillageMoveWait int + MapSize int NobleRestart int + SelectStart int StartVillages int + VillageMoveWait int } type ServerConfigSitter struct { @@ -121,19 +121,19 @@ type ServerConfigSitter struct { type ServerConfigSleep struct { Active int Delay int - Min int Max int - MinAwake int MaxAwake int + Min int + MinAwake int WarnTime int } type ServerConfigNight struct { Active int - StartHour int - EndHour int DefFactor float64 Duration int + EndHour int + StartHour int } type ServerConfigWin struct { diff --git a/internal/bun/bunmodel/unit_info.go b/internal/bun/bunmodel/unit_info.go index 8708758..67aa4e2 100644 --- a/internal/bun/bunmodel/unit_info.go +++ b/internal/bun/bunmodel/unit_info.go @@ -7,14 +7,14 @@ import ( ) type Unit struct { + Attack int BuildTime float64 + Carry int + Defense int + DefenseArcher int + DefenseCavalry int Pop int Speed float64 - Attack int - Defense int - DefenseCavalry int - DefenseArcher int - Carry int } type UnitInfo struct { diff --git a/internal/domain/building_info.go b/internal/domain/building_info.go index a889414..87170d3 100644 --- a/internal/domain/building_info.go +++ b/internal/domain/building_info.go @@ -1,18 +1,18 @@ package domain type Building struct { - MaxLevel int - MinLevel int - Wood int - Stone int - Iron int - Pop int - WoodFactor float64 - StoneFactor float64 - IronFactor float64 - PopFactor float64 BuildTime float64 BuildTimeFactor float64 + Iron int + IronFactor float64 + MaxLevel int + MinLevel int + Pop int + PopFactor float64 + Stone int + StoneFactor float64 + Wood int + WoodFactor float64 } type BuildingInfo struct { diff --git a/internal/domain/server_config.go b/internal/domain/server_config.go index 8b160d2..29f7f11 100644 --- a/internal/domain/server_config.go +++ b/internal/domain/server_config.go @@ -6,106 +6,106 @@ type ServerConfigBuild struct { type ServerConfigMisc struct { KillRanking int - Tutorial int TradeCancelTime int + Tutorial int } type ServerConfigCommands struct { - MillisArrival int CommandCancelTime int + MillisArrival int } type ServerConfigNewbie struct { Days int - RatioDays int Ratio int + RatioDays int RemoveNewbieVillages int } type ServerConfigGame struct { - BuildtimeFormula int - Knight int - KnightNewItems int Archer int - Tech int - FarmLimit int - Church int - Watchtower int - Stronghold int - FakeLimit float64 + BarbarianMaxPoints int BarbarianRise float64 BarbarianShrink int - BarbarianMaxPoints int - Scavenging int + BaseProduction int + BuildtimeFormula int + Church int + Event int + FakeLimit float64 + FarmLimit int Hauls int HaulsBase int HaulsMax int - BaseProduction int - Event int + Knight int + KnightNewItems int + Scavenging int + Stronghold int SuppressEvents int + Tech int + Watchtower int } type ServerConfigBuildings struct { - CustomMain int - CustomFarm int - CustomStorage int - CustomPlace int CustomBarracks int CustomChurch int - CustomSmith int - CustomWood int - CustomStone int - CustomIron int - CustomMarket int - CustomStable int - CustomWall int + CustomFarm int CustomGarage int CustomHide int + CustomIron int + CustomMain int + CustomMarket int + CustomPlace int + CustomSmith int CustomSnob int + CustomStable int CustomStatue int + CustomStone int + CustomStorage int + CustomWall int CustomWatchtower int + CustomWood int } type ServerConfigSnob struct { - Gold int CheapRebuild int - Rise int - MaxDist int - Factor float64 - CoinWood int - CoinStone int CoinIron int + CoinStone int + CoinWood int + Factor float64 + Gold int + MaxDist int NoBarbConquer int + Rise int } type ServerConfigAlly struct { + AllytimeSupport int + FixedAllies int + Levels int + Limit int NoHarm int + NoJoin int + NoLeave int NoOtherSupport int NoOtherSupportType int - AllytimeSupport int - NoLeave int - NoJoin int - Limit int - FixedAllies int PointsMemberCount int + WarsAutoacceptDays int WarsMemberRequirement int WarsPointsRequirement int - WarsAutoacceptDays int - Levels int XpRequirements string } type ServerConfigCoord struct { - MapSize int - Func int - EmptyVillages int - BonusVillages int BonusNew int + BonusVillages int + EmptyVillages int + Func int Inner int - SelectStart int - VillageMoveWait int + MapSize int NobleRestart int + SelectStart int StartVillages int + VillageMoveWait int } type ServerConfigSitter struct { @@ -115,19 +115,19 @@ type ServerConfigSitter struct { type ServerConfigSleep struct { Active int Delay int - Min int Max int - MinAwake int MaxAwake int + Min int + MinAwake int WarnTime int } type ServerConfigNight struct { Active int - StartHour int - EndHour int DefFactor float64 Duration int + EndHour int + StartHour int } type ServerConfigWin struct { diff --git a/internal/domain/unit_info.go b/internal/domain/unit_info.go index 2acc3a9..24ec30e 100644 --- a/internal/domain/unit_info.go +++ b/internal/domain/unit_info.go @@ -1,14 +1,14 @@ package domain type Unit struct { + Attack int BuildTime float64 + Carry int + Defense int + DefenseArcher int + DefenseCavalry int Pop int Speed float64 - Attack int - Defense int - DefenseCavalry int - DefenseArcher int - Carry int } type UnitInfo struct { diff --git a/internal/port/handler_http_api_error.go b/internal/port/handler_http_api_error.go index edbe117..dadeb9b 100644 --- a/internal/port/handler_http_api_error.go +++ b/internal/port/handler_http_api_error.go @@ -139,7 +139,7 @@ func (re apiErrorRenderer) invalidParamFormatErrorToAPIError( func (re apiErrorRenderer) domainErrorToAPIError(domainErr domain.Error) apiError { message := domainErr.Error() - var pathElems []errorPathSegment + var pathSegments []errorPathSegment var err error = domainErr for err != nil { @@ -148,7 +148,7 @@ func (re apiErrorRenderer) domainErrorToAPIError(domainErr domain.Error) apiErro switch { case errors.As(err, &validationErr): - pathElems = append(pathElems, errorPathSegment{ + pathSegments = append(pathSegments, errorPathSegment{ model: validationErr.Model, field: validationErr.Field, index: -1, @@ -156,7 +156,7 @@ func (re apiErrorRenderer) domainErrorToAPIError(domainErr domain.Error) apiErro err = validationErr.Unwrap() message = err.Error() case errors.As(err, &sliceElementValidationErr): - pathElems = append(pathElems, errorPathSegment{ + pathSegments = append(pathSegments, errorPathSegment{ model: sliceElementValidationErr.Model, field: sliceElementValidationErr.Field, index: sliceElementValidationErr.Index, @@ -170,12 +170,12 @@ func (re apiErrorRenderer) domainErrorToAPIError(domainErr domain.Error) apiErro var path []string - if len(pathElems) > 0 { + if len(pathSegments) > 0 { if re.formatErrorPath == nil { return errAPIInternalServerError } - path = re.formatErrorPath(pathElems) + path = re.formatErrorPath(pathSegments) if len(path) == 0 { return errAPIInternalServerError diff --git a/internal/port/handler_http_api_server.go b/internal/port/handler_http_api_server.go index 0103b0a..738b374 100644 --- a/internal/port/handler_http_api_server.go +++ b/internal/port/handler_http_api_server.go @@ -71,6 +71,36 @@ func (h *apiHTTPHandler) GetServer( renderJSON(w, r, http.StatusOK, apimodel.NewGetServerResponse(server)) } +func (h *apiHTTPHandler) GetBuildingInfo( + w http.ResponseWriter, + r *http.Request, + _ apimodel.VersionCodePathParam, + _ apimodel.ServerKeyPathParam, +) { + server, _ := serverFromContext(r.Context()) + renderJSON(w, r, http.StatusOK, apimodel.NewGetBuildingInfoResponse(server.BuildingInfo())) +} + +func (h *apiHTTPHandler) GetServerConfig( + w http.ResponseWriter, + r *http.Request, + _ apimodel.VersionCodePathParam, + _ apimodel.ServerKeyPathParam, +) { + server, _ := serverFromContext(r.Context()) + renderJSON(w, r, http.StatusOK, apimodel.NewGetServerConfigResponse(server.Config())) +} + +func (h *apiHTTPHandler) GetUnitInfo( + w http.ResponseWriter, + r *http.Request, + _ apimodel.VersionCodePathParam, + _ apimodel.ServerKeyPathParam, +) { + server, _ := serverFromContext(r.Context()) + renderJSON(w, r, http.StatusOK, apimodel.NewGetUnitInfoResponse(server.UnitInfo())) +} + func (h *apiHTTPHandler) serverMiddleware(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { ctx := r.Context() diff --git a/internal/port/internal/apimodel/server.go b/internal/port/internal/apimodel/server.go index b87c6c0..bb436fb 100644 --- a/internal/port/internal/apimodel/server.go +++ b/internal/port/internal/apimodel/server.go @@ -55,8 +55,87 @@ func NewListServersResponse(res domain.ListServersResult) ListServersResponse { return resp } -func NewGetServerResponse(v domain.Server) GetServerResponse { +func NewGetServerResponse(s domain.Server) GetServerResponse { return GetServerResponse{ - Data: NewServer(v), + Data: NewServer(s), + } +} + +func NewServerConfig(cfg domain.ServerConfig) ServerConfig { + return ServerConfig{ + Speed: cfg.Speed(), + UnitSpeed: cfg.UnitSpeed(), + Moral: cfg.Moral(), + Build: ServerConfigBuild(cfg.Build()), + Misc: ServerConfigMisc(cfg.Misc()), + Commands: ServerConfigCommands(cfg.Commands()), + Newbie: ServerConfigNewbie(cfg.Newbie()), + Game: ServerConfigGame(cfg.Game()), + Buildings: ServerConfigBuildings(cfg.Buildings()), + Snob: ServerConfigSnob(cfg.Snob()), + Ally: ServerConfigAlly(cfg.Ally()), + Coord: ServerConfigCoord(cfg.Coord()), + Sitter: ServerConfigSitter(cfg.Sitter()), + Sleep: ServerConfigSleep(cfg.Sleep()), + Night: ServerConfigNight(cfg.Night()), + Win: ServerConfigWin(cfg.Win()), + } +} + +func NewGetServerConfigResponse(cfg domain.ServerConfig) GetServerConfigResponse { + return GetServerConfigResponse{ + Data: NewServerConfig(cfg), + } +} + +func NewBuildingInfo(info domain.BuildingInfo) BuildingInfo { + return BuildingInfo{ + Main: Building(info.Main()), + Barracks: Building(info.Barracks()), + Stable: Building(info.Stable()), + Garage: Building(info.Garage()), + Watchtower: Building(info.Watchtower()), + Snob: Building(info.Snob()), + Smith: Building(info.Smith()), + Place: Building(info.Place()), + Statue: Building(info.Statue()), + Market: Building(info.Market()), + Wood: Building(info.Wood()), + Stone: Building(info.Stone()), + Iron: Building(info.Iron()), + Farm: Building(info.Farm()), + Storage: Building(info.Storage()), + Hide: Building(info.Hide()), + Wall: Building(info.Wall()), + } +} + +func NewGetBuildingInfoResponse(info domain.BuildingInfo) GetBuildingInfoResponse { + return GetBuildingInfoResponse{ + Data: NewBuildingInfo(info), + } +} + +func NewUnitInfo(info domain.UnitInfo) UnitInfo { + return UnitInfo{ + Spear: Unit(info.Spear()), + Sword: Unit(info.Sword()), + Axe: Unit(info.Axe()), + Archer: Unit(info.Archer()), + Spy: Unit(info.Spy()), + Light: Unit(info.Light()), + Marcher: Unit(info.Marcher()), + Heavy: Unit(info.Heavy()), + Ram: Unit(info.Ram()), + Catapult: Unit(info.Catapult()), + Knight: Unit(info.Knight()), + Snob: Unit(info.Snob()), + Militia: Unit(info.Militia()), + } +} + +func NewGetUnitInfoResponse(info domain.UnitInfo) GetUnitInfoResponse { + return GetUnitInfoResponse{ + Data: NewUnitInfo(info), } } diff --git a/internal/tw/building_info.go b/internal/tw/building_info.go index fdb5099..8b1f768 100644 --- a/internal/tw/building_info.go +++ b/internal/tw/building_info.go @@ -5,18 +5,18 @@ import ( ) type Building struct { - MaxLevel int `xml:"max_level"` - MinLevel int `xml:"min_level"` - Wood int `xml:"wood"` - Stone int `xml:"stone"` - Iron int `xml:"iron"` - Pop int `xml:"pop"` - WoodFactor float64 `xml:"wood_factor"` - StoneFactor float64 `xml:"stone_factor"` - IronFactor float64 `xml:"iron_factor"` - PopFactor float64 `xml:"pop_factor"` BuildTime float64 `xml:"build_time"` BuildTimeFactor float64 `xml:"build_time_factor"` + Iron int `xml:"iron"` + IronFactor float64 `xml:"iron_factor"` + MaxLevel int `xml:"max_level"` + MinLevel int `xml:"min_level"` + Pop int `xml:"pop"` + PopFactor float64 `xml:"pop_factor"` + Stone int `xml:"stone"` + StoneFactor float64 `xml:"stone_factor"` + Wood int `xml:"wood"` + WoodFactor float64 `xml:"wood_factor"` } type BuildingInfo struct { diff --git a/internal/tw/server_config.go b/internal/tw/server_config.go index 8cb65e2..7613605 100644 --- a/internal/tw/server_config.go +++ b/internal/tw/server_config.go @@ -12,19 +12,19 @@ type ServerConfigBuild struct { type ServerConfigMisc struct { KillRanking int `xml:"kill_ranking"` - Tutorial int `xml:"tutorial"` TradeCancelTime int `xml:"trade_cancel_time"` + Tutorial int `xml:"tutorial"` } type ServerConfigCommands struct { - MillisArrival int `xml:"millis_arrival"` CommandCancelTime int `xml:"command_cancel_time"` + MillisArrival int `xml:"millis_arrival"` } type ServerConfigNewbie struct { Days int `xml:"days"` - RatioDays int `xml:"ratio_days"` Ratio int `xml:"ratio"` + RatioDays int `xml:"ratio_days"` RemoveNewbieVillages int `xml:"removeNewbieVillages"` } @@ -54,89 +54,89 @@ func (k *KnightNewItems) UnmarshalXML(d *xml.Decoder, start xml.StartElement) er } type ServerConfigGame struct { - BuildtimeFormula int `xml:"buildtime_formula"` - Knight int `xml:"knight"` - KnightNewItems KnightNewItems `xml:"knight_new_items"` Archer int `xml:"archer"` - Tech int `xml:"tech"` - FarmLimit int `xml:"farm_limit"` - Church int `xml:"church"` - Watchtower int `xml:"watchtower"` - Stronghold int `xml:"stronghold"` - FakeLimit float64 `xml:"fake_limit"` + BarbarianMaxPoints int `xml:"barbarian_max_points"` BarbarianRise float64 `xml:"barbarian_rise"` BarbarianShrink int `xml:"barbarian_shrink"` - BarbarianMaxPoints int `xml:"barbarian_max_points"` - Scavenging int `xml:"scavenging"` + BaseProduction int `xml:"base_production"` + BuildtimeFormula int `xml:"buildtime_formula"` + Church int `xml:"church"` + Event int `xml:"event"` + FakeLimit float64 `xml:"fake_limit"` + FarmLimit int `xml:"farm_limit"` Hauls int `xml:"hauls"` HaulsBase int `xml:"hauls_base"` HaulsMax int `xml:"hauls_max"` - BaseProduction int `xml:"base_production"` - Event int `xml:"event"` + Knight int `xml:"knight"` + KnightNewItems KnightNewItems `xml:"knight_new_items"` + Scavenging int `xml:"scavenging"` + Stronghold int `xml:"stronghold"` SuppressEvents int `xml:"suppress_events"` + Tech int `xml:"tech"` + Watchtower int `xml:"watchtower"` } type ServerConfigBuildings struct { - CustomMain int `xml:"custom_main"` - CustomFarm int `xml:"custom_farm"` - CustomStorage int `xml:"custom_storage"` - CustomPlace int `xml:"custom_place"` CustomBarracks int `xml:"custom_barracks"` CustomChurch int `xml:"custom_church"` - CustomSmith int `xml:"custom_smith"` - CustomWood int `xml:"custom_wood"` - CustomStone int `xml:"custom_stone"` - CustomIron int `xml:"custom_iron"` - CustomMarket int `xml:"custom_market"` - CustomStable int `xml:"custom_stable"` - CustomWall int `xml:"custom_wall"` + CustomFarm int `xml:"custom_farm"` CustomGarage int `xml:"custom_garage"` CustomHide int `xml:"custom_hide"` + CustomIron int `xml:"custom_iron"` + CustomMain int `xml:"custom_main"` + CustomMarket int `xml:"custom_market"` + CustomPlace int `xml:"custom_place"` + CustomSmith int `xml:"custom_smith"` CustomSnob int `xml:"custom_snob"` + CustomStable int `xml:"custom_stable"` CustomStatue int `xml:"custom_statue"` + CustomStone int `xml:"custom_stone"` + CustomStorage int `xml:"custom_storage"` + CustomWall int `xml:"custom_wall"` CustomWatchtower int `xml:"custom_watchtower"` + CustomWood int `xml:"custom_wood"` } type ServerConfigSnob struct { - Gold int `xml:"gold"` CheapRebuild int `xml:"cheap_rebuild"` - Rise int `xml:"rise"` - MaxDist int `xml:"max_dist"` - Factor float64 `xml:"factor"` - CoinWood int `xml:"coin_wood"` - CoinStone int `xml:"coin_stone"` CoinIron int `xml:"coin_iron"` + CoinStone int `xml:"coin_stone"` + CoinWood int `xml:"coin_wood"` + Factor float64 `xml:"factor"` + Gold int `xml:"gold"` + MaxDist int `xml:"max_dist"` NoBarbConquer int `xml:"no_barb_conquer"` + Rise int `xml:"rise"` } type ServerConfigAlly struct { + AllytimeSupport int `xml:"allytime_support"` + FixedAllies int `xml:"fixed_allies"` + Levels int `xml:"levels"` + Limit int `xml:"limit"` NoHarm int `xml:"no_harm"` + NoJoin int `xml:"no_join"` + NoLeave int `xml:"no_leave"` NoOtherSupport int `xml:"no_other_support"` NoOtherSupportType int `xml:"no_other_support_type"` - AllytimeSupport int `xml:"allytime_support"` - NoLeave int `xml:"no_leave"` - NoJoin int `xml:"no_join"` - Limit int `xml:"limit"` - FixedAllies int `xml:"fixed_allies"` PointsMemberCount int `xml:"points_member_count"` + WarsAutoacceptDays int `xml:"wars_autoaccept_days"` WarsMemberRequirement int `xml:"wars_member_requirement"` WarsPointsRequirement int `xml:"wars_points_requirement"` - WarsAutoacceptDays int `xml:"wars_autoaccept_days"` - Levels int `xml:"levels"` XpRequirements string `xml:"xp_requirements"` } type ServerConfigCoord struct { - MapSize int `xml:"map_size"` - Func int `xml:"func"` - EmptyVillages int `xml:"empty_villages"` - BonusVillages int `xml:"bonus_villages"` BonusNew int `xml:"bonus_new"` + BonusVillages int `xml:"bonus_villages"` + EmptyVillages int `xml:"empty_villages"` + Func int `xml:"func"` Inner int `xml:"inner"` - SelectStart int `xml:"select_start"` - VillageMoveWait int `xml:"village_move_wait"` + MapSize int `xml:"map_size"` NobleRestart int `xml:"noble_restart"` + SelectStart int `xml:"select_start"` StartVillages int `xml:"start_villages"` + VillageMoveWait int `xml:"village_move_wait"` } type ServerConfigSitter struct { @@ -146,19 +146,19 @@ type ServerConfigSitter struct { type ServerConfigSleep struct { Active int `xml:"active"` Delay int `xml:"delay"` - Min int `xml:"min"` Max int `xml:"max"` - MinAwake int `xml:"min_awake"` MaxAwake int `xml:"max_awake"` + Min int `xml:"min"` + MinAwake int `xml:"min_awake"` WarnTime int `xml:"warn_time"` } type ServerConfigNight struct { Active int `xml:"active"` - StartHour int `xml:"start_hour"` - EndHour int `xml:"end_hour"` DefFactor float64 `xml:"def_factor"` Duration int `xml:"duration"` + EndHour int `xml:"end_hour"` + StartHour int `xml:"start_hour"` } type ServerConfigWin struct { diff --git a/internal/tw/unit_info.go b/internal/tw/unit_info.go index a1fcc47..ff52f46 100644 --- a/internal/tw/unit_info.go +++ b/internal/tw/unit_info.go @@ -5,14 +5,14 @@ import ( ) type Unit struct { + Attack int `xml:"attack"` BuildTime float64 `xml:"build_time"` + Carry int `xml:"carry"` + Defense int `xml:"defense"` + DefenseArcher int `xml:"defense_archer"` + DefenseCavalry int `xml:"defense_cavalry"` Pop int `xml:"pop"` Speed float64 `xml:"speed"` - Attack int `xml:"attack"` - Defense int `xml:"defense"` - DefenseCavalry int `xml:"defense_cavalry"` - DefenseArcher int `xml:"defense_archer"` - Carry int `xml:"carry"` } type UnitInfo struct {