Permalink
Browse files

Handle initial RPL_WELCOME and RPL_YOURHOST.

  • Loading branch information...
1 parent 01e5d31 commit f0b272df951ba9f924a2971789a22314309ca74b @jlouis jlouis committed Jul 1, 2012
Showing with 31 additions and 6 deletions.
  1. +12 −1 src/pony.erl
  2. +13 −4 src/pony_client.erl
  3. +6 −1 src/pony_protocol.erl
View
@@ -1,6 +1,6 @@
-module(pony).
--export([start/0, me/0]).
+-export([start/0, me/0, description/0, server/0, version/0]).
start() ->
application:load(pony_core),
@@ -12,6 +12,17 @@ me() ->
{ok, N} = application:get_env(pony_core, host),
N.
+description() ->
+ {ok, N} = application:get_env(pony_core, description),
+ N.
+
+version() ->
+ {ok, V} = application:get_key(pony_core, vsn),
+ V.
+
+server() ->
+ io_lib:format("~s[todo]", [me()]).
+
%% ----------------------------------------------------------------------
ensure_started(App) ->
case application:start(App) of
View
@@ -32,7 +32,7 @@ start_link(ListenerPid, Socket, Transport, Opts) ->
Opts], []).
msg(Client, Msg) ->
- gen_server:cast(Client, {msg, Msg}).
+ gen_server:cast(Client, Msg).
%%%===================================================================
@@ -50,6 +50,11 @@ handle_call(Request, _From, State) ->
{reply, Reply, State}.
%% @private
+handle_cast({numeric, Numeric, Text},
+ #state { socket = Sock,
+ synchronized = {yes, _} } = State) ->
+ out(Sock, pony_protocol:render_numeric(Numeric, Text)),
+ {noreply, State};
handle_cast({msg, M}, #state { socket = Sock,
synchronized = {yes, _} } = State) ->
out(Sock, pony_protocol:render(M)),
@@ -82,9 +87,13 @@ handle_info(timeout, #state { synchronized = no,
%% process a limited amount of new connections
ranch:accept_ack(Listener),
ack(Socket),
+ msg(self(), {numeric, 'RPL_WELCOME', [pony:me(), "*", pony:description(), "*"]}),
+ msg(self(), {numeric, 'RPL_YOURHOST', [pony:me(), "*",
+ pony:server(), pony:version()]}),
+ %% this.SendMotd()
{noreply, State#state { synchronized = {yes, Hostname} }};
handle_info(Info, State) ->
- lager:warning("Unknown message received: ~p", [Info]),
+ lager:warning("Unknown message received: ~p State: ~p", [Info, State]),
{noreply, State}.
%% @private
@@ -100,8 +109,8 @@ code_change(_OldVsn, State, _Extra) ->
ack({Transport, Socket}) ->
Transport:setopts(Socket, [{active, once}]).
-handle_message(_M, State) ->
- %% Ignore for now
+handle_message(M, State) ->
+ lager:debug("Incoming Message: ~s", [pony_protocol:stringify(M)]),
State.
%% @doc Synchronize the socket
View
@@ -1,7 +1,7 @@
-module(pony_protocol).
-export([parse/1, stringify/1, stringify/3]).
-export([numeric/1]).
--export([render/1]).
+-export([render/1, render_numeric/2]).
command_to_atom(X) when is_binary(X) ->
command_to_atom(binary_to_list(X));
@@ -293,5 +293,10 @@ numeric(N) when is_atom(N) ->
'RPL_ENDOFRSACHALLENGE2'-> 741
end.
+render_numeric('RPL_WELCOME', Args) ->
+ io_lib:format(":~s 001 ~s :Welcome to the ~s Internet Relay Chat Network ~s", Args);
+render_numeric('RPL_YOURHOST', Args) ->
+ io_lib:format(":~s 002 ~s :Your host is ~s, running version ~s", Args).
+
render(_X) ->
"todo".

0 comments on commit f0b272d

Please sign in to comment.