Skip to main content

Overview

GamePanelX’s network management system enables you to manage game servers across multiple physical servers, both local and remote. The network module handles IP address allocation, SSH connectivity, and remote command execution.

Multi-Server Support

Manage servers across multiple physical machines and locations

IP Management

Track and allocate IP addresses and ports automatically

Remote Control

Execute commands via SSH on remote servers

Load Balancing

Distribute servers based on network load monitoring

Network Architecture

GamePanelX supports two deployment types:

Local Servers

Characteristics:
  • Game servers run on the same machine as the web panel
  • Commands executed via PHP exec() function
  • Direct file system access
  • No SSH required
  • Faster operations
Use Cases:
  • Small installations
  • Development/testing environments
  • Single-server game hosting

Remote Servers

Characteristics:
  • Game servers run on separate physical machines
  • Commands executed via SSH (PHPSecLib)
  • Encrypted credentials
  • Parent-child network hierarchy
  • Distributed infrastructure
Use Cases:
  • Multi-server hosting providers
  • Geographic distribution
  • Load balancing across hardware
  • Dedicated game server nodes

Network Server Management

Creating Network Servers

The Network::create() method adds new network servers:
Create Network Server
// Add a network server
$Network = new Network();
$result = $Network->create(
    $ip,            // IP address (x.x.x.x format)
    $is_local,      // 1 for local, 0 for remote
    $os,            // Operating system
    $datacenter,    // Datacenter name/location
    $location,      // Geographic location
    $login_user,    // SSH username (for remote)
    $login_pass,    // SSH password (for remote)
    $login_port     // SSH port (default 22)
);
1

Validation

  • Validates IP address format
  • Checks for duplicate IP addresses
  • Verifies required parameters
2

Local Setup

For local servers:
  • Verifies exec() function is available
  • Checks script permissions in _SERVERS/scripts/
  • Confirms scripts are executable
3

Remote Setup

For remote servers:
  • Tests SSH connectivity
  • Verifies login credentials
  • Checks script installation with CheckInstall
  • Creates callback token for remote communication
  • Syncs existing user accounts to remote server
4

Database Entry

  • Encrypts SSH credentials using AES
  • Stores network configuration
  • Generates unique token for callbacks
Remote servers require the GamePanelX Remote package to be installed at /usr/local/gpx/. The CheckInstall script verifies proper installation.

Network Hierarchy

GamePanelX supports parent-child network relationships:
Parent Network Server (Physical Machine)
├── Child IP 1 (192.168.1.100)
├── Child IP 2 (192.168.1.101)
└── Child IP 3 (192.168.1.102)
Parent Servers:
  • Physical machine running game servers
  • Has SSH credentials
  • Manages all child IPs
  • Field: parentid = 0
Child IPs:
  • Additional IP addresses on the same physical machine
  • Inherit parent’s SSH credentials
  • Share the same physical resources
  • Field: parentid = <parent_id>

Deleting Network Servers

Delete Network Server
// Delete a network server
$Network = new Network();
$result = $Network->delete($netid);
Deletion Process:
  1. Checks if any servers use this network ID
  2. Prevents deletion if servers exist
  3. Deletes associated templates
  4. Removes parent and all child IPs
All servers must be removed before deleting a network server. Templates associated with the network will also be deleted.

Remote Command Execution

Running Commands

The Network::runcmd() method is the core of remote operations:
Execute Remote Command
// Run a command on a network server
$Network = new Network();
$result = $Network->runcmd(
    $netid,         // Network server ID
    $netarr,        // Network info array
    $cmd,           // Command to execute
    $output,        // Return output? (true/false)
    $gamesrv_id     // Server ID (for SSO commands)
);
Command Execution Flow:
// Local server command
$cmd = DOCROOT.'/_SERVERS/scripts/Restart -u user -i 192.168.1.1 -p 27015';
$cmd = 'export HOME='.DOCROOT.'/_SERVERS; ' . $cmd;
$cmd .= ' 2>&1'; // Capture stderr

$result = exec($cmd);
Process:
  1. Prepends script path: _SERVERS/scripts/
  2. Sets $HOME environment variable
  3. Redirects stderr to stdout
  4. Executes via exec(), shell_exec(), or system()

SSO vs Admin Commands

GamePanelX uses different authentication for different commands:
These commands run as the game server owner:
  • Restart
  • Stop
  • UpdateServer
  • DeleteServer
  • CheckGame
  • ServerOutput
  • ServerSendCMD
  • ConfigUpdate
  • MoveServerLocal
Authentication: Uses decrypted SSO credentials from user accountUser Format: gpx + username (e.g., gpxjohn)
These commands run as the main GPX user:
  • AutoInstall
  • CheckCreateServerStatus
  • CheckInstall
  • CheckTemplates
  • CreateUser
  • CreateTemplate
  • CreateServer
  • DeleteUser
  • DeleteTemplate
  • ChangePassword
  • UsernameChange
  • SteamCMDInstall
  • SteamInstall
Authentication: Uses network server’s SSH credentials

Command Security

All commands are sanitized before execution:
Command Sanitization
// Remove dangerous patterns
$cmd = str_replace('..', '', $cmd);           // No directory traversal
$cmd = str_replace(';', '', $cmd);            // No command chaining
$cmd = str_replace('&&', '', $cmd);           // No AND operators
$cmd = preg_replace('/\ +/', ' ', $cmd);     // Normalize spaces
Commands containing .. are automatically sanitized. Multi-command sequences with ; or && are blocked except for UpdateServer commands.

IP Address Management

Automatic IP/Port Allocation

GamePanelX can automatically find available IP/port combinations:
Find Available Port
// Get available IP and port for a game
$Servers = new Servers();
$available = $Servers->get_avail_ip_port(
    $game_intname,  // Game internal name
    $port           // Optional: specific port to try
);

// Returns:
// [
//   'available' => 'yes',
//   'netid'     => 5,
//   'port'      => 27015
// ]
Allocation Strategy:
1

Load Balancing

  • Queries loadavg table for server loads
  • Selects network server with lowest load average
  • Falls back to first available if no load data exists
2

Default Port

  • Retrieves default port from game configuration
  • Checks each IP address for default port availability
  • Returns first IP where default port is free
3

Alternative Ports

  • If default port unavailable on all IPs
  • Increments port from default+10 to default+60
  • Returns first available port on any IP
4

Failure

  • Returns available = 0 if no ports found
  • Admin must manually specify port or add IPs

Port Conflict Detection

Before creating servers, GamePanelX validates IP/port availability:
Check IP/Port Combination
// Verify IP/port is not in use
$Servers = new Servers();
$is_available = $Servers->checkcombo($netid, $port);

// Returns: true if available, false if in use
GamePanelX prevents port conflicts by checking the database before server creation. Each IP/port combination can only be used once.

Network Information Retrieval

Getting Network Details

The Network::netinfo() method retrieves network server configuration:
Get Network Info
// Get network server details
$Network = new Network();
$net_info = $Network->netinfo($netid);

// Returns:
// [
//   'is_local'     => 0,
//   'ssh_user'     => 'gpx',
//   'ssh_pass'     => 'decrypted_password',
//   'ssh_port'     => 22,
//   'ssh_homedir'  => '/usr/local/gpx/',
//   'ssh_ip'       => '192.168.1.10',
//   'real_ip'      => '192.168.1.100',  // Child IP
//   'game_ip'      => '192.168.1.10'    // Parent IP
// ]
Retrieved Information:
  • SSH connection details (decrypted)
  • Local vs remote status
  • Parent and child IP relationships
  • Home directory path
  • Server working directory and PID file location

Checking Local vs Remote

Check Server Type
// Determine if a server is local
$Network = new Network();
$is_local = $Network->islocal($server_id);

// Returns: 1 for local, 0 for remote

Load Monitoring

GamePanelX tracks network server resources:

Load Average Table

