#include <config.h>#include <errno.h>#include <stdio.h>#include "com.h"#include "empio.h"#include "empthread.h"#include "file.h"#include "journal.h"#include "misc.h"#include "nat.h"#include "optlist.h"#include "player.h"#include "proto.h"#include "prototypes.h"#include "tel.h"Include dependency graph for player.c:

Go to the source code of this file.
Functions | |
| static int | command (void) |
| static int | status (void) |
| void | player_main (struct player *p) |
| int | execute (void) |
| int | show_motd (void) |
| int | quit (void) |
| char * | praddr (struct player *p) |
Variables | |
| player * | player |
| static int command | ( | void | ) | [static] |
Definition at line 136 of file player.c.
References player::argp, player::combuf, player::comtail, player::condarg, dispatch(), getcommand(), parse(), player, and pr().
Referenced by dispatch(), and player_main().
00137 { 00138 char *redir; /* UTF-8 */ 00139 char scanspace[1024]; 00140 00141 if (getcommand(player->combuf) < 0) 00142 return 0; 00143 if (parse(player->combuf, scanspace, player->argp, player->comtail, 00144 &player->condarg, &redir) < 0) { 00145 pr("See \"info Syntax\"?\n"); 00146 } else { 00147 if (dispatch(player->combuf, redir) < 0) 00148 pr("Try \"list of commands\" or \"info\"\n"); 00149 } 00150 return 1; 00151 }
Here is the call graph for this function:

| int execute | ( | void | ) |
Definition at line 245 of file player.c.
References player::argp, player::comtail, player::condarg, dispatch(), player::eof, EXEC, getstring(), player::nstat, NULL, parse(), player, pr(), prexec(), recvclient(), RET_OK, RET_SYN, and status().
00246 { 00247 char buf[1024]; 00248 int failed; 00249 char *p; 00250 char *redir; /* UTF-8 */ 00251 char scanspace[1024]; 00252 00253 failed = 0; 00254 00255 if (player->comtail[1]) 00256 p = player->comtail[1]; 00257 else 00258 p = getstring("File? ", buf); 00259 if (p == NULL || *p == '\0') 00260 return RET_SYN; 00261 prexec(p); 00262 00263 while (!failed && status()) { 00264 player->nstat &= ~EXEC; 00265 if (recvclient(buf, sizeof(buf)) < 0) 00266 break; 00267 if (parse(buf, scanspace, player->argp, player->comtail, 00268 &player->condarg, &redir) < 0) { 00269 failed = 1; 00270 continue; 00271 } 00272 pr("\nExecute : %s\n", buf); 00273 if (redir) { 00274 pr("Execute : redirection not supported\n"); 00275 failed = 1; 00276 } else if (dispatch(buf, NULL) < 0) 00277 failed = 1; 00278 } 00279 if (failed) { 00280 while (recvclient(buf, sizeof(buf)) >= 0) ; 00281 } 00282 00283 pr("Execute : %s\n", failed ? "aborted" : "terminated"); 00284 player->eof = 0; 00285 return RET_OK; 00286 }
Here is the call graph for this function:

