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

@@ -2,6 +2,7 @@ package requests
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
"net/url"
@@ -17,12 +18,48 @@ func (conf *FoundryHttpRequest) PostAuthenticationData() (*http.Response, error)
return nil, err
}
header := conf.GetRequestHeader()
header := conf.GetRequestHeader(AuthPath)
header.Set("Content-Length", fmt.Sprintf("%d", len(authData.Encode())))
req.Header = header.Clone()
client := &http.Client{}
client := &http.Client{Jar: conf.Jar}
resp, err := client.Do(req)
if err != nil {
return nil, err
}
return resp, nil
}
func (conf *FoundryHttpRequest) PostJoinWorld(userId, password string) (*http.Response, error) {
data := struct {
UserId string `json:"userid"`
Password string `json:"password"`
Action string `json:"action"`
Session string `json:"session"`
}{
UserId: userId,
Password: password,
Action: "join",
Session: *conf.SessionID,
}
byteData, err := json.Marshal(data)
if err != nil {
return nil, err
}
req, err := http.NewRequest("POST", fmt.Sprintf("http://%s%s", conf.Host, JoinPath), bytes.NewBuffer(byteData))
if err != nil {
return nil, err
}
header := conf.GetRequestHeaderJson(JoinPath)
header.Set("Content-Length", fmt.Sprintf("%d", len(byteData)))
req.Header = header.Clone()
client := &http.Client{Jar: conf.Jar}
resp, err := client.Do(req)
if err != nil {
return nil, err
@@ -40,12 +77,12 @@ func (conf *FoundryHttpRequest) PostLaunchWorld(world string) (*http.Response, e
return nil, err
}
header := conf.GetRequestHeader()
header := conf.GetRequestHeader(SetupPath)
header.Set("Content-Length", fmt.Sprintf("%d", len(launchData.Encode())))
req.Header = header.Clone()
client := &http.Client{}
client := &http.Client{Jar: conf.Jar}
resp, err := client.Do(req)
if err != nil {
return nil, err
@@ -62,12 +99,12 @@ func (conf *FoundryHttpRequest) PostReturnToSetup() (*http.Response, error) {
return nil, err
}
header := conf.GetRequestHeader()
header := conf.GetRequestHeader(JoinPath)
header.Set("Content-Length", fmt.Sprintf("%d", len(launchData.Encode())))
req.Header = header.Clone()
client := &http.Client{}
client := &http.Client{Jar: conf.Jar}
resp, err := client.Do(req)
if err != nil {
return nil, err