rcon helper script
This commit is contained in:
		
							parent
							
								
									3c053cf51b
								
							
						
					
					
						commit
						7aeb3be86d
					
				
					 1 changed files with 32 additions and 0 deletions
				
			
		
							
								
								
									
										32
									
								
								bin/rcon
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										32
									
								
								bin/rcon
									
									
									
									
									
										Executable file
									
								
							|  | @ -0,0 +1,32 @@ | |||
| #!/usr/bin/env python3 | ||||
| 
 | ||||
| from sys import argv | ||||
| from os.path import realpath, dirname | ||||
| from shlex import quote | ||||
| from bundlewrap.repo import Repository | ||||
| 
 | ||||
| repo = Repository(dirname(dirname(realpath(__file__)))) | ||||
| 
 | ||||
| if len(argv) == 1: | ||||
|     for node in repo.nodes: | ||||
|         for name in node.metadata.get('left4dead2/servers', {}): | ||||
|             print(name) | ||||
|     exit(0) | ||||
| 
 | ||||
| server = argv[1] | ||||
| command = argv[2] | ||||
| 
 | ||||
| remote_code = """ | ||||
| from rcon.source import Client | ||||
| 
 | ||||
| with Client('127.0.0.1', {port}, passwd='''{password}''') as client: | ||||
|     response = client.run('''{command}''') | ||||
| 
 | ||||
| print(response) | ||||
| """ | ||||
| 
 | ||||
| for node in repo.nodes: | ||||
|     for name, conf in node.metadata.get('left4dead2/servers', {}).items(): | ||||
|         if name == server: | ||||
|             response = node.run('python3 -c ' + quote(remote_code.format(port=conf['port'], password=conf['rcon_password'], command=command))) | ||||
|             print(response.stdout.decode()) | ||||
		Loading…
	
		Reference in a new issue