Skip to content

Instantly share code, notes, and snippets.

@Laforeta
Last active October 10, 2015 08:40
Show Gist options
  • Save Laforeta/80422cd4b04123bf773c to your computer and use it in GitHub Desktop.
Save Laforeta/80422cd4b04123bf773c to your computer and use it in GitHub Desktop.
Obsolete version, please use https://github.com/Laforeta/ooi2/wiki/Installation-on-ubuntu-14.04-Trusty/
@Laforeta
Copy link
Author

What is OOI?

Online Objects Integration (OOI) is a web-based Kancolle proxy written in Python3 for players outside Japan.

OOI works the best on linux or BSD based servers. While it is technically possible to host OOI on a Windows server, performance is very poor as tornado has not been optimised for windows.

Code repository:
https://github.com/kitakamiooi/ooi2

Installation on Ubuntu

Install the following packages as root:

apt-get update && apt-get upgrade
apt-get install gcc python3-dev python3-pip python-virtualenv git nginx supervisor libcurl4-openssl-dev

Clone the source code of OOI:

cd /srv
git clone https://github.com/kitakamiooi/ooi2.git

Generate a virtualenv for OOI:

virtualenv -p /usr/bin/python3 --no-site-packages ooi2

Enable the virtualenv and install dependencies in PIP.

source /srv/ooi2/bin/activate
pip install -U pip
pip install -U setuptools
pip install pycurl
pip install tornado
deactivate

Prefetch game files

Due to certain technical limitations, a number of files have to be prefetched from the game servers.

mkdir /srv/_kcs
cd /srv/_kcs
wget http://203.104.209.102/kcs/resources/image/world/125_006_184_015_l.png
wget http://203.104.209.102/kcs/resources/image/world/125_006_184_015_s.png
wget http://203.104.209.102/kcs/resources/image/world/125_006_184_016_l.png
wget http://203.104.209.102/kcs/resources/image/world/125_006_184_016_s.png
wget http://203.104.209.102/kcs/resources/image/world/125_006_187_205_l.png
wget http://203.104.209.102/kcs/resources/image/world/125_006_187_205_s.png
wget http://203.104.209.102/kcs/resources/image/world/125_006_187_229_l.png
wget http://203.104.209.102/kcs/resources/image/world/125_006_187_229_s.png
wget http://203.104.209.102/kcs/resources/image/world/125_006_187_253_l.png
wget http://203.104.209.102/kcs/resources/image/world/125_006_187_253_s.png
wget http://203.104.209.102/kcs/resources/image/world/125_006_188_025_l.png
wget http://203.104.209.102/kcs/resources/image/world/125_006_188_025_s.png
wget http://203.104.209.102/kcs/resources/image/world/125_006_189_007_l.png
wget http://203.104.209.102/kcs/resources/image/world/125_006_189_007_s.png
wget http://203.104.209.102/kcs/resources/image/world/125_006_189_039_l.png
wget http://203.104.209.102/kcs/resources/image/world/125_006_189_039_s.png
wget http://203.104.209.102/kcs/resources/image/world/125_006_189_071_l.png
wget http://203.104.209.102/kcs/resources/image/world/125_006_189_071_s.png
wget http://203.104.209.102/kcs/resources/image/world/125_006_189_103_l.png
wget http://203.104.209.102/kcs/resources/image/world/125_006_189_103_s.png
wget http://203.104.209.102/kcs/resources/image/world/125_006_189_135_l.png
wget http://203.104.209.102/kcs/resources/image/world/125_006_189_135_s.png
wget http://203.104.209.102/kcs/resources/image/world/125_006_189_167_l.png
wget http://203.104.209.102/kcs/resources/image/world/125_006_189_167_s.png
wget http://203.104.209.102/kcs/resources/image/world/125_006_189_215_l.png
wget http://203.104.209.102/kcs/resources/image/world/125_006_189_215_s.png
wget http://203.104.209.102/kcs/resources/image/world/125_006_189_247_l.png
wget http://203.104.209.102/kcs/resources/image/world/125_006_189_247_s.png
wget http://203.104.209.102/kcs/resources/image/world/203_104_105_167_l.png
wget http://203.104.209.102/kcs/resources/image/world/203_104_105_167_s.png
wget http://203.104.209.102/kcs/resources/image/world/203_104_209_023_l.png
wget http://203.104.209.102/kcs/resources/image/world/203_104_209_023_s.png
wget http://203.104.209.102/kcs/resources/image/world/203_104_209_039_l.png
wget http://203.104.209.102/kcs/resources/image/world/203_104_209_039_s.png
wget http://203.104.209.102/kcs/resources/image/world/203_104_209_055_l.png
wget http://203.104.209.102/kcs/resources/image/world/203_104_209_055_s.png
wget http://203.104.209.102/kcs/resources/image/world/203_104_209_071_l.png
wget http://203.104.209.102/kcs/resources/image/world/203_104_209_071_s.png
wget http://203.104.209.102/kcs/resources/image/world/203_104_209_102_l.png
wget http://203.104.209.102/kcs/resources/image/world/203_104_209_102_s.png
wget http://203.104.209.102/kcs/resources/image/world/203_104_248_135_l.png
wget http://203.104.209.102/kcs/resources/image/world/203_104_248_135_s.png
wget http://203.104.209.102/kcs/mainD2.swf

