Skip to content

Commit dba2226

Browse files
serving static files via cpp-httplib.
1 parent cc88138 commit dba2226

File tree

15 files changed

+211
-169
lines changed

15 files changed

+211
-169
lines changed

.gitmodules

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[submodule "server/websocketpp"]
22
path = server/websocketpp
33
url = https://github.com/zaphoyd/websocketpp.git
4-
[submodule "server/mongoose-cpp"]
5-
path = server/mongoose-cpp
6-
url = https://github.com/Gregwar/mongoose-cpp
4+
[submodule "server/cpp-httplib"]
5+
path = server/cpp-httplib
6+
url = https://github.com/yhirose/cpp-httplib
File renamed without changes.

LICENSE.rst

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
.. _license:
2+
3+
########
4+
Licenses
5+
########
6+
7+
DFHack is distributed under the Zlib license, with some MIT-
8+
and BSD-licensed components. These licenses protect your right
9+
to use DFHack for any purpose, distribute copies, and so on.
10+
11+
The core, plugins, scripts, and other DFHack code all use the
12+
ZLib license unless noted otherwise. By contributing to DFHack,
13+
authors release the contributed work under this license.
14+
15+
DFHack also draws on several external packages.
16+
Their licenses are summarised here and reproduced below.
17+
18+
=============== ============= =================================================
19+
Component License Copyright
20+
=============== ============= =================================================
21+
DFHack_ Zlib \(c\) 2009-2012, Petr Mrรกzek
22+
clsocket_ BSD 3-clause \(c\) 2007-2009, CarrierLabs, LLC.
23+
dirent_ MIT \(c\) 2006, Toni Ronkko
24+
JSON.lua_ CC-BY-SA_ \(c\) 2010-2014, Jeffrey Friedl
25+
jsoncpp_ MIT \(c\) 2007-2010, Baptiste Lepilleur
26+
linenoise_ BSD 2-clause \(c\) 2010, Salvatore Sanfilippo & Pieter Noordhuis
27+
lua_ MIT \(c\) 1994-2008, Lua.org, PUC-Rio.
28+
luafilesystem_ MIT \(c\) 2003-2014, Kepler Project
29+
lua-profiler_ MIT \(c\) 2002,2003,2004 Pepperfish
30+
protobuf_ BSD 3-clause \(c\) 2008, Google Inc.
31+
tinythread_ Zlib \(c\) 2010, Marcus Geelnard
32+
tinyxml_ Zlib \(c\) 2000-2006, Lee Thomason
33+
UTF-8-decoder_ MIT \(c\) 2008-2010, Bjoern Hoehrmann
34+
webfort_ ISC \(c\) 2014, Vitaly Pronkin, Kyle Mclamb
35+
cpp-httplib_ MIT \(c\) 2017, yhirose
36+
=============== ============= =================================================
37+
38+
.. _DFHack: https://github.com/DFHack/dfhack
39+
.. _clsocket: https://github.com/DFHack/clsocket
40+
.. _dirent: https://github.com/tronkko/dirent
41+
.. _JSON.lua: http://regex.info/blog/lua/json
42+
.. _jsoncpp: https://github.com/open-source-parsers/jsoncpp
43+
.. _linenoise: http://github.com/antirez/linenoise
44+
.. _lua: http://www.lua.org
45+
.. _luafilesystem: https://github.com/keplerproject/luafilesystem
46+
.. _protobuf: https://github.com/google/protobuf
47+
.. _tinythread: http://tinythreadpp.bitsnbites.eu/
48+
.. _tinyxml: http://www.sourceforge.net/projects/tinyxml
49+
.. _UTF-8-decoder: http://bjoern.hoehrmann.de/utf-8/decoder/dfa
50+
.. _lua-profiler: http://lua-users.org/wiki/PepperfishProfiler
51+
.. _webfort: https://github.com/Ankoku/df-webfort
52+
.. _cpp-httplib: https://github.com/yhirose/cpp-httplib
53+
54+
.. _CC-BY-SA: http://creativecommons.org/licenses/by/3.0/deed.en_US
55+
56+
57+
Zlib License
58+
============
59+
See https://en.wikipedia.org/wiki/Zlib_License
60+
::
61+
62+
This software is provided 'as-is', without any express or implied
63+
warranty. In no event will the authors be held liable for any
64+
damages arising from the use of this software.
65+
66+
Permission is granted to anyone to use this software for any
67+
purpose, including commercial applications, and to alter it and
68+
redistribute it freely, subject to the following restrictions:
69+
70+
1. The origin of this software must not be misrepresented; you must
71+
not claim that you wrote the original software. If you use this
72+
software in a product, an acknowledgment in the product
73+
documentation would be appreciated but is not required.
74+
75+
2. Altered source versions must be plainly marked as such, and
76+
must not be misrepresented as being the original software.
77+
78+
3. This notice may not be removed or altered from any source
79+
distribution.
80+
81+
MIT License
82+
===========
83+
See https://en.wikipedia.org/wiki/MIT_License
84+
::
85+
86+
Permission is hereby granted, free of charge, to any person obtaining
87+
a copy of this software and associated documentation files (the
88+
"Software"), to deal in the Software without restriction, including
89+
without limitation the rights to use, copy, modify, merge, publish,
90+
distribute, sublicense, and/or sell copies of the Software, and to
91+
permit persons to whom the Software is furnished to do so, subject to
92+
the following conditions:
93+
94+
The above copyright notice and this permission notice shall be included
95+
in all copies or substantial portions of the Software.
96+
97+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
98+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
99+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
100+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
101+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
102+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
103+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
104+
105+
BSD Licenses
106+
============
107+
See https://en.wikipedia.org/wiki/BSD_licenses
108+
::
109+
110+
Redistribution and use in source and binary forms, with or without
111+
modification, are permitted provided that the following conditions are
112+
met:
113+
114+
1. Redistributions of source code must retain the above copyright
115+
notice, this list of conditions and the following disclaimer.
116+
117+
2. Redistributions in binary form must reproduce the above copyright
118+
notice, this list of conditions and the following disclaimer in
119+
the documentation and/or other materials provided with the
120+
distribution.
121+
122+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
123+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
124+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
125+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
126+
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
127+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
128+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
129+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
130+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
131+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
132+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
133+
134+
``linenoise`` adds no further clauses.
135+
136+
``protobuf`` adds the following clause::
137+
138+
3. Neither the name of Google Inc. nor the names of its
139+
contributors may be used to endorse or promote products derived
140+
from this software without specific prior written permission.
141+
142+
``clsocket`` adds the following clauses::
143+
144+
3. The name of the author may not be used to endorse or promote
145+
products derived from this software without specific prior
146+
written permission.
147+
148+
4. The name "CarrierLabs" must not be used to endorse or promote
149+
products derived from this software without prior written
150+
permission. For written permission, please contact
151+
152+
153+
ISC License
154+
===========
155+
See https://en.wikipedia.org/wiki/ISC_license
156+
::
157+
158+
Permission to use, copy, modify, and/or distribute this software for any
159+
purpose with or without fee is hereby granted, provided that the above
160+
copyright notice and this permission notice appear in all copies.
161+
162+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
163+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
164+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
165+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
166+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
167+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
168+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

