From 1a145626b809cb3be366d62cd593862019c46a3a Mon Sep 17 00:00:00 2001 From: Lexon <44340857+L-e-x-o-n@users.noreply.github.com> Date: Thu, 10 Oct 2024 17:03:38 +0200 Subject: [PATCH] Revert "Update SpringTcpServer state when joining channels (#479)" (#503) This reverts commit 287fd307b38d59044cc64c80b99c979aaf681ab3. --- lib/teiserver/protocols/spring/spring_in.ex | 27 ++++++++-------- .../servers/spring_tcp_server_test.exs | 31 ------------------- 2 files changed, 13 insertions(+), 45 deletions(-) diff --git a/lib/teiserver/protocols/spring/spring_in.ex b/lib/teiserver/protocols/spring/spring_in.ex index 92e0f258d..81e7a96ef 100644 --- a/lib/teiserver/protocols/spring/spring_in.ex +++ b/lib/teiserver/protocols/spring/spring_in.ex @@ -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 diff --git a/test/teiserver/servers/spring_tcp_server_test.exs b/test/teiserver/servers/spring_tcp_server_test.exs index 484101cf2..01fd1d32d 100644 --- a/test/teiserver/servers/spring_tcp_server_test.exs +++ b/test/teiserver/servers/spring_tcp_server_test.exs @@ -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