meow purrr :3
This commit is contained in:
parent
3fb5fc9033
commit
aff3757618
5 changed files with 93 additions and 0 deletions
3
go.mod
Normal file
3
go.mod
Normal file
|
@ -0,0 +1,3 @@
|
|||
module exhq.dev/mptp
|
||||
|
||||
go 1.22.3
|
21
src/helper/decorder.go
Normal file
21
src/helper/decorder.go
Normal file
|
@ -0,0 +1,21 @@
|
|||
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]},
|
||||
}, ""
|
||||
}
|
21
src/helper/read.go
Normal file
21
src/helper/read.go
Normal file
|
@ -0,0 +1,21 @@
|
|||
package helper
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
)
|
||||
|
||||
func ReadUntilNull(reader *bufio.Reader) ([]byte, error) {
|
||||
var buf bytes.Buffer
|
||||
for {
|
||||
b, err := reader.ReadByte()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if b == byte(rune(0)) {
|
||||
break
|
||||
}
|
||||
buf.WriteByte(b)
|
||||
}
|
||||
return buf.Bytes(), nil
|
||||
}
|
9
src/helper/stringfuckery.go
Normal file
9
src/helper/stringfuckery.go
Normal file
|
@ -0,0 +1,9 @@
|
|||
package helper
|
||||
|
||||
func Ender() string {
|
||||
return string(rune(0))
|
||||
}
|
||||
|
||||
func ByteWithEnd(str string) []byte {
|
||||
return append([]byte(str), byte(0))
|
||||
}
|
39
src/main.go
Normal file
39
src/main.go
Normal file
|
@ -0,0 +1,39 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
"strings"
|
||||
|
||||
"exhq.dev/mptp/src/helper"
|
||||
)
|
||||
|
||||
func main() {
|
||||
ln, err := net.Listen("tcp", ":8000")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
fmt.Println("Listening on port 8000")
|
||||
for {
|
||||
conn, err := ln.Accept()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
message, err := helper.ReadUntilNull(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
|
||||
}
|
||||
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))))
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue