Commit graph

74 commits

Author SHA1 Message Date
b9b0710128 Fix treatment of EOF from player
Commit 79407e68 (v4.3.11) changed recvclient() to keep failing after
receiving EOF from player.  This was bad, because some places getting
input check player->aborted instead of recvclient() failure, and
player->aborted wasn't set on EOF.  Bugs caused by this:

* comm_bomb(), ship_bomb(), plane_bomb(), land_bomb() went into an
  infinite loop that eventually ate all memory.

* deli(), desi(), dist(), fly(), morale(), zdon(), att_prompt(),
  ask_move_in() interpreted EOF as empty input instead of no more
  input.

* cmd_sail_ship() dereferenced a null pointer.

Fix by setting player->aborted on EOF, too.
(cherry picked from commit b3a7a8ee11)
2008-07-15 06:37:05 -04:00
80b57b2f95 Simplify breaking of command loop
Change status() to check player->eof instead of io_error() and
io_eof().  Ignore value of command().
(cherry picked from commit 9c5854c8c9)
2008-07-15 06:33:45 -04:00
db02dda32f Update copyright notice 2008-01-19 10:15:37 +01:00
adfab4344e Disable nested execute. The execute protocol is flawed and cannot be
implemented correctly by asynchronous clients --- unless a client
waits for a prompt after sending the execute command and its argument,
it is prone to send more input before the C_EXECUTE arrives.  That
input overtakes the contents of the script file.  This is almost
certain to happen when the execute is in a script file.  Disabling
that is probably more useful and certainly less painful than
documenting this mess.  The client rejects nested execute since
servcmd.c rev. 1.42.
(EXEC): new.
(player_coms): Require it for execute.
(player_set_nstat): Set it in nstat.
(execute): Clear it in nstat.
2007-12-09 17:24:30 +00:00
ed8e0cd552 (execute): Clients can't reliably detect where a redirection ends
because the server doesn't send C_PROMPT.  The client simply rejects
such redirections since servcmd.c rev. 1.42.  Before it didn't, but
incorrectly extended the redirection until the end of the script, and
screwed up when there was more than one redirection in the execute.
Make the server reject such redirections as well, because that's
probably more useful and certainly less painful than documenting this
mess.
2007-12-09 17:06:03 +00:00
d3eec3e09d (status, init_nats): Concentrate CAP and MONEY logic in
player_set_nstat().
2007-12-08 20:53:08 +00:00
976c885dfc (dispatch, explain, status): Use player->nstat instead of
player->ncomstat for command permissions.  Side effect: status() no
longer notifies deities when they go broke or become solvent.
(dispatch): Don't distinguish between transiently and permanently
unavailable commands.  Didn't really work anyway.
(player): Remove unused member ncomstat.
2007-12-08 20:47:13 +00:00
f36aa0f89d (player): Remove member broke.
(player_set_nstat): Don't set it.
(status): Check nstat instead of broke and nat_money.
2007-12-08 20:09:35 +00:00
2b5ebf1f3f (player_set_nstat): New, factored out of init_nats().
(init_nats): Use it.  No functional change.

(status): Use it.  This sets player->nstat from scratch, not just
MONEY and CAP.
(brea): Don't bother to update player->nstat, status() will.
2007-12-08 19:27:41 +00:00
a71ec1459d (status): Round money before checking solvency, and consistently treat
$0 as solvent.  Before, you became bankrupt / solvent when your money
went below / above zero before rounding, but not when you hit zero
exactly.
2007-12-08 14:36:54 +00:00
c96761ecee (status): Simplify. No functional change. 2007-12-08 07:33:45 +00:00
698322553a (execute): Use player->comtail[1] instead of player->argp[1]. This
makes execute send everything after the command back to the client
verbatim, not just the first argument (with quotes and funny
characters stripped).  The client always expected that, and got
confused when the server sent something else.
2007-11-25 14:06:53 +00:00
90631d56ed Record raw arguments, to be used in the next changesets:
(player): New member comtail.
(parse): New parameter tail.  Reorder parameter list.
(command, execute): Pass player->comtail.
(player_login, emp_config, do_unit_move): Pass NULL.  No functional
change.
2007-11-25 13:55:52 +00:00
79407e68fd Shut down session on receipt of "ctld\n" even when reading arguments:
(player): New member eof.
(recvclient): Return -1 without receiving input when it is set.  Set
it on receipt of "ctld\n".
(execute): Clear it after receiving the script.
2007-11-15 19:10:04 +00:00
bd0d5c10b6 (execute): Prompted for a missing argument, but then passed a null
pointer to prexec() instead.  Some systems (GNU, Windows) deal
gracefully with printing null strings, others crash.
2007-11-15 19:03:27 +00:00
404095d2fa Trim system includes. 2007-08-18 17:03:14 +00:00
Ron Koenderink
4bbc3f4286 Simple POSIX I/O emulation layer to work around Windows's defective
Unix I/O:
[_WIN32] (socklen_t, accept, posix_accept, bind. posix_bind, listen)
(posix_listen, setsockopt, posix_setsockopt, shutdown, posix_shutdown)
(socket, posix_socket, close, posix_close, creat, fstat, posix_fstat)
(lseek, posix_lseek, open, posix_open, read, posix_read, write)
(posix_write, fileno, posix_fileno, fcntl, O_NONBLOCK, F_RDLCK)
(F_WRLCK, F_GETFL, F_SETFL, F_SETLK, EWOULDBLOCK, ENOTSOCK)
(flock, fsync, posix_fsync):
New.
(ef_open, io_close, io_input, io_output, io_shutdown, io_noblocking)
(player_accept): Use them to simplify.
[_WIN32] (posix_fd2socket): New.
(empth_select): Use it.
(gen_power): Use it.
2007-08-14 03:33:28 +00:00
6f1cc795f1 (status): Simplify conditional for the "lost your capital" message.
(player): No uses of member visitor left, remove.
2007-07-15 16:15:03 +00:00
63bdc89835 Update copyright notice. 2007-01-09 19:09:31 +00:00
c9f21c0e73 (player_main): Delay journal_login() until after error exits, to
ensure it is properly paired with journal_logout().
2006-09-23 08:58:54 +00:00
Ron Koenderink
d413884a37 [_WIN32, __GNUC__]: Reorganize the include files for WIN32 to
separate the MinGW environment from the MSVC environment and
WIN32 environment.  Reorganize the order of the includes so
the system files are always loaded first to prevent with misc.h defines.
Remove system file includes from misc.h.
2006-07-13 21:14:16 +00:00
e42053d928 Break inclusion cycle: prototypes.h and commands.h included each
other.  Ensure headers in include/ can be included in any order
(except for econfig-spec.h, which is special).  New header types.h to
help avoid inclusion cycles.  Sort include directives.  Remove some
superflous includes.
2006-07-10 06:37:23 +00:00
1ca0b5cb2b Finally merge the journal patch:
(keep_journal): New econfig key.
(player_main): Log player login and logout.
(recvclient): Log player input.
(ef_open_srv, ef_close_srv): Log startup and shutdown.
(update_main): Log update.

Support the common SIGHUP log rotation idiom:
(empth_wait_for_shutdown, empth_wait_for_signal): Rename.
[EMPTH_LWP, EMPTH_POSIX] (empth_init, empth_wait_for_signal): Wait for
SIGHUP as well.
(main) [SIGHUP]: Reopen journal when empth_wait_for_signal() returns
SIGHUP.
2006-06-08 20:11:26 +00:00
Ron Koenderink
548bc5bbdc (command): Remove unused local variable i. 2006-05-22 20:37:20 +00:00
df3786ac40 (command): Don't fold conditionals to lower case. This was added
early in Chainsaw 3, most probably to make them case insensitive.
This is of debatable utility, and inconsistent with the case
sensitivity of commands and arguments.  It also interferes with string
conditionals: fleet#A is folded to fleet#a, which means something
else!
2006-05-22 20:04:54 +00:00
2ae6be9af6 (num_teles, redir_fp, pipe_fp, exec_fd, sendeof, prompt, command)
(ac_intercept, all_missiles, ac_planedamage, ac_doflak, ac_landflak)
(ac_shipflak, ac_fireflak, can_fly, do_evade, att_calcodds)
(emp_setbitmap, lnd_hit_mine, conditions, get_wp, daemonize): Internal
linkage.
2006-05-20 13:54:45 +00:00
e28851b8e9 Normalize unsigned int to just unsigned. 2006-04-30 12:26:07 +00:00
d182f3dc1d (command): Simplify mapping of condarg to lower case. 2006-03-27 20:13:50 +00:00
f5a9284867 Update known contributors comment. 2006-02-24 21:35:27 +00:00
5537d902b7 (player_main): Don't end session silently when init_nats() fails. 2006-02-23 07:40:11 +00:00
02ddee69fb (banfil, authfil): Remove. Matching user is useless, because the
player can send whatever he wants.  Banning IPs is better done with a
packet filter.  That leaves restricting deity IPs.
(privip): New econfig key to restrict deity IPs.
(may_play): Implement it.
(match_user): Unused, remove.
2006-02-22 20:57:51 +00:00
342d7b33ce (may_play): New, factored out of play_cmd() and kill_cmd().
(play_cmd, kill_cmd): Use it.
(player_main): Don't check authfil, caller takes care of that.
2006-02-22 19:50:01 +00:00
4515b84c59 COPYING duplicates information from README. Remove. Move GPL from
LICENSE to COPYING, because that's where it usually is.  Update all
the references to these files.
2006-01-21 19:48:41 +00:00
Ron Koenderink
04a8b84592 (ship_bomb, deli, do_demo, fuel, grin, look_ship)
(ltend, multifire, quite_bigdef, mine, landmine)
(do_loan, prod, printdiff, sell, sona, stre)
(tend, fire_dchrg, vers, work, ac_planedamage)
(ac_shipflak, ask_off, get_mine_dsupport, att_fight)
(ask_move_in_off, detonate, sd, land_gun)
(land_unitgun, lnd_fort_interdiction, lnd_fortify)
(perform_mission, pln_mine, pln_mobcost)
(retreat_ship1, retreat_land1, shp_sweep)
(shp_fort_interdiction, shp_missle_defense)
(new_work, growfood, upd_land, land_repair)
(get_materials, do_mob_ship, do_mob_land)
(load_it, unload_it, prod_plane, produce)
(guerrilla, upd_buildeff, spread_fallout)
(upd_ship, ship_repair, min, dmin, MIN):
Remove min() and dmin() functions and replace
with a MIN macro in misc.h.  Remove local MIN
macros and use the new one in misc.h.  This
change removes the need for the special
case for _WIN32.

