diff options
author | Andrei Karas <akaras@inbox.ru> | 2014-01-26 21:45:57 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2014-01-26 22:01:51 +0300 |
commit | 5889bd94d241b8454268804861a67c79315a7731 (patch) | |
tree | b37aaec28083110308fbbc5fa3a2c4bb07ce2ed7 /src/commands.cpp | |
parent | bae784c3718b2d28bef80ef57f23c47cc4342c64 (diff) | |
download | manaverse-5889bd94d241b8454268804861a67c79315a7731.tar.gz manaverse-5889bd94d241b8454268804861a67c79315a7731.tar.bz2 manaverse-5889bd94d241b8454268804861a67c79315a7731.tar.xz manaverse-5889bd94d241b8454268804861a67c79315a7731.zip |
add chat command for uploading main config.xml
New chat command: /uploadconfig
Diffstat (limited to 'src/commands.cpp')
-rw-r--r-- | src/commands.cpp | 78 |
1 files changed, 76 insertions, 2 deletions
diff --git a/src/commands.cpp b/src/commands.cpp index 72fedeff1..ee41b04d0 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -58,6 +58,7 @@ #include "net/adminhandler.h" #include "net/beinghandler.h" #include "net/chathandler.h" +#include "net/download.h" #include "net/gamehandler.h" #include "net/guildhandler.h" #include "net/net.h" @@ -96,7 +97,8 @@ extern char **environ; namespace Commands { -static void outString(ChatTab *const tab, const std::string &str, +static void outString(ChatTab *const tab, + const std::string &str, const std::string &def) { if (!tab) @@ -236,7 +238,7 @@ static void outStringNormal(ChatTab *const tab, case ChatTab::TAB_WHISPER: { const WhisperTab *const whisper - = static_cast<WhisperTab *const>(tab); + = static_cast<const WhisperTab *const>(tab); tab->chatLog(player_node->getName(), str); Net::getChatHandler()->privateMessage(whisper->getNick(), str); break; @@ -1268,6 +1270,78 @@ impHandler1(talkPet) Net::getChatHandler()->talk(args, GENERAL_CHANNEL); } + +struct UploadChatInfo +{ + UploadChatInfo() : + tab(nullptr), + upload(nullptr), + text(), + addStr() + { } + + ChatTab *tab; + Net::Download *upload; + std::string text; + std::string addStr; +}; + +static int uploadUpdate(void *ptr, + DownloadStatus status, + size_t total A_UNUSED, + size_t remaining A_UNUSED) +{ + if (status == DOWNLOAD_STATUS_IDLE || status == DOWNLOAD_STATUS_STARTING) + return 0; + + UploadChatInfo *const info = reinterpret_cast<UploadChatInfo*>(ptr); + if (status == DOWNLOAD_STATUS_COMPLETE) + { + ChatTab *const tab = info->tab; + if (chatWindow && (!tab || chatWindow->isTabPresent(tab))) + { + std::string str = Net::Download::getUploadResponse(); + const int sz = str.size(); + if (sz > 0) + { + if (str[sz - 1] == '\n') + str = str.substr(0, sz - 1); + str.append(info->addStr); + str = strprintf("%s [@@%s |%s@@]", + info->text.c_str(), str.c_str(), str.c_str()); + outStringNormal(tab, str, str); + } + } + } + delete info->upload; + info->upload = nullptr; + delete info; + return 0; +} + +static void uploadFile(const std::string &str, + const std::string &fileName, + const std::string &addStr) +{ + UploadChatInfo *const info = new UploadChatInfo(); + Net::Download *const upload = new Net::Download(info, + "http://sprunge.us", + &uploadUpdate, + false, true); + info->upload = upload; + info->text = str; + info->addStr = addStr; + upload->setFile(fileName); + upload->start(); +} + +impHandler0(uploadConfig) +{ + uploadFile(_("Uploaded config into:"), + config.getFileName(), + "?xml"); +} + impHandler0(testsdlfont) { #if defined USE_OPENGL && defined DEBUG_SDLFONT |