--- deliantra/server/socket/init.C 2007/01/06 14:42:31 1.33 +++ deliantra/server/socket/init.C 2007/01/07 02:39:15 1.34 @@ -61,6 +61,8 @@ cmd_ev (this, &client::cmd_cb), cc_inv (this), cc_other (this) { + refcnt_inc (); // the socket is an external reference + { struct linger linger_opt; @@ -152,22 +154,12 @@ send_packet_printf ("version %d %d %s\n", VERSION_CS, VERSION_SC, VERSION_INFO); flush (); - // clients are externally referenced by the socket - refcnt_inc (); - clients.push_back (this); - -#if 0//TODO - socket_info.nconns++; - if (socket_info.nconns > cst_tot.max_conn) cst_tot.max_conn = socket_info.nconns; - if (socket_info.nconns > cst_lst.max_conn) cst_lst.max_conn = socket_info.nconns; -#endif + clients.insert (this); } client::~client () { - sockvec::iterator i = find (clients.begin (), clients.end (), this); - if (i != clients.end ()) - clients.erase (i); + clients.erase (this); sfree (faces_sent, nrofpixmaps); free (stats.range); @@ -184,15 +176,19 @@ pl->disconnect (); if (fd >= 0) - close (fd); + { + send_packet ("goodbye"); + flush (); + + close (fd); + } state = ST_DEAD; socket_ev.suspend (); cmd_ev.suspend (); - // socket now longer references us - refcnt_dec (); + refcnt_dec (); // socket no longer open } /** This sets up the socket and reads all the image information into memory. */