Skip to content

Commit 5388a6f

Browse files
committed
refactor: Enhance Layout component and improve error handling in server links
- Updated Layout.vue to include a new MyGlobalButton component and improved template formatting. - Enhanced error handling in serverlinks.go by adding validation for server links count during decoding, ensuring it does not exceed the maximum limit.
1 parent 24014d8 commit 5388a6f

3 files changed

Lines changed: 59 additions & 18 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<template>
2+
<a
3+
target="_blank"
4+
class="fixed bottom-5 right-5 z-50"
5+
href="https://minekube.com/discord"
6+
>
7+
<button
8+
aria-label="Discord Support"
9+
class="flex items-center justify-center gap-[6px] w-fit h-fit rounded-full transition-all bg-white hover:bg-[var(--vp-button-brand-hover-bg)] stroke-black hover:stroke-[var(--vp-button-brand-hover-text)] px-4 py-3 sm:px-8 sm:py-4 font-[500] text-black hover:text-[var(--vp-button-brand-hover-text)] text-[16px] leading-[20.83px] sm:text-[19px] sm:leading-[25px] !px-[16px] !py-[13px] !max-sm:rounded-full !sm:rounded-br-none !text-[16px] !leading-[21px]"
10+
>
11+
<svg width="32" height="32" viewBox="0 0 32 33" fill="inherit">
12+
<path
13+
d="M26.1303 11.347C24.3138 9.93899 22.134 9.23502 19.8331 9.11768L19.4697 9.4697C21.5284 9.93899 23.345 10.8776 25.0404 12.1683C22.9817 11.1123 20.6807 10.4084 18.2587 10.1737C17.5321 10.0563 16.9266 10.0563 16.2 10.0563C15.4734 10.0563 14.8679 10.0563 14.1413 10.1737C11.7193 10.4084 9.41833 11.1123 7.35963 12.1683C9.05501 10.8776 10.8716 9.93899 12.9303 9.4697L12.5669 9.11768C10.266 9.23502 8.08621 9.93899 6.26972 11.347C4.21101 15.1017 3.1211 19.3257 3 23.6669C4.81649 25.5443 7.35963 26.7177 10.0239 26.7177C10.0239 26.7177 10.8716 25.779 11.477 24.9576C9.90277 24.6057 8.44954 23.7843 7.48074 22.4937C8.32843 22.963 9.17611 23.4323 10.0239 23.7843C11.1138 24.2537 12.2037 24.4883 13.2936 24.723C14.2624 24.8403 15.2312 24.9576 16.2 24.9576C17.1688 24.9576 18.1376 24.8403 19.1064 24.723C20.1963 24.4883 21.2862 24.2537 22.3761 23.7843C23.2239 23.4323 24.0716 22.963 24.9193 22.4937C23.9505 23.7843 22.4972 24.6057 20.923 24.9576C21.5284 25.779 22.3761 26.7177 22.3761 26.7177C25.0404 26.7177 27.5835 25.5443 29.4 23.6669C29.2789 19.3257 28.189 15.1017 26.1303 11.347ZM12.2037 21.555C10.9927 21.555 9.90278 20.499 9.90278 19.2084C9.90278 17.9177 10.9927 16.8617 12.2037 16.8617C13.4147 16.8617 14.5046 17.9177 14.5046 19.2084C14.5046 20.499 13.4147 21.555 12.2037 21.555ZM20.1963 21.555C18.9853 21.555 17.8954 20.499 17.8954 19.2084C17.8954 17.9177 18.9853 16.8617 20.1963 16.8617C21.4073 16.8617 22.4972 17.9177 22.4972 19.2084C22.4972 20.499 21.4073 21.555 20.1963 21.555Z"
14+
fill="inherit"
15+
></path>
16+
</svg>
17+
<div class="max-sm:hidden">Discord Support</div>
18+
</button>
19+
</a>
20+
</template>
Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,40 @@
11
<script setup>
2-
import DefaultTheme from 'vitepress/theme'
3-
import {useRouter} from 'vitepress';
4-
import {watch} from 'vue';
5-
import HomeHeroImage from "./HomeHeroImage.vue";
2+
import DefaultTheme from 'vitepress/theme';
3+
import { useRouter } from 'vitepress';
4+
import { watch } from 'vue';
5+
import HomeHeroImage from './HomeHeroImage.vue';
66
import LandingAfter from './LandingAfter.vue';
7+
import MyGlobalButton from './DiscordButton.vue';
78
8-
const {Layout} = DefaultTheme
9+
const { Layout } = DefaultTheme;
910
1011
const router = useRouter();
1112
1213
// Only run this on the client. Not during build
1314
if (typeof window !== 'undefined' && window.posthog) {
14-
watch(() => router.route.data.relativePath, (path) => {
15-
posthog.capture("$pageview");
16-
}, {immediate: true});
15+
watch(
16+
() => router.route.data.relativePath,
17+
(path) => {
18+
posthog.capture('$pageview');
19+
},
20+
{ immediate: true }
21+
);
1722
}
18-
1923
</script>
2024

2125
<template>
2226
<Layout>
2327
<template #home-hero-image>
24-
<HomeHeroImage/>
28+
<HomeHeroImage />
2529
</template>
2630
<template #home-features-after>
27-
<LandingAfter/>
31+
<LandingAfter />
32+
</template>
33+
<template #default>
34+
<slot />
35+
</template>
36+
<template #layout-bottom>
37+
<MyGlobalButton />
2838
</template>
2939
</Layout>
30-
</template>
40+
</template>

pkg/edition/java/proto/packet/serverlinks.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package packet
22

33
import (
4+
"fmt"
5+
"io"
6+
47
"go.minekube.com/gate/pkg/edition/java/proto/packet/chat"
58
protoutil "go.minekube.com/gate/pkg/edition/java/proto/util"
69
"go.minekube.com/gate/pkg/gate/proto"
7-
"io"
810
)
911

1012
type ServerLinks struct {
@@ -27,15 +29,24 @@ func (p *ServerLinks) Decode(c *proto.PacketContext, rd io.Reader) (err error) {
2729
r := protoutil.PanicReader(rd)
2830
var serverLinksCount int
2931
r.VarInt(&serverLinksCount)
32+
33+
if serverLinksCount < 0 {
34+
return fmt.Errorf("server links count %d cannot be negative", serverLinksCount)
35+
}
36+
const maxServerLinks = 128
37+
if serverLinksCount > maxServerLinks {
38+
return fmt.Errorf("too many server links (attempted %d, max %d)", serverLinksCount, maxServerLinks)
39+
}
40+
3041
p.ServerLinks = make([]*ServerLink, serverLinksCount)
3142
for i := 0; i < serverLinksCount; i++ {
32-
p.ServerLinks[i] = new(ServerLink)
33-
err = p.ServerLinks[i].Decode(c, rd)
34-
if err != nil {
35-
return err
43+
link := new(ServerLink)
44+
if err = link.Decode(c, rd); err != nil {
45+
return fmt.Errorf("error decoding server link index %d: %w", i, err)
3646
}
47+
p.ServerLinks[i] = link
3748
}
38-
return
49+
return nil
3950
}
4051

4152
type ServerLink struct {

0 commit comments

Comments
 (0)