Cleaned up zone/nats_manager logic

This commit is contained in:
Xackery 2018-03-12 20:44:13 -07:00
parent 40ef387496
commit ac07e7d578
4 changed files with 523 additions and 174 deletions

View File

@ -0,0 +1,253 @@
package main
import (
"fmt"
"log"
"strconv"
"strings"
"time"
"github.com/eqemu/server/protobuf/go/eqproto"
"github.com/golang/protobuf/proto"
"github.com/nats-io/go-nats"
)
var (
nc *nats.Conn
err error
entities []*eqproto.Entity
)
func main() {
if nc, err = nats.Connect(nats.DefaultURL); err != nil {
log.Fatal(err)
}
defer nc.Close()
zone := "ecommons"
instance := 0
entityID := int64(288)
entities = zoneEntityList(zone, 0)
fmt.Println(len(entities), "entities known")
var attackEntityID int64
for _, entity := range entities {
if entity.Name == "Guard_Reskin000" {
fmt.Println("Found guard reskin as ID", entity.Id)
attackEntityID = int64(entity.Id)
break
}
}
if attackEntityID == 0 {
log.Fatal("Can't find guard to attack!")
}
entityID = zoneCommandEntity(zone, "spawn", []string{
"146.17",
"-112.51",
"-52.01",
"109.6",
"GoSpawn",
})
if entityID == 0 {
log.Fatal("failed to get entity ID!")
}
go testMoveToLoop(zone, entityID)
go testAttack(zone, entityID, attackEntityID)
go entityEventSubscriber(zone, instance, entityID)
time.Sleep(1000 * time.Second)
}
//testMoveToLoop causes an npc to go in a circle in pojustice
func testMoveToLoop(zone string, entityID int64) {
params := []string{}
positions := []string{
"156.72 -136.71 -52.02 112.8",
"116.18 -101.56 -51.56 228.8",
"151.37 -102.54 -52.01 228.8",
}
command := "moveto"
curPos := 0
for {
curPos++
fmt.Println("Moving to position", curPos)
if len(positions) < curPos+1 {
fmt.Println("Resetting position")
curPos = 0
}
params = []string{}
params = append(params, fmt.Sprintf("%d", entityID))
params = append(params, strings.Split(positions[curPos], " ")...)
zoneCommand(zone, command, params)
time.Sleep(5 * time.Second)
}
}
func testAttack(zone string, entityID int64, targetID int64) {
time.Sleep(10 * time.Second)
fmt.Println("10 seconds, Having", entityID, "attack", targetID)
params := []string{
fmt.Sprintf("%d", entityID),
fmt.Sprintf("%d", targetID), //attack first element
"1", //amount of hate
}
command := "attack"
zoneCommand(zone, command, params)
}
func zoneEntityList(zone string, instanceID int) (entities []*eqproto.Entity) {
msg := &eqproto.CommandMessage{
Author: "xackery",
Command: "entitylist",
Params: []string{"npc"},
}
d, err := proto.Marshal(msg)
if err != nil {
log.Fatal(err)
}
channel := fmt.Sprintf("zone.%s.command_message.in", zone)
reply, err := nc.Request(channel, d, 1*time.Second)
if err != nil {
log.Println("Failed to get response on", channel, "", err.Error())
return
}
err = proto.Unmarshal(reply.Data, msg)
if err != nil {
fmt.Println("Failed to unmarshal", err.Error())
return
}
rootEntities := &eqproto.Entities{}
err = proto.Unmarshal([]byte(msg.Payload), rootEntities)
if err != nil {
fmt.Println("failed to unmarshal entities", err.Error(), msg)
return
}
entities = rootEntities.Entities
return
}
func zoneCommandEntity(zone string, command string, params []string) (entityID int64) {
msg := &eqproto.CommandMessage{
Author: "xackery",
Command: command,
Params: params,
}
d, err := proto.Marshal(msg)
if err != nil {
log.Fatal(err)
}
reply, err := nc.Request(fmt.Sprintf("zone.%s.command_message.in", zone), d, 1*time.Second)
if err != nil {
log.Println("Failed to get request response:", err.Error())
return
}
err = proto.Unmarshal(reply.Data, msg)
if err != nil {
fmt.Println("Failed to unmarshal", err.Error())
return
}
fmt.Println("Response:", msg)
entityID, err = strconv.ParseInt(msg.Result, 10, 64)
if err != nil {
fmt.Println("Failed to parse response", err.Error(), msg.Result)
return
}
return
}
func zoneCommand(zone string, command string, params []string) {
msg := &eqproto.CommandMessage{
Author: "xackery",
Command: command,
Params: params,
}
d, err := proto.Marshal(msg)
if err != nil {
log.Fatal(err)
}
reply, err := nc.Request(fmt.Sprintf("zone.%s.command_message.in", zone), d, 1*time.Second)
if err != nil {
log.Println("Failed to get request response:", err.Error())
return
}
err = proto.Unmarshal(reply.Data, msg)
if err != nil {
fmt.Println("Failed to unmarshal", err.Error())
return
}
fmt.Println("Response:", msg)
return
}
func entityEventSubscriber(zone string, instance int, entityID int64) {
/*event := &eqproto.EntityEvent{
Entity: &eqproto.Entity{
Id: 1,
},
}
d, err := proto.Marshal(event)
if err != nil {
log.Fatal(err)
}
if err = nc.Publish(fmt.Sprintf("zone.%s.entity.event_subscribe.all", zone), d); err != nil {
log.Println("Failed to publish event subscribe:", err.Error())
return
}*/
var opCode int64
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{}
err = proto.Unmarshal(m.Data, event)
if err != nil {
fmt.Println("invalid event data passed", m.Data)
}
var eventPayload proto.Message
switch event.Op {
case eqproto.OpCode_OP_ClientUpdate:
eventPayload = &eqproto.PlayerPositionUpdateEvent{}
case eqproto.OpCode_OP_Animation:
eventPayload = &eqproto.AnimationEvent{}
case eqproto.OpCode_OP_NewSpawn:
eventPayload = &eqproto.SpawnEvent{}
case eqproto.OpCode_OP_ZoneEntry:
eventPayload = &eqproto.SpawnEvent{}
case eqproto.OpCode_OP_HPUpdate:
eventPayload = &eqproto.HPEvent{}
case eqproto.OpCode_OP_MobHealth:
eventPayload = &eqproto.HPEvent{}
case eqproto.OpCode_OP_DeleteSpawn:
eventPayload = &eqproto.DeleteSpawnEvent{}
case eqproto.OpCode_OP_Damage:
eventPayload = &eqproto.DamageEvent{}
default:
return
}
err = proto.Unmarshal(event.Payload, eventPayload)
if err != nil {
fmt.Println("Invalid data passed for opcode", eqproto.OpCode(opCode), err.Error(), string(m.Data[index+1:]))
return
}
fmt.Println(m.Subject, event.Op, eventPayload)
//log.Printf("Received a message on %s: %s\n", m.Subject, string(m.Data))
//proto.Unmarshal(m.Data, event)
//log.Println(event.Op.String(), event.Entity, event.Target)
})
log.Println("Subscribed to", channel, ", waiting on messages...")
time.Sleep(500 * time.Second)
}

View File

@ -167,20 +167,20 @@ void NatsManager::SendAdminMessage(std::string adminMessage, const char* reply)
message->set_message(adminMessage.c_str());
std::string pubMessage;
if (!message->SerializeToString(&pubMessage)) {
Log(Logs::General, Logs::NATS, "global.admin_message->out: failed to serialize message to string");
Log(Logs::General, Logs::NATS, "global.admin_message.out: failed to serialize message to string");
return;
}
if (reply && strlen(reply) > 0)
s = natsConnection_Publish(conn, reply, (const void*)pubMessage.c_str(), pubMessage.length());
else
s = natsConnection_Publish(conn, "global.admin_message->out", (const void*)pubMessage.c_str(), pubMessage.length());
s = natsConnection_Publish(conn, "global.admin_message.out", (const void*)pubMessage.c_str(), pubMessage.length());
if (s != NATS_OK) {
Log(Logs::General, Logs::NATS, "global.admin_message->out failed: %s", nats_GetLastError(&s));
Log(Logs::General, Logs::NATS, "global.admin_message.out failed: %s", nats_GetLastError(&s));
return;
}
Log(Logs::General, Logs::NATS, "global.admin_message->out: %s", adminMessage.c_str());
Log(Logs::General, Logs::NATS, "global.admin_message.out: %s", adminMessage.c_str());
}
// SendChannelMessage will send a channel message to NATS
@ -190,20 +190,20 @@ void NatsManager::SendChannelMessage(eqproto::ChannelMessage* message, const cha
std::string pubMessage;
if (!message->SerializeToString(&pubMessage)) {
Log(Logs::General, Logs::NATS, "world.channel_message->out: failed to serialize message to string");
Log(Logs::General, Logs::NATS, "world.channel_message.out: failed to serialize message to string");
return;
}
if (reply && strlen(reply) > 0)
s = natsConnection_Publish(conn, reply, (const void*)pubMessage.c_str(), pubMessage.length());
else
s = natsConnection_Publish(conn, "world.channel_message->out", (const void*)pubMessage.c_str(), pubMessage.length());
s = natsConnection_Publish(conn, "world.channel_message.out", (const void*)pubMessage.c_str(), pubMessage.length());
if (s != NATS_OK) {
Log(Logs::General, Logs::NATS, "world.channel_message->out failed: %s");
Log(Logs::General, Logs::NATS, "world.channel_message.out failed: %s");
return;
}
Log(Logs::General, Logs::NATS, "world.channel_message->out: %s", message->message().c_str());
Log(Logs::General, Logs::NATS, "world.channel_message.out: %s", message->message().c_str());
}
// SendCommandMessage will send a channel message to NATS
@ -217,20 +217,21 @@ void NatsManager::SendCommandMessage(eqproto::CommandMessage* message, const cha
std::string pubMessage;
if (!message->SerializeToString(&pubMessage)) {
Log(Logs::General, Logs::NATS, "world.command_message->out: failed to serialize message to string");
Log(Logs::General, Logs::NATS, "world.command_message.out: failed to serialize message to string");
return;
}
if (reply && strlen(reply) > 0)
s = natsConnection_Publish(conn, reply, (const void*)pubMessage.c_str(), pubMessage.length());
else
s = natsConnection_Publish(conn, "world.command_message->out", (const void*)pubMessage.c_str(), pubMessage.length());
s = natsConnection_Publish(conn, "world.command_message.out", (const void*)pubMessage.c_str(), pubMessage.length());
if (s != NATS_OK) {
Log(Logs::General, Logs::NATS, "world.command_message->out failed: %s");
Log(Logs::General, Logs::NATS, "world.command_message.out failed: %s");
return;
}
Log(Logs::General, Logs::NATS, "world.command_message->out: %s", message->command().c_str());
Log(Logs::General, Logs::NATS, "world.command_message.in: %s (%s)", message->command().c_str(), message->result().c_str());
}
// GetCommandMessage is used to process a command message
@ -240,8 +241,6 @@ void NatsManager::GetCommandMessage(eqproto::CommandMessage* message, const char
std::string pubMessage;
Log(Logs::General, Logs::NATS, "world.command_message->in: %s", message->command().c_str());
if (message->command().compare("who") == 0) {
message->set_result(client_list.GetWhoAll());
SendCommandMessage(message, reply);

View File

@ -51,19 +51,21 @@ void NatsManager::Process()
for (int count = 0; (s == NATS_OK) && count < 5; count++)
{
s = natsSubscription_NextMsg(&msg, zoneCommandMessageSub, 1);
if (s != NATS_OK)
break;
if (s != NATS_OK) {
s = natsSubscription_NextMsg(&msg, zoneInstanceCommandMessageSub, 1);
if (s != NATS_OK) {
break;
}
}
eqproto::CommandMessage* message = google::protobuf::Arena::CreateMessage<eqproto::CommandMessage>(&the_arena);
if (!message->ParseFromString(natsMsg_GetData(msg))) {
Log(Logs::General, Logs::NATS, "zone.%s.%d.command_message->in: failed to parse");
Log(Logs::General, Logs::NATS, "zone.%s.%d.command_message.in: failed to parse", subscribedZoneName.c_str(), subscribedZoneInstance);
natsMsg_Destroy(msg);
continue;
}
Log(Logs::General, Logs::NATS, "zone.%s.%d.command_message->in: %s", message->command().c_str());
if (message->command().compare("npctypespawn") == 0) {
if (message->params_size() < 2) {
message->set_result("Usage: !npctypespawn <npctypeid> <factionid> <x> <y> <z> <h>.");
@ -94,9 +96,9 @@ void NatsManager::Process()
}
}
if (message->command().compare("spawn") == 0) {
if (message->command().compare("npctypespawn") == 0) {
if (message->params_size() < 5) {
message->set_result("Usage: npctypespawn <x> <y> <z> <h> name race level material hp gender class priweapon secweapon merchantid bodytype.");
message->set_result("Usage: npctypespawn <x> <y> <z> <h> name race level material hp gender class priweapon secweapon merchantid bodytype.");
}
else {
@ -165,7 +167,7 @@ void NatsManager::Process()
else {
npc->AddToHateList(mob, hateAmount);
message->set_result("OK");
}
}
}
}
}
@ -191,6 +193,7 @@ void NatsManager::Process()
message->set_result("Failed to serialized entitiy result");
}
else {
message->set_result("OK");
message->set_payload(entityPayload.c_str());
}
}
@ -213,32 +216,30 @@ void NatsManager::Process()
}*/
else {
message->set_result("Usage: entitylist <typeid>.");
}
}
}
}
if (message->result().length() < 1) {
message->set_result("Failed to parse command.");
Log(Logs::General, Logs::NATS, "zone.%s.%d.command_message->out: failed to parse command", subscribedZoneName.c_str(), subscribedZoneInstance);
Log(Logs::General, Logs::NATS, "zone.%s.%d.command_message.in: failed to parse command", subscribedZoneName.c_str(), subscribedZoneInstance);
natsMsg_Destroy(msg);
continue;
}
if (!message->SerializeToString(&pubMessage)) {
Log(Logs::General, Logs::NATS, "zone.%s.%d.command_message->out: failed to serialize to string", subscribedZoneName.c_str(), subscribedZoneInstance);
Log(Logs::General, Logs::NATS, "zone.%s.%d.command_message.in: failed to serialize to string", subscribedZoneName.c_str(), subscribedZoneInstance);
natsMsg_Destroy(msg);
continue;
}
s = natsConnection_Publish(conn, natsMsg_GetReply(msg), (const void*)pubMessage.c_str(), pubMessage.length());
if (s != NATS_OK) {
Log(Logs::General, Logs::NATS, "zone.%s.%d.command_message->out: failed to publish: %s", subscribedZoneName.c_str(), subscribedZoneInstance, nats_GetLastError(&s));
Log(Logs::General, Logs::NATS, "zone.%s.%d.command_message.in: failed to publish: %s", subscribedZoneName.c_str(), subscribedZoneInstance, nats_GetLastError(&s));
natsMsg_Destroy(msg);
continue;
}
Log(Logs::General, Logs::NATS, "zone.%s.%d.command_message->out: success", subscribedZoneName.c_str(), subscribedZoneInstance);
Log(Logs::General, Logs::NATS, "zone.%s.%d.command_message.in: %s (%s)", subscribedZoneName.c_str(), subscribedZoneInstance, message->command().c_str(), message->result().c_str());
}
}
@ -254,33 +255,33 @@ void NatsManager::Unregister()
if (zoneCommandMessageSub != NULL) {
s = natsSubscription_Unsubscribe(zoneCommandMessageSub);
zoneCommandMessageSub = NULL;
if (s != NATS_OK) Log(Logs::General, Logs::NATS, "unsubscribe from zoneCommandMessageSub failed: %s", nats_GetLastError(&s));
if (s != NATS_OK)
Log(Logs::General, Logs::NATS, "unsubscribe from zoneCommandMessageSub failed: %s", nats_GetLastError(&s));
}
if (zoneEntityEventSubscribeAllSub != NULL) {
s = natsSubscription_Unsubscribe(zoneEntityEventSubscribeAllSub);
zoneEntityEventSubscribeAllSub = NULL;
if (s != NATS_OK) Log(Logs::General, Logs::NATS, "unsubscribe from zoneEntityEventSubscribeAllSub failed: %s", nats_GetLastError(&s));
}
if (zoneEntityEventSubscribeSub != NULL) {
s = natsSubscription_Unsubscribe(zoneEntityEventSubscribeSub);
zoneEntityEventSubscribeSub = NULL;
if (s != NATS_OK) Log(Logs::General, Logs::NATS, "unsubscribe from zoneEntityEventSubscribeSub failed: %s", nats_GetLastError(&s));
if (zoneInstanceCommandMessageSub != NULL) {
s = natsSubscription_Unsubscribe(zoneInstanceCommandMessageSub);
zoneInstanceCommandMessageSub = NULL;
if (s != NATS_OK)
Log(Logs::General, Logs::NATS, "unsubscribe from zoneCommandMessageSub failed: %s", nats_GetLastError(&s));
}
if (zoneEntityEventListSub != NULL) {
s = natsSubscription_Unsubscribe(zoneEntityEventListSub);
zoneEntityEventListSub = NULL;
if (s != NATS_OK) Log(Logs::General, Logs::NATS, "unsubscribe from zoneEntityEventListSub failed: %s", nats_GetLastError(&s));
if (zoneChannelMessageSub != NULL) {
s = natsSubscription_Unsubscribe(zoneChannelMessageSub);
zoneChannelMessageSub = NULL;
if (s != NATS_OK)
Log(Logs::General, Logs::NATS, "unsubscribe from zoneCommandMessageSub failed: %s", nats_GetLastError(&s));
}
if (zoneEntityEventSub != NULL) {
s = natsSubscription_Unsubscribe(zoneEntityEventSub);
zoneEntityEventSub = NULL;
if (s != NATS_OK) Log(Logs::General, Logs::NATS, "unsubscribe from zoneEntityEventSub failed: %s", nats_GetLastError(&s));
if (zoneInstanceChannelMessageSub != NULL) {
s = natsSubscription_Unsubscribe(zoneInstanceChannelMessageSub);
zoneInstanceChannelMessageSub = NULL;
if (s != NATS_OK)
Log(Logs::General, Logs::NATS, "unsubscribe from zoneCommandMessageSub failed: %s", nats_GetLastError(&s));
}
Log(Logs::General, Logs::NATS, "unsubscribed from %s (%d)", subscribedZoneName.c_str(), subscribedZoneInstance);
SendAdminMessage(StringFormat("%s (%d) unregistered", subscribedZoneName.c_str(), subscribedZoneInstance).c_str());
subscribedZoneName.clear();
return;
}
@ -298,57 +299,41 @@ void NatsManager::ZoneSubscribe(const char* zonename, uint32 instance) {
subscribedZoneInstance = instance;
if (subscribedZoneInstance == 0) {
s = natsConnection_SubscribeSync(&zoneChannelMessageSub, conn, StringFormat("zone.%s.channel_message->in", subscribedZoneName.c_str()).c_str());
s = natsConnection_SubscribeSync(&zoneChannelMessageSub, conn, StringFormat("zone.%s.channel_message.in", subscribedZoneName.c_str()).c_str());
if (s != NATS_OK)
Log(Logs::General, Logs::NATS, "zone.%s.channel_message->in: failed to subscribe: %s", subscribedZoneName.c_str(), nats_GetLastError(&s));
Log(Logs::General, Logs::NATS, "zone.%s.channel_message.in: failed to subscribe: %s", subscribedZoneName.c_str(), nats_GetLastError(&s));
s = natsSubscription_SetPendingLimits(zoneChannelMessageSub, -1, -1);
if (s != NATS_OK)
Log(Logs::General, Logs::NATS, "zone.%s.channel_message->in: failed to set pending limits: %s", subscribedZoneName.c_str(), nats_GetLastError(&s));
Log(Logs::General, Logs::NATS, "zone.%s.channel_message.in: failed to set pending limits: %s", subscribedZoneName.c_str(), nats_GetLastError(&s));
s = natsConnection_SubscribeSync(&zoneCommandMessageSub, conn, StringFormat("zone.%s.command_message->in", subscribedZoneName.c_str()).c_str());
s = natsConnection_SubscribeSync(&zoneCommandMessageSub, conn, StringFormat("zone.%s.command_message.in", subscribedZoneName.c_str()).c_str());
if (s != NATS_OK)
Log(Logs::General, Logs::NATS, "zone.%s.command_message->in: failed to subscribe: %s", subscribedZoneName.c_str(), nats_GetLastError(&s));
Log(Logs::General, Logs::NATS, "zone.%s.command_message.in: failed to subscribe: %s", subscribedZoneName.c_str(), nats_GetLastError(&s));
s = natsSubscription_SetPendingLimits(zoneCommandMessageSub, -1, -1);
if (s != NATS_OK)
Log(Logs::General, Logs::NATS, "zone.%s.channel_message->in: failed to set pending limits: %s", subscribedZoneName.c_str(), nats_GetLastError(&s));
s = natsConnection_SubscribeSync(&zoneEntityEventSubscribeAllSub, conn, StringFormat("zone.%s.entity.event_subscribe.all", subscribedZoneName.c_str(), subscribedZoneInstance).c_str());
if (s != NATS_OK)
Log(Logs::General, Logs::NATS, "zone.%s.command_message->in: failed to subscribe: %s", subscribedZoneName.c_str(), nats_GetLastError(&s));
s = natsSubscription_SetPendingLimits(zoneEntityEventSubscribeAllSub, -1, -1);
if (s != NATS_OK)
Log(Logs::General, Logs::NATS, "zone.%s.channel_message->in: failed to set pending limits: %s", subscribedZoneName.c_str(), nats_GetLastError(&s));
Log(Logs::General, Logs::NATS, "zone.%s.channel_message.in: failed to set pending limits: %s", subscribedZoneName.c_str(), nats_GetLastError(&s));
}
s = natsConnection_SubscribeSync(&zoneChannelMessageSub, conn, StringFormat("zone.%s.%d.channel_message->in", subscribedZoneName.c_str(), subscribedZoneInstance).c_str());
s = natsConnection_SubscribeSync(&zoneInstanceChannelMessageSub, conn, StringFormat("zone.%s.%d.channel_message.in", subscribedZoneName.c_str(), subscribedZoneInstance).c_str());
if (s != NATS_OK)
Log(Logs::General, Logs::NATS, "zone.%s.%d.channel_message->in: failed to subscribe: %s", subscribedZoneName.c_str(), subscribedZoneInstance, nats_GetLastError(&s));
Log(Logs::General, Logs::NATS, "zone.%s.%d.channel_message.in: failed to subscribe: %s", subscribedZoneName.c_str(), subscribedZoneInstance, nats_GetLastError(&s));
s = natsSubscription_SetPendingLimits(zoneChannelMessageSub, -1, -1);
s = natsSubscription_SetPendingLimits(zoneInstanceChannelMessageSub, -1, -1);
if (s != NATS_OK)
Log(Logs::General, Logs::NATS, "zone.%s.%d.channel_message->in: failed to set pending limits: %s", subscribedZoneName.c_str(), subscribedZoneInstance, nats_GetLastError(&s));
Log(Logs::General, Logs::NATS, "zone.%s.%d.channel_message.in: failed to set pending limits: %s", subscribedZoneName.c_str(), subscribedZoneInstance, nats_GetLastError(&s));
s = natsConnection_SubscribeSync(&zoneCommandMessageSub, conn, StringFormat("zone.%s.%d.command_message->in", subscribedZoneName.c_str()).c_str());
s = natsConnection_SubscribeSync(&zoneInstanceCommandMessageSub, conn, StringFormat("zone.%s.%d.command_message.in", subscribedZoneName.c_str()).c_str());
if (s != NATS_OK)
Log(Logs::General, Logs::NATS, "zone.%s.%d.command_message->in: failed to subscribe: %s", subscribedZoneName.c_str(), subscribedZoneInstance, nats_GetLastError(&s));
Log(Logs::General, Logs::NATS, "zone.%s.%d.command_message.in: failed to subscribe: %s", subscribedZoneName.c_str(), subscribedZoneInstance, nats_GetLastError(&s));
s = natsSubscription_SetPendingLimits(zoneCommandMessageSub, -1, -1);
s = natsSubscription_SetPendingLimits(zoneInstanceCommandMessageSub, -1, -1);
if (s != NATS_OK)
Log(Logs::General, Logs::NATS, "zone.%s.%d.channel_message->in: failed to set pending limits: %s", subscribedZoneName.c_str(), subscribedZoneInstance, nats_GetLastError(&s));
s = natsConnection_SubscribeSync(&zoneEntityEventSubscribeAllSub, conn, StringFormat("zone.%s.%d.entity.event_subscribe.all", subscribedZoneName.c_str(), subscribedZoneInstance).c_str());
if (s != NATS_OK)
Log(Logs::General, Logs::NATS, "zone.%s.%d.command_message->in: failed to subscribe: %s", subscribedZoneName.c_str(), subscribedZoneInstance, nats_GetLastError(&s));
s = natsSubscription_SetPendingLimits(zoneEntityEventSubscribeAllSub, -1, -1);
if (s != NATS_OK)
Log(Logs::General, Logs::NATS, "zone.%s.%d.channel_message->in: failed to set pending limits: %s", subscribedZoneName.c_str(), subscribedZoneInstance, nats_GetLastError(&s));
Log(Logs::General, Logs::NATS, "zone.%s.%d.channel_message.in: failed to set pending limits: %s", subscribedZoneName.c_str(), subscribedZoneInstance, nats_GetLastError(&s));
Log(Logs::General, Logs::NATS, "subscribed as %s (%d)", subscribedZoneName.c_str(), subscribedZoneInstance);
SendAdminMessage(StringFormat("%s (%d) registered", subscribedZoneName.c_str(), subscribedZoneInstance).c_str());
}
@ -360,17 +345,17 @@ void NatsManager::SendAdminMessage(std::string adminMessage) {
message->set_message(adminMessage.c_str());
std::string pubMessage;
if (!message->SerializeToString(&pubMessage)) {
Log(Logs::General, Logs::NATS, "global.admin_message->out: failed to serialize message to string");
Log(Logs::General, Logs::NATS, "global.admin_message.out: failed to serialize message to string");
return;
}
s = natsConnection_Publish(conn, "global.admin_message->out", (const void*)pubMessage.c_str(), pubMessage.length());
s = natsConnection_Publish(conn, "global.admin_message.out", (const void*)pubMessage.c_str(), pubMessage.length());
if (s != NATS_OK) {
Log(Logs::General, Logs::NATS, "global.admin_message->out: failed: %s", nats_GetLastError(&s));
Log(Logs::General, Logs::NATS, "global.admin_message.out: failed: %s", nats_GetLastError(&s));
return;
}
Log(Logs::General, Logs::NATS, "global.admin_message->out: %s", adminMessage.c_str());
Log(Logs::General, Logs::NATS, "global.admin_message.out: %s", adminMessage.c_str());
}
@ -505,18 +490,22 @@ void NatsManager::OnEntityEvent(const EmuOpcode op, Entity *ent, Entity *target)
bool NatsManager::isEntitySubscribed(const uint16 ID) {
if (!connect())
return false;
return false;
return true;
}
void NatsManager::OnDeathEvent(Death_Struct* d) {
if (!connect())
return;
if (d == NULL)
return;
if (!isEntityEventAllEnabled && !isEntitySubscribed(d->spawn_id))
return;
auto op = eqproto::OP_Death;
std::string pubMessage;
eqproto::DeathEvent* event = google::protobuf::Arena::CreateMessage<eqproto::DeathEvent>(&the_arena);
@ -527,29 +516,34 @@ void NatsManager::OnDeathEvent(Death_Struct* d) {
event->set_attack_skill_id(d->attack_skill);
event->set_damage(d->damage);
if (!event->SerializeToString(&pubMessage)) {
Log(Logs::General, Logs::NATS, "Failed to serialize message to string");
Log(Logs::General, Logs::NATS, "zone.%s.%d.entity.%d.event.out: (OP: %d) failed to serialize message to string", subscribedZoneName.c_str(), subscribedZoneInstance, d->spawn_id, op);
return;
}
eqproto::Event* finalEvent = google::protobuf::Arena::CreateMessage<eqproto::Event>(&the_arena);
finalEvent->set_payload(pubMessage.c_str());
finalEvent->set_op(eqproto::OP_Death);
finalEvent->set_op(op);
if (!finalEvent->SerializeToString(&pubMessage)) {
Log(Logs::General, Logs::NATS, "Failed to serialize message to string");
Log(Logs::General, Logs::NATS, "zone.%s.%d.entity.%d.event.out: (OP: %d) failed to serialize message to string", subscribedZoneName.c_str(), subscribedZoneInstance, d->spawn_id, op);
return;
}
s = natsConnection_Publish(conn, StringFormat("zone.%s.entity.event->%d", subscribedZoneName.c_str(), d->spawn_id).c_str(), (const void*)pubMessage.c_str(), pubMessage.length());
if (s != NATS_OK) Log(Logs::General, Logs::NATS, "Failed to send EntityEvent");
s = natsConnection_Publish(conn, StringFormat("zone.%s.%d.entity.%d.event.out", subscribedZoneName.c_str(), subscribedZoneInstance, d->spawn_id).c_str(), (const void*)pubMessage.c_str(), pubMessage.length());
if (s != NATS_OK)
Log(Logs::General, Logs::NATS, "zone.%s.%d.entity.%d.event.out: (OP: %d) failed to send: %s", subscribedZoneName.c_str(), subscribedZoneInstance, d->spawn_id, op, nats_GetLastError(&s));
}
void NatsManager::OnChannelMessageEvent(uint32 entity_id, ChannelMessage_Struct* cm) {
if (!connect()) return;
if (entity_id == 0) return;
if (!isEntityEventAllEnabled && !isEntitySubscribed(entity_id)) return;
if (!connect())
return;
if (entity_id == 0)
return;
if (!isEntityEventAllEnabled && !isEntitySubscribed(entity_id))
return;
std::string pubMessage;
eqproto::ChannelMessageEvent* event = google::protobuf::Arena::CreateMessage<eqproto::ChannelMessageEvent>(&the_arena);
@ -562,25 +556,33 @@ void NatsManager::OnChannelMessageEvent(uint32 entity_id, ChannelMessage_Struct*
event->set_skill_in_language(cm->skill_in_language);
event->set_message(cm->message);
if (!event->SerializeToString(&pubMessage)) {
Log(Logs::General, Logs::NATS, "Failed to serialize message to string"); return;
if (!event->SerializeToString(&pubMessage)) {
Log(Logs::General, Logs::NATS, "zone.%s.%d.channel_message.out: failed to serialize message to string", subscribedZoneName.c_str(), subscribedZoneInstance);
return;
}
eqproto::Event* finalEvent = google::protobuf::Arena::CreateMessage<eqproto::Event>(&the_arena);
finalEvent->set_payload(pubMessage.c_str());
finalEvent->set_op(eqproto::OP_ChannelMessage);
if (!finalEvent->SerializeToString(&pubMessage)) {
Log(Logs::General, Logs::NATS, "Failed to serialize message to string"); return;
Log(Logs::General, Logs::NATS, "zone.%s.%d.channel_message.out: failed to serialize message to string", subscribedZoneName.c_str(), subscribedZoneInstance);
return;
}
s = natsConnection_Publish(conn, StringFormat("zone.%s.entity.event->%d", subscribedZoneName.c_str(), entity_id).c_str(), (const void*)pubMessage.c_str(), pubMessage.length());
if (s != NATS_OK) Log(Logs::General, Logs::NATS, "Failed to send EntityEvent");
s = natsConnection_Publish(conn, StringFormat("zone.%s.%d.channel_message.out", subscribedZoneName.c_str(), subscribedZoneInstance).c_str(), (const void*)pubMessage.c_str(), pubMessage.length());
if (s != NATS_OK)
Log(Logs::General, Logs::NATS, "Failed to send EntityEvent");
}
void NatsManager::OnEntityEvent(const EmuOpcode op, uint32 entity_id, uint32 target_id) {
if (!connect()) return;
if (entity_id == 0) return;
if (!connect())
return;
if (!isEntityEventAllEnabled && !isEntitySubscribed(entity_id)) return;
if (entity_id == 0)
return;
if (!isEntityEventAllEnabled && !isEntitySubscribed(entity_id))
return;
std::string pubMessage;
@ -588,10 +590,14 @@ void NatsManager::OnEntityEvent(const EmuOpcode op, uint32 entity_id, uint32 tar
event->set_entity_id(entity_id);
event->set_target_id(target_id);
if (!event->SerializeToString(&pubMessage)) { Log(Logs::General, Logs::NATS, "Failed to serialize message to string"); return; }
if (!event->SerializeToString(&pubMessage)) {
Log(Logs::General, Logs::NATS, "zone.%s.%d.entity.%d.event.out: (OP: %d) failed to serialize message to string", subscribedZoneName.c_str(), subscribedZoneInstance, entity_id, op);
return;
}
eqproto::Event* finalEvent = google::protobuf::Arena::CreateMessage<eqproto::Event>(&the_arena);
finalEvent->set_payload(pubMessage.c_str());
if (op == OP_Camp) {
finalEvent->set_op(eqproto::OP_Camp);
}
@ -603,19 +609,23 @@ void NatsManager::OnEntityEvent(const EmuOpcode op, uint32 entity_id, uint32 tar
return;
}
if (!finalEvent->SerializeToString(&pubMessage)) {
Log(Logs::General, Logs::NATS, "Failed to serialize message to string");
Log(Logs::General, Logs::NATS, "zone.%s.%d.entity.%d.event.out: (OP: %d) failed to serialize message to string", subscribedZoneName.c_str(), subscribedZoneInstance, entity_id, op);
return;
}
s = natsConnection_Publish(conn, StringFormat("zone.%s.entity.event->%d", subscribedZoneName.c_str(), entity_id).c_str(), (const void*)pubMessage.c_str(), pubMessage.length());
if (s != NATS_OK) Log(Logs::General, Logs::NATS, "Failed to send EntityEvent");
s = natsConnection_Publish(conn, StringFormat("zone.%s.%d.entity.%d.event.out", subscribedZoneName.c_str(), subscribedZoneInstance, entity_id).c_str(), (const void*)pubMessage.c_str(), pubMessage.length());
if (s != NATS_OK)
Log(Logs::General, Logs::NATS, "zone.%s.%d.entity.%d.event.out: (OP: %d) failed to send: %s", subscribedZoneName.c_str(), subscribedZoneInstance, entity_id, op, nats_GetLastError(&s));
}
void NatsManager::OnSpawnEvent(const EmuOpcode op, uint32 entity_id, Spawn_Struct *spawn) {
if (!connect())
return;
if (entity_id == 0)
return;
if (!isEntityEventAllEnabled && !isEntitySubscribed(entity_id))
return;
@ -729,24 +739,42 @@ void NatsManager::OnSpawnEvent(const EmuOpcode op, uint32 entity_id, Spawn_Struc
event->set_targetable_with_hotkey(spawn->targetable_with_hotkey);
event->set_show_name(spawn->show_name);
if (!event->SerializeToString(&pubMessage)) { Log(Logs::General, Logs::NATS, "Failed to serialize message to string"); return; }
if (!event->SerializeToString(&pubMessage)) {
Log(Logs::General, Logs::NATS, "zone.%s.%d.entity.%d.event.out: (OP: %d) failed to serialize message to string", subscribedZoneName.c_str(), subscribedZoneInstance, entity_id, op);
return;
}
eqproto::Event* finalEvent = google::protobuf::Arena::CreateMessage<eqproto::Event>(&the_arena);
finalEvent->set_payload(pubMessage.c_str());
if (op == OP_ZoneEntry) finalEvent->set_op(eqproto::OP_ZoneEntry);
else if (op == OP_NewSpawn) finalEvent->set_op(eqproto::OP_NewSpawn);
else { Log(Logs::General, Logs::NATS, "unhandled op type passed: %i", op); return; }
if (!finalEvent->SerializeToString(&pubMessage)) { Log(Logs::General, Logs::NATS, "Failed to serialize message to string"); return; }
s = natsConnection_Publish(conn, StringFormat("zone.%s.entity.event->%d", subscribedZoneName.c_str(), entity_id).c_str(), (const void*)pubMessage.c_str(), pubMessage.length());
if (s != NATS_OK) Log(Logs::General, Logs::NATS, "Failed to send EntityEvent");
if (op == OP_ZoneEntry)
finalEvent->set_op(eqproto::OP_ZoneEntry);
else if (op == OP_NewSpawn)
finalEvent->set_op(eqproto::OP_NewSpawn);
else {
Log(Logs::General, Logs::NATS, "zone.%s.%d.entity.%d.event.out: (OP: %d) unhandled opcode passed", subscribedZoneName.c_str(), subscribedZoneInstance, entity_id, op);
return;
}
if (!finalEvent->SerializeToString(&pubMessage)) {
Log(Logs::General, Logs::NATS, "zone.%s.%d.entity.%d.event.out: (OP: %d) failed to serialize message to string", subscribedZoneName.c_str(), subscribedZoneInstance, entity_id, op);
return;
}
s = natsConnection_Publish(conn, StringFormat("zone.%s.%d.entity.%d.event.out", subscribedZoneName.c_str(), subscribedZoneInstance, entity_id).c_str(), (const void*)pubMessage.c_str(), pubMessage.length());
if (s != NATS_OK)
Log(Logs::General, Logs::NATS, "zone.%s.%d.entity.%d.event.out: (OP: %d) failed to send: %s", subscribedZoneName.c_str(), subscribedZoneInstance, entity_id, op, nats_GetLastError(&s));
}
void NatsManager::OnWearChangeEvent(uint32 entity_id, WearChange_Struct *wc) {
if (!connect()) return;
if (entity_id == 0) return;
if (!isEntityEventAllEnabled && !isEntitySubscribed(entity_id)) return;
if (!connect())
return;
if (entity_id == 0)
return;
if (!isEntityEventAllEnabled && !isEntitySubscribed(entity_id))
return;
auto op = eqproto::OP_WearChange;
std::string pubMessage;
eqproto::WearChangeEvent* event = google::protobuf::Arena::CreateMessage<eqproto::WearChangeEvent>(&the_arena);
event->set_spawn_id(wc->spawn_id);
@ -758,41 +786,66 @@ void NatsManager::OnWearChangeEvent(uint32 entity_id, WearChange_Struct *wc) {
//event->set_color(wc->color); //tint
event->set_wear_slot_id(wc->wear_slot_id);
if (!event->SerializeToString(&pubMessage)) { Log(Logs::General, Logs::NATS, "Failed to serialize message to string"); return; }
if (!event->SerializeToString(&pubMessage)) {
Log(Logs::General, Logs::NATS, "zone.%s.%d.entity.%d.event.out: (OP: %d) failed to serialize message to string", subscribedZoneName.c_str(), subscribedZoneInstance, entity_id, op);
return;
}
eqproto::Event* finalEvent = google::protobuf::Arena::CreateMessage<eqproto::Event>(&the_arena);
finalEvent->set_payload(pubMessage.c_str());
finalEvent->set_op(eqproto::OP_WearChange);
if (!finalEvent->SerializeToString(&pubMessage)) { Log(Logs::General, Logs::NATS, "Failed to serialize message to string"); return; }
s = natsConnection_Publish(conn, StringFormat("zone.%s.entity.event->%d", subscribedZoneName.c_str(), entity_id).c_str(), (const void*)pubMessage.c_str(), pubMessage.length());
if (s != NATS_OK) Log(Logs::General, Logs::NATS, "Failed to send EntityEvent");
finalEvent->set_op(op);
if (!finalEvent->SerializeToString(&pubMessage)) {
Log(Logs::General, Logs::NATS, "zone.%s.%d.entity.%d.event.out: (OP: %d) failed to serialize message to string", subscribedZoneName.c_str(), subscribedZoneInstance, entity_id, op);
return;
}
s = natsConnection_Publish(conn, StringFormat("zone.%s.%d.entity.%d.event.out", subscribedZoneName.c_str(), subscribedZoneInstance, entity_id).c_str(), (const void*)pubMessage.c_str(), pubMessage.length());
if (s != NATS_OK)
Log(Logs::General, Logs::NATS, "zone.%s.%d.entity.%d.event.out: (OP: %d) failed to send: %s", subscribedZoneName.c_str(), subscribedZoneInstance, entity_id, op, nats_GetLastError(&s));
}
void NatsManager::OnDeleteSpawnEvent(uint32 entity_id, DeleteSpawn_Struct *ds) {
if (!connect()) return;
if (entity_id == 0) return;
if (!isEntityEventAllEnabled && !isEntitySubscribed(entity_id)) return;
if (!connect())
return;
if (entity_id == 0)
return;
if (!isEntityEventAllEnabled && !isEntitySubscribed(entity_id))
return;
std::string pubMessage;
auto op = eqproto::OP_DeleteSpawn;
eqproto::DeleteSpawnEvent* event = google::protobuf::Arena::CreateMessage<eqproto::DeleteSpawnEvent>(&the_arena);
event->set_spawn_id(ds->spawn_id);
event->set_decay(ds->Decay);
if (!event->SerializeToString(&pubMessage)) { Log(Logs::General, Logs::NATS, "Failed to serialize message to string"); return; }
if (!event->SerializeToString(&pubMessage)) {
Log(Logs::General, Logs::NATS, "zone.%s.%d.entity.%d.event.out: (OP: %d) failed to serialize message to string", subscribedZoneName.c_str(), subscribedZoneInstance, entity_id, op);
return;
}
eqproto::Event* finalEvent = google::protobuf::Arena::CreateMessage<eqproto::Event>(&the_arena);
finalEvent->set_payload(pubMessage.c_str());
finalEvent->set_op(eqproto::OP_DeleteSpawn);
if (!finalEvent->SerializeToString(&pubMessage)) { Log(Logs::General, Logs::NATS, "Failed to serialize message to string"); return; }
s = natsConnection_Publish(conn, StringFormat("zone.%s.entity.event->%d", subscribedZoneName.c_str(), entity_id).c_str(), (const void*)pubMessage.c_str(), pubMessage.length());
if (s != NATS_OK) Log(Logs::General, Logs::NATS, "Failed to send EntityEvent");
finalEvent->set_op(op);
if (!finalEvent->SerializeToString(&pubMessage)) {
Log(Logs::General, Logs::NATS, "zone.%s.%d.entity.%d.event.out: (OP: %d) failed to serialize message to string", subscribedZoneName.c_str(), subscribedZoneInstance, entity_id, op);
return;
}
s = natsConnection_Publish(conn, StringFormat("zone.%s.%d.entity.%d.event.out", subscribedZoneName.c_str(), subscribedZoneInstance, entity_id).c_str(), (const void*)pubMessage.c_str(), pubMessage.length());
if (s != NATS_OK)
Log(Logs::General, Logs::NATS, "zone.%s.%d.entity.%d.event.out: (OP: %d) failed to send: %s", subscribedZoneName.c_str(), subscribedZoneInstance, entity_id, op, nats_GetLastError(&s));
}
void NatsManager::OnHPEvent(const EmuOpcode op, uint32 entity_id, uint32 cur_hp, uint32 max_hp) {
if (!connect()) return;
if (entity_id == 0) return;
if (!isEntityEventAllEnabled && !isEntitySubscribed(entity_id)) return;
if (cur_hp == max_hp) return;
if (!connect())
return;
if (entity_id == 0)
return;
if (!isEntityEventAllEnabled && !isEntitySubscribed(entity_id))
return;
if (cur_hp == max_hp)
return;
std::string pubMessage;
@ -801,23 +854,40 @@ void NatsManager::OnHPEvent(const EmuOpcode op, uint32 entity_id, uint32 cur_hp,
event->set_cur_hp(cur_hp);
event->set_max_hp(max_hp);
if (!event->SerializeToString(&pubMessage)) { Log(Logs::General, Logs::NATS, "Failed to serialize message to string"); return; }
if (!event->SerializeToString(&pubMessage)) {
Log(Logs::General, Logs::NATS, "zone.%s.%d.entity.%d.event.out: (OP: %d) failed to serialize message to string", subscribedZoneName.c_str(), subscribedZoneInstance, entity_id, op);
return;
}
eqproto::Event* finalEvent = google::protobuf::Arena::CreateMessage<eqproto::Event>(&the_arena);
finalEvent->set_payload(pubMessage.c_str());
if (op == OP_MobHealth) finalEvent->set_op(eqproto::OP_MobHealth);
else if (op == OP_HPUpdate) finalEvent->set_op(eqproto::OP_HPUpdate);
else { Log(Logs::General, Logs::NATS, "unhandled op type passed: %i", op); return; }
if (!finalEvent->SerializeToString(&pubMessage)) { Log(Logs::General, Logs::NATS, "Failed to serialize message to string"); return; }
s = natsConnection_Publish(conn, StringFormat("zone.%s.entity.event->%d", subscribedZoneName.c_str(), entity_id).c_str(), (const void*)pubMessage.c_str(), pubMessage.length());
if (s != NATS_OK) Log(Logs::General, Logs::NATS, "Failed to send EntityEvent");
if (op == OP_MobHealth)
finalEvent->set_op(eqproto::OP_MobHealth);
else if (op == OP_HPUpdate)
finalEvent->set_op(eqproto::OP_HPUpdate);
else {
Log(Logs::General, Logs::NATS, "unhandled op type passed: %i", op);
return;
}
if (!finalEvent->SerializeToString(&pubMessage)) {
Log(Logs::General, Logs::NATS, "zone.%s.%d.entity.%d.event.out: (OP: %d) failed to serialize message to string", subscribedZoneName.c_str(), subscribedZoneInstance, entity_id, op);
return;
}
s = natsConnection_Publish(conn, StringFormat("zone.%s.%d.entity.%d.event.out", subscribedZoneName.c_str(), subscribedZoneInstance, entity_id).c_str(), (const void*)pubMessage.c_str(), pubMessage.length());
if (s != NATS_OK)
Log(Logs::General, Logs::NATS, "zone.%s.%d.entity.%d.event.out: (OP: %d) failed to send: %s", subscribedZoneName.c_str(), subscribedZoneInstance, entity_id, op, nats_GetLastError(&s));
}
void NatsManager::OnDamageEvent(uint32 entity_id, CombatDamage_Struct *cd) {
if (!connect()) return;
if (entity_id == 0) return;
if (!isEntityEventAllEnabled && !isEntitySubscribed(entity_id)) return;
std::string pubMessage;
if (!connect())
return;
if (entity_id == 0)
return;
if (!isEntityEventAllEnabled && !isEntitySubscribed(entity_id))
return;
std::string pubMessage;
eqproto::DamageEvent* event = google::protobuf::Arena::CreateMessage<eqproto::DamageEvent>(&the_arena);
event->set_target(cd->target);
@ -828,24 +898,38 @@ void NatsManager::OnDamageEvent(uint32 entity_id, CombatDamage_Struct *cd) {
event->set_force(cd->force);
event->set_meleepush_xy(cd->hit_heading);
event->set_meleepush_z(cd->hit_pitch);
auto op = eqproto::OP_Damage;
if (!event->SerializeToString(&pubMessage)) { Log(Logs::General, Logs::NATS, "Failed to serialize message to string"); return; }
if (!event->SerializeToString(&pubMessage)) {
Log(Logs::General, Logs::NATS, "Failed to serialize message to string");
return;
}
eqproto::Event* finalEvent = google::protobuf::Arena::CreateMessage<eqproto::Event>(&the_arena);
finalEvent->set_payload(pubMessage.c_str());
finalEvent->set_op(eqproto::OP_Damage);
if (!finalEvent->SerializeToString(&pubMessage)) { Log(Logs::General, Logs::NATS, "Failed to serialize message to string"); return; }
s = natsConnection_Publish(conn, StringFormat("zone.%s.entity.event->%d", subscribedZoneName.c_str(), entity_id).c_str(), (const void*)pubMessage.c_str(), pubMessage.length());
if (s != NATS_OK) Log(Logs::General, Logs::NATS, "Failed to send EntityEvent");
finalEvent->set_op(op);
if (!finalEvent->SerializeToString(&pubMessage)) {
Log(Logs::General, Logs::NATS, "zone.%s.%d.entity.%d.event.out: (OP: %d) failed to serialize message to string", subscribedZoneName.c_str(), subscribedZoneInstance, entity_id, op);
return;
}
s = natsConnection_Publish(conn, StringFormat("zone.%s.%d.entity.%d.event.out", subscribedZoneName.c_str(), subscribedZoneInstance, entity_id).c_str(), (const void*)pubMessage.c_str(), pubMessage.length());
if (s != NATS_OK)
Log(Logs::General, Logs::NATS, "zone.%s.%d.entity.%d.event.out: (OP: %d) failed to send: %s", subscribedZoneName.c_str(), subscribedZoneInstance, entity_id, op, nats_GetLastError(&s));
}
void NatsManager::OnClientUpdateEvent(uint32 entity_id, PlayerPositionUpdateServer_Struct * spu) {
if (!connect()) return;
if (entity_id == 0) return;
if (!isEntityEventAllEnabled && !isEntitySubscribed(entity_id)) return;
auto op = eqproto::OP_ClientUpdate;
if (!connect())
return;
if (entity_id == 0)
return;
if (!isEntityEventAllEnabled && !isEntitySubscribed(entity_id))
return;
std::string pubMessage;
eqproto::PlayerPositionUpdateEvent* event = google::protobuf::Arena::CreateMessage<eqproto::PlayerPositionUpdateEvent>(&the_arena);
event->set_spawn_id(spu->spawn_id);
event->set_delta_heading(spu->delta_heading);
@ -861,42 +945,57 @@ void NatsManager::OnClientUpdateEvent(uint32 entity_id, PlayerPositionUpdateServ
event->set_padding0014(spu->padding0014);
event->set_delta_z(spu->delta_z);
event->set_padding0018(spu->padding0018);
if (!event->SerializeToString(&pubMessage)) {
Log(Logs::General, Logs::NATS, "Failed to serialize message to string");
Log(Logs::General, Logs::NATS, "zone.%s.%d.entity.%d.event.out: (OP: %d) failed to serialize message to string", subscribedZoneName.c_str(), subscribedZoneInstance, entity_id, op);
return;
}
eqproto::Event* finalEvent = google::protobuf::Arena::CreateMessage<eqproto::Event>(&the_arena);
finalEvent->set_payload(pubMessage.c_str());
finalEvent->set_op(eqproto::OP_ClientUpdate);
if (!finalEvent->SerializeToString(&pubMessage)) {
Log(Logs::General, Logs::NATS, "Failed to serialize message to string");
return;
finalEvent->set_op(op);
if (!finalEvent->SerializeToString(&pubMessage)) {
Log(Logs::General, Logs::NATS, "zone.%s.%d.entity.%d.event.out: (OP: %d) failed to serialize message to string", subscribedZoneName.c_str(), subscribedZoneInstance, entity_id, op);
return;
}
s = natsConnection_Publish(conn, StringFormat("zone.%s.entity.event->%d", subscribedZoneName.c_str(), entity_id).c_str(), (const void*)pubMessage.c_str(), pubMessage.length());
if (s != NATS_OK) Log(Logs::General, Logs::NATS, "Failed to send EntityEvent");
s = natsConnection_Publish(conn, StringFormat("zone.%s.%d.entity.%d.event.out", subscribedZoneName.c_str(), subscribedZoneInstance, entity_id).c_str(), (const void*)pubMessage.c_str(), pubMessage.length());
if (s != NATS_OK)
Log(Logs::General, Logs::NATS, "zone.%s.%d.entity.%d.event.out: (OP: %d) failed to send: %s", subscribedZoneName.c_str(), subscribedZoneInstance, entity_id, op, nats_GetLastError(&s));
}
void NatsManager::OnAnimationEvent(uint32 entity_id, Animation_Struct *anim) {
if (!connect()) return;
if (entity_id == 0) return;
if (!isEntityEventAllEnabled && !isEntitySubscribed(entity_id)) return;
if (!connect())
return;
if (entity_id == 0)
return;
if (!isEntityEventAllEnabled && !isEntitySubscribed(entity_id))
return;
std::string pubMessage;
auto op = eqproto::OP_Animation;
eqproto::AnimationEvent* event = google::protobuf::Arena::CreateMessage<eqproto::AnimationEvent>(&the_arena);
event->set_spawnid(anim->spawnid);
event->set_speed(anim->speed);
event->set_action(anim->action);
if (!event->SerializeToString(&pubMessage)) { Log(Logs::General, Logs::NATS, "Failed to serialize message to string"); return; }
if (!event->SerializeToString(&pubMessage)) {
Log(Logs::General, Logs::NATS, "zone.%s.%d.entity.%d.event.out: (OP: %d) failed to serialize message to string", subscribedZoneName.c_str(), subscribedZoneInstance, entity_id, op);
return;
}
eqproto::Event* finalEvent = google::protobuf::Arena::CreateMessage<eqproto::Event>(&the_arena);
finalEvent->set_payload(pubMessage.c_str());
finalEvent->set_op(eqproto::OP_Animation);
if (!finalEvent->SerializeToString(&pubMessage)) { Log(Logs::General, Logs::NATS, "Failed to serialize message to string"); return; }
s = natsConnection_Publish(conn, StringFormat("zone.%s.entity.event->%d", subscribedZoneName.c_str(), entity_id).c_str(), (const void*)pubMessage.c_str(), pubMessage.length());
if (s != NATS_OK) Log(Logs::General, Logs::NATS, "Failed to send EntityEvent");
finalEvent->set_op(op);
if (!finalEvent->SerializeToString(&pubMessage)) {
Log(Logs::General, Logs::NATS, "zone.%s.%d.entity.%d.event.out: (OP: %d) failed to serialize message to string", subscribedZoneName.c_str(), subscribedZoneInstance, entity_id, op);
return;
}
s = natsConnection_Publish(conn, StringFormat("zone.%s.%d.entity.%d.event.out", subscribedZoneName.c_str(), subscribedZoneInstance, entity_id).c_str(), (const void*)pubMessage.c_str(), pubMessage.length());
if (s != NATS_OK)
Log(Logs::General, Logs::NATS, "zone.%s.%d.entity.%d.event.out: (OP: %d) failed to send: %s", subscribedZoneName.c_str(), subscribedZoneInstance, entity_id, op, nats_GetLastError(&s));
}

View File

@ -40,11 +40,9 @@ protected:
std::string subscribedZoneName;
uint32 subscribedZoneInstance;
natsSubscription *zoneChannelMessageSub = NULL;
natsSubscription *zoneInstanceChannelMessageSub = NULL;
natsSubscription *zoneCommandMessageSub = NULL;
natsSubscription *zoneEntityEventSubscribeAllSub = NULL;
natsSubscription *zoneEntityEventSubscribeSub = NULL;
natsSubscription *zoneEntityEventListSub = NULL;
natsSubscription *zoneEntityEventSub = NULL;
natsSubscription *zoneInstanceCommandMessageSub = NULL;
};
#endif