include/server.h File Reference

#include "empthread.h"

Include dependency graph for server.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define UPDATE_TIME_LEN   16

Functions

void market_init (void)
void update_main (void)
void update_init (void)
int update_trigger (void)
int update_reschedule (void)
int shutdown_initiate (int)
void delete_lostitems (void *)
void player_kill_idle (void *)

Variables

int shutdown_pending
empth_rwlock_tplay_lock
int play_wrlock_wanted
int update_running
time_t update_time [16]


Define Documentation

#define UPDATE_TIME_LEN   16

Definition at line 39 of file server.h.


Function Documentation

void delete_lostitems ( void *   ) 

Definition at line 44 of file lostitem.c.

References empth_sleep(), getlost, lost(), lost_items_timeout, and putlost.

Referenced by start_server().

00045 {
00046     time_t now;
00047     struct loststr lost;
00048     int n;
00049     int ncnt;
00050 
00051     while (1) {
00052         time(&now);
00053 /*      logerror("Deleting lost items at %s", ctime(&now));*/
00054         ncnt = 0;
00055         for (n = 0; getlost(n, &lost); n++) {
00056             if (!lost.lost_owner)
00057                 continue;
00058             if (lost.lost_timestamp > (now - lost_items_timeout))
00059                 continue;
00060             lost.lost_owner = 0;
00061             lost.lost_timestamp = 0;
00062             putlost(n, &lost);
00063             ncnt++;
00064         }
00065 /*      logerror("Deleted %d lost items", ncnt, ctime(&now));*/
00066         now = now + 900;        /* Every 15 minutes */
00067         empth_sleep(now);
00068     }
00069     /*NOTREACHED*/
00070 }

Here is the call graph for this function:

void market_init ( void   ) 

Definition at line 65 of file marketup.c.

References empth_create(), exit_nomem(), market_update(), opt_MARKET, and player_new().

Referenced by start_server().

00066 {
00067     struct player *dp;
00068 
00069     if (!opt_MARKET)
00070         return;
00071     dp = player_new(-1);
00072     if (!dp)
00073         exit_nomem();
00074     if (!empth_create(market_update, 50 * 1024, 0, "MarketUpdate", dp))
00075         exit_nomem();
00076 }

Here is the call graph for this function:

void player_kill_idle ( void *   ) 

Definition at line 45 of file idle.c.

References player::aborted, player::curup, empth_sleep(), empth_wakeup(), max_idle, player_next(), pr_flash(), player::proc, PS_SHUTDOWN, and player::state.

Referenced by start_server().

00046 {
00047     struct player *p;
00048     time_t now;
00049 
00050     time(&now);
00051     while (1) {
00052         empth_sleep(now + 60);
00053         time(&now);
00054         for (p = player_next(0); p != 0; p = player_next(p)) {
00055             if (p->state == PS_SHUTDOWN) {
00056                 /*
00057                  * Player thread hung or just aborted by update or
00058                  * shutdown, we can't tell.
00059                  */
00060                 continue;
00061             }
00062             if (p->curup + max_idle * 60 < now) {
00063                 p->state = PS_SHUTDOWN;
00064                 p->aborted++;
00065                 pr_flash(p, "idle connection terminated\n");
00066                 empth_wakeup(p->proc);
00067             }
00068         }
00069     }
00070     /*NOTREACHED*/
00071 }

Here is the call graph for this function:

int shutdown_initiate ( int   ) 

Definition at line 49 of file shutdown.c.

References empth_create(), NULL, pr_wall(), shutdown_pending, and shutdown_sequence().

Referenced by shut().

00050 {
00051     int old_pending = shutdown_pending;
00052 
00053     if (mins_from_now < 0) {
00054         if (shutdown_pending) {
00055             shutdown_pending = 0;
00056             pr_wall("The server shutdown has been cancelled!\n");
00057         }
00058         return old_pending;
00059     }
00060 
00061     shutdown_pending = mins_from_now + 1;
00062 
00063     if (old_pending) {
00064         pr_wall("The shutdown time has been changed to %d minutes!\n",
00065                 mins_from_now);
00066         /* FIXME wake up shutdown_sequence() */
00067     } else {
00068         if (!empth_create(shutdown_sequence, 50 * 1024, 0,
00069                           "shutdownSeq", NULL))
00070             return -1;
00071     }
00072 
00073     return old_pending;
00074 }

