From e539aeb33813072c011306ba28b846c17a2204e8 Mon Sep 17 00:00:00 2001 From: Alain Gilbert Date: Wed, 25 Mar 2020 21:01:03 -0700 Subject: [PATCH 1/3] Add sample --- samples/v7.2/en/messages.html | 513 ++++++++++++++++++++++++++++++++++ 1 file changed, 513 insertions(+) create mode 100644 samples/v7.2/en/messages.html diff --git a/samples/v7.2/en/messages.html b/samples/v7.2/en/messages.html new file mode 100644 index 00000000..6be9d565 --- /dev/null +++ b/samples/v7.2/en/messages.html @@ -0,0 +1,513 @@ +
+
\ No newline at end of file From e6d45c521675031643513a8041f43c1c57538a38 Mon Sep 17 00:00:00 2001 From: Alain Gilbert Date: Fri, 27 Mar 2020 23:26:51 -0700 Subject: [PATCH 2/3] LoginWithExistingCookies to return either or not it reused the existing cookies --- interfaces.go | 2 +- ogame.go | 31 +++++++++++++++++++------------ prioritize.go | 3 ++- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/interfaces.go b/interfaces.go index 0871e941..a1873a80 100644 --- a/interfaces.go +++ b/interfaces.go @@ -37,7 +37,7 @@ type Wrapper interface { GetPageContent(url.Values) []byte GetAlliancePageContent(url.Values) []byte PostPageContent(url.Values, url.Values) []byte - LoginWithExistingCookies() error + LoginWithExistingCookies() (bool, error) Login() error Logout() IsLoggedIn() bool diff --git a/ogame.go b/ogame.go index c81923a4..adf07acb 100644 --- a/ogame.go +++ b/ogame.go @@ -169,7 +169,7 @@ type Params struct { // New creates a new instance of OGame wrapper. func New(universe, username, password, lang string) (*OGame, error) { b := NewNoLogin(username, password, universe, lang, "", 0) - if err := b.LoginWithExistingCookies(); err != nil { + if _, err := b.LoginWithExistingCookies(); err != nil { return nil, err } return b, nil @@ -186,7 +186,7 @@ func NewWithParams(params Params) (*OGame, error) { } } if params.AutoLogin { - if err := b.LoginWithExistingCookies(); err != nil { + if _, err := b.LoginWithExistingCookies(); err != nil { return nil, err } } @@ -556,7 +556,8 @@ func (b *OGame) getServerData() (ServerData, error) { return serverData, nil } -func (b *OGame) loginWithExistingCookies() error { +// Return either or not the bot logged in using the existing cookies. +func (b *OGame) loginWithExistingCookies() (bool, error) { cookies := b.Client.Jar.(*cookiejar.Jar).AllCookies() found := false for _, c := range cookies { @@ -566,26 +567,28 @@ func (b *OGame) loginWithExistingCookies() error { } } if !found { - return b.login() + err := b.login() + return false, err } server, userAccount, err := b.loginPart1() if err != nil { - return b.login() + err := b.login() + return false, err } if err := b.loginPart2(server, userAccount); err != nil { - return err + return false, err } pageHTML, err := b.getPage(OverviewPage, CelestialID(0)) if err != nil { - return err + return false, err } b.debug("login using existing cookies") if err := b.loginPart3(userAccount, pageHTML); err != nil { - return err + return false, err } - return nil + return true, nil } func (b *OGame) login() error { @@ -747,8 +750,12 @@ var DefaultLoginWrapper = func(loginFn func() error) error { return loginFn() } -func (b *OGame) wrapLoginWithExistingCookies() error { - return b.loginWrapper(b.loginWithExistingCookies) +func (b *OGame) wrapLoginWithExistingCookies() (useCookies bool, err error) { + fn := func() error { + useCookies, err = b.loginWithExistingCookies() + return err + } + return useCookies, b.loginWrapper(fn) } func (b *OGame) wrapLogin() error { @@ -3936,7 +3943,7 @@ func (b *OGame) SetUserAgent(newUserAgent string) { } // LoginWithExistingCookies to ogame server reusing existing cookies -func (b *OGame) LoginWithExistingCookies() error { +func (b *OGame) LoginWithExistingCookies() (bool, error) { return b.WithPriority(Normal).LoginWithExistingCookies() } diff --git a/prioritize.go b/prioritize.go index 973c60c8..7c48518d 100644 --- a/prioritize.go +++ b/prioritize.go @@ -72,7 +72,8 @@ func (b *Prioritize) FakeCall(name string, delay int) { } // LoginWithExistingCookies to ogame server reusing existing cookies -func (b *Prioritize) LoginWithExistingCookies() error { +// Returns either or not the bot logged in using the existing cookies +func (b *Prioritize) LoginWithExistingCookies() (bool, error) { b.begin("LoginWithExistingCookies") defer b.done() return b.bot.wrapLoginWithExistingCookies() From 7313f1aaa834ebd4a0513f009e44ef1ac66569f6 Mon Sep 17 00:00:00 2001 From: Alain Gilbert Date: Sat, 28 Mar 2020 00:08:23 -0700 Subject: [PATCH 3/3] Add auctioneer packet examples --- ogame.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ogame.go b/ogame.go index adf07acb..c7c71391 100644 --- a/ogame.go +++ b/ogame.go @@ -933,6 +933,9 @@ LOOP: } else if bytes.Equal(msg, []byte("2::")) { _, _ = b.ws.Write([]byte("2::")) } else if regexp.MustCompile(`\d+::/auctioneer`).Match(msg) { + // 5::/auctioneer:{"name":"timeLeft","args":["approx. 10m remaining until the auction ends"]} // every minute + // 5::/auctioneer:{"name":"new bid","args":[{"player":{"id":106734,"name":"Someone","link":"https://s152-en.ogame.gameforge.com/game/index.php?page=ingame&component=galaxy&galaxy=4&system=116"},"sum":2000,"price":3000,"bids":2,"auctionId":"13355"}]} + // 5::/auctioneer:{"name":"auction finished","args":[{"sum":2000,"player":{"id":106734,"name":"Someone","link":"http://s152-en.ogame.gameforge.com/game/index.php?page=ingame&component=galaxy&galaxy=4&system=116"},"bids":2,"info":"Next auction in:
\n1390","time":"06:36"}]} for _, clb := range b.auctioneerCallbacks { clb(msg) }