@@ -2,73 +2,22 @@ package creategamehandler
22
33import (
44 "context"
5- "fmt"
6- "strconv"
7- "time"
5+ "errors"
86
97 "connectrpc.com/connect"
10- "github.com/makasim/flowstate"
11- "github.com/makasim/gogame/internal/api/convertor"
12- "github.com/makasim/gogame/internal/staleflow"
138 v1 "github.com/makasim/gogame/protogen/gogame/v1"
149)
1510
11+ // deprecated
1612type Handler struct {
17- e flowstate.Engine
1813}
1914
20- func New (e flowstate.Engine ) * Handler {
21- return & Handler {
22- e : e ,
23- }
15+ // deprecated
16+ func New () * Handler {
17+ return & Handler {}
2418}
2519
20+ // deprecated
2621func (h * Handler ) CreateGame (_ context.Context , req * connect.Request [v1.CreateGameRequest ]) (* connect.Response [v1.CreateGameResponse ], error ) {
27- if req .Msg .Name == `` {
28- return nil , connect .NewError (connect .CodeInvalidArgument , fmt .Errorf ("game name is required" ))
29- }
30- if req .Msg .Player1 != nil && req .Msg .Player1 .Name == `` {
31- return nil , connect .NewError (connect .CodeInvalidArgument , fmt .Errorf ("player1 name is required" ))
32- }
33-
34- g := & v1.Game {
35- Id : strconv .FormatInt (time .Now ().UnixNano (), 10 ),
36- Name : req .Msg .Name ,
37- Player1 : req .Msg .Player1 ,
38- State : v1 .State_STATE_CREATED ,
39- MoveDurationSec : req .Msg .MoveDurationSec ,
40- }
41- if g .MoveDurationSec == 0 {
42- g .MoveDurationSec = 60
43- }
44-
45- d := & flowstate.Data {}
46- if err := convertor .GameToData (g , d ); err != nil {
47- return nil , connect .NewError (connect .CodeInternal , err )
48- }
49-
50- stateCtx := & flowstate.StateCtx {
51- Current : flowstate.State {
52- ID : flowstate .StateID (g .Id ),
53- Labels : map [string ]string {
54- `game` : `true` ,
55- `game.id` : g .Id ,
56- `game.state` : `created` ,
57- },
58- },
59- }
60-
61- if err := h .e .Do (flowstate .Commit (
62- flowstate .AttachData (stateCtx , d , `game` ),
63- flowstate .Park (stateCtx ),
64- flowstate .Delay (stateCtx , staleflow .ID , time .Minute ),
65- )); err != nil {
66- return nil , connect .NewError (connect .CodeInternal , err )
67- }
68-
69- g .Rev = int32 (stateCtx .Current .Rev )
70-
71- return connect .NewResponse (& v1.CreateGameResponse {
72- Game : g ,
73- }), nil
22+ return nil , connect .NewError (connect .CodeUnimplemented , errors .New ("gogame.v1.GameService.CreateGame is not implemented" ))
7423}
0 commit comments