浏览代码

IRCClient: Allow CTCP replies to be user configurable in IRCClient.ini

Brendan Coles 5 年之前
父节点
当前提交
ddb8597c0c
共有 3 个文件被更改,包括 36 次插入1 次删除
  1. 23 1
      Applications/IRCClient/IRCClient.cpp
  2. 8 0
      Applications/IRCClient/IRCClient.h
  3. 5 0
      Base/home/anon/IRCClient.ini

+ 23 - 1
Applications/IRCClient/IRCClient.cpp

@@ -75,6 +75,9 @@ IRCClient::IRCClient()
     m_nickname = m_config->read_entry("User", "Nickname", "seren1ty");
     m_nickname = m_config->read_entry("User", "Nickname", "seren1ty");
     m_hostname = m_config->read_entry("Connection", "Server", "");
     m_hostname = m_config->read_entry("Connection", "Server", "");
     m_port = m_config->read_num_entry("Connection", "Port", 6667);
     m_port = m_config->read_num_entry("Connection", "Port", 6667);
+    m_ctcp_version_reply = m_config->read_entry("CTCP", "VersionReply", "IRC Client [x86] / Serenity OS");
+    m_ctcp_userinfo_reply = m_config->read_entry("CTCP", "UserInfoReply", "anon");
+    m_ctcp_finger_reply = m_config->read_entry("CTCP", "FingerReply", "anon");
 }
 }
 
 
 IRCClient::~IRCClient()
 IRCClient::~IRCClient()
@@ -1056,7 +1059,26 @@ void IRCClient::handle_ctcp_request(const StringView& peer, const StringView& pa
     dbg() << "handle_ctcp_request: " << payload;
     dbg() << "handle_ctcp_request: " << payload;
 
 
     if (payload == "VERSION") {
     if (payload == "VERSION") {
-        send_ctcp_response(peer, "VERSION IRC Client [x86] / Serenity OS");
+        auto version = ctcp_version_reply();
+        if (version.is_empty())
+            return;
+        send_ctcp_response(peer, String::format("VERSION %s", version.characters()));
+        return;
+    }
+
+    if (payload == "USERINFO") {
+        auto userinfo = ctcp_userinfo_reply();
+        if (userinfo.is_empty())
+            return;
+        send_ctcp_response(peer, String::format("USERINFO %s", userinfo.characters()));
+        return;
+    }
+
+    if (payload == "FINGER") {
+        auto finger = ctcp_finger_reply();
+        if (finger.is_empty())
+            return;
+        send_ctcp_response(peer, String::format("FINGER %s", finger.characters()));
         return;
         return;
     }
     }
 
 

+ 8 - 0
Applications/IRCClient/IRCClient.h

@@ -56,6 +56,10 @@ public:
 
 
     String nickname() const { return m_nickname; }
     String nickname() const { return m_nickname; }
 
 
+    String ctcp_version_reply() const { return m_ctcp_version_reply; }
+    String ctcp_userinfo_reply() const { return m_ctcp_userinfo_reply; }
+    String ctcp_finger_reply() const { return m_ctcp_finger_reply; }
+
     void join_channel(const String&);
     void join_channel(const String&);
     void part_channel(const String&);
     void part_channel(const String&);
     void change_nick(const String&);
     void change_nick(const String&);
@@ -198,6 +202,10 @@ private:
     HashMap<String, RefPtr<IRCChannel>, CaseInsensitiveStringTraits> m_channels;
     HashMap<String, RefPtr<IRCChannel>, CaseInsensitiveStringTraits> m_channels;
     HashMap<String, RefPtr<IRCQuery>, CaseInsensitiveStringTraits> m_queries;
     HashMap<String, RefPtr<IRCQuery>, CaseInsensitiveStringTraits> m_queries;
 
 
+    String m_ctcp_version_reply;
+    String m_ctcp_userinfo_reply;
+    String m_ctcp_finger_reply;
+
     Vector<IRCWindow*> m_windows;
     Vector<IRCWindow*> m_windows;
 
 
     IRCWindow* m_server_subwindow { nullptr };
     IRCWindow* m_server_subwindow { nullptr };

+ 5 - 0
Base/home/anon/IRCClient.ini

@@ -5,3 +5,8 @@ Nickname=anon_seren1ty
 Server=chat.freenode.net
 Server=chat.freenode.net
 Port=6667
 Port=6667
 AutoJoinChannels=#serenityos
 AutoJoinChannels=#serenityos
+
+[CTCP]
+VersionReply=IRC Client [x86] / Serenity OS
+UserInfoReply=anon
+FingerReply=anon