anchor.diff:          , end_per_testcase/2
           ]).
   -export([ ping/1
  +        , games/1
           ]).
   
   -define(UCHAR,  8/unsigned-integer).
   -define(USHORT, 16/unsigned-integer).
   -define(UINT,   32/unsigned-integer).
  --define(HEADER_LENGTH, 56).
  +-define(VERY_MUCH, 9999999).
   
   -spec all() -> [atom()].
   all() -> spts_test_utils:all(?MODULE).
  
positive.code:   {socket, UdpSocket} = lists:keyfind(socket, 1, Config),
    Port = application:get_env(serpents, udp_port, 8584),
    {ok, {{127, 0, 0, 1}, Port, Packet}} =
      gen_udp:recv(UdpSocket, ?HEADER_LENGTH, 1000),
    <<Flags:?UCHAR, MsgId:?UINT, Time:?USHORT>> = Packet,
    ct:pal(
      "Flags: ~p / MsgId: ~p, Time: ~p, Pckt: ~p",
      [Flags, MsgId, Time, Packet]),
    Type =
      case Flags of
        0 -> throw(error);
        129 -> ping_response;
        130 -> info_response;
        131 -> join_response;
        132 -> game_update
      end,
    Message = hdp_recv_msg(Type, Config),
    {Type, MsgId, Time, Message}.
  
  hdp_recv_msg(ping_response, _Config) -> <<>>.
  
  hdp_send(Message, Config) ->
    {socket, UdpSocket} = lists:keyfind(socket, 1, Config),
    Port = application:get_env(serpents, udp_port, 8584),
    gen_udp:send(UdpSocket, localhost, Port, Message).
  
  hdp_ping(MsgId) -> hdp_head(1, MsgId).
  
  
negative.code:   ok = hdp_send(hdp_ping(1), Config),
  
    ct:comment("A ping is received"),
    {ping_response, 1, _, pong} = hdp_recv(Config),
  
    ct:comment("A new ping is sent"),
    ok = hdp_send(hdp_ping(2), Config),
  
    ct:comment("A new ping is received"),
    {ping_response, 2, _, pong} = hdp_recv(Config),
    {comment, ""}.
  
  -spec games(spts_test_utils:config()) -> {comment, []}.
  games(Config) ->
    ct:comment("A games request is sent"),
    ok = hdp_send(hdp_games(1), Config),
  
    ct:comment("A games list is received"),
    {info_response, 1, _, {0, []}} = hdp_recv(Config),
  
    ct:comment("A game is started"),
    GameId = spts_games:numeric_id(spts_core:create_game()),
  
    ct:comment("A games request is sent"),
    ok = hdp_send(hdp_games(2), Config),
  
    ct:comment("A games list is received"),
    {info_response, 2, _, {1, [{GameId, 250, 0, 255}]}} = hdp_recv(Config),
  
    {comment, ""}.
  
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  