diff --git a/src/pony_chan_srv.erl b/src/pony_chan_srv.erl index eea802b..1c38019 100644 --- a/src/pony_chan_srv.erl +++ b/src/pony_chan_srv.erl @@ -17,6 +17,7 @@ ]). -export([channel_members/1, + list_channels/0, set_topic/3, topic/1, part_channel/1, @@ -32,8 +33,8 @@ -define(SERVER, ?MODULE). -record(channel, - { name, - topic }). + { name :: binary(), + topic :: binary() | undefined }). -record(state, {}). @@ -58,6 +59,10 @@ quits(Pid, Name) -> channel_members(Channel) -> [Pid || {Pid, _} <- gproc:lookup_local_properties({channel, Channel})]. +list_channels() -> + Channels = ets:match_object(?CHAN_TAB, '_'), + [{N, length(channel_members(N)), T} || #channel { topic = T, name = N} <- Channels]. + part_channel(Channel) -> gproc:unreg({p, l, {channel, Channel}}). diff --git a/src/pony_client.erl b/src/pony_client.erl index 1efda77..8222a03 100644 --- a/src/pony_client.erl +++ b/src/pony_client.erl @@ -216,6 +216,16 @@ handle_message(Prefix, Command, Args, #state { nickname = CurNick } = State) -> || Pid <- pony_chan_srv:channel_members(Channel)], pony_chan_srv:part_channel(Channel), State; + {<<>>, list, [<<>>]} -> + send_numeric('RPL_LISTSTART', [CurNick]), + Channels = pony_chan_srv:list_channels(), + [send_numeric('RPL_LIST', [CurNick, Chan, Count, case Topic of + undefined -> ""; + X -> X + end]) + || {Chan, Count, Topic} <- Channels], + send_numeric('RPL_LISTEND', [CurNick]), + State; _ -> handle_nick_user(Prefix, Command, Args, State) end. diff --git a/src/pony_protocol.erl b/src/pony_protocol.erl index 581cdbe..e338ffc 100644 --- a/src/pony_protocol.erl +++ b/src/pony_protocol.erl @@ -95,6 +95,15 @@ render_numeric('RPL_NOTOPIC', [Nick, Channel]) -> render_numeric('RPL_TOPIC', [Nick, Chan, Topic]) -> io_lib:format(":~s 332 ~s ~s :~s", [pony:me(), Nick, Chan, Topic]); +render_numeric('RPL_LISTSTART', [Nick]) -> + io_lib:format(":~s 321 ~s Channel :Users Topic", + [pony:me(), Nick]); +render_numeric('RPL_LIST', [Nick, Chan, Count, Topic]) -> + io_lib:format(":~s 322 ~s ~s ~B :~s", + [pony:me(), Nick, Chan, Count, Topic]); +render_numeric('RPL_LISTEND', [Nick]) -> + io_lib:format(":~s 323 ~s :End of /LIST", + [pony:me(), Nick]); render_numeric('RPL_NAMREPLY', [Nick, Chan, Names]) -> io_lib:format(":~s 353 ~s ~s ~s :~s", [pony:me(), Nick, "=", %% This is a RatBox thing