Add account feature
@@ -32,6 +32,7 @@ import (
// Wrapper all available functions to control ogame bot
type Wrapper interface {
GetSession() string
+ AddAccount(number int, lang string) (NewAccount, error)
GetServer() Server
SetUserAgent(newUserAgent string)
ServerURL() string
@@ -2832,6 +2833,47 @@ func (b *OGame) GetSession() string {
return b.ogameSession
}
+type NewAccount struct {
+ ID int
+ Server struct {
+ Language string
+ Number int
+ }
+}
+
+// AddAccount add a new account (server) to your list of accounts
+func (b *OGame) AddAccount(number int, lang string) (NewAccount, error) {
+ var payload struct {
+ Language string `json:"language"`
+ Number int `json:"number"`
+ }
+ payload.Language = lang
+ payload.Number = number
+ jsonPayloadBytes, err := json.Marshal(&payload)
+ if err != nil {
+ return NewAccount{}, err
+ }
+ req, err := http.NewRequest("PUT", "https://lobby-api.ogame.gameforge.com/users/me/accounts", strings.NewReader(string(jsonPayloadBytes)))
+ if err != nil {
+ return NewAccount{}, err
+ }
+ req.Header.Add("Content-Type", "application/json")
+ resp, err := b.client.Do(req)
+ if err != nil {
+ return NewAccount{}, err
+ }
+ defer resp.Body.Close()
+ by, err := ioutil.ReadAll(resp.Body)
+ if err != nil {
+ return NewAccount{}, err
+ }
+ var newAccount NewAccount
+ if err := json.Unmarshal(by, &newAccount); err != nil {
+ return NewAccount{}, err
+ }
+ return newAccount, nil
+}
+
// GetServer get ogame server information that the bot is connected to
func (b *OGame) GetServer() Server {
return b.server
