Open farta1986 opened 4 years ago
You can start it with the --port
flag. eg: ./ogamed --port 8090
I just added an endpoint for "jump-gate". Hopefully it works, I didn't try it.
curl http://127.0.0.1:8080/bot/moons/<ORIGIN_MOON_ID>/jump-gate -d "moonDestination=12345&ships=204,1&ships=205,2"
You need >= 0.39.1
Thanks a lot. BTW is there any interface for
You can Add an Endpoint to the OGamed Service very easy.
Add Endpoint Example
e.POST("/api/v1/flighttime", APIFlightTime)
func APIFlightTime(c echo.Context) error {
bot := c.Get("bot").(*ogame.OGame)
cachedData := bot.GetCachedData()
formdata, _ := c.MultipartForm()
var ships ogame.ShipsInfos
var origin int64
var destination ogame.Coordinate
var speed ogame.Speed
for k, v := range formdata.Value {
log.Printf("%s, %s", k, v[0])
switch k {
case "LightFighter":
nbr, _ := strconv.ParseInt(v[0], 10, 64)
ships.LightFighter = nbr
break
case "HeavyFighter":
nbr, _ := strconv.ParseInt(v[0], 10, 64)
ships.HeavyFighter = nbr
break
case "Cruiser":
nbr, _ := strconv.ParseInt(v[0], 10, 64)
ships.Cruiser = nbr
break
case "Battleship":
nbr, _ := strconv.ParseInt(v[0], 10, 64)
ships.Battleship = nbr
break
case "Battlecruiser":
nbr, _ := strconv.ParseInt(v[0], 10, 64)
ships.Battlecruiser = nbr
break
case "Bomber":
nbr, _ := strconv.ParseInt(v[0], 10, 64)
ships.Bomber = nbr
break
case "Destroyer":
nbr, _ := strconv.ParseInt(v[0], 10, 64)
ships.Destroyer = nbr
break
case "Deathstar":
nbr, _ := strconv.ParseInt(v[0], 10, 64)
ships.Deathstar = nbr
break
case "SmallCargo":
nbr, _ := strconv.ParseInt(v[0], 10, 64)
ships.SmallCargo = nbr
break
case "LargeCargo":
nbr, _ := strconv.ParseInt(v[0], 10, 64)
ships.LargeCargo = nbr
break
case "ColonyShip":
nbr, _ := strconv.ParseInt(v[0], 10, 64)
ships.ColonyShip = nbr
break
case "Recycler":
nbr, _ := strconv.ParseInt(v[0], 10, 64)
ships.Recycler = nbr
break
case "EspionageProbe":
nbr, _ := strconv.ParseInt(v[0], 10, 64)
ships.EspionageProbe = nbr
break
case "Crawler":
nbr, _ := strconv.ParseInt(v[0], 10, 64)
ships.Crawler = nbr
break
case "Reaper":
nbr, _ := strconv.ParseInt(v[0], 10, 64)
ships.Reaper = nbr
break
case "Pathfinder":
nbr, _ := strconv.ParseInt(v[0], 10, 64)
ships.Pathfinder = nbr
break
case "origin":
nbr, _ := strconv.ParseInt(v[0], 10, 64)
origin = nbr
break
case "speed":
nbr, _ := strconv.ParseInt(v[0], 10, 64)
speed = ogame.Speed(nbr)
break
case "destGalaxy":
nbr, _ := strconv.ParseInt(v[0], 10, 64)
destination.Galaxy = nbr
break
case "destSystem":
nbr, _ := strconv.ParseInt(v[0], 10, 64)
destination.System = nbr
break
case "destPosition":
nbr, _ := strconv.ParseInt(v[0], 10, 64)
destination.Position = nbr
break
}
}
cel := bot.GetCachedCelestial(origin)
secs, fuel := bot.FlightTime(cel.GetCoordinate(), destination, speed, ships)
cargo := ships.Cargo(cachedData.Researches, false, bot.CharacterClass() == ogame.Collector)
human_time := time.Duration(secs) * time.Second
data := struct {
Secs int64 `json:"secs"`
Fuel int64 `json:"fuel"`
Cargo int64 `json:"cargo"`
Human_time string `json:"human_time"`
}{
Secs: secs,
Fuel: fuel,
Cargo: cargo,
Human_time: human_time.String(),
}
return c.JSON(http.StatusOK, data)
}
Has ogamed exposed any http interface to
I did't find them in document & I'm not familiar with go. Would you have a look about it? Thank you.