├── .gitattributes ├── .gitignore ├── .npmignore ├── README.md ├── package.json └── sourcequery.js /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | 3 | ################# 4 | ## Eclipse 5 | ################# 6 | 7 | *.pydevproject 8 | .project 9 | .metadata 10 | bin/ 11 | tmp/ 12 | *.tmp 13 | *.bak 14 | *.swp 15 | *~.nib 16 | local.properties 17 | .classpath 18 | .settings/ 19 | .loadpath 20 | 21 | # External tool builders 22 | .externalToolBuilders/ 23 | 24 | # Locally stored "Eclipse launch configurations" 25 | *.launch 26 | 27 | # CDT-specific 28 | .cproject 29 | 30 | # PDT-specific 31 | .buildpath 32 | 33 | 34 | ################# 35 | ## Visual Studio 36 | ################# 37 | 38 | ## Ignore Visual Studio temporary files, build results, and 39 | ## files generated by popular Visual Studio add-ons. 40 | 41 | # User-specific files 42 | *.suo 43 | *.user 44 | *.sln.docstates 45 | 46 | # Build results 47 | [Dd]ebug/ 48 | [Rr]elease/ 49 | *_i.c 50 | *_p.c 51 | *.ilk 52 | *.meta 53 | *.obj 54 | *.pch 55 | *.pdb 56 | *.pgc 57 | *.pgd 58 | *.rsp 59 | *.sbr 60 | *.tlb 61 | *.tli 62 | *.tlh 63 | *.tmp 64 | *.vspscc 65 | .builds 66 | *.dotCover 67 | 68 | ## TODO: If you have NuGet Package Restore enabled, uncomment this 69 | #packages/ 70 | 71 | # Visual C++ cache files 72 | ipch/ 73 | *.aps 74 | *.ncb 75 | *.opensdf 76 | *.sdf 77 | 78 | # Visual Studio profiler 79 | *.psess 80 | *.vsp 81 | 82 | # ReSharper is a .NET coding add-in 83 | _ReSharper* 84 | 85 | # Installshield output folder 86 | [Ee]xpress 87 | 88 | # DocProject is a documentation generator add-in 89 | DocProject/buildhelp/ 90 | DocProject/Help/*.HxT 91 | DocProject/Help/*.HxC 92 | DocProject/Help/*.hhc 93 | DocProject/Help/*.hhk 94 | DocProject/Help/*.hhp 95 | DocProject/Help/Html2 96 | DocProject/Help/html 97 | 98 | # Click-Once directory 99 | publish 100 | 101 | # Others 102 | [Bb]in 103 | [Oo]bj 104 | sql 105 | TestResults 106 | *.Cache 107 | ClientBin 108 | stylecop.* 109 | ~$* 110 | *.dbmdl 111 | Generated_Code #added for RIA/Silverlight projects 112 | 113 | # Backup & report files from converting an old project file to a newer 114 | # Visual Studio version. Backup files are not needed, because we have git ;-) 115 | _UpgradeReport_Files/ 116 | Backup*/ 117 | UpgradeLog*.XML 118 | 119 | 120 | 121 | ############ 122 | ## Windows 123 | ############ 124 | 125 | # Windows image file caches 126 | Thumbs.db 127 | 128 | # Folder config file 129 | Desktop.ini 130 | 131 | 132 | ############# 133 | ## Python 134 | ############# 135 | 136 | *.py[co] 137 | 138 | # Packages 139 | *.egg 140 | *.egg-info 141 | dist 142 | build 143 | eggs 144 | parts 145 | bin 146 | var 147 | sdist 148 | develop-eggs 149 | .installed.cfg 150 | 151 | # Installer logs 152 | pip-log.txt 153 | 154 | # Unit test / coverage reports 155 | .coverage 156 | .tox 157 | 158 | #Translations 159 | *.mo 160 | 161 | #Mr Developer 162 | .mr.developer.cfg 163 | 164 | # Mac crap 165 | .DS_Store 166 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | 2 | .gitignore 3 | .gitattributes 4 | node_modules/ -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | SourceQuery 2 | =========== 3 | 4 | A Source Server Query protocol implementation for node.js 5 | 6 | Protocol specification can be found here: https://developer.valvesoftware.com/wiki/Server_queries 7 | 8 | Usage 9 | ----- 10 | 11 | Install with npm: 12 | 13 | npm install sourcequery 14 | 15 | Example usage: 16 | 17 | ```js 18 | var SourceQuery = require('sourcequery'); 19 | 20 | var sq = new SourceQuery(1000); // 1000ms timeout 21 | sq.open('87.106.131.249', 27015); 22 | 23 | sq.getInfo(function(err, info){ 24 | console.log('Server Info:', info); 25 | }); 26 | 27 | sq.getPlayers(function(err, players){ 28 | console.log('Online Players:', players); 29 | }); 30 | 31 | sq.getRules(function(err, rules){ 32 | console.log('Server Rules:', rules); 33 | }); 34 | 35 | sq.close(function(){ 36 | // socket closes when all pending queries have returned or timed out 37 | console.log('Socket closed.'); 38 | }); 39 | ``` 40 | 41 | Licence 42 | ------- 43 | > Copyright (c) 2013, Gareth Hughes 44 | > All rights reserved. 45 | > 46 | > Redistribution and use in source and binary forms, with or without 47 | > modification, are permitted provided that the following conditions are met: 48 | > 49 | > 1. Redistributions of source code must retain the above copyright notice, this 50 | > list of conditions and the following disclaimer. 51 | > 2. Redistributions in binary form must reproduce the above copyright notice, 52 | > this list of conditions and the following disclaimer in the documentation 53 | > and/or other materials provided with the distribution. 54 | > 55 | > THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 56 | > ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 57 | > WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 58 | > DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 59 | > ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 60 | > (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 61 | > LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 62 | > ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 63 | > (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 64 | > SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 65 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "sourcequery", 3 | "version": "0.0.1", 4 | "description": "A Source Server Query protocol implementation for node.js", 5 | "keywords": ["srcds","source","query"], 6 | "homepage": "https://github.com/flamescape/SourceQuery/", 7 | "bugs": {"url":"https://github.com/flamescape/SourceQuery/issues"}, 8 | "author": { 9 | "name": "Gareth Hughes", 10 | "url": "http://flamescape.com" 11 | }, 12 | "main": "sourcequery", 13 | "repository": { 14 | "type": "git", 15 | "url": "https://github.com/flamescape/SourceQuery.git" 16 | }, 17 | "dependencies": { 18 | "bufferpack": "0.0.6" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /sourcequery.js: -------------------------------------------------------------------------------- 1 | var dgram = require('dgram') 2 | , bp = require('bufferpack') 3 | ; 4 | 5 | var Answer = function() { 6 | this.compressed = false; 7 | this.parts = []; 8 | this.partsfound = 0; 9 | }; 10 | 11 | Answer.prototype.add = function(id, buffer) { 12 | var head = bp.unpack(' 1) { 202 | offset = 0; 203 | var EDF = bp.unpack(' 0) { 298 | closingSocketCb = cb; 299 | } else { 300 | sq.client.close(); 301 | cb(); 302 | } 303 | }; 304 | }; 305 | 306 | module.exports = SourceQuery; 307 | --------------------------------------------------------------------------------