吾爱尚玩资源基地

标题: T端中带时间间隔限制和聊天字符限制的世界喊话系统 [打印本页]

作者: admin    时间: 2016-4-24 18:03
标题: T端中带时间间隔限制和聊天字符限制的世界喊话系统
这个是一个Trinity端的设计公告系统,该系统与其他的世界公告不同的地方在于:
1、可以限制每次世界喊话后,下次喊话的时间间隔。这样就不会出现玩家刷屏的情况

2、限制每次世界喊话最少的字符数量。

参考意义:可以通过该代码,获得时间间隔怎么设置和控制字符数量的配置



---
src/server/game/World/World.cpp              |   5 ++
src/server/game/World/World.h                |   3 +
src/server/scripts/Custom/CMakeLists.txt     |   1 +
src/server/scripts/Custom/World_Chat.cpp     | 119 +++++++++++++++++++++++++++
src/server/worldserver/worldserver.conf.dist |  24 ++++++
5 files changed, 152 insertions(+)
create mode 100644 src/server/scripts/Custom/World_Chat.cpp

diff --git a/src/server/game/World/World.cpp b/src/server/game/World/World.cpp
index ec11a29..a627a90 100644
--- a/src/server/game/World/World.cpp
+++ b/src/server/game/World/World.cpp
@@ -1221,6 +1221,11 @@ void World::LoadConfigSettings(bool reload)
     m_int_configs[CONFIG_WINTERGRASP_NOBATTLETIME] = ConfigMgr::GetIntDefault("Wintergrasp.NoBattleTimer", 150);
     m_int_configs[CONFIG_WINTERGRASP_RESTART_AFTER_CRASH] = ConfigMgr::GetIntDefault("Wintergrasp.CrashRestartTimer", 10);

+    // World Chat
+    m_bool_configs[CONFIG_WORLD_CHAT_ENABLE] = ConfigMgr::GetBoolDefault("World_Chat.Enable", false);
+    m_int_configs[CONFIG_WORLD_CHAT_MINLENGTH] = ConfigMgr::GetIntDefault("World_Chat.MinLength", 0);
+    m_int_configs[CONFIG_WORLD_CHAT_MUTETIME] = ConfigMgr::GetIntDefault("World_Chat.MuteTime", 0);
+
     // call ScriptMgr if we're reloading the configuration
     if (reload)
         sScriptMgr->OnConfigLoad(reload);
diff --git a/src/server/game/World/World.h b/src/server/game/World/World.h
index 00bb9e7..2f97dd7 100644
--- a/src/server/game/World/World.h
+++ b/src/server/game/World/World.h
@@ -159,6 +159,7 @@ enum WorldBoolConfigs
     CONFIG_WINTERGRASP_ENABLE,
     CONFIG_UI_QUESTLEVELS_IN_DIALOGS,     // Should we add quest levels to the title in the NPC dialogs?
     CONFIG_EVENT_ANNOUNCE,
+    CONFIG_WORLD_CHAT_ENABLE,
     BOOL_CONFIG_VALUE_COUNT
};

@@ -320,6 +321,8 @@ enum WorldIntConfigs
     CONFIG_WINTERGRASP_BATTLETIME,
     CONFIG_WINTERGRASP_NOBATTLETIME,
     CONFIG_WINTERGRASP_RESTART_AFTER_CRASH,
+    CONFIG_WORLD_CHAT_MINLENGTH,
+    CONFIG_WORLD_CHAT_MUTETIME,
     INT_CONFIG_VALUE_COUNT
};

diff --git a/src/server/scripts/Custom/CMakeLists.txt b/src/server/scripts/Custom/CMakeLists.txt
index 99cf026..daf48e6 100644
--- a/src/server/scripts/Custom/CMakeLists.txt
+++ b/src/server/scripts/Custom/CMakeLists.txt
@@ -10,6 +10,7 @@

set(scripts_STAT_SRCS
   ${scripts_STAT_SRCS}
+Custom/World_Chat.cpp
)

message("  -> Prepared: Custom")
diff --git a/src/server/scripts/Custom/World_Chat.cpp b/src/server/scripts/Custom/World_Chat.cpp
new file mode 100644
index 0000000..38af933
--- /dev/null
+++ b/src/server/scripts/Custom/World_Chat.cpp
@@ -0,0 +1,119 @@
+/*
+
+By: @mthsena
+
+Script made by: @Ghostcrawler336
+Rewrote and improved by: @AlexeWarr
+
+*/
+#include "ScriptPCH.h"
+#include "Chat.h"
+
+// Ranks
+#define PLAYER                "<Player>"
+#define MODERATOR            "<MOD>"
+#define GAMEMASTER            "<GM>"
+#define ADMINISTRATOR        "<ADM>"
+#define CONSOLE                "<OWNER>"
+// Colors
+#define MSG_COLOR_WHITE        "|cffffffff"
+#define MSG_COLOR_CHAT        "|cff0bf10a"
+#define MSG_COLOR_MSG        "|cff4387c4"
+#define MSG_COLOR_PLAYER    "|cff00ffff"
+#define MSG_COLOR_MOD        "|cffffc800"
+#define MSG_COLOR_GM        "|cffff5f00"
+#define MSG_COLOR_ADM        "|cffff3c00"
+#define MSG_COLOR_OWNER        "|cffFF0000"
+
+void _SendWorldChat(Player* player, std::string message)
+{
+    std::string rank, color;
+    std::ostringstream chat_string;
+
+    switch(player->GetSession()->GetSecurity())
+    {
+    case SEC_PLAYER:
+        rank = PLAYER;
+        color = MSG_COLOR_PLAYER;
+        break;
+    case SEC_MODERATOR:   
+        rank = MODERATOR;
+        color = MSG_COLOR_MOD;
+        break;
+    case SEC_GAMEMASTER:
+        rank = GAMEMASTER;
+        color = MSG_COLOR_GM;
+        break;
+    case SEC_ADMINISTRATOR:
+        rank = ADMINISTRATOR;
+        color = MSG_COLOR_ADM;
+        break;
+    case SEC_CONSOLE:
+        rank = CONSOLE;
+        color = MSG_COLOR_OWNER;
+        break;
+    }
+
+    chat_string << color << rank << MSG_COLOR_WHITE << " " << ChatHandler(player->GetSession()).GetNameLink() << " " << MSG_COLOR_CHAT << "Chat: " << MSG_COLOR_MSG << message;
+
+    char msg[1024];
+
+    snprintf(msg, 1024, chat_string.str().c_str());
+
+    if(message.length() >= sWorld->getIntConfig(CONFIG_WORLD_CHAT_MINLENGTH))//这里就是判断字符的长度了
+    {
+        sWorld->SendGlobalText(msg, NULL);
+        if(sWorld->getIntConfig(CONFIG_WORLD_CHAT_MUTETIME) > 0) //这里开始设置每次喊话的时间间隔了
+        {
+            PreparedStatement * mt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_MUTE_TIME);
+            int64 muteTime = time(NULL) + sWorld->getIntConfig(CONFIG_WORLD_CHAT_MUTETIME);
+            player->GetSession()->m_muteTime = muteTime;
+            mt->setInt64(0, muteTime);
+        }
+    }
+    else
+        player->GetSession()->SendNotification("Your message has to be at least %d characters longer", sWorld->getIntConfig(CONFIG_WORLD_CHAT_MINLENGTH));
+
+}
+
+class World_Chat : public CommandScript
+{
+public:
+    World_Chat() : CommandScript("World_Chat"){}
+
+    static bool HandleWorldChatCommand(ChatHandler * pChat, const char * msg)
+    {
+        if (!sWorld->getBoolConfig(CONFIG_WORLD_CHAT_ENABLE))
+        {
+            pChat->PSendSysMessage("World Chat is disabled.");
+            pChat->SetSentErrorMessage(true);
+            return false;
+        }
+
+        if(!*msg)
+            return false;
+
+        Player* pPlayer = pChat->GetSession()->GetPlayer();
+
+        if (!pChat->GetSession()->GetPlayer()->CanSpeak())
+            return false;
+
+        _SendWorldChat(pChat->GetSession()->GetPlayer(), msg);
+        return true;
+    }
+
+    ChatCommand * GetCommands() const
+    {
+        static ChatCommand World_ChatCommandTable[] =
+        {
+            {"chat", SEC_PLAYER, true, &HandleWorldChatCommand, "", NULL},
+            {NULL, 0, false, NULL, "", NULL}
+        };
+        return World_ChatCommandTable;
+    }
+};
+
+void AddSC_World_Chat()
+{
+    new World_Chat;
+}
\ No newline at end of file
diff --git a/src/server/worldserver/worldserver.conf.dist b/src/server/worldserver/worldserver.conf.dist
index bf19240..4765836 100644
--- a/src/server/worldserver/worldserver.conf.dist
+++ b/src/server/worldserver/worldserver.conf.dist
@@ -27,6 +27,7 @@
#    CHARACTER DELETE OPTIONS
#    CUSTOM SERVER OPTIONS
#    LOGGING SYSTEM SETTINGS
+#    WORLD CHAT
#
###################################################################################################

@@ -2760,3 +2761,26 @@ Log.Async.Enable = 0

#
###################################################################################################
+
+###################################################################################################
+# WORLD CHAT
+#
+#    World_Chat.Enable
+#          Description: Enables the script World_Chat on server.   (这个地方就是控制是否开启世界喊话)
+#          Default:     0 - (Disabled)
+#                       1 - (Enabled)
+#    World_Chat.MinLength
+#          Description: Minimum characters to use the chat.  (每次世界喊话输入的最少的字符数)
+#                       Example: if 1, will need at least 1 character. (如果设置1,那么最少1个字符)
+#    World_Chat.MuteTime
+#          Description: MuteTime(in seconds) after use the chat, avoids the flood.(设置每次喊话的时间间隔。避免刷频)
+#          Default:     0 - (Disabled)
+#                       Example: if 1, will get 1 second mutetime.
+
+World_Chat.Enable = 1
+World_Chat.MinLength = 3
+World_Chat.MuteTime = 5
+
+#
+###################################################################################################
--
1.8.1.msysgit.1



OK,。代码就到这里。下面提供一个下载。。有些解释我已经些到代码里面了。其他的请大家自己看看


回复下载完整代码





作者: 我回来了    时间: 2016-10-29 21:26
小白一个 顶一下,吾爱尚玩免费服务端下载!
作者: 12333    时间: 2019-12-19 00:39
支持吾爱 支持吾爱 支持吾爱 支持吾爱 支持吾爱 支持吾爱




欢迎光临 吾爱尚玩资源基地 (http://bbs.523play.com/) Powered by Discuz! X3.4