Skip to content

Commit

Permalink
feat: allow setting quick play flags added in 1.20
Browse files Browse the repository at this point in the history
  • Loading branch information
mworzala committed Sep 16, 2023
1 parent e84d54e commit 875158e
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 24 deletions.
30 changes: 29 additions & 1 deletion cmd/mc/launch.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ import (
type launchOpts struct {
app *cli.App

// Quick play actions
quickPlaySingleplayer string
quickPlayMultiplayer string
quickPlayRealms string

tail bool
}

Expand All @@ -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
Expand Down Expand Up @@ -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)
}
71 changes: 48 additions & 23 deletions internal/pkg/game/launch/launch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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{}
Expand Down Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions internal/pkg/game/launch/model.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package launch

type QuickPlayType int

const (
QuickPlaySingleplayer QuickPlayType = iota
QuickPlayMultiplayer
QuickPlayRealms
)

type QuickPlay struct {
Type QuickPlayType
Id string
}

0 comments on commit 875158e

Please sign in to comment.