added ggs_logger module and implemented some ggs_table stuff

This commit is contained in:
Jeena Paradies 2011-02-16 20:53:36 +01:00
parent 62be1f04cc
commit 4be808049e
5 changed files with 52 additions and 23 deletions

View file

@ -12,36 +12,36 @@
%% @doc Starts the coordinator process.
start_link() ->
not_implemented().
ggs_logger:not_implemented().
%% @doc Terminates the coordinator process.
stop(_Reason) ->
not_implemented().
ggs_logger:not_implemented().
%% @doc Joins table with specified token
join_table(_Token) ->
not_implemented().
ggs_logger:not_implemented().
%% @doc Create a new table
create_table(_Params) ->
not_implemented().
ggs_logger:not_implemented().
%% @doc This is the first function run by a newly created players.
%% Generates a unique token that we use to identify the player.
join_lobby() ->
not_implemented().
ggs_logger:not_implemented().
%% @doc Act as a supervisor to player and respawns player when it gets bad data.
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.
respawn_table(_Token) ->
not_implemented().
ggs_logger:not_implemented().
%% @doc Removes a player from coordinator.
remove_player(From, Player) ->
not_implemented().
ggs_logger:not_implemented().
%% gen_server callbacks

View file

@ -20,12 +20,12 @@
%% Port = Integer
%% Pid = #<Pid>
start_link(Port) ->
not_implemented().
ggs_logger:not_implemented().
%% @doc Stops the dispatcher with the specified reason.
%% @spec stop(Reason) -> ok.
%% Reason = String
stop(Reason) -> not_implemented().
stop(Reason) -> ggs_logger:not_implemented().
%% gen_server callbacks

8
src/ggs_logger.erl Normal file
View 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).

View file

@ -13,7 +13,7 @@
%% identifying the player.
%% @spec start_link(Socket::socket()) -> ok
start_link(Socket) ->
not_implemented().
ggs_logger:not_implemented().
%% @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(),
%% {Command::String(), Message::string()}) -> ok
notify(Player, From, Message) ->
not_implemented().
ggs_logger:not_implemented().
%% @doc Get the player token uniquely representing the player.
%% @spec get_token() -> string()
get_token() ->
not_implemented().
ggs_logger:not_implemented().
%% @doc Properly terminates the player process. The player token will be destroyed.
%% Makes table token unreferenced and destroys the process in the end.
%% @spec stop(Table::pid()) -> Reason::string()
stop(Table) ->
not_implemented().
ggs_logger:not_implemented().

View file

@ -1,5 +1,3 @@
%% @doc This module represents a Player with a Socket and a Token
-module(ggs_table).
-export([
start_link/1,
@ -9,28 +7,51 @@
notify/3
]).
%% @doc This module represents a Player with a Socket and a Token
% @doc returns a new table
start_link(Token) ->
not_implemented().
start_link(Token, Socket) ->
spawn_link(fun(Token, Socket) ->
GameVM = ggs_gamevm:start_link();
loop(Token, Socket, GameVM, [])
).
% @doc adds a player to a table
add_player(Table, Player) ->
not_implemented().
ggs_logger:not_implemented().
% @doc removes player form a table
remove_player(Table, Player) ->
not_implemented().
ggs_logger:not_implemented().
% @doc stops the table process
stop(Table) ->
not_implemented().
Table ! {'EXIT', self(), normal}
% @doc notifies the table with a message from a player
notify(Table, Player, Message) ->
not_implemented().
Table ! {notify, Player, Message}.
% 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