Permalink
Browse files

Fix small bugs, flesh out example a bit

  • Loading branch information...
1 parent 20d86d6 commit 4cdd138ddb5d1bcbfc83b998c5fdbf65c37d2d56 @brendonh committed Feb 14, 2010
Showing with 33 additions and 11 deletions.
  1. +2 −2 src/slerl_api.erl
  2. +5 −2 src/slerl_bot.erl
  3. +25 −6 src/slerl_sandbox.erl
  4. +1 −1 src/slerl_sim.erl
View
@@ -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,
@@ -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)})
View
@@ -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}.
View
@@ -5,6 +5,8 @@
-export([test/0]).
+-define(OWNER, "Brendon Lanley").
+
test() ->
application:start(slerl),
{ok, [Bits]} = file:consult("login.config"),
@@ -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.
+
View
@@ -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}};

0 comments on commit 4cdd138

Please sign in to comment.