Set up supervisord

Create a new supervisord configuration file:

vim /etc/supervisor/conf.d/ooi2.conf

The configuration file should contain the following fields:

[program:ooi2]
command=/srv/ooi2/bin/python3 /srv/ooi2/ooi.py
environment=OOI_SECRET=%Use a strong randomised password for this string%
directory=/srv/ooi2
autostart=true
autorestart=true
user=www-data

ooi.py is the main executable script and accepts three arguments:

  • --port the port number listened on by OOI, default is 8000;
  • --mp Toggles multithreading;
    • --debug Toggles debugging in tornado, Multithreading is turned off whenever this option is enabled.

Additional options available under the “environment=” field. Enter these options as a single line delimited by semicolons.

  • OOI_KCS_DOMAIN: Cache redirection to another domain over HTTP;
  • OOI_KCS_HTTPS_DOMAIN: Cache redirection to another domain over HTTPS;
  • OOI_PROXY_HOST: Make OOI connect to the internet via another proxy upstream, useful when you need to test new settings from a non-Japanese IP.
  • OOI_PROXY_PORT: Specifies port number of the upstream proxy.

Restart supervisor after you have finished editing the config files:
service supervisor restart

If the –mp argument is used to start OOI, additional stops needs to be performed to restart the service reliably:
service supervisor stop
killall python3
service supervisor start

Note that error logs will be saved to
/var/log/supervisor/

Nginx configuration example

A minimum of three configuration files is required for OOI. This example covers the basics; one can always add other functions such as TLS and caching on top of what’s shown here. In theory any http server capable of operating in reverse proxy mode will work, e.g. apache and httpd.

/etc/nginx/kcs_upstream.conf contains the source address to pull the cache files from:

upstream kcs_backend {
  server 203.104.209.71:80;
  server 125.6.184.15:80;
  server 125.6.184.16:80;
  server 125.6.187.205:80;
  server 125.6.187.229:80;
  server 125.6.187.253:80;
  server 125.6.188.25:80;
  server 203.104.248.135:80;
  server 125.6.189.7:80;
  server 125.6.189.39:80;
  server 125.6.189.71:80;
  server 125.6.189.103:80;
  server 125.6.189.135:80;
  server 125.6.189.167:80;
  server 125.6.189.215:80;
  server 125.6.189.247:80;
  server 203.104.209.23:80;
  server 203.104.209.39:80;
  server 203.104.209.55:80;
  server 203.104.209.102:80;
}

/etc/nginx/ooi2_proxy.conf defines the internal proxy between OOI and nginx:

proxy_pass_header Server;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_connect_timeout 2m;
proxy_read_timeout 5m;
proxy_pass http://127.0.0.1:8000;

Timeouts defined here are extremely conservative. In practice they could be reduced to 1000ms or shorter.

/etc/nginx/site-enabled/ooi2.conf contains configuration for the public-facing side of OOI.

include /etc/nginx/kcs_upstream.conf;

server {
  listen 80;
  server_name  www.exampledomain.com;

  location = /favicon.ico {
    alias /srv/ooi2/static/img/favicon.ico;
  }
  location ^~ /static/ {
    alias /srv/ooi2/static/;
  }
  location ^~ /_kcs/ {
    alias /srv/_kcs/;
  }

  location /kcs/ {
    proxy_pass http://kcs_backend;
  }
  location ~ /kcs/resources/image/world/(.*)\.png$ {
    include /etc/nginx/ooi2_proxy.conf;
  }
  location = /kcs/mainD2.swf {
    include /etc/nginx/ooi2_proxy.conf;
  }

  location / {
    include /etc/nginx/ooi2_proxy.conf;
  }

  access_log /var/log/nginx/ooi2-access.log;
  error_log /var/log/nginx/ooi2-error.log;
}

Restart nginx service after you finish editing the configuration file:

service nginx restart

Assuming you have no firewalls restricting external access to port 80, the service should not be accessible over your specific host name.

Optional: Ubuntu server comes with an easy to configure firewalld (ufw). It it highly recommended that you use it for better security.

ufw allow ssh
ufw allow http
ufw enable

Customisable components

/customize/ contains a bunch of files that could be modified to change the appearance of OOI in browser.

  • title.html - Title of the main page;
  • info.htm - Information panel on the right ;
  • copyrigth.html - Copyright bar at the bottom of pages;
  • notice.html - Information panel displayed below the embedded flash module;
  • statistic.html - This is where your analytics/trackers should dwell;

Known Issues

The following functions are not supported and unlikely to be implemented in the near term
* Facebook/Google logins
* Make purchases via the item shop
* Change signature in ranking
* Set up in-game ID (Newly registered accounts only)
Should your account ever get flagged for a password reset, you have to do it via the dmm.com website.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment