Skip to content

Commit

Permalink
Fix small bugs, flesh out example a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
brendonh committed Feb 14, 2010
1 parent 20d86d6 commit 4cdd138
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/slerl_api.erl
Expand Up @@ -11,7 +11,7 @@
position/0, block/0,
teleport/2,
chat/1, chat/2, chat/3,
im_name/2,
im/2,
retrieve_ims/0,
subscribe/1, unsubscribe/1,
get_region/1, get_uuids/1,
Expand Down Expand Up @@ -53,7 +53,7 @@ chat(Type, Channel, Text) ->
Channel,
make_bin_string(Text)}).

im_name(Name, Text) ->
im(Name, Text) ->
case exact_avatar_uuid(Name) of
not_found -> {error, not_found};
UUID -> gen_server:call(Bot, {send_im, UUID, make_bin_string(Text)})
Expand Down
7 changes: 5 additions & 2 deletions src/slerl_bot.erl
Expand Up @@ -114,8 +114,11 @@ handle_call(retrieve_ims, _From, State) ->
{reply, Reply, State};

handle_call({send_im, UUID, Text}, _From, State) ->
send_im(UUID, none, Text, State),
{reply, ok, State};
Reply = case current_sim(State) of
none -> {error, no_sim};
_ -> send_im(UUID, none, Text, State)
end,
{reply, Reply, State};

handle_call(_Request, _From, State) ->
{reply, unknown_call, State}.
Expand Down
31 changes: 25 additions & 6 deletions src/slerl_sandbox.erl
Expand Up @@ -5,6 +5,8 @@

-export([test/0]).

-define(OWNER, "Brendon Lanley").

test() ->
application:start(slerl),
{ok, [Bits]} = file:consult("login.config"),
Expand All @@ -29,26 +31,43 @@ after_login(Bot) ->
start_chat_logger(Bot) ->
spawn(fun() ->
Bot:subscribe([chat, im]),
chat_logger()
chat_logger(Bot)
end).

chat_logger() ->
chat_logger(Bot) ->
receive
{message, chat, Chat, _Name} ->
io:format("(~.8s) <~s> ~s~n",
[Chat#chat.type, Chat#chat.fromName, Chat#chat.text]);


{message, im, #im{fromName= <<?OWNER>>,
type=message_from_agent}=IM, _Name} ->
handle_command(Bot, IM#im.text, IM);

{message, im, #im{type=message_from_agent}=IM, _Name} ->
io:format("*****IM***** <~s> ~s~n",
[IM#im.fromName, IM#im.text]);

{message, im, IM, _Name} ->
io:format("[~s ~s]~n", [IM#im.fromName, IM#im.type]);

Other ->
?DBG({other, Other})
Other -> ?DBG(Other)
end,
chat_logger().

chat_logger(Bot).


handle_command(Bot, <<"port ", Region/binary>>, _) ->
Bot:im(?OWNER, list_to_binary(["Porting to ", Region])),
Bot:teleport(Region, {128, 128, 2500});
handle_command(Bot, <<"heel">>, IM) ->
Position = slerl_util:get_field(['MessageBlock', 'Position'], IM#im.message),
{ok, {SimName, _}} = Bot:position(),
case Position of
{0.0, 0.0, 0.0} -> Bot:im(?OWNER, "Port me first");
_ ->
Result = Bot:teleport(SimName, Position),
Bot:im(?OWNER, lists:flatten(io_lib:format("Result: ~p", [Result])))
end;
handle_command(_, _, _) -> ok.

2 changes: 1 addition & 1 deletion src/slerl_sim.erl
Expand Up @@ -129,7 +129,7 @@ handle_info({message, 'RegionHandshake', Message, _Conn}, State) ->
SimName = slerl_util:extract_string(
slerl_util:get_field(['RegionInfo', 'SimName'], Message#message.message)),
RegionID = slerl_util:get_field(['RegionInfo2', 'RegionID'], Message#message.message),
NewSimInfo = (State#state.simInfo)#sim{regionID=RegionID},
NewSimInfo = (State#state.simInfo)#sim{regionID=RegionID, name=SimName},
bot_cast({simulator, region_changed, {NewSimInfo, SimName}}, State),
{noreply, State#state{simInfo=NewSimInfo}};

Expand Down

0 comments on commit 4cdd138

Please sign in to comment.