This commit is contained in:
amy 2024-07-14 06:19:21 +03:30
parent aff3757618
commit cc8322f221
9 changed files with 136 additions and 38 deletions

View file

@ -1,3 +1,10 @@
# mptp # pas
meow purr transfer protocol - an excuse to mess with sockets 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.

2
go.mod
View file

@ -1,3 +1,3 @@
module exhq.dev/mptp module exhq.dev/pas
go 1.22.3 go 1.22.3

View file

@ -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
}

View file

@ -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]},
}, ""
}

View file

@ -19,3 +19,11 @@ func ReadUntilNull(reader *bufio.Reader) ([]byte, error) {
} }
return buf.Bytes(), nil return buf.Bytes(), nil
} }
func ReadUntilNullString(reader *bufio.Reader) (string, error) {
buf, err := ReadUntilNull(reader)
if err != nil {
return "", err
}
return string(buf), nil
}

17
src/helper/response.go Normal file
View file

@ -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)
}

View file

@ -4,6 +4,6 @@ func Ender() string {
return string(rune(0)) return string(rune(0))
} }
func ByteWithEnd(str string) []byte { func StringToByteWithEnd(str string) []byte {
return append([]byte(str), byte(0)) return append([]byte(str), byte(0))
} }

View file

@ -5,35 +5,39 @@ import (
"fmt" "fmt"
"log" "log"
"net" "net"
"strings"
"exhq.dev/mptp/src/helper" "exhq.dev/pas/src/Constants"
"exhq.dev/pas/src/helper"
"exhq.dev/pas/src/parser"
) )
func main() { func main() {
ln, err := net.Listen("tcp", ":8000") ln, err := net.Listen("tcp", ":42069")
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
fmt.Println("Listening on port 8000") fmt.Println("Listening on port 42069")
for { for {
conn, err := ln.Accept() conn, err := ln.Accept()
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
message, err := helper.ReadUntilNull(bufio.NewReader(conn)) message, err := helper.ReadUntilNullString(bufio.NewReader(conn))
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
header, er := helper.GetHeaders(string(message)) parsed := parser.ParseIntent(message)
println("connected to: " + (conn.RemoteAddr().String()))
if er == "wrong nuggets" { if parsed.Path == "/" {
conn.Write(helper.ByteWithEnd("UR NUGGIES ARE INVALID >:3")) conn.Write(helper.StringToByteWithEnd(helper.IntentGenerator(Constants.OK, map[string]string{
continue "version": "0.69",
}) + "welcome to the first ever shitternet page"))
}
if parsed.Path == "/meow" {
conn.Write(helper.StringToByteWithEnd(helper.IntentGenerator(Constants.OK, map[string]string{
"version": "0.69",
}) + "meowmeow"))
} }
if strings.TrimSpace(strings.Join(header["version"], "")) != "MPTP/0.1" {
conn.Write(helper.ByteWithEnd("i... don know that language >M<"))
}
conn.Write([]byte("meoww :3\nhiiii" + string(rune(0))))
} }
} }

61
src/parser/parser.go Normal file
View file

@ -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,
}
}