diff --git a/client/decode.go b/client/decode.go index 5fc99f9..0366cc3 100644 --- a/client/decode.go +++ b/client/decode.go @@ -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 { @@ -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{} @@ -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{} diff --git a/client/operation_get_cluster_map_info.go b/client/operation_get_cluster_map_info.go new file mode 100644 index 0000000..c620b2a --- /dev/null +++ b/client/operation_get_cluster_map_info.go @@ -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) +} diff --git a/cmd/natsdumper/natsdumper.go b/cmd/natsdumper/natsdumper.go index c8ec605..3ffc408 100644 --- a/cmd/natsdumper/natsdumper.go +++ b/cmd/natsdumper/natsdumper.go @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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)) } } } @@ -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 @@ -152,5 +201,9 @@ func main() { subscribeGoldPricesIngest(nc) case lib.NatsGoldPricesDeduped: subscribeGoldPricesDeduped(nc) + case lib.NatsMapDataIngest: + subscribeMapDataIngest(nc) + case lib.NatsMapDataDeduped: + subscribeMapDataDeduped(nc) } } diff --git a/lib/map.go b/lib/map.go new file mode 100644 index 0000000..c90db9b --- /dev/null +++ b/lib/map.go @@ -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"` +} diff --git a/lib/market.go b/lib/market.go index a705d60..9102fce 100644 --- a/lib/market.go +++ b/lib/market.go @@ -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"` diff --git a/lib/nats.go b/lib/nats.go index 1f012bf..03ff56c 100644 --- a/lib/nats.go +++ b/lib/nats.go @@ -5,4 +5,6 @@ const ( NatsGoldPricesDeduped = "goldprices.deduped" NatsMarketOrdersIngest = "marketorders.ingest" NatsMarketOrdersDeduped = "marketorders.deduped" + NatsMapDataIngest = "mapdata.ingest" + NatsMapDataDeduped = "mapdata.deduped" )