From 604fdfb03c1486f40eb1245b2b567e032dc33db0 Mon Sep 17 00:00:00 2001 From: deflinhec Date: Sun, 29 Jan 2023 16:58:04 +0100 Subject: [PATCH] nakama console send match signal --- console/console.proto | 18 ++++++++++++++++++ console/ui/src/app/console.service.ts | 14 ++++++++++++++ .../ui/src/app/matches/matches.component.html | 13 +++++++++++++ .../ui/src/app/matches/matches.component.ts | 16 ++++++++++++++++ server/console_match.go | 8 ++++++++ 5 files changed, 69 insertions(+) diff --git a/console/console.proto b/console/console.proto index 078e589ef..b92bca542 100644 --- a/console/console.proto +++ b/console/console.proto @@ -256,6 +256,11 @@ service Console { option (google.api.http).get = "/v2/console/match/{id}/state"; } + // Send signal to specific match id + rpc SendMatchSignal (MatchSignalRequest) returns (MatchSignalResponse) { + option (google.api.http).post = "/v2/console/match/{id}/signal/{signal}"; + } + // Get runtime info rpc GetRuntime (google.protobuf.Empty) returns (RuntimeInfo) { option (google.api.http).get = "/v2/console/runtime"; @@ -823,6 +828,19 @@ message MatchStateRequest { string id = 1; } +// Perform match signal +message MatchSignalRequest { + // Match ID + string id = 1; + // Signal + string signal = 2; +} + +message MatchSignalResponse { + // Match Signal Result + string result = 1; +} + message DeleteChannelMessagesResponse { // Total number of messages deleted. int64 total = 1; diff --git a/console/ui/src/app/console.service.ts b/console/ui/src/app/console.service.ts index b008bc496..e26d801e5 100644 --- a/console/ui/src/app/console.service.ts +++ b/console/ui/src/app/console.service.ts @@ -225,6 +225,11 @@ export interface MatchListMatch { node?:string } +export interface MatchSignalResponse { + // Match Signal Result + result?:string +} + export interface MatchState { // Presence list. presences?:Array @@ -1269,6 +1274,15 @@ export class ConsoleService { return this.httpClient.get(this.config.host + urlPath, { params: params, headers: this.getTokenAuthHeaders(auth_token) }) } + /** Send signal to specific match id */ + sendMatchSignal(auth_token: string, id: string, signal: string): Observable { + id = encodeURIComponent(String(id)) + signal = encodeURIComponent(String(signal)) + const urlPath = `/v2/console/match/${id}/signal/${signal}`; + let params = new HttpParams(); + return this.httpClient.post(this.config.host + urlPath, { params: params, headers: this.getTokenAuthHeaders(auth_token) }) + } + /** Get current state of a running match */ getMatchState(auth_token: string, id: string): Observable { id = encodeURIComponent(String(id)) diff --git a/console/ui/src/app/matches/matches.component.html b/console/ui/src/app/matches/matches.component.html index e0632263d..96046365e 100644 --- a/console/ui/src/app/matches/matches.component.html +++ b/console/ui/src/app/matches/matches.component.html @@ -98,6 +98,19 @@
An error occurred: {{error}}
Match Label
{{m.api_match.label}}
+ + Match Signal +
+
+ + +
+
+
{{matchSignalResult[i]}}
+ + +
{{matchSignalError[i]}}
+
diff --git a/console/ui/src/app/matches/matches.component.ts b/console/ui/src/app/matches/matches.component.ts index 735b464d7..6f2013213 100644 --- a/console/ui/src/app/matches/matches.component.ts +++ b/console/ui/src/app/matches/matches.component.ts @@ -34,7 +34,10 @@ export class MatchesComponent implements OnInit { public matches: Array = []; public matchStates: Array = []; public matchStatesOpen: Array = []; + public matchSignalResult: Array = []; + public matchSignalError: Array = []; public updated = false; + public signalForm: FormGroup; public searchForm1: FormGroup; public searchForm2: FormGroup; public searchForm3: FormGroup; //Authoritative @@ -50,6 +53,9 @@ export class MatchesComponent implements OnInit { private readonly formBuilder: FormBuilder, private readonly consoleService: ConsoleService, ) { + this.signalForm = this.formBuilder.group({ + signal: '', result: '', + }) this.searchForm1 = this.formBuilder.group({ match_id: '', }); @@ -185,6 +191,16 @@ export class MatchesComponent implements OnInit { }); } + sendMatchSignal(i: number, match: MatchListMatch, signal: string) : void { + this.consoleService.sendMatchSignal('', match.api_match.match_id, signal).subscribe(d => { + this.matchSignalResult[i] = d.result; + this.matchSignalError[i] = null; + }, err => { + this.matchSignalResult[i] = null; + this.matchSignalError[i] = err; + }); + } + getMatchPresencesString(ps: Array): string { return JSON.stringify(ps); } diff --git a/server/console_match.go b/server/console_match.go index 4b320cb84..6bb8ed5bf 100644 --- a/server/console_match.go +++ b/server/console_match.go @@ -122,3 +122,11 @@ func (s *ConsoleServer) GetMatchState(ctx context.Context, in *console.MatchStat return &console.MatchState{Presences: presences, Tick: tick, State: state}, nil } + +func (s *ConsoleServer) SendMatchSignal(ctx context.Context, in *console.MatchSignalRequest) (*console.MatchSignalResponse, error) { + result, err := s.matchRegistry.Signal(ctx, in.Id, in.Signal) + if err != nil { + return nil, status.Error(codes.Aborted, err.Error()) + } + return &console.MatchSignalResponse{Result: result}, nil +}