Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- ONLY for Testing...
- require'oosocks'
- module("srvq",package.seeall)
- A2S_INFO_HEADER = "ÿÿÿÿTSource Engine Query\0"
- QuerySocket = 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 size = binread:GetSize()
- MsgN("size:",size)
- local rawdata = "";
- for i=1, size do
- local byte=binread:ReadByte()
- rawdata = rawdata .. (byte!=0 and string.char( byte ) or '#' )
- end
- MsgN("RawData: '"..tostring(rawdata).."'")
- MsgN"------------------"
- binread:Rewind()
- --]]
- 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 '#' )
- -- MsgN("\t".."protocol:",protocol)
- info.servername=binread:ReadString()
- -- MsgN("\t".."servername:",servername)
- info.map=binread:ReadString()
- -- MsgN("\t".."map:",map)
- info.gamename=binread:ReadString()
- -- MsgN("\t".."gamename:",gamename)
- info.gamedesc=binread:ReadString()
- -- MsgN("\t".."gamedesc:",gamedesc)
- local b1=binread:ReadByte()
- local b2=binread:ReadByte()
- b2=b2*256
- info.appid=b1+b2
- -- MsgN("\t".."appid:",appid)
- info.players=binread:ReadByte()
- -- MsgN("\t".."players:",players)
- info.maxplayers=binread:ReadByte()
- -- MsgN("\t".."maxplayers:",maxplayers)
- info.bots=binread:ReadByte()
- -- MsgN("\t".."bots:",bots)
- local byte=binread:ReadByte()
- info.servertype=(byte!=0 and string.char( byte ) or '#' )
- -- MsgN("\t".."servertype:",servertype)
- local byte=binread:ReadByte()
- info.ostype=(byte!=0 and string.char( byte ) or '#' )
- -- MsgN("\t".."ostype:",ostype)
- info.passworded=binread:ReadByte()
- -- MsgN("\t".."passworded:",passworded)
- info.secure=binread:ReadByte()
- -- MsgN("\t".."secure:",secure)
- info.gameversion=binread:ReadString()
- -- MsgN("\t".."gameversion:",gameversion)
- info.EDF=binread:ReadByte()
- -- MsgN("\t".."EDF:",EDF)
- for name,data in pairs(info) do
- MsgN(" > "..name..":\t"..tostring(data))
- end
- 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))
Add Comment
Please, Sign In to add comment