Skip to content

Commit

Permalink
Update ID generics
Browse files Browse the repository at this point in the history
  • Loading branch information
FlowingSPDG committed Jun 21, 2024
1 parent fd3976c commit 5296300
Show file tree
Hide file tree
Showing 8 changed files with 249 additions and 351 deletions.
82 changes: 41 additions & 41 deletions controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,62 +6,62 @@ import (
)

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

// EventHandler EventHandler interface handles read operation by get5 events
type EventHandler[TMatchID MatchID] interface {
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[TMatchID]) error
HandleOnMapResult(ctx context.Context, p OnMapResultPayload[TMatchID]) error
HandleOnSeriesResult(ctx context.Context, p OnSeriesResultPayload[TMatchID]) error
HandleOnSidePicked(ctx context.Context, p OnSidePickedPayload[TMatchID]) error
HandleOnMapPicked(ctx context.Context, p OnMapPickedPayload[TMatchID]) error
HandleOnMapVetoed(ctx context.Context, p OnMapVetoedPayload[TMatchID]) error
HandleOnBackupRestore(ctx context.Context, p OnBackupRestorePayload[TMatchID]) error
HandleOnDemoFinished(ctx context.Context, p OnDemoFinishedPayload[TMatchID]) error
HandleOnDemoUploadEnded(ctx context.Context, p OnDemoUploadEndedPayload[TMatchID]) error
HandleOnMatchPaused(ctx context.Context, p OnMatchPausedPayload[TMatchID]) error
HandleOnMatchUnpaused(ctx context.Context, p OnMatchUnpausedPayload[TMatchID]) error
HandleOnPauseBegan(ctx context.Context, p OnPauseBeganPayload[TMatchID]) error
HandleOnKnifeRoundStarted(ctx context.Context, p OnKnifeRoundStartedPayload[TMatchID]) error
HandleOnKnifeRoundWon(ctx context.Context, p OnKnifeRoundWonPayload[TMatchID]) error
HandleOnTeamReadyStatusChanged(ctx context.Context, p OnTeamReadyStatusChangedPayload[TMatchID]) error
HandleOnGoingLive(ctx context.Context, p OnGoingLivePayload[TMatchID]) error
HandleOnRoundStart(ctx context.Context, p OnRoundStartPayload[TMatchID]) error
HandleOnRoundEnd(ctx context.Context, p OnRoundEndPayload[TMatchID]) error
HandleOnRoundStatsUpdated(ctx context.Context, p OnRoundStatsUpdatedPayload[TMatchID]) error
HandleOnPlayerBecameMVP(ctx context.Context, p OnPlayerBecameMVPPayload[TMatchID]) error
HandleOnGrenadeThrown(ctx context.Context, p OnGrenadeThrownPayload[TMatchID]) error
HandleOnPlayerDeath(ctx context.Context, p OnPlayerDeathPayload[TMatchID]) error
HandleOnHEGrenadeDetonated(ctx context.Context, p OnHEGrenadeDetonatedPayload[TMatchID]) error
HandleOnMolotovDetonated(ctx context.Context, p OnMolotovDetonatedPayload[TMatchID]) error
HandleOnFlashbangDetonated(ctx context.Context, p OnFlashbangDetonatedPayload[TMatchID]) error
HandleOnSmokeGrenadeDetonated(ctx context.Context, p OnSmokeGrenadeDetonatedPayload[TMatchID]) error
HandleOnDecoyStarted(ctx context.Context, p OnDecoyStartedPayload[TMatchID]) error
HandleOnBombPlanted(ctx context.Context, p OnBombPlantedPayload[TMatchID]) error
HandleOnBombDefused(ctx context.Context, p OnBombDefusedPayload[TMatchID]) error
HandleOnBombExploded(ctx context.Context, p OnBombExplodedPayload[TMatchID]) error
HandleOnPlayerConnected(ctx context.Context, p OnPlayerConnectedPayload[TMatchID]) error
HandleOnPlayerDisconnected(ctx context.Context, p OnPlayerDisconnectedPayload[TMatchID]) error
HandleOnPlayerSay(ctx context.Context, p OnPlayerSayPayload[TMatchID]) 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[TMatchID MatchID] interface {
type MatchLoader interface {
// Load respond to get5_loadmatch_url
Load(ctx context.Context, mid TMatchID) (G5Match[TMatchID], error)
Load(ctx context.Context, mid int) (*Match, error)
}

// DemoUploader is for Demo Upload Operation(get5_dem_upload_url)
type DemoUploader[TMatchID MatchID] interface {
Upload(ctx context.Context, mid TMatchID, filename string, r io.Reader) error // demoファイルの登録処理
type DemoUploader interface {
Upload(ctx context.Context, mid int, filename string, r io.Reader) error // demoファイルの登録処理
}
24 changes: 5 additions & 19 deletions match.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,8 @@ package got5
// MatchZy: https://shobhit-pathak.github.io/MatchZy/match_setup/#example
// MatchZy(source): https://github.com/shobhit-pathak/MatchZy/blob/ae597e50756f8ed8380e4cbacec4a4c1eb9013da/MatchManagement.cs#L254

// MatchID currently int only
type MatchID interface {
int
}

type Match[TmatchID MatchID] struct {
MatchID TmatchID `json:"matchid,omitempty"` // originally string in get5 but MatchZy uses int
type Match struct {
MatchID int `json:"matchid,omitempty"` // originally string in get5 but MatchZy uses int
ClinchSeries bool `json:"clinch_series,omitempty"`
NumMaps int `json:"num_maps,omitempty"`
Wingman bool `json:"wingman,omitempty"`
Expand All @@ -27,13 +22,9 @@ type Match[TmatchID MatchID] struct {
Cvars map[string]string `json:"cvars,omitempty"`
}

func (m Match[TMatchID]) ToG5Format() Match[TMatchID] {
return m
}

func GetDefaultMatchBO1[TMatchID MatchID]() Match[TMatchID] {
return Match[TMatchID]{
MatchID: *new(TMatchID),
func GetDefaultMatchBO1() Match {
return Match{
MatchID: 0,
ClinchSeries: true,
NumMaps: 1,
PlayersPerTeam: 5,
Expand Down Expand Up @@ -65,8 +56,3 @@ type Team struct {
Players map[string]string `json:"players,omitempty"`
Name string `json:"name,omitempty"`
}

// G5Match 別の構造体にG5Matchインターフェースを実装すれば型が違っても変換してGet5に渡してくれる
type G5Match[TMatchID MatchID] interface {
ToG5Format() Match[TMatchID]
}
Loading

0 comments on commit 5296300

Please sign in to comment.