giantsd/dpnet/EnumResponse.py

95 lines
3.5 KiB
Python
Raw Normal View History

2019-01-22 01:30:42 +01:00
from .packet import Packet
class EnumResponse:
LEAD = 0x00
COMMAND = 0x03
def __init__(self, packet=None):
self.Lead = EnumResponse.LEAD
self.Command = EnumResponse.COMMAND
self.Payload = b''
self.ReplyOffset = b''
self.ReplySize = b''
self.ApplicationDescSize = b''
self.ApplicationDescFlags = b''
self.MaxPlayers = b''
self.CurrentPlayers = b''
self.SessionNameOffset = b''
self.SessionNameSize = b''
self.PasswordOffset = b''
self.PasswordSize = b''
self.ReservedDataOffset = b''
self.ReservedDataSize = b''
self.ApplicationReservedDataOffset = b''
self.ApplicationReservedDataSize = b''
self.ApplicationInstanceGUID = b''
self.ApplicationGUID = b''
self.SessionName = b''
self.Password = b''
self.ReservedData = b''
self.ApplicationReservedData = b''
self.ApplicationData = b''
if packet:
self.parse(packet)
def parse(self, packet):
self.Lead = EnumResponse.LEAD
self.Command = EnumResponse.COMMAND
self.Payload = packet.getShort()
def to_packet(self):
varpos = 88
self.SessionNameSize = len(self.SessionName.encode("utf-16"))
self.SessionNameOffset = varpos if self.SessionName else 0
varpos += self.SessionNameSize if self.SessionName else 0
self.PasswordSize = len(self.Password)
self.PasswordOffset = varpos if self.Password else 0
varpos += self.PasswordSize if self.Password else 0
self.ReservedDataSize = len(self.ReservedData)
self.ReservedDataOffset = varpos if self.ReservedData else 0
varpos += self.ReservedDataSize if self.ReservedData else 0
self.ApplicationReservedDataSize = len(self.ApplicationReservedData)
self.ApplicationReservedDataOffset = varpos if self.ApplicationReservedData else 0
varpos += self.ApplicationReservedDataSize if self.ApplicationReservedData else 0
self.ReplySize = len(self.ApplicationData)
self.ReplyOffset = varpos if self.ApplicationData else 0
varpos += self.ReplySize if self.ApplicationData else 0
packet = Packet()
packet.putByte(EnumResponse.LEAD)
packet.putByte(EnumResponse.COMMAND)
packet.putShort(self.Payload)
packet.putLong(self.ReplyOffset)
packet.putLong(self.ReplySize)
packet.putLong(self.ApplicationDescSize)
packet.putLong(self.ApplicationDescFlags)
packet.putLong(self.MaxPlayers)
packet.putLong(self.CurrentPlayers)
packet.putLong(self.SessionNameOffset)
packet.putLong(self.SessionNameSize)
packet.putLong(self.PasswordOffset)
packet.putLong(self.PasswordSize)
packet.putLong(self.ReservedDataOffset)
packet.putLong(self.ReservedDataSize)
packet.putLong(self.ApplicationReservedDataOffset)
packet.putLong(self.ApplicationReservedDataSize)
packet.putBytes(self.ApplicationInstanceGUID)
packet.putBytes(self.ApplicationGUID)
if self.SessionName:
packet.putBytes((self.SessionName+'\x00').encode("utf-16-le"))
if self.Password:
packet.putBytes(self.Password)
if self.ReservedData:
packet.putBytes(self.ReservedData)
if self.ApplicationReservedData:
packet.putBytes(self.ApplicationReservedData)
if self.ApplicationData:
packet.putBytes(self.ApplicationData)
return packet