Skip to content

Commit

Permalink
Revert "Update SpringTcpServer state when joining channels (#479)" (#503
Browse files Browse the repository at this point in the history
)

This reverts commit 287fd30.
  • Loading branch information
L-e-x-o-n authored Oct 10, 2024
1 parent 88c6494 commit 1a14562
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 45 deletions.
27 changes: 13 additions & 14 deletions lib/teiserver/protocols/spring/spring_in.ex
Original file line number Diff line number Diff line change
Expand Up @@ -648,26 +648,25 @@ defmodule Teiserver.Protocols.SpringIn do
:nomatch
end

new_state =
case regex_result do
:nomatch ->
_no_match(state, "JOIN", msg_id, data)
case regex_result do
:nomatch ->
_no_match(state, "JOIN", msg_id, data)

{room_name, _key} ->
case Room.can_join_room?(state.userid, room_name) do
true ->
SpringOut.do_join_room(state, room_name)
{room_name, _key} ->
case Room.can_join_room?(state.userid, room_name) do
true ->
SpringOut.do_join_room(state, room_name)

{false, reason} ->
reply(:join_failure, {room_name, reason}, msg_id, state)
end
end
{false, reason} ->
reply(:join_failure, {room_name, reason}, msg_id, state)
end
end

if not new_state.exempt_from_cmd_throttle do
if not state.exempt_from_cmd_throttle do
:timer.sleep(Application.get_env(:teiserver, Teiserver)[:spring_post_state_change_delay])
end

new_state
state
end

defp do_handle("LEAVE", room_name, msg_id, state) do
Expand Down
31 changes: 0 additions & 31 deletions test/teiserver/servers/spring_tcp_server_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -467,35 +467,4 @@ defmodule Teiserver.SpringTcpServerTest do
assert r ==
"JOIN dud_room\nJOINED dud_room #{user.name}\nCHANNELTOPIC dud_room #{dud.name}\nADDUSER #{dud.name} ?? #{dud.id} LuaLobby Chobby\nCLIENTSTATUS #{dud.name} 0\nCLIENTS dud_room #{user.name} #{dud.name}\n"
end

test "notified when user LEFT room" do
%{socket: user_1_socket, user: user_1, pid: user_1_pid} = auth_setup()
%{socket: user_2_socket, user: user_2, pid: user_2_pid} = auth_setup()

channel = "test_channel"

# Flush various welcome messages
_ = _recv_raw(user_1_socket)
_ = _recv_raw(user_2_socket)

_send_raw(user_1_socket, "JOIN #{channel}\n")
reply = _recv_raw(user_1_socket)
assert reply =~ "JOIN #{channel}\n"
assert reply =~ "JOINED #{channel} #{user_1.name}\n"
assert reply =~ "CHANNELTOPIC #{channel} #{user_1.name}\n"
assert reply =~ "CLIENTS #{channel} #{user_1.name}\n"

_send_raw(user_2_socket, "JOIN #{channel}\n")
reply = _recv_raw(user_2_socket)
assert reply =~ "JOIN #{channel}\n"
assert reply =~ "JOINED #{channel} #{user_2.name}\n"
assert reply =~ "CHANNELTOPIC #{channel} #{user_1.name}\n"
assert reply =~ ~r/CLIENTS #{channel}[^\n]+#{user_1.name}/
assert reply =~ ~r/CLIENTS #{channel}[^\n]+#{user_2.name}/

_send_raw(user_1_socket, "EXIT\n")

user_2_notification = _recv_raw(user_2_socket)
assert user_2_notification =~ "LEFT #{channel} #{user_1.name}\nREMOVEUSER #{user_1.name}\n"
end
end

0 comments on commit 1a14562

Please sign in to comment.