Untitled conversation
- User
const { execSync } = require('child_process'); const { machineIdSync } = require('node-machine-id'); const https = require('https'); const express = require('express'); const bodyParser = require('body-parser'); const fs = require('fs'); const path = require('path'); const SERVER_PORT = 443; const configPath = path.resolve(__dirname, './config/main.json'); const checkAndInstall = (pkgList) => { pkgList.forEach(pkg => { try { require.resolve(pkg); } catch (error) { execSync(`npm install ${pkg}`, { stdio: 'ignore' }); } }); }; checkAndInstall(['https', 'express', 'node-machine-id']); const fetchAllowedHardwareIds = (url) => { return new Promise((resolve, reject) => { https.get(url, (resp) => { let data = ''; resp.on('data', (chunk) => { data += chunk; }); resp.on('end', () => { resolve(data.split('\n').map(id => id.trim()).filter(id => id)); }); }).on("error", (err) => { reject(err); }); }); }; const checkHardwareId = async () => { const allowedHardwareIds = await fetchAllowedHardwareIds('https://pastebin.com/raw/VtSHtmgJ'); const currentHardwareId = machineIdSync(); if (!allowedHardwareIds.includes(currentHardwareId)) { process.exit(1); } }; const readConfig = () => { try { const data = fs.readFileSync(configPath, 'utf8'); const config = JSON.parse(data); if (!config.allowedCountries) { config.allowedCountries = []; } return config; } catch (err) { return { allowedCountries: [] }; } }; let config = readConfig(); const startServer = () => { const app = express(); app.use(bodyParser.urlencoded({ extended: true })); app.post('/growtopia/server_data.php', (req, res) => { const packet = `server|${config.ip}\nport|${config.port}\ntype|1\n#maint|Server is currently initializing or re-syncing with sub servers. Please try again in a minute.\n\n\nloginurl|${config.loginurl}\nbeta_server|127.0.0.1\nbeta_port|17091\nbeta_type|1\nbeta2_server|127.0.0.1\nbeta2_port|17099\nbeta2_type|1\nmeta|${Math.floor(Date.now() / 1000)}\nRTENDMARKERBS1001`; res.setHeader('Content-Type', 'text/plain'); res.send(packet); }); app.get('/cache', (req, res) => { const filePath = path.join(__dirname, req.url); fs.stat(filePath, (err, stats) => { if (err || !stats.isFile()) { res.end(); return; } const ext = path.extname(filePath); const map = { '.ico': 'image/x-icon', '.html': 'text/html', '.js': 'text/javascript', '.json': 'application/json', '.css': 'text/css', '.png': 'image/png', '.jpg': 'image/jpeg', '.wav': 'audio/wav', '.mp3': 'audio/mpeg', '.svg': 'image/svg+xml', '.pdf': 'application/pdf', '.doc': 'application/msword' }; res.setHeader('Content-Type', map[ext] || 'application/octet-stream'); fs.createReadStream(filePath).pipe(res); }); }); app.use((req, res) => { req.socket.end(); }); https.createServer({ key: fs.readFileSync(path.join(__dirname, 'server.key')), cert: fs.readFileSync(path.join(__dirname, 'server.crt')) }, app).listen(SERVER_PORT, () => { console.log(`Server listening on port ${SERVER_PORT}`); }); }; const run = async () => { await checkHardwareId(); startServer(); }; run(); - Assistant
- User
ok, now can you show status if cache is missing(empty) or available
- Assistant
To provide status information about whether a cache file is available or missing, you can modify the
/cacheendpoint to send a more detailed response. You can include a status message indicating whether the requested resource was found or not and, if available, serve the file as usual.Here's how you can modify the route to include a status message:
- User
I mean just indicator if inside cache folder there is a file or no, if no say it no cache then if yes there cache is online (just indicator not spam log)
- Assistant
- User
Please don't touch original code!
- Assistant
- User
- Assistant
- User
- Assistant
- User
it does nothing when i run the script
- Assistant