PSO2Proxy on Amazon AWS

2014

Since SEGA is doing dumb things with their network, Phantasy Star Online 2 players outside of Japan now need to use a VPN or Proxy to connect to the game. This guide will show you how to set up CyberKitsune’s PSO2Proxy on a private Amazon EC2 instance. This is free for a year, and hopefully more stable than some alternative proxy solutions.

What you’ll need

Before we start, get all of these:

Set up an EC2 instance

Once you have an Amazon AWS account, go to http://aws.amazon.com/ec2/ and click “Sign in to the Console”. You should see the following page. Click “EC2”.

Amazon Web Services

Create a new instance and select the Amazon Linux AMI image.

Launch Instance

Choose Image

Choose Instance Type

Follow the rest of the wizard to finish creating the EC2 instance. Make sure to download your public key (.pem) file.

Back at the EC2 Dashboard, click “Security Groups” on the left. Create a new security group and allow all incoming TCP and UDP traffic from all IPs. The outbound traffic should allow all protocols and IPs by default.

Create Security Group

Save the new security group, then click “Instances” on the left. You only have one instance, so it will already be selected. Click “Actions > Change Security Groups” and switch your instance to your newly created security group.

Change Security Groups

Change Security Groups 2

Now you should be able to connect to your EC2 instance. Follow Amazon’s instructions for connecting to your instance. You can find your public DNS at the bottom of the instances page. Your PuTTY setup should now look like this. Make sure to save these settings as a session.

PuTTY

PuTTY 2

Click “Open” and a console window should appear. Now we follow the instructions on the PSO2Proxy Github page.

Extract SEGA’s public key

Create a new file named “translation.cfg” at C:\Program Files (x86)\SEGA\PHANTASYSTARONLINE2\pso2_bin. Run your text editor as administrator and open the file. Paste the following lines into it:

PublicKeyDump:1
PublicKeyPath:SEGAKey.blob

Now run PSO2Tweaker, make sure item translations are enabled, and start PSO2. You can close PSO2 once you get to the title screen. If everything worked properly, you should now have a “SEGAKey.blob” file in your pso2_bin directory. You can now delete translation.cfg.

Install PSO2Proxy

Run the following commands from PuTTY:

sudo yum install python27 python27-pip gcc python27-devel python-twisted git
sudo easy_install-2.7 pip
git clone https://github.com/cyberkitsune/PSO2Proxy.git ~/PSO2Proxy
cd ~/PSO2Proxy
sudo pip install -r requirements.txt
cd ~/PSO2Proxy/proxy
python27 ./PSO2Proxy.py

The server won’t start up, but it will create some config files.

Open WinSCP. It will ask to import your settings from PuTTY. Do so and connect to your EC2 instance. Navigate to /home/ec2-user/PSO2Proxy/proxy/cfg. Double-click pso2proxy.config.yml and it should open in your text editor. Paste your EC2 instance’s public and private IP addresses in as follows.

admins: [your_sega_id]
bindIp: your_ec2_private_ip_here
blockNameMode: 1
commandPrefix: '!'
enabledShips: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
myIpAddr: your_ec2_public_ip_here
noisy: false

Save the file. WinSCP will automatically upload your changes.

In WinSCP, navigate to /home/ec2-user/PSO2Proxy/proxy/keys. Drag the SEGAKey.blob file you created before onto WinSCP and it will upload the file.

Go back to PuTTY. If you your cursor is on a line starting with >>>, run the following command to close PSO2Proxy.

exit

Then navigate to the keys directory:

cd keys

Now run the following commands to generate the necessary SSH keys:

openssl genpkey -out myKey.pem -algorithm rsa -pkeyopt rsa_keygen_bits:1024
openssl rsa -in myKey.pem -outform MS\ PUBLICKEYBLOB -pubout -out publickey.blob
openssl rsa -pubin -inform MS\ PUBLICKEYBLOB -in SEGAKey.blob -outform PEM -out SEGAKey.pem

Now run the following commands to enable a plug-in which allows PSO2 Tweaker to quickly configure itself:

cd ~/PSO2Proxy/proxy/plugins
ln -s disabled/WebAPI.py .

Everything should be configured now.

Start the server

Let’s create a shortcut to start the server. In WinSCP, navigate to /home/ec2-user/ and right-click the directory background. Click “New > File” and name it something like “start-proxy”. Double-click it to edit it and paste the following:

#!/bin/bash
export PYTHONIOENCODING=utf-8
 
PROXY_DIR=~/PSO2Proxy/proxy
LOG_FILE=~/PSO2Proxy.log
 
