Browse Source

init

tags/1.0.0
kami 7 months ago
commit
7f87d77257
12 changed files with 324 additions and 0 deletions
  1. +42
    -0
      .drone.yml
  2. +8
    -0
      .gitignore
  3. +1
    -0
      CHANGELOG.md
  4. +46
    -0
      OauthPlugin/pom.xml
  5. +38
    -0
      OauthPlugin/src/main/java/com/varelus/mc_oauth/JoinListener.java
  6. +17
    -0
      OauthPlugin/src/main/java/com/varelus/mc_oauth/OauthPlugin.java
  7. +5
    -0
      OauthPlugin/src/main/resources/plugin.yml
  8. +87
    -0
      README.md
  9. +1
    -0
      RELEASE.md
  10. +7
    -0
      api/build.sh
  11. +69
    -0
      api/server.go
  12. +3
    -0
      docker-golang-git/Dockerfile

+ 42
- 0
.drone.yml View File

@@ -0,0 +1,42 @@
kind: pipeline
name: default
steps:
- name: server
image: vardrop/golang-git
volumes:
- name: dist
path: /tmp/dist
commands:
- go get github.com/gorilla/mux
- chmod +x api/build.sh
- api/build.sh
- name: plugin
image: maven:latest
volumes:
- name: dist
path: /tmp/dist
commands:
- mvn clean install -f OauthPlugin/pom.xml
- mvn package -f OauthPlugin/pom.xml
- cp OauthPlugin/target/OauthPlugin* /tmp/dist/OauthPlugin.jar
- name: gitea_release
image: plugins/gitea-release
volumes:
- name: dist
path: /tmp/dist
settings:
api_key:
from_secret: gitea_token
base_url: https://git.varelus.com
files:
- /tmp/dist/*
checksum:
- md5
- sha1
title: RELEASE.md
note: CHANGELOG.md
when:
event: tag
volumes:
- name: dist
temp: {}

+ 8
- 0
.gitignore View File

@@ -0,0 +1,8 @@
spigot
server
.idea
*.iml
player.csv
dist
OauthPlugin/target
dockerconfig.json

+ 1
- 0
CHANGELOG.md View File

@@ -0,0 +1 @@
intial build

+ 46
- 0
OauthPlugin/pom.xml View File

@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.varelus.mc-oauth</groupId>
<artifactId>OauthPlugin</artifactId>
<version>0.0.1-SNAPSHOT</version>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.12.2-R0.1-SNAPSHOT</version><!--change this value depending on the version or use LATEST-->
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.12.2-R0.1-SNAPSHOT</version><!--change this value depending on the version-->
<type>jar</type>
<scope>provided</scope>
</dependency>
</dependencies>

</project>

+ 38
- 0
OauthPlugin/src/main/java/com/varelus/mc_oauth/JoinListener.java View File

@@ -0,0 +1,38 @@
package com.varelus.mc_oauth;

import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;

import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.*;
import java.util.Arrays;
import java.util.Date;

public class JoinListener implements Listener {

public static int getRandom(int min, int max){
int x = (int)(Math.random()*((max-min)+1))+min;
return x;
}

@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) throws IOException {
Integer token = getRandom(100000, 999999);
Player player = event.getPlayer();
player.kickPlayer("Your auth code is \"" + token + "\"\nThis token will expire in 5 minutes.");
Path file = Paths.get("player.csv");
try {
Files.createFile(file);
} catch (FileAlreadyExistsException ignored) { }
Files.write(
file,
Arrays.asList((new Date()).getTime() / 1000 + "," + player.getUniqueId() + "," + player.getDisplayName() + "," + token),
Charset.forName("UTF-8"),
StandardOpenOption.APPEND
);
}

}

+ 17
- 0
OauthPlugin/src/main/java/com/varelus/mc_oauth/OauthPlugin.java View File

@@ -0,0 +1,17 @@
package com.varelus.mc_oauth;

import org.bukkit.plugin.java.JavaPlugin;

public class OauthPlugin extends JavaPlugin {

@Override
public void onEnable() {
getLogger().info("onEnable has been invoked!");
getServer().getPluginManager().registerEvents(new JoinListener(), this);
}

@Override
public void onDisable() {
getLogger().info("onDisable has been invoked!");
}
}

+ 5
- 0
OauthPlugin/src/main/resources/plugin.yml View File

@@ -0,0 +1,5 @@
name: OauthPlugin
main: com.varelus.mc_oauth.OauthPlugin
version: 0.0.1
author: kami
api-version: 1.8

+ 87
- 0
README.md View File

@@ -0,0 +1,87 @@
# mc-oauth

This isnt technically oauth but oh well.

This server and plugin are meant to verify that an mc user exists and is valid. Inspired by https://mc-oauth.net/. Head over to their description, seriously its a lot better.
Too complicated to run all build steps below by hand? Try `drone exec` (requires drone-cli installed) or head over to the releases tab. Compatible with Minecraft Client 1.7.X to 1.14.X and further through ViaVersion.

## Dependencies

- Java 11

#### Optional (if building OauthPlugin)

- Maven

#### Optional (if building API Server)

- Go

## Prerequesites

#### Build Spigot

- Get [Spigot BuildTools](https://www.spigotmc.org/wiki/buildtools/)

```shell
curl -o BuildTools.jar https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar
```

- Build `spigot.jar` in version 1.8.X

```shell
java -Xmx1024M -jar BuildTools.jar --rev 1.8
```

#### Install Plugins

- Install into `/plugins` [ViaVersion](https://www.spigotmc.org/resources/viaversion.19254/)
- (Optional for MC 1.7.X) Install into `/plugins` [ViaRewind](https://www.spigotmc.org/resources/viarewind.52109/)

## Get OauthPlugin

Install into `/plugins`, either
- build via `mvn package` (project at `OauthPlugin`)
- install release from release tab

## API Server

#### Dependencies

```shell
go get github.com/gorilla/mux
```

#### Install

Build `server.go`, either
- `go build server.go`
- install release from release tab

## Start service

- start spigot (make sure that all plugins are installed!)

```shell
java -Xmx1024M -jar spigot-1.8.jar
```

- start api server

```shell
./server
```

## API

Server will per default attach to port 80 (please use port forwarding in prduction).

#### `GET /api/{token}`

Response:

```json
{"status":"success","message":"valid token","uuid":"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx","username":"lolthisalegituser"}
```

or none

+ 1
- 0
RELEASE.md View File

@@ -0,0 +1 @@
And a merry christmas to you

+ 7
- 0
api/build.sh View File

@@ -0,0 +1,7 @@
#!/bin/sh
for GOOS in windows darwin linux; do
for GOARCH in 386 amd64; do
export GOOS GOARCH
go build -v -o /tmp/dist/server-$GOOS-$GOARCH api/server.go
done
done

+ 69
- 0
api/server.go View File

@@ -0,0 +1,69 @@
package main

import (
"bufio"
"encoding/csv"
"encoding/json"
"github.com/gorilla/mux"
"io"
"log"
"net/http"
"os"
"strconv"
"time"
)

type Response struct {
Status string `json:"status"`
Message string `json:"message"`
Uuid string `json:"uuid"`
Username string `json:"username"`
}

type User struct {
Date string
Uuid string
Username string
Token string
}

func main() {
router := mux.NewRouter().StrictSlash(true)
router.HandleFunc("/api/{token}", Api)
log.Fatal(http.ListenAndServe(":80", router))
}

func Api(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
csvFile, _ := os.Open("player.csv")
reader := csv.NewReader(bufio.NewReader(csvFile))
var users []User
for {
line, error := reader.Read()
if error == io.EOF {
break
} else if error != nil {
log.Fatal(error)
}
date, _ := strconv.ParseInt(line[0], 10, 64)
if time.Now().Unix() < date + (5 * 60) {
users = append(users, User{
line[0],
line[1],
line[2],
line[3],
})
}
for _, user := range users {
if user.Token == vars["token"] {
response := Response{
Status: "success",
Message: "valid token",
Uuid: user.Uuid,
Username: user.Username,
}
json.NewEncoder(w).Encode(response)
}
}
}
}

+ 3
- 0
docker-golang-git/Dockerfile View File

@@ -0,0 +1,3 @@
FROM golang:alpine

RUN apk add --no-cache git

Loading…
Cancel
Save