server/CMakeLists.txt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,11 @@ endif()
8484
# websocketpp
8585
include_directories(websocketpp)
8686

87-
# mongoose
88-
include_directories(mongoose-cpp)
89-
add_subdirectory(mongoose-cpp)
87+
# cpp-httplib
88+
include_directories(cpp-httplib)
9089

9190
if (isPlugin)
92-
DFHACK_PLUGIN(dfplex ${SRC} LINK_LIBRARIES SDL dfhack-tinythread mongoose ${PROJECT_LIBS})
91+
DFHACK_PLUGIN(dfplex ${SRC} LINK_LIBRARIES SDL dfhack-tinythread ${PROJECT_LIBS})
9392
target_link_libraries(dfplex ${Boost_LIBRARIES} SDL)
9493
INSTALL(DIRECTORY ../dist/shared/ DESTINATION .)
9594
INSTALL(DIRECTORY ../static/ DESTINATION ./hack/www)
@@ -112,7 +111,7 @@ else()
112111
)
113112

114113
add_library(dfplex.plug SHARED ${SRC})
115-
target_link_libraries(dfplex.plug mongoose ${PROJECT_LIBS})
114+
target_link_libraries(dfplex.plug ${PROJECT_LIBS})
116115
# Installing
117116
install(TARGETS dfplex.plug
118117
RUNTIME DESTINATION ${DF_ROOT}/hack/plugins

server/config.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,6 @@ bool load_text_file()
7070
if (key == "MAX_CLIENTS") {
7171
MAX_CLIENTS = (uint32_t)std::stol(val);
7272
}
73-
if (key == "AUTOSAVE_WHILE_IDLE") {
74-
AUTOSAVE_WHILE_IDLE = val == "YES";
75-
}
7673
if (key == "NOPAUSE")
7774
{
7875
NOPAUSE = std::stol(val);
@@ -116,9 +113,6 @@ bool load_env_vars()
116113
if ((tmp = getenv("DFPLEX_MAX_CLIENTS"))) {
117114
MAX_CLIENTS = (uint32_t)std::stol(tmp);
118115
}
119-
if ((tmp = getenv("DFPLEX_AUTOSAVE"))) {
120-
AUTOSAVE_WHILE_IDLE = std::stol(tmp) != 0;
121-
}
122116
if ((tmp = getenv("DFPLEX_SECRET"))) {
123117
SECRET = tmp;
124118
}

server/cpp-httplib

Submodule cpp-httplib added at 2feea0c

server/dfplex.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ static void dfplex_update();
100100
// or if the global state is paused.
101101
//
102102
// NOTE: this function ignores the value of df's pause variable
103-
// and global::debug_nopause (NOPAUSE)
104103
bool is_paused()
105104
{
106105
if (global_pause) return true;
@@ -565,14 +564,6 @@ void dfplex_update()
565564
vs->feed_key(df::enums::interface_key::D_ONESTEP);
566565
}
567566
single_step_requested = false;
568-
569-
if (NOPAUSE)
570-
{
571-
// update nopause status to match global pause.
572-
#ifdef DFPLEX_ENABLE_NOPAUSE
573-
*df::global::debug_nopause = !global_pause;
574-
#endif
575-
}
576567
}
577568

578569
frames_elapsed++;

server/mongoose-cpp

Lines changed: 0 additions & 1 deletion
This file was deleted.

server/staticserver.cpp

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,41 @@
1111
#include "Console.h"
1212
#include "Core.h"
1313

14-
#include <mongoose/Server.h>
15-
#include <mongoose/WebController.h>
14+
#include <httplib.h>
1615

17-
using namespace Mongoose;
16+
using namespace DFHack;
1817

1918
void init_static(void*)
2019
{
21-
WebController c;
22-
Server server(STATICPORT, STATICDIR.c_str());
23-
server.registerController(&c);
20+
using namespace httplib;
2421

25-
server.start();
26-
*_out << "[DFPLEX] Static site server started on port " << STATICPORT << endl;
27-
*_out << "[DFPLEX] Connect to http://localhost:" << STATICPORT << "/dfplex.html in your browser." << endl;
22+
Server svr;
23+
//Server server(STATICPORT, STATICDIR.c_str());
2824

29-
while (1) {
30-
DFHack::Core::getInstance().getConsole().msleep(60);
25+
auto ret = svr.set_mount_point("/", STATICDIR.c_str());
26+
svr.Get("/", [](const Request& req, Response& res) {
27+
res.set_redirect("dfplex.html");
28+
});
29+
30+
svr.Get("/config-srv.js", [](const Request& req, Response& res) {
31+
std::stringstream ss;
32+
ss << "// This file is dynamically generated.\n";
33+
ss << "config.port = '" << PORT << "';\n";
34+
res.set_content(ss.str().c_str(), "application/javascript");
35+
});
36+
37+
if (!ret)
38+
{
39+
_out->color(COLOR_RED);
40+
*_out << "[DFPLEX] Failed to serve static site files from \"" << STATICDIR.c_str()
41+
<< "\"" << std::endl;
42+
_out->color(COLOR_RESET);
43+
}
44+
else
45+
{
46+
*_out << "[DFPLEX] Static site server starting on port " << STATICPORT << endl;
47+
*_out << "[DFPLEX] Serving files from directory " << STATICDIR << endl;
48+
*_out << "[DFPLEX] Connect to http://localhost:" << STATICPORT << "/dfplex.html in your browser." << endl;
49+
svr.listen("0.0.0.0", STATICPORT);
3150
}
32-
3351
}

static/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ for debug purposes. here are all of them:
77

88
| option | value | default | description |
99
|-------------|---------------------|----------------------|-------------------------------------------|
10-
| `host` | any hostname | current hostname | The websocket domain to connect to. |
1110
| `port` | any port number | 1234 | The port number of the websocket. |
1211
| `tiles` | an image in `art/` | `Spacefox_16x16.png` | The tileset to use. |
1312
| `text` | an image in `art/` | `ShizzleClean.png` | the tileset to use for ingame text. |

0 commit comments

Comments
 (0)