diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e43b0f9 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.DS_Store diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..2ebc1db --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +FROM ubuntu:wily + +RUN sed -i 's#archive.ubuntu.com#mirrors.aliyun.com#' /etc/apt/sources.list && \ + apt-get update && \ + apt-get install -y libevent-2.0 libmysqlclient18 libpq5 zlib1g libpcre3 \ + --no-install-recommends && \ + rm -rf /var/lib/apt/lists/* + +COPY bin/driver bin/portbind bin/dtrace_compile /usr/bin/ + +ENTRYPOINT ["/usr/bin/driver"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..0cf1957 --- /dev/null +++ b/README.md @@ -0,0 +1,31 @@ +Docker Fluffos +============== + +### build compile image + +```bash +docker build -t lostsnow/fluffos-build ./build +``` + +### compile driver + +```bash +docker run --rm -v /opt/projects/mud:/opt/projects lostsnow/fluffos-build +``` + +### build mudlib image + +```bash +docker build -t lostsnow/fluffos . +``` + +### run mudlib + +```bash +# https://github.com/mudchina/es2-utf8 +mkdir -p /opt/projects/mud/es2-utf8/log +docker run --name es2 \ + -p 4000:4000 \ + -v /opt/projects/mud:/opt/projects \ + lostsnow/fluffos /opt/projects/docker-fluffos/example/config.ES2 +``` \ No newline at end of file diff --git a/bin/driver b/bin/driver new file mode 100755 index 0000000..bc10cb6 Binary files /dev/null and b/bin/driver differ diff --git a/bin/dtrace_compile b/bin/dtrace_compile new file mode 100755 index 0000000..a104753 Binary files /dev/null and b/bin/dtrace_compile differ diff --git a/bin/portbind b/bin/portbind new file mode 100755 index 0000000..a908609 Binary files /dev/null and b/bin/portbind differ diff --git a/build/Dockerfile b/build/Dockerfile new file mode 100644 index 0000000..2f3e9bd --- /dev/null +++ b/build/Dockerfile @@ -0,0 +1,11 @@ +FROM ubuntu:wily + +RUN sed -i 's#archive.ubuntu.com#mirrors.aliyun.com#' /etc/apt/sources.list && \ + apt-get update && \ + apt-get install -y git make g++ libevent-dev libmysqlclient-dev libpq-dev zlib1g-dev libpcre3-dev bison python wget tar gzip patch \ + --no-install-recommends && \ + rm -rf /var/lib/apt/lists/* + +COPY entrypoint.sh /entrypoint.sh + +ENTRYPOINT ["/entrypoint.sh"] diff --git a/build/build.FluffOS b/build/build.FluffOS new file mode 100755 index 0000000..be26d44 --- /dev/null +++ b/build/build.FluffOS @@ -0,0 +1,88 @@ +#!/bin/bash +set -eo pipefail + +# By default driver compile to native environment, you can +# add "-m64" to force compile under 64bit, "-m32" for 32bit. +# +# If you are building binary to run on another machine, you +# should change -march=native to -mtune=generic +COMPILER_FLAGS=${COMPILER_FLAGS:-"-mtune=generic"} + +OPTIMIZE="-O3 -funroll-loops" +DEBUG="-DNDEBUG -g" + +# Change this if you want to use another make. +MAKE=make + +# change this if you wish the driver binary to be named something else +# no suffix is needed. +DRIVER_BIN=driver + +# Set INSTALL_DIR to the directory where you want to install the executables. +INSTALL_DIR=`dirname $(pwd)`/bin + +#Enable warnings from the compiler (g++), if wanted. +WARN=( +"-Wall" +"-Wextra" +"-Wformat-security" +# Turn off some warnings from GCC. +"-Wno-char-subscripts" +"-Wno-sign-compare" +"-Wno-return-type" +"-Wno-unused-parameter" +"-Wno-missing-field-initializers" +# GCC's warning produces too many false positives: +# https://groups.google.com/a/google.com/forum/#!topic/c-users/jLRfP804wuc +# https://groups.google.com/a/google.com/d/msg/c-users/jLRfP804wuc/sKe4Ba2PKwAJ +"-Wno-overloaded-virtual" +# GCC's warning produces false positives: +# https://groups.google.com/a/google.com/d/msg/llvm-team/Mq_7JNPqE2o/lh2XpArujl8J +"-Wno-non-virtual-dtor" +# features +"-fdiagnostics-show-option" +"-fmessage-length=0" +# Less undefined behavior +"-funsigned-char" +"-fwrapv" +) +WARN="$(IFS=' '; echo "${WARN[*]}")" + + +if test $# -ne 0; then + case $1 in + develop) + echo Preparing to build developmental version of MudOS driver ... + OPTIMIZE="-O0" + DEBUG="-g -DDEBUG" + # Hardening mode activated, for more error visibility + DEBUG="$DEBUG -D_FORTIFY_SOURCE=2 -fstack-protector-all" + DEBUG="$DEBUG -Wstack-protector --param ssp-buffer-size=1 -fstrict-aliasing" + shift + ;; + *) + ;; + esac +else + echo Preparing to build standard driver ... +fi + +####### END OF USER CONFIGURABLE OPTIONS + +CFLAGS="$CFLAGS $COMPILER_FLAGS $WARN $OPTIMIZE $DEBUG" + +if [ -d $(pwd)/../.git ]; then + if [ "$(git --no-pager show -s --format='%ae')" == "sunyucong@gmail.com" ]; then + SOURCE_REVISION="git" + else + SOURCE_REVISION="git-local" + fi + SOURCE_REVISION="$SOURCE_REVISION-$(git --no-pager show -s --format='%h-%ct')" +else + SOURCE_REVISION="unknown-nongit" +fi + +# Force an reconfigure. +rm -f configure.h +CFLAGS=$CFLAGS CXXFLAGS=$CFLAGS MAKE=$MAKE ARCH=$ARCH DRIVER_BIN=$DRIVER_BIN OPTIMIZE=$OPTIMIZE SOURCE_REVISION=$SOURCE_REVISION ./configure --bindir=$INSTALL_DIR $@ +$MAKE help diff --git a/build/drop-gets.diff b/build/drop-gets.diff new file mode 100644 index 0000000..4201f69 --- /dev/null +++ b/build/drop-gets.diff @@ -0,0 +1,28 @@ +--- old/srclib/stdio.in.h ++++ new/srclib/stdio.in.h +@@ -679,22 +679,11 @@ + # endif + #endif + +-#if @GNULIB_GETS@ +-# if @REPLACE_STDIO_READ_FUNCS@ && @GNULIB_STDIO_H_NONBLOCKING@ +-# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +-# undef gets +-# define gets rpl_gets +-# endif +-_GL_FUNCDECL_RPL (gets, char *, (char *s) _GL_ARG_NONNULL ((1))); +-_GL_CXXALIAS_RPL (gets, char *, (char *s)); +-# else +-_GL_CXXALIAS_SYS (gets, char *, (char *s)); +-# undef gets +-# endif +-_GL_CXXALIASWARN (gets); + /* It is very rare that the developer ever has full control of stdin, +- so any use of gets warrants an unconditional warning. Assume it is +- always declared, since it is required by C89. */ ++ so any use of gets warrants an unconditional warning; besides, C11 ++ removed it. */ ++#undef gets ++#if HAVE_RAW_DECL_GETS + _GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead"); + #endif diff --git a/build/entrypoint.sh b/build/entrypoint.sh new file mode 100755 index 0000000..fac7276 --- /dev/null +++ b/build/entrypoint.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +if [ ! -d "/fluffos-build.lock" ]; then + apt-get update + + (wget -qO - http://ftpmirror.gnu.org/libiconv/libiconv-1.14.tar.gz | tar zxf - -C /tmp) + cd /tmp/libiconv-1.14 + # libiconv remove gets declarations patch + # https://github.com/paulczar/omnibus-fpm/blob/master/config/patches/libiconv/libiconv-1.14_srclib_stdio.in.h-remove-gets-declarations.patch + cp /opt/projects/docker-fluffos/build/drop-gets.diff ./ && patch -p1 < drop-gets.diff + make clean && ./configure --prefix=/usr && make -s && make install && rm -rf /tmp/libiconv-1.14 + + cd /opt/projects/fluffos/src + cp /opt/projects/docker-fluffos/build/{build.FluffOS,local_options} ./ + ./build.FluffOS && make + + cp ./{driver,dtrace_compile,portbind} /opt/projects/docker-fluffos/bin/ + rm -rf /var/lib/apt/lists/* + + touch /fluffos-build.lock +fi diff --git a/build/local_options b/build/local_options new file mode 100644 index 0000000..00d4b4f --- /dev/null +++ b/build/local_options @@ -0,0 +1,85 @@ +/* + * local_options.h: compile-time configuration of the driver + */ + +/**************************************************************************** + * EVERY time you change ANYTHING in this file, RECOMPILE from scratch. * + * (type "make clean" then "make" on a UNIX system) Failure to do so may * + * cause the driver to behave oddly. * + ****************************************************************************/ + +/* NOTES: Many of the configurable options are now set in the runtime config. + * + * This file only contain a list of default settings, for quick diffing . + * See detailed explaination from 'local_options.README' + */ + +#ifndef _LOCAL_OPTIONS_H_ +#define _LOCAL_OPTIONS_H_ + +/**************************************************************************** + * COMPAT * + ****************************************************************************/ +#undef NO_ADD_ACTION +#undef NO_SNOOP +#undef NO_ENVIRONMENT +#undef NO_WIZARDS +#undef NO_LIGHT +#define OLD_ED +#undef ED_INDENT_CASE +#define ED_INDENT_SPACES 4 +#undef RECEIVE_ED +#define RESTRICTED_ED +#undef SENSIBLE_MODIFIERS + +/**************************************************************************** + * MISCELLANEOUS * + ****************************************************************************/ +#define CUSTOM_CRYPT +#undef COMPAT_32 +#define DEFAULT_PRAGMAS PRAGMA_WARNINGS + PRAGMA_SAVE_TYPES + PRAGMA_ERROR_CONTEXT + PRAGMA_OPTIMIZE +#define SAVE_EXTENSION ".o" +#undef PRIVS +#undef NO_SHADOWS +#define USE_ICONV +#undef IPV6 +#undef DTRACE + +/**************************************************************************** + * PACKAGES * + ****************************************************************************/ +#define PACKAGE_OPS +#define PACKAGE_CORE + +#define PACKAGE_CONTRIB +#define PACKAGE_DEVELOP +#define PACKAGE_MATH +#undef PACKAGE_MATRIX +#define PACKAGE_MUDLIB_STATS +#define PACKAGE_SOCKETS +#undef PACKAGE_PARSER +#define PACKAGE_EXTERNAL +#define PACKAGE_DB +#ifdef PACKAGE_DB +#define USE_MYSQL 1 +#undef USE_MSQL +#undef USE_POSTGRES +#undef USE_SQLITE3 +#define DEFAULT_DB USE_MYSQL +#endif +#define PACKAGE_ASYNC +#define PACKAGE_SHA1 +#undef PACKAGE_CRYPTO +#define PACKAGE_TRIM +#define PACKAGE_PCRE +#undef PACKAGE_DWLIB +#define PACKAGE_UIDS +#ifdef PACKAGE_UIDS +#define AUTO_SETEUID +#undef AUTO_TRUST_BACKBONE +#endif +#define PACKAGE_COMPRESS +#define SAVE_GZ_EXTENSION ".o.gz" +#undef PACKAGE_THREAD + +#endif /* _LOCAL_OPTIONS_H_ */ diff --git a/example/config.ES2 b/example/config.ES2 new file mode 100644 index 0000000..ffb2a96 --- /dev/null +++ b/example/config.ES2 @@ -0,0 +1,149 @@ +############################################################################### +# Customizable runtime config file for MudOS 0.9.20 # +############################################################################### +# NOTE: All paths specified here are relative to the mudlib directory except # +# for mudlib directory, and binary directory. # +# Lines beginning with a # or a newline are ignored. # +############################################################################### + +# name of this mud +name : 东方故事Ⅱ + +# port number to accept users on +port number : 4000 + +# the address server is an external program that lets the mud translate +# internet names to numbers (and vice versa). select an unused port. +address server ip : localhost +address server port : 3990 + +# absolute pathname of mudlib +mudlib directory : /opt/projects/es2-utf8 + +# absolute pathname of driver/config dir +binary directory : /opt/projects/docker-fluffos/bin + +# debug.log and author/domain stats are stored here +log directory : /log + +# the directories which are searched by #include <...> +# for multiple dirs, separate each path with a ':' +include directories : /include + +# Directory to save binaries in. (if BINARIES is defined) +save binaries directory : /binaries + +# the file which defines the master object +master file : /adm/obj/master + +# The global include file is included automatically. +global include file : + +# the file where all global simulated efuns are defined. +simulated efun file : /adm/obj/simul_efun + +# file to swap out objects; not used if time to swap is 0 +swap file : /adm/tmp/swapfile + +# alternate debug.log file name (assumed to be in specified 'log directory') +debug log file : debug.log + +# if an object is left alone for a certain time, then the +# function clean_up will be called. This function can do anything, +# like destructing the object. If the function isn't defined by the +# object, then nothing will happen. +# This time should be substantially longer than the swapping time. +time to clean up : 180 + +# How long time until an unused object is swapped out. +# Machine with too many players and too little memory: 900 (15 minutes) +# Machine with few players and lot of memory: 10000 +# Machine with infinite memory: 0 (never swap). +time to swap : 120 + +# How many seconds until an object is reset again. +time to reset : 1800 + +# Maximum number of bits in a bit field. They are stored in printable +# strings, 6 bits per byte. +maximum bits in a bitfield : 1200 + +# Max number of local variables in a function. +maximum local variables : 30 + +# Maximum amount of "eval cost" per thread - execution is halted when +# it is exceeded. +# Because of the heavy load on the Power PC, made it larger to pass the +# bad time. (By Annihilator) +#maximum evaluation cost : 100000 +maximum evaluation cost : 30000000 + +# This is the maximum array size allowed for one single array. +maximum array size : 15000 + +# This is the maximum allowed size of a variable of type 'buffer'. +maximum buffer size : 400000 + +# Max size for a mapping +maximum mapping size : 15000 + +# Max inherit chain size +inherit chain size : 30 + +# maximum length of a string variable +maximum string length : 200000 + +# Max size of a file allowed to be read by 'read_file()'. +maximum read file size : 200000 + +# max number of bytes you allow to be read and written with read_bytes +# and write_bytes +maximum byte transfer : 10000 + +# Reserve an extra memory area from malloc(), to free when we run out +# of memory; so begins Armageddon. +# If this value is 0, no area will be reserved. +reserved size : 0 + +# Define the size of the shared string hash table. This number should +# a prime, probably between 1000 and 30000; if you set it to about 1/5 +# of the number of distinct strings you have, you will get a hit ratio +# (number of comparisons to find a string) very close to 1, as found strings +# are automatically moved to the head of a hash chain. You will never +# need more, and you will still get good results with a smaller table. +hash table size : 7001 + +# Object hash table size. +# Define this like you did with the strings; probably set to about 1/4 of +# the number of objects in a game, as the distribution of accesses to +# objects is somewhat more uniform than that of strings. +object table size : 1501 + +# default no-matching-action message +default fail message : 什麽? + +# default message when error() occurs (optional) +default error message : 你发现事情不大对了,但是又说不上来。 + +############################################################################### +# The following aren't currently used or implemented (yet) # +############################################################################### + +# maximum number of users in the game. +maximum users : 70 + +# Define the maximum stack size of the stack machine. This stack will also +# contain all local variables and arguments. (unused currently) +evaluator stack size : 1000 + +# Define the size of the compiler stack. This defines how complex +# expressions the compiler can parse. (unused currently) +compiler stack size : 200 + +# Define the maximum call depth for functions. (unused currently) +maximum call depth : 30 + +# There is a hash table for living objects, used by find_living(). +# (unused currently) +living hash table size : 100 +