Author Topic: node.js module for soldat admin connections  (Read 7773 times)

0 Members and 1 Guest are viewing this topic.

Offline ramirez

  • Retired Soldat Developer
  • Camper
  • ******
  • Posts: 394
    • Soldat Central
node.js module for soldat admin connections
« on: February 13, 2012, 10:40:43 am »
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

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: [Select]
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' }
« Last Edit: February 13, 2012, 10:44:54 am by ramirez »

Offline FliesLikeABrick

  • Administrator
  • Flamebow Warrior
  • *****
  • Posts: 6144
    • Ultimate 13 Soldat
Re: node.js module for soldat admin connections
« Reply #1 on: February 13, 2012, 10:46:12 am »
Very neat, thanks for sharing

Offline jrgp

  • Administrator
  • Flamebow Warrior
  • *****
  • Posts: 5037
Re: node.js module for soldat admin connections
« Reply #2 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
There are other worlds than these

Offline ramirez

  • Retired Soldat Developer
  • Camper
  • ******
  • Posts: 394
    • Soldat Central
Re: node.js module for soldat admin connections
« Reply #3 on: February 13, 2012, 12:01:45 pm »
heh now we can easily make a comet soldat admin client using node.js/socket.io on the server side

neat
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.

Offline Mr

  • Inactive Soldat Developer
  • Soldier
  • ******
  • Posts: 166
Re: node.js module for soldat admin connections
« Reply #4 on: February 15, 2012, 05:08:21 pm »
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!

Offline ramirez

  • Retired Soldat Developer
  • Camper
  • ******
  • Posts: 394
    • Soldat Central
Re: node.js module for soldat admin connections
« Reply #5 on: February 17, 2012, 06:20:42 pm »
Fixed, thanks! I guess that was changed in 1.6.2 server or something, I recall it was with two periods before. :P

Offline ManSoft|Warlord

  • Major
  • *
  • Posts: 70
  • Soldat.IDE Creator
Re: node.js module for soldat admin connections
« Reply #6 on: June 28, 2013, 06:56:22 pm »
Great! Thank you very much. I'm using it now.
Hint: There is no Event .on('kill', function(killer, victim, weapon){}); ;)