From cc8322f221c0b80e7dd222a350edaad50267ae6d Mon Sep 17 00:00:00 2001 From: echo Date: Sun, 14 Jul 2024 06:19:21 +0330 Subject: [PATCH] grrrr --- README.md | 11 +++++-- go.mod | 2 +- src/Constants/constants.go | 22 +++++++++++++ src/helper/decorder.go | 21 ------------- src/helper/read.go | 8 +++++ src/helper/response.go | 17 +++++++++++ src/helper/stringfuckery.go | 2 +- src/main.go | 30 ++++++++++-------- src/parser/parser.go | 61 +++++++++++++++++++++++++++++++++++++ 9 files changed, 136 insertions(+), 38 deletions(-) create mode 100644 src/Constants/constants.go delete mode 100644 src/helper/decorder.go create mode 100644 src/helper/response.go create mode 100644 src/parser/parser.go diff --git a/README.md b/README.md index b44c3c2..29c26b3 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,10 @@ -# mptp +# pas -meow purr transfer protocol - an excuse to mess with sockets \ No newline at end of file +piss and shit protocol - the new internet + +a month ago, a youtuber called facedev: [made a video](https://www.youtube.com/watch?v=qiOtinFFfk8) +this video, is PISSING ME OFF, HE DID NOT MAKE ANYTHING +HE JUST USED EXISTING SOFTWARE IN A HORRIBLE INSECURE FUCKING WAY +THERE'S NOTHING BEING "MADE", +ALSO THE "WEB" IS NOT THE THING YOU CREATED, YOU RECREATED WEBSITES +IT FUCKING SUCKS, so im making my own. \ No newline at end of file diff --git a/go.mod b/go.mod index 93f7756..70e652e 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ -module exhq.dev/mptp +module exhq.dev/pas go 1.22.3 diff --git a/src/Constants/constants.go b/src/Constants/constants.go new file mode 100644 index 0000000..2014d21 --- /dev/null +++ b/src/Constants/constants.go @@ -0,0 +1,22 @@ +package Constants + +type Method string +type Response string + +const ( + UNKNOWN Method = "wtf bro" + GET Method = "GET" + POST Method = "POST" +) + +const ( + OK Response = "OK" + NOTFOUND Response = "NOTFOUND" +) + +type Intent struct { + Method Method + Path string + Version string + Headers map[string]string +} diff --git a/src/helper/decorder.go b/src/helper/decorder.go deleted file mode 100644 index 412ebc6..0000000 --- a/src/helper/decorder.go +++ /dev/null @@ -1,21 +0,0 @@ -package helper - -import ( - "regexp" - "strings" -) - -func GetHeaders(rawMessage string) (map[string][]string, string) { - msgarr := strings.Split(rawMessage, "\n") - pattern := `^MPTP/\d\.\d HAIIII :3 (GIB|TAEK)$` - re := regexp.MustCompile(pattern) - - // Check if msgarr[0] matches the pattern - if !re.MatchString(msgarr[0]) { - return nil, "wrong nuggets" - } - - return map[string][]string{ - "version": {strings.Split(msgarr[0], "HAIIII :3")[0]}, - }, "" -} diff --git a/src/helper/read.go b/src/helper/read.go index a00d62e..e82b742 100644 --- a/src/helper/read.go +++ b/src/helper/read.go @@ -19,3 +19,11 @@ func ReadUntilNull(reader *bufio.Reader) ([]byte, error) { } return buf.Bytes(), nil } + +func ReadUntilNullString(reader *bufio.Reader) (string, error) { + buf, err := ReadUntilNull(reader) + if err != nil { + return "", err + } + return string(buf), nil +} diff --git a/src/helper/response.go b/src/helper/response.go new file mode 100644 index 0000000..5bd67c2 --- /dev/null +++ b/src/helper/response.go @@ -0,0 +1,17 @@ +package helper + +import ( + "fmt" + "strings" + + "exhq.dev/pas/src/Constants" +) + +func IntentGenerator(status Constants.Response, headers map[string]string) string { + headersString := "" + for key, value := range headers { + headersString += fmt.Sprintf("%s:%s\n", key, value) + } + headersString = strings.TrimSuffix(headersString, "\n") + return fmt.Sprintf("PAS %s\n%s\n\n", string(status), headersString) +} diff --git a/src/helper/stringfuckery.go b/src/helper/stringfuckery.go index 9663f2f..75fe354 100644 --- a/src/helper/stringfuckery.go +++ b/src/helper/stringfuckery.go @@ -4,6 +4,6 @@ func Ender() string { return string(rune(0)) } -func ByteWithEnd(str string) []byte { +func StringToByteWithEnd(str string) []byte { return append([]byte(str), byte(0)) } diff --git a/src/main.go b/src/main.go index c8d9413..920ba5a 100644 --- a/src/main.go +++ b/src/main.go @@ -5,35 +5,39 @@ import ( "fmt" "log" "net" - "strings" - "exhq.dev/mptp/src/helper" + "exhq.dev/pas/src/Constants" + "exhq.dev/pas/src/helper" + "exhq.dev/pas/src/parser" ) func main() { - ln, err := net.Listen("tcp", ":8000") + ln, err := net.Listen("tcp", ":42069") if err != nil { log.Fatal(err) } - fmt.Println("Listening on port 8000") + fmt.Println("Listening on port 42069") for { conn, err := ln.Accept() if err != nil { log.Fatal(err) } - message, err := helper.ReadUntilNull(bufio.NewReader(conn)) + message, err := helper.ReadUntilNullString(bufio.NewReader(conn)) if err != nil { log.Fatal(err) } - header, er := helper.GetHeaders(string(message)) - println("connected to: " + (conn.RemoteAddr().String())) - if er == "wrong nuggets" { - conn.Write(helper.ByteWithEnd("UR NUGGIES ARE INVALID >:3")) - continue + parsed := parser.ParseIntent(message) + + if parsed.Path == "/" { + conn.Write(helper.StringToByteWithEnd(helper.IntentGenerator(Constants.OK, map[string]string{ + "version": "0.69", + }) + "welcome to the first ever shitternet page")) } - if strings.TrimSpace(strings.Join(header["version"], "")) != "MPTP/0.1" { - conn.Write(helper.ByteWithEnd("i... don know that language >M<")) + + if parsed.Path == "/meow" { + conn.Write(helper.StringToByteWithEnd(helper.IntentGenerator(Constants.OK, map[string]string{ + "version": "0.69", + }) + "meowmeow")) } - conn.Write([]byte("meoww :3\nhiiii" + string(rune(0)))) } } diff --git a/src/parser/parser.go b/src/parser/parser.go new file mode 100644 index 0000000..c5f3121 --- /dev/null +++ b/src/parser/parser.go @@ -0,0 +1,61 @@ +package parser + +import ( + "strings" + + "exhq.dev/pas/src/Constants" +) + +func ParseIntent(intent string) Constants.Intent { + if intent == "" { + return Constants.Intent{ + Method: Constants.UNKNOWN, + Path: "", + Version: "", + Headers: map[string]string{}, + } + } + + lines := strings.Split(intent, "\n") + if len(lines) < 1 { + return Constants.Intent{ + Method: Constants.UNKNOWN, + Path: "", + Version: "", + Headers: map[string]string{}, + } + } + + firstLine := lines[0] + parts := strings.Fields(firstLine) + if len(parts) != 3 { + return Constants.Intent{ + Method: Constants.UNKNOWN, + Path: "", + Version: "", + Headers: map[string]string{}, + } + } + + method := Constants.UNKNOWN + if parts[0] == string(Constants.GET) { + method = Constants.GET + } else if parts[0] == string(Constants.POST) { + method = Constants.POST + } + + headers := make(map[string]string) + for _, line := range lines[1:] { + headerParts := strings.SplitN(line, ":", 2) + if len(headerParts) == 2 { + headers[strings.TrimSpace(headerParts[0])] = strings.TrimSpace(headerParts[1]) + } + } + + return Constants.Intent{ + Method: method, + Path: parts[1], + Version: strings.ReplaceAll(parts[2], "PAS/", ""), + Headers: headers, + } +}