| 1 |
sysadm |
1.1 |
/*
|
| 2 |
|
|
* Copyright (C) 2000,2001 Onlyer (onlyer@263.net)
|
| 3 |
|
|
*
|
| 4 |
|
|
* This program is free software; you can redistribute it and/or
|
| 5 |
|
|
* modify it under the terms of the GNU General Public License
|
| 6 |
|
|
* as published by the Free Software Foundation; either version 2
|
| 7 |
|
|
* of the License, or (at your option) any later version.
|
| 8 |
|
|
*
|
| 9 |
|
|
* This program is distributed in the hope that it will be useful,
|
| 10 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 11 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 12 |
|
|
* GNU General Public License for more details.
|
| 13 |
|
|
*
|
| 14 |
|
|
* You should have received a copy of the GNU General Public License
|
| 15 |
|
|
* along with this program; if not, write to the Free Software
|
| 16 |
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
| 17 |
|
|
*/
|
| 18 |
|
|
#include "common/setup_before.h"
|
| 19 |
|
|
#include "setup.h"
|
| 20 |
|
|
|
| 21 |
|
|
#ifdef HAVE_STDDEF_H
|
| 22 |
|
|
# include <stddef.h>
|
| 23 |
|
|
#else
|
| 24 |
|
|
# ifndef NULL
|
| 25 |
|
|
# define NULL ((void *)0)
|
| 26 |
|
|
# endif
|
| 27 |
|
|
#endif
|
| 28 |
|
|
#ifdef TIME_WITH_SYS_TIME
|
| 29 |
|
|
# include <time.h>
|
| 30 |
|
|
# include <sys/time.h>
|
| 31 |
|
|
#else
|
| 32 |
|
|
# ifdef HAVE_SYS_TIME_H
|
| 33 |
|
|
# include <sys/time.h>
|
| 34 |
|
|
# else
|
| 35 |
|
|
# include <time.h>
|
| 36 |
|
|
# endif
|
| 37 |
|
|
#endif
|
| 38 |
|
|
|
| 39 |
|
|
#include "bnetd.h"
|
| 40 |
|
|
#include "prefs.h"
|
| 41 |
|
|
#include "s2s.h"
|
| 42 |
|
|
#include "handle_bnetd.h"
|
| 43 |
|
|
#include "connection.h"
|
| 44 |
|
|
#include "common/eventlog.h"
|
| 45 |
|
|
#include "common/setup_after.h"
|
| 46 |
|
|
|
| 47 |
|
|
static t_connection * bnetd_connection=NULL;
|
| 48 |
|
|
|
| 49 |
|
|
extern int bnetd_init(void)
|
| 50 |
|
|
{
|
| 51 |
|
|
return bnetd_check();
|
| 52 |
|
|
}
|
| 53 |
|
|
|
| 54 |
|
|
extern int bnetd_check(void)
|
| 55 |
|
|
{
|
| 56 |
|
|
static unsigned int prev_connecting_checktime=0;
|
| 57 |
|
|
|
| 58 |
|
|
if (bnetd_connection) {
|
| 59 |
|
|
if (d2cs_conn_get_state(bnetd_connection)==conn_state_connecting) {
|
| 60 |
|
|
if (time(NULL) - prev_connecting_checktime > prefs_get_s2s_timeout()) {
|
| 61 |
|
|
eventlog(eventlog_level_warn,__FUNCTION__,"connection to bnetd s2s timeout");
|
| 62 |
|
|
d2cs_conn_set_state(bnetd_connection,conn_state_destroy);
|
| 63 |
|
|
return -1;
|
| 64 |
|
|
}
|
| 65 |
|
|
}
|
| 66 |
|
|
return 0;
|
| 67 |
|
|
}
|
| 68 |
|
|
if (!(bnetd_connection=s2s_create(prefs_get_bnetdaddr(),BNETD_SERV_PORT,conn_class_bnetd))) {
|
| 69 |
|
|
return -1;
|
| 70 |
|
|
}
|
| 71 |
|
|
if (d2cs_conn_get_state(bnetd_connection)==conn_state_init) {
|
| 72 |
|
|
handle_bnetd_init(bnetd_connection);
|
| 73 |
|
|
} else {
|
| 74 |
|
|
prev_connecting_checktime=time(NULL);
|
| 75 |
|
|
}
|
| 76 |
|
|
return 0;
|
| 77 |
|
|
}
|
| 78 |
|
|
|
| 79 |
|
|
|
| 80 |
|
|
extern t_connection * bnetd_conn(void)
|
| 81 |
|
|
{
|
| 82 |
|
|
return bnetd_connection;
|
| 83 |
|
|
}
|
| 84 |
|
|
|
| 85 |
|
|
extern int bnetd_set_connection(t_connection * c)
|
| 86 |
|
|
{
|
| 87 |
|
|
bnetd_connection=c;
|
| 88 |
|
|
return 0;
|
| 89 |
|
|
}
|
| 90 |
|
|
|
| 91 |
|
|
extern int bnetd_destroy(t_connection * c)
|
| 92 |
|
|
{
|
| 93 |
|
|
if (bnetd_connection != c) {
|
| 94 |
|
|
eventlog(eventlog_level_error,__FUNCTION__,"bnetd connection do not match");
|
| 95 |
|
|
return -1;
|
| 96 |
|
|
}
|
| 97 |
|
|
bnetd_connection=NULL;
|
| 98 |
|
|
return 0;
|
| 99 |
|
|
}
|