This repository has been archived by the owner on Apr 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
channels.c
191 lines (164 loc) · 5.26 KB
/
channels.c
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
/* channels.c -- general channel functions */
#include <lightweight.h>
#include <globalexterns.h>
#include <stdio.h>
#include <channelsdb.h>
#include <channels.h>
/*
* SyncTimestamp
*
* Given a new timestamp for a channel, works out if it's "better"
* than ours. Handles appropriately if we're bursting or whatever.
*
* Also, if we are sitting on channels, this function should cause
* us to join the channel if we haven't already.
*/
void SyncTimestamp(struct reggedchannel *chanptr, time_t timestamp)
{
char buf[512];
/* Check if we need to do anything */
if (chanptr == NULL) /* Abort if it's NULL */
return;
if ((chanptr->timestamp != 0) && (chanptr->timestamp <= timestamp))
/* Our timestamp is older/same and valid. Forget it. */
/* Note that if we're sitting on channels we MUST be
* on the chan if we need to be already to have a valid timestamp */
return;
/* ONLY WRITE TO chanptr->timestamp HERE!! */
chanptr->timestamp = timestamp;
#ifdef SIT_ON_CHANNELS
if (!IsSuspended(chanptr)) {
if (IsJoined(chanptr)) {
/* We are already on the channel, hack mode */
HackOps(chanptr);
} else {
/* We are joining the channel */
if (burst_done == 0) {
/* We are still bursting, we can join seamlessly */
sprintf(buf, "%s B %s %ld %sAAA:o\r\n", my_numeric, chanptr->channelname, timestamp, my_numeric);
SendLine(buf);
} else {
#ifdef HORRIBLE_DEOPALL_HACK
/* we are still under burst; do the same as above anyway :) */
sprintf(buf, "%s B %s %ld %sAAA:o\r\n", my_numeric, chanptr->channelname, timestamp, my_numeric);
SendLine(buf);
#else
/* Sitting on channels but being nice with the protocol? Need to join and hack mode */
CheckJoined(chanptr);
#endif
} /* if (burst_done ... */
SetJoined(chanptr);
} /* if (IsJoined ... */
} /* if (IsSuspended ... */
#endif /* SIT_ON_CHANNELS */
}
void HackOps(struct reggedchannel *chanptr)
{
/* We do this so often, bring it out into a function */
char buf[512];
sprintf(buf, "%s M %s +o %sAAA\r\n", my_numeric, chanptr->channelname, my_numeric);
SendLine(buf);
}
void OpUser(struct reggedchannel *chanptr, char *numeric)
{
/* Op user on channel */
char buf[512];
#ifdef SIT_ON_CHANNELS
CheckJoined(chanptr);
sprintf(buf, "%sAAA M %s +o %s\r\n", my_numeric, chanptr->channelname, numeric);
SendLine(buf);
#else
sprintf(buf, "%s M %s +o %s\r\n", my_numeric, chanptr->channelname, numeric);
SendLine(buf);
#endif
}
void VoiceUser(struct reggedchannel *chanptr, char *numeric)
{
/* Voice user on channel */
char buf[512];
#ifdef SIT_ON_CHANNELS
CheckJoined(chanptr);
sprintf(buf, "%sAAA M %s +v %s\r\n", my_numeric, chanptr->channelname, numeric);
SendLine(buf);
#else
sprintf(buf, "%s M %s +v %s\r\n", my_numeric, chanptr->channelname, numeric);
SendLine(buf);
#endif
}
void VoiceAndDeopUser(struct reggedchannel *chanptr, char *numeric)
{
/* Voice user on channel */
char buf[512];
#ifdef SIT_ON_CHANNELS
CheckJoined(chanptr);
sprintf(buf, "%sAAA M %s -o+v %s %s\r\n", my_numeric, chanptr->channelname, numeric, numeric);
SendLine(buf);
#else
sprintf(buf, "%s M %s -o+v %s %s\r\n", my_numeric, chanptr->channelname, numeric, numeric);
SendLine(buf);
#endif
}
void DeopUser(struct reggedchannel *chanptr, char *numeric)
{
/* Deop user on channel */
char buf[512];
#ifdef SIT_ON_CHANNELS
CheckJoined(chanptr);
sprintf(buf, "%sAAA M %s -o %s\r\n", my_numeric, chanptr->channelname, numeric);
SendLine(buf);
#else
sprintf(buf, "%s M %s -o %s\r\n", my_numeric, chanptr->channelname, numeric);
SendLine(buf);
#endif
}
void KickUser(struct reggedchannel *chanptr, char *nick, char *reason)
{
/* Deop user on channel */
char buf[512];
#ifdef SIT_ON_CHANNELS
CheckJoined(chanptr);
sprintf(buf, "%sAAA K %s %s :%s\r\n", my_numeric, chanptr->channelname, nick, reason);
SendLine(buf);
#else
sprintf(buf, "%s K %s %s :%s\r\n", my_numeric, chanptr->channelname, nick, reason);
SendLine(buf);
#endif
}
#ifdef SIT_ON_CHANNELS
void InviteUser(struct reggedchannel *chanptr, char *nick)
{
/* invite user to channel */
char buf[512];
CheckJoined(chanptr);
sprintf(buf, "%sAAA I %s :%s\r\n", my_numeric, nick, chanptr->channelname);
SendLine(buf);
}
void CheckJoined(struct reggedchannel *chanptr)
{
/* Check we're joined to a channel */
char buf[512];
if (!IsJoined(chanptr) && !IsSuspended(chanptr)) {
sprintf(buf, "%sAAA J %s\r\n", my_numeric, chanptr->channelname);
SendLine(buf);
HackOps(chanptr);
SetJoined(chanptr);
if (IsInviteOnly(chanptr)) {
sprintf(buf, "%sAAA M %s +isn\r\n", my_numeric, chanptr->channelname);
SendLine(buf);
}
}
}
void PartChannel(struct reggedchannel *chanptr, char *reason)
{
char buf[512];
if (IsJoined(chanptr)) {
sprintf(buf, "%sAAA L %s :%s\r\n", my_numeric, chanptr->channelname,
(reason != NULL) ? reason : "So long, and thanks for all the fish.");
SendLine(buf);
ClearJoined(chanptr);
/* Clear the timestamp. We are trusting the person telling us to part
* that we are the last user in the channel and that the channel will now cease to exist. */
chanptr->timestamp = 0;
}
}
#endif