- /* Test if the user has reached his maximum channel count */
- if ((Conf_MaxJoins > 0) && (Channel_CountForUser(Client) >= Conf_MaxJoins))
- return IRC_WriteStrClient(Client, ERR_TOOMANYCHANNELS_MSG,
- Client_ID(Client), channame);
- if (!chan) /* New Channel: first user will be channel operator */
- flags = "o";
- else
- if (!join_allowed(Client, target, chan, channame, key))
- break;
+ if (chan) {
+ /* Already existing channel: already member? */
+ if (Channel_IsMemberOf(chan, Client))
+ goto join_next;
+ } else {
+ /* Channel must be created */
+ if (!strchr(Conf_AllowedChannelTypes, channame[0])) {
+ /* ... but channel type is not allowed! */
+ IRC_WriteErrClient(Client,
+ ERR_NOSUCHCHANNEL_MSG,
+ Client_ID(Client), channame);
+ goto join_next;
+ }
+ }
+
+ /* Test if the user has reached the channel limit */
+ if ((Conf_MaxJoins > 0) &&
+ (Channel_CountForUser(Client) >= Conf_MaxJoins)) {
+ if (!IRC_WriteErrClient(Client,
+ ERR_TOOMANYCHANNELS_MSG,
+ Client_ID(Client), channame))
+ return DISCONNECTED;
+ goto join_next;
+ }
+
+ if (chan) {
+ /* Already existing channel: check if the
+ * client is allowed to join */
+ if (!join_allowed(Client, chan, channame, key))
+ goto join_next;
+ } else {
+ /* New channel: first user will become channel
+ * operator unless this is a modeless channel */
+ if (*channame != '+')
+ flags = "o";
+ }
+
+ /* Local client: update idle time */
+ Conn_UpdateIdle(Client_Conn(Client));