Skip to content

Commit

Permalink
SV 1.3 a lot of changes
Browse files Browse the repository at this point in the history
Quick rundown:
- Everything is organized into directories
- Docker actually works
- Schedule, and most other .MDs moved to the wiki
- Tests to see if the app actually works (devs)
- I use NeoVim and Arch BTW
- Branch sqlite3
- I actually commit from my account instead of a ghp key
  • Loading branch information
RewardedIvan committed Nov 15, 2022
1 parent 8cfade5 commit e0b129f
Show file tree
Hide file tree
Showing 22 changed files with 2,453 additions and 85 deletions.
10 changes: 5 additions & 5 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ A clear and concise description of what you expected to happen.
If applicable, add screenshots to help explain your problem.

**Server (please complete the following information):**
- OS: [e.g. Linux]
- Version [e.g. 1.2]
- OS: [examples: Ubuntu 22.04 amd64, Arch Linux 32, Debian Stable aarch64]
- Server Version (sv) can be found with -version: [e.g. latest - 1.3]

**Additional context**
Add any other context about the problem here.

**I'm sure that**
- [ ] I have checked the FAQ
- [ ] No other issue, that has been closed has your bug or check the [schedule](https://github.com/RewardedIvan/3DPS/blob/master/schedule.md), or if there is a bug not scheduled, please like it so I can see it
- [ ] There is no other solution
- [ ] I have checked the [FAQ](https://github.com/RewardedIvan/3DPS/wiki/FAQ) and the [TODO](https://github.com/RewardedIvan/3DPS/wiki/TODO)
- [ ] I am on the latest commit of the git repo.

Again again, if your not sure your issue **will** be closed
3 changes: 1 addition & 2 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,5 @@ A clear and concise description of any alternative solutions or features you've
Add any other context or screenshots about the feature request here.

**I'm sure that**
- [ ] This doesn't exist already or some other issue is [scheduled](https://github.com/RewardedIvan/3DPS/blob/master/schedule.md), like other issues that haven't been seen by me.
- [ ] This issue is so irrelevant that it would change a single character in my code
- [ ] I have checked the [FAQ](https://github.com/RewardedIvan/3DPS/wiki/FAQ) and the [TODO](https://github.com/RewardedIvan/3DPS/wiki/TODO)
Again if your not sure, your issue **will** be closed
10 changes: 9 additions & 1 deletion .github/ISSUE_TEMPLATE/help-me-.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,20 @@ assignees: ''
---

**What went wrong**
The docker build failed with `Failed to connect to docker socket`
e.g. The docker build failed with `Failed to connect to docker socket`

**Steps to reproduce**
e.g.:
1. `docker build .`
2. Get the error message

**Additional context**
e.g. Today I woke up with some eggs for a breakfest. Opened up my beast, and started gaming. Then I saw this somewhere on youtube, installed.........

**Additional info**
- OS: [e.g. Windows 10 64 bit]
- Client: [e.g. 1.2, modified, custom]

**I'm sure that**
- [ ] I have checked the [FAQ](https://github.com/RewardedIvan/3DPS/wiki/FAQ)
- [ ] No other issue, that has been closed has your problem
Expand Down
18 changes: 10 additions & 8 deletions .github/ISSUE_TEMPLATE/i-want-my-distro-on-the-list.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
---
name: I want my distro on the list
name: I want my package manager on the list
about: Most of the package managers on the list are there, but if I miss something
you have to tell me
title: "[distro] Arch"
title: "[distro] e.g. Arch"
labels: ''
assignees: ''

---

**distribution**
Arch
(Anything but nixos) e.g. Arch Linux

**derivatives**
Manjaro, Garuda, Endevour OS
e.g. Manjaro, Garuda, Endevour OS...

**package manager along with the install command to golang, docker sqlite3**
pacman -Sy go docker sqlite
**package manager along with the install command to golang, docker and sqlite3**
e.g. pacman -Sy go docker sqlite3

**additional context**
e.g. The package manager I have described can't install multiple packages at once, meaning it has to be multiple lines...

**I'm sure that**
- [ ] It's obviously not on the list
- [ ] The distro is not [scheduled](https://github.com/RewardedIvan/3DPS/blob/master/schedule.md) or a similar issue exists that I have not seen, please like that issue so I can see it
- [ ] It's obviously anywhere (in the wiki)
If your not sure, your issue **will** be closed.
7 changes: 4 additions & 3 deletions .github/ISSUE_TEMPLATE/spelling-mistake--aka--typo.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
name: spelling mistake (aka) typo
about: Everyone makes mistakes
title: "[typo]"
title: "[typo] e.g. in the wiki"
labels: ''
assignees: ''

Expand All @@ -11,7 +11,8 @@ assignees: ''
[Provide a link](https://www.youtube.com/watch?v=dQw4w9WgXcQ)

**What?**
It's supposed to be `environment`, when it is `ennviroment`
What did I misspell?

**I am sure**
- [ ] There isn't a similar issue [scheduled](https://github.com/RewardedIvan/3DPS/blob/main/schedule.md), or if there is an issue that is not scheduled, but matches your typo. Please like it so I can see it
- [ ] It isn't in the code. Since go report card already checks for this.
- [ ] I have checked the [FAQ](https://github.com/RewardedIvan/3DPS/wiki/FAQ)
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
./src/levels.db
./src/src
./test/test
9 changes: 0 additions & 9 deletions Dockerfile

This file was deleted.

15 changes: 15 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM golang:alpine
RUN apk add --update gcc musl-dev curl
RUN mkdir /src
RUN mkdir /3DPS

COPY docker/setup.sh /src/setup.sh
RUN chmod +x /src/setup.sh

COPY src/* /src/

RUN [ "sh", "/src/setup.sh" ]

EXPOSE 9991
HEALTHCHECK CMD if [[ "$(curl localhost:9991 -s | md5sum)" == "cfdf6a1ec3ca70cc1d00b7820c4ba64f -" ]]; then; exit 0; else; exit 1; fi
ENTRYPOINT ["/3DPS/server", "-db", "/db/levels.db"]
18 changes: 18 additions & 0 deletions docker/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/sh
cd /src

# Check the wiki for more info
#openssl req -x509 -nodes -newkey rsa:2048 -keyout TLS.key -out TLS.crt -days 69420 -subj "/C=EA/ST=Planet/L=Earth/O=Global Security/OU=IT Department/CN=3DPS"

go mod tidy
go build
mv 3DPS /3DPS/server
cd /
rm -rf /src

# I was originally going to use postgres, but no one is going to get that many users
# If the sqlite experience is bad enough, I will try to use another database, ofc in another branch

#wget https://raw.githubusercontent.com/vishnubob/wait-for-it/master/wait-for-it.sh
#chmod +x wait-for-it.sh
#./wait-for-it.sh -h postgres -p 5432 -t 69 -- ......
22 changes: 0 additions & 22 deletions dockersetup.sh

This file was deleted.

5 changes: 0 additions & 5 deletions go.mod

This file was deleted.

2 changes: 0 additions & 2 deletions go.sum

This file was deleted.

File renamed without changes.
9 changes: 0 additions & 9 deletions schedule.md

This file was deleted.

57 changes: 38 additions & 19 deletions 3dps.go → src/3dps.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ import (
"fmt"
"log"
"net/http"
"os"
"strconv"
"flag"

_ "github.com/mattn/go-sqlite3"
)

const SV = "1.3"

type Data struct {
Name string
Author string
Expand All @@ -25,16 +29,17 @@ type Data struct {
CameraData []int
}

func check(err error, where string) bool {
var database *sql.DB;

func check(err error, where string, exit bool) {
if err != nil {
log.Fatal(where+": ", err)
return false
if exit == true {
os.Exit(1);
}
}
return true
}

var database, dberr = sql.Open("sqlite3", "./levels.db")

func hewo(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Content-Type", "text/html")
w.Write([]byte("<h2>Hewo!</h2>"))
Expand Down Expand Up @@ -87,12 +92,11 @@ func postLevel(w http.ResponseWriter, r *http.Request) {
return
}
// Shit gets checked for acutal valid data
if len(UD.Name) > 24 || len(UD.Author) > 24 || UD.SongID > 21 || UD.Difficulty > 5 || UD.FloorID > 3 || UD.BackgroundID > 2 || len(UD.Name) == 0 || len(UD.Author) == 0 || UD.SongID < 0 || UD.Difficulty < 0 || UD.FloorID < 0 || UD.BackgroundID < 0 {
/*if len(UD.Name) > 24 || len(UD.Author) > 24 || UD.SongID > 21 || UD.Difficulty > 5 || UD.FloorID > 3 || UD.BackgroundID > 2 || len(UD.Name) == 0 || len(UD.Author) == 0 || UD.SongID < 0 || UD.Difficulty < 0 || UD.FloorID < 0 || UD.BackgroundID < 0 {
w.WriteHeader(http.StatusBadRequest)
return
}
}*/

err = nil
var Iid int64
_, err = database.Exec("INSERT INTO levels VALUES(?)", r.Form["data"][0])
if err != nil {
Expand All @@ -104,16 +108,15 @@ func postLevel(w http.ResponseWriter, r *http.Request) {
return
}
}
row := database.QueryRow("SELECT ROWID FROM levels ORDER BY DESC LIMIT 1")
row := database.QueryRow("SELECT ROWID FROM levels ORDER BY ROWID DESC LIMIT 1")
row.Scan(&Iid)

w.Write([]byte(fmt.Sprint(Iid + 1)))
w.Write([]byte(fmt.Sprint(Iid)))
}

func getRecents(w http.ResponseWriter, r *http.Request) {
rows, err := database.Query("SELECT data,ROWID FROM levels ORDER BY ROWID DESC LIMIT 20") // Specify the amount of recents you want to see
check(err, "quering recent levels")
err = nil
check(err, "quering recent levels", false)

var result string

Expand Down Expand Up @@ -142,14 +145,30 @@ func getRecents(w http.ResponseWriter, r *http.Request) {
}

func main() {
//# Flags
flag.Func("version", "Displays the sv (server version) and exits. Please put a argument, go is angry", func(s string) error {
fmt.Printf("sv. %s\n", SV)

os.Exit(0)
return nil // Unreachable code lmao
})

dbstr := flag.String("db", "./levels.db", "Database connection string/file")

flag.Parse()

//# Database using sqlite3
check(dberr, "loading database")
InitTable, err := database.Prepare("CREATE TABLE IF NOT EXISTS levels(data BLOB UNIQUE)")
check(err, "creating levels' table")
err = nil
InitTable.Exec()

var err error
database, err = sql.Open("sqlite3", *dbstr)
check(err, "loading database", true)

_, err = database.Exec("CREATE TABLE IF NOT EXISTS levels(data BLOB UNIQUE)")
check(err, "creating levels table", true)

defer database.Close()


//# Routing
http.HandleFunc("/", hewo)
http.HandleFunc("/level/get", getLevel)
Expand All @@ -159,8 +178,8 @@ func main() {
//# Listen And Serve
fmt.Println("Listening and serving...")
//HTTPS is protection against man in the middle attacks, which will never happen, unless your in a public network AND someone is TARGETING YOU
//Although it doesn't work on unity's network thing sadly, and thats why it didn't work. If it ever does, please make an issue
//Although it doesn't work on unity's network thing (curl and its libs are OSS) sadly, and thats why it didn't work.
//err = http.ListenAndServeTLS(":9991", "TLS.crt", "TLS.key", nil)
err = http.ListenAndServe(":9991", nil)
check(err, "listen n serving")
check(err, "listen n serving", true)
}
5 changes: 5 additions & 0 deletions src/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module github.com/RewardedIvan/3DPS

go 1.19

require github.com/mattn/go-sqlite3 v1.14.16
2 changes: 2 additions & 0 deletions src/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github.com/mattn/go-sqlite3 v1.14.16 h1:yOQRA0RpS5PFz/oikGwBEqvAWhWg5ufRz4ETLjwpU1Y=
github.com/mattn/go-sqlite3 v1.14.16/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
3 changes: 3 additions & 0 deletions test/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/RewardedIvan/3DPS/test

go 1.19

0 comments on commit e0b129f

Please sign in to comment.