first commit
This commit is contained in:
commit
42b928f6e1
234 changed files with 27908 additions and 0 deletions
9
ViaProxy/.gitattributes
vendored
Normal file
9
ViaProxy/.gitattributes
vendored
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
#
|
||||
# https://help.github.com/articles/dealing-with-line-endings/
|
||||
#
|
||||
# Linux start script should use lf
|
||||
/gradlew text eol=lf
|
||||
|
||||
# These are Windows script files and should use crlf
|
||||
*.bat text eol=crlf
|
||||
|
||||
1
ViaProxy/.github/FUNDING.yml
vendored
Normal file
1
ViaProxy/.github/FUNDING.yml
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
ko_fi: "rk_01"
|
||||
12
ViaProxy/.github/crowdin.yml
vendored
Normal file
12
ViaProxy/.github/crowdin.yml
vendored
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
project_id_env: "CROWDIN_PROJECT_ID"
|
||||
api_token_env: "CROWDIN_PERSONAL_TOKEN"
|
||||
base_path: "../"
|
||||
preserve_hierarchy: true
|
||||
files: [
|
||||
{
|
||||
source: "/src/main/resources/assets/viaproxy/language/en_US.properties",
|
||||
translation: "/src/main/resources/assets/viaproxy/language/%locale_with_underscore%.properties",
|
||||
escape_quotes: 0,
|
||||
escape_special_characters: 0
|
||||
}
|
||||
]
|
||||
16
ViaProxy/.github/dependabot.yml
vendored
Normal file
16
ViaProxy/.github/dependabot.yml
vendored
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
version: 2
|
||||
registries:
|
||||
maven-central:
|
||||
type: "maven-repository"
|
||||
url: "https://repo.maven.apache.org/maven2/"
|
||||
updates:
|
||||
- package-ecosystem: "gradle"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "daily"
|
||||
registries:
|
||||
- "maven-central"
|
||||
- package-ecosystem: "github-actions"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "daily"
|
||||
62
ViaProxy/.github/workflows/build-docker.yml
vendored
Normal file
62
ViaProxy/.github/workflows/build-docker.yml
vendored
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
name: "Build Docker image"
|
||||
on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
branches:
|
||||
- "main"
|
||||
|
||||
permissions:
|
||||
contents: "read"
|
||||
packages: "write"
|
||||
|
||||
env:
|
||||
REGISTRY: "ghcr.io"
|
||||
|
||||
jobs:
|
||||
build-docker-image:
|
||||
runs-on: "ubuntu-24.04"
|
||||
steps:
|
||||
- name: "Checkout repository"
|
||||
uses: "actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd" # v6.0.2
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: "Set up Gradle"
|
||||
uses: "gradle/actions/setup-gradle@f29f5a9d7b09a7c6b29859002d29d24e1674c884" # v5.0.1
|
||||
- name: "Set up Java 25"
|
||||
uses: "actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654" # v5.2.0
|
||||
with:
|
||||
distribution: "temurin"
|
||||
java-version: 25
|
||||
check-latest: true
|
||||
- name: "Build with Gradle"
|
||||
run: "./gradlew build"
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 # v3.7.0
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3.12.0
|
||||
- name: Log into registry ${{ env.REGISTRY }}
|
||||
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0
|
||||
with:
|
||||
registry: ${{ env.REGISTRY }}
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
- name: Extract Docker metadata
|
||||
id: meta
|
||||
uses: docker/metadata-action@c299e40c65443455700f0fdfc63efafe5b349051 # v5.10.0
|
||||
with:
|
||||
tags: |
|
||||
type=raw,value=latest
|
||||
type=raw,value=${{ github.ref_name }}
|
||||
type=semver,pattern={{version}}
|
||||
images: ${{ env.REGISTRY }}/${{ github.repository }}
|
||||
- name: Build and push Docker image
|
||||
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
|
||||
with:
|
||||
context: .
|
||||
platforms: linux/amd64,linux/arm64
|
||||
push: true
|
||||
provenance: false
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
cache-from: type=gha
|
||||
cache-to: type=gha,mode=max
|
||||
30
ViaProxy/.github/workflows/build.yml
vendored
Normal file
30
ViaProxy/.github/workflows/build.yml
vendored
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
name: "Build"
|
||||
on: ["push", "pull_request", "workflow_dispatch"]
|
||||
|
||||
permissions:
|
||||
contents: "read"
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: "ubuntu-24.04"
|
||||
if: "${{ github.event_name != 'pull_request' || github.repository != github.event.pull_request.head.repo.full_name }}"
|
||||
steps:
|
||||
- name: "Checkout repository"
|
||||
uses: "actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd" # v6.0.2
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: "Set up Gradle"
|
||||
uses: "gradle/actions/setup-gradle@f29f5a9d7b09a7c6b29859002d29d24e1674c884" # v5.0.1
|
||||
- name: "Set up Java 25"
|
||||
uses: "actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654" # v5.2.0
|
||||
with:
|
||||
distribution: "temurin"
|
||||
java-version: 25
|
||||
check-latest: true
|
||||
- name: "Build with Gradle"
|
||||
run: "./gradlew build"
|
||||
- name: "Upload artifacts to GitHub"
|
||||
uses: "actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f" # v6.0.0
|
||||
with:
|
||||
name: "Artifacts"
|
||||
path: "build/libs/"
|
||||
34
ViaProxy/.github/workflows/crowdin-sync.yml
vendored
Normal file
34
ViaProxy/.github/workflows/crowdin-sync.yml
vendored
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
name: "Synchronize with Crowdin"
|
||||
on:
|
||||
workflow_dispatch:
|
||||
schedule:
|
||||
- cron: "0 0 * * *"
|
||||
|
||||
permissions:
|
||||
contents: "write"
|
||||
pull-requests: "write"
|
||||
|
||||
jobs:
|
||||
synchronize-with-crowdin:
|
||||
runs-on: "ubuntu-24.04"
|
||||
steps:
|
||||
- name: "Checkout repository"
|
||||
uses: "actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd" # v6.0.2
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: "Crowdin sync"
|
||||
uses: "crowdin/github-action@b4b468cffefb50bdd99dd83e5d2eaeb63c880380" # v2.14.0
|
||||
with:
|
||||
config: ".github/crowdin.yml"
|
||||
upload_sources: true
|
||||
download_translations: true
|
||||
localization_branch_name: "l10n_crowdin_translations"
|
||||
create_pull_request: true
|
||||
pull_request_base_branch_name: "main"
|
||||
pull_request_title: "New Crowdin Translations"
|
||||
pull_request_body: "New Crowdin translations by [Crowdin GH Action](https://github.com/crowdin/github-action)"
|
||||
commit_message: "Updated translations from Crowdin"
|
||||
env:
|
||||
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
|
||||
CROWDIN_PROJECT_ID: "${{ secrets.CROWDIN_PROJECT_ID }}"
|
||||
CROWDIN_PERSONAL_TOKEN: "${{ secrets.CROWDIN_PERSONAL_TOKEN }}"
|
||||
18
ViaProxy/.gitignore
vendored
Normal file
18
ViaProxy/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
# Compiled class file
|
||||
*.class
|
||||
|
||||
# Log file
|
||||
*.log
|
||||
*.log.gz
|
||||
|
||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||
hs_err_pid*
|
||||
|
||||
# Project files
|
||||
/.idea/*
|
||||
!/.idea/copyright/
|
||||
/.gradle/
|
||||
/buildSrc/.gradle/
|
||||
build/
|
||||
out/
|
||||
/run/
|
||||
6
ViaProxy/.idea/copyright/GPL_3_0.xml
generated
Normal file
6
ViaProxy/.idea/copyright/GPL_3_0.xml
generated
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
<component name="CopyrightManager">
|
||||
<copyright>
|
||||
<option name="notice" value="This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy Copyright (C) 2021-&#36;today.year RK_01/RaphiMC and contributors This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>." />
|
||||
<option name="myName" value="GPL-3.0" />
|
||||
</copyright>
|
||||
</component>
|
||||
10
ViaProxy/.idea/copyright/profiles_settings.xml
generated
Normal file
10
ViaProxy/.idea/copyright/profiles_settings.xml
generated
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<component name="CopyrightManager">
|
||||
<settings>
|
||||
<module2copyright>
|
||||
<element module="Project Files" copyright="GPL-3.0" />
|
||||
</module2copyright>
|
||||
<LanguageOptions name="__TEMPLATE__">
|
||||
<option name="addBlankAfter" value="false" />
|
||||
</LanguageOptions>
|
||||
</settings>
|
||||
</component>
|
||||
4
ViaProxy/Dockerfile
Normal file
4
ViaProxy/Dockerfile
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
FROM eclipse-temurin:21-jre-alpine
|
||||
WORKDIR /app/run
|
||||
COPY /build/libs/ViaProxy-*.jar /app/ViaProxy.jar
|
||||
ENTRYPOINT ["java", "-jar", "/app/ViaProxy.jar", "config", "viaproxy.yml"]
|
||||
674
ViaProxy/LICENSE
Normal file
674
ViaProxy/LICENSE
Normal file
|
|
@ -0,0 +1,674 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
||||
102
ViaProxy/README.md
Normal file
102
ViaProxy/README.md
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
# ViaProxy
|
||||
Standalone proxy which allows players to join EVERY Minecraft server version (Classic, Alpha, Beta, Release, Bedrock)
|
||||
|
||||
To download the latest version, go to the [Releases section](#executable-jar-file) and download the latest version.
|
||||
Using it is very simple, just run the jar file, and it will start a user interface where everything can be configured.
|
||||
For a full user guide go to the [Usage for Players](#usage-for-players-gui) section or the [Usage for Server Owners](#usage-for-server-owners-config) section.
|
||||
|
||||
## Supported Server versions
|
||||
- Release (1.0.0 - 1.21.11)
|
||||
- Beta (b1.0 - b1.8.1)
|
||||
- Alpha (a1.0.15 - a1.2.6)
|
||||
- Classic (c0.0.15 - c0.30 including [CPE](https://wiki.vg/Classic_Protocol_Extension))
|
||||
- April Fools (3D Shareware, 20w14infinite, 25w14craftmine)
|
||||
- Combat Snapshots (Combat Test 8c)
|
||||
- Bedrock Edition 1.21.130 ([Some features are missing](https://github.com/RaphiMC/ViaBedrock#features))
|
||||
|
||||
## Supported Client versions
|
||||
- Release (1.7.2 - 1.21.11)
|
||||
- April Fools (3D Shareware, 25w14craftmine)
|
||||
- Bedrock Edition (Requires the [Geyser plugin](https://geysermc.org/download))
|
||||
- Beta 1.7.3 (Requires the [Beta2Release plugin](https://github.com/ViaVersionAddons/ViaProxyBeta2Release))
|
||||
- Classic, Alpha, Beta, Release 1.0 - 1.6.4 (Only passthrough)
|
||||
|
||||
ViaProxy supports joining to any of the listed server version from any of the listed client versions.
|
||||
|
||||
## Special Features
|
||||
- Support for joining online mode servers
|
||||
- Support for joining on servers which have chat signing enabled from all listed client versions
|
||||
- Supports transfer and cookies for <=1.20.4 clients on 1.20.5+ servers
|
||||
- Allows joining Minecraft Realms with any supported client version
|
||||
- Supports Simple Voice Chat mod
|
||||
|
||||
## Releases
|
||||
### Executable Jar File
|
||||
If you want the executable jar file you can download a stable release from [GitHub Releases](https://github.com/ViaVersion/ViaProxy/releases/latest) or the latest dev version from [GitHub Actions](https://github.com/RaphiMC/ViaProxy/actions/workflows/build.yml) or the [ViaVersion Jenkins](https://ci.viaversion.com/view/Platforms/job/ViaProxy/).
|
||||
|
||||
### Docker Image
|
||||
ViaProxy docker images can be found on [GitHub Packages](https://github.com/ViaVersion/ViaProxy/pkgs/container/viaproxy).
|
||||
|
||||
To run the latest version of ViaProxy you can use the following command:
|
||||
```bash
|
||||
docker run -it -v /path/to/run:/app/run -p 25568:25568 ghcr.io/viaversion/viaproxy:latest
|
||||
```
|
||||
where ``/path/to/run`` is the path where the ViaProxy data should be stored and ``25568`` is the port ViaProxy should listen on.
|
||||
|
||||
## Usage for Players (GUI)
|
||||

|
||||
1. Download the latest version from the [Releases section](#executable-jar-file)
|
||||
2. Put the jar file into a folder (ViaProxy will generate config files and store some data there)
|
||||
3. Run the jar file
|
||||
4. Fill in the required fields like server address and version
|
||||
5. If you want to join online mode servers, add your Minecraft account in the Accounts tab
|
||||
6. Click on "Start"
|
||||
7. Join with your Minecraft client on the displayed address
|
||||
8. Have fun!
|
||||
|
||||
## Usage for Server owners (Config)
|
||||
1. Download the latest version from the [Releases section](#executable-jar-file)
|
||||
2. Put the jar file into a folder (ViaProxy will generate config files and store some data there)
|
||||
3. Run the jar file (Using ``java -jar ViaProxy-whateverversion.jar config viaproxy.yml``)
|
||||
4. ViaProxy now generates a config file called ``viaproxy.yml`` in the same folder and exits
|
||||
5. Open the config file and configure the proxy (Most important options are at the top)
|
||||
6. Start the proxy using the start command and test whether it works (Join using the server's public address and the bind port you configured)
|
||||
7. Have fun!
|
||||
|
||||
## Usage for Server owners (CLI)
|
||||
1. Download the latest version from the [Releases section](#executable-jar-file)
|
||||
2. Put the jar file into a folder (ViaProxy will generate config files and store some data there)
|
||||
3. Run the jar file (Using ``java -jar ViaProxy-whateverversion.jar cli --help``)
|
||||
4. ViaProxy will print the CLI usage and exit
|
||||
5. Configure the proxy and optionally put the finished start command into a script
|
||||
6. Start the proxy using the start command and test whether it works (Join using the server's public address and the bind port you configured)
|
||||
7. Have fun!
|
||||
|
||||
### Configuring the protocol translation
|
||||
To change ViaProxy settings you can check out the ``viaproxy.yml`` config file. Most of the settings are configurable via the GUI.
|
||||
To change the protocol translation settings/features you can look into the ``ViaLoader`` folder.
|
||||
You will find 5 config files there:
|
||||
- viaversion.yml (ViaVersion)
|
||||
- viabackwards.yml (ViaBackwards)
|
||||
- viarewind.yml (ViaRewind)
|
||||
- vialegacy.yml (ViaLegacy)
|
||||
- viabedrock.yml (ViaBedrock)
|
||||
|
||||
### Developer Plugin API
|
||||
ViaProxy has a plugin API which allows you to extend and modify the behavior of ViaProxy.
|
||||
Documentation for the plugin API can be found [here](https://github.com/ViaVersion/ViaProxy/wiki/Creating-plugins).
|
||||
A list of plugins can be found [here](https://github.com/ViaVersion/ViaProxy/wiki/Plugins).
|
||||
|
||||
## Contributing
|
||||
Contributions in the form of pull requests are always welcome.
|
||||
Please make sure to keep your code style consistent with the rest of the project and that your code is easily maintainable.
|
||||
If you plan to make a large scale changes, please open an issue first or join my discord to discuss it.
|
||||
|
||||
### Translations
|
||||
If you want to help translating ViaProxy you can do so on [Crowdin](https://crowdin.com/project/viaproxy).
|
||||
|
||||
## Contact
|
||||
If you encounter any issues, please report them on the
|
||||
[issue tracker](https://github.com/ViaVersion/ViaProxy/issues).
|
||||
If you just want to talk or need help using ViaProxy feel free to join the ViaVersion
|
||||
[Discord](https://discord.gg/viaversion).
|
||||
145
ViaProxy/build.gradle
Normal file
145
ViaProxy/build.gradle
Normal file
|
|
@ -0,0 +1,145 @@
|
|||
plugins {
|
||||
id "java"
|
||||
id "base.base-conventions"
|
||||
id "base.application-conventions"
|
||||
id "base.fill-build-constants"
|
||||
id "viaproxy.publishing-conventions"
|
||||
id "net.raphimc.class-token-replacer" version "1.1.7"
|
||||
id "xyz.wagyourtail.jvmdowngrader" version "1.3.6"
|
||||
}
|
||||
|
||||
configurations {
|
||||
includeInJarJ8
|
||||
}
|
||||
|
||||
repositories {
|
||||
maven {
|
||||
name = "ViaVersion"
|
||||
url = "https://repo.viaversion.com"
|
||||
|
||||
content {
|
||||
includeGroupByRegex "com\\.viaversion(\\..+)?"
|
||||
includeGroupByRegex "net\\.raphimc(\\..+)?"
|
||||
}
|
||||
}
|
||||
maven {
|
||||
name = "Lenni0451"
|
||||
url = "https://maven.lenni0451.net/everything"
|
||||
|
||||
content {
|
||||
includeGroupByRegex "net\\.lenni0451(\\..+)?"
|
||||
includeGroupByRegex "net\\.raphimc(\\..+)?"
|
||||
}
|
||||
}
|
||||
maven {
|
||||
name = "Minecraft Libraries"
|
||||
url = "https://libraries.minecraft.net"
|
||||
|
||||
content {
|
||||
includeGroup "com.mojang"
|
||||
}
|
||||
}
|
||||
maven {
|
||||
name = "Jitpack"
|
||||
url = "https://jitpack.io"
|
||||
|
||||
content {
|
||||
includeGroupByRegex "com\\.github\\..+"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
includeInJar "com.viaversion:viaversion-common:5.7.2-SNAPSHOT"
|
||||
includeInJar "com.viaversion:viabackwards-common:5.7.1"
|
||||
includeInJar "com.viaversion:viarewind-common:4.0.14"
|
||||
includeInJar "net.raphimc:ViaLegacy:3.0.13"
|
||||
includeInJar "com.viaversion:viaaprilfools-common:4.0.8"
|
||||
includeInJar "net.raphimc:ViaBedrock:0.0.25-SNAPSHOT"
|
||||
|
||||
includeInJar "com.google.guava:guava:33.5.0-jre"
|
||||
includeInJar "com.google.code.gson:gson:2.13.2"
|
||||
includeInJar "com.formdev:flatlaf:3.7"
|
||||
includeInJar "com.formdev:flatlaf-extras:3.7"
|
||||
includeInJar "org.apache.commons:commons-lang3:3.20.0"
|
||||
includeInJar "commons-io:commons-io:2.21.0"
|
||||
includeInJar "net.sf.jopt-simple:jopt-simple:5.0.4"
|
||||
includeInJar "org.apache.logging.log4j:log4j-core:2.25.3"
|
||||
includeInJar "org.apache.logging.log4j:log4j-slf4j2-impl:2.25.3"
|
||||
includeInJar "org.jline:jansi:3.30.6"
|
||||
includeInJar("com.mojang:authlib:6.0.58") {
|
||||
exclude group: "org.slf4j", module: "slf4j-api"
|
||||
}
|
||||
includeInJar "net.lenni0451.classtransform:mixinstranslator:1.14.1"
|
||||
includeInJar "net.lenni0451.classtransform:mixinsdummy:1.14.1"
|
||||
includeInJar "net.lenni0451.classtransform:additionalclassprovider:1.14.1"
|
||||
includeInJar "net.lenni0451:Reflect:1.6.2"
|
||||
includeInJar "net.lenni0451:LambdaEvents:2.4.2"
|
||||
includeInJar("net.lenni0451:MCPing:1.4.4") {
|
||||
exclude group: "com.google.code.gson", module: "gson"
|
||||
}
|
||||
includeInJar "net.lenni0451.commons:swing:1.9.2"
|
||||
includeInJar "net.lenni0451.commons:brigadier:1.9.2"
|
||||
includeInJar "net.lenni0451.commons:unchecked:1.9.2"
|
||||
includeInJar("net.raphimc.netminecraft:all:3.1.5-SNAPSHOT") {
|
||||
exclude group: "com.google.code.gson", module: "gson"
|
||||
}
|
||||
includeInJar("io.netty:netty-codec-haproxy:4.2.10.Final") {
|
||||
transitive = false
|
||||
}
|
||||
includeInJar("io.netty:netty-handler-proxy:4.2.10.Final") {
|
||||
transitive = false
|
||||
}
|
||||
includeInJar("io.netty:netty-codec-socks:4.2.10.Final") {
|
||||
transitive = false
|
||||
}
|
||||
includeInJar("net.raphimc:MinecraftAuth:5.0.0") {
|
||||
exclude group: "com.google.code.gson", module: "gson"
|
||||
}
|
||||
includeInJar("dev.kastle.netty:netty-transport-raknet:1.6.1") {
|
||||
exclude group: "io.netty"
|
||||
}
|
||||
includeInJar("dev.kastle.netty:netty-transport-nethernet:1.6.1") {
|
||||
exclude group: "io.netty"
|
||||
}
|
||||
["windows-x86_64", "windows-aarch64", "linux-x86_64", "linux-aarch64", "macos-aarch64"].each {
|
||||
includeInJar "dev.kastle.webrtc:webrtc-java:1.0.3:$it"
|
||||
}
|
||||
includeInJar "gs.mclo:api:6.2.0"
|
||||
includeInJar "net.lenni0451:optconfig:1.1.1"
|
||||
|
||||
includeInJarJ8(compileOnly("xyz.wagyourtail.jvmdowngrader:jvmdowngrader:1.3.6"))
|
||||
includeInJarJ8 "xyz.wagyourtail.jvmdowngrader:jvmdowngrader-java-api:1.3.6:downgraded-8"
|
||||
}
|
||||
|
||||
application {
|
||||
mainClass = "net.raphimc.viaproxy.ViaProxy"
|
||||
}
|
||||
|
||||
jar {
|
||||
manifest {
|
||||
attributes(
|
||||
"Launcher-Agent-Class": application.mainClass
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
downgradeJar {
|
||||
dependsOn(configurations.includeInJarJ8)
|
||||
from {
|
||||
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
||||
configurations.includeInJarJ8.collect {
|
||||
zipTree(it)
|
||||
}
|
||||
} {
|
||||
exclude "META-INF/*.RSA", "META-INF/*.SF", "META-INF/*.DSA"
|
||||
}
|
||||
|
||||
downgradeTo = JavaVersion.VERSION_1_8
|
||||
ignoreWarningsIn.add("net/lenni0451/commons/httpclient/executor/HttpClientExecutor")
|
||||
archiveClassifier = null
|
||||
archiveVersion = project.version + "+java8"
|
||||
}
|
||||
build.finalizedBy("downgradeJar")
|
||||
|
||||
tasks.javadoc.enabled = false
|
||||
7
ViaProxy/buildSrc/build.gradle
Normal file
7
ViaProxy/buildSrc/build.gradle
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
plugins {
|
||||
id "groovy-gradle-plugin"
|
||||
}
|
||||
|
||||
repositories {
|
||||
gradlePluginPortal()
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
plugins {
|
||||
id "application"
|
||||
id "base.include-in-jar-configuration"
|
||||
id "base.exclude-run-folder"
|
||||
}
|
||||
|
||||
jar {
|
||||
manifest {
|
||||
attributes(
|
||||
"Main-Class": application.mainClass,
|
||||
"Multi-Release": "true",
|
||||
"Enable-Native-Access": "ALL-UNNAMED"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
base {
|
||||
java.toolchain.languageVersion = JavaLanguageVersion.of(project.java_version)
|
||||
|
||||
group = project.maven_group
|
||||
archivesName = project.name
|
||||
version = project.maven_version
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
jar {
|
||||
if (layout.projectDirectory.file("LICENSE").asFile.exists()) {
|
||||
def projectName = project.name
|
||||
from(layout.projectDirectory.file("LICENSE")) {
|
||||
rename { "${it}_${projectName}" }
|
||||
}
|
||||
} else if (rootProject.layout.projectDirectory.file("LICENSE").asFile.exists()) {
|
||||
def projectName = rootProject.name
|
||||
from(rootProject.layout.projectDirectory.file("LICENSE")) {
|
||||
rename { "${it}_${projectName}" }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tasks.withType(JavaCompile).configureEach {
|
||||
it.options.encoding = "UTF-8"
|
||||
}
|
||||
|
||||
tasks.withType(Javadoc).configureEach {
|
||||
it.options.encoding = "UTF-8"
|
||||
it.options.addStringOption("Xdoclint:none", "-quiet")
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
plugins {
|
||||
id "idea"
|
||||
}
|
||||
|
||||
idea {
|
||||
module {
|
||||
["run"].each {
|
||||
excludeDirs << layout.projectDirectory.file("$it").asFile
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
plugins {
|
||||
id "net.raphimc.class-token-replacer"
|
||||
}
|
||||
|
||||
sourceSets.configureEach {
|
||||
it.classTokenReplacer {
|
||||
property("\${version}", project.version)
|
||||
property("\${commit_hash}", latestCommitHash().get())
|
||||
}
|
||||
}
|
||||
|
||||
Provider<String> latestCommitHash() {
|
||||
return providers.exec {
|
||||
commandLine = ["git", "rev-parse", "--short", "HEAD"]
|
||||
}.standardOutput.getAsText().map(String::trim)
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
configurations {
|
||||
includeInJar
|
||||
|
||||
implementation.extendsFrom(includeInJar)
|
||||
}
|
||||
|
||||
jar {
|
||||
dependsOn(configurations.includeInJar)
|
||||
from {
|
||||
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
||||
configurations.includeInJar.collect {
|
||||
zipTree(it)
|
||||
}
|
||||
} {
|
||||
exclude("META-INF/*.RSA", "META-INF/*.SF", "META-INF/*.DSA")
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
plugins {
|
||||
id "maven-publish"
|
||||
id "signing"
|
||||
}
|
||||
|
||||
java {
|
||||
withSourcesJar()
|
||||
withJavadocJar()
|
||||
}
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
mavenJava(MavenPublication) {
|
||||
from(components.java)
|
||||
|
||||
groupId = project.maven_group
|
||||
artifactId = project.maven_name
|
||||
version = project.maven_version
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
signing {
|
||||
setRequired(false)
|
||||
sign(publishing.publications.mavenJava)
|
||||
}
|
||||
|
||||
tasks.withType(PublishToMavenRepository).configureEach {
|
||||
it.dependsOn(tasks.withType(Sign))
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
publishing {
|
||||
repositories {
|
||||
maven {
|
||||
name = "Via"
|
||||
url = "https://repo.viaversion.com/"
|
||||
|
||||
credentials(PasswordCredentials)
|
||||
authentication {
|
||||
basic(BasicAuthentication)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
plugins {
|
||||
id "base.publishing-conventions"
|
||||
id "via.viaversion-maven-publishing"
|
||||
}
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
mavenJava {
|
||||
pom {
|
||||
name = "ViaProxy"
|
||||
description = "Standalone proxy which allows players to join EVERY Minecraft server version (Classic, Alpha, Beta, Release, Bedrock)"
|
||||
url = "https://github.com/ViaVersion/ViaProxy"
|
||||
licenses {
|
||||
license {
|
||||
name = "GPL-3.0 License"
|
||||
url = "https://github.com/ViaVersion/ViaProxy/blob/main/LICENSE"
|
||||
}
|
||||
}
|
||||
developers {
|
||||
developer {
|
||||
id = "RK_01"
|
||||
}
|
||||
}
|
||||
scm {
|
||||
connection = "scm:git:git://github.com/ViaVersion/ViaProxy.git"
|
||||
developerConnection = "scm:git:ssh://github.com/ViaVersion/ViaProxy.git"
|
||||
url = "https://github.com/ViaVersion/ViaProxy.git"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
9
ViaProxy/gradle.properties
Normal file
9
ViaProxy/gradle.properties
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
org.gradle.daemon=true
|
||||
org.gradle.parallel=true
|
||||
org.gradle.configuration-cache=true
|
||||
org.gradle.jvmargs=-Xmx2G
|
||||
|
||||
java_version=17
|
||||
maven_group=net.raphimc
|
||||
maven_name=ViaProxy
|
||||
maven_version=3.4.9-SNAPSHOT
|
||||
BIN
ViaProxy/gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
BIN
ViaProxy/gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
Binary file not shown.
8
ViaProxy/gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
8
ViaProxy/gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionSha256Sum=b266d5ff6b90eada6dc3b20cb090e3731302e553a27c5d3e4df1f0d76beaff06
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-9.3.1-bin.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
248
ViaProxy/gradlew
vendored
Executable file
248
ViaProxy/gradlew
vendored
Executable file
|
|
@ -0,0 +1,248 @@
|
|||
#!/bin/sh
|
||||
|
||||
#
|
||||
# Copyright © 2015 the original authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# Gradle start up script for POSIX generated by Gradle.
|
||||
#
|
||||
# Important for running:
|
||||
#
|
||||
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
|
||||
# noncompliant, but you have some other compliant shell such as ksh or
|
||||
# bash, then to run this script, type that shell name before the whole
|
||||
# command line, like:
|
||||
#
|
||||
# ksh Gradle
|
||||
#
|
||||
# Busybox and similar reduced shells will NOT work, because this script
|
||||
# requires all of these POSIX shell features:
|
||||
# * functions;
|
||||
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
|
||||
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
|
||||
# * compound commands having a testable exit status, especially «case»;
|
||||
# * various built-in commands including «command», «set», and «ulimit».
|
||||
#
|
||||
# Important for patching:
|
||||
#
|
||||
# (2) This script targets any POSIX shell, so it avoids extensions provided
|
||||
# by Bash, Ksh, etc; in particular arrays are avoided.
|
||||
#
|
||||
# The "traditional" practice of packing multiple parameters into a
|
||||
# space-separated string is a well documented source of bugs and security
|
||||
# problems, so this is (mostly) avoided, by progressively accumulating
|
||||
# options in "$@", and eventually passing that to Java.
|
||||
#
|
||||
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
|
||||
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
|
||||
# see the in-line comments for details.
|
||||
#
|
||||
# There are tweaks for specific operating systems such as AIX, CygWin,
|
||||
# Darwin, MinGW, and NonStop.
|
||||
#
|
||||
# (3) This script is generated from the Groovy template
|
||||
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# within the Gradle project.
|
||||
#
|
||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
|
||||
# Resolve links: $0 may be a link
|
||||
app_path=$0
|
||||
|
||||
# Need this for daisy-chained symlinks.
|
||||
while
|
||||
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
|
||||
[ -h "$app_path" ]
|
||||
do
|
||||
ls=$( ls -ld "$app_path" )
|
||||
link=${ls#*' -> '}
|
||||
case $link in #(
|
||||
/*) app_path=$link ;; #(
|
||||
*) app_path=$APP_HOME$link ;;
|
||||
esac
|
||||
done
|
||||
|
||||
# This is normally unused
|
||||
# shellcheck disable=SC2034
|
||||
APP_BASE_NAME=${0##*/}
|
||||
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
||||
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD=maximum
|
||||
|
||||
warn () {
|
||||
echo "$*"
|
||||
} >&2
|
||||
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
} >&2
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
nonstop=false
|
||||
case "$( uname )" in #(
|
||||
CYGWIN* ) cygwin=true ;; #(
|
||||
Darwin* ) darwin=true ;; #(
|
||||
MSYS* | MINGW* ) msys=true ;; #(
|
||||
NONSTOP* ) nonstop=true ;;
|
||||
esac
|
||||
|
||||
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD=$JAVA_HOME/jre/sh/java
|
||||
else
|
||||
JAVACMD=$JAVA_HOME/bin/java
|
||||
fi
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD=java
|
||||
if ! command -v java >/dev/null 2>&1
|
||||
then
|
||||
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||
case $MAX_FD in #(
|
||||
max*)
|
||||
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC2039,SC3045
|
||||
MAX_FD=$( ulimit -H -n ) ||
|
||||
warn "Could not query maximum file descriptor limit"
|
||||
esac
|
||||
case $MAX_FD in #(
|
||||
'' | soft) :;; #(
|
||||
*)
|
||||
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC2039,SC3045
|
||||
ulimit -n "$MAX_FD" ||
|
||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||
esac
|
||||
fi
|
||||
|
||||
# Collect all arguments for the java command, stacking in reverse order:
|
||||
# * args from the command line
|
||||
# * the main class name
|
||||
# * -classpath
|
||||
# * -D...appname settings
|
||||
# * --module-path (only if needed)
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
|
||||
|
||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||
if "$cygwin" || "$msys" ; then
|
||||
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
||||
|
||||
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
||||
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
for arg do
|
||||
if
|
||||
case $arg in #(
|
||||
-*) false ;; # don't mess with options #(
|
||||
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
|
||||
[ -e "$t" ] ;; #(
|
||||
*) false ;;
|
||||
esac
|
||||
then
|
||||
arg=$( cygpath --path --ignore --mixed "$arg" )
|
||||
fi
|
||||
# Roll the args list around exactly as many times as the number of
|
||||
# args, so each arg winds up back in the position where it started, but
|
||||
# possibly modified.
|
||||
#
|
||||
# NB: a `for` loop captures its iteration list before it begins, so
|
||||
# changing the positional parameters here affects neither the number of
|
||||
# iterations, nor the values presented in `arg`.
|
||||
shift # remove old arg
|
||||
set -- "$@" "$arg" # push replacement arg
|
||||
done
|
||||
fi
|
||||
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Collect all arguments for the java command:
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||
# and any embedded shellness will be escaped.
|
||||
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
||||
# treated as '${Hostname}' itself on the command line.
|
||||
|
||||
set -- \
|
||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
|
||||
"$@"
|
||||
|
||||
# Stop when "xargs" is not available.
|
||||
if ! command -v xargs >/dev/null 2>&1
|
||||
then
|
||||
die "xargs is not available"
|
||||
fi
|
||||
|
||||
# Use "xargs" to parse quoted args.
|
||||
#
|
||||
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||
#
|
||||
# In Bash we could simply go:
|
||||
#
|
||||
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
|
||||
# set -- "${ARGS[@]}" "$@"
|
||||
#
|
||||
# but POSIX shell has neither arrays nor command substitution, so instead we
|
||||
# post-process each arg (as a line of input to sed) to backslash-escape any
|
||||
# character that might be a shell metacharacter, then use eval to reverse
|
||||
# that process (while maintaining the separation between arguments), and wrap
|
||||
# the whole thing up as a single "set" statement.
|
||||
#
|
||||
# This will of course break if any of these variables contains a newline or
|
||||
# an unmatched quote.
|
||||
#
|
||||
|
||||
eval "set -- $(
|
||||
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
|
||||
xargs -n1 |
|
||||
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
|
||||
tr '\n' ' '
|
||||
)" '"$@"'
|
||||
|
||||
exec "$JAVACMD" "$@"
|
||||
93
ViaProxy/gradlew.bat
vendored
Normal file
93
ViaProxy/gradlew.bat
vendored
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
@rem
|
||||
@rem Copyright 2015 the original author or authors.
|
||||
@rem
|
||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@rem you may not use this file except in compliance with the License.
|
||||
@rem You may obtain a copy of the License at
|
||||
@rem
|
||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||
@rem
|
||||
@rem Unless required by applicable law or agreed to in writing, software
|
||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
@rem SPDX-License-Identifier: Apache-2.0
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%"=="" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%"=="" set DIRNAME=.
|
||||
@rem This is normally unused
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if %ERRORLEVEL% equ 0 goto execute
|
||||
|
||||
echo. 1>&2
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
|
||||
echo. 1>&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||
echo location of your Java installation. 1>&2
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto execute
|
||||
|
||||
echo. 1>&2
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
|
||||
echo. 1>&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||
echo location of your Java installation. 1>&2
|
||||
|
||||
goto fail
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if %ERRORLEVEL% equ 0 goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
set EXIT_CODE=%ERRORLEVEL%
|
||||
if %EXIT_CODE% equ 0 set EXIT_CODE=1
|
||||
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
|
||||
exit /b %EXIT_CODE%
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
||||
12
ViaProxy/settings.gradle
Normal file
12
ViaProxy/settings.gradle
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
pluginManagement {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
gradlePluginPortal()
|
||||
}
|
||||
}
|
||||
|
||||
plugins {
|
||||
id "org.gradle.toolchains.foojay-resolver-convention" version "1.0.0"
|
||||
}
|
||||
|
||||
rootProject.name = "ViaProxy"
|
||||
353
ViaProxy/src/main/java/net/raphimc/viaproxy/ViaProxy.java
Normal file
353
ViaProxy/src/main/java/net/raphimc/viaproxy/ViaProxy.java
Normal file
|
|
@ -0,0 +1,353 @@
|
|||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2026 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.raphimc.viaproxy;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.group.ChannelGroup;
|
||||
import io.netty.channel.group.DefaultChannelGroup;
|
||||
import io.netty.util.ResourceLeakDetector;
|
||||
import io.netty.util.concurrent.GlobalEventExecutor;
|
||||
import io.netty.util.internal.PlatformDependent;
|
||||
import net.lenni0451.classtransform.TransformerManager;
|
||||
import net.lenni0451.classtransform.additionalclassprovider.GuavaClassPathProvider;
|
||||
import net.lenni0451.classtransform.mixinstranslator.MixinsTranslator;
|
||||
import net.lenni0451.classtransform.utils.loader.EnumLoaderPriority;
|
||||
import net.lenni0451.classtransform.utils.loader.InjectionClassLoader;
|
||||
import net.lenni0451.classtransform.utils.tree.IClassProvider;
|
||||
import net.lenni0451.lambdaevents.LambdaManager;
|
||||
import net.lenni0451.lambdaevents.generator.LambdaMetaFactoryGenerator;
|
||||
import net.lenni0451.reflect.Agents;
|
||||
import net.lenni0451.reflect.ClassLoaders;
|
||||
import net.lenni0451.reflect.JavaBypass;
|
||||
import net.lenni0451.reflect.Methods;
|
||||
import net.raphimc.netminecraft.constants.MCPipeline;
|
||||
import net.raphimc.netminecraft.netty.connection.NetServer;
|
||||
import net.raphimc.viaproxy.cli.ConsoleHandler;
|
||||
import net.raphimc.viaproxy.plugins.PluginManager;
|
||||
import net.raphimc.viaproxy.plugins.events.Client2ProxyHandlerCreationEvent;
|
||||
import net.raphimc.viaproxy.plugins.events.ProxyStartEvent;
|
||||
import net.raphimc.viaproxy.plugins.events.ProxyStopEvent;
|
||||
import net.raphimc.viaproxy.plugins.events.ViaProxyLoadedEvent;
|
||||
import net.raphimc.viaproxy.protocoltranslator.ProtocolTranslator;
|
||||
import net.raphimc.viaproxy.protocoltranslator.viaproxy.ViaProxyConfig;
|
||||
import net.raphimc.viaproxy.proxy.client2proxy.Client2ProxyChannelInitializer;
|
||||
import net.raphimc.viaproxy.proxy.client2proxy.Client2ProxyHandler;
|
||||
import net.raphimc.viaproxy.proxy.session.ProxyConnection;
|
||||
import net.raphimc.viaproxy.saves.SaveManager;
|
||||
import net.raphimc.viaproxy.tasks.SystemRequirementsCheck;
|
||||
import net.raphimc.viaproxy.tasks.UpdateCheckTask;
|
||||
import net.raphimc.viaproxy.ui.SplashScreen;
|
||||
import net.raphimc.viaproxy.ui.ViaProxyWindow;
|
||||
import net.raphimc.viaproxy.util.AddressUtil;
|
||||
import net.raphimc.viaproxy.util.ClassLoaderPriorityUtil;
|
||||
import net.raphimc.viaproxy.util.JarUtil;
|
||||
import net.raphimc.viaproxy.util.logging.Logger;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.instrument.Instrumentation;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class ViaProxy {
|
||||
|
||||
public static final String VERSION = "${version}";
|
||||
public static final String IMPL_VERSION = "git-ViaProxy-${version}:${commit_hash}";
|
||||
|
||||
public static final LambdaManager EVENT_MANAGER = LambdaManager.threadSafe(new LambdaMetaFactoryGenerator(JavaBypass.TRUSTED_LOOKUP));
|
||||
private static /*final*/ File CWD;
|
||||
private static /*final*/ PluginManager PLUGIN_MANAGER;
|
||||
private static /*final*/ SaveManager SAVE_MANAGER;
|
||||
private static /*final*/ ViaProxyConfig CONFIG;
|
||||
private static /*final*/ ChannelGroup CLIENT_CHANNELS;
|
||||
|
||||
private static Instrumentation instrumentation;
|
||||
private static NetServer currentProxyServer;
|
||||
private static ViaProxyWindow viaProxyWindow;
|
||||
private static JFrame foregroundWindow;
|
||||
|
||||
public static void agentmain(final String args, final Instrumentation instrumentation) {
|
||||
ViaProxy.instrumentation = instrumentation;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Throwable {
|
||||
final IClassProvider classProvider = new GuavaClassPathProvider();
|
||||
final TransformerManager transformerManager = new TransformerManager(classProvider);
|
||||
transformerManager.addTransformerPreprocessor(new MixinsTranslator());
|
||||
transformerManager.addTransformer("net.raphimc.viaproxy.injection.mixins.**");
|
||||
if (instrumentation != null) {
|
||||
transformerManager.hookInstrumentation(instrumentation);
|
||||
injectedMain("Launcher Agent", args);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
transformerManager.hookInstrumentation(Agents.getInstrumentation());
|
||||
} catch (Throwable t) {
|
||||
final InjectionClassLoader injectionClassLoader = new InjectionClassLoader(transformerManager, ClassLoaders.getSystemClassPath());
|
||||
injectionClassLoader.setPriority(EnumLoaderPriority.PARENT_FIRST);
|
||||
Thread.currentThread().setContextClassLoader(injectionClassLoader);
|
||||
Methods.invoke(null, Methods.getDeclaredMethod(injectionClassLoader.loadClass(ViaProxy.class.getName()), "injectedMain", String.class, String[].class), "Injection ClassLoader", args);
|
||||
return;
|
||||
}
|
||||
injectedMain("Runtime Agent", args);
|
||||
}
|
||||
|
||||
public static void injectedMain(final String injectionMethod, final String[] args) throws InterruptedException, IOException, InvocationTargetException {
|
||||
final boolean useUI = args.length == 0 && !GraphicsEnvironment.isHeadless();
|
||||
final boolean useConfig = args.length == 2 && args[0].equals("config");
|
||||
final boolean useCLI = args.length > 0 && args[0].equals("cli");
|
||||
|
||||
final List<File> potentialCwds = new ArrayList<>();
|
||||
if (System.getenv("VP_RUN_DIR") != null) {
|
||||
potentialCwds.add(new File(System.getenv("VP_RUN_DIR")));
|
||||
}
|
||||
potentialCwds.add(new File(System.getProperty("user.dir")));
|
||||
potentialCwds.add(new File("."));
|
||||
JarUtil.getJarFile().map(File::getParentFile).ifPresent(potentialCwds::add);
|
||||
|
||||
final List<File> failedCwds = new ArrayList<>();
|
||||
for (File potentialCwd : potentialCwds) {
|
||||
if (potentialCwd.isDirectory()) {
|
||||
if (Files.isWritable(potentialCwd.toPath())) {
|
||||
CWD = potentialCwd;
|
||||
break;
|
||||
}
|
||||
}
|
||||
failedCwds.add(potentialCwd);
|
||||
}
|
||||
if (CWD == null) { // Backup strategy for weird permission setups: Attempt to write a dummy file to check if the directory is writable
|
||||
for (File potentialCwd : potentialCwds) {
|
||||
if (potentialCwd.isDirectory()) {
|
||||
try {
|
||||
final Path testFile = new File(potentialCwd, "viaproxy_writable_test.txt").toPath();
|
||||
Files.deleteIfExists(testFile);
|
||||
Files.writeString(testFile, "This is just a test. This file can be deleted.");
|
||||
Files.deleteIfExists(testFile);
|
||||
CWD = potentialCwd;
|
||||
break;
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (CWD != null) {
|
||||
System.setProperty("user.dir", CWD.getAbsolutePath());
|
||||
} else if (useUI) {
|
||||
JOptionPane.showMessageDialog(null, "Could not find a suitable directory to use as working directory. Make sure that the current folder is writeable.", "ViaProxy", JOptionPane.ERROR_MESSAGE);
|
||||
System.exit(1);
|
||||
} else {
|
||||
System.err.println("Could not find a suitable directory to use as working directory. Make sure that the current folder is writeable.");
|
||||
System.err.println("Attempted to use the following directories:");
|
||||
for (File failedCwd : failedCwds) {
|
||||
System.err.println("\t- " + failedCwd.getAbsolutePath());
|
||||
}
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
Logger.setup();
|
||||
if (!useUI && !useConfig && !useCLI) {
|
||||
final String fileName = JarUtil.getJarFile().map(File::getName).orElse("ViaProxy.jar");
|
||||
Logger.LOGGER.info("Usage: java -jar " + fileName + " | Starts ViaProxy in graphical mode if available");
|
||||
Logger.LOGGER.info("Usage: java -jar " + fileName + " config <config file> | Starts ViaProxy with the specified config file");
|
||||
Logger.LOGGER.info("Usage: java -jar " + fileName + " cli --help | Starts ViaProxy in CLI mode");
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
Logger.LOGGER.info("Initializing ViaProxy {} v{} ({}) (Injected using {})...", useUI ? "GUI" : "CLI", VERSION, IMPL_VERSION, injectionMethod);
|
||||
Logger.LOGGER.info("Using java version: " + System.getProperty("java.vm.name") + " " + System.getProperty("java.version") + " (" + System.getProperty("java.vendor") + ") on " + System.getProperty("os.name"));
|
||||
Logger.LOGGER.info("Available memory (bytes): " + Runtime.getRuntime().maxMemory());
|
||||
Logger.LOGGER.info("Working directory: " + CWD.getAbsolutePath());
|
||||
if (!failedCwds.isEmpty()) {
|
||||
Logger.LOGGER.warn("Failed to use the following directories as working directory:");
|
||||
for (File failedCwd : failedCwds) {
|
||||
Logger.LOGGER.warn("\t- " + failedCwd.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
if (System.getProperty("ignoreSystemRequirements") == null) {
|
||||
SystemRequirementsCheck.run(useUI);
|
||||
}
|
||||
|
||||
final SplashScreen splashScreen;
|
||||
final Consumer<String> progressConsumer;
|
||||
if (useUI) {
|
||||
final float progressStep = 1F / 7F;
|
||||
foregroundWindow = splashScreen = new SplashScreen();
|
||||
progressConsumer = (text) -> {
|
||||
splashScreen.setProgress(splashScreen.getProgress() + progressStep);
|
||||
splashScreen.setText(text);
|
||||
};
|
||||
Thread.setDefaultUncaughtExceptionHandler((t, e) -> {
|
||||
ViaProxyWindow.showException(e);
|
||||
System.exit(1);
|
||||
});
|
||||
} else {
|
||||
splashScreen = null;
|
||||
progressConsumer = text -> {
|
||||
};
|
||||
}
|
||||
progressConsumer.accept("Initializing ViaProxy");
|
||||
|
||||
ConsoleHandler.hookConsole();
|
||||
ViaProxy.loadNetty();
|
||||
ClassLoaderPriorityUtil.loadOverridingJars();
|
||||
|
||||
progressConsumer.accept("Loading Plugins");
|
||||
PLUGIN_MANAGER = new PluginManager();
|
||||
progressConsumer.accept("Loading Protocol Translators");
|
||||
ProtocolTranslator.init();
|
||||
progressConsumer.accept("Loading Saves");
|
||||
SAVE_MANAGER = new SaveManager();
|
||||
progressConsumer.accept("Loading Config");
|
||||
final File viaProxyConfigFile;
|
||||
if (useConfig) {
|
||||
final File absoluteConfigFile = new File(args[1]);
|
||||
if (absoluteConfigFile.isAbsolute()) {
|
||||
viaProxyConfigFile = absoluteConfigFile;
|
||||
} else {
|
||||
viaProxyConfigFile = new File(ViaProxy.getCwd(), args[1]);
|
||||
}
|
||||
} else {
|
||||
viaProxyConfigFile = new File(ViaProxy.getCwd(), "viaproxy.yml");
|
||||
}
|
||||
final boolean firstStart = !viaProxyConfigFile.exists();
|
||||
CONFIG = ViaProxyConfig.create(viaProxyConfigFile);
|
||||
|
||||
if (useUI) {
|
||||
progressConsumer.accept("Loading GUI");
|
||||
SwingUtilities.invokeAndWait(() -> {
|
||||
try {
|
||||
foregroundWindow = viaProxyWindow = new ViaProxyWindow();
|
||||
progressConsumer.accept("Done");
|
||||
splashScreen.dispose();
|
||||
} catch (Throwable e) {
|
||||
Logger.LOGGER.fatal("Failed to initialize UI", e);
|
||||
System.exit(1);
|
||||
}
|
||||
});
|
||||
if (System.getProperty("skipUpdateCheck") == null) {
|
||||
CompletableFuture.runAsync(new UpdateCheckTask(true));
|
||||
}
|
||||
EVENT_MANAGER.call(new ViaProxyLoadedEvent());
|
||||
Logger.LOGGER.info("ViaProxy started successfully!");
|
||||
} else {
|
||||
if (useCLI) {
|
||||
final String[] cliArgs = new String[args.length - 1];
|
||||
System.arraycopy(args, 1, cliArgs, 0, cliArgs.length);
|
||||
try {
|
||||
CONFIG.loadFromArguments(cliArgs);
|
||||
} catch (Throwable e) {
|
||||
throw new RuntimeException("Failed to load CLI arguments", e);
|
||||
}
|
||||
} else if (firstStart) {
|
||||
Logger.LOGGER.info("This is the first start of ViaProxy. Please configure the settings in the " + viaProxyConfigFile.getName() + " file and restart ViaProxy.");
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
if (System.getProperty("skipUpdateCheck") == null) {
|
||||
CompletableFuture.runAsync(new UpdateCheckTask(false));
|
||||
}
|
||||
EVENT_MANAGER.call(new ViaProxyLoadedEvent());
|
||||
Logger.LOGGER.info("ViaProxy started successfully!");
|
||||
ViaProxy.startProxy();
|
||||
|
||||
Thread.sleep(Integer.MAX_VALUE);
|
||||
}
|
||||
}
|
||||
|
||||
public static void startProxy() {
|
||||
if (currentProxyServer != null) {
|
||||
throw new IllegalStateException("Proxy is already running");
|
||||
}
|
||||
try {
|
||||
Logger.LOGGER.info("Starting proxy server");
|
||||
currentProxyServer = new NetServer(new Client2ProxyChannelInitializer(() -> EVENT_MANAGER.call(new Client2ProxyHandlerCreationEvent(new Client2ProxyHandler(), false)).getHandler()));
|
||||
EVENT_MANAGER.call(new ProxyStartEvent());
|
||||
Logger.LOGGER.info("Binding proxy server to " + AddressUtil.toString(CONFIG.getBindAddress()));
|
||||
currentProxyServer.bind(CONFIG.getBindAddress(), false);
|
||||
} catch (Throwable e) {
|
||||
currentProxyServer = null;
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public static void stopProxy() {
|
||||
if (currentProxyServer != null) {
|
||||
Logger.LOGGER.info("Stopping proxy server");
|
||||
EVENT_MANAGER.call(new ProxyStopEvent());
|
||||
|
||||
currentProxyServer.getChannel().close();
|
||||
currentProxyServer = null;
|
||||
|
||||
for (Channel channel : CLIENT_CHANNELS) {
|
||||
try {
|
||||
ProxyConnection.fromChannel(channel).kickClient("§cViaProxy has been stopped");
|
||||
} catch (Throwable ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void loadNetty() {
|
||||
ResourceLeakDetector.setLevel(ResourceLeakDetector.Level.DISABLED);
|
||||
if (System.getProperty("io.netty.allocator.type") == null) {
|
||||
System.setProperty("io.netty.allocator.type", PlatformDependent.isAndroid() ? "unpooled" : "pooled");
|
||||
}
|
||||
MCPipeline.useOptimizedPipeline();
|
||||
CLIENT_CHANNELS = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);
|
||||
}
|
||||
|
||||
public static File getCwd() {
|
||||
return CWD;
|
||||
}
|
||||
|
||||
public static PluginManager getPluginManager() {
|
||||
return PLUGIN_MANAGER;
|
||||
}
|
||||
|
||||
public static SaveManager getSaveManager() {
|
||||
return SAVE_MANAGER;
|
||||
}
|
||||
|
||||
public static ViaProxyConfig getConfig() {
|
||||
return CONFIG;
|
||||
}
|
||||
|
||||
public static ChannelGroup getConnectedClients() {
|
||||
return CLIENT_CHANNELS;
|
||||
}
|
||||
|
||||
public static NetServer getCurrentProxyServer() {
|
||||
return currentProxyServer;
|
||||
}
|
||||
|
||||
public static ViaProxyWindow getViaProxyWindow() {
|
||||
return viaProxyWindow;
|
||||
}
|
||||
|
||||
public static JFrame getForegroundWindow() {
|
||||
return foregroundWindow;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2026 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.raphimc.viaproxy.cli;
|
||||
|
||||
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
|
||||
import joptsimple.BuiltinHelpFormatter;
|
||||
import joptsimple.OptionDescriptor;
|
||||
import joptsimple.internal.Classes;
|
||||
import joptsimple.internal.Strings;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class BetterHelpFormatter extends BuiltinHelpFormatter {
|
||||
|
||||
public BetterHelpFormatter() {
|
||||
super(120, 2);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String extractTypeIndicator(OptionDescriptor descriptor) {
|
||||
String indicator = descriptor.argumentTypeIndicator();
|
||||
if (indicator != null) {
|
||||
indicator = indicator.substring(indicator.indexOf('$') + 1);
|
||||
if (indicator.startsWith("[")) {
|
||||
return indicator.substring(1, indicator.length() - 1);
|
||||
}
|
||||
}
|
||||
return !Strings.isNullOrEmpty(indicator) && !String.class.getName().equals(indicator) ? Classes.shortNameOf(indicator) : "String";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String createDefaultValuesDisplay(List<?> defaultValues) {
|
||||
if (defaultValues.size() == 1) {
|
||||
Object value = defaultValues.get(0);
|
||||
if (value instanceof ProtocolVersion version) {
|
||||
return version.getName();
|
||||
} else if (value instanceof String) {
|
||||
return "\"" + value + "\"";
|
||||
}
|
||||
|
||||
return value.toString();
|
||||
}
|
||||
|
||||
return defaultValues.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,104 @@
|
|||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2026 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.raphimc.viaproxy.cli;
|
||||
|
||||
public class ConsoleFormatter {
|
||||
|
||||
private static final String PREFIX = "\033[";
|
||||
private static final String SUFFIX = "m";
|
||||
|
||||
public static String convert(final String s) {
|
||||
StringBuilder out = new StringBuilder();
|
||||
char[] chars = s.toCharArray();
|
||||
for (int i = 0; i < chars.length; i++) {
|
||||
char c = chars[i];
|
||||
char next = i + 1 < chars.length ? chars[i + 1] : '\0';
|
||||
if (c == '§') {
|
||||
if (next != '\0') {
|
||||
if (isColor(next)) out.append(convertToAnsi('r'));
|
||||
out.append(convertToAnsi(next));
|
||||
i++;
|
||||
}
|
||||
} else {
|
||||
out.append(c);
|
||||
}
|
||||
}
|
||||
return out + convertToAnsi('r');
|
||||
}
|
||||
|
||||
//The ANSI codes are an approximation. True color is used to get the exact color.
|
||||
private static String convertToAnsi(final char color) {
|
||||
switch (Character.toLowerCase(color)) {
|
||||
case '0': //Black
|
||||
return PREFIX + getColor("30", 0x00_00_00) + SUFFIX;
|
||||
case '1': //Dark Blue
|
||||
return PREFIX + getColor("34", 0x00_00_AA) + SUFFIX;
|
||||
case '2': //Dark Green
|
||||
return PREFIX + getColor("32", 0x00_AA_00) + SUFFIX;
|
||||
case '3': //Dark Aqua
|
||||
return PREFIX + getColor("36", 0x00_AA_AA) + SUFFIX;
|
||||
case '4': //Dark Red
|
||||
return PREFIX + getColor("31", 0xAA_00_00) + SUFFIX;
|
||||
case '5': //Dark Purple
|
||||
return PREFIX + getColor("35", 0xAA_00_AA) + SUFFIX;
|
||||
case '6': //Gold
|
||||
return PREFIX + getColor("33", 0xFF_AA_00) + SUFFIX;
|
||||
case '7': //Gray
|
||||
return PREFIX + getColor("37", 0xAA_AA_AA) + SUFFIX;
|
||||
case '8': //Dark Gray
|
||||
return PREFIX + getColor("90", 0x55_55_55) + SUFFIX;
|
||||
case '9': //Blue
|
||||
return PREFIX + getColor("94", 0x55_55_FF) + SUFFIX;
|
||||
case 'a': //Green
|
||||
return PREFIX + getColor("92", 0x55_FF_55) + SUFFIX;
|
||||
case 'b': //Aqua
|
||||
return PREFIX + getColor("96", 0x55_FF_FF) + SUFFIX;
|
||||
case 'c': //Red
|
||||
return PREFIX + getColor("91", 0xFF_55_55) + SUFFIX;
|
||||
case 'd': //Light Purple
|
||||
return PREFIX + getColor("95", 0xFF_55_FF) + SUFFIX;
|
||||
case 'e': //Yellow
|
||||
return PREFIX + getColor("93", 0xFF_FF_55) + SUFFIX;
|
||||
case 'f': //White
|
||||
return PREFIX + getColor("97", 0xFF_FF_FF) + SUFFIX;
|
||||
case 'k': //Obfuscated
|
||||
return ""; //Not supported in terminal
|
||||
case 'l': //Bold
|
||||
return PREFIX + "1" + SUFFIX;
|
||||
case 'm': //Strikethrough
|
||||
return PREFIX + "9" + SUFFIX;
|
||||
case 'n': //Underline
|
||||
return PREFIX + "4" + SUFFIX;
|
||||
case 'o': //Italic
|
||||
return PREFIX + "3" + SUFFIX;
|
||||
case 'r': //Reset
|
||||
default:
|
||||
return PREFIX + 0 + SUFFIX;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isColor(char color) {
|
||||
color = Character.toLowerCase(color);
|
||||
return color >= '0' && color <= '9' || color >= 'a' && color <= 'f';
|
||||
}
|
||||
|
||||
private static String getColor(final String ansi, final int rgb) {
|
||||
return String.format("38;2;%d;%d;%d", (rgb >> 16) & 255, (rgb >> 8) & 255, rgb & 255);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2026 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.raphimc.viaproxy.cli;
|
||||
|
||||
import net.raphimc.viaproxy.cli.command.CommandManager;
|
||||
import net.raphimc.viaproxy.util.logging.Logger;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class ConsoleHandler {
|
||||
|
||||
public static void hookConsole() {
|
||||
try { // Best way I could find to check if a console is attached to System.in
|
||||
System.in.available();
|
||||
} catch (IOException e) {
|
||||
Logger.LOGGER.info("Console input is not available. CLI commands are disabled.");
|
||||
return;
|
||||
}
|
||||
|
||||
new Thread(ConsoleHandler::listen, "Console-Handler").start();
|
||||
}
|
||||
|
||||
private static void listen() {
|
||||
final CommandManager commandManager = new CommandManager();
|
||||
final Scanner scanner = new Scanner(System.in);
|
||||
try {
|
||||
while (scanner.hasNextLine()) {
|
||||
final String line = scanner.nextLine();
|
||||
try {
|
||||
commandManager.execute(line);
|
||||
} catch (Throwable e) {
|
||||
Logger.LOGGER.error("Error while handling console input", e);
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
Logger.LOGGER.error("Error while reading console input", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2026 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.raphimc.viaproxy.cli;
|
||||
|
||||
public class HelpRequestedException extends RuntimeException {
|
||||
}
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2026 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.raphimc.viaproxy.cli.command;
|
||||
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import net.lenni0451.commons.brigadier.CommandBuilder;
|
||||
import net.raphimc.viaproxy.cli.command.executor.CommandExecutor;
|
||||
|
||||
public abstract class Command implements CommandBuilder<CommandExecutor> {
|
||||
|
||||
private final String[] names;
|
||||
private final String description;
|
||||
private final String help;
|
||||
|
||||
public Command(final String name, final String description, final String help, final String... aliases) {
|
||||
this.names = new String[aliases.length + 1];
|
||||
this.names[0] = name;
|
||||
System.arraycopy(aliases, 0, this.names, 1, aliases.length);
|
||||
this.description = description;
|
||||
this.help = help;
|
||||
}
|
||||
|
||||
public abstract void register(final LiteralArgumentBuilder<CommandExecutor> builder);
|
||||
|
||||
public String getName() {
|
||||
return this.names[0];
|
||||
}
|
||||
|
||||
public String[] getNames() {
|
||||
return this.names;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return this.description;
|
||||
}
|
||||
|
||||
public String getHelp() {
|
||||
return this.help;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,108 @@
|
|||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2026 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.raphimc.viaproxy.cli.command;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import net.lenni0451.commons.brigadier.CommandBuilder;
|
||||
import net.lenni0451.commons.brigadier.HelpAppender;
|
||||
import net.lenni0451.reflect.stream.RStream;
|
||||
import net.raphimc.viaproxy.ViaProxy;
|
||||
import net.raphimc.viaproxy.cli.command.executor.CommandExecutor;
|
||||
import net.raphimc.viaproxy.cli.command.executor.ConsoleCommandExecutor;
|
||||
import net.raphimc.viaproxy.cli.command.impl.*;
|
||||
import net.raphimc.viaproxy.plugins.events.ConsoleCommandEvent;
|
||||
import net.raphimc.viaproxy.util.logging.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class CommandManager implements CommandBuilder<CommandExecutor> {
|
||||
|
||||
private final CommandDispatcher<CommandExecutor> dispatcher = HelpAppender.newAutoHelpAppendingCommandDispatcher((sender, name, usages) -> {
|
||||
sender.sendMessage("Incomplete command. Possible usages:");
|
||||
for (String usage : usages) {
|
||||
sender.sendMessage(" - " + usage);
|
||||
}
|
||||
});
|
||||
private final List<Command> commands = new ArrayList<>();
|
||||
|
||||
// Core commands
|
||||
private final HelpCommand HelpCommand = new HelpCommand(this);
|
||||
private final StopCommand StopCommand = new StopCommand();
|
||||
private final ViaVersionCommand ViaVersionCommand = new ViaVersionCommand();
|
||||
private final UploadLogCommand UploadLogCommand = new UploadLogCommand();
|
||||
private final AccountCommand AccountCommand = new AccountCommand();
|
||||
|
||||
// Debugging commands
|
||||
private final GcCommand GcCommand = new GcCommand();
|
||||
private final ThreadDumpCommand ThreadDumpCommand = new ThreadDumpCommand();
|
||||
|
||||
public CommandManager() {
|
||||
RStream
|
||||
.of(this)
|
||||
.fields()
|
||||
.filter(field -> Command.class.isAssignableFrom(field.type()))
|
||||
.forEach(field -> {
|
||||
final Command command = field.get();
|
||||
try {
|
||||
for (String name : command.getNames()) {
|
||||
final LiteralArgumentBuilder<CommandExecutor> builder = literal(name);
|
||||
command.register(builder);
|
||||
this.dispatcher.register(builder);
|
||||
}
|
||||
this.commands.add(command);
|
||||
} catch (Throwable e) {
|
||||
Logger.LOGGER.error("Failed to register command " + command.getNames()[0], e);
|
||||
}
|
||||
});
|
||||
|
||||
this.dispatcher.findAmbiguities((parent, child, sibling, inputs) -> Logger.LOGGER.warn("Ambiguity between arguments {} and {} with inputs: {}", this.dispatcher.getPath(child), this.dispatcher.getPath(sibling), inputs));
|
||||
}
|
||||
|
||||
public void execute(final String message) {
|
||||
try {
|
||||
this.dispatcher.execute(message, ConsoleCommandExecutor.INSTANCE);
|
||||
} catch (CommandSyntaxException e) {
|
||||
if (e.getMessage().startsWith("Unknown command at position 0")) { // Compat for the old command API
|
||||
final String[] parts = message.split(" ");
|
||||
if (parts.length != 0) {
|
||||
final String command = parts[0];
|
||||
final String[] args = Arrays.copyOfRange(parts, 1, parts.length);
|
||||
if (ViaProxy.EVENT_MANAGER.call(new ConsoleCommandEvent(command, args)).isCancelled()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
Logger.LOGGER.error(e.getMessage().replace("Unknown command", "Unknown or incomplete command"));
|
||||
Logger.LOGGER.error("Type 'help' for help and a list of available commands.");
|
||||
} else if (e.getMessage().startsWith("Unknown command at position")) {
|
||||
Logger.LOGGER.error(e.getMessage().replace("Unknown command", "Unknown or incomplete command"));
|
||||
Logger.LOGGER.error("Type 'help' for help and a list of available commands.");
|
||||
} else {
|
||||
Logger.LOGGER.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<Command> getCommands() {
|
||||
return this.commands;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2026 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.raphimc.viaproxy.cli.command.executor;
|
||||
|
||||
public interface CommandExecutor {
|
||||
|
||||
void sendMessage(final String message);
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2026 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.raphimc.viaproxy.cli.command.executor;
|
||||
|
||||
import net.raphimc.viaproxy.util.logging.Logger;
|
||||
|
||||
public class ConsoleCommandExecutor implements CommandExecutor {
|
||||
|
||||
public static final ConsoleCommandExecutor INSTANCE = new ConsoleCommandExecutor();
|
||||
|
||||
private ConsoleCommandExecutor() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(final String message) {
|
||||
Logger.LOGGER.info(message);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,141 @@
|
|||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2026 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.raphimc.viaproxy.cli.command.impl;
|
||||
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import net.raphimc.minecraftauth.MinecraftAuth;
|
||||
import net.raphimc.minecraftauth.bedrock.BedrockAuthManager;
|
||||
import net.raphimc.minecraftauth.java.JavaAuthManager;
|
||||
import net.raphimc.minecraftauth.msa.model.MsaDeviceCode;
|
||||
import net.raphimc.minecraftauth.msa.service.impl.DeviceCodeMsaAuthService;
|
||||
import net.raphimc.viabedrock.protocol.data.ProtocolConstants;
|
||||
import net.raphimc.viaproxy.ViaProxy;
|
||||
import net.raphimc.viaproxy.cli.command.Command;
|
||||
import net.raphimc.viaproxy.cli.command.executor.CommandExecutor;
|
||||
import net.raphimc.viaproxy.saves.impl.accounts.Account;
|
||||
import net.raphimc.viaproxy.saves.impl.accounts.BedrockAccount;
|
||||
import net.raphimc.viaproxy.saves.impl.accounts.MicrosoftAccount;
|
||||
import net.raphimc.viaproxy.util.TFunction;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static com.mojang.brigadier.arguments.IntegerArgumentType.getInteger;
|
||||
import static com.mojang.brigadier.arguments.IntegerArgumentType.integer;
|
||||
import static com.mojang.brigadier.arguments.StringArgumentType.getString;
|
||||
import static com.mojang.brigadier.arguments.StringArgumentType.string;
|
||||
|
||||
public class AccountCommand extends Command {
|
||||
|
||||
public AccountCommand() {
|
||||
super("account", "Manage the account list and the currently selected account", "account list/select <index>/deselect/add (offline <name>/microsoft/bedrock)/remove <index>");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(LiteralArgumentBuilder<CommandExecutor> builder) {
|
||||
builder.then(literal("list").executes(ctx -> {
|
||||
List<Account> accounts = ViaProxy.getSaveManager().accountsSave.getAccounts();
|
||||
if (accounts.isEmpty()) {
|
||||
ctx.getSource().sendMessage("No accounts added yet.");
|
||||
} else {
|
||||
for (int i = 0; i < accounts.size(); i++) {
|
||||
boolean isSelected = ViaProxy.getConfig().getAccount() == accounts.get(i);
|
||||
ctx.getSource().sendMessage("[" + i + "] " + accounts.get(i).getDisplayString() + (isSelected ? " <--" : ""));
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}));
|
||||
builder.then(literal("deselect").executes(ctx -> {
|
||||
ViaProxy.getConfig().setAccount(null);
|
||||
ctx.getSource().sendMessage("Deselected current account.");
|
||||
return 1;
|
||||
}));
|
||||
builder.then(literal("select").then(argument("index", integer(0)).executes(ctx -> {
|
||||
List<Account> accounts = ViaProxy.getSaveManager().accountsSave.getAccounts();
|
||||
if (accounts.isEmpty()) {
|
||||
ctx.getSource().sendMessage("No accounts to select from.");
|
||||
return 0;
|
||||
}
|
||||
int index = getInteger(ctx, "index");
|
||||
if (index < 0 || index >= accounts.size()) {
|
||||
ctx.getSource().sendMessage("Invalid account index (run 'account list' to see a list of all accounts).");
|
||||
return 0;
|
||||
}
|
||||
Account account = ViaProxy.getSaveManager().accountsSave.getAccounts().get(index);
|
||||
ViaProxy.getConfig().setAccount(account);
|
||||
ctx.getSource().sendMessage("Selected account " + index + ": " + account.getDisplayString() + ".");
|
||||
return 1;
|
||||
})));
|
||||
builder.then(literal("add")
|
||||
.then(literal("offline").then(argument("name", string()).executes(ctx -> {
|
||||
String name = getString(ctx, "name");
|
||||
ViaProxy.getSaveManager().accountsSave.addAccount(name);
|
||||
ViaProxy.getSaveManager().save();
|
||||
ctx.getSource().sendMessage("Added offline account '" + name + "'.");
|
||||
return 1;
|
||||
})))
|
||||
.then(literal("microsoft").executes(ctx -> {
|
||||
return this.handleLogin(ctx.getSource(), msaDeviceCodeConsumer -> new MicrosoftAccount(JavaAuthManager.create(MinecraftAuth.createHttpClient()).login(DeviceCodeMsaAuthService::new, msaDeviceCodeConsumer)));
|
||||
}))
|
||||
.then(literal("bedrock").executes(ctx -> {
|
||||
return this.handleLogin(ctx.getSource(), msaDeviceCodeConsumer -> new BedrockAccount(BedrockAuthManager.create(MinecraftAuth.createHttpClient(), ProtocolConstants.BEDROCK_VERSION_NAME).login(DeviceCodeMsaAuthService::new, msaDeviceCodeConsumer)));
|
||||
}))
|
||||
);
|
||||
builder.then(literal("remove").then(argument("index", integer(0)).executes(ctx -> {
|
||||
List<Account> accounts = ViaProxy.getSaveManager().accountsSave.getAccounts();
|
||||
if (accounts.isEmpty()) {
|
||||
ctx.getSource().sendMessage("No accounts to remove.");
|
||||
return 0;
|
||||
}
|
||||
int index = getInteger(ctx, "index");
|
||||
if (index < 0 || index >= accounts.size()) {
|
||||
ctx.getSource().sendMessage("Invalid account index (run 'account list' to see a list of all accounts).");
|
||||
return 0;
|
||||
}
|
||||
Account account = ViaProxy.getSaveManager().accountsSave.getAccounts().get(index);
|
||||
ViaProxy.getSaveManager().accountsSave.removeAccount(account);
|
||||
ViaProxy.getSaveManager().save();
|
||||
if (ViaProxy.getConfig().getAccount() == account) {
|
||||
ViaProxy.getConfig().setAccount(null);
|
||||
}
|
||||
ctx.getSource().sendMessage("Removed account " + index + ": " + account.getDisplayString() + ".");
|
||||
return 1;
|
||||
})));
|
||||
}
|
||||
|
||||
private int handleLogin(final CommandExecutor source, final TFunction<Consumer<MsaDeviceCode>, Account> requestHandler) {
|
||||
try {
|
||||
Account account = requestHandler.apply(code -> {
|
||||
source.sendMessage("Please open your browser and visit " + code.getDirectVerificationUri() + " and login with your Microsoft account.");
|
||||
source.sendMessage("If the code is not inserted automatically, please enter the code: " + code.getUserCode() + ".");
|
||||
});
|
||||
ViaProxy.getSaveManager().accountsSave.addAccount(account);
|
||||
ViaProxy.getSaveManager().save();
|
||||
return 1;
|
||||
} catch (InterruptedException ignored) {
|
||||
} catch (TimeoutException e) {
|
||||
source.sendMessage("The authentication process timed out.");
|
||||
} catch (Throwable t) {
|
||||
source.sendMessage("An error occurred while trying to authenticate: " + t.getMessage());
|
||||
t.printStackTrace();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2026 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.raphimc.viaproxy.cli.command.impl;
|
||||
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import net.raphimc.viaproxy.cli.command.Command;
|
||||
import net.raphimc.viaproxy.cli.command.executor.CommandExecutor;
|
||||
|
||||
public class GcCommand extends Command {
|
||||
|
||||
public GcCommand() {
|
||||
super("gc", "Perform JVM garbage collection", "gc");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(final LiteralArgumentBuilder<CommandExecutor> builder) {
|
||||
builder.executes(context -> {
|
||||
System.gc();
|
||||
context.getSource().sendMessage("Performed garbage collection.");
|
||||
return 1;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2026 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.raphimc.viaproxy.cli.command.impl;
|
||||
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import net.raphimc.viaproxy.cli.command.Command;
|
||||
import net.raphimc.viaproxy.cli.command.CommandManager;
|
||||
import net.raphimc.viaproxy.cli.command.executor.CommandExecutor;
|
||||
|
||||
public class HelpCommand extends Command {
|
||||
|
||||
private final CommandManager commandManager;
|
||||
|
||||
public HelpCommand(final CommandManager commandManager) {
|
||||
super("help", "Print a list of available commands and their arguments", "help");
|
||||
this.commandManager = commandManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(final LiteralArgumentBuilder<CommandExecutor> builder) {
|
||||
builder
|
||||
.executes(context -> {
|
||||
final CommandExecutor executor = context.getSource();
|
||||
for (Command command : this.commandManager.getCommands()) {
|
||||
executor.sendMessage(command.getName() + " (" + command.getDescription() + "): " + command.getHelp());
|
||||
}
|
||||
return 1;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2026 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.raphimc.viaproxy.cli.command.impl;
|
||||
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import net.raphimc.viaproxy.cli.command.Command;
|
||||
import net.raphimc.viaproxy.cli.command.executor.CommandExecutor;
|
||||
|
||||
public class StopCommand extends Command {
|
||||
|
||||
public StopCommand() {
|
||||
super("stop", "Stop ViaProxy", "stop", "exit", "end");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(final LiteralArgumentBuilder<CommandExecutor> builder) {
|
||||
builder.executes(context -> {
|
||||
context.getSource().sendMessage("Stopping ViaProxy...");
|
||||
System.exit(0);
|
||||
return 1;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2026 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.raphimc.viaproxy.cli.command.impl;
|
||||
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import net.raphimc.viaproxy.cli.command.Command;
|
||||
import net.raphimc.viaproxy.cli.command.executor.CommandExecutor;
|
||||
|
||||
public class ThreadDumpCommand extends Command {
|
||||
|
||||
public ThreadDumpCommand() {
|
||||
super("threaddump", "Print the stacktrace of the currently running threads", "threaddump");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(final LiteralArgumentBuilder<CommandExecutor> builder) {
|
||||
builder.executes(context -> {
|
||||
StringBuilder dump = new StringBuilder();
|
||||
Thread.getAllStackTraces().forEach((thread, stackTrace) -> {
|
||||
dump.append(thread.getName()).append(":\n");
|
||||
for (StackTraceElement element : stackTrace) {
|
||||
dump.append("\tat ").append(element).append("\n");
|
||||
}
|
||||
});
|
||||
context.getSource().sendMessage(dump.toString());
|
||||
return 1;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2026 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.raphimc.viaproxy.cli.command.impl;
|
||||
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import gs.mclo.api.MclogsClient;
|
||||
import gs.mclo.api.response.UploadLogResponse;
|
||||
import net.raphimc.viaproxy.ViaProxy;
|
||||
import net.raphimc.viaproxy.cli.command.Command;
|
||||
import net.raphimc.viaproxy.cli.command.executor.CommandExecutor;
|
||||
import net.raphimc.viaproxy.util.logging.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.core.appender.RollingRandomAccessFileAppender;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
public class UploadLogCommand extends Command {
|
||||
|
||||
public UploadLogCommand() {
|
||||
super("uploadlog", "Upload the ViaProxy log", "uploadlog");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(final LiteralArgumentBuilder<CommandExecutor> builder) {
|
||||
builder.executes(context -> {
|
||||
final org.apache.logging.log4j.core.Logger logger = (org.apache.logging.log4j.core.Logger) LogManager.getRootLogger();
|
||||
final RollingRandomAccessFileAppender fileAppender = (RollingRandomAccessFileAppender) logger.getAppenders().get("LatestFile");
|
||||
fileAppender.getManager().flush();
|
||||
final File logFile = new File(fileAppender.getFileName());
|
||||
|
||||
try {
|
||||
final MclogsClient mclogsClient = new MclogsClient("ViaProxy", ViaProxy.VERSION);
|
||||
final UploadLogResponse apiResponse = mclogsClient.uploadLog(logFile.toPath()).get();
|
||||
context.getSource().sendMessage("Uploaded log file to " + apiResponse.getUrl());
|
||||
} catch (ExecutionException e) {
|
||||
if (e.getCause() instanceof FileNotFoundException) {
|
||||
context.getSource().sendMessage("The log file could not be found");
|
||||
} else {
|
||||
Logger.LOGGER.error("Failed to upload log file", e.getCause());
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
Logger.LOGGER.error("Failed to upload log file", e);
|
||||
}
|
||||
return 1;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2026 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.raphimc.viaproxy.cli.command.impl;
|
||||
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import net.raphimc.viaproxy.cli.command.Command;
|
||||
import net.raphimc.viaproxy.cli.command.executor.CommandExecutor;
|
||||
import net.raphimc.viaproxy.protocoltranslator.viaproxy.ConsoleCommandSender;
|
||||
|
||||
public class ViaVersionCommand extends Command {
|
||||
|
||||
public ViaVersionCommand() {
|
||||
super("viaversion", "Execute a ViaVersion command", "viaversion <args>", "via", "vv");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(final LiteralArgumentBuilder<CommandExecutor> builder) {
|
||||
builder.then(argument("args", StringArgumentType.greedyString()).executes(context -> {
|
||||
Via.getManager().getCommandHandler().onCommand(new ConsoleCommandSender(), StringArgumentType.getString(context, "args").split(" "));
|
||||
return 1;
|
||||
}));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,172 @@
|
|||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2026 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.raphimc.viaproxy.injection;
|
||||
|
||||
import com.viaversion.nbt.tag.CompoundTag;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
||||
import com.viaversion.viaversion.api.type.Types;
|
||||
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_17;
|
||||
import net.raphimc.vialegacy.api.LegacyProtocolVersion;
|
||||
import net.raphimc.vialegacy.protocol.classic.c0_28_30toa1_0_15.model.ClassicLevel;
|
||||
import net.raphimc.vialegacy.protocol.classic.c0_28_30toa1_0_15.provider.ClassicWorldHeightProvider;
|
||||
import net.raphimc.vialegacy.protocol.classic.c0_28_30toa1_0_15.storage.ClassicLevelStorage;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.BitSet;
|
||||
import java.util.List;
|
||||
|
||||
public class ClassicWorldHeightInjection {
|
||||
|
||||
public static PacketHandler handleJoinGame(final PacketHandler parentHandler) {
|
||||
return wrapper -> {
|
||||
parentHandler.handle(wrapper);
|
||||
if (wrapper.isCancelled()) return;
|
||||
|
||||
if (wrapper.user().getProtocolInfo().serverProtocolVersion().olderThanOrEqualTo(LegacyProtocolVersion.c0_28toc0_30)) {
|
||||
for (CompoundTag dimension : wrapper.get(Types.NAMED_COMPOUND_TAG, 0).getCompoundTag("minecraft:dimension_type").getListTag("value", CompoundTag.class)) {
|
||||
changeDimensionTagHeight(wrapper.user(), dimension.getCompoundTag("element"));
|
||||
}
|
||||
changeDimensionTagHeight(wrapper.user(), wrapper.get(Types.NAMED_COMPOUND_TAG, 1));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static PacketHandler handleRespawn(final PacketHandler parentHandler) {
|
||||
return wrapper -> {
|
||||
parentHandler.handle(wrapper);
|
||||
if (wrapper.isCancelled()) return;
|
||||
|
||||
if (wrapper.user().getProtocolInfo().serverProtocolVersion().olderThanOrEqualTo(LegacyProtocolVersion.c0_28toc0_30)) {
|
||||
changeDimensionTagHeight(wrapper.user(), wrapper.get(Types.NAMED_COMPOUND_TAG, 0));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static PacketHandler handleChunkData(final PacketHandler parentHandler) {
|
||||
return wrapper -> {
|
||||
parentHandler.handle(wrapper);
|
||||
if (wrapper.isCancelled()) return;
|
||||
|
||||
if (wrapper.user().getProtocolInfo().serverProtocolVersion().olderThanOrEqualTo(LegacyProtocolVersion.c0_28toc0_30)) {
|
||||
wrapper.resetReader();
|
||||
final Chunk chunk = wrapper.read(new ChunkType1_17(16));
|
||||
wrapper.write(new ChunkType1_17(chunk.getSections().length), chunk);
|
||||
|
||||
final ClassicWorldHeightProvider heightProvider = Via.getManager().getProviders().get(ClassicWorldHeightProvider.class);
|
||||
if (chunk.getSections().length < heightProvider.getMaxChunkSectionCount(wrapper.user())) { // Increase available sections to match new world height
|
||||
final ChunkSection[] newArray = new ChunkSection[heightProvider.getMaxChunkSectionCount(wrapper.user())];
|
||||
System.arraycopy(chunk.getSections(), 0, newArray, 0, chunk.getSections().length);
|
||||
chunk.setSections(newArray);
|
||||
}
|
||||
|
||||
final BitSet chunkMask = new BitSet();
|
||||
for (int i = 0; i < chunk.getSections().length; i++) {
|
||||
if (chunk.getSections()[i] != null) chunkMask.set(i);
|
||||
}
|
||||
chunk.setChunkMask(chunkMask);
|
||||
|
||||
final int[] newBiomeData = new int[chunk.getSections().length * 4 * 4 * 4];
|
||||
System.arraycopy(chunk.getBiomeData(), 0, newBiomeData, 0, chunk.getBiomeData().length);
|
||||
for (int i = 64; i < chunk.getSections().length * 4; i++) { // copy top layer of old biome data all the way to max world height
|
||||
System.arraycopy(chunk.getBiomeData(), chunk.getBiomeData().length - 16, newBiomeData, i * 16, 16);
|
||||
}
|
||||
chunk.setBiomeData(newBiomeData);
|
||||
|
||||
chunk.setHeightMap(new CompoundTag()); // rip heightmap :(
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static PacketHandler handleUpdateLight(final PacketHandler parentHandler) {
|
||||
final PacketHandler classicLightHandler = new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.VAR_INT); // x
|
||||
map(Types.VAR_INT); // y
|
||||
map(Types.BOOLEAN); // trust edges
|
||||
handler(wrapper -> {
|
||||
wrapper.read(Types.VAR_INT); // sky light mask
|
||||
wrapper.read(Types.VAR_INT); // block light mask
|
||||
final int emptySkyLightMask = wrapper.read(Types.VAR_INT); // empty sky light mask
|
||||
final int emptyBlockLightMask = wrapper.read(Types.VAR_INT); // empty block light mask
|
||||
|
||||
final ClassicLevel level = wrapper.user().get(ClassicLevelStorage.class).getClassicLevel();
|
||||
final ClassicWorldHeightProvider heightProvider = Via.getManager().getProviders().get(ClassicWorldHeightProvider.class);
|
||||
|
||||
int sectionYCount = level.getSizeY() >> 4;
|
||||
if (level.getSizeY() % 16 != 0) sectionYCount++;
|
||||
if (sectionYCount > heightProvider.getMaxChunkSectionCount(wrapper.user())) {
|
||||
sectionYCount = heightProvider.getMaxChunkSectionCount(wrapper.user());
|
||||
}
|
||||
|
||||
final List<byte[]> lightArrays = new ArrayList<>();
|
||||
while (wrapper.isReadable(Types.BYTE_ARRAY_PRIMITIVE, 0)) {
|
||||
lightArrays.add(wrapper.read(Types.BYTE_ARRAY_PRIMITIVE));
|
||||
}
|
||||
|
||||
int skyLightCount = 16;
|
||||
int blockLightCount = sectionYCount;
|
||||
if (lightArrays.size() == 16 + 0 + 2) {
|
||||
blockLightCount = 0;
|
||||
} else if (lightArrays.size() == 16 + sectionYCount + 2) {
|
||||
} else if (lightArrays.size() == sectionYCount + sectionYCount + 2) {
|
||||
skyLightCount = sectionYCount;
|
||||
}
|
||||
skyLightCount += 2; // Chunk below 0 and above 255
|
||||
|
||||
final BitSet skyLightMask = new BitSet();
|
||||
final BitSet blockLightMask = new BitSet();
|
||||
skyLightMask.set(0, skyLightCount);
|
||||
blockLightMask.set(0, blockLightCount);
|
||||
|
||||
wrapper.write(Types.LONG_ARRAY_PRIMITIVE, skyLightMask.toLongArray());
|
||||
wrapper.write(Types.LONG_ARRAY_PRIMITIVE, blockLightMask.toLongArray());
|
||||
wrapper.write(Types.LONG_ARRAY_PRIMITIVE, new long[emptySkyLightMask]);
|
||||
wrapper.write(Types.LONG_ARRAY_PRIMITIVE, new long[emptyBlockLightMask]);
|
||||
|
||||
wrapper.write(Types.VAR_INT, skyLightCount);
|
||||
for (int i = 0; i < skyLightCount; i++) {
|
||||
wrapper.write(Types.BYTE_ARRAY_PRIMITIVE, lightArrays.remove(0));
|
||||
}
|
||||
wrapper.write(Types.VAR_INT, blockLightCount);
|
||||
for (int i = 0; i < blockLightCount; i++) {
|
||||
wrapper.write(Types.BYTE_ARRAY_PRIMITIVE, lightArrays.remove(0));
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
return wrapper -> {
|
||||
if (wrapper.user().getProtocolInfo().serverProtocolVersion().olderThanOrEqualTo(LegacyProtocolVersion.c0_28toc0_30)) {
|
||||
classicLightHandler.handle(wrapper);
|
||||
} else {
|
||||
parentHandler.handle(wrapper);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static void changeDimensionTagHeight(final UserConnection user, final CompoundTag tag) {
|
||||
tag.putInt("height", Via.getManager().getProviders().get(ClassicWorldHeightProvider.class).getMaxChunkSectionCount(user) << 4);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2026 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.raphimc.viaproxy.injection;
|
||||
|
||||
import net.lenni0451.classtransform.transformer.IAnnotationHandlerPreprocessor;
|
||||
import net.lenni0451.classtransform.utils.ASMUtils;
|
||||
import net.lenni0451.classtransform.utils.Sneaky;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
import xyz.wagyourtail.jvmdg.runtime.ClassDowngradingAgent;
|
||||
|
||||
import java.lang.instrument.IllegalClassFormatException;
|
||||
|
||||
public class TransformerDowngrader implements IAnnotationHandlerPreprocessor {
|
||||
|
||||
private final ClassLoader classLoader;
|
||||
private final ClassDowngradingAgent downgrader = new ClassDowngradingAgent();
|
||||
|
||||
public TransformerDowngrader(final ClassLoader classLoader) {
|
||||
this.classLoader = classLoader;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process(final ClassNode node) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassNode replace(final ClassNode node) {
|
||||
final byte[] bytes = ASMUtils.toStacklessBytes(node);
|
||||
try {
|
||||
final byte[] transformed = this.downgrader.transform(this.classLoader, node.name, null, null, bytes);
|
||||
if (transformed != null) {
|
||||
return ASMUtils.fromBytes(transformed);
|
||||
} else {
|
||||
return node;
|
||||
}
|
||||
} catch (IllegalClassFormatException e) {
|
||||
Sneaky.sneakyThrow(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,170 @@
|
|||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2026 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.raphimc.viaproxy.injection.mixins;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.HolderSet;
|
||||
import com.viaversion.viaversion.api.minecraft.data.StructuredDataContainer;
|
||||
import com.viaversion.viaversion.api.minecraft.data.StructuredDataKey;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.ToolProperties;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.ToolRule;
|
||||
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
|
||||
import com.viaversion.viaversion.libs.fastutil.ints.IntOpenHashSet;
|
||||
import com.viaversion.viaversion.libs.fastutil.ints.IntSet;
|
||||
import com.viaversion.viaversion.libs.gson.JsonArray;
|
||||
import com.viaversion.viaversion.libs.gson.JsonElement;
|
||||
import com.viaversion.viaversion.libs.gson.JsonObject;
|
||||
import com.viaversion.viaversion.protocols.v1_20_2to1_20_3.packet.ClientboundPacket1_20_3;
|
||||
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.Protocol1_20_3To1_20_5;
|
||||
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundPacket1_20_5;
|
||||
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.rewriter.BlockItemPacketRewriter1_20_5;
|
||||
import com.viaversion.viaversion.rewriter.ItemRewriter;
|
||||
import net.raphimc.vialegacy.api.LegacyProtocolVersion;
|
||||
import net.raphimc.viaproxy.ViaProxy;
|
||||
import net.raphimc.viaproxy.plugins.events.ViaLoadingEvent;
|
||||
import net.raphimc.viaproxy.protocoltranslator.impl.ViaProxyMappingDataLoader;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@Mixin(value = BlockItemPacketRewriter1_20_5.class, remap = false)
|
||||
public abstract class MixinBlockItemPacketRewriter1_20_5 extends ItemRewriter<ClientboundPacket1_20_3, ServerboundPacket1_20_5, Protocol1_20_3To1_20_5> {
|
||||
|
||||
@Unique
|
||||
private final Set<String> foodItems_b1_7_3 = new HashSet<>();
|
||||
|
||||
@Unique
|
||||
private final Map<String, Integer> armorMaxDamage_b1_8_1 = new HashMap<>();
|
||||
|
||||
@Unique
|
||||
private final Map<ProtocolVersion, Map<String, ToolProperties>> toolDataChanges = new LinkedHashMap<>();
|
||||
|
||||
public MixinBlockItemPacketRewriter1_20_5() {
|
||||
super(null, null, null, null, null);
|
||||
}
|
||||
|
||||
@Inject(method = "<init>", at = @At("RETURN"))
|
||||
public void loadItemMappings(Protocol1_20_3To1_20_5 protocol, CallbackInfo ci) {
|
||||
this.foodItems_b1_7_3.add("minecraft:apple");
|
||||
this.foodItems_b1_7_3.add("minecraft:mushroom_stew");
|
||||
this.foodItems_b1_7_3.add("minecraft:bread");
|
||||
this.foodItems_b1_7_3.add("minecraft:porkchop");
|
||||
this.foodItems_b1_7_3.add("minecraft:cooked_porkchop");
|
||||
this.foodItems_b1_7_3.add("minecraft:golden_apple");
|
||||
this.foodItems_b1_7_3.add("minecraft:cod");
|
||||
this.foodItems_b1_7_3.add("minecraft:cooked_cod");
|
||||
this.foodItems_b1_7_3.add("minecraft:cookie");
|
||||
|
||||
final JsonObject armorMaxDamages = ViaProxyMappingDataLoader.INSTANCE.loadData("armor-damages-b1.8.1.json");
|
||||
for (Map.Entry<String, JsonElement> entry : armorMaxDamages.entrySet()) {
|
||||
this.armorMaxDamage_b1_8_1.put(entry.getKey(), entry.getValue().getAsInt());
|
||||
}
|
||||
|
||||
ViaProxy.EVENT_MANAGER.registerRunnable(() -> {
|
||||
final JsonObject itemToolComponents = ViaProxyMappingDataLoader.INSTANCE.loadData("item-tool-components.json");
|
||||
for (Map.Entry<String, JsonElement> entry : itemToolComponents.entrySet()) {
|
||||
final ProtocolVersion version = ProtocolVersion.getClosest(entry.getKey());
|
||||
if (version == null) {
|
||||
throw new IllegalStateException("Unknown protocol version: " + entry.getKey());
|
||||
}
|
||||
final Map<String, ToolProperties> toolProperties = new HashMap<>();
|
||||
final JsonArray toolComponents = entry.getValue().getAsJsonArray();
|
||||
for (JsonElement toolComponent : toolComponents) {
|
||||
final JsonObject toolComponentObject = toolComponent.getAsJsonObject();
|
||||
final String item = toolComponentObject.get("item").getAsString();
|
||||
final float defaultMiningSpeed = toolComponentObject.get("default_mining_speed").getAsFloat();
|
||||
final int damagePerBlock = toolComponentObject.get("damage_per_block").getAsInt();
|
||||
final int[] suitableFor = this.blockJsonArrayToIds(version, toolComponentObject.getAsJsonArray("suitable_for"));
|
||||
final List<ToolRule> toolRules = new ArrayList<>();
|
||||
final JsonArray miningSpeeds = toolComponentObject.getAsJsonArray("mining_speeds");
|
||||
for (JsonElement miningSpeed : miningSpeeds) {
|
||||
final JsonObject miningSpeedObject = miningSpeed.getAsJsonObject();
|
||||
final int[] blocks = this.blockJsonArrayToIds(version, miningSpeedObject.getAsJsonArray("blocks"));
|
||||
final float speed = miningSpeedObject.get("speed").getAsFloat();
|
||||
toolRules.add(new ToolRule(HolderSet.of(blocks), speed, null));
|
||||
}
|
||||
if (suitableFor.length > 0) {
|
||||
toolRules.add(new ToolRule(HolderSet.of(suitableFor), null, true));
|
||||
}
|
||||
toolProperties.put(item, new ToolProperties(toolRules.toArray(new ToolRule[0]), defaultMiningSpeed, damagePerBlock));
|
||||
}
|
||||
this.toolDataChanges.put(version, toolProperties);
|
||||
}
|
||||
}, ViaLoadingEvent.class);
|
||||
}
|
||||
|
||||
@Inject(method = "appendItemDataFixComponents", at = @At("RETURN"))
|
||||
private void appendItemDataFixComponents(UserConnection user, Item item, CallbackInfo ci) {
|
||||
final StructuredDataContainer data = item.dataContainer();
|
||||
final String identifier = this.protocol.getMappingData().getFullItemMappings().identifier(item.identifier());
|
||||
|
||||
if (user.getProtocolInfo().serverProtocolVersion().olderThanOrEqualTo(LegacyProtocolVersion.b1_8tob1_8_1)) {
|
||||
if (this.armorMaxDamage_b1_8_1.containsKey(identifier)) {
|
||||
data.set(StructuredDataKey.MAX_DAMAGE, this.armorMaxDamage_b1_8_1.get(identifier));
|
||||
}
|
||||
}
|
||||
|
||||
if (user.getProtocolInfo().serverProtocolVersion().olderThanOrEqualTo(LegacyProtocolVersion.b1_7tob1_7_3)) {
|
||||
if (this.foodItems_b1_7_3.contains(identifier)) {
|
||||
data.set(StructuredDataKey.MAX_STACK_SIZE, 1);
|
||||
data.setEmpty(StructuredDataKey.FOOD1_20_5);
|
||||
}
|
||||
}
|
||||
|
||||
for (Map.Entry<ProtocolVersion, Map<String, ToolProperties>> entry : this.toolDataChanges.entrySet()) {
|
||||
if (user.getProtocolInfo().serverProtocolVersion().olderThanOrEqualTo(entry.getKey())) {
|
||||
final ToolProperties toolProperties = entry.getValue().get(identifier);
|
||||
if (toolProperties != null) {
|
||||
data.set(StructuredDataKey.TOOL1_20_5, toolProperties);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Unique
|
||||
private int[] blockJsonArrayToIds(final ProtocolVersion protocolVersion, final JsonArray jsonArray) {
|
||||
final IntSet ids = new IntOpenHashSet();
|
||||
for (final JsonElement element : jsonArray) {
|
||||
final String name = element.getAsString();
|
||||
if (name.startsWith("#")) { // Material name
|
||||
final String material = name.substring(1);
|
||||
for (Map.Entry<String, Map<ProtocolVersion, String>> entry : ViaProxyMappingDataLoader.BLOCK_MATERIALS.entrySet()) {
|
||||
for (Map.Entry<ProtocolVersion, String> materialEntry : entry.getValue().entrySet()) {
|
||||
if (protocolVersion.olderThanOrEqualTo(materialEntry.getKey()) && materialEntry.getValue().equals(material)) {
|
||||
ids.add(this.protocol.getMappingData().blockId(entry.getKey()));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (name.startsWith("-")) { // Block name
|
||||
ids.remove(this.protocol.getMappingData().blockId(name.substring(1)));
|
||||
} else { // Block name
|
||||
ids.add(this.protocol.getMappingData().blockId(name));
|
||||
}
|
||||
}
|
||||
return ids.toIntArray();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2026 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.raphimc.viaproxy.injection.mixins;
|
||||
|
||||
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
|
||||
import com.viaversion.viaversion.protocols.v1_21_9to1_21_11.rewriter.BlockItemPacketRewriter1_21_11;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
|
||||
@Mixin(BlockItemPacketRewriter1_21_11.class)
|
||||
public abstract class MixinBlockItemPacketRewriter1_21_11 {
|
||||
|
||||
// The vanilla client uses the game mode from the player list entry to determine the game mode. ViaLegacy uses fake player list entries and thus the check won't work as intended.
|
||||
@Redirect(method = "appendItemDataFixComponents", at = @At(value = "INVOKE", target = "Lcom/viaversion/viaversion/api/protocol/version/ProtocolVersion;olderThanOrEqualTo(Lcom/viaversion/viaversion/api/protocol/version/ProtocolVersion;)Z"))
|
||||
private boolean disableOnPre1_8Servers(ProtocolVersion instance, ProtocolVersion other) {
|
||||
return instance.equals(other);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2026 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.raphimc.viaproxy.injection.mixins;
|
||||
|
||||
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
|
||||
import com.viaversion.viaversion.protocols.v1_21_2to1_21_4.rewriter.BlockItemPacketRewriter1_21_4;
|
||||
import net.raphimc.vialegacy.api.LegacyProtocolVersion;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
|
||||
@Mixin(value = BlockItemPacketRewriter1_21_4.class, remap = false)
|
||||
public abstract class MixinBlockItemPacketRewriter1_21_4 {
|
||||
|
||||
@Redirect(method = "appendItemDataFixComponents", at = @At(value = "INVOKE", target = "Lcom/viaversion/viaversion/api/protocol/version/ProtocolVersion;olderThanOrEqualTo(Lcom/viaversion/viaversion/api/protocol/version/ProtocolVersion;)Z"))
|
||||
private boolean changeSwordFixVersionRange(ProtocolVersion instance, ProtocolVersion other) {
|
||||
if (other == ProtocolVersion.v1_8) {
|
||||
return instance.betweenInclusive(LegacyProtocolVersion.b1_8tob1_8_1, ProtocolVersion.v1_8);
|
||||
} else {
|
||||
return instance.olderThanOrEqualTo(other);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2026 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.raphimc.viaproxy.injection.mixins;
|
||||
|
||||
import net.raphimc.netminecraft.packet.impl.handshaking.C2SHandshakingClientIntentionPacket;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.Constant;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyConstant;
|
||||
|
||||
@Mixin(C2SHandshakingClientIntentionPacket.class)
|
||||
public abstract class MixinC2SHandshakingClientIntentionPacket {
|
||||
|
||||
@ModifyConstant(method = "read", constant = @Constant(intValue = 255))
|
||||
private int allowLargerHostnames(int constant) {
|
||||
return Short.MAX_VALUE;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2026 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.raphimc.viaproxy.injection.mixins;
|
||||
|
||||
import com.viaversion.viaversion.legacy.bossbar.CommonBoss;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
|
||||
@Mixin(value = CommonBoss.class, remap = false)
|
||||
public abstract class MixinCommonBoss {
|
||||
|
||||
@Redirect(method = {"<init>", "setHealth"}, at = @At(value = "INVOKE", target = "Lcom/google/common/base/Preconditions;checkArgument(ZLjava/lang/Object;)V"))
|
||||
private void removeBoundChecks(boolean expression, Object errorMessage) {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2026 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.raphimc.viaproxy.injection.mixins;
|
||||
|
||||
import com.viaversion.viaversion.api.protocol.Protocol;
|
||||
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
|
||||
import com.viaversion.viaversion.protocols.v1_16_1to1_16_2.packet.ClientboundPackets1_16_2;
|
||||
import com.viaversion.viaversion.protocols.v1_16_4to1_17.Protocol1_16_4To1_17;
|
||||
import com.viaversion.viaversion.protocols.v1_16_4to1_17.rewriter.EntityPacketRewriter1_17;
|
||||
import net.raphimc.viaproxy.injection.ClassicWorldHeightInjection;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
|
||||
@Mixin(value = EntityPacketRewriter1_17.class, remap = false)
|
||||
public abstract class MixinEntityPacketRewriter1_17 {
|
||||
|
||||
@Redirect(method = "registerPackets", at = @At(value = "INVOKE", target = "Lcom/viaversion/viaversion/protocols/v1_16_4to1_17/Protocol1_16_4To1_17;registerClientbound(Lcom/viaversion/viaversion/api/protocol/packet/ClientboundPacketType;Lcom/viaversion/viaversion/api/protocol/remapper/PacketHandler;)V"))
|
||||
private void handleClassicWorldHeight(Protocol1_16_4To1_17 instance, ClientboundPacketType packetType, PacketHandler packetHandler) {
|
||||
if (packetType == ClientboundPackets1_16_2.LOGIN) packetHandler = ClassicWorldHeightInjection.handleJoinGame(packetHandler);
|
||||
if (packetType == ClientboundPackets1_16_2.RESPAWN) packetHandler = ClassicWorldHeightInjection.handleRespawn(packetHandler);
|
||||
|
||||
((Protocol) instance).registerClientbound(packetType, packetHandler);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2026 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.raphimc.viaproxy.injection.mixins;
|
||||
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.rewriter.EntityPacketRewriter1_20_5;
|
||||
import net.raphimc.vialegacy.api.LegacyProtocolVersion;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@Mixin(value = EntityPacketRewriter1_20_5.class, remap = false)
|
||||
public abstract class MixinEntityPacketRewriter1_20_5 {
|
||||
|
||||
@Shadow
|
||||
protected abstract void writeAttribute(PacketWrapper wrapper, String attributeId, double base, UUID modifierId, double amount);
|
||||
|
||||
@Redirect(method = "sendRangeAttributes", at = @At(value = "INVOKE", target = "Lcom/viaversion/viaversion/protocols/v1_20_3to1_20_5/rewriter/EntityPacketRewriter1_20_5;writeAttribute(Lcom/viaversion/viaversion/api/protocol/packet/PacketWrapper;Ljava/lang/String;DLjava/util/UUID;D)V"))
|
||||
private void useLegacyValues(EntityPacketRewriter1_20_5 instance, PacketWrapper wrapper, String attributeId, double base, UUID modifierId, double amount) {
|
||||
if (attributeId.equals("player.block_interaction_range") && wrapper.user().getProtocolInfo().serverProtocolVersion().olderThan(LegacyProtocolVersion.r1_0_0tor1_0_1)) {
|
||||
this.writeAttribute(wrapper, attributeId, 4D, modifierId, 1D);
|
||||
} else if (attributeId.equals("player.entity_interaction_range") && wrapper.user().getProtocolInfo().serverProtocolVersion().olderThanOrEqualTo(LegacyProtocolVersion.r1_6_4)) {
|
||||
this.writeAttribute(wrapper, attributeId, 3D, modifierId, 3D);
|
||||
} else {
|
||||
this.writeAttribute(wrapper, attributeId, base, modifierId, amount);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2026 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.raphimc.viaproxy.injection.mixins;
|
||||
|
||||
import com.viaversion.viaversion.api.minecraft.entitydata.EntityData;
|
||||
import com.viaversion.viaversion.protocols.v1_8to1_9.storage.EntityTracker1_9;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
import org.spongepowered.asm.mixin.injection.Slice;
|
||||
|
||||
@Mixin(value = EntityTracker1_9.class, remap = false)
|
||||
public abstract class MixinEntityTracker1_9 {
|
||||
|
||||
@Redirect(method = "handleEntityData", at = @At(value = "INVOKE", target = "Ljava/lang/Math;min(FF)F"), slice = @Slice(from = @At(value = "INVOKE", target = "Lcom/viaversion/viaversion/api/configuration/ViaVersionConfig;isBossbarAntiflicker()Z")))
|
||||
private float removeMin(float a, float b) {
|
||||
return a;
|
||||
}
|
||||
|
||||
@Redirect(method = "handleEntityData", at = @At(value = "INVOKE", target = "Ljava/lang/Math;max(FF)F"), slice = @Slice(from = @At(value = "INVOKE", target = "Lcom/viaversion/viaversion/api/configuration/ViaVersionConfig;isBossbarAntiflicker()Z")))
|
||||
private float removeMax(float a, float b) {
|
||||
return b;
|
||||
}
|
||||
|
||||
@Redirect(method = "handleEntityData", at = @At(value = "INVOKE", target = "Lcom/viaversion/viaversion/api/minecraft/entitydata/EntityData;getValue()Ljava/lang/Object;"), slice = @Slice(from = @At(value = "INVOKE", target = "Lcom/viaversion/viaversion/api/configuration/ViaVersionConfig;isBossbarAntiflicker()Z")))
|
||||
private Object remapNaNToZero(EntityData instance) {
|
||||
if (instance.getValue() instanceof Float && ((Float) instance.getValue()).isNaN()) {
|
||||
return 0F;
|
||||
}
|
||||
|
||||
return instance.getValue();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,137 @@
|
|||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2026 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.raphimc.viaproxy.injection.mixins;
|
||||
|
||||
import com.viaversion.nbt.tag.CompoundTag;
|
||||
import com.viaversion.nbt.tag.ListTag;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.AttributeModifiers1_20_5;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.libs.fastutil.ints.Int2ObjectMap;
|
||||
import com.viaversion.viaversion.libs.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
import com.viaversion.viaversion.libs.gson.JsonElement;
|
||||
import com.viaversion.viaversion.libs.gson.JsonObject;
|
||||
import com.viaversion.viaversion.protocols.v1_8to1_9.Protocol1_8To1_9;
|
||||
import com.viaversion.viaversion.protocols.v1_8to1_9.packet.ClientboundPackets1_8;
|
||||
import com.viaversion.viaversion.protocols.v1_8to1_9.packet.ServerboundPackets1_9;
|
||||
import com.viaversion.viaversion.protocols.v1_8to1_9.rewriter.ItemPacketRewriter1_9;
|
||||
import com.viaversion.viaversion.rewriter.ItemRewriter;
|
||||
import com.viaversion.viaversion.util.Pair;
|
||||
import net.raphimc.viaproxy.protocoltranslator.impl.ViaProxyMappingDataLoader;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
@Mixin(value = ItemPacketRewriter1_9.class, remap = false)
|
||||
public abstract class MixinItemPacketRewriter1_9 extends ItemRewriter<ClientboundPackets1_8, ServerboundPackets1_9, Protocol1_8To1_9> {
|
||||
|
||||
@Unique
|
||||
private final Int2ObjectMap<String> itemIdentifiers = new Int2ObjectOpenHashMap<>();
|
||||
|
||||
@Unique
|
||||
private final Map<String, Map<String, Pair<String, AttributeModifiers1_20_5.ModifierData>>> itemAttributes = new HashMap<>();
|
||||
|
||||
public MixinItemPacketRewriter1_9(Protocol1_8To1_9 protocol, Type<Item> itemType, Type<Item[]> itemArrayType, Type<Item> mappedItemType, Type<Item[]> mappedItemArrayType) {
|
||||
super(protocol, itemType, itemArrayType, mappedItemType, mappedItemArrayType);
|
||||
}
|
||||
|
||||
@Inject(method = "<init>", at = @At("RETURN"))
|
||||
private void loadAdditionalData(CallbackInfo ci) {
|
||||
final JsonObject itemIdentifiers = ViaProxyMappingDataLoader.INSTANCE.loadData("item-identifiers-1.8.json");
|
||||
for (Map.Entry<String, JsonElement> entry : itemIdentifiers.entrySet()) {
|
||||
this.itemIdentifiers.put(entry.getValue().getAsInt(), entry.getKey());
|
||||
}
|
||||
|
||||
final JsonObject itemAttributes = ViaProxyMappingDataLoader.INSTANCE.loadData("item-attributes-1.8.json");
|
||||
for (Map.Entry<String, JsonElement> itemEntry : itemAttributes.entrySet()) {
|
||||
final String itemIdentifier = itemEntry.getKey();
|
||||
final Map<String, Pair<String, AttributeModifiers1_20_5.ModifierData>> attributes = new HashMap<>();
|
||||
for (Map.Entry<String, JsonElement> attributeEntry : itemEntry.getValue().getAsJsonObject().entrySet()) {
|
||||
final String attribute = attributeEntry.getKey();
|
||||
final JsonObject attributeData = attributeEntry.getValue().getAsJsonObject();
|
||||
final AttributeModifiers1_20_5.ModifierData modifierData = new AttributeModifiers1_20_5.ModifierData(UUID.fromString(attributeData.get("id").getAsString()), attributeData.get("name").getAsString(), attributeData.get("amount").getAsDouble(), attributeData.get("operation").getAsInt());
|
||||
final String slot = attributeData.get("slot").getAsString();
|
||||
attributes.put(attribute, new Pair<>(slot, modifierData));
|
||||
}
|
||||
this.itemAttributes.put(itemIdentifier, attributes);
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "handleItemToClient", at = @At("RETURN"))
|
||||
private void addAttributeFixData(CallbackInfoReturnable<Item> cir) {
|
||||
final Item item = cir.getReturnValue();
|
||||
if (item == null) return;
|
||||
|
||||
final String identifier = this.itemIdentifiers.get(item.identifier());
|
||||
if (identifier != null && this.itemAttributes.containsKey(identifier)) {
|
||||
final Map<String, Pair<String, AttributeModifiers1_20_5.ModifierData>> attributes = this.itemAttributes.get(identifier);
|
||||
final CompoundTag attributeFixTag = new CompoundTag();
|
||||
CompoundTag tag = item.tag();
|
||||
if (tag == null) {
|
||||
tag = new CompoundTag();
|
||||
item.setTag(tag);
|
||||
attributeFixTag.putBoolean("RemoveTag", true);
|
||||
}
|
||||
tag.put(nbtTagName("attributeFix"), attributeFixTag);
|
||||
|
||||
ListTag<CompoundTag> attributeModifiers = tag.getListTag("AttributeModifiers", CompoundTag.class);
|
||||
if (attributeModifiers == null) {
|
||||
attributeModifiers = new ListTag<>(CompoundTag.class);
|
||||
for (Map.Entry<String, Pair<String, AttributeModifiers1_20_5.ModifierData>> entry : attributes.entrySet()) {
|
||||
final CompoundTag attributeModifier = new CompoundTag();
|
||||
attributeModifier.putString("AttributeName", entry.getKey());
|
||||
attributeModifier.putString("Name", entry.getValue().value().name());
|
||||
attributeModifier.putDouble("Amount", entry.getValue().value().amount());
|
||||
attributeModifier.putInt("Operation", entry.getValue().value().operation());
|
||||
attributeModifier.putLong("UUIDMost", entry.getValue().value().uuid().getMostSignificantBits());
|
||||
attributeModifier.putLong("UUIDLeast", entry.getValue().value().uuid().getLeastSignificantBits());
|
||||
attributeModifier.putString("Slot", entry.getValue().key());
|
||||
attributeModifiers.add(attributeModifier);
|
||||
}
|
||||
tag.put("AttributeModifiers", attributeModifiers);
|
||||
attributeFixTag.putBoolean("RemoveAttributeModifiers", true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "handleItemToServer", at = @At("RETURN"))
|
||||
private void removeAttributeFixData(CallbackInfoReturnable<Item> cir) {
|
||||
final Item item = cir.getReturnValue();
|
||||
if (item == null) return;
|
||||
final CompoundTag tag = item.tag();
|
||||
if (tag == null) return;
|
||||
final CompoundTag attributeFixTag = tag.removeUnchecked(nbtTagName("attributeFix"));
|
||||
if (attributeFixTag == null) return;
|
||||
|
||||
if (attributeFixTag.contains("RemoveAttributeModifiers")) {
|
||||
tag.remove("AttributeModifiers");
|
||||
}
|
||||
if (attributeFixTag.contains("RemoveTag")) {
|
||||
item.setTag(null);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2026 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.raphimc.viaproxy.injection.mixins;
|
||||
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.core.config.plugins.util.PluginManager;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
|
||||
@Mixin(PluginManager.class)
|
||||
public abstract class MixinPluginManager {
|
||||
|
||||
@Redirect(method = "collectPlugins(Ljava/util/List;)V", at = @At(value = "INVOKE", target = "Lorg/apache/logging/log4j/Logger;warn(Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V"))
|
||||
private void dontLogWarning(Logger logger, String message, Object p0, Object p1, Object p2) {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2026 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.raphimc.viaproxy.injection.mixins;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.protocol.AbstractProtocol;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
||||
import com.viaversion.viaversion.api.type.Types;
|
||||
import com.viaversion.viaversion.protocols.v1_16_4to1_17.packet.ServerboundPackets1_17;
|
||||
import com.viaversion.viaversion.protocols.v1_17_1to1_18.packet.ClientboundPackets1_18;
|
||||
import com.viaversion.viaversion.protocols.v1_18to1_18_2.Protocol1_18To1_18_2;
|
||||
import net.raphimc.viaproxy.protocoltranslator.viaproxy.loading_terrain_fix.SpawnPositionTracker;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
|
||||
@Mixin(Protocol1_18To1_18_2.class)
|
||||
public abstract class MixinProtocol1_18To1_18_2 extends AbstractProtocol<ClientboundPackets1_18, ClientboundPackets1_18, ServerboundPackets1_17, ServerboundPackets1_17> {
|
||||
|
||||
@Inject(method = "registerPackets", at = @At("RETURN"))
|
||||
private void fixDownloadingTerrainScreenNotClosing() {
|
||||
this.registerClientbound(ClientboundPackets1_18.PLAYER_POSITION, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
handler(wrapper -> wrapper.user().get(SpawnPositionTracker.class).sendSpawnPosition());
|
||||
}
|
||||
});
|
||||
this.registerClientbound(ClientboundPackets1_18.SET_DEFAULT_SPAWN_POSITION, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.BLOCK_POSITION1_14); // position
|
||||
map(Types.FLOAT); // angle
|
||||
handler(wrapper -> wrapper.user().get(SpawnPositionTracker.class).setSpawnPosition(wrapper.get(Types.BLOCK_POSITION1_14, 0), wrapper.get(Types.FLOAT, 0)));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(UserConnection user) {
|
||||
user.put(new SpawnPositionTracker(user));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2026 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.raphimc.viaproxy.injection.mixins;
|
||||
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.protocols.v1_19_3to1_19_4.packet.ServerboundPackets1_19_4;
|
||||
import com.viaversion.viaversion.protocols.v1_20to1_20_2.Protocol1_20To1_20_2;
|
||||
import com.viaversion.viaversion.protocols.v1_20to1_20_2.packet.ServerboundPackets1_20_2;
|
||||
import net.raphimc.viaproxy.ViaProxy;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(value = Protocol1_20To1_20_2.class, remap = false)
|
||||
public abstract class MixinProtocol1_20To1_20_2 {
|
||||
|
||||
@Inject(method = "lambda$queueServerboundPacket$12", at = @At("HEAD"), cancellable = true)
|
||||
private static void dontQueueConfigPackets(ServerboundPackets1_20_2 packetType, PacketWrapper wrapper, CallbackInfo ci) {
|
||||
if (ViaProxy.getConfig().shouldSkipConfigStatePacketQueue()) {
|
||||
ci.cancel();
|
||||
switch (packetType) {
|
||||
case CUSTOM_PAYLOAD -> wrapper.setPacketType(ServerboundPackets1_19_4.CUSTOM_PAYLOAD);
|
||||
case KEEP_ALIVE -> wrapper.setPacketType(ServerboundPackets1_19_4.KEEP_ALIVE);
|
||||
case PONG -> wrapper.setPacketType(ServerboundPackets1_19_4.PONG);
|
||||
default -> throw new IllegalStateException("Unexpected packet type: " + packetType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2026 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.raphimc.viaproxy.injection.mixins;
|
||||
|
||||
import net.raphimc.vialegacy.ViaLegacyConfig;
|
||||
import net.raphimc.viaproxy.ViaProxy;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(ViaLegacyConfig.class)
|
||||
public abstract class MixinViaLegacyConfig {
|
||||
|
||||
@Inject(method = "isLegacySkinLoading", at = @At("HEAD"), cancellable = true)
|
||||
private void makeGUIConfigurable1(final CallbackInfoReturnable<Boolean> cir) {
|
||||
if (ViaProxy.getViaProxyWindow() != null) {
|
||||
cir.setReturnValue(ViaProxy.getViaProxyWindow().advancedTab.legacySkinLoading.isSelected());
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "isLegacySkullLoading", at = @At("HEAD"), cancellable = true)
|
||||
private void makeGUIConfigurable2(final CallbackInfoReturnable<Boolean> cir) {
|
||||
if (ViaProxy.getViaProxyWindow() != null) {
|
||||
cir.setReturnValue(ViaProxy.getViaProxyWindow().advancedTab.legacySkinLoading.isSelected());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2026 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.raphimc.viaproxy.injection.mixins;
|
||||
|
||||
import com.viaversion.viaversion.protocols.v1_16_1to1_16_2.rewriter.WorldPacketRewriter1_16_2;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.Constant;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyConstant;
|
||||
|
||||
@Mixin(value = WorldPacketRewriter1_16_2.class, remap = false)
|
||||
public abstract class MixinWorldPacketRewriter1_16_2 {
|
||||
|
||||
@ModifyConstant(method = "lambda$register$0", constant = @Constant(intValue = 16))
|
||||
private static int modifySectionCountToSupportClassicWorldHeight(int constant) {
|
||||
return 64;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2026 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.raphimc.viaproxy.injection.mixins;
|
||||
|
||||
import com.viaversion.viaversion.api.protocol.Protocol;
|
||||
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
|
||||
import com.viaversion.viaversion.protocols.v1_16_1to1_16_2.packet.ClientboundPackets1_16_2;
|
||||
import com.viaversion.viaversion.protocols.v1_16_4to1_17.Protocol1_16_4To1_17;
|
||||
import com.viaversion.viaversion.protocols.v1_16_4to1_17.rewriter.WorldPacketRewriter1_17;
|
||||
import net.raphimc.viaproxy.injection.ClassicWorldHeightInjection;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
|
||||
@Mixin(value = WorldPacketRewriter1_17.class, remap = false)
|
||||
public abstract class MixinWorldPacketRewriter1_17 {
|
||||
|
||||
@Redirect(method = "register", at = @At(value = "INVOKE", target = "Lcom/viaversion/viaversion/protocols/v1_16_4to1_17/Protocol1_16_4To1_17;registerClientbound(Lcom/viaversion/viaversion/api/protocol/packet/ClientboundPacketType;Lcom/viaversion/viaversion/api/protocol/remapper/PacketHandler;)V"))
|
||||
private static void handleClassicWorldHeight(Protocol1_16_4To1_17 instance, ClientboundPacketType packetType, PacketHandler packetHandler) {
|
||||
if (packetType == ClientboundPackets1_16_2.LEVEL_CHUNK) packetHandler = ClassicWorldHeightInjection.handleChunkData(packetHandler);
|
||||
if (packetType == ClientboundPackets1_16_2.LIGHT_UPDATE) packetHandler = ClassicWorldHeightInjection.handleUpdateLight(packetHandler);
|
||||
|
||||
((Protocol) instance).registerClientbound(packetType, packetHandler);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,195 @@
|
|||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2026 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.raphimc.viaproxy.plugins;
|
||||
|
||||
import com.vdurmont.semver4j.Semver;
|
||||
import net.lenni0451.classtransform.TransformerManager;
|
||||
import net.lenni0451.classtransform.additionalclassprovider.GuavaClassPathProvider;
|
||||
import net.lenni0451.classtransform.additionalclassprovider.LazyFileClassProvider;
|
||||
import net.lenni0451.classtransform.utils.loader.InjectionClassLoader;
|
||||
import net.lenni0451.classtransform.utils.tree.IClassProvider;
|
||||
import net.lenni0451.reflect.stream.RStream;
|
||||
import net.raphimc.viaproxy.ViaProxy;
|
||||
import net.raphimc.viaproxy.injection.TransformerDowngrader;
|
||||
import net.raphimc.viaproxy.util.logging.Logger;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
import xyz.wagyourtail.jvmdg.Constants;
|
||||
import xyz.wagyourtail.jvmdg.runtime.ClassDowngradingAgent;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class PluginManager {
|
||||
|
||||
public static final File PLUGINS_DIR = new File(ViaProxy.getCwd(), "plugins");
|
||||
|
||||
private final Yaml yaml = new Yaml();
|
||||
private final IClassProvider rootClassProvider = new GuavaClassPathProvider();
|
||||
private final List<ViaProxyPlugin> plugins = new ArrayList<>();
|
||||
|
||||
public PluginManager() {
|
||||
this.loadPlugins();
|
||||
Runtime.getRuntime().addShutdownHook(new Thread(this::unloadPlugins));
|
||||
}
|
||||
|
||||
public List<ViaProxyPlugin> getPlugins() {
|
||||
return Collections.unmodifiableList(this.plugins);
|
||||
}
|
||||
|
||||
public ViaProxyPlugin getPlugin(String name) {
|
||||
for (ViaProxyPlugin plugin : this.plugins) {
|
||||
if (plugin.getName().equalsIgnoreCase(name)) {
|
||||
return plugin;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void loadPlugins() {
|
||||
if (!PLUGINS_DIR.exists() || !PLUGINS_DIR.isDirectory()) {
|
||||
if (!PLUGINS_DIR.mkdirs()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
final File[] files = PLUGINS_DIR.listFiles();
|
||||
if (files == null) return;
|
||||
|
||||
for (File file : files) {
|
||||
if (!file.getName().toLowerCase().endsWith(".jar")) continue;
|
||||
try {
|
||||
loadAndScanJar(file);
|
||||
} catch (Throwable e) {
|
||||
Logger.LOGGER.error("Unable to load plugin '" + file.getName() + "'", e);
|
||||
}
|
||||
}
|
||||
|
||||
for (ViaProxyPlugin plugin : this.plugins) {
|
||||
if (!plugin.isEnabled()) {
|
||||
this.enablePlugin(plugin);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void loadAndScanJar(final File file) throws Throwable {
|
||||
final URL url = file.toURI().toURL();
|
||||
final TransformerManager transformerManager = new TransformerManager(new LazyFileClassProvider(Collections.singletonList(file), this.rootClassProvider));
|
||||
final InjectionClassLoader classLoader = new InjectionClassLoader(transformerManager, PluginManager.class.getClassLoader(), url);
|
||||
classLoader.addProtectedPackage("io.netty.");
|
||||
|
||||
try {
|
||||
final String[] versions = System.getProperty("java.class.version").split("\\.");
|
||||
final int nativeClassVersion = Integer.parseInt(versions[0]);
|
||||
if (nativeClassVersion < Opcodes.V17) {
|
||||
System.setProperty(Constants.ALLOW_MAVEN_LOOKUP, "false");
|
||||
transformerManager.addClassFileTransformer(classLoader, new ClassDowngradingAgent());
|
||||
transformerManager.addTransformerPreprocessor(new TransformerDowngrader(classLoader));
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
Logger.LOGGER.error("Failed to setup class downgrading", e);
|
||||
}
|
||||
|
||||
final InputStream viaproxyYml = classLoader.getResourceAsStream("viaproxy.yml");
|
||||
if (viaproxyYml == null) throw new IllegalStateException("Plugin '" + file.getName() + "' does not have a viaproxy.yml");
|
||||
final Map<String, Object> yaml = this.yaml.load(viaproxyYml);
|
||||
if (!yaml.containsKey("name")) throw new IllegalStateException("Plugin '" + file.getName() + "' does not have a name attribute in the viaproxy.yml");
|
||||
if (!yaml.containsKey("author")) throw new IllegalStateException("Plugin '" + file.getName() + "' does not have a author attribute in the viaproxy.yml");
|
||||
if (!yaml.containsKey("version")) throw new IllegalStateException("Plugin '" + file.getName() + "' does not have a version attribute in the viaproxy.yml");
|
||||
if (!yaml.containsKey("main")) throw new IllegalStateException("Plugin '" + file.getName() + "' does not have a main attribute in the viaproxy.yml");
|
||||
final Semver minVersion = new Semver(yaml.getOrDefault("min-version", "0.0.0").toString());
|
||||
if (!ViaProxy.VERSION.startsWith("${") && minVersion.isGreaterThan(ViaProxy.VERSION.replace("-SNAPSHOT", ""))) {
|
||||
throw new IllegalStateException("Plugin '" + file.getName() + "' requires a newer version of ViaProxy (v" + minVersion + ")");
|
||||
}
|
||||
|
||||
final String main = (String) yaml.get("main");
|
||||
|
||||
final Class<?> mainClass = classLoader.loadClass(main);
|
||||
if (!ViaProxyPlugin.class.isAssignableFrom(mainClass)) {
|
||||
throw new IllegalStateException("Class '" + mainClass.getName() + "' from '" + file.getName() + "' does not extend ViaProxyPlugin");
|
||||
}
|
||||
final Object instance = mainClass.getDeclaredConstructor().newInstance();
|
||||
final ViaProxyPlugin plugin = (ViaProxyPlugin) instance;
|
||||
|
||||
plugin.init(classLoader, yaml);
|
||||
|
||||
if (plugin.getDepends().size() > 1) {
|
||||
throw new IllegalStateException("Plugin '" + file.getName() + "' has more than one dependency. This is not supported yet.");
|
||||
}
|
||||
|
||||
Logger.LOGGER.info("Loaded plugin '" + plugin.getName() + "' by " + plugin.getAuthor() + " (v" + plugin.getVersion() + ")");
|
||||
this.plugins.add(plugin);
|
||||
}
|
||||
|
||||
private void enablePlugin(final ViaProxyPlugin plugin) {
|
||||
for (String depend : plugin.getDepends()) {
|
||||
final ViaProxyPlugin dependPlugin = this.getPlugin(depend);
|
||||
if (dependPlugin == null) {
|
||||
Logger.LOGGER.error("Plugin '" + plugin.getName() + "' depends on '" + depend + "' which is not loaded");
|
||||
return;
|
||||
}
|
||||
if (!dependPlugin.isEnabled()) {
|
||||
this.enablePlugin(dependPlugin);
|
||||
}
|
||||
|
||||
RStream.of(plugin.getClassLoader()).withSuper().fields().by("parent").set(dependPlugin.getClassLoader());
|
||||
}
|
||||
|
||||
try {
|
||||
plugin.enable();
|
||||
Logger.LOGGER.info("Enabled plugin '" + plugin.getName() + "'");
|
||||
} catch (Throwable e) {
|
||||
Logger.LOGGER.error("Failed to enable plugin '" + plugin.getName() + "'", e);
|
||||
}
|
||||
}
|
||||
|
||||
private void unloadPlugins() {
|
||||
for (ViaProxyPlugin plugin : this.plugins) {
|
||||
if (plugin.isEnabled()) {
|
||||
this.disablePlugin(plugin);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void disablePlugin(final ViaProxyPlugin plugin) {
|
||||
for (String depend : plugin.getDepends()) {
|
||||
final ViaProxyPlugin dependPlugin = this.getPlugin(depend);
|
||||
if (dependPlugin == null) {
|
||||
Logger.LOGGER.error("Plugin '" + plugin.getName() + "' depends on '" + depend + "' which is not loaded");
|
||||
return;
|
||||
}
|
||||
if (dependPlugin.isEnabled()) {
|
||||
this.disablePlugin(dependPlugin);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
plugin.disable();
|
||||
Logger.LOGGER.info("Disabled plugin '" + plugin.getName() + "'");
|
||||
} catch (Throwable e) {
|
||||
Logger.LOGGER.error("Failed to disable plugin '" + plugin.getName() + "'", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,87 @@
|
|||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2026 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.raphimc.viaproxy.plugins;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class ViaProxyPlugin {
|
||||
|
||||
private URLClassLoader classLoader;
|
||||
private Map<String, Object> viaProxyYaml;
|
||||
private boolean enabled;
|
||||
|
||||
final void init(final URLClassLoader classLoader, final Map<String, Object> viaProxyYaml) {
|
||||
this.classLoader = classLoader;
|
||||
this.viaProxyYaml = viaProxyYaml;
|
||||
}
|
||||
|
||||
final void enable() {
|
||||
this.onEnable();
|
||||
this.enabled = true;
|
||||
}
|
||||
|
||||
public abstract void onEnable();
|
||||
|
||||
final void disable() {
|
||||
try {
|
||||
this.onDisable();
|
||||
} finally {
|
||||
this.enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void onDisable() {
|
||||
}
|
||||
|
||||
public final File getDataFolder() {
|
||||
final File dataFolder = new File(PluginManager.PLUGINS_DIR, (String) this.viaProxyYaml.get("name"));
|
||||
if (!dataFolder.exists()) {
|
||||
dataFolder.mkdirs();
|
||||
}
|
||||
return dataFolder;
|
||||
}
|
||||
|
||||
public final String getName() {
|
||||
return (String) this.viaProxyYaml.get("name");
|
||||
}
|
||||
|
||||
public final String getAuthor() {
|
||||
return (String) this.viaProxyYaml.get("author");
|
||||
}
|
||||
|
||||
public final String getVersion() {
|
||||
return String.valueOf(this.viaProxyYaml.get("version"));
|
||||
}
|
||||
|
||||
public final List<String> getDepends() {
|
||||
return Collections.unmodifiableList((List<String>) this.viaProxyYaml.getOrDefault("depends", Collections.emptyList()));
|
||||
}
|
||||
|
||||
public final URLClassLoader getClassLoader() {
|
||||
return this.classLoader;
|
||||
}
|
||||
|
||||
public final boolean isEnabled() {
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2026 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.raphimc.viaproxy.plugins.events;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import net.raphimc.viaproxy.plugins.events.types.EventCancellable;
|
||||
import net.raphimc.viaproxy.plugins.events.types.ITyped;
|
||||
|
||||
public class Client2ProxyChannelInitializeEvent extends EventCancellable implements ITyped {
|
||||
|
||||
private final Type type;
|
||||
private final Channel channel;
|
||||
private final boolean isLegacyPassthrough;
|
||||
|
||||
public Client2ProxyChannelInitializeEvent(final Type type, final Channel channel, final boolean isLegacyPassthrough) {
|
||||
this.type = type;
|
||||
this.channel = channel;
|
||||
this.isLegacyPassthrough = isLegacyPassthrough;
|
||||
}
|
||||
|
||||
public Channel getChannel() {
|
||||
return this.channel;
|
||||
}
|
||||
|
||||
public boolean isLegacyPassthrough() {
|
||||
return this.isLegacyPassthrough;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Type getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2026 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.raphimc.viaproxy.plugins.events;
|
||||
|
||||
import io.netty.channel.ChannelHandler;
|
||||
|
||||
public class Client2ProxyHandlerCreationEvent {
|
||||
|
||||
/**
|
||||
* The handler which will be used to handle Client<->Proxy packets.
|
||||
*/
|
||||
private ChannelHandler handler;
|
||||
|
||||
/**
|
||||
* Whether the handler is a legacy passthrough handler.
|
||||
*/
|
||||
private final boolean isLegacyPassthrough;
|
||||
|
||||
public Client2ProxyHandlerCreationEvent(final ChannelHandler handler, final boolean isLegacyPassthrough) {
|
||||
this.handler = handler;
|
||||
this.isLegacyPassthrough = isLegacyPassthrough;
|
||||
}
|
||||
|
||||
public ChannelHandler getHandler() {
|
||||
return this.handler;
|
||||
}
|
||||
|
||||
public void setHandler(final ChannelHandler handler) {
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
public boolean isLegacyPassthrough() {
|
||||
return this.isLegacyPassthrough;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2026 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.raphimc.viaproxy.plugins.events;
|
||||
|
||||
import net.raphimc.viaproxy.proxy.session.ProxyConnection;
|
||||
|
||||
public class ClientLoggedInEvent {
|
||||
|
||||
private final ProxyConnection proxyConnection;
|
||||
|
||||
public ClientLoggedInEvent(final ProxyConnection proxyConnection) {
|
||||
this.proxyConnection = proxyConnection;
|
||||
}
|
||||
|
||||
public ProxyConnection getProxyConnection() {
|
||||
return this.proxyConnection;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2026 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.raphimc.viaproxy.plugins.events;
|
||||
|
||||
import net.raphimc.viaproxy.plugins.events.types.EventCancellable;
|
||||
import net.raphimc.viaproxy.proxy.session.ProxyConnection;
|
||||
|
||||
public class ConnectEvent extends EventCancellable {
|
||||
|
||||
private final ProxyConnection proxyConnection;
|
||||
|
||||
public ConnectEvent(final ProxyConnection proxyConnection) {
|
||||
this.proxyConnection = proxyConnection;
|
||||
}
|
||||
|
||||
public ProxyConnection getProxyConnection() {
|
||||
return this.proxyConnection;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2026 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.raphimc.viaproxy.plugins.events;
|
||||
|
||||
import net.raphimc.viaproxy.plugins.events.types.EventCancellable;
|
||||
|
||||
public class ConsoleCommandEvent extends EventCancellable {
|
||||
|
||||
private final String command;
|
||||
private final String[] args;
|
||||
|
||||
public ConsoleCommandEvent(final String command, final String[] args) {
|
||||
this.command = command;
|
||||
this.args = args;
|
||||
}
|
||||
|
||||
public String getCommand() {
|
||||
return this.command;
|
||||
}
|
||||
|
||||
public String[] getArgs() {
|
||||
return this.args;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2026 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.raphimc.viaproxy.plugins.events;
|
||||
|
||||
import net.raphimc.viaproxy.proxy.session.ProxyConnection;
|
||||
|
||||
public class FillPlayerDataEvent {
|
||||
|
||||
private final ProxyConnection proxyConnection;
|
||||
|
||||
public FillPlayerDataEvent(final ProxyConnection proxyConnection) {
|
||||
this.proxyConnection = proxyConnection;
|
||||
}
|
||||
|
||||
public ProxyConnection getProxyConnection() {
|
||||
return this.proxyConnection;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2026 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.raphimc.viaproxy.plugins.events;
|
||||
|
||||
import net.raphimc.viaproxy.plugins.events.types.EventCancellable;
|
||||
import net.raphimc.viaproxy.proxy.session.ProxyConnection;
|
||||
|
||||
public class JoinServerRequestEvent extends EventCancellable {
|
||||
|
||||
private final ProxyConnection proxyConnection;
|
||||
private final String serverIdHash;
|
||||
|
||||
public JoinServerRequestEvent(final ProxyConnection proxyConnection, final String serverIdHash) {
|
||||
this.proxyConnection = proxyConnection;
|
||||
this.serverIdHash = serverIdHash;
|
||||
}
|
||||
|
||||
public ProxyConnection getProxyConnection() {
|
||||
return this.proxyConnection;
|
||||
}
|
||||
|
||||
public String getServerIdHash() {
|
||||
return this.serverIdHash;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2026 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.raphimc.viaproxy.plugins.events;
|
||||
|
||||
import joptsimple.OptionSet;
|
||||
|
||||
public class PostOptionsParseEvent {
|
||||
|
||||
private final OptionSet options;
|
||||
|
||||
public PostOptionsParseEvent(final OptionSet options) {
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
public OptionSet getOptions() {
|
||||
return this.options;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,89 @@
|
|||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2026 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.raphimc.viaproxy.plugins.events;
|
||||
|
||||
import com.google.common.net.HostAndPort;
|
||||
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
|
||||
import io.netty.channel.Channel;
|
||||
import net.raphimc.netminecraft.constants.IntendedState;
|
||||
import net.raphimc.viaproxy.plugins.events.types.EventCancellable;
|
||||
|
||||
import java.net.SocketAddress;
|
||||
|
||||
public class PreConnectEvent extends EventCancellable {
|
||||
|
||||
private SocketAddress serverAddress;
|
||||
private ProtocolVersion serverVersion;
|
||||
private final ProtocolVersion clientVersion;
|
||||
private final HostAndPort clientHandshakeAddress;
|
||||
private final IntendedState intendedState;
|
||||
private final Channel clientChannel;
|
||||
|
||||
private String cancelMessage = "§cCould not connect to the backend server! (Server is blacklisted)";
|
||||
|
||||
public PreConnectEvent(final SocketAddress serverAddress, final ProtocolVersion serverVersion, final ProtocolVersion clientVersion, final HostAndPort clientHandshakeAddress, final IntendedState intendedState, final Channel clientChannel) {
|
||||
this.serverAddress = serverAddress;
|
||||
this.serverVersion = serverVersion;
|
||||
this.clientVersion = clientVersion;
|
||||
this.clientHandshakeAddress = clientHandshakeAddress;
|
||||
this.intendedState = intendedState;
|
||||
this.clientChannel = clientChannel;
|
||||
}
|
||||
|
||||
public SocketAddress getServerAddress() {
|
||||
return this.serverAddress;
|
||||
}
|
||||
|
||||
public void setServerAddress(final SocketAddress serverAddress) {
|
||||
this.serverAddress = serverAddress;
|
||||
}
|
||||
|
||||
public ProtocolVersion getServerVersion() {
|
||||
return this.serverVersion;
|
||||
}
|
||||
|
||||
public void setServerVersion(final ProtocolVersion serverVersion) {
|
||||
this.serverVersion = serverVersion;
|
||||
}
|
||||
|
||||
public ProtocolVersion getClientVersion() {
|
||||
return this.clientVersion;
|
||||
}
|
||||
|
||||
public HostAndPort getClientHandshakeAddress() {
|
||||
return this.clientHandshakeAddress;
|
||||
}
|
||||
|
||||
public IntendedState getIntendedState() {
|
||||
return this.intendedState;
|
||||
}
|
||||
|
||||
public Channel getClientChannel() {
|
||||
return this.clientChannel;
|
||||
}
|
||||
|
||||
public String getCancelMessage() {
|
||||
return this.cancelMessage;
|
||||
}
|
||||
|
||||
public void setCancelMessage(final String cancelMessage) {
|
||||
this.setCancelled(true);
|
||||
this.cancelMessage = cancelMessage;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2026 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.raphimc.viaproxy.plugins.events;
|
||||
|
||||
import joptsimple.OptionParser;
|
||||
|
||||
public class PreOptionsParseEvent {
|
||||
|
||||
private final OptionParser parser;
|
||||
|
||||
public PreOptionsParseEvent(final OptionParser parser) {
|
||||
this.parser = parser;
|
||||
}
|
||||
|
||||
public OptionParser getParser() {
|
||||
return this.parser;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2026 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.raphimc.viaproxy.plugins.events;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class ProtocolTranslatorInitEvent {
|
||||
|
||||
private final List<Supplier<?>> additionalPlatformSuppliers = new ArrayList<>();
|
||||
|
||||
public ProtocolTranslatorInitEvent(final Supplier<?>... additionalPlatformSuppliers) {
|
||||
for (final Supplier<?> platformSupplier : additionalPlatformSuppliers) {
|
||||
this.registerPlatform(platformSupplier);
|
||||
}
|
||||
}
|
||||
|
||||
public void registerPlatform(final Supplier<?> platformSupplier) {
|
||||
this.additionalPlatformSuppliers.add(platformSupplier);
|
||||
}
|
||||
|
||||
public List<Supplier<?>> getPlatformSuppliers() {
|
||||
return this.additionalPlatformSuppliers;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2026 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.raphimc.viaproxy.plugins.events;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import net.raphimc.viaproxy.plugins.events.types.EventCancellable;
|
||||
import net.raphimc.viaproxy.plugins.events.types.ITyped;
|
||||
|
||||
public class Proxy2ServerChannelInitializeEvent extends EventCancellable implements ITyped {
|
||||
|
||||
private final Type type;
|
||||
private final Channel channel;
|
||||
private final boolean isLegacyPassthrough;
|
||||
|
||||
public Proxy2ServerChannelInitializeEvent(final Type type, final Channel channel, final boolean isLegacyPassthrough) {
|
||||
this.type = type;
|
||||
this.channel = channel;
|
||||
this.isLegacyPassthrough = isLegacyPassthrough;
|
||||
}
|
||||
|
||||
public Channel getChannel() {
|
||||
return this.channel;
|
||||
}
|
||||
|
||||
public boolean isLegacyPassthrough() {
|
||||
return this.isLegacyPassthrough;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Type getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2026 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.raphimc.viaproxy.plugins.events;
|
||||
|
||||
import io.netty.channel.ChannelHandler;
|
||||
|
||||
public class Proxy2ServerHandlerCreationEvent {
|
||||
|
||||
/**
|
||||
* The handler which will be used to handle Proxy<->Server packets.
|
||||
*/
|
||||
private ChannelHandler handler;
|
||||
|
||||
/**
|
||||
* Whether the handler is a legacy passthrough handler.
|
||||
*/
|
||||
private final boolean isLegacyPassthrough;
|
||||
|
||||
public Proxy2ServerHandlerCreationEvent(final ChannelHandler handler, final boolean isLegacyPassthrough) {
|
||||
this.handler = handler;
|
||||
this.isLegacyPassthrough = isLegacyPassthrough;
|
||||
}
|
||||
|
||||
public ChannelHandler getHandler() {
|
||||
return this.handler;
|
||||
}
|
||||
|
||||
public void setHandler(final ChannelHandler handler) {
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
public boolean isLegacyPassthrough() {
|
||||
return this.isLegacyPassthrough;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2026 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.raphimc.viaproxy.plugins.events;
|
||||
|
||||
import net.raphimc.netminecraft.netty.connection.NetClient;
|
||||
|
||||
public class ProxySessionCreationEvent<T extends NetClient> {
|
||||
|
||||
/**
|
||||
* The proxy session which will be used to connect to the server and store connection related data.
|
||||
*/
|
||||
private T proxySession;
|
||||
|
||||
/**
|
||||
* Whether the proxy session is a legacy passthrough handler.
|
||||
*/
|
||||
private final boolean isLegacyPassthrough;
|
||||
|
||||
public ProxySessionCreationEvent(final T proxySession, final boolean isLegacyPassthrough) {
|
||||
this.proxySession = proxySession;
|
||||
this.isLegacyPassthrough = isLegacyPassthrough;
|
||||
}
|
||||
|
||||
public T getProxySession() {
|
||||
return this.proxySession;
|
||||
}
|
||||
|
||||
public void setProxySession(final T proxySession) {
|
||||
this.proxySession = proxySession;
|
||||
}
|
||||
|
||||
public boolean isLegacyPassthrough() {
|
||||
return this.isLegacyPassthrough;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2026 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.raphimc.viaproxy.plugins.events;
|
||||
|
||||
public class ProxyStartEvent {
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2026 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.raphimc.viaproxy.plugins.events;
|
||||
|
||||
public class ProxyStopEvent {
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2026 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.raphimc.viaproxy.plugins.events;
|
||||
|
||||
import net.raphimc.viaproxy.plugins.events.types.EventCancellable;
|
||||
import net.raphimc.viaproxy.proxy.session.ProxyConnection;
|
||||
|
||||
public class ShouldVerifyOnlineModeEvent extends EventCancellable {
|
||||
|
||||
private final ProxyConnection proxyConnection;
|
||||
|
||||
public ShouldVerifyOnlineModeEvent(final ProxyConnection proxyConnection) {
|
||||
this.proxyConnection = proxyConnection;
|
||||
}
|
||||
|
||||
public ProxyConnection getProxyConnection() {
|
||||
return this.proxyConnection;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2026 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.raphimc.viaproxy.plugins.events;
|
||||
|
||||
public class ViaLoadingEvent {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2026 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.raphimc.viaproxy.plugins.events;
|
||||
|
||||
public class ViaProxyLoadedEvent {
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2026 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.raphimc.viaproxy.plugins.events.types;
|
||||
|
||||
import net.lenni0451.lambdaevents.types.ICancellableEvent;
|
||||
|
||||
public abstract class EventCancellable implements ICancellableEvent {
|
||||
|
||||
private boolean cancelled = false;
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return this.cancelled;
|
||||
}
|
||||
|
||||
public void setCancelled(final boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2026 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.raphimc.viaproxy.plugins.events.types;
|
||||
|
||||
public interface ITyped {
|
||||
|
||||
Type getType();
|
||||
|
||||
|
||||
enum Type {
|
||||
PRE, POST
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,136 @@
|
|||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2026 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.raphimc.viaproxy.protocoltranslator;
|
||||
|
||||
import com.viaversion.viaaprilfools.ViaAprilFoolsPlatformImpl;
|
||||
import com.viaversion.viabackwards.ViaBackwardsPlatformImpl;
|
||||
import com.viaversion.viarewind.ViaRewindPlatformImpl;
|
||||
import com.viaversion.viaversion.ViaManagerImpl;
|
||||
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
|
||||
import com.viaversion.viaversion.api.protocol.version.VersionType;
|
||||
import com.viaversion.viaversion.commands.ViaCommandHandler;
|
||||
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.Protocol1_20_3To1_20_5;
|
||||
import net.lenni0451.classtransform.utils.log.Logger;
|
||||
import net.raphimc.viabedrock.ViaBedrockPlatformImpl;
|
||||
import net.raphimc.viaproxy.ViaProxy;
|
||||
import net.raphimc.viaproxy.plugins.events.ProtocolTranslatorInitEvent;
|
||||
import net.raphimc.viaproxy.protocoltranslator.impl.ViaProxyInjector;
|
||||
import net.raphimc.viaproxy.protocoltranslator.impl.ViaProxyPlatformLoader;
|
||||
import net.raphimc.viaproxy.protocoltranslator.impl.ViaProxyViaLegacyPlatform;
|
||||
import net.raphimc.viaproxy.protocoltranslator.impl.ViaProxyViaVersionPlatform;
|
||||
import net.raphimc.viaproxy.util.YamlConfigPatcher;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class ProtocolTranslator {
|
||||
|
||||
public static final ProtocolVersion AUTO_DETECT_PROTOCOL = new ProtocolVersion(VersionType.SPECIAL, -2, -1, "Auto Detect (1.7+ servers)", null) {
|
||||
@Override
|
||||
protected Comparator<ProtocolVersion> customComparator() {
|
||||
return (o1, o2) -> {
|
||||
if (o1 == AUTO_DETECT_PROTOCOL) {
|
||||
return 1;
|
||||
} else if (o2 == AUTO_DETECT_PROTOCOL) {
|
||||
return -1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isKnown() {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
public static void init() {
|
||||
moveConfigs();
|
||||
patchConfigs();
|
||||
final Supplier<?>[] platformSuppliers = ViaProxy.EVENT_MANAGER.call(new ProtocolTranslatorInitEvent(ViaBackwardsPlatformImpl::new, ViaRewindPlatformImpl::new, ViaProxyViaLegacyPlatform::new, ViaAprilFoolsPlatformImpl::new, ViaBedrockPlatformImpl::new)).getPlatformSuppliers().toArray(new Supplier[0]);
|
||||
ViaManagerImpl.initAndLoad(new ViaProxyViaVersionPlatform(), new ViaProxyInjector(), new ViaCommandHandler(false), new ViaProxyPlatformLoader(), () -> {
|
||||
for (Supplier<?> platformSupplier : platformSuppliers) {
|
||||
platformSupplier.get();
|
||||
}
|
||||
});
|
||||
Protocol1_20_3To1_20_5.strictErrorHandling = false;
|
||||
ProtocolVersion.register(AUTO_DETECT_PROTOCOL);
|
||||
}
|
||||
|
||||
// Migrate from old config location (ViaLoader folder) to new one
|
||||
private static void moveConfigs() {
|
||||
try {
|
||||
final File oldConfigDir = new File(ViaProxy.getCwd(), "ViaLoader");
|
||||
if (!oldConfigDir.exists() || !oldConfigDir.isDirectory()) {
|
||||
return;
|
||||
}
|
||||
for (File file : oldConfigDir.listFiles()) {
|
||||
FileUtils.moveToDirectory(file, ViaProxy.getCwd(), true);
|
||||
}
|
||||
FileUtils.deleteDirectory(oldConfigDir);
|
||||
} catch (Throwable e) {
|
||||
Logger.error("Failed to migrate old ViaLoader configs", e);
|
||||
}
|
||||
}
|
||||
|
||||
private static void patchConfigs() {
|
||||
try {
|
||||
final YamlConfigPatcher configPatcher = new YamlConfigPatcher(new File(ViaProxy.getCwd(), "viaversion.yml"));
|
||||
final Map<String, Object> config = configPatcher.getConfig();
|
||||
config.putIfAbsent("1_13-tab-complete-delay", 5);
|
||||
config.putIfAbsent("no-delay-shield-blocking", true);
|
||||
config.putIfAbsent("handle-invalid-item-count", true);
|
||||
config.putIfAbsent("send-player-details", false);
|
||||
final Map<String, Object> packetLimiter = (Map<String, Object>) config.computeIfAbsent("packet-limiter", k -> new LinkedHashMap<>());
|
||||
packetLimiter.putIfAbsent("max-per-second", 1400);
|
||||
packetLimiter.putIfAbsent("sustained-max-per-second", 400);
|
||||
final Map<String, Object> logging = (Map<String, Object>) config.computeIfAbsent("logging", k -> new LinkedHashMap<>());
|
||||
logging.putIfAbsent("log-text-component-conversion-errors", true);
|
||||
logging.putIfAbsent("log-other-conversion-warnings", true);
|
||||
configPatcher.write();
|
||||
} catch (Throwable e) {
|
||||
throw new RuntimeException("Failed to patch ViaVersion config", e);
|
||||
}
|
||||
|
||||
try {
|
||||
final YamlConfigPatcher configPatcher = new YamlConfigPatcher(new File(ViaProxy.getCwd(), "viabackwards.yml"));
|
||||
final Map<String, Object> config = configPatcher.getConfig();
|
||||
config.putIfAbsent("fix-1_13-face-player", true);
|
||||
config.putIfAbsent("handle-pings-as-inv-acknowledgements", true);
|
||||
configPatcher.write();
|
||||
} catch (Throwable e) {
|
||||
throw new RuntimeException("Failed to patch ViaBackwards config", e);
|
||||
}
|
||||
|
||||
try {
|
||||
final YamlConfigPatcher configPatcher = new YamlConfigPatcher(new File(ViaProxy.getCwd(), "viarewind.yml"));
|
||||
final Map<String, Object> config = configPatcher.getConfig();
|
||||
config.putIfAbsent("replace-adventure", true);
|
||||
config.putIfAbsent("replace-particles", true);
|
||||
configPatcher.write();
|
||||
} catch (Throwable e) {
|
||||
throw new RuntimeException("Failed to patch ViaRewind config", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2026 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.raphimc.viaproxy.protocoltranslator.impl;
|
||||
|
||||
import com.viaversion.viaversion.platform.NoopInjector;
|
||||
|
||||
public class ViaProxyInjector extends NoopInjector {
|
||||
|
||||
@Override
|
||||
public String getEncoderName() {
|
||||
return ViaProxyViaCodec.NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDecoderName() {
|
||||
return ViaProxyViaCodec.NAME;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2026 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.raphimc.viaproxy.protocoltranslator.impl;
|
||||
|
||||
import com.viaversion.viaversion.api.data.MappingDataLoader;
|
||||
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
|
||||
import com.viaversion.viaversion.libs.gson.JsonElement;
|
||||
import com.viaversion.viaversion.libs.gson.JsonObject;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ViaProxyMappingDataLoader extends MappingDataLoader {
|
||||
|
||||
public static final Map<String, Material> MATERIALS = new HashMap<>();
|
||||
public static final Map<String, Map<ProtocolVersion, String>> BLOCK_MATERIALS = new HashMap<>();
|
||||
|
||||
public static final ViaProxyMappingDataLoader INSTANCE = new ViaProxyMappingDataLoader();
|
||||
|
||||
private ViaProxyMappingDataLoader() {
|
||||
super(ViaProxyMappingDataLoader.class, "assets/viaproxy/data/");
|
||||
|
||||
final JsonObject materialsData = this.loadData("materials-1.19.4.json");
|
||||
for (Map.Entry<String, JsonElement> entry : materialsData.getAsJsonObject("materials").entrySet()) {
|
||||
final JsonObject materialData = entry.getValue().getAsJsonObject();
|
||||
MATERIALS.put(entry.getKey(), new Material(
|
||||
materialData.get("blocksMovement").getAsBoolean(),
|
||||
materialData.get("burnable").getAsBoolean(),
|
||||
materialData.get("liquid").getAsBoolean(),
|
||||
materialData.get("blocksLight").getAsBoolean(),
|
||||
materialData.get("replaceable").getAsBoolean(),
|
||||
materialData.get("solid").getAsBoolean()
|
||||
));
|
||||
}
|
||||
for (Map.Entry<String, JsonElement> blockEntry : materialsData.getAsJsonObject("blocks").entrySet()) {
|
||||
final Map<ProtocolVersion, String> blockMaterials = new HashMap<>();
|
||||
for (Map.Entry<String, JsonElement> entry : blockEntry.getValue().getAsJsonObject().entrySet()) {
|
||||
blockMaterials.put(ProtocolVersion.getClosest(entry.getKey()), entry.getValue().getAsString());
|
||||
}
|
||||
BLOCK_MATERIALS.put(blockEntry.getKey(), blockMaterials);
|
||||
}
|
||||
}
|
||||
|
||||
public record Material(boolean blocksMovement, boolean burnable, boolean liquid, boolean blocksLight, boolean replaceable, boolean solid) {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2026 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.raphimc.viaproxy.protocoltranslator.impl;
|
||||
|
||||
import com.viaversion.viabackwards.protocol.v1_20_5to1_20_3.provider.TransferProvider;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.platform.ViaPlatformLoader;
|
||||
import com.viaversion.viaversion.api.protocol.version.VersionProvider;
|
||||
import com.viaversion.viaversion.protocols.v1_8to1_9.provider.CompressionProvider;
|
||||
import net.raphimc.viabedrock.protocol.provider.NettyPipelineProvider;
|
||||
import net.raphimc.vialegacy.protocol.classic.c0_28_30toa1_0_15.provider.ClassicCustomCommandProvider;
|
||||
import net.raphimc.vialegacy.protocol.classic.c0_28_30toa1_0_15.provider.ClassicMPPassProvider;
|
||||
import net.raphimc.vialegacy.protocol.classic.c0_28_30toa1_0_15.provider.ClassicWorldHeightProvider;
|
||||
import net.raphimc.vialegacy.protocol.release.r1_2_4_5tor1_3_1_2.provider.OldAuthProvider;
|
||||
import net.raphimc.vialegacy.protocol.release.r1_6_4tor1_7_2_5.provider.EncryptionProvider;
|
||||
import net.raphimc.vialegacy.protocol.release.r1_7_6_10tor1_8.provider.GameProfileFetcher;
|
||||
import net.raphimc.viaproxy.ViaProxy;
|
||||
import net.raphimc.viaproxy.plugins.events.ViaLoadingEvent;
|
||||
import net.raphimc.viaproxy.protocoltranslator.providers.*;
|
||||
|
||||
public class ViaProxyPlatformLoader implements ViaPlatformLoader {
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
// ViaVersion
|
||||
Via.getManager().getProviders().use(VersionProvider.class, new ViaProxyVersionProvider());
|
||||
Via.getManager().getProviders().use(CompressionProvider.class, new ViaProxyCompressionProvider());
|
||||
|
||||
// ViaBackwards
|
||||
Via.getManager().getProviders().use(TransferProvider.class, new ViaProxyTransferProvider());
|
||||
|
||||
// ViaLegacy
|
||||
Via.getManager().getProviders().use(GameProfileFetcher.class, new ViaProxyGameProfileFetcher());
|
||||
Via.getManager().getProviders().use(EncryptionProvider.class, new ViaProxyEncryptionProvider());
|
||||
Via.getManager().getProviders().use(OldAuthProvider.class, new ViaProxyOldAuthProvider());
|
||||
Via.getManager().getProviders().use(ClassicWorldHeightProvider.class, new ViaProxyClassicWorldHeightProvider());
|
||||
Via.getManager().getProviders().use(ClassicCustomCommandProvider.class, new ViaProxyClassicCustomCommandProvider());
|
||||
Via.getManager().getProviders().use(ClassicMPPassProvider.class, new ViaProxyClassicMPPassProvider());
|
||||
|
||||
// ViaBedrock
|
||||
Via.getManager().getProviders().use(NettyPipelineProvider.class, new ViaProxyNettyPipelineProvider());
|
||||
|
||||
// ViaProxy plugins
|
||||
ViaProxy.EVENT_MANAGER.call(new ViaLoadingEvent());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unload() {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2026 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.raphimc.viaproxy.protocoltranslator.impl;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.platform.ViaCodecHandler;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import net.raphimc.viaproxy.ViaProxy;
|
||||
import net.raphimc.viaproxy.util.logging.Logger;
|
||||
|
||||
public class ViaProxyViaCodec extends ViaCodecHandler {
|
||||
|
||||
public ViaProxyViaCodec(UserConnection user) {
|
||||
super(user);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
|
||||
if (ViaProxy.getConfig().shouldIgnoreProtocolTranslationErrors()) {
|
||||
try {
|
||||
super.channelRead(ctx, msg);
|
||||
} catch (Throwable e) {
|
||||
Logger.LOGGER.error("ProtocolTranslator packet translation error occurred", e);
|
||||
}
|
||||
} else {
|
||||
super.channelRead(ctx, msg);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2026 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.raphimc.viaproxy.protocoltranslator.impl;
|
||||
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import net.raphimc.vialegacy.ViaLegacyPlatformImpl;
|
||||
|
||||
public class ViaProxyViaLegacyPlatform extends ViaLegacyPlatformImpl {
|
||||
|
||||
@Override
|
||||
public String getCpeAppName() {
|
||||
return Via.getPlatform().getPlatformName() + " " + Via.getPlatform().getPlatformVersion();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,107 @@
|
|||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2026 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.raphimc.viaproxy.protocoltranslator.impl;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.libs.gson.JsonArray;
|
||||
import com.viaversion.viaversion.libs.gson.JsonObject;
|
||||
import com.viaversion.viaversion.platform.UserConnectionViaVersionPlatform;
|
||||
import io.netty.channel.ChannelFutureListener;
|
||||
import net.raphimc.netminecraft.packet.impl.configuration.C2SConfigCustomPayloadPacket;
|
||||
import net.raphimc.netminecraft.packet.impl.configuration.S2CConfigCustomPayloadPacket;
|
||||
import net.raphimc.netminecraft.packet.impl.play.C2SPlayCustomPayloadPacket;
|
||||
import net.raphimc.netminecraft.packet.impl.play.S2CPlayCustomPayloadPacket;
|
||||
import net.raphimc.viaproxy.ViaProxy;
|
||||
import net.raphimc.viaproxy.plugins.ViaProxyPlugin;
|
||||
import net.raphimc.viaproxy.proxy.session.ProxyConnection;
|
||||
import net.raphimc.viaproxy.proxy.util.CloseAndReturn;
|
||||
import net.raphimc.viaproxy.util.logging.JLoggerToSLF4J;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class ViaProxyViaVersionPlatform extends UserConnectionViaVersionPlatform {
|
||||
|
||||
public ViaProxyViaVersionPlatform() {
|
||||
super(ViaProxy.getCwd());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Logger createLogger(final String name) {
|
||||
return new JLoggerToSLF4J(LoggerFactory.getLogger(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlatformName() {
|
||||
return "ViaProxy";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlatformVersion() {
|
||||
return ViaProxy.VERSION;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean kickPlayer(final UserConnection connection, final String message) {
|
||||
try {
|
||||
ProxyConnection.fromUserConnection(connection).kickClient(message);
|
||||
} catch (CloseAndReturn ignored) {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendCustomPayload(final UserConnection connection, final String channel, final byte[] message) {
|
||||
final ProxyConnection proxyConnection = ProxyConnection.fromUserConnection(connection);
|
||||
proxyConnection.getChannel().writeAndFlush(switch (proxyConnection.getP2sConnectionState()) {
|
||||
case CONFIGURATION -> new C2SConfigCustomPayloadPacket(channel, message);
|
||||
case PLAY -> new C2SPlayCustomPayloadPacket(channel, message);
|
||||
default -> throw new UnsupportedOperationException("Can't send custom payloads in state: " + proxyConnection.getP2sConnectionState());
|
||||
}).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendCustomPayloadToClient(final UserConnection connection, final String channel, final byte[] message) {
|
||||
final ProxyConnection proxyConnection = ProxyConnection.fromUserConnection(connection);
|
||||
proxyConnection.getC2P().writeAndFlush(switch (proxyConnection.getC2pConnectionState()) {
|
||||
case CONFIGURATION -> new S2CConfigCustomPayloadPacket(channel, message);
|
||||
case PLAY -> new S2CPlayCustomPayloadPacket(channel, message);
|
||||
default -> throw new UnsupportedOperationException("Can't send custom payloads in state: " + proxyConnection.getC2pConnectionState());
|
||||
}).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonObject getDump() {
|
||||
final JsonObject root = new JsonObject();
|
||||
|
||||
root.addProperty("impl_version", ViaProxy.IMPL_VERSION);
|
||||
|
||||
final JsonArray plugins = new JsonArray();
|
||||
for (ViaProxyPlugin plugin : ViaProxy.getPluginManager().getPlugins()) {
|
||||
final JsonObject pluginObj = new JsonObject();
|
||||
pluginObj.addProperty("name", plugin.getName());
|
||||
pluginObj.addProperty("version", plugin.getVersion());
|
||||
pluginObj.addProperty("author", plugin.getAuthor());
|
||||
plugins.add(pluginObj);
|
||||
}
|
||||
root.add("plugins", plugins);
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2026 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.raphimc.viaproxy.protocoltranslator.providers;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import net.raphimc.vialegacy.ViaLegacy;
|
||||
import net.raphimc.vialegacy.protocol.alpha.a1_0_16_2toa1_0_17_1_0_17_4.storage.TimeLockStorage;
|
||||
import net.raphimc.vialegacy.protocol.classic.c0_28_30toa1_0_15.provider.ClassicCustomCommandProvider;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class ViaProxyClassicCustomCommandProvider extends ClassicCustomCommandProvider {
|
||||
|
||||
@Override
|
||||
public boolean handleChatMessage(UserConnection user, String message) {
|
||||
try {
|
||||
if (message.startsWith("/")) {
|
||||
message = message.substring(1);
|
||||
final String[] args = message.split(" ");
|
||||
if (args.length == 0) return super.handleChatMessage(user, message);
|
||||
if (args[0].equals("settime")) {
|
||||
try {
|
||||
if (args.length > 1) {
|
||||
final long time = Long.parseLong(args[1]) % 24_000L;
|
||||
user.get(TimeLockStorage.class).setTime(time);
|
||||
this.sendFeedback(user, "§aTime has been set to §6" + time);
|
||||
} else {
|
||||
throw new RuntimeException("Invalid usage");
|
||||
}
|
||||
} catch (Throwable ignored) {
|
||||
this.sendFeedback(user, "§cUsage: /settime <Time (Long)>");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
ViaLegacy.getPlatform().getLogger().log(Level.WARNING, "Error handling custom classic command", e);
|
||||
}
|
||||
|
||||
return super.handleChatMessage(user, message);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2026 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.raphimc.viaproxy.protocoltranslator.providers;
|
||||
|
||||
import com.google.common.hash.Hashing;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import net.lenni0451.commons.httpclient.HttpClient;
|
||||
import net.lenni0451.commons.httpclient.handler.ThrowingResponseHandler;
|
||||
import net.lenni0451.commons.httpclient.requests.impl.GetRequest;
|
||||
import net.raphimc.vialegacy.protocol.classic.c0_28_30toa1_0_15.provider.ClassicMPPassProvider;
|
||||
import net.raphimc.vialegacy.protocol.release.r1_2_4_5tor1_3_1_2.provider.OldAuthProvider;
|
||||
import net.raphimc.viaproxy.ViaProxy;
|
||||
import net.raphimc.viaproxy.proxy.session.ProxyConnection;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HexFormat;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class ViaProxyClassicMPPassProvider extends ClassicMPPassProvider {
|
||||
|
||||
@Override
|
||||
public String getMpPass(UserConnection user) {
|
||||
final String mppass = ProxyConnection.fromUserConnection(user).getUserOptions().classicMpPass();
|
||||
if (mppass != null && !mppass.isBlank()) {
|
||||
return mppass;
|
||||
} else if (ViaProxy.getConfig().useBetacraftAuth()) {
|
||||
try {
|
||||
final HttpClient httpClient = new HttpClient();
|
||||
String externalIp;
|
||||
try {
|
||||
externalIp = httpClient.execute(new GetRequest("https://checkip.amazonaws.com"), new ThrowingResponseHandler()).getContentAsString();
|
||||
} catch (Throwable e) {
|
||||
throw new RuntimeException("Failed to get external IP address!", e);
|
||||
}
|
||||
final byte[] hash = Hashing.sha1().hashString(externalIp.strip(), StandardCharsets.UTF_8).asBytes();
|
||||
Via.getManager().getProviders().get(OldAuthProvider.class).sendAuthRequest(user, HexFormat.of().formatHex(hash));
|
||||
} catch (Throwable e) {
|
||||
Via.getPlatform().getLogger().log(Level.WARNING, "An unknown error occurred while authenticating with BetaCraft", e);
|
||||
}
|
||||
}
|
||||
|
||||
return super.getMpPass(user);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2026 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.raphimc.viaproxy.protocoltranslator.providers;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
|
||||
import net.raphimc.vialegacy.protocol.classic.c0_28_30toa1_0_15.provider.ClassicWorldHeightProvider;
|
||||
|
||||
public class ViaProxyClassicWorldHeightProvider extends ClassicWorldHeightProvider {
|
||||
|
||||
@Override
|
||||
public short getMaxChunkSectionCount(UserConnection user) {
|
||||
if (user.getProtocolInfo().protocolVersion().newerThanOrEqualTo(ProtocolVersion.v1_17)) {
|
||||
return 64;
|
||||
}
|
||||
return 16;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2026 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.raphimc.viaproxy.protocoltranslator.providers;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.protocols.v1_8to1_9.provider.CompressionProvider;
|
||||
import net.raphimc.netminecraft.constants.MCPipeline;
|
||||
|
||||
public class ViaProxyCompressionProvider extends CompressionProvider {
|
||||
|
||||
@Override
|
||||
public void handlePlayCompression(final UserConnection user, final int threshold) {
|
||||
user.getChannel().attr(MCPipeline.COMPRESSION_THRESHOLD_ATTRIBUTE_KEY).set(threshold);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2026 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.raphimc.viaproxy.protocoltranslator.providers;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import net.raphimc.vialegacy.protocol.release.r1_6_4tor1_7_2_5.provider.EncryptionProvider;
|
||||
import net.raphimc.viaproxy.proxy.session.ProxyConnection;
|
||||
|
||||
public class ViaProxyEncryptionProvider extends EncryptionProvider {
|
||||
|
||||
@Override
|
||||
public void enableDecryption(UserConnection user) {
|
||||
try {
|
||||
ProxyConnection.fromUserConnection(user).enablePreNettyEncryption();
|
||||
} catch (Throwable e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2026 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.raphimc.viaproxy.protocoltranslator.providers;
|
||||
|
||||
import com.mojang.authlib.ProfileLookupCallback;
|
||||
import com.mojang.authlib.properties.Property;
|
||||
import com.mojang.authlib.yggdrasil.ProfileNotFoundException;
|
||||
import com.mojang.authlib.yggdrasil.ProfileResult;
|
||||
import com.viaversion.viaversion.api.minecraft.GameProfile;
|
||||
import net.raphimc.vialegacy.protocol.release.r1_7_6_10tor1_8.provider.GameProfileFetcher;
|
||||
import net.raphimc.viaproxy.proxy.external_interface.AuthLibServices;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
public class ViaProxyGameProfileFetcher extends GameProfileFetcher {
|
||||
|
||||
@Override
|
||||
public UUID loadMojangUuid(final String playerName) throws ExecutionException, InterruptedException {
|
||||
final CompletableFuture<com.mojang.authlib.GameProfile> future = new CompletableFuture<>();
|
||||
AuthLibServices.PROFILE_REPOSITORY.findProfilesByNames(new String[]{playerName}, new ProfileLookupCallback() {
|
||||
@Override
|
||||
public void onProfileLookupSucceeded(final com.mojang.authlib.GameProfile gameProfile) {
|
||||
future.complete(gameProfile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProfileLookupFailed(final String profileName, final Exception exception) {
|
||||
future.completeExceptionally(exception);
|
||||
}
|
||||
});
|
||||
if (!future.isDone()) {
|
||||
future.completeExceptionally(new ProfileNotFoundException());
|
||||
}
|
||||
return future.get().getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameProfile loadGameProfile(final UUID uuid) {
|
||||
final ProfileResult result = AuthLibServices.SESSION_SERVICE.fetchProfile(uuid, true);
|
||||
if (result == null) {
|
||||
throw new ProfileNotFoundException();
|
||||
}
|
||||
|
||||
final com.mojang.authlib.GameProfile gameProfile = result.profile();
|
||||
final GameProfile.Property[] properties = new GameProfile.Property[gameProfile.getProperties().size()];
|
||||
int i = 0;
|
||||
for (final Map.Entry<String, Property> entry : gameProfile.getProperties().entries()) {
|
||||
properties[i++] = new GameProfile.Property(entry.getValue().name(), entry.getValue().value(), entry.getValue().signature());
|
||||
}
|
||||
return new GameProfile(gameProfile.getName(), gameProfile.getId(), properties);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2026 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.raphimc.viaproxy.protocoltranslator.providers;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import io.netty.channel.Channel;
|
||||
import net.lenni0451.commons.unchecked.Sneaky;
|
||||
import net.raphimc.netminecraft.constants.MCPipeline;
|
||||
import net.raphimc.viabedrock.api.io.compression.ProtocolCompression;
|
||||
import net.raphimc.viabedrock.netty.CompressionCodec;
|
||||
import net.raphimc.viabedrock.netty.raknet.AesEncryptionCodec;
|
||||
import net.raphimc.viabedrock.netty.raknet.MessageCodec;
|
||||
import net.raphimc.viabedrock.protocol.provider.NettyPipelineProvider;
|
||||
import net.raphimc.viaproxy.proxy.session.ProxyConnection;
|
||||
|
||||
import javax.crypto.SecretKey;
|
||||
|
||||
public class ViaProxyNettyPipelineProvider extends NettyPipelineProvider {
|
||||
|
||||
@Override
|
||||
public void enableCompression(UserConnection user, ProtocolCompression protocolCompression) {
|
||||
final ProxyConnection proxyConnection = ProxyConnection.fromUserConnection(user);
|
||||
final Channel channel = proxyConnection.getChannel();
|
||||
|
||||
if (channel.pipeline().names().contains(MCPipeline.COMPRESSION_HANDLER_NAME)) {
|
||||
throw new IllegalStateException("Compression already enabled");
|
||||
}
|
||||
|
||||
channel.pipeline().addBefore(MCPipeline.SIZER_HANDLER_NAME, MCPipeline.COMPRESSION_HANDLER_NAME, new CompressionCodec(protocolCompression));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enableEncryption(UserConnection user, SecretKey key) {
|
||||
final ProxyConnection proxyConnection = ProxyConnection.fromUserConnection(user);
|
||||
final Channel channel = proxyConnection.getChannel();
|
||||
|
||||
if (channel.pipeline().names().contains(MCPipeline.ENCRYPTION_HANDLER_NAME)) {
|
||||
throw new IllegalStateException("Encryption already enabled");
|
||||
}
|
||||
|
||||
if (channel.pipeline().get(MessageCodec.NAME) != null) { // Only enable encryption for RakNet connections
|
||||
try {
|
||||
channel.pipeline().addAfter(MessageCodec.NAME, MCPipeline.ENCRYPTION_HANDLER_NAME, new AesEncryptionCodec(key));
|
||||
} catch (Throwable e) {
|
||||
Sneaky.sneakyThrow(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2026 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.raphimc.viaproxy.protocoltranslator.providers;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import net.raphimc.vialegacy.protocol.release.r1_2_4_5tor1_3_1_2.provider.OldAuthProvider;
|
||||
import net.raphimc.viaproxy.proxy.external_interface.ExternalInterface;
|
||||
import net.raphimc.viaproxy.proxy.session.ProxyConnection;
|
||||
|
||||
public class ViaProxyOldAuthProvider extends OldAuthProvider {
|
||||
|
||||
@Override
|
||||
public void sendAuthRequest(final UserConnection user, final String serverId) throws Throwable {
|
||||
ExternalInterface.joinServer(serverId, ProxyConnection.fromUserConnection(user));
|
||||
}
|
||||
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue