Test
This commit is contained in:
commit
6b65d42471
8
.idea/.gitignore
vendored
Normal file
8
.idea/.gitignore
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
9
.idea/PewServer.iml
Normal file
9
.idea/PewServer.iml
Normal file
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="WEB_MODULE" version="4">
|
||||
<component name="Go" enabled="true" />
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
8
.idea/modules.xml
Normal file
8
.idea/modules.xml
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/PewServer.iml" filepath="$PROJECT_DIR$/.idea/PewServer.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
6
.idea/vcs.xml
Normal file
6
.idea/vcs.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
12
client.go
Normal file
12
client.go
Normal file
@ -0,0 +1,12 @@
|
||||
package main
|
||||
|
||||
import "net"
|
||||
import "github.com/quartercastle/vector"
|
||||
|
||||
type Client struct {
|
||||
conn *net.Conn
|
||||
position vector.MutableVector
|
||||
velocity vector.MutableVector
|
||||
health uint8
|
||||
name string
|
||||
}
|
5
go.mod
Normal file
5
go.mod
Normal file
@ -0,0 +1,5 @@
|
||||
module PewServer
|
||||
|
||||
go 1.22
|
||||
|
||||
require github.com/quartercastle/vector v0.2.0
|
2
go.sum
Normal file
2
go.sum
Normal file
@ -0,0 +1,2 @@
|
||||
github.com/quartercastle/vector v0.2.0 h1:qpVsHi7S624B/NrUl6Osfs6F25kKaZJI+gteUIdLQ6g=
|
||||
github.com/quartercastle/vector v0.2.0/go.mod h1:jRB+p+Bk9qkkZHC72+N6fztVgih6kYslX0vk+3dL5V4=
|
54
main.go
Normal file
54
main.go
Normal file
@ -0,0 +1,54 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
HOST = "localhost"
|
||||
PORT = "8080"
|
||||
TYPE = "tcp"
|
||||
)
|
||||
|
||||
var clients []Client
|
||||
|
||||
func main() {
|
||||
listen, err := net.Listen(TYPE, HOST+":"+PORT)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
// close listener
|
||||
defer listen.Close()
|
||||
for {
|
||||
conn, err := listen.Accept()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
go handleRequest(conn)
|
||||
}
|
||||
}
|
||||
|
||||
func handleRequest(conn net.Conn) {
|
||||
for {
|
||||
// incoming request
|
||||
buffer := make([]byte, 1024)
|
||||
_, err := conn.Read(buffer)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// write data to response
|
||||
timeString := time.Now().Format(time.ANSIC)
|
||||
responseStr := fmt.Sprintf("Your message is: %v. Received timeString: %v", string(buffer[:]), timeString)
|
||||
_, err = conn.Write([]byte(responseStr))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
33
messages.proto
Normal file
33
messages.proto
Normal file
@ -0,0 +1,33 @@
|
||||
syntax = "proto3";
|
||||
option go_package = "main";
|
||||
package main;
|
||||
|
||||
message Packet {
|
||||
int32 id = 1;
|
||||
oneof payload{
|
||||
Ping ping = 2;
|
||||
Handshake handshake = 3;
|
||||
LocationUpdate locationUpdate = 4;
|
||||
}
|
||||
}
|
||||
|
||||
message Ping {
|
||||
bytes data = 1;
|
||||
}
|
||||
|
||||
message LocationUpdate {
|
||||
int64 positionX = 1;
|
||||
int64 positionY = 2;
|
||||
int64 positionZ = 3;
|
||||
|
||||
int64 velocityX = 4;
|
||||
int64 velocityY = 5;
|
||||
int64 velocityZ = 6;
|
||||
|
||||
int64 rotationX = 7;
|
||||
int64 rotationY = 8;
|
||||
}
|
||||
|
||||
message Handshake {
|
||||
string name = 1;
|
||||
}
|
20
serverbound.go
Normal file
20
serverbound.go
Normal file
@ -0,0 +1,20 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
)
|
||||
|
||||
//packet 0x0000 ping ({}byte data)
|
||||
//packet 0x0001 handshake (string name)
|
||||
|
||||
func doPacketAction(data []byte, client *Client) {
|
||||
response := make([]byte, 1024)
|
||||
|
||||
conn := *client.conn
|
||||
write, err := conn.Write(response)
|
||||
if err != nil || write != len(response) {
|
||||
log.Fatal("Write failed")
|
||||
return
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user