summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2011-06-01 03:03:12 +0300
committerAndrei Karas <akaras@inbox.ru>2011-06-01 03:07:13 +0300
commit09ebcebf32be3842d6158c3145492fbf2959440e (patch)
tree44970b335330ca56ab38d06f083fa005f1c53ca5 /src
parentfdb8081a82ec85c9ff23a89a82f81240d8bcaec9 (diff)
downloadManaVerse-09ebcebf32be3842d6158c3145492fbf2959440e.tar.gz
ManaVerse-09ebcebf32be3842d6158c3145492fbf2959440e.tar.bz2
ManaVerse-09ebcebf32be3842d6158c3145492fbf2959440e.tar.xz
ManaVerse-09ebcebf32be3842d6158c3145492fbf2959440e.zip
Add setup option for finding bad chars in nicks.
Highlight bad nicks on map with secure font.
Diffstat (limited to 'src')
-rw-r--r--src/actorspritemanager.cpp1
-rw-r--r--src/being.cpp5
-rw-r--r--src/being.h7
-rw-r--r--src/defaults.cpp1
-rw-r--r--src/gui/gui.cpp6
-rw-r--r--src/gui/setup_other.cpp9
-rw-r--r--src/gui/setup_players.cpp53
-rw-r--r--src/gui/setup_players.h8
-rw-r--r--src/playerrelations.cpp27
-rw-r--r--src/playerrelations.h2
10 files changed, 104 insertions, 15 deletions
diff --git a/src/actorspritemanager.cpp b/src/actorspritemanager.cpp
index 1b2e0c2e8..78cfa256b 100644
--- a/src/actorspritemanager.cpp
+++ b/src/actorspritemanager.cpp
@@ -1128,6 +1128,7 @@ void ActorSpriteManager::updatePlayerNames()
}
Being *being = static_cast<Being*>(*it);
+ being->setGoodStatus(-1);
if (being->getType() == ActorSprite::PLAYER && being->getName() != "")
being->updateName();
}
diff --git a/src/being.cpp b/src/being.cpp
index 27b4721b4..e38e60026 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -208,6 +208,7 @@ Being::Being(int id, Type type, Uint16 subtype, Map *map):
mHP(0), mMaxHP(0),
mDistance(0),
mIsReachable(REACH_UNKNOWN),
+ mGoodStatus(-1),
mErased(false),
mEnemy(false),
mIp(""),
@@ -1489,6 +1490,10 @@ void Being::showName()
{
font = boldFont;
}
+ else if (getType() == PLAYER && !player_relations.isGoodName(this) && gui)
+ {
+ font = gui->getSecureFont();
+ }
mDispName = new FlashText(mDisplayName, getPixelX(), getPixelY(),
gcn::Graphics::CENTER, mNameColor, font);
diff --git a/src/being.h b/src/being.h
index 1f0d318f3..3313f40ba 100644
--- a/src/being.h
+++ b/src/being.h
@@ -715,6 +715,12 @@ class Being : public ActorSprite, public ConfigListener
void undressItemById(int id);
+ int getGoodStatus()
+ { return mGoodStatus; }
+
+ void setGoodStatus(int n)
+ { mGoodStatus = n; }
+
static void clearCache();
protected:
@@ -820,6 +826,7 @@ class Being : public ActorSprite, public ConfigListener
int mMaxHP;
int mDistance;
int mIsReachable; /**< 0 - unknown, 1 - reachable, 2 - not reachable*/
+ int mGoodStatus;
static int mUpdateConfigTime;
static unsigned int mConfLineLim;
diff --git a/src/defaults.cpp b/src/defaults.cpp
index 833c64bc2..cb5c0011c 100644
--- a/src/defaults.cpp
+++ b/src/defaults.cpp
@@ -201,6 +201,7 @@ DefaultsData* getConfigDefaults()
AddDEF(configData, "hideChatInput", true);
AddDEF(configData, "enableAttackFilter", true);
AddDEF(configData, "securetrades", true);
+ AddDEF(configData, "unsecureChars", "IO0@#$");
return configData;
}
diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp
index 6651a01d5..51d2f9adf 100644
--- a/src/gui/gui.cpp
+++ b/src/gui/gui.cpp
@@ -330,6 +330,12 @@ void Gui::updateFonts()
fontFile = branding.getStringValue("boldFont");
static_cast<SDLFont*>(boldFont)->loadFont(fontFile, fontSize);
+
+ fontFile = config.getValue("secureFont", "");
+ if (fontFile.empty())
+ fontFile = branding.getStringValue("secureFont");
+
+ static_cast<SDLFont*>(mSecureFont)->loadFont(fontFile, fontSize);
}
void Gui::distributeMouseEvent(gcn::Widget* source, int type, int button,
diff --git a/src/gui/setup_other.cpp b/src/gui/setup_other.cpp
index 311a06bb5..7ddc89e67 100644
--- a/src/gui/setup_other.cpp
+++ b/src/gui/setup_other.cpp
@@ -280,7 +280,7 @@ void Setup_Other::action(const gcn::ActionEvent &event)
}
else if (event.getId() == ACTION_EDIT_PROGRAM)
{
- mEditDialog = new EditDialog("Crazy Move A",
+ mEditDialog = new EditDialog(_("Crazy Move A"),
mMoveProgramField->getText(), ACTION_EDIT_PROGRAM_OK);
mEditDialog->addActionListener(this);
}
@@ -288,12 +288,13 @@ void Setup_Other::action(const gcn::ActionEvent &event)
{
mMoveProgramField->setText(mEditDialog->getMsg());
}
-
else if (event.getId() == ACTION_AFK)
- mAfk = mAfkField->getText();
+ {
+ mAfk = mAfkField->getText();
+ }
else if (event.getId() == ACTION_EDIT_AFK)
{
- mEditDialog = new EditDialog("Afk message", mAfkField->getText(),
+ mEditDialog = new EditDialog(_("Afk message"), mAfkField->getText(),
ACTION_EDIT_AFK_OK);
mEditDialog->addActionListener(this);
}
diff --git a/src/gui/setup_players.cpp b/src/gui/setup_players.cpp
index e071eee73..2795ce223 100644
--- a/src/gui/setup_players.cpp
+++ b/src/gui/setup_players.cpp
@@ -27,6 +27,7 @@
#include "localplayer.h"
#include "log.h"
+#include "gui/editdialog.h"
#include "gui/okdialog.h"
#include "gui/widgets/button.h"
@@ -36,6 +37,7 @@
#include "gui/widgets/layouthelper.h"
#include "gui/widgets/scrollarea.h"
#include "gui/widgets/table.h"
+#include "gui/widgets/textfield.h"
#include "utils/dtor.h"
#include "utils/gettext.h"
@@ -232,6 +234,9 @@ public:
#define ACTION_TARGET_DEAD "target dead"
#define ACTION_SHOW_OWN_NAME "show own name"
#define ACTION_SECURE_TRADES "secure trades"
+#define ACTION_UNSECURE "unsecure"
+#define ACTION_EDIT_UNSECURE "edit unsecure"
+#define ACTION_EDIT_UNSECURE_OK "edit unsecure ok"
Setup_Players::Setup_Players():
mPlayerTableTitleModel(new StaticTableModel(1, COLUMNS_NR)),
@@ -253,7 +258,9 @@ Setup_Players::Setup_Players():
mShowLevel(config.getBoolValue("showlevel")),
mShowOwnName(config.getBoolValue("showownname")),
mTargetDead(config.getBoolValue("targetDeadPlayers")),
- mSecureTrades(config.getBoolValue("securetrades"))
+ mSecureTrades(config.getBoolValue("securetrades")),
+ mUnsecureChars(config.getStringValue("unsecureChars")),
+ mEditDialog(0)
{
setName(_("Players"));
@@ -319,26 +326,34 @@ Setup_Players::Setup_Players():
mSecureTradesCheckBox->setActionEventId(ACTION_SECURE_TRADES);
mSecureTradesCheckBox->addActionListener(this);
+ mUnsecureCharsLabel = new Label(_("Unsecure chars in names"));
+ mUnsecureCharsField = new TextField(mUnsecureChars,
+ true, this, ACTION_UNSECURE);
+ mUnsecureCharsButton = new Button(_("Edit"), ACTION_EDIT_UNSECURE, this);
+
reset();
// Do the layout
LayoutHelper h(this);
ContainerPlacer place = h.getPlacer(0, 0);
- place(0, 0, mPlayerTitleTable, 5);
- place(0, 1, mPlayerScrollArea, 5, 4).setPadding(2);
+ place(0, 0, mPlayerTitleTable, 6);
+ place(0, 1, mPlayerScrollArea, 6, 4).setPadding(2);
place(0, 5, mDeleteButton);
place(0, 6, mShowGenderCheckBox, 3).setPadding(2);
place(0, 7, mShowLevelCheckBox, 3).setPadding(2);
place(0, 8, mShowOwnNameCheckBox, 3).setPadding(2);
place(1, 5, mOldButton, 1);
- place(3, 5, ignore_action_label);
- place(3, 6, mIgnoreActionChoicesBox, 2).setPadding(2);
- place(3, 7, mDefaultTrading, 2);
- place(3, 8, mDefaultWhisper, 2);
- place(3, 9, mSecureTradesCheckBox, 2);
- place(0, 9, mWhisperTabCheckBox, 4).setPadding(4);
- place(0, 10, mTargetDeadCheckBox, 4).setPadding(4);
+ place(3, 5, ignore_action_label, 1);
+ place(4, 5, mIgnoreActionChoicesBox, 2).setPadding(2);
+ place(3, 6, mDefaultTrading, 3);
+ place(3, 7, mDefaultWhisper, 3);
+ place(3, 8, mSecureTradesCheckBox, 3);
+ place(3, 9, mUnsecureCharsLabel, 3);
+ place(3, 10, mUnsecureCharsField, 2);
+ place(5, 10, mUnsecureCharsButton, 1);
+ place(0, 9, mWhisperTabCheckBox, 3).setPadding(4);
+ place(0, 10, mTargetDeadCheckBox, 3).setPadding(4);
player_relations.addListener(this);
@@ -391,6 +406,7 @@ void Setup_Players::apply()
config.setValue("targetDeadPlayers", mTargetDead);
config.setValue("showgender", mShowGender);
config.setValue("securetrades", mSecureTrades);
+ config.setValue("unsecureChars", mUnsecureCharsField->getText());
if (actorSpriteManager)
actorSpriteManager->updatePlayerNames();
@@ -413,6 +429,8 @@ void Setup_Players::cancel()
mTargetDeadCheckBox->setSelected(mTargetDead);
mSecureTrades = config.getBoolValue("securetrades");
mSecureTradesCheckBox->setSelected(mSecureTrades);
+ mUnsecureChars = config.getStringValue("unsecureChars");
+ mUnsecureCharsField->setText(mUnsecureChars);
}
void Setup_Players::action(const gcn::ActionEvent &event)
@@ -480,9 +498,22 @@ void Setup_Players::action(const gcn::ActionEvent &event)
{
mSecureTrades = mSecureTradesCheckBox->isSelected();
}
+ else if (event.getId() == ACTION_EDIT_UNSECURE)
+ {
+ mEditDialog = new EditDialog(_("Unsecure chars in names"),
+ mUnsecureCharsField->getText(), ACTION_EDIT_UNSECURE_OK);
+ mEditDialog->addActionListener(this);
+ }
+ else if (event.getId() == ACTION_EDIT_UNSECURE_OK)
+ {
+ mUnsecureCharsField->setText(mEditDialog->getMsg());
+ }
+ else if (event.getId() == ACTION_UNSECURE)
+ {
+ mUnsecureChars = mUnsecureCharsField->getText();
+ }
}
-
void Setup_Players::updatedPlayer(const std::string &name _UNUSED_)
{
mPlayerTableModel->playerRelationsUpdated();
diff --git a/src/gui/setup_players.h b/src/gui/setup_players.h
index 64561ed91..afc902f1b 100644
--- a/src/gui/setup_players.h
+++ b/src/gui/setup_players.h
@@ -36,6 +36,7 @@
#define _UNUSED_
#endif
+class EditDialog;
class GuiTable;
class PlayerTableModel;
class StaticTableModel;
@@ -94,6 +95,13 @@ private:
bool mSecureTrades;
gcn::CheckBox *mSecureTradesCheckBox;
+
+ gcn::Label *mUnsecureCharsLabel;
+ gcn::TextField *mUnsecureCharsField;
+ gcn::Button *mUnsecureCharsButton;
+ std::string mUnsecureChars;
+
+ EditDialog *mEditDialog;
};
#endif
diff --git a/src/playerrelations.cpp b/src/playerrelations.cpp
index f41ea5e4d..87318ff43 100644
--- a/src/playerrelations.cpp
+++ b/src/playerrelations.cpp
@@ -494,5 +494,32 @@ PlayerRelationsManager::getPlayerIgnoreStrategies()
return &mIgnoreStrategies;
}
+bool PlayerRelationsManager::isGoodName(Being *being)
+{
+ bool status(false);
+
+ if (!being)
+ return false;
+ if (being->getGoodStatus() != -1)
+ return (being->getGoodStatus() == 1);
+
+ const std::string name = being->getName();
+ const int size = name.size();
+ std::string check = config.getStringValue("unsecureChars");
+
+ if (size < 3 || mRelations[name])
+ return true;
+ else if (name.substr(0, 1) == " " || name.substr(size - 1, 1) == " ")
+ status = false;
+ else if (check.empty())
+ status = true;
+ else if (name.find_first_of(check) != std::string::npos)
+ status = false;
+ else
+ status = true;
+
+ being->setGoodStatus(status ? 1 : 0);
+ return status;
+}
PlayerRelationsManager player_relations;
diff --git a/src/playerrelations.h b/src/playerrelations.h
index 1b4204a62..b4ef6dd45 100644
--- a/src/playerrelations.h
+++ b/src/playerrelations.h
@@ -217,6 +217,8 @@ class PlayerRelationsManager
void ignoreTrade(std::string name);
+ bool isGoodName(Being *being);
+
/**
* Change the `ignore persist' flag.
*