freeman
Version:
Source/GoldSrc server query library
1 lines • 4.13 kB
JavaScript
(function(){"use strict";var e,r,n,t,a,d,i,o,u,c;r=require("dgram"),o=require("ref"),c=function(e,r){var n,t;for(t="";;){if(n=e.readUInt8(r),r+=1,0===n)break;t+=String.fromCharCode(n)}return t},a=function(e){var r,n,t,a;return a={},t=4,a.header=String.fromCharCode(e.readUInt8(t)),t+=1,"I"===a.header?(a.protocol=e.readUInt8(t),t+=1,a.name=c(e,t),t+=a.name.length+1,a.map=c(e,t),t+=a.map.length+1,a.folder=c(e,t),t+=a.folder.length+1,a.game=c(e,t),t+=a.game.length+1,a.app_id=e.readInt16LE(t),t+=2,a.players=e.readUInt8(t),t+=1,a.max_players=e.readUInt8(t),t+=1,a.bots=e.readUInt8(t),t+=1,a.server_type=String.fromCharCode(e.readUInt8(t)),a.server_type=function(){switch(String.fromCharCode(e.readUInt8(t))){case"d":return"dedicated";case"l":return"listen";case"p":return"hltv"}}(),t+=1,a.environment=function(){switch(String.fromCharCode(e.readUInt8(t))){case"l":return"linux";case"w":return"windows";case"m":case"o":return"mac"}}(),t+=1,a.visibility=0===e.readUInt8(t)?"public":"private",t+=1,a.vac=function(){switch(e.readUInt8(t)){case 0:return"unsecured";case 1:return"secured"}}(),t+=1,-1!==[2400,2401,2402,2412].indexOf(a.app_id)&&(a.mode=function(){switch(e.readUInt8(t)){case 0:return"Hunt";case 1:return"Elimination";case 2:return"Duel";case 3:return"Deathmatch";case 4:return"VIP Team";case 5:return"Team Elimination"}}(),t+=1,a.witnesses=e.readUInt8(t),t+=1,a.duration=e.readUInt8(t),t+=1),a.version=c(e,t),t+=a.version.length+1,r=e.readUInt8(t,!0),null!=r&&(a.edf=r,t+=1,128&a.edf&&(a.port=e.readInt16LE(t),t+=2),16&a.edf&&(a.steam_id=e.readUInt64LE(t),t+=8),64&a.edf&&(a.source_tv={},a.source_tv.port=e.readInt16LE(t),t+=2,a.source_tv.name=c(e,t),t+=a.source_tv.name.length+1),32&a.edf&&(n=c(e,t),a.keywords=n.split(","),t+=n.length+1),1&a.edf&&(a.app_id64=e.readUInt64LE(t),t+=8))):"m"===a.header&&(a.address=c(e,t),t+=a.address.length+1,a.name=c(e,t),t+=a.name.length+1,a.map=c(e,t),t+=a.map.length+1,a.folder=c(e,t),t+=a.folder.length+1,a.game=c(e,t),t+=a.game.length+1,a.players=e.readUInt8(t),t+=1,a.server_type=function(){switch(String.fromCharCode(e.readUInt8(t))){case"d":return"dedicated";case"l":return"listen";case"p":return"hltv"}}(),t+=1,a.environment=function(){switch(String.fromCharCode(e.readUInt8(t))){case"l":return"linux";case"w":return"windows";case"m":case"o":return"mac"}}(),t+=1,a.visibility=function(){switch(e.readUInt8(t)){case 0:return"public";case 1:return"private"}}(),t+=1,a.mod=function(){switch(e.readUInt8(t)){case 0:return"hl";case 1:return"mod"}}(),t+=1,"mod"===a.mod&&(a.mod_info={},a.mod_info.link=c(e,t),t+=a.mod_info.link.length+1,a.mod_info.download_link=c(e,t),t+=a.mod_info.download_link.length+1,t+=1,a.mod_info.version=e.readInt32LE(t),t+=2,a.mod_info.size=e.readInt32LE(t),t+=2,a.mod_info.type=function(){switch(e.readUInt8(t)){case 0:return"sp";case 1:return"mp"}}(),t+=1,a.mod_info.dll=function(){switch(e.readUInt8(t)){case 0:return"hl";case 1:return"custom"}}(),t+=1),a.vac=function(){switch(e.readUInt8(t)){case 0:return"unsecured";case 1:return"secured"}}(),t+=1,a.bots=e.readUInt8(t),t+=1),a},n=function(e,r,n){return u(e,r,new Buffer("TSource Engine Query","binary"),a,n)},t=function(e){var r,n;return n={},r=4,n.header=String.fromCharCode(e.readUInt8(r)),r+=1,n.challenge=e.readInt32LE(r),n},e=function(e,r,n){return u(e,r,new Buffer("Uÿÿÿÿ","binary"),t,n)},d=function(e){var r,n,t,a;return t={},n=4,t.header=String.fromCharCode(e.readUInt8(n)),n+=1,t.num_players=e.readUInt8(n),n+=1,t.players=function(){var d,i,o;for(o=[],r=d=0,i=t.num_players-1;i>=0?i>=d:d>=i;r=i>=0?++d:--d)a={},a.index=e.readUInt8(n),n+=1,a.name=c(e,n),n+=a.name.length+1,a.score=e.readInt32LE(n),n+=4,a.duration=e.readInt32LE(n),n+=4,o.push(a);return o}(),t},i=function(e,r,n,t){var a;return a=new Buffer(5),a.writeUInt8(85,0),a.writeInt32LE(n,1),u(e,r,a,d,t)},u=function(e,n,t,a,d){var i,o;return o=r.createSocket("udp4"),o.on("error",function(e){if(null!=e)throw e}),o.on("message",function(e){return o.close(),d(a(e))}),i=Buffer.concat([new Buffer("ÿÿÿÿ","binary"),t,new Buffer("\x00","binary")]),o.send(i,0,i.length,n,e)},module.exports={info:n,challenge:e,player:i}}).call(this);