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.34 by root, Sun Jan 7 02:39:15 2007 UTC

1/* 1/*
2 CrossFire, A Multiplayer game for X-windows 2 CrossFire, A Multiplayer game for X-windows
3 3
4 Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team
4 Copyright (C) 2001 Mark Wedel 5 Copyright (C) 2001 Mark Wedel
5 Copyright (C) 1992 Frank Tore Johansen 6 Copyright (C) 1992 Frank Tore Johansen
6 7
7 This program is free software; you can redistribute it and/or modify 8 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by 9 it under the terms of the GNU General Public License as published by
42#include <netinet/ip.h> 43#include <netinet/ip.h>
43#include <netdb.h> 44#include <netdb.h>
44 45
45#include <unistd.h> 46#include <unistd.h>
46#include <arpa/inet.h> 47#include <arpa/inet.h>
48
49#include <algorithm>
47 50
48sockvec clients; 51sockvec clients;
49 52
50/** 53/**
51 * Initializes a connection. Really, it just sets up the data structure, 54 * Initializes a connection. Really, it just sets up the data structure,
56: fd (fd), host (strdup (peername)), 59: fd (fd), host (strdup (peername)),
57 socket_ev (this, &client::socket_cb), 60 socket_ev (this, &client::socket_cb),
58 cmd_ev (this, &client::cmd_cb), 61 cmd_ev (this, &client::cmd_cb),
59 cc_inv (this), cc_other (this) 62 cc_inv (this), cc_other (this)
60{ 63{
64 refcnt_inc (); // the socket is an external reference
65
61 { 66 {
62 struct linger linger_opt; 67 struct linger linger_opt;
63 68
64 linger_opt.l_onoff = 0; 69 linger_opt.l_onoff = 0;
65 linger_opt.l_linger = 0; 70 linger_opt.l_linger = 0;
147 152
148 // initialisation done, kick it! 153 // initialisation done, kick it!
149 send_packet_printf ("version %d %d %s\n", VERSION_CS, VERSION_SC, VERSION_INFO); 154 send_packet_printf ("version %d %d %s\n", VERSION_CS, VERSION_SC, VERSION_INFO);
150 flush (); 155 flush ();
151 156
152#if 0//TODO 157 clients.insert (this);
153 socket_info.nconns++;
154 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;
156#endif
157} 158}
158 159
159client::~client () 160client::~client ()
160{ 161{
161 if (pl) 162 clients.erase (this);
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 163
173 sfree<uint8> (faces_sent, nrofpixmaps); 164 sfree<uint8> (faces_sent, nrofpixmaps);
174 free (stats.range); 165 free (stats.range);
175 free (stats.title); 166 free (stats.title);
176 free (host); 167 free (host);
177} 168}
178 169
179void 170void
180client::destroy () 171client::do_destroy ()
181{ 172{
182 INVOKE_CLIENT (DESTROY, this); 173 attachable::do_destroy ();
174
175 if (pl)
176 pl->disconnect ();
177
178 if (fd >= 0)
179 {
180 send_packet ("goodbye");
181 flush ();
182
183 close (fd);
184 }
183 185
184 state = ST_DEAD; 186 state = ST_DEAD;
185 187
186 socket_ev.suspend (); 188 socket_ev.suspend ();
187 cmd_ev.suspend (); 189 cmd_ev.suspend ();
190
191 refcnt_dec (); // socket no longer open
188} 192}
189 193
190/** This sets up the socket and reads all the image information into memory. */ 194/** This sets up the socket and reads all the image information into memory. */
191void 195void
192init_ericserver (void) 196init_ericserver (void)
223 return 0; 227 return 0;
224 } 228 }
225 else 229 else
226 { 230 {
227 client *ns = new client (dup (fd), peername); 231 client *ns = new client (dup (fd), peername);
228 clients.push_back (ns);
229 232
230 ns->instantiate (); // effectively a nop right now 233 ns->instantiate (); // effectively a nop right now
231 234
232 INVOKE_CLIENT (CONNECT, ns); 235 INVOKE_CLIENT (CONNECT, ns);
233 236

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines