LCOV - code coverage report
Current view: top level - src/lib/srv/mod-udpd - mod-udpd-setup.c (source / functions) Hit Total Coverage
Test: liquidwar6.info Lines: 28 31 90.3 %
Date: 2014-03-26 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /*
       2             :   Liquid War 6 is a unique multiplayer wargame.
       3             :   Copyright (C)  2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014  Christian Mauduit <ufoot@ufoot.org>
       4             : 
       5             :   This program is free software; you can redistribute it and/or modify
       6             :   it under the terms of the GNU General Public License as published by
       7             :   the Free Software Foundation, either version 3 of the License, or
       8             :   (at your option) any later version.
       9             : 
      10             :   This program is distributed in the hope that it will be useful,
      11             :   but WITHOUT ANY WARRANTY; without even the implied warranty of
      12             :   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      13             :   GNU General Public License for more details.
      14             : 
      15             :   You should have received a copy of the GNU General Public License
      16             :   along with this program.  If not, see <http://www.gnu.org/licenses/>.
      17             : 
      18             : 
      19             :   Liquid War 6 homepage : http://www.gnu.org/software/liquidwar6/
      20             :   Contact author        : ufoot@ufoot.org
      21             : */
      22             : 
      23             : #ifdef HAVE_CONFIG_H
      24             : #include "config.h"
      25             : #endif
      26             : 
      27             : #include "../srv.h"
      28             : #include "mod-udpd-internal.h"
      29             : 
      30             : _mod_udpd_context_t *
      31          47 : _mod_udpd_init (int argc, const char *argv[],
      32             :                 lw6cnx_properties_t * properties,
      33             :                 lw6srv_listener_t * listener)
      34             : {
      35          47 :   _mod_udpd_context_t *udpd_context = NULL;
      36          47 :   char *data_dir = NULL;
      37          47 :   int ok = 0;
      38             : 
      39          47 :   lw6sys_log (LW6SYS_LOG_INFO, _x_ ("udpd init"));
      40             : 
      41          47 :   udpd_context =
      42             :     (_mod_udpd_context_t *) LW6SYS_CALLOC (sizeof (_mod_udpd_context_t));
      43          47 :   if (udpd_context)
      44             :     {
      45          47 :       data_dir = lw6sys_get_data_dir (argc, argv);
      46          47 :       if (data_dir)
      47             :         {
      48          47 :           if (_mod_udpd_load_data (&(udpd_context->data), data_dir))
      49             :             {
      50          47 :               properties->hint_timeout =
      51          47 :                 udpd_context->data.consts.error_timeout;
      52          47 :               properties->ping_alter_base =
      53          47 :                 udpd_context->data.consts.ping_alter_base;
      54          47 :               properties->ping_alter_percent =
      55          47 :                 udpd_context->data.consts.ping_alter_percent;
      56          47 :               properties->reliable = 0;
      57          47 :               properties->backend_id = MOD_UDPD_BACKEND_ID;
      58          47 :               ok = 1;
      59             :             }
      60          47 :           LW6SYS_FREE (data_dir);
      61             :         }
      62          47 :       if (!ok)
      63             :         {
      64           0 :           _mod_udpd_quit (udpd_context);
      65           0 :           udpd_context = NULL;
      66             :         }
      67             :     }
      68             : 
      69          47 :   if (!udpd_context)
      70             :     {
      71           0 :       lw6sys_log (LW6SYS_LOG_ERROR, _("can't initialize mod_udpd"));
      72             :     }
      73             : 
      74          47 :   return udpd_context;
      75             : }
      76             : 
      77             : void
      78          47 : _mod_udpd_quit (_mod_udpd_context_t * udpd_context)
      79             : {
      80          47 :   lw6sys_log (LW6SYS_LOG_INFO, _x_ ("udpd quit"));
      81          47 :   _mod_udpd_unload_data (&(udpd_context->data));
      82          47 :   LW6SYS_FREE (udpd_context);
      83          47 : }

Generated by: LCOV version 1.10