Skip to content
This repository was archived by the owner on Jan 19, 2024. It is now read-only.

Initial implementations 🎉 #29

Open
wants to merge 144 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
144 commits
Select commit Hold shift + click to select a range
792ee19
feat: implemented lhcore and transports
GalvinGao Jun 17, 2022
c93004d
fix(deps): update module github.com/rs/zerolog to v1.27.0
renovate-bot Jun 17, 2022
0831f99
Merge pull request #4 from penguin-statistics/renovate/github.ghproxy.top-rs-…
GalvinGao Jun 17, 2022
8cfa4cd
feat: add lhcore, wshub & pubsub impl
GalvinGao Jun 18, 2022
3ac2684
feat: lhcore improvement
GalvinGao Jun 21, 2022
2974083
fix(deps): update module github.com/gofiber/websocket/v2 to v2.0.24
renovate[bot] Aug 3, 2022
50ff39c
Merge pull request #6 from penguin-statistics/renovate/github.ghproxy.top-gof…
GalvinGao Aug 3, 2022
748ee59
fix(deps): update module github.com/gofiber/helmet/v2 to v2.2.15
renovate[bot] Aug 3, 2022
3652b74
fix(deps): update module google.golang.org/grpc to v1.48.0
renovate[bot] Aug 3, 2022
dea3b76
Merge pull request #8 from penguin-statistics/renovate/github.ghproxy.top-gof…
GalvinGao Aug 3, 2022
019fa44
Merge pull request #7 from penguin-statistics/renovate/google.golang.…
GalvinGao Aug 3, 2022
1bb81d1
fix(deps): update module google.golang.org/protobuf to v1.28.1
renovate[bot] Aug 3, 2022
49d00d2
chore(deps): update dependency golang to v1.19.0
renovate[bot] Aug 3, 2022
9921f42
chore(deps): update module go to 1.19
renovate[bot] Aug 3, 2022
a4939dc
Merge pull request #11 from penguin-statistics/renovate/go-1.x
GalvinGao Aug 25, 2022
d2e8844
Merge pull request #10 from penguin-statistics/renovate/golang-1.x
GalvinGao Aug 25, 2022
b0d52da
Merge pull request #9 from penguin-statistics/renovate/google.golang.…
GalvinGao Aug 25, 2022
11114f8
fix(deps): update module github.com/prometheus/client_golang to v1.13.0
renovate[bot] Aug 25, 2022
88a7f6a
fix(deps): update module go.uber.org/fx to v1.18.1
renovate[bot] Aug 25, 2022
6033005
Merge pull request #13 from penguin-statistics/renovate/go.uber.org-f…
GalvinGao Aug 25, 2022
81d9267
Merge pull request #12 from penguin-statistics/renovate/github.ghproxy.top-pr…
GalvinGao Aug 25, 2022
1c2cb8b
build: use unified actions
GalvinGao Aug 26, 2022
505e758
feat: improve logger configuration
GalvinGao Aug 26, 2022
05a7e15
fix(deps): update module github.com/gofiber/helmet/v2 to v2.2.16
renovate[bot] Aug 31, 2022
2d6901e
Merge pull request #17 from penguin-statistics/renovate/github.ghproxy.top-go…
GalvinGao Sep 1, 2022
7adeca6
fix(deps): update module github.com/gofiber/websocket/v2 to v2.0.25
renovate[bot] Sep 1, 2022
cb4251a
fix(deps): update module github.com/rs/zerolog to v1.28.0
renovate[bot] Sep 1, 2022
bab24a4
Merge pull request #15 from penguin-statistics/renovate/github.ghproxy.top-rs…
GalvinGao Sep 5, 2022
1a93c67
Merge pull request #18 from penguin-statistics/renovate/github.ghproxy.top-go…
GalvinGao Sep 5, 2022
fc8f875
fix(deps): update module google.golang.org/grpc to v1.49.0
renovate[bot] Sep 5, 2022
18127bd
chore(deps): update golang docker tag to v1.19.1
renovate[bot] Sep 6, 2022
5d95c40
Merge pull request #19 from penguin-statistics/renovate/golang-1.x
GalvinGao Sep 6, 2022
0506452
Merge pull request #14 from penguin-statistics/renovate/google.golang…
GalvinGao Sep 6, 2022
9029e9d
fix(deps): update module github.com/gofiber/fiber/v2 to v2.37.1
renovate[bot] Sep 8, 2022
45aaf53
Merge pull request #20 from penguin-statistics/renovate/github.ghproxy.top-go…
GalvinGao Sep 11, 2022
42b3e7c
fix(deps): update module github.com/getsentry/sentry-go to v0.14.0
renovate[bot] Oct 4, 2022
9409a6c
Merge pull request #24 from penguin-statistics/renovate/github.ghproxy.top-ge…
GalvinGao Oct 4, 2022
53ea04d
chore(deps): update golang docker tag to v1.19.2
renovate[bot] Oct 4, 2022
e6270ac
fix(deps): update module go.uber.org/fx to v1.18.2
renovate[bot] Oct 4, 2022
903c59e
fix(deps): update module github.com/gofiber/fiber/v2 to v2.38.1
renovate[bot] Oct 4, 2022
6703d7a
fix(deps): update module github.com/nats-io/nats.go to v1.17.0
renovate[bot] Oct 4, 2022
d2e4306
Merge pull request #22 from penguin-statistics/renovate/github.ghproxy.top-go…
GalvinGao Oct 5, 2022
c42aa88
Merge pull request #25 from penguin-statistics/renovate/golang-1.x
GalvinGao Oct 5, 2022
3018317
Merge pull request #21 from penguin-statistics/renovate/github.ghproxy.top-na…
GalvinGao Oct 5, 2022
95ed921
Merge pull request #23 from penguin-statistics/renovate/go.uber.org-f…
GalvinGao Oct 5, 2022
afd2d8a
fix(deps): update module google.golang.org/grpc to v1.50.0
renovate[bot] Oct 6, 2022
cfce644
Merge pull request #28 from penguin-statistics/renovate/google.golang…
GalvinGao Oct 6, 2022
07decdf
fix(deps): update module github.com/gofiber/websocket/v2 to v2.1.0
renovate[bot] Oct 6, 2022
673922c
feat: improve livehouse impl
GalvinGao Oct 6, 2022
303e17c
chore: update modules
GalvinGao Oct 6, 2022
c536a14
test: add several scripts
GalvinGao Oct 6, 2022
96c0878
feat(pb): add error to subscribe resp
GalvinGao Oct 6, 2022
b72638d
feat: improve log level
GalvinGao Oct 6, 2022
db30c49
Merge pull request #27 from penguin-statistics/renovate/github.ghproxy.top-go…
GalvinGao Oct 6, 2022
f4444eb
feat: add multi-server support
GalvinGao Oct 7, 2022
4b132fc
fix: use correct bit amounts for IDSet
GalvinGao Oct 7, 2022
018000e
fix(deps): update module github.com/gofiber/helmet/v2 to v2.2.17
renovate[bot] Oct 7, 2022
d4e6681
Merge pull request #26 from penguin-statistics/renovate/github.ghproxy.top-go…
GalvinGao Oct 7, 2022
8e9952c
fix(deps): update module github.com/samber/lo to v1.31.0
renovate[bot] Oct 7, 2022
f0e9d04
Merge pull request #30 from penguin-statistics/renovate/github.ghproxy.top-sa…
GalvinGao Oct 7, 2022
5acfe0e
feat: add devtools
GalvinGao Oct 8, 2022
3d3ba32
chore: improve wording for `reports`
GalvinGao Oct 8, 2022
24765df
test: add matchtest
GalvinGao Oct 8, 2022
5361494
chore: play around
GalvinGao Oct 8, 2022
53bae70
fix: zero times
GalvinGao Oct 8, 2022
fba8a1d
feat: execute separate of concerns
GalvinGao Oct 8, 2022
2289a17
fix(deps): update module github.com/samber/lo to v1.32.0
renovate[bot] Oct 10, 2022
f86b5c5
Merge pull request #31 from penguin-statistics/renovate/github.ghproxy.top-sa…
GalvinGao Oct 11, 2022
47c40a0
feat: improve lhcore file structure
GalvinGao Oct 8, 2022
d628f2b
refactor: rename scripts
GalvinGao Oct 12, 2022
05c1c45
tests: add tests
GalvinGao Oct 12, 2022
af327b4
chore(gopkg): change import path to exusiai.dev/livehouse
GalvinGao Oct 12, 2022
865c8d6
refactor(gommon): use gommon
GalvinGao Oct 12, 2022
7455d11
chore: update LICENSE year
GalvinGao Oct 12, 2022
11b74af
refactor(gommon): use gommon for pb models
GalvinGao Oct 12, 2022
c20e866
fix(deps): update module github.com/nats-io/nats.go to v1.18.0
renovate[bot] Oct 12, 2022
9324989
Merge pull request #32 from penguin-statistics/renovate/github.ghproxy.top-na…
GalvinGao Oct 13, 2022
1bbccd2
fix(deps): update module google.golang.org/grpc to v1.50.1
renovate[bot] Oct 14, 2022
b5a55b0
Merge pull request #34 from penguin-statistics/renovate/google.golang…
GalvinGao Oct 15, 2022
be5253a
fix(deps): update module github.com/samber/lo to v1.33.0
renovate[bot] Oct 14, 2022
0b76eb5
fix(deps): update module exusiai.dev/gommon to v0.0.4
renovate[bot] Oct 22, 2022
d08f95b
fix(deps): update module github.com/gofiber/fiber/v2 to v2.39.0
renovate[bot] Oct 23, 2022
8f29e0a
fix(deps): update module github.com/stretchr/testify to v1.8.1
renovate[bot] Oct 24, 2022
dfa4acf
fix(deps): update module github.com/gofiber/websocket/v2 to v2.1.1
renovate[bot] Oct 24, 2022
b65f48a
fix(deps): update module github.com/gofiber/helmet/v2 to v2.2.18
renovate[bot] Oct 24, 2022
1cd5abd
chore(deps): update golang docker tag to v1.19.3
renovate[bot] Nov 1, 2022
473fd2d
fix(deps): update module github.com/prometheus/client_golang to v1.13.1
renovate[bot] Nov 2, 2022
a6c70be
build: add golang.org/x/exp to ignoreDeps
GalvinGao Nov 9, 2022
6d52938
fix(deps): update module github.com/prometheus/client_golang to v1.14.0
renovate[bot] Nov 8, 2022
359ded4
fix(deps): update module github.com/samber/lo to v1.34.0
renovate[bot] Nov 12, 2022
93d7798
fix(deps): update module github.com/gofiber/helmet/v2 to v2.2.21
renovate[bot] Nov 11, 2022
5579794
fix(deps): update module github.com/getsentry/sentry-go to v0.15.0
renovate[bot] Nov 9, 2022
8e88a91
fix(deps): update module github.com/nats-io/nats.go to v1.20.0
renovate[bot] Nov 11, 2022
4a38113
fix(deps): update module github.com/samber/lo to v1.35.0
renovate[bot] Nov 15, 2022
c3bf7bc
fix(deps): update module github.com/gofiber/fiber/v2 to v2.40.0
renovate[bot] Nov 18, 2022
92e953e
fix(deps): update module github.com/gofiber/websocket/v2 to v2.1.2
renovate[bot] Nov 24, 2022
b732b69
fix(deps): update module github.com/tidwall/gjson to v1.14.4
renovate[bot] Nov 22, 2022
61f9dd9
fix(deps): update module google.golang.org/grpc to v1.51.0
renovate[bot] Nov 18, 2022
3599554
fix(deps): update module github.com/gofiber/helmet/v2 to v2.2.22
renovate[bot] Nov 25, 2022
621e7ff
fix(deps): update module github.com/samber/lo to v1.36.0
renovate[bot] Nov 28, 2022
1d5267d
chore(deps): update golang docker tag to v1.19.4
renovate[bot] Dec 6, 2022
1aa9b9e
fix(deps): update module github.com/getsentry/sentry-go to v0.16.0
renovate[bot] Dec 7, 2022
cf88399
fix(deps): update module github.com/samber/lo to v1.37.0
renovate[bot] Dec 15, 2022
af749de
fix(deps): update module github.com/nats-io/nats.go to v1.21.0
renovate[bot] Dec 5, 2022
fd64cc4
fix(deps): update module github.com/nats-io/nats.go to v1.22.0
renovate[bot] Dec 20, 2022
3f20c4e
fix(deps): update module github.com/nats-io/nats.go to v1.22.1
renovate[bot] Dec 22, 2022
8df43e6
chore(deps): update golang docker tag to v1.19.5
renovate[bot] Jan 11, 2023
a94a043
fix(deps): update module github.com/gofiber/fiber/v2 to v2.41.0
renovate[bot] Jan 3, 2023
8e24d93
fix(deps): update module github.com/gofiber/helmet/v2 to v2.2.23
renovate[bot] Jan 17, 2023
f20cfb4
fix(deps): update module github.com/getsentry/sentry-go to v0.17.0
renovate[bot] Jan 12, 2023
6979edd
fix(deps): update module exusiai.dev/gommon to v0.0.5
renovate[bot] Jan 6, 2023
2bbca4f
fix(deps): update module google.golang.org/grpc to v1.52.3
renovate[bot] Jan 25, 2023
6c80c0f
fix(deps): update module github.com/fasthttp/websocket to v1.5.1
renovate[bot] Jan 20, 2023
4dd067b
fix(deps): update module github.com/nats-io/nats.go to v1.23.0
renovate[bot] Jan 26, 2023
85bcc5a
fix(deps): update module github.com/gofiber/websocket/v2 to v2.1.3
renovate[bot] Jan 19, 2023
e872125
fix(deps): update module github.com/go-redis/redis/v8 to v9
renovate[bot] Jan 30, 2023
855343a
chore(deps): update to github.com/redis/go-redis/v9
GalvinGao Jan 30, 2023
6375615
fix(deps): update module github.com/rs/zerolog to v1.29.0
renovate[bot] Jan 30, 2023
fe830ae
build(deps): bump github.com/nats-io/nats-server/v2 from 2.7.3 to 2.7.4
dependabot[bot] Jan 30, 2023
17c8c5a
fix(deps): update module github.com/redis/go-redis/v9 to v9.0.2
renovate[bot] Feb 1, 2023
77a20e7
fix(deps): update module github.com/joho/godotenv to v1.5.0
renovate[bot] Feb 4, 2023
f763508
fix(deps): update module github.com/gofiber/fiber/v2 to v2.42.0
renovate[bot] Feb 3, 2023
46ad87a
fix(deps): update module github.com/gofiber/websocket/v2 to v2.1.4
renovate[bot] Feb 5, 2023
71c9b94
chore(deps): update golang docker tag to v1.20.0
renovate[bot] Feb 1, 2023
93765ad
fix(deps): update module github.com/gofiber/helmet/v2 to v2.2.24
renovate[bot] Feb 6, 2023
16db061
fix(deps): update module google.golang.org/grpc to v1.53.0
renovate[bot] Feb 14, 2023
650e210
fix(deps): update module github.com/joho/godotenv to v1.5.1
renovate[bot] Feb 6, 2023
bc2fc6e
chore(deps): update golang docker tag to v1.20.1
renovate[bot] Feb 15, 2023
5df2e0e
fix(deps): update module github.com/getsentry/sentry-go to v0.18.0
renovate[bot] Feb 7, 2023
589230e
fix(deps): update module gopkg.in/natefinch/lumberjack.v2 to v2.2.1
renovate[bot] Feb 7, 2023
e0b663d
fix(deps): update module github.com/nats-io/nats.go to v1.24.0
renovate[bot] Feb 24, 2023
b3c6e1e
fix(deps): update module github.com/getsentry/sentry-go to v0.19.0
renovate[bot] Mar 6, 2023
7ed81bc
chore(deps): update golang docker tag to v1.20.2
renovate[bot] Mar 8, 2023
daaae40
fix(deps): update module github.com/stretchr/testify to v1.8.2
renovate[bot] Feb 25, 2023
ef3c499
fix(deps): update module github.com/samber/lo to v1.38.0
renovate[bot] Mar 20, 2023
848f5d1
fix(deps): update module github.com/samber/lo to v1.38.1
renovate[bot] Mar 21, 2023
6fb9cb3
fix(deps): update module google.golang.org/protobuf to v1.31.0
renovate[bot] Jun 26, 2023
e5f4926
fix(deps): update module google.golang.org/grpc to v1.56.2
renovate[bot] Jul 7, 2023
4a90084
chore(deps): update golang docker tag to v1.20.6
renovate[bot] Jul 11, 2023
c8a43e1
fix(deps): update module exusiai.dev/gommon to v0.0.8
renovate[bot] Oct 10, 2023
8fa1b75
fix(deps): update module github.com/fasthttp/websocket to v1.5.4
renovate[bot] Oct 12, 2023
ace6c0f
fix(deps): update module go.uber.org/fx to v1.20.0
renovate[bot] Oct 12, 2023
fbdcd9b
chore(deps): update golang docker tag to v1.21.3
renovate[bot] Oct 12, 2023
6b3b694
fix(deps): update module github.com/getsentry/sentry-go to v0.25.0
renovate[bot] Oct 12, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 8 additions & 28 deletions .github/workflows/build-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,13 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: "Checkout"
uses: actions/checkout@v3