(fuel, look_ship, multifire, mission, sona)
(plane_sona, ef_open, player_accept, player_main)
(ac_dog, att_get_combat, calc_mobcost)
(ask_move_in_off, intelligence_report)
(build_mission_list_type, perform_mission)
(show_mission, use_supply, dodistribute)
(allocate_memory, max, dmax, MAX):
Remove max() and dmax() functions and replace
with a MAX macro in misc.h.  Remove local MAX
macros and use the new one in misc.h.  This
change removes the need for the special
case for _WIN32.
2006-01-12 14:23:55 +00:00
87aa405823 (status): src/lib/subs/mtch.c rev. 1.10 broke deity commands that
require CAP or MONEY.  Fix by setting them in ncomstat.
2006-01-06 20:07:13 +00:00
3e400c018c Update copyright notice. 2006-01-05 13:36:57 +00:00
8b16c31223 Change nation status from bits to a simple enum:
(nat_status, STAT_UNUSED, STAT_VIS, STAT_ACTIVE): New.
(STAT_NEW, STAT_SANCT, STAT_GOD): Change into nat_status members.
(STAT_INUSE, STAT_NORM): Remove.
(natstr): Use new nat_status for nat_stat.
    New value       Old value
    STAT_UNUSED     0
    STAT_NEW        STAT_INUSE | STAT_NEW
    STAT_VIS        STAT_INUSE
    STAT_SANCT      STAT_INUSE | STAT_SANCT
    STAT_ACTIVE     STAT_INUSE | STAT_NORM
    STAT_GOD        STAT_INUSE | STAT_NORM | STAT_GOD
Users changed.
2006-01-04 22:49:42 +00:00
85bb851c04 (status): Enforce m_m_p_d only for active countries, not for deities,
visitors and such.
2006-01-04 17:58:16 +00:00
3aebb68ee7 Include config.h. 2005-12-27 18:04:19 +00:00
Ron Koenderink
9b3e820d3a (nat_cap, status): Use the new function influx() to determine
if a valid capital is present or not.
2005-12-23 01:10:07 +00:00
d343fee727 Remove superflous include. 2005-12-11 10:09:09 +00:00
f94f81ee16 (add): Initialize nat_last_login and nat_last_logout to zero rather
than current time.  Nation addition time is irrelevant.
(natstr): Document zero nat_last_login, nat_last_login mean never
logged in/out.
(player_main): Test nat_last_login zero instead of nat_hostaddr empty.

(player_main): Assign nat_userid, nat_hostname, nat_hostaddr straight
from player.  The last connection's host is now shown as dotted quads
instead of nowhere when the name isn't known.
(natstr): Document that nat_userid, nat_hostname may be empty.

(player_main): Simplify printing last connection address: nat_hostaddr
can't be empty here; don't bother to substitute "nobody" for empty
user.
2005-10-03 13:25:54 +00:00
95d2b48ee2 (match_user, main): Use full buffer for fgets(); was off by one. 2005-10-03 10:45:00 +00:00
4f1ebae4b7 (natstr): Member nat_connected is inappropriate, because it is
transient server state, not persistent game state.  Remove.
(player_main, edit): Remove uses.
(coun): Use getplayer() instead of nat_connected.  Delete the message
on command being out of order.
2005-10-02 17:01:15 +00:00
8cc53c1c2b (status): Internal linkage. 2005-07-23 16:41:18 +00:00
Ron Koenderink
db6fd8dad2 (player_main): Add empth_yield() in the command processing loop to ensure
after every command, other players gets a chance to execute a command.
This prevents denial of service attack that monopolizing the active server
thread by continuing feeding data to the server from a client.
2005-07-23 13:37:36 +00:00
71e164ed30 Document, in particular use of UTF-8. Simplify code in a couple of
places, but no functional changes.
2005-06-13 19:02:49 +00:00
968e754447 (lrange, shoo, execute): Buffer passed to getstarg() was too small.
Player could overrun it!
2005-06-13 11:32:07 +00:00
58a0d40777 (player_login, player_main): Move the C_INIT that terminates the login
phase to player_login().  No functional change.
(showvers): Trivial, used just once.  Inline, remove.
2005-06-13 09:45:32 +00:00
e536b02c1c (gamedown, show_motd): Fix message buffer size. Messages of maximum
length were considered overlong and ignored.
2005-06-12 09:25:22 +00:00