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.29 by root, Fri Dec 22 06:02:29 2006 UTC vs.
Revision 1.33 by pippijn, Sat Jan 6 14:42:31 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,
147 150
148 // initialisation done, kick it! 151 // initialisation done, kick it!
149 send_packet_printf ("version %d %d %s\n", VERSION_CS, VERSION_SC, VERSION_INFO); 152 send_packet_printf ("version %d %d %s\n", VERSION_CS, VERSION_SC, VERSION_INFO);
150 flush (); 153 flush ();
151 154
155 // clients are externally referenced by the socket
156 refcnt_inc ();
157 clients.push_back (this);
158
152#if 0//TODO 159#if 0//TODO
153 socket_info.nconns++; 160 socket_info.nconns++;
154 if (socket_info.nconns > cst_tot.max_conn) cst_tot.max_conn = socket_info.nconns; 161 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; 162 if (socket_info.nconns > cst_lst.max_conn) cst_lst.max_conn = socket_info.nconns;
156#endif 163#endif
157} 164}
158 165
159client::~client () 166client::~client ()
160{ 167{
161 if (pl) 168 sockvec::iterator i = find (clients.begin (), clients.end (), this);
162 pl->ns = 0; 169 if (i != clients.end ())
163 170 clients.erase (i);
164 if (fd >= 0)
165 close (fd);
166 171
167 sfree<uint8> (faces_sent, nrofpixmaps); 172 sfree<uint8> (faces_sent, nrofpixmaps);
168 free (stats.range); 173 free (stats.range);
169 free (stats.title); 174 free (stats.title);
170 free (host); 175 free (host);
171} 176}
172 177
173void 178void
174client::destroy () 179client::do_destroy ()
175{ 180{
176 INVOKE_CLIENT (DESTROY, this); 181 attachable::do_destroy ();
182
183 if (pl)
184 pl->disconnect ();
185
186 if (fd >= 0)
187 close (fd);
177 188
178 state = ST_DEAD; 189 state = ST_DEAD;
179 190
180 socket_ev.suspend (); 191 socket_ev.suspend ();
181 cmd_ev.suspend (); 192 cmd_ev.suspend ();
193
194 // socket now longer references us
195 refcnt_dec ();
182} 196}
183 197
184/** This sets up the socket and reads all the image information into memory. */ 198/** This sets up the socket and reads all the image information into memory. */
185void 199void
186init_ericserver (void) 200init_ericserver (void)
204void 218void
205free_all_newserver (void) 219free_all_newserver (void)
206{ 220{
207 LOG (llevDebug, "Freeing all new client/server information.\n"); 221 LOG (llevDebug, "Freeing all new client/server information.\n");
208 free_socket_images (); 222 free_socket_images ();
209}
210
211/** Sends the 'goodbye' command to the player, and closes connection. */
212void
213final_free_player (player *pl)
214{
215 free_player (pl);
216} 223}
217 224
218client * 225client *
219client::create (int fd, const char *peername) 226client::create (int fd, const char *peername)
220{ 227{
224 return 0; 231 return 0;
225 } 232 }
226 else 233 else
227 { 234 {
228 client *ns = new client (dup (fd), peername); 235 client *ns = new client (dup (fd), peername);
229 clients.push_back (ns);
230 236
231 ns->instantiate (); // effectively a nop right now 237 ns->instantiate (); // effectively a nop right now
232 238
233 INVOKE_CLIENT (CONNECT, ns); 239 INVOKE_CLIENT (CONNECT, ns);
234 240

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines