Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ spec:
spec:
containers:
- name: flowstatesrv
image: docker.io/makasim/flowstate:e662c53f
image: docker.io/makasim/flowstate:372320ea
ports:
- containerPort: 9282
env:
Expand Down
15 changes: 8 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,20 @@ go 1.24.0
toolchain go1.24.3

require (
connectrpc.com/connect v1.18.1
github.com/makasim/flowstate v0.0.0-20250726121746-e662c53f5288
connectrpc.com/connect v1.19.0
github.com/VictoriaMetrics/easyproto v0.1.4
github.com/makasim/flowstate v0.0.0-20250928165947-4916d95f4b01
github.com/oklog/ulid/v2 v2.1.1
github.com/otrego/clamshell v0.0.0-20220814024334-043dd78cf746
github.com/rs/cors v1.11.1
golang.org/x/net v0.38.0
google.golang.org/protobuf v1.36.6
golang.org/x/net v0.44.0
google.golang.org/protobuf v1.36.9
)

require (
github.com/VictoriaMetrics/easyproto v0.1.4 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/google/go-cmp v0.7.0 // indirect
github.com/oklog/ulid/v2 v2.1.1 // indirect
golang.org/x/text v0.23.0 // indirect
golang.org/x/text v0.29.0 // indirect
golang.org/x/time v0.6.0 // indirect
)

Expand Down
15 changes: 13 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
connectrpc.com/connect v1.18.1 h1:PAg7CjSAGvscaf6YZKUefjoih5Z/qYkyaTrBW8xvYPw=
connectrpc.com/connect v1.18.1/go.mod h1:0292hj1rnx8oFrStN7cB4jjVBeqs+Yx5yDIC2prWDO8=
connectrpc.com/connect v1.19.0 h1:LuqUbq01PqbtL0o7vn0WMRXzR2nNsiINe5zfcJ24pJM=
connectrpc.com/connect v1.19.0/go.mod h1:tN20fjdGlewnSFeZxLKb0xwIZ6ozc3OQs2hTXy4du9w=
github.com/VictoriaMetrics/easyproto v0.1.4 h1:r8cNvo8o6sR4QShBXQd1bKw/VVLSQma/V2KhTBPf+Sc=
github.com/VictoriaMetrics/easyproto v0.1.4/go.mod h1:QlGlzaJnDfFd8Lk6Ci/fuLxfTo3/GThPs2KH23mv710=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/gorhill/cronexpr v0.0.0-20180427100037-88b0669f7d75 h1:f0n1xnMSmBLzVfsMMvriDyA75NB/oBgILX2GcHXIQzY=
github.com/gorhill/cronexpr v0.0.0-20180427100037-88b0669f7d75/go.mod h1:g2644b03hfBX9Ov0ZBDgXXens4rxSxmqFBbhvKv2yVA=
github.com/makasim/flowstate v0.0.0-20250726121746-e662c53f5288 h1:ajU8iOGqcXWIL4FHaU9bIVZYiBHNYb3ZlObu+ewT4SQ=
github.com/makasim/flowstate v0.0.0-20250726121746-e662c53f5288/go.mod h1:576Odv1ZCb4I12pDq72WbZrwLegxzh5xpc1Fe0KDdIw=
github.com/makasim/flowstate v0.0.0-20250928112803-eb5364b83eb4 h1:03a5XK93tbmw6aPOQWLllclY/pMbLuzeoke7OZAXxIM=
github.com/makasim/flowstate v0.0.0-20250928112803-eb5364b83eb4/go.mod h1:Q2DpFG+Wx13WP4Vj5e7BilfRKa0cWrm21cYNzWg1zsw=
github.com/makasim/flowstate v0.0.0-20250928165947-4916d95f4b01 h1:OhhDaqVVlixyCbhhPSTvU4mYAHH4n6Mu5kSg0xYpmDw=
github.com/makasim/flowstate v0.0.0-20250928165947-4916d95f4b01/go.mod h1:Q2DpFG+Wx13WP4Vj5e7BilfRKa0cWrm21cYNzWg1zsw=
github.com/oklog/ulid/v2 v2.1.1 h1:suPZ4ARWLOJLegGFiZZ1dFAkqzhMjL3J1TzI+5wHz8s=
github.com/oklog/ulid/v2 v2.1.1/go.mod h1:rcEKHmBBKfef9DhnvX7y1HZBYxjXb0cP5ExxNsTT1QQ=
github.com/otrego/clamshell v0.0.0-20220814024334-043dd78cf746 h1:lRPeFeuZAdclG9NZudMoF5T+sImSK/YqGI7spKR7q/U=
Expand All @@ -27,11 +33,16 @@ go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
golang.org/x/net v0.38.0 h1:vRMAPTMaeGqVhG5QyLJHqNDwecKTomGeqbnfZyKlBI8=
golang.org/x/net v0.38.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8=
golang.org/x/net v0.44.0 h1:evd8IRDyfNBMBTTY5XRF1vaZlD+EmWx6x8PkhR04H/I=
golang.org/x/net v0.44.0/go.mod h1:ECOoLqd5U3Lhyeyo/QDCEVQ4sNgYsqvCZ722XogGieY=
golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY=
golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4=
golang.org/x/text v0.29.0/go.mod h1:7MhJOA9CD2qZyOKYazxdYMF85OwPdEr9jTtBpO7ydH4=
golang.org/x/time v0.6.0 h1:eTDhh4ZXt5Qf0augr54TN6suAUudPcawVZeIAPU7D4U=
golang.org/x/time v0.6.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY=
google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY=
google.golang.org/protobuf v1.36.9 h1:w2gp2mA27hUeUzj9Ex9FBjsBm40zfaDtEWow293U7Iw=
google.golang.org/protobuf v1.36.9/go.mod h1:fuxRtAxBytpl4zzqUh6/eyUujkJdNiuEkXntxiD/uRU=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
10 changes: 5 additions & 5 deletions internal/api/convertor/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,31 @@ func GameToData(g *v1.Game, d *flowstate.Data) error {
return err
}

