mirror of
https://github.com/EQEmu/Server.git
synced 2026-01-06 17:43:52 +00:00
Cleaned up zone/nats_manager logic
This commit is contained in:
parent
40ef387496
commit
ac07e7d578
253
utils/nats/npcwalk/npcwalk.go
Normal file
253
utils/nats/npcwalk/npcwalk.go
Normal 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)
|
||||||
|
}
|
||||||
@ -167,20 +167,20 @@ void NatsManager::SendAdminMessage(std::string adminMessage, const char* reply)
|
|||||||
message->set_message(adminMessage.c_str());
|
message->set_message(adminMessage.c_str());
|
||||||
std::string pubMessage;
|
std::string pubMessage;
|
||||||
if (!message->SerializeToString(&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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (reply && strlen(reply) > 0)
|
if (reply && strlen(reply) > 0)
|
||||||
s = natsConnection_Publish(conn, reply, (const void*)pubMessage.c_str(), pubMessage.length());
|
s = natsConnection_Publish(conn, reply, (const void*)pubMessage.c_str(), pubMessage.length());
|
||||||
else
|
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) {
|
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;
|
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
|
// SendChannelMessage will send a channel message to NATS
|
||||||
@ -190,20 +190,20 @@ void NatsManager::SendChannelMessage(eqproto::ChannelMessage* message, const cha
|
|||||||
|
|
||||||
std::string pubMessage;
|
std::string pubMessage;
|
||||||
if (!message->SerializeToString(&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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (reply && strlen(reply) > 0)
|
if (reply && strlen(reply) > 0)
|
||||||
s = natsConnection_Publish(conn, reply, (const void*)pubMessage.c_str(), pubMessage.length());
|
s = natsConnection_Publish(conn, reply, (const void*)pubMessage.c_str(), pubMessage.length());
|
||||||
else
|
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) {
|
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;
|
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
|
// SendCommandMessage will send a channel message to NATS
|
||||||
@ -217,20 +217,21 @@ void NatsManager::SendCommandMessage(eqproto::CommandMessage* message, const cha
|
|||||||
|
|
||||||
std::string pubMessage;
|
std::string pubMessage;
|
||||||
if (!message->SerializeToString(&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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (reply && strlen(reply) > 0)
|
if (reply && strlen(reply) > 0)
|
||||||
s = natsConnection_Publish(conn, reply, (const void*)pubMessage.c_str(), pubMessage.length());
|
s = natsConnection_Publish(conn, reply, (const void*)pubMessage.c_str(), pubMessage.length());
|
||||||
else
|
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) {
|
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;
|
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
|
// GetCommandMessage is used to process a command message
|
||||||
@ -240,8 +241,6 @@ void NatsManager::GetCommandMessage(eqproto::CommandMessage* message, const char
|
|||||||
|
|
||||||
std::string pubMessage;
|
std::string pubMessage;
|
||||||
|
|
||||||
Log(Logs::General, Logs::NATS, "world.command_message->in: %s", message->command().c_str());
|
|
||||||
|
|
||||||
if (message->command().compare("who") == 0) {
|
if (message->command().compare("who") == 0) {
|
||||||
message->set_result(client_list.GetWhoAll());
|
message->set_result(client_list.GetWhoAll());
|
||||||
SendCommandMessage(message, reply);
|
SendCommandMessage(message, reply);
|
||||||
|
|||||||
@ -51,19 +51,21 @@ void NatsManager::Process()
|
|||||||
for (int count = 0; (s == NATS_OK) && count < 5; count++)
|
for (int count = 0; (s == NATS_OK) && count < 5; count++)
|
||||||
{
|
{
|
||||||
s = natsSubscription_NextMsg(&msg, zoneCommandMessageSub, 1);
|
s = natsSubscription_NextMsg(&msg, zoneCommandMessageSub, 1);
|
||||||
if (s != NATS_OK)
|
if (s != NATS_OK) {
|
||||||
break;
|
s = natsSubscription_NextMsg(&msg, zoneInstanceCommandMessageSub, 1);
|
||||||
|
if (s != NATS_OK) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
eqproto::CommandMessage* message = google::protobuf::Arena::CreateMessage<eqproto::CommandMessage>(&the_arena);
|
eqproto::CommandMessage* message = google::protobuf::Arena::CreateMessage<eqproto::CommandMessage>(&the_arena);
|
||||||
|
|
||||||
if (!message->ParseFromString(natsMsg_GetData(msg))) {
|
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);
|
natsMsg_Destroy(msg);
|
||||||
continue;
|
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->command().compare("npctypespawn") == 0) {
|
||||||
if (message->params_size() < 2) {
|
if (message->params_size() < 2) {
|
||||||
message->set_result("Usage: !npctypespawn <npctypeid> <factionid> <x> <y> <z> <h>.");
|
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) {
|
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 {
|
else {
|
||||||
|
|
||||||
@ -165,7 +167,7 @@ void NatsManager::Process()
|
|||||||
else {
|
else {
|
||||||
npc->AddToHateList(mob, hateAmount);
|
npc->AddToHateList(mob, hateAmount);
|
||||||
message->set_result("OK");
|
message->set_result("OK");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -191,6 +193,7 @@ void NatsManager::Process()
|
|||||||
message->set_result("Failed to serialized entitiy result");
|
message->set_result("Failed to serialized entitiy result");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
message->set_result("OK");
|
||||||
message->set_payload(entityPayload.c_str());
|
message->set_payload(entityPayload.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -213,32 +216,30 @@ void NatsManager::Process()
|
|||||||
}*/
|
}*/
|
||||||
else {
|
else {
|
||||||
message->set_result("Usage: entitylist <typeid>.");
|
message->set_result("Usage: entitylist <typeid>.");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (message->result().length() < 1) {
|
if (message->result().length() < 1) {
|
||||||
message->set_result("Failed to parse command.");
|
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);
|
natsMsg_Destroy(msg);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!message->SerializeToString(&pubMessage)) {
|
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);
|
natsMsg_Destroy(msg);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
s = natsConnection_Publish(conn, natsMsg_GetReply(msg), (const void*)pubMessage.c_str(), pubMessage.length());
|
s = natsConnection_Publish(conn, natsMsg_GetReply(msg), (const void*)pubMessage.c_str(), pubMessage.length());
|
||||||
if (s != NATS_OK) {
|
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);
|
natsMsg_Destroy(msg);
|
||||||
continue;
|
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) {
|
if (zoneCommandMessageSub != NULL) {
|
||||||
s = natsSubscription_Unsubscribe(zoneCommandMessageSub);
|
s = natsSubscription_Unsubscribe(zoneCommandMessageSub);
|
||||||
zoneCommandMessageSub = NULL;
|
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) {
|
if (zoneInstanceCommandMessageSub != NULL) {
|
||||||
s = natsSubscription_Unsubscribe(zoneEntityEventSubscribeAllSub);
|
s = natsSubscription_Unsubscribe(zoneInstanceCommandMessageSub);
|
||||||
zoneEntityEventSubscribeAllSub = NULL;
|
zoneInstanceCommandMessageSub = NULL;
|
||||||
if (s != NATS_OK) Log(Logs::General, Logs::NATS, "unsubscribe from zoneEntityEventSubscribeAllSub failed: %s", nats_GetLastError(&s));
|
if (s != NATS_OK)
|
||||||
}
|
Log(Logs::General, Logs::NATS, "unsubscribe from zoneCommandMessageSub 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 (zoneEntityEventListSub != NULL) {
|
if (zoneChannelMessageSub != NULL) {
|
||||||
s = natsSubscription_Unsubscribe(zoneEntityEventListSub);
|
s = natsSubscription_Unsubscribe(zoneChannelMessageSub);
|
||||||
zoneEntityEventListSub = NULL;
|
zoneChannelMessageSub = NULL;
|
||||||
if (s != NATS_OK) Log(Logs::General, Logs::NATS, "unsubscribe from zoneEntityEventListSub failed: %s", nats_GetLastError(&s));
|
if (s != NATS_OK)
|
||||||
|
Log(Logs::General, Logs::NATS, "unsubscribe from zoneCommandMessageSub failed: %s", nats_GetLastError(&s));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (zoneEntityEventSub != NULL) {
|
if (zoneInstanceChannelMessageSub != NULL) {
|
||||||
s = natsSubscription_Unsubscribe(zoneEntityEventSub);
|
s = natsSubscription_Unsubscribe(zoneInstanceChannelMessageSub);
|
||||||
zoneEntityEventSub = NULL;
|
zoneInstanceChannelMessageSub = NULL;
|
||||||
if (s != NATS_OK) Log(Logs::General, Logs::NATS, "unsubscribe from zoneEntityEventSub failed: %s", nats_GetLastError(&s));
|
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();
|
subscribedZoneName.clear();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -298,57 +299,41 @@ void NatsManager::ZoneSubscribe(const char* zonename, uint32 instance) {
|
|||||||
subscribedZoneInstance = instance;
|
subscribedZoneInstance = instance;
|
||||||
|
|
||||||
if (subscribedZoneInstance == 0) {
|
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)
|
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);
|
s = natsSubscription_SetPendingLimits(zoneChannelMessageSub, -1, -1);
|
||||||
if (s != NATS_OK)
|
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)
|
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);
|
s = natsSubscription_SetPendingLimits(zoneCommandMessageSub, -1, -1);
|
||||||
if (s != NATS_OK)
|
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(&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));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
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)
|
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)
|
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)
|
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(&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, "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());
|
message->set_message(adminMessage.c_str());
|
||||||
std::string pubMessage;
|
std::string pubMessage;
|
||||||
if (!message->SerializeToString(&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;
|
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) {
|
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;
|
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) {
|
bool NatsManager::isEntitySubscribed(const uint16 ID) {
|
||||||
if (!connect())
|
if (!connect())
|
||||||
return false;
|
return false;
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void NatsManager::OnDeathEvent(Death_Struct* d) {
|
void NatsManager::OnDeathEvent(Death_Struct* d) {
|
||||||
if (!connect())
|
if (!connect())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (d == NULL)
|
if (d == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!isEntityEventAllEnabled && !isEntitySubscribed(d->spawn_id))
|
if (!isEntityEventAllEnabled && !isEntitySubscribed(d->spawn_id))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
auto op = eqproto::OP_Death;
|
||||||
|
|
||||||
std::string pubMessage;
|
std::string pubMessage;
|
||||||
eqproto::DeathEvent* event = google::protobuf::Arena::CreateMessage<eqproto::DeathEvent>(&the_arena);
|
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_attack_skill_id(d->attack_skill);
|
||||||
event->set_damage(d->damage);
|
event->set_damage(d->damage);
|
||||||
|
|
||||||
|
|
||||||
if (!event->SerializeToString(&pubMessage)) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
eqproto::Event* finalEvent = google::protobuf::Arena::CreateMessage<eqproto::Event>(&the_arena);
|
eqproto::Event* finalEvent = google::protobuf::Arena::CreateMessage<eqproto::Event>(&the_arena);
|
||||||
|
|
||||||
finalEvent->set_payload(pubMessage.c_str());
|
finalEvent->set_payload(pubMessage.c_str());
|
||||||
finalEvent->set_op(eqproto::OP_Death);
|
finalEvent->set_op(op);
|
||||||
if (!finalEvent->SerializeToString(&pubMessage)) {
|
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;
|
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());
|
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, "Failed to send EntityEvent");
|
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) {
|
void NatsManager::OnChannelMessageEvent(uint32 entity_id, ChannelMessage_Struct* cm) {
|
||||||
if (!connect()) return;
|
if (!connect())
|
||||||
if (entity_id == 0) return;
|
return;
|
||||||
if (!isEntityEventAllEnabled && !isEntitySubscribed(entity_id)) return;
|
|
||||||
|
if (entity_id == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!isEntityEventAllEnabled && !isEntitySubscribed(entity_id))
|
||||||
|
return;
|
||||||
|
|
||||||
std::string pubMessage;
|
std::string pubMessage;
|
||||||
eqproto::ChannelMessageEvent* event = google::protobuf::Arena::CreateMessage<eqproto::ChannelMessageEvent>(&the_arena);
|
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_skill_in_language(cm->skill_in_language);
|
||||||
event->set_message(cm->message);
|
event->set_message(cm->message);
|
||||||
|
|
||||||
if (!event->SerializeToString(&pubMessage)) {
|
if (!event->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;
|
||||||
}
|
}
|
||||||
|
|
||||||
eqproto::Event* finalEvent = google::protobuf::Arena::CreateMessage<eqproto::Event>(&the_arena);
|
eqproto::Event* finalEvent = google::protobuf::Arena::CreateMessage<eqproto::Event>(&the_arena);
|
||||||
|
|
||||||
finalEvent->set_payload(pubMessage.c_str());
|
finalEvent->set_payload(pubMessage.c_str());
|
||||||
finalEvent->set_op(eqproto::OP_ChannelMessage);
|
finalEvent->set_op(eqproto::OP_ChannelMessage);
|
||||||
if (!finalEvent->SerializeToString(&pubMessage)) {
|
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());
|
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");
|
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) {
|
void NatsManager::OnEntityEvent(const EmuOpcode op, uint32 entity_id, uint32 target_id) {
|
||||||
if (!connect()) return;
|
if (!connect())
|
||||||
if (entity_id == 0) return;
|
return;
|
||||||
|
|
||||||
if (!isEntityEventAllEnabled && !isEntitySubscribed(entity_id)) return;
|
if (entity_id == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!isEntityEventAllEnabled && !isEntitySubscribed(entity_id))
|
||||||
|
return;
|
||||||
|
|
||||||
std::string pubMessage;
|
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_entity_id(entity_id);
|
||||||
event->set_target_id(target_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);
|
eqproto::Event* finalEvent = google::protobuf::Arena::CreateMessage<eqproto::Event>(&the_arena);
|
||||||
finalEvent->set_payload(pubMessage.c_str());
|
finalEvent->set_payload(pubMessage.c_str());
|
||||||
|
|
||||||
if (op == OP_Camp) {
|
if (op == OP_Camp) {
|
||||||
finalEvent->set_op(eqproto::OP_Camp);
|
finalEvent->set_op(eqproto::OP_Camp);
|
||||||
}
|
}
|
||||||
@ -603,19 +609,23 @@ void NatsManager::OnEntityEvent(const EmuOpcode op, uint32 entity_id, uint32 tar
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!finalEvent->SerializeToString(&pubMessage)) {
|
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;
|
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());
|
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, "Failed to send EntityEvent");
|
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) {
|
void NatsManager::OnSpawnEvent(const EmuOpcode op, uint32 entity_id, Spawn_Struct *spawn) {
|
||||||
if (!connect())
|
if (!connect())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (entity_id == 0)
|
if (entity_id == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!isEntityEventAllEnabled && !isEntitySubscribed(entity_id))
|
if (!isEntityEventAllEnabled && !isEntitySubscribed(entity_id))
|
||||||
return;
|
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_targetable_with_hotkey(spawn->targetable_with_hotkey);
|
||||||
event->set_show_name(spawn->show_name);
|
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);
|
eqproto::Event* finalEvent = google::protobuf::Arena::CreateMessage<eqproto::Event>(&the_arena);
|
||||||
finalEvent->set_payload(pubMessage.c_str());
|
finalEvent->set_payload(pubMessage.c_str());
|
||||||
if (op == OP_ZoneEntry) finalEvent->set_op(eqproto::OP_ZoneEntry);
|
if (op == OP_ZoneEntry)
|
||||||
else if (op == OP_NewSpawn) finalEvent->set_op(eqproto::OP_NewSpawn);
|
finalEvent->set_op(eqproto::OP_ZoneEntry);
|
||||||
else { Log(Logs::General, Logs::NATS, "unhandled op type passed: %i", op); return; }
|
else if (op == OP_NewSpawn)
|
||||||
if (!finalEvent->SerializeToString(&pubMessage)) { Log(Logs::General, Logs::NATS, "Failed to serialize message to string"); return; }
|
finalEvent->set_op(eqproto::OP_NewSpawn);
|
||||||
s = natsConnection_Publish(conn, StringFormat("zone.%s.entity.event->%d", subscribedZoneName.c_str(), entity_id).c_str(), (const void*)pubMessage.c_str(), pubMessage.length());
|
else {
|
||||||
if (s != NATS_OK) Log(Logs::General, Logs::NATS, "Failed to send EntityEvent");
|
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) {
|
void NatsManager::OnWearChangeEvent(uint32 entity_id, WearChange_Struct *wc) {
|
||||||
if (!connect()) return;
|
if (!connect())
|
||||||
if (entity_id == 0) return;
|
return;
|
||||||
if (!isEntityEventAllEnabled && !isEntitySubscribed(entity_id)) return;
|
if (entity_id == 0)
|
||||||
|
return;
|
||||||
|
if (!isEntityEventAllEnabled && !isEntitySubscribed(entity_id))
|
||||||
|
return;
|
||||||
|
|
||||||
|
auto op = eqproto::OP_WearChange;
|
||||||
std::string pubMessage;
|
std::string pubMessage;
|
||||||
eqproto::WearChangeEvent* event = google::protobuf::Arena::CreateMessage<eqproto::WearChangeEvent>(&the_arena);
|
eqproto::WearChangeEvent* event = google::protobuf::Arena::CreateMessage<eqproto::WearChangeEvent>(&the_arena);
|
||||||
event->set_spawn_id(wc->spawn_id);
|
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_color(wc->color); //tint
|
||||||
event->set_wear_slot_id(wc->wear_slot_id);
|
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);
|
eqproto::Event* finalEvent = google::protobuf::Arena::CreateMessage<eqproto::Event>(&the_arena);
|
||||||
finalEvent->set_payload(pubMessage.c_str());
|
finalEvent->set_payload(pubMessage.c_str());
|
||||||
finalEvent->set_op(eqproto::OP_WearChange);
|
finalEvent->set_op(op);
|
||||||
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 (!finalEvent->SerializeToString(&pubMessage)) {
|
||||||
if (s != NATS_OK) Log(Logs::General, Logs::NATS, "Failed to send EntityEvent");
|
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) {
|
void NatsManager::OnDeleteSpawnEvent(uint32 entity_id, DeleteSpawn_Struct *ds) {
|
||||||
if (!connect()) return;
|
if (!connect())
|
||||||
if (entity_id == 0) return;
|
return;
|
||||||
if (!isEntityEventAllEnabled && !isEntitySubscribed(entity_id)) return;
|
if (entity_id == 0)
|
||||||
|
return;
|
||||||
|
if (!isEntityEventAllEnabled && !isEntitySubscribed(entity_id))
|
||||||
|
return;
|
||||||
|
|
||||||
std::string pubMessage;
|
std::string pubMessage;
|
||||||
|
auto op = eqproto::OP_DeleteSpawn;
|
||||||
eqproto::DeleteSpawnEvent* event = google::protobuf::Arena::CreateMessage<eqproto::DeleteSpawnEvent>(&the_arena);
|
eqproto::DeleteSpawnEvent* event = google::protobuf::Arena::CreateMessage<eqproto::DeleteSpawnEvent>(&the_arena);
|
||||||
|
|
||||||
event->set_spawn_id(ds->spawn_id);
|
event->set_spawn_id(ds->spawn_id);
|
||||||
event->set_decay(ds->Decay);
|
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);
|
eqproto::Event* finalEvent = google::protobuf::Arena::CreateMessage<eqproto::Event>(&the_arena);
|
||||||
finalEvent->set_payload(pubMessage.c_str());
|
finalEvent->set_payload(pubMessage.c_str());
|
||||||
finalEvent->set_op(eqproto::OP_DeleteSpawn);
|
finalEvent->set_op(op);
|
||||||
if (!finalEvent->SerializeToString(&pubMessage)) { Log(Logs::General, Logs::NATS, "Failed to serialize message to string"); return; }
|
if (!finalEvent->SerializeToString(&pubMessage)) {
|
||||||
s = natsConnection_Publish(conn, StringFormat("zone.%s.entity.event->%d", subscribedZoneName.c_str(), entity_id).c_str(), (const void*)pubMessage.c_str(), pubMessage.length());
|
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);
|
||||||
if (s != NATS_OK) Log(Logs::General, Logs::NATS, "Failed to send EntityEvent");
|
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) {
|
void NatsManager::OnHPEvent(const EmuOpcode op, uint32 entity_id, uint32 cur_hp, uint32 max_hp) {
|
||||||
if (!connect()) return;
|
if (!connect())
|
||||||
if (entity_id == 0) return;
|
return;
|
||||||
if (!isEntityEventAllEnabled && !isEntitySubscribed(entity_id)) return;
|
if (entity_id == 0)
|
||||||
if (cur_hp == max_hp) return;
|
return;
|
||||||
|
if (!isEntityEventAllEnabled && !isEntitySubscribed(entity_id))
|
||||||
|
return;
|
||||||
|
if (cur_hp == max_hp)
|
||||||
|
return;
|
||||||
std::string pubMessage;
|
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_cur_hp(cur_hp);
|
||||||
event->set_max_hp(max_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);
|
eqproto::Event* finalEvent = google::protobuf::Arena::CreateMessage<eqproto::Event>(&the_arena);
|
||||||
finalEvent->set_payload(pubMessage.c_str());
|
finalEvent->set_payload(pubMessage.c_str());
|
||||||
if (op == OP_MobHealth) finalEvent->set_op(eqproto::OP_MobHealth);
|
if (op == OP_MobHealth)
|
||||||
else if (op == OP_HPUpdate) finalEvent->set_op(eqproto::OP_HPUpdate);
|
finalEvent->set_op(eqproto::OP_MobHealth);
|
||||||
else { Log(Logs::General, Logs::NATS, "unhandled op type passed: %i", op); return; }
|
else if (op == OP_HPUpdate)
|
||||||
if (!finalEvent->SerializeToString(&pubMessage)) { Log(Logs::General, Logs::NATS, "Failed to serialize message to string"); return; }
|
finalEvent->set_op(eqproto::OP_HPUpdate);
|
||||||
s = natsConnection_Publish(conn, StringFormat("zone.%s.entity.event->%d", subscribedZoneName.c_str(), entity_id).c_str(), (const void*)pubMessage.c_str(), pubMessage.length());
|
else {
|
||||||
if (s != NATS_OK) Log(Logs::General, Logs::NATS, "Failed to send EntityEvent");
|
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) {
|
void NatsManager::OnDamageEvent(uint32 entity_id, CombatDamage_Struct *cd) {
|
||||||
if (!connect()) return;
|
if (!connect())
|
||||||
if (entity_id == 0) return;
|
return;
|
||||||
if (!isEntityEventAllEnabled && !isEntitySubscribed(entity_id)) return;
|
if (entity_id == 0)
|
||||||
std::string pubMessage;
|
return;
|
||||||
|
if (!isEntityEventAllEnabled && !isEntitySubscribed(entity_id))
|
||||||
|
return;
|
||||||
|
|
||||||
|
std::string pubMessage;
|
||||||
|
|
||||||
eqproto::DamageEvent* event = google::protobuf::Arena::CreateMessage<eqproto::DamageEvent>(&the_arena);
|
eqproto::DamageEvent* event = google::protobuf::Arena::CreateMessage<eqproto::DamageEvent>(&the_arena);
|
||||||
event->set_target(cd->target);
|
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_force(cd->force);
|
||||||
event->set_meleepush_xy(cd->hit_heading);
|
event->set_meleepush_xy(cd->hit_heading);
|
||||||
event->set_meleepush_z(cd->hit_pitch);
|
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);
|
eqproto::Event* finalEvent = google::protobuf::Arena::CreateMessage<eqproto::Event>(&the_arena);
|
||||||
finalEvent->set_payload(pubMessage.c_str());
|
finalEvent->set_payload(pubMessage.c_str());
|
||||||
finalEvent->set_op(eqproto::OP_Damage);
|
finalEvent->set_op(op);
|
||||||
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 (!finalEvent->SerializeToString(&pubMessage)) {
|
||||||
if (s != NATS_OK) Log(Logs::General, Logs::NATS, "Failed to send EntityEvent");
|
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) {
|
void NatsManager::OnClientUpdateEvent(uint32 entity_id, PlayerPositionUpdateServer_Struct * spu) {
|
||||||
if (!connect()) return;
|
|
||||||
if (entity_id == 0) return;
|
auto op = eqproto::OP_ClientUpdate;
|
||||||
if (!isEntityEventAllEnabled && !isEntitySubscribed(entity_id)) return;
|
if (!connect())
|
||||||
|
return;
|
||||||
|
if (entity_id == 0)
|
||||||
|
return;
|
||||||
|
if (!isEntityEventAllEnabled && !isEntitySubscribed(entity_id))
|
||||||
|
return;
|
||||||
|
|
||||||
std::string pubMessage;
|
std::string pubMessage;
|
||||||
|
|
||||||
|
|
||||||
eqproto::PlayerPositionUpdateEvent* event = google::protobuf::Arena::CreateMessage<eqproto::PlayerPositionUpdateEvent>(&the_arena);
|
eqproto::PlayerPositionUpdateEvent* event = google::protobuf::Arena::CreateMessage<eqproto::PlayerPositionUpdateEvent>(&the_arena);
|
||||||
event->set_spawn_id(spu->spawn_id);
|
event->set_spawn_id(spu->spawn_id);
|
||||||
event->set_delta_heading(spu->delta_heading);
|
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_padding0014(spu->padding0014);
|
||||||
event->set_delta_z(spu->delta_z);
|
event->set_delta_z(spu->delta_z);
|
||||||
event->set_padding0018(spu->padding0018);
|
event->set_padding0018(spu->padding0018);
|
||||||
|
|
||||||
if (!event->SerializeToString(&pubMessage)) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
eqproto::Event* finalEvent = google::protobuf::Arena::CreateMessage<eqproto::Event>(&the_arena);
|
eqproto::Event* finalEvent = google::protobuf::Arena::CreateMessage<eqproto::Event>(&the_arena);
|
||||||
finalEvent->set_payload(pubMessage.c_str());
|
finalEvent->set_payload(pubMessage.c_str());
|
||||||
finalEvent->set_op(eqproto::OP_ClientUpdate);
|
finalEvent->set_op(op);
|
||||||
if (!finalEvent->SerializeToString(&pubMessage)) {
|
|
||||||
Log(Logs::General, Logs::NATS, "Failed to serialize message to string");
|
if (!finalEvent->SerializeToString(&pubMessage)) {
|
||||||
return;
|
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());
|
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, "Failed to send EntityEvent");
|
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) {
|
void NatsManager::OnAnimationEvent(uint32 entity_id, Animation_Struct *anim) {
|
||||||
if (!connect()) return;
|
if (!connect())
|
||||||
if (entity_id == 0) return;
|
return;
|
||||||
if (!isEntityEventAllEnabled && !isEntitySubscribed(entity_id)) return;
|
if (entity_id == 0)
|
||||||
|
return;
|
||||||
|
if (!isEntityEventAllEnabled && !isEntitySubscribed(entity_id))
|
||||||
|
return;
|
||||||
|
|
||||||
std::string pubMessage;
|
std::string pubMessage;
|
||||||
|
|
||||||
|
auto op = eqproto::OP_Animation;
|
||||||
|
|
||||||
eqproto::AnimationEvent* event = google::protobuf::Arena::CreateMessage<eqproto::AnimationEvent>(&the_arena);
|
eqproto::AnimationEvent* event = google::protobuf::Arena::CreateMessage<eqproto::AnimationEvent>(&the_arena);
|
||||||
event->set_spawnid(anim->spawnid);
|
event->set_spawnid(anim->spawnid);
|
||||||
event->set_speed(anim->speed);
|
event->set_speed(anim->speed);
|
||||||
event->set_action(anim->action);
|
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);
|
eqproto::Event* finalEvent = google::protobuf::Arena::CreateMessage<eqproto::Event>(&the_arena);
|
||||||
|
|
||||||
finalEvent->set_payload(pubMessage.c_str());
|
finalEvent->set_payload(pubMessage.c_str());
|
||||||
finalEvent->set_op(eqproto::OP_Animation);
|
finalEvent->set_op(op);
|
||||||
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 (!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));
|
||||||
}
|
}
|
||||||
@ -40,11 +40,9 @@ protected:
|
|||||||
std::string subscribedZoneName;
|
std::string subscribedZoneName;
|
||||||
uint32 subscribedZoneInstance;
|
uint32 subscribedZoneInstance;
|
||||||
natsSubscription *zoneChannelMessageSub = NULL;
|
natsSubscription *zoneChannelMessageSub = NULL;
|
||||||
|
natsSubscription *zoneInstanceChannelMessageSub = NULL;
|
||||||
natsSubscription *zoneCommandMessageSub = NULL;
|
natsSubscription *zoneCommandMessageSub = NULL;
|
||||||
natsSubscription *zoneEntityEventSubscribeAllSub = NULL;
|
natsSubscription *zoneInstanceCommandMessageSub = NULL;
|
||||||
natsSubscription *zoneEntityEventSubscribeSub = NULL;
|
|
||||||
natsSubscription *zoneEntityEventListSub = NULL;
|
|
||||||
natsSubscription *zoneEntityEventSub = NULL;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
Loading…
x
Reference in New Issue
Block a user