Skip to content
This repository has been archived by the owner on May 8, 2023. It is now read-only.

Commit

Permalink
Merge pull request #95 from Regner/feature/map-data
Browse files Browse the repository at this point in the history
Adding map data
  • Loading branch information
regner authored Aug 24, 2017
2 parents 57ed0d8 + af24b19 commit f14dcac
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 11 deletions.
23 changes: 23 additions & 0 deletions client/decode.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package client

import (
"sort"

"github.com/mitchellh/mapstructure"
"github.com/regner/albiondata-client/log"
)

func decodeRequest(params map[string]interface{}) operation {
Expand All @@ -21,6 +24,12 @@ func decodeRequest(params map[string]interface{}) operation {
operation := operationAuctionGetOffers{}
mapstructure.Decode(params, &operation)

return operation
case 166:
operation := operationGetClusterMapInfo{}
mapstructure.Decode(params, &operation)
log.Debug("Location: ", params)

return operation
case 217:
operation := operationGoldMarketGetAverageInfo{}
Expand Down Expand Up @@ -59,6 +68,20 @@ func decodeResponse(params map[string]interface{}) operation {
operation := operationAuctionGetRequestsResponse{}
mapstructure.Decode(params, &operation)

return operation
case 166:
operation := operationGetClusterMapInfoResponse{}
mapstructure.Decode(params, &operation)
var keys []string
for k := range params {
keys = append(keys, k)
}
sort.Strings(keys)

for _, k := range keys {
log.Debug(k, ": ", params[k])
}

return operation
case 217:
operation := operationGoldMarketGetAverageInfoResponse{}
Expand Down
51 changes: 51 additions & 0 deletions client/operation_get_cluster_map_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package client

import (
"encoding/json"

"github.com/regner/albiondata-client/lib"
"github.com/regner/albiondata-client/log"
)

type operationGetClusterMapInfo struct {
}

func (op operationGetClusterMapInfo) Process(state *albionState, uploader iuploader) {
log.Debug("Got GetClusterMapInfo operation...")
}

type operationGetClusterMapInfoResponse struct {
ZoneID int `mapstructure:"0"`
BuildingType []int `mapstructure:"5"`
AvailableFood []int `mapstructure:"10"`
Reward []int `mapstructure:"12"`
AvailableSilver []int `mapstructure:"13"`
Owners []string `mapstructure:"14"`
Buildable []bool `mapstructure:"19"`
IsForSale []bool `mapstructure:"27"`
BuyPrice []int `mapstructure:"28"`
}

func (op operationGetClusterMapInfoResponse) Process(state *albionState, uploader iuploader) {
log.Debug("Got response to GetClusterMapInfo operation...")

data, err := json.Marshal(lib.MapDataUpload{
ZoneID: op.ZoneID,
BuildingType: op.BuildingType,
AvailableFood: op.AvailableFood,
Reward: op.Reward,
AvailableSilver: op.AvailableSilver,
Owners: op.Owners,
Buildable: op.Buildable,
IsForSale: op.IsForSale,
BuyPrice: op.BuyPrice,
})

if err != nil {
log.Errorf("Error while marshalling payload for market data: %v", err)
return
}

log.Info("Sending market data to ingest")
uploader.sendToIngest(data, lib.NatsMapDataIngest)
}
75 changes: 64 additions & 11 deletions cmd/natsdumper/natsdumper.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,24 @@ func init() {
flag.StringVar(
&natsChannels,
"c",
fmt.Sprintf("%s,%s", lib.NatsMarketOrdersDeduped, lib.NatsGoldPricesDeduped),
fmt.Sprintf("NATS channels to connect to, comma saperated. Can be '%s', '%s', '%s', '%s'",
lib.NatsMarketOrdersDeduped, lib.NatsGoldPricesDeduped, lib.NatsMarketOrdersIngest, lib.NatsGoldPricesIngest,
fmt.Sprintf(
"%s,%s,%s",
lib.NatsMarketOrdersDeduped,
lib.NatsGoldPricesDeduped,
lib.NatsMapDataDeduped,
),
fmt.Sprintf(
"NATS channels to connect to, comma saperated. Can be '%s', '%s', '%s', '%s'",
lib.NatsMarketOrdersDeduped,
lib.NatsGoldPricesDeduped,
lib.NatsMarketOrdersIngest,
lib.NatsGoldPricesIngest,
),
)
}

func subscribeMarketOrdersIngest(nc *nats.Conn) {
fmt.Printf("mi Subscribing %s\n", lib.NatsMarketOrdersIngest)
fmt.Printf("mo i Subscribing %s\n", lib.NatsMarketOrdersIngest)
marketCh := make(chan *nats.Msg, 64)
marketSub, err := nc.ChanSubscribe(lib.NatsMarketOrdersIngest, marketCh)
if err != nil {
Expand All @@ -53,14 +62,14 @@ func subscribeMarketOrdersIngest(nc *nats.Conn) {

for _, order := range morders.Orders {
jb, _ := json.Marshal(order)
fmt.Printf("mi %s\n", string(jb))
fmt.Printf("mo i %s\n", string(jb))
}
}
}
}

func subscribeMarketOrdersDeduped(nc *nats.Conn) {
fmt.Printf("md Subscribing %s\n", lib.NatsMarketOrdersDeduped)
fmt.Printf("mo d Subscribing %s\n", lib.NatsMarketOrdersDeduped)
marketCh := make(chan *nats.Msg, 64)
marketSub, err := nc.ChanSubscribe(lib.NatsMarketOrdersDeduped, marketCh)
if err != nil {
Expand All @@ -72,13 +81,13 @@ func subscribeMarketOrdersDeduped(nc *nats.Conn) {
for {
select {
case msg := <-marketCh:
fmt.Printf("md %s\n", string(msg.Data))
fmt.Printf("mo d %s\n", string(msg.Data))
}
}
}

func subscribeGoldPricesIngest(nc *nats.Conn) {
fmt.Printf("gi Subscribing %s\n", lib.NatsGoldPricesIngest)
fmt.Printf("gp i Subscribing %s\n", lib.NatsGoldPricesIngest)
goldCh := make(chan *nats.Msg, 64)
goldSub, err := nc.ChanSubscribe(lib.NatsGoldPricesIngest, goldCh)
if err != nil {
Expand All @@ -90,13 +99,13 @@ func subscribeGoldPricesIngest(nc *nats.Conn) {
for {
select {
case msg := <-goldCh:
fmt.Printf("gi %s\n", string(msg.Data))
fmt.Printf("gp i %s\n", string(msg.Data))
}
}
}

func subscribeGoldPricesDeduped(nc *nats.Conn) {
fmt.Printf("gd Subscribing %s\n", lib.NatsGoldPricesDeduped)
fmt.Printf("gp d Subscribing %s\n", lib.NatsGoldPricesDeduped)
goldCh := make(chan *nats.Msg, 64)
goldSub, err := nc.ChanSubscribe(lib.NatsGoldPricesDeduped, goldCh)
if err != nil {
Expand All @@ -108,7 +117,43 @@ func subscribeGoldPricesDeduped(nc *nats.Conn) {
for {
select {
case msg := <-goldCh:
fmt.Printf("gd %s\n", string(msg.Data))
fmt.Printf("gp d %s\n", string(msg.Data))
}
}
}

func subscribeMapDataIngest(nc *nats.Conn) {
fmt.Printf("md i Subscribing %s\n", lib.NatsMapDataIngest)
mapCh := make(chan *nats.Msg, 64)
mapSub, err := nc.ChanSubscribe(lib.NatsMapDataIngest, mapCh)
if err != nil {
fmt.Printf("%v\n", err)
return
}
defer mapSub.Unsubscribe()

for {
select {
case msg := <-mapCh:
fmt.Printf("md i %s\n", string(msg.Data))
}
}
}

func subscribeMapDataDeduped(nc *nats.Conn) {
fmt.Printf("md d Subscribing %s\n", lib.NatsMapDataDeduped)
mapCh := make(chan *nats.Msg, 64)
mapSub, err := nc.ChanSubscribe(lib.NatsMapDataDeduped, mapCh)
if err != nil {
fmt.Printf("%v\n", err)
return
}
defer mapSub.Unsubscribe()

for {
select {
case msg := <-mapCh:
fmt.Printf("md d %s\n", string(msg.Data))
}
}
}
Expand All @@ -134,6 +179,10 @@ func main() {
go subscribeGoldPricesIngest(nc)
case lib.NatsGoldPricesDeduped:
go subscribeGoldPricesDeduped(nc)
case lib.NatsMapDataIngest:
go subscribeMapDataIngest(nc)
case lib.NatsMapDataDeduped:
go subscribeMapDataDeduped(nc)
}

goChans = goChans + 1
Expand All @@ -152,5 +201,9 @@ func main() {
subscribeGoldPricesIngest(nc)
case lib.NatsGoldPricesDeduped:
subscribeGoldPricesDeduped(nc)
case lib.NatsMapDataIngest:
subscribeMapDataIngest(nc)
case lib.NatsMapDataDeduped:
subscribeMapDataDeduped(nc)
}
}
14 changes: 14 additions & 0 deletions lib/map.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package lib

// MapDataUpload contains information on zone maps
type MapDataUpload struct {
ZoneID int `json:"ZoneID"`
BuildingType []int `json:"BuildingType"`
AvailableFood []int `json:"AvailableFood"`
Reward []int `json:"Reward"`
AvailableSilver []int `json:"AvailableSilver"`
Owners []string `json:"Owners"`
Buildable []bool `json:"Buildable"`
IsForSale []bool `json:"IsForSale"`
BuyPrice []int `json:"BuyPrice"`
}
1 change: 1 addition & 0 deletions lib/market.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package lib
type MarketOrder struct {
ID int `json:"Id"`
ItemID string `json:"ItemTypeId"`
GroupTypeId string `json:"ItemGroupTypeId"`
LocationID int `json:"LocationId"`
QualityLevel int `json:"QualityLevel"`
EnchantmentLevel int `json:"EnchantmentLevel"`
Expand Down
2 changes: 2 additions & 0 deletions lib/nats.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ const (
NatsGoldPricesDeduped = "goldprices.deduped"
NatsMarketOrdersIngest = "marketorders.ingest"
NatsMarketOrdersDeduped = "marketorders.deduped"
NatsMapDataIngest = "mapdata.ingest"
NatsMapDataDeduped = "mapdata.deduped"
)

0 comments on commit f14dcac

Please sign in to comment.