noita-mapcap/bin/capture/server.go.disabled
David Vogel 99ad91e67c Several changes
- Don't change effects, as it's not needed anymore
- Add capture library to be loaded by lua (go and PureBasic)
- Modify pixel size, to nicely fit into FullHD
- Move camera instead of player
- Add capturing routine
- Round position to fit into grid, and also render the world pixel perfect
- Add util/helper functions
2019-10-20 16:28:17 +02:00

82 lines
1.6 KiB
Plaintext

// Copyright (c) 2019 David Vogel
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
package main
import (
"bufio"
"log"
"net"
"strconv"
"strings"
)
func startServer() {
log.Printf("Launching server...\n")
// listen on all interfaces
ln, err := net.Listen("tcp", ":46789")
if err != nil {
log.Fatalf("Couldn't open TCP server at port 46789: %v", err)
}
// accept connections
for {
conn, err := ln.Accept()
if err != nil {
log.Fatalf("Couldn't accept TCP connection: %v", err)
}
// Handle incoming data
go func(conn net.Conn) {
defer conn.Close()
var x, y int
for {
message, err := bufio.NewReader(conn).ReadString('\n')
if err != nil {
log.Printf("Couldn't read from connection: %v", err)
return
}
// Check for end condition
if message == "\n" {
break
}
colonPos := strings.IndexByte(message, ':') // Expect UTF-8
if colonPos < 0 {
log.Printf("Missing colon in message: %v", message)
return
}
key, value := message[:colonPos], message[colonPos+1:]
log.Printf("Bla %v blub %v", key, value)
switch key { // Expect UTF-8
case "x":
if res, err := strconv.ParseInt(value, 10, 0); err == nil {
x = int(res)
} else {
log.Printf("Can't parse string %v to integer: %v", value, err)
return
}
case "y":
if res, err := strconv.ParseInt(value, 10, 0); err == nil {
y = int(res)
} else {
log.Printf("Can't parse string %v to integer: %v", value, err)
return
}
}
}
conn.Write([]byte("\n"))
log.Printf("capture bla at %v, %v", x, y)
}(conn)
}
}