Skip to content

Commit

Permalink
handle errors
Browse files Browse the repository at this point in the history
Interactive CLI

Add deps

test tcp & http bot

Add deps

Add planet img

cleanup

send message

samples html

get defense

mock fns

cleanup & test

Add fns

fix bug

galaxy infos

simplify code

send fleet

Add type FleetID

lint

logout

update readme

improve cli

update readme

Create LICENSE

fix imports

update user-agent

bot logging

Add logs

handle >= 500 http status

Handle bot error

refactor getPageContent

Add endpoint to display original overview

move constants file

start tcp server in a fn

Fix code

Add some formulas

building example

remove submodules

intercept signals

cleanup + RPC client/server

cli params

reset cookie jar on login

static assets

simplify code

improve bot

cleanup

fix browser links

fix browser

Check fleet errors

get planet by coordinate

agent sub command & account defender code

split code

lint

makefile deploy

remove bindata from git

ignore bindata

experiment

Add logs

multiple accounts

start/stop bots

simplify code

galaxy scanner

galaxy scanner

fix imports

move file

bunch of tests

improve ui

galaxy with debris sample

use new resources pkg

extract debris and player tags from galaxy page

improve defender algo

Add new fields to DB

Galaxy explorer

Galaxy player search

fix tests

extract alliance infos

Add alliance infos to schema / scanner

alliance search

add bot to manager

buildings

Add building infos

technologies infos

testing

testing

cleanup

missing file

better ui

crawl ships

colors

improve ui

improve galaxy view ui

scan universe now feature

fix template

improve ux

better ux

Add missing defenses to crawler

page for top-100 debris

GetUniverseSpeed feature

when attacked, spend resources on cancelable buildings/techs

..

util fn

stuff

simplify code

OGameID type

test

...

cancel research/building fns

bot ai plan

avoid out of range panics

fix tests

message sample

espionage report sample

simplify code

Add overview in jp and de

simplify code

fix example

simplify code

fix imports

Get ships by ogame id

Fix ships ogame id type

simplify code

long line

simplify code

simplify code

simplify code

complete defender

long lines

lint

Change sendFleet signature

Add fns to resources

Add more infos to galaxy page

remove debug code

constructions being built

improve ui

... stuff

Check attacks now chan

improve ui

better ui

GetFleets feature

better ux

better ux

start bot AI

fix bug

fix logger

GetProduction feature

Add doc

more doc

test

repatriate resources

assets

rename file

more assets

img

improve ui

fix

nothing

test fns

simplify build fns

Add flexible fns to wrapper interface

lint

better name

dedup code

typo

add tests

add todo

long lines

simplify code

move code

extract fleet id in getFleets

fix type

split type in many files

String fns

simplify code

nothing again

requirements for ships

fix requirements for graviton tech

more doc

setResourcesSettings

remove useless code

fix

fr sample

i18n user infos regex

Fix regex, planet name can be multi words

Fix regex for french universes

Allow bot to use http/socks proxy

reorder

move code

mv code

ogamed service

remove bindata

ignore bindata

update readme

use cli

...

remove useless fn

reorder fns

remove duplicated code

return better err

ogamed

apparently order is important '-__-

fix ogamed

move package resources

update doc

readme

update doc

more doc

more doc

pubsub & ignore test bot

goreleaser test

update doc

update api responses

fix sendMessage

handle more errors when sending message

Add requirements to ships

get defense by id

normalize defense requirements

fix tests

Change OGameID -> ID

Add new fns to brain

move file

getRequirementToBuild

Add resources to another

test price of deut synth

total price of all requirements

nothing

lint

change defense GetBaseCost -> GetPrice

Resources CanAfford method

simplify code

ResourcesBuildings GetProductions

levelable interface

buildable interface

Add GetLevel to tech & building

normalize IsAvailable fns

normalize GetPrice

Fix for new fns

simplify code

simplify code

Add resources settings to productions calc

fix code

simplify code

fix divison by zero

simplify code

timeUntilResources test

metal mine test

useless

nothing

simplify code

extract static ogame informations as we login

add doc

simplify code

display server stats

simplify code

Equal method for coordinate

simplify code

fix galaxy scanner bad state

If we need deut and we don't produce any, infinite time

Add doc

Add building construction time

test construction time on metalmine

lint

