Merge branch 'jonte_rewrite' into rewrite
Conflicts: src/ggs_coordinator.erl src/ggs_dispatcher.erl src/ggs_player.erl
This commit is contained in:
commit
9e3ad5fa9b
17 changed files with 77 additions and 460 deletions
|
@ -1,5 +1,7 @@
|
|||
-module(ggs_dispatcher).
|
||||
|
||||
-behaviour(gen_server).
|
||||
|
||||
%% API Exports
|
||||
-export([start_link/1, stop/1]).
|
||||
|
||||
|
@ -7,6 +9,8 @@
|
|||
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2,
|
||||
code_change/3]).
|
||||
|
||||
-define(SERVER, ?MODULE).
|
||||
|
||||
|
||||
%% @doc This module is the entry-point for clients connecting to GGS. This is
|
||||
%% the module responsible for:
|
||||
|
@ -20,19 +24,20 @@
|
|||
%% Port = Integer
|
||||
%% Pid = #<Pid>
|
||||
start_link(Port) ->
|
||||
not_implemented().
|
||||
gen_server:start_link({local, ?SERVER}, ?MODULE, [Port], []).
|
||||
|
||||
%% @doc Stops the dispatcher with the specified reason.
|
||||
%% @spec stop(Reason) -> ok.
|
||||
%% Reason = String
|
||||
stop(Reason) -> not_implemented().
|
||||
|
||||
stop(_Reason) -> helpers:not_implemented().
|
||||
|
||||
%% gen_server callbacks
|
||||
|
||||
%% @doc Initiate the dispatcher. This is called from gen_server
|
||||
init([Port]) ->
|
||||
{ok, ok}.
|
||||
{ok, LSock} = gen_tcp:listen(Port, [{active, true},
|
||||
{reuseaddr, true}]),
|
||||
{ok, LSock, 0}.
|
||||
|
||||
handle_call(_Message, _From, State) ->
|
||||
{noreply, State}.
|
||||
|
@ -40,8 +45,24 @@ handle_call(_Message, _From, State) ->
|
|||
handle_cast(_Message, State) ->
|
||||
{noreply, State}.
|
||||
|
||||
handle_info({tcp, _Socket, RawData}, State) ->
|
||||
io:format("Got connect request!~n"),
|
||||
{noreply, State};
|
||||
|
||||
handle_info({tcp_closed, Socket}, State) ->
|
||||
gen_tcp:close(Socket),
|
||||
{stop, "Client closed socket", State};
|
||||
|
||||
%% @doc This is our function for accepting connections. When a client connects,
|
||||
%% it will immediately time out due to timing settings set in init and here,
|
||||
%% and when it does, we accept the connection.
|
||||
handle_info(timeout, LSock) ->
|
||||
{ok, Sock} = gen_tcp:accept(LSock),
|
||||
spawn(ggs_player, start_link, [Sock]),
|
||||
{noreply, LSock, 0}.
|
||||
|
||||
terminate(normal, _State) ->
|
||||
ok.
|
||||
|
||||
code_change(_OldVsn, State, Extra) ->
|
||||
code_change(_OldVsn, State, _Extra) ->
|
||||
{ok, State}.
|
||||
|
|
Reference in a new issue