Improved network handling

This commit is contained in:
2024-01-16 00:22:14 +01:00
parent b885d70625
commit 8f0f3d9998
14 changed files with 178 additions and 126 deletions

View File

@ -1,6 +1,7 @@
package main
import (
"bytes"
"fmt"
"server/core"
"server/packet"
@ -9,5 +10,12 @@ import (
// login checks the account credentials and gives a network peer access to an account.
func login(data []byte, client *core.Client) {
fmt.Println("2 - login!")
server.Send(packet.LOGIN, nil, client)
if bytes.Equal(data, []byte("password")) {
fmt.Println("login success")
server.Send(packet.LOGIN, []byte{0}, client)
} else {
fmt.Println("login failure")
server.Send(packet.LOGIN, []byte{1}, client)
}
}

View File

@ -8,7 +8,6 @@ import (
// ping is used as a heartbeat and latency check.
func ping(data []byte, client *core.Client) {
fmt.Println("1 - ping!")
fmt.Println("1 - ping")
server.Send(packet.PING, data, client)
fmt.Println(server.Count(), "clients")
}