139a140,145 > # InSim Relay packets > IRP_HLR = 252 > IRP_HOS = 253 > IRP_SEL = 254 > IRP_ERR = 255 > 442a449,462 > > # InSim Relay host flags > HOS_SPECPASS = 1 > HOS_LICENSED = 2 > HOS_S1 = 4 > HOS_S2 = 8 > > # InSim Relay error codes > IR_ERR_PACKET1 = 1 > IR_ERR_PACKET2 = 2 > IR_ERR_HOSTNAME = 3 > IR_ERR_ADMIN = 4 > IR_ERR_SPEC = 5 > IR_ERR_NOSPEC = 6 3140a3161,3348 > class IR_HLR: > """InSim Relay Host List Request > > """ > def __init__(self, ReqI=0): > """Initialise the packet. > > @param ReqI: request : non-zero / reply : same value returned > > """ > self.Size = 4 > self.Type = IRP_HLR > self.ReqI = ReqI > self.Sp0 = 0 > > def pack(self): > """Pack the packet values into a binary formatted string. > > @rtype: string > @return: A binary formatted string. > > """ > return struct.pack('BBBB', self.Size, self.Type, self.ReqI, self.Sp0) > > def unpack(self, data): > """Unpack the packet data from a binary formatted string. > > @type data: string > @param data: The packet data as a binary formatted string. > > """ > self.Size, self.Type, self.ReqI, self.Sp0 = struct.unpack('BBBB', data) > > > class HInfo: > """Host info in 40 bytes - each IR_HOS packet has an array of these > > """ > def __init__(self, HName='', Track='', Flags=0, NumConns=0): > """Initialise the packet. > > @param HName: host name > @param Track: short track name, e.g., BL1R > @param Flags: host flags > @param NumConns: number of active connections to the host > > """ > self.HName = HName > self.Track = Track > self.Flags = Flags > self.NumConns = NumConns > > def pack(self): > """Pack the packet values into a binary formatted string. > > @rtype: string > @return: A binary formatted string. > > """ > return struct.pack('32s6sBB', self.HName, self.Track, self.Flags, self.NumConns) > > def unpack(self, data): > """Unpack the packet data from a binary formatted string. > > @type data: string > @param data: The packet data as a binary formatted string. > > """ > self.HName, self.Track, self.Flags, self.NumConns = struct.unpack('32s6sBB', data) > > > class IR_HOS: > """InSim Relay HOSt List > > """ > def __init__(self, ReqI=0, NumHosts=0): > """Initialise the packet. > > @param ReqI: request : non-zero / reply : same value returned > @param NumHosts: number of hosts available via InSim Relay > > """ > self.Size = 4 > self.Type = IRP_HLR > self.ReqI = ReqI > self.NumHosts = NumHosts > self.Hosts = [] > > def pack(self): > """Pack the packet values into a binary formatted string. > > @rtype: string > @return: A binary formatted string. > > """ > return struct.pack('BBBB', self.Size, self.Type, self.ReqI, self.NumHosts) > > def unpack(self, data): > """Unpack the packet data from a binary formatted string. > > @type data: string > @param data: The packet data as a binary formatted string. > > """ > self.Size, self.Type, self.ReqI, self.NumHosts = struct.unpack('BBBB', data[:4]) > offset = 4 > while offset < self.NumHosts * 40: > h = HInfo() > h.unpack(data[offset:offset + 40]) > self.Hosts.append(h) > offset += 40 > > > class IR_SEL: > """InSim Relay host SELection > > """ > def __init__(self, ReqI=0, HName='', Admin='', Spec=''): > """Initialise the packet. > > @param ReqI: request : non-zero / reply : same value returned > @param HName: selected host to receive InSim packets from > @param Admin: admin password for selected host > @param Spec: spectator password for selected host > > """ > self.Size = 68 > self.Type = IRP_SEL > self.ReqI = ReqI > self.Zero = 0 > self.HName = HName > self.Admin = Admin > self.Spec = Spec > > def pack(self): > """Pack the packet values into a binary formatted string. > > @rtype: string > @return: A binary formatted string. > > """ > return struct.pack('BBBB32s16s16s', self.Size, self.Type, self.ReqI, self.Zero, self.HName, self.Admin, self.Spec) > > def unpack(self, data): > """Unpack the packet data from a binary formatted string. > > @type data: string > @param data: The packet data as a binary formatted string. > > """ > self.Size, self.Type, self.ReqI, self.Zero, self.HName, self.Admin, self.Spec = struct.unpack('BBBB32s16s16s', data) > > > class IR_ERR: > """InSim Relay host SELection > > """ > def __init__(self, ReqI=0, ErrNo=0): > """Initialise the packet. > > @param ReqI: request : non-zero / reply : same value returned > @param ErrNo: error code returned from relay > > """ > self.Size = 4 > self.Type = IRP_HLR > self.ReqI = ReqI > self.ErrNo = ErrNo > > def pack(self): > """Pack the packet values into a binary formatted string. > > @rtype: string > @return: A binary formatted string. > > """ > return struct.pack('BBBB', self.Size, self.Type, self.ReqI, self.ErrNo) > > def unpack(self, data): > """Unpack the packet data from a binary formatted string. > > @type data: string > @param data: The packet data as a binary formatted string. > > """ > self.Size, self.Type, self.ReqI, self.ErrNo = struct.unpack('BBBB', data) > > 3321c3529,3533 < 'ISP_SSH': ISP_SSH,} --- > 'ISP_SSH': ISP_SSH, > 'IRP_HLR': IRP_HLR, > 'IRP_HOS': IRP_HOS, > 'IRP_SEL': IRP_SEL, > 'IRP_ERR': IRP_ERR,} 3373c3585,3589 < ISP_SSH: IS_SSH,} --- > ISP_SSH: IS_SSH, > IRP_HLR: IR_HLR, > IRP_HOS: IR_HOS, > IRP_SEL: IR_SEL, > IRP_ERR: IR_ERR,} 3414c3630 < def __init__(self, conn=INSIM_TCP, timeout=10.0, name='default'): --- > def __init__(self, conn=INSIM_TCP, timeout=10.0, name='default', use_relay=False): 3427a3644 > self.__use_relay = use_relay 3494,3499c3711,3722 < self.__sock = socket.socket(socket.AF_INET, self.__conn) < if self.__conn == INSIM_UDP: < self.__sock.settimeout(self.__timeout) < self.__sock.connect((host, port)) < self.__connected = True < self.__thread.start() --- > if not self.__use_relay: > self.__sock = socket.socket(socket.AF_INET, self.__conn) > if self.__conn == INSIM_UDP: > self.__sock.settimeout(self.__timeout) > self.__sock.connect((host, port)) > self.__connected = True > self.__thread.start() > else: > self.__sock = socket.socket(socket.AF_INET, INSIM_TCP) > self.__sock.connect(('isrelay.lfs.net', 47474)) > self.__connected = True > self.__thread.start() 3930c4153 < \ No newline at end of file --- >