summaryrefslogtreecommitdiff
path: root/lib/irc
diff options
context:
space:
mode:
authorhref <href@random.sh>2021-09-01 12:31:13 +0200
committerhref <href@random.sh>2021-09-01 12:31:13 +0200
commit3ff6b4aae3b3c8beed2ce59c5766ad21e1bdc9af (patch)
tree67f2b7a61cd850bc35f0a98e6b150e945b38822a /lib/irc
parentpreums: remove migration code (diff)
track: clean on reconnecting
Diffstat (limited to 'lib/irc')
-rw-r--r--lib/irc/connection.ex11
-rw-r--r--lib/irc/plugin_supervisor.ex2
-rw-r--r--lib/irc/user_track.ex16
3 files changed, 26 insertions, 3 deletions
diff --git a/lib/irc/connection.ex b/lib/irc/connection.ex
index b83c4d3..bdcc658 100644
--- a/lib/irc/connection.ex
+++ b/lib/irc/connection.ex
@@ -183,9 +183,10 @@ defmodule IRC.Connection do
end
def init([conn]) do
+ Logger.metadata(conn: conn.id)
backoff = :backoff.init(@min_backoff, @max_backoff)
|> :backoff.type(:jitter)
- {:ok, %{client: nil, backoff: backoff, conn: conn}, {:continue, :connect}}
+ {:ok, %{client: nil, backoff: backoff, conn: conn, connected_server: nil, connected_port: nil, network: nil}, {:continue, :connect}}
end
@triggers %{
@@ -243,7 +244,7 @@ defmodule IRC.Connection do
Logger.info("#{inspect(self())} Connected to #{server}:#{port} #{inspect state}")
{_, backoff} = :backoff.succeed(state.backoff)
ExIRC.Client.logon(state.client, state.conn.pass || "", state.conn.nick, state.conn.user, state.conn.name)
- {:noreply, %{state | backoff: backoff}}
+ {:noreply, %{state | backoff: backoff, connected_server: server, connected_port: port}}
end
# Logon successful
@@ -254,6 +255,12 @@ defmodule IRC.Connection do
{:noreply, %{state | backoff: backoff}}
end
+ # ISUP
+ def handle_info({:isup, network}, state) do
+ IRC.UserTrack.clear_network(network)
+ {:noreply, %{state | network: network}}
+ end
+
# Been kicked
def handle_info({:kicked, _sender, chan, _reason}, state) do
ExIRC.Client.join(state.client, chan)
diff --git a/lib/irc/plugin_supervisor.ex b/lib/irc/plugin_supervisor.ex
index 5f93f17..24ac683 100644
--- a/lib/irc/plugin_supervisor.ex
+++ b/lib/irc/plugin_supervisor.ex
@@ -15,7 +15,7 @@ defmodule IRC.Plugin do
case DynamicSupervisor.start_child(__MODULE__, spec) do
{:ok, _} = res -> res
:ignore ->
- Logger.info("Ignored #{module}")
+ Logger.warn("Ignored #{module}")
:ignore
{:error,_} = res ->
Logger.error("Could not start #{module}: #{inspect(res, pretty: true)}")
diff --git a/lib/irc/user_track.ex b/lib/irc/user_track.ex
index 08b5160..5e1c3a3 100644
--- a/lib/irc/user_track.ex
+++ b/lib/irc/user_track.ex
@@ -17,6 +17,18 @@ defmodule IRC.UserTrack do
op(fn(ets) -> :ets.insert(ets, tuple) end)
end
+ def clear_network(network) do
+ op(fn(ets) ->
+ spec = [
+ {{:_, :"$1", :_, :_, :_, :_, :_, :_, :_, :_, :_},
+ [
+ {:==, :"$1", {:const, network}}
+ ], [:"$_"]}
+ ]
+ :ets.match_delete(ets, spec)
+ end)
+ end
+
def op(fun) do
GenServer.call(__MODULE__, {:op, fun})
end
@@ -97,6 +109,10 @@ defmodule IRC.UserTrack do
end
end
+ def clear_network(network) do
+ Storage.clear_network(network)
+ end
+
def merge_account(old_id, new_id) do
#iex(15)> :ets.fun2ms(fn(obj = {_, net, acct, _, _, _, _, _, _}) when net == network and acct == account -> obj end)