File: README.umodes

package info (click to toggle)
dancer-ircd 1.0.36-8
  • links: PTS, VCS
  • area: main
  • in suites: lenny, squeeze
  • size: 3,204 kB
  • ctags: 2,703
  • sloc: ansic: 36,121; sh: 3,534; perl: 612; makefile: 307
file content (123 lines) | stat: -rw-r--r-- 3,887 bytes parent folder | download | duplicates (4)
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
In order to accomodate the broad control over what an oper can do
implemented in dancer, the umode system has been expanded to be
considerably more powerful. Instead of the old tables and simple
32-bit field in struct Client that used to contain umodes, compound
bitfield macros have been added to umodes.h which can handle
consdierably more than 32 umodes.

A new umode can be trivially added as follows:

Add a constant index number for it to umodes.h. These are the UMODE_*
#defines.

Add a field to the array in umodes.h to attach a mode letter to the
constant.

All the other tables are created at start time from the table in
umodes.h, and all functions (such as user_mode()) which parse actual
umodes in IRC messages should iterate over this array. If anything
special has to be done when the umode is set/unset, it should be added
to user_mode() in client.c in the large switch() in the middle. The
examples are the unsetting of umode o (UMODE_OPER), and the setting of
umode e (UMODE_IDENTIFIED).

If a umode should be settable by any user, rather than limited to
O:lines, then a single line calling the SetBit macro should be added
to init_umodes() at the bottom of s_user.c, setting that bit in
user_umodes.

Should it be necessary to manipulate the umode structures by hand (as
when working with the functions which parse umodes in IRC messages),
it should always be done via the macros (if an operation is missing,
and cannot be constructed from a simple combination of macros, a new
macro should be added). umode_t is a typedef to the array of bitfields
used to store umodes. The macros currently provided are:

SetBit(bitfield, bit)
ClearBit(bitfield, bit)

These set and clear individual bits in the fields. The "bit" parameter
should be one of the UMODE_* constants defined in client.h. Example:

-------
umode_t umodes;
SetBit(umodes, UMODE_INVISIBLE);
ClearBit(umodes, UMODE_IDENTIFIED);
-------

TestBit(field, bit)

This will be true if the given bit is set and false
otherwise. Example:

-------
if (!TestBit(user_umodes, UMODE_GRANT))
-------

HasUmode(cptr, mode)
SetUmode(cptr, mode)
ClearUmode(cptr, mode)

These are the counterparts of TestBit, SetBit, and ClearBit, which
take a struct Client and work on it's umodes field. Purely for
convinience, these are used in preference to the others.

AndUmodes(destination, a, b)

This logically ANDs the contents of a with b, and stores the result in
destination. It is usually used to mask out umodes which shouldn't be
set:

------- Remove all umodes not in allowed_umodes from umodes
AndUmodes(sptr->umodes, sptr->umodes, sptr->allowed_umodes);
-------

OrUmodes(destination, a, b)
NotUmodes(destination, a)

These do the corresponding boolean operations

AndNotUmodes(destination, a, b)

This is 'destination = a &~ b', the mask form of ClearBit() and
counterpart to AndUmodes()

CopyUmodes(destination, source)

This copies the contents of source to destination.

ClearBitfield(f)

This clears all bits in f (sets all bits to 0).

AnyBits(field)

This is true if the given umode_t has *any* bits set.
------------------------------------------------------------------------

Currently, the bitfields are allocated with space for 63 umodes (1-63,
0 is reserved). If more are needed, in client.h, change:

The line "typedef u_int32_t umode_t[2];" to allocate more 32 bit words
to the bitfields.

The #define BITFIELD_SIZE to be the total number of bits allocated.

All the boolean macros just below these values (excluding SetBit,
ClearBit, and TestBit, which will always work) to also act on the new
members of the array.


To convert back from mode letters to umode indices, index the
character into user_modes_from_c_to_bitmask[]:

-------
for (c = parv[2]; *c; c++)
  switch(user_modes_from_c_to_bitmask[(unsigned char) c])
    {
      case UMODE_IDENTIFIED:
      ...
      default:
      ...
    };
-------