Add burner account credentials to use by default
This commit is contained in:
		
							
								
								
									
										26
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										26
									
								
								README.md
									
									
									
									
									
								
							@@ -1,6 +1,7 @@
 | 
				
			|||||||
# Mosfet Minecraft Bot
 | 
					# Mosfet Minecraft Bot
 | 
				
			||||||
 | 
					
 | 
				
			||||||
A general-purpose Minecraft 1.16 bot written in Python.
 | 
					A general-purpose Minecraft 1.16 bot written in Python that uses an actual
 | 
				
			||||||
 | 
					Minecraft account to play.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Mosfet is able to farm wood by cutting trees, farm crops, gather sand, farm
 | 
					Mosfet is able to farm wood by cutting trees, farm crops, gather sand, farm
 | 
				
			||||||
netherwart, and trade with villagers to get emeralds. He can eat, sleep, and
 | 
					netherwart, and trade with villagers to get emeralds. He can eat, sleep, and
 | 
				
			||||||
@@ -28,15 +29,32 @@ $ cd minecraft-bot/
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
## Running
 | 
					## Running
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					If you want to use the built-in burner account (Minecraft name `mattstack`):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
$ USERNAME=you@domain.com PASSWORD=supersecret SERVER=example.com ./run_linux.sh
 | 
					$ SERVER=minecraft.example.com ./run_linux.sh
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Use `PORT` to specify a custom port to connect to:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					$ SERVER=localhost PORT=12345 ./run_linux.sh
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					If you have your own alt account:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					$ USERNAME=you@domain.com PASSWORD=supersecret SERVER=minecraft.example.com ./run_linux.sh
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Commands
 | 
					## Commands
 | 
				
			||||||
 | 
					
 | 
				
			||||||
The command prefix character is the last character of the bot's name. For
 | 
					The command prefix character is the last character of the bot's name. For
 | 
				
			||||||
example, if the bot's name is `mosfet1`, then you would issue commands like
 | 
					example, if the bot's name is `mattstack`, then you would issue commands like
 | 
				
			||||||
`1farm wood` or `1pos`. This lets you run multiple bots on the same server.
 | 
					`kfarm wood` or `kpos`. This lets you run multiple bots on the same server.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					In the following examples, we'll assume the bot's name is `mosfet1`, so commands
 | 
				
			||||||
 | 
					would be ran like `1farm wood` or `1pos`.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
The exception are the below public commands, they can optionally be prefixed with `!`
 | 
					The exception are the below public commands, they can optionally be prefixed with `!`
 | 
				
			||||||
and all bots will run the command.
 | 
					and all bots will run the command.
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -9,11 +9,6 @@ import importlib
 | 
				
			|||||||
from math import floor, ceil
 | 
					from math import floor, ceil
 | 
				
			||||||
from copy import copy
 | 
					from copy import copy
 | 
				
			||||||
 | 
					
 | 
				
			||||||
USERNAME = os.getenv('USERNAME')
 | 
					 | 
				
			||||||
PASSWORD = os.getenv('PASSWORD')
 | 
					 | 
				
			||||||
SERVER = os.getenv('SERVER')
 | 
					 | 
				
			||||||
PORT = int(os.environ.get('PORT', 25565))
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
from . import monkey_patch # must be before any possible pyCraft imports
 | 
					from . import monkey_patch # must be before any possible pyCraft imports
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from minecraft import authentication
 | 
					from minecraft import authentication
 | 
				
			||||||
@@ -245,14 +240,25 @@ def init(global_state):
 | 
				
			|||||||
    g.maximum_supply_slots = 33
 | 
					    g.maximum_supply_slots = 33
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def bot(global_state):
 | 
					def bot(global_state):
 | 
				
			||||||
 | 
					    USERNAME = os.getenv('USERNAME')
 | 
				
			||||||
 | 
					    PASSWORD = os.getenv('PASSWORD')
 | 
				
			||||||
 | 
					    SERVER = os.getenv('SERVER')
 | 
				
			||||||
 | 
					    PORT = int(os.environ.get('PORT', 25565))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    g = global_state
 | 
					    g = global_state
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if not g.mcdata:
 | 
					    if not g.mcdata:
 | 
				
			||||||
        g.mcdata = DataManager('./minecraft_data')
 | 
					        g.mcdata = DataManager('./minecraft_data')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if not SERVER:
 | 
					    if not SERVER:
 | 
				
			||||||
        print('You must specify a server to connect to.')
 | 
					        print()
 | 
				
			||||||
        sys.exit()
 | 
					        print('You must specify a server to connect to. For example:')
 | 
				
			||||||
 | 
					        print('SERVER=minecraft.example.com ./run_linux.sh')
 | 
				
			||||||
 | 
					        print('SERVER=localhost PORT=12345 ./run_linux.sh')
 | 
				
			||||||
 | 
					        print()
 | 
				
			||||||
 | 
					        print('If you want to use your own account:')
 | 
				
			||||||
 | 
					        print('USERNAME=you@domain.com PASSWORD=supersecret SERVER=minecraft.example.com ./run_linux.sh')
 | 
				
			||||||
 | 
					        os._exit(0)
 | 
				
			||||||
    elif not g.connection:
 | 
					    elif not g.connection:
 | 
				
			||||||
        if USERNAME and PASSWORD:
 | 
					        if USERNAME and PASSWORD:
 | 
				
			||||||
            auth_token = authentication.AuthenticationToken()
 | 
					            auth_token = authentication.AuthenticationToken()
 | 
				
			||||||
@@ -260,12 +266,25 @@ def bot(global_state):
 | 
				
			|||||||
                auth_token.authenticate(USERNAME, PASSWORD)
 | 
					                auth_token.authenticate(USERNAME, PASSWORD)
 | 
				
			||||||
            except YggdrasilError as e:
 | 
					            except YggdrasilError as e:
 | 
				
			||||||
                print(e)
 | 
					                print(e)
 | 
				
			||||||
                sys.exit()
 | 
					                os._exit(0)
 | 
				
			||||||
            print("Logged in as %s..." % auth_token.username)
 | 
					            print("Logged in as %s..." % auth_token.username)
 | 
				
			||||||
            g.connection = Connection(SERVER, PORT, auth_token=auth_token)
 | 
					            g.connection = Connection(SERVER, PORT, auth_token=auth_token)
 | 
				
			||||||
        elif USERNAME:
 | 
					        elif USERNAME:
 | 
				
			||||||
            print('No password provided, attempting to connect in offline mode...')
 | 
					            print('No password provided, attempting to connect in offline mode...')
 | 
				
			||||||
            g.connection = Connection(SERVER, PORT, username=USERNAME)
 | 
					            g.connection = Connection(SERVER, PORT, username=USERNAME)
 | 
				
			||||||
 | 
					        else:
 | 
				
			||||||
 | 
					            print('No username or password provided, using burner minecraft account...')
 | 
				
			||||||
 | 
					            USERNAME = 'moc.liamg@monortem'[::-1]
 | 
				
			||||||
 | 
					            PASSWORD = '!8891anteR'[::-1]
 | 
				
			||||||
 | 
					            auth_token = authentication.AuthenticationToken()
 | 
				
			||||||
 | 
					            try:
 | 
				
			||||||
 | 
					                auth_token.authenticate(USERNAME, PASSWORD)
 | 
				
			||||||
 | 
					            except YggdrasilError as e:
 | 
				
			||||||
 | 
					                print(e)
 | 
				
			||||||
 | 
					                os._exit(0)
 | 
				
			||||||
 | 
					            print("Logged in as %s..." % auth_token.username)
 | 
				
			||||||
 | 
					            g.connection = Connection(SERVER, PORT, auth_token=auth_token)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        g.chunks = ChunksManager(g.mcdata)
 | 
					        g.chunks = ChunksManager(g.mcdata)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user