Add & test tech construction time

construction time for ships/defenses

better timeUntilResources

getRequirementToBuild based on timeUntilResources

testing stuff

useless log

fix makefile

nothing

Add metal storage capacity

crystal storage capacity & test

deut tank capacity & test

simplify code

Add tests for shipyard

Add tests for astrophysic

impulse drive tests

combustion drive tests

simplify code

Add methods to interfaces

defense has no increase factor

better ogame id string fn

fix for new string fn

esearch lab test

lint

get ordered requirements to build

tests

fix tests

Add ship only if > 0

repatriate resources to se SC as well

Fix inactive info

Add inactive infos to bot DB & galaxy page

Add link from empire page to galaxy

test code

extract Administrator infos

Add administrator to bot

Delete message by id

Get spy reports ids

admin sample

Add asset

add samples

improve doc

Get espionage report by msg id

fix typo

fleet espionage report

better code

outlaw example

newbie sample

Add missing values

spy report defence example

add defences to spy report

extract coords

remove false infos !

host & port flags

get compiled version

display version in html

update readme

favicon

simplify code

Add colors to galaxy view

fix bug in LC manager

extract ogame time location at login

Add fleet ArriveIn (secs)

simplify code

simplify attack arrival time

Get ship speed

fix interface

doc

galaxy distance

fr ship names

system distance

fix typo

planet distance

calc flight time example

fix imports

stop galaxy scan button

Add logs

scanner to log to db

logs page

crawler to log in db

defender to log in db

debug scanner log

table header

logs filter

fix typo

useless code

improve logs

cancel evacuations

check attacks now

fix typo

logs

logs

hack remove flickering

fix host

more fns to resources

universe page

test basic algo to build mines

once.Tick test

ogame C wrapper

C example

Add fn to c wrapper

fix typo

better example

missile attack

fix auto scrolling

event_linst missile attack

improve logs

improve autobuild algo

improve espionage messages retreival

better logs

improve auto build

better num format

improve fmt

test

spy report table

allow to scan one page of the universe now

format local time fn for tmpls

scan system now handler

simplify code

account crawler to crawl messages

report page

new way to display galaxy pages

extract report date

fix typo

improve template

btn to delete bot

Delete bot

update readme

tmpl

remove useless locks

Add new methods to get server infos

add server infos to bot home page

update readme

change icon

new menu

Add admin / account / license pages

remove bot
  • Loading branch information
alaingilbert committed Jul 26, 2018
1 parent 8822934 commit 4bc58d1
Show file tree
Hide file tree
Showing 179 changed files with 52,468 additions and 388 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
.idea
dist
cmd/scripts/bindata
cmd/bot1
Empty file added .gitmodules
Empty file.
41 changes: 41 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
project_name: ogamed
release:
github:
owner: alaingilbert
name: ogame
name_template: '{{.Tag}}'
brew:
commit_author:
name: goreleaserbot
email: [email protected]
install: bin.install "ogame"
builds:
- goos:
- windows
- linux
- darwin
goarch:
- amd64
- "386"
goarm:
- "6"
main: ./cmd/ogamed/main.go
ldflags: -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}}
binary: ogamed
archive:
format: tar.gz
name_template: '{{ .Binary }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{
.Arm }}{{ end }}'
files:
- licence*
- LICENCE*
- license*
- LICENSE*
- readme*
- README*
- changelog*
- CHANGELOG*
snapshot:
name_template: SNAPSHOT-{{ .Commit }}
checksum:
name_template: '{{ .ProjectName }}_{{ .Version }}_checksums.txt'
21 changes: 21 additions & 0 deletions .realize.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
schema:
- name: ogame
path: /Users/agilbert/go/src/ogame/cmd/scripts
args:
- -rpc
commands:
run:
status: true
watcher:
extensions:
- go
- html
paths:
- /
ignored_paths:
- .git
- .realize
- vendor
scripts:
- type: before
command: make -C ../.. bindata-dev
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018 Alain Gilbert

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
18 changes: 18 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
PKGS = $(shell go list ./... | grep -v /vendor/ | grep -v /bindata)
VERSION = $(shell git describe)

lint:
@golint $(PKGS)

test:
@go test $(PKGS)

serve:
realize start

