Skip to content

Commit

Permalink
inject version info
Browse files Browse the repository at this point in the history
  • Loading branch information
inada-s committed May 2, 2020
1 parent 1752b00 commit cbbb765
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
with:
Expand Down
13 changes: 9 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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

4 changes: 2 additions & 2 deletions gdxsv/lbs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
19 changes: 8 additions & 11 deletions gdxsv/lbs_lobby.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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("<B>%s<B><BR><B>%s<END>", lobby.McsRegion, gcpLocationName[lobby.McsRegion])
case 11:
lobby.McsRegion = "asia-east2"
lobby.Comment = fmt.Sprintf("<B>%s<B><BR><B>%s<END>", lobby.McsRegion, gcpLocationName[lobby.McsRegion])
case 12:
lobby.McsRegion = "asia-northeast1"
lobby.Comment = fmt.Sprintf("<B>%s<B><BR><B>%s<END>", lobby.McsRegion, gcpLocationName[lobby.McsRegion])
case 13:
lobby.McsRegion = "asia-northeast2"
lobby.Comment = fmt.Sprintf("<B>%s<B><BR><B>%s<END>", lobby.McsRegion, gcpLocationName[lobby.McsRegion])
case 14:
lobby.McsRegion = "australia-southeast1"
lobby.Comment = fmt.Sprintf("<B>%s<B><BR><B>%s<END>", lobby.McsRegion, gcpLocationName[lobby.McsRegion])
case 15:
lobby.McsRegion = "europe-west3"
lobby.Comment = fmt.Sprintf("<B>%s<B><BR><B>%s<END>", lobby.McsRegion, gcpLocationName[lobby.McsRegion])
case 16:
lobby.McsRegion = "us-central1"
lobby.Comment = fmt.Sprintf("<B>%s<B><BR><B>%s<END>", lobby.McsRegion, gcpLocationName[lobby.McsRegion])
case 17:
lobby.McsRegion = "us-east1"
lobby.Comment = fmt.Sprintf("<B>%s<B><BR><B>%s<END>", lobby.McsRegion, gcpLocationName[lobby.McsRegion])
case 19:
lobby.Comment = "<B>ダメージレベル4<B><BR><B>DAMAGELEVEL4<END>"
lobby.Rule.DamageLevel = 3
Expand All @@ -98,6 +91,10 @@ func NewLobby(app *Lbs, platform uint8, lobbyID uint16) *LbsLobby {
}
}

if lobby.McsRegion != "" {
lobby.Comment = fmt.Sprintf("<B>%s<B><BR><B>%s<END>", lobby.McsRegion, gcpLocationName[lobby.McsRegion])
}

return lobby
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions gdxsv/lbs_mcsfunc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
}
Expand Down
61 changes: 36 additions & 25 deletions gdxsv/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
)

Expand All @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion gdxsv/shareddata.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit cbbb765

Please sign in to comment.