| 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 STDC_HEADERS
|
| 22 |
|
|
# include <stdlib.h>
|
| 23 |
|
|
#else
|
| 24 |
|
|
# ifdef HAVE_MALLOC_H
|
| 25 |
|
|
# include <malloc.h>
|
| 26 |
|
|
# endif
|
| 27 |
|
|
#endif
|
| 28 |
|
|
|
| 29 |
|
|
#include "connection.h"
|
| 30 |
|
|
#include "handle_init.h"
|
| 31 |
|
|
#include "handle_d2gs.h"
|
| 32 |
|
|
#include "d2gs.h"
|
| 33 |
|
|
#include "prefs.h"
|
| 34 |
|
|
#include "common/init_protocol.h"
|
| 35 |
|
|
#include "common/addr.h"
|
| 36 |
|
|
#include "common/packet.h"
|
| 37 |
|
|
#include "common/queue.h"
|
| 38 |
|
|
#include "common/eventlog.h"
|
| 39 |
|
|
#include "common/bn_type.h"
|
| 40 |
|
|
#include "common/setup_after.h"
|
| 41 |
|
|
|
| 42 |
|
|
static int on_d2gs_initconn(t_connection * c);
|
| 43 |
|
|
static int on_d2cs_initconn(t_connection * c);
|
| 44 |
|
|
|
| 45 |
|
|
extern int d2cs_handle_init_packet(t_connection * c, t_packet * packet)
|
| 46 |
|
|
{
|
| 47 |
|
|
int class;
|
| 48 |
|
|
int retval;
|
| 49 |
|
|
|
| 50 |
|
|
ASSERT(c,-1);
|
| 51 |
|
|
ASSERT(packet,-1);
|
| 52 |
|
|
class=bn_byte_get(packet->u.client_initconn.class);
|
| 53 |
|
|
switch (class) {
|
| 54 |
|
|
case CLIENT_INITCONN_CLASS_D2CS:
|
| 55 |
|
|
retval=on_d2cs_initconn(c);
|
| 56 |
|
|
break;
|
| 57 |
|
|
case CLIENT_INITCONN_CLASS_D2GS:
|
| 58 |
|
|
retval=on_d2gs_initconn(c);
|
| 59 |
|
|
break;
|
| 60 |
|
|
default:
|
| 61 |
|
|
eventlog(eventlog_level_error,__FUNCTION__,"got bad connection class %d",class);
|
| 62 |
|
|
retval=-1;
|
| 63 |
|
|
break;
|
| 64 |
|
|
}
|
| 65 |
|
|
return retval;
|
| 66 |
|
|
}
|
| 67 |
|
|
|
| 68 |
|
|
static int on_d2gs_initconn(t_connection * c)
|
| 69 |
|
|
{
|
| 70 |
|
|
t_d2gs * gs;
|
| 71 |
|
|
|
| 72 |
|
|
eventlog(eventlog_level_info,__FUNCTION__,"[%d] client initiated d2gs connection",d2cs_conn_get_socket(c));
|
| 73 |
|
|
if (!(gs=d2gslist_find_gs_by_ip(d2cs_conn_get_addr(c)))) {
|
| 74 |
|
|
// reload list and see if any dns addy's has changed
|
| 75 |
|
|
if (d2gslist_reload(prefs_get_d2gs_list())<0) {
|
| 76 |
|
|
eventlog(eventlog_level_error,__FUNCTION__,"error reloading game server list,exitting");
|
| 77 |
|
|
return -1;
|
| 78 |
|
|
}
|
| 79 |
|
|
//recheck
|
| 80 |
|
|
if (!(gs=d2gslist_find_gs_by_ip(d2cs_conn_get_addr(c)))) {
|
| 81 |
|
|
eventlog(eventlog_level_error,__FUNCTION__,"d2gs connection from invalid ip address %s",addr_num_to_ip_str(d2cs_conn_get_addr(c)));
|
| 82 |
|
|
return -1;
|
| 83 |
|
|
}
|
| 84 |
|
|
}
|
| 85 |
|
|
d2cs_conn_set_class(c,conn_class_d2gs);
|
| 86 |
|
|
d2cs_conn_set_state(c,conn_state_connected);
|
| 87 |
|
|
conn_set_d2gs_id(c,d2gs_get_id(gs));
|
| 88 |
|
|
if (handle_d2gs_init(c)<0) {
|
| 89 |
|
|
eventlog(eventlog_level_error,__FUNCTION__,"failed to init d2gs connection");
|
| 90 |
|
|
return -1;
|
| 91 |
|
|
}
|
| 92 |
|
|
return 0;
|
| 93 |
|
|
}
|
| 94 |
|
|
|
| 95 |
|
|
static int on_d2cs_initconn(t_connection * c)
|
| 96 |
|
|
{
|
| 97 |
|
|
eventlog(eventlog_level_info,__FUNCTION__,"[%d] client initiated d2cs connection",d2cs_conn_get_socket(c));
|
| 98 |
|
|
d2cs_conn_set_class(c,conn_class_d2cs);
|
| 99 |
|
|
d2cs_conn_set_state(c,conn_state_connected);
|
| 100 |
|
|
return 0;
|
| 101 |
|
|
}
|