mirror of
https://github.com/EQEmu/Server.git
synced 2026-06-25 22:57:15 +00:00
Added lua/perl support for nats AdminMessage, added more response fields
This commit is contained in:
+64
-26
@@ -3,6 +3,7 @@
|
||||
#include "zonelist.h"
|
||||
#include "login_server_list.h"
|
||||
#include "clientlist.h"
|
||||
#include "cliententry.h"
|
||||
#include "worlddb.h"
|
||||
|
||||
#include <google/protobuf/arena.h>
|
||||
@@ -98,7 +99,7 @@ void NatsManager::Process()
|
||||
break;
|
||||
|
||||
eqproto::ChannelMessage* message = google::protobuf::Arena::CreateMessage<eqproto::ChannelMessage>(&the_arena);
|
||||
if (!message->ParseFromString(natsMsg_GetData(msg))) {
|
||||
if (!message->ParseFromArray(natsMsg_GetData(msg), natsMsg_GetDataLength(msg))) {
|
||||
Log(Logs::General, Logs::NATS, "world.channel_message.in: failed to parse");
|
||||
natsMsg_Destroy(msg);
|
||||
continue;
|
||||
@@ -115,11 +116,11 @@ void NatsManager::Process()
|
||||
break;
|
||||
|
||||
eqproto::CommandMessage* message = google::protobuf::Arena::CreateMessage<eqproto::CommandMessage>(&the_arena);
|
||||
if (!message->ParseFromString(natsMsg_GetData(msg))) {
|
||||
if (!message->ParseFromArray(natsMsg_GetData(msg), natsMsg_GetDataLength(msg))) {
|
||||
Log(Logs::General, Logs::NATS, "world.command_message.in: failed to parse");
|
||||
natsMsg_Destroy(msg);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
GetCommandMessage(message, natsMsg_GetReply(msg));
|
||||
}
|
||||
}
|
||||
@@ -191,10 +192,6 @@ void NatsManager::SendCommandMessage(eqproto::CommandMessage* message, const cha
|
||||
if (!connect())
|
||||
return;
|
||||
|
||||
if (message->result().length() <= 1)
|
||||
message->set_result("Failed to parse command.");
|
||||
|
||||
|
||||
size_t event_size = message->ByteSizeLong();
|
||||
void *event_buffer = malloc(event_size);
|
||||
if (!message->SerializeToArray(event_buffer, event_size)) {
|
||||
@@ -209,11 +206,11 @@ void NatsManager::SendCommandMessage(eqproto::CommandMessage* message, const cha
|
||||
s = natsConnection_Publish(conn, "world.command_message.out", event_buffer, event_size);
|
||||
|
||||
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", nats_GetLastError(&s));
|
||||
return;
|
||||
}
|
||||
|
||||
Log(Logs::General, Logs::NATS, "world.command_message.in: %s (%s)", message->command().c_str(), message->result().c_str());
|
||||
Log(Logs::General, Logs::NATS, "world.command_message.in: %s (%d: %s)", message->command().c_str(), message->response_error(), message->response_message().c_str());
|
||||
}
|
||||
|
||||
// GetCommandMessage is used to process a command message
|
||||
@@ -222,7 +219,7 @@ void NatsManager::GetCommandMessage(eqproto::CommandMessage* message, const char
|
||||
return;
|
||||
|
||||
if (message->command().compare("who") == 0) {
|
||||
message->set_result(client_list.GetWhoAll());
|
||||
message->set_response_message(client_list.GetWhoAll());
|
||||
SendCommandMessage(message, reply);
|
||||
return;
|
||||
}
|
||||
@@ -231,7 +228,7 @@ void NatsManager::GetCommandMessage(eqproto::CommandMessage* message, const char
|
||||
WorldConfig::UnlockWorld();
|
||||
if (loginserverlist.Connected())
|
||||
loginserverlist.SendStatus();
|
||||
message->set_result("Server is now unlocked.");
|
||||
message->set_response_message("Server is now unlocked.");
|
||||
SendCommandMessage(message, reply);
|
||||
return;
|
||||
}
|
||||
@@ -240,7 +237,7 @@ void NatsManager::GetCommandMessage(eqproto::CommandMessage* message, const char
|
||||
WorldConfig::LockWorld();
|
||||
if (loginserverlist.Connected())
|
||||
loginserverlist.SendStatus();
|
||||
message->set_result("Server is now locked.");
|
||||
message->set_response_message("Server is now locked.");
|
||||
SendCommandMessage(message, reply);
|
||||
return;
|
||||
}
|
||||
@@ -250,26 +247,27 @@ void NatsManager::GetCommandMessage(eqproto::CommandMessage* message, const char
|
||||
uint32 interval=0;
|
||||
|
||||
if(message->params_size() == 2 && ((time=atoi(message->params(0).c_str()))>0) && ((interval=atoi(message->params(1).c_str()))>0)) {
|
||||
message->set_result(StringFormat("Sending shutdown packet now, World will shutdown in: %i minutes with an interval of: %i seconds", (time / 60), interval));
|
||||
message->set_response_message(StringFormat("Sending shutdown packet now, World will shutdown in: %i minutes with an interval of: %i seconds", (time / 60), interval));
|
||||
zoneserver_list.WorldShutDown(time, interval);
|
||||
SendCommandMessage(message, reply);
|
||||
return;
|
||||
}
|
||||
else if(strcasecmp(message->params(0).c_str(), "now") == 0){
|
||||
message->set_result("Sending shutdown packet now");
|
||||
message->set_response_message("Sending shutdown packet now");
|
||||
zoneserver_list.WorldShutDown(0, 0);
|
||||
SendCommandMessage(message, reply);
|
||||
return;
|
||||
}
|
||||
else if(strcasecmp(message->params(0).c_str(), "disable") == 0){
|
||||
message->set_result("Shutdown prevented, next time I may not be so forgiving...");
|
||||
message->set_response_message("Shutdown prevented, next time I may not be so forgiving...");
|
||||
zoneserver_list.SendEmoteMessage(0, 0, 0, 15, "<SYSTEMWIDE MESSAGE>:SYSTEM MSG:World shutdown aborted.");
|
||||
zoneserver_list.shutdowntimer->Disable();
|
||||
zoneserver_list.reminder->Disable();
|
||||
SendCommandMessage(message, reply);
|
||||
return;
|
||||
}
|
||||
message->set_result("worldshutdown - Shuts down the server and all zones.\n \
|
||||
message->set_response_error(eqproto::ERR_Request);
|
||||
message->set_response_message("worldshutdown - Shuts down the server and all zones.\n \
|
||||
Usage: worldshutdown now - Shuts down the server and all zones immediately.\n \
|
||||
Usage: worldshutdown disable - Stops the server from a previously scheduled shut down.\n \
|
||||
Usage: worldshutdown [timer] [interval] - Shuts down the server and all zones after [timer] seconds and sends warning every [interval] seconds\n");
|
||||
@@ -277,7 +275,8 @@ void NatsManager::GetCommandMessage(eqproto::CommandMessage* message, const char
|
||||
return;
|
||||
}
|
||||
|
||||
message->set_result("unknown command sent");
|
||||
message->set_response_error(eqproto::ERR_Request);
|
||||
message->set_response_message("Unknown command");
|
||||
SendCommandMessage(message, reply);
|
||||
return;
|
||||
}
|
||||
@@ -289,21 +288,60 @@ void NatsManager::GetChannelMessage(eqproto::ChannelMessage* message, const char
|
||||
|
||||
if (message->is_emote()) { //emote message
|
||||
zoneserver_list.SendEmoteMessage(message->to().c_str(), message->guilddbid(), message->minstatus(), message->type(), message->message().c_str());
|
||||
message->set_result("Sent message");
|
||||
message->set_response_message("Success");
|
||||
SendChannelMessage(message, reply);
|
||||
return;
|
||||
}
|
||||
|
||||
//normal broadcast
|
||||
char tmpname[64];
|
||||
tmpname[0] = '*';
|
||||
strcpy(&tmpname[1], message->from().c_str());
|
||||
//TODO: add To support on tells
|
||||
char from[64];
|
||||
from[0] = '*';
|
||||
strcpy(&from[1], message->from().c_str());
|
||||
|
||||
|
||||
int channel = message->number();
|
||||
if (channel < 1)
|
||||
if (channel < 1) {
|
||||
channel = MT_OOC; //default to ooc
|
||||
zoneserver_list.SendChannelMessage(tmpname, 0, channel, message->language(), message->message().c_str());
|
||||
message->set_result("1");
|
||||
message->set_number(eqproto::OOC);
|
||||
}
|
||||
|
||||
if (message->to().length() == 0) { //Send a world message
|
||||
zoneserver_list.SendChannelMessage(from, 0, channel, message->language(), message->message().c_str());
|
||||
message->set_response_message("Success");
|
||||
SendChannelMessage(message, reply);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
//Send a tell
|
||||
|
||||
channel = 7; //tells are always echo
|
||||
message->set_number(static_cast<eqproto::MessageType>(7));
|
||||
ClientListEntry* cle = client_list.FindCharacter(message->to().c_str());
|
||||
if (cle == 0 || cle->Online() < CLE_Status_Zoning ||
|
||||
(cle->TellsOff() && ((cle->Anon() == 1 && message->fromadmin() < cle->Admin()) || message->fromadmin() < 80))) {
|
||||
message->set_response_error(eqproto::ERR_Failed);
|
||||
message->set_response_message("Player is offline");
|
||||
SendChannelMessage(message, reply);
|
||||
return;
|
||||
}
|
||||
|
||||
if (cle->Online() == CLE_Status_Zoning) {
|
||||
if (cle->TellQueueFull()) {
|
||||
message->set_response_error(eqproto::ERR_Failed);
|
||||
message->set_response_message("Queue is full");
|
||||
SendChannelMessage(message, reply);
|
||||
return;
|
||||
}
|
||||
|
||||
//This should succeed in going into a tell queue, since it doesn't return we have to detect above
|
||||
zoneserver_list.SendChannelMessage(from, message->to().c_str(), channel, message->language(), message->message().c_str());
|
||||
message->set_response_message("Player is zoning, tell is queued");
|
||||
SendChannelMessage(message, reply);
|
||||
return;
|
||||
}
|
||||
zoneserver_list.SendChannelMessage(from, message->to().c_str(), channel, message->language(), message->message().c_str());
|
||||
message->set_response_message("Success");
|
||||
SendChannelMessage(message, reply);
|
||||
return;
|
||||
}
|
||||
@@ -334,7 +372,7 @@ void NatsManager::SendChannelMessage(eqproto::ChannelMessage* message, const cha
|
||||
}
|
||||
|
||||
if (reply)
|
||||
Log(Logs::General, Logs::NATS, "world.channel_message.in: %s (%s)", message->message().c_str(), message->result().c_str());
|
||||
Log(Logs::General, Logs::NATS, "world.channel_message.in: %s (%d: %s)", message->message().c_str(), message->response_error(), message->response_message().c_str());
|
||||
else
|
||||
Log(Logs::General, Logs::NATS, "world.channel_message.out: %s", message->message().c_str());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user