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.1 by elmex, Sun Aug 13 17:16:06 2006 UTC vs.
Revision 1.2 by root, Thu Aug 24 13:13:49 2006 UTC

1 1
2/* 2/*
3 * static char *rcsid_loop_c = 3 * static char *rcsid_loop_c =
4 * "$Id: loop.C,v 1.1 2006/08/13 17:16:06 elmex Exp $"; 4 * "$Id: loop.C,v 1.2 2006/08/24 13:13:49 root Exp $";
5 */ 5 */
6 6
7/* 7/*
8 CrossFire, A Multiplayer game for X-windows 8 CrossFire, A Multiplayer game for X-windows
9 9
459 } 459 }
460 sendto(fd,(void *)&fd,1,0,(struct sockaddr *)&insock,sizeof(insock)); 460 sendto(fd,(void *)&fd,1,0,(struct sockaddr *)&insock,sizeof(insock));
461} 461}
462#endif 462#endif
463 463
464extern unsigned long todtick;
465
466/** Waits for new connection */
467static void block_until_new_connection(void)
468{
469
470 struct timeval Timeout;
471 fd_set readfs;
472 int cycles;
473
474 LOG(llevInfo, "Waiting for connections...\n");
475
476 cycles=1;
477 do {
478 /* Every minutes is a bit often for updates - especially if nothing is going
479 * on. This slows it down to every 6 minutes.
480 */
481 cycles++;
482 if (cycles%2 == 0)
483 tick_the_clock();
484
485 FD_ZERO(&readfs);
486 FD_SET((uint32)init_sockets[0].fd, &readfs);
487
488 /* If fastclock is set, we need to seriously slow down the updates
489 * to the metaserver as well as watchdog. Do same for flush_old_maps() -
490 * that is time sensitive, so there is no good reason to call it 2000 times
491 * a second.
492 */
493 if (settings.fastclock > 0) {
494#ifdef WATCHDOG
495 if (cycles % 120000 == 0) {
496 watchdog();
497 flush_old_maps();
498 }
499#endif
500 if (cycles == 720000) {
501 metaserver_update();
502 cycles=1;
503 }
504 Timeout.tv_sec=0;
505 Timeout.tv_usec=50;
506 } else {
507 Timeout.tv_sec=60;
508 Timeout.tv_usec=0;
509 if (cycles == 7) {
510 metaserver_update();
511 cycles=1;
512 }
513 flush_old_maps();
514 }
515 }
516 while (select(socket_info.max_filedescriptor, &readfs, NULL, NULL, &Timeout)==0);
517
518 reset_sleep(); /* Or the game would go too fast */
519}
520
521void flush_sockets(void) 464void flush_sockets(void)
522{ 465{
523 player *pl; 466 player *pl;
524 467
525 for (pl = first_player; pl != NULL; pl = pl->next) 468 for (pl = first_player; pl != NULL; pl = pl->next)
584 FD_SET((uint32)pl->socket.fd, &tmp_write); 527 FD_SET((uint32)pl->socket.fd, &tmp_write);
585 FD_SET((uint32)pl->socket.fd, &tmp_exceptions); 528 FD_SET((uint32)pl->socket.fd, &tmp_exceptions);
586 pl=pl->next; 529 pl=pl->next;
587 } 530 }
588 } 531 }
589
590#if 0
591 // the event system and plugins require the server ti run at all times.
592 // since its primarily cf.schmorp.de we are interested in, and
593 // that is supposed to run all the time anyway, its globally disabled
594 // until we can use Event.
595 if (socket_info.nconns==1 && first_player==NULL)
596 block_until_new_connection();
597#endif
598 532
599 /* Reset timeout each time, since some OS's will change the values on 533 /* Reset timeout each time, since some OS's will change the values on
600 * the return from select. 534 * the return from select.
601 */ 535 */
602 socket_info.timeout.tv_sec = 0; 536 socket_info.timeout.tv_sec = 0;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines