From 3b03f87070d91f63f0dc3c7152723727781dcccf Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 28 Apr 2018 11:52:04 +0200 Subject: Add commands, users side panel, improve image download start using odhtdb --- src/Command.cpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/Command.cpp (limited to 'src/Command.cpp') diff --git a/src/Command.cpp b/src/Command.cpp new file mode 100644 index 0000000..a074930 --- /dev/null +++ b/src/Command.cpp @@ -0,0 +1,37 @@ +#include "../include/Command.hpp" +#include + +using namespace std; + +namespace dchat +{ + unordered_map commandHandlerFuncs; + + bool Command::add(const string &cmd, CommandHandlerFunc handlerFunc) + { + auto it = commandHandlerFuncs.find(cmd); + if(it != commandHandlerFuncs.end()) + return false; + + commandHandlerFuncs[cmd] = handlerFunc; + return true; + } + + bool Command::call(const string &cmd, const vector &args) + { + auto it = commandHandlerFuncs.find(cmd); + if(it != commandHandlerFuncs.end()) + { + try + { + it->second(args); + } + catch(exception &e) + { + fprintf(stderr, "Failed while executing command %s, reason: %s\n", cmd.c_str(), e.what()); + } + return true; + } + return false; + } +} -- cgit v1.2.3-70-g09d2