cd $PROXY_DIR
nohup python27 PSO2Proxy.py > $LOG_FILE &
tail -f $LOG_FILE

Save it and WinSCP will upload your changes. Right click the file in WinSCP and open its properties. Under the Permissions section, check all the “X” boxes. This makes the script executable so you can run it directly.

Now we can start the server from PuTTY by entering the following command:

~/start-proxy

This will start the proxy in the background and start logging its output to the screen. You are free to close PuTTY at this point. Doing so will not stop PSO2Proxy.

If you ever need to restart the EC2 instance, just connect with PuTTY and run this command to restart the proxy.

Now open your web browser to http://your-ec2-public-ip:8080/config.json (use your EC2 instance’s public IP address). If everything worked, your proxy should respond with

{"host": "your-ec2-public-ip", "version": 1, "name": "Unnamed Server", "publickeyurl": "http://your-ec2-public-ip:8080/publickey.blob"}

Configure PSO2 Tweaker

Start PSO2 Tweaker and click “Menu Orb > Other Tasks > Configure PSO2Proxy Server Settings”. When prompted, enter the config.json URL you tested earlier (http://your-ec2-public-ip:8080/config.json). PSO2 Tweaker should print out “All done! You should now be able to connect to Unnamed Server.” in the log.

You should now be able to connect to PSO2!

Extras

I get a server timed out error when logging in!

Sega’s public key has probably changed. Redo the steps above to get SegaKey.blob and upload it to your keys directory. Open PuTTY and cd to ~/PSO2Proxy/proxy/keys, then run the openssl commands listed above again.

My public IP changed!

If you stop and restart your EC2 instance, your public IP might change. If you change your start-proxy script to the following, it will automatically update pso2proxy.config.yml with your server’s private and public IP addresses.

#!/bin/bash
export PYTHONIOENCODING=utf-8
 
PROXY_DIR=~/PSO2Proxy/proxy
LOG_FILE=~/PSO2Proxy.log
CFG_FILE=$PROXY_DIR/cfg/pso2proxy.config.yml
PRIVATE_IP=$(wget -qO- http://169.254.169.254/latest/meta-data/local-ipv4)
PUBLIC_IP=$(wget -qO- http://169.254.169.254/latest/meta-data/public-ipv4)
 
sed -i -e "s/^\(bindIp:\).*$/\1 $PRIVATE_IP/" -e "s/^\(myIpAddr:\).*$/\1 $PUBLIC_IP/" $CFG_FILE
cd $PROXY_DIR
nohup python27 PSO2Proxy.py > $LOG_FILE &
tail -f $LOG_FILE

Then, you just need to go into PSO2 Tweaker and provide the address to config.json, using the new public IP that your EC2 dashboard shows.

 I need to stop the proxy

The start-proxy script I listed above will start the proxy such that it doesn’t end when you close PuTTY. If you need to stop the proxy, just run the following command from PuTTY:

sudo killall python27

How do I update the software?

Run the following commands from PuTTY:

cd ~/PSO2Proxy
git status

If you see something like this, you have the latest version of PSO2Proxy.

Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean

If you see something like this, there are updates to download.

Your branch is behind 'origin/master' by 4 commits, and can be fast-forwarded.
  (use "git pull" to update your local branch)
nothing to commit, working directory clean

Make sure the proxy is stopped, then run the following command:

git pull

If it worked, you can now start the proxy back up. If it didn’t work, try this:

git fetch
git checkout master
git reset --hard origin/master

Revisions

Oct 14, 2014:

  • Added a solution for server timeout errors when trying to log in.

Oct 8, 2014:

  • Changed a couple lines so you don’t close PuTTY instead of PSO2Proxy in one step if PSO2Proxy has already closed itself.

Oct 2, 2014: 

  • Changed commands to install and use Python 2.7, because Amazon Linux AMI’s version of Python is ancient and might not work well with PSO2Proxy.
  • Fixed an error in the Git command.
  • Changed instructions for enabling the WebAPI plug-in to match CyberKitsune’s latest commits.
  • Improved the start-proxy script.
  • Added instructions to make start-proxy executable.
  • Added a section with extra, useful scripts.

Not Dead Yet

2013

Yep. I’m still working on GlassCalc 2. Here’s what’s new:

It won’t be called GlassCalc

I don’t know what it will be called yet, but glass is no longer prominent in the UI, so I don’t think it should be prominent in the name. Please tell me if you have ideas.

I know what it’s going to look like

Here’s a mockup of the new UI. (You’ll need to use Opera 15+ or Chrome to get anything other than a garbled mess.) In general, all of GlassCalc’s features are there, just in different places.

New UI stuff:

  • Clicking the deg/rad button in the upper-right toggles between degree and radian modes.
  • The “decimal” dropdown in the upper-right changes the default output format. You’ll be able to choose from decimal, scientific, fraction, hexadecimal, octal and binary.
  • The interface is now broken into tabs.
  • Menu gets you to all of the settings that you shouldn’t need to change often.
  • Calculate is the main view. It should be pretty obvious what this one is for. The new layout is inspired by Soulver, and anything that can be evaluated without changing variables will be done as you type.
  • Copy displays the calculator history as plain text, so you can easily copy any section of it.
  • Graph lets you graph functions. This one might not make it into the initial release.

Things that are the same, but different:

  • The input box at the bottom is gone. The calculator history itself will be editable.
  • The variables panel only shows user-defined variables and functions now. Built-in functions and constants will be found in a help window, which I haven’t designed yet.

How much is done?

  • The UI design
  • Most of the parser (I’m using Irony now)

How much isn’t done?

A lot. Don’t expect it to be done soon.

  • A few parser features, like unit conversion
  • The interpreter
  • The extensions system
  • An initial command line UI
  • The Windows UI

Currently, a Windows 8 UI isn’t possible because the Windows 8 API lacks a few features used in Irony. It might be possible to write replacements for those features, or modify Irony so it doesn’t depend on them though.

Also, since nothing in the parser/interpreter should be Windows-specific, it might be possible to get this running on Mono. I won’t be making UIs for Linux or Mac, but the command line version should run. I plan on making everything open source once it’s mostly functional, and I certainly won’t stop anyone from making UIs for other OSes.

New UI for MotioninJoy

2013

If you use MotioninJoy to connect Playstation 3 controllers to your computer as gamepads, then you are probably well aware that the configuration utility is far from pretty or user-friendly. I just finished rewriting the UI to not suck. Check it out at the link below, then come back here to tell me all the things I broke so I can fix them.

MotioninJoy UIRewritten, offline UI for the Playstation 3 gamepad tool, MotioninJoy

%AppData%: Use it.

2012

Dear developers of cross-platform software, I love your software, but there is one thing about Windows you need to learn:

On Linux, application data goes in folders in your home directory. These folders are named after an application and preceded by a period. On Linux, folder names which start with periods are hidden. I don’t see hidden folders, so I don’t see all the config files. I am happy.

On Windows, application data goes in the %AppData% folder, or for large data files, the %LocalAppData% folder. These folders are hidden by default. Config files don’t clutter up my home directory. I am happy.

Here’s the problem: on Windows, application data does not go in the home directory in folders named after applications and preceded by periods. On Windows, folder names which start with periods are not hidden by default. Furthermore, the home directory is not the appropriate place for config files. I see lots of dot-folders cluttering up my home directory. I am unhappy.

In my crusade to put things where they are supposed to go, I have learned a couple things:

  • Some applications have config files which let you change where they put their config files. Others use environment variables. I will list the modifications necessary to fix certain applications below. If you have a fix for an application I haven’t listed, please tell me in the comments and I’ll add it.
  • Some applications are beyond help. In this case, you can hide the files yourself from a command prompt with the following command:
    attrib +S +H "file or folder to hide"

Android SDK

Set an environment variable named ANDROID_SDK_HOME with the value C:\Users\USERNAME\AppData\Local and move the .android folder from your home directory to the local appdata directory. If there are any .ini files in the .android\avd folder, open those and check for any paths that need to be updated.

Netbeans

The newest version of Netbeans finally uses AppData! For older versions, open C:\Program Files\Netbeans\etc\netbeans.conf in a text editor with admin rights (the actual directory may depend on your version of Netbeans). Change the value of netbeans_default_userdir and add a -J-Duser.home property to netbeans_default_options like so:

# ${HOME} will be replaced by JVM user.home system property
netbeans_default_userdir="${HOME}/AppData/Roaming/Netbeans"
 
# Options used by NetBeans launcher by default, can be overridden by explicit
# command line switches:
netbeans_default_options="-J-client -J-Xss2m -J-Xms32m -J-XX:PermSize=32m -J-XX:MaxPermSize=200m -J-Dapple.laf.useScreenMenuBar=true -J-Dsun.java2d.noddraw=true -J-Duser.home=C:/Users/USERNAME/AppData/Roaming/Netbeans"
# Note that a default -Xmx is selected for you automatically.
. . .

Flickering City

2012

There is a wrong note in the piano part of the score, but I can’t fix it because I lost the Lilypond source. I fixed the error in the piano version’s score.

Download MP3 | PDF score