# - name: Run Snyk to check for vulnerabilities
# uses: snyk/actions/golang@master
# continue-on-error: true
# env:
# SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
# with:
# args: --sarif-file-output=snyk.sarif

# - name: Get Tag Version
# id: get_version
# run: |
# export TRUNCATED_GITHUB_SHA=$(echo ${{ github.sha }} | cut -c1-7);
# echo "VERSION=${GITHUB_REF/refs\/tags\//}+${TRUNCATED_GITHUB_SHA}" >> $GITHUB_ENV
# echo "GIT_TAG=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV

# - name: Log in to the Container registry
# uses: docker/[email protected]
# with:
# registry: ${{ env.REGISTRY }}
# username: ${{ github.actor }}
# password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push Docker image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
- name: "Docker: Build and Push Image"
id: ghcr-docker
uses: 'penguin-statistics/actions/ghcr-docker@main'
with:
context: .
push: false # for check workflow, we don't want to push
tags: penguin-statistics/livehouse:${{ github.sha }}
version: '__check__'
repository: 'penguin-statistics/livehouse'
push: false
71 changes: 24 additions & 47 deletions .github/workflows/build-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,52 +14,29 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

# - name: Run Snyk to check for vulnerabilities
# uses: snyk/actions/golang@master
# continue-on-error: true
# env:
# SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
# with:
# args: --sarif-file-output=snyk.sarif

# - name: Upload result to GitHub Code Scanning
# uses: github/codeql-action/upload-sarif@v1
# with:
# sarif_file: snyk.sarif

# - name: Run golangci-lint
# uses: golangci/[email protected]

- name: Get Tag Version
id: get_version
run: |
export TRUNCATED_GITHUB_SHA=$(echo ${{ github.sha }} | cut -c1-7);
echo "VERSION=${GITHUB_REF/refs\/tags\//}+${TRUNCATED_GITHUB_SHA}" >> $GITHUB_ENV
echo "GIT_TAG=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV

- name: Build and Publish to Registry
uses: elgohr/[email protected]
with:
name: penguin-statistics/livehouse
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
registry: ghcr.io
tags: "latest,${{ env.GIT_TAG }}"
buildargs: VERSION

- name: Create Sentry release
uses: getsentry/action-release@v1
env:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
SENTRY_ORG: ${{ secrets.SENTRY_ORG }}
SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }}
- name: "Checkout"
uses: actions/checkout@v3

- name: "Metadata: Git"
id: git-meta
uses: 'penguin-statistics/actions/git-meta@main'

- name: "Docker: Build and Push Image"
id: ghcr-docker
uses: 'penguin-statistics/actions/ghcr-docker@main'
with:
environment: prod
version: ${{ env.VERSION }}

- uses: "marvinpinto/action-automatic-releases@latest"
version: ${{ steps.git-meta.outputs.version }}
repository: 'penguin-statistics/livehouse'
build-args: |
BUILD_DOCS_COMMIT=fb08b08f5f97e89b2407e56c20b0707f19dc8f32
BUILD_WEB_COMMIT=451e3aef9973f6cd0d58cd60aa75961acf460b51

- name: "Release: Call Dispatcher"
id: release-dispatcher
uses: 'penguin-statistics/actions/release-dispatcher@main'
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
prerelease: false
version: ${{ steps.git-meta.outputs.version }}
use-ghrelease: true
# use-manifestbot: true
# manifestbot-file-path: 'applications/livehouse/values-prod.yaml'
# manifestbot-token: ${{ secrets.PAT_FOR_MANIFESTBOT }}
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ linters:
- exhaustive
- funlen
- goconst
- gocritic
# - gocritic
- gocyclo
# - revive
# - gomnd
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.18.3-alpine AS base
FROM golang:1.21.3-alpine AS base
WORKDIR /app

# builder
Expand All @@ -20,7 +20,7 @@ RUN go mod download
COPY . .

# inject versioning information & build the binary
RUN export BUILD_TIME=$(date -u +"%Y-%m-%dT%H:%M:%SZ"); go build -o livehouse -ldflags "-X github.com/penguin-statistics/livehouse/internal/pkg/bininfo.Version=$VERSION -X github.com/penguin-statistics/livehouse/internal/pkg/bininfo.BuildTime=$BUILD_TIME" .
RUN export BUILD_TIME=$(date -u +"%Y-%m-%dT%H:%M:%SZ"); go build -o livehouse -ldflags "-X exusiai.dev/livehouse/internal/pkg/bininfo.Version=$VERSION -X exusiai.dev/livehouse/internal/pkg/bininfo.BuildTime=$BUILD_TIME" .

# runner
FROM base AS runner
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 Penguin Statistics
Copyright (c) 2022 Penguin Statistics

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
111 changes: 111 additions & 0 deletions cmd/scripts/matchtest/matchtest.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package main

import (
"fmt"
"log"
"net/http"

"github.com/fasthttp/websocket"
"github.com/samber/lo"
"google.golang.org/protobuf/proto"

"exusiai.dev/gommon/model/pb"
)

var (
StageID = uint32(18)
Generation = uint64(0)
)

func genreq(drops []*pb.Drop) *pb.ReportBatchRequest {
return &pb.ReportBatchRequest{
Reports: []*pb.Report{
{
Server: pb.Server_CN,
Generation: Generation,
StageId: StageID,
Drops: drops,
},
},
}
}

func main() {
// conn := lo.Must(grpc.Dial("localhost:9015", grpc.WithInsecure()))

// client := pb.NewConnectedLiveServiceClient(conn)
// lo.Must(client.PushReportBatch(context.Background(), genreq([]*pb.Drop{{
// ItemId: 1,
// Quantity: 1,
// }})))

req := pb.MatrixUpdateSubscribeReq{
Id: &pb.MatrixUpdateSubscribeReq_ItemId{
ItemId: 38,
},
}

b, err := proto.Marshal(&req)
if err != nil {
log.Fatalln(err)
}

wsconn, resp, err := websocket.DefaultDialer.Dial("ws://localhost:9020/live", http.Header{
"Sec-WebSocket-Protocol": []string{"v3.penguin-stats.live+proto"},
})
if err != nil {
log.Fatalln("dial error:", err, resp)
}

err = wsconn.WriteMessage(websocket.BinaryMessage, b)
if err != nil {
log.Fatalln("write error:", err)
}

go func() {
for {
_, msg, err := wsconn.ReadMessage()
if err != nil {
log.Fatalln("read error:", err)
}

var msgresp pb.MatrixUpdateMessage
proto.Unmarshal(msg, &msgresp)

log.Print("received the following updates:\n", lo.Reduce(msgresp.Segments, func(acc string, seg *pb.MatrixUpdateMessage_Element, _ int) string {
return acc + fmt.Sprintf(" - server=%s, stage=%d, item=%d, times=%d, quantity=%d\n", seg.Server, seg.StageId, seg.ItemId, seg.Times, seg.Quantity)
}, ""))
}
}()

// lo.Must(client.PushReportBatch(context.Background(), genreq([]*pb.Drop{})))

// log.Println("expect quantity = 1, times = 2")
// time.Sleep(time.Second * 10)

// lo.Must(client.PushReportBatch(context.Background(), genreq([]*pb.Drop{
// {
// ItemId: 1,
// Quantity: 1,
// },
// })))

// log.Println("expect quantity = 2, times = 3")
// time.Sleep(time.Second * 10)

// lo.Must(client.PushReportBatch(context.Background(), genreq([]*pb.Drop{
// {
// ItemId: 1,
// Quantity: 2,
// },
// })))

// log.Println("expect quantity = 4, times = 4")
// time.Sleep(time.Second * 10)

// lo.Must(client.PushReportBatch(context.Background(), genreq([]*pb.Drop{})))

// log.Println("expect quantity = 4, times = 5")

select {}
}
25 changes: 25 additions & 0 deletions cmd/scripts/pbmsgs/pbmsgs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package main

