some more interface compatibility

This commit is contained in:
Jeena Paradies 2011-02-15 07:57:44 +01:00
parent 56c70c38b7
commit 66aa7f4bf1

View file

@ -105,26 +105,33 @@ handle_cast({srv_cmd, "call", Headers, Data}, State) ->
{noreply, State}; {noreply, State};
% Set the new state to the reference generated, and JSVM associated % Set the new state to the reference generated, and JSVM associated
%handle_cast({server, hello, Headers}, State) ->
handle_cast({srv_cmd, "hello", Headers, Data}, State) -> handle_cast({srv_cmd, "hello", Headers, Data}, State) ->
GameVM = ggs_vm_runner:start_link(), GameToken = case proplist:get_value(game_token, Headers) of ->
Client = getRef(), undefined -> getNewToken();
send(State#state.lsock, Client, "This is your refID"), GT -> GT;
end,
ClientToken = getNewToken(),
OldMap = State#state.client_vm_map, OldMap = State#state.client_vm_map,
NewState = State#state{client_vm_map = OldMap ++ [{Client, GameVM}]}, NewState = State#state{client_vm_map = OldMap ++ [{ClientToken, GameVM, GameToken}]},
gen_server:cast(ggs_backup, {set_backup, NewState}), gen_server:cast(ggs_backup, {set_backup, NewState}),
{noreply, NewState}. {noreply, NewState}.
%%----------------------------------------------------- %%-----------------------------------------------------
%% Helpers %% Helpers
%%----------------------------------------------------- %%-----------------------------------------------------
getRef() -> getNewToken() ->
string:strip(os:cmd("uuidgen"), right, $\n ). string:strip(os:cmd("uuidgen"), right, $\n ).
getJSVM(RefID, State) -> getJSVM(ClientToken, State) ->
VMs = State#state.client_vm_map, VMs = State#state.client_vm_map,
erlang:display(RefID), {value, {_,VM}} = lists:keysearch(ClientToken, 1, VMs),
erlang:display(VMs), VM.
{value, {_,VM}} = lists:keysearch(RefID, 1, VMs),
getGameVMByGameToken(GameToken, State) ->
VMs = State#state.client_vm_map,
{value, {_,VM}} = lists:keysearch(GameToken, 3, VMs),
VM. VM.
send(Socket, RefID, String) -> send(Socket, RefID, String) ->