RAGE Multiplayer backend development boilerplate
Start your next project within seconds! This boilerplate accelerates the work you need to put to start developing server. Just clone repo, install packages, setup database with two commands and thats it! You have working environment ready! 👏
🚗 Included example vehicle model with manager, loader, migration and seeder!
- Clone or download repository.
- Copy RAGE Multiplayer server-files files and paste here.
- Open terminal and:
- Type
npm install
. cd .env.example .env
- Edit .env with your configs.
- Create database using Sequelize CLI:
sequelize db:create
. - Type
npm run watch
. (migrations are run automatically!) - Run watch tasks
tsc -w
orCtrl+Shift+B
onsrc/server
andsrc/client
folders. - That's it! You are ready to develop. Any changes in files in
src/client
orsrc/server
directory gonna automatically restart server! ✨
- Type
Should be inside src
folder or in a different repository linked by submodules, and then compiled to client_packages with gulp or something.
- ESLint with JavaScript standard style config, prepared for ES6.
- dotenv zero-dependency module that loads environment variables from a .env file into process.env.
- nodemon monitor any changes in server/client files and automatically restart the server!
- sequelize promise-based ORM for Node.js including CLI to easily operate on database (see commands below).
- mysql2 fast mysql driver.
- lodash utility library thats deliver modularity, performance, & extras.
- log4js logging library for Node.js based on original Log4js framework.
Client-side features
- Disabled vehicle rewards,
- Disabled wanted stars and cash hud,
- Three new functions for managing chat. States of two last functions are "saved" to globals:
- clearGameChat() - clear game chat.
- toggleChat(boolean) - toggles chat visibility.
- disableChat(boolean) - enables or disables chat.
Client-side helpers
- hideHudElements(array) - hide hud elements from array.
- disableControlActions(array) - disable controls from array.
- sendHelpMessage(string) - sends help message in the top left corner.
Server-side features
- Loads server gamemode async with help of loaders,
- Logger based on log4js package, with following configuration:
- Logs inside /logs/ directory and printed in console,
- Easy wrapper function around logger - logger(moduleName, message, type), for example:
logger('vehicle', 'Created vehicle Sabre on world.', 'info');
- Available log types;
trace, debug, info, warn, error, fatal
.
- Sequelize as promise-based ORM with following things:
- Ability to loading models dynamically from
models
directory, - One example model Vehicle,
- Migration for model Vehicle,
- Seeder for model Vehicle.
- Ability to loading models dynamically from
- Three loaders, following:
- "Bootstrap" loader - responsible for booting all the database models data for the script (ex: characters, vehicles, doors, etc).
- Commands loader - responsible for sync all commands files from directory and put them on server.
- Database loader - responsible for load database and models from main database file.
- Example vehicles manager, with following functions:
- create(player, model) - creates entry as vehicle in database with given model and random colors.
- spawn(vehicle) - creates vehicle (entity) from database ingame.
- configureCreated(createdVehicle, vehicleData) - configures created vehicle with given data, setting and assigns example informations from database to entity.
- loadAll() - loads all vehicles from database and spawns them ingame.
- Example command (/vehicle) to create vehicle to show how its working with "manager".
Server-side helpers
- randomInt(min, max) - returns random int from min to max.
watch
starts server and monitor all changes in files underclient_packages
andpackages
directory.watch-server
starts server and watch all changes in files underpackages
directory.watch-client
starts server and watch all changes in files underclient_packages
directory.
I don't want MySQL. What about PostgreSQL/SQLite?
- Change dialect to the right one (sqlite, postgres), remove package mysql2, and switch to one of the following:
- For PostgreSQL:
yarn add pg pg-hstore
ornpm install --save pg pg-hstore
- For SQLite
yarn add sqlite3
ornpm install --save sqlite3
- For PostgreSQL:
I don't like semicolons! (eslint)
- Edit line semi under rules with following code:
"semi": ["error", "never"]
I want identation with tabs, not spaces! (eslint)
- No worries. Add rule indent with following code:
["error", "tab"]
I want double quotes! (eslint)
- Add rule quotes with following code:
["error", "double"]
- RAGE Multiplayer Wiki all you need to develop server.
- Sequelize Docs documentation for Sequelize.
- Node.js Docs - Node.js documentation.
If you want use 'sequelize' globally, just install CLI globally with:
- Yarn:
yarn global add sequelize-cli
- NPM:
npm install -g sequelize-cli
db:migrate Run pending migrations.
db:migrate:status List the status of all migrations.
db:migrate:undo --name migration-file.js Reverts a specific migration.
db:migrate:undo:all Revert all migrations ran.
db:seed Run specified seeder.
db:seed:undo Deletes data from the database.
db:seed:all Run every seeder.
db:seed:undo:all Deletes data from the database.
db:create Create database specified by configuration.
db:drop Drop database specified by configuration.
migration:generate Generates a new migration file.
model:generate Generates a model and its migration.
seed:generate Generates a new seed file.
If you want to help community grow or just expand this example, before pushing pull request please make sure your code is formatted along with JavaScript Standard Style (or just don't change anything in this eslint config).