Skip to content

Commit

Permalink
価値が低いexampleの削除、ディレクトリ変更
Browse files Browse the repository at this point in the history
  • Loading branch information
Shugo Kawamura committed Aug 12, 2023
1 parent be9dcc0 commit 47e4636
Show file tree
Hide file tree
Showing 49 changed files with 796 additions and 2,286 deletions.
80 changes: 40 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Shugo Kawamura - 河村 柊吾
controller does not have database interface, so you may implement database system by yourself.

#### EventHandler
[EventHandler](https://github.com/FlowingSPDG/Got5/blob/75996d44058558ca7453af1c4b4f9e73115924d4/controller/controller.go#L10-L52) interface should handle event coming from get5 [Events & Forwards](https://splewis.github.io/get5/latest/events_and_forwards/) (get5_remote_log_url).
[EventHandler](https://github.com/FlowingSPDG/Got5/blob/75996d44058558ca7453af1c4b4f9e73115924d4/controller/got5.go#L10-L52) interface should handle event coming from get5 [Events & Forwards](https://splewis.github.io/get5/latest/events_and_forwards/) (get5_remote_log_url).
e.g. You can post Discord message, or save stats to your database.
```go
// EventHandler EventHandler interface handles read operation by get5 events
Expand All @@ -27,46 +27,46 @@ type EventHandler interface {
CheckEventAuth(ctx context.Context, mid string, reqAuth string) error

// GET5 Events
HandleOnGameStateChanged(ctx context.Context, p models.OnGameStateChangedPayload) error
HandleOnPreLoadMatchConfig(ctx context.Context, p models.OnPreLoadMatchConfigPayload) error
HandleOnLoadMatchConfigFailed(ctx context.Context, p models.OnLoadMatchConfigFailedPayload) error
HandleOnSeriesInit(ctx context.Context, p models.OnSeriesInitPayload) error
HandleOnMapResult(ctx context.Context, p models.OnMapResultPayload) error
HandleOnSeriesResult(ctx context.Context, p models.OnSeriesResultPayload) error
HandleOnSidePicked(ctx context.Context, p models.OnSidePickedPayload) error
HandleOnMapPicked(ctx context.Context, p models.OnMapPickedPayload) error
HandleOnMapVetoed(ctx context.Context, p models.OnMapVetoedPayload) error
HandleOnBackupRestore(ctx context.Context, p models.OnBackupRestorePayload) error
HandleOnDemoFinished(ctx context.Context, p models.OnDemoFinishedPayload) error
HandleOnDemoUploadEnded(ctx context.Context, p models.OnDemoUploadEndedPayload) error
HandleOnMatchPaused(ctx context.Context, p models.OnMatchPausedPayload) error
HandleOnMatchUnpaused(ctx context.Context, p models.OnMatchUnpausedPayload) error
HandleOnKnifeRoundStarted(ctx context.Context, p models.OnKnifeRoundStartedPayload) error
HandleOnKnifeRoundWon(ctx context.Context, p models.OnKnifeRoundWonPayload) error
HandleOnTeamReadyStatusChanged(ctx context.Context, p models.OnTeamReadyStatusChangedPayload) error
HandleOnGoingLive(ctx context.Context, p models.OnGoingLivePayload) error
HandleOnRoundStart(ctx context.Context, p models.OnRoundStartPayload) error
HandleOnRoundEnd(ctx context.Context, p models.OnRoundEndPayload) error
HandleOnRoundStatsUpdated(ctx context.Context, p models.OnRoundStatsUpdatedPayload) error
HandleOnPlayerBecameMVP(ctx context.Context, p models.OnPlayerBecameMVPPayload) error
HandleOnGrenadeThrown(ctx context.Context, p models.OnGrenadeThrownPayload) error
HandleOnPlayerDeath(ctx context.Context, p models.OnPlayerDeathPayload) error
HandleOnHEGrenadeDetonated(ctx context.Context, p models.OnHEGrenadeDetonatedPayload) error
HandleOnMolotovDetonated(ctx context.Context, p models.OnMolotovDetonatedPayload) error
HandleOnFlashbangDetonated(ctx context.Context, p models.OnFlashbangDetonatedPayload) error
HandleOnSmokeGrenadeDetonated(ctx context.Context, p models.OnSmokeGrenadeDetonatedPayload) error
HandleOnDecoyStarted(ctx context.Context, p models.OnDecoyStartedPayload) error
HandleOnBombPlanted(ctx context.Context, p models.OnBombPlantedPayload) error
HandleOnBombDefused(ctx context.Context, p models.OnBombDefusedPayload) error
HandleOnBombExploded(ctx context.Context, p models.OnBombExplodedPayload) error
HandleOnPlayerConnected(ctx context.Context, p models.OnPlayerConnectedPayload) error
HandleOnPlayerDisconnected(ctx context.Context, p models.OnPlayerDisconnectedPayload) error
HandleOnPlayerSay(ctx context.Context, p models.OnPlayerSayPayload) error
HandleOnGameStateChanged(ctx context.Context, p got5.OnGameStateChangedPayload) error
HandleOnPreLoadMatchConfig(ctx context.Context, p got5.OnPreLoadMatchConfigPayload) error
HandleOnLoadMatchConfigFailed(ctx context.Context, p got5.OnLoadMatchConfigFailedPayload) error
HandleOnSeriesInit(ctx context.Context, p got5.OnSeriesInitPayload) error
HandleOnMapResult(ctx context.Context, p got5.OnMapResultPayload) error
HandleOnSeriesResult(ctx context.Context, p got5.OnSeriesResultPayload) error
HandleOnSidePicked(ctx context.Context, p got5.OnSidePickedPayload) error
HandleOnMapPicked(ctx context.Context, p got5.OnMapPickedPayload) error
HandleOnMapVetoed(ctx context.Context, p got5.OnMapVetoedPayload) error
HandleOnBackupRestore(ctx context.Context, p got5.OnBackupRestorePayload) error
HandleOnDemoFinished(ctx context.Context, p got5.OnDemoFinishedPayload) error
HandleOnDemoUploadEnded(ctx context.Context, p got5.OnDemoUploadEndedPayload) error
HandleOnMatchPaused(ctx context.Context, p got5.OnMatchPausedPayload) error
HandleOnMatchUnpaused(ctx context.Context, p got5.OnMatchUnpausedPayload) error
HandleOnKnifeRoundStarted(ctx context.Context, p got5.OnKnifeRoundStartedPayload) error
HandleOnKnifeRoundWon(ctx context.Context, p got5.OnKnifeRoundWonPayload) error
HandleOnTeamReadyStatusChanged(ctx context.Context, p got5.OnTeamReadyStatusChangedPayload) error
HandleOnGoingLive(ctx context.Context, p got5.OnGoingLivePayload) error
HandleOnRoundStart(ctx context.Context, p got5.OnRoundStartPayload) error
HandleOnRoundEnd(ctx context.Context, p got5.OnRoundEndPayload) error
HandleOnRoundStatsUpdated(ctx context.Context, p got5.OnRoundStatsUpdatedPayload) error
HandleOnPlayerBecameMVP(ctx context.Context, p got5.OnPlayerBecameMVPPayload) error
HandleOnGrenadeThrown(ctx context.Context, p got5.OnGrenadeThrownPayload) error
HandleOnPlayerDeath(ctx context.Context, p got5.OnPlayerDeathPayload) error
HandleOnHEGrenadeDetonated(ctx context.Context, p got5.OnHEGrenadeDetonatedPayload) error
HandleOnMolotovDetonated(ctx context.Context, p got5.OnMolotovDetonatedPayload) error
HandleOnFlashbangDetonated(ctx context.Context, p got5.OnFlashbangDetonatedPayload) error
HandleOnSmokeGrenadeDetonated(ctx context.Context, p got5.OnSmokeGrenadeDetonatedPayload) error
HandleOnDecoyStarted(ctx context.Context, p got5.OnDecoyStartedPayload) error
HandleOnBombPlanted(ctx context.Context, p got5.OnBombPlantedPayload) error
HandleOnBombDefused(ctx context.Context, p got5.OnBombDefusedPayload) error
HandleOnBombExploded(ctx context.Context, p got5.OnBombExplodedPayload) error
HandleOnPlayerConnected(ctx context.Context, p got5.OnPlayerConnectedPayload) error
HandleOnPlayerDisconnected(ctx context.Context, p got5.OnPlayerDisconnectedPayload) error
HandleOnPlayerSay(ctx context.Context, p got5.OnPlayerSayPayload) error
}
```

#### MatchLoader
[MatchLoader](https://github.com/FlowingSPDG/Got5/blob/75996d44058558ca7453af1c4b4f9e73115924d4/controller/controller.go#L54-L57) interface should handle ``get5_loadmatch_url`` request from game server.
[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.
https://splewis.github.io/get5/latest/match_schema/
```go
Expand All @@ -76,11 +76,11 @@ type MatchLoader interface {
CheckMatchAuth(ctx context.Context, mid string, auth string) error

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

models.G5Match is interface for generating get5 supported format JSON.
got5.G5Match is interface for generating get5 supported format JSON.
```go
// G5Match 別の構造体にG5Matchインターフェースを実装すれば型が違っても変換してGet5に渡してくれる
type G5Match interface {
Expand Down Expand Up @@ -111,7 +111,7 @@ type Match struct {
```

#### DemoUploader
[DemoUploader](https://github.com/FlowingSPDG/Got5/blob/75996d44058558ca7453af1c4b4f9e73115924d4/controller/controller.go#L59-L62) interface should handle demo upload from game server.
[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)
Expand Down
67 changes: 67 additions & 0 deletions controller.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package got5

import (
"context"
"io"
)

// Auth Auth interface handles auth
type Auth interface {
EventAuth(ctx context.Context, serverID string, auth string) error
MatchAuth(ctx context.Context, mid string, auth string) error
CheckDemoAuth(ctx context.Context, mid string, filename string, mapNumber int, serverID string, auth string) error
}

// EventHandler EventHandler interface handles read operation by get5 events
type EventHandler interface {
Close() error

// GET5 Events
HandleOnGameStateChanged(ctx context.Context, p OnGameStateChangedPayload) error
HandleOnPreLoadMatchConfig(ctx context.Context, p OnPreLoadMatchConfigPayload) error
HandleOnLoadMatchConfigFailed(ctx context.Context, p OnLoadMatchConfigFailedPayload) error
HandleOnSeriesInit(ctx context.Context, p OnSeriesInitPayload) error
HandleOnMapResult(ctx context.Context, p OnMapResultPayload) error
HandleOnSeriesResult(ctx context.Context, p OnSeriesResultPayload) error
HandleOnSidePicked(ctx context.Context, p OnSidePickedPayload) error
HandleOnMapPicked(ctx context.Context, p OnMapPickedPayload) error
HandleOnMapVetoed(ctx context.Context, p OnMapVetoedPayload) error
HandleOnBackupRestore(ctx context.Context, p OnBackupRestorePayload) error
HandleOnDemoFinished(ctx context.Context, p OnDemoFinishedPayload) error
HandleOnDemoUploadEnded(ctx context.Context, p OnDemoUploadEndedPayload) error
HandleOnMatchPaused(ctx context.Context, p OnMatchPausedPayload) error
HandleOnMatchUnpaused(ctx context.Context, p OnMatchUnpausedPayload) error
HandleOnPauseBegan(ctx context.Context, p OnPauseBeganPayload) error
HandleOnKnifeRoundStarted(ctx context.Context, p OnKnifeRoundStartedPayload) error
HandleOnKnifeRoundWon(ctx context.Context, p OnKnifeRoundWonPayload) error
HandleOnTeamReadyStatusChanged(ctx context.Context, p OnTeamReadyStatusChangedPayload) error
HandleOnGoingLive(ctx context.Context, p OnGoingLivePayload) error
HandleOnRoundStart(ctx context.Context, p OnRoundStartPayload) error
HandleOnRoundEnd(ctx context.Context, p OnRoundEndPayload) error
HandleOnRoundStatsUpdated(ctx context.Context, p OnRoundStatsUpdatedPayload) error
HandleOnPlayerBecameMVP(ctx context.Context, p OnPlayerBecameMVPPayload) error
HandleOnGrenadeThrown(ctx context.Context, p OnGrenadeThrownPayload) error
HandleOnPlayerDeath(ctx context.Context, p OnPlayerDeathPayload) error
HandleOnHEGrenadeDetonated(ctx context.Context, p OnHEGrenadeDetonatedPayload) error
HandleOnMolotovDetonated(ctx context.Context, p OnMolotovDetonatedPayload) error
HandleOnFlashbangDetonated(ctx context.Context, p OnFlashbangDetonatedPayload) error
HandleOnSmokeGrenadeDetonated(ctx context.Context, p OnSmokeGrenadeDetonatedPayload) error
HandleOnDecoyStarted(ctx context.Context, p OnDecoyStartedPayload) error
HandleOnBombPlanted(ctx context.Context, p OnBombPlantedPayload) error
HandleOnBombDefused(ctx context.Context, p OnBombDefusedPayload) error
HandleOnBombExploded(ctx context.Context, p OnBombExplodedPayload) error
HandleOnPlayerConnected(ctx context.Context, p OnPlayerConnectedPayload) error
HandleOnPlayerDisconnected(ctx context.Context, p OnPlayerDisconnectedPayload) error
HandleOnPlayerSay(ctx context.Context, p OnPlayerSayPayload) error
}

// MatchLoader is for Read Operation(get5_loadmatch_url)
type MatchLoader interface {
// Load respond to get5_loadmatch_url
Load(ctx context.Context, mid string) (G5Match, error)
}

// DemoUploader is for Demo Upload Operation(get5_dem_upload_url)
type DemoUploader interface {
Upload(ctx context.Context, mid string, filename string, r io.Reader) error // demoファイルの登録処理
}
69 changes: 0 additions & 69 deletions controller/controller.go

This file was deleted.

8 changes: 4 additions & 4 deletions examples/discord/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
"context"
"fmt"

"github.com/FlowingSPDG/Got5/controller"
got5 "github.com/FlowingSPDG/Got5"
)

var _ controller.Auth = (*Discord)(nil)
var _ got5.Auth = (*Discord)(nil)

// EventAuth
func (d *Discord) EventAuth(ctx context.Context, mid string, auth string) error {
Expand All @@ -18,7 +18,7 @@ func (d *Discord) EventAuth(ctx context.Context, mid string, auth string) error
return fmt.Errorf("Password mismatch")
}

// CheckDemoAuth implements controller.JWTAuth
// CheckDemoAuth implements got5.JWTAuth
func (d *Discord) CheckDemoAuth(ctx context.Context, mid string, filename string, mapNumber int, serverID string, auth string) error {
// Lets say simple password...
if auth == d.setting.password {
Expand All @@ -27,7 +27,7 @@ func (d *Discord) CheckDemoAuth(ctx context.Context, mid string, filename string
return fmt.Errorf("Password mismatch")
}

// MatchAuth implements controller.JWTAuth
// MatchAuth implements got5.JWTAuth
func (d *Discord) MatchAuth(ctx context.Context, mid string, auth string) error {
// Lets say simple password...
if auth == d.setting.password {
Expand Down
2 changes: 1 addition & 1 deletion examples/discord/demo.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"io"
)

// Upload implements controller.DemoUploader
// Upload implements got5.DemoUploader
func (d *Discord) Upload(ctx context.Context, mid string, filename string, r io.Reader) error {
io.Copy(io.Discard, r)
return nil
Expand Down
21 changes: 10 additions & 11 deletions examples/discord/discord.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ import (

"github.com/bwmarrin/discordgo"

"github.com/FlowingSPDG/Got5/controller"
"github.com/FlowingSPDG/Got5/models"
got5 "github.com/FlowingSPDG/Got5"
)

var _ controller.EventHandler = (*Discord)(nil)
var _ controller.MatchLoader = (*Discord)(nil)
var _ controller.DemoUploader = (*Discord)(nil)
var _ got5.EventHandler = (*Discord)(nil)
var _ got5.MatchLoader = (*Discord)(nil)
var _ got5.DemoUploader = (*Discord)(nil)

// ControllerSetting Settings
type ControllerSetting struct {
Expand All @@ -33,16 +32,16 @@ type Discord struct {
matches map[string]struct {
interaction *discordgo.Interaction // Interaction
member *discordgo.Member // マッチ作成を実行したユーザー
match models.Match // GET5自体のマッチ情報
match got5.Match // GET5自体のマッチ情報
} // GET5のマッチID(=interactionID))に対応したマッチ情報
}

// Hostname implements controller.EventHandler
// Hostname implements got5.EventHandler
func (d *Discord) Hostname() string {
return d.setting.Hostname
}

// Close implements controller.EventHandler
// Close implements got5.EventHandler
func (d *Discord) Close() error {
return d.s.Close()
}
Expand Down Expand Up @@ -93,7 +92,7 @@ func NewDiscord(ctx context.Context, token string, setting ControllerSetting) (*
matches: make(map[string]struct {
interaction *discordgo.Interaction
member *discordgo.Member
match models.Match
match got5.Match
}),
}

Expand Down Expand Up @@ -255,15 +254,15 @@ func NewDiscord(ctx context.Context, token string, setting ControllerSetting) (*
if strings.HasPrefix(data.CustomID, "get5_create_") {
// m.User, m.Message など、nilになる値があるので注意
mf := getCreateMatchModalFormBySubmitted(data)
match := models.GetDefaultMatchBO1()
match := got5.GetDefaultMatchBO1()
match.MatchTitle = fmt.Sprintf("%s : Created by %s", mf.MatchTitle, m.Member.Nick)
match.MatchID = m.Interaction.ID
match.Team1.Name = mf.Team1Name
c.mu.Lock()
c.matches[m.Interaction.ID] = struct {
interaction *discordgo.Interaction
member *discordgo.Member
match models.Match
match got5.Match
}{
interaction: m.Interaction,
member: m.Member,
Expand Down
Loading

0 comments on commit 47e4636

Please sign in to comment.