d.ID = flowstate.DataID(g.Id)
d.B = b
d.Blob = b
return nil
}

func DataToGame(d *flowstate.Data) (*v1.Game, error) {
g := &v1.Game{}
if err := protojson.Unmarshal(d.B, g); err != nil {
if err := protojson.Unmarshal(d.Blob, g); err != nil {
return nil, err
}

return g, nil
}

func FindGame(e flowstate.Engine, gID string, gRev int32) (*v1.Game, *flowstate.StateCtx, *flowstate.Data, error) {
d := &flowstate.Data{}
stateCtx := &flowstate.StateCtx{}

if err := e.Do(
flowstate.GetStateByID(stateCtx, flowstate.StateID(gID), int64(gRev)),
flowstate.GetData(stateCtx, d, `game`),
flowstate.GetData(stateCtx, `game`),
); err != nil {
return nil, nil, nil, err
}

d := stateCtx.MustData(`game`)

g, err := DataToGame(d)
if err != nil {
return nil, nil, nil, err
Expand Down
8 changes: 3 additions & 5 deletions internal/api/convertor/undo.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package convertor

import (
"fmt"

"github.com/makasim/flowstate"
v1 "github.com/makasim/gogame/protogen/gogame/v1"
"google.golang.org/protobuf/encoding/protojson"
Expand All @@ -14,14 +12,14 @@ func UndoToData(u *v1.Undo, d *flowstate.Data) error {
return err
}

d.ID = flowstate.DataID(fmt.Sprintf("%s-%d", u.GameId, u.GameRev))
d.B = b
//d.ID = flowstate.DataID(fmt.Sprintf("%s-%d", u.GameId, u.GameRev))
d.Blob = b
return nil
}

func DataToUndo(d *flowstate.Data) (*v1.Undo, error) {
u := &v1.Undo{}
if err := protojson.Unmarshal(d.B, u); err != nil {
if err := protojson.Unmarshal(d.Blob, u); err != nil {
return nil, err
}

Expand Down
37 changes: 0 additions & 37 deletions internal/api/corsmiddleware/cors.go

This file was deleted.

54 changes: 6 additions & 48 deletions internal/api/gameservicev1/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,6 @@ import (

var _ gogamev1connect.GameServiceHandler = (*Service)(nil)

type createGameHandler interface {
CreateGame(_ context.Context, req *connect.Request[v1.CreateGameRequest]) (*connect.Response[v1.CreateGameResponse], error)
}

type joinGameHandler interface {
JoinGame(_ context.Context, req *connect.Request[v1.JoinGameRequest]) (*connect.Response[v1.JoinGameResponse], error)
}

type streamVacantGamesHandler interface {
StreamVacantGames(ctx context.Context, req *connect.Request[v1.StreamVacantGamesRequest], stream *connect.ServerStream[v1.StreamVacantGamesResponse]) error
}
Expand All @@ -26,61 +18,27 @@ type streamGameEventsHandler interface {
StreamGameEvents(context.Context, *connect.Request[v1.StreamGameEventsRequest], *connect.ServerStream[v1.StreamGameEventsResponse]) error
}

type makeMoveHandler interface {
MakeMove(_ context.Context, req *connect.Request[v1.MakeMoveRequest]) (*connect.Response[v1.MakeMoveResponse], error)
}

type resignHandler interface {
Resign(context.Context, *connect.Request[v1.ResignRequest]) (*connect.Response[v1.ResignResponse], error)
}

type passHandler interface {
Pass(context.Context, *connect.Request[v1.PassRequest]) (*connect.Response[v1.PassResponse], error)
}

type undoHandler interface {
Undo(_ context.Context, req *connect.Request[v1.UndoRequest]) (*connect.Response[v1.UndoResponse], error)
}

type Service struct {
cgh createGameHandler
jgh joinGameHandler
svgh streamVacantGamesHandler
sgeh streamGameEventsHandler
mmh makeMoveHandler
rh resignHandler
ph passHandler
uh undoHandler
}

func New(
cgh createGameHandler,
jgh joinGameHandler,
svgh streamVacantGamesHandler,
sgeh streamGameEventsHandler,
mmh makeMoveHandler,
rh resignHandler,
ph passHandler,
uh undoHandler,
) *Service {
return &Service{
cgh: cgh,
jgh: jgh,
svgh: svgh,
sgeh: sgeh,
mmh: mmh,
rh: rh,
ph: ph,
uh: uh,
}
}

func (s *Service) CreateGame(ctx context.Context, req *connect.Request[v1.CreateGameRequest]) (*connect.Response[v1.CreateGameResponse], error) {
return s.cgh.CreateGame(ctx, req)
panic("BUG: CreateGame must not be called")
}

func (s *Service) JoinGame(ctx context.Context, req *connect.Request[v1.JoinGameRequest]) (*connect.Response[v1.JoinGameResponse], error) {
return s.jgh.JoinGame(ctx, req)
panic("BUG: JoinGame must not be called")
}

func (s *Service) StreamVacantGames(ctx context.Context, req *connect.Request[v1.StreamVacantGamesRequest], stream *connect.ServerStream[v1.StreamVacantGamesResponse]) error {
Expand All @@ -92,17 +50,17 @@ func (s *Service) StreamGameEvents(ctx context.Context, req *connect.Request[v1.
}

func (s *Service) MakeMove(ctx context.Context, req *connect.Request[v1.MakeMoveRequest]) (*connect.Response[v1.MakeMoveResponse], error) {
return s.mmh.MakeMove(ctx, req)
panic("BUG: MakeMove must not be called")
}

func (s *Service) Pass(ctx context.Context, req *connect.Request[v1.PassRequest]) (*connect.Response[v1.PassResponse], error) {
return s.ph.Pass(ctx, req)
panic("BUG: Pass must not be called")
}

func (s *Service) Resign(ctx context.Context, req *connect.Request[v1.ResignRequest]) (*connect.Response[v1.ResignResponse], error) {
return s.rh.Resign(ctx, req)
panic("BUG: Resign must not be called")
}

func (s *Service) Undo(ctx context.Context, req *connect.Request[v1.UndoRequest]) (*connect.Response[v1.UndoResponse], error) {
return s.uh.Undo(ctx, req)
panic("BUG: Undo must not be called")
}
10 changes: 5 additions & 5 deletions internal/api/gameservicev1/streamgameeventshandler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,19 @@ func (h *Handler) StreamGameEvents(ctx context.Context, req *connect.Request[v1.
gID := state.Annotations[`game.id`]
gRev, _ := strconv.ParseInt(state.Annotations[`game.rev`], 10, 0)

d := &flowstate.Data{}
stateCtx := &flowstate.StateCtx{}

undoStateCtx := state.CopyToCtx(&flowstate.StateCtx{})
undoD := &flowstate.Data{}
if err := h.e.Do(
flowstate.GetStateByID(stateCtx, flowstate.StateID(gID), gRev),
flowstate.GetData(stateCtx, d, `game`),
flowstate.GetData(undoStateCtx, undoD, `undo`),
flowstate.GetData(stateCtx, `game`),
flowstate.GetData(undoStateCtx, `undo`),
); err != nil {
continue
}

d := stateCtx.MustData(`game`)
undoD := undoStateCtx.MustData(`undo`)

u, err := convertor.DataToUndo(undoD)
if err != nil {
continue
Expand Down
Loading