… | |
… | |
39 | #include <sys/time.h> |
39 | #include <sys/time.h> |
40 | #include <sys/socket.h> |
40 | #include <sys/socket.h> |
41 | #include <netinet/in.h> |
41 | #include <netinet/in.h> |
42 | #include <netdb.h> |
42 | #include <netdb.h> |
43 | |
43 | |
44 | #ifdef HAVE_UNISTD_H |
|
|
45 | # include <unistd.h> |
44 | #include <unistd.h> |
46 | #endif |
|
|
47 | |
|
|
48 | #ifdef HAVE_ARPA_INET_H |
|
|
49 | # include <arpa/inet.h> |
45 | #include <arpa/inet.h> |
50 | #endif |
|
|
51 | #include <newserver.h> |
|
|
52 | |
46 | |
53 | sockvec client_sockets; |
47 | sockvec clients; |
54 | |
48 | |
55 | /** |
49 | /** |
56 | * Initializes a connection. Really, it just sets up the data structure, |
50 | * Initializes a connection. Really, it just sets up the data structure, |
57 | * 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 |
58 | * client. |
52 | * client. |
59 | */ |
53 | */ |
60 | client_socket::client_socket (int fd, const char *peername) |
54 | client::client (int fd, const char *peername) |
61 | : fd (fd), host (strdup (peername)) |
55 | : fd (fd), host (strdup (peername)), |
|
|
56 | socket_ev (this, &client::socket_cb) |
62 | { |
57 | { |
63 | { |
58 | { |
64 | struct linger linger_opt; |
59 | struct linger linger_opt; |
65 | |
60 | |
66 | linger_opt.l_onoff = 0; |
61 | linger_opt.l_onoff = 0; |
… | |
… | |
105 | * this face. Face 0 is sent to the client to say clear |
100 | * this face. Face 0 is sent to the client to say clear |
106 | * face information. |
101 | * face information. |
107 | */ |
102 | */ |
108 | faces_sent[0] = NS_FACESENT_FACE; |
103 | faces_sent[0] = NS_FACESENT_FACE; |
109 | |
104 | |
110 | can_write = 1; |
105 | socket_ev.fd (fd); |
111 | |
106 | |
112 | // initialisation done, kick it! |
107 | // initialisation done, kick it! |
113 | |
108 | |
114 | { |
109 | { |
115 | packet sl; |
110 | packet sl; |
116 | sl.printf ("version %d %d %s\n", VERSION_CS, VERSION_SC, VERSION_INFO); |
111 | sl.printf ("version %d %d %s\n", VERSION_CS, VERSION_SC, VERSION_INFO); |
117 | send_packet (sl); |
112 | send_packet (sl); |
|
|
113 | flush (); |
118 | } |
114 | } |
119 | |
115 | |
120 | #if 0//TODO |
116 | #if 0//TODO |
121 | socket_info.nconns++; |
117 | socket_info.nconns++; |
122 | 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; |
123 | 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; |
124 | #endif |
120 | #endif |
125 | } |
121 | } |
126 | |
122 | |
127 | client_socket::~client_socket () |
123 | client::~client () |
128 | { |
124 | { |
129 | status = Ns_Dead; |
125 | status = Ns_Dead; |
130 | } |
126 | } |
131 | |
127 | |
132 | /** 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. */ |
… | |
… | |
167 | * 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 |
168 | * update the list |
164 | * update the list |
169 | */ |
165 | */ |
170 | |
166 | |
171 | void |
167 | void |
172 | free_newsocket (client_socket *ns) |
168 | free_newsocket (client *ns) |
173 | { |
169 | { |
174 | if (ns->fd >= 0) |
170 | if (ns->fd >= 0) |
175 | close (ns->fd); |
171 | close (ns->fd); |
176 | |
172 | |
177 | if (ns->stats.range) |
173 | if (ns->stats.range) |
… | |
… | |
196 | free_newsocket (pl->socket); |
192 | free_newsocket (pl->socket); |
197 | free_player (pl); |
193 | free_player (pl); |
198 | } |
194 | } |
199 | |
195 | |
200 | bool |
196 | bool |
201 | add_client_socket (int fd, const char *peername) |
197 | add_client (int fd, const char *peername) |
202 | { |
198 | { |
203 | if (checkbanned (NULL, peername)) |
199 | if (checkbanned (NULL, peername)) |
204 | { |
200 | { |
205 | LOG (llevInfo, "Banned host tried to connect: [%s]\n", peername); |
201 | LOG (llevInfo, "Banned host tried to connect: [%s]\n", peername); |
206 | return false; |
202 | return false; |
207 | } |
203 | } |
208 | else |
204 | else |
209 | { |
205 | { |
210 | client_socket *ns = new client_socket (dup (fd), peername); |
206 | client *ns = new client (dup (fd), peername); |
211 | client_sockets.push_back (ns); |
207 | clients.push_back (ns); |
212 | return true; |
208 | return true; |
213 | } |
209 | } |
214 | } |
210 | } |
215 | |
211 | |