def connection_made(self, transport: asyncio.Transport): self._transport = transport self.peername = self._transport.get_extra_info("peername") transport.write(self.local._connect_buffer) self.ready = True CONNECTION_MADE_COUNT.inc() ACTIVE_CONNECTION_COUNT.inc()
def new_client(self, transport: asyncio.Transport) -> Client: """Create a new client, add it to the list, and assign it a player ID. Args: transport (asyncio.Transport): Transport to send data across Raises: ClientError: The server is full Returns: Client: The newly constructed client """ try: user_id = heappop(self.cur_id) except IndexError: transport.write(b'BD#This server is full.#%') raise ClientError peername = transport.get_extra_info('peername')[0] # hash IP into previous system's IPID system to maintain old banlist if 'server_number' in self.server.config: x = peername + str(self.server.config['server_number']) hash_object = hashlib.sha256(x.encode('utf-8')) peername = hash_object.hexdigest()[:12] c = self.Client(self.server, transport, user_id, database.ipid(peername)) self.clients.add(c) temp_ipid = c.ipid for client in self.server.client_manager.clients: if client.ipid == temp_ipid: client.clientscon += 1 return c
def new_client(self, transport: asyncio.Transport) -> Client: """Create a new client, add it to the list, and assign it a player ID. Args: transport (asyncio.Transport): Transport to send data across Raises: ClientError: The server is full Returns: Client: The newly constructed client """ try: user_id = heappop(self.cur_id) except IndexError: transport.write(b'BD#This server is full.#%') raise ClientError peername = transport.get_extra_info('peername')[0] c = self.Client(self.server, transport, user_id, database.ipid(peername)) self.clients.add(c) temp_ipid = c.ipid for client in self.server.client_manager.clients: if client.ipid == temp_ipid: client.clientscon += 1 return c
def send_file_response(path: str, http_version: str, transport: asyncio.Transport) -> None: """ Function used to send encoded file HTTP response on transport. Args: path: Path of the file requested by client. http_version: HTTP version. transport: The async object representing the connection with client. """ file_type = path.split('.')[-1].upper() ok_response_line = ResponseLineHeader(http_version, HTTPStatus.OK, HTTPStatus.OK.phrase) response_headers = HTTPResponseHeaders(ok_response_line, list()) try: with open(path, 'rb' if file_type in IMAGE_FILES else 'r') as f: body = f.read() except FileNotFoundError: print(f'Invalid client GET Request - File not found: {path.split("/")[-1]}') response_headers.response_line_header = ResponseLineHeader( http_version, HTTPStatus.NOT_FOUND, HTTPStatus.NOT_FOUND.phrase) body = INVALID_RESPONSE_HTML file_type = 'HTML' if file_type not in IMAGE_FILES: response_headers.headers.append(HTTPHeader('Charset', 'utf-8')) response_headers.headers.append(HTTPHeader('Content-Type', str(CONTENT_TYPES[file_type]))) response_headers.headers.append(HTTPHeader('Content-Length', str(len(body)))) response_headers.headers.append(HTTPHeader('Connection', 'Keep-Alive')) response = _get_response(file_type, response_headers, body) transport.write(response)
def __call__(self, transport: asyncio.Transport) -> None: # send command cmd = str(self.id) + ' ' + self.command + '\n' transport.write(bytes(cmd, 'utf-8')) # store current time and set as sent self.time = time.time() self.sent = True
def connection_made(self, transport: asyncio.Transport): self.transport = transport # Add to opened connections Server.serviceConnections.add(transport) # Send buffered data if any if len(self.redirectorServer.buffer) > 0: transport.write(self.redirectorServer.buffer) # No more buffer is needed self.redirectorServer.buffer = None self.redirectorServer = None
def connection_made(self, transport: asyncio.Transport): """Receives a connection and calls the connection callback.""" if self.max_connections is None or (len(self.transports) < self.max_connections): self.transports.append(transport) else: transport.write("Maximum number of connections reached.") transport.close() if self.connection_callback: self.connection_callback(transport)
async def async_gateway_connect(transport: asyncio.Transport, protocol: ScreenLogicProtocol) -> str: connectString = b"CONNECTSERVERHOST\r\n\r\n" # as bytes, not string try: # Connect ping _LOGGER.debug("Pinging protocol adapter") transport.write(connectString) except Exception as ex: raise ScreenLogicError("Error sending connect ping") from ex await asyncio.sleep(0.25) try: _LOGGER.debug("Sending challenge") await asyncio.wait_for( (request := protocol.await_send_message(CODE.CHALLENGE_QUERY)), MESSAGE.COM_TIMEOUT, ) if not request.cancelled(): # mac address return decodeMessageString(request.result()) except asyncio.TimeoutError: raise ScreenLogicError("Host failed to respond to challenge")
def connection_made(self, transport: asyncio.Transport): self._transport = transport self.peer = self._transport.get_extra_info("peername") self.cipher_man = CipherMan(access_user=self.local.cipher_man.access_user, peer=self.peer) transport.write(self.local.connect_buffer) self.ready = True
def connection_made(self, transport: asyncio.Transport): self._transport = transport self.peername = self._transport.get_extra_info("peername") transport.write(self.local._connect_buffer) self.ready = True