forked from kofany/psotnic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
classes.h
1382 lines (1161 loc) · 29.4 KB
/
classes.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#ifndef PSOTNIC_CLASSES_H
#define PSOTNIC_CLASSES_H 1
class chan;
class fifo;
class inetconn;
class inet;
class adns;
class chanuser;
class ent;
class CONFIG;
class client;
struct HANDLE;
#include "pstring.h"
#include "class-ent.h"
#include <string>
#include <map>
using std::map;
class XSRand
{
private:
unsigned int x;
static unsigned int a, b, c;
public:
XSRand() { };
void srand(unsigned int seed);
unsigned int rand();
};
#ifdef HAVE_ADNS
class adns
{
public:
class host2ip
{
public:
char *host;
char *ip4;
char *ip6;
time_t creat_t;
unsigned int hash;
host2ip(const char *h, const char *i4="", const char *i6="");
~host2ip();
unsigned int hash32() const;
int operator==(const host2ip &h) const;
time_t creation() { return creat_t; };
};
class host2resolv
{
public:
char *host;
unsigned int hash;
int fd;
int type;
host2resolv(const char *h);
~host2resolv();
unsigned int hash32() const;
int operator==(const host2resolv &h) const;
};
protected:
hashlist<host2ip> *cache;
hashlist<host2resolv> *resolving;
hashlist<host2resolv> *todo;
host2ip *__getIp(const char *host);
public:
virtual void resolv(const char *host) = 0;
virtual host2ip *getIp(const char *host) = 0;
virtual void expire(time_t t, time_t now) = 0;
static unsigned int xorHash(const char *str);
virtual ~adns();
#ifdef HAVE_DEBUG
void display();
#endif
};
#endif
#ifdef HAVE_ADNS_PTHREAD
class adns_pthread : public adns
{
private:
bool die;
pthread_mutex_t data_mutex;
pthread_mutex_t condition_mutex;
pthread_cond_t condition;
pthread_t *th;
int poolSize;
void work();
void removePool();
void killThreads();
public:
virtual void resolv(const char *host);
virtual host2ip *getIp(const char *host);
void setupPool(int n);
adns_pthread(int n);
virtual ~adns_pthread();
void expire(time_t t, time_t now);
void lock_data();
void unlock_data();
#ifdef HAVE_DEBUG
void display();
#endif
friend void *__adns_work(void *);
friend class client;
};
#endif
#ifdef HAVE_ADNS_FIREDNS
class adns_firedns : public adns
{
private:
time_t last_check;
bool shouldWeCheck();
public:
virtual void resolv(const char *host);
virtual host2ip *getIp(const char *host);
adns_firedns();
virtual ~adns_firedns();
void expire(time_t t, time_t now);
#ifdef HAVE_DEBUG
void display();
#endif
int fillFDSET(fd_set *set);
void processResultSET(fd_set *set);
void closeAllConnections();
};
#endif
class protmodelist
{
int expire(const char *channel = NULL);
public:
class entry
{
public:
char *mask;
char *reason;
char *by;
time_t expires;
time_t when;
time_t last_used;
bool sticky;
entry();
entry(const char *_mask, const char *_by, const char *_reason, time_t _when, time_t _expires, bool _sticky=0);
~entry();
char *fullReason();
};
ptrlist<entry> data;
int type;
char mode;
entry *add(const char *mask, const char *by, time_t when, time_t expires, const char *reason, bool sicky);
static entry *add(const char *data, inetconn *c=NULL);
entry *conflicts(const char *mask);
entry *match(const chanuser *u);
entry *wildMatch(const char *mask);
entry *find(const char *str);
entry *findByMask(const char *mask);
int remove(const char *mask);
int remove(int num);
int sendShitsToOwner(inetconn *c, const char *nme, int i=0);
static int sendShitsToOwner(inetconn *c, int type, const char *channel, const char *expr);
void sendToUserlist(inetconn *c, const char *name);
static bool isSticky(const char *mask, int type, const chan *ch);
static protmodelist::entry *findSticky(const char *mask, int type, const chan *ch);
static entry *updateLastUsedTime(const char *channel, const char *mask, int type);
static entry *findBestByMask(const char *channel, const char *mask, int type);
static int addShit(const char *channel, const char *mask, const char *from, int delay, const char *reason, const char *bot=NULL);
static int expireAll();
void clear();
protmodelist(int type, char mode);
~protmodelist();
};
class Pchar
{
public:
char *data;
int step;
int alloced;
int len;
Pchar(int s=4096);
char *push(const char *str, int l=-1);
char *push(const char c);
~Pchar();
void clean();
};
class comment
{
public:
class entry
{
public:
char *key;
char *value;
entry(const char *k, const char *v);
~entry();
int operator==(const entry &ent) const;
int operator<(const entry &e) const;
};
ptrlist<entry> data;
int add(char *key, char *value);
int del(char *key);
char *get(char *key);
comment();
};
class asyn_socks5
{
char proxyip[16];
unsigned short proxyport;
char remotehost[256];
unsigned short remoteport;
int step;
int i;
int toRead;
int fd;
char buf[515];
unsigned char len;
unsigned char atyp;
public:
asyn_socks5();
void setup(const char *pip, unsigned short pport, const char *rhost, unsigned short rport);
int connect();
void disconnect();
int work(char byte);
int use();
};
class modeq
{
public:
class modeq_ent
{
public:
char mode[3];
char *arg;
int expire;
bool backupmode;
bool reject;
modeq_ent(time_t exp, const char *m, const char *a=NULL);
~modeq_ent();
int operator==(modeq_ent &c);
int operator&(modeq_ent &c);
};
private:
chan *ch;
int validate(modeq_ent *e, int &a, int &n);
grouplist<modeq_ent> data;
public:
modeq_ent *add(time_t exp, const char *m, const char *a=NULL);
int flush(int prio);
modeq(chan *channel=NULL);
void setChannel(chan *channel);
void removeBackupModesFor(const char *mode, const char *arg);
modeq_ent *find(const char *mode, const char *arg);
};
class fifo
{
public:
int maxEnt;
static time_t lastFlush;
int flushDelay;
ptrlist<pstring<8> > data;
fifo(int size=0, int delay=1);
~fifo();
int push(const char *lst, ...);
int wisePush(const char *lst, ...);
int wildWisePush(char *lst, ...);
char *pop();
int flush(inetconn *c);
char *flush();
};
/*! Base class for all custom data storages.
* Inherit from this function if you want your class to be saveable as custom data.
*/
class CustomDataObject
{
public:
CustomDataObject() {};
virtual ~CustomDataObject() {};
};
/*! Storage place for custom data entries.
* In order to give the ability to let modules store data inside your class, simply inherit from
* this one.
*/
class CustomDataStorage
{
public:
CustomDataStorage();
virtual ~CustomDataStorage();
CustomDataObject *customData( const char *moduleName );
void setCustomData( const char *moduleName, CustomDataObject *data );
void delCustomData( const char *moduleName );
private:
map< const char *, CustomDataObject * > m_data; //! Storage.
};
class chanuser
#ifdef HAVE_MODULES
: public CustomDataStorage
#endif
{
public:
char *nick;
char *ident;
char *host;
char *reason;
unsigned int flags;
HANDLE *handle;
unsigned int hash;
char *ip4;
char *ip6;
unsigned int dnsinfo;
unsigned int clones_to_check;
chanuser(const char *n, const char *m, const char *h, const int f=0);
chanuser(const char *m, const chan *ch, const int f=0, const bool scan=0);
chanuser(const char *str);
void getFlags(const chan *ch);
~chanuser();
int operator==(const chanuser &c) const;
int operator<(const chanuser &c) const;
unsigned int hash32() const;
void setReason(const char *);
int matches(const char *mask) const;
int matchesBan(const char *mask) const;
#ifdef HAVE_ADNS
int updateDNSEntry();
#endif
bool ok() const;
#ifdef HAVE_DEBUG
void display();
#endif
};
class clone_host
{
public:
chanuser *user;
time_t cr;
int type;
clone_host(chanuser *u, int t);
time_t creation();
int operator==(const clone_host &c);
int operator&(const clone_host &c);
};
class clone_ident
{
public:
chanuser *user;
time_t cr;
clone_ident(chanuser *u);
time_t creation();
int operator==(const clone_ident &c);
int operator&(const clone_ident &c);
};
class clone_proxy
{
public:
chanuser *user;
time_t cr;
clone_proxy(chanuser *u);
time_t creation();
int operator==(const clone_proxy &c);
int operator&(const clone_proxy &c);
};
class wasoptest
{
class entry
{
public:
char *mask;
time_t when;
entry(char *n, char *i, char *h);
entry(char *m, int alloc=1);
~entry();
};
public:
ptrlist<entry> data;
int TOL;
time_t since;
int add(chanuser *p);
int add(char *nick, char *ident, char *host);
int add(char *mask, int alloc=1);
int remove(chanuser *user);
int remove(char *nick, char *ident, char *host);
int remove(char *mask);
static int checkSplit(const char *reason);
void expire();
bool isEmpty();
wasoptest(int life=60*45);
};
class masklist_ent
{
public:
char *mask;
time_t expire;
time_t when;
char *who;
bool sent;
masklist_ent(const char *m, const char *w, time_t t);
~masklist_ent();
};
class masklist
{
public:
ptrlist<masklist_ent> masks;
bool received;
int add(const char *mask, const char *who, time_t);
int remove(char *mask);
masklist_ent *find(const char *mask);
masklist_ent *wildMatch(char *mask);
masklist_ent *matchBan(char *mask, char *ip, char *uid);
masklist_ent *match(const char *mask);
ptrlist<masklist_ent>::iterator expire(ptrlist<masklist_ent>::iterator m=0);
// masklist_ent *exactFind(char *mask);
int remove(masklist_ent *m);
void clear();
masklist();
};
class inetconn
{
private:
void _close(const char *reason=NULL);
CBlowFish *blowfish;
void lock();
void unlock();
public:
int fd;
int status;
char *name;
char *pass;
char *tmpstr;
char *origin;
int tmpint;
int killTime;
int lastPing;
#ifdef HAVE_SSL
SSL_CTX *ssl_ctx;
SSL *ssl;
#endif
IOBUF read;
IOBUF write;
HANDLE *handle;
int enableLameCrypt();
int enableCrypt(const unsigned char *key, int len=-1);
int enableCrypt(const char *key, int len=-1);
int disableCrypt();
#ifdef HAVE_SSL
bool enableSSL();
void SSLHandshake();
#endif
int send(const char *lst, ...);
int va_send(va_list ap, const char *lst);
int readln(char *buf, int len, int *ok=NULL);
int open(const char *pathname, int flags, mode_t mode=0);
void close(const char *reason=NULL);
int checkFlag(int flag, int where=GLOBAL);
int sendPing();
int timedOut();
unsigned int getPeerIp4();
unsigned int getMyIp4();
const char *getPeerIpName();
const char *getMyIpName();
char *getPeerPortName();
char *getMyPortName();
//int getPort();
void echo(int n, char *app=NULL);
inetconn();
~inetconn();
int isSlave();
int isLeaf();
int isMain();
int isRegBot();
int isRegOwner();
int isRegUser();
int isRedir();
int isReg();
int isConnected();
int isBot();
int isSSL();
void writeBufferedData();
friend class inet;// closeConn(int fd);
};
class inet
{
public:
int conns, max_conns, listenfd, maxFd;
inetconn *conn, hub, irc;
#ifdef HAVE_SSL
int ssl_listenfd;
static SSL_CTX *server_ctx;
#endif
inetconn *addConn(int fd);
inetconn *findConn(const char *name);
inetconn *findConn(const HANDLE *h);
int closeConn(inetconn *c, const char *reason=NULL);
void send(int who, const char *lst, ...);
void sendexcept(int excp, int who, const char *lst, ...);
void sendBotListTo(inetconn *c);
void sendOwner(const char *who, const char *lst, ...);
void sendCmd(inetconn *c, const char *lst, ...);
void sendCmd(const char *from, const char *lst, ...);
void propagate(inetconn *from, const char *str, ...);
inetconn *findRedirConn(inetconn *c);
int bidMaxFd(int fd);
inetconn *findMainBot();
#ifdef HAVE_DEBUG
void display();
#endif
void resize();
int bots();
int owners();
static int gethostbyname(const char *host, char *buf, int protocol=AF_INET);
inet();
~inet();
};
class settings : public options
{
public:
entBool PRIVATE_CTCP;
entTime CYCLE_DELAY;
entTime REJOIN_DELAY;
entTime REJOIN_FAIL_DELAY;
entTime HUB_CONN_DELAY;
entTime IRC_CONN_DELAY;
entTime AUTH_TIME;
entInt OPS_PER_MODE;
entTime ASK_FOR_OP_DELAY;
entTime CONN_TIMEOUT;
entTime KEEP_NICK_CHECK_DELAY;
entBool SAVE_NICK;
entBool REMEMBER_OLD_KEYS;
entInt TELNET_OWNERS;
entBool GETOP_OP_CHECK;
entInt MAX_MATCHES;
entInt PERIP_MAX_SHOWN_CONNS;
entInt PERIP_BURST_TIME;
entInt PERIP_BURST_SIZE;
entTime PERIP_IGNORE_TIME;
entInt SYNFLOOD_MAX_CONNS;
entTime SYNFLOOD_IGNORE_TIME;
entTime BIE_MODE_BOUNCE_TIME;
entTime WASOP_CACHE_TIME;
entTime CHAT_TIME;
entTime AWAY_TIME;
entPerc RANDOMNESS;
entTime BETWEEN_MSG_DELAY;
entBool PUBLIC_AWAY;
entTime CLONE_LIFE_TIME;
entInt HOST_CLONES;
entInt IDENT_CLONES;
entInt PROXY_CLONES;
entInt CRITICAL_BOTS;
entTime QUARANTINE_TIME;
entTime BACKUP_MODE_DELAY;
entInt DONT_TRUST_OPS;
entTime SERVER_LIMIT_TIME;
entBool PRE_023_FINAL_COMPAT;
entBool PRE_0211_FINAL_COMPAT;
entBool PRE_0214_FINAL_COMPAT;
entBool PRE_REV127_COMPAT;
entBool BOTS_CAN_ADD_SHIT;
settings();
};
class chanset : public options
{
public:
entInt AOP_BOTS;
entInt BOT_AOP_BOTS;
entInt BOT_AOP_MODE;
entPerc PUNISH_BOTS;
entInt INVITE_BOTS;
entInt GUARDIAN_BOTS;
entBool LIMIT;
entTime LIMIT_TIME;
entTime LIMIT_TIME_UP;
entTime LIMIT_TIME_DOWN;
entInt LIMIT_OFFSET;
entInt LIMIT_BOTS;
entPerc LIMIT_TOLERANCE;
entBool CHANNEL_CTCP;
entInt ENFORCE_BANS;
entBool ENFORCE_LIMITS;
entBool STOP_NETHACK;
entInt GETOP_BOTS;
entTime OWNER_LIMIT_TIME;
entBool TAKEOVER;
entBool BITCH;
entBool WASOPTEST;
entBool CLONECHECK;
entBool DYNAMIC_BANS;
entBool DYNAMIC_EXEMPTS;
entBool DYNAMIC_INVITES;
entBool LOCKDOWN;
entTime LOCKDOWN_TIME;
entInt PROTECT_CHMODES;
entChattr MODE_LOCK;
entBool STRICT_BANS;
entBool CHECK_SHIT_ON_NICK_CHANGE;
entBool INVITE_ON_UNBAN_REQUEST;
entBool KEEPOUT;
entInt IDIOTS;
entInt USER_BANS;
entInt USER_INVITES;
entInt USER_EXEMPTS;
entInt USER_REOPS;
entBool CYCLE;
chanset();
chanset &operator=(const chanset &chset);
};
class prvset : public options
{
public:
entInt debug_show_irc_write;
entInt debug_show_irc_read;
prvset();
};
class CONFIG : public options
{
public:
pstring<> file;
entWord nick;
entWord altnick;
entWord ident;
entWord oidentd_cfg;
entWord nickappend;
entString realname;
entHost myipv4;
entHost vhost;
entWord userlist_file;
entString kickreason;
entString quitreason;
entString limitreason;
entString keepoutreason;
entString partreason;
entString cyclereason;
entWord botnetword;
entWord logfile;
entWord handle;
entInt listenport;
#ifdef HAVE_SSL
entInt ssl_listenport;
#endif
entBool keepnick;
entInt ctcptype;
entBool dontfork;
entHPPH bnc;
entHPPH router;
entHub hub;
entMult alt_storage;
entHub alt[MAX_ALTS];
entHub *currentHub;
entMult server_storage;
entMult ssl_server_storage;
#ifdef HAVE_SSL
entServer server[MAX_SERVERS*2];
#else
entServer server[MAX_SERVERS];
#endif
entMD5Hash ownerpass;
entMult module_load_storage;
entLoadModules module_load[MAX_MODULES];
entMult module_debugLoad_storage;
entLoadModules module_debugLoad[MAX_MODULES];
entString alias[MAX_ALIASES];
entMult alias_storage;
#ifdef HAVE_ADNS
entInt resolve_threads;
entTime domain_ttl;
#endif
entBool check_shit_on_nick_change;
int bottype;
CONFIG();
void polish();
void load(const char *file, bool decrypted=false);
options::event *save(bool decrypted=false);
};
class CHANLIST
#ifdef HAVE_MODULES
: public CustomDataStorage
#endif
{
public:
pstring<> name;
pstring<> pass;
int status;
int nextjoin;
char updated;
chanset *chset;
wasoptest *wasop;
wasoptest *allowedOps;
protmodelist *protlist[4];
CHANLIST() :
#ifdef HAVE_MODULES
CustomDataStorage(),
#endif
status(0), nextjoin(0), updated(0), chset(0), wasop(0), allowedOps(0) { };
void reset();
};
class chan
#ifdef HAVE_MODULES
: public CustomDataStorage
#endif
{
public:
fastptrlist<chanuser> users, toOp, botsToOp, opedBots, toKick;
grouplist<clone_host> hostClones;
grouplist<clone_ident> identClones;
grouplist<clone_proxy> proxyClones;
chan *next, *prev;
pstring<> name, key, topic;
int status, limit, channum, nextlimit, synlevel, flags, sentKicks;
chanuser *me;
chanset *chset;
wasoptest *wasop;
time_t initialOp, since;
masklist list[4];
masklist sentList[4];
modeq modeQ[2];
protmodelist *protlist[4];
/* Actions */
int op(chanuser **MultHandle, int num);
int op(chanuser *p);
int deOp(const chanuser *p);
int kick4(chanuser **MultHandle, int num);
int kick6(chanuser **MultHandle, int num);
int kick(chanuser *p, const char *reason);
int invite(const char *nick);
void enforceLimits();
void updateLimit();
void updateKey(const char *newkey);
int massKick(const int who, int lock=0);
void requestOp() const;
int applyShit(const protmodelist::entry *s, int force=0);
void enforceBan(const char *ban, chanuser *u, const char *reason=NULL, const bool autoKick=true);
int flushKickQueue();
void punishClones(const char *mask, bool isMyTurn);
void knockout(chanuser *u, const char *reason, int delay=60);
/* Probabilistics */
int myTurn(int num, int hash=0);
/* Got something */
void gotNickChange(const char *from, const char *to);
void gotMode(const char *args, const char *modes, const char *mask);
void gotKick(const char *victim, const char *offender, const char *reason);
void gotPart(const char *nick, int netsplit=0);
int gotBan(const char *ban, chanuser *caster);
bool checkClone(chanuser *u);
chanuser *gotJoin(const char *mask, int def_flags=0);
chanuser *getUser(const char *nick);
/* other */
void recheckFlags();
void quoteBots(const char *str);
int quoteOpedBots(const char *str, int num);
void reOp();
void rejoin(int t);
int numberOfBots(int num) const;
int chops() const;
int synced() const;
void setFlags(const char *str);
void addFlags(const char *str);
int hasFlag(char f) const;
void removeFlags(const char *str);
void buildAllowedOpsList(const char *offender);
char *getModes();
int userLevel(const chanuser *c) const;
int userLevel(int flags) const;
void names(const char *owner);
void cwho(const char *owner, const char *arg="");
int myPos();
#ifdef HAVE_ADNS
void updateDnsEntries();
#endif
protmodelist::entry *checkShit(const chanuser *u, const char *host=NULL);
void recheckShits();
void checkList();
void checkKeepout();
void checkProtectedChmodes();
static char valid(const char *str);
static bool chanModeRequiresArgument(char ,char);
static char getTypeOfChanMode(char);
static bool isChannel(const char *);
/* Debug */
#ifdef HAVE_DEBUG
void display();
#endif
/* Constructor */
chan();
/* Destruction derby */
~chan();
void removeFromAllPtrLists(chanuser *handle);
};
/** Stores server information.
* \author patrick <[email protected]>
* \warning the values are only available when the bot is connected to an ircserver
*/
class Server
{
public:
// from 004
char *name; ///< name of the server
char *version; ///< ircd version
char *usermodes; ///< available user modes
char *chanmodes; ///< available channel modes (please prefer isupport.chanmodes)
// from 005
class Isupport
{
public:
typedef map<std::string, std::string> isupportType;
isupportType isupport_map; ///< contains all 005 tokens
Server *server; // pointer to upper class
/* the following variables are in the map too,
* but either they are used very often, so the bot should not search
* for them in map everytime or the value is not accessable without further parsing.
*/
char *chan_status_flags; ///< specifies a list of channel status flags (usually: "ov")
char *chanmodes; ///< indicates the channel modes available and the arguments they take (format: "A,B,C,D")
int maxchannels; ///< maximum number of chans a client can join
int maxlist; ///< limits how many "variable" modes of type A a client may set in total on a channel
int max_kick_targets; ///< maximum number of users that can be kicked with one KICK command
int max_who_targets; ///< maximum number of targets that are allowed in a WHO command
int max_mode_targets; /**< maximum number of targets (channels and users) that are allowed in a MODE command
e.g. MODE #chan1,#chan2,#chan3 */
Isupport();
~Isupport();
void insert(const char *key, const char *value);
const char *find(const char *key);
void reset();
void init();
} isupport;
Server();
~Server();
void reset();
};
class client
{
public:
chan *first, *last, *current;
int channels, joinDelay;
pstring<> nick, ident, host, mask, ircip, uid, overrider;
time_t nextNickCheck, startedAt, nextConnToIrc, nextConnToHub;
time_t nextRecheck;
time_t nextReconnect, ircConnFailDelay;
Server server;
/* Irc channels */
chan *createNewChannel(const char *name);
chan *findChannel(const char *name);
chan *findNotSyncedChannel(const char *name);
void removeChannel(const char *name);
void gotUserQuit(const char *mask, const char *reason=NULL);
void recheckFlags();
void recheckFlags(const char *channel);
void autoRecheck();
void rejoin(const char *name, int t);
void rejoinCheck();
void joinAllChannels();
void gotNickChange(const char *from, const char *to);
void checkQueue();