Skip to content

Commit ee07c3f

Browse files
prollerIlya Zhuravlev
authored and
Ilya Zhuravlev
committedFeb 21, 2013
new auto masterserver
1 parent ef6b8be commit ee07c3f

20 files changed

+6919
-49
lines changed
 

‎.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ src/cguittfont/CMakeFiles/
4040
src/cguittfont/libcguittfont.a
4141
src/cguittfont/cmake_install.cmake
4242
src/cguittfont/Makefile
43+
src/json/CMakeFiles/
44+
src/json/libjson.a
4345
CMakeCache.txt
4446
CPackConfig.cmake
4547
CPackSourceConfig.cmake

‎cmake/Modules/FindJson.cmake

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Look for json, use our own if not found
2+
3+
#FIND_PATH(JSON_INCLUDE_DIR json.h)
4+
5+
#FIND_LIBRARY(JSON_LIBRARY NAMES json)
6+
7+
#IF(JSON_LIBRARY AND JSON_INCLUDE_DIR)
8+
# SET( JSON_FOUND TRUE )
9+
#ENDIF(JSON_LIBRARY AND JSON_INCLUDE_DIR)
10+
11+
#IF(JSON_FOUND)
12+
# MESSAGE(STATUS "Found system json header file in ${JSON_INCLUDE_DIR}")
13+
# MESSAGE(STATUS "Found system json library ${JSON_LIBRARY}")
14+
#ELSE(JSON_FOUND)
15+
SET(JSON_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/json)
16+
SET(JSON_LIBRARY json)
17+
MESSAGE(STATUS "Using project json library")
18+
#ENDIF(JSON_FOUND)

‎minetest.conf.example

+11-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@
159159
#media_fetch_threads = 8
160160

161161
# Url to the server list displayed in the Multiplayer Tab
162-
#serverlist_url = servers.minetest.ru/server.list
162+
#serverlist_url = servers.minetest.net
163163
# File in client/serverlist/ that contains your favorite servers displayed in the Multiplayer Tab
164164
#serverlist_file = favoriteservers.txt
165165

@@ -172,6 +172,16 @@
172172
# Server stuff
173173
#
174174

175+
# Name of server
176+
#server_name = Minetest server
177+
# Description of server
178+
#server_description = mine here
179+
# Domain name of server
180+
#server_address = game.minetest.net
181+
# Homepage of server
182+
#server_url = http://minetest.net
183+
# Automaticaly report to masterserver
184+
#server_announce = 0
175185
# Default game (default when creating a new world)
176186
#default_game = minetest
177187
# World directory (everything in the world is stored here)

‎src/CMakeLists.txt

+24-5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ cmake_minimum_required( VERSION 2.6 )
55
mark_as_advanced(EXECUTABLE_OUTPUT_PATH LIBRARY_OUTPUT_PATH)
66
mark_as_advanced(JTHREAD_INCLUDE_DIR JTHREAD_LIBRARY)
77
mark_as_advanced(SQLITE3_INCLUDE_DIR SQLITE3_LIBRARY)
8+
mark_as_advanced(JSON_INCLUDE_DIR JSON_LIBRARY)
89

910
option(ENABLE_CURL "Enable cURL support for fetching media" 1)
1011

@@ -170,6 +171,7 @@ endif()
170171

171172
find_package(Jthread REQUIRED)
172173
find_package(Sqlite3 REQUIRED)
174+
find_package(Json REQUIRED)
173175

174176
if(USE_FREETYPE)
175177
find_package(Freetype REQUIRED)
@@ -242,6 +244,7 @@ set(common_SRCS
242244
biome.cpp
243245
clientserver.cpp
244246
staticobject.cpp
247+
serverlist.cpp
245248
util/serialize.cpp
246249
util/directiontables.cpp
247250
util/numeric.cpp
@@ -303,7 +306,6 @@ set(minetest_SRCS
303306
filecache.cpp
304307
tile.cpp
305308
shader.cpp
306-
serverlist.cpp
307309
game.cpp
308310
main.cpp
309311
)
@@ -332,6 +334,7 @@ include_directories(
332334
${JTHREAD_INCLUDE_DIR}
333335
${SQLITE3_INCLUDE_DIR}
334336
${LUA_INCLUDE_DIR}
337+
${JSON_INCLUDE_DIR}
335338
)
336339

337340
if(USE_FREETYPE)
@@ -341,6 +344,12 @@ if(USE_FREETYPE)
341344
)
342345
endif(USE_FREETYPE)
343346

347+
if(USE_CURL)
348+
include_directories(
349+
${CURL_INCLUDE_DIR}
350+
)
351+
endif(USE_CURL)
352+
344353
set(EXECUTABLE_OUTPUT_PATH "${CMAKE_SOURCE_DIR}/bin")
345354

