Cleaned up channel message styles

This commit is contained in:
Xackery 2018-03-10 14:25:43 -08:00
parent 2270bd267d
commit 0c5779d2de
3 changed files with 17 additions and 75 deletions

View File

@ -147,11 +147,11 @@ void NatsManager::SendAdminMessage(std::string adminMessage) {
Log(Logs::General, Logs::NATS, "Failed to serialize message to string"); Log(Logs::General, Logs::NATS, "Failed to serialize message to string");
return; return;
} }
s = natsConnection_PublishString(conn, "AdminMessage", pubMessage.c_str()); s = natsConnection_PublishString(conn, "world.admin_message", pubMessage.c_str());
if (s != NATS_OK) { if (s != NATS_OK) {
Log(Logs::General, Logs::NATS, "Failed to SendAdminMessage"); Log(Logs::General, Logs::NATS, "Failed to publish to world.admin_message");
} }
Log(Logs::General, Logs::NATS, "AdminMessage: %s", adminMessage.c_str()); Log(Logs::General, Logs::NATS, "world.admin_message: %s", adminMessage.c_str());
} }
//Send (publish) message to NATS //Send (publish) message to NATS
@ -163,9 +163,9 @@ void NatsManager::SendChannelMessage(eqproto::ChannelMessage* message) {
Log(Logs::General, Logs::NATS, "Failed to serialize message to string"); Log(Logs::General, Logs::NATS, "Failed to serialize message to string");
return; return;
} }
s = natsConnection_PublishString(conn, "ChannelMessage", pubMessage.c_str()); s = natsConnection_PublishString(conn, "world.command_message", pubMessage.c_str());
if (s != NATS_OK) { if (s != NATS_OK) {
Log(Logs::General, Logs::NATS, "Failed to send ChannelMessageEvent"); Log(Logs::General, Logs::NATS, "Failed to send world.command_message");
} }
} }
@ -262,7 +262,7 @@ void NatsManager::Load()
{ {
if (!connect()) return; if (!connect()) return;
s = natsConnection_SubscribeSync(&channelMessageSub, conn, "ChannelMessageWorld"); s = natsConnection_SubscribeSync(&channelMessageSub, conn, "world.channel_message");
s = natsConnection_SubscribeSync(&commandMessageSub, conn, "CommandMessageWorld"); s = natsConnection_SubscribeSync(&commandMessageSub, conn, "world.command_message");
return; return;
} }

View File

@ -38,27 +38,14 @@ NatsManager::~NatsManager()
void NatsManager::Process() void NatsManager::Process()
{ {
if (zoneSub == NULL) {
return;
}
if (!connect()) return; if (!connect()) return;
natsMsg *msg = NULL; natsMsg *msg = NULL;
s = NATS_OK;
std::string pubMessage; std::string pubMessage;
for (int count = 0; (s == NATS_OK) && count < 100; count++)
{
s = natsSubscription_NextMsg(&msg, zoneSub, 1);
if (s != NATS_OK) break;
Log(Logs::General, Logs::NATS, "got message '%s'", natsMsg_GetData(msg));
natsMsg_Destroy(msg);
}
s = NATS_OK; s = NATS_OK;
for (int count = 0; (s == NATS_OK) && count < 5; count++) for (int count = 0; (s == NATS_OK) && count < 5; count++)
{ {
s = natsSubscription_NextMsg(&msg, commandMessageSub, 1); s = natsSubscription_NextMsg(&msg, zoneCommandMessageSub, 1);
if (s != NATS_OK) break; if (s != NATS_OK) break;
Log(Logs::General, Logs::World_Server, "NATS Got Command Message '%s'", natsMsg_GetData(msg)); Log(Logs::General, Logs::World_Server, "NATS Got Command Message '%s'", natsMsg_GetData(msg));
eqproto::CommandMessage message; eqproto::CommandMessage message;
@ -244,16 +231,10 @@ void NatsManager::Process()
void NatsManager::Unregister() void NatsManager::Unregister()
{ {
if (!connect()) return; if (!connect()) return;
if (commandMessageSub != NULL) { if (zoneCommandMessageSub != NULL) {
s = natsSubscription_Unsubscribe(commandMessageSub); s = natsSubscription_Unsubscribe(zoneCommandMessageSub);
commandMessageSub = NULL; zoneCommandMessageSub = NULL;
if (s != NATS_OK) Log(Logs::General, Logs::NATS, "unsubscribe from commandMessageSub failed: %s", nats_GetLastError(&s)); if (s != NATS_OK) Log(Logs::General, Logs::NATS, "unsubscribe from zoneCommandMessageSub 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 zoneChannelMessageSub failed: %s", nats_GetLastError(&s));
} }
if (zoneEntityEventSubscribeAllSub != NULL) { if (zoneEntityEventSubscribeAllSub != NULL) {
@ -296,10 +277,10 @@ void NatsManager::ZoneSubscribe(const char* zonename) {
s = natsSubscription_SetPendingLimits(zoneChannelMessageSub, -1, -1); s = natsSubscription_SetPendingLimits(zoneChannelMessageSub, -1, -1);
if (s != NATS_OK) Log(Logs::General, Logs::NATS, "failed to set pending limits to zoneChannelMessageSub %s", nats_GetLastError(&s)); if (s != NATS_OK) Log(Logs::General, Logs::NATS, "failed to set pending limits to zoneChannelMessageSub %s", nats_GetLastError(&s));
s = natsConnection_SubscribeSync(&commandMessageSub, conn, StringFormat("zone.%s.command_message", subscribedZonename.c_str()).c_str()); s = natsConnection_SubscribeSync(&zoneCommandMessageSub, conn, StringFormat("zone.%s.command_message", subscribedZonename.c_str()).c_str());
if (s != NATS_OK) Log(Logs::General, Logs::NATS, "failed to subscribe to commandMessageSub %s", nats_GetLastError(&s)); if (s != NATS_OK) Log(Logs::General, Logs::NATS, "failed to subscribe to zoneCommandMessageSub %s", nats_GetLastError(&s));
s = natsSubscription_SetPendingLimits(commandMessageSub, -1, -1); s = natsSubscription_SetPendingLimits(zoneCommandMessageSub, -1, -1);
if (s != NATS_OK) Log(Logs::General, Logs::NATS, "failed to set pending limits to commandMessageSub %s", nats_GetLastError(&s)); if (s != NATS_OK) Log(Logs::General, Logs::NATS, "failed to set pending limits to zoneCommandMessageSub %s", nats_GetLastError(&s));
s = natsConnection_SubscribeSync(&zoneEntityEventSubscribeAllSub, conn, StringFormat("zone.%s.entity.event_subscribe.all", subscribedZonename.c_str()).c_str()); s = natsConnection_SubscribeSync(&zoneEntityEventSubscribeAllSub, conn, StringFormat("zone.%s.entity.event_subscribe.all", subscribedZonename.c_str()).c_str());
if (s != NATS_OK) Log(Logs::General, Logs::NATS, "failed to subscribe to zoneEntityEventSubscribeAllSub %s", nats_GetLastError(&s)); if (s != NATS_OK) Log(Logs::General, Logs::NATS, "failed to subscribe to zoneEntityEventSubscribeAllSub %s", nats_GetLastError(&s));
@ -366,40 +347,6 @@ bool NatsManager::connect() {
void NatsManager::Load() void NatsManager::Load()
{ {
if (!connect()) return; if (!connect()) return;
s = natsConnection_SubscribeSync(&zoneSub, conn, "zone");
if (s != NATS_OK) {
Log(Logs::General, Logs::NATS, "failed to subscribe to zone: %s", nats_GetLastError(&s));
return;
}
s = natsSubscription_SetPendingLimits(zoneSub, -1, -1);
if (s != NATS_OK) {
Log(Logs::General, Logs::NATS, "failed to set pending limits while subscribed to zone %s", nats_GetLastError(&s));
return;
}
s = natsConnection_SubscribeSync(&commandMessageSub, conn, "zone.command_message");
if (s != NATS_OK) {
Log(Logs::General, Logs::NATS, "failed to subscribe to commandMessageSub: %s", nats_GetLastError(&s));
return;
}
s = natsSubscription_SetPendingLimits(commandMessageSub, -1, -1);
if (s != NATS_OK) {
Log(Logs::General, Logs::NATS, "failed to set pending limits while subscribed to commandMessageSub: %s", nats_GetLastError(&s));
return;
}
s = natsConnection_SubscribeSync(&channelMessageSub, conn, "zone.channel_message");
if (s != NATS_OK) {
Log(Logs::General, Logs::NATS, "failed to subscribe to channel message: %s", nats_GetLastError(&s));
return;
}
s = natsSubscription_SetPendingLimits(channelMessageSub, -1, -1);
if (s != NATS_OK) {
Log(Logs::General, Logs::NATS, "failed to set pending limits while subscribed to channel message: %s", nats_GetLastError(&s));
return;
}
return; return;
} }
@ -419,7 +366,7 @@ void NatsManager::DailyGain(int account_id, int character_id, const char* identi
return; return;
} }
s = natsConnection_PublishString(conn, "DailyGain", pubMessage.c_str()); s = natsConnection_PublishString(conn, "daily_gain", pubMessage.c_str());
if (s != NATS_OK) Log(Logs::General, Logs::NATS, "failed to send DailyGain: %s", nats_GetLastError(&s)); if (s != NATS_OK) Log(Logs::General, Logs::NATS, "failed to send DailyGain: %s", nats_GetLastError(&s));
} }

View File

@ -39,11 +39,6 @@ protected:
natsStatus s; natsStatus s;
natsOptions *opts = NULL; natsOptions *opts = NULL;
std::string subscribedZonename; std::string subscribedZonename;
//global zone subscriptions
natsSubscription *zoneSub = NULL;
natsSubscription *channelMessageSub = NULL;
natsSubscription *commandMessageSub = NULL;
//zone specific subscriptions
natsSubscription *zoneChannelMessageSub = NULL; natsSubscription *zoneChannelMessageSub = NULL;
natsSubscription *zoneCommandMessageSub = NULL; natsSubscription *zoneCommandMessageSub = NULL;
natsSubscription *zoneEntityEventSubscribeAllSub = NULL; natsSubscription *zoneEntityEventSubscribeAllSub = NULL;