Skip to content

Commit b7a13e3

Browse files
committed
Fail immediately with ERR_BADCHANMASK when clients ignore TARGMAX
No need to send this to the homeserver, this is very likely to be a client error, so we should show a helpful message instead of the generic error from the homeserver
1 parent 249e91b commit b7a13e3

File tree

2 files changed

+33
-13
lines changed

2 files changed

+33
-13
lines changed

lib/irc/handler.ex

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -799,21 +799,32 @@ defmodule M51.IrcConn.Handler do
799799
})
800800

801801
{"JOIN", [channel | _]} ->
802-
case M51.MatrixClient.Client.join_room(matrix_client, channel) do
803-
{:ok, _room_id} ->
804-
# Should we send a JOIN?
805-
send_ack.()
802+
if String.contains?(channel, ",") do
803+
# ERR_BADCHANMASK
804+
send_numeric.(
805+
"476",
806+
[
807+
channel,
808+
"commas are not allowed in channel names (ISUPPORT MAXTARGETS/TARGMAX not implemented?)"
809+
]
810+
)
811+
else
812+
case M51.MatrixClient.Client.join_room(matrix_client, channel) do
813+
{:ok, _room_id} ->
814+
# Should we send a JOIN?
815+
send_ack.()
806816

807-
{:error, :already_joined, _room_id} ->
808-
send_ack.()
817+
{:error, :already_joined, _room_id} ->
818+
send_ack.()
809819

810-
{:error, :banned_or_missing_invite, message} ->
811-
# ERR_BANNEDFROMCHAN
812-
send_numeric.("474", [channel, "Cannot join channel: " <> message])
820+
{:error, :banned_or_missing_invite, message} ->
821+
# ERR_BANNEDFROMCHAN
822+
send_numeric.("474", [channel, "Cannot join channel: " <> message])
813823

814-
{:error, :unknown, message} ->
815-
# ERR_NOSUCHCHANNEL
816-
send_numeric.("403", [channel, "Cannot join channel: " <> message])
824+
{:error, :unknown, message} ->
825+
# ERR_NOSUCHCHANNEL
826+
send_numeric.("403", [channel, "Cannot join channel: " <> message])
827+
end
817828
end
818829

819830
{"JOIN", _} ->

test/irc/handler_test.exs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,16 @@ defmodule M51.IrcConn.HandlerTest do
429429
assert_line("@label=abcd ACK\r\n")
430430
end
431431

432+
test "joining multiple rooms", %{handler: handler} do
433+
do_connection_registration(handler)
434+
435+
send(handler, cmd("@label=abcd JOIN #room1:example.org,#room2:example.org"))
436+
437+
assert_line(
438+
"@label=abcd :server. 476 foo:example.org #room1:example.org,#room2:example.org :commas are not allowed in channel names (ISUPPORT MAXTARGETS/TARGMAX not implemented?)\r\n"
439+
)
440+
end
441+
432442
test "ignores TAGMSG", %{handler: handler} do
433443
do_connection_registration(handler)
434444

@@ -946,7 +956,6 @@ defmodule M51.IrcConn.HandlerTest do
946956

947957
assert_line("BATCH :-#{batch_id}\r\n")
948958

949-
950959
send(handler, cmd("@label=l1 CHATHISTORY LATEST #chan * 2"))
951960
{batch_id, line} = assert_open_batch()
952961
assert line == "@label=l1 BATCH +#{batch_id} :chathistory\r\n"

0 commit comments

Comments
 (0)