fixed problem with two concurrent players
This commit is contained in:
parent
231bbfdf16
commit
f013e75b5c
1 changed files with 1 additions and 21 deletions
|
@ -27,33 +27,13 @@
|
||||||
start(Socket) ->
|
start(Socket) ->
|
||||||
gen_server:start(?MODULE, [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]) ->
|
init([Socket]) ->
|
||||||
{ok, Protocol} = ggs_protocol:start_link(),
|
{ok, Protocol} = ggs_protocol:start_link(),
|
||||||
{ok, Token} = ggs_coordinator:join_lobby(),
|
{ok, Token} = ggs_coordinator:join_lobby(),
|
||||||
|
|
||||||
erlang:port_connect(Socket, self()),
|
erlang:port_connect(Socket, self()),
|
||||||
|
|
||||||
Table = join_table(1),
|
Table = ggs_coordinator:join_table(),
|
||||||
State = #state{
|
State = #state{
|
||||||
token = Token,
|
token = Token,
|
||||||
socket = Socket,
|
socket = Socket,
|
||||||
|
|
Reference in a new issue