ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/socket/init.C
(Generate patch)

Comparing deliantra/server/socket/init.C (file contents):
Revision 1.17 by root, Thu Dec 14 20:39:54 2006 UTC vs.
Revision 1.20 by root, Fri Dec 15 19:59:20 2006 UTC

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
53sockvec client_sockets; 47sockvec 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 */
60client_socket::client_socket (int fd, const char *peername) 54client::client (int fd, const char *peername)
61: fd (fd), host (strdup (peername)), 55: fd (fd), host (strdup (peername)),
62 socket_ev (this, &client_socket::socket_cb) 56 socket_ev (this, &client::socket_cb)
63{ 57{
64 { 58 {
65 struct linger linger_opt; 59 struct linger linger_opt;
66 60
67 linger_opt.l_onoff = 0; 61 linger_opt.l_onoff = 0;
106 * 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
107 * face information. 101 * face information.
108 */ 102 */
109 faces_sent[0] = NS_FACESENT_FACE; 103 faces_sent[0] = NS_FACESENT_FACE;
110 104
111 socket_ev.fd (fd).poll (PE_W).start (); 105 socket_ev.fd (fd);
112 106
113 // initialisation done, kick it! 107 // initialisation done, kick it!
114 108
115 { 109 {
116 packet sl; 110 packet sl;
117 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);
118 send_packet (sl); 112 send_packet (sl);
113 flush ();
119 } 114 }
120 115
121#if 0//TODO 116#if 0//TODO
122 socket_info.nconns++; 117 socket_info.nconns++;
123 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;
124 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;
125#endif 120#endif
126} 121}
127 122
128client_socket::~client_socket () 123client::~client ()
129{ 124{
130 status = Ns_Dead; 125 status = Ns_Dead;
131} 126}
132 127
133/** 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. */
168 * 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
169 * update the list 164 * update the list
170 */ 165 */
171 166
172void 167void
173free_newsocket (client_socket *ns) 168free_newsocket (client *ns)
174{ 169{
175 if (ns->fd >= 0) 170 if (ns->fd >= 0)
176 close (ns->fd); 171 close (ns->fd);
177 172
178 if (ns->stats.range) 173 if (ns->stats.range)
197 free_newsocket (pl->socket); 192 free_newsocket (pl->socket);
198 free_player (pl); 193 free_player (pl);
199} 194}
200 195
201bool 196bool
202add_client_socket (int fd, const char *peername) 197add_client (int fd, const char *peername)
203{ 198{
204 if (checkbanned (NULL, peername)) 199 if (checkbanned (NULL, peername))
205 { 200 {
206 LOG (llevInfo, "Banned host tried to connect: [%s]\n", peername); 201 LOG (llevInfo, "Banned host tried to connect: [%s]\n", peername);
207 return false; 202 return false;
208 } 203 }
209 else 204 else
210 { 205 {
211 client_socket *ns = new client_socket (dup (fd), peername); 206 client *ns = new client (dup (fd), peername);
212 client_sockets.push_back (ns); 207 clients.push_back (ns);
213 return true; 208 return true;
214 } 209 }
215} 210}
216 211

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines