summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-01-26 21:45:57 +0300
committerAndrei Karas <akaras@inbox.ru>2014-01-26 22:01:51 +0300
commit5889bd94d241b8454268804861a67c79315a7731 (patch)
treeb37aaec28083110308fbbc5fa3a2c4bb07ce2ed7 /src
parentbae784c3718b2d28bef80ef57f23c47cc4342c64 (diff)
downloadplus-5889bd94d241b8454268804861a67c79315a7731.tar.gz
plus-5889bd94d241b8454268804861a67c79315a7731.tar.bz2
plus-5889bd94d241b8454268804861a67c79315a7731.tar.xz
plus-5889bd94d241b8454268804861a67c79315a7731.zip
add chat command for uploading main config.xml
New chat command: /uploadconfig
Diffstat (limited to 'src')
-rw-r--r--src/client.cpp6
-rw-r--r--src/client.h4
-rw-r--r--src/commands.cpp78
-rw-r--r--src/commands.h3
-rw-r--r--src/configuration.h3
-rw-r--r--src/gui/widgets/tabbedarea.cpp10
-rw-r--r--src/gui/widgets/tabbedarea.h4
-rw-r--r--src/gui/windows/chatwindow.cpp5
-rw-r--r--src/gui/windows/chatwindow.h2
-rw-r--r--src/net/download.cpp13
-rw-r--r--src/net/download.h5
11 files changed, 119 insertions, 14 deletions
diff --git a/src/client.cpp b/src/client.cpp
index 289b4df0b..13835c938 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -226,6 +226,7 @@ Client::Client(const Options &options) :
mRootDir(),
mServerName(),
mOnlineListUrl(),
+ mLogFileName(),
mCurrentServer(),
mGame(nullptr),
mCurrentDialog(nullptr),
@@ -293,9 +294,10 @@ void Client::gameInit()
// Configure logger
if (!mOptions.logFileName.empty())
- logger->setLogFile(mOptions.logFileName);
+ mLogFileName = mOptions.logFileName;
else
- logger->setLogFile(mLocalDataDir + "/manaplus.log");
+ mLogFileName = mLocalDataDir + "/manaplus.log";
+ logger->setLogFile(mLogFileName);
#ifdef USE_FUZZER
Fuzzer::init();
diff --git a/src/client.h b/src/client.h
index c166b438b..7a88c6734 100644
--- a/src/client.h
+++ b/src/client.h
@@ -272,6 +272,9 @@ public:
std::string getSupportUrl() const A_WARN_UNUSED
{ return mCurrentServer.supportUrl; }
+ std::string getLogFileName() const A_WARN_UNUSED
+ { return mLogFileName; }
+
bool isKeyboardVisible() const;
void setGuiAlpha(const float n)
@@ -406,6 +409,7 @@ private:
std::string mRootDir;
std::string mServerName;
std::string mOnlineListUrl;
+ std::string mLogFileName;
ServerInfo mCurrentServer;
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
diff --git a/src/commands.h b/src/commands.h
index 37e4b8215..1a28f9fa7 100644
--- a/src/commands.h
+++ b/src/commands.h
@@ -130,6 +130,7 @@ namespace Commands
decHandler(createItems);
decHandler(talkRaw);
decHandler(talkPet);
+ decHandler(uploadConfig);
void replaceVars(std::string &str);
} // namespace Commands
@@ -227,6 +228,7 @@ enum
COMMAND_CREATEITEMS,
COMMAND_TALKRAW,
COMMAND_TALKPET,
+ COMMAND_UPLOADCONFIG,
COMMAND_HACK,
END_COMMANDS
};
@@ -324,6 +326,7 @@ static const CommandInfo commands[] =
{"createitems", &Commands::createItems, -1, false},
{"talkraw", &Commands::talkRaw, -1, true},
{"talkpet", &Commands::talkPet, -1, true},
+ {"uploadconfig", &Commands::uploadConfig, -1, false},
{"hack", &Commands::hack, -1, true}
};
diff --git a/src/configuration.h b/src/configuration.h
index 322d4c934..daa10f51b 100644
--- a/src/configuration.h
+++ b/src/configuration.h
@@ -343,6 +343,9 @@ class Configuration final : public ConfigurationObject
void removeOldKeys();
+ std::string getFileName() const A_WARN_UNUSED
+ { return mFilename; }
+
private:
/**
* Clean up the default values member.
diff --git a/src/gui/widgets/tabbedarea.cpp b/src/gui/widgets/tabbedarea.cpp
index 70e098cd3..da6c89d1a 100644
--- a/src/gui/widgets/tabbedarea.cpp
+++ b/src/gui/widgets/tabbedarea.cpp
@@ -236,6 +236,16 @@ bool TabbedArea::isTabSelected(const unsigned int index) const
return mSelectedTab == mTabs[index].first;
}
+bool TabbedArea::isTabPresent(const Tab *const tab) const
+{
+ FOR_EACH (TabContainer::const_iterator, it, mTabs)
+ {
+ if ((*it).first == tab || (*it).second == tab)
+ return true;
+ }
+ return false;
+}
+
bool TabbedArea::isTabSelected(const Tab *const tab) const
{
return mSelectedTab == tab;
diff --git a/src/gui/widgets/tabbedarea.h b/src/gui/widgets/tabbedarea.h
index 37950e204..eaac7a6d5 100644
--- a/src/gui/widgets/tabbedarea.h
+++ b/src/gui/widgets/tabbedarea.h
@@ -104,6 +104,8 @@ class TabbedArea final : public Widget2,
bool isTabSelected(const Tab *const tab) const A_WARN_UNUSED;
+ bool isTabPresent(const Tab *const tab) const A_WARN_UNUSED;
+
/**
* Overload the remove tab function as it's broken in guichan 0.8.
*/
@@ -206,7 +208,7 @@ class TabbedArea final : public Widget2,
gcn::Container* mTabContainer;
gcn::Container* mWidgetContainer;
std::vector<Tab*> mTabsToDelete;
- std::vector<std::pair<Tab*, gcn::Widget*> > mTabs;
+ TabContainer mTabs;
/**
* The overall width of all tab.
diff --git a/src/gui/windows/chatwindow.cpp b/src/gui/windows/chatwindow.cpp
index b9a2592fa..62a032341 100644
--- a/src/gui/windows/chatwindow.cpp
+++ b/src/gui/windows/chatwindow.cpp
@@ -1949,3 +1949,8 @@ void ChatWindow::addGlobalMessage(const std::string &line)
else
localChatTab->chatLog(line, BY_GM);
}
+
+bool ChatWindow::isTabPresent(const ChatTab *const tab) const
+{
+ return mChatTabs->isTabPresent(tab);
+}
diff --git a/src/gui/windows/chatwindow.h b/src/gui/windows/chatwindow.h
index 014eceb5a..c000215f1 100644
--- a/src/gui/windows/chatwindow.h
+++ b/src/gui/windows/chatwindow.h
@@ -292,6 +292,8 @@ class ChatWindow final : public Window,
void postInit() override final;
+ bool isTabPresent(const ChatTab *const tab) const A_WARN_UNUSED;
+
static void localPetSay(const std::string &nick,
const std::string &text);
diff --git a/src/net/download.cpp b/src/net/download.cpp
index 22f5d9aa4..2abffba0c 100644
--- a/src/net/download.cpp
+++ b/src/net/download.cpp
@@ -58,7 +58,7 @@ enum
namespace Net
{
-std::string Download::mUploadRssponse = "";
+std::string Download::mUploadResponse = "";
Download::Download(void *const ptr, const std::string &url,
const DownloadUpdate updateFunction,
@@ -228,10 +228,7 @@ int Download::downloadProgress(void *clientp, double dltotal, double dlnow,
Download *const d = reinterpret_cast<Download *const>(clientp);
if (!d)
- {
- logger->log("downloadProgress error");
return -5;
- }
if (d->mUpload)
return 0;
@@ -295,7 +292,7 @@ int Download::downloadThread(void *ptr)
curl_easy_setopt(d->mCurl, CURLOPT_HTTPPOST, d->mFormPost);
curl_easy_setopt(d->mCurl, CURLOPT_WRITEFUNCTION,
&Download::writeFunction);
- mUploadRssponse.clear();
+ mUploadResponse.clear();
}
else
{
@@ -457,6 +454,8 @@ int Download::downloadThread(void *ptr)
attempts++;
}
+ d->mThread = nullptr;
+
if (d->mOptions.cancel)
{
// Nothing to do...
@@ -470,7 +469,6 @@ int Download::downloadThread(void *ptr)
d->mUpdateFunction(d->mPtr, DOWNLOAD_STATUS_COMPLETE, 0, 0);
}
- d->mThread = nullptr;
return 0;
}
@@ -569,8 +567,7 @@ size_t Download::writeFunction(void *ptr, size_t size,
char *buf = new char[totalMem + 1];
memcpy(buf, ptr, totalMem);
buf[totalMem] = 0;
- mUploadRssponse.append(buf);
- logger->log("data: %s", buf);
+ mUploadResponse.append(buf);
return totalMem;
}
diff --git a/src/net/download.h b/src/net/download.h
index f5b886053..bc06f1974 100644
--- a/src/net/download.h
+++ b/src/net/download.h
@@ -106,12 +106,15 @@ class Download final
static unsigned long adlerBuffer(char *buffer, int size);
+ static std::string getUploadResponse()
+ { return mUploadResponse; }
+
private:
static int downloadThread(void *ptr);
static int downloadProgress(void *clientp, double dltotal,
double dlnow, double ultotal,
double ulnow);
- static std::string mUploadRssponse;
+ static std::string mUploadResponse;
void *mPtr;
std::string mUrl;
struct