Skip to content

Commit

Permalink
Renamed application to bqs
Browse files Browse the repository at this point in the history
  • Loading branch information
sedrik committed Aug 13, 2013
1 parent 022911a commit 1cb0587
Show file tree
Hide file tree
Showing 15 changed files with 108 additions and 108 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion init.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
erl -pa deps/*/ebin -pa ebin -eval "application:start(crypto), application:start(compiler), application:start(syntax_tools), application:start(lager), application:start(cowboy), application:start(browserquest_srv)."
erl -pa deps/*/ebin -pa ebin -eval "application:start(crypto), application:start(compiler), application:start(syntax_tools), application:start(lager), application:start(cowboy), application:start(bqs)."
6 changes: 3 additions & 3 deletions src/browserquest_srv.app.src → src/bqs.app.src
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{application, browserquest_srv,
{application, bqs,
[
{description, "Backend server for browserquest"},
{description, "Backend server for bqs"},
{vsn, "0.1.0"},
{registered, []},
{applications, [
Expand All @@ -12,7 +12,7 @@
crypto,
syntax_tools
]},
{mod, { browserquest_srv_app, []}},
{mod, { bqs_app, []}},
{env, [
{world_map, "world_map.json"},
{riak_ip, "127.0.0.1"},
Expand Down
10 changes: 5 additions & 5 deletions src/browserquest_srv_app.erl → src/bqs_app.erl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-module(browserquest_srv_app).
-module(bqs_app).

-behaviour(application).

Expand Down Expand Up @@ -26,19 +26,19 @@ start(_StartType, _StartArgs) ->
end,

Dispatch = [{'_', [
{'_', browserquest_srv_handler, []}
{'_', bqs_handler, []}
]}],

%% lager:debug("Starting browserquest_srv on port ~p", [ListeningPort]),
%% lager:debug("Starting bqs on port ~p", [ListeningPort]),

%% Name, NbAcceptors, Transport, TransOpts, Protocol, ProtoOpts
%% Listen in 10100/tcp for http connections.
ranch:start_listener(browserquest_srv_handler, 100,
ranch:start_listener(bqs_handler, 100,
cowboy_tcp_transport, [{port, ListeningPort}],
cowboy_http_protocol, [{dispatch, Dispatch}]
),

browserquest_srv_sup:start_link().
bqs_sup:start_link().

stop(_State) ->
ok.
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
%%% @end
%%% Created : 8 Jul 2012 by Niclas Axelsson <burbas@Niclass-MacBook-Pro.local>
%%%-------------------------------------------------------------------
-module(browserquest_srv_entity_handler).
-module(bqs_entity_handler).

-behaviour(gen_server).

-include("../include/browserquest.hrl").
-include("../include/bqs.hrl").
%% API
-export([
start_link/0,
Expand Down Expand Up @@ -94,7 +94,7 @@ move_zone(OldZone, NewZone) ->
%% @end
%%--------------------------------------------------------------------
init([]) ->
Args = [fun add_mob/1, browserquest_srv_map:get_attribute("mobAreas")],
Args = [fun add_mob/1, bqs_map:get_attribute("mobAreas")],
erlang:spawn(lists, foreach, Args),
{ok, #state{zones = dict:new(), targets = dict:new()}}.

Expand Down Expand Up @@ -237,4 +237,4 @@ calculate_dmg(TargetArmor, SourceWeapon) ->
end.

add_mob(#mobarea{type = Type, x = X, y = Y}) ->
browserquest_srv_mob_sup:add_child(Type, X, Y).
bqs_mob_sup:add_child(Type, X, Y).
32 changes: 16 additions & 16 deletions src/browserquest_srv_handler.erl → src/bqs_handler.erl
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
%%% @end
%%% Created : 7 July 2012 by <gustav.simonsson@gmail.com>
%%%-------------------------------------------------------------------
-module(browserquest_srv_handler).
-module(bqs_handler).
-compile(export_all).

-behaviour(cowboy_http_handler).
-behaviour(cowboy_websocket_handler).

-include("../include/browserquest.hrl").
-include("../include/bqs.hrl").

% Behaviour cowboy_http_handler
-export([init/3, handle/2, terminate/3]).
Expand All @@ -22,7 +22,7 @@
websocket_info/3, websocket_terminate/3
]).

-define(APP, browserquest_srv).
-define(APP, bqs).

-record(state, {
riak,
Expand Down Expand Up @@ -80,7 +80,7 @@ websocket_handle({text, Msg}, Req, State) ->
% With this callback we can handle other kind of
% messages, like binary.
websocket_handle(_Any, Req, State) ->
browserquest_srv_util:unexpected_info(
bqs_util:unexpected_info(
?MODULE,"websocket binary received", State),
{ok, Req, State}.

Expand All @@ -94,7 +94,7 @@ websocket_info(<<"tick">>, Req, State = #state{player = undefined}) ->
{ok, Req, State};

websocket_info(<<"tick">>, Req, State = #state{player = Player}) ->
case browserquest_srv_player:get_surrondings(Player) of
case bqs_player:get_surrondings(Player) of
[] ->
ok;
ActionList ->
Expand All @@ -114,56 +114,56 @@ websocket_info(Msg, Req, State) ->

websocket_terminate(_Reason, _Req, #state{player = Player}) ->
lager:debug("Connection closed"),
browserquest_srv_player:stop(Player),
bqs_player:stop(Player),
ok.

%%%===================================================================
%%% Internal functions
%%%===================================================================
parse_action([?HELLO, Name, Armor, Weapon], State) ->
%% This is a player call
{ok, Player} = browserquest_srv_player:start_link(Name, Armor, Weapon),
{ok, Status} = browserquest_srv_player:get_status(Player),
{ok, Player} = bqs_player:start_link(Name, Armor, Weapon),
{ok, Status} = bqs_player:get_status(Player),
{json, [?WELCOME|Status], State#state{player = Player}};

parse_action([?MOVE, X, Y], State = #state{player = Player}) ->
{ok, Status} = browserquest_srv_player:move(Player, X, Y),
{ok, Status} = bqs_player:move(Player, X, Y),
lager:debug("MOVED ~p ~p", [X, Y]),
{json, [?MOVE|Status], State};

parse_action([?ATTACK, Target], State = #state{player = Player}) ->
ok = browserquest_srv_player:attack(Player, Target),
ok = bqs_player:attack(Player, Target),
{ok, [], State};

parse_action([?HIT, Target], State = #state{player = Player}) ->
{ok, Return} = browserquest_srv_player:hit(Player, Target),
{ok, Return} = bqs_player:hit(Player, Target),

{json, Return, State};

parse_action([?DAMAGE, _Target], State = #state{player = _Player}) ->
{ok, [], State};

parse_action([?HURT, Attacker], State = #state{player = Player}) ->
{ok, Status} = browserquest_srv_player:hurt(Player, Attacker),
{ok, Status} = bqs_player:hurt(Player, Attacker),
{json, Status, State};

parse_action([?AGGRO, _Target], State = #state{player = _Player}) ->
{ok, [], State};

parse_action([?CHAT, Message], State = #state{player = Player}) ->
{ok, Return} = browserquest_srv_player:chat(Player, Message),
{ok, Return} = bqs_player:chat(Player, Message),
{json, Return, State};

parse_action([?TELEPORT, X, Y], State = #state{player = Player}) ->
{ok, Status} = browserquest_srv_player:move(Player, X, Y),
{ok, Status} = bqs_player:move(Player, X, Y),
{json, [?TELEPORT|Status], State};

parse_action([?CHECK, Value], State = #state{player = Player}) ->
browserquest_srv_player:set_checkpoint(Player, Value),
bqs_player:set_checkpoint(Player, Value),
{ok, [], State};

parse_action([?ZONE], State = #state{player = Player}) ->
browserquest_srv_player:update_zone(Player),
bqs_player:update_zone(Player),
{ok, [], State};

parse_action(ActionList, _State) ->
Expand Down
14 changes: 7 additions & 7 deletions src/browserquest_srv_item.erl → src/bqs_item.erl
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
%%% @end
%%% Created : 7 July 2012 by <gustav.simonsson@gmail.com>
%%%-------------------------------------------------------------------
-module(browserquest_srv_item).
-module(bqs_item).

-behaviour(gen_server).

-include("../include/browserquest.hrl").
-include("../include/bqs.hrl").
%% API
-export([create/4, start_link/4]).

Expand Down Expand Up @@ -38,24 +38,24 @@ pickup(ItemPid, PlayerState) ->
%%% gen_server callbacks
%%%===================================================================
init([Zone, Item, Id, SpawnInfo]) ->
browserquest_srv_entity_handler:register(Zone, Item, Id, SpawnInfo),
bqs_entity_handler:register(Zone, Item, Id, SpawnInfo),
{ok, #state{id = Item, zone = Zone}}.

handle_call({pickup, PlayerState}, _From,
State = #state{id = Id, zone = Zone}) ->
browserquest_srv_entity_handler:unregister(Zone),
bqs_entity_handler:unregister(Zone),
{stop, normal, new_player_state(Id, PlayerState), State};
handle_call(Request, From, State) ->
browserquest_srv_util:unexpected_call(?MODULE, Request, From, State),
bqs_util:unexpected_call(?MODULE, Request, From, State),
Reply = ok,
{reply, Reply, State}.

handle_cast(Msg, State) ->
browserquest_srv_util:unexpected_cast(?MODULE, Msg, State),
bqs_util:unexpected_cast(?MODULE, Msg, State),
{noreply, State}.

handle_info(Info, State) ->
browserquest_srv_util:unexpected_info(?MODULE, Info, State),
bqs_util:unexpected_info(?MODULE, Info, State),
{noreply, State}.

terminate(_Reason, _State) ->
Expand Down
12 changes: 6 additions & 6 deletions src/browserquest_srv_map.erl → src/bqs_map.erl
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
%%% @end
%%% Created : 7 July 2012 by <gustav.simonsson@gmail.com>
%%%-------------------------------------------------------------------
-module(browserquest_srv_map).
-module(bqs_map).

-behaviour(gen_server).

-include("../include/browserquest.hrl").
-include("../include/bqs.hrl").
%% API
-export([start_link/1]).

Expand Down Expand Up @@ -46,7 +46,7 @@ tileid_to_pos(TileId) ->
%%% gen_server callbacks
%%%===================================================================
init([MapName]) ->
File = code:priv_dir(browserquest_srv) ++ "/maps/" ++ MapName,
File = code:priv_dir(bqs) ++ "/maps/" ++ MapName,
{ok, FileBin} = file:read_file(File),
Json = mochijson3:decode(FileBin),
Height = get_json_value("height", Json),
Expand Down Expand Up @@ -95,16 +95,16 @@ handle_call({tileid_to_pos, TileId}, _From, #map{attributes = PL} = Map) ->
TileToPos = proplists:get_value("tiletopos", PL),
{reply, tileid_to_pos(TileId, TileToPos), Map};
handle_call(Request, From, State) ->
browserquest_srv_util:unexpected_call(?MODULE, Request, From, State),
bqs_util:unexpected_call(?MODULE, Request, From, State),
Reply = ok,
{reply, Reply, State}.

handle_cast(Msg, State) ->
browserquest_srv_util:unexpected_cast(?MODULE, Msg, State),
bqs_util:unexpected_cast(?MODULE, Msg, State),
{noreply, State}.

handle_info(Info, State) ->
browserquest_srv_util:unexpected_info(?MODULE, Info, State),
bqs_util:unexpected_info(?MODULE, Info, State),
{noreply, State}.

terminate(_Reason, _State) ->
Expand Down
36 changes: 18 additions & 18 deletions src/browserquest_srv_mob.erl → src/bqs_mob.erl
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
%%% @end
%%% Created : 7 July 2012 by <sir.sedrik@gmail.com>
%%%-------------------------------------------------------------------
-module(browserquest_srv_mob).
-module(bqs_mob).

-behaviour(gen_server).

-include("../include/browserquest.hrl").
-include("../include/bqs.hrl").

%% API
-export([start_link/3, receive_damage/2, get_stats/1]).
Expand All @@ -32,24 +32,24 @@ start_link(Type, X, Y) ->
receive_damage(Pid, Amount) when is_pid(Pid) ->
gen_server:cast(Pid, {receive_damage, Amount});
receive_damage(Target, Amount) ->
{ok, Pid} = browserquest_srv_entity_handler:get_target(Target),
{ok, Pid} = bqs_entity_handler:get_target(Target),
receive_damage(Pid, Amount).

get_stats(Pid) when is_pid(Pid) ->
lager:debug("Trying to get stats from Pid: ~p", [Pid]),
gen_server:call(Pid, {get_stats});
get_stats(Target) ->
{ok, Pid} = browserquest_srv_entity_handler:get_target(Target),
{ok, Pid} = bqs_entity_handler:get_target(Target),
get_stats(Pid).


%%%===================================================================
%%% gen_server callbacks
%%%===================================================================
init([BinType, X, Y]) ->
Id = browserquest_srv_entity_handler:generate_id("1"),
Zone = browserquest_srv_entity_handler:make_zone(X, Y),
Type = browserquest_srv_util:type_to_internal(BinType),
Id = bqs_entity_handler:generate_id("1"),
Zone = bqs_entity_handler:make_zone(X, Y),
Type = bqs_util:type_to_internal(BinType),
Orientation = random:uniform(4),
State = do_init(
Type,
Expand All @@ -58,7 +58,7 @@ init([BinType, X, Y]) ->
orientation = Orientation}
),

browserquest_srv_entity_handler:register(Zone, Type, Id, {action, [false,
bqs_entity_handler:register(Zone, Type, Id, {action, [false,
?SPAWN, Id, Type, X, Y]}),
{ok, State#mob_state{zone = Zone, id = Id, type = Type}}.

Expand All @@ -67,7 +67,7 @@ handle_call({get_stats}, _From, State = #mob_state{id = Id, weapon = Weapon, arm
{reply, {ok, {Id, Weapon, Armor}}, State};

handle_call(Request, From, State) ->
browserquest_srv_util:unexpected_call(?MODULE, Request, From, State),
bqs_util:unexpected_call(?MODULE, Request, From, State),
{reply, ok, State}.

handle_cast({tick}, State = #mob_state{hate = _Hate, hitpoints = HP}) ->
Expand Down Expand Up @@ -96,7 +96,7 @@ handle_cast({event, _From, ?WARRIOR, {action, [?MOVE, _Id, ?WARRIOR, _X, _Y, _Na
handle_cast({event, _From, ?WARRIOR, {action, [?ATTACK, Id]}}, State) ->
%% Hates on for you
lager:debug("RETALIATE!", [State#mob_state.id, Id]),
browserquest_srv_entity_handler:event(State#mob_state.zone,
bqs_entity_handler:event(State#mob_state.zone,
State#mob_state.type,
{action, [?ATTACK, State#mob_state.id]}),
{noreply, State};
Expand All @@ -114,7 +114,7 @@ handle_cast({event, From, ?WARRIOR,
case erlang:integer_to_list(Id) of
Target ->
%% I'm gonna KILL you
browserquest_srv_entity_handler:event(
bqs_entity_handler:event(
Zone, Type, {action, [?ATTACK, Id]}),
{noreply, State#mob_state{hate = [From]}};
_ ->
Expand All @@ -129,21 +129,21 @@ handle_cast({receive_damage, Amount},
NewState = State#mob_state{hitpoints = Total},
case Total =< 0 of
true ->
browserquest_srv_entity_handler:event(
bqs_entity_handler:event(
Zone, Type, {action, [?DESPAWN, Id]}),
browserquest_srv_entity_handler:unregister(Zone),
bqs_entity_handler:unregister(Zone),
drop_item(Item, X, Y),
{stop, normal, NewState};
false ->
{noreply, NewState}
end;

handle_cast(Msg, State) ->
browserquest_srv_util:unexpected_cast(?MODULE, Msg, State),
bqs_util:unexpected_cast(?MODULE, Msg, State),
{noreply, State}.

handle_info(Info, State) ->
browserquest_srv_util:unexpected_info(?MODULE, Info, State),
bqs_util:unexpected_info(?MODULE, Info, State),
{noreply, State}.

terminate(_Reason, _State) ->
Expand All @@ -158,11 +158,11 @@ code_change(_OldVsn, State, _Extra) ->
%%%===================================================================
drop_item(Item, X, Y) ->
%% Items start with 9
Id = browserquest_srv_entity_handler:generate_id("9"),
Zone = browserquest_srv_entity_handler:make_zone(X,Y),
Id = bqs_entity_handler:generate_id("9"),
Zone = bqs_entity_handler:make_zone(X,Y),
SpawnInfo = [?SPAWN, Id, Item, X, Y],
%% Remove apply, spawn item gen_server, call register from it
Fun = fun() -> browserquest_srv_item:create(Zone, Item, Id, SpawnInfo) end,
Fun = fun() -> bqs_item:create(Zone, Item, Id, SpawnInfo) end,
spawn(Fun),
ok.

Expand Down
Loading

0 comments on commit 1cb0587

Please sign in to comment.