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

Comparing deliantra/server/socket/loop.C (file contents):
Revision 1.29 by root, Tue Dec 19 04:58:05 2006 UTC vs.
Revision 1.35 by root, Tue Jan 2 11:08:36 2007 UTC

46#include <arpa/inet.h> 46#include <arpa/inet.h>
47 47
48#include <loader.h> 48#include <loader.h>
49 49
50#define MAX_QUEUE_DEPTH 500 //TODO 50#define MAX_QUEUE_DEPTH 500 //TODO
51#define MAX_QUEUE_BACKLOG 5. //TODO 51#define MAX_QUEUE_BACKLOG 3. //TODO
52 52
53void 53void
54client::reset_state () 54client::reset_state ()
55{ 55{
56 if (!pl) 56 if (!pl)
86client::handle_command () 86client::handle_command ()
87{ 87{
88 bool skipping = false; 88 bool skipping = false;
89 89
90 while (!cmd_queue.empty () 90 while (!cmd_queue.empty ()
91 && !(pl && pl->state == ST_PLAYING && pl->ob && pl->ob->speed_left < 0)) 91 && !(state == ST_PLAYING && pl->ob && pl->ob->speed_left < 0))
92 { 92 {
93 command &cmd = cmd_queue.front (); 93 command &cmd = cmd_queue.front ();
94 94
95 if (cmd.stamp + MAX_QUEUE_BACKLOG < now ()) 95 if (cmd.stamp + MAX_QUEUE_BACKLOG < now ())
96 { 96 {
116 116
117void 117void
118flush_sockets (void) 118flush_sockets (void)
119{ 119{
120 for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i) 120 for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i)
121 if ((*i)->status != Ns_Dead)
122 (*i)->flush (); 121 (*i)->flush ();
123} 122}
124 123
125/** 124/**
126 * This checks the sockets for input, does the right thing. 125 * This checks the sockets for input, does the right thing.
127 * 126 *
135#ifdef CS_LOGSTATS 134#ifdef CS_LOGSTATS
136 if ((time (NULL) - cst_lst.time_start) >= CS_LOGTIME) 135 if ((time (NULL) - cst_lst.time_start) >= CS_LOGTIME)
137 write_cs_stats (); 136 write_cs_stats ();
138#endif 137#endif
139 138
140 /* Go through the players. Let the loop set the next pl value, 139 //TODO: should not be done here, either
141 * since we may remove some 140 for (int i = 0; i < clients.size (); ++i)
142 */
143 //TODO: must be handled cleanly elsewhere
144 for (player *pl = first_player; pl; )
145 { 141 {
146 player *npl = pl->next;
147
148 //TODO: must be handled cleanly elsewhere
149 if (!pl->socket || pl->socket->status == Ns_Dead)
150 {
151 save_player (pl->ob, 0);
152
153 if (!QUERY_FLAG (pl->ob, FLAG_REMOVED))
154 {
155 terminate_all_pets (pl->ob);
156 pl->ob->remove ();
157 }
158
159 leave (pl, 1);
160 final_free_player (pl);
161 }
162
163 pl = npl;
164 }
165
166 for (sockvec::iterator i = clients.begin (); i != clients.end (); )
167 {
168 client *s = *i; 142 client *s = clients [i];
169
170 if (s->status == Ns_Dead)
171 {
172 clients.erase (i);
173 delete s;
174 }
175 else
176 ++i;
177 }
178
179 /* We need to do some of the processing below regardless */
180
181 /* Check for any input on the sockets */
182 for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i)
183 {
184 client *s = *i;
185 player *pl = s->pl; 143 player *pl = s->pl;
186 144
187 //TODO: should not be done here, either 145 if (pl && pl->ns && !pl->ns->destroyed ())
188 if (s->status != Ns_Dead && pl)
189 { 146 {
190 /* Update the players stats once per tick. More efficient than 147 /* Update the players stats once per tick. More efficient than
191 * sending them whenever they change, and probably just as useful 148 * sending them whenever they change, and probably just as useful
192 */ 149 */
193 esrv_update_stats (pl); 150 esrv_update_stats (pl);
203 draw_client_map (pl->ob); 160 draw_client_map (pl->ob);
204 161
205 if (s->update_look) 162 if (s->update_look)
206 esrv_draw_look (pl->ob); 163 esrv_draw_look (pl->ob);
207 } 164 }
165
166 s->refcnt_chk ();
208 } 167 }
209} 168}
210 169

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines