Skip to content

Instantly share code, notes, and snippets.

@youhide
Last active December 6, 2019 13:42
Show Gist options
  • Save youhide/cdf4986ccb8d89038fe17e20e6b87fd9 to your computer and use it in GitHub Desktop.
Save youhide/cdf4986ccb8d89038fe17e20e6b87fd9 to your computer and use it in GitHub Desktop.
Ultima Online Sphere Server Info Packet
'use strict'
const net = require('net')
module.exports = {
totalPlayers: function (loginserv, port = 2593) {
const client = new net.Socket()
client.on('close', () => {
console.log('Socket closed')
})
const connOpt = {
host: loginserv,
port: port
}
client.setTimeout(500)
client.connect(connOpt, () => {
console.log(`Socket connected: ${loginserv}:${port}`)
})
const promise = new Promise((resolve, reject) => {
try {
client.write(Buffer.from('22', 'hex'))
client.on('data', (data) => {
const res = data.toString().split('=')[3].split(',')[0]
client.destroy()
resolve(res)
})
client.on('timeout', () => {
console.log('Socket timeout')
client.destroy()
resolve('timeout')
})
client.on('error', (err) => {
client.destroy()
console.log(err)
resolve('err')
})
} catch (e) {
client.destroy()
reject(e)
}
})
return promise
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment