Clean up how quit and server shutdown trigger connection close
Simply set the player connection's EOF indicator. Cleaner than setting player->state to PS_SHUTDOWN from random places. Move the assignment of PS_PLAYING from player_main() to its caller play_cmd(), so that player->state is exclusively controlled in login.c.
This commit is contained in:
parent
0a7306a5ac
commit
8549efbc19
3 changed files with 7 additions and 7 deletions
|
@ -86,7 +86,7 @@ player_login(void *ud)
|
|||
|
||||
pr_id(player, C_INIT, "Empire server ready\n");
|
||||
|
||||
while (player->state != PS_SHUTDOWN) {
|
||||
for (;;) {
|
||||
io_output(player->iop, 1);
|
||||
if (io_gets(player->iop, buf, sizeof(buf)) < 0) {
|
||||
res = io_input(player->iop, 1);
|
||||
|
@ -355,9 +355,11 @@ play_cmd(void)
|
|||
empth_set_name(empth_self(), buf);
|
||||
logerror("%s logged in as country #%d", praddr(player), player->cnum);
|
||||
pr_id(player, C_INIT, "%d\n", CLIENTPROTO);
|
||||
player->state = PS_PLAYING;
|
||||
player_main(player);
|
||||
logerror("%s logged out, country #%d", praddr(player), player->cnum);
|
||||
player->state = PS_SHUTDOWN;
|
||||
if (CANT_HAPPEN(!io_eof(player->iop)))
|
||||
io_set_eof(player->iop);
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -59,7 +59,6 @@ player_main(struct player *p)
|
|||
struct natstr *natp;
|
||||
char buf[128];
|
||||
|
||||
p->state = PS_PLAYING;
|
||||
player = p;
|
||||
time(&player->curup);
|
||||
update_timeused_login(player->curup);
|
||||
|
@ -174,7 +173,6 @@ status(void)
|
|||
time(&player->curup);
|
||||
update_timeused(player->curup);
|
||||
if (io_error(player->iop) || io_eof(player->iop)
|
||||
|| player->state == PS_SHUTDOWN
|
||||
|| !may_play_now(natp, player->curup))
|
||||
return 0;
|
||||
|
||||
|
@ -284,7 +282,7 @@ show_motd(void)
|
|||
int
|
||||
quit(void)
|
||||
{
|
||||
player->state = PS_SHUTDOWN;
|
||||
io_set_eof(player->iop);
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -419,9 +419,9 @@ shutdwn(int sig)
|
|||
if (p->state != PS_PLAYING)
|
||||
continue;
|
||||
pr_flash(p, "Server shutting down...\n");
|
||||
p->state = PS_SHUTDOWN;
|
||||
io_set_eof(p->iop);
|
||||
p->aborted = 1;
|
||||
p->may_sleep = PLAYER_SLEEP_NEVER;
|
||||
p->aborted++;
|
||||
if (p->command) {
|
||||
pr_flash(p, "Shutdown aborting command\n");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue