… | |
… | |
41 | #include <netinet/in.h> |
41 | #include <netinet/in.h> |
42 | #include <netdb.h> |
42 | #include <netdb.h> |
43 | |
43 | |
44 | #include <unistd.h> |
44 | #include <unistd.h> |
45 | #include <arpa/inet.h> |
45 | #include <arpa/inet.h> |
46 | #include <newserver.h> |
|
|
47 | |
46 | |
48 | sockvec client_sockets; |
47 | sockvec clients; |
49 | |
48 | |
50 | /** |
49 | /** |
51 | * Initializes a connection. Really, it just sets up the data structure, |
50 | * Initializes a connection. Really, it just sets up the data structure, |
52 | * socket setup is handled elsewhere. We do send a version to the |
51 | * socket setup is handled elsewhere. We do send a version to the |
53 | * client. |
52 | * client. |
54 | */ |
53 | */ |
55 | client_socket::client_socket (int fd, const char *peername) |
54 | client::client (int fd, const char *peername) |
56 | : fd (fd), host (strdup (peername)), |
55 | : fd (fd), host (strdup (peername)), |
57 | socket_ev (this, &client_socket::socket_cb) |
56 | socket_ev (this, &client::socket_cb) |
58 | { |
57 | { |
59 | { |
58 | { |
60 | struct linger linger_opt; |
59 | struct linger linger_opt; |
61 | |
60 | |
62 | linger_opt.l_onoff = 0; |
61 | linger_opt.l_onoff = 0; |
… | |
… | |
119 | if (socket_info.nconns > cst_tot.max_conn) cst_tot.max_conn = socket_info.nconns; |
118 | if (socket_info.nconns > cst_tot.max_conn) cst_tot.max_conn = socket_info.nconns; |
120 | if (socket_info.nconns > cst_lst.max_conn) cst_lst.max_conn = socket_info.nconns; |
119 | if (socket_info.nconns > cst_lst.max_conn) cst_lst.max_conn = socket_info.nconns; |
121 | #endif |
120 | #endif |
122 | } |
121 | } |
123 | |
122 | |
124 | client_socket::~client_socket () |
123 | client::~client () |
125 | { |
124 | { |
126 | status = Ns_Dead; |
125 | status = Ns_Dead; |
127 | } |
126 | } |
128 | |
127 | |
129 | /** This sets up the socket and reads all the image information into memory. */ |
128 | /** This sets up the socket and reads all the image information into memory. */ |
… | |
… | |
164 | * might be associated with the socket. It is up to the caller to |
163 | * might be associated with the socket. It is up to the caller to |
165 | * update the list |
164 | * update the list |
166 | */ |
165 | */ |
167 | |
166 | |
168 | void |
167 | void |
169 | free_newsocket (client_socket *ns) |
168 | free_newsocket (client *ns) |
170 | { |
169 | { |
171 | if (ns->fd >= 0) |
170 | if (ns->fd >= 0) |
172 | close (ns->fd); |
171 | close (ns->fd); |
173 | |
172 | |
174 | if (ns->stats.range) |
173 | if (ns->stats.range) |
… | |
… | |
193 | free_newsocket (pl->socket); |
192 | free_newsocket (pl->socket); |
194 | free_player (pl); |
193 | free_player (pl); |
195 | } |
194 | } |
196 | |
195 | |
197 | bool |
196 | bool |
198 | add_client_socket (int fd, const char *peername) |
197 | add_client (int fd, const char *peername) |
199 | { |
198 | { |
200 | if (checkbanned (NULL, peername)) |
199 | if (checkbanned (NULL, peername)) |
201 | { |
200 | { |
202 | LOG (llevInfo, "Banned host tried to connect: [%s]\n", peername); |
201 | LOG (llevInfo, "Banned host tried to connect: [%s]\n", peername); |
203 | return false; |
202 | return false; |
204 | } |
203 | } |
205 | else |
204 | else |
206 | { |
205 | { |
207 | client_socket *ns = new client_socket (dup (fd), peername); |
206 | client *ns = new client (dup (fd), peername); |
208 | client_sockets.push_back (ns); |
207 | clients.push_back (ns); |
209 | return true; |
208 | return true; |
210 | } |
209 | } |
211 | } |
210 | } |
212 | |
211 | |