fix errors on insertion to game, fix db creation of game
This commit is contained in:
@@ -3,7 +3,8 @@ package actions
|
||||
import "errors"
|
||||
|
||||
var (
|
||||
ErrActionNotFound = errors.New("Action doesn't found")
|
||||
ErrObjTypeNotMatch = errors.New("Provided value type didn't match obj field type")
|
||||
ErrObjNotPointer = errors.New("Passed obj is not pointer")
|
||||
ErrActionNotFound = errors.New("Action doesn't found")
|
||||
ErrObjTypeNotMatch = errors.New("Provided value type didn't match obj field type")
|
||||
ErrObjNotPointer = errors.New("Passed obj is not pointer")
|
||||
ErrUserChannelIsClosed = errors.New("User channel is closed")
|
||||
)
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package actions
|
||||
|
||||
import (
|
||||
"gitea.local.lab/Lbenedar/foundry_helper_service/internal/foundry/temp_models/db"
|
||||
"gitea.local.lab/Lbenedar/foundry_helper_service/internal/foundry/temp_models/json"
|
||||
"gitea.local.lab/Lbenedar/foundry_helper_service/internal/foundry/transport"
|
||||
"gitea.local.lab/Lbenedar/foundry_helper_service/internal/foundry/types"
|
||||
)
|
||||
@@ -22,8 +24,18 @@ func (msg WsSessionMsg) Action(tr *transport.FoundryTransport, status *types.Fou
|
||||
close(tr.ReadChan.Reconnect())
|
||||
return nil
|
||||
}
|
||||
// tr.Logger.Warn("World is started. Please, return to setup page to fully initialize database")
|
||||
// go msg.OnActiveWorld(tr)
|
||||
|
||||
// select {
|
||||
// case <-tr.LoggedInChan:
|
||||
// return ErrUserChannelIsClosed
|
||||
// default:
|
||||
// tr.LoggedInChan <- true
|
||||
// }
|
||||
|
||||
// time.Sleep(3 * time.Second)
|
||||
// types.CloseChannel(tr.LoggedInChan)
|
||||
|
||||
go msg.OnActiveWorld(tr)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -37,13 +49,27 @@ func (msg WsSessionMsg) Action(tr *transport.FoundryTransport, status *types.Fou
|
||||
}
|
||||
|
||||
func (msg WsSessionMsg) OnActiveWorld(tr *transport.FoundryTransport) error {
|
||||
wsMsg := types.NewWsMessage("world", tr.CurrWsId)
|
||||
tr.CurrWsId++
|
||||
|
||||
answer, err := tr.HandleWebsocketRequest(wsMsg)
|
||||
msgJson, err := tr.GetJsonData("world")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
tr.Logger.Info("World data", "answer", string(answer))
|
||||
|
||||
tr.Logger.Info("Game data received")
|
||||
|
||||
gameJson, err := json.ParseGame(msgJson)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var foundryStateDb db.Game
|
||||
gameJson.ToDB(&foundryStateDb)
|
||||
|
||||
err = foundryStateDb.Insert(tr.DB)
|
||||
if err != nil {
|
||||
tr.ReadChan.Err() <- &types.FoundryError{Direction: types.WriterCode, Err: err, Type: types.DbCode}
|
||||
}
|
||||
|
||||
tr.Logger.Info("Game data succesfully inserted to DB")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user