From 087babc2525ddb89e5b31f240a08739d9a3029a9 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 11 Jan 2010 18:52:23 +0200 Subject: Improve chat speed. For improve chat speed this patch add some hacks to BrowserBox class, split big words in ChatTab. Also fix DoS in chat. --- src/gui/widgets/chattab.cpp | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'src/gui/widgets/chattab.cpp') diff --git a/src/gui/widgets/chattab.cpp b/src/gui/widgets/chattab.cpp index 6a915e5b..1701cbd3 100644 --- a/src/gui/widgets/chattab.cpp +++ b/src/gui/widgets/chattab.cpp @@ -42,6 +42,8 @@ #include +#define MAX_WORD_SIZE 50 + ChatTab::ChatTab(const std::string &name) : Tab() { setCaption(name); @@ -181,12 +183,12 @@ void ChatTab::chatLog(std::string line, int own, bool ignoreRecord) // at comparison. if (mScrollArea->getVerticalScrollAmount() >= mScrollArea->getVerticalMaxScroll()) { - mTextOutput->addRow(line); + addRow(line); mScrollArea->setVerticalScrollAmount(mScrollArea->getVerticalMaxScroll()); } else { - mTextOutput->addRow(line); + addRow(line); } mScrollArea->logic(); @@ -275,3 +277,22 @@ int ChatTab::getType() const { return INPUT; } + +void ChatTab::addRow(std::string &line) +{ + std::string::size_type idx = 0; + + for (unsigned int f = 0; f < line.length(); f++) + { + if (line.at(f) == ' ') + { + idx = f; + } + else if (f - idx > MAX_WORD_SIZE) + { + line.insert(f, " "); + idx = f; + } + } + mTextOutput->addRow(line); +} -- cgit v1.2.3-70-g09d2