add reconnect to websocket, add get world json object

This commit is contained in:
lbenedar
2026-04-13 17:40:59 +03:00
parent cd204ebcf5
commit 5bb592ea8a
14 changed files with 321 additions and 103 deletions

View File

@@ -6,13 +6,24 @@ import (
)
type WsSessionMsg struct {
SessionId string `json:"sessionId"`
UserId *string `json:"userId,omitempty"`
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.Warn("World is started. Please, return to setup page to fully initialize database")
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
}
@@ -24,3 +35,15 @@ func (msg WsSessionMsg) Action(tr *transport.FoundryTransport, status *types.Fou
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
}