forked from Sandertv/go-raknet
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit b08a1dd
Showing
34 changed files
with
3,024 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
version = 1 | ||
|
||
[[analyzers]] | ||
name = "go" | ||
enabled = true | ||
|
||
[analyzers.meta] | ||
import_root = "github.com/Sandertv/go-raknet" | ||
dependencies_vendored = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
name: Go | ||
on: [push] | ||
jobs: | ||
|
||
build: | ||
name: Build | ||
runs-on: ubuntu-latest | ||
steps: | ||
|
||
- name: Set up Go 1.19 | ||
uses: actions/setup-go@v1 | ||
with: | ||
go-version: 1.19 | ||
id: go | ||
|
||
- name: Check out code into the Go module directory | ||
uses: actions/checkout@v1 | ||
|
||
- name: Get dependencies | ||
run: | | ||
mkdir -p $GOPATH/bin | ||
export PATH=$PATH:$GOPATH/bin | ||
- name: Vet | ||
run: go vet ./... | ||
|
||
- name: Staticcheck | ||
run: | | ||
go get honnef.co/go/tools/cmd/staticcheck | ||
GOBIN=$PWD/bin go install honnef.co/go/tools/cmd/staticcheck | ||
./bin/staticcheck ./... | ||
- name: Build | ||
run: go build -o raknet_exe -v . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# Created by .ignore support plugin (hsz.mobi) | ||
### Go template | ||
# Binaries for programs and plugins | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
*.so | ||
*.dylib | ||
|
||
# Test binary, build with `go test -c` | ||
*.test | ||
|
||
# Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out | ||
### JetBrains template | ||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm | ||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 | ||
|
||
# User-specific stuff | ||
idea/ | ||
|
||
.idea/**/workspace.xml | ||
.idea/**/tasks.xml | ||
.idea/**/dictionaries | ||
.idea/**/shelf | ||
|
||
# Sensitive or high-churn files | ||
.idea/**/dataSources/ | ||
.idea/**/dataSources.ids | ||
.idea/**/dataSources.local.xml | ||
.idea/**/sqlDataSources.xml | ||
.idea/**/dynamic.xml | ||
.idea/**/uiDesigner.xml | ||
.idea/**/dbnavigator.xml | ||
|
||
# Gradle | ||
.idea/**/gradle.xml | ||
.idea/**/libraries | ||
|
||
# CMake | ||
cmake-build-debug/ | ||
cmake-build-release/ | ||
|
||
# Mongo Explorer plugin | ||
.idea/**/mongoSettings.xml | ||
|
||
# File-based project format | ||
*.iws | ||
|
||
# IntelliJ | ||
out/ | ||
|
||
# mpeltonen/sbt-idea plugin | ||
.idea_modules/ | ||
|
||
# JIRA plugin | ||
atlassian-ide-plugin.xml | ||
|
||
# Cursive Clojure plugin | ||
.idea/replstate.xml | ||
|
||
# Crashlytics plugin (for Android Studio and IntelliJ) | ||
com_crashlytics_export_strings.xml | ||
crashlytics.properties | ||
crashlytics-build.properties | ||
fabric.properties | ||
|
||
# Editor-based Rest Client | ||
.idea/httpRequests | ||
|
||
.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2019 Sander ten Veldhuis | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# go-raknet | ||
|
||
go-raknet is a library that implements a basic version of the RakNet protocol, which is used for | ||
Minecraft (Bedrock Edition). It implements Unreliable, Reliable and | ||
ReliableOrdered packets and sends user packets as ReliableOrdered. | ||
|
||
go-raknet attempts to abstract away direct interaction with RakNet, and provides simple to use, idiomatic Go | ||
API used to listen for connections or connect to servers. | ||
|
||
## Getting started | ||
|
||
### Prerequisites | ||
To use this library, at least **Go 1.18** must be installed. | ||
|
||
### Usage | ||
go-raknet can be used for both clients and servers, (and proxies, when combined) in a way very similar to the | ||
standard net.TCP* functions. | ||
|
||
Basic RakNet server: | ||
```go | ||
package main | ||
|
||
import ( | ||
"github.com/sandertv/go-raknet" | ||
) | ||
|
||
func main() { | ||
listener, _ := raknet.Listen("0.0.0.0:19132") | ||
defer listener.Close() | ||
for { | ||
conn, _ := listener.Accept() | ||
|
||
b := make([]byte, 1024*1024*4) | ||
_, _ = conn.Read(b) | ||
_, _ = conn.Write([]byte{1, 2, 3}) | ||
|
||
conn.Close() | ||
} | ||
} | ||
``` | ||
|
||
Basic RakNet client: | ||
|
||
```go | ||
package main | ||
|
||
import ( | ||
"github.com/sandertv/go-raknet" | ||
) | ||
|
||
func main() { | ||
conn, _ := raknet.Dial("mco.mineplex.com:19132") | ||
defer conn.Close() | ||
|
||
b := make([]byte, 1024*1024*4) | ||
_, _ = conn.Write([]byte{1, 2, 3}) | ||
_, _ = conn.Read(b) | ||
} | ||
``` | ||
|
||
### Documentation | ||
[![PkgGoDev](https://pkg.go.dev/badge/github.com/sandertv/go-raknet)](https://pkg.go.dev/github.com/sandertv/go-raknet) | ||
|
||
## Contact | ||
[![Discord Banner 2](https://discordapp.com/api/guilds/623638955262345216/widget.png?style=banner2)](https://discord.gg/U4kFWHhTNR) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package raknet | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
) | ||
|
||
// uint24 represents an integer existing out of 3 bytes. It is actually a uint32, but is an alias for the | ||
// sake of clarity. | ||
type uint24 uint32 | ||
|
||
// readUint24 reads 3 bytes from the buffer passed and combines it into a uint24. If there were no 3 bytes to | ||
// read, an error is returned. | ||
func readUint24(b *bytes.Buffer) (uint24, error) { | ||
ba, _ := b.ReadByte() | ||
bb, _ := b.ReadByte() | ||
bc, err := b.ReadByte() | ||
if err != nil { | ||
return 0, fmt.Errorf("error reading uint24: %v", err) | ||
} | ||
return uint24(ba) | (uint24(bb) << 8) | (uint24(bc) << 16), nil | ||
} | ||
|
||
// writeUint24 writes a uint24 to the buffer passed as 3 bytes. If not successful, an error is returned. | ||
func writeUint24(b *bytes.Buffer, value uint24) { | ||
b.WriteByte(byte(value)) | ||
b.WriteByte(byte(value >> 8)) | ||
b.WriteByte(byte(value >> 16)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package raknet | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
) | ||
|
||
func Test_uint24(t *testing.T) { | ||
b := bytes.NewBuffer(nil) | ||
writeUint24(b, 123456) | ||
val, err := readUint24(b) | ||
if err != nil { | ||
t.Fatalf("error reading uint24: %v", err) | ||
} | ||
if val != 123456 { | ||
t.Fatal("read uint24 was not equal to 123456") | ||
} | ||
} |
Oops, something went wrong.