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 {
|
for _, msg := range messages {
|
||||||
localMsg := types.ChatMessage{
|
localMsg := types.ChatMessage{
|
||||||
PlayerID: msg.PlayerId,
|
PlayerID: msg.PlayerId,
|
||||||
|
Username: msg.Username,
|
||||||
Content: msg.Content,
|
Content: msg.Content,
|
||||||
Time: time.Unix(0, msg.Timestamp),
|
Time: time.Unix(0, msg.Timestamp),
|
||||||
}
|
}
|
||||||
@ -117,7 +118,7 @@ func (c *Chat) Draw(screenWidth, screenHeight int32) {
|
|||||||
|
|
||||||
for i := startIdx; i < endIdx; i++ {
|
for i := startIdx; i < endIdx; i++ {
|
||||||
msg := c.messages[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)
|
rl.DrawText(text, int32(chatX)+5, int32(messageY), 20, rl.White)
|
||||||
messageY += messageHeight
|
messageY += messageHeight
|
||||||
}
|
}
|
||||||
|
16
game/game.go
16
game/game.go
@ -68,16 +68,16 @@ func (g *Game) Update(deltaTime float32) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Assign model based on player ID
|
||||||
|
modelIndex := int(playerID) % len(g.Models)
|
||||||
g.Player = &types.Player{
|
g.Player = &types.Player{
|
||||||
PosActual: rl.NewVector3(5*types.TileSize, 0, 5*types.TileSize),
|
|
||||||
PosTile: GetTile(5, 5),
|
|
||||||
Speed: 50.0,
|
Speed: 50.0,
|
||||||
TargetPath: []types.Tile{},
|
TargetPath: []types.Tile{},
|
||||||
UserData: g,
|
UserData: g,
|
||||||
QuitDone: make(chan struct{}),
|
QuitDone: make(chan struct{}),
|
||||||
ID: playerID,
|
ID: playerID,
|
||||||
Model: g.Models[0].Model,
|
Model: g.Models[modelIndex].Model,
|
||||||
Texture: g.Models[0].Texture,
|
Texture: g.Models[modelIndex].Texture,
|
||||||
}
|
}
|
||||||
|
|
||||||
go network.HandleServerCommunication(conn, playerID, g.Player, g.OtherPlayers, g.QuitChan)
|
go network.HandleServerCommunication(conn, playerID, g.Player, g.OtherPlayers, g.QuitChan)
|
||||||
@ -208,7 +208,13 @@ func (g *Game) Render() {
|
|||||||
g.DrawMap()
|
g.DrawMap()
|
||||||
g.DrawPlayer(g.Player, g.Player.Model)
|
g.DrawPlayer(g.Player, g.Player.Model)
|
||||||
for id, other := range g.OtherPlayers {
|
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()
|
rl.EndMode3D()
|
||||||
|
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit 52ab45fe53cba3ab2e09546c5ac0cd8bab3d73f4
|
Subproject commit 3f7205d73e2c32fc8b28fba393c4bb8092e35d28
|
@ -11,9 +11,12 @@ import (
|
|||||||
|
|
||||||
"gitea.boner.be/bdnugget/goonscape/types"
|
"gitea.boner.be/bdnugget/goonscape/types"
|
||||||
pb "gitea.boner.be/bdnugget/goonserver/actions"
|
pb "gitea.boner.be/bdnugget/goonserver/actions"
|
||||||
|
rl "github.com/gen2brain/raylib-go/raylib"
|
||||||
"google.golang.org/protobuf/proto"
|
"google.golang.org/protobuf/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const protoVersion = 1
|
||||||
|
|
||||||
var serverAddr = "boner.be:6969"
|
var serverAddr = "boner.be:6969"
|
||||||
|
|
||||||
func SetServerAddr(addr string) {
|
func SetServerAddr(addr string) {
|
||||||
@ -40,7 +43,8 @@ func ConnectToServer(username, password string, isRegistering bool) (net.Conn, i
|
|||||||
}
|
}
|
||||||
|
|
||||||
authBatch := &pb.ActionBatch{
|
authBatch := &pb.ActionBatch{
|
||||||
Actions: []*pb.Action{authAction},
|
Actions: []*pb.Action{authAction},
|
||||||
|
ProtocolVersion: protoVersion,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := writeMessage(conn, authBatch); err != nil {
|
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)
|
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 {
|
if !response.AuthSuccess {
|
||||||
conn.Close()
|
conn.Close()
|
||||||
return nil, 0, fmt.Errorf(response.ErrorMessage)
|
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 {
|
for _, state := range serverMessage.Players {
|
||||||
if state.PlayerId == playerID {
|
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
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,6 +39,7 @@ type ModelAsset struct {
|
|||||||
|
|
||||||
type ChatMessage struct {
|
type ChatMessage struct {
|
||||||
PlayerID int32
|
PlayerID int32
|
||||||
|
Username string
|
||||||
Content string
|
Content string
|
||||||
Time time.Time
|
Time time.Time
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user