├── plugins ├── survival │ ├── persistence │ │ └── nbt │ │ │ ├── include │ │ │ ├── nbt │ │ │ ├── nbt.h │ │ │ └── itoa.h │ │ │ └── src │ │ │ ├── nbt.c │ │ │ └── itoa.c │ ├── mapgen │ │ ├── noise │ │ │ ├── sdnoise1234.c │ │ │ ├── simplexnoise1234.c │ │ │ ├── Makefile.am │ │ │ ├── simplexnoise1234.h │ │ │ ├── noise1234.h │ │ │ ├── srdnoise23.h │ │ │ ├── cellular.h │ │ │ └── sdnoise1234.h │ │ ├── trivial │ │ │ └── main.c │ │ └── classic │ │ │ └── main.c │ └── commands │ │ └── admin │ │ └── src │ │ └── workers.c ├── httpd │ ├── htdocs │ │ ├── images │ │ │ ├── save.png │ │ │ ├── start.png │ │ │ ├── stop.png │ │ │ ├── db_wiki.png │ │ │ ├── icon_16.png │ │ │ ├── icon_64.png │ │ │ ├── logo_64.png │ │ │ ├── restart.png │ │ │ ├── arrow_left.png │ │ │ ├── bg_content.jpg │ │ │ ├── db_console.png │ │ │ ├── db_default.png │ │ │ ├── db_plugin.png │ │ │ ├── db_stats.png │ │ │ ├── save_off.png │ │ │ ├── start_off.png │ │ │ ├── stop_off.png │ │ │ ├── arrow_right.png │ │ │ ├── icon_64_off.png │ │ │ ├── nav_selected.png │ │ │ └── restart_off.png │ │ ├── css │ │ │ ├── ui-lightness │ │ │ │ └── images │ │ │ │ │ ├── ui-icons_222222_256x240.png │ │ │ │ │ ├── ui-icons_228ef1_256x240.png │ │ │ │ │ ├── ui-icons_ef8c08_256x240.png │ │ │ │ │ ├── ui-icons_ffd27a_256x240.png │ │ │ │ │ ├── ui-icons_ffffff_256x240.png │ │ │ │ │ ├── ui-bg_flat_10_000000_40x100.png │ │ │ │ │ ├── ui-bg_glass_100_f6f6f6_1x400.png │ │ │ │ │ ├── ui-bg_glass_100_fdf5ce_1x400.png │ │ │ │ │ ├── ui-bg_glass_65_ffffff_1x400.png │ │ │ │ │ ├── ui-bg_gloss-wave_35_f6a828_500x100.png │ │ │ │ │ ├── ui-bg_diagonals-thick_18_b81900_40x40.png │ │ │ │ │ ├── ui-bg_diagonals-thick_20_666666_40x40.png │ │ │ │ │ ├── ui-bg_highlight-soft_100_eeeeee_1x100.png │ │ │ │ │ └── ui-bg_highlight-soft_75_ffe45c_1x100.png │ │ │ ├── html5reset-1.6.1.css │ │ │ └── jquery.jqplot.min.css │ │ └── LICENSES.txt │ ├── main.c │ └── include │ │ └── HTTPd.h └── Makefile.am ├── include ├── craftd │ ├── klib │ │ ├── khmm.h │ │ ├── kmin.h │ │ ├── knhx.h │ │ ├── kseq.h │ │ ├── kvec.h │ │ ├── kbtree.h │ │ ├── khash.h │ │ ├── klist.h │ │ ├── ksort.h │ │ ├── knetfile.h │ │ └── kstring.h │ ├── bstring │ │ ├── bsafe.h │ │ ├── bstraux.h │ │ ├── bstrlib.h │ │ └── bstrwrap.h │ ├── protocols.h │ ├── extras.h │ ├── version.h │ ├── protocols │ │ ├── survival │ │ │ ├── common.h │ │ │ ├── Logger.h │ │ │ ├── Region.h │ │ │ └── Player.h │ │ └── survival.h │ ├── Error.h │ ├── lock.h │ ├── Dynamic.h │ ├── utils.h │ ├── Protocol.h │ ├── Buffers.h │ ├── Console.h │ ├── Worker.h │ ├── Plugins.h │ ├── Client.h │ ├── Plugin.h │ ├── Workers.h │ ├── Buffer.h │ ├── ScriptingEngines.h │ ├── ScriptingEngine.h │ ├── Job.h │ ├── Regexp.h │ ├── Arithmetic.h │ ├── common.h │ └── Logger.h └── Makefile.am ├── autogen.sh ├── motd.conf.dist ├── scripting ├── javascript │ ├── scripts │ │ └── joined.js │ ├── lib │ │ └── dispatcher.js │ ├── include │ │ ├── common.h │ │ ├── Dynamic.h │ │ ├── Global.h │ │ └── Client.h │ ├── src │ │ ├── Dynamic.c │ │ ├── Client.c │ │ └── Global.c │ └── main.c └── lisp │ ├── lib │ ├── client.lisp │ ├── wrap.lisp │ ├── player.lisp │ ├── craftd.asd │ ├── server.lisp │ ├── minecraft.lisp │ ├── dynamic.lisp │ ├── string.lisp │ └── dispatcher.lisp │ └── scripts │ └── joined.asd ├── extras ├── cppcheck.sh ├── valgrind.sh ├── minecraftdos.rb └── build.sh ├── AUTHORS ├── .gitmodules ├── third-party ├── Makefile.am └── bstring │ ├── bsafe.h │ ├── license.txt │ └── bsafe.c ├── Makefile.am ├── src ├── Makefile.am ├── Dynamic.c ├── Error.c ├── Logger.c ├── SystemLogger.c ├── Protocol.c ├── extras.c ├── Console.c ├── protocols │ └── survival │ │ ├── main.c │ │ └── Region.c ├── Buffers.c ├── Client.c ├── Job.c ├── ConsoleLogger.c ├── Plugins.c └── ScriptingEngines.c ├── INSTALL ├── COPYING ├── .gitignore ├── README ├── configure.ac └── craftd.conf.dist.in /plugins/survival/persistence/nbt/include/nbt: -------------------------------------------------------------------------------- 1 | . -------------------------------------------------------------------------------- /include/craftd/klib/khmm.h: -------------------------------------------------------------------------------- 1 | ../../../third-party/klib/khmm.h -------------------------------------------------------------------------------- /include/craftd/klib/kmin.h: -------------------------------------------------------------------------------- 1 | ../../../third-party/klib/kmin.h -------------------------------------------------------------------------------- /include/craftd/klib/knhx.h: -------------------------------------------------------------------------------- 1 | ../../../third-party/klib/knhx.h -------------------------------------------------------------------------------- /include/craftd/klib/kseq.h: -------------------------------------------------------------------------------- 1 | ../../../third-party/klib/kseq.h -------------------------------------------------------------------------------- /include/craftd/klib/kvec.h: -------------------------------------------------------------------------------- 1 | ../../../third-party/klib/kvec.h -------------------------------------------------------------------------------- /include/craftd/klib/kbtree.h: -------------------------------------------------------------------------------- 1 | ../../../third-party/klib/kbtree.h -------------------------------------------------------------------------------- /include/craftd/klib/khash.h: -------------------------------------------------------------------------------- 1 | ../../../third-party/klib/khash.h -------------------------------------------------------------------------------- /include/craftd/klib/klist.h: -------------------------------------------------------------------------------- 1 | ../../../third-party/klib/klist.h -------------------------------------------------------------------------------- /include/craftd/klib/ksort.h: -------------------------------------------------------------------------------- 1 | ../../../third-party/klib/ksort.h -------------------------------------------------------------------------------- /include/craftd/bstring/bsafe.h: -------------------------------------------------------------------------------- 1 | ../../../third-party/bstring/bsafe.h -------------------------------------------------------------------------------- /include/craftd/klib/knetfile.h: -------------------------------------------------------------------------------- 1 | ../../../third-party/klib/knetfile.h -------------------------------------------------------------------------------- /include/craftd/klib/kstring.h: -------------------------------------------------------------------------------- 1 | ../../../third-party/klib/kstring.h -------------------------------------------------------------------------------- /include/craftd/bstring/bstraux.h: -------------------------------------------------------------------------------- 1 | ../../../third-party/bstring/bstraux.h -------------------------------------------------------------------------------- /include/craftd/bstring/bstrlib.h: -------------------------------------------------------------------------------- 1 | ../../../third-party/bstring/bstrlib.h -------------------------------------------------------------------------------- /include/craftd/bstring/bstrwrap.h: -------------------------------------------------------------------------------- 1 | ../../../third-party/bstring/bstrwrap.h -------------------------------------------------------------------------------- /autogen.sh: -------------------------------------------------------------------------------- 1 | git submodule init 2 | git submodule update 3 | autoreconf -iv 4 | -------------------------------------------------------------------------------- /motd.conf.dist: -------------------------------------------------------------------------------- 1 | Welcome to craftd! This is a test server. 2 | Check us out at http://mc.kev009.com/craftd/ 3 | -------------------------------------------------------------------------------- /plugins/httpd/htdocs/images/save.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kev009/craftd/HEAD/plugins/httpd/htdocs/images/save.png -------------------------------------------------------------------------------- /plugins/httpd/htdocs/images/start.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kev009/craftd/HEAD/plugins/httpd/htdocs/images/start.png -------------------------------------------------------------------------------- /plugins/httpd/htdocs/images/stop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kev009/craftd/HEAD/plugins/httpd/htdocs/images/stop.png -------------------------------------------------------------------------------- /plugins/httpd/htdocs/images/db_wiki.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kev009/craftd/HEAD/plugins/httpd/htdocs/images/db_wiki.png -------------------------------------------------------------------------------- /plugins/httpd/htdocs/images/icon_16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kev009/craftd/HEAD/plugins/httpd/htdocs/images/icon_16.png -------------------------------------------------------------------------------- /plugins/httpd/htdocs/images/icon_64.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kev009/craftd/HEAD/plugins/httpd/htdocs/images/icon_64.png -------------------------------------------------------------------------------- /plugins/httpd/htdocs/images/logo_64.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kev009/craftd/HEAD/plugins/httpd/htdocs/images/logo_64.png -------------------------------------------------------------------------------- /plugins/httpd/htdocs/images/restart.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kev009/craftd/HEAD/plugins/httpd/htdocs/images/restart.png -------------------------------------------------------------------------------- /scripting/javascript/scripts/joined.js: -------------------------------------------------------------------------------- 1 | Craftd.register("Client.connect", function (client) { 2 | print(client.ip); 3 | }); 4 | -------------------------------------------------------------------------------- /plugins/httpd/htdocs/images/arrow_left.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kev009/craftd/HEAD/plugins/httpd/htdocs/images/arrow_left.png -------------------------------------------------------------------------------- /plugins/httpd/htdocs/images/bg_content.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kev009/craftd/HEAD/plugins/httpd/htdocs/images/bg_content.jpg -------------------------------------------------------------------------------- /plugins/httpd/htdocs/images/db_console.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kev009/craftd/HEAD/plugins/httpd/htdocs/images/db_console.png -------------------------------------------------------------------------------- /plugins/httpd/htdocs/images/db_default.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kev009/craftd/HEAD/plugins/httpd/htdocs/images/db_default.png -------------------------------------------------------------------------------- /plugins/httpd/htdocs/images/db_plugin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kev009/craftd/HEAD/plugins/httpd/htdocs/images/db_plugin.png -------------------------------------------------------------------------------- /plugins/httpd/htdocs/images/db_stats.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kev009/craftd/HEAD/plugins/httpd/htdocs/images/db_stats.png -------------------------------------------------------------------------------- /plugins/httpd/htdocs/images/save_off.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kev009/craftd/HEAD/plugins/httpd/htdocs/images/save_off.png -------------------------------------------------------------------------------- /plugins/httpd/htdocs/images/start_off.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kev009/craftd/HEAD/plugins/httpd/htdocs/images/start_off.png -------------------------------------------------------------------------------- /plugins/httpd/htdocs/images/stop_off.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kev009/craftd/HEAD/plugins/httpd/htdocs/images/stop_off.png -------------------------------------------------------------------------------- /plugins/httpd/htdocs/images/arrow_right.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kev009/craftd/HEAD/plugins/httpd/htdocs/images/arrow_right.png -------------------------------------------------------------------------------- /plugins/httpd/htdocs/images/icon_64_off.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kev009/craftd/HEAD/plugins/httpd/htdocs/images/icon_64_off.png -------------------------------------------------------------------------------- /plugins/httpd/htdocs/images/nav_selected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kev009/craftd/HEAD/plugins/httpd/htdocs/images/nav_selected.png -------------------------------------------------------------------------------- /plugins/httpd/htdocs/images/restart_off.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kev009/craftd/HEAD/plugins/httpd/htdocs/images/restart_off.png -------------------------------------------------------------------------------- /plugins/survival/mapgen/noise/sdnoise1234.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kev009/craftd/HEAD/plugins/survival/mapgen/noise/sdnoise1234.c -------------------------------------------------------------------------------- /plugins/survival/mapgen/noise/simplexnoise1234.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kev009/craftd/HEAD/plugins/survival/mapgen/noise/simplexnoise1234.c -------------------------------------------------------------------------------- /plugins/httpd/htdocs/css/ui-lightness/images/ui-icons_222222_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kev009/craftd/HEAD/plugins/httpd/htdocs/css/ui-lightness/images/ui-icons_222222_256x240.png -------------------------------------------------------------------------------- /plugins/httpd/htdocs/css/ui-lightness/images/ui-icons_228ef1_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kev009/craftd/HEAD/plugins/httpd/htdocs/css/ui-lightness/images/ui-icons_228ef1_256x240.png -------------------------------------------------------------------------------- /plugins/httpd/htdocs/css/ui-lightness/images/ui-icons_ef8c08_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kev009/craftd/HEAD/plugins/httpd/htdocs/css/ui-lightness/images/ui-icons_ef8c08_256x240.png -------------------------------------------------------------------------------- /plugins/httpd/htdocs/css/ui-lightness/images/ui-icons_ffd27a_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kev009/craftd/HEAD/plugins/httpd/htdocs/css/ui-lightness/images/ui-icons_ffd27a_256x240.png -------------------------------------------------------------------------------- /plugins/httpd/htdocs/css/ui-lightness/images/ui-icons_ffffff_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kev009/craftd/HEAD/plugins/httpd/htdocs/css/ui-lightness/images/ui-icons_ffffff_256x240.png -------------------------------------------------------------------------------- /extras/cppcheck.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ -d "src" ]; then 4 | cppcheck -I include -v --force --enable=all src/ plugins/ 5 | else 6 | echo -e "\nRun from the project's repo root" 7 | fi 8 | -------------------------------------------------------------------------------- /plugins/httpd/htdocs/css/ui-lightness/images/ui-bg_flat_10_000000_40x100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kev009/craftd/HEAD/plugins/httpd/htdocs/css/ui-lightness/images/ui-bg_flat_10_000000_40x100.png -------------------------------------------------------------------------------- /plugins/httpd/htdocs/css/ui-lightness/images/ui-bg_glass_100_f6f6f6_1x400.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kev009/craftd/HEAD/plugins/httpd/htdocs/css/ui-lightness/images/ui-bg_glass_100_f6f6f6_1x400.png -------------------------------------------------------------------------------- /plugins/httpd/htdocs/css/ui-lightness/images/ui-bg_glass_100_fdf5ce_1x400.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kev009/craftd/HEAD/plugins/httpd/htdocs/css/ui-lightness/images/ui-bg_glass_100_fdf5ce_1x400.png -------------------------------------------------------------------------------- /plugins/httpd/htdocs/css/ui-lightness/images/ui-bg_glass_65_ffffff_1x400.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kev009/craftd/HEAD/plugins/httpd/htdocs/css/ui-lightness/images/ui-bg_glass_65_ffffff_1x400.png -------------------------------------------------------------------------------- /plugins/httpd/htdocs/css/ui-lightness/images/ui-bg_gloss-wave_35_f6a828_500x100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kev009/craftd/HEAD/plugins/httpd/htdocs/css/ui-lightness/images/ui-bg_gloss-wave_35_f6a828_500x100.png -------------------------------------------------------------------------------- /plugins/httpd/htdocs/css/ui-lightness/images/ui-bg_diagonals-thick_18_b81900_40x40.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kev009/craftd/HEAD/plugins/httpd/htdocs/css/ui-lightness/images/ui-bg_diagonals-thick_18_b81900_40x40.png -------------------------------------------------------------------------------- /plugins/httpd/htdocs/css/ui-lightness/images/ui-bg_diagonals-thick_20_666666_40x40.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kev009/craftd/HEAD/plugins/httpd/htdocs/css/ui-lightness/images/ui-bg_diagonals-thick_20_666666_40x40.png -------------------------------------------------------------------------------- /plugins/httpd/htdocs/css/ui-lightness/images/ui-bg_highlight-soft_100_eeeeee_1x100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kev009/craftd/HEAD/plugins/httpd/htdocs/css/ui-lightness/images/ui-bg_highlight-soft_100_eeeeee_1x100.png -------------------------------------------------------------------------------- /plugins/httpd/htdocs/css/ui-lightness/images/ui-bg_highlight-soft_75_ffe45c_1x100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kev009/craftd/HEAD/plugins/httpd/htdocs/css/ui-lightness/images/ui-bg_highlight-soft_75_ffe45c_1x100.png -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Core Maintainers: 2 | * Kevin Bowling 3 | * Elias Woods 4 | * meh. 5 | 6 | Core Contributors: 7 | * Tomy 8 | * Youx 9 | * ayan4m1 10 | 11 | Core Plugins Contributors: 12 | 13 | Web and WebAdmin: 14 | * Coestar 15 | 16 | -------------------------------------------------------------------------------- /scripting/lisp/lib/client.lisp: -------------------------------------------------------------------------------- 1 | (in-package craftd) 2 | 3 | (export '(client-ip)) 4 | 5 | (uffi:def-struct client 6 | (server (* :void)) 7 | (ip (:array :char 128)) 8 | (socket :int) 9 | (buffers (* :void)) 10 | (status :int) 11 | (jobs :char)) 12 | 13 | (defun client-ip (client) 14 | (uffi:convert-from-foreign-string (get-wrapped-value client 'ip))) 15 | -------------------------------------------------------------------------------- /scripting/lisp/scripts/joined.asd: -------------------------------------------------------------------------------- 1 | (defsystem :joined 2 | :version "0.1") 3 | 4 | (craftd:register :Player.login #'(lambda (player status) 5 | (format t "~s (~s) joined the game~%" (craftd:player-username player) '(craftd:player-ip player)))) 6 | 7 | (craftd:register :Player.logout #'(lambda (player status) 8 | (format t "~s (~s) left the game~%" (craftd:player-username player) '(craftd:player-ip player)))) 9 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "third-party/klib"] 2 | path = third-party/klib 3 | url = git://github.com/attractivechaos/klib.git 4 | [submodule "plugins/survival/tests/tinytest"] 5 | path = plugins/survival/tests/tinytest 6 | url = git://github.com/nmathewson/tinytest.git 7 | [submodule "plugins/survival/persistence/nbt/cNBT"] 8 | path = plugins/survival/persistence/nbt/cNBT 9 | url = git://github.com/FliPPeh/cNBT.git 10 | -------------------------------------------------------------------------------- /third-party/Makefile.am: -------------------------------------------------------------------------------- 1 | noinst_LTLIBRARIES = libbstring.la 2 | 3 | libbstring_la_SOURCES = bstring/bstraux.c \ 4 | bstring/bstrlib.c \ 5 | bstring/bstraux.h \ 6 | bstring/bstrlib.h 7 | 8 | # bstring extas 9 | bstrdir = bstring 10 | EXTRA_DIST = $(bstrdir)/license.txt $(bstrdir)/security.txt \ 11 | $(bstrdir)/bstrlib.txt $(bstrdir)/porting.txt 12 | 13 | # klib extras 14 | klibdir = klib 15 | EXTRA_DIST += $(klibdir) 16 | 17 | -------------------------------------------------------------------------------- /plugins/survival/mapgen/noise/Makefile.am: -------------------------------------------------------------------------------- 1 | # Various noise generators 2 | noinst_LTLIBRARIES = libnoise_cell.la libnoise_std.la libnoise_sd.la libnoise_simplex.la libnoise_srd.la 3 | libnoise_cell_la_SOURCES = cellular.c cellular.h 4 | libnoise_std_la_SOURCES = noise1234.c noise1234.h 5 | libnoise_sd_la_SOURCES = sdnoise1234.c sdnoise1234.h 6 | libnoise_simplex_la_SOURCES = simplexnoise1234.c simplexnoise1234.h 7 | libnoise_srd_la_SOURCES = srdnoise23.c srdnoise23.h 8 | -------------------------------------------------------------------------------- /scripting/lisp/lib/wrap.lisp: -------------------------------------------------------------------------------- 1 | (in-package craftd) 2 | 3 | (export '(wrap get-wrapped-value get-wrapped-pointer)) 4 | 5 | (defun wrap (object struct) 6 | (if (equal (type-of object) 'cons) 7 | object 8 | (list object struct))) 9 | 10 | (defun get-wrapped-object (object) 11 | (first object)) 12 | 13 | (defun get-wrapped-value (object attribute) 14 | (uffi:get-slot-value (first object) (second object) attribute)) 15 | 16 | (defun get-wrapped-pointer (object attribute) 17 | (uffi:get-slot-pointer (first object) (second object) attribute)) 18 | -------------------------------------------------------------------------------- /scripting/lisp/lib/player.lisp: -------------------------------------------------------------------------------- 1 | (in-package craftd) 2 | 3 | (export '(player-ip player-username)) 4 | 5 | (uffi:def-struct player 6 | (entity entity) 7 | 8 | (client (* :void)) 9 | (world (* :void)) 10 | 11 | (yaw :float) 12 | (pitch :float) 13 | 14 | (username (* :void)) 15 | 16 | (dynamic (* :void)) 17 | (error error-type)) 18 | 19 | (defun player-ip (player) 20 | (client-ip (wrap (get-wrapped-value player 'client) 'client))) 21 | 22 | (defun player-username (player) 23 | (string-content (get-wrapped-value player 'username))) 24 | -------------------------------------------------------------------------------- /scripting/lisp/lib/craftd.asd: -------------------------------------------------------------------------------- 1 | (defpackage #:craftd 2 | (:use #:cl #:asdf)) 3 | 4 | (in-package craftd) 5 | 6 | (unless (find :unicode *features*) 7 | (error "Please build ECL with unicode support (configure --enable-unicode)")) 8 | 9 | (unless (find :threads *features*) 10 | (error "Please build ECL with thread support (configure --enable-threads)")) 11 | 12 | (defsystem :craftd 13 | :version "0.1" 14 | 15 | :serial t 16 | 17 | :components ( 18 | (:file "string") 19 | (:file "minecraft") 20 | (:file "wrap") 21 | (:file "dispatcher") 22 | (:file "server") 23 | (:file "client") 24 | (:file "player"))) 25 | -------------------------------------------------------------------------------- /extras/valgrind.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ "src" ]; then 4 | case "$1" in 5 | thread) 6 | valgrind --log-file="valgrind-`date +%s`.log" --tool=drd --exclusive-threshold=100 ./craftd -c craftd.conf.dist 7 | ;; 8 | 9 | call) 10 | valgrind --log-file="valgrind-`date +%s`.log" --tool=callgrind ./craftd -c craftd.conf.dist 11 | echo -e "\nUse a tool like kcachegrind for visualization of the .out file" 12 | ;; 13 | 14 | *) 15 | valgrind --log-file="valgrind-`date +%s`.log" -v --show-reachable=yes --leak-check=full --track-origins=yes ./craftd -c craftd.conf.dist 16 | ;; 17 | esac 18 | else 19 | echo -e "\nRun from the project's repo root" 20 | fi 21 | -------------------------------------------------------------------------------- /scripting/lisp/lib/server.lisp: -------------------------------------------------------------------------------- 1 | (in-package :craftd) 2 | 3 | (export '(server-name kick)) 4 | 5 | (uffi:def-struct timeloop) 6 | (uffi:def-struct config) 7 | (uffi:def-struct plugins) 8 | (uffi:def-struct logger) 9 | 10 | (uffi:def-struct server 11 | (timeloop (* :void)) 12 | (config (* :void))) 13 | 14 | (uffi:def-function ("CD_ServerToString" c-server-name) ((self (* :void))) 15 | :returning :cstring) 16 | 17 | (uffi:def-function ("CD_ServerKick" c-server-kick) ((self (* :void)) (client (* :void)) (reason (* :void)))) 18 | 19 | (defun server-name () 20 | (uffi:convert-from-cstring (c-server-name *server*))) 21 | 22 | (defun kick (client reason) 23 | (let ((reason (create-string reason))) 24 | (c-server-kick *server* client reason) 25 | (destroy-string reason))) 26 | -------------------------------------------------------------------------------- /scripting/lisp/lib/minecraft.lisp: -------------------------------------------------------------------------------- 1 | (in-package craftd) 2 | 3 | (uffi:def-struct chunk-position 4 | (x :int) 5 | (z :int)) 6 | 7 | (uffi:def-struct block-position 8 | (x :int) 9 | (y :int) 10 | (z :int)) 11 | 12 | (uffi:def-struct absolute-position 13 | (x :int) 14 | (y :int) 15 | (z :int)) 16 | 17 | (uffi:def-struct precise-position 18 | (x :double) 19 | (y :double) 20 | (z :double)) 21 | 22 | (uffi:def-struct relative-position 23 | (x :char) 24 | (y :char) 25 | (z :char)) 26 | 27 | (uffi:def-foreign-type entity-id :int) 28 | 29 | (uffi:def-enum entity-type (:player :pickup :mob :object)) 30 | 31 | (uffi:def-struct entity 32 | (id entity-id) 33 | (type entity-type) 34 | (position precise-position)) 35 | 36 | (uffi:def-foreign-type error-type :int) 37 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | ACLOCAL_AMFLAGS = -I build/auto/m4 2 | 3 | SUBDIRS = include third-party src plugins 4 | 5 | EXTRA_DIST = craftd.conf.dist.in motd.conf.dist 6 | 7 | # Make a correct default config file 8 | edit = sed \ 9 | -e 's|@localstatedir[@]|$(localstatedir)|g' \ 10 | -e 's|@datadir[@]|$(datadir)|g' \ 11 | -e 's|@sysconfdir[@]|$(sysconfdir)|g' \ 12 | -e 's|@libdir[@]|$(libdir)|g' 13 | craftd.conf.dist: Makefile 14 | rm -f $@ $@.tmp 15 | srcdir='' \ 16 | test -f ./$@.in || srcdir=$(srcdir)/; \ 17 | $(edit) $${srcdir}$@.in >$@.tmp 18 | mv $@.tmp $@ 19 | 20 | craftd.conf.dist: $(srcdir)/craftd.conf.dist.in 21 | 22 | DISTCLEANFILES = craftd.conf.dist 23 | 24 | craftdconfdir = ${sysconfdir}/craftd/ 25 | craftdconf_DATA = craftd.conf.dist motd.conf.dist 26 | 27 | install-data-local: 28 | $(MKDIR_P) $(DESTDIR)$(localstatedir)/craftd/world 29 | 30 | include $(top_srcdir)/build/auto/build.mk 31 | -------------------------------------------------------------------------------- /scripting/lisp/lib/dynamic.lisp: -------------------------------------------------------------------------------- 1 | (in-package :craftd) 2 | 3 | (export '(dynamic-get dynamic-put dynamic-delete)) 4 | 5 | (uffi:def-function ("CD_HashGet" c-hash-get) ((self (* :void)) (name :cstring)) 6 | :returning (* :void)) 7 | 8 | (uffi:def-function ("CD_HashPut" c-hash-put) ((self (* :void)) (name :cstring) (value (* :void))) 9 | :returning (* :void)) 10 | 11 | (uffi:def-function ("CD_HashDelete" c-hash-delete) ((self (* :void)) (name :cstring)) 12 | :returning (+ :void)) 13 | 14 | (defun dynamic-get (object name) 15 | (uffi:with-cstring (c-name name) 16 | (c-hash-get (get-wrapped-value object 'dynamic) name))) 17 | 18 | (defun dynamic-set (object name value) 19 | (uffi:with-cstring (c-name name) 20 | (c-hash-set (get-wrapped-value object 'dynamic) name value))) 21 | 22 | (defun dynamic-delete (object name) 23 | (uffi:with-cstring (c-name name) 24 | (c-hash-delete (get-wrapped-value object 'dynamic) name))) 25 | -------------------------------------------------------------------------------- /scripting/javascript/lib/dispatcher.js: -------------------------------------------------------------------------------- 1 | Craftd.events = {}; 2 | 3 | Craftd.register = function (name) { 4 | if (Craftd.events[name] && Craftd.events[name].constructor != Array) { 5 | Craftd.events[name] = []; 6 | } 7 | 8 | for (let i = 1; i < arguments.length; i++) { 9 | Craftd.events[name].push(arguments[i]); 10 | } 11 | } 12 | 13 | Craftd.unregister = function (name) { 14 | if (Craftd.events[name] && Craftd.events[name].constructor != Array) { 15 | return; 16 | } 17 | 18 | var callbacks = []; 19 | 20 | for (let i = 1; i < arguments.length; i++) { 21 | callbacks.push(arguments[i]); 22 | } 23 | 24 | if (callbacks.length == 0) { 25 | Craftd.events[name] = []; 26 | } 27 | else { 28 | Craftd.events[name] = Craftd.events[name].filter(function (callback) { 29 | for (let i = 0; i < callbacks.length; i++) { 30 | if (callback == callbacks[i]) { 31 | return false; 32 | } 33 | } 34 | 35 | return true; 36 | }); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /scripting/lisp/lib/string.lisp: -------------------------------------------------------------------------------- 1 | (in-package :craftd) 2 | 3 | (export '(create-string destroy-string string-content)) 4 | 5 | (uffi:def-function ("CD_CreateStringFromCStringCopy" c-create-string) ((data :cstring)) 6 | :returning (* :void)) 7 | 8 | (uffi:def-function ("CD_DestroyString" c-destroy-string) ((self (* :void)))) 9 | 10 | (uffi:def-function ("CD_StringContent" c-string-content) ((self (* :void))) 11 | :returning :cstring) 12 | 13 | (uffi:def-function ("CD_StringLength" c-string-length) ((self (* :void))) 14 | :returning :int) 15 | 16 | (uffi:def-function ("CD_StringSize" c-string-size) ((self (* :void))) 17 | :returning :int) 18 | 19 | (defun create-string (data) 20 | (c-create-string data)) 21 | 22 | (defun destroy-string (self) 23 | (c-destroy-string self)) 24 | 25 | (defun string-content (self) 26 | (uffi:convert-from-cstring (c-string-content self))) 27 | 28 | (defun string-length (self) 29 | (c-string-length self)) 30 | 31 | (defun string-size (self) 32 | (c-string-size self)) 33 | -------------------------------------------------------------------------------- /extras/minecraftdos.rb: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env ruby 2 | require 'socket' 3 | require 'thread' 4 | 5 | HOST, PORT = ARGV.shift.split(':') + [25565] 6 | COUNT = ARGV.shift || 2000 7 | 8 | sockets = Class.new(Array) { 9 | def initialize (number) 10 | @number = number 11 | end 12 | 13 | def spawn 14 | self.each {|s| 15 | self.delete(s) if s.closed? 16 | } 17 | 18 | to_spawn = @number - self.length 19 | 20 | if to_spawn > 0 21 | puts "Spawning #{to_spawn} fake connections" 22 | 23 | 1.upto(to_spawn) { 24 | socket = TCPSocket.new(HOST, PORT) 25 | socket.write_nonblock("\x02\xff\xff") 26 | 27 | self << socket 28 | } 29 | end 30 | end 31 | }.new(COUNT) 32 | 33 | thread = Thread.new { 34 | loop do 35 | sockets.each {|socket| 36 | begin 37 | socket.write_nonblock((rand * 255).floor.chr) 38 | rescue Exception => e 39 | socket.close rescue nil 40 | end 41 | } 42 | 43 | begin; sockets.spawn; rescue; break; end 44 | 45 | sleep 0.5 46 | end 47 | } 48 | 49 | thread.join 50 | -------------------------------------------------------------------------------- /scripting/lisp/lib/dispatcher.lisp: -------------------------------------------------------------------------------- 1 | (in-package craftd) 2 | 3 | (export '(register unregister fire)) 4 | 5 | (defparameter *event-callbacks* (make-hash-table)) 6 | 7 | (defun get-callbacks (name) 8 | (gethash name *event-callbacks*)) 9 | 10 | (defun set-callbacks (name callbacks) 11 | (setf (gethash name *event-callbacks*) callbacks)) 12 | 13 | (defun sort-callbacks (a b) 14 | (cond 15 | ((= (second a) (second b)) 0) 16 | ((< (second a) (second b)) 1) 17 | (t -1))) 18 | 19 | (defun register (name callback &optional priority) 20 | (let ((callbacks (get-callbacks name))) 21 | (set-callbacks name (sort (append (list (list callback (or priority 0))) callbacks) #'sort-callbacks)))) 22 | 23 | (defun unregister (name &optional callback) 24 | (let ((callbacks (get-callbacks name))) 25 | (set-callbacks name (if callback 26 | (remove-if #'(lambda (element) (equal (first element) callback)) callbacks) 27 | nil)))) 28 | 29 | (defun fire (name &rest rest) 30 | (dolist (callback (get-callbacks name)) 31 | (apply (first callback) rest))) 32 | -------------------------------------------------------------------------------- /src/Makefile.am: -------------------------------------------------------------------------------- 1 | bin_PROGRAMS = craftd 2 | 3 | # Add in lexicographic order: 4 | # 5 | # craftd_SOURCES += 6 | # ls *.c | awk '{ print $1" \\" }' | sort 7 | # truncate last \ 8 | # 9 | craftd_SOURCES = Buffer.c \ 10 | Buffers.c \ 11 | Client.c \ 12 | Config.c \ 13 | Console.c \ 14 | ConsoleLogger.c \ 15 | craftd.c \ 16 | Dynamic.c \ 17 | Error.c \ 18 | Event.c \ 19 | extras.c \ 20 | Hash.c \ 21 | Job.c \ 22 | List.c \ 23 | Logger.c \ 24 | Map.c \ 25 | Plugin.c \ 26 | Plugins.c \ 27 | Protocol.c \ 28 | Regexp.c \ 29 | ScriptingEngine.c \ 30 | ScriptingEngines.c \ 31 | Server.c \ 32 | Set.c \ 33 | String.c \ 34 | SystemLogger.c \ 35 | TimeLoop.c \ 36 | utils.c \ 37 | Worker.c \ 38 | Workers.c 39 | 40 | # Modular protocol dependant srcs 41 | craftd_SOURCES += protocols/survival/Buffer.c \ 42 | protocols/survival/minecraft.c \ 43 | protocols/survival/Packet.c \ 44 | protocols/survival/PacketLength.c \ 45 | protocols/survival/Player.c \ 46 | protocols/survival/Region.c \ 47 | protocols/survival/World.c \ 48 | protocols/survival/main.c 49 | 50 | craftd_LDFLAGS = -export-dynamic 51 | craftd_LDADD = $(AM_LIBS) $(top_builddir)/third-party/libbstring.la 52 | 53 | include $(top_srcdir)/build/auto/build.mk 54 | -------------------------------------------------------------------------------- /INSTALL: -------------------------------------------------------------------------------- 1 | Installation Instructions 2 | 3 | == Linux 4 | 5 | You will need zlib and autotools installed to compile craftd. 6 | 7 | First, download the latest libevent from http://monkey.org/~provos/libevent/. 8 | Extract the archive and run the following commands inside the resulting folder: 9 | 10 | ./configure 11 | make 12 | make install 13 | ldconfig 14 | 15 | Note that users of sudo will probably need to wrap the last two commands with 16 | sudo. 17 | 18 | Second, do a similar routine with jansson, found at http://www.digip.org/jansson/. 19 | You can omit the ldconfig part. 20 | 21 | Next, change to your craftd directory. If you obtained the code from our git repo 22 | and you have not done so, run autoreconf -i. This will create a configure script 23 | for you. 24 | 25 | Run the following commands to install the server: 26 | 27 | ./configure 28 | make 29 | make install 30 | 31 | Now you can configure your server. Copy the file /usr/local/etc/craftd/craftd.conf.dist 32 | to /usr/local/etc/craftd/craftd.conf and edit the resulting file. For more information on 33 | configuring the server, see http://mc.kev009.com/Craftd:Configuration 34 | 35 | Please note that unlike the official server, craftd will not generate a world if one is not 36 | provided. You will need to put valid world data in the world directory specified in the 37 | server configuration file until the mapgen is integrated. 38 | -------------------------------------------------------------------------------- /plugins/survival/mapgen/noise/simplexnoise1234.h: -------------------------------------------------------------------------------- 1 | /* SimplexNoise1234, Simplex noise with true analytic 2 | * derivative in 1D to 4D. 3 | * 4 | * Author: Stefan Gustavson, 2003-2005 5 | * Contact: stegu@itn.liu.se 6 | * 7 | * This code was GPL licensed until February 2011. 8 | * As the original author of this code, I hereby 9 | * release it into the public domain. 10 | * Please feel free to use it for whatever you want. 11 | * Credit is appreciated where appropriate, and I also 12 | * appreciate being told where this code finds any use, 13 | * but you may do as you like. 14 | */ 15 | 16 | /** \file 17 | \brief Header for "simplexnoise1234.c" for producing Perlin simplex noise. 18 | \author Stefan Gustavson (stegu@itn.liu.se) 19 | */ 20 | 21 | /* 22 | * This is a clean, fast, modern and free Perlin Simplex noise function. 23 | * It is a stand-alone compilation unit with no external dependencies, 24 | * highly reusable without source code modifications. 25 | * 26 | * 27 | * Note: 28 | * Replacing the "float" type with "double" can actually make this run faster 29 | * on some platforms. Having both versions could be useful. 30 | */ 31 | 32 | /** 1D, 2D, 3D and 4D float Perlin simplex noise 33 | */ 34 | float snoise1( float x ); 35 | float snoise2( float x, float y ); 36 | float snoise3( float x, float y, float z ); 37 | float snoise4( float x, float y, float z, float w ); 38 | -------------------------------------------------------------------------------- /src/Dynamic.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2011 Kevin M. Bowling, , USA 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | -------------------------------------------------------------------------------- /third-party/bstring/bsafe.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This source file is part of the bstring string library. This code was 3 | * written by Paul Hsieh in 2002-2010, and is covered by either the 3-clause 4 | * BSD open source license or GPL v2.0. Refer to the accompanying documentation 5 | * for details on usage and license. 6 | */ 7 | 8 | /* 9 | * bsafe.h 10 | * 11 | * This is an optional module that can be used to help enforce a safety 12 | * standard based on pervasive usage of bstrlib. This file is not necessarily 13 | * portable, however, it has been tested to work correctly with Intel's C/C++ 14 | * compiler, WATCOM C/C++ v11.x and Microsoft Visual C++. 15 | */ 16 | 17 | #ifndef BSTRLIB_BSAFE_INCLUDE 18 | #define BSTRLIB_BSAFE_INCLUDE 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | #if !defined (__GNUC__) && (!defined(_MSC_VER) || (_MSC_VER <= 1310)) 25 | /* This is caught in the linker, so its not necessary for gcc. */ 26 | extern char * (gets) (char * buf); 27 | #endif 28 | 29 | extern char * (strncpy) (char *dst, const char *src, size_t n); 30 | extern char * (strncat) (char *dst, const char *src, size_t n); 31 | extern char * (strtok) (char *s1, const char *s2); 32 | extern char * (strdup) (const char *s); 33 | 34 | #undef strcpy 35 | #undef strcat 36 | #define strcpy(a,b) bsafe_strcpy(a,b) 37 | #define strcat(a,b) bsafe_strcat(a,b) 38 | 39 | #ifdef __cplusplus 40 | } 41 | #endif 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /plugins/survival/persistence/nbt/src/nbt.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2011 Kevin M. Bowling, , USA 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | -------------------------------------------------------------------------------- /plugins/survival/persistence/nbt/include/nbt.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2011 Kevin M. Bowling, , USA 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #include 27 | -------------------------------------------------------------------------------- /src/Error.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2011 Kevin M. Bowling, , USA 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #include 27 | 28 | int 29 | CD_ErrorToErrno (CDError error) 30 | { 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /include/craftd/protocols.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2011 Kevin M. Bowling, , USA 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef CRAFTD_PROTOCOLS_H 27 | #define CRAFTD_PROTOCOLS_H 28 | 29 | #include 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /src/Logger.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2011 Kevin M. Bowling, , USA 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #define CRAFTD_LOGGER_IGNORE_EXTERN 27 | #include 28 | #undef CRAFTD_LOGGER_IGNORE_EXTERN 29 | 30 | CDLogger CDDefaultLogger; 31 | -------------------------------------------------------------------------------- /include/craftd/extras.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2011 Kevin M. Bowling, , USA 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #include 27 | 28 | int config_export (config_setting_t* setting, config_t* config); 29 | 30 | int config_unexport (config_t* config); 31 | -------------------------------------------------------------------------------- /scripting/javascript/include/common.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2011 Kevin M. Bowling, , USA 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef CRAFTD_JAVASCRIPT_COMMON_H 27 | #define CRAFTD_JAVASCRIPT_COMMON_H 28 | 29 | #include 30 | 31 | #include 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /plugins/survival/mapgen/noise/noise1234.h: -------------------------------------------------------------------------------- 1 | // noise1234 2 | // 3 | // Author: Stefan Gustavson, 2003-2005 4 | // Contact: stegu@itn.liu.se 5 | // 6 | // This code was GPL licensed until February 2011. 7 | // As the original author of this code, I hereby 8 | // release it into the public domain. 9 | // Please feel free to use it for whatever you want. 10 | // Credit is appreciated where appropriate, and I also 11 | // appreciate being told where this code finds any use, 12 | // but you may do as you like. 13 | 14 | /** \file 15 | \brief Declares the "noise1" through "noise4" functions for Perlin noise. 16 | \author Stefan Gustavson (stegu@itn.liu.se) 17 | */ 18 | 19 | /* 20 | * This is a backport to C of my improved noise class in C++. 21 | * It is highly reusable without source code modifications. 22 | * 23 | * Note: 24 | * Replacing the "float" type with "double" can actually make this run faster 25 | * on some platforms. A templatized version of Noise1234 could be useful. 26 | */ 27 | 28 | /** 1D, 2D, 3D and 4D float Perlin noise, SL "noise()" 29 | */ 30 | extern float noise1( float x ); 31 | extern float noise2( float x, float y ); 32 | extern float noise3( float x, float y, float z ); 33 | extern float noise4( float x, float y, float z, float w ); 34 | 35 | /** 1D, 2D, 3D and 4D float Perlin periodic noise, SL "pnoise()" 36 | */ 37 | extern float pnoise1( float x, int px ); 38 | extern float pnoise2( float x, float y, int px, int py ); 39 | extern float pnoise3( float x, float y, float z, int px, int py, int pz ); 40 | extern float pnoise4( float x, float y, float z, float w, 41 | int px, int py, int pz, int pw ); 42 | -------------------------------------------------------------------------------- /third-party/bstring/license.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2002-2008 Paul Hsieh 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | 10 | Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | Neither the name of bstrlib nor the names of its contributors may be used 15 | to endorse or promote products derived from this software without 16 | specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | POSSIBILITY OF SUCH DAMAGE. 29 | 30 | -------------------------------------------------------------------------------- /include/craftd/version.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2011 Kevin M. Bowling, , USA 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef CRAFTD_VERSION_H 27 | #define CRAFTD_VERSION_H 28 | 29 | #define CRAFTD_NOTICE_MESSAGE "(" PACKAGE_STRING ")\n" \ 30 | " Copyright (c) 2011 Kevin Bowling - http://mc.kev009.com/craftd/\n" 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /include/craftd/protocols/survival/common.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2011 Kevin M. Bowling, , USA 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef CRAFTD_SURVIVAL_COMMON_H 27 | #define CRAFTD_SURVIVAL_COMMON_H 28 | 29 | #include 30 | 31 | #include 32 | #include 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /src/SystemLogger.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2011 Kevin M. Bowling, , USA 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | 27 | #define CRAFTD_LOGGER_IGNORE_EXTERN 28 | #include 29 | #undef CRAFTD_LOGGER_IGNORE_EXTERN 30 | 31 | CDLogger CDSystemLogger = { 32 | .log = syslog, 33 | .setlogmask = setlogmask, 34 | .closelog = closelog, 35 | }; 36 | -------------------------------------------------------------------------------- /include/craftd/Error.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2011 Kevin M. Bowling, , USA 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef CRAFTD_ERROR_H 27 | #define CRAFTD_ERROR_H 28 | 29 | typedef int CDError; 30 | 31 | typedef enum _CDErrorType { 32 | CDOk 33 | } CDErrorType; 34 | 35 | #define CD_DEFINE_ERROR CDError _error; 36 | 37 | #define ERROR(data) ((data)->_error) 38 | 39 | int CD_ErrorToErrno (CDError error); 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /include/craftd/lock.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2011 Kevin M. Bowling, , USA 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #include 27 | 28 | #ifndef HAVE_PTHREAD_SPIN_T 29 | #define pthread_spinlock_t pthread_mutex_t 30 | #define pthread_spin_init(l, a) pthread_mutex_init(l, NULL) 31 | #define pthread_spin_destroy(l) pthread_mutex_destroy(l) 32 | #define pthread_spin_lock(l) pthread_mutex_lock(l) 33 | #define pthread_spin_unlock(l) pthread_mutex_unlock(l) 34 | #endif 35 | -------------------------------------------------------------------------------- /plugins/survival/persistence/nbt/include/itoa.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2011 Kevin M. Bowling, , USA 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | /** 27 | * Take an integer and convert it to a base 2 to 36 char representation. 28 | * 29 | * Ideas from (http://www.jb.man.ac.uk/~slowe/cpp/itoa.html) and K&R pg. 64 30 | * 31 | * @param value integer to convert 32 | * @param result string representation 33 | * @param base conversion base, 2 to 36 34 | * @return pointer to string representation 35 | */ 36 | char* itoa (int value, char *result, int base); 37 | -------------------------------------------------------------------------------- /include/craftd/protocols/survival.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2011 Kevin M. Bowling, , USA 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef CRAFTD_SURVIVAL_H 27 | #define CRAFTD_SURVIVAL_H 28 | 29 | #include 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | CDProtocol* CD_InitializeSurvivalProtocol (CDServer* server); 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /include/craftd/protocols/survival/Logger.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2011 Kevin M. Bowling, , USA 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef CRAFTD_BETA_LOGGER_H 27 | #define CRAFTD_BETA_LOGGER_H 28 | 29 | #include 30 | 31 | #define WLOG(world, priority, format, ...) \ 32 | server->logger.log(priority, "%s[%s]> " format, CD_ServerToString(world->server), CD_StringContent(world->name), ##__VA_ARGS__) 33 | 34 | #define WDEBUG(world, format, ...) WLOG(world, LOG_DEBUG, format, ##__VA_ARGS__) 35 | 36 | #define WERR(world, format, ...) WLOG(world, LOG_CRIT, format, ##__VA_ARGS__) 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /src/Protocol.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2011 Kevin M. Bowling, , USA 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #include 27 | 28 | CDProtocol* 29 | CD_CreateProtocol (const char* name, CDProtocolPacketParsable parsable, CDProtocolPacketParse parse) 30 | { 31 | CDProtocol* self = CD_malloc(sizeof(CDProtocol)); 32 | 33 | assert(name); 34 | assert(parsable); 35 | assert(parse); 36 | 37 | self->name = CD_CreateStringFromCStringCopy(name); 38 | self->parsable = parsable; 39 | self->parse = parse; 40 | 41 | return self; 42 | } 43 | 44 | void CD_DestroyProtocol (CDProtocol* self); 45 | 46 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | The craftd software contains code written by third parties. Such 2 | software will have its own individual license file in the directory in 3 | which it appears. This file will describe the copyrights, license, and 4 | restrictions which apply to that code. 5 | 6 | ============================================================================= 7 | craftd Simplified BSD License, see http://www.opensource.org/licenses/ 8 | ----------------------------------------------------------------------------- 9 | Copyright (c) 2010-2011 Kevin M. Bowling, , USA 10 | All rights reserved. 11 | 12 | Redistribution and use in source and binary forms, with or without 13 | modification, are permitted provided that the following conditions are met: 14 | 15 | * Redistributions of source code must retain the above copyright notice, 16 | this list of conditions and the following disclaimer. 17 | * Redistributions in binary form must reproduce the above copyright 18 | notice, this list of conditions and the following disclaimer in the 19 | documentation and/or other materials provided with the distribution. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 25 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | POSSIBILITY OF SUCH DAMAGE. 32 | ============================================================================= 33 | -------------------------------------------------------------------------------- /include/craftd/Dynamic.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2011 Kevin M. Bowling, , USA 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef CRAFTD_DYNAMIC_H 27 | #define CRAFTD_DYNAMIC_H 28 | 29 | #define CD_DEFINE_DYNAMIC CDHash* _dynamic 30 | 31 | #define DYNAMIC(data) ((data)->_dynamic) 32 | 33 | #define CD_CreateDynamic() CD_CreateHash() 34 | #define CD_DestroyDynamic(self) CD_DestroyHash(self) 35 | 36 | #define CD_DynamicGet(object, property) CD_HashGet(DYNAMIC(object), property) 37 | #define CD_DynamicPut(object, property, value) CD_HashPut(DYNAMIC(object), property, (value)) 38 | #define CD_DynamicDelete(object, property) CD_HashDelete(DYNAMIC(object), property) 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /include/craftd/protocols/survival/Region.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2011 Kevin M. Bowling, , USA 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef CRAFTD_BETA_REGION_H 27 | #define CRAFTD_BETA_REGION_H 28 | 29 | #include 30 | #include 31 | 32 | bool SV_IsCoordInRadius (SVChunkPosition* coord, SVChunkPosition* centerCoord, int radius); 33 | 34 | bool SV_IsDistanceGreater (SVPrecisePosition a, SVPrecisePosition b, int maxDistance); 35 | 36 | SVRelativePosition SV_RelativeMove (SVPrecisePosition* a, SVPrecisePosition* b); 37 | 38 | void SV_RegionBroadcastPacket (SVPlayer* player, SVPacket* packet); 39 | 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /include/craftd/utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2011 Kevin M. Bowling, , USA 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef CRAFTD_UTILS_H 27 | #define CRAFTD_UTILS_H 28 | 29 | #include 30 | 31 | void CD_abort (const char* error, ...); 32 | 33 | int CD_mkdir (const char* path, mode_t mode); 34 | 35 | size_t CD_FileSize (const char* path); 36 | 37 | bool CD_IsFile (const char* path); 38 | 39 | bool CD_IsDirectory (const char* path); 40 | 41 | bool CD_IsSymlink (const char* path); 42 | 43 | bool CD_PathExists (const char* path); 44 | 45 | bool CD_IsReadable (const char* path); 46 | 47 | bool CD_IsWritable (const char* path); 48 | 49 | bool CD_IsExecutable (const char* path); 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /include/craftd/Protocol.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2011 Kevin M. Bowling, , USA 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef CRAFTD_PROTOCOL_H 27 | #define CRAFTD_PROTOCOL_H 28 | 29 | #include 30 | 31 | typedef bool (*CDProtocolPacketParsable) (CDBuffers* buffers); 32 | typedef void* (*CDProtocolPacketParse) (CDBuffers* buffers); 33 | 34 | typedef struct _CDProtocol { 35 | CDString* name; 36 | 37 | CDProtocolPacketParsable parsable; 38 | CDProtocolPacketParse parse; 39 | } CDProtocol; 40 | 41 | CDProtocol* CD_CreateProtocol (const char* name, CDProtocolPacketParsable parsable, CDProtocolPacketParse parse); 42 | 43 | void CD_DestroyProtocol (CDProtocol* self); 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /src/extras.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2011 Kevin M. Bowling, , USA 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #include 27 | 28 | int 29 | config_export (config_setting_t* setting, config_t* config) 30 | { 31 | if (config_setting_is_group(setting) != CONFIG_TRUE) { 32 | return CONFIG_FALSE; 33 | } 34 | 35 | memset(config, 0, sizeof(*config)); 36 | 37 | config->root = setting; 38 | 39 | #if LIBCONFIG_VER_MAJOR >= 1 && LIBCONFIG_VER_MINOR >= 4 40 | config->tab_width = 2; 41 | #endif 42 | 43 | return CONFIG_TRUE; 44 | } 45 | 46 | int 47 | config_unexport (config_t* config) 48 | { 49 | memset(config, 0, sizeof(*config)); 50 | 51 | return CONFIG_TRUE; 52 | } 53 | -------------------------------------------------------------------------------- /include/craftd/Buffers.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2011 Kevin M. Bowling, , USA 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef CRAFTD_BUFFERS_H 27 | #define CRAFTD_BUFFERS_H 28 | 29 | #include 30 | 31 | #define CD_DEFAULT_HIGH_WATERMARK 4096 32 | 33 | typedef struct bufferevent* CDRawBuffers; 34 | 35 | typedef struct _CDBuffers { 36 | CDRawBuffers raw; 37 | 38 | CDBuffer* input; 39 | CDBuffer* output; 40 | 41 | bool external; 42 | } CDBuffers; 43 | 44 | CDBuffers* CD_CreateBuffers (void); 45 | 46 | CDBuffers* CD_WrapBuffers (CDRawBuffers buffers); 47 | 48 | void CD_DestroyBuffers (CDBuffers* self); 49 | 50 | void CD_BufferReadIn (CDBuffers* self, size_t low, size_t high); 51 | 52 | void CD_BuffersFlush (CDBuffers* self); 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /include/craftd/Console.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2011 Kevin M. Bowling, , USA 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef CRAFTD_CONSOLE_H 27 | #define CRAFTD_CONSOLE_H 28 | 29 | #include 30 | 31 | const char* CDConsoleColors[] = { 32 | "\e[1;30m", // black 33 | "\e[34m", // dark blue 34 | "\e[32m", // dark green 35 | "\e[36m", // dark cyan 36 | "\e[31m", // dark red 37 | "\e[35m", // dark magenta 38 | "\e[33m", // dark orange 39 | "\e[1;37m", // gray 40 | "\e[37m", // dark gray 41 | "\e[1;34m", // blue 42 | "\e[1;32m", // green 43 | "\e[1;36m", // cyan 44 | "\e[1;31m", // red 45 | "\e[1;35m", // magenta 46 | "\e[1;33m" // yellow 47 | }; 48 | 49 | CDString* CD_ConvertStringColorForConsole (CDString* self); 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /scripting/javascript/include/Dynamic.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2011 Kevin M. Bowling, , USA 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #include "common.h" 27 | 28 | JSBool cdjs_InitializeDynamic (CDServer* server, JSContext* context); 29 | 30 | JSBool Dynamic_constructor (JSContext* context, uintN argc, jsval* argv); 31 | 32 | JSBool Dynamic_delete (JSContext* context, JSObject* owner, jsid id, jsval* value); 33 | 34 | JSBool Dynamic_get (JSContext* context, JSObject* owner, jsid id, jsval* value); 35 | 36 | JSBool Dynamic_set (JSContext* context, JSObject* owner, jsid id, JSBool strict, jsval* value); 37 | 38 | static JSClass Dynamic_class = { 39 | "Dynamic", JSCLASS_HAS_PRIVATE, 40 | JS_PropertyStub, Dynamic_delete, Dynamic_get, Dynamic_set, 41 | JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub 42 | }; 43 | -------------------------------------------------------------------------------- /scripting/javascript/include/Global.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2011 Kevin M. Bowling, , USA 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef CRAFTD_JAVASCRIPT_GLOBAL_H 27 | #define CRAFTD_JAVASCRIPT_GLOBAL_H 28 | 29 | #include "common.h" 30 | 31 | static JSClass Global_class = { 32 | "Craftd", JSCLASS_GLOBAL_FLAGS | JSCLASS_HAS_PRIVATE, 33 | JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_StrictPropertyStub, 34 | JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub, 35 | JSCLASS_NO_OPTIONAL_MEMBERS 36 | }; 37 | 38 | JSBool Global_include (JSContext* context, uintN argc, jsval* argv); 39 | 40 | static JSFunctionSpec Global_functions[] = { 41 | JS_FS("include", Global_include, 0, 0), 42 | 43 | JS_FS_END 44 | }; 45 | 46 | JSBool cdjs_InitializeGlobal (CDServer* server, JSContext* context); 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /src/Console.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2011 Kevin M. Bowling, , USA 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #include 27 | 28 | CDString* 29 | CD_ConvertStringColorForConsole (CDString* self) 30 | { 31 | CDString* result = CD_CreateString(); 32 | 33 | for (size_t i = 0, end = CD_StringLength(self); i < end; i++) { 34 | CDString* ch = CD_CharAt(self, i); 35 | 36 | if (CD_StringIsEqual(ch, "§")) { 37 | CD_DestroyString(ch); 38 | ch = CD_CharAt(self, i++); 39 | char c = CD_StringContent(ch)[0]; 40 | 41 | // use some math to get the array index 42 | CD_AppendCString(result, CDConsoleColors[ 43 | ((c >= 97) ? (c - 0x57) : (c - 0x30)) 44 | ]); 45 | } 46 | else { 47 | CD_AppendString(result, ch); 48 | } 49 | 50 | CD_DestroyString(ch); 51 | } 52 | 53 | return result; 54 | } 55 | -------------------------------------------------------------------------------- /scripting/javascript/src/Dynamic.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2011 Kevin M. Bowling, , USA 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #include "../include/Dynamic.h" 27 | 28 | JSBool 29 | cdjs_InitializeDynamic (CDServer* server, JSContext* context) 30 | { 31 | return JS_TRUE; 32 | } 33 | 34 | JSBool 35 | Dynamic_constructor (JSContext* context, uintN argc, jsval* argv) 36 | { 37 | return JS_TRUE; 38 | } 39 | 40 | JSBool 41 | Dynamic_delete (JSContext* context, JSObject* owner, jsid id, jsval* value) 42 | { 43 | jsval name; 44 | CDHash* self = (CDHash*) JS_GetPrivate(context, owner); 45 | 46 | JS_IdToValue(context, id, &name); 47 | 48 | return JS_TRUE; 49 | } 50 | 51 | JSBool 52 | Dynamic_get (JSContext* context, JSObject* owner, jsid id, jsval* value) 53 | { 54 | return JS_TRUE; 55 | } 56 | 57 | JSBool 58 | Dynamic_set (JSContext* context, JSObject* owner, jsid id, JSBool strict, jsval* value) 59 | { 60 | return JS_TRUE; 61 | } 62 | -------------------------------------------------------------------------------- /plugins/survival/persistence/nbt/src/itoa.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2011 Kevin M. Bowling, , USA 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #include 27 | #include 28 | 29 | char* 30 | itoa (int value, char* result, int base) 31 | { 32 | int tmp_value; 33 | char tmp_char; 34 | char* ptr = result; 35 | char* ptr1 = result; 36 | 37 | assert(base > 2 || base < 36); 38 | 39 | do { 40 | tmp_value = value; 41 | value /= base; 42 | *ptr++ = "zyxwvutsrqponmlkjihgfedcba9876543210123456789abcdefghijklmnopqrstuvwxyz" 43 | [35 + (tmp_value - value * base)]; 44 | } while (value); 45 | 46 | /* Add a negative sign if needed */ 47 | if (tmp_value < 0) { 48 | *ptr++ = '-'; 49 | } 50 | 51 | *ptr-- = '\0'; 52 | 53 | while (ptr1 < ptr) { 54 | tmp_char = *ptr; 55 | *ptr-- = *ptr1; 56 | *ptr1++ = tmp_char; 57 | } 58 | 59 | return result; 60 | } 61 | -------------------------------------------------------------------------------- /extras/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | CRAFTDDIR=$(pwd)/craftd 4 | SRCDIR=$CRAFTDDIR/src 5 | LIBDIR=$CRAFTDDIR/lib 6 | DATADIR=$CRAFTDDIR/data 7 | EXAMPLESDIR=$CRAFTDDIR/examples 8 | LIBEVENT2VER=libevent-2.0.10-stable 9 | LIBEVENT2DIR=$SRCDIR/$LIBEVENT2VER 10 | JANSSONVER=jansson-2.0 11 | JANSSONDIR=$SRCDIR/$JANSSONVER 12 | 13 | echo "Creating directories..." 14 | mkdir -p $SRCDIR $LIBDIR $DATADIR $EXAMPLESDIR || exit 1 15 | 16 | echo "Downloading $LIBEVENT2VER..." 17 | cd $SRCDIR 18 | wget -q http://monkey.org/~provos/$LIBEVENT2VER.tar.gz || exit 1 19 | tar xzf $LIBEVENT2VER.tar.gz || exit 1 20 | 21 | echo "Preparing $LIBEVENT2VER..." 22 | cd $LIBEVENT2DIR 23 | ./configure -q || exit 1 24 | 25 | echo "Building $LIBEVENT2VER..." 26 | make >/dev/null 2>&1 || exit 1 27 | cp .libs/*.so* $LIBDIR/ || exit 1 28 | 29 | cd $SRCDIR 30 | echo "Downloading $JANSSONVER..." 31 | wget -q http://www.digip.org/jansson/releases/$JANSSONVER.tar.gz || exit 1 32 | tar zxf $JANSSONVER.tar.gz || exit 1 33 | 34 | echo "Preparing $JANSSONVER..." 35 | cd $JANSSONVER 36 | ./configure -q || exit 1 37 | 38 | echo "Building $JANSSONVER..." 39 | make >/dev/null 2>&1 || exit 1 40 | cp src/.libs/*.so* $LIBDIR/ || exit 1 41 | 42 | echo "Fetching latest craftd from git repository..." 43 | cd $SRCDIR 44 | git clone -q git://github.com/kev009/craftd.git || exit 1 45 | 46 | echo "Building craftd..." 47 | cd $SRCDIR/craftd 48 | ./autogen.sh >/dev/null 2>&1 || exit 1 49 | export libevent2_pthreads_LIBS="-levent -levent_pthreads -L$LIBDIR" 50 | export libevent2_pthreads_CFLAGS="-I$LIBEVENT2DIR/include" 51 | export jansson_LIBS="-ljansson -L$LIBDIR" 52 | export jansson_CFLAGS="-I$JANSSONDIR/src" 53 | 54 | # rpath magic to find the local libs 55 | export LDFLAGS="$LDFLAGS -Wl,-rpath,\$$ORIGIN/lib" 56 | 57 | ./configure -q --prefix=$CRAFTDDIR --bindir=$CRAFTDDIR --sysconfdir=$EXAMPLESDIR --datarootdir=$DATADIR || exit 1 58 | make >/dev/null 2>&1 || exit 1 59 | make install >/dev/null 2>&1 || exit 1 60 | 61 | echo "Creating empty world directory..." 62 | mkdir -p $DATADIR/craftd/world 63 | 64 | echo "Creating config..." 65 | cp $EXAMPLESDIR/craftd/craftd.conf.dist $CRAFTDDIR/craftd.conf 66 | cd $CRAFTDDIR 67 | 68 | echo "Done" 69 | echo 70 | echo "--------------------------------------------------" 71 | echo "Start craftd with: ./craftd -c craftd.conf" 72 | echo "--------------------------------------------------" 73 | -------------------------------------------------------------------------------- /scripting/javascript/src/Client.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2011 Kevin M. Bowling, , USA 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #include "../include/Client.h" 27 | 28 | JSBool 29 | cdjs_InitializeClient (CDServer* server, JSContext* context) 30 | { 31 | JSObject* self = JS_InitClass(context, JS_GetGlobalObject(context), NULL, 32 | &Client_class, Client_constructor, 1, 33 | Client_properties, Client_methods, 34 | Client_static_properties, Client_static_methods); 35 | 36 | if (!self) { 37 | return JS_FALSE; 38 | } 39 | 40 | return JS_TRUE; 41 | } 42 | 43 | JSBool 44 | Client_constructor (JSContext* context, uintN argc, jsval* argv) 45 | { 46 | JSObject* self = NULL; 47 | 48 | return JS_TRUE; 49 | } 50 | 51 | JSBool 52 | Client_get_ip (JSContext* context, JSObject* owner, jsid id, jsval* value) 53 | { 54 | CDClient* self = JS_GetPrivate(context, owner); 55 | 56 | *value = STRING_TO_JSVAL(JS_NewStringCopyZ(context, self->ip)); 57 | 58 | return JS_TRUE; 59 | } 60 | -------------------------------------------------------------------------------- /scripting/javascript/include/Client.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2011 Kevin M. Bowling, , USA 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #include "common.h" 27 | 28 | JSBool cdjs_InitializeClient (CDServer* server, JSContext* context); 29 | 30 | JSBool Client_constructor (JSContext* context, uintN argc, jsval* argv); 31 | 32 | static JSClass Client_class = { 33 | "Client", JSCLASS_HAS_PRIVATE, 34 | JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_StrictPropertyStub, 35 | JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub 36 | }; 37 | 38 | JSBool Client_get_ip (JSContext* context, JSObject* owner, jsid id, jsval* value); 39 | 40 | static JSPropertySpec Client_properties[] = { 41 | { "ip", 0, 0, Client_get_ip, NULL }, 42 | 43 | { NULL } 44 | }; 45 | 46 | static JSFunctionSpec Client_methods[] = { 47 | JS_FS_END 48 | }; 49 | 50 | static JSPropertySpec Client_static_properties[] = { 51 | { NULL } 52 | }; 53 | 54 | static JSFunctionSpec Client_static_methods[] = { 55 | JS_FS_END 56 | }; 57 | -------------------------------------------------------------------------------- /include/craftd/Worker.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2011 Kevin M. Bowling, , USA 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef CRAFTD_WORKER_H 27 | #define CRAFTD_WORKER_H 28 | 29 | #include 30 | #include 31 | 32 | struct _CDWorkers; 33 | struct _CDServer; 34 | 35 | typedef struct _CDWorker { 36 | struct _CDServer* server; 37 | 38 | int id; 39 | pthread_t thread; 40 | 41 | struct _CDWorkers* workers; 42 | 43 | CDJob* job; 44 | bool working; 45 | bool stopped; 46 | } CDWorker; 47 | 48 | /** 49 | * Create a Worker object 50 | */ 51 | CDWorker* CD_CreateWorker (struct _CDServer* server); 52 | 53 | /** 54 | * Destroy a Worker object and its eventual working Job 55 | * 56 | * @param worker The worker object to destroy 57 | */ 58 | void CD_DestroyWorker (CDWorker* self); 59 | 60 | /** 61 | * Main thread function, pass the result of CD_CreateWorker as argument. 62 | */ 63 | bool CD_RunWorker (CDWorker* self); 64 | 65 | /** 66 | * Stop a worker 67 | */ 68 | bool CD_StopWorker (CDWorker* self); 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /plugins/Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS = survival/mapgen/noise 2 | 3 | pkglib_LTLIBRARIES = libsurvival.tests.la libsurvival.base.la libsurvival.persistence.nbt.la libsurvival.mapgen.classic.la libsurvival.mapgen.trivial.la libhttpd.la 4 | # BROKEN: libsvcmdadmin.la 5 | 6 | libsurvival_tests_la_SOURCES = survival/tests/main.c survival/tests/tinytest/tinytest.c survival/tests/tinytest/tinytest.h survival/tests/tinytest/tinytest_macros.h 7 | libsurvival_tests_la_CPPFLAGS = $(AM_CPPFLAGS) -Isurvival/tests 8 | libsurvival_tests_la_LDFLAGS = -version-info=0:0:0 9 | 10 | libsurvival_base_la_SOURCES = survival/base/main.c 11 | libsurvival_base_la_LDFLAGS = -version-info=0:0:0 12 | libsurvival_base_la_LIBS = $(AM_LIBS) $(jansson_LIBS) 13 | EXTRA_DIST = survival/base/callbacks.c 14 | 15 | # admin mod code is currently broken 16 | #libsvcmdadmin_la_SOURCES = survival/commands/admin/main.c 17 | #survival/commands/admin/src/auth.c survival/commands/admin/src/ticket.c survival/commands/admin/src/player.c survival/commands/admin/src/workers.c 18 | #libsvcmdadmin_la_LDFLAGS = -version-info=0:0:0 19 | #EXTRA_DIST += survival/commands/admin/src 20 | 21 | libsurvival_persistence_nbt_la_SOURCES = survival/persistence/nbt/main.c survival/persistence/nbt/src/itoa.c survival/persistence/nbt/include/itoa.h survival/persistence/nbt/include/nbt.h survival/persistence/nbt/cNBT/nbt_loading.c survival/persistence/nbt/cNBT/nbt.h 22 | libsurvival_persistence_nbt_la_CPPFLAGS = $(AM_CPPFLAGS) -Isurvival/persistence/nbt/include -Isurvival/persistence/nbt 23 | 24 | # Classic map generator 25 | libsurvival_mapgen_classic_la_SOURCES = survival/mapgen/classic/main.c 26 | libsurvival_mapgen_classic_la_CPPFLAGS = $(AM_CPPFLAGS) -Isurvival/mapgen 27 | libsurvival_mapgen_classic_la_LIBADD = survival/mapgen/noise/libnoise_simplex.la -lm 28 | libsurvival_mapgen_classic_la_LDFLAGS = -version-info 0:0:0 29 | 30 | # Trivial map generator 31 | libsurvival_mapgen_trivial_la_SOURCES = survival/mapgen/trivial/main.c 32 | libsurvival_mapgen_trivial_la_CPPFLAGS = $(AM_CPPFLAGS) -Isurvival/mapgen 33 | libsurvival_mapgen_trivial_la_LIBADD = survival/mapgen/noise/libnoise_simplex.la -lm 34 | libsurvival_mapgen_trivial_la_LDFLAGS = -version-info 0:0:0 35 | 36 | libhttpd_la_SOURCES = httpd/main.c httpd/src/HTTPd.c httpd/include/HTTPd.h 37 | libhttpd_la_CPPFLAGS = $(AM_CPPFLAGS) -Ihttpd 38 | libhttpd_la_LDFLAGS = -version-info 0:0:0 39 | 40 | # Global build envs 41 | include $(top_srcdir)/build/auto/build.mk 42 | -------------------------------------------------------------------------------- /plugins/httpd/htdocs/css/html5reset-1.6.1.css: -------------------------------------------------------------------------------- 1 | /* 2 | html5doctor.com Reset Stylesheet 3 | v1.6.1 4 | Last Updated: 2010-09-17 5 | Author: Richard Clark - http://richclarkdesign.com 6 | Twitter: @rich_clark 7 | */ 8 | 9 | html, body, div, span, object, iframe, 10 | h1, h2, h3, h4, h5, h6, p, blockquote, pre, 11 | abbr, address, cite, code, 12 | del, dfn, em, img, ins, kbd, q, samp, 13 | small, strong, sub, sup, var, 14 | b, i, 15 | dl, dt, dd, ol, ul, li, 16 | fieldset, form, label, legend, 17 | table, caption, tbody, tfoot, thead, tr, th, td, 18 | article, aside, canvas, details, figcaption, figure, 19 | footer, header, hgroup, menu, nav, section, summary, 20 | time, mark, audio, video { 21 | margin:0; 22 | padding:0; 23 | border:0; 24 | outline:0; 25 | font-size:100%; 26 | vertical-align:baseline; 27 | background:transparent; 28 | } 29 | 30 | body { 31 | line-height:1; 32 | } 33 | 34 | article,aside,details,figcaption,figure, 35 | footer,header,hgroup,menu,nav,section { 36 | display:block; 37 | } 38 | 39 | nav ul { 40 | list-style:none; 41 | } 42 | 43 | blockquote, q { 44 | quotes:none; 45 | } 46 | 47 | blockquote:before, blockquote:after, 48 | q:before, q:after { 49 | content:''; 50 | content:none; 51 | } 52 | 53 | a { 54 | margin:0; 55 | padding:0; 56 | font-size:100%; 57 | vertical-align:baseline; 58 | background:transparent; 59 | } 60 | 61 | /* change colours to suit your needs */ 62 | ins { 63 | background-color:#ff9; 64 | color:#000; 65 | text-decoration:none; 66 | } 67 | 68 | /* change colours to suit your needs */ 69 | mark { 70 | background-color:#ff9; 71 | color:#000; 72 | font-style:italic; 73 | font-weight:bold; 74 | } 75 | 76 | del { 77 | text-decoration: line-through; 78 | } 79 | 80 | abbr[title], dfn[title] { 81 | border-bottom:1px dotted; 82 | cursor:help; 83 | } 84 | 85 | table { 86 | border-collapse:collapse; 87 | border-spacing:0; 88 | } 89 | 90 | /* change border colour to suit your needs */ 91 | hr { 92 | display:block; 93 | height:1px; 94 | border:0; 95 | border-top:1px solid #cccccc; 96 | margin:1em 0; 97 | padding:0; 98 | } 99 | 100 | input, select { 101 | vertical-align:middle; 102 | } -------------------------------------------------------------------------------- /include/Makefile.am: -------------------------------------------------------------------------------- 1 | # Add in lexicographic order: 2 | # 3 | # pkginclude_HEADERS = 4 | # ls craftd/*.h | awk '{ print $1" \\" }' | sort 5 | # truncate last \ 6 | # 7 | pkginclude_HEADERS = craftd/Arithmetic.h \ 8 | craftd/Buffer.h \ 9 | craftd/Buffers.h \ 10 | craftd/Client.h \ 11 | craftd/common.h \ 12 | craftd/Config.h \ 13 | craftd/Console.h \ 14 | craftd/Dynamic.h \ 15 | craftd/Error.h \ 16 | craftd/Event.h \ 17 | craftd/extras.h \ 18 | craftd/Hash.h \ 19 | craftd/javaendian.h \ 20 | craftd/Job.h \ 21 | craftd/List.h \ 22 | craftd/Logger.h \ 23 | craftd/Map.h \ 24 | craftd/memory.h \ 25 | craftd/Plugin.h \ 26 | craftd/Plugins.h \ 27 | craftd/Protocol.h \ 28 | craftd/Regexp.h \ 29 | craftd/ScriptingEngine.h \ 30 | craftd/ScriptingEngines.h \ 31 | craftd/Server.h \ 32 | craftd/Set.h \ 33 | craftd/String.h \ 34 | craftd/TimeLoop.h \ 35 | craftd/utils.h \ 36 | craftd/version.h \ 37 | craftd/Worker.h \ 38 | craftd/Workers.h 39 | 40 | # Modular protocol headers 41 | protocoldir = $(pkgincludedir)/protocols 42 | protocol_HEADERS = craftd/protocols/survival.h 43 | 44 | # Survival protocol headers 45 | survivaldir = $(pkgincludedir)/protocols/survival 46 | survival_HEADERS = craftd/protocols/survival/Buffer.h \ 47 | craftd/protocols/survival/common.h \ 48 | craftd/protocols/survival/Logger.h \ 49 | craftd/protocols/survival/minecraft.h \ 50 | craftd/protocols/survival/Packet.h \ 51 | craftd/protocols/survival/PacketLength.h \ 52 | craftd/protocols/survival/Player.h \ 53 | craftd/protocols/survival/Region.h \ 54 | craftd/protocols/survival/World.h 55 | 56 | # bstring headers 57 | bstringdir = $(pkgincludedir)/bstring 58 | bstring_HEADERS = craftd/bstring/bsafe.h \ 59 | craftd/bstring/bstraux.h \ 60 | craftd/bstring/bstrlib.h \ 61 | craftd/bstring/bstrwrap.h 62 | 63 | # klib headers 64 | klibdir = $(pkgincludedir)/klib 65 | klib_HEADERS = craftd/klib/kbtree.h \ 66 | craftd/klib/khash.h \ 67 | craftd/klib/khmm.h \ 68 | craftd/klib/klist.h \ 69 | craftd/klib/kmin.h \ 70 | craftd/klib/knetfile.h \ 71 | craftd/klib/knhx.h \ 72 | craftd/klib/kseq.h \ 73 | craftd/klib/ksort.h \ 74 | craftd/klib/kstring.h \ 75 | craftd/klib/kvec.h 76 | -------------------------------------------------------------------------------- /plugins/survival/mapgen/noise/srdnoise23.h: -------------------------------------------------------------------------------- 1 | /* srdnoise23, Simplex noise with rotating gradients 2 | * and a true analytic derivative in 2D and 3D. 3 | * 4 | * This is version 2 of srdnoise23 written in early 2008. 5 | * A stupid bug was corrected. Do not use earlier versions. 6 | * 7 | * Author: Stefan Gustavson, 2003-2008 8 | * 9 | * Contact: stefan.gustavson@gmail.com 10 | * 11 | * This code was GPL licensed until February 2011. 12 | * As the original author of this code, I hereby 13 | * release it into the public domain. 14 | * Please feel free to use it for whatever you want. 15 | * Credit is appreciated where appropriate, and I also 16 | * appreciate being told where this code finds any use, 17 | * but you may do as you like. 18 | */ 19 | 20 | /** \file 21 | \brief C header file for Perlin simplex noise with rotating 22 | gradients and analytic derivative over 2 and 3 dimensions. 23 | \author Stefan Gustavson (stegu@itn.liu.se) 24 | */ 25 | 26 | /* 27 | * This is an implementation of Perlin "simplex noise" over two dimensions 28 | * (x,y) and three dimensions (x,y,z). One extra parameter 't' rotates the 29 | * underlying gradients of the grid, which gives a swirling, flow-like 30 | * motion. The derivative is returned, to make it possible to do pseudo- 31 | * advection and implement "flow noise", as presented by Ken Perlin and 32 | * Fabrice Neyret at Siggraph 2001. 33 | * 34 | * When not animated and presented in one octave only, this noise 35 | * looks exactly the same as the plain version of simplex noise. 36 | * It's nothing magical by itself, although the extra animation 37 | * parameter 't' is useful. Fun stuff starts to happen when you 38 | * do fractal sums of several octaves, with different rotation speeds 39 | * and an advection of smaller scales by larger scales (or even the 40 | * other way around it you feel adventurous). 41 | * 42 | * The gradient rotations that can be performed by this noise function 43 | * and the true analytic derivatives are required to do flow noise. 44 | * You can't do it properly with regular Perlin noise. 45 | * 46 | */ 47 | 48 | /** 49 | * Simplex, rotating, derivative noise over 2 dimensions 50 | */ 51 | float srdnoise2( float x, float y, float t, float *dnoise_dx, float *dnoise_dy ); 52 | 53 | /** 54 | * Simplex, rotating, derivative noise over 3 dimensions 55 | */ 56 | float srdnoise3( float x, float y, float z, float t, float *dnoise_dx, float *dnoise_dy, float *dnoise_dz ); 57 | 58 | -------------------------------------------------------------------------------- /plugins/survival/mapgen/noise/cellular.h: -------------------------------------------------------------------------------- 1 | /* Copyright 1994, 2002 by Steven Worley 2 | This software may be modified and redistributed without restriction 3 | provided this comment header remains intact in the source code. 4 | This code is provided with no warrantee, express or implied, for 5 | any purpose. 6 | 7 | A detailed description and application examples can be found in the 8 | 1996 SIGGRAPH paper "A Cellular Texture Basis Function" and 9 | especially in the 2002 book "Texturing and Modeling, a Procedural 10 | Approach, 3rd edition." There is also extra information on the web 11 | site http://www.worley.com/cellular.html . 12 | 13 | If you do find interesting uses for this tool, and especially if 14 | you enhance it, please drop me an email at steve@worley.com. */ 15 | 16 | 17 | 18 | /* Worley() 19 | 20 | An implementation of the key cellular texturing basis 21 | function. This function is hardwired to return an average F_1 value 22 | of 1.0. It returns the most closest feature point distances 23 | F_1, F_2, .. F_n the vector delta to those points, and a 32 bit 24 | seed for each of the feature points. This function is not 25 | difficult to extend to compute alternative information such as 26 | higher order F values, to use the Manhattan distance metric, or 27 | other fun perversions. 28 | 29 | The input sample location. 30 | Smaller values compute faster. < 5, read the book to extend it. 31 | The output values of F_1, F_2, ..F[n] in F[0], F[1], F[n-1] 32 | The output vector difference between the sample point and the n-th 33 | closest feature point. Thus, the feature point's location is the 34 | hit point minus this value. The DERIVATIVE of F is the unit 35 | normalized version of this vector. 36 | The output 32 bit ID number which labels the feature point. This 37 | is useful for domain partitions, especially for coloring flagstone 38 | patterns. 39 | 40 | This implementation is tuned for speed in a way that any order > 5 41 | will likely have discontinuous artifacts in its computation of F5+. 42 | This can be fixed by increasing the internal points-per-cube 43 | density in the source code, at the expense of slower 44 | computation. The book lists the details of this tuning. */ 45 | 46 | void Worley(double at[3], long max_order, 47 | double F[2], double delta[2][3], unsigned long ID[2]); 48 | -------------------------------------------------------------------------------- /scripting/javascript/src/Global.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2011 Kevin M. Bowling, , USA 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #include "../include/Global.h" 27 | #include "../include/Dynamic.h" 28 | #include "../include/Client.h" 29 | 30 | JSBool 31 | cdjs_InitializeGlobal (CDServer* server, JSContext* context) 32 | { 33 | JSObject* self = JS_NewCompartmentAndGlobalObject(context, &Global_class, NULL); 34 | 35 | if (!JS_InitStandardClasses(context, self)) { 36 | return JS_FALSE; 37 | } 38 | 39 | #ifdef HAVE_CONST_JS_HAS_CTYPES 40 | JS_InitCTypesClass(context, self); 41 | #endif 42 | 43 | if (!JS_DefineFunctions(context, self, Global_functions)) { 44 | return JS_FALSE; 45 | } 46 | 47 | JS_DefineProperty(context, self, "Craftd", OBJECT_TO_JSVAL(self), 48 | JS_PropertyStub, JS_StrictPropertyStub, JSPROP_READONLY); 49 | 50 | cdjs_InitializeDynamic(server, context); 51 | cdjs_InitializeClient(server, context); 52 | 53 | return JS_TRUE; 54 | } 55 | 56 | JSBool 57 | Global_include (JSContext* context, uintN argc, jsval* argv) 58 | { 59 | for (uintN i = 0; i < argc; i++) { 60 | 61 | } 62 | 63 | return JS_TRUE; 64 | } 65 | -------------------------------------------------------------------------------- /src/protocols/survival/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2011 Kevin M. Bowling, , USA 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #include 27 | 28 | CDProtocol* 29 | CD_InitializeSurvivalProtocol (CDServer* server) 30 | { 31 | server->protocol = CD_CreateProtocol("survival", SV_PacketParsable, (CDProtocolPacketParse) SV_PacketFromBuffers); 32 | 33 | CD_EventProvides(server, "Client.process", CD_CreateEventParameters("CDClient", "SVPacket", NULL)); 34 | CD_EventProvides(server, "Client.processed", CD_CreateEventParameters("CDClient", "SVPacket", NULL)); 35 | 36 | CD_EventProvides(server, "Player.destroy", CD_CreateEventParameters("SVPlayer", NULL)); 37 | 38 | CD_EventProvides(server, "World.create", CD_CreateEventParameters("SVWorld", NULL)); 39 | CD_EventProvides(server, "World.save", CD_CreateEventParameters("SVWorld", NULL)); 40 | CD_EventProvides(server, "World.chunk", CD_CreateEventParameters("SVWorld", "int", "int", "SVChunk", NULL)); 41 | CD_EventProvides(server, "World.chunk=", CD_CreateEventParameters("SVWorld", "int", "int", "SVChunk", NULL)); 42 | CD_EventProvides(server, "World.destroy", CD_CreateEventParameters("SVWorld", NULL)); 43 | 44 | return server->protocol; 45 | } 46 | 47 | -------------------------------------------------------------------------------- /plugins/survival/mapgen/noise/sdnoise1234.h: -------------------------------------------------------------------------------- 1 | /* sdnoise1234, Simplex noise with true analytic 2 | * derivative in 1D to 4D. 3 | * 4 | * Author: Stefan Gustavson, 2003-2005 5 | * Contact: stegu@itn.liu.se 6 | * 7 | * This code was GPL licensed until February 2011. 8 | * As the original author of this code, I hereby 9 | * release it into the public domain. 10 | * Please feel free to use it for whatever you want. 11 | * Credit is appreciated where appropriate, and I also 12 | * appreciate being told where this code finds any use, 13 | * but you may do as you like. 14 | */ 15 | 16 | /** \file 17 | \brief C header file for Perlin simplex noise with analytic 18 | derivative over 1, 2, 3 and 4 dimensions. 19 | \author Stefan Gustavson (stefan.gustavson@gmail.com) 20 | */ 21 | 22 | /* 23 | * This is an implementation of Perlin "simplex noise" over one 24 | * dimension (x), two dimensions (x,y), three dimensions (x,y,z) 25 | * and four dimensions (x,y,z,w). The analytic derivative is 26 | * returned, to make it possible to do lots of fun stuff like 27 | * flow animations, curl noise, analytic antialiasing and such. 28 | * 29 | * Visually, this noise is exactly the same as the plain version of 30 | * simplex noise provided in the file "snoise1234.c". It just returns 31 | * all partial derivatives in addition to the scalar noise value. 32 | * 33 | */ 34 | 35 | #include 36 | 37 | /** 1D simplex noise with derivative. 38 | * If the last argument is not null, the analytic derivative 39 | * is also calculated. 40 | */ 41 | float sdnoise1( float x, float *dnoise_dx); 42 | 43 | /** 2D simplex noise with derivatives. 44 | * If the last two arguments are not null, the analytic derivative 45 | * (the 2D gradient of the scalar noise field) is also calculated. 46 | */ 47 | float sdnoise2( float x, float y, float *dnoise_dx, float *dnoise_dy ); 48 | 49 | /** 3D simplex noise with derivatives. 50 | * If the last tthree arguments are not null, the analytic derivative 51 | * (the 3D gradient of the scalar noise field) is also calculated. 52 | */ 53 | float sdnoise3( float x, float y, float z, 54 | float *dnoise_dx, float *dnoise_dy, float *dnoise_dz ); 55 | 56 | /** 4D simplex noise with derivatives. 57 | * If the last four arguments are not null, the analytic derivative 58 | * (the 4D gradient of the scalar noise field) is also calculated. 59 | */ 60 | float sdnoise4( float x, float y, float z, float w, 61 | float *dnoise_dx, float *dnoise_dy, 62 | float *dnoise_dz, float *dnoise_dw); 63 | -------------------------------------------------------------------------------- /include/craftd/Plugins.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2011 Kevin M. Bowling, , USA 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef CRAFTD_PLUGINS_H 27 | #define CRAFTD_PLUGINS_H 28 | 29 | #include 30 | 31 | #include 32 | 33 | struct _CDServer; 34 | 35 | /** 36 | * The Plugins class. 37 | */ 38 | typedef struct _CDPlugins { 39 | struct _CDServer* server; 40 | 41 | CDHash* items; 42 | 43 | lt_dladvise advise; 44 | } CDPlugins; 45 | 46 | /** 47 | * Create a Plugins object on the given Server 48 | * 49 | * @param server The server the Plugins will run on 50 | * 51 | * @return THe instantiated Plugins object 52 | */ 53 | CDPlugins* CD_CreatePlugins (struct _CDServer* server); 54 | 55 | /** 56 | * Destroy a Plugins object 57 | */ 58 | void CD_DestroyPlugins (CDPlugins* self); 59 | 60 | /** 61 | * Load plugins referenced in the Config 62 | */ 63 | bool CD_LoadPlugins (CDPlugins* self); 64 | 65 | /** 66 | * Load a Plugin from the given path and save it as loaded plugin. 67 | * 68 | * @param path The path to the plugin 69 | */ 70 | CDPlugin* CD_LoadPlugin (CDPlugins* self, const char* name); 71 | 72 | CDPlugin* CD_GetPlugin (CDPlugins* self, const char* name); 73 | 74 | void CD_UnloadPlugin (CDPlugins* self, const char* name); 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /plugins/httpd/htdocs/LICENSES.txt: -------------------------------------------------------------------------------- 1 | htdocs/LICENSE 2 | 3 | The craftd software contains code written by third parties. Such 4 | software will have its own individual license file in the directory in 5 | which it appears. This file will describe the copyrights, license, and 6 | restrictions which apply to that code. 7 | 8 | * craftd content is licensed under the Simplified BSD License. 9 | * jquery dual licensed; we prefer the MIT license http://jquery.org/license 10 | * html5reset was released to the public domain: http://html5doctor.com/html-5-reset-stylesheet/ 11 | * 960 grid system is dual licensed; we prefer the MIT license: http://960.gs 12 | 13 | ============================================================================= 14 | craftd Simplified BSD License, see http://www.opensource.org/licenses/ 15 | ----------------------------------------------------------------------------- 16 | Copyright (c) 2010-2011 Kevin M. Bowling, , USA 17 | All rights reserved. 18 | 19 | Redistribution and use in source and binary forms, with or without 20 | modification, are permitted provided that the following conditions are met: 21 | 22 | * Redistributions of source code must retain the above copyright notice, 23 | this list of conditions and the following disclaimer. 24 | * Redistributions in binary form must reproduce the above copyright 25 | notice, this list of conditions and the following disclaimer in the 26 | documentation and/or other materials provided with the distribution. 27 | * Neither the name of the Swiss Federal Institute of Technology Zurich 28 | nor the names of its contributors may be used to endorse or promote 29 | products derived from this software without specific prior written 30 | permission. 31 | 32 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 33 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 34 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 35 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 36 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 37 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 38 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 39 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 40 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 41 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 42 | POSSIBILITY OF SUCH DAMAGE. 43 | ============================================================================= 44 | -------------------------------------------------------------------------------- /include/craftd/Client.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2011 Kevin M. Bowling, , USA 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef CRAFTD_CLIENT_H 27 | #define CRAFTD_CLIENT_H 28 | 29 | #include 30 | 31 | struct _CDServer; 32 | 33 | typedef enum _CDClientStatus { 34 | CDClientConnect, 35 | CDClientIdle, 36 | CDClientProcess, 37 | CDClientDisconnect 38 | } CDClientStatus; 39 | 40 | typedef struct _CDClient { 41 | struct _CDServer* server; 42 | 43 | char ip[128]; 44 | evutil_socket_t socket; 45 | CDBuffers* buffers; 46 | 47 | CDClientStatus status; 48 | uint8_t jobs; 49 | 50 | struct { 51 | pthread_rwlock_t status; 52 | } lock; 53 | 54 | CD_DEFINE_DYNAMIC; 55 | CD_DEFINE_ERROR; 56 | } CDClient; 57 | 58 | /** 59 | * Create a Client object on the given Server. 60 | * 61 | * @param server The Server the Client will play on 62 | * 63 | * @return The instantiated Client object 64 | */ 65 | CDClient* CD_CreateClient (struct _CDServer* server); 66 | 67 | /** 68 | * Destroy a Client object 69 | */ 70 | void CD_DestroyClient (CDClient* self); 71 | 72 | /** 73 | * Send a raw String to a Client 74 | * 75 | * @param data The raw String to send 76 | */ 77 | void CD_ClientSendBuffer (CDClient* self, CDBuffer* data); 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /third-party/bstring/bsafe.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This source file is part of the bstring string library. This code was 3 | * written by Paul Hsieh in 2002-2010, and is covered by either the 3-clause 4 | * BSD open source license or GPL v2.0. Refer to the accompanying documentation 5 | * for details on usage and license. 6 | */ 7 | 8 | /* 9 | * bsafe.c 10 | * 11 | * This is an optional module that can be used to help enforce a safety 12 | * standard based on pervasive usage of bstrlib. This file is not necessarily 13 | * portable, however, it has been tested to work correctly with Intel's C/C++ 14 | * compiler, WATCOM C/C++ v11.x and Microsoft Visual C++. 15 | */ 16 | 17 | #include 18 | #include 19 | #include "bsafe.h" 20 | 21 | static int bsafeShouldExit = 1; 22 | 23 | char * strcpy (char *dst, const char *src); 24 | char * strcat (char *dst, const char *src); 25 | 26 | char * strcpy (char *dst, const char *src) { 27 | dst = dst; 28 | src = src; 29 | fprintf (stderr, "bsafe error: strcpy() is not safe, use bstrcpy instead.\n"); 30 | if (bsafeShouldExit) exit (-1); 31 | return NULL; 32 | } 33 | 34 | char * strcat (char *dst, const char *src) { 35 | dst = dst; 36 | src = src; 37 | fprintf (stderr, "bsafe error: strcat() is not safe, use bstrcat instead.\n"); 38 | if (bsafeShouldExit) exit (-1); 39 | return NULL; 40 | } 41 | 42 | #if !defined (__GNUC__) && (!defined(_MSC_VER) || (_MSC_VER <= 1310)) 43 | char * (gets) (char * buf) { 44 | buf = buf; 45 | fprintf (stderr, "bsafe error: gets() is not safe, use bgets.\n"); 46 | if (bsafeShouldExit) exit (-1); 47 | return NULL; 48 | } 49 | #endif 50 | 51 | char * (strncpy) (char *dst, const char *src, size_t n) { 52 | dst = dst; 53 | src = src; 54 | n = n; 55 | fprintf (stderr, "bsafe error: strncpy() is not safe, use bmidstr instead.\n"); 56 | if (bsafeShouldExit) exit (-1); 57 | return NULL; 58 | } 59 | 60 | char * (strncat) (char *dst, const char *src, size_t n) { 61 | dst = dst; 62 | src = src; 63 | n = n; 64 | fprintf (stderr, "bsafe error: strncat() is not safe, use bstrcat then btrunc\n\tor cstr2tbstr, btrunc then bstrcat instead.\n"); 65 | if (bsafeShouldExit) exit (-1); 66 | return NULL; 67 | } 68 | 69 | char * (strtok) (char *s1, const char *s2) { 70 | s1 = s1; 71 | s2 = s2; 72 | fprintf (stderr, "bsafe error: strtok() is not safe, use bsplit or bsplits instead.\n"); 73 | if (bsafeShouldExit) exit (-1); 74 | return NULL; 75 | } 76 | 77 | char * (strdup) (const char *s) { 78 | s = s; 79 | fprintf (stderr, "bsafe error: strdup() is not safe, use bstrcpy.\n"); 80 | if (bsafeShouldExit) exit (-1); 81 | return NULL; 82 | } 83 | -------------------------------------------------------------------------------- /include/craftd/Plugin.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2011 Kevin M. Bowling, , USA 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef CRAFTD_PLUGIN_H 27 | #define CRAFTD_PLUGIN_H 28 | 29 | #include 30 | 31 | #include 32 | #include 33 | 34 | struct _CDPlugin; 35 | struct _CDServer; 36 | 37 | /** 38 | * Callback type to initialize the Plugin 39 | */ 40 | typedef bool (*CDPluginInitializer)(struct _CDPlugin*); 41 | 42 | /** 43 | * Callback type to finalize the Plugin 44 | */ 45 | typedef bool (*CDPluginFinalizer)(struct _CDPlugin*); 46 | 47 | /** 48 | * The Plugin class. 49 | */ 50 | typedef struct _CDPlugin { 51 | struct _CDServer* server; 52 | 53 | CDString* name; 54 | CDString* description; 55 | 56 | config_t* config; 57 | 58 | lt_dlhandle handle; 59 | 60 | CDPluginInitializer initialize; 61 | CDPluginFinalizer finalize; 62 | 63 | CD_DEFINE_DYNAMIC; 64 | CD_DEFINE_ERROR; 65 | } CDPlugin; 66 | 67 | /** 68 | * Create a Plugin from a given path. 69 | * 70 | * @param server The Server the plugin will run on 71 | * @param name The name of the plugin 72 | * 73 | * @return The instantiated Plugin object 74 | */ 75 | CDPlugin* CD_CreatePlugin (struct _CDServer* server, const char* name); 76 | 77 | /** 78 | * Destroy a Plugin object 79 | */ 80 | void CD_DestroyPlugin (CDPlugin* self); 81 | 82 | #endif 83 | -------------------------------------------------------------------------------- /include/craftd/Workers.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2011 Kevin M. Bowling, , USA 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef CRAFTD_WORKERS_H 27 | #define CRAFTD_WORKERS_H 28 | 29 | #include 30 | #include 31 | 32 | #define CD_THREAD_STACK 8388608 33 | 34 | struct _CDServer; 35 | 36 | typedef struct _CDWorkers { 37 | struct _CDServer* server; 38 | 39 | int64_t last; 40 | 41 | size_t length; 42 | CDWorker** item; 43 | 44 | CDList* jobs; 45 | 46 | pthread_attr_t attributes; 47 | 48 | struct { 49 | pthread_cond_t condition; 50 | pthread_mutex_t mutex; 51 | } lock; 52 | } CDWorkers; 53 | 54 | CDWorkers* CD_CreateWorkers (struct _CDServer* server); 55 | 56 | void CD_DestroyWorkers (CDWorkers* self); 57 | 58 | void CD_StopWorkers (CDWorkers* self); 59 | 60 | CDWorker** CD_SpawnWorkers (CDWorkers* self, size_t number); 61 | 62 | void CD_KillWorkers (CDWorkers* self, size_t number); 63 | 64 | void CD_KillWorkersAvoid (CDWorkers* self, size_t number, CDWorker* worker); 65 | 66 | CDWorkers* CD_ConcatWorkers (CDWorkers* self, CDWorker** workers, size_t number); 67 | 68 | CDWorkers* CD_AppendWorker (CDWorkers* self, CDWorker* worker); 69 | 70 | bool CD_HasJobs (CDWorkers* self); 71 | 72 | void CD_AddJob (CDWorkers* self, CDJob* job); 73 | 74 | CDJob* CD_NextJob (CDWorkers* self); 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /include/craftd/Buffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2011 Kevin M. Bowling, , USA 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef CRAFTD_BUFFER_H 27 | #define CRAFTD_BUFFER_H 28 | 29 | #ifndef CRAFTD_BUFFERS_H 30 | #define CRAFTD_BUFFERS_H 31 | #include 32 | #undef CRAFTD_BUFFERS_H 33 | #else 34 | #include 35 | #endif 36 | 37 | typedef struct evbuffer* CDRawBuffer; 38 | 39 | typedef struct _CDBuffer { 40 | CDRawBuffer raw; 41 | 42 | bool external; 43 | } CDBuffer; 44 | 45 | /** 46 | * Create an empty Buffer object 47 | * 48 | * @return The instantiated Buffer object 49 | */ 50 | CDBuffer* CD_CreateBuffer (void); 51 | 52 | /** 53 | * Wrap an existing raw buffer (struct evbuffer*) into a Buffer object 54 | * 55 | * @return The instantiated Buffer object 56 | */ 57 | CDBuffer* CD_WrapBuffer (CDRawBuffer buffer); 58 | 59 | void CD_DestroyBuffer (CDBuffer* self); 60 | 61 | CDPointer CD_BufferContent (CDBuffer* self); 62 | 63 | size_t CD_BufferLength (CDBuffer* self); 64 | 65 | bool CD_BufferEmpty (CDBuffer* self); 66 | 67 | int CD_BufferDrain (CDBuffer* self, size_t length); 68 | 69 | void CD_BufferAdd (CDBuffer* self, CDPointer data, size_t length); 70 | 71 | void CD_BufferAddBuffer (CDBuffer* self, CDBuffer* data); 72 | 73 | CDPointer CD_BufferRemove (CDBuffer* self, size_t length); 74 | 75 | CDBuffer* CD_BufferRemoveBuffer (CDBuffer* self); 76 | 77 | #endif 78 | -------------------------------------------------------------------------------- /src/Buffers.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2011 Kevin M. Bowling, , USA 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #include 27 | 28 | CDBuffers* 29 | CD_CreateBuffers (void) 30 | { 31 | CDBuffers* self = CD_malloc(sizeof(CDBuffers)); 32 | 33 | self->input = CD_CreateBuffer(); 34 | self->output = CD_CreateBuffer(); 35 | 36 | self->raw = NULL; 37 | self->external = false; 38 | 39 | return self; 40 | } 41 | 42 | CDBuffers* 43 | CD_WrapBuffers (CDRawBuffers buffers) 44 | { 45 | CDBuffers* self = CD_malloc(sizeof(CDBuffers)); 46 | 47 | self->input = CD_WrapBuffer(bufferevent_get_input(buffers)); 48 | self->output = CD_WrapBuffer(bufferevent_get_output(buffers)); 49 | 50 | self->raw = buffers; 51 | self->external = true; 52 | 53 | return self; 54 | } 55 | 56 | void 57 | CD_DestroyBuffers (CDBuffers* self) 58 | { 59 | assert(self); 60 | 61 | CD_DestroyBuffer(self->input); 62 | CD_DestroyBuffer(self->output); 63 | 64 | CD_free(self); 65 | } 66 | 67 | void 68 | CD_BufferReadIn (CDBuffers* self, size_t low, size_t high) 69 | { 70 | assert(self); 71 | 72 | if (high == 0) { 73 | high = CD_DEFAULT_HIGH_WATERMARK; 74 | } 75 | 76 | bufferevent_setwatermark(self->raw, EV_READ, low, high); 77 | } 78 | 79 | void 80 | CD_BuffersFlush (CDBuffers* self) 81 | { 82 | bufferevent_flush(self->raw, EV_READ | EV_WRITE, BEV_FLUSH); 83 | } 84 | -------------------------------------------------------------------------------- /plugins/httpd/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2011 Kevin M. Bowling, , USA 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #include 27 | #include 28 | 29 | #include "include/HTTPd.h" 30 | 31 | static 32 | bool 33 | cdhttp_ServerStart (CDServer* server) 34 | { 35 | CDHTTPd* httpd = (CDHTTPd*) CD_DynamicGet(server, "HTTPd.instance"); 36 | 37 | pthread_create(&httpd->thread, &httpd->attributes, (void *(*)(void *)) CD_RunHTTPd, httpd); 38 | 39 | return true; 40 | } 41 | 42 | static 43 | bool 44 | cdhttp_ServerStop (CDServer* server) 45 | { 46 | CDHTTPd* httpd = (CDHTTPd*) CD_DynamicGet(server, "HTTPd.instance"); 47 | 48 | CD_StopHTTPd(httpd); 49 | 50 | return true; 51 | } 52 | 53 | extern 54 | bool 55 | CD_PluginInitialize (CDPlugin* self) 56 | { 57 | self->description = CD_CreateStringFromCString("Web Interface and RPC"); 58 | 59 | CD_DynamicPut(self->server, "HTTPd.instance", (CDPointer) CD_CreateHTTPd(self)); 60 | 61 | CD_EventRegister(self->server, "Server.start!", cdhttp_ServerStart); 62 | CD_EventRegister(self->server, "Server.stop!", cdhttp_ServerStop); 63 | 64 | 65 | return true; 66 | } 67 | 68 | extern 69 | bool 70 | CD_PluginFinalize (CDPlugin* self) 71 | { 72 | CD_DestroyHTTPd((CDHTTPd*) CD_DynamicDelete(self->server, "HTTPd.instance")); 73 | 74 | CD_EventUnregister(self->server, "Server.start!", cdhttp_ServerStart); 75 | CD_EventUnregister(self->server, "Server.stop!", cdhttp_ServerStop); 76 | 77 | return true; 78 | } 79 | -------------------------------------------------------------------------------- /include/craftd/ScriptingEngines.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2011 Kevin M. Bowling, , USA 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef CRAFTD_SCRIPTINGENGINES_H 27 | #define CRAFTD_SCRIPTINGENGINES_H 28 | 29 | #include 30 | 31 | #include 32 | 33 | struct _CDServer; 34 | 35 | /** 36 | * The ScriptingEngines class. 37 | */ 38 | typedef struct _CDScriptingEngines { 39 | struct _CDServer* server; 40 | 41 | CDHash* items; 42 | 43 | lt_dladvise advise; 44 | } CDScriptingEngines; 45 | 46 | /** 47 | * Create a ScriptingEngines object on the given Server 48 | * 49 | * @param server The server the ScriptingEngines will run on 50 | * 51 | * @return THe instantiated ScriptingEngines object 52 | */ 53 | CDScriptingEngines* CD_CreateScriptingEngines (struct _CDServer* server); 54 | 55 | /** 56 | * Destroy a ScriptingEngines object 57 | */ 58 | void CD_DestroyScriptingEngines (CDScriptingEngines* self); 59 | 60 | /** 61 | * Load scripting engines referenced in the Config 62 | */ 63 | bool CD_LoadScriptingEngines (CDScriptingEngines* self); 64 | 65 | /** 66 | * Load a ScriptingEngine from the given path and save it as loaded plugin. 67 | * 68 | * @param path The path to the plugin 69 | */ 70 | CDScriptingEngine* CD_LoadScriptingEngine (CDScriptingEngines* self, const char* name); 71 | 72 | CDScriptingEngine* CD_GetScriptingEngine (CDScriptingEngines* self, const char* name); 73 | 74 | void CD_UnloadScriptingEngine (CDScriptingEngines* self, const char* name); 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ### 2 | # craftd .gitignore 3 | # Last update: November 22, 2010 4 | # Author: github + mods by Kevin Bowling 5 | # https://github.com/github/gitignore 6 | ### 7 | 8 | ## Binaries and generated 9 | /craftd 10 | /src/craftd 11 | /craftd.conf.dist 12 | 13 | ## C 14 | # Compiled Object files 15 | *.slo 16 | *.lo 17 | *.o 18 | 19 | # Compiled Dynamic libraries 20 | *.so 21 | 22 | # Compiled Static libraries 23 | *.lai 24 | *.la 25 | *.a 26 | 27 | # Windows 28 | *.obj 29 | *.exe 30 | *.lib 31 | 32 | ## Autotools 33 | # http://www.gnu.org/software/automake 34 | Makefile.in 35 | .deps 36 | 37 | # http://www.gnu.org/software/autoconf 38 | # Check build-aux/.gitignore for the commented stuff 39 | /autom4te.cache 40 | /aclocal.m4 41 | /build/auto/configaux/ 42 | /configure 43 | /config.guess 44 | /config.log 45 | /config.status 46 | /config.sub 47 | config.h 48 | /include/craftd/config.h.in 49 | stamp-h1 50 | Makefile 51 | 52 | # libtool 53 | /libtool 54 | /build/auto/m4/libtool.m4 55 | /build/auto/m4/ltoptions.m4 56 | /build/auto/m4/ltsugar.m4 57 | /build/auto/m4/ltversion.m4 58 | /build/auto/m4/lt~obsolete.m4 59 | 60 | ## Editors 61 | # Eclipse 62 | *.pydevproject 63 | .project 64 | .metadata 65 | bin/** 66 | tmp/** 67 | tmp/**/* 68 | *.tmp 69 | *.bak 70 | *.swp 71 | *~.nib 72 | local.properties 73 | .classpath 74 | .settings/ 75 | .loadpath 76 | .cproject 77 | 78 | # emacs 79 | *~ 80 | \#*\# 81 | /.emacs.desktop 82 | /.emacs.desktop.lock 83 | 84 | # Linux 85 | .* 86 | *~ 87 | *.sw[a-p] 88 | # KDE 89 | .directory 90 | 91 | # NetBeans 92 | nbproject/ 93 | 94 | # OS X 95 | .DS_Store? 96 | Icon? 97 | # Thumbnails 98 | ._* 99 | # Files that might appear on external disk 100 | .Spotlight-V100 101 | .Trashes 102 | *.tmproj 103 | tmtags 104 | 105 | # vim 106 | .*.sw[a-z] 107 | *.un~ 108 | 109 | # KDevelop 4 110 | *.kdev4 111 | 112 | # Windows 113 | Thumbs.db 114 | Desktop.ini 115 | 116 | ## Visual Studio 117 | # Ignore Visual Studio temporary files, build results, and 118 | # files generated by popular Visual Studio add-ons. 119 | 120 | # User-specific files 121 | *.suo 122 | *.user 123 | 124 | # Build results 125 | Debug/ 126 | Release/ 127 | *.ncb 128 | *.aps 129 | *.obj 130 | .builds 131 | 132 | # ReSharper is a .NET coding add-in 133 | _ReSharper* 134 | 135 | # DocProject is a documentation generator add-in 136 | DocProject/buildhelp/ 137 | DocProject/Help/*.HxT 138 | DocProject/Help/*.HxC 139 | DocProject/Help/*.hhc 140 | DocProject/Help/*.hhk 141 | DocProject/Help/*.hhp 142 | DocProject/Help/Html2 143 | DocProject/Help/html 144 | 145 | # Click-Once directory 146 | publish 147 | 148 | # Others 149 | dox 150 | bin 151 | Bin 152 | obj 153 | Obj 154 | sql 155 | TestResults 156 | *.Cache 157 | ClientBin 158 | stylecop.* 159 | ~$* 160 | *.dbmdl 161 | test 162 | mkmf.log 163 | config.h 164 | conftest* 165 | *.fas 166 | -------------------------------------------------------------------------------- /src/Client.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2011 Kevin M. Bowling, , USA 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #include 27 | #include 28 | 29 | CDClient* 30 | CD_CreateClient (CDServer* server) 31 | { 32 | CDClient* self = CD_malloc(sizeof(CDClient)); 33 | 34 | if (pthread_rwlock_init(&self->lock.status, NULL) != 0) { 35 | CD_abort("pthread rwlock failed to initialize"); 36 | } 37 | 38 | self->server = server; 39 | 40 | self->status = CDClientConnect; 41 | self->jobs = 0; 42 | 43 | self->buffers = NULL; 44 | 45 | DYNAMIC(self) = CD_CreateDynamic(); 46 | ERROR(self) = CDNull; 47 | 48 | return self; 49 | } 50 | 51 | void 52 | CD_DestroyClient (CDClient* self) 53 | { 54 | assert(self); 55 | 56 | CD_EventDispatch(self->server, "Client.destroy", self); 57 | 58 | if (self->buffers) { 59 | bufferevent_flush(self->buffers->raw, EV_READ | EV_WRITE, BEV_FINISHED); 60 | bufferevent_disable(self->buffers->raw, EV_READ | EV_WRITE); 61 | bufferevent_free(self->buffers->raw); 62 | 63 | CD_DestroyBuffers(self->buffers); 64 | } 65 | 66 | CD_DestroyDynamic(DYNAMIC(self)); 67 | 68 | pthread_rwlock_destroy(&self->lock.status); 69 | 70 | CD_free(self); 71 | } 72 | 73 | void 74 | CD_ClientSendBuffer (CDClient* self, CDBuffer* buffer) 75 | { 76 | assert(self); 77 | assert(buffer); 78 | 79 | if (!self->buffers) { 80 | return; 81 | } 82 | 83 | CD_BufferAddBuffer(self->buffers->output, buffer); 84 | 85 | CD_BuffersFlush(self->buffers); 86 | } 87 | -------------------------------------------------------------------------------- /include/craftd/ScriptingEngine.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2011 Kevin M. Bowling, , USA 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef CRAFTD_SCRIPTINGENGINE_H 27 | #define CRAFTD_SCRIPTINGENGINE_H 28 | 29 | #include 30 | 31 | #include 32 | #include 33 | 34 | struct _CDScriptingEngine; 35 | struct _CDServer; 36 | 37 | /** 38 | * Callback type to initialize the ScriptingEngine 39 | */ 40 | typedef bool (*CDScriptingEngineInitializer)(struct _CDScriptingEngine*); 41 | 42 | /** 43 | * Callback type to finalize the ScriptingEngine 44 | */ 45 | typedef bool (*CDScriptingEngineFinalizer)(struct _CDScriptingEngine*); 46 | 47 | /** 48 | * The ScriptingEngine class. 49 | */ 50 | typedef struct _CDScriptingEngine { 51 | struct _CDServer* server; 52 | 53 | CDString* name; 54 | CDString* description; 55 | 56 | config_t* config; 57 | 58 | lt_dlhandle handle; 59 | 60 | CDScriptingEngineInitializer initialize; 61 | CDScriptingEngineFinalizer finalize; 62 | 63 | CD_DEFINE_DYNAMIC; 64 | CD_DEFINE_ERROR; 65 | } CDScriptingEngine; 66 | 67 | /** 68 | * Create a ScriptingEngine from a given path. 69 | * 70 | * @param server The Server the scripting engine will run on 71 | * @param name The name of the scripting engine 72 | * 73 | * @return The instantiated ScriptingEngine object 74 | */ 75 | CDScriptingEngine* CD_CreateScriptingEngine (struct _CDServer* server, const char* name); 76 | 77 | /** 78 | * Destroy a ScriptingEngine object 79 | */ 80 | void CD_DestroyScriptingEngine (CDScriptingEngine* self); 81 | 82 | #endif 83 | -------------------------------------------------------------------------------- /plugins/survival/commands/admin/src/workers.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2011 Kevin M. Bowling, , USA 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | if (CD_StringIsEqual(matches->item[1], "workers")) { 27 | if (!cdadmin_AuthLevelIsEnoughWithMessage(player, CDLevelAdmin)) { 28 | goto done; 29 | } 30 | 31 | if (!matches->item[2]) { 32 | cdadmin_SendResponse(player, CD_CreateStringFromFormat("There are %d workers running.", 33 | server->workers->length)); 34 | } 35 | else { 36 | int workers = atoi(CD_StringContent(matches->item[2])); 37 | 38 | if (workers <= 0) { 39 | cdadmin_SendFailure(player, CD_CreateStringFromCString("You can have 1 worker at minimum")); 40 | goto done; 41 | } 42 | 43 | if (workers > server->workers->length) { 44 | CD_free(CD_SpawnWorkers(server->workers, workers - server->workers->length)); 45 | } 46 | else if (workers < server->workers->length) { 47 | for (size_t i = 0; i < server->workers->length; i++) { 48 | if (!server->workers->item[i]->job || server->workers->item[i]->job->type != CDClientProcessJob) { 49 | continue; 50 | } 51 | 52 | if (((CDClientProcessJobData*) server->workers->item[i]->job->data)->client == player->client) { 53 | CD_KillWorkersAvoid(server->workers, server->workers->length - workers, server->workers->item[i]); 54 | break; 55 | } 56 | } 57 | } 58 | } 59 | 60 | goto done; 61 | } 62 | -------------------------------------------------------------------------------- /plugins/httpd/htdocs/css/jquery.jqplot.min.css: -------------------------------------------------------------------------------- 1 | .jqplot-target{position:relative;color:#666;font-size:1em;}.jqplot-axis{font-size:.75em;}.jqplot-xaxis{margin-top:10px;}.jqplot-x2axis{margin-bottom:10px;}.jqplot-yaxis{margin-right:10px;}.jqplot-y2axis,.jqplot-y3axis,.jqplot-y4axis,.jqplot-y5axis,.jqplot-y6axis,.jqplot-y7axis,.jqplot-y8axis,.jqplot-y9axis{margin-left:10px;margin-right:10px;}.jqplot-axis-tick,.jqplot-xaxis-tick,.jqplot-yaxis-tick,.jqplot-x2axis-tick,.jqplot-y2axis-tick,.jqplot-y3axis-tick,.jqplot-y4axis-tick,.jqplot-y5axis-tick,.jqplot-y6axis-tick,.jqplot-y7axis-tick,.jqplot-y8axis-tick,.jqplot-y9axis-tick{position:absolute;}.jqplot-xaxis-tick{top:0;left:15px;vertical-align:top;}.jqplot-x2axis-tick{bottom:0;left:15px;vertical-align:bottom;}.jqplot-yaxis-tick{right:0;top:15px;text-align:right;}.jqplot-y2axis-tick,.jqplot-y3axis-tick,.jqplot-y4axis-tick,.jqplot-y5axis-tick,.jqplot-y6axis-tick,.jqplot-y7axis-tick,.jqplot-y8axis-tick,.jqplot-y9axis-tick{left:0;top:15px;text-align:left;}.jqplot-meterGauge-tick{font-size:.75em;color:#999;}.jqplot-meterGauge-label{font-size:1em;color:#999;}.jqplot-xaxis-label{margin-top:10px;font-size:11pt;position:absolute;}.jqplot-x2axis-label{margin-bottom:10px;font-size:11pt;position:absolute;}.jqplot-yaxis-label{margin-right:10px;font-size:11pt;position:absolute;}.jqplot-y2axis-label,.jqplot-y3axis-label,.jqplot-y4axis-label,.jqplot-y5axis-label,.jqplot-y6axis-label,.jqplot-y7axis-label,.jqplot-y8axis-label,.jqplot-y9axis-label{font-size:11pt;position:absolute;}table.jqplot-table-legend{margin-top:12px;margin-bottom:12px;margin-left:12px;margin-right:12px;}table.jqplot-table-legend,table.jqplot-cursor-legend{background-color:rgba(255,255,255,0.6);border:1px solid #ccc;position:absolute;font-size:.75em;}td.jqplot-table-legend{vertical-align:middle;}td.jqplot-seriesToggle:hover,td.jqplot-seriesToggle:active{cursor:pointer;}td.jqplot-table-legend>div{border:1px solid #ccc;padding:1px;}div.jqplot-table-legend-swatch{width:0;height:0;border-top-width:5px;border-bottom-width:5px;border-left-width:6px;border-right-width:6px;border-top-style:solid;border-bottom-style:solid;border-left-style:solid;border-right-style:solid;}.jqplot-title{top:0;left:0;padding-bottom:.5em;font-size:1.2em;}table.jqplot-cursor-tooltip{border:1px solid #ccc;font-size:.75em;}.jqplot-cursor-tooltip{border:1px solid #ccc;font-size:.75em;white-space:nowrap;background:rgba(208,208,208,0.5);padding:1px;}.jqplot-highlighter-tooltip{border:1px solid #ccc;font-size:.75em;white-space:nowrap;background:rgba(208,208,208,0.5);padding:1px;}.jqplot-point-label{font-size:.75em;z-index:2;}td.jqplot-cursor-legend-swatch{vertical-align:middle;text-align:center;}div.jqplot-cursor-legend-swatch{width:1.2em;height:.7em;}.jqplot-error{text-align:center;}.jqplot-error-message{position:relative;top:46%;display:inline-block;}div.jqplot-bubble-label{font-size:.8em;padding-left:2px;padding-right:2px;color:rgb(20%,20%,20%);}div.jqplot-bubble-label.jqplot-bubble-label-highlight{background:rgba(90%,90%,90%,0.7);} -------------------------------------------------------------------------------- /src/Job.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2011 Kevin M. Bowling, , USA 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #include 27 | 28 | CDJob* 29 | CD_CreateJob (CDJobType type, CDPointer data) 30 | { 31 | CDJob* self = CD_malloc(sizeof(CDJob)); 32 | 33 | self->type = type; 34 | self->data = data; 35 | self->external = false; 36 | 37 | return self; 38 | } 39 | 40 | CDJob* 41 | CD_CreateExternalJob (CDJobType type, CDPointer data) 42 | { 43 | CDJob* self = CD_malloc(sizeof(CDJob)); 44 | 45 | self->type = type; 46 | self->data = data; 47 | self->external = true; 48 | 49 | return self; 50 | } 51 | 52 | void 53 | CD_DestroyJob (CDJob* self) 54 | { 55 | assert(self); 56 | 57 | if (!self->external && self->data) { 58 | CD_free((void*) self->data); 59 | } 60 | 61 | CD_free(self); 62 | } 63 | 64 | CDPointer 65 | CD_DestroyJobKeepData (CDJob* self) 66 | { 67 | assert(self); 68 | 69 | CDPointer result = self->data; 70 | 71 | CD_free(self); 72 | 73 | return result; 74 | } 75 | 76 | CDCustomJobData* 77 | CD_CreateCustomJob (CDCustomJobCallback callback, CDPointer data) 78 | { 79 | CDCustomJobData* self = CD_malloc(sizeof(CDCustomJobData)); 80 | 81 | self->callback = callback; 82 | self->data = data; 83 | 84 | return self; 85 | } 86 | 87 | CDClientProcessJobData* 88 | CD_CreateClientProcessJob (CDClient* client, void* packet) 89 | { 90 | CDClientProcessJobData* self = CD_malloc(sizeof(CDClientProcessJobData)); 91 | 92 | self->client = client; 93 | self->packet = packet; 94 | 95 | return self; 96 | } 97 | -------------------------------------------------------------------------------- /include/craftd/Job.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2011 Kevin M. Bowling, , USA 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef CRAFTD_JOB_H 27 | #define CRAFTD_JOB_H 28 | 29 | #include 30 | 31 | #include 32 | 33 | typedef enum _CDJobType { 34 | CDClientConnectJob, 35 | CDClientProcessJob, 36 | CDClientDisconnectJob, 37 | 38 | CDCustomJob 39 | } CDJobType; 40 | 41 | #define CD_JOB_IS_CUSTOM(job) ( \ 42 | job->type == CDCustomJob \ 43 | ) 44 | 45 | #define CD_JOB_IS_PLAYER(job) ( \ 46 | job->type == CDClientConnectJob \ 47 | || job->type == CDClientProcessJob \ 48 | || job->type == CDClientDisconnectJob \ 49 | ) 50 | 51 | typedef void (*CDCustomJobCallback) (CDPointer); 52 | 53 | typedef struct _CDCustomJobData { 54 | CDCustomJobCallback callback; 55 | CDPointer data; 56 | } CDCustomJobData; 57 | 58 | typedef struct _CDClientProcessJobData { 59 | CDClient* client; 60 | void* packet; 61 | } CDClientProcessJobData; 62 | 63 | typedef struct _CDJob { 64 | CDJobType type; 65 | CDPointer data; 66 | 67 | bool external; 68 | } CDJob; 69 | 70 | CDJob* CD_CreateJob (CDJobType type, CDPointer data); 71 | 72 | CDJob* CD_CreateExternalJob (CDJobType type, CDPointer data); 73 | 74 | void CD_DestroyJob (CDJob* job); 75 | 76 | void CD_DestroyJobData (CDJob* job); 77 | 78 | CDPointer CD_DestroyJobKeepData (CDJob* job); 79 | 80 | CDCustomJobData* CD_CreateCustomJob (CDCustomJobCallback callback, CDPointer data); 81 | 82 | CDClientProcessJobData* CD_CreateClientProcessJob (CDClient* client, void* packet); 83 | 84 | #endif 85 | -------------------------------------------------------------------------------- /include/craftd/Regexp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2011 Kevin M. Bowling, , USA 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef CRAFTD_REGEXP_H 27 | #define CRAFTD_REGEXP_H 28 | 29 | #include 30 | 31 | typedef enum _CDRegexpOption { 32 | CDRegexpNone = 0, 33 | CDRegexpCaseInsensitive = PCRE_CASELESS, 34 | CDRegexpExtended = PCRE_EXTENDED, 35 | CDRegexpMultiline = PCRE_MULTILINE, 36 | CDRegexpDotAll = PCRE_DOTALL 37 | } CDRegexpOption; 38 | 39 | #define CD_REGEXP_I PCRE_CASELESS 40 | #define CD_REGEXP_X PCRE_EXTENDED 41 | #define CD_REGEXP_M PCRE_MULTILINE 42 | #define CD_REGEXP_S PCRE_DOTALL 43 | 44 | #include 45 | 46 | typedef struct _CDRegexp { 47 | char* string; 48 | int options; 49 | 50 | pcre* pattern; 51 | pcre_extra* study; 52 | } CDRegexp; 53 | 54 | typedef struct _CDRegexpMatches { 55 | size_t matched; 56 | 57 | size_t length; 58 | CDString** item; 59 | } CDRegexpMatches; 60 | 61 | CDRegexp* CD_CreateRegexp (char* regexp, int options); 62 | 63 | void CD_DestroyRegexp (CDRegexp* self); 64 | 65 | void CD_DestroyRegexpKeepString (CDRegexp* self); 66 | 67 | CDRegexpMatches* CD_CreateRegexpMatches (size_t length); 68 | 69 | void CD_DestroyRegexpMatches (CDRegexpMatches* self); 70 | 71 | CDRegexpMatches* CD_RegexpMatch (CDRegexp* self, CDString* string); 72 | 73 | CDRegexpMatches* CD_RegexpMatchString (char* regexp, int options, CDString* string); 74 | 75 | CDRegexpMatches* CD_RegexpMatchCString (char* regexp, int options, char* string); 76 | 77 | bool CD_RegexpTest (CDRegexp* self, CDString* string); 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | Welcome to craftd! Up to date documentation lives at: 2 | http://mc.kev009.com/craftd/ 3 | 4 | Need help? Want to help? Come talk! irc.freenode.net #craftd. 5 | 6 | This is early, pre-alpha software. If you aren't familiar with autotools, 7 | please wait until binary packages are available. 8 | 9 | Dependencies: 10 | libevent 2.0.9+ - http://monkey.org/~provos/libevent/ 11 | zlib 1.2.3+ - http://zlib.net/ 12 | jansson 2.0+ - http://www.digip.org/jansson/ 13 | pthreads 14 | 15 | Successfully built on: 16 | Linux - GCC, LLVM/clang 17 | FreeBSD - GCC 18 | IRIX - MIPSpro (Big-Endian functionality verified) 19 | AIX - xlC, GCC (Big-Endian functionality verified) 20 | Windows - MinGW - Needs rework. Priority is getting basics working on UNIX. 21 | Windows - Cygwin (works great without modification) 22 | 23 | == Users == 24 | Ubuntu users can try to compile from the latest source tarball available from this 25 | server: http://bb.tkte.ch/job/craftd-ubuntu/ or use git to download from 26 | git://github.com/kev009/craftd.git. 27 | 28 | Keep in mind that this is bleeding edge and may not always be stable or usable. 29 | 30 | Ruby and Rake are the suggested way of building craftd, although a statically generated 31 | Makefile and configure script are shipped if you cannot/do not want to install Ruby and Rake. 32 | 33 | If you need to compile from the git repo, don't forget to run ./autogen.sh 34 | before heading into configuration/compilation. 35 | 36 | Once you have the source prepared you can run rake install OR ./configure, make, and make install. 37 | By default, the server binary is located at /usr/local/bin/craftd. 38 | 39 | At the moment craftd does not generate world data for a new server. You will need to 40 | provide world data from another server to start. 41 | 42 | == Developers == 43 | Please contact me and let me know what parts you intend to work on first. 44 | 45 | NOTE: You must run ./autogen.sh after checking out the git repo to generate a 46 | configure script and pull the submodules. 47 | 48 | Use `git pull` for being up to date. Should you run into build issues, try running 49 | `make distclean` and see if it helps. 50 | 51 | Developer Documentation: 52 | Coding style and architecture notes are on the wiki - 53 | http://mc.kev009.com/wiki/Craftd:Main_Page 54 | 55 | You should have a good understanding of libevent-2. 56 | http://www.wangafu.net/~nickm/libevent-book/ 57 | http://mc.kev009.com/libevent - Up to date doxygen 58 | 59 | Bundled Libs: 60 | bstring - Safer C strings - http://bstring.sourceforge.net/ 61 | klib - a standalone and lightweight C library 62 | 63 | Protocol reference: 64 | http://mc.kev009.com/wiki/ 65 | 66 | Continuous Integration Builds; 67 | http://bb.tkte.ch/job/craftd-ubuntu/ 68 | 69 | Also recommended books: 70 | * Advanced Programming in the UNIX Environment - Stevens, et. al 71 | * Programming with POSIX Threads - Butenhof 72 | * UNIX Network Programming, Vol. 1 - Stevens, et. al 73 | * A download of POSIX.1-2008 - http://www.unix.org/2008edition/ 74 | -------------------------------------------------------------------------------- /include/craftd/Arithmetic.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Adapted by Kevin M. Bowling for compiler inlining 3 | * 4 | * Contains significant code and influence from the book: 5 | * "C Interfaces and Implementations" by David R. Hanson (ISBN 0-201-49841-3) 6 | * 7 | * See https://github.com/kev009/cii/blob/master/LICENSE for the original MIT 8 | * license. 9 | */ 10 | 11 | #ifndef CRAFTD_ARITHMETIC_H 12 | #define CRAFTD_ARITHMETIC_H 13 | 14 | #define ABS(x) ((x < 0) ? -x : x) 15 | 16 | /** 17 | * Return the maximum of two values 18 | * 19 | * @param x an integer value 20 | * @param y an integer value 21 | * 22 | * @return greater of the two parameters 23 | */ 24 | static inline 25 | int 26 | CD_Max (int x, int y) 27 | { 28 | return x > y ? x : y; 29 | } 30 | 31 | /** 32 | * Return the minimum of two values 33 | * 34 | * @param x an integer value 35 | * @param y an integer value 36 | * 37 | * @return smaller of the two parameters 38 | */ 39 | static inline 40 | int 41 | CD_Min (int x, int y) 42 | { 43 | return x > y ? y : x; 44 | } 45 | 46 | /** 47 | * Perform well defined integer division 48 | * 49 | * The C standard has goofy semantics wrt negative numbers and integer division 50 | * This one always truncates toward left on number line and works as expected 51 | * 52 | * @param x the dividend 53 | * @param y the divisor 54 | * 55 | * @return the integer quotient 56 | */ 57 | static inline 58 | int 59 | CD_Div (int x, int y) 60 | { 61 | if (-13 / 5 == -2 && (x < 0) != (y < 0) && x % y != 0) { 62 | return x / y - 1; 63 | } 64 | else { 65 | return x / y; 66 | } 67 | } 68 | 69 | /** 70 | * Perform well defined modulo division 71 | * 72 | * The C standard has goofy semantics wrt negative numbers and modulo division 73 | * This one always truncates toward left on number line and works as expected 74 | * 75 | * @param x the dividend 76 | * @param y the divisor 77 | * 78 | * @return the integer quotient 79 | */ 80 | static inline 81 | int 82 | CD_Mod (int x, int y) 83 | { 84 | if (-13 / 5 == -2 && (x < 0) != (y < 0) && x % y != 0) { 85 | return x % y + y; 86 | } 87 | else { 88 | return x % y; 89 | } 90 | } 91 | 92 | /** 93 | * Perform well defined integer floor 94 | * 95 | * In the x/y, returns the integer to the left on the number line 96 | * 97 | * @param x dividend 98 | * @param y divisior 99 | * 100 | * @return floor of x/y 101 | */ 102 | static inline 103 | int 104 | CD_Floor (int x, int y) 105 | { 106 | return CD_Div(x, y); 107 | } 108 | 109 | /** 110 | * Perform well defined integer ceiling 111 | * In the x/y, returns the integer to the right on the number line 112 | * 113 | * @param x dividend 114 | * @param y divisior 115 | * 116 | * @return ceiling of x/y 117 | */ 118 | static inline 119 | int 120 | CD_Ceiling (int x, int y) 121 | { 122 | return CD_Div(x, y) + (x % y != 0); 123 | } 124 | 125 | #endif 126 | -------------------------------------------------------------------------------- /src/protocols/survival/Region.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2011 Kevin M. Bowling, , USA 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #include 27 | 28 | bool 29 | SV_IsCoordInRadius (SVChunkPosition* coord, SVChunkPosition* centerCoord, int radius) 30 | { 31 | return (coord->x >= centerCoord->x - radius && 32 | coord->x <= centerCoord->x + radius && 33 | coord->z >= centerCoord->z - radius && 34 | coord->z <= centerCoord->z + radius); 35 | } 36 | 37 | bool 38 | SV_IsDistanceGreater (SVPrecisePosition a, SVPrecisePosition b, int maxDistance) 39 | { 40 | return (abs( a.x - b.x ) > maxDistance || 41 | abs( a.y - b.y ) > maxDistance || 42 | abs( a.z - b.z ) > maxDistance); 43 | } 44 | 45 | SVRelativePosition 46 | SV_RelativeMove (SVPrecisePosition* a, SVPrecisePosition* b) 47 | { 48 | SVAbsolutePosition absoluteA = SV_PrecisePositionToAbsolutePosition(*a); 49 | SVAbsolutePosition absoluteB = SV_PrecisePositionToAbsolutePosition(*b); 50 | 51 | return (SVRelativePosition) { 52 | .x = absoluteA.x - absoluteB.x, 53 | .y = absoluteA.y - absoluteB.y, 54 | .z = absoluteA.z - absoluteB.z 55 | }; 56 | } 57 | 58 | void 59 | SV_RegionBroadcastPacket (SVPlayer* player, SVPacket* packet) 60 | { 61 | CDList* seenPlayers = (CDList*) CD_DynamicGet(player, "Player.seenPlayers"); 62 | 63 | CD_LIST_FOREACH(seenPlayers, it) { 64 | if (player == (SVPlayer*) CD_ListIteratorValue(it)) { 65 | continue; 66 | } 67 | 68 | SV_PlayerSendPacket((SVPlayer*) CD_ListIteratorValue(it), packet); 69 | } 70 | } 71 | 72 | 73 | -------------------------------------------------------------------------------- /plugins/httpd/include/HTTPd.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2011 Kevin M. Bowling, , USA 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef CRAFTD_HTTP_HTTPD_H 27 | #define CRAFTD_HTTP_HTTPD_H 28 | 29 | #include 30 | 31 | #include 32 | 33 | typedef struct _CDContentType { 34 | const char* extension; 35 | const char* mime; 36 | } CDContentType; 37 | 38 | static const CDContentType CDContentTypes[] = { 39 | { "txt", "text/plain" }, 40 | { "c", "text/plain" }, 41 | { "h", "text/plain" }, 42 | { "js", "text/javascript" }, 43 | { "html", "text/html" }, 44 | { "htm", "text/html" }, 45 | { "css", "text/css" }, 46 | { "gif", "image/gif" }, 47 | { "jpg", "image/jpeg"}, 48 | { "jpeg", "image/jpeg" }, 49 | { "png", "image/png" }, 50 | { "pdf", "application/pdf" }, 51 | { "ps", "application/postsript" }, 52 | { NULL }, 53 | }; 54 | 55 | typedef struct _CDHTTPd { 56 | CDServer* server; 57 | 58 | struct { 59 | struct event_base* base; 60 | struct evhttp* httpd; 61 | struct evhttp_bound_socket* handle; 62 | } event; 63 | 64 | struct { 65 | struct { 66 | struct { 67 | const char* ipv4; 68 | const char* ipv6; 69 | } bind; 70 | 71 | uint16_t port; 72 | } connection; 73 | 74 | const char* root; 75 | } config; 76 | 77 | pthread_t thread; 78 | pthread_attr_t attributes; 79 | } CDHTTPd; 80 | 81 | CDHTTPd* CD_CreateHTTPd (CDPlugin* plugin); 82 | 83 | void CD_DestroyHTTPd (CDHTTPd* self); 84 | 85 | void* CD_RunHTTPd (CDHTTPd* self); 86 | 87 | bool CD_StopHTTPd (CDHTTPd* self); 88 | 89 | #endif 90 | -------------------------------------------------------------------------------- /src/ConsoleLogger.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2011 Kevin M. Bowling, , USA 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #define CRAFTD_LOGGER_IGNORE_EXTERN 27 | #include 28 | #undef CRAFTD_LOGGER_IGNORE_EXTERN 29 | 30 | static int cd_mask = 0; 31 | 32 | static 33 | void 34 | cd_ConsoleLog (int priority, const char* format, ...) 35 | { 36 | /* Return on MASKed log priorities */ 37 | if (LOG_MASK(priority) & cd_mask) { 38 | return; 39 | } 40 | 41 | static const char* names[] = { 42 | "EMERG", "ALERT", "CRIT", "ERR", "WARNING", "NOTICE", "INFO", "DEBUG" 43 | }; 44 | 45 | va_list ap; 46 | va_start(ap, format); 47 | 48 | CDString* priorityBuffer; 49 | CDString* messageBuffer = CD_CreateStringFromFormatList(format, ap); 50 | 51 | if (priority >= ARRAY_SIZE(names) || priority < 0) { 52 | priorityBuffer = CD_CreateStringFromCString("UNKNOWN"); 53 | } 54 | else { 55 | priorityBuffer = CD_CreateStringFromCString(names[priority]); 56 | } 57 | 58 | printf("%s: %s\n", CD_StringContent(priorityBuffer), CD_StringContent(messageBuffer)); 59 | fflush(stdout); 60 | 61 | CD_DestroyString(priorityBuffer); 62 | CD_DestroyString(messageBuffer); 63 | 64 | va_end(ap); 65 | } 66 | 67 | static 68 | int cd_ConsoleSetLogMask (int mask) 69 | { 70 | int old = cd_mask; 71 | 72 | if (mask != 0) { 73 | cd_mask = mask; 74 | } 75 | 76 | return old; 77 | } 78 | 79 | static 80 | void cd_ConsoleCloseLog (void) 81 | { 82 | fflush(stdout); 83 | } 84 | 85 | CDLogger CDConsoleLogger = { 86 | .log = cd_ConsoleLog, 87 | .setlogmask = cd_ConsoleSetLogMask, 88 | .closelog = cd_ConsoleCloseLog 89 | }; 90 | -------------------------------------------------------------------------------- /include/craftd/protocols/survival/Player.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2011 Kevin M. Bowling, , USA 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef CRAFTD_SURVIVAL_PLAYER_H 27 | #define CRAFTD_SURVIVAL_PLAYER_H 28 | 29 | #include 30 | 31 | #include 32 | #include 33 | 34 | struct _SVWorld; 35 | 36 | /** 37 | * The Player class. 38 | */ 39 | typedef struct _SVPlayer { 40 | SVEntity entity; 41 | 42 | CDClient* client; 43 | struct _SVWorld* world; 44 | 45 | SVFloat yaw; 46 | SVFloat pitch; 47 | 48 | CDString* username; 49 | 50 | CD_DEFINE_DYNAMIC; 51 | CD_DEFINE_ERROR; 52 | } SVPlayer; 53 | 54 | /** 55 | * Create a Player object on the given Server. 56 | * 57 | * @param server The Server the Player will play on 58 | * 59 | * @return The instantiated Player object 60 | */ 61 | SVPlayer* SV_CreatePlayer (CDClient* client); 62 | 63 | /** 64 | * Destroy a Player object 65 | */ 66 | void SV_DestroyPlayer (SVPlayer* self); 67 | 68 | /** 69 | * Send a chat message to a player 70 | * 71 | * @param message The message to send 72 | */ 73 | void SV_PlayerSendMessage (SVPlayer* self, CDString* message); 74 | 75 | /** 76 | * Send a Packet to a Player 77 | * 78 | * @param packet The Packet object to send 79 | */ 80 | void SV_PlayerSendPacket (SVPlayer* self, SVPacket* packet); 81 | 82 | /** 83 | * Send a Packet to a Player and destroy the packet 84 | * 85 | * @param packet The Packet object to send 86 | */ 87 | void SV_PlayerSendPacketAndClean (SVPlayer* self, SVPacket* packet); 88 | 89 | /** 90 | * Send a Packet to a Player and destroy the packet data 91 | * 92 | * @param packet The Packet object to send 93 | */ 94 | void SV_PlayerSendPacketAndCleanData (SVPlayer* self, SVPacket* packet); 95 | 96 | #endif 97 | -------------------------------------------------------------------------------- /plugins/survival/mapgen/trivial/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2011 Kevin M. Bowling, , USA 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #include 27 | #include 28 | 29 | #include 30 | 31 | static 32 | bool 33 | cdtrivial_GenerateLevel (CDServer* server, SVWorld* world) 34 | { 35 | world->spawnPosition = (SVBlockPosition) { 36 | .x = 0, 37 | .y = 120, 38 | .z = 0 39 | }; 40 | 41 | return true; 42 | } 43 | 44 | static 45 | bool 46 | cdtrivial_GenerateChunk (CDServer* server, int x, int z, SVChunk* data, const char* seed) 47 | { 48 | int lightValue = CD_Max(0x0F - ABS(x) - ABS(z), 0); 49 | 50 | // this should only put 1 layer of bedrock 51 | for (int x = 0; x < 16; x++) { 52 | for (int z = 0; z < 16; z++) { 53 | data->blocks[(z * 128) + (x * 128 * 16)] = SVBedrock; // one layer bedrock 54 | data->heightMap[x + (z * 16)] = 1; // max height is 1 55 | 56 | for (int y = 1; y < 128; y++) { 57 | // full light for first 2 layers 58 | data->skyLight[((z * 128) + (x * 128 * 16) + y) / 2] = (lightValue | (lightValue << 4)); 59 | } 60 | } 61 | } 62 | 63 | return false; 64 | } 65 | 66 | extern 67 | bool 68 | CD_PluginInitialize (CDPlugin* self) 69 | { 70 | self->description = CD_CreateStringFromCString("Trivial Mapgen"); 71 | 72 | CD_EventRegister(self->server, "Mapgen.level", cdtrivial_GenerateLevel); 73 | CD_EventRegister(self->server, "Mapgen.chunk", cdtrivial_GenerateChunk); 74 | 75 | return true; 76 | } 77 | 78 | extern 79 | bool 80 | CD_PluginFinalize (CDPlugin* self) 81 | { 82 | CD_EventUnregister(self->server, "Mapgen.level", cdtrivial_GenerateLevel); 83 | CD_EventUnregister(self->server, "Mapgen.chunk", cdtrivial_GenerateChunk); 84 | 85 | return true; 86 | } 87 | -------------------------------------------------------------------------------- /include/craftd/common.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2011 Kevin M. Bowling, , USA 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef CRAFTD_COMMON_H 27 | #define CRAFTD_COMMON_H 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | 44 | #include 45 | 46 | #define ARRAY_SIZE(array) (sizeof(array) / sizeof(*array)) 47 | 48 | #define DO \ 49 | for (char __cddo_tmp__ = 0; __cddo_tmp__ == 0; __cddo_tmp__++) 50 | 51 | #include 52 | #include 53 | #include 54 | #include 55 | #include 56 | 57 | #include 58 | 59 | #ifdef SIZEOF_FP 60 | # define SIZEOF_FUNCTION_POINTER SIZEOF_FP 61 | #endif 62 | 63 | #ifdef SIZEOF_INTPTR_T 64 | # define SIZEOF_POINTER SIZEOF_INTPTR_T 65 | #endif 66 | 67 | #if SIZEOF_FUNCTION_POINTER == 4 && SIZEOF_POINTER == 4 68 | typedef int32_t CDPointer; 69 | #else 70 | typedef int64_t CDPointer; 71 | #endif 72 | 73 | #ifdef __cplusplus 74 | # define PUBLIC extern "C" 75 | #else 76 | # define PUBLIC extern 77 | #endif 78 | 79 | #define CDNull (0) 80 | 81 | #include 82 | #include 83 | #include 84 | #include 85 | 86 | #include 87 | #include 88 | #include 89 | #include 90 | #include 91 | #include 92 | #include 93 | #include 94 | #include 95 | 96 | #include 97 | 98 | #include 99 | #include 100 | 101 | #endif 102 | -------------------------------------------------------------------------------- /include/craftd/Logger.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2011 Kevin M. Bowling, , USA 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef CRAFTD_LOGGER_H 27 | #define CRAFTD_LOGGER_H 28 | 29 | #include 30 | 31 | #include "common.h" 32 | 33 | typedef struct _CDLogger { 34 | void (*log) (int, const char*, ...); 35 | int (*setlogmask) (int); 36 | void (*closelog) (void); 37 | } CDLogger; 38 | 39 | #ifndef CRAFTD_LOGGER_IGNORE_EXTERN 40 | extern CDLogger CDConsoleLogger; 41 | extern CDLogger CDSystemLogger; 42 | extern CDLogger CDDefaultLogger; 43 | #endif 44 | 45 | #define LOG(priority, format, ...) \ 46 | ((CDMainServer != NULL) \ 47 | ? CDMainServer->logger.log(priority, "%s> " format, CD_ServerToString(CDMainServer), ##__VA_ARGS__) \ 48 | : CDDefaultLogger.log(priority, format, ##__VA_ARGS__)) 49 | 50 | #define DEBUG(format, ...) LOG(LOG_DEBUG, format, ##__VA_ARGS__) 51 | 52 | #define ERR(format, ...) LOG(LOG_ERR, format, ##__VA_ARGS__) 53 | 54 | #define WARN(format, ...) LOG(LOG_WARNING, format, ##__VA_ARGS__) 55 | 56 | #define LOG_CLOSE() do { \ 57 | if (CDMainServer) CDMainServer->logger.closelog(); \ 58 | CDDefaultLogger.closelog(); \ 59 | } while (0) 60 | 61 | #define CLOG(priority, format, ...) CDConsoleLogger.log(priority, format, ##__VA_ARGS__) 62 | 63 | #define CDEBUG(format, ...) CLOG(LOG_DEBUG, format, ##__VA_ARGS__) 64 | 65 | #define CERR(format, ...) CLOG(LOG_ERR, format, ##__VA_ARGS__) 66 | 67 | #define CWARN(format, ...) CLOG(LOG_WARNING, format, ##__VA_ARGS__) 68 | 69 | #define SLOG(server, priority, format, ...) \ 70 | server->logger.log(priority, "%s> " format, CD_ServerToString(server), ##__VA_ARGS__) 71 | 72 | #define SDEBUG(server, format, ...) SLOG(server, LOG_DEBUG, format, ##__VA_ARGS__) 73 | 74 | #define SERR(server, format, ...) SLOG(server, LOG_ERR, format, ##__VA_ARGS__) 75 | 76 | #define SWARN(server, format, ...) SLOG(server, LOG_WARNING, format, ##__VA_ARGS__) 77 | 78 | #define SLOG_CLOSE(server) server->logger.close() 79 | 80 | #endif 81 | 82 | #include "Server.h" 83 | -------------------------------------------------------------------------------- /src/Plugins.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2011 Kevin M. Bowling, , USA 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #include 27 | 28 | #include 29 | 30 | CDPlugins* 31 | CD_CreatePlugins (struct _CDServer* server) 32 | { 33 | CDPlugins* self = CD_malloc(sizeof(CDPlugins)); 34 | 35 | self->server = server; 36 | self->items = CD_CreateHash(); 37 | 38 | lt_dlinit(); 39 | 40 | lt_dladvise_init(&self->advise); 41 | lt_dladvise_ext(&self->advise); 42 | lt_dladvise_global(&self->advise); 43 | 44 | C_FOREACH(path, C_PATH(self->server->config, "server.plugins.paths")) { 45 | lt_dladdsearchdir(C_TO_STRING(path)); 46 | } 47 | 48 | return self; 49 | } 50 | 51 | void 52 | CD_DestroyPlugins (CDPlugins* self) 53 | { 54 | CD_HASH_FOREACH(self->items, it) { 55 | CD_DestroyPlugin((CDPlugin*) CD_HashIteratorValue(it)); 56 | } 57 | 58 | CD_DestroyHash(self->items); 59 | 60 | CD_free(self); 61 | 62 | lt_dladvise_destroy(&self->advise); 63 | lt_dlexit(); 64 | } 65 | 66 | bool 67 | CD_LoadPlugins (CDPlugins* self) 68 | { 69 | C_FOREACH(plugin, C_PATH(self->server->config, "server.plugins.load")) { 70 | if (C_GET(plugin, "name")) { 71 | CD_LoadPlugin(self, C_TO_STRING(C_GET(plugin, "name"))); 72 | } 73 | } 74 | 75 | return true; 76 | } 77 | 78 | CDPlugin* 79 | CD_LoadPlugin (CDPlugins* self, const char* name) 80 | { 81 | CDPlugin* plugin = CD_CreatePlugin(self->server, name); 82 | 83 | if (!plugin) { 84 | return NULL; 85 | } 86 | 87 | CD_HashPut(self->items, name, (CDPointer) plugin); 88 | 89 | return plugin; 90 | } 91 | 92 | CDPlugin* 93 | CD_GetPlugin (CDPlugins* self, const char* name) 94 | { 95 | return (CDPlugin*) CD_HashGet(self->items, name); 96 | } 97 | 98 | void 99 | CD_UnloadPlugin (CDPlugins* self, const char* name) 100 | { 101 | CD_DestroyPlugin((CDPlugin*) CD_HashDelete(self->items, name)); 102 | } 103 | -------------------------------------------------------------------------------- /configure.ac: -------------------------------------------------------------------------------- 1 | # craftd configure.ac 2 | AC_PREREQ([2.64]) 3 | 4 | AC_INIT([craftd], [0.2-pre], [kevin.bowling@kev009.com]) 5 | 6 | AC_CONFIG_AUX_DIR([build/auto/configaux]) 7 | AM_INIT_AUTOMAKE([foreign -Wall -Werror subdir-objects dist-bzip2]) 8 | AC_CONFIG_MACRO_DIR([build/auto/m4]) 9 | 10 | # Don't look for C++ or Fortran compilers 11 | m4_undefine([AC_PROG_CXX]) 12 | m4_defun([AC_PROG_CXX],[]) 13 | m4_undefine([AC_PROG_F77]) 14 | m4_defun([AC_PROG_F77],[]) 15 | 16 | AC_PROG_CC_C99 17 | AM_PROG_CC_C_O 18 | AC_USE_SYSTEM_EXTENSIONS 19 | LT_PREREQ([2.2]) 20 | AM_PROG_LIBTOOL 21 | AC_LTDL_DLLIB 22 | AC_SUBST(LIBTOOL_DEPS) 23 | LT_INIT([dlopen]) 24 | 25 | AC_CONFIG_HEADERS([include/craftd/config.h]) 26 | AC_CONFIG_FILES([ 27 | Makefile 28 | src/Makefile 29 | include/Makefile 30 | third-party/Makefile 31 | plugins/Makefile 32 | plugins/survival/mapgen/noise/Makefile 33 | ]) 34 | 35 | AC_CONFIG_SRCDIR([src/craftd.c]) 36 | 37 | # Checks for libraries. 38 | AC_CHECK_LIB([ltdl], [lt_dlopen]) 39 | AX_LIB_SOCKET_NSL 40 | AX_CHECK_ZLIB 41 | AX_PTHREAD([], AC_MSG_ERROR([pthreads is required])) 42 | AX_PATH_LIB_PCRE 43 | 44 | PKG_CHECK_MODULES([libevent2_pthreads], [libevent_pthreads >= 2.0.9], 45 | , , 46 | AC_MSG_ERROR([System libevent2_pthreads not found. Install it and check the 47 | PKG_CONFIG_PATH env var. ])) 48 | 49 | PKG_CHECK_MODULES([libconfig], [libconfig >= 1.3], 50 | , , 51 | AC_MSG_ERROR([System libconfig not found. Install it and check the 52 | PKG_CONFIG_PATH env var.])) 53 | 54 | # Jansson removed from core. Add --with-json logic later. 55 | # PKG_CHECK_MODULES([jansson], [jansson >= 2.0], 56 | # , , 57 | # AC_MSG_ERROR([System jansson not found. Install it and check the PKG_CONFIG_PATH 58 | # env var. ])) 59 | 60 | 61 | # Establish default CFLAGS and pthread portability 62 | AX_CFLAGS_WARN_ALL 63 | CC="$PTHREAD_CC" 64 | PTHREAD_LIBS="$PTHREAD_LIBS" 65 | PTHREAD_CFLAGS="$PTHREAD_CFLAGS" 66 | # Force pthread for everything? 67 | #LIBS="$PTHREAD_LIBS $LIBS" 68 | CFLAGS="$CFLAGS -Wno-unused-label" 69 | #CC="$PTHREAD_CC" 70 | 71 | # Checks for header files. 72 | AC_CHECK_HEADERS([arpa/inet.h netdb.h netinet/in.h stdlib.h string.h \ 73 | sys/socket.h unistd.h endian.h sys/endian.h ltdl.h]) 74 | 75 | AC_C_INLINE 76 | case $ac_cv_c_inline in 77 | yes) json_inline=inline;; 78 | no) json_inline=;; 79 | *) json_inline=$ac_cv_c_inline;; 80 | esac 81 | AC_SUBST([json_inline]) 82 | 83 | # Checks for typedefs, structures, and compiler characteristics. 84 | AC_HEADER_STDBOOL 85 | AC_TYPE_INT16_T 86 | AC_TYPE_INT32_T 87 | AC_TYPE_INT64_T 88 | AC_TYPE_INT8_T 89 | AC_TYPE_UINT64_T 90 | AC_TYPE_UINT32_T 91 | AC_TYPE_UINT16_T 92 | AC_TYPE_UINT8_T 93 | AC_TYPE_SIZE_T 94 | AC_TYPE_INTPTR_T 95 | AC_CHECK_SIZEOF([intptr_t]) 96 | AC_CHECK_SIZEOF([fp], [], [typedef void (*fp)();]) 97 | 98 | AC_C_BIGENDIAN 99 | AC_CHECK_DECLS([be64toh,htobe64], [], [], 100 | [#ifdef HAVE_ENDIAN_H 101 | #include 102 | #endif 103 | #ifdef HAVE_SYS_ENDIAN_H 104 | #include 105 | #endif 106 | ]) 107 | 108 | AC_CHECK_MEMBERS([struct sigaction.sa_handler], [], [], 109 | [#include 110 | ]) 111 | 112 | AC_CHECK_TYPES([pthread_spinlock_t], [], [], [[#include ]]) 113 | 114 | # Check if we need to reorder float and double types 115 | AX_C_FLOAT_WORDS_BIGENDIAN 116 | 117 | AC_OUTPUT 118 | -------------------------------------------------------------------------------- /src/ScriptingEngines.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2011 Kevin M. Bowling, , USA 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #include 27 | 28 | #include 29 | 30 | CDScriptingEngines* 31 | CD_CreateScriptingEngines (struct _CDServer* server) 32 | { 33 | CDScriptingEngines* self = CD_malloc(sizeof(CDScriptingEngines)); 34 | 35 | self->server = server; 36 | self->items = CD_CreateHash(); 37 | 38 | lt_dlinit(); 39 | 40 | lt_dladvise_init(&self->advise); 41 | lt_dladvise_ext(&self->advise); 42 | lt_dladvise_local(&self->advise); 43 | 44 | C_FOREACH(path, C_PATH(self->server->config, "server.scripting.paths")) { 45 | lt_dladdsearchdir(C_STRING(path)); 46 | } 47 | 48 | return self; 49 | } 50 | 51 | void 52 | CD_DestroyScriptingEngines (CDScriptingEngines* self) 53 | { 54 | CD_HASH_FOREACH(self->items, it) { 55 | CD_DestroyScriptingEngine((CDScriptingEngine*) CD_HashIteratorValue(it)); 56 | } 57 | 58 | CD_DestroyHash(self->items); 59 | 60 | CD_free(self); 61 | 62 | lt_dladvise_destroy(&self->advise); 63 | lt_dlexit(); 64 | } 65 | 66 | bool 67 | CD_LoadScriptingEngines (CDScriptingEngines* self) 68 | { 69 | C_FOREACH(engine, C_PATH(self->server->config, "server.scripting.engines")) { 70 | CD_LoadScriptingEngine(self, C_STRING(C_GET(engine, "name"))); 71 | } 72 | 73 | return true; 74 | } 75 | 76 | CDScriptingEngine* 77 | CD_LoadScriptingEngine (CDScriptingEngines* self, const char* name) 78 | { 79 | CDScriptingEngine* engine = CD_CreateScriptingEngine(self->server, name); 80 | 81 | if (!engine) { 82 | return NULL; 83 | } 84 | 85 | CD_HashPut(self->items, name, (CDPointer) engine); 86 | 87 | return engine; 88 | } 89 | 90 | CDScriptingEngine* 91 | CD_GetScriptingEngine (CDScriptingEngines* self, const char* name) 92 | { 93 | return (CDScriptingEngine*) CD_HashGet(self->items, name); 94 | } 95 | 96 | void 97 | CD_UnloadScriptingEngine (CDScriptingEngines* self, const char* name) 98 | { 99 | CD_DestroyScriptingEngine((CDScriptingEngine*) CD_HashDelete(self->items, name)); 100 | } 101 | -------------------------------------------------------------------------------- /craftd.conf.dist.in: -------------------------------------------------------------------------------- 1 | # craftd config file 2 | 3 | server: { 4 | daemonize: false; 5 | 6 | connection: { 7 | bind: { 8 | ipv4: "0.0.0.0"; 9 | ipv6: "::"; 10 | }; 11 | 12 | port: 25565; 13 | backlog: 16; 14 | }; 15 | 16 | # It's a good idea to keep the number of workers equal to the number of CPU cores, 17 | # keep in mind that other threads might be spawned by plugins and that craftd has a minimum 18 | # number of threads equal to WORKERS + 2 19 | workers: 2; 20 | 21 | files: { 22 | motd: "@sysconfdir@/craftd/motd.conf.dist"; 23 | }; 24 | 25 | game: { 26 | # This value is used by the base module to know if it has to act like the 27 | # official server or if it can use craftd specific additions 28 | standard: true; 29 | 30 | # This configuration is used by the protocol implementation in use 31 | protocol: { 32 | name: "survival"; 33 | 34 | worlds: ( 35 | { name: "world"; default: true; 36 | rate: { 37 | sunrise: 20; 38 | day: 20; 39 | sunset: 20; 40 | night: 20; 41 | }; 42 | } 43 | ); 44 | }; 45 | 46 | clients: { 47 | max: 0; 48 | simultaneous: 0; 49 | }; 50 | }; 51 | 52 | plugins: { 53 | paths: ["plugins", "@libdir@/craftd/plugins"]; 54 | 55 | load: ( 56 | # Comment this if you don't want the web interface and RPC capabilities 57 | { name: "httpd"; 58 | connection: { 59 | bind: { 60 | ipv4: "127.0.0.1"; 61 | ipv6: "::1"; 62 | }; 63 | 64 | port: 25566; 65 | }; 66 | }, 67 | 68 | { name: "survival.base"; 69 | command: "/"; 70 | }, 71 | 72 | { name : "survival.mapgen.classic"; }, 73 | 74 | { name: "survival.persistence.nbt"; 75 | path: "@datadir@/craftd/worlds"; 76 | }, 77 | 78 | { name: "survival.mapgen.classic"; }, 79 | 80 | { name: "survival.commands.admin"; 81 | authorizations: ( 82 | { name: "Notch"; 83 | password: "faggotree"; 84 | level: "admin"; 85 | } 86 | ); 87 | 88 | ticket: { 89 | max: 50; 90 | }; 91 | }, 92 | 93 | { name: "survival.tests"; } 94 | ); 95 | }; 96 | 97 | scripting: { 98 | paths: ["scripting", "@libdir@/craftd/scripting"]; 99 | 100 | engines: ( 101 | /* { name: "lisp"; 102 | paths: ["scripting/lisp/lib", "scripting/lisp/scripts", "@libdir@/craftd/scripting/lisp", "@libdir@/craftd/scripting/lisp/lib"]; 103 | 104 | options: []; 105 | 106 | shell: false; 107 | 108 | scripts: ["joined"]; 109 | }, */ 110 | 111 | { name: "javascript"; 112 | paths: ["scripting/javascript/lib", "scripting/javascript/scripts", "@libdir@/craftd/scripting/javascript", "@libdir@/craftd/scripting/javascript/lib"]; 113 | } 114 | ); 115 | }; 116 | }; 117 | -------------------------------------------------------------------------------- /plugins/survival/mapgen/classic/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2011 Kevin M. Bowling, , USA 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #include 27 | #include 28 | 29 | #include 30 | 31 | static struct { 32 | const char* seed; 33 | } _config; 34 | 35 | #include "helpers.c" 36 | 37 | static 38 | bool 39 | cdclassic_GenerateLevel (CDServer* server, SVWorld* world, const char* seed) 40 | { 41 | if (seed == NULL) { 42 | seed = _config.seed; 43 | } 44 | 45 | world->spawnPosition = (SVBlockPosition) { 46 | .x = 0, 47 | .y = 120, 48 | .z = 0 49 | }; 50 | 51 | return true; 52 | } 53 | 54 | static 55 | bool 56 | cdclassic_GenerateChunk (CDServer* server, SVWorld* world, int x, int z, SVChunk* data, const char* seed) 57 | { 58 | memset(data, 0, sizeof(*data)); 59 | 60 | if (seed == NULL) { 61 | seed = _config.seed; 62 | } 63 | 64 | cdclassic_GenerateHeightMap(data, x, z); 65 | cdclassic_GenerateFilledChunk(data, x, z, SVStone); 66 | cdclassic_DigCaves(data, x, z); 67 | cdclassic_ErodeLandscape(data, x, z); 68 | cdclassic_AddMinerals(data, x, z); 69 | cdclassic_AddSediments(data, x, z); 70 | cdclassic_FloodWithWater(data, x, z, 64); 71 | cdclassic_BedrockGround(data, x, z); 72 | cdclassic_GenerateSkyLight(data, x, z); 73 | 74 | return true; 75 | } 76 | 77 | extern 78 | bool 79 | CD_PluginInitialize (CDPlugin* self) 80 | { 81 | self->description = CD_CreateStringFromCString("Classic Mapgen"); 82 | 83 | DO { // Initiailize config cache 84 | _config.seed = "^_^"; 85 | 86 | C_SAVE(C_PATH(self->config, "seed"), C_STRING, _config.seed); 87 | } 88 | 89 | 90 | CD_EventRegister(self->server, "Mapgen.level", cdclassic_GenerateLevel); 91 | CD_EventRegister(self->server, "Mapgen.chunk", cdclassic_GenerateChunk); 92 | 93 | return true; 94 | } 95 | 96 | extern 97 | bool 98 | CD_PluginFinalize (CDPlugin* self) 99 | { 100 | CD_EventUnregister(self->server, "Mapgen.level", cdclassic_GenerateLevel); 101 | CD_EventUnregister(self->server, "Mapgen.chunk", cdclassic_GenerateChunk); 102 | 103 | return true; 104 | } 105 | -------------------------------------------------------------------------------- /scripting/javascript/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2011 Kevin M. Bowling, , USA 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #include 27 | 28 | #include "include/common.h" 29 | #include "helpers.c" 30 | 31 | bool 32 | cdjs_EventDispatcher (CDServer* server, const char* event, va_list args) 33 | { 34 | if (!CD_HashHasKey(server->event.provided, event)) { 35 | return true; 36 | } 37 | 38 | JSRuntime* runtime = (JSRuntime*) CD_DynamicGet(server, "JavaScript.runtime"); 39 | CDMap* contextes = (CDMap*) CD_DynamicGet(server, "JavaScript.contextes"); 40 | JSContext* context = (JSContext*) CD_MapGet(contextes, pthread_self()); 41 | 42 | if (!context) { 43 | CD_MapPut(contextes, pthread_self(), (CDPointer) (context = cdjs_CreateContext(server, runtime))); 44 | } 45 | 46 | JS_BeginRequest(context); 47 | 48 | JS_EndRequest(context); 49 | 50 | return true; 51 | } 52 | 53 | extern 54 | bool 55 | CD_ScriptingEngineInitialize (CDScriptingEngine* self) 56 | { 57 | self->description = CD_CreateStringFromCString("JavaScript scripting"); 58 | 59 | JS_SetCStringsAreUTF8(); 60 | 61 | JSRuntime* runtime = JS_NewRuntime(8L * 1024L * 1024L); 62 | JSContext* context = cdjs_CreateContext(self->server, runtime); 63 | CDMap* contextes = CD_CreateMap(); 64 | 65 | CD_DynamicPut(self->server, "JavaScript.runtime", (CDPointer) runtime); 66 | CD_DynamicPut(self->server, "JavaScript.contextes", (CDPointer) contextes); 67 | CD_DynamicPut(self->server, "JavaScript.context", (CDPointer) context); 68 | 69 | CD_EventRegister(self->server, "Event.dispatch:before", cdjs_EventDispatcher); 70 | 71 | return true; 72 | } 73 | 74 | extern 75 | bool 76 | CD_ScriptingEngineFinalize (CDScriptingEngine* self) 77 | { 78 | CD_EventUnregister(self->server, "Event.dispatch:before", cdjs_EventDispatcher); 79 | 80 | CDMap* contextes = (CDMap*) CD_DynamicDelete(self->server, "JavaScript.contextes"); 81 | 82 | CD_MAP_FOREACH(contextes, it) { 83 | JS_DestroyContext((JSContext*) CD_MapIteratorValue(it)); 84 | } 85 | 86 | CD_DestroyMap(contextes); 87 | 88 | JS_DestroyContext((JSContext*) CD_DynamicDelete(self->server, "JavaScript.context")); 89 | 90 | JS_DestroyRuntime((JSRuntime*) CD_DynamicDelete(self->server, "JavaScript.runtime")); 91 | 92 | JS_ShutDown(); 93 | 94 | return true; 95 | } 96 | --------------------------------------------------------------------------------