feat 稳定300人

This commit is contained in:
2025-12-17 09:54:24 +08:00
parent 4983638c19
commit 0274262591
16 changed files with 467 additions and 234 deletions

View File

@@ -2,8 +2,10 @@ package server
import (
"common/log"
"common/proto/sc/sc_pb"
"common/proto/ss/grpc_pb"
"context"
"google.golang.org/protobuf/proto"
"scene/instance"
"sync"
)
@@ -11,7 +13,7 @@ import (
func (s *Server) Enter(ctx context.Context, req *grpc_pb.EnterReq) (*grpc_pb.EnterResp, error) {
var i *instance.Instance
if len(instance.Mgr.GetAll()) == 0 {
i = instance.NewScene(s.SID, int(req.InstanceID))
i = instance.NewScene(s.SID, req.InstanceID)
i.Start(s.EtcdTTL)
} else {
for _, v := range instance.Mgr.GetAll() {
@@ -20,12 +22,29 @@ func (s *Server) Enter(ctx context.Context, req *grpc_pb.EnterReq) (*grpc_pb.Ent
}
}
i.EventIn <- req
payload, _ := proto.Marshal(&sc_pb.S2C_EnterInstance{
Info: &sc_pb.PositionInfo{
UID: req.UID,
X: 1,
Y: 1,
},
})
return &grpc_pb.EnterResp{
SceneSID: s.SID,
UniqueNo: i.UniqueNo,
SceneSID: s.SID,
UniqueNo: i.UniqueNo,
MessageID: int32(sc_pb.MessageID_MESSAGE_ID_ENTER_INSTANCE),
Payload: payload,
}, nil
}
func (s *Server) Leave(ctx context.Context, req *grpc_pb.LeaveReq) (*grpc_pb.LeaveResp, error) {
if i := instance.Mgr.GetByUniqueNo(req.UniqueNo); i != nil {
i.EventIn <- req
}
return &grpc_pb.LeaveResp{}, nil
}
func (s *Server) Action(server grpc_pb.Scene_ActionServer) error {
wg := &sync.WaitGroup{}
wg.Add(1)