DexterDexter

DexterDeployment

How to deploy your own PokeDexter server.

Deployment Guide

This guide covers deploying PokeDexter for development, testing, or running your own instance.

Prerequisites

RequirementVersionNotes
Node.js22+Required for server
npm8+Comes with Node.js
PM2LatestProcess manager (optional but recommended)
nginxLatestReverse proxy (for production)
GitLatestFor cloning repos

Install Prerequisites

# Node.js 22 (using nvm)
nvm install 22
nvm use 22
 
# PM2
npm install -g pm2
 
# nginx (Ubuntu/Debian)
sudo apt install nginx

Repository Setup

PokeDexter consists of two repositories:

# Clone both repos
git clone <pokedexter-server-repo> pokedexter
git clone <pokedexter-client-repo> pokedexter-client

Server Setup

1. Install Dependencies

cd pokedexter
npm ci

2. Build

npm run build

3. Configure

Edit config/config.js:

// Essential settings
exports.port = 8000;
exports.bindaddress = '0.0.0.0';
 
// For development/private servers
exports.noguestsecurity = true;  // Allow login without auth server
exports.noipchecks = true;       // Allow same-IP battles (for testing)

4. Environment Variables

Create .env in the root:

# Solana Configuration
SOLANA_RPC_URL=https://api.mainnet-beta.solana.com
USDC_MINT=EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v
 
# Wagering Configuration
HOUSE_CUT_PERCENT=5
HOUSE_WALLET_ADDRESS=YourWalletAddressHere
MIN_WAGER_USD=1
MAX_WAGER_USD=100
 
# Facilitator
FACILITATOR_URL=https://x402.dexter.cash

5. Start the Server

Development:

node pokemon-showdown start

Production (PM2):

pm2 start pokemon-showdown --name pokedexter-game -- start
pm2 save

The server runs on port 8000 by default.


Fake Login Server Setup

The fake login server allows instant usernames without registration.

1. Start the Server

# In the pokedexter directory
node fake-login-server.js

Or with PM2:

pm2 start fake-login-server.js --name pokedexter-login
pm2 save

The login server runs on port 8001 by default.


Client Setup

1. Install Dependencies

cd pokedexter-client
npm ci

2. Configure

Edit play.pokemonshowdown.com/config/config.js:

Config.defaultserver = {
  id: 'pokedexter',
  host: 'your-domain.com',      // Your domain
  port: 443,                     // HTTPS port
  httpport: 443,
  altport: 80,
  prefix: '/showdown',
  registered: true
};
 
Config.routes = {
  root: 'your-domain.com',
  client: 'your-domain.com',
  dex: 'dex.pokemonshowdown.com',      // Can use official
  replays: 'replay.pokemonshowdown.com', // Can use official
};

3. Build

node build

4. Serve Static Files

The built client is static HTML/JS/CSS. Serve via nginx:

server {
    listen 80;
    server_name your-domain.com;
    root /path/to/pokedexter-client/play.pokemonshowdown.com;
    index index.html;
    
    location / {
        try_files $uri $uri/ =404;
    }
}

Nginx Reverse Proxy (Production)

For production, use nginx to handle SSL and proxy to the game server:

# /etc/nginx/sites-available/pokedexter
 
# HTTP → HTTPS redirect
server {
    listen 80;
    server_name poke.your-domain.com;
    return 301 https://$server_name$request_uri;
}
 
# Main HTTPS server
server {
    listen 443 ssl http2;
    server_name poke.your-domain.com;
 
    # SSL certificates (Let's Encrypt)
    ssl_certificate /etc/letsencrypt/live/poke.your-domain.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/poke.your-domain.com/privkey.pem;
 
    # Client static files
    root /path/to/pokedexter-client/play.pokemonshowdown.com;
    index index.html;
 
    # Serve static files
    location / {
        try_files $uri $uri/ =404;
    }
 
    # WebSocket proxy to game server
    location /showdown {
        proxy_pass http://localhost:8000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_read_timeout 86400;
    }
}

Enable the site:

sudo ln -s /etc/nginx/sites-available/pokedexter /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx

SSL with Let's Encrypt

# Install certbot
sudo apt install certbot python3-certbot-nginx
 
# Get certificate
sudo certbot --nginx -d poke.your-domain.com
 
# Auto-renewal is set up automatically

PM2 Process Management

View Running Processes

pm2 list

View Logs

pm2 logs pokedexter-game
pm2 logs pokedexter-login

Restart

pm2 restart pokedexter-game
pm2 restart pokedexter-login

Stop

pm2 stop pokedexter-game
pm2 stop pokedexter-login

Startup Script

Make PM2 start on boot:

pm2 startup
# Follow the instructions it gives you
pm2 save

Directory Structure

After setup, your directories should look like:

/home/user/
├── pokedexter/                    # Game server
│   ├── server/
│   ├── sim/
│   ├── config/
│   │   └── config.js              # Server config
│   ├── .env                       # Environment variables
│   ├── fake-login-server.js
│   └── pokemon-showdown           # Entry point

└── pokedexter-client/             # Client
    └── play.pokemonshowdown.com/
        ├── config/
        │   └── config.js          # Client config
        ├── js/                    # Built JavaScript
        ├── style/                 # CSS
        └── index.html

Testing Your Deployment

1. Check Server is Running

curl http://localhost:8000
# Should return something (not connection refused)

2. Check Login Server

curl "http://localhost:8001/?act=getassertion&userid=testuser"
# Should return: testuser,0,

3. Check Client Loads

Visit https://poke.your-domain.com in browser.

4. Test a Battle

  1. Open two browser windows (or use incognito)
  2. Pick different usernames
  3. Challenge one from the other
  4. Battle should work

5. Test Wallet Connection

/connectwallet YourSolanaAddressHere
/mywallet

Troubleshooting

"Connection refused"

  • Check the game server is running: pm2 list
  • Check the port: netstat -tlnp | grep 8000
  • Check firewall: sudo ufw status

"WebSocket connection failed"

  • Check nginx WebSocket config (Upgrade headers)
  • Check SSL certificate is valid
  • Try clearing browser cache

"User not found"

  • Both users must be connected to the same server
  • Check both have picked usernames

"Cannot find module"

# In the problematic directory
rm -rf node_modules
npm ci

Logs

Check logs for errors:

pm2 logs pokedexter-game --lines 100
pm2 logs pokedexter-login --lines 100

Production Checklist

Before going live with wagering:

  • SSL configured and working
  • PM2 startup script enabled
  • .env has real wallet addresses
  • HOUSE_WALLET_ADDRESS is your actual wallet
  • Tested wager flow end-to-end
  • Backup strategy for config files
  • Monitoring/alerting set up
  • Persistence layer for escrow keys (critical!)

Next Steps