346355
if(BUILD_CLIENT)
@@ -359,18 +368,15 @@ if(BUILD_CLIENT)
359368
${JTHREAD_LIBRARY}
360369
${SQLITE3_LIBRARY}
361370
${LUA_LIBRARY}
371+
${JSON_LIBRARY}
362372
${PLATFORM_LIBS}
363373
${CLIENT_PLATFORM_LIBS}
364374
)
365-
366375
if(USE_CURL)
367376
target_link_libraries(
368377
${PROJECT_NAME}
369378
${CURL_LIBRARY}
370379
)
371-
include_directories(
372-
${CURL_INCLUDE_DIR}
373-
)
374380
endif(USE_CURL)
375381
if(USE_FREETYPE)
376382
target_link_libraries(
@@ -388,12 +394,20 @@ if(BUILD_SERVER)
388394
${ZLIB_LIBRARIES}
389395
${JTHREAD_LIBRARY}
390396
${SQLITE3_LIBRARY}
397+
${JSON_LIBRARY}
391398
${GETTEXT_LIBRARY}
392399
${LUA_LIBRARY}
393400
${PLATFORM_LIBS}
394401
)
402+
if(USE_CURL)
403+
target_link_libraries(
404+
${PROJECT_NAME}server
405+
${CURL_LIBRARY}
406+
)
407+
endif(USE_CURL)
395408
endif(BUILD_SERVER)
396409

410+
397411
#
398412
# Set some optimizations and tweaks
399413
#
@@ -569,4 +583,9 @@ else (LUA_FOUND)
569583
add_subdirectory(lua)
570584
endif (LUA_FOUND)
571585

586+
if (JSON_FOUND)
587+
else (JSON_FOUND)
588+
add_subdirectory(json)
589+
endif (JSON_FOUND)
590+
572591
#end

‎src/defaultsettings.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,13 @@ void set_default_settings(Settings *settings)
130130

131131
settings->setDefault("media_fetch_threads", "8");
132132

133-
settings->setDefault("serverlist_url", "servers.minetest.ru/server.list");
133+
settings->setDefault("serverlist_url", "servers.minetest.net");
134134
settings->setDefault("serverlist_file", "favoriteservers.txt");
135+
settings->setDefault("server_announce", "false");
136+
settings->setDefault("server_url", "");
137+
settings->setDefault("server_address", "");
138+
settings->setDefault("server_name", "");
139+
settings->setDefault("server_description", "");
135140

136141
settings->setDefault("font_path", porting::getDataPath("fonts" DIR_DELIM "liberationsans.ttf"));
137142
settings->setDefault("font_size", "13");

‎src/guiMainMenu.cpp

+48-16
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ enum
108108
GUI_ID_ENABLE_PARTICLES_CB,
109109
GUI_ID_DAMAGE_CB,
110110
GUI_ID_CREATIVE_CB,
111+
GUI_ID_PUBLIC_CB,
111112
GUI_ID_JOIN_GAME_BUTTON,
112113
GUI_ID_CHANGE_KEYS_BUTTON,
113114
GUI_ID_DELETE_WORLD_BUTTON,
@@ -562,6 +563,14 @@ void GUIMainMenu::regenerateGui(v2u32 screensize)
562563
Environment->addCheckBox(m_data->enable_damage, rect, this, GUI_ID_DAMAGE_CB,
563564
wgettext("Enable Damage"));
564565
}
566+
#if USE_CURL
567+
{
568+
core::rect<s32> rect(0, 0, 250, 30);
569+
rect += m_topleft_server + v2s32(30+20+250+20, 60);
570+
Environment->addCheckBox(m_data->enable_public, rect, this, GUI_ID_PUBLIC_CB,
571+
wgettext("Public"));
572+
}
573+
#endif
565574
// Delete world button
566575
{
567576
core::rect<s32> rect(0, 0, 130, 30);
@@ -841,6 +850,11 @@ void GUIMainMenu::readInput(MainMenuData *dst)
841850
if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
842851
dst->enable_damage = ((gui::IGUICheckBox*)e)->isChecked();
843852
}
853+
{
854+
gui::IGUIElement *e = getElementFromId(GUI_ID_PUBLIC_CB);
855+
if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
856+
dst->enable_public = ((gui::IGUICheckBox*)e)->isChecked();
857+
}
844858
{
845859
gui::IGUIElement *e = getElementFromId(GUI_ID_FANCYTREE_CB);
846860
if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
@@ -912,8 +926,8 @@ void GUIMainMenu::readInput(MainMenuData *dst)
912926
{
913927
ServerListSpec server =
914928
getServerListSpec(wide_to_narrow(dst->address), wide_to_narrow(dst->port));
915-
dst->servername = server.name;
916-
dst->serverdescription = server.description;
929+
dst->servername = server["name"].asString();
930+
dst->serverdescription = server["description"].asString();
917931
}
918932
}
919933

