Based db and accounts and log in where you logged out
This commit is contained in:
@ -11,9 +11,12 @@ import (
|
||||
|
||||
"gitea.boner.be/bdnugget/goonscape/types"
|
||||
pb "gitea.boner.be/bdnugget/goonserver/actions"
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
const protoVersion = 1
|
||||
|
||||
var serverAddr = "boner.be:6969"
|
||||
|
||||
func SetServerAddr(addr string) {
|
||||
@ -40,7 +43,8 @@ func ConnectToServer(username, password string, isRegistering bool) (net.Conn, i
|
||||
}
|
||||
|
||||
authBatch := &pb.ActionBatch{
|
||||
Actions: []*pb.Action{authAction},
|
||||
Actions: []*pb.Action{authAction},
|
||||
ProtocolVersion: protoVersion,
|
||||
}
|
||||
|
||||
if err := writeMessage(conn, authBatch); err != nil {
|
||||
@ -69,6 +73,12 @@ func ConnectToServer(username, password string, isRegistering bool) (net.Conn, i
|
||||
return nil, 0, fmt.Errorf("failed to unmarshal auth response: %v", err)
|
||||
}
|
||||
|
||||
if response.ProtocolVersion > protoVersion {
|
||||
conn.Close()
|
||||
return nil, 0, fmt.Errorf("server requires newer protocol version (server: %d, client: %d)",
|
||||
response.ProtocolVersion, protoVersion)
|
||||
}
|
||||
|
||||
if !response.AuthSuccess {
|
||||
conn.Close()
|
||||
return nil, 0, fmt.Errorf(response.ErrorMessage)
|
||||
@ -185,6 +195,17 @@ func HandleServerCommunication(conn net.Conn, playerID int32, player *types.Play
|
||||
|
||||
for _, state := range serverMessage.Players {
|
||||
if state.PlayerId == playerID {
|
||||
player.Lock()
|
||||
// Update initial position if not set
|
||||
if player.PosActual.X == 0 && player.PosActual.Z == 0 {
|
||||
player.PosActual = rl.Vector3{
|
||||
X: float32(state.X * types.TileSize),
|
||||
Y: 0,
|
||||
Z: float32(state.Y * types.TileSize),
|
||||
}
|
||||
player.PosTile = types.Tile{X: int(state.X), Y: int(state.Y)}
|
||||
}
|
||||
player.Unlock()
|
||||
continue
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user