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.30 by root, Fri Dec 22 16:34:00 2006 UTC vs.
Revision 1.31 by root, Mon Dec 25 11:25:50 2006 UTC

42#include <netinet/ip.h> 42#include <netinet/ip.h>
43#include <netdb.h> 43#include <netdb.h>
44 44
45#include <unistd.h> 45#include <unistd.h>
46#include <arpa/inet.h> 46#include <arpa/inet.h>
47
48#include <algorithm>
47 49
48sockvec clients; 50sockvec clients;
49 51
50/** 52/**
51 * Initializes a connection. Really, it just sets up the data structure, 53 * Initializes a connection. Really, it just sets up the data structure,
147 149
148 // initialisation done, kick it! 150 // initialisation done, kick it!
149 send_packet_printf ("version %d %d %s\n", VERSION_CS, VERSION_SC, VERSION_INFO); 151 send_packet_printf ("version %d %d %s\n", VERSION_CS, VERSION_SC, VERSION_INFO);
150 flush (); 152 flush ();
151 153
154 // clients are externally referenced by the socket
155 refcnt_inc ();
156 clients.push_back (this);
157
152#if 0//TODO 158#if 0//TODO
153 socket_info.nconns++; 159 socket_info.nconns++;
154 if (socket_info.nconns > cst_tot.max_conn) cst_tot.max_conn = socket_info.nconns; 160 if (socket_info.nconns > cst_tot.max_conn) cst_tot.max_conn = socket_info.nconns;
155 if (socket_info.nconns > cst_lst.max_conn) cst_lst.max_conn = socket_info.nconns; 161 if (socket_info.nconns > cst_lst.max_conn) cst_lst.max_conn = socket_info.nconns;
156#endif 162#endif
157} 163}
158 164
159client::~client () 165client::~client ()
160{ 166{
161 if (pl)
162 {
163 pl->save ();
164 leave (pl, 1);
165 pl->ns = 0;
166
167 delete pl;
168 }
169
170 if (fd >= 0)
171 close (fd);
172
173 sfree<uint8> (faces_sent, nrofpixmaps); 167 sfree<uint8> (faces_sent, nrofpixmaps);
174 free (stats.range); 168 free (stats.range);
175 free (stats.title); 169 free (stats.title);
176 free (host); 170 free (host);
177} 171}
178 172
179void 173void
180client::destroy () 174client::do_destroy ()
181{ 175{
182 INVOKE_CLIENT (DESTROY, this); 176 attachable::do_destroy ();
177
178 sockvec::iterator i = find (clients.begin (), clients.end (), this);
179 if (i != clients.end ())
180 clients.erase (i);
181
182 if (pl)
183 pl->disconnect ();
184
185 if (fd >= 0)
186 close (fd);
183 187
184 state = ST_DEAD; 188 state = ST_DEAD;
185 189
186 socket_ev.suspend (); 190 socket_ev.suspend ();
187 cmd_ev.suspend (); 191 cmd_ev.suspend ();
192
193 // socket now longer references us
194 refcnt_dec ();
188} 195}
189 196
190/** This sets up the socket and reads all the image information into memory. */ 197/** This sets up the socket and reads all the image information into memory. */
191void 198void
192init_ericserver (void) 199init_ericserver (void)
223 return 0; 230 return 0;
224 } 231 }
225 else 232 else
226 { 233 {
227 client *ns = new client (dup (fd), peername); 234 client *ns = new client (dup (fd), peername);
228 clients.push_back (ns);
229 235
230 ns->instantiate (); // effectively a nop right now 236 ns->instantiate (); // effectively a nop right now
231 237
232 INVOKE_CLIENT (CONNECT, ns); 238 INVOKE_CLIENT (CONNECT, ns);
233 239

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines