add unit_config, server_config, building_config and dataUpdatedAt fields to graphql

This commit is contained in:
Dawid Wysokiński 2020-06-19 19:50:23 +02:00
parent 917780f737
commit 74267fbd86
11 changed files with 8707 additions and 14 deletions

View File

@ -5,6 +5,8 @@ import (
"strconv"
"time"
"github.com/tribalwarshelp/api/utils"
"github.com/pkg/errors"
"github.com/tribalwarshelp/shared/models"
)
@ -14,13 +16,10 @@ type lineParser struct {
}
func newLineParser(timezone string) (*lineParser, error) {
loc, err := time.LoadLocation(timezone)
if err != nil {
return nil, fmt.Errorf("Invalid timezone: %s", timezone)
}
return &lineParser{
location: loc,
}, nil
location: utils.GetLocation(timezone),
},
nil
}
func (parser *lineParser) parse(line []string) (*models.Ennoblement, error) {

8
go.mod
View File

@ -5,17 +5,17 @@ go 1.14
require (
github.com/99designs/gqlgen v0.11.3
github.com/gin-gonic/gin v1.6.3
github.com/go-pg/pg/v10 v10.0.0-beta.1
github.com/go-pg/pg/v10 v10.0.0-beta.2
github.com/go-playground/validator/v10 v10.3.0 // indirect
github.com/go-redis/redis/v8 v8.0.0-beta.5
github.com/joho/godotenv v1.3.0
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/pkg/errors v0.9.1
github.com/segmentio/encoding v0.1.13 // indirect
github.com/tribalwarshelp/shared v0.0.0-20200618150949-896cd6c98d06
github.com/segmentio/encoding v0.1.14 // indirect
github.com/tribalwarshelp/shared v0.0.0-20200619170430-9ae1e58e717a
github.com/vektah/gqlparser/v2 v2.0.1
golang.org/x/net v0.0.0-20200602114024-627f9648deb9 // indirect
golang.org/x/sys v0.0.0-20200602100848-8d3cce7afc34 // indirect
golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1 // indirect
gopkg.in/yaml.v2 v2.3.0 // indirect
)

24
go.sum
View File

@ -44,6 +44,8 @@ github.com/gin-gonic/gin v1.6.3/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwv
github.com/go-chi/chi v3.3.2+incompatible/go.mod h1:eB3wogJHnLi3x/kFX2A+IbTBlXxmMeXJVKy9tTv1XzQ=
github.com/go-pg/pg/v10 v10.0.0-beta.1 h1:GD65aZVx9yR6fxxXdglBlook89oxxg2FYE11TDd9Now=
github.com/go-pg/pg/v10 v10.0.0-beta.1/go.mod h1:JYxBTzIz9dpSAa+bphD1U7A/PBCwiuw1o8pYNDSsQ+4=
github.com/go-pg/pg/v10 v10.0.0-beta.2 h1:8tNEJLtOEw5/Df0BLLBOHCiLaYAiu4uhdngjK955MK8=
github.com/go-pg/pg/v10 v10.0.0-beta.2/go.mod h1:UAuqGPC94ySi4rJ3DC5e4SY1rlwugZbJA/XoJ/kf5Rw=
github.com/go-pg/pg/v9 v9.0.0-beta.14/go.mod h1:T2Sr6bpTCOr2lUqOUMiXLMJqZHSUBKk1LdgSqjwhZfA=
github.com/go-pg/pg/v9 v9.0.3/go.mod h1:Tm/Q3Vt6gdQOH6TTN1H/xLlIXc+Qrka7TZ6uREtu/eA=
github.com/go-pg/pg/v9 v9.1.6 h1:IqBayenvp9EWjHncRE7//SRmQuktq60oeO1/MkEx3dY=
@ -151,6 +153,8 @@ github.com/segmentio/encoding v0.1.12 h1:SwIDXReTDnlYqOcLachzJEczAEihST7Mx7nGlAW
github.com/segmentio/encoding v0.1.12/go.mod h1:RWhr02uzMB9gQC1x+MfYxedtmBibb9cZ6Vv9VxRSSbw=
github.com/segmentio/encoding v0.1.13 h1:izH8HknGvMZvlqplu+kmCmbsW5VEvz4yBsZpdUUKUDM=
github.com/segmentio/encoding v0.1.13/go.mod h1:RWhr02uzMB9gQC1x+MfYxedtmBibb9cZ6Vv9VxRSSbw=
github.com/segmentio/encoding v0.1.14 h1:BfnglNbNRohLaBLf93uP5/IwKqeWrezXK/g6IRnj75c=
github.com/segmentio/encoding v0.1.14/go.mod h1:RWhr02uzMB9gQC1x+MfYxedtmBibb9cZ6Vv9VxRSSbw=
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
github.com/shurcooL/httpfs v0.0.0-20171119174359-809beceb2371/go.mod h1:ZY1cvUeJuFPAdZ/B6v7RHavJWZn2YPVFQ1OSXhCGOkg=
@ -170,6 +174,18 @@ github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc h1:9lRDQMhESg+zvGYm
github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc/go.mod h1:bciPuU6GHm1iF1pBvUfxfsH0Wmnc2VbpgvbI9ZWuIRs=
github.com/tribalwarshelp/shared v0.0.0-20200618150949-896cd6c98d06 h1:T87o4fice0XTUdAG/tctFCDiuyUGb10bY1hdWvwlrro=
github.com/tribalwarshelp/shared v0.0.0-20200618150949-896cd6c98d06/go.mod h1:tf+2yTHasV6jAF3V2deZ9slNoCyBzC0fMdTjI7clf6Y=
github.com/tribalwarshelp/shared v0.0.0-20200619133428-b2cab5452bdc h1:Rx6Mi32rNCp0YZ2KfVDBttPCZ4UMC3WWjyHGMhAbJ/4=
github.com/tribalwarshelp/shared v0.0.0-20200619133428-b2cab5452bdc/go.mod h1:tf+2yTHasV6jAF3V2deZ9slNoCyBzC0fMdTjI7clf6Y=
github.com/tribalwarshelp/shared v0.0.0-20200619155726-3476188924c3 h1:vJyTmEdxs6b3BJ3c2QsobHWQgfCQl9ninyVLnLD2yFk=
github.com/tribalwarshelp/shared v0.0.0-20200619155726-3476188924c3/go.mod h1:tf+2yTHasV6jAF3V2deZ9slNoCyBzC0fMdTjI7clf6Y=
github.com/tribalwarshelp/shared v0.0.0-20200619160727-e6290ee856b4 h1:3YxJkIVpqXxr8QmHu28sH2z1rMQLlwBQY7Ofiw1HubQ=
github.com/tribalwarshelp/shared v0.0.0-20200619160727-e6290ee856b4/go.mod h1:tf+2yTHasV6jAF3V2deZ9slNoCyBzC0fMdTjI7clf6Y=
github.com/tribalwarshelp/shared v0.0.0-20200619160938-496316e74a8b h1:EK/RSHhBB+xalIhBWCpw78POvtNmJQw//w6v7oyo5Pg=
github.com/tribalwarshelp/shared v0.0.0-20200619160938-496316e74a8b/go.mod h1:tf+2yTHasV6jAF3V2deZ9slNoCyBzC0fMdTjI7clf6Y=
github.com/tribalwarshelp/shared v0.0.0-20200619163026-783d3512bc3e h1:u54k/lorToKUmhruBLLLtykF4MBC3qu5xrzDTk2WLjY=
github.com/tribalwarshelp/shared v0.0.0-20200619163026-783d3512bc3e/go.mod h1:tf+2yTHasV6jAF3V2deZ9slNoCyBzC0fMdTjI7clf6Y=
github.com/tribalwarshelp/shared v0.0.0-20200619170430-9ae1e58e717a h1:DvZaFa0q43ME/j9vBQMgI2v23Re/Dx11pxqpXw5NzC4=
github.com/tribalwarshelp/shared v0.0.0-20200619170430-9ae1e58e717a/go.mod h1:tf+2yTHasV6jAF3V2deZ9slNoCyBzC0fMdTjI7clf6Y=
github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo=
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs=
@ -188,6 +204,8 @@ github.com/vmihailenco/msgpack/v4 v4.3.11 h1:Q47CePddpNGNhk4GCnAx9DDtASi2rasatE0
github.com/vmihailenco/msgpack/v4 v4.3.11/go.mod h1:gborTTJjAo/GWTqqRjrLCn9pgNN+NXzzngzBKDPIqw4=
github.com/vmihailenco/msgpack/v5 v5.0.0-alpha.2 h1:0jVpYJSRJzGY7m21n9V5uIkl7Zre64W8DR1dxEKX2g4=
github.com/vmihailenco/msgpack/v5 v5.0.0-alpha.2/go.mod h1:LDfrk4wJpSFwkzNOJxrCWiSm8c7Iqw/hXNPT2fzQfE8=
github.com/vmihailenco/msgpack/v5 v5.0.0-beta.1 h1:d71/KA0LhvkrJ/Ok+Wx9qK7bU8meKA1Hk0jpVI5kJjk=
github.com/vmihailenco/msgpack/v5 v5.0.0-beta.1/go.mod h1:xlngVLeyQ/Qi05oQxhQ+oTuqa03RjMwMfk/7/TCs+QI=
github.com/vmihailenco/tagparser v0.1.0/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgqMEUPoW2WPyhdI=
github.com/vmihailenco/tagparser v0.1.1 h1:quXMXlA39OCbd2wAdTsGDlK9RkOk6Wuw+x37wVyIuWY=
github.com/vmihailenco/tagparser v0.1.1/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgqMEUPoW2WPyhdI=
@ -202,6 +220,8 @@ golang.org/x/crypto v0.0.0-20191128160524-b544559bb6d1/go.mod h1:LzIPMQfyMNhhGPh
golang.org/x/crypto v0.0.0-20200221231518-2aa609cf4a9d/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37 h1:cg5LA/zNPRzIXIWSCxQW10Rvpy94aQh3LT/ShoCpkHw=
golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200604202706-70a84ac30bf9 h1:vEg9joUBmeBcK9iSJftGNf3coIG4HqZElCPehJsfAYM=
golang.org/x/crypto v0.0.0-20200604202706-70a84ac30bf9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
@ -242,6 +262,10 @@ golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200602100848-8d3cce7afc34 h1:u6CI7A++8r4SItZHYe2cWeAEndN4p1p+3Oum/Ft2EzM=
golang.org/x/sys v0.0.0-20200602100848-8d3cce7afc34/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200602225109-6fdc65e7d980 h1:OjiUf46hAmXblsZdnoSXsEUSKU8r1UEzcL5RVZ4gO9Y=
golang.org/x/sys v0.0.0-20200602225109-6fdc65e7d980/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1 h1:ogLJMz+qpzav7lGMh10LMvAkM/fAoGlaiiHYiFYdm80=
golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=

File diff suppressed because it is too large Load Diff

View File

@ -22,6 +22,42 @@ models:
model: github.com/tribalwarshelp/shared/models.LangVersionFilter
Server:
model: github.com/tribalwarshelp/shared/models.Server
ServerConfig:
model: github.com/tribalwarshelp/shared/models.ServerConfig
ServerConfigBuild:
model: github.com/tribalwarshelp/shared/models.ServerConfigBuild
ServerConfigMisc:
model: github.com/tribalwarshelp/shared/models.ServerConfigMisc
ServerConfigCommands:
model: github.com/tribalwarshelp/shared/models.ServerConfigCommands
ServerConfigNewbie:
model: github.com/tribalwarshelp/shared/models.ServerConfigNewbie
ServerConfigGame:
model: github.com/tribalwarshelp/shared/models.ServerConfigGame
ServerConfigBuildings:
model: github.com/tribalwarshelp/shared/models.ServerConfigBuildings
ServerConfigSnob:
model: github.com/tribalwarshelp/shared/models.ServerConfigSnob
ServerConfigAlly:
model: github.com/tribalwarshelp/shared/models.ServerConfigAlly
ServerConfigCoord:
model: github.com/tribalwarshelp/shared/models.ServerConfigCoord
ServerConfigSitter:
model: github.com/tribalwarshelp/shared/models.ServerConfigSitter
ServerConfigSleep:
model: github.com/tribalwarshelp/shared/models.ServerConfigSleep
ServerConfigNight:
model: github.com/tribalwarshelp/shared/models.ServerConfigNight
ServerConfigWin:
model: github.com/tribalwarshelp/shared/models.ServerConfigWin
Unit:
model: github.com/tribalwarshelp/shared/models.Unit
UnitConfig:
model: github.com/tribalwarshelp/shared/models.UnitConfig
Building:
model: github.com/tribalwarshelp/shared/models.Building
BuildingConfig:
model: github.com/tribalwarshelp/shared/models.BuildingConfig
ServerFilter:
model: github.com/tribalwarshelp/shared/models.ServerFilter
Player:

View File

@ -2,6 +2,9 @@ package resolvers
import (
"context"
"time"
"github.com/tribalwarshelp/api/utils"
"github.com/tribalwarshelp/api/middleware"
@ -18,6 +21,18 @@ func (r *serverResolver) LangVersion(ctx context.Context, obj *models.Server) (*
return nil, nil
}
func (r *serverResolver) DataUpdatedAt(ctx context.Context, obj *models.Server) (*time.Time, error) {
loaders := middleware.DataLoadersFromContext(ctx)
if loaders != nil {
lv, err := loaders.LangVersionByTag.Load(obj.LangVersionTag.String())
if err == nil {
dataUpdatedAt := obj.DataUpdatedAt.In(utils.GetLocation(lv.Timezone))
return &dataUpdatedAt, nil
}
}
return &obj.DataUpdatedAt, nil
}
func (r *queryResolver) Servers(ctx context.Context, filter *models.ServerFilter) (*generated.ServersList, error) {
var err error
list := &generated.ServersList{}

View File

@ -0,0 +1,34 @@
type Building {
maxLevel: Int!
minLevel: Int!
wood: Int!
stone: Int!
iron: Int!
pop: Int!
woodFactor: Float!
stoneFactor: Float!
ironFactor: Float!
popFactor: Float!
buildTime: Float!
buildTimeFactor: Float!
}
type BuildingConfig {
main: Building!
barracks: Building!
stable: Building!
garage: Building!
watchtower: Building!
snob: Building!
smith: Building!
place: Building!
statue: Building!
market: Building!
wood: Building!
stone: Building!
iron: Building!
farm: Building!
storage: Building!
hide: Building!
wall: Building!
}

View File

@ -8,6 +8,10 @@ type Server {
key: String!
status: ServerStatus!
langVersion: LangVersion @goField(forceResolver: true)
config: ServerConfig!
unitConfig: UnitConfig!
buildingConfig: BuildingConfig!
dataUpdatedAt: Time! @goField(forceResolver: true)
}
type ServersList {

View File

@ -0,0 +1,149 @@
type ServerConfigBuild {
destroy: Int!
}
type ServerConfigMisc {
killRanking: Int!
tutorial: Int!
tradeCancelTime: Int!
}
type ServerConfigCommands {
millisArrival: Int!
commandCancelTime: Int!
}
type ServerConfigNewbie {
days: Int!
ratioDays: Int!
ratio: Int!
removeNewbieVillages: Int!
}
type ServerConfigGame {
buildtimeFormula: Int!
knight: Int!
knightNewItems: Boolean!
archer: Int!
tech: Int!
farmLimit: Int!
church: Int!
watchtower: Int!
stronghold: Int!
fakeLimit: Int!
barbarianRise: Float!
barbarianShrink: Int!
barbarianMaxPoints: Int!
hauls: Int!
haulsBase: Int!
haulsMax: Int!
baseProduction: Int!
event: Int!
suppressEvents: Int!
}
type ServerConfigBuildings {
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!
customGarage: Int!
customHide: Int!
customSnob: Int!
customStatue: Int!
customWatchtower: Int!
}
type ServerConfigSnob {
gold: Int!
cheapRebuild: Int!
rise: Int!
maxDist: Int!
factor: Float!
coinWood: Int!
coinStone: Int!
coinIron: Int!
noBarbConquer: Boolean!
}
type ServerConfigAlly {
noHarm: Int!
noOtherSupport: Int!
allytimeSupport: Int!
noLeave: Int!
noJoin: Int!
limit: Int!
fixedAllies: Int!
pointsMemberCount: Int!
warsMemberRequirement: Int!
warsPointsRequirement: Int!
warsAutoacceptDays: Int!
levels: Int!
xpRequirements: String!
}
type ServerConfigCoord {
mapSize: Int!
func: Int!
emptyVillages: Int!
bonusVillages: Int!
bonusNew: Int!
inner: Int!
selectStart: Int!
villageMoveWait: Int!
nobleRestart: Int!
startVillages: Int!
}
type ServerConfigSitter {
allow: Int!
}
type ServerConfigSleep {
active: Int!
delay: Int!
min: Int!
max: Int!
minAwake: Int!
maxAwake: Int!
warnTime: Int!
}
type ServerConfigNight {
active: Int!
startHour: Int!
endHour: Int!
defFactor: Int!
}
type ServerConfigWin {
check: Int!
}
type ServerConfig {
speed: Float!
unitSpeed: Float!
moral: Int!
build: ServerConfigBuild!
misc: ServerConfigMisc!
commands: ServerConfigCommands!
newbie: ServerConfigNewbie!
game: ServerConfigGame!
buildings: ServerConfigBuildings!
snob: ServerConfigSnob!
ally: ServerConfigAlly!
coord: ServerConfigCoord!
sitter: ServerConfigSitter!
sleep: ServerConfigSleep!
night: ServerConfigNight!
win: ServerConfigWin!
}

View File

@ -0,0 +1,26 @@
type Unit {
buildTime: Float!
pop: Int!
speed: Float!
attack: Int!
defense: Int!
defenseCavalry: Int!
defenseArcher: Int!
carry: Int!
}
type UnitConfig {
spear: Unit!
sword: Unit!
axe: Unit!
archer: Unit!
spy: Unit!
light: Unit!
marcher: Unit!
heavy: Unit!
ram: Unit!
catapult: Unit!
knight: Unit!
snob: Unit!
militia: Unit!
}

11
utils/get_location.go Normal file
View File

@ -0,0 +1,11 @@
package utils
import "time"
func GetLocation(timezone string) *time.Location {
loc, err := time.LoadLocation(timezone)
if err == nil {
return loc
}
return time.UTC
}