]>
jfr.im git - irc/quakenet/lightweight.git/blob - channels.c
1 /* channels.c -- general channel functions */
3 #include <lightweight.h>
4 #include <globalexterns.h>
6 #include <channelsdb.h>
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.
15 * Also, if we are sitting on channels, this function should cause
16 * us to join the channel if we haven't already.
19 void SyncTimestamp(struct reggedchannel
*chanptr
, time_t timestamp
)
23 /* Check if we need to do anything */
24 if (chanptr
== NULL
) /* Abort if it's NULL */
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 */
33 /* ONLY WRITE TO chanptr->timestamp HERE!! */
34 chanptr
->timestamp
= timestamp
;
36 #ifdef SIT_ON_CHANNELS
37 if (!IsSuspended(chanptr
)) {
38 if (IsJoined(chanptr
)) {
39 /* We are already on the channel, hack mode */
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
);
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
);
53 /* Sitting on channels but being nice with the protocol? Need to join and hack mode */
56 } /* if (burst_done ... */
58 } /* if (IsJoined ... */
59 } /* if (IsSuspended ... */
60 #endif /* SIT_ON_CHANNELS */
63 void HackOps(struct reggedchannel
*chanptr
)
65 /* We do this so often, bring it out into a function */
68 sprintf(buf
, "%s M %s +o %sAAA\r\n", my_numeric
, chanptr
->channelname
, my_numeric
);
72 void OpUser(struct reggedchannel
*chanptr
, char *numeric
)
74 /* Op user on channel */
77 #ifdef SIT_ON_CHANNELS
79 sprintf(buf
, "%sAAA M %s +o %s\r\n", my_numeric
, chanptr
->channelname
, numeric
);
82 sprintf(buf
, "%s M %s +o %s\r\n", my_numeric
, chanptr
->channelname
, numeric
);
87 void VoiceUser(struct reggedchannel
*chanptr
, char *numeric
)
89 /* Voice user on channel */
92 #ifdef SIT_ON_CHANNELS
94 sprintf(buf
, "%sAAA M %s +v %s\r\n", my_numeric
, chanptr
->channelname
, numeric
);
97 sprintf(buf
, "%s M %s +v %s\r\n", my_numeric
, chanptr
->channelname
, numeric
);
102 void VoiceAndDeopUser(struct reggedchannel
*chanptr
, char *numeric
)
104 /* Voice user on channel */
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
);
112 sprintf(buf
, "%s M %s -o+v %s %s\r\n", my_numeric
, chanptr
->channelname
, numeric
, numeric
);
117 void DeopUser(struct reggedchannel
*chanptr
, char *numeric
)
119 /* Deop user on channel */
122 #ifdef SIT_ON_CHANNELS
123 CheckJoined(chanptr
);
124 sprintf(buf
, "%sAAA M %s -o %s\r\n", my_numeric
, chanptr
->channelname
, numeric
);
127 sprintf(buf
, "%s M %s -o %s\r\n", my_numeric
, chanptr
->channelname
, numeric
);
132 void KickUser(struct reggedchannel
*chanptr
, char *nick
, char *reason
)
134 /* Deop user on channel */
137 #ifdef SIT_ON_CHANNELS
138 CheckJoined(chanptr
);
139 sprintf(buf
, "%sAAA K %s %s :%s\r\n", my_numeric
, chanptr
->channelname
, nick
, reason
);
142 sprintf(buf
, "%s K %s %s :%s\r\n", my_numeric
, chanptr
->channelname
, nick
, reason
);
147 #ifdef SIT_ON_CHANNELS
149 void InviteUser(struct reggedchannel
*chanptr
, char *nick
)
151 /* invite user to channel */
154 CheckJoined(chanptr
);
155 sprintf(buf
, "%sAAA I %s :%s\r\n", my_numeric
, nick
, chanptr
->channelname
);
159 void CheckJoined(struct reggedchannel
*chanptr
)
161 /* Check we're joined to a channel */
164 if (!IsJoined(chanptr
) && !IsSuspended(chanptr
)) {
165 sprintf(buf
, "%sAAA J %s\r\n", my_numeric
, chanptr
->channelname
);
169 if (IsInviteOnly(chanptr
)) {
170 sprintf(buf
, "%sAAA M %s +isn\r\n", my_numeric
, chanptr
->channelname
);
176 void PartChannel(struct reggedchannel
*chanptr
, char *reason
)
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.");
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;