From 30848faebc92869551cf3db7daff0a5c779c66e9 Mon Sep 17 00:00:00 2001 From: kercylan98 Date: Fri, 5 May 2023 17:01:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=8E=B7=E5=8F=96=E8=BF=9E?= =?UTF-8?q?=E6=8E=A5=E7=9A=84=E6=8E=A5=E5=8F=A3=EF=BC=8C=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E4=BA=8B=E4=BB=B6=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- game/builtin/examples/game/game/server.go | 4 ++-- server/server.go | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/game/builtin/examples/game/game/server.go b/game/builtin/examples/game/game/server.go index 507af65..c3828ac 100644 --- a/game/builtin/examples/game/game/server.go +++ b/game/builtin/examples/game/game/server.go @@ -11,7 +11,7 @@ func init() { Server.RegConnectionReceivePacketEvent(onConnectionReceivePacket) } -func onConnectionReceivePacket(conn *server.Conn, packet []byte) { +func onConnectionReceivePacket(srv *server.Server, conn *server.Conn, packet []byte) { player := Game.World.GetPlayerWithConnID(conn.GetID()) if player == nil { return @@ -31,7 +31,7 @@ func onConnectionClosed(player *Player) { player.Close() } -func onConnectionOpened(conn *server.Conn) { +func onConnectionOpened(srv *server.Server, conn *server.Conn) { player := NewPlayer(sole.GetSync(), conn) if err := Game.World.Join(player); err != nil { panic(err) diff --git a/server/server.go b/server/server.go index 7f08220..6f568ce 100644 --- a/server/server.go +++ b/server/server.go @@ -267,6 +267,11 @@ func (slf *Server) IsDev() bool { return !slf.prod } +// GetConnections 获取所有在线的连接 +func (slf *Server) GetConnections() synchronization.MapReadonly[string, *Conn] { + return slf.connections +} + // Shutdown 停止运行服务器 func (slf *Server) Shutdown(err error) { if slf.initMessageChannel {