Soldat Fans > Developers Corner
node.js module for soldat admin connections
ramirez:
This is something I wrote a while back for a node.js bot I was writing, I figured why not release it, some people might find it useful. It's a module that allows you to easily connect to Soldat servers, and then listen to various different events (player joining/leaving, chat messages, etc). The bot does things like keep track the current players/specs on the server, and whenever an event originates from a given player (let's say a chat message), the event receives the full user information as parameter, meaning that you can easily access information like the player's ip/ping/kills/caps/whatever from whatever event the player triggers.
The code can be found here:
http://soldat.fi/soldatadmin.js
Here's a list of all the events the module supports, look at the soldatadmin.js source code to figure out what parameters they get passed (or just try it out with console.log yourself):
--- Quote ---line
auth
invalid auth
version
password
timeleft
nextmap
command
request
admin added
pm
change team
leave
flag capture
flag return
score
chat
team chat
admin connect
admin disconnect
shutdown
join
refresh
--- End quote ---
You can access the current players on the server anywhere via the .players property of the server. The module also has an auto-reconnect feature, if the server for some reason crashes (or is closed otherwise), the module will attempt to auto-reconnect to the server, by default every 5 seconds (this can be tweaked by changing the reconnectWaitTime option, which is passed to connect function as 4th argument).
Here's a simple example script of how to use the module (simply run this from same folder as soldatadmin.js):
http://pastie.org/private/tebkpilzta0b4wt86wncfa
The output could be something similar to this:
--- Code: ---SERVER RUNNING VERSION: 2.7.2
SCRIPTING: false
MIN RESPAWN TIME: 2
MAX RESPAWN TIME: 5
CAPTURE LIMIT: 10
MAX GRENADES: 3
PLAYER JOIN:
{ id: 2,
ip: 'xxx.xxx.xxx.xxx',
hwid: 'XXXXXXXXXXX',
name: 'm!nus',
ping: 0,
active: true }
PLAYER JOIN:
{ id: 4,
ip: 'xxx.xxx.xxx.xxx',
hwid: 'RAINBWDASH1',
name: 'Rainbow Dash',
ping: 4096,
active: true }
MSG SERVER -> m!nus: THIS SERVER IS MONITORED BY SCTFL
MSG SERVER -> m!nus: AND USES VALID SETTINGS FOR A SCTFL MATCH
MSG SERVER -> Rainbow Dash: THIS SERVER IS MONITORED BY SCTFL
MSG SERVER -> Rainbow Dash: AND USES VALID SETTINGS FOR A SCTFL MATCH
CURRENT STATE:
{ players:
[ { id: 3,
name: 'James',
hwid: 'XXXXXXXXXXXX',
ping: 33,
ip: 'xxx.xxx.xxx.xxx',
team: [Object],
kills: 2,
caps: 0,
deaths: 3,
x: -719.1261596679688,
y: 473.6373596191406,
isSpec: false },
{ id: 2,
name: 'm!nus',
hwid: 'XXXXXXXXXXXX',
ping: 268435456,
ip: 'xxx.xxx.xxx.xxx',
team: [Object],
kills: 0,
caps: 0,
deaths: 0,
x: -106.08069610595703,
y: 5.7643256187438965,
isSpec: false },
{ id: 1,
name: 'Boogie Man',
hwid: '',
ping: 1048576,
ip: '0.0.0.0',
team: [Object],
kills: 0,
caps: 0,
deaths: 0,
x: -720.949462890625,
y: 408.25604248046875,
isSpec: false },
{ id: 4,
name: 'Rainbow Dash',
hwid: 'RAINBWDASH1',
ping: 4096,
ip: 'xxx.xxx.xxx.xxx',
team: [Object],
kills: 0,
caps: 0,
deaths: 0,
x: -94.4830551147461,
y: -255.3679962158203,
isSpec: false } ],
specs: [],
teams:
[ { id: 1, name: 'Alpha', score: 0, players: [Object] },
{ id: 2, name: 'Bravo', score: 0, players: [] },
{ id: 3, name: 'Charlie', score: 0, players: [] },
{ id: 4, name: 'Delta', score: 0, players: [] } ],
flags:
{ red: { x: -1630.8197021484375, y: 806.057373046875 },
blue: { x: 1605.6246337890625, y: 1567.36181640625 } },
map: 'Lothic',
timeLimit: 36000,
currentTime: 15313,
limit: 10,
mode: 'CTF',
maxPlayers: 12,
maxSpecs: 12,
hasPassword: 1,
nextMap: 'Lothic' }
--- End code ---
FliesLikeABrick:
Very neat, thanks for sharing
jrgp:
heh now we can easily make a comet soldat admin client using node.js/socket.io on the server side
neat
ramirez:
--- Quote from: jrgp on February 13, 2012, 11:52:34 am ---heh now we can easily make a comet soldat admin client using node.js/socket.io on the server side
neat
--- End quote ---
That was one of the primary purposes of the bot I made this for actually, I might release its code some day after finishing some things and cleaning the code base.
Mr:
There is a horrible error on line 275 which will result in the shutdown event not being triggered at all. We're doomed.
Thanks for that amazing piece of code!
Navigation
[0] Message Index
[#] Next page
Go to full version