| void player_main | ( | struct player * | p | ) |
Definition at line 58 of file player.c.
References player::aborted, chance(), player::cnum, command(), player::curup, daychange(), empth_yield(), gamehours(), getminleft(), getnatp, player::hostaddr, player::hostname, init_nats(), journal_login(), journal_logout(), player::lasttime, m_m_p_d, MAX, player::minleft, natstr::nat_flags, natstr::nat_hostaddr, natstr::nat_hostname, natstr::nat_last_login, natstr::nat_last_logout, natstr::nat_minused, natstr::nat_stat, natstr::nat_tgms, natstr::nat_userid, NF_INFORM, numstr(), player, pr(), PS_PLAYING, putnat, secs, show_motd(), STAT_GOD, STAT_VIS, player::state, status(), and player::userid.
Referenced by play_cmd().
00059 { 00060 struct natstr *natp; 00061 int secs; 00062 char buf[128]; 00063 00064 p->state = PS_PLAYING; 00065 player = p; 00066 time(&player->lasttime); 00067 time(&player->curup); 00068 show_motd(); 00069 if (init_nats() < 0) { 00070 pr("Server confused, try again later\n"); 00071 return; 00072 } 00073 natp = getnatp(player->cnum); 00074 if (!gamehours(player->curup)) { 00075 pr("Empire hours restriction in force\n"); 00076 if (natp->nat_stat != STAT_GOD) 00077 return; 00078 } 00079 daychange(player->curup); 00080 if ((player->minleft = getminleft(player->curup, m_m_p_d)) <= 0) { 00081 pr("Time exceeded today\n"); 00082 return; 00083 } 00084 if (natp->nat_stat != STAT_VIS 00085 && natp->nat_last_login 00086 && (strcmp(natp->nat_hostaddr, player->hostaddr) 00087 || strcmp(natp->nat_userid, player->userid))) { 00088 pr("Last connection from: %s", ctime(&natp->nat_last_login)); 00089 pr(" to: %s", 00090 natp->nat_last_login <= natp->nat_last_logout 00091 ? ctime(&natp->nat_last_logout) : "?"); 00092 pr(" by: %s@%s\n", 00093 natp->nat_userid, 00094 *natp->nat_hostname ? natp->nat_hostname : natp->nat_hostaddr); 00095 } 00096 strcpy(natp->nat_userid, player->userid); 00097 strcpy(natp->nat_hostname, player->hostname); 00098 strcpy(natp->nat_hostaddr, player->hostaddr); 00099 00100 time(&natp->nat_last_login); 00101 putnat(natp); 00102 journal_login(); 00103 if (natp->nat_flags & NF_INFORM && natp->nat_tgms > 0) { 00104 if (natp->nat_tgms == 1) 00105 pr("You have a new telegram waiting ...\n"); 00106 else 00107 pr("You have %s new telegrams waiting ...\n", 00108 numstr(buf, natp->nat_tgms)); 00109 natp->nat_tgms = 0; 00110 } 00111 00112 while (status()) { 00113 if (command() == 0 && !player->aborted) 00114 break; 00115 player->aborted = 0; 00116 empth_yield(); 00117 } 00118 /* #*# I put the following line in to prevent server crash -KHS */ 00119 natp = getnatp(player->cnum); 00120 /* 00121 * randomly round up to the nearest minute, 00122 * charging at least 15 seconds. 00123 */ 00124 time(&natp->nat_last_logout); 00125 secs = MAX(natp->nat_last_logout - player->lasttime, 15); 00126 natp->nat_minused += secs / 60; 00127 secs = secs % 60; 00128 if (chance(secs / 60.0)) 00129 natp->nat_minused += 1; 00130 putnat(natp); 00131 pr("Bye-bye\n"); 00132 journal_logout(); 00133 }
Here is the call graph for this function:

| char* praddr | ( | struct player * | p | ) |
Definition at line 333 of file player.c.
References player::hostaddr, player::hostname, prbuf(), and player::userid.
Referenced by kill_cmd(), may_play(), pass_cmd(), play_cmd(), and play_list().
00334 { 00335 return prbuf("%s@%s", p->userid, 00336 *p->hostname ? p->hostname : p->hostaddr); 00337 }
Here is the call graph for this function:

| int quit | ( | void | ) |
Definition at line 326 of file player.c.
References player, PS_SHUTDOWN, RET_OK, and player::state.
Referenced by nav_ship().
00327 { 00328 player->state = PS_SHUTDOWN; 00329 return RET_OK; 00330 }
| int show_motd | ( | void | ) |
Definition at line 289 of file player.c.
References logerror(), MAXTELSIZE, motdfil, NULL, pr(), RET_FAIL, RET_OK, RET_SYS, and uprnf().
Referenced by player_main().
00290 { 00291 FILE *motd_fp; 00292 struct telstr tgm; 00293 char buf[MAXTELSIZE + 1]; /* UTF-8 */ 00294 00295 if ((motd_fp = fopen(motdfil, "rb")) == NULL) { 00296 if (errno == ENOENT) 00297 return RET_OK; 00298 else { 00299 pr ("Could not open motd.\n"); 00300 logerror("Could not open motd (%s).\n", motdfil); 00301 return RET_SYS; 00302 } 00303 } 00304 if (fread(&tgm, sizeof(tgm), 1, motd_fp) != 1) { 00305 logerror("bad header on login message (motdfil)"); 00306 fclose(motd_fp); 00307 return RET_FAIL; 00308 } 00309 if (tgm.tel_length >= (long)sizeof(buf)) { 00310 logerror("text length (%ld) is too long for login message (motdfil)", tgm.tel_length); 00311 fclose(motd_fp); 00312 return RET_FAIL; 00313 } 00314 if (fread(buf, tgm.tel_length, 1, motd_fp) != 1) { 00315 logerror("bad length %ld on login message", tgm.tel_length); 00316 fclose(motd_fp); 00317 return RET_FAIL; 00318 } 00319 buf[tgm.tel_length] = 0; 00320 uprnf(buf); 00321 fclose(motd_fp); 00322 return RET_OK; 00323 }
Here is the call graph for this function:

| static int status | ( | void | ) | [static] |
Definition at line 154 of file player.c.
References player::btused, CAP, player::cnum, player::curup, daychange(), player::dolcost, gamedown(), gamehours(), getminleft(), getnatp, player::god, io_eof(), io_error(), player::iop, player::lasttime, m_m_p_d, player::minleft, MONEY, natstr::nat_ann, natstr::nat_btu, natstr::nat_flags, natstr::nat_minused, natstr::nat_money, natstr::nat_stat, natstr::nat_tgms, NF_INFORM, NORM, player::nstat, numstr(), player, player_set_nstat(), pr(), PS_SHUTDOWN, putnat, roundavg(), STAT_ACTIVE, STAT_GOD, player::state, and VIS.
Referenced by comtch(), coun_list(), execute(), player_main(), and run_hook().
00155 { 00156 struct natstr *natp; 00157 int old_nstat, minute; 00158 char buf[128]; 00159 00160 if (player->state == PS_SHUTDOWN) 00161 return 0; 00162 natp = getnatp(player->cnum); 00163 if (io_error(player->iop) || io_eof(player->iop)) { 00164 putnat(natp); 00165 return 0; 00166 } 00167 if (player->dolcost > 100.0) 00168 pr("That just cost you $%.2f\n", player->dolcost); 00169 else if (player->dolcost < -100.0) 00170 pr("You just made $%.2f\n", -player->dolcost); 00171 natp->nat_money -= roundavg(player->dolcost); 00172 player->dolcost = 0.0; 00173 00174 old_nstat = player->nstat; 00175 player_set_nstat(player, natp); 00176 if ((old_nstat & MONEY) && !(player->nstat & MONEY)) 00177 pr("You are now broke; industries are on strike.\n"); 00178 if (!(old_nstat & MONEY) && (player->nstat & MONEY)) 00179 pr("You are no longer broke!\n"); 00180 00181 time(&player->curup); 00182 minute = (player->curup - player->lasttime) / 60; 00183 if (minute > 0) { 00184 player->minleft -= minute; 00185 if (player->minleft <= 0) { 00186 /* 00187 * countdown timer "player->minleft" has expired. 00188 * either day change, or hours restriction 00189 */ 00190 daychange(player->curup); 00191 if (!gamehours(player->curup)) { 00192 pr("Empire hours restriction in force\n"); 00193 if (natp->nat_stat != STAT_GOD) { 00194 putnat(natp); 00195 return 0; 00196 } 00197 } 00198 player->minleft = getminleft(player->curup, m_m_p_d); 00199 } 00200 player->lasttime += minute * 60; 00201 natp->nat_minused += minute; 00202 } 00203 if (natp->nat_stat == STAT_ACTIVE && natp->nat_minused > m_m_p_d) { 00204 pr("Max minutes per day limit exceeded.\n"); 00205 player->nstat = (player->nstat & ~NORM) | VIS; 00206 } 00207 if (player->btused) { 00208 natp->nat_btu -= player->btused; 00209 player->btused = 0; 00210 } 00211 if (natp->nat_tgms > 0) { 00212 if (!(natp->nat_flags & NF_INFORM)) { 00213 if (natp->nat_tgms == 1) 00214 pr("You have a new telegram waiting ...\n"); 00215 else 00216 pr("You have %s new telegrams waiting ...\n", 00217 numstr(buf, natp->nat_tgms)); 00218 natp->nat_tgms = 0; 00219 } 00220 } 00221 if (natp->nat_ann > 0) { 00222 if (natp->nat_ann == 1) 00223 pr("You have a new announcement waiting ...\n"); 00224 else 00225 pr("You have %s new announcements waiting ...\n", 00226 numstr(buf, natp->nat_ann)); 00227 natp->nat_ann = 0; 00228 } 00229 if (natp->nat_stat == STAT_ACTIVE && (player->nstat & CAP) == 0) 00230 pr("You lost your capital... better designate one\n"); 00231 putnat(natp); 00232 if (gamedown() && !player->god) { 00233 pr("gamedown\n"); 00234 return 0; 00235 } 00236 return 1; 00237 }
Here is the call graph for this function:

1.5.2