-
Notifications
You must be signed in to change notification settings - Fork 2
Papermc arclight #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Fellsoul
wants to merge
8
commits into
kmcsr:main
Choose a base branch
from
Fellsoul:papermc_arclight2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8806ece
Fix go vet
Fellsoul a9cdfba
change logs and readme
Fellsoul ff24147
Update README.MD
Fellsoul b3c9029
Update README_zh.MD
Fellsoul 997e302
Update README_zh.MD
Fellsoul 3797202
Update arclight_installer.go
Fellsoul fc8163f
Update papermc_installer.go
Fellsoul 68ef4e6
Update arclight_installer use time parse .go
Fellsoul File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,189 @@ | ||
| package installer | ||
|
|
||
| import ( | ||
| "context" | ||
| "os" | ||
| "os/exec" | ||
| "path/filepath" | ||
| "strconv" | ||
| "strings" | ||
| ) | ||
|
|
||
| type ( | ||
| ArclightInstaller struct {} | ||
|
|
||
| ArclightAssets struct { | ||
| AssetsUrl string `json:"url"` | ||
| AssetsName string `json:"name"` | ||
| DownloadUrl string `json:"browser_download_url"` | ||
| } | ||
Fellsoul marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ArclightRelease struct { | ||
| Assets []ArclightAssets `json:"assets"` | ||
| IsExpired bool | ||
| PublishTime string `json:"published_at"` | ||
Fellsoul marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| ) | ||
|
|
||
| var DefaultArclightInstaller = &ArclightInstaller{} | ||
|
|
||
| var _ Installer = DefaultArclightInstaller | ||
|
|
||
| func init() { | ||
| Installers["arclight"] = DefaultArclightInstaller | ||
| } | ||
|
|
||
| func (r *ArclightInstaller) Install(path, name string, target string) (installed string, err error) { | ||
| return r.InstallWithLoader(path, name, target, "") | ||
| } | ||
|
|
||
| func (r *ArclightInstaller) InstallWithLoader(path, name string, target string, loader string) (installed string, err error) { | ||
| versions, err := r.GetInstallerVersions() | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
| if len(loader) == 0 { | ||
| var alreadyFind bool = false | ||
| allVersions := r.GetOnlyVersions(versions) | ||
| if target == "latest" { | ||
| loader, err = r.GetLatestVersion() | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
| alreadyFind = true | ||
| } | ||
| for _, version := range allVersions { | ||
| if version == target { | ||
| loader = target | ||
| alreadyFind = true | ||
| } | ||
| } | ||
| if !alreadyFind { | ||
| loger.Info("not find the suitable builder, the version should be included in the following list:") | ||
| for _, version := range allVersions { | ||
| if versions[version].IsExpired { | ||
| loger.Info("versions:", version, " EXPIRED, DO NOT SUPPORT") | ||
| } else { | ||
| loger.Info("versions:", version) | ||
| } | ||
| } | ||
| return "", &VersionNotFoundErr{target} | ||
| } | ||
| } | ||
| exactDownloadeName := versions[loader].Assets[0].AssetsName | ||
| ArclightInstallerUrl := versions[loader].Assets[0].DownloadUrl | ||
| if version, ok := versions[loader]; ok && version.IsExpired { | ||
| loger.Fatal("Sorry, the one you choose has already expired, try another version.") | ||
| return "", &VersionNotFoundErr{target} | ||
| } | ||
| var buildJar string | ||
| if buildJar, err = DefaultHTTPClient.DownloadDirect(ArclightInstallerUrl, exactDownloadeName, downloadingCallback(ArclightInstallerUrl)); err != nil { | ||
| return | ||
| } | ||
| installed, err = r.Runbuilder(buildJar, exactDownloadeName, path) | ||
| if err != nil { | ||
| loger.Info("an error occurred while running the server jar file, but you can still do that manually.") | ||
| loger.Error(err) | ||
| } | ||
| return | ||
| } | ||
|
|
||
| func (r *ArclightInstaller) ListVersions(snapshot bool) ([]string, error) { | ||
| additionalVersions, err := r.GetInstallerVersions() | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| return r.GetOnlyVersions(additionalVersions), err | ||
| } | ||
|
|
||
| func (r *ArclightInstaller) GetLatestVersion() (version string, err error) { | ||
| additionalVersions, err := r.GetInstallerVersions() | ||
| if err != nil { | ||
| return | ||
| } | ||
| var dataVersions []string = r.GetOnlyVersions(additionalVersions) | ||
| var v0, v1 Version | ||
| for _, v := range dataVersions { | ||
| if v1, err = VersionFromString(v); err != nil { | ||
| return | ||
| } | ||
| if v0.Less(v1) { | ||
| v0 = v1 | ||
| } | ||
| } | ||
| version = v0.String() | ||
| return | ||
| } | ||
|
|
||
| func (r *ArclightInstaller) GetInstallerVersions() (map[string]ArclightRelease, error) { | ||
| additionalVersions := make(map[string]ArclightRelease) | ||
| link := "https://api.github.com/repos/IzzelAliz/Arclight/releases" | ||
| var releases []*ArclightRelease | ||
| err := DefaultHTTPClient.GetJson(link, &releases) | ||
| if err != nil { | ||
| return additionalVersions, err | ||
| } | ||
| for _, release := range releases { | ||
| details := strings.Split(release.Assets[0].AssetsName, "-") | ||
| // details should be ["arclight","forge","{VERSION}","{BUILDNUM}.jar"], so append value of index 2 | ||
| layout := "2006-01-02T14:41:48Z" | ||
| timeDetails, err := time.Parse(layout, release.PublishTime) | ||
| if err != nil{ | ||
| return additionalVersions, err | ||
| } | ||
| year := timeDetails.Year() | ||
| month := timeDetails.Month() | ||
| expiredYear := 2024 | ||
| expiredMonth := time.February | ||
| if year < expiredYear || (year == expiredYear && month < expiredMonth) { | ||
| release.IsExpired = true | ||
| } else { | ||
| release.IsExpired = false | ||
| } | ||
| if len(additionalVersions[details[2]].Assets) == 0 { | ||
| additionalVersions[details[2]] = *release | ||
| } | ||
| // to get the newest builder for each version | ||
| } | ||
| return additionalVersions, err | ||
| } | ||
|
|
||
| func (r *ArclightInstaller) GetOnlyVersions(additionalVersions map[string]ArclightRelease) (versions []string) { | ||
| for k, _ := range additionalVersions { | ||
| versions = append(versions, k) | ||
| } | ||
| return | ||
| } | ||
|
|
||
| func (r *ArclightInstaller) Runbuilder(buildJar string, ExactDownloadName string, path string) (installed string, err error) { | ||
| const SUFFIX_LENGTH int = 4 | ||
| NameWithoutSuffix := ExactDownloadName[0 : len(ExactDownloadName)-SUFFIX_LENGTH] | ||
| serverDirectory := filepath.Join(".", "server-"+NameWithoutSuffix) | ||
| os.RemoveAll(serverDirectory) | ||
| err = os.MkdirAll(serverDirectory, os.ModePerm) | ||
| if err != nil { | ||
| return | ||
| } | ||
| err = os.Rename(buildJar, filepath.Join(serverDirectory, ExactDownloadName)) | ||
| if err != nil { | ||
| return | ||
| } | ||
| buildJar = filepath.Join(serverDirectory, ExactDownloadName) | ||
| loger.Info("Server jar file is successfully installed in path: " + buildJar) | ||
| ctx, cancel := context.WithCancel(context.Background()) | ||
| defer cancel() | ||
| javapath, err := lookJavaPath() | ||
| if err != nil { | ||
| return | ||
| } | ||
| cmd := exec.CommandContext(ctx, javapath, "-jar", buildJar) | ||
| cmd.Dir = filepath.Join(path, "server-"+ExactDownloadName[0 : len(ExactDownloadName)-SUFFIX_LENGTH]) | ||
| cmd.Stdout = os.Stdout | ||
| cmd.Stderr = os.Stdout | ||
| loger.Infof("Running %q...", cmd.String()) | ||
| if err = cmd.Run(); err != nil { | ||
| return | ||
| } | ||
| installed = buildJar | ||
| return | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
|
|
||
| #### Adds | ||
|
|
||
| - Add the support of Papermc server downloading and available versions inquiry | ||
| - Add the support of Arclight server downloading and available versions inquiry | ||
|
|
||
| #### Changes | ||
|
|
||
| - Support new types of server: Papermc, Arclight |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.