| 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 |
|
|
#ifndef INCLUDED_CONNECTION_H
|
| 19 |
|
|
#define INCLUDED_CONNECTION_H
|
| 20 |
|
|
|
| 21 |
|
|
#include "common/queue.h"
|
| 22 |
|
|
#include "common/hashtable.h"
|
| 23 |
|
|
#include "common/packet.h"
|
| 24 |
|
|
#include "common/fdwatch.h"
|
| 25 |
|
|
#include "d2charfile.h"
|
| 26 |
|
|
#include "gamequeue.h"
|
| 27 |
|
|
|
| 28 |
|
|
typedef enum
|
| 29 |
|
|
{
|
| 30 |
|
|
conn_state_none = 0x00,
|
| 31 |
|
|
conn_state_init = 0x01,
|
| 32 |
|
|
conn_state_connecting = 0x02,
|
| 33 |
|
|
conn_state_connected = 0x04,
|
| 34 |
|
|
conn_state_authed = 0x08,
|
| 35 |
|
|
conn_state_char_authed = 0x10,
|
| 36 |
|
|
conn_state_destroy = 0x20,
|
| 37 |
|
|
conn_state_destroying = 0x40,
|
| 38 |
|
|
conn_state_any = 0xff
|
| 39 |
|
|
} t_conn_state;
|
| 40 |
|
|
|
| 41 |
|
|
typedef enum
|
| 42 |
|
|
{
|
| 43 |
|
|
conn_class_none,
|
| 44 |
|
|
conn_class_init,
|
| 45 |
|
|
conn_class_d2cs,
|
| 46 |
|
|
conn_class_d2gs,
|
| 47 |
|
|
conn_class_bnetd
|
| 48 |
|
|
} t_conn_class;
|
| 49 |
|
|
|
| 50 |
|
|
typedef struct
|
| 51 |
|
|
{
|
| 52 |
|
|
char const * charname;
|
| 53 |
|
|
char const * account;
|
| 54 |
|
|
int sock;
|
| 55 |
|
|
int fdw_idx;
|
| 56 |
|
|
unsigned int socket_flag;
|
| 57 |
|
|
unsigned int addr;
|
| 58 |
|
|
unsigned int local_addr;
|
| 59 |
|
|
unsigned short port;
|
| 60 |
|
|
unsigned short local_port;
|
| 61 |
|
|
unsigned int last_active;
|
| 62 |
|
|
t_conn_class class;
|
| 63 |
|
|
t_conn_state state;
|
| 64 |
|
|
unsigned int sessionnum;
|
| 65 |
|
|
t_queue * outqueue;
|
| 66 |
|
|
unsigned int outsize;
|
| 67 |
|
|
unsigned int outsizep;
|
| 68 |
|
|
t_packet * inqueue;
|
| 69 |
|
|
unsigned int insize;
|
| 70 |
|
|
t_d2charinfo_summary const * charinfo;
|
| 71 |
|
|
unsigned int d2gs_id;
|
| 72 |
|
|
t_gq * gamequeue;
|
| 73 |
|
|
unsigned int bnetd_sessionnum;
|
| 74 |
|
|
unsigned int sessionnum_hash;
|
| 75 |
|
|
unsigned int charname_hash;
|
| 76 |
sysadm |
1.2 |
|
| 77 |
|
|
/* by sowater, 200503031 */
|
| 78 |
|
|
char checknum;
|
| 79 |
|
|
|
| 80 |
sysadm |
1.1 |
} t_connection;
|
| 81 |
|
|
|
| 82 |
|
|
typedef int ( * packet_handle_func) (t_connection * c, t_packet * packet);
|
| 83 |
|
|
typedef struct
|
| 84 |
|
|
{
|
| 85 |
|
|
unsigned int size;
|
| 86 |
|
|
t_conn_state state;
|
| 87 |
|
|
packet_handle_func handler;
|
| 88 |
|
|
} t_packet_handle_table;
|
| 89 |
|
|
|
| 90 |
|
|
#define SOCKET_FLAG_READ 0x1
|
| 91 |
|
|
#define SOCKET_FLAG_WRITE 0x2
|
| 92 |
|
|
|
| 93 |
|
|
extern t_hashtable * d2cs_connlist(void);
|
| 94 |
|
|
extern int d2cs_connlist_destroy(void);
|
| 95 |
|
|
extern int d2cs_connlist_reap(void);
|
| 96 |
|
|
extern int d2cs_connlist_create(void);
|
| 97 |
|
|
extern int conn_check_multilogin(t_connection const * c,char const * charname);
|
| 98 |
|
|
extern t_connection * d2cs_connlist_find_connection_by_sessionnum(unsigned int sessionnum);
|
| 99 |
|
|
extern t_connection * d2cs_connlist_find_connection_by_charname(char const * charname);
|
| 100 |
|
|
extern int conn_handle_socket(t_connection * c);
|
| 101 |
|
|
extern t_connection * d2cs_conn_create(int sock, unsigned int local_addr, unsigned short local_port,
|
| 102 |
|
|
unsigned int addr, unsigned short port);
|
| 103 |
|
|
extern int d2cs_conn_destroy(t_connection * c, t_elem ** elem);
|
| 104 |
|
|
extern int d2cs_conn_get_socket(t_connection const * c);
|
| 105 |
|
|
extern unsigned int d2cs_conn_get_sessionnum(t_connection const * c);
|
| 106 |
|
|
extern t_conn_class d2cs_conn_get_class(t_connection const * c);
|
| 107 |
|
|
extern int d2cs_conn_set_class(t_connection * c, t_conn_class class);
|
| 108 |
|
|
extern t_conn_state d2cs_conn_get_state(t_connection const * c);
|
| 109 |
|
|
extern int d2cs_conn_set_state(t_connection * c, t_conn_state state);
|
| 110 |
|
|
extern t_queue * * d2cs_conn_get_out_queue(t_connection const * c);
|
| 111 |
|
|
extern t_packet * d2cs_conn_get_in_queue(t_connection const * c);
|
| 112 |
|
|
extern void d2cs_conn_set_in_queue(t_connection * c, t_packet * packet);
|
| 113 |
|
|
extern unsigned int d2cs_conn_get_in_size(t_connection const * c);
|
| 114 |
|
|
extern unsigned int d2cs_conn_get_out_size(t_connection const * c);
|
| 115 |
|
|
extern int conn_push_outqueue(t_connection * c, t_packet * packet);
|
| 116 |
|
|
extern t_packet * conn_peek_outqueue(t_connection * c);
|
| 117 |
|
|
extern t_packet * conn_pull_outqueue(t_connection * c);
|
| 118 |
|
|
extern int conn_add_socket_flag(t_connection * c, unsigned int flag);
|
| 119 |
|
|
extern int conn_process_packet(t_connection * c, t_packet * packet, t_packet_handle_table * table,
|
| 120 |
|
|
unsigned int table_size);
|
| 121 |
|
|
extern int d2cs_conn_set_account(t_connection * c, char const * account);
|
| 122 |
|
|
extern int d2cs_conn_set_charname(t_connection * c, char const * charname);
|
| 123 |
|
|
extern char const * d2cs_conn_get_account(t_connection const * c);
|
| 124 |
|
|
extern char const * d2cs_conn_get_charname(t_connection const * c);
|
| 125 |
|
|
extern int conn_set_charinfo(t_connection * c, t_d2charinfo_summary const * charinfo);
|
| 126 |
|
|
extern unsigned int conn_get_charinfo_ladder(t_connection const * c);
|
| 127 |
|
|
extern unsigned int conn_get_charinfo_expansion(t_connection const * c);
|
| 128 |
|
|
extern unsigned int conn_get_charinfo_hardcore(t_connection const * c);
|
| 129 |
|
|
extern unsigned int conn_get_charinfo_dead(t_connection const * c);
|
| 130 |
|
|
extern unsigned int conn_get_charinfo_difficulty(t_connection const * c);
|
| 131 |
|
|
extern unsigned int conn_get_charinfo_level(t_connection const * c);
|
| 132 |
|
|
extern unsigned int conn_get_charinfo_class(t_connection const * c);
|
| 133 |
|
|
extern unsigned int conn_get_d2gs_id(t_connection const * c);
|
| 134 |
|
|
extern int conn_set_d2gs_id(t_connection * c, unsigned int d2gs_id);
|
| 135 |
|
|
extern unsigned int d2cs_conn_get_addr(t_connection const * c);
|
| 136 |
|
|
extern unsigned short d2cs_conn_get_port(t_connection const * c);
|
| 137 |
|
|
extern t_gq * conn_get_gamequeue(t_connection const * c);
|
| 138 |
|
|
extern int conn_set_gamequeue(t_connection * c, t_gq * gq);
|
| 139 |
|
|
extern int conn_set_bnetd_sessionnum(t_connection * c, unsigned int sessionnum);
|
| 140 |
|
|
extern unsigned int conn_get_bnetd_sessionnum(t_connection const * c);
|
| 141 |
|
|
extern int conn_add_fd(t_connection * c, t_fdwatch_type rw, fdwatch_handler handler);
|
| 142 |
|
|
extern int connlist_check_timeout(void);
|
| 143 |
|
|
|
| 144 |
sysadm |
1.2 |
/* by sowater, 20050331 */
|
| 145 |
|
|
extern int d2cs_conn_set_checknum(t_connection * c, char checknum);
|
| 146 |
|
|
extern char d2cs_conn_get_checknum(t_connection * c);
|
| 147 |
|
|
|
| 148 |
sysadm |
1.1 |
#endif
|