working lobby-ish

This commit is contained in:
Beric Bearnson
2024-08-23 11:59:19 -06:00
parent e90b9c26b1
commit e5df746e7f
6 changed files with 94 additions and 35 deletions
+15
View File
@@ -4,6 +4,8 @@ import (
"log"
"net"
sync "sync"
"google.golang.org/protobuf/proto"
)
type Client struct {
@@ -32,6 +34,19 @@ func init() {
externalMessageChan = make(chan ExternalMessage)
lobbyMembers = sync.Map{}
go func() {
for {
msg := <-externalMessageChan
player, ok := lobbyMembers.Load(msg.Target)
if !ok {
continue
}
client, _ := player.(Client)
bytes, _ := proto.Marshal(msg.Message)
client.Conn.Write(bytes)
}
}()
}
// Starts listening on port 12345 for TCP connections