1 #ifndef _KVI_IRCCONNECTIONSERVERINFO_H_ 2 #define _KVI_IRCCONNECTIONSERVERINFO_H_ 3 //============================================================================= 4 // 5 // File : KviIrcConnectionServerInfo.h 6 // Creation date : Tue 22 Jun 2004 03:57:32 by Szymon Stefanek 7 // 8 // This file is part of the KVIrc IRC client distribution 9 // Copyright (C) 2004-2010 Szymon Stefanek <pragma at kvirc dot net> 10 // 11 // This program is FREE software. You can redistribute it and/or 12 // modify it under the terms of the GNU General Public License 13 // as published by the Free Software Foundation; either version 2 14 // of the License, or (at your option) any later version. 15 // 16 // This program is distributed in the HOPE that it will be USEFUL, 17 // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 19 // See the GNU General Public License for more details. 20 // 21 // You should have received a copy of the GNU General Public License 22 // along with this program. If not, write to the Free Software Foundation, 23 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 24 // 25 //============================================================================= 26 27 #include "kvi_settings.h" 28 #include "KviQString.h" 29 #include "kvi_inttypes.h" 30 31 #include <QStringList> 32 33 class KviIrcConnectionServerInfo; 34 35 class KVIRC_API KviBasicIrcServerInfo 36 { 37 // ircnet 38 protected: 39 QString m_szServerVersion; 40 KviIrcConnectionServerInfo * m_pParent; 41 42 public: 43 KviBasicIrcServerInfo(KviIrcConnectionServerInfo * pParent = nullptr, QString version = KviQString::Empty); 44 virtual ~KviBasicIrcServerInfo(); 45 46 public: 47 virtual const QString & getChannelModeDescription(char mode) const; 48 virtual const QString & getUserModeDescription(QChar mode) const; 49 virtual QChar getUserModeRequirement(QChar mode) const; getRegisterModeChar()50 virtual char getRegisterModeChar() const { return 0; } getSoftware()51 virtual const char * getSoftware() const { return "Ircd"; } getNeedsOpToListModeseI()52 virtual bool getNeedsOpToListModeseI() const { return false; } getNeedsOperToSetS()53 virtual bool getNeedsOperToSetS() const { return false; } 54 }; 55 56 // 57 // Hybrid + forks 58 // 59 60 class KVIRC_API KviHybridServerInfo : public KviBasicIrcServerInfo 61 { 62 // This is a major IRCd that most modern forks are based off of 63 public: 64 KviHybridServerInfo(KviIrcConnectionServerInfo * pParent = nullptr, const QString & version = KviQString::Empty) KviBasicIrcServerInfo(pParent,version)65 : KviBasicIrcServerInfo(pParent, version) {} 66 const QString & getChannelModeDescription(char mode) const override; 67 const QString & getUserModeDescription(QChar mode) const override; 68 QChar getUserModeRequirement(QChar mode) const override; getRegisterModeChar()69 char getRegisterModeChar() const override { return 'r'; } getSoftware()70 const char * getSoftware() const override { return "Hybrid"; } 71 }; 72 73 class KVIRC_API KviIrcdRatboxIrcServerInfo : public KviHybridServerInfo 74 { 75 // efnet 76 public: 77 KviIrcdRatboxIrcServerInfo(KviIrcConnectionServerInfo * pParent = nullptr, const QString & version = KviQString::Empty) KviHybridServerInfo(pParent,version)78 : KviHybridServerInfo(pParent, version) {} 79 const QString & getChannelModeDescription(char mode) const override; 80 const QString & getUserModeDescription(QChar mode) const override; 81 QChar getUserModeRequirement(QChar mode) const override; getSoftware()82 const char * getSoftware() const override { return "Ircd-ratbox"; } getNeedsOpToListModeseI()83 bool getNeedsOpToListModeseI() const override { return true; } 84 }; 85 86 class KVIRC_API KviCharybdisServerInfo : public KviIrcdRatboxIrcServerInfo 87 { 88 public: 89 KviCharybdisServerInfo(KviIrcConnectionServerInfo * pParent = nullptr, const QString & version = KviQString::Empty) KviIrcdRatboxIrcServerInfo(pParent,version)90 : KviIrcdRatboxIrcServerInfo(pParent, version) {} 91 const QString & getChannelModeDescription(char mode) const override; 92 const QString & getUserModeDescription(QChar mode) const override; 93 QChar getUserModeRequirement(QChar mode) const override; getSoftware()94 const char * getSoftware() const override { return "Charybdis"; } getNeedsOperToSetS()95 bool getNeedsOperToSetS() const override { return true; } 96 }; 97 98 class KVIRC_API KviIrcdSevenIrcServerInfo : public KviCharybdisServerInfo 99 { 100 // freenode 101 public: 102 KviIrcdSevenIrcServerInfo(KviIrcConnectionServerInfo * pParent = nullptr, const QString & version = KviQString::Empty) KviCharybdisServerInfo(pParent,version)103 : KviCharybdisServerInfo(pParent, version) {} 104 const QString & getUserModeDescription(QChar mode) const override; 105 QChar getUserModeRequirement(QChar mode) const override; getSoftware()106 const char * getSoftware() const override { return "Ircd-seven"; } 107 }; 108 109 class KVIRC_API KviPlexusIrcServerInfo : public KviHybridServerInfo 110 { 111 // rizon; note: plexus is an extension to hybrid 112 public: 113 KviPlexusIrcServerInfo(KviIrcConnectionServerInfo * pParent = nullptr, const QString & version = KviQString::Empty) KviHybridServerInfo(pParent,version)114 : KviHybridServerInfo(pParent, version) {} 115 const QString & getChannelModeDescription(char mode) const override; 116 const QString & getUserModeDescription(QChar mode) const override; 117 QChar getUserModeRequirement(QChar mode) const override; getSoftware()118 const char * getSoftware() const override { return "Plexus"; } getNeedsOpToListModeseI()119 bool getNeedsOpToListModeseI() const override { return true; } 120 }; 121 122 class KVIRC_API KviOftcIrcServerInfo : public KviHybridServerInfo 123 { 124 // oftc; note: hybrid+oftc is an extension to hybrid 125 public: 126 KviOftcIrcServerInfo(KviIrcConnectionServerInfo * pParent = nullptr, const QString & version = KviQString::Empty) KviHybridServerInfo(pParent,version)127 : KviHybridServerInfo(pParent, version) {} 128 const QString & getChannelModeDescription(char mode) const override; 129 const QString & getUserModeDescription(QChar mode) const override; 130 QChar getUserModeRequirement(QChar mode) const override; getRegisterModeChar()131 char getRegisterModeChar() const override { return 'R'; } getSoftware()132 const char * getSoftware() const override { return "Hybrid+Oftc"; } getNeedsOpToListModeseI()133 bool getNeedsOpToListModeseI() const override { return true; } 134 }; 135 136 // 137 // P10 138 // 139 140 class KVIRC_API KviIrcuIrcServerInfo : public KviBasicIrcServerInfo 141 { 142 // undernet 143 public: 144 KviIrcuIrcServerInfo(KviIrcConnectionServerInfo * pParent = nullptr, const QString & version = KviQString::Empty) KviBasicIrcServerInfo(pParent,version)145 : KviBasicIrcServerInfo(pParent, version) {} 146 const QString & getChannelModeDescription(char mode) const override; 147 const QString & getUserModeDescription(QChar mode) const override; 148 QChar getUserModeRequirement(QChar mode) const override; getSoftware()149 const char * getSoftware() const override { return "Ircu"; } getNeedsOpToListModeseI()150 bool getNeedsOpToListModeseI() const override { return true; } getNeedsOperToSetS()151 bool getNeedsOperToSetS() const override { return true; } 152 }; 153 154 class KVIRC_API KviSnircdIrcServerInfo : public KviIrcuIrcServerInfo 155 { 156 // quakenet; note: snird is an extension to ircu 157 public: 158 KviSnircdIrcServerInfo(KviIrcConnectionServerInfo * pParent = nullptr, const QString & version = KviQString::Empty) KviIrcuIrcServerInfo(pParent,version)159 : KviIrcuIrcServerInfo(pParent, version) {} 160 const QString & getChannelModeDescription(char mode) const override; 161 const QString & getUserModeDescription(QChar mode) const override; 162 QChar getUserModeRequirement(QChar mode) const override; getSoftware()163 const char * getSoftware() const override { return "Snircd"; } getNeedsOperToSetS()164 bool getNeedsOperToSetS() const override { return true; } 165 }; 166 167 class KVIRC_API KviDarenetIrcServerInfo : public KviIrcuIrcServerInfo 168 { 169 // darenet; note: u2+ircd-darenet is an extension to ircu 170 public: 171 KviDarenetIrcServerInfo(KviIrcConnectionServerInfo * pParent = nullptr, const QString & version = KviQString::Empty) KviIrcuIrcServerInfo(pParent,version)172 : KviIrcuIrcServerInfo(pParent, version) {} 173 const QString & getChannelModeDescription(char mode) const override; 174 const QString & getUserModeDescription(QChar mode) const override; 175 QChar getUserModeRequirement(QChar mode) const override; getRegisterModeChar()176 char getRegisterModeChar() const override { return 'r'; } getSoftware()177 const char * getSoftware() const override { return "Ircu+Darenet"; } 178 }; 179 180 // 181 // Unreal -> Unreal 3.2 -> Unreal 4.0 182 // 183 184 class KVIRC_API KviUnrealIrcServerInfo : public KviBasicIrcServerInfo 185 { 186 public: 187 KviUnrealIrcServerInfo(KviIrcConnectionServerInfo * pParent = nullptr, const QString & version = KviQString::Empty) KviBasicIrcServerInfo(pParent,version)188 : KviBasicIrcServerInfo(pParent, version) {} 189 const QString & getChannelModeDescription(char mode) const override; getRegisterModeChar()190 char getRegisterModeChar() const override { return 'r'; } getSoftware()191 const char * getSoftware() const override { return "Unreal"; } getNeedsOperToSetS()192 bool getNeedsOperToSetS() const override { return true; } 193 }; 194 195 class KVIRC_API KviUnreal32IrcServerInfo : public KviUnrealIrcServerInfo 196 { 197 // This is a continuation on to Unreal, so use its predecessor 198 // as a base class. 199 public: 200 KviUnreal32IrcServerInfo(KviIrcConnectionServerInfo * pParent = nullptr, const QString & version = KviQString::Empty) KviUnrealIrcServerInfo(pParent,version)201 : KviUnrealIrcServerInfo(pParent, version) {} 202 const QString & getChannelModeDescription(char mode) const override; 203 const QString & getUserModeDescription(QChar mode) const override; 204 QChar getUserModeRequirement(QChar mode) const override; getSoftware()205 const char * getSoftware() const override { return "Unreal32"; } 206 }; 207 208 class KVIRC_API KviUnreal40IrcServerInfo : public KviUnreal32IrcServerInfo 209 { 210 public: 211 KviUnreal40IrcServerInfo(KviIrcConnectionServerInfo * pParent = nullptr, const QString & version = KviQString::Empty) KviUnreal32IrcServerInfo(pParent,version)212 : KviUnreal32IrcServerInfo(pParent, version) {} 213 const QString & getChannelModeDescription(char mode) const override; 214 const QString & getUserModeDescription(QChar mode) const override; getSoftware()215 const char * getSoftware() const override { return "Unreal40"; } 216 }; 217 218 class KVIRC_API KviCritenIrcServerInfo : public KviBasicIrcServerInfo 219 { 220 // abjects 221 public: 222 KviCritenIrcServerInfo(KviIrcConnectionServerInfo * pParent = nullptr, const QString & version = KviQString::Empty) KviBasicIrcServerInfo(pParent,version)223 : KviBasicIrcServerInfo(pParent, version) {} 224 const QString & getChannelModeDescription(char mode) const override; 225 const QString & getUserModeDescription(QChar mode) const override; 226 QChar getUserModeRequirement(QChar mode) const override; getRegisterModeChar()227 char getRegisterModeChar() const override { return 'r'; } getSoftware()228 const char * getSoftware() const override { return "Criten"; } getNeedsOpToListModeseI()229 bool getNeedsOpToListModeseI() const override { return true; } 230 }; 231 232 class KVIRC_API KviNemesisIrcServerInfo : public KviCritenIrcServerInfo 233 { 234 // criten 235 public: 236 KviNemesisIrcServerInfo(KviIrcConnectionServerInfo * pParent = nullptr, const QString & version = KviQString::Empty) KviCritenIrcServerInfo(pParent,version)237 : KviCritenIrcServerInfo(pParent, version) {} getSoftware()238 const char * getSoftware() const override { return "Nemesis"; } 239 }; 240 241 class KVIRC_API KviNemesis20IrcServerInfo : public KviUnreal32IrcServerInfo 242 { 243 public: 244 KviNemesis20IrcServerInfo(KviIrcConnectionServerInfo * pParent = nullptr, const QString & version = KviQString::Empty) KviUnreal32IrcServerInfo(pParent,version)245 : KviUnreal32IrcServerInfo(pParent, version) {} getSoftware()246 const char * getSoftware() const override { return "Nemesis2.0"; } 247 }; 248 249 class KVIRC_API KviBahamutIrcServerInfo : public KviBasicIrcServerInfo 250 { 251 // dalnet, azzurranet 252 public: 253 KviBahamutIrcServerInfo(KviIrcConnectionServerInfo * pParent = nullptr, const QString & version = KviQString::Empty) KviBasicIrcServerInfo(pParent,version)254 : KviBasicIrcServerInfo(pParent, version) {} 255 const QString & getChannelModeDescription(char mode) const override; 256 const QString & getUserModeDescription(QChar mode) const override; 257 QChar getUserModeRequirement(QChar mode) const override; getRegisterModeChar()258 char getRegisterModeChar() const override { return 'r'; } getSoftware()259 const char * getSoftware() const override { return "Bahamut"; } 260 }; 261 262 class KVIRC_API KviHyperionIrcServerInfo : public KviBasicIrcServerInfo 263 { 264 // legacy freenode : no longer maintained 265 public: 266 KviHyperionIrcServerInfo(KviIrcConnectionServerInfo * pParent = nullptr, const QString & version = KviQString::Empty) KviBasicIrcServerInfo(pParent,version)267 : KviBasicIrcServerInfo(pParent, version) {} 268 const QString & getUserModeDescription(QChar mode) const override; 269 QChar getUserModeRequirement(QChar mode) const override; getRegisterModeChar()270 char getRegisterModeChar() const override { return 'e'; } getSoftware()271 const char * getSoftware() const override { return "Hyperion"; } getNeedsOpToListModeseI()272 bool getNeedsOpToListModeseI() const override { return true; } 273 }; 274 275 class KVIRC_API KviInspIRCdIrcServerInfo : public KviBasicIrcServerInfo 276 { 277 // chatspike 278 public: 279 KviInspIRCdIrcServerInfo(KviIrcConnectionServerInfo * pParent = nullptr, const QString & version = KviQString::Empty) KviBasicIrcServerInfo(pParent,version)280 : KviBasicIrcServerInfo(pParent, version) {} 281 const QString & getChannelModeDescription(char mode) const override; 282 const QString & getUserModeDescription(QChar mode) const override; 283 QChar getUserModeRequirement(QChar mode) const override; getRegisterModeChar()284 char getRegisterModeChar() const override { return 'r'; } getSoftware()285 const char * getSoftware() const override { return "InspIRCd"; } getNeedsOpToListModeseI()286 bool getNeedsOpToListModeseI() const override { return true; } getNeedsOperToSetS()287 bool getNeedsOperToSetS() const override { return true; } 288 }; 289 290 class KVIRC_API KviIrcConnectionServerInfo 291 { 292 friend class KviConsoleWindow; // for now 293 friend class KviIrcServerParser; 294 friend class KviIrcConnection; 295 296 protected: 297 KviIrcConnectionServerInfo(); 298 ~KviIrcConnectionServerInfo(); 299 300 private: 301 KviBasicIrcServerInfo * m_pServInfo; 302 QString m_szNetworkName; // the most actual network name (may be the one we specify or the one that the server reports) 303 QString m_szName; // the most actual server name (may be the one we specify or the one that the server wants to be known as) 304 QString m_szSupportedUserModes; // the supported user modes 305 QString m_szSupportedChannelModes = "pstnmiklb"; // the supported channel modes (all of them) 306 QString m_szSupportedModePrefixes = "@+"; // the actually used mode prefixes @+ 307 QString m_szSupportedStatusMsgPrefixes; // mode prefixes that can be used to target messages (from the STATUSMSG ISUPPORT token) 308 kvi_u32_t * m_pModePrefixTable = nullptr; // the mode prefixes above in a table 309 unsigned int m_uPrefixes; 310 QString m_szSupportedModeFlags = "ov"; // the actually used mode flags ov 311 QString m_szSupportedChannelTypes = "#&!+"; // the supported channel types 312 bool m_bSupportsWatchList = false; // supports the watch list ? 313 bool m_bSupportsCodePages = false; // supports the /CODEPAGE command ? 314 int m_iMaxTopicLen = -1; 315 int m_iMaxModeChanges = 3; 316 // Mode that adds or removes a nick or address to a list. Always has a parameter (eg: "b" as ban) 317 QString m_szListModes = "b"; 318 // Mode that changes a setting and always has a parameter (eg: "k" as channel key) 319 QString m_szParameterModes = "k"; 320 // Mode that changes a setting and only has a parameter when set (eg: "l" as channel limit) 321 QString m_szParameterWhenSetModes = "l"; 322 // Mode that changes a setting and never has a parameter (eg: "m" as channel moderated) 323 QString m_szPlainModes = "pstnmi"; 324 bool m_bSupportsCap = false; 325 QStringList m_lSupportedCaps; 326 bool m_bSupportsWhox = false; // supports WHOX 327 public: registerModeChar()328 char registerModeChar() const { return m_pServInfo ? m_pServInfo->getRegisterModeChar() : 0; } software()329 const char * software() const { return m_pServInfo ? m_pServInfo->getSoftware() : 0; } getNeedsOpToListModeseI()330 bool getNeedsOpToListModeseI() const { return m_pServInfo ? m_pServInfo->getNeedsOpToListModeseI() : false; } getNeedsOperToSetS()331 bool getNeedsOperToSetS() const { return m_pServInfo ? m_pServInfo->getNeedsOperToSetS() : false; } name()332 const QString & name() const { return m_szName; } networkName()333 const QString & networkName() const { return m_szNetworkName; } supportedUserModes()334 const QString & supportedUserModes() const { return m_szSupportedUserModes; } supportedChannelModes()335 const QString & supportedChannelModes() const { return m_szSupportedChannelModes; } supportedChannelTypes()336 const QString & supportedChannelTypes() const { return m_szSupportedChannelTypes; } supportedModePrefixes()337 const QString & supportedModePrefixes() const { return m_szSupportedModePrefixes; } supportedStatusMsgPrefixes()338 const QString & supportedStatusMsgPrefixes() const { return m_szSupportedStatusMsgPrefixes; } supportedModeFlags()339 const QString & supportedModeFlags() const { return m_szSupportedModeFlags; } supportedListModes()340 const QString & supportedListModes() const { return m_szListModes; } supportedParameterModes()341 const QString & supportedParameterModes() const { return m_szParameterModes; } supportedParameterWhenSetModes()342 const QString & supportedParameterWhenSetModes() const { return m_szParameterWhenSetModes; } supportedPlainModes()343 const QString & supportedPlainModes() const { return m_szPlainModes; } supportsCap()344 bool supportsCap() const { return m_bSupportsCap; } supportedCaps()345 const QStringList & supportedCaps() const { return m_lSupportedCaps; } supportsWatchList()346 bool supportsWatchList() const { return m_bSupportsWatchList; } supportsCodePages()347 bool supportsCodePages() const { return m_bSupportsCodePages; } supportsWhox()348 bool supportsWhox() const { return m_bSupportsWhox; } 349 maxTopicLen()350 int maxTopicLen() const { return m_iMaxTopicLen; } maxModeChanges()351 int maxModeChanges() const { return m_iMaxModeChanges; } 352 353 void setServerVersion(const QString & version); 354 getChannelModeDescription(char mode)355 const QString & getChannelModeDescription(char mode) const { return m_pServInfo->getChannelModeDescription(mode); } getUserModeDescription(QChar mode)356 const QString & getUserModeDescription(QChar mode) const { return m_pServInfo->getUserModeDescription(mode); } 357 358 // Returning ! means the mode can never be set by the user. Returning QChar::Null means the mode is free to set. 359 // Returning a QChar means the mode has another mode dependency (the QChar we're returning) getUserModeRequirement(QChar mode)360 QChar getUserModeRequirement(QChar mode) const { return m_pServInfo ? m_pServInfo->getUserModeRequirement(mode) : QChar::Null; } 361 362 bool isSupportedChannelType(QChar c) const; 363 bool isSupportedModePrefix(QChar c) const; 364 bool isSupportedModeFlag(QChar c) const; 365 QChar modePrefixChar(kvi_u32_t flag) const; 366 QChar modeFlagChar(kvi_u32_t flag) const; 367 kvi_u32_t modeFlagFromPrefixChar(QChar c) const; 368 kvi_u32_t modeFlagFromModeChar(QChar c) const; 369 370 protected: setNetworkName(const QString & szName)371 void setNetworkName(const QString & szName) { m_szNetworkName = szName; } setName(const QString & szName)372 void setName(const QString & szName) { m_szName = szName; } setSupportedUserModes(const QString & szSupportedUserModes)373 void setSupportedUserModes(const QString & szSupportedUserModes) { m_szSupportedUserModes = szSupportedUserModes; } 374 void setSupportedChannelModes(const QString & szSupportedChannelModes); 375 void setSupportedModePrefixes(const QString & szSupportedModePrefixes, const QString & szSupportedModeFlags); setSupportedStatusMsgPrefixes(const QString & szSupportedStatusMsgPrefixes)376 void setSupportedStatusMsgPrefixes(const QString & szSupportedStatusMsgPrefixes) { m_szSupportedStatusMsgPrefixes = szSupportedStatusMsgPrefixes; } setSupportedChannelTypes(const QString & szSupportedChannelTypes)377 void setSupportedChannelTypes(const QString & szSupportedChannelTypes) { m_szSupportedChannelTypes = szSupportedChannelTypes; } setSupportsWatchList(bool bSupportsWatchList)378 void setSupportsWatchList(bool bSupportsWatchList) { m_bSupportsWatchList = bSupportsWatchList; } setSupportsCodePages(bool bSupportsCodePages)379 void setSupportsCodePages(bool bSupportsCodePages) { m_bSupportsCodePages = bSupportsCodePages; } 380 void addSupportedCaps(const QString & szCapList); setMaxTopicLen(int iTopLen)381 void setMaxTopicLen(int iTopLen) { m_iMaxTopicLen = iTopLen; } setMaxModeChanges(int iModes)382 void setMaxModeChanges(int iModes) { m_iMaxModeChanges = iModes; } setSupportsWhox(bool bSupportsWhox)383 void setSupportsWhox(bool bSupportsWhox) { m_bSupportsWhox = bSupportsWhox; } 384 private: 385 void buildModePrefixTable(); 386 }; 387 388 #endif //!_KVI_IRCCONNECTIONSERVERINFO_H_ 389