From 5adaf46868a06b8708f966c32882f4f14f647178 Mon Sep 17 00:00:00 2001 From: mworzala Date: Sat, 16 Sep 2023 14:50:59 -0400 Subject: [PATCH] feat: allow setting quick play flags added in 1.20 --- cmd/mc/launch.go | 30 ++++++++++++- internal/pkg/game/launch/launch.go | 71 ++++++++++++++++++++---------- internal/pkg/game/launch/model.go | 14 ++++++ 3 files changed, 91 insertions(+), 24 deletions(-) create mode 100644 internal/pkg/game/launch/model.go diff --git a/cmd/mc/launch.go b/cmd/mc/launch.go index 8c8fe20..b943458 100644 --- a/cmd/mc/launch.go +++ b/cmd/mc/launch.go @@ -15,6 +15,11 @@ import ( type launchOpts struct { app *cli.App + // Quick play actions + quickPlaySingleplayer string + quickPlayMultiplayer string + quickPlayRealms string + tail bool } @@ -32,6 +37,11 @@ func newLaunchCmd(app *cli.App) *cobra.Command { }, } + cmd.Flags().StringVarP(&o.quickPlaySingleplayer, "world", "", "", "launch into the server (1.20+)") + cmd.Flags().StringVarP(&o.quickPlayMultiplayer, "server", "", "", "launch into a world (1.20+)") + cmd.Flags().StringVarP(&o.quickPlayRealms, "realm", "", "", "launch into a realm (1.20+)") + cmd.MarkFlagsMutuallyExclusive("world", "server", "realm") + cmd.Flags().BoolVarP(&o.tail, "tail", "t", false, "attach the game stdout to the process") return cmd @@ -71,5 +81,23 @@ func (o *launchOpts) launch(args []string) error { } } - return launch.LaunchProfile(o.app.ConfigDir, p, acc, accessToken, javaInstall, o.tail) + var quickPlay *launch.QuickPlay + if o.quickPlaySingleplayer != "" { + quickPlay = &launch.QuickPlay{ + Type: launch.QuickPlaySingleplayer, + Id: o.quickPlaySingleplayer, + } + } else if o.quickPlayMultiplayer != "" { + quickPlay = &launch.QuickPlay{ + Type: launch.QuickPlayMultiplayer, + Id: o.quickPlayMultiplayer, + } + } else if o.quickPlayRealms != "" { + quickPlay = &launch.QuickPlay{ + Type: launch.QuickPlayRealms, + Id: o.quickPlayRealms, + } + } + + return launch.LaunchProfile(o.app.ConfigDir, p, acc, accessToken, javaInstall, o.tail, quickPlay) } diff --git a/internal/pkg/game/launch/launch.go b/internal/pkg/game/launch/launch.go index 5abe73c..ca0b5aa 100644 --- a/internal/pkg/game/launch/launch.go +++ b/internal/pkg/game/launch/launch.go @@ -21,7 +21,16 @@ import ( "github.com/mworzala/mc/internal/pkg/util" ) -func LaunchProfile(dataDir string, p *profile.Profile, acc *account.Account, accessToken string, javaInstall *java.Installation, tail bool) error { +// todo need to rewrite this whole thing... it's a mess +func LaunchProfile( + dataDir string, + p *profile.Profile, + acc *account.Account, + accessToken string, + javaInstall *java.Installation, + tail bool, + quickPlay *QuickPlay, +) error { var spec gameModel.VersionSpec versionSpecPath := path.Join(dataDir, "versions", p.Version, fmt.Sprintf("%s.json", p.Version)) @@ -40,7 +49,43 @@ func LaunchProfile(dataDir string, p *profile.Profile, acc *account.Account, acc spec = *mergeSpec(&spec, &inheritedSpec) } - rules := rule.NewEvaluator() + vars := map[string]string{ + // jvm + "natives_directory": ".", + "launcher_name": "mc", + "launcher_version": "0.0.1", + // game + "version_name": p.Version, + "game_directory": p.Directory, + "assets_root": path.Join(dataDir, "assets"), + "assets_index_name": spec.Assets, + "auth_player_name": acc.Profile.Username, + "auth_uuid": util.TrimUUID(acc.UUID), + "auth_access_token": accessToken, + // Clientid seems to be the mso client id, without dashes, base64 encoded. Should try it with my own client id to see if that works + "clientid": "MTMwQUU2ODYwQUE1NDUwNkIyNUZCMzZBNjFCNjc3M0Q=", + "user_type": "msa", + "version_type": "release", //todo this needs to be release/snapshot + "resolution_width": "1920", + "resolution_height": "1080", + } + + var features []string + if quickPlay != nil { + //todo need to check game version for this + switch quickPlay.Type { + case QuickPlaySingleplayer: + features = append(features, "is_quick_play_singleplayer") + vars["quickPlaySingleplayer"] = quickPlay.Id + case QuickPlayMultiplayer: + features = append(features, "is_quick_play_multiplayer") + vars["quickPlayMultiplayer"] = quickPlay.Id + case QuickPlayRealms: + features = append(features, "is_quick_play_realms") + vars["quickPlayRealms"] = quickPlay.Id + } + } + rules := rule.NewEvaluator(features...) // Build classpath classpath := strings.Builder{} @@ -72,27 +117,7 @@ func LaunchProfile(dataDir string, p *profile.Profile, acc *account.Account, acc classpath.WriteString(path.Join(dataDir, "versions", p.Version, fmt.Sprintf("%s.jar", p.Version))) } - vars := map[string]string{ - // jvm - "natives_directory": ".", - "launcher_name": "mc", - "launcher_version": "0.0.1", - "classpath": classpath.String(), - // game - "version_name": p.Version, - "game_directory": p.Directory, - "assets_root": path.Join(dataDir, "assets"), - "assets_index_name": spec.Assets, - "auth_player_name": acc.Profile.Username, - "auth_uuid": util.TrimUUID(acc.UUID), - "auth_access_token": accessToken, - // Clientid seems to be the mso client id, without dashes, base64 encoded. Should try it with my own client id to see if that works - "clientid": "MTMwQUU2ODYwQUE1NDUwNkIyNUZCMzZBNjFCNjc3M0Q=", - "user_type": "msa", - "version_type": "release", //todo this needs to be release/snapshot - "resolution_width": "1920", - "resolution_height": "1080", - } + vars["classpath"] = classpath.String() if msoTokenData, ok := acc.Source.(*account.MicrosoftTokenData); ok { vars["auth_xuid"] = msoTokenData.UserHash diff --git a/internal/pkg/game/launch/model.go b/internal/pkg/game/launch/model.go new file mode 100644 index 0000000..9d098fe --- /dev/null +++ b/internal/pkg/game/launch/model.go @@ -0,0 +1,14 @@ +package launch + +type QuickPlayType int + +const ( + QuickPlaySingleplayer QuickPlayType = iota + QuickPlayMultiplayer + QuickPlayRealms +) + +type QuickPlay struct { + Type QuickPlayType + Id string +}