import (
"log"

"google.golang.org/protobuf/proto"

"exusiai.dev/gommon/model/pb"
)

func main() {
stageId := uint32(175)
req := pb.MatrixUpdateSubscribeReq{
Id: &pb.MatrixUpdateSubscribeReq_StageId{
StageId: stageId,
},
}

b, err := proto.Marshal(&req)
if err != nil {
log.Fatalln(err)
}

log.Printf("update subscription with stageId = %d (hex): %x", stageId, b)
}
97 changes: 97 additions & 0 deletions cmd/scripts/pushbench/pushbench.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package main

import (
"context"
"io"
"log"
"math/rand"
"net/http"
"time"

"github.com/samber/lo"
"github.com/tidwall/gjson"
"google.golang.org/grpc"

"exusiai.dev/gommon/model/pb"
)

func penguinV3GetRequest(path string) []byte {
log.Println("Fetching", path)
r := lo.Must(http.NewRequest("GET", "https://penguin-stats.io/api/v3alpha"+path, nil))
r.Header.Set("Accept", "application/vnd.penguin.v3+json")
resp := lo.Must(http.DefaultClient.Do(r))
defer resp.Body.Close()
return lo.Must(io.ReadAll(resp.Body))
}

func penguinItemIds() []uint32 {
resp := penguinV3GetRequest("/items")
gj := gjson.ParseBytes(resp).Array()
ids := make([]uint32, len(gj))
for i, v := range gj {
ids[i] = uint32(v.Get("penguinItemId").Uint())
}
return ids
}