@@ -1174,13 +1188,31 @@ void GUIMainMenu::updateGuiServerList()
11741188
i != m_data->servers.end(); i++)
11751189
{
11761190
std::string text;
1177-
if (i->name != "" && i->description != "")
1178-
text = i->name + " (" + i->description + ")";
1179-
else if (i->name !="")
1180-
text = i->name;
1181-
else
1182-
text = i->address + ":" + i->port;
11831191

1192+
if ((*i)["clients"].asString().size())
1193+
text += (*i)["clients"].asString();
1194+
if ((*i)["clients_max"].asString().size())
1195+
text += "/" + (*i)["clients_max"].asString();
1196+
text += " ";
1197+
if ((*i)["version"].asString().size())
1198+
text += (*i)["version"].asString() + " ";
1199+
if ((*i)["password"].asString().size())
1200+
text += "*";
1201+
if ((*i)["creative"].asString().size())
1202+
text += "C";
1203+
if ((*i)["damage"].asString().size())
1204+
text += "D";
1205+
if ((*i)["pvp"].asString().size())
1206+
text += "P";
1207+
text += " ";
1208+
1209+
if ((*i)["name"] != "" && (*i)["description"] != "")
1210+
text += (*i)["name"].asString() + " (" + (*i)["description"].asString() + ")";
1211+
else if ((*i)["name"] !="")
1212+
text += (*i)["name"].asString();
1213+
else
1214+
text += (*i)["address"].asString() + ":" + (*i)["port"].asString();
1215+
11841216
serverlist->addItem(narrow_to_wide(text).c_str());
11851217
}
11861218
}
@@ -1191,26 +1223,26 @@ void GUIMainMenu::serverListOnSelected()
11911223
{
11921224
gui::IGUIListBox *serverlist = (gui::IGUIListBox*)getElementFromId(GUI_ID_SERVERLIST);
11931225
u16 id = serverlist->getSelected();
1194-
if (id < 0) return;
1226+
//if (id < 0) return; // u16>0!
11951227
((gui::IGUIEditBox*)getElementFromId(GUI_ID_ADDRESS_INPUT))
1196-
->setText(narrow_to_wide(m_data->servers[id].address).c_str());
1228+
->setText(narrow_to_wide(m_data->servers[id]["address"].asString()).c_str());
11971229
((gui::IGUIEditBox*)getElementFromId(GUI_ID_PORT_INPUT))
1198-
->setText(narrow_to_wide(m_data->servers[id].port).c_str());
1230+
->setText(narrow_to_wide(m_data->servers[id]["port"].asString()).c_str());
11991231
}
12001232
}
12011233

12021234
ServerListSpec GUIMainMenu::getServerListSpec(std::string address, std::string port)
12031235
{
12041236
ServerListSpec server;
1205-
server.address = address;
1206-
server.port = port;
1237+
server["address"] = address;
1238+
server["port"] = port;
12071239
for(std::vector<ServerListSpec>::iterator i = m_data->servers.begin();
12081240
i != m_data->servers.end(); i++)
12091241
{
1210-
if (i->address == address && i->port == port)
1242+
if ((*i)["address"] == address && (*i)["port"] == port)
12111243
{
1212-
server.description = i->description;
1213-
server.name = i->name;
1244+
server["description"] = (*i)["description"];
1245+
server["name"] = (*i)["name"];
12141246
break;
12151247
}
12161248
}

‎src/guiMainMenu.h

+2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ struct MainMenuData
5555
// Server options
5656
bool creative_mode;
5757
bool enable_damage;
58+
bool enable_public;
5859
int selected_world;
5960
bool simple_singleplayer_mode;
6061
// Actions
@@ -77,6 +78,7 @@ struct MainMenuData
7778
// Server opts
7879
creative_mode(false),
7980
enable_damage(false),
81+
enable_public(false),
8082
selected_world(0),
8183
simple_singleplayer_mode(false),
8284
// Actions

‎src/json/CMakeLists.txt

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
if( UNIX )
2+
set(json_SRCS jsoncpp.cpp)
3+
set(json_platform_LIBS "")
4+
else( UNIX )
5+
set(json_SRCS jsoncpp.cpp)
6+
set(json_platform_LIBS "")
7+
endif( UNIX )
8+
9+
add_library(json ${json_SRCS})
10+
11+
target_link_libraries(
12+
json
13+
${json_platform_LIBS}
14+
)

‎src/json/UPDATING

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/sh
2+
cd ..
3+
svn co https://jsoncpp.svn.sourceforge.net/svnroot/jsoncpp/trunk/jsoncpp jsoncpp
4+
svn up jsoncpp
5+
cd jsoncpp
6+
python amalgamate.py
7+
cp -R dist/json ..
8+
cp dist/jsoncpp.cpp ../json
9+
10+
# maybe you need to patch:
11+
# src/json/jsoncpp.cpp:
12+
# -#include <json/json.h>
13+
# +#include "json/json.h"
14+
15+
#svn export --force https://jsoncpp.svn.sourceforge.net/svnroot/jsoncpp/trunk/jsoncpp/src/lib_json json
16+
#svn export --force https://jsoncpp.svn.sourceforge.net/svnroot/jsoncpp/trunk/jsoncpp/include/json json

0 commit comments

Comments
 (0)
Please sign in to comment.