diff --git a/AUTO_DEPLOY_SETUP.txt b/AUTO_DEPLOY_SETUP.txt deleted file mode 100644 index 836804a..0000000 --- a/AUTO_DEPLOY_SETUP.txt +++ /dev/null @@ -1,108 +0,0 @@ -=============================================================================== -AUTO-DEPLOY SETUP - Fix Database Disconnection After Git Pull -=============================================================================== - -PROBLEM YOU'RE EXPERIENCING: -- Git auto-pulls new code to production -- Database stops connecting -- You have to manually run deploy.sh to fix it - -SOLUTION: -Automatic service restart after every git pull! - -=============================================================================== -INSTALLATION (Run Once on Production Server) -=============================================================================== - -SSH into your production server and navigate to Connect-5 directory, then run: - -bash setup-auto-deploy.sh - -That's it! The script will: -ā Install a git post-merge hook -ā Detect your service manager (PM2/systemd/manual) -ā Configure automatic restart after git pull - -=============================================================================== -HOW IT WORKS -=============================================================================== - -After installation, every time git pulls new code: - -1. Git auto-pull happens (your existing automation) -2. Git triggers the post-merge hook automatically -3. Hook checks if package.json changed ā runs npm install if needed -4. Hook restarts the Node.js service automatically -5. Database reconnects immediately -6. No manual intervention needed! - -=============================================================================== -WHAT'S INCLUDED -=============================================================================== - -š git-hooks/post-merge - - The hook script that runs after git pull - - Handles: npm install + service restart - - Works with: PM2, systemd, or manual process restart - -š setup-auto-deploy.sh - - One-time setup script - - Copies hook to .git/hooks/ - - Makes it executable - - Tests which service manager you're using - -=============================================================================== -QUICK SETUP (Copy/Paste This) -=============================================================================== - -On your production server: - -cd /path/to/Connect-5 -bash setup-auto-deploy.sh - -Answer "y" when asked to test the hook. - -=============================================================================== -VERIFICATION -=============================================================================== - -After setup, test it: - -1. Make a small change to README.md on your local machine -2. Git push from local -3. Wait for server to auto-pull (your existing setup) -4. SSH into server and check: - - # Check if service restarted - pm2 logs connect5 - # OR - sudo systemctl status connect5 - # OR - tail -f server.log - -5. You should see: - "š Git Pull Detected - Running Auto-Deploy" - "ā Auto-Deploy Complete!" - -=============================================================================== -NO MORE MANUAL DEPLOYS! -=============================================================================== - -Before: Git pulls ā Database disconnects ā You run deploy.sh manually -After: Git pulls ā Hook runs ā Service restarts ā Database reconnects ā - -You'll never need to run deploy.sh manually again for database connection issues! - -=============================================================================== -ROLLBACK (If Needed) -=============================================================================== - -To disable auto-deploy: - -rm .git/hooks/post-merge - -To re-enable: - -bash setup-auto-deploy.sh - -=============================================================================== diff --git a/DEPLOYMENT.md b/DEPLOYMENT.md index 9599736..90dff4e 100644 --- a/DEPLOYMENT.md +++ b/DEPLOYMENT.md @@ -337,6 +337,42 @@ sudo systemctl restart apache2 --- +## š Auto-Restart & Auto-Deploy + +### 1. Enable Auto-Start on Boot (Systemd) + +To ensure your application starts automatically when the server reboots: + +```bash +cd /path/to/Connect-5 +sudo bash setup-auto-start.sh +``` + +This script will: +* Install `connect5.service` to systemd +* Configure the service to wait for PostgreSQL +* Enable it to start on boot +* Auto-restart the app if it crashes (10s delay) + +### 2. Enable Auto-Deploy (Git Hooks) + +To automatically restart the database and server every time you `git pull`: + +```bash +cd /path/to/Connect-5 +bash setup-auto-deploy.sh +``` + +This installs a git `post-merge` hook that: +* Detects when code is pulled +* Runs `npm install` (only if package.json changed) +* Restarts the `connect5` service +* Ensures the connection is refreshed properly + +This prevents "Database Disconnected" errors after updates. + +--- + ## Support For issues: diff --git a/PRODUCTION_DEPLOYMENT_STEPS.txt b/PRODUCTION_DEPLOYMENT_STEPS.txt deleted file mode 100644 index 45d547b..0000000 --- a/PRODUCTION_DEPLOYMENT_STEPS.txt +++ /dev/null @@ -1,183 +0,0 @@ -=============================================================================== -PRODUCTION DEPLOYMENT INSTRUCTIONS - PostgreSQL Migration -=============================================================================== - -Git changes have been pushed. Since you have auto-pull set up, follow these -steps on your PRODUCTION SERVER to complete the migration: - -=============================================================================== -STEP 1: After Git Auto-Pull Completes -=============================================================================== - -SSH into your production server and navigate to the Connect-5 directory. - -=============================================================================== -STEP 2: Install New Dependencies -=============================================================================== - -npm install - -This will: -- Remove @supabase/supabase-js -- Install pg (PostgreSQL driver) - -=============================================================================== -STEP 3: Create db.config.js with PostgreSQL Credentials -=============================================================================== - -IMPORTANT: You need to create db.config.js on the production server. - -Option A - Using the example file: ------------------------------------ -cp db.config.example.js db.config.js -nano db.config.js - -Then edit with your PostgreSQL credentials: -{ - HOST: '202.171.184.108', - USER: 'postgres', - PASSWORD: 'X@gon2005!#$', - DB: 'connect5', - dialect: 'postgres', - pool: { max: 5, min: 0, acquire: 30000, idle: 10000 } -} - -Option B - Quick create (copy/paste this entire block): --------------------------------------------------------- -cat > db.config.js << 'EOF' -module.exports = { - HOST: '202.171.184.108', - USER: 'postgres', - PASSWORD: 'X@gon2005!#$', - DB: 'connect5', - dialect: 'postgres', - pool: { - max: 5, - min: 0, - acquire: 30000, - idle: 10000 - } -}; -EOF - -=============================================================================== -STEP 4: Apply Database Schema (if not already done) -=============================================================================== - -Run the schema application script: - -node apply-schema.js - -Expected output: -ā Schema applied successfully! -ā Found 4 tables: active_sessions, game_moves, games, players - -If you see errors about tables already existing, that's fine - skip this step. - -=============================================================================== -STEP 5: Restart the Node.js Service -=============================================================================== - -Depending on how you're running the server: - -Option A - If using PM2: ------------------------- -pm2 restart connect5 -# OR -pm2 restart server.js -# OR -pm2 restart all - -Option B - If using nohup: --------------------------- -pkill -f "node server.js" -sleep 2 -nohup node server.js > server.log 2>&1 & - -Option C - If using systemd service: ------------------------------------- -sudo systemctl restart connect5 -# OR -sudo systemctl restart connect5.service - -Option D - Not sure what's running it? --------------------------------------- -# Check what's running -ps aux | grep "node server.js" - -# Kill the process (replace PID with actual process ID) -kill -9 PID - -# Start it again -nohup node server.js > server.log 2>&1 & - -=============================================================================== -STEP 6: Verify the Service is Running -=============================================================================== - -Check if the server started successfully: - -# View the logs -tail -f server.log - -Expected output: -š Initializing PostgreSQL database schema... -ā Database schema verified successfully -š Server running on port 3000 -š” WebSocket server ready -šļø Database connected - -# Test the API endpoint -curl http://localhost:3000/api/db-status - -Expected response: -{ - "connected": true, - "latency": 10, - "writeCapable": true, - "connectionType": "PostgreSQL Direct Connection", - "host": "202.171.184.108", - "database": "connect5" -} - -=============================================================================== -STEP 7: Test the Production URL -=============================================================================== - -Visit your production URL (e.g., https://connect5.beyondcloud.technology/) - -Verify: -ā Page loads correctly -ā Status bar shows "Connected" in green -ā Latency is displayed -ā "Write: Enabled" shows in green -ā Multiplayer functionality works - -=============================================================================== -SUMMARY OF SERVICES TO RESTART -=============================================================================== - -You need to restart: -ā Node.js service (server.js) - This is the ONLY service that needs restarting - -You DO NOT need to restart: -ā Nginx/Apache (web server) - No changes to proxy config -ā PostgreSQL - Database server continues running -ā The production server itself - -=============================================================================== -TROUBLESHOOTING -=============================================================================== - -If the service won't start: -1. Check db.config.js exists and has correct credentials -2. Check logs: tail -f server.log -3. Test database connection: node apply-schema.js -4. Ensure PostgreSQL is accessible from production server - -Common issues: -- "Cannot find module './db.config.js'" ā Create db.config.js (Step 3) -- "Table 'players' does not exist" ā Run apply-schema.js (Step 4) -- "ECONNREFUSED" ā Check PostgreSQL firewall/network access - -=============================================================================== diff --git a/README.md b/README.md index 6eb012f..4f1ff15 100644 --- a/README.md +++ b/README.md @@ -35,9 +35,11 @@ A beautiful, feature-rich implementation of the classic Connect-5 (Gomoku) game ### š Multiplayer Features - **Player Lobby**: See all online players in real-time - **Challenge System**: Send and receive game invitations +- **Surrender Option**: Forfeit games gracefully with confirmation +- **Rematch System**: Instantly challenge the same opponent again +- **Reliable Connections**: Auto-reconnect and state restoration - **Player Statistics**: Track wins, losses, and draws - **Auto-Login**: Username persistence across sessions -- **Session Management**: Automatic reconnection handling - **Profanity Filter**: Safe and family-friendly usernames ### š² Gameplay diff --git a/SETUP_INSTRUCTIONS.txt b/SETUP_INSTRUCTIONS.txt deleted file mode 100644 index 3037de4..0000000 --- a/SETUP_INSTRUCTIONS.txt +++ /dev/null @@ -1,70 +0,0 @@ -================================================================= -POSTGRESQL MIGRATION - FINAL SETUP STEP -================================================================= - -ā Code migration: COMPLETE -ā Dependencies installed: COMPLETE -ā Configuration file created: COMPLETE - -ā ļø DATABASE SCHEMA: NEEDS TO BE APPLIED - -================================================================= -NEXT STEP: Initialize PostgreSQL Database -================================================================= - -You need to run the postgres-schema.sql file on your PostgreSQL server. - -METHOD 1: If you have PostgreSQL client tools installed --------------------------------------------------------- -Run this command from PowerShell: - -$env:PGPASSWORD='X@gon2005!#$'; psql -h 202.171.184.108 -U postgres -d connect5 -f postgres-schema.sql - -METHOD 2: Using pgAdmin or another PostgreSQL GUI --------------------------------------------------- -1. Open pgAdmin or your PostgreSQL management tool -2. Connect to server: 202.171.184.108 -3. Username: postgres -4. Password: X@gon2005!#$ -5. Right-click on database 'connect5' (create if doesn't exist) -6. Select "Query Tool" -7. Open the file: postgres-schema.sql -8. Execute the entire script -9. You should see "Tables Created Successfully! table_count = 4" - -METHOD 3: Copy/Paste SQL -------------------------- -If database 'connect5' doesn't exist, first run: - CREATE DATABASE connect5; - -Then connect to connect5 and run the entire contents of: - postgres-schema.sql - -================================================================= -VERIFY SCHEMA WAS APPLIED -================================================================= - -After running the schema, verify with this query: - -SELECT table_name -FROM information_schema.tables -WHERE table_schema = 'public' -AND table_name IN ('players', 'active_sessions', 'games', 'game_moves'); - -Expected: 4 tables listed - -================================================================= -THEN START THE SERVER -================================================================= - -Once the schema is applied: - -npm start - -The server should start successfully and show: - ā Database schema verified successfully - š Server running on port 3000 - -Then test at: http://localhost:3000 - -================================================================= diff --git a/apply-prod-schema.sh b/apply-prod-schema.sh new file mode 100644 index 0000000..e09ff28 --- /dev/null +++ b/apply-prod-schema.sh @@ -0,0 +1,14 @@ +#!/bin/bash +# Apply schema update to production database +# Use this if you are getting "function increment_wins does not exist" errors + +# Setup +export PGHOST=202.171.184.108 +export PGUSER=postgres +export PGPASSWORD=your_password_here +export PGDATABASE=connect5 + +echo "Applying schema..." +psql -f postgres-schema.sql + +echo "Done!" diff --git a/apply-schema.js b/apply-schema.js deleted file mode 100644 index 3e318a1..0000000 --- a/apply-schema.js +++ /dev/null @@ -1,60 +0,0 @@ -// Quick script to apply postgres-schema.sql to the database -// Run with: node apply-schema.js - -const fs = require('fs'); -const { Pool } = require('pg'); -const dbConfig = require('./db.config.js'); - -const pool = new Pool({ - host: dbConfig.HOST, - user: dbConfig.USER, - password: dbConfig.PASSWORD, - database: dbConfig.DB, - port: 5432 -}); - -async function applySchema() { - try { - console.log('š Reading postgres-schema.sql...'); - const schema = fs.readFileSync('./postgres-schema.sql', 'utf8'); - - console.log('š Connecting to PostgreSQL...'); - console.log(` Host: ${dbConfig.HOST}`); - console.log(` Database: ${dbConfig.DB}`); - - console.log('āļø Applying schema...'); - await pool.query(schema); - - console.log('ā Schema applied successfully!'); - - // Verify tables were created - console.log('\nš Verifying tables...'); - const result = await pool.query(` - SELECT table_name - FROM information_schema.tables - WHERE table_schema = 'public' - AND table_name IN ('players', 'active_sessions', 'games', 'game_moves') - ORDER BY table_name; - `); - - console.log(`ā Found ${result.rows.length} tables:`); - result.rows.forEach(row => { - console.log(` - ${row.table_name}`); - }); - - if (result.rows.length === 4) { - console.log('\nš Database setup complete! You can now run: npm start'); - } else { - console.log('\nā ļø Warning: Expected 4 tables but found', result.rows.length); - } - - } catch (error) { - console.error('ā Error applying schema:', error.message); - console.error('\nDetails:', error); - process.exit(1); - } finally { - await pool.end(); - } -} - -applySchema(); diff --git a/fix-existing-vhost.sh b/fix-existing-vhost.sh deleted file mode 100644 index debed56..0000000 --- a/fix-existing-vhost.sh +++ /dev/null @@ -1,97 +0,0 @@ -#!/bin/bash -# Add proxy rules to existing CloudSticks vhost config - -echo "š§ Adding proxy rules to existing app-connect5.conf" -echo "====================================================" -echo "" - -GREEN='\033[0;32m' -NC='\033[0m' - -if [ "$EUID" -ne 0 ]; then - echo "ā Run with sudo" - exit 1 -fi - -CONFIG="/etc/nginx-cs/vhosts.d/app-connect5.conf" - -echo "Step 1: Backing up existing config..." -cp "$CONFIG" "${CONFIG}.backup.$(date +%Y%m%d_%H%M%S)" -echo -e "${GREEN}ā Backup created${NC}" -echo "" - -echo "Step 2: Adding proxy rules..." - -# Add proxy rules before the closing brace -sed -i '/^}$/i\ -\ - # Connect-5 API Proxy\ - location /api {\ - proxy_pass http://localhost:3000;\ - proxy_http_version 1.1;\ - proxy_set_header Upgrade $http_upgrade;\ - proxy_set_header Connection '"'"'upgrade'"'"';\ - proxy_set_header Host $host;\ - proxy_cache_bypass $http_upgrade;\ - 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;\ - }\ -\ - # Connect-5 Socket.io Proxy\ - location /socket.io {\ - proxy_pass http://localhost:3000;\ - proxy_http_version 1.1;\ - proxy_set_header Upgrade $http_upgrade;\ - proxy_set_header Connection "upgrade";\ - proxy_set_header Host $host;\ - proxy_cache_bypass $http_upgrade;\ - 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;\ - }' "$CONFIG" - -echo -e "${GREEN}ā Proxy rules added${NC}" -echo "" - -echo "Step 3: Removing duplicate connect5-proxy.conf..." -rm -f /etc/nginx-cs/vhosts.d/connect5-proxy.conf -echo -e "${GREEN}ā Removed duplicate${NC}" -echo "" - -echo "Step 4: Restarting nginx-cs..." -systemctl restart nginx-cs -echo -e "${GREEN}ā Nginx restarted${NC}" -echo "" - -echo "Step 5: Checking Node.js..." -if ! pgrep -f "node server.js" > /dev/null; then - cd /home/github2/apps/app-connect5 - nohup node server.js > server.log 2>&1 & - sleep 2 -fi -echo -e "${GREEN}ā Node.js running${NC}" -echo "" - -echo "Step 6: Testing..." -sleep 3 - -LOCAL=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:3000/api/db-status 2>/dev/null) -PROD=$(curl -s -o /dev/null -w "%{http_code}" https://connect5.beyondcloud.technology/api/db-status 2>/dev/null) - -echo "Local: HTTP $LOCAL" -echo "Production: HTTP $PROD" -echo "" - -if [ "$PROD" = "200" ]; then - echo -e "${GREEN}ā ā ā SUCCESS! ā ā ā ${NC}" - echo "" - curl -s https://connect5.beyondcloud.technology/api/db-status | python3 -m json.tool 2>/dev/null - echo "" - echo "====================================================" - echo -e "${GREEN}š PRODUCTION IS LIVE! š${NC}" - echo "Visit: https://connect5.beyondcloud.technology/" - echo "====================================================" -else - echo "ā ļø Still HTTP $PROD - check logs" -fi diff --git a/temp-multiplayer-methods.txt b/temp-multiplayer-methods.txt deleted file mode 100644 index ae444f4..0000000 --- a/temp-multiplayer-methods.txt +++ /dev/null @@ -1,71 +0,0 @@ - - // Surrender game - surrenderGame() { - if (!this.isMultiplayer || !this.currentGameId) { - this.showMessage('No active game to surrender', 'error'); - return; - } - - this.socket.emit('surrender', { gameId: this.currentGameId }); - } - - // Handle rematch request from opponent - handleRematchRequest(data) { - const notification = document.createElement('div'); - notification.className = 'challenge-notification'; - notification.innerHTML = ` -
${data.from} wants a rematch
-Board size: ${data.boardSize}Ć${data.boardSize}
-