Based db and accounts and log in where you logged out
This commit is contained in:
parent
bb01dccf2b
commit
e45066b2a8
@ -53,6 +53,7 @@ func (c *Chat) HandleServerMessages(messages []*pb.ChatMessage) {
|
||||
for _, msg := range messages {
|
||||
localMsg := types.ChatMessage{
|
||||
PlayerID: msg.PlayerId,
|
||||
Username: msg.Username,
|
||||
Content: msg.Content,
|
||||
Time: time.Unix(0, msg.Timestamp),
|
||||
}
|
||||
@ -117,7 +118,7 @@ func (c *Chat) Draw(screenWidth, screenHeight int32) {
|
||||
|
||||
for i := startIdx; i < endIdx; i++ {
|
||||
msg := c.messages[i]
|
||||
text := fmt.Sprintf("[%d]: %s", msg.PlayerID, msg.Content)
|
||||
text := fmt.Sprintf("%s: %s", msg.Username, msg.Content)
|
||||
rl.DrawText(text, int32(chatX)+5, int32(messageY), 20, rl.White)
|
||||
messageY += messageHeight
|
||||
}
|
||||
|
16
game/game.go
16
game/game.go
@ -68,16 +68,16 @@ func (g *Game) Update(deltaTime float32) {
|
||||
return
|
||||
}
|
||||
|
||||
// Assign model based on player ID
|
||||
modelIndex := int(playerID) % len(g.Models)
|
||||
g.Player = &types.Player{
|
||||
PosActual: rl.NewVector3(5*types.TileSize, 0, 5*types.TileSize),
|
||||
PosTile: GetTile(5, 5),
|
||||
Speed: 50.0,
|
||||
TargetPath: []types.Tile{},
|
||||
UserData: g,
|
||||
QuitDone: make(chan struct{}),
|
||||
ID: playerID,
|
||||
Model: g.Models[0].Model,
|
||||
Texture: g.Models[0].Texture,
|
||||
Model: g.Models[modelIndex].Model,
|
||||
Texture: g.Models[modelIndex].Texture,
|
||||
}
|
||||
|
||||
go network.HandleServerCommunication(conn, playerID, g.Player, g.OtherPlayers, g.QuitChan)
|
||||
@ -208,7 +208,13 @@ func (g *Game) Render() {
|
||||
g.DrawMap()
|
||||
g.DrawPlayer(g.Player, g.Player.Model)
|
||||
for id, other := range g.OtherPlayers {
|
||||
g.DrawPlayer(other, g.Models[int(id)%len(g.Models)].Model)
|
||||
if other.Model.Meshes == nil {
|
||||
// Assign model based on player ID for consistency
|
||||
modelIndex := int(id) % len(g.Models)
|
||||
other.Model = g.Models[modelIndex].Model
|
||||
other.Texture = g.Models[modelIndex].Texture
|
||||
}
|
||||
g.DrawPlayer(other, other.Model)
|
||||
}
|
||||
rl.EndMode3D()
|
||||
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 52ab45fe53cba3ab2e09546c5ac0cd8bab3d73f4
|
||||
Subproject commit 3f7205d73e2c32fc8b28fba393c4bb8092e35d28
|
@ -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) {
|
||||
@ -41,6 +44,7 @@ func ConnectToServer(username, password string, isRegistering bool) (net.Conn, i
|
||||
|
||||
authBatch := &pb.ActionBatch{
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -39,6 +39,7 @@ type ModelAsset struct {
|
||||
|
||||
type ChatMessage struct {
|
||||
PlayerID int32
|
||||
Username string
|
||||
Content string
|
||||
Time time.Time
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user