50 lines
1.2 KiB
Go
50 lines
1.2 KiB
Go
package actions
|
|
|
|
import (
|
|
"gitea.local.lab/Lbenedar/foundry_helper_service/internal/foundry/transport"
|
|
"gitea.local.lab/Lbenedar/foundry_helper_service/internal/foundry/types"
|
|
)
|
|
|
|
type WsSessionMsg struct {
|
|
SessionId string `json:"sessionId"`
|
|
UserId string `json:"userId,omitempty"`
|
|
}
|
|
|
|
func (msg WsSessionMsg) Action(tr *transport.FoundryTransport, status *types.FoundryStatus) error {
|
|
if status.IsActive {
|
|
tr.Logger.Info("Session msg", "userid", msg.UserId)
|
|
if msg.UserId == "" {
|
|
err := tr.LogInToWorld()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
tr.Logger.Info("World is started. Succesfully logged into world")
|
|
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)
|
|
return nil
|
|
}
|
|
|
|
if tr.IsDbInit {
|
|
return nil
|
|
}
|
|
tr.IsDbInit = true
|
|
|
|
go tr.FillDBWithFoundryData()
|
|
return nil
|
|
}
|
|
|
|
func (msg WsSessionMsg) OnActiveWorld(tr *transport.FoundryTransport) error {
|
|
wsMsg := types.NewWsMessage("world", tr.CurrWsId)
|
|
tr.CurrWsId++
|
|
|
|
answer, err := tr.HandleWebsocketRequest(wsMsg)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
tr.Logger.Info("World data", "answer", string(answer))
|
|
return nil
|
|
}
|