Here is the call graph for this function:

void update_init ( void   ) 

Definition at line 69 of file update.c.

References double, empth_create(), empth_rwlock_create(), exit_nomem(), NULL, play_lock, player_new(), update_get_schedule(), update_sched(), update_schedule_anchor, update_thread, WORLD_X, and WORLD_Y.

Referenced by start_server().

00070 {
00071     struct player *dp;
00072     int stacksize;
00073 
00074     update_schedule_anchor = (time(NULL) + 59) / 60 * 60;
00075     if (update_get_schedule() < 0)
00076         exit(1);
00077 
00078     play_lock = empth_rwlock_create("Update");
00079     if (!play_lock)
00080         exit_nomem();
00081 
00082     dp = player_new(-1);
00083     if (!dp)
00084         exit_nomem();
00085     /* FIXME ancient black magic; figure out true stack need */
00086     stacksize = 100000 +
00087 /* finish_sects */ WORLD_X * WORLD_Y * (2 * sizeof(double) +
00088                                         sizeof(char *));
00089     update_thread = empth_create(update_sched, stacksize, 0,
00090                                  "Update", dp);
00091     if (!update_thread)
00092         exit_nomem();
00093 }

Here is the call graph for this function:

void update_main ( void   ) 

Definition at line 55 of file main.c.

References age_levels(), air_money, AT_WAR, bp_alloc(), clear_telegram_is_new(), count_pop(), delete_old_announcements(), delete_old_news(), ef_flush(), EF_LAND, EF_NATION, EF_PLANE, EF_SECTOR, EF_SHIP, etu_per_update, finish_sects(), game_record_update(), getnatp, getrel(), int, journal_update(), lnd_money, logerror(), MAXNOC, mob_land(), mob_plane(), mob_sect(), mob_ship(), MOBILIZATION, money, money_res, natstr::nat_money, natstr::nat_reserve, natstr::nat_stat, NULL, opt_AUTO_POWER, opt_MOB_ACCESS, opt_SLOW_WAR, pops, prepare_sects(), prod_land(), prod_nat(), prod_plane(), prod_ship(), produce_sect(), SCT_TYPE_MAX, sea_money, setrel(), SITZKRIEG, STAT_SANCT, tpops, UPD_DEMAND_ASYNC, UPD_DEMAND_SCHED, update_demand, update_power(), and update_removewants().

Referenced by update_run().

