A sample api server for Sonolus, use C++ & MySQL to develop. You can use it to test your own Sonolus engine or build a Sonolus server for yourself.
It can be deployed in any Linux devices and any Windows devices, even if a moblie phone also can compile the server successfully.
Use httpd core developed by myself, which also support you to build HTTPS server.
- Catalog
- Links
- Screenshots
- Install
- Building
- Configuration
- Endpoints
- Custom Search
- Tips
- Third-party Repo
- Plugins
- Upload Log
We provide executable file compression packages for each version, with SQLite database selected by default.
For Windows
users, there's no need to configure the environment, just enter ./main serve
.
For Linux
users, you need to prepare dependencies by yourself. The installation instructions can be found in Install Dependencies.
g++ main.cpp -o main -lpthread -lcrypto -lssl -ljsoncpp -lmysqlclient -lz -std=c++14 -O2 -g
Just enter MySQL Server and import data.sql
.
- Edit
./config/*_search.json
for all search configuration. - Edit
./config/config.json
for application configuration.
git clone --recursive https://github.com/SonolusHaniwa/sonolus-server-cpp
Basic Compile Command:
g++ main.cpp -o main -lpthread -lcrypto -lssl -ljsoncpp -lmysqlclient -g
Extra Compilation Options List
-DENABLE_SONOLUS
Load main routes of Sonolus Server.-DENABLE_STUDIOS
Load main routes of Sonolus Studios Server (developing...).-DENABLE_MYSQL
allow program interactive with MySQL/MariaDB database.-DENABLE_SQLITE
allow program interactive with SQLite database.
Compile Plugins:
g++ plugins/libsonolush/libsonolush.cpp -o plugins/libsonolush.so -fPIC -shared -std=c++17 -DENABLE_MYSQL -DENABLE_SQLITE
g++ plugins/libsonolusjs/libsonolusjs.cpp -o plugins/libsonolusjs.so -fPIC -shared -std=c++17 -DENABLE_MYSQL -DENABLE_SQLITE
Take Bandori's data package bandori.bin
as an example.
./main import bandori.bin
We provide data package download of all official engines: Data Packages for v1.2.1+
./main serve
Take the export engine named bandori
as an example
./main export engine bandori bandori.bin
Take the export level named bandori-#1
as an example
./main export level "bandori-#1" bandori1.bin
database
: Database type. You can choosemysql
orsqlite
。mysql.hostname
: MySQL Server listen host.mysql.port
: MySQL Server listen port.mysql.username
: MySQL user's name.mysql.password
: MySQL user's password.mysql.database
: MySQL Server database's name.sqlite.dbfile
: SQLite Database File path。server.name
: Default issonolus
.server.title
: Sonolus server's title.server.description
: Sonolus server's description.server.logo
: Sonolus server's logo.server.bannerUrl
: The banner address that will displayed in the app.server.bannerHash
: The SHA1 code of the banner.server.listenHost
: Listening address for WebServer Core.server.listenPort
: Listening port for WebServer Core.server.enableSSL
: Whether the WebServer Core use HTTPS.server.httpsCacert
: Server's CA Certificate.server.httpsPrivate
: Server's Private Certificate.server.threadNumber
: The number of multithread.server.rootUrl
: Website's root directory(without protocol).logSystem.debug
: Whether the WebServer Core output DEBUG info.logSystem.target
: Where the log info was output.0
for none,1
for Console,2
for Log File,3
for Console & Log File.logSystem.targetFile
: Log file path.language.default
: Default language name.
POST /uploader
: Upload a file.GET /data/{hash}
: Download a file whoes SHA-1 is {hash}.GET /sonolus/info
: Fetch the information of the server.GET /sonolus/levels/list
: Fetch a list of levels.GET /sonolus/skins/list
: Fetch a list of skins.GET /sonolus/backgrounds/list
: Fetch a list of backgrounds.GET /sonolus/effects/list
: Fecth a list of effects.GET /sonolus/particles/list
: Fetch a list of particles.GET /sonolus/engines/list
: Fecth a list of engines.POST /sonolus/levels/create
: Put a request to create a level.POST /sonolus/skins/create
: Put a request to create a skin.POST /sonolus/backgrounds/create
: Put a request to create a background.POST /sonolus/effects/create
: Put a request to create an effect.POST /sonolus/particles/create
: Put a request to create a particle.POST /sonolus/engines/create
: Put a request to create an engine.GET /sonolus/levels/{name}
: Fetch the information of level named {name}.GET /sonolus/skins/{name}
: Fetch the information of skin named {name}.GET /sonolus/backgrounds/{name}
: Fetch the information of background named {name}.GET /sonolus/effects/{name}
: Fetch the information of effect named {name}.GET /sonolus/particles/{name}
: Fetch the information of particle named {name}.GET /sonolus/engines/{name}
: Fetch the information of engine named {name}.
GET /
: Website's index.GET /index
: Website's index.GET /levels/list
: List levels according to the filter.GET /skins/list
: List skins according to the filter.GET /backgrounds/list
: List backgrounds according to the filter.GET /effects/list
: List effects according to the filter.GET /particles/list
: List particles according to the filter.GET /engines/list
: List engines according to the filter.GET /levels/search
: Search levels page.GET /skins/search
: Search skins page.GET /backgrounds/search
: Search backgrounds page.GET /effects/search
: Search effects page.GET /particles/search
: Search particles page.GET /engines/search
: Search engines page.GET /levels/create
: Create level page.GET /skins/create
: Create skin page.GET /backgrounds/create
: Create background page.GET /effects/create
: Create effect page.GET /particles/create
: Create particle page.GET /engines/create
: Create engine page.GET /levels/jump/{page}
: Jump to level list page.GET /skins/jump/{page}
: Jump to skin list page.GET /backgrounds/jump/{page}
: Jump to background list page.GET /effects/jump/{page}
: Jump to effect list page.GET /particles/jump/{page}
: Jump to particle list page.GET /engines/jump/{page}
: Jump to engine list page.GET /levels/{name}
: Show information of level named {name}.GET /skins/{name}
: Show information of skin named {name}.GET /backgrounds/{name}
: Show information of background named {name}.GET /effects/{name}
: Show information of effect named {name}.GET /particles/{name}
: Show information of particle named {name}.GET /engines/{name}
: Show information of engine named {name}.
class Search {
vector<SearchOption> options;
}
class SearchOption =
SearchTextOption text ||
SearchSliderOption slider ||
SearchToggleOption toggle ||
SearchSelectOption select;
class SearchTextOption {
string query;
string name;
string type = "text";
string placeholder;
}
class SearchSliderOption {
string query;
string name;
string type = "slider";
int def;
int min;
int max;
int step;
string unit;
}
class SearchToggleOption {
string query;
string name;
string type = "toggle";
bool def = 0;
}
class SearchSelectOption {
string query;
string name;
string type = "select";
int def;
vector<string> values;
}
{
"options": [
{
"query": "keywords",
"name": "#KEYWORDS",
"type": "text",
"placeholder": "#KEYWORDS"
}
]
}
By default, this code deals with all the requirements of ?keywords={{keywords}}
.
Take processing the search level as an example, modify the levelSearch()
function in items/LevelItem.h
.
Function defination: string levelSearch(map<string, string> $_GET) {}
.
Of which $_GET
is the requested GET
parameter, and the return value is the parameter after MySQL SELECT
function WHERE
.
Specific examples:
/**
* @brief Level search request processing function
* @param $_GET requested GET parameter
* @return MySQL search filter code
*/
string levelSearch(map<string, string> $_GET) {
string filter = "";
if ($_GET["keywords"] != "") filter = "title like \"%" + str_replace("\"", "\\\"", $_GET["keywords"]) + "%\"";
return filter;
}
Accroding to the implementation of sevenc-nanashi/chart_cyanvas, we implemented the interface for logging in using Sonolus users.At present, the upper right part of the webpage is the login entry for the webpage.
We have rewritten the automatic compilation scripts for each environment, adding pre-compiled version of the executable file for Linux
users. And for Windows
users, we have changed the installation package to a compressed package containing executable files and runtime environment.
~~Windows users need to execute program "Setup Sonolus Database" as administrator firstly, and then execute "Sonolus Server for Windows" to open the service. ~~
If you want set port to 80/443
, you must have the administrator privilege.
These days, the official wiki website has added an endpoint /sonolus/authenticate
and an object UserProfile
, but I couldn't find the interactive way with the Sonolus app. So I didn't add this function into the application.
- open-source-parsers/jsoncpp
- libmysqlclient
- openssl/openssl
- jquery/jquery
- dankogai/js-base64
- lyoj-dev/webserver
- pluma
- libsonolush
- libsonolusjs
- libonedrive (Default: Disable)
- Add a OneDrive upload and download interface.
- Update workflows script
- Add a Sonolus user login interface and discard the old login interface.
- Fixed some Windows compilation issues.
- Update workflows scripts.
- Add plugin functionality.
- Allow custom Sonolus Server version.
- Update workflows scripts.
- Add package & test engine features.
- Add create items button.
- Add admin login interface.
- Add each component creation page.
- Add a
file
type search component, which can be used to create pages. - Add
Windows
automatic packaging script.
- New support for SQLite database.
- The data package format has been modified to provide support for SQLite.
- Re-package the official engine with a new download link: Data Packages for v1.2.1+。
- New component creation interfaces are added to support the creation of components in the next version.
- Temporarily delete the
/levels/create
interface to facilitate GUI rewriting in the next version.
🎁 Happy Valentine's Day 💝
All basic web interfaces have been completed. At present, all pages and hyperlinks have been consistent with the official ones.
- Add the jump page of all components.
- Update the level search configuration.
- Add the feature to save the status of all search interfaces.
- Fix the problem that language modification only takes effect on the current page.
- Fix the error of displaying
{{html.xxx}}
when the list page has no entries. - Completely repair the memory leak caused by the client's long connection without sending information.
- Add the display of search criteria on the list page of each component.
- Fix the problem of stiff animation when the link jumps.
- Fix the problem of reading error when reading the search configuration file.
- Fix the problem that the search link on the list page of each component cannot be used.
- Fix the problem that the server title cannot be displayed.
- Add a search page for each component.
- Add WebServer Core to display listening address.
- Add the database result quantity feedback function of each component.
- Add the function of user-defined search function for each component.
- Fix the problem that the
/sonolus/*/list
endpoint does not support paging. - Add a list page for each component.
- Modify the loading mode of all pictures as lazy loading.
- Add link jump animation.
- Fix the memory leak error caused by improper memory release.
- Fixed the error that the main page displays
{{html.xxx}}
when there are no entries. - Fixed the program error caused by NULL data in the database.
- Added data import function and provided data packages of bandori, pjsekai, llsif, taiko, voez and deemo.
- Added data export function and provided exporting engines and levels.
- Modified the server startup mode to
./main serve
- Added application help information.
- Fixed Windows version will compiled error caused by missing __int64_t.
- Fixed the error that the feedbacks of all list apis is the same.
- Add the recommended display function, which displays 5 works of the same author by default.
- Add a new homepage and use native javascript to write it after the official project.
- Add the detail page of each component, and use native javascript to write after the official project.
- Add the website internationalization function.
- Fixed the issues occurred by
MYSQL
struct by @LittleYang0531 in #1.
- Add the endpoints to create levels.
- Add a sample page to create levels.
- Provide configuration options to set the website title and banner.
- Merge all the configuration into
./config/config.json
- Optimize the CPU usage of WebServer Core
- Release the first version