def test_authenticate_timeout(self, request, rcon_server): rcon_server.expect(0, valve.rcon.RCONMessage.Type.AUTH, b"") rcon = valve.rcon.RCON(rcon_server.server_address, b"", 1.5) rcon.connect() request.addfinalizer(rcon.close) with pytest.raises(valve.rcon.RCONTimeoutError): rcon.authenticate()
async def handle_rcon_command(self, message): words = message.content.split(' ') if len(words) < 4: reply = "Error: invalid parameters\n" reply += " Usage:\n @{} rcon <server-name> <rcon-command>\n".format( self.user.name) reply += " E.g:\n @{} rcon ark-server-name listplayers\n".format( self.user.name) await message.channel.send(reply) return command = words[1] server_name = words[2] rcon_command = " ".join(words[3:]) if not server_name in self.__servers__: reply = "Error: server name not found in list of servers" await message.channel.send(reply) return #print( " RCON {} {}".format( server_name, rcon_command ) ) ip = self.__servers__[server_name]["ip_address"] port = self.__servers__[server_name]["port"] password = self.__servers__[server_name]["password"] server_tuple = (ip, port) try: rcon = valve.rcon.RCON(server_tuple, password, multi_part=False) rcon.connect() rcon.authenticate() response = rcon.execute(rcon_command, timeout=10) except (valve.rcon.RCONError, ConnectionRefusedError) as e: await message.channel.send( "Failed to connect to server '{}'".format(server_name)) rcon.close() return except valve.rcon.RCONAuthenticationError as e: await message.channel.send( "Failed to authenticate to server '{}'".format(server_name)) rcon.close() return except valve.rcon.RCONTimeoutError as e: await message.channel.send( "Timeout waiting for response from server '{}'".format( server_name)) rcon.close() return except valve.rcon.RCONCommunicationError as e: await message.channel.send( "Error communicating with server '{}'".format(server_name)) await message.channel.send("Server response:\n{}".format(response.text) ) rcon.close()
def test_authenticate_timeout(self, request, rcon_server): rcon_server.expect( 0, valve.rcon.RCONMessage.Type.AUTH, b"") rcon = valve.rcon.RCON(rcon_server.server_address, b"", 1.5) rcon.connect() request.addfinalizer(rcon.close) with pytest.raises(valve.rcon.RCONTimeoutError): rcon.authenticate()
async def cmd(self, ctx, *, cmd_): global servers #servers = await load_json('./json/servers.json') for server in servers: channel_id = servers[server]["discord_channel_id"] if ctx.channel.id == channel_id: addr = server.split(":") addr = (addr[0], int(addr[1])) rcon_password = servers[server]["rcon_password"] try: """print("Here") rcon = valve.rcon.RCON(addr, rcon_password, timeout=None) print("Here2") rcon.connect() print("Her3") rcon.authenticate() print("Her4") command = rcon.__call__(cmd_) print("Her5")""" rcon = valve.rcon.RCON(addr, rcon_password, timeout=None) rcon.connect() rcon.authenticate() response = rcon.execute(cmd_) response_text = response.body.decode("utf-8") log1, log2 = "", "" if cmd_ == 'status': response_text = response_text.split("#") for item in range(2, len(response_text)): try: if item < len(response_text) // 2: add = format_status_log( response_text[item]) log1 = log1 + add + "\n" else: add = format_status_log( response_text[item]) log2 = log2 + add + "\n" except: await ctx.send(response_text[item]) log1 = log1 + f"{chr(701)}" await ctx.send(log1) await ctx.send(log2) else: await ctx.send(f"***__{response_text}__***") except Exception as e: print(f"Command Error: {e}") break
def test_authenticate_not_connected(self): rcon = valve.rcon.RCON(None, b"") with pytest.raises(valve.rcon.RCONError): rcon.authenticate()