00056 {
00057     int etu = etu_per_update;
00058     int n;
00059     int x;
00060     struct bp *bp;
00061     int cn, cn2, rel;
00062     struct natstr *cnp;
00063     struct natstr *np;
00064 
00065     logerror("production update (%d etus)", etu);
00066     game_record_update(time(NULL));
00067     journal_update(etu);
00068 
00069     /* First, make sure all mobility is updated correctly. */
00070     if (opt_MOB_ACCESS) {
00071         mob_ship();
00072         mob_sect();
00073         mob_plane();
00074         mob_land();
00075     }
00076 
00077     if (opt_AUTO_POWER)
00078         update_power();
00079 
00080     /*
00081      * set up all the variables which get used in the
00082      * sector production routine (for producing education,
00083      * happiness, and printing out the state of the nation)
00084      */
00085     memset(pops, 0, sizeof(pops));
00086     memset(air_money, 0, sizeof(air_money));
00087     memset(sea_money, 0, sizeof(sea_money));
00088     memset(lnd_money, 0, sizeof(lnd_money));
00089     bp = bp_alloc();
00090     for (n = 0; n < MAXNOC; n++) {
00091         money[n] = 0;
00092         if (!(np = getnatp(n)))
00093             continue;
00094         money[n] = np->nat_money;
00095         tpops[n] = count_pop(n);
00096     }
00097 
00098     logerror("preparing sectors...");
00099     prepare_sects(etu, bp);
00100     logerror("done preparing sectors.");
00101     logerror("producing for countries...");
00102     for (x = 0; x < MAXNOC; x++) {
00103         long p_sect[SCT_TYPE_MAX+2][2];
00104 
00105         memset(p_sect, 0, sizeof(p_sect));
00106         if (!(np = getnatp(x)))
00107             continue;
00108         if (np->nat_stat == STAT_SANCT) {
00109 #ifdef DEBUG
00110             logerror("Country %i is in sanctuary and did not update", x);
00111 #endif
00112             continue;
00113         }
00114         np->nat_money += (int)(np->nat_reserve * money_res * etu);
00115 
00116         /* maintain units */
00117         prod_ship(etu, x, bp, 0);
00118         prod_plane(etu, x, bp, 0);
00119         prod_land(etu, x, bp, 0);
00120 
00121         /* produce all sects */
00122         produce_sect(x, etu, bp, p_sect);
00123 
00124         /* build units */
00125         prod_ship(etu, x, bp, 1);
00126         prod_plane(etu, x, bp, 1);
00127         prod_land(etu, x, bp, 1);
00128     }
00129     logerror("done producing for countries.");
00130 
00131     finish_sects(etu);
00132     prod_nat(etu);
00133     age_levels(etu);
00134     free(bp);
00135     /*flushwu(); */
00136     if (opt_SLOW_WAR) {
00137         /* Update war declarations */
00138         /* MOBILIZATION->SITZKRIEG->AT_WAR */
00139         for (cn = 1; cn < MAXNOC; cn++) {
00140             if ((cnp = getnatp(cn)) == 0)
00141                 break;
00142             for (cn2 = 1; cn2 < MAXNOC; cn2++) {
00143                 if (cn2 == cn)
00144                     continue;
00145                 rel = getrel(cnp, cn2);
00146                 if (rel == MOBILIZATION) {
00147                     rel = SITZKRIEG;
00148                     setrel(cn, cn2, rel);
00149                 } else if (rel == SITZKRIEG) {
00150                     rel = AT_WAR;
00151                     setrel(cn, cn2, rel);
00152                 }
00153             }
00154         }
00155     }
00156     /* Only update mobility for non-MOB_ACCESS here, since it doesn't
00157        get done for MOB_ACCESS anyway during the update */
00158     if (!opt_MOB_ACCESS) {
00159         mob_ship();
00160         mob_sect();
00161         mob_plane();
00162         mob_land();
00163     }
00164     if (update_demand == UPD_DEMAND_SCHED
00165         || update_demand == UPD_DEMAND_ASYNC)
00166         update_removewants();
00167     /* flush all mem file objects to disk */
00168     ef_flush(EF_NATION);
00169     ef_flush(EF_SECTOR);
00170     ef_flush(EF_SHIP);
00171     ef_flush(EF_PLANE);
00172     ef_flush(EF_LAND);
00173     delete_old_announcements();
00174     delete_old_news();
00175     /* Clear all the telegram flags */
00176     for (cn = 0; cn < MAXNOC; cn++)
00177         clear_telegram_is_new(cn);
00178     logerror("End update");
00179 }

Here is the call graph for this function:

int update_reschedule ( void   ) 

Definition at line 186 of file update.c.

References empth_wakeup(), and update_thread.

Referenced by main(), and relo().

00187 {
00188     empth_wakeup(update_thread);
00189     return 0;
00190 }

Here is the call graph for this function:

int update_trigger ( void   ) 

Definition at line 173 of file update.c.

References empth_wakeup(), logerror(), update_thread, and update_wanted.

Referenced by force(), and zdon().

00174 {
00175     logerror("Triggering unscheduled update");
00176     update_wanted = 1;
00177     empth_wakeup(update_thread);
00178     return 0;
00179 }

Here is the call graph for this function:


Variable Documentation

empth_rwlock_t* play_lock

Definition at line 81 of file main.c.

Referenced by dispatch(), shutdwn(), update_init(), and update_run().

int play_wrlock_wanted

Definition at line 88 of file main.c.

Referenced by dispatch(), io_output_all(), shutdwn(), and update_run().

int shutdown_pending

Definition at line 44 of file shutdown.c.

Referenced by force(), shutdown_initiate(), and shutdown_sequence().

int update_running

Definition at line 56 of file update.c.

Referenced by lnd_do_upd_mob(), mpr(), pln_do_upd_mob(), PR(), sct_do_upd_mob(), setrel(), shp_do_upd_mob(), shp_nav(), telegram_is_new(), update_run(), and wu().

time_t update_time[16]

Definition at line 38 of file updtime.c.

Referenced by secs_per_etu(), show_updates(), upda(), update_get_schedule(), and update_sched().


Generated on Fri Mar 28 11:01:32 2008 for empserver by  doxygen 1.5.2