Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require'oosocks'
- ---------- HALPER
- function byteArrayFromInteger(integer)
- local str = string.char(integer >> 24)..string.char(integer >> 16)..string.char(integer >> 8)..string.char(integer)
- print("result:",string.byte(str,1,4))
- return str
- end
- function integerFromByteArray(byteArray)
- return byteArray[0] << 24 |
- (byteArray[1] & 0xff) << 16 |
- (byteArray[2] & 0xff) << 8 |
- (byteArray[3] & 0xff)
- end
- module("masterquery",package.seeall)
- A2S_INFO_HEADER = "ÿÿÿÿTSource Engine Query\0"
- QuerySocket = QuerySocket or OOSock(IPPROTO_UDP)
- function QueryServer(ip,port,callback)
- QuerySocket:Send(A2S_INFO_HEADER,ip,tonumber(port))
- QuerySocket:ReceiveDatagram()
- end
- QuerySocket:SetBinaryMode(true)
- Calltypes = {
- [SCKCALL_CONNECT] = "Connect", -- SCKCALL_CONNECT
- [SCKCALL_REC_SIZE] = "Rec Size", -- SCKCALL_REC_SIZE
- [SCKCALL_REC_LINE] = "Rec Line", -- SCKCALL_REC_LINE
- [SCKCALL_SEND] = "Send", -- SCKCALL_SEND
- [SCKCALL_BIND] = "Bind", -- SCKCALL_BIND
- [SCKCALL_ACCEPT] = "Accept", -- SCKCALL_ACCEPT
- [SCKCALL_LISTEN] = "Listen", -- SCKCALL_LISTEN
- [SCKCALL_REC_DATAGRAM] = "Datagram", -- SCKCALL_REC_DATAGRAM
- }
- Errtypes = {
- [SCKERR_OK] = "Ok", -- SCKERR_OK
- [SCKERR_BAD] = "Bad", -- SCKERR_BAD
- [SCKERR_CONNECTION_RESET] = "Con Rest", -- SCKERR_CONNECTION_RESET
- [SCKERR_NOT_CONNECTED] = "Not Con", -- SCKERR_NOT_CONNECTED
- [SCKERR_TIMED_OUT] = "Timed Out", -- SCKERR_TIMED_OUT
- }
- function QueryCallback(sock,call,id,err,binread,peer,peerport)
- MsgN("[Server Query] Call: "..Calltypes[call].." - Error: "..Errtypes[err])
- if call == SCKCALL_REC_DATAGRAM and err == SCKERR_OK then
- local info={peer=peer,peerport=peerport}
- -- Skip Header: Should be 0xFF 0xFF 0xFF 0xFF
- binread:ReadByte()binread:ReadByte()binread:ReadByte()binread:ReadByte()
- local byte=binread:ReadByte()
- info.type=(byte!=0 and string.char( byte ) or '#' )
- info.servername=binread:ReadString()
- info.map=binread:ReadString()
- info.gamename=binread:ReadString()
- info.gamedesc=binread:ReadString()
- local b1=binread:ReadByte()
- local b2=binread:ReadByte()
- b2=b2*256
- info.appid=b1+b2
- info.players=binread:ReadByte()
- info.maxplayers=binread:ReadByte()
- info.bots=binread:ReadByte()
- local byte=binread:ReadByte()
- info.servertype=(byte!=0 and string.char( byte ) or '#' )
- local byte=binread:ReadByte()
- info.ostype=(byte!=0 and string.char( byte ) or '#' )
- info.passworded=binread:ReadByte()
- info.secure=binread:ReadByte()
- info.gameversion=binread:ReadString()
- info.EDF=binread:ReadByte()
- for name,data in pairs(info) do
- MsgN(" > "..name..":\t"..tostring(data))
- end
- print"close"
- --sock:Close() --asdf. Nee to think of how to make the "resolver" work as in whether we use the same socket for everything/socket for every requested server query instance/etc...
- end
- end
- QuerySocket:SetCallback(QueryCallback)
- MsgN("Querying server...",QueryServer("88.191.102.162",27015))
Advertisement
Add Comment
Please, Sign In to add comment