fixed problem with two concurrent players

This commit is contained in:
Jeena Paradies 2011-04-13 16:31:11 +02:00
parent f013e75b5c
commit d9e95b2508
2 changed files with 42 additions and 18 deletions

View file

@ -27,13 +27,33 @@
start(Socket) ->
gen_server:start(?MODULE, [Socket], []).
join_table(Num) ->
case ggs_coordinator:join_table(integer_to_list(Num)) of
{ok, T} ->
io:format("Joining existing table: ~p~n", [T]),
T;
{error, no_such_table} ->
case ggs_coordinator:create_table({force, integer_to_list(Num)}) of
{ok, TBToken} -> ok
end,
case ggs_coordinator:join_table(integer_to_list(Num)) of
{ok, T} -> io:format("Creating new table: ~p~n", [T]),
T;
{error, E} -> erlang:display(E),
join_table(Num+1)
end;
{error, table_full} ->
erlang:display("Table full!"),
join_table(Num+1)
end.
init([Socket]) ->
{ok, Protocol} = ggs_protocol:start_link(),
{ok, Token} = ggs_coordinator:join_lobby(),
erlang:port_connect(Socket, self()),
Table = ggs_coordinator:join_table(),
Table = join_table(1),
State = #state{
token = Token,
socket = Socket,
@ -108,4 +128,4 @@ terminate(Reason, State) ->
% TODO: release Socket
ok.
code_change(_OldVsn, St, _Extra) -> {ok, St}.
code_change(_OldVsn, St, _Extra) -> {ok, St}.