added ggs_logger module and implemented some ggs_table stuff
This commit is contained in:
parent
62be1f04cc
commit
4be808049e
5 changed files with 52 additions and 23 deletions
|
|
@ -12,36 +12,36 @@
|
||||||
|
|
||||||
%% @doc Starts the coordinator process.
|
%% @doc Starts the coordinator process.
|
||||||
start_link() ->
|
start_link() ->
|
||||||
not_implemented().
|
ggs_logger:not_implemented().
|
||||||
|
|
||||||
%% @doc Terminates the coordinator process.
|
%% @doc Terminates the coordinator process.
|
||||||
stop(_Reason) ->
|
stop(_Reason) ->
|
||||||
not_implemented().
|
ggs_logger:not_implemented().
|
||||||
|
|
||||||
%% @doc Joins table with specified token
|
%% @doc Joins table with specified token
|
||||||
join_table(_Token) ->
|
join_table(_Token) ->
|
||||||
not_implemented().
|
ggs_logger:not_implemented().
|
||||||
|
|
||||||
%% @doc Create a new table
|
%% @doc Create a new table
|
||||||
create_table(_Params) ->
|
create_table(_Params) ->
|
||||||
not_implemented().
|
ggs_logger:not_implemented().
|
||||||
|
|
||||||
%% @doc This is the first function run by a newly created players.
|
%% @doc This is the first function run by a newly created players.
|
||||||
%% Generates a unique token that we use to identify the player.
|
%% Generates a unique token that we use to identify the player.
|
||||||
join_lobby() ->
|
join_lobby() ->
|
||||||
not_implemented().
|
ggs_logger:not_implemented().
|
||||||
|
|
||||||
%% @doc Act as a supervisor to player and respawns player when it gets bad data.
|
%% @doc Act as a supervisor to player and respawns player when it gets bad data.
|
||||||
respawn_player(_Player, _Socket) ->
|
respawn_player(_Player, _Socket) ->
|
||||||
not_implemented().
|
ggs_logger:not_implemented().
|
||||||
|
|
||||||
%% @doc Act as a supervisor to table and respawns table when it gets bad data.
|
%% @doc Act as a supervisor to table and respawns table when it gets bad data.
|
||||||
respawn_table(_Token) ->
|
respawn_table(_Token) ->
|
||||||
not_implemented().
|
ggs_logger:not_implemented().
|
||||||
|
|
||||||
%% @doc Removes a player from coordinator.
|
%% @doc Removes a player from coordinator.
|
||||||
remove_player(From, Player) ->
|
remove_player(From, Player) ->
|
||||||
not_implemented().
|
ggs_logger:not_implemented().
|
||||||
|
|
||||||
%% gen_server callbacks
|
%% gen_server callbacks
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,12 +20,12 @@
|
||||||
%% Port = Integer
|
%% Port = Integer
|
||||||
%% Pid = #<Pid>
|
%% Pid = #<Pid>
|
||||||
start_link(Port) ->
|
start_link(Port) ->
|
||||||
not_implemented().
|
ggs_logger:not_implemented().
|
||||||
|
|
||||||
%% @doc Stops the dispatcher with the specified reason.
|
%% @doc Stops the dispatcher with the specified reason.
|
||||||
%% @spec stop(Reason) -> ok.
|
%% @spec stop(Reason) -> ok.
|
||||||
%% Reason = String
|
%% Reason = String
|
||||||
stop(Reason) -> not_implemented().
|
stop(Reason) -> ggs_logger:not_implemented().
|
||||||
|
|
||||||
|
|
||||||
%% gen_server callbacks
|
%% gen_server callbacks
|
||||||
|
|
|
||||||
8
src/ggs_logger.erl
Normal file
8
src/ggs_logger.erl
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
-module(ggs_logger).
|
||||||
|
-export(not_implemented/0, log/2).
|
||||||
|
|
||||||
|
not_implemented() ->
|
||||||
|
exit(not_implemented).
|
||||||
|
|
||||||
|
log(Format, Args) ->
|
||||||
|
error_logger:info_msg(Format, Args).
|
||||||
|
|
@ -13,7 +13,7 @@
|
||||||
%% identifying the player.
|
%% identifying the player.
|
||||||
%% @spec start_link(Socket::socket()) -> ok
|
%% @spec start_link(Socket::socket()) -> ok
|
||||||
start_link(Socket) ->
|
start_link(Socket) ->
|
||||||
not_implemented().
|
ggs_logger:not_implemented().
|
||||||
|
|
||||||
|
|
||||||
%% @doc Handles incoming messages from the GGS and forwards them through the player
|
%% @doc Handles incoming messages from the GGS and forwards them through the player
|
||||||
|
|
@ -21,16 +21,16 @@ start_link(Socket) ->
|
||||||
%% @spec notify(Player::Pid(), From::Pid(),
|
%% @spec notify(Player::Pid(), From::Pid(),
|
||||||
%% {Command::String(), Message::string()}) -> ok
|
%% {Command::String(), Message::string()}) -> ok
|
||||||
notify(Player, From, Message) ->
|
notify(Player, From, Message) ->
|
||||||
not_implemented().
|
ggs_logger:not_implemented().
|
||||||
|
|
||||||
%% @doc Get the player token uniquely representing the player.
|
%% @doc Get the player token uniquely representing the player.
|
||||||
%% @spec get_token() -> string()
|
%% @spec get_token() -> string()
|
||||||
get_token() ->
|
get_token() ->
|
||||||
not_implemented().
|
ggs_logger:not_implemented().
|
||||||
|
|
||||||
|
|
||||||
%% @doc Properly terminates the player process. The player token will be destroyed.
|
%% @doc Properly terminates the player process. The player token will be destroyed.
|
||||||
%% Makes table token unreferenced and destroys the process in the end.
|
%% Makes table token unreferenced and destroys the process in the end.
|
||||||
%% @spec stop(Table::pid()) -> Reason::string()
|
%% @spec stop(Table::pid()) -> Reason::string()
|
||||||
stop(Table) ->
|
stop(Table) ->
|
||||||
not_implemented().
|
ggs_logger:not_implemented().
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,3 @@
|
||||||
%% @doc This module represents a Player with a Socket and a Token
|
|
||||||
|
|
||||||
-module(ggs_table).
|
-module(ggs_table).
|
||||||
-export([
|
-export([
|
||||||
start_link/1,
|
start_link/1,
|
||||||
|
|
@ -9,28 +7,51 @@
|
||||||
notify/3
|
notify/3
|
||||||
]).
|
]).
|
||||||
|
|
||||||
|
%% @doc This module represents a Player with a Socket and a Token
|
||||||
|
|
||||||
% @doc returns a new table
|
% @doc returns a new table
|
||||||
start_link(Token) ->
|
start_link(Token, Socket) ->
|
||||||
not_implemented().
|
spawn_link(fun(Token, Socket) ->
|
||||||
|
GameVM = ggs_gamevm:start_link();
|
||||||
|
loop(Token, Socket, GameVM, [])
|
||||||
|
).
|
||||||
|
|
||||||
% @doc adds a player to a table
|
% @doc adds a player to a table
|
||||||
add_player(Table, Player) ->
|
add_player(Table, Player) ->
|
||||||
not_implemented().
|
ggs_logger:not_implemented().
|
||||||
|
|
||||||
% @doc removes player form a table
|
% @doc removes player form a table
|
||||||
remove_player(Table, Player) ->
|
remove_player(Table, Player) ->
|
||||||
not_implemented().
|
ggs_logger:not_implemented().
|
||||||
|
|
||||||
% @doc stops the table process
|
% @doc stops the table process
|
||||||
stop(Table) ->
|
stop(Table) ->
|
||||||
not_implemented().
|
Table ! {'EXIT', self(), normal}
|
||||||
|
|
||||||
% @doc notifies the table with a message from a player
|
% @doc notifies the table with a message from a player
|
||||||
notify(Table, Player, Message) ->
|
notify(Table, Player, Message) ->
|
||||||
not_implemented().
|
Table ! {notify, Player, Message}.
|
||||||
|
|
||||||
|
|
||||||
% loop
|
% loop
|
||||||
|
loop(Token, Socket, GameVM, PlayerList) ->
|
||||||
|
receive
|
||||||
|
{add_player, Player} ->
|
||||||
|
NewPlayerList = list:append(PlayerList, [Player]),
|
||||||
|
loop(Token, Socket, GameVM, NewPlayerList);
|
||||||
|
{remove_player, Player} ->
|
||||||
|
NewPlayerList = list:delete(Player, PlayerList),
|
||||||
|
loop(Token, Socket, GameVM, NewPlayerList);
|
||||||
|
{notify, Player, Message} ->
|
||||||
|
case Message of
|
||||||
|
{server, define, Args} ->
|
||||||
|
ggs_gamevm:define(GameVM, Args),
|
||||||
|
loop(Token, Socket, GameVM, PlayerList);
|
||||||
|
{game, Command, Args} ->
|
||||||
|
ggs_gamevm:user_command(GameVM, Player, Command, Args),
|
||||||
|
loop(Token, Socket, GameVM, PlayerList);
|
||||||
|
end
|
||||||
|
end.
|
||||||
|
|
||||||
|
|
||||||
% private helpers
|
% private helpers
|
||||||
Reference in a new issue