Guides

Merc with open-source tools

This guide outlines the technical process for compiling and initializing a legacy Merc 2.2 codebase on modern Linux distributions (Debian 11+, Ubuntu 20.04+). It addresses specific compiler deprecations, library linking requirements, and filesystem expectations inherent to the Merc architecture.

45 minutes6 steps
Merc with open-source tools illustration
Placeholder illustration shown while custom artwork is being produced.
1

Modernize the Makefile

Legacy Merc Makefiles often use hardcoded paths and outdated flags. You must update the CC variable and ensure the crypt library is explicitly linked, as it is no longer part of glibc in many modern distros.

src/Makefile
CC      = gcc
PROF    = -O2 -g
NOCRYPT = 
C_FLAGS =  -Wall $(PROF) $(NOCRYPT)
L_FLAGS =  $(PROF) -lcrypt

merc: $(O_FILES)
	rm -f merc
	$(CC) $(L_FLAGS) -o merc $(O_FILES)

⚠ Common Pitfalls

  • Failure to include -lcrypt will result in 'undefined reference to crypt' linker errors.
  • Ensure the 'O_FILES' list includes all .o files corresponding to your .c files.
2

Resolve Crypt Header Dependencies

Merc 2.2 relies on the crypt(3) function for password hashing. Modern C compilers require the explicit inclusion of <crypt.h> and <unistd.h> to avoid implicit function declaration warnings that are treated as errors in GCC 10+.

src/comm.c
#include <sys/types.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <crypt.h>
#include "merc.h"

⚠ Common Pitfalls

  • Do not define _XOPEN_SOURCE manually unless you are prepared to resolve standard library conflicts.
3

Fix Type Mismatches in merc.h

Merc often uses 'int' for time values or sizes where modern systems expect 'time_t' or 'size_t'. Update the system-level typedefs in merc.h to match modern 64-bit architecture expectations.

src/merc.h
/* Find and update these lines */
typedef int sh_int;
typedef int bool;

/* Ensure time_t is used for timestamps */
struct char_data {
    /* ... */
    time_t logon;
    time_t save_time;
    /* ... */
};

⚠ Common Pitfalls

  • Changing sh_int to 32-bit int is safer for modern memory alignment, but ensure area file loading logic (fread_number) matches the expected bit-width.
4

Standardize Pointer Declarations

Legacy Merc code frequently uses (char *) for generic pointers or omits explicit casting for malloc/calloc. Scan for 'get_mem' or 'alloc_perm' calls and ensure they align with modern C pointer arithmetic.

src/db.c
/* Example fix in db.c */
void *alloc_perm( int sMem )
{
    static char *top_ptr;
    static int malloc_size;
    /* ... logic ... */
    return (void *)top_ptr;
}
5

Establish Directory Hierarchy

The Merc binary expects a specific directory structure relative to its execution point. If these do not exist, the MUD will crash immediately on boot when trying to load the area list or system files.

setup_dirs.sh
mkdir -p area
mkdir -p player
mkdir -p log
mkdir -p god
touch area/area.lst

⚠ Common Pitfalls

  • Merc is case-sensitive. Ensure 'area' is lowercase if your area.lst or code references it as such.
  • The 'god' directory is required for pfile saving of level 35+ characters.
6

Validate Area File Loading

Merc uses a specific EOF marker ($) in area files. Use a hex editor or cat -e to ensure your area files do not have trailing Windows-style line endings (\r\n) which can cause the parser to misread VNUMs.

launch.sh
sed -i 's/\r//' area/*.are
./merc 4000 & tail -f ../log/current.log

⚠ Common Pitfalls

  • If the MUD hangs at 'Loading help sections', there is likely a missing '$' at the end of a help file or area file.

What you built

With the Makefile updated and header conflicts resolved, the Merc codebase should compile under modern GCC. Success is indicated by the 'boot_db' function completing without a segmentation fault. Developers should next focus on replacing the legacy 'crypt' function with a more secure SHA-256 or bcrypt implementation for production use.