- /* Are channel keys given? */
- if( Req->argc > 1 ) key = Req->argv[1];
- else key = NULL;
-
- /* Channel-Namen durchgehen */
- chan = NULL;
- channame = strtok( Req->argv[0], "," );
- while( channame )
- {
- chan = flags = NULL;
-
- /* wird der Channel neu angelegt? */
- if( Channel_Search( channame )) is_new_chan = FALSE;
- else is_new_chan = TRUE;
-
- /* Hat ein Server Channel-User-Modes uebergeben? */
- if( Client_Type( Client ) == CLIENT_SERVER )
- {
- /* Channel-Flags extrahieren */
- flags = strchr( channame, 0x7 );
- if( flags )
- {
- *flags = '\0';
- flags++;
- }
+ if (is_banned && !is_invited && !is_exception) {
+ /* Client is banned from channel (and not on invite list) */
+ IRC_WriteErrClient(Client, ERR_BANNEDFROMCHAN_MSG,
+ Client_ID(Client), channame);
+ return false;
+ }
+
+ if (Channel_HasMode(chan, 'i') && !is_invited) {
+ /* Channel is "invite-only" and client is not on invite list */
+ IRC_WriteErrClient(Client, ERR_INVITEONLYCHAN_MSG,
+ Client_ID(Client), channame);
+ return false;
+ }
+
+ if (!Channel_CheckKey(chan, Client, key ? key : "")) {
+ /* Channel is protected by a channel key and the client
+ * didn't specify the correct one */
+ IRC_WriteErrClient(Client, ERR_BADCHANNELKEY_MSG,
+ Client_ID(Client), channame);
+ return false;
+ }
+
+ if (Channel_HasMode(chan, 'l') &&
+ (Channel_MaxUsers(chan) <= Channel_MemberCount(chan))) {
+ /* There are more clints joined to this channel than allowed */
+ IRC_WriteErrClient(Client, ERR_CHANNELISFULL_MSG,
+ Client_ID(Client), channame);
+ return false;
+ }
+
+ if (Channel_HasMode(chan, 'z') && !Conn_UsesSSL(Client_Conn(Client))) {
+ /* Only "secure" clients are allowed, but clients doesn't
+ * use SSL encryption */
+ IRC_WriteErrClient(Client, ERR_SECURECHANNEL_MSG,
+ Client_ID(Client), channame);
+ return false;
+ }
+
+ if (Channel_HasMode(chan, 'O') && !Client_HasMode(Client, 'o')) {
+ /* Only IRC operators are allowed! */
+ IRC_WriteErrClient(Client, ERR_OPONLYCHANNEL_MSG,
+ Client_ID(Client), channame);
+ return false;
+ }
+
+ if (Channel_HasMode(chan, 'R') && !Client_HasMode(Client, 'R')) {
+ /* Only registered users are allowed! */
+ IRC_WriteErrClient(Client, ERR_REGONLYCHANNEL_MSG,
+ Client_ID(Client), channame);
+ return false;
+ }
+
+ return true;
+} /* join_allowed */
+
+/**
+ * Set user channel modes.
+ *
+ * @param chan Channel
+ * @param target User to set modes for
+ * @param flags Channel modes to add
+ */
+static void
+join_set_channelmodes(CHANNEL *chan, CLIENT *target, const char *flags)
+{
+ if (flags) {
+ while (*flags) {
+ Channel_UserModeAdd(chan, target, *flags);
+ flags++;