bindata-dev:
go-bindata -debug -pkg bindata -o cmd/scripts/bindata/bindata.go -prefix "cmd/scripts/web/public/" cmd/scripts/web/public/...

bindata-prod:
go-bindata -pkg bindata -o cmd/scripts/bindata/bindata.go -prefix "cmd/scripts/web/public/" cmd/scripts/web/public/...

build: bindata-prod
go build -ldflags "-s -w -X main.version=$(VERSION)" -o bot cmd/scripts/main.go

build-linux: bindata-prod
GOOS=linux GOARCH=amd64 go build -ldflags "-s -w -X main.version=0.0.0" -o bot cmd/scripts/main.go

.PHONY: bindata-dev bindata-prod build build-linux serve test lint
147 changes: 146 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,146 @@
Documentation: [https://godoc.org/github.com/alaingilbert/ogame](https://godoc.org/github.com/alaingilbert/ogame)
<img src="./logo.png" width="300" />

# OGame automation toolkit

- As a library
- As a service (ogamed)

---

# ogame library

### Verify attack example

```go
package main

import "fmt"
import "os"
import "github.com/alaingilbert/ogame"

func main() {
universe := os.Getenv("UNIVERSE")
username := os.Getenv("USERNAME")
password := os.Getenv("PASSWORD")
bot, _ := ogame.New(universe, username, password)
attacked := bot.IsUnderAttack()
fmt.Println(attacked) // False
}
```

### Available methods

```go
SetUserAgent(newUserAgent string)
ServerURL() string
GetPageContent(url.Values) string
Login() error
Logout()
GetUniverseSpeed() int
GetUniverseSpeedFleet() int
IsDonutGalaxy() bool
IsDonutSystem() bool
ServerVersion() string
ServerTime() time.Time
IsUnderAttack() bool
GetUserInfos() UserInfos
SendMessage(playerID int, message string) error
GetFleets() []Fleet
CancelFleet(FleetID) error
GetAttacks() []AttackEvent
GalaxyInfos(galaxy, system int) ([]PlanetInfos, error)
GetResearch() Researches
GetPlanets() []Planet
GetPlanetByCoord(Coordinate) (Planet, error)
GetPlanet(PlanetID) (Planet, error)
GetEspionageReportMessages() ([]EspionageReportSummary, error)
GetEspionageReport(msgID int) (EspionageReport, error)
DeleteMessage(msgID int) error

// Planet specific functions
GetResourceSettings(PlanetID) (ResourceSettings, error)
SetResourceSettings(PlanetID, ResourceSettings) error
GetResourcesBuildings(PlanetID) (ResourcesBuildings, error)
GetDefense(PlanetID) (Defense, error)
GetShips(PlanetID) (Ships, error)
GetFacilities(PlanetID) (Facilities, error)
Build(planetID PlanetID, ogameID ID, nbr int) error
BuildCancelable(PlanetID, ID) error
BuildProduction(planetID PlanetID, ogameID ID, nbr int) error
BuildBuilding(planetID PlanetID, buildingID ID) error
BuildTechnology(planetID PlanetID, technologyID ID) error
BuildDefense(planetID PlanetID, defenseID ID, nbr int) error
BuildShips(planetID PlanetID, shipID ID, nbr int) error
GetProduction(PlanetID) ([]Quantifiable, error)
ConstructionsBeingBuilt(PlanetID) (buildingID ID, buildingCountdown int, researchID ID, researchCountdown int)
CancelBuilding(PlanetID) error
CancelResearch(PlanetID) error
GetResources(PlanetID) (Resources, error)
SendFleet(planetID PlanetID, ships []Quantifiable, speed Speed, where Coordinate, mission MissionID, resources Resources) (FleetID, error)
```

### Full documentation

[https://godoc.org/github.com/alaingilbert/ogame](https://godoc.org/github.com/alaingilbert/ogame)

---

# ogamed service

Download [ogamed binary here](https://github.com/alaingilbert/ogame/releases)

```
./ogamed --universe=Test [email protected] --password=secret
```

```
$ curl 127.0.0.1:8080/bot/is-under-attack
{"Status":"ok","Code":200,"Message":"","Result":false}
$ curl 127.0.0.1:8080/bot/send-message -d 'playerID=123&message="Sup boi!"'
{"Status":"ok","Code":200,"Message":"","Result":null}
$ curl 127.0.0.1:8080/bot/user-infos
{"Status":"ok","Code":200,"Message":"","Result":{"PlayerID":106734,"PlayerName":"Commodore Nomad","Points":43825,"Rank":1130,"Total":1675,"HonourPoints":0}}
```

```
POST /bot/set-user-agent
POST /bot/server-url
POST /bot/page-content
GET /bot/login
GET /bot/logout
GET /bot/server/speed
GET /bot/server/version
GET /bot/server/time
GET /bot/is-under-attack
GET /bot/user-infos
POST /bot/send-message
GET /bot/fleets
POST /bot/fleets/:fleetID/cancel
GET /bot/attacks
GET /bot/galaxy-infos/:galaxy/:system
GET /bot/get-research
GET /bot/planets
GET /bot/planets/:galaxy/:system/:position
GET /bot/planets/:planetID
GET /bot/planets/:planetID/resource-settings
POST /bot/planets/:planetID/resource-settings
GET /bot/planets/:planetID/resources-buildings
GET /bot/planets/:planetID/defence
GET /bot/planets/:planetID/ships
GET /bot/planets/:planetID/facilities
POST /bot/planets/:planetID/build/:ogameID/:nbr
POST /bot/planets/:planetID/build/cancelable/:ogameID
POST /bot/planets/:planetID/build/production/:ogameID/:nbr
POST /bot/planets/:planetID/build/building/:ogameID
POST /bot/planets/:planetID/build/technology/:ogameID
POST /bot/planets/:planetID/build/defence/:ogameID/:nbr
POST /bot/planets/:planetID/build/ships/:ogameID/:nbr
GET /bot/planets/:planetID/production
GET /bot/planets/:planetID/constructions
POST /bot/planets/:planetID/cancel-building
POST /bot/planets/:planetID/cancel-research
GET /bot/planets/:planetID/resources
POST /bot/planets/:planetID/send-fleet
```
26 changes: 26 additions & 0 deletions attackEvent.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package ogame

import (
"strconv"
"time"
)

// AttackEvent ...
type AttackEvent struct {
MissionType MissionID
Origin Coordinate
Destination Coordinate
ArrivalTime time.Time
AttackerID int
Missiles int
}

func (a AttackEvent) String() string {
return "" +
"Mission Type: " + strconv.Itoa(int(a.MissionType)) + "\n" +
" Origin: " + a.Origin.String() + "\n" +
" Destination: " + a.Destination.String() + "\n" +
" ArrivalTime: " + a.ArrivalTime.String() + "\n" +
" AttackerID: " + strconv.Itoa(a.AttackerID) + "\n" +
" Missiles: " + strconv.Itoa(a.Missiles)
}
34 changes: 34 additions & 0 deletions buildable/buildable.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package buildable

import (
"github.com/alaingilbert/ogame"
"github.com/alaingilbert/ogame/buildings"
"github.com/alaingilbert/ogame/defenses"
"github.com/alaingilbert/ogame/ships"
"github.com/alaingilbert/ogame/technologies"
)

// Buildable ...
type Buildable interface {
GetOGameID() ogame.ID
IsAvailable(ogame.ResourcesBuildings, ogame.Facilities, ogame.Researches, int) bool
GetPrice(int) ogame.Resources
GetRequirements() map[ogame.ID]int
}

// GetByID ...
func GetByID(id ogame.ID) Buildable {
if id.IsBuilding() {
return buildings.GetByID(id)
}
if id.IsTech() {
return technologies.GetByID(id)
}
if id.IsDefense() {
return defenses.GetByID(id)
}
if id.IsShip() {
return ships.GetByID(id)
}
return nil
}
20 changes: 20 additions & 0 deletions buildings/allianceDepot/allianceDepot.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package allianceDepot

import (
"github.com/alaingilbert/ogame"
"github.com/alaingilbert/ogame/buildings/baseBuilding"
)

// AllianceDepot ...
type AllianceDepot struct {
baseBuilding.BaseBuilding
}

// New ...
func New() *AllianceDepot {
b := new(AllianceDepot)
b.OGameID = 34
b.IncreaseFactor = 2.0
b.BaseCost = ogame.Resources{Metal: 20000, Crystal: 40000}
return b
}
Loading

0 comments on commit 4bc58d1

Please sign in to comment.