Skip to content

Commit

Permalink
MatchIDが実態stringのintだったので対応化
Browse files Browse the repository at this point in the history
  • Loading branch information
FlowingSPDG committed Jun 22, 2024
1 parent 4c81f83 commit 6283e25
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 94 deletions.
67 changes: 7 additions & 60 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,86 +67,33 @@ type EventHandler interface {

#### MatchLoader
[MatchLoader](https://github.com/FlowingSPDG/Got5/blob/75996d44058558ca7453af1c4b4f9e73115924d4/controller/got5.go#L54-L57) interface should handle ``get5_loadmatch_url`` request from game server.
You need to respond game server with JSON.
You need to respond JSON.
https://splewis.github.io/get5/latest/match_schema/
```go
// MatchLoader is for Read Operation(get5_loadmatch_url)
type MatchLoader interface {
// Auth Checker
CheckMatchAuth(ctx context.Context, mid string, auth string) error
CheckMatchAuth(ctx context.Context, mid int, auth string) error

// Load respond to get5_loadmatch_url
Load(ctx context.Context, mid string) (got5.G5Match, error)
Load(ctx context.Context, mid string) (got5.Match, error)
}
```

got5.G5Match is interface for generating get5 supported format JSON.
```go
// G5Match 別の構造体にG5Matchインターフェースを実装すれば型が違っても変換してGet5に渡してくれる
type G5Match interface {
ToG5Format() Match
}
```
```go
type Match struct {
MatchTitle string `json:"match_title"`
MatchID string `json:"matchid"`
ClinchSeries bool `json:"clinch_series"`
NumMaps int `json:"num_maps"`
PlayersPerTeam int `json:"players_per_team"`
CoachesPerTeam int `json:"coaches_per_team"`
CoachesMustReady bool `json:"coaches_must_ready"`
MinPlayersToReady int `json:"min_players_to_ready"`
MinSpectatorsToReady int `json:"min_spectators_to_ready"`
SkipVeto bool `json:"skip_veto"`
VetoFirst string `json:"veto_first"`
SideType string `json:"side_type"`
Spectators Spectators `json:"spectators"`
Maplist []string `json:"maplist"`
MapSides []string `json:"map_sides"`
Team1 Team `json:"team1"`
Team2 Team `json:"team2"`
Cvars map[string]string `json:"cvars"`
}
```

#### DemoUploader
[DemoUploader](https://github.com/FlowingSPDG/Got5/blob/75996d44058558ca7453af1c4b4f9e73115924d4/controller/got5.go#L59-L62) interface should handle demo upload from game server.
You may want to add auth middleware to prevend unauthorized demo uploads.
```go
// DemoUploader is for Demo Upload Operation(get5_dem_upload_url)
type DemoUploader interface {
CheckDemoAuth(ctx context.Context, mid string, filename string, mapNumber int, serverID string, auth string) error
Upload(ctx context.Context, mid string, filename string, r io.Reader) error // demoファイルの登録処理
CheckDemoAuth(ctx context.Context, mid int, filename string, mapNumber int, serverID string, auth string) error
Upload(ctx context.Context, mid int, filename string, r io.Reader) error // demoファイルの登録処理
}
```

## Authentication
There are some CVARs for authenticating Got5 and get5 gameserver.
- `get5_remote_log_url` - For specifying where to send Event Data.
- `get5_remote_log_header_key` - HTTP Header key for event request.
- `get5_remote_log_header_value` - HTTP header value for event request.
- `get5_demo_upload_url` - For specifying where to upload demo data.
- `get5_demo_upload_header_key` - HTTP Header key for demo upload.
- `get5_demo_upload_header_value` - HTTP Header value for demo upload.
- `get5_loadmatch_url "https://example.com/match_config.json" "Authorization" "Bearer <token>"` - For loading match info.
TODO...

## Examples
### logger
[logger](https://github.com/FlowingSPDG/Got5/tree/main/examples/discord) is most simple implemention for Got5 interfaces.
logger simply prints what happens.
No write operation, No Data store system.

### firebase
[firebase](https://github.com/FlowingSPDG/Got5/tree/main/examples/firebase) interfaces will read/write match/event informations.
You may need to enable firestore on your Google Cloud Platform project.

### Discord
[discord](https://github.com/FlowingSPDG/Got5/tree/main/examples/discord) is most complicated implemention of Got5 interfaces.
Discord struct implements all Got5 interfaces.
You can create match, store event datas and post what happens.

### Discord webhook
[discord_webhook](https://github.com/FlowingSPDG/Got5/tree/main/examples/discord_webhook) posts received get5 events.
This is fairly simple and nice example for learning your first Got5 based system.

TODO...
66 changes: 33 additions & 33 deletions models.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type OnLoadMatchConfigFailedPayload struct {
// OnSeriesInitPayload Fired when a series is started after loading a match config.
type OnSeriesInitPayload struct {
Event
MatchID int `json:"matchid"`
MatchID int `json:"matchid,string"`
NumMaps int `json:"num_maps"`
Team1 struct {
ID string `json:"id"`
Expand All @@ -50,7 +50,7 @@ type OnSeriesInitPayload struct {
// OnMapResultPayload Fired when the map ends.
type OnMapResultPayload struct {
Event
MatchID int `json:"matchid"`
MatchID int `json:"matchid,string"`
MapNumber int `json:"map_number"`
Team1 Get5StatsTeam `json:"team1"`
Team2 Get5StatsTeam `json:"team2"`
Expand Down Expand Up @@ -112,7 +112,7 @@ type Get5StatsPlayer struct {
// OnSeriesResultPayload Fired when a series is over. winner indicates team and side 0 if there was no winner in cases of a draw or if the series was forcefully canceled.
type OnSeriesResultPayload struct {
Event
MatchID int `json:"matchid"`
MatchID int `json:"matchid,string"`
Team1SeriesScore int `json:"team1_series_score"`
Team2SeriesScore int `json:"team2_series_score"`
Winner Winner `json:"winner"`
Expand All @@ -122,7 +122,7 @@ type OnSeriesResultPayload struct {
// OnSidePickedPayload Fired when a side is picked by a team.
type OnSidePickedPayload struct {
Event
MatchID int `json:"matchid"`
MatchID int `json:"matchid,string"`
Team string `json:"team"`
MapName string `json:"map_name"`
Side string `json:"side"`
Expand All @@ -132,7 +132,7 @@ type OnSidePickedPayload struct {
// OnMapPickedPayload Fired when a team picks a map.
type OnMapPickedPayload struct {
Event
MatchID int `json:"matchid"`
MatchID int `json:"matchid,string"`
Team string `json:"team"`
MapName string `json:"map_name"`
MapNumber int `json:"map_number"`
Expand All @@ -141,15 +141,15 @@ type OnMapPickedPayload struct {
// OnMapVetoedPayload Fired when a team vetos a map.
type OnMapVetoedPayload struct {
Event
MatchID int `json:"matchid"`
MatchID int `json:"matchid,string"`
Team string `json:"team"`
MapName string `json:"map_name"`
}

// OnBackupRestorePayload Fired when a round is restored from a backup. Note that the map and round numbers indicate the round being restored to, not the round the backup was requested during.
type OnBackupRestorePayload struct {
Event
MatchID int `json:"matchid"`
MatchID int `json:"matchid,string"`
MapNumber int `json:"map_number"`
RoundNumber int `json:"round_number"`
Filename string `json:"filename"`
Expand All @@ -158,15 +158,15 @@ type OnBackupRestorePayload struct {
// OnDemoFinishedPayload Fired when the GOTV recording has ended. This event does not fire if no demo was recorded.
type OnDemoFinishedPayload struct {
Event
MatchID int `json:"matchid"`
MatchID int `json:"matchid,string"`
MapNumber int `json:"map_number"`
Filename string `json:"filename"`
}

// OnDemoUploadEndedPayload Fired when the request to upload a demo ends, regardless if it succeeds or fails. If you upload demos, you should not shut down a server until this event has fired.
type OnDemoUploadEndedPayload struct {
Event
MatchID int `json:"matchid"`
MatchID int `json:"matchid,string"`
MapNumber int `json:"map_number"`
Filename string `json:"filename"`
Success bool `json:"success"`
Expand All @@ -177,7 +177,7 @@ type OnDemoUploadEndedPayload struct {
// OnMatchPausedPayload Fired when the match is paused.
type OnMatchPausedPayload struct {
Event
MatchID int `json:"matchid"`
MatchID int `json:"matchid,string"`
MapNumber int `json:"map_number"`
Team string `json:"team"`
PauseType string `json:"pause_type"`
Expand All @@ -186,15 +186,15 @@ type OnMatchPausedPayload struct {
// OnMatchUnpausedPayload Fired when the match is unpaused.
type OnMatchUnpausedPayload struct {
Event
MatchID int `json:"matchid"`
MatchID int `json:"matchid,string"`
MapNumber int `json:"map_number"`
Team string `json:"team"`
PauseType string `json:"pause_type"`
}

type OnPauseBeganPayload struct {
Event
MatchID int `json:"matchid"`
MatchID int `json:"matchid,string"`
MapNumber int `json:"map_number"`
Team string `json:"team"`
PauseType string `json:"pause_type"`
Expand All @@ -203,14 +203,14 @@ type OnPauseBeganPayload struct {
// OnKnifeRoundStartedPayload Fired when the knife round starts.
type OnKnifeRoundStartedPayload struct {
Event
MatchID int `json:"matchid"`
MatchID int `json:"matchid,string"`
MapNumber int `json:"map_number"`
}

// OnKnifeRoundWonPayload Fired when the knife round is over and the teams have elected to swap or stay. side represents the chosen side of the winning team, not the side that won the knife round.
type OnKnifeRoundWonPayload struct {
Event
MatchID int `json:"matchid"`
MatchID int `json:"matchid,string"`
MapNumber int `json:"map_number"`
Team string `json:"team"`
Side string `json:"side"`
Expand All @@ -220,7 +220,7 @@ type OnKnifeRoundWonPayload struct {
// OnTeamReadyStatusChangedPayload Fired when a team's ready status changes.
type OnTeamReadyStatusChangedPayload struct {
Event
MatchID int `json:"matchid"`
MatchID int `json:"matchid,string"`
Team *string `json:"team"` // nullable
Ready bool `json:"ready"`
GameState string `json:"game_state"`
Expand All @@ -229,22 +229,22 @@ type OnTeamReadyStatusChangedPayload struct {
// OnGoingLivePayload Fired when a map is going live.
type OnGoingLivePayload struct {
Event
MatchID int `json:"matchid"`
MatchID int `json:"matchid,string"`
MapNumber int `json:"map_number"`
}

// OnRoundStartPayload Fired when a round starts (when freezetime begins).
type OnRoundStartPayload struct {
Event
MatchID int `json:"matchid"`
MatchID int `json:"matchid,string"`
MapNumber int `json:"map_number"`
RoundNumber int `json:"round_number"`
}

// OnRoundEndPayload Fired when a round ends - when the result is in; not when the round stops. Game activity can occur after this.
type OnRoundEndPayload struct {
Event
MatchID int `json:"matchid"`
MatchID int `json:"matchid,string"`
MapNumber int `json:"map_number"`
RoundNumber int `json:"round_number"`
RoundTime int `json:"round_time"`
Expand All @@ -263,15 +263,15 @@ type Winner struct {
// OnRoundStatsUpdatedPayload Fired after the stats update on round end.
type OnRoundStatsUpdatedPayload struct {
Event
MatchID int `json:"matchid"`
MatchID int `json:"matchid,string"`
MapNumber int `json:"map_number"`
RoundNumber int `json:"round_number"`
}

// OnPlayerBecameMVPPayload Fired when a player is elected the MVP of the round.
type OnPlayerBecameMVPPayload struct {
Event
MatchID int `json:"matchid"`
MatchID int `json:"matchid,string"`
MapNumber int `json:"map_number"`
RoundNumber int `json:"round_number"`
Player Player `json:"player"`
Expand All @@ -290,7 +290,7 @@ type Player struct {
// OnGrenadeThrownPayload Fired whenever a grenade is thrown by a player. The weapon property reflects the grenade used.
type OnGrenadeThrownPayload struct {
Event
MatchID int `json:"matchid"`
MatchID int `json:"matchid,string"`
MapNumber int `json:"map_number"`
RoundNumber int `json:"round_number"`
RoundTime int `json:"round_time"`
Expand All @@ -307,7 +307,7 @@ type Weapon struct {
// OnPlayerDeathPayload Fired when a player dies.
type OnPlayerDeathPayload struct {
Event
MatchID int `json:"matchid"`
MatchID int `json:"matchid,string"`
MapNumber int `json:"map_number"`
RoundNumber int `json:"round_number"`
RoundTime int `json:"round_time"`
Expand Down Expand Up @@ -344,7 +344,7 @@ type Assist struct {
// OnHEGrenadeDetonatedPayload Fired when an HE grenade detonates. player describes who threw the HE and victims who were affected. weapon is always an HE grenade.
type OnHEGrenadeDetonatedPayload struct {
Event
MatchID int `json:"matchid"`
MatchID int `json:"matchid,string"`
MapNumber int `json:"map_number"`
RoundNumber int `json:"round_number"`
RoundTime int `json:"round_time"`
Expand All @@ -365,7 +365,7 @@ type Victim struct {
// OnMolotovDetonatedPayload Fired when a molotov grenade expires. player describes who threw the molotov and victims who were affected. weapon is always a molotov grenade. Note that round_time reflects the time at which the grenade detonated (started burning).
type OnMolotovDetonatedPayload struct {
Event
MatchID int `json:"matchid"`
MatchID int `json:"matchid,string"`
MapNumber int `json:"map_number"`
RoundNumber int `json:"round_number"`
RoundTime int `json:"round_time"`
Expand All @@ -379,7 +379,7 @@ type OnMolotovDetonatedPayload struct {
// OnFlashbangDetonatedPayload Fired when a flash bang grenade detonates. player describes who threw the flash bang and victims who were affected. weapon is always a flash bang grenade.
type OnFlashbangDetonatedPayload struct {
Event
MatchID int `json:"matchid"`
MatchID int `json:"matchid,string"`
MapNumber int `json:"map_number"`
RoundNumber int `json:"round_number"`
RoundTime int `json:"round_time"`
Expand All @@ -391,7 +391,7 @@ type OnFlashbangDetonatedPayload struct {
// OnSmokeGrenadeDetonatedPayload Fired when an smoke grenade expires. player describes who threw the grenade. weapon is always a smoke grenade.
type OnSmokeGrenadeDetonatedPayload struct {
Event
MatchID int `json:"matchid"`
MatchID int `json:"matchid,string"`
MapNumber int `json:"map_number"`
RoundNumber int `json:"round_number"`
RoundTime int `json:"round_time"`
Expand All @@ -403,7 +403,7 @@ type OnSmokeGrenadeDetonatedPayload struct {
// OnDecoyStartedPayload Fired when a decoy starts making noise. player describes who threw the grenade. weapon is always a decoy grenade.
type OnDecoyStartedPayload struct {
Event
MatchID int `json:"matchid"`
MatchID int `json:"matchid,string"`
MapNumber int `json:"map_number"`
RoundNumber int `json:"round_number"`
RoundTime int `json:"round_time"`
Expand All @@ -414,7 +414,7 @@ type OnDecoyStartedPayload struct {
// OnBombPlantedPayload Fired when the bomb is planted. player describes who planted the bomb.
type OnBombPlantedPayload struct {
Event
MatchID int `json:"matchid"`
MatchID int `json:"matchid,string"`
MapNumber int `json:"map_number"`
RoundNumber int `json:"round_number"`
RoundTime int `json:"round_time"`
Expand All @@ -425,7 +425,7 @@ type OnBombPlantedPayload struct {
// OnBombDefusedPayload Fired when the bomb is defused. player describes who defused the bomb.
type OnBombDefusedPayload struct {
Event
MatchID int `json:"matchid"`
MatchID int `json:"matchid,string"`
MapNumber int `json:"map_number"`
RoundNumber int `json:"round_number"`
RoundTime int `json:"round_time"`
Expand All @@ -437,7 +437,7 @@ type OnBombDefusedPayload struct {
// OnBombExplodedPayload Fired when the bomb explodes.
type OnBombExplodedPayload struct {
Event
MatchID int `json:"matchid"`
MatchID int `json:"matchid,string"`
MapNumber int `json:"map_number"`
RoundNumber int `json:"round_number"`
RoundTime int `json:"round_time"`
Expand All @@ -447,22 +447,22 @@ type OnBombExplodedPayload struct {
// OnPlayerConnectedPayload Fired when a player connects to the server.
type OnPlayerConnectedPayload struct {
Event
MatchID int `json:"matchid"`
MatchID int `json:"matchid,string"`
Player Player `json:"player"`
IPAddress string `json:"ip_address"`
}

// OnPlayerDisconnectedPayload Fired when a player disconnects from the server.
type OnPlayerDisconnectedPayload struct {
Event
MatchID int `json:"matchid"`
MatchID int `json:"matchid,string"`
Player Player `json:"player"`
}

// OnPlayerSayPayload Fired when a player types in chat.
type OnPlayerSayPayload struct {
Event
MatchID int `json:"matchid"`
MatchID int `json:"matchid,string"`
MapNumber int `json:"map_number"`
RoundNumber int `json:"round_number"`
RoundTime int `json:"round_time"`
Expand Down
2 changes: 1 addition & 1 deletion route/gin/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func OnEventHandler(ctrl got5.EventHandler) func(c *gin.Context) {
}
ev, ok := (p["event"]).(string)
if !ok {
c.AbortWithError(http.StatusBadRequest, xerrors.New("Invalid JSON")) // TODO: Wrap error code
c.AbortWithError(http.StatusBadRequest, xerrors.New("Invalid JSON(event name)")) // TODO: Wrap error code
return
}
switch ev {
Expand Down

0 comments on commit 6283e25

Please sign in to comment.