From cbbb765bd137df3b0d2d44fa47456b635a5f27f7 Mon Sep 17 00:00:00 2001 From: Shingo INADA Date: Sat, 2 May 2020 12:23:04 +0900 Subject: [PATCH] inject version info --- .github/workflows/release.yml | 2 +- Makefile | 13 +++++--- gdxsv/lbs.go | 4 +-- gdxsv/lbs_lobby.go | 19 +++++------ gdxsv/lbs_mcsfunc.go | 4 +-- gdxsv/main.go | 61 +++++++++++++++++++++-------------- gdxsv/shareddata.go | 2 +- 7 files changed, 59 insertions(+), 46 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3183803..478a940 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -24,7 +24,7 @@ jobs: - name: Get dependencies run: go get -u -a golang.org/x/tools/cmd/stringer - name: Build - run: make ci + run: make release - name: Release uses: meeDamian/github-release@2.0 with: diff --git a/Makefile b/Makefile index 3a90222..d0529d7 100644 --- a/Makefile +++ b/Makefile @@ -1,15 +1,20 @@ all: build -# all build for local environment. .PHONY: build build: mkdir -p bin go generate ./gdxsv - go build -o bin/gdxsv ./gdxsv + go build -ldflags "-X main.gdxsvVersion=$(shell git describe --tags --abbrev=0) -X main.gdxsvRevision=$(shell git rev-parse --short HEAD)" -o bin/gdxsv ./gdxsv -# ci .PHONY: ci ci: mkdir -p bin go generate ./gdxsv - go build -o bin/gdxsv ./gdxsv + go build -ldflags "-X main.gdxsvVersion=$(shell git describe --tags --abbrev=0) -X main.gdxsvRevision=$(shell git rev-parse --short HEAD)" -o bin/gdxsv ./gdxsv + +.PHONY: release +release: + mkdir -p bin + go generate ./gdxsv + go build -ldflags "-X main.gdxsvVersion=$(shell git describe --tags --abbrev=0) -X main.gdxsvRevision=$(shell git rev-parse --short HEAD)" -o bin/gdxsv ./gdxsv + diff --git a/gdxsv/lbs.go b/gdxsv/lbs.go index 690de80..b3c6929 100644 --- a/gdxsv/lbs.go +++ b/gdxsv/lbs.go @@ -82,8 +82,8 @@ func (lbs *Lbs) GetLobby(platform uint8, lobbyID uint16) *LbsLobby { return lobby } -func (s *Lbs) ListenAndServeLobby(addr string) error { - glog.Info("ListenAndServeLobby", addr) +func (s *Lbs) ListenAndServe(addr string) error { + glog.Info("ListenAndServe", addr) tcpAddr, err := net.ResolveTCPAddr("tcp", addr) if err != nil { diff --git a/gdxsv/lbs_lobby.go b/gdxsv/lbs_lobby.go index 83f7e8b..71116c5 100644 --- a/gdxsv/lbs_lobby.go +++ b/gdxsv/lbs_lobby.go @@ -32,6 +32,7 @@ func NewLobby(app *Lbs, platform uint8, lobbyID uint16) *LbsLobby { ZeonRooms: make(map[uint16]*LbsRoom), EntryUsers: make([]string, 0), } + for i := 1; i <= maxRoomCount; i++ { roomID := uint16(i) lobby.RenpoRooms[roomID] = NewRoom(app, platform, lobby, roomID, TeamRenpo) @@ -59,28 +60,20 @@ func NewLobby(app *Lbs, platform uint8, lobbyID uint16) *LbsLobby { lobby.Rule.ReloadFlag = 1 case 10: lobby.McsRegion = "asia-east1" - lobby.Comment = fmt.Sprintf("%s
%s", lobby.McsRegion, gcpLocationName[lobby.McsRegion]) case 11: lobby.McsRegion = "asia-east2" - lobby.Comment = fmt.Sprintf("%s
%s", lobby.McsRegion, gcpLocationName[lobby.McsRegion]) case 12: lobby.McsRegion = "asia-northeast1" - lobby.Comment = fmt.Sprintf("%s
%s", lobby.McsRegion, gcpLocationName[lobby.McsRegion]) case 13: lobby.McsRegion = "asia-northeast2" - lobby.Comment = fmt.Sprintf("%s
%s", lobby.McsRegion, gcpLocationName[lobby.McsRegion]) case 14: lobby.McsRegion = "australia-southeast1" - lobby.Comment = fmt.Sprintf("%s
%s", lobby.McsRegion, gcpLocationName[lobby.McsRegion]) case 15: lobby.McsRegion = "europe-west3" - lobby.Comment = fmt.Sprintf("%s
%s", lobby.McsRegion, gcpLocationName[lobby.McsRegion]) case 16: lobby.McsRegion = "us-central1" - lobby.Comment = fmt.Sprintf("%s
%s", lobby.McsRegion, gcpLocationName[lobby.McsRegion]) case 17: lobby.McsRegion = "us-east1" - lobby.Comment = fmt.Sprintf("%s
%s", lobby.McsRegion, gcpLocationName[lobby.McsRegion]) case 19: lobby.Comment = "ダメージレベル4
DAMAGELEVEL4" lobby.Rule.DamageLevel = 3 @@ -98,6 +91,10 @@ func NewLobby(app *Lbs, platform uint8, lobbyID uint16) *LbsLobby { } } + if lobby.McsRegion != "" { + lobby.Comment = fmt.Sprintf("%s
%s", lobby.McsRegion, gcpLocationName[lobby.McsRegion]) + } + return lobby } @@ -196,7 +193,7 @@ func (l *LbsLobby) GetLobbyMatchEntryUserCount() (uint16, uint16) { func (l *LbsLobby) pickLobbyBattleParticipants() []*LbsPeer { a := uint16(0) b := uint16(0) - peers := []*LbsPeer{} + var peers []*LbsPeer for _, userID := range l.EntryUsers { if p := l.app.FindPeer(userID); p != nil { switch p.Team { @@ -254,7 +251,7 @@ func (l *LbsLobby) CheckLobbyBattleStart() { Players: len(participants), Aggregate: 1, }) - AddUserWhoIsGoingTobattle( + AddUserWhoIsGoingToBattle( b.BattleCode, b.McsRegion, q.UserID, q.Name, q.Team, q.SessionID) NotifyReadyBattle(q) } @@ -338,7 +335,7 @@ func (l *LbsLobby) CheckRoomBattleStart() { Players: len(participants), Aggregate: 1, }) - AddUserWhoIsGoingTobattle( + AddUserWhoIsGoingToBattle( b.BattleCode, b.McsRegion, q.UserID, q.Name, q.Team, q.SessionID) NotifyReadyBattle(q) } diff --git a/gdxsv/lbs_mcsfunc.go b/gdxsv/lbs_mcsfunc.go index e162fd3..0f599bf 100644 --- a/gdxsv/lbs_mcsfunc.go +++ b/gdxsv/lbs_mcsfunc.go @@ -70,7 +70,7 @@ func McsFuncEnabled() bool { } func McsFuncAlloc(region string) error { - if time.Since(mcsFuncRequestTime["alloc/"+region]).Seconds() <= 10 { + if time.Since(mcsFuncRequestTime["alloc/"+region]).Seconds() <= 30 { return nil } mcsFuncRequestTime["alloc/"+region] = time.Now() @@ -80,7 +80,7 @@ func McsFuncAlloc(region string) error { return err } - resp, err := client.Get(conf.McsFuncURL + fmt.Sprintf("/alloc?region=%s", region)) + resp, err := client.Get(conf.McsFuncURL + fmt.Sprintf("/alloc?region=%s&version=%s", region, gdxsvVersion)) if err != nil { return err } diff --git a/gdxsv/main.go b/gdxsv/main.go index d9da724..89e96e9 100644 --- a/gdxsv/main.go +++ b/gdxsv/main.go @@ -18,10 +18,16 @@ import ( ) var ( - conf Config - dump = flag.Bool("dump", false, "enable var dump to dump.txt") - cpu = flag.Int("cpu", 2, "setting GOMAXPROCS") - profile = flag.Int("profile", 1, "0: no profile, 1: enable http pprof, 2: enable blocking profile") + // This will be overwritten via ldflags. + gdxsvVersion string + gdxsvRevision string +) + +var ( + conf Config + dump = flag.Bool("dump", false, "enable var dump to dump.txt") + cpu = flag.Int("cpu", 2, "setting GOMAXPROCS") + profile = flag.Int("profile", 1, "0: no profile, 1: enable http pprof, 2: enable blocking profile") mcsdelay = flag.Duration("mcsdelay", 0, "mcs room delay for network lag emulation") ) @@ -36,6 +42,30 @@ type Config struct { DBName string `env:"GDXSV_DB_NAME" envDefault:"gdxsv.db"` } +func printHeader() { + glog.Infoln("========================================================================") + glog.Infoln(" gdxsv - Mobile Suit Gundam: Federation vs. Zeon&DX Private Game Server.") + glog.Infof(" Version: %v (%v)\n", gdxsvVersion, gdxsvRevision) + glog.Infoln("========================================================================") +} + +func printUsage() { + glog.Info("") + glog.Info("Usage: gdxsv [lbs, mcs, initdb]") + glog.Info("") + glog.Info(" lbs: Serve lobby server and default battle server.") + glog.Info(" A lbs hosts PS2, DC1 and DC2 version, but their lobbies are separated internally.") + glog.Info("") + glog.Info(" mcs: Serve battle server.") + glog.Info(" The mcs attempts to register itself with a lbs.") + glog.Info(" When the mcs is vacant for a certain period, it will automatically end.") + glog.Info(" It is supposed to host mcs in a different location than the lobby server.") + glog.Info("") + glog.Info(" initdb: Initialize database.") + glog.Info(" It is supposed to run this command when first booting manually.") + glog.Info(" Note that if the database file already exists it will be permanently deleted.") +} + func loadConfig() { var c Config if err := env.Parse(&c); err != nil { @@ -57,23 +87,6 @@ func pprofPort(mode string) int { } } -func printUsage() { - glog.Info("") - glog.Info("Usage: gdxsv [lbs, mcs, initdb]") - glog.Info("") - glog.Info(" lbs: Serve lobby server and default battle server.") - glog.Info(" A lbs hosts PS2, DC1 and DC2 version, but their lobbies are separated internally.") - glog.Info("") - glog.Info(" mcs: Serve battle server.") - glog.Info(" The mcs attempts to register itself with a lbs.") - glog.Info(" When the mcs is vacant for a certain period, it will automatically end.") - glog.Info(" It is supposed to host mcs in a different location than the lobby server.") - glog.Info("") - glog.Info(" initdb: Initialize database.") - glog.Info(" It is supposed to run this command when first booting manually.") - glog.Info(" Note that if the database file already exists it will be permanently deleted.") -} - func prepareOption(command string) { runtime.GOMAXPROCS(*cpu) if *profile >= 1 { @@ -109,7 +122,7 @@ func prepareDB() { func mainLbs() { lbs := NewLbs() - go lbs.ListenAndServeLobby(stripHost(conf.LobbyAddr)) + go lbs.ListenAndServe(stripHost(conf.LobbyAddr)) defer lbs.Quit() mcs := NewMcs(*mcsdelay) @@ -152,9 +165,7 @@ func main() { flag.Parse() rand.Seed(time.Now().UnixNano()) - glog.Infoln("========================================================================") - glog.Infoln(" gdxsv - Mobile Suit Gundam: Federation vs. Zeon&DX Private Game Server.") - glog.Infoln("========================================================================") + printHeader() args := flag.Args() glog.Infoln(args, len(args)) diff --git a/gdxsv/shareddata.go b/gdxsv/shareddata.go index cfcd101..67522c4 100644 --- a/gdxsv/shareddata.go +++ b/gdxsv/shareddata.go @@ -47,7 +47,7 @@ type LbsStatus struct { Users []McsUser `json:"users,omitempty"` } -func AddUserWhoIsGoingTobattle(battleCode string, mcsRegion string, userID string, name string, side uint16, sessionID string) { +func AddUserWhoIsGoingToBattle(battleCode string, mcsRegion string, userID string, name string, side uint16, sessionID string) { sharedData.Lock() defer sharedData.Unlock() sharedData.battleUsers[sessionID] = McsUser{