Publishing now has a space for an article and a title. Also reduced amount of copying
This commit is contained in:
parent
98bfab4ba5
commit
8187d045cd
8 changed files with 76 additions and 35 deletions
|
@ -3,6 +3,8 @@
|
|||
|
||||
#include "router.h"
|
||||
|
||||
#include <string_view>
|
||||
|
||||
#include "module/module.h"
|
||||
#include "connection/connection.h"
|
||||
|
||||
|
@ -42,12 +44,23 @@ void Router::routeMessage(const std::string& sender, const std::string& body) {
|
|||
if (aItr == actors.end())
|
||||
aItr = actors.emplace(sender, std::make_shared<Actor>(sender, defaultGroup)).first;
|
||||
|
||||
Shared::Strings args = Shared::split(body);
|
||||
std::string moduleAlias = Module::Module::lower(args[0]);
|
||||
std::string_view view(body);
|
||||
std::string_view aliasView = Module::Module::pop(view);
|
||||
|
||||
if (aliasView.size() > 1000) {
|
||||
warn("Received a message with the first word larger than 1000 symbols, " + sender + "is clearly looking for a vulnerability");
|
||||
return onMessageResult(Shared::unhandled, sender);
|
||||
}
|
||||
|
||||
Modules::iterator mItr = modules.find(moduleAlias);
|
||||
if (view.empty()) {
|
||||
debug("Incoming message from " + sender + " consists of only one word, modules have nothing to process");
|
||||
return onMessageResult(Shared::unhandled, sender);
|
||||
}
|
||||
|
||||
std::string alias(aliasView);
|
||||
Modules::iterator mItr = modules.find(alias);
|
||||
if (mItr == modules.end()) {
|
||||
debug("could not find module \"" + moduleAlias + "\" to handle message from " + sender);
|
||||
debug("could not find module \"" + alias + "\" to handle message from " + sender);
|
||||
return onMessageResult(Shared::unhandled, sender);
|
||||
}
|
||||
|
||||
|
@ -57,10 +70,9 @@ void Router::routeMessage(const std::string& sender, const std::string& body) {
|
|||
return onMessageResult(Shared::error, sender);
|
||||
}
|
||||
|
||||
args.erase(args.begin());
|
||||
Shared::Result result;
|
||||
try {
|
||||
result = module->message(aItr->second, args);
|
||||
result = module->message(aItr->second, view);
|
||||
if (result == Shared::success)
|
||||
debug("module \"" + mItr->first + "\" successfully handled message from " + sender);
|
||||
} catch (...) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue