mindstorm38 / portablemc

A fast, reliable and cross-platform command-line Minecraft launcher and API for developers. Including fast and easy installation of common mod loaders such as Fabric, Forge, NeoForge and Quilt.
https://pypi.org/project/portablemc/
GNU General Public License v3.0
354 stars 20 forks source link

Errors remain when attempting offline usage #178

Closed user10072023github closed 11 months ago

user10072023github commented 11 months ago

Hi mindstorm, thanks for all your work so far on this.

Following up on the 08/27 commit: still getting errors when trying to run MC when offline (no internet available to my home).

Specific error is:

C:\Users\User\AppData\Roaming\Python\Python310\Scripts>portablemc start
[←[31mFAILED←[0m] This operation requires an operational network, but a socket error happened:
         gaierror(11001, 'getaddrinfo failed')
[←[34m INFO ←[0m] Use verbose flag -v to get informations that may be useful for developers.

Verbose output since there are multiple errors when network is down:

C:\Users\User\AppData\Roaming\Python\Python310\Scripts>portablemc -v start
[←[31mFAILED←[0m] This operation requires an operational network, but a socket error happened:
Traceback (most recent call last):
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 1348, in do_open
    h.request(req.get_method(), req.selector, req.data, headers,
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\http\client.py", line 1283, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\http\client.py", line 1329, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\http\client.py", line 1278, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\http\client.py", line 1038, in _send_output
    self.send(msg)
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\http\client.py", line 976, in send
    self.connect()
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\http\client.py", line 1448, in connect
    super().connect()
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\http\client.py", line 942, in connect
    self.sock = self._create_connection(
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\socket.py", line 824, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\socket.py", line 955, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 11001] getaddrinfo failed
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "C:\Users\User\AppData\Roaming\Python\Python310\site-packages\portablemc\http.py", line 91, in http_request
    res: HTTPResponse = urllib.request.urlopen(req, context=ctx)
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 216, in urlopen
    return opener.open(url, data, timeout)
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 519, in open
    response = self._open(req, data)
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 536, in _open
    result = self._call_chain(self.handle_open, protocol, protocol +
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 496, in _call_chain
    result = func(*args)
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 1391, in https_open
    return self.do_open(http.client.HTTPSConnection, req,
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 1351, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [Errno 11001] getaddrinfo failed>
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "C:\Users\User\AppData\Roaming\Python\Python310\site-packages\portablemc\cli\__init__.py", line 140, in cmd
    handler(ns)
  File "C:\Users\User\AppData\Roaming\Python\Python310\site-packages\portablemc\cli\__init__.py", line 345, in cmd_start
    env = version.install(watcher=StartWatcher(ns))
  File "C:\Users\User\AppData\Roaming\Python\Python310\site-packages\portablemc\standard.py", line 318, in install
    self._resolve_version(watcher)
  File "C:\Users\User\AppData\Roaming\Python\Python310\site-packages\portablemc\standard.py", line 338, in _resolve_version
    self.version = self.manifest.filter_latest(self.version)[0]
  File "C:\Users\User\AppData\Roaming\Python\Python310\site-packages\portablemc\standard.py", line 1466, in filter_latest
    latest = self._ensure_data()["latest"].get(version)
  File "C:\Users\User\AppData\Roaming\Python\Python310\site-packages\portablemc\standard.py", line 1431, in _ensure_data
    res = http_request("GET", VERSION_MANIFEST_URL,
  File "C:\Users\User\AppData\Roaming\Python\Python310\site-packages\portablemc\http.py", line 96, in http_request
    raise HttpError(HttpResponse(None), method, url, error)
portablemc.http.HttpError: (<HttpResponse 0>, 'GET', 'https://piston-meta.mojang.com/mc/game/version_manifest_v2.json', URLError(gaierror(11001, 'getaddrinfo failed')))

Really hope to get this figured out since ideally I can take everything off my online PC and transfer the .minecraft folder to my offline pc since that's what I actually use to play singleplayer games so I can have a pristine/baselined/unchanging environment. I have the exact version of Python (3.10.11) installed on the offline pc so the environment is nearly the same except the network functionality being missing and if it weren't for these errors it should work finally...

Thanks again!

mindstorm38 commented 11 months ago

Thank you for the detailed report! I think your problem comes from your side, you are using the short form of the start command, without specifying the version's identifier, so it defaults to release, which needs to be resolved (to get the real version, like 1.20.2) from the Mojang's API. Could you try specifying the real version when starting, like portablemc start 1.20.2? Obviously, you'll need to have it installed before that!

Your issue is still very interesting as the launcher should be clearer about the problem and how to fix it, I'll try to add a more explaining error text.

mindstorm38 commented 11 months ago

If I'm correct, this should also work if you have a locally cached version manifest! (portablemc_version_manifest.json)

mindstorm38 commented 11 months ago

I released a patch version 4.0.3 to add better tips to launch in offline mode, and also fixing an issue with locally cached manifest...

user10072023github commented 11 months ago

I'd tried quite a few other args but didn't think of trying to specify the exact version when I only had one installed. Apologies for missing that! I admire your speed and diligence, I'll try the 4.0.3 patch in just a few and report back!

mindstorm38 commented 11 months ago

Thank you, the 4.0.3 patch may be required to fix your issue! Tell me if this works when possible

user10072023github commented 11 months ago

I'm very pleased to say everything works perfectly! I deleted everything created by 4.0.2 and re-ran the install instructions this time with 4.0.3. I then unplugged my online pc to simulate network outage/etc and it launched without a hitch. I also copied everything over to my offline pc, recreated the folder structure for everything again, and it too launched right up with no issues! I'm quite elated I have to say if I'm being fully transparent.

I'll follow up this comment with my exact steps on setting everything up so that others can follow in case they need it...

mindstorm38 commented 11 months ago

So happy this worked! Thank you, I keep this issue open to read the steps, this may end-up linked in the README because PortableMC is made exactly for this use case!

user10072023github commented 11 months ago

For others desiring step-by-step to set up portablemc on an offline pc:

1) Install Python x64 installer for Windows and select the option add python.exe to PATH (I used v3.10 series because I already use Python for other things but v3.11 is tested to work for this project, and be careful not to try v3.12 as that just released on 10/02 but has not been tested with this project's scripts yet) 2) Follow instructions provided in this project's README on online pc and successfully launch Minecraft at least to the main menu but probably better to go ahead and create/load world too just to make 100% sure 3) Install the same exact version Python version to the offline pc (this might not be necessary because the generated .EXE using Python I think is a rollup of the commands and functions that's fully contained but if mindstorm38 wants to jump in it could be quite welcomed since I just don't know as much as I'd like to about it) 4) Copy ".minecraft" folder from your %APPDATA%\Roaming directory (this is the game files), copy "Python" folder from your %APPDATA%\Roaming directory (this has the EXE and this project's scripts), and copy "pip" folder from your %APPDATA%\Local directory (this has cached metadata of some sort that may or may not be needed now or later) and put this all onto the external media of your choice such as a portable flash drive 5) Copy everything over to the exact same locations on the offline pc (make sure your Windows username is the same between the online and offline pc or this might cause problems...someone else would need to test if that would be any issue now or later) 6) Open Command Prompt as Administrator and type "cd C:\Users\User\AppData\Roaming\Python\Python310\Scripts" making sure to substitute "User" in that command for whatever your Windows username is...also make sure to check which Python version you're using i.e. since I used v3.10 my directory contains "Python310" but if you use Python v3.11 then it would be "Python311" 7) Lastly, type "portablemc start 1.20.2" making sure to substitute the "1.20.2" portion for whichever version is locally stored

When you want to back things up, such as your world progress, just copy the ".minecraft" folder from your %APPDATA%\Roaming directory to your preferred backup medium...you could just copy the "saves" folder inside the ".minecraft" folder but there could be issues if your Minecraft game versions aren't the same between your offline/online/prior backup

So, 7 steps that looks like a lot but can be done in about 10 minutes or less...has to be verbose since there a quite a few variables.

Final note...I mentioned twice above the phrase "now or later" to allude to possible future trickery that Microsoft or Mojang might be up to now or later where maybe they configured this Java application to check for a valid digital certificate which might expire every 12 months...or maybe there's a token created somewhere that is only good for 30 days at which time a new token would be needed...could be anything like that that I hope isn't ever implemented or found to have been implemented.

Happy to edit anything down or revise based on quality/friendly feedback from anyone

mindstorm38 commented 11 months ago

TODO for me: Link this issue and last answer in the README.

mindstorm38 commented 11 months ago

This will be linked in the next version's README! Thanks @user10072023github

user10072023github commented 11 months ago

This will be linked in the next version's README! Thanks @user10072023github

So happy to help kind sir!

Rezadirect commented 4 months ago

how to change offline username

mindstorm38 commented 4 months ago

how to change offline username

It's in the main README! For conveniance: portablemc start --username <NAME> or portablemc start -u <NAME>

Rezadirect commented 4 months ago

tnx bro

On Wed, 22 May 2024 at 08:24, Théo Rozier @.***> wrote:

how to change offline username

It's in the main README! For conveniance: portablemc start --username or portablemc start -u

— Reply to this email directly, view it on GitHub https://github.com/mindstorm38/portablemc/issues/178#issuecomment-2124664173, or unsubscribe https://github.com/notifications/unsubscribe-auth/BIPQRTUEKAYU46DQNYDOE7DZDSFAZAVCNFSM6AAAAAA5XLCSOCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMRUGY3DIMJXGM . You are receiving this because you commented.Message ID: @.***>