CREATE TABLE loadavg (
  id INT UNSIGNED AUTO_INCREMENT,
  netid INT UNSIGNED,          -- Network server ID
  free_mem INT UNSIGNED,       -- Free memory (MB)
  total_mem INT UNSIGNED,      -- Total memory (MB)
  timestamp TIMESTAMP,         -- Last update time
  load_avg VARCHAR(6),         -- Load average (e.g., "0.45")
  PRIMARY KEY (id)
);
Load Data Collection:
1

Remote Manager

GamePanelX Remote Manager runs on each network server
2

Periodic Callback

Manager calls back to web panel every 5 minutes
3

System Metrics

  • Load average from /proc/loadavg
  • Memory usage from /proc/meminfo
  • Current timestamp
4

Database Update

Panel updates loadavg table with current metrics
Load averages are used for automatic server placement. Servers are preferentially created on network nodes with the lowest load.

Database Schema

Network Table

CREATE TABLE network (
  id INT UNSIGNED AUTO_INCREMENT,
  parentid INT UNSIGNED,           -- Parent network ID (0 if parent)
  is_local TINYINT(1) DEFAULT 0,   -- 1=local, 0=remote
  login_user BLOB,                 -- AES encrypted SSH username
  login_pass BLOB,                 -- AES encrypted SSH password
  login_port BLOB,                 -- AES encrypted SSH port
  ip VARCHAR(20),                  -- IP address
  token VARCHAR(32),               -- Callback token
  os VARCHAR(64),                  -- Operating system
  location VARCHAR(128),           -- Geographic location
  datacenter VARCHAR(128),         -- Datacenter name
  homedir VARCHAR(255),            -- Remote home directory
  PRIMARY KEY (id),
  KEY parentid (parentid)
);

Callback System

Remote servers communicate back to the panel via callbacks:

Callback URL Format

http://panel.domain.com/includes/callback.php?token=abc123&id=45
Parameters:
  • token - Unique security token (32 characters)
  • id - Server or network ID
  • Optional: status, msg, progress

Callback Uses

# CreateServer script calls back on completion
wget -qO- "$callback_url&status=complete"
Updates server status from installing to complete
Callbacks use tokens for security. Each operation generates a unique token stored in the database. The callback script validates the token before processing.

Best Practices

  • Use descriptive datacenter and location names
  • Group related IPs under the same parent server
  • Document hardware specifications in location fields
  • Maintain consistent SSH credentials across servers
  • Use SSH key authentication instead of passwords (custom setup)
  • Restrict SSH access to specific IP addresses
  • Regularly rotate encryption keys
  • Use non-standard SSH ports (not 22)
  • Distribute servers across multiple network nodes
  • Monitor load averages and add capacity as needed
  • Use local servers when possible for faster operations
  • Keep SSH connections alive with timeout settings
  • Test SSH connectivity before adding network servers
  • Verify callback URLs are accessible from remote servers
  • Maintain synchronized time (NTP) on all servers
  • Monitor disk space on network nodes

Troubleshooting

SSH Connection Failures

  1. Verify SSH credentials are correct
  2. Check firewall allows connections on SSH port
  3. Test connectivity: telnet <ip> <port>
  4. Verify SSH service is running on remote server
  5. Check PHPSecLib has correct permissions

Callback Issues

  1. Verify callback URL is accessible from remote server
  2. Check token matches in database
  3. Review web server access logs
  4. Test callback manually: wget -qO- "<callback_url>"
  5. Ensure includes/callback.php exists and is executable

Port Allocation Problems

  1. Check if IP addresses are properly configured
  2. Verify port range isn’t exhausted
  3. Review servers table for orphaned entries
  4. Manually specify ports if auto-allocation fails
  5. Add additional IP addresses to network pool

Load Data Not Updating

  1. Verify GPXManager is running on remote server
  2. Check manager cron job or service status
  3. Test callback URL from remote server
  4. Review loadavg table for stale data
  5. Check remote server system time is synchronized
Lost encryption keys will prevent decryption of SSH credentials. Store the encryption key from configuration.php securely and back it up.

Build docs developers (and LLMs) love