Permalink
Browse files

added reload support

  • Loading branch information...
1 parent 31833e5 commit 65eff1aaa0ae30ad70380b5e5f4e31e226d94ddc @dnet committed Dec 27, 2010
Showing with 46 additions and 3 deletions.
  1. +26 −1 admin.erl
  2. +13 −1 ping.erl
  3. +7 −1 pong.erl
View
@@ -1,12 +1,16 @@
-module(admin).
--export([ircmain/1, ircproc/1, lsmod/2, rmmod/3, insmod/3]).
+-export([ircmain/1, ircproc/1, lsmod/2, rmmod/3, insmod/3, reload/3, reload/2]).
-include("nick.hrl").
ircmain(Contact) ->
Pid = spawn(?MODULE, ircproc, [Contact]),
Contact ! {subscribe, Pid},
Pid.
+reload(Contact, Pid) ->
+ Pid ! reloaded,
+ ircproc(Contact).
+
ircproc(Contact) ->
receive
quit -> quit;
@@ -23,6 +27,8 @@ ircproc(Contact) ->
{ident, Pid} ->
Pid ! {ident, "admin"},
ircproc(Contact);
+ {reload, Pid} ->
+ ?MODULE:reload(Contact, Pid);
_ -> ircproc(Contact)
end.
@@ -100,6 +106,13 @@ process_privmsg("-insmod", Remainder, ReplyTo, Prefix, Contact) ->
false ->
noreply
end;
+process_privmsg("-reload", Remainder, ReplyTo, Prefix, Contact) ->
+ case admin(Prefix) of
+ true ->
+ spawn(?MODULE, reload, [ReplyTo, Remainder, Contact]), noreply;
+ false ->
+ noreply
+ end;
process_privmsg("-load", [Module | _], ReplyTo, Prefix, _Contact) ->
case admin(Prefix) of
true ->
@@ -166,6 +179,18 @@ insmod(To, [ModName | Params], Contact) ->
Contact ! {raw, "PRIVMSG " ++ To ++ " :(timeout)"}
end.
+reload(To, [FirstParam | _], Contact) ->
+ N = list_to_integer(FirstParam),
+ Contact ! {getmods, self()},
+ receive
+ {mods, L} ->
+ lists:nth(N, L) ! {reload, self()},
+ Resp = receive reloaded -> "module reloaded successfully" after 2500 -> "(timeout)" end,
+ Contact ! {raw, "PRIVMSG " ++ To ++ " :" ++ Resp}
+ after 1500 ->
+ Contact ! {raw, "PRIVMSG " ++ To ++ " :(timeout)"}
+ end.
+
strip_crlf(Str) ->
string:strip(string:strip(Str, right, $\n), right, $\r).
View
@@ -1,11 +1,19 @@
-module(ping).
--export([ircmain/1, ircproc/1]).
+-export([ircmain/1, ircproc/1, reload/2, reload_inner/4]).
ircmain(Contact) ->
Pid = spawn(?MODULE, ircproc, [Contact]),
Contact ! {subscribe, Pid},
Pid.
+reload_inner(Contact, ServerName, Reconnect, Pid) ->
+ Pid ! reloaded,
+ inner_ircproc(Contact, ServerName, Reconnect).
+
+reload(Contact, Pid) ->
+ Pid ! reloaded,
+ ircproc(Contact).
+
ircproc(Contact) ->
receive
quit -> quit;
@@ -16,6 +24,8 @@ ircproc(Contact) ->
{ident, Pid} ->
Pid ! {ident, "ping"},
ircproc(Contact);
+ {reload, Pid} ->
+ ?MODULE:reload(Contact, Pid);
_ -> ircproc(Contact)
end.
@@ -28,6 +38,8 @@ inner_ircproc(Contact, ServerName, Reconnect) ->
{ident, Pid} ->
Pid ! {ident, "ping"},
inner_ircproc(Contact, ServerName, Reconnect);
+ {reload, Pid} ->
+ ?MODULE:reload_inner(Contact, ServerName, Reconnect, Pid);
_ -> inner_ircproc(Contact, ServerName)
after 120000 ->
case Reconnect of
View
@@ -1,11 +1,15 @@
-module(pong).
--export([ircmain/1, ircproc/1]).
+-export([ircmain/1, ircproc/1, reload/2]).
ircmain(Contact) ->
Pid = spawn(?MODULE, ircproc, [Contact]),
Contact ! {subscribe, Pid},
Pid.
+reload(Contact, Pid) ->
+ Pid ! reloaded,
+ ircproc(Contact).
+
ircproc(Contact) ->
receive
quit -> quit;
@@ -15,5 +19,7 @@ ircproc(Contact) ->
{ident, Pid} ->
Pid ! {ident, "pong"},
ircproc(Contact);
+ {reload, Pid} ->
+ ?MODULE:reload(Contact, Pid);
_ -> ircproc(Contact)
end.

0 comments on commit 65eff1a

Please sign in to comment.