180 lines
6.4 KiB
Python
180 lines
6.4 KiB
Python
from .packet import Packet
|
|
from .DFrame import DFrame
|
|
from giants import APPLICATION_GUID
|
|
|
|
|
|
class DN_NAMETABLE_ENTRY_INFO:
|
|
def __init__(self):
|
|
self.dpnid = 0
|
|
self.dpnidOwner = 0
|
|
self.dwFlags = 0
|
|
self.dwVersion = 2
|
|
self.dwVersionNotUsed = 0
|
|
self.dwDNETVersion = 7
|
|
self.dwNameOffset = 0
|
|
self.dwNameSize = 0
|
|
self.dwDataOffset = 0
|
|
self.dwDataSize = 0
|
|
self.dwURLOffset = 0
|
|
self.dwURLSize = 0
|
|
self.URL = b''
|
|
self.Data = b''
|
|
self.Name = b''
|
|
|
|
def to_packet(self):
|
|
p = Packet()
|
|
p.putULong(self.dpnid)
|
|
p.putULong(self.dpnidOwner)
|
|
p.putULong(self.dwFlags)
|
|
p.putULong(self.dwVersion)
|
|
p.putULong(self.dwVersionNotUsed)
|
|
p.putULong(self.dwDNETVersion)
|
|
p.putULong(self.dwNameOffset)
|
|
p.putULong(self.dwNameSize)
|
|
p.putULong(self.dwDataOffset)
|
|
p.putULong(self.dwDataSize)
|
|
p.putULong(self.dwURLOffset)
|
|
p.putULong(self.dwURLSize)
|
|
return p
|
|
|
|
class DN_MSG_INTERNAl_SEND_CONNECT_INFO(DFrame):
|
|
dwPacketType = 0xc2
|
|
|
|
def __init__(self, netserver, newplayer, packet=None):
|
|
super().__init__(packet)
|
|
self.Command = DFrame.PACKET_COMMAND_DATA | DFrame.PACKET_COMMAND_RELIABLE | DFrame.PACKET_COMMAND_SEQUENTIAL | DFrame.PACKET_COMMAND_POLL | DFrame.PACKET_COMMAND_NEW_MSG | DFrame.PACKET_COMMAND_END_MSG | DFrame.PACKET_COMMAND_USER_1
|
|
self.Control = 0x00
|
|
self.netserver = netserver
|
|
self.newplayer = newplayer
|
|
self.dwPacketType = DN_MSG_INTERNAl_SEND_CONNECT_INFO.dwPacketType
|
|
self.dwReplyOffset = 0
|
|
self.dwReplySize = 0
|
|
self.dwSize = 0x50
|
|
self.dwFlags = 0x41
|
|
self.dwMaxPlayers = netserver.server.maxplayers
|
|
self.dwCurrentPlayers = len(netserver.server.players) + len(netserver.server.tempplayers)
|
|
self.dwSessionNameOffset = 0
|
|
self.dwSessionNameSize = len((netserver.server.name+"\x00").encode("utf-16-le"))
|
|
self.dwPasswordOffset = 0
|
|
self.dwPasswordSize = 0
|
|
self.dwReservedDataOffset = 0
|
|
self.dwReservedDataSize = 0
|
|
self.dwApplicationReservedDataOffset = 0
|
|
self.dwApplicationReservedDataSize = 0
|
|
self.guidInstance = netserver.guid
|
|
self.guidApplication = APPLICATION_GUID
|
|
self.dpnid = newplayer.id
|
|
self.dwVersion = 3
|
|
self.dwVersionNotUsed = 0
|
|
self.dwEntryCount = 0
|
|
self.dwMembershipCount = 0
|
|
self.DN_NameTable_Entry_Info = []
|
|
self.DN_NameTable_Membership_Info = []
|
|
self.ApplicationReservedData = b''
|
|
self.ReservedData = b''
|
|
self.Password = b''
|
|
self.SessionName = (netserver.server.name+"\x00").encode("utf-16-le")
|
|
self.Reply = b''
|
|
|
|
if packet:
|
|
self.parse(packet)
|
|
|
|
def parse(self, packet):
|
|
pass
|
|
|
|
def to_packet(self):
|
|
var = 108
|
|
|
|
s = self.netserver.server.players[0]
|
|
entry_server = DN_NAMETABLE_ENTRY_INFO()
|
|
self.DN_NameTable_Entry_Info.append(entry_server)
|
|
|
|
p = self.newplayer
|
|
entry_player = DN_NAMETABLE_ENTRY_INFO()
|
|
self.DN_NameTable_Entry_Info.append(entry_player)
|
|
|
|
self.dwEntryCount = len(self.DN_NameTable_Entry_Info)
|
|
self.dwMembershipCount = len(self.DN_NameTable_Membership_Info)
|
|
|
|
entry_server.dpnid = s.id
|
|
entry_server.dwFlags = 0x0402
|
|
entry_server.dwVersion = 2
|
|
|
|
entry_player.dpnid = p.id
|
|
entry_player.dwFlags = 0x0200
|
|
entry_player.Name = p.name.encode("utf-16-le")
|
|
entry_player.dwVersion = 3
|
|
|
|
var = var + self.dwEntryCount * 48 # 48=size of DN_NAMETABLE_ENTRY_INFO
|
|
entry_player.dwNameOffset = var
|
|
entry_player.dwNameSize = len(entry_player.Name)
|
|
|
|
var += entry_player.dwNameSize
|
|
|
|
if self.ApplicationReservedData:
|
|
self.dwApplicationReservedDataSize = len(self.ApplicationReservedData)
|
|
self.dwApplicationReservedDataOffset = var
|
|
var += self.dwApplicationReservedDataSize
|
|
if self.ReservedData:
|
|
self.dwReservedDataSize = len(self.ReservedData)
|
|
self.dwReservedDataOffset = var
|
|
var += self.dwReservedDataSize
|
|
if self.Password:
|
|
self.dwPasswordSize = len(self.Password)
|
|
self.dwPasswordOffset = var
|
|
var += self.dwPasswordSize
|
|
if self.SessionName:
|
|
self.dwSessionNameSize = len(self.SessionName)
|
|
self.dwSessionNameOffset = var
|
|
var += self.dwSessionNameSize
|
|
if self.Reply:
|
|
self.dwReplySize = len(self.Reply)
|
|
self.dwReplyOffset = var
|
|
var += self.dwReplySize
|
|
|
|
packet = Packet()
|
|
packet.putULong(self.dwPacketType)
|
|
packet.putULong(self.dwReplyOffset)
|
|
packet.putULong(self.dwReplySize)
|
|
packet.putULong(self.dwSize)
|
|
packet.putULong(self.dwFlags)
|
|
packet.putLong(self.dwMaxPlayers)
|
|
packet.putULong(self.dwCurrentPlayers)
|
|
packet.putULong(self.dwSessionNameOffset)
|
|
packet.putULong(self.dwSessionNameSize)
|
|
packet.putULong(self.dwPasswordOffset)
|
|
packet.putULong(self.dwPasswordSize)
|
|
packet.putULong(self.dwReservedDataOffset)
|
|
packet.putULong(self.dwReservedDataSize)
|
|
packet.putULong(self.dwApplicationReservedDataOffset)
|
|
packet.putULong(self.dwApplicationReservedDataSize)
|
|
packet.putBytes(self.guidInstance)
|
|
packet.putBytes(self.guidApplication)
|
|
packet.putULong(self.dpnid)
|
|
packet.putULong(self.dwVersion)
|
|
packet.putULong(self.dwVersionNotUsed)
|
|
packet.putULong(self.dwEntryCount)
|
|
packet.putULong(self.dwMembershipCount)
|
|
|
|
for entry in self.DN_NameTable_Entry_Info:
|
|
packet.putBytes(entry.to_packet().getvalue())
|
|
for entry in self.DN_NameTable_Membership_Info:
|
|
packet.putBytes(entry.to_packet().getvalue())
|
|
|
|
if entry_player.URL:
|
|
packet.putBytes(entry_player.URL)
|
|
if entry_player.Data:
|
|
packet.putBytes(entry_player.Data)
|
|
if entry_player.Name:
|
|
packet.putBytes(entry_player.Name)
|
|
|
|
packet.putBytes(self.ApplicationReservedData)
|
|
packet.putBytes(self.ReservedData)
|
|
packet.putBytes(self.Password)
|
|
packet.putBytes(self.SessionName)
|
|
packet.putBytes(self.Reply)
|
|
|
|
self.Payload = packet.getvalue()
|
|
|
|
return super().to_packet()
|