OvercastNetwork / OCN

Website and backend of the former Overcast/Lifeboat PC Network
GNU Affero General Public License v3.0
40 stars 22 forks source link

OCN Website/Backend

This is the code that powered the website and backend services of the former Overcast/Lifeboat PC Network.

Besides the removal of some branding and configuration data, it is more or less unmodified. It is probably not directly useful to third parties in its current state, but it may be help in understanding how the ProjectAres plugins work.

We are quite open to the idea of evolving this into something more generally useful. If you would like to contribute to this effort, talk to us in Discord.

NOTE: This repository is no longer maintained, but you can still contribute to forks.

License

OCN Website/Backend is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

A copy of the GNU Affero General Public License is included in the file LICENSE.txt, and can also be found at https://www.gnu.org/licenses/agpl-3.0.en.html

The AGPL license is quite restrictive, please make sure you understand it. If you run a modified version of this software as a network service, anyone who can use that service must also have access to the modified source code.

Architecture

This repo contains the following components:

Install the backend app

Install the following services and configure them to run on their default ports:

Ensure bundler is installed: gem install bundle

Run bundle install to download and install dependencies.

Setup the database

Start MongoDB, Redis, and CouchDB with default settings. Then, run the following shell commands from the Web repo:

rake db:setup
rake db:create_indexes

This should create several databases starting with oc_, generally one for each model.

The OCN-Data repo contains static configuration data for the database. This includes things like permission groups, server families, and game types. Clone it somewhere, and create a symlink to it from /minecraft/repo/data. From the Web repo, run rails c to start a Rails shell session. From the Rails shell, run Repository[:data].load_models to import everything from the Data repo into MongoDB.

Run the backend app

Run the following shell commands from the Web repo to start all the backend services:

rails octc              # Public website on http://localhost:3000
rails api               # Internal API on http://localhost:3010
config/worker.rb        # Worker daemon

At this point, you should be able to visit the website at http://localhost:3000, but there isn't much to see and you have no account to login with. To create an account, we'll first get a Bungee and Lobby running, and then do the standard registration process.

Create a Bungee instance

To create a Bungee server record in the database, run this in the Rails shell:

Server.without_attr_protection{ Server.create!(
    datacenter: 'DV',
    box: Box.local_id,
    network: Server::Identity::Network::PUBLIC,
    role: Server::Role::BUNGEE,
    family: 'bungee',
    name: 'bungee-dev'
)}

Assuming this is the first server you have created, you can retrieve it in the rails shell as Server.first, or Server.bungees.first. Alternately, you can look it up by name (or any other field) with Server.find_by(name: 'bungee-dev'). You can assign it to a local variable in the shell with server = Server.find_by(...). You can inspect fields of the server object with server.field. To see the ID of the server, type server.id.to_s. This 24-digit hex number is the primary key of the server in the database, and will end up in the config.yml file for the API plugin.

Next, setup a BungeeCord server with the API and Commons plugins from the ProjectAres repo (make sure to use our custom BungeeCord fork, the upstream version won't work). In the config.yml file for the API plugin, fill in the top section to match the server record you just created:

server:
  id: 0123456789abcdef01234567        # server.id.to_s
  datacenter: DV                      # server.datacenter
  box: ...                            # server.box
  role: BUNGEE

Start Bungee with a shell command similar to this:

java -Dtc.oc.stage=DEVELOPMENT \
     -jar BungeeCord.jar

At startup, Bungee should connect to the API and retrieve its record from the database, and update that record with its current status. If you try to connect to Bungee, you will just get an error since there is no lobby to join.

Create a Lobby instance

Run this in the Rails shell to create a new Lobby server record:

Server.without_attr_protection{ Server.create!(
    datacenter:'DV',
    box: Box.local_id,
    network: Server::Identity::Network::PUBLIC,
    role: Server::Role::LOBBY,
    family: 'lobby-public',
    bungee_name: 'lobby-dev',
    name: 'Lobby'
)}

If this is the only lobby in the database, you can quickly retrieve it with Server.lobbies.first, or you can use any kind ofServer.find_by query to look it up.

Setup a SportBukkit instance with the appropriate plugins for a lobby. In the config.yml for the API plugin, enter the details from the lobby server record.

Start the server with a shell command similar to this:

java -Xms1G -Xmx1G \
     -Dlog4j.configurationFile=log4j2.xml \
     -Dtc.oc.stage=DEVELOPMENT \
     -jar SportBukkit.jar

You should now be able to connect to your Bungee server and spawn in the lobby.

Create an admin user

To create the initial admin user for the website, type this command into rails console, replacing the data fields with your account info. Make sure to replace the UUID field with the UUID of your Minecraft account, which you can find here

User.without_attr_protection {
    User.create!(
        email: 'your@email',
        username: 'your_username',
        password: 'password',
        password_confirmation: 'password',
        admin: true,
        uuid: 'uuid'
    ).confirm!
}

Create a PGM instance

On the website, under Admin -> Servers, you can see all the servers you have configured, and easily create/edit them. Use this to create a PGM server, by cloning the Lobby server and changing the role to PGM. Then, setup the SportBukkit instance in the same way you did for the Lobby.

You now have a basic working development environment.

Coding Conventions

✔ = Things we presently do fairly well

✘ = Things we presently fail miserably at

Style

Models

Views/Controllers

API

Testing