00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef __USERS_H__
00015 #define __USERS_H__
00016
00017 #include "socket.h"
00018 #include "connection.h"
00019 #include "dns.h"
00020 #include "mode.h"
00021
00024 enum ChanStatus {
00026 STATUS_OP = 4,
00028 STATUS_HOP = 2,
00030 STATUS_VOICE = 1,
00032 STATUS_NORMAL = 0
00033 };
00034
00037 enum ClassTypes {
00039 CC_ALLOW = 0,
00041 CC_DENY = 1
00042 };
00043
00046 enum UserModes {
00048 UM_SNOMASK = 's' - 65,
00050 UM_WALLOPS = 'w' - 65,
00052 UM_INVISIBLE = 'i' - 65,
00054 UM_OPERATOR = 'o' - 65
00055 };
00056
00060 enum RegistrationState {
00061
00062 #ifndef WIN32 // Burlex: This is already defined in win32, luckily it is still 0.
00063 REG_NONE = 0,
00064 #endif
00065
00066 REG_USER = 1,
00067 REG_NICK = 2,
00068 REG_NICKUSER = 3,
00069 REG_ALL = 7
00070 };
00071
00072
00073 class Channel;
00074 class UserResolver;
00075
00078 class CoreExport ConnectClass : public classbase
00079 {
00080 private:
00083 char type;
00086 std::string name;
00089 unsigned int registration_timeout;
00092 unsigned int flood;
00095 std::string host;
00098 unsigned int pingtime;
00101 std::string pass;
00102
00105 std::string hash;
00106
00109 unsigned int threshold;
00110
00113 unsigned long sendqmax;
00114
00117 unsigned long recvqmax;
00118
00121 unsigned long maxlocal;
00122
00125 unsigned long maxglobal;
00126
00129 unsigned int maxchans;
00130
00133 int port;
00134
00135 public:
00136
00139 ConnectClass(const ConnectClass* source) : classbase(), type(source->type), name(source->name),
00140 registration_timeout(source->registration_timeout), flood(source->flood), host(source->host),
00141 pingtime(source->pingtime), pass(source->pass), hash(source->hash), threshold(source->threshold), sendqmax(source->sendqmax),
00142 recvqmax(source->recvqmax), maxlocal(source->maxlocal), maxglobal(source->maxglobal), maxchans(source->maxchans),
00143 port(source->port), RefCount(0), disabled(false), limit(source->limit)
00144 {
00145 }
00146
00149 ConnectClass() : type(CC_DENY), name("unnamed"), registration_timeout(0), flood(0), host(""), pingtime(0), pass(""), hash(""),
00150 threshold(0), sendqmax(0), recvqmax(0), maxlocal(0), maxglobal(0), RefCount(0), disabled(false), limit(0)
00151 {
00152 }
00153
00168 ConnectClass(const std::string &thename, unsigned int timeout, unsigned int fld, const std::string &hst, unsigned int ping,
00169 const std::string &pas, const std::string &hsh, unsigned int thres, unsigned long sendq, unsigned long recvq,
00170 unsigned long maxl, unsigned long maxg, unsigned int maxc, int p = 0) :
00171 type(CC_ALLOW), name(thename), registration_timeout(timeout), flood(fld), host(hst), pingtime(ping), pass(pas), hash(hsh),
00172 threshold(thres), sendqmax(sendq), recvqmax(recvq), maxlocal(maxl), maxglobal(maxg), maxchans(maxc), port(p), RefCount(0), disabled(false), limit(0) { }
00173
00178 ConnectClass(const std::string &thename, const std::string &hst) : type(CC_DENY), name(thename), registration_timeout(0),
00179 flood(0), host(hst), pingtime(0), pass(""), hash(""), threshold(0), sendqmax(0), recvqmax(0), maxlocal(0), maxglobal(0), maxchans(0), port(0), RefCount(0), disabled(false), limit(0)
00180 {
00181 }
00182
00183
00184
00185
00186
00187 ConnectClass(const std::string &thename, const ConnectClass* source) : type(source->type), name(thename),
00188 registration_timeout(source->registration_timeout), flood(source->flood), host(source->host),
00189 pingtime(source->pingtime), pass(source->pass), hash(source->hash), threshold(source->threshold), sendqmax(source->sendqmax),
00190 recvqmax(source->recvqmax), maxlocal(source->maxlocal), maxglobal(source->maxglobal), maxchans(source->maxchans),
00191 port(source->port), RefCount(0), disabled(false), limit(source->limit)
00192 {
00193 }
00194
00195 void SetDisabled(bool t)
00196 {
00197 this->disabled = t;
00198 }
00199
00200 bool GetDisabled()
00201 {
00202 return this->disabled;
00203 }
00204
00205
00206
00207 void Update(unsigned int timeout, unsigned int fld, const std::string &hst, unsigned int ping,
00208 const std::string &pas, unsigned int thres, unsigned long sendq, unsigned long recvq,
00209 unsigned long maxl, unsigned long maxg, unsigned int maxc, int p, unsigned long llimit)
00210 {
00211 if (timeout)
00212 registration_timeout = timeout;
00213 if (fld)
00214 flood = fld;
00215 if (!hst.empty())
00216 host = hst;
00217 if (ping)
00218 pingtime = ping;
00219 if (!pas.empty())
00220 pass = pas;
00221 if (thres)
00222 threshold = thres;
00223 if (sendq)
00224 sendqmax = sendq;
00225 if (recvq)
00226 recvqmax = recvq;
00227 if (maxl)
00228 maxlocal = maxl;
00229 if (maxg)
00230 maxglobal = maxg;
00231 if (maxc)
00232 maxchans = maxc;
00233 if (p)
00234 port = p;
00235
00236 this->limit = llimit;
00237 }
00238
00239 void Update(const std::string &n, const std::string &hst)
00240 {
00241 name = n;
00242 host = hst;
00243 }
00244
00249 unsigned long RefCount;
00250
00253 bool disabled;
00254
00257 unsigned long limit;
00258
00259 size_t GetMaxChans()
00260 {
00261 return maxchans;
00262 }
00263
00266 char GetType()
00267 {
00268 return (type == CC_ALLOW ? CC_ALLOW : CC_DENY);
00269 }
00270
00271 std::string& GetName()
00272 {
00273 return name;
00274 }
00275
00278 time_t GetRegTimeout()
00279 {
00280 return (registration_timeout ? registration_timeout : 90);
00281 }
00282
00285 unsigned int GetFlood()
00286 {
00287 return (threshold ? flood : 999);
00288 }
00289
00292 const std::string& GetHost()
00293 {
00294 return host;
00295 }
00296
00299 int GetPort()
00300 {
00301 return port;
00302 }
00303
00306 void SetPort(int p)
00307 {
00308 port = p;
00309 }
00310
00313 unsigned int GetPingTime()
00314 {
00315 return (pingtime ? pingtime : 120);
00316 }
00317
00320 const std::string& GetPass()
00321 {
00322 return pass;
00323 }
00324
00327 const std::string& GetHash()
00328 {
00329 return hash;
00330 }
00331
00334 unsigned int GetThreshold()
00335 {
00336 return (threshold ? threshold : 1);
00337 }
00338
00341 unsigned long GetSendqMax()
00342 {
00343 return (sendqmax ? sendqmax : 262114);
00344 }
00345
00348 unsigned long GetRecvqMax()
00349 {
00350 return (recvqmax ? recvqmax : 4096);
00351 }
00352
00355 unsigned long GetMaxLocal()
00356 {
00357 return maxlocal;
00358 }
00359
00362 unsigned long GetMaxGlobal()
00363 {
00364 return maxglobal;
00365 }
00366 };
00367
00370 typedef std::vector< std::pair<irc::string, time_t> > InvitedList;
00371
00374 typedef std::vector<ConnectClass*> ClassVector;
00375
00378 typedef std::map<Channel*, char> UserChanList;
00379
00382 typedef UserChanList::iterator UCListIter;
00383
00384
00385
00386 class User;
00387
00393 class CoreExport VisData
00394 {
00395 public:
00398 VisData();
00401 virtual ~VisData();
00406 virtual bool VisibleTo(User* user);
00407 };
00408
00416 class CoreExport User : public connection
00417 {
00418 private:
00423 InspIRCd* ServerInstance;
00424
00429 InvitedList invites;
00430
00433 std::string cached_fullhost;
00434
00437 std::string cached_hostip;
00438
00441 std::string cached_makehost;
00442
00445 std::string cached_fullrealhost;
00446
00449 std::string cachedip;
00450
00455 void DecrementModes();
00456
00457 std::map<std::string, bool>* AllowedOperCommands;
00458
00460 bool* AllowedUserModes;
00461
00463 bool* AllowedChanModes;
00464
00465 public:
00468 Module* io;
00469
00473 ConnectClass *MyClass;
00474
00477 VisData* Visibility;
00478
00481 std::string stored_host;
00482
00487 void StartDNSLookup();
00488
00493 std::string nick;
00494
00498 std::string uuid;
00499
00503 std::string ident;
00504
00508 std::string dhost;
00509
00512 std::string fullname;
00513
00524 std::bitset<64> modes;
00525
00529 std::bitset<64> snomasks;
00530
00533 UserChanList chans;
00534
00537 const char* server;
00538
00542 std::string awaymsg;
00543
00547 time_t awaytime;
00548
00554 std::string oper;
00555
00560 bool dns_done;
00561
00566 std::string password;
00567
00572 std::string recvq;
00573
00577 std::string sendq;
00578
00581 std::string quitmsg;
00582
00585 std::string operquitmsg;
00586
00589 bool quietquit;
00590
00593 unsigned int lines_in;
00594
00597 time_t reset_due;
00598
00604 bool quitting;
00605
00609 sockaddr* ip;
00610
00616 void SetSockAddr(int protocol_family, const char* ip, int port);
00617
00621 int GetPort();
00622
00626 int GetProtocolFamily();
00627
00631 const char* GetIPString(bool translate4in6 = true);
00632
00640 const char *GetCIDRMask(int range);
00641
00644 bool exempt;
00645
00649 int Penalty;
00650
00653 bool OverPenalty;
00654
00657 bool ExemptFromPenalty;
00658
00664 User(InspIRCd* Instance, const std::string &uid = "");
00665
00669 bool CheckLines();
00670
00676 virtual const std::string& GetFullHost();
00677
00684 virtual const std::string& GetFullRealHost();
00685
00689 void InvalidateCache();
00690
00694 const char* FormatNoticeMasks();
00695
00702 std::string ProcessNoticeMasks(const char *sm);
00703
00708 bool IsNoticeMaskSet(unsigned char sm);
00709
00714 void SetNoticeMask(unsigned char sm, bool value);
00715
00719 const char* FormatModes(bool showparameters = false);
00720
00725 bool IsModeSet(unsigned char m);
00726
00731 void SetMode(unsigned char m, bool value);
00732
00737 virtual bool IsInvited(const irc::string &channel);
00738
00743 virtual void InviteTo(const irc::string &channel, time_t timeout);
00744
00750 virtual void RemoveInvite(const irc::string &channel);
00751
00758 bool HasPermission(const std::string &command);
00759
00767 bool HasModePermission(unsigned char mode, ModeType type);
00768
00774 int ReadData(void* buffer, size_t size);
00775
00785 bool AddBuffer(const std::string &a);
00786
00791 bool BufferIsReady();
00792
00795 void ClearBuffer();
00796
00805 std::string GetBuffer();
00806
00812 void AddWriteBuf(const std::string &data);
00813
00820 void FlushWriteBuf();
00821
00825 InvitedList* GetInviteList();
00826
00831 char* MakeWildHost();
00832
00837 const std::string& MakeHost();
00838
00843 const std::string& MakeHostIP();
00844
00849 void CloseSocket();
00850
00853 void AddToWhoWas();
00854
00859 void Oper(const std::string &opertype, const std::string &opername);
00860
00863 void CheckClass();
00864
00868 void FullConnect();
00869
00876 User* UpdateNickHash(const char* New);
00877
00885 bool ForceNickChange(const char* newnick);
00886
00890 void UnOper();
00891
00895 void Write(std::string text);
00896
00901 void Write(const char *text, ...) CUSTOM_PRINTF(2, 3);
00902
00906 void WriteServ(const std::string& text);
00907
00912 void WriteServ(const char* text, ...) CUSTOM_PRINTF(2, 3);
00913
00914 void WriteNumeric(unsigned int numeric, const char* text, ...) CUSTOM_PRINTF(3, 4);
00915
00916 void WriteNumeric(unsigned int numeric, const std::string &text);
00917
00922 void WriteFrom(User *user, const std::string &text);
00923
00929 void WriteFrom(User *user, const char* text, ...) CUSTOM_PRINTF(3, 4);
00930
00935 void WriteTo(User *dest, const std::string &data);
00936
00942 void WriteTo(User *dest, const char *data, ...) CUSTOM_PRINTF(3, 4);
00943
00947 void WriteCommon(const std::string &text);
00948
00953 void WriteCommon(const char* text, ...) CUSTOM_PRINTF(2, 3);
00954
00959 void WriteCommonExcept(const char* text, ...) CUSTOM_PRINTF(2, 3);
00960
00964 void WriteCommonExcept(const std::string &text);
00965
00971 void WriteCommonQuit(const std::string &normal_text, const std::string &oper_text);
00972
00978 void WriteWallOps(const char* text, ...) CUSTOM_PRINTF(2, 3);
00979
00984 void WriteWallOps(const std::string &text);
00985
00990 bool SharesChannelWith(User *other);
00991
01000 bool ChangeDisplayedHost(const char* host);
01001
01009 bool ChangeIdent(const char* newident);
01010
01018 bool ChangeName(const char* gecos);
01019
01028 void SendAll(const char* command, const char* text, ...) CUSTOM_PRINTF(3, 4);
01029
01035 std::string ChannelList(User* source);
01036
01042 void SplitChanList(User* dest, const std::string &cl);
01043
01047 void PurgeEmptyChannels();
01048
01052 ConnectClass *GetClass();
01053
01058 ConnectClass *SetClass(const std::string &explicit_name = "");
01059
01062 void ShowMOTD();
01063
01066 void ShowRULES();
01067
01071 void SetOperQuit(const std::string &oquit);
01072
01076 const std::string& GetOperQuit();
01077
01080 void IncreasePenalty(int increase);
01081
01084 void DecreasePenalty(int decrease);
01085
01091 void HandleEvent(EventType et, int errornum = 0);
01092
01095 virtual ~User();
01096 };
01097
01100 class CoreExport UserResolver : public Resolver
01101 {
01102 private:
01105 User* bound_user;
01108 int bound_fd;
01111 bool fwd;
01112 public:
01120 UserResolver(InspIRCd* Instance, User* user, std::string to_resolve, QueryType qt, bool &cache);
01121
01128 void OnLookupComplete(const std::string &result, unsigned int ttl, bool cached, int resultnum = 0);
01129
01134 void OnError(ResolverError e, const std::string &errormessage);
01135 };
01136
01137
01138
01139
01140 #endif
01141