Debian Codegraph @

src/d2cs/connection.h

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