Anonymous avatar Anonymous committed e5e2d91

Actually partly working now

Comments (0)

Files changed (2)

src/ircbot_server.erl

 -export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2,
          code_change/3]).
 
--record(conn_info, {socket, server, port, nickname, realname, channels = [], pid}).
+-record(conn_info, {socket, server, port, nickname, realname, channels = [], pid=self()}).
 
 %%--------------
 %%
 %% 
 %%------------------------------
 init(_Args) ->
-	irc_event_manager:add_handler(irc_rawtext_handler),
+%	irc_event_manager:add_handler(irc_rawtext_handler),
 	State = #conn_info{},
-	
+
 	{ok, State}.
 
 handle_call({connect, [Server, Port, Nick, Real]}, From, State) ->
 	
 	{ok, Sock} = gen_tcp:connect(Server, Port, ?TCP_OPTIONS),
 	NewState = State#conn_info{socket=Sock, server=Server, port=Port, 
-				   nickname=Nick, realname=Real, channels=[], pid=From},
+				   nickname=Nick, realname=Real, channels=[], pid=self()},
 	
         gen_tcp:send(NewState#conn_info.socket, ["NICK ", Nick, ?LINEFEED]),
         gen_tcp:send(NewState#conn_info.socket, ["USER ", Nick, " 8 * :", Real, ?LINEFEED]),
 	%% PING/PONG responses are fairly low-level so we've implemented this here.  This does not need to be user editable and so should remain in this low level portion of the bot.
 
 	From = binary_to_list(FromBin),
-	gen_server:call(State#conn_info.pid, {pong, From}),		
-
+	gen_tcp:send(State#conn_info.socket, ["PONG :", From, ?LINEFEED]),
 
 	{noreply, State};
 

src/ircbot_supervisor.erl

 -module(ircbot_supervisor).
 -author(jrb).
 -behaviour(supervisor).
-
 -export([start_link/0]).
-
--export([init/1]).
+-export([init/1, add_server/1, test/0]).
+-define(TCP_OPTIONS, [binary, {packet, line}, {keepalive, true} ]).
 
 start_link() ->
 	supervisor:start_link({local, ?MODULE}, ?MODULE, []).
 	Server = {ircbot_server_0, {ircbot_server, start_link, []},
 			permanent, 2000, worker, [gen_server] },
 
+	
+	{ok, {{one_for_one, 5, 10}, [EventManager]}}.
 
-	{ok, {{one_for_one, 5, 10}, [EventManager, Server]}}.
+test() ->
+	irc_event_manager:add_handler(irc_rawtext_handler),
+	add_server(["irc.synirc.net", 6667, "neckbeard23", "neckbeard", "synirc"]),
+        add_server(["irc.gamesurge.net", 6667, "nackbard23", "nackbard23", "gamesurge"]).
 
+add_server([Server, Port, Nick, Real, ServerName ]) ->
+	%% Add a new server process to the supervision tree and connect
+
+	%% Grab our socket
+
+	ServerAtom = list_to_atom(ServerName),
+
+
+	ChildRef = {ServerAtom, {ircbot_server, start_link, []}, temporary, 2000, worker, [gen_server]},
+
+	supervisor:start_child(ircbot_supervisor, ChildRef),
+	
+	Children = supervisor:which_children(ircbot_supervisor),
+
+	{ServerAtom, ServerPid, _, _}  = lists:keyfind(ServerAtom, 1, Children),
+	ircbot_server:connect(ServerPid, Server, Port, Nick, Real),
+	{ok, ServerPid}.
+		
+
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.