func penguinStageIds() []uint32 {
resp := penguinV3GetRequest("/stages")
gj := gjson.ParseBytes(resp).Array()
ids := make([]uint32, len(gj))
for i, v := range gj {
ids[i] = uint32(v.Get("penguinStageId").Uint())
}
return ids
}

func randomInSlice(slice []uint32) uint32 {
return slice[rand.Intn(len(slice))]
}

var Servers = []pb.Server{pb.Server_CN, pb.Server_US, pb.Server_JP, pb.Server_KR}

func main() {
conn, err := grpc.Dial("localhost:9015", grpc.WithInsecure())
if err != nil {
panic(err)
}
defer conn.Close()

rand.Seed(time.Now().UnixNano())

cl := pb.NewConnectedLiveServiceClient(conn)

items := penguinItemIds()
stages := penguinStageIds()

for {
fakeReportSize := rand.Intn(100) + 200

start := time.Now()
var req pb.ReportBatchRequest
req.Reports = make([]*pb.Report, fakeReportSize)
for i := 0; i < fakeReportSize; i++ {
drops := make([]*pb.Drop, rand.Intn(10)+1)
for j := range drops {
drops[j] = &pb.Drop{
ItemId: randomInSlice(items),
Quantity: rand.Uint64()%50 + 10,
}
}

req.Reports[i] = &pb.Report{
Server: Servers[rand.Intn(len(Servers))],
StageId: randomInSlice(stages),
Drops: drops,
}
}
log.Println("generated", fakeReportSize, "reports, took", time.Since(start))
start = time.Now()
_, err := cl.PushReportBatch(context.Background(), &req)
if err != nil {
log.Println(" failed to send report:", err)
}
log.Printf("sent reports and got ack. took %s", time.Since(start))
time.Sleep(500 * time.Millisecond)
}
}
Loading