diff --git a/utils/nats/helloworld/helloworld.go b/utils/nats/helloworld/helloworld.go index 977f330b2..c28b78058 100644 --- a/utils/nats/helloworld/helloworld.go +++ b/utils/nats/helloworld/helloworld.go @@ -28,14 +28,14 @@ func main() { //send a channel message to broadcast channel go testBroadcastMessage(nc, "Hello, World!") - time.Sleep(20 * time.Second) - fmt.Println("Exited after 20 seconds") + time.Sleep(100 * time.Second) + fmt.Println("Exited after 100 seconds") } // asyncChannelMessageSubscriber is an example of how to subscribe // and invoke a function when a message is received func asyncChannelMessageSubscriber(nc *nats.Conn) { - nc.Subscribe("world.channel_message", func(m *nats.Msg) { + nc.Subscribe("world.channel_message.out", func(m *nats.Msg) { message := &eqproto.ChannelMessage{} proto.Unmarshal(m.Data, message) log.Println(message) @@ -66,7 +66,7 @@ func testBroadcastMessage(nc *nats.Conn, msg string) { message := &eqproto.ChannelMessage{ From: "go", Message: msg, - ChanNum: 5, //5 is ooc, 6 is bc + Number: 5, //5 is ooc, 6 is bc } d, err := proto.Marshal(message) if err != nil { diff --git a/utils/nats/playersay/playersay.go b/utils/nats/playersay/playersay.go index 4040fea14..c03890fa6 100644 --- a/utils/nats/playersay/playersay.go +++ b/utils/nats/playersay/playersay.go @@ -30,6 +30,7 @@ func main() { entities = zoneEntityList(zone, 0) fmt.Println(len(entities), "entities known") + //fmt.Println(entities) var entityID int32 for _, entity := range entities { @@ -42,7 +43,7 @@ func main() { if entityID == 0 { log.Fatal("Can't find entity!") } - + go asyncChannelMessageSubscriber(nc) //async is recommended go entityEventSubscriber(zone, instance, entityID) zoneChannel(zone, instance, entityID, eqproto.EntityType_Client, eqproto.MessageType_Say, "Hello, World!") time.Sleep(1000 * time.Second) @@ -116,6 +117,12 @@ func zoneEntityList(zone string, instanceID int) (entities []*eqproto.Entity) { return } + if msg.Result != "1" { + fmt.Println("Failed response: ", msg.Result) + return + } + + //fmt.Println("reply", len(msg.Payload), string(msg.Payload)) rootEntities := &eqproto.Entities{} err = proto.Unmarshal([]byte(msg.Payload), rootEntities) if err != nil { @@ -198,6 +205,7 @@ func entityEventSubscriber(zone string, instance int64, entityID int32) { }*/ var index int + channel := fmt.Sprintf("zone.%s.%d.entity.%d.event.out", zone, instance, entityID) nc.Subscribe(channel, func(m *nats.Msg) { event := &eqproto.Event{} @@ -226,6 +234,8 @@ func entityEventSubscriber(zone string, instance int64, entityID int32) { eventPayload = &eqproto.DamageEvent{} case eqproto.OpCode_OP_SpecialMesg: eventPayload = &eqproto.SpecialMessageEvent{} + case eqproto.OpCode_OP_ChannelMessage: + eventPayload = &eqproto.ChannelMessageEvent{} default: return } @@ -244,3 +254,19 @@ func entityEventSubscriber(zone string, instance int64, entityID int32) { time.Sleep(500 * time.Second) } + +// asyncChannelMessageSubscriber is an example of how to subscribe +// and invoke a function when a message is received +func asyncChannelMessageSubscriber(nc *nats.Conn) { + nc.Subscribe("world.channel_message.out", func(m *nats.Msg) { + message := &eqproto.ChannelMessage{} + proto.Unmarshal(m.Data, message) + log.Println(message) + }) + nc.Subscribe("zone.ecommons.0.channel_message.out", func(m *nats.Msg) { + message := &eqproto.ChannelMessage{} + proto.Unmarshal(m.Data, message) + log.Println(message) + }) + log.Println("Waiting on async messages...") +} diff --git a/zone/nats_manager.cpp b/zone/nats_manager.cpp index b25a6af76..da84cd49d 100644 --- a/zone/nats_manager.cpp +++ b/zone/nats_manager.cpp @@ -168,7 +168,7 @@ void NatsManager::SendChannelMessage(eqproto::ChannelMessage* message, const cha if (s != NATS_OK) { - Log(Logs::General, Logs::NATS, "world.channel_message.out failed: %s", nats_GetLastError(&s)); + Log(Logs::General, Logs::NATS, StringFormat("zone.%s.%d.channel_message.out failed: %s", subscribedZoneName.c_str(), subscribedZoneInstance).c_str(), nats_GetLastError(&s)); return; }