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

@ -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