]> jfr.im git - irc/quakenet/lightweight.git/blob - channels.c
Make L auth to the network when it connects
[irc/quakenet/lightweight.git] / channels.c
1 /* channels.c -- general channel functions */
2
3 #include <lightweight.h>
4 #include <globalexterns.h>
5 #include <stdio.h>
6 #include <channelsdb.h>
7 #include <channels.h>
8
9 /*
10 * SyncTimestamp
11 *
12 * Given a new timestamp for a channel, works out if it's "better"
13 * than ours. Handles appropriately if we're bursting or whatever.
14 *
15 * Also, if we are sitting on channels, this function should cause
16 * us to join the channel if we haven't already.
17 */
18
19 void SyncTimestamp(struct reggedchannel *chanptr, time_t timestamp)
20 {
21 char buf[512];
22
23 /* Check if we need to do anything */
24 if (chanptr == NULL) /* Abort if it's NULL */
25 return;
26
27 if ((chanptr->timestamp != 0) && (chanptr->timestamp <= timestamp))
28 /* Our timestamp is older/same and valid. Forget it. */
29 /* Note that if we're sitting on channels we MUST be
30 * on the chan if we need to be already to have a valid timestamp */
31 return;
32
33 /* ONLY WRITE TO chanptr->timestamp HERE!! */
34 chanptr->timestamp = timestamp;
35
36 #ifdef SIT_ON_CHANNELS
37 if (!IsSuspended(chanptr)) {
38 if (IsJoined(chanptr)) {
39 /* We are already on the channel, hack mode */
40 HackOps(chanptr);
41 } else {
42 /* We are joining the channel */
43 if (burst_done == 0) {
44 /* We are still bursting, we can join seamlessly */
45 sprintf(buf, "%s B %s %ld %sAAA:o\r\n", my_numeric, chanptr->channelname, timestamp, my_numeric);
46 SendLine(buf);
47 } else {
48 #ifdef HORRIBLE_DEOPALL_HACK
49 /* we are still under burst; do the same as above anyway :) */
50 sprintf(buf, "%s B %s %ld %sAAA:o\r\n", my_numeric, chanptr->channelname, timestamp, my_numeric);
51 SendLine(buf);
52 #else
53 /* Sitting on channels but being nice with the protocol? Need to join and hack mode */
54 CheckJoined(chanptr);
55 #endif
56 } /* if (burst_done ... */
57 SetJoined(chanptr);
58 } /* if (IsJoined ... */
59 } /* if (IsSuspended ... */
60 #endif /* SIT_ON_CHANNELS */
61 }
62
63 void HackOps(struct reggedchannel *chanptr)
64 {
65 /* We do this so often, bring it out into a function */
66 char buf[512];
67
68 sprintf(buf, "%s M %s +o %sAAA\r\n", my_numeric, chanptr->channelname, my_numeric);
69 SendLine(buf);
70 }
71
72 void OpUser(struct reggedchannel *chanptr, char *numeric)
73 {
74 /* Op user on channel */
75 char buf[512];
76
77 #ifdef SIT_ON_CHANNELS
78 CheckJoined(chanptr);
79 sprintf(buf, "%sAAA M %s +o %s\r\n", my_numeric, chanptr->channelname, numeric);
80 SendLine(buf);
81 #else
82 sprintf(buf, "%s M %s +o %s\r\n", my_numeric, chanptr->channelname, numeric);
83 SendLine(buf);
84 #endif
85 }
86
87 void VoiceUser(struct reggedchannel *chanptr, char *numeric)
88 {
89 /* Voice user on channel */
90 char buf[512];
91
92 #ifdef SIT_ON_CHANNELS
93 CheckJoined(chanptr);
94 sprintf(buf, "%sAAA M %s +v %s\r\n", my_numeric, chanptr->channelname, numeric);
95 SendLine(buf);
96 #else
97 sprintf(buf, "%s M %s +v %s\r\n", my_numeric, chanptr->channelname, numeric);
98 SendLine(buf);
99 #endif
100 }
101
102 void VoiceAndDeopUser(struct reggedchannel *chanptr, char *numeric)
103 {
104 /* Voice user on channel */
105 char buf[512];
106
107 #ifdef SIT_ON_CHANNELS
108 CheckJoined(chanptr);
109 sprintf(buf, "%sAAA M %s -o+v %s %s\r\n", my_numeric, chanptr->channelname, numeric, numeric);
110 SendLine(buf);
111 #else
112 sprintf(buf, "%s M %s -o+v %s %s\r\n", my_numeric, chanptr->channelname, numeric, numeric);
113 SendLine(buf);
114 #endif
115 }
116
117 void DeopUser(struct reggedchannel *chanptr, char *numeric)
118 {
119 /* Deop user on channel */
120 char buf[512];
121
122 #ifdef SIT_ON_CHANNELS
123 CheckJoined(chanptr);
124 sprintf(buf, "%sAAA M %s -o %s\r\n", my_numeric, chanptr->channelname, numeric);
125 SendLine(buf);
126 #else
127 sprintf(buf, "%s M %s -o %s\r\n", my_numeric, chanptr->channelname, numeric);
128 SendLine(buf);
129 #endif
130 }
131
132 void KickUser(struct reggedchannel *chanptr, char *nick, char *reason)
133 {
134 /* Deop user on channel */
135 char buf[512];
136
137 #ifdef SIT_ON_CHANNELS
138 CheckJoined(chanptr);
139 sprintf(buf, "%sAAA K %s %s :%s\r\n", my_numeric, chanptr->channelname, nick, reason);
140 SendLine(buf);
141 #else
142 sprintf(buf, "%s K %s %s :%s\r\n", my_numeric, chanptr->channelname, nick, reason);
143 SendLine(buf);
144 #endif
145 }
146
147 #ifdef SIT_ON_CHANNELS
148
149 void InviteUser(struct reggedchannel *chanptr, char *nick)
150 {
151 /* invite user to channel */
152 char buf[512];
153
154 CheckJoined(chanptr);
155 sprintf(buf, "%sAAA I %s :%s\r\n", my_numeric, nick, chanptr->channelname);
156 SendLine(buf);
157 }
158
159 void CheckJoined(struct reggedchannel *chanptr)
160 {
161 /* Check we're joined to a channel */
162 char buf[512];
163
164 if (!IsJoined(chanptr) && !IsSuspended(chanptr)) {
165 sprintf(buf, "%sAAA J %s\r\n", my_numeric, chanptr->channelname);
166 SendLine(buf);
167 HackOps(chanptr);
168 SetJoined(chanptr);
169 if (IsInviteOnly(chanptr)) {
170 sprintf(buf, "%sAAA M %s +isn\r\n", my_numeric, chanptr->channelname);
171 SendLine(buf);
172 }
173 }
174 }
175
176 void PartChannel(struct reggedchannel *chanptr, char *reason)
177 {
178 char buf[512];
179
180 if (IsJoined(chanptr)) {
181 sprintf(buf, "%sAAA L %s :%s\r\n", my_numeric, chanptr->channelname,
182 (reason != NULL) ? reason : "So long, and thanks for all the fish.");
183 SendLine(buf);
184 ClearJoined(chanptr);
185 /* Clear the timestamp. We are trusting the person telling us to part
186 * that we are the last user in the channel and that the channel will now cease to exist. */
187 chanptr->timestamp = 0;
188 }
189 }
190
191 #endif