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

@@ -33,7 +33,7 @@ func FindInstanceByUniqueNo(uniqueNO int64) (sid string) {
} }
// RegisterInstance 注册副本 // RegisterInstance 注册副本
func RegisterInstance(sid int64, instanceID int, uniqueNo, ttl int64) error { func RegisterInstance(sid int64, instanceID int32, uniqueNo, ttl int64) error {
serverMU.Lock() serverMU.Lock()
defer serverMU.Unlock() defer serverMU.Unlock()
leaseID, err := common.NewLeaseAndKeepAlive(ttl) leaseID, err := common.NewLeaseAndKeepAlive(ttl)

View File

@@ -44,4 +44,5 @@ type ISocketConn interface {
Ping() error // 需要隔一段时间调用一下建议20s Ping() error // 需要隔一段时间调用一下建议20s
Write(data []byte) error Write(data []byte) error
Close() error Close() error
IsClose() bool
} }

View File

@@ -197,6 +197,10 @@ func (w *WSConn) Close() (err error) {
return w.write(make([]byte, 0), ws.OpClose) return w.write(make([]byte, 0), ws.OpClose)
} }
func (w *WSConn) IsClose() bool {
return w.isClose
}
func (w *WSConn) write(data []byte, opCode ws.OpCode) error { func (w *WSConn) write(data []byte, opCode ws.OpCode) error {
if w.isClose { if w.isClose {
return errors.New("connection has close") return errors.New("connection has close")

View File

@@ -25,19 +25,19 @@ const (
type ActionID int32 type ActionID int32
const ( const (
ActionID_ACTION_ID_MOVE ActionID = 0 // 0-15都是移动指令 ActionID_ACTION_ID_MOVE ActionID = 0 // 移动
ActionID_ACTION_ID_ATTACK ActionID = 16 // 攻击指令 ActionID_ACTION_ID_ATTACK ActionID = 1 // 攻击
) )
// Enum value maps for ActionID. // Enum value maps for ActionID.
var ( var (
ActionID_name = map[int32]string{ ActionID_name = map[int32]string{
0: "ACTION_ID_MOVE", 0: "ACTION_ID_MOVE",
16: "ACTION_ID_ATTACK", 1: "ACTION_ID_ATTACK",
} }
ActionID_value = map[string]int32{ ActionID_value = map[string]int32{
"ACTION_ID_MOVE": 0, "ACTION_ID_MOVE": 0,
"ACTION_ID_ATTACK": 16, "ACTION_ID_ATTACK": 1,
} }
) )
@@ -168,8 +168,12 @@ type C2S_Action struct {
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields unknownFields protoimpl.UnknownFields
Action ActionID `protobuf:"varint,1,opt,name=Action,proto3,enum=ActionID" json:"Action,omitempty"` // 指令ID Sequence uint32 `protobuf:"varint,1,opt,name=Sequence,proto3" json:"Sequence,omitempty"` // 指令序号
Payload []byte `protobuf:"bytes,2,opt,name=Payload,proto3" json:"Payload,omitempty"` // 指令数据 Timestamp int64 `protobuf:"varint,2,opt,name=Timestamp,proto3" json:"Timestamp,omitempty"` // 时间戳(毫秒)
Action ActionID `protobuf:"varint,3,opt,name=Action,proto3,enum=ActionID" json:"Action,omitempty"` // 指令ID
DirX int32 `protobuf:"zigzag32,4,opt,name=DirX,proto3" json:"DirX,omitempty"` // 移动-X方向×100 缩放)
DirY int32 `protobuf:"zigzag32,5,opt,name=DirY,proto3" json:"DirY,omitempty"` // 移动-Y方向×100 缩放)
SkillID int32 `protobuf:"varint,6,opt,name=SkillID,proto3" json:"SkillID,omitempty"` // 攻击-技能ID
} }
func (x *C2S_Action) Reset() { func (x *C2S_Action) Reset() {
@@ -204,6 +208,20 @@ func (*C2S_Action) Descriptor() ([]byte, []int) {
return file_action_proto_rawDescGZIP(), []int{2} return file_action_proto_rawDescGZIP(), []int{2}
} }
func (x *C2S_Action) GetSequence() uint32 {
if x != nil {
return x.Sequence
}
return 0
}
func (x *C2S_Action) GetTimestamp() int64 {
if x != nil {
return x.Timestamp
}
return 0
}
func (x *C2S_Action) GetAction() ActionID { func (x *C2S_Action) GetAction() ActionID {
if x != nil { if x != nil {
return x.Action return x.Action
@@ -211,11 +229,25 @@ func (x *C2S_Action) GetAction() ActionID {
return ActionID_ACTION_ID_MOVE return ActionID_ACTION_ID_MOVE
} }
func (x *C2S_Action) GetPayload() []byte { func (x *C2S_Action) GetDirX() int32 {
if x != nil { if x != nil {
return x.Payload return x.DirX
} }
return nil return 0
}
func (x *C2S_Action) GetDirY() int32 {
if x != nil {
return x.DirY
}
return 0
}
func (x *C2S_Action) GetSkillID() int32 {
if x != nil {
return x.SkillID
}
return 0
} }
// MESSAGE_ID_POSITION // MESSAGE_ID_POSITION
@@ -225,8 +257,8 @@ type PositionInfo struct {
unknownFields protoimpl.UnknownFields unknownFields protoimpl.UnknownFields
UID int32 `protobuf:"varint,1,opt,name=UID,proto3" json:"UID,omitempty"` UID int32 `protobuf:"varint,1,opt,name=UID,proto3" json:"UID,omitempty"`
X float64 `protobuf:"fixed64,2,opt,name=X,proto3" json:"X,omitempty"` X int32 `protobuf:"zigzag32,2,opt,name=X,proto3" json:"X,omitempty"`
Y float64 `protobuf:"fixed64,3,opt,name=Y,proto3" json:"Y,omitempty"` Y int32 `protobuf:"zigzag32,3,opt,name=Y,proto3" json:"Y,omitempty"`
} }
func (x *PositionInfo) Reset() { func (x *PositionInfo) Reset() {
@@ -268,14 +300,14 @@ func (x *PositionInfo) GetUID() int32 {
return 0 return 0
} }
func (x *PositionInfo) GetX() float64 { func (x *PositionInfo) GetX() int32 {
if x != nil { if x != nil {
return x.X return x.X
} }
return 0 return 0
} }
func (x *PositionInfo) GetY() float64 { func (x *PositionInfo) GetY() int32 {
if x != nil { if x != nil {
return x.Y return x.Y
} }
@@ -340,24 +372,31 @@ var file_action_proto_rawDesc = []byte{
0x63, 0x65, 0x49, 0x44, 0x22, 0x36, 0x0a, 0x11, 0x53, 0x32, 0x43, 0x5f, 0x45, 0x6e, 0x74, 0x65, 0x63, 0x65, 0x49, 0x44, 0x22, 0x36, 0x0a, 0x11, 0x53, 0x32, 0x43, 0x5f, 0x45, 0x6e, 0x74, 0x65,
0x72, 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x12, 0x21, 0x0a, 0x04, 0x49, 0x6e, 0x66, 0x72, 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x12, 0x21, 0x0a, 0x04, 0x49, 0x6e, 0x66,
0x6f, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0d, 0x2e, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0d, 0x2e, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69,
0x6f, 0x6e, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x04, 0x49, 0x6e, 0x66, 0x6f, 0x22, 0x49, 0x0a, 0x0a, 0x6f, 0x6e, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x04, 0x49, 0x6e, 0x66, 0x6f, 0x22, 0xab, 0x01, 0x0a,
0x43, 0x32, 0x53, 0x5f, 0x41, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x21, 0x0a, 0x06, 0x41, 0x63, 0x0a, 0x43, 0x32, 0x53, 0x5f, 0x41, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x1a, 0x0a, 0x08, 0x53,
0x74, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x09, 0x2e, 0x41, 0x63, 0x74, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x63, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x08, 0x53,
0x69, 0x6f, 0x6e, 0x49, 0x44, 0x52, 0x06, 0x41, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x18, 0x0a, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x63, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x54, 0x69, 0x6d, 0x65, 0x73,
0x07, 0x50, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x74, 0x61, 0x6d, 0x70, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x54, 0x69, 0x6d, 0x65,
0x50, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x22, 0x3c, 0x0a, 0x0c, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x12, 0x21, 0x0a, 0x06, 0x41, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x18,
0x69, 0x6f, 0x6e, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x10, 0x0a, 0x03, 0x55, 0x49, 0x44, 0x18, 0x01, 0x03, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x09, 0x2e, 0x41, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x44,
0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x55, 0x49, 0x44, 0x12, 0x0c, 0x0a, 0x01, 0x58, 0x18, 0x02, 0x52, 0x06, 0x41, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x12, 0x0a, 0x04, 0x44, 0x69, 0x72, 0x58,
0x20, 0x01, 0x28, 0x01, 0x52, 0x01, 0x58, 0x12, 0x0c, 0x0a, 0x01, 0x59, 0x18, 0x03, 0x20, 0x01, 0x18, 0x04, 0x20, 0x01, 0x28, 0x11, 0x52, 0x04, 0x44, 0x69, 0x72, 0x58, 0x12, 0x12, 0x0a, 0x04,
0x28, 0x01, 0x52, 0x01, 0x59, 0x22, 0x31, 0x0a, 0x0c, 0x53, 0x32, 0x43, 0x5f, 0x50, 0x6f, 0x73, 0x44, 0x69, 0x72, 0x59, 0x18, 0x05, 0x20, 0x01, 0x28, 0x11, 0x52, 0x04, 0x44, 0x69, 0x72, 0x59,
0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x21, 0x0a, 0x04, 0x49, 0x6e, 0x66, 0x6f, 0x18, 0x01, 0x20, 0x12, 0x18, 0x0a, 0x07, 0x53, 0x6b, 0x69, 0x6c, 0x6c, 0x49, 0x44, 0x18, 0x06, 0x20, 0x01, 0x28,
0x03, 0x28, 0x0b, 0x32, 0x0d, 0x2e, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x6e, 0x05, 0x52, 0x07, 0x53, 0x6b, 0x69, 0x6c, 0x6c, 0x49, 0x44, 0x22, 0x3c, 0x0a, 0x0c, 0x50, 0x6f,
0x66, 0x6f, 0x52, 0x04, 0x49, 0x6e, 0x66, 0x6f, 0x2a, 0x34, 0x0a, 0x08, 0x41, 0x63, 0x74, 0x69, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x10, 0x0a, 0x03, 0x55, 0x49,
0x6f, 0x6e, 0x49, 0x44, 0x12, 0x12, 0x0a, 0x0e, 0x41, 0x43, 0x54, 0x49, 0x4f, 0x4e, 0x5f, 0x49, 0x44, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x55, 0x49, 0x44, 0x12, 0x0c, 0x0a, 0x01,
0x44, 0x5f, 0x4d, 0x4f, 0x56, 0x45, 0x10, 0x00, 0x12, 0x14, 0x0a, 0x10, 0x41, 0x43, 0x54, 0x49, 0x58, 0x18, 0x02, 0x20, 0x01, 0x28, 0x11, 0x52, 0x01, 0x58, 0x12, 0x0c, 0x0a, 0x01, 0x59, 0x18,
0x4f, 0x4e, 0x5f, 0x49, 0x44, 0x5f, 0x41, 0x54, 0x54, 0x41, 0x43, 0x4b, 0x10, 0x10, 0x42, 0x17, 0x03, 0x20, 0x01, 0x28, 0x11, 0x52, 0x01, 0x59, 0x22, 0x31, 0x0a, 0x0c, 0x53, 0x32, 0x43, 0x5f,
0x5a, 0x15, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x73, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x21, 0x0a, 0x04, 0x49, 0x6e, 0x66, 0x6f,
0x63, 0x2f, 0x73, 0x63, 0x5f, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0d, 0x2e, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f,
0x6e, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x04, 0x49, 0x6e, 0x66, 0x6f, 0x2a, 0x34, 0x0a, 0x08, 0x41,
0x63, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x44, 0x12, 0x12, 0x0a, 0x0e, 0x41, 0x43, 0x54, 0x49, 0x4f,
0x4e, 0x5f, 0x49, 0x44, 0x5f, 0x4d, 0x4f, 0x56, 0x45, 0x10, 0x00, 0x12, 0x14, 0x0a, 0x10, 0x41,
0x43, 0x54, 0x49, 0x4f, 0x4e, 0x5f, 0x49, 0x44, 0x5f, 0x41, 0x54, 0x54, 0x41, 0x43, 0x4b, 0x10,
0x01, 0x42, 0x17, 0x5a, 0x15, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2f, 0x70, 0x72, 0x6f, 0x74,
0x6f, 0x2f, 0x73, 0x63, 0x2f, 0x73, 0x63, 0x5f, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74,
0x6f, 0x33,
} }
var ( var (

View File

@@ -91,6 +91,8 @@ type EnterResp struct {
SceneSID int64 `protobuf:"varint,1,opt,name=SceneSID,proto3" json:"SceneSID,omitempty"` // 场景服务ID SceneSID int64 `protobuf:"varint,1,opt,name=SceneSID,proto3" json:"SceneSID,omitempty"` // 场景服务ID
UniqueNo int64 `protobuf:"varint,2,opt,name=UniqueNo,proto3" json:"UniqueNo,omitempty"` // 副本唯一编号 UniqueNo int64 `protobuf:"varint,2,opt,name=UniqueNo,proto3" json:"UniqueNo,omitempty"` // 副本唯一编号
MessageID int32 `protobuf:"varint,3,opt,name=MessageID,proto3" json:"MessageID,omitempty"` // 发送给客户端的消息ID
Payload []byte `protobuf:"bytes,4,opt,name=Payload,proto3" json:"Payload,omitempty"` // 消息负载
} }
func (x *EnterResp) Reset() { func (x *EnterResp) Reset() {
@@ -139,6 +141,129 @@ func (x *EnterResp) GetUniqueNo() int64 {
return 0 return 0
} }
func (x *EnterResp) GetMessageID() int32 {
if x != nil {
return x.MessageID
}
return 0
}
func (x *EnterResp) GetPayload() []byte {
if x != nil {
return x.Payload
}
return nil
}
type LeaveReq struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
UID int32 `protobuf:"varint,1,opt,name=UID,proto3" json:"UID,omitempty"` // 用户ID
GatewaySID int64 `protobuf:"varint,2,opt,name=GatewaySID,proto3" json:"GatewaySID,omitempty"` // 网关服务ID
InstanceID int32 `protobuf:"varint,3,opt,name=InstanceID,proto3" json:"InstanceID,omitempty"` // 副本ID
UniqueNo int64 `protobuf:"varint,4,opt,name=UniqueNo,proto3" json:"UniqueNo,omitempty"` // 副本唯一编号
}
func (x *LeaveReq) Reset() {
*x = LeaveReq{}
if protoimpl.UnsafeEnabled {
mi := &file_service_scene_proto_msgTypes[2]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *LeaveReq) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*LeaveReq) ProtoMessage() {}
func (x *LeaveReq) ProtoReflect() protoreflect.Message {
mi := &file_service_scene_proto_msgTypes[2]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use LeaveReq.ProtoReflect.Descriptor instead.
func (*LeaveReq) Descriptor() ([]byte, []int) {
return file_service_scene_proto_rawDescGZIP(), []int{2}
}
func (x *LeaveReq) GetUID() int32 {
if x != nil {
return x.UID
}
return 0
}
func (x *LeaveReq) GetGatewaySID() int64 {
if x != nil {
return x.GatewaySID
}
return 0
}
func (x *LeaveReq) GetInstanceID() int32 {
if x != nil {
return x.InstanceID
}
return 0
}
func (x *LeaveReq) GetUniqueNo() int64 {
if x != nil {
return x.UniqueNo
}
return 0
}
type LeaveResp struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
}
func (x *LeaveResp) Reset() {
*x = LeaveResp{}
if protoimpl.UnsafeEnabled {
mi := &file_service_scene_proto_msgTypes[3]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *LeaveResp) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*LeaveResp) ProtoMessage() {}
func (x *LeaveResp) ProtoReflect() protoreflect.Message {
mi := &file_service_scene_proto_msgTypes[3]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use LeaveResp.ProtoReflect.Descriptor instead.
func (*LeaveResp) Descriptor() ([]byte, []int) {
return file_service_scene_proto_rawDescGZIP(), []int{3}
}
type ActionReq struct { type ActionReq struct {
state protoimpl.MessageState state protoimpl.MessageState
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
@@ -146,14 +271,16 @@ type ActionReq struct {
UniqueNo int64 `protobuf:"varint,1,opt,name=UniqueNo,proto3" json:"UniqueNo,omitempty"` // 副本唯一编号 UniqueNo int64 `protobuf:"varint,1,opt,name=UniqueNo,proto3" json:"UniqueNo,omitempty"` // 副本唯一编号
UID int32 `protobuf:"varint,2,opt,name=UID,proto3" json:"UID,omitempty"` // 用户ID UID int32 `protobuf:"varint,2,opt,name=UID,proto3" json:"UID,omitempty"` // 用户ID
Action int32 `protobuf:"varint,3,opt,name=Action,proto3" json:"Action,omitempty"` // 动作ID Action int32 `protobuf:"varint,3,opt,name=Action,proto3" json:"Action,omitempty"` // 指令ID
Payload []byte `protobuf:"bytes,4,opt,name=Payload,proto3" json:"Payload,omitempty"` // 动作数据 DirX int32 `protobuf:"zigzag32,4,opt,name=DirX,proto3" json:"DirX,omitempty"` // 移动-X方向×1000 缩放)
DirY int32 `protobuf:"zigzag32,5,opt,name=DirY,proto3" json:"DirY,omitempty"` // 移动-Y方向×1000 缩放)
SkillID int32 `protobuf:"varint,6,opt,name=SkillID,proto3" json:"SkillID,omitempty"` // 攻击-技能ID
} }
func (x *ActionReq) Reset() { func (x *ActionReq) Reset() {
*x = ActionReq{} *x = ActionReq{}
if protoimpl.UnsafeEnabled { if protoimpl.UnsafeEnabled {
mi := &file_service_scene_proto_msgTypes[2] mi := &file_service_scene_proto_msgTypes[4]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi) ms.StoreMessageInfo(mi)
} }
@@ -166,7 +293,7 @@ func (x *ActionReq) String() string {
func (*ActionReq) ProtoMessage() {} func (*ActionReq) ProtoMessage() {}
func (x *ActionReq) ProtoReflect() protoreflect.Message { func (x *ActionReq) ProtoReflect() protoreflect.Message {
mi := &file_service_scene_proto_msgTypes[2] mi := &file_service_scene_proto_msgTypes[4]
if protoimpl.UnsafeEnabled && x != nil { if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil { if ms.LoadMessageInfo() == nil {
@@ -179,7 +306,7 @@ func (x *ActionReq) ProtoReflect() protoreflect.Message {
// Deprecated: Use ActionReq.ProtoReflect.Descriptor instead. // Deprecated: Use ActionReq.ProtoReflect.Descriptor instead.
func (*ActionReq) Descriptor() ([]byte, []int) { func (*ActionReq) Descriptor() ([]byte, []int) {
return file_service_scene_proto_rawDescGZIP(), []int{2} return file_service_scene_proto_rawDescGZIP(), []int{4}
} }
func (x *ActionReq) GetUniqueNo() int64 { func (x *ActionReq) GetUniqueNo() int64 {
@@ -203,11 +330,25 @@ func (x *ActionReq) GetAction() int32 {
return 0 return 0
} }
func (x *ActionReq) GetPayload() []byte { func (x *ActionReq) GetDirX() int32 {
if x != nil { if x != nil {
return x.Payload return x.DirX
} }
return nil return 0
}
func (x *ActionReq) GetDirY() int32 {
if x != nil {
return x.DirY
}
return 0
}
func (x *ActionReq) GetSkillID() int32 {
if x != nil {
return x.SkillID
}
return 0
} }
type ActionResp struct { type ActionResp struct {
@@ -219,7 +360,7 @@ type ActionResp struct {
func (x *ActionResp) Reset() { func (x *ActionResp) Reset() {
*x = ActionResp{} *x = ActionResp{}
if protoimpl.UnsafeEnabled { if protoimpl.UnsafeEnabled {
mi := &file_service_scene_proto_msgTypes[3] mi := &file_service_scene_proto_msgTypes[5]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi) ms.StoreMessageInfo(mi)
} }
@@ -232,7 +373,7 @@ func (x *ActionResp) String() string {
func (*ActionResp) ProtoMessage() {} func (*ActionResp) ProtoMessage() {}
func (x *ActionResp) ProtoReflect() protoreflect.Message { func (x *ActionResp) ProtoReflect() protoreflect.Message {
mi := &file_service_scene_proto_msgTypes[3] mi := &file_service_scene_proto_msgTypes[5]
if protoimpl.UnsafeEnabled && x != nil { if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil { if ms.LoadMessageInfo() == nil {
@@ -245,7 +386,7 @@ func (x *ActionResp) ProtoReflect() protoreflect.Message {
// Deprecated: Use ActionResp.ProtoReflect.Descriptor instead. // Deprecated: Use ActionResp.ProtoReflect.Descriptor instead.
func (*ActionResp) Descriptor() ([]byte, []int) { func (*ActionResp) Descriptor() ([]byte, []int) {
return file_service_scene_proto_rawDescGZIP(), []int{3} return file_service_scene_proto_rawDescGZIP(), []int{5}
} }
var File_service_scene_proto protoreflect.FileDescriptor var File_service_scene_proto protoreflect.FileDescriptor
@@ -259,26 +400,43 @@ var file_service_scene_proto_rawDesc = []byte{
0x49, 0x44, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0a, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x49, 0x44, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0a, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61,
0x79, 0x53, 0x49, 0x44, 0x12, 0x1e, 0x0a, 0x0a, 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x79, 0x53, 0x49, 0x44, 0x12, 0x1e, 0x0a, 0x0a, 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65,
0x49, 0x44, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0a, 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x49, 0x44, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0a, 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6e,
0x63, 0x65, 0x49, 0x44, 0x22, 0x43, 0x0a, 0x09, 0x45, 0x6e, 0x74, 0x65, 0x72, 0x52, 0x65, 0x73, 0x63, 0x65, 0x49, 0x44, 0x22, 0x7b, 0x0a, 0x09, 0x45, 0x6e, 0x74, 0x65, 0x72, 0x52, 0x65, 0x73,
0x70, 0x12, 0x1a, 0x0a, 0x08, 0x53, 0x63, 0x65, 0x6e, 0x65, 0x53, 0x49, 0x44, 0x18, 0x01, 0x20, 0x70, 0x12, 0x1a, 0x0a, 0x08, 0x53, 0x63, 0x65, 0x6e, 0x65, 0x53, 0x49, 0x44, 0x18, 0x01, 0x20,
0x01, 0x28, 0x03, 0x52, 0x08, 0x53, 0x63, 0x65, 0x6e, 0x65, 0x53, 0x49, 0x44, 0x12, 0x1a, 0x0a, 0x01, 0x28, 0x03, 0x52, 0x08, 0x53, 0x63, 0x65, 0x6e, 0x65, 0x53, 0x49, 0x44, 0x12, 0x1a, 0x0a,
0x08, 0x55, 0x6e, 0x69, 0x71, 0x75, 0x65, 0x4e, 0x6f, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x55, 0x6e, 0x69, 0x71, 0x75, 0x65, 0x4e, 0x6f, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52,
0x08, 0x55, 0x6e, 0x69, 0x71, 0x75, 0x65, 0x4e, 0x6f, 0x22, 0x6b, 0x0a, 0x09, 0x41, 0x63, 0x74, 0x08, 0x55, 0x6e, 0x69, 0x71, 0x75, 0x65, 0x4e, 0x6f, 0x12, 0x1c, 0x0a, 0x09, 0x4d, 0x65, 0x73,
0x73, 0x61, 0x67, 0x65, 0x49, 0x44, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x09, 0x4d, 0x65,
0x73, 0x73, 0x61, 0x67, 0x65, 0x49, 0x44, 0x12, 0x18, 0x0a, 0x07, 0x50, 0x61, 0x79, 0x6c, 0x6f,
0x61, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x50, 0x61, 0x79, 0x6c, 0x6f, 0x61,
0x64, 0x22, 0x78, 0x0a, 0x08, 0x4c, 0x65, 0x61, 0x76, 0x65, 0x52, 0x65, 0x71, 0x12, 0x10, 0x0a,
0x03, 0x55, 0x49, 0x44, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x55, 0x49, 0x44, 0x12,
0x1e, 0x0a, 0x0a, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x53, 0x49, 0x44, 0x18, 0x02, 0x20,
0x01, 0x28, 0x03, 0x52, 0x0a, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x53, 0x49, 0x44, 0x12,
0x1e, 0x0a, 0x0a, 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x49, 0x44, 0x18, 0x03, 0x20,
0x01, 0x28, 0x05, 0x52, 0x0a, 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x49, 0x44, 0x12,
0x1a, 0x0a, 0x08, 0x55, 0x6e, 0x69, 0x71, 0x75, 0x65, 0x4e, 0x6f, 0x18, 0x04, 0x20, 0x01, 0x28,
0x03, 0x52, 0x08, 0x55, 0x6e, 0x69, 0x71, 0x75, 0x65, 0x4e, 0x6f, 0x22, 0x0b, 0x0a, 0x09, 0x4c,
0x65, 0x61, 0x76, 0x65, 0x52, 0x65, 0x73, 0x70, 0x22, 0x93, 0x01, 0x0a, 0x09, 0x41, 0x63, 0x74,
0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x12, 0x1a, 0x0a, 0x08, 0x55, 0x6e, 0x69, 0x71, 0x75, 0x65, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x12, 0x1a, 0x0a, 0x08, 0x55, 0x6e, 0x69, 0x71, 0x75, 0x65,
0x4e, 0x6f, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x55, 0x6e, 0x69, 0x71, 0x75, 0x65, 0x4e, 0x6f, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x55, 0x6e, 0x69, 0x71, 0x75, 0x65,
0x4e, 0x6f, 0x12, 0x10, 0x0a, 0x03, 0x55, 0x49, 0x44, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x4e, 0x6f, 0x12, 0x10, 0x0a, 0x03, 0x55, 0x49, 0x44, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52,
0x03, 0x55, 0x49, 0x44, 0x12, 0x16, 0x0a, 0x06, 0x41, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x03, 0x03, 0x55, 0x49, 0x44, 0x12, 0x16, 0x0a, 0x06, 0x41, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x03,
0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x41, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x18, 0x0a, 0x07, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x41, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x12, 0x0a, 0x04,
0x50, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x50, 0x44, 0x69, 0x72, 0x58, 0x18, 0x04, 0x20, 0x01, 0x28, 0x11, 0x52, 0x04, 0x44, 0x69, 0x72, 0x58,
0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x22, 0x0c, 0x0a, 0x0a, 0x41, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x12, 0x0a, 0x04, 0x44, 0x69, 0x72, 0x59, 0x18, 0x05, 0x20, 0x01, 0x28, 0x11, 0x52, 0x04,
0x52, 0x65, 0x73, 0x70, 0x32, 0x50, 0x0a, 0x05, 0x53, 0x63, 0x65, 0x6e, 0x65, 0x12, 0x20, 0x0a, 0x44, 0x69, 0x72, 0x59, 0x12, 0x18, 0x0a, 0x07, 0x53, 0x6b, 0x69, 0x6c, 0x6c, 0x49, 0x44, 0x18,
0x05, 0x45, 0x6e, 0x74, 0x65, 0x72, 0x12, 0x09, 0x2e, 0x45, 0x6e, 0x74, 0x65, 0x72, 0x52, 0x65, 0x06, 0x20, 0x01, 0x28, 0x05, 0x52, 0x07, 0x53, 0x6b, 0x69, 0x6c, 0x6c, 0x49, 0x44, 0x22, 0x0c,
0x71, 0x1a, 0x0a, 0x2e, 0x45, 0x6e, 0x74, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x22, 0x00, 0x12, 0x0a, 0x0a, 0x41, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x32, 0x72, 0x0a, 0x05,
0x25, 0x0a, 0x06, 0x41, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x0a, 0x2e, 0x41, 0x63, 0x74, 0x69, 0x53, 0x63, 0x65, 0x6e, 0x65, 0x12, 0x20, 0x0a, 0x05, 0x45, 0x6e, 0x74, 0x65, 0x72, 0x12, 0x09,
0x6f, 0x6e, 0x52, 0x65, 0x71, 0x1a, 0x0b, 0x2e, 0x41, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x2e, 0x45, 0x6e, 0x74, 0x65, 0x72, 0x52, 0x65, 0x71, 0x1a, 0x0a, 0x2e, 0x45, 0x6e, 0x74, 0x65,
0x73, 0x70, 0x22, 0x00, 0x28, 0x01, 0x42, 0x19, 0x5a, 0x17, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x72, 0x52, 0x65, 0x73, 0x70, 0x22, 0x00, 0x12, 0x20, 0x0a, 0x05, 0x4c, 0x65, 0x61, 0x76, 0x65,
0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x73, 0x73, 0x2f, 0x67, 0x72, 0x70, 0x63, 0x5f, 0x70, 0x12, 0x09, 0x2e, 0x4c, 0x65, 0x61, 0x76, 0x65, 0x52, 0x65, 0x71, 0x1a, 0x0a, 0x2e, 0x4c, 0x65,
0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, 0x61, 0x76, 0x65, 0x52, 0x65, 0x73, 0x70, 0x22, 0x00, 0x12, 0x25, 0x0a, 0x06, 0x41, 0x63, 0x74,
0x69, 0x6f, 0x6e, 0x12, 0x0a, 0x2e, 0x41, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x1a,
0x0b, 0x2e, 0x41, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x22, 0x00, 0x28, 0x01,
0x42, 0x19, 0x5a, 0x17, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f,
0x2f, 0x73, 0x73, 0x2f, 0x67, 0x72, 0x70, 0x63, 0x5f, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f,
0x74, 0x6f, 0x33,
} }
var ( var (
@@ -293,20 +451,24 @@ func file_service_scene_proto_rawDescGZIP() []byte {
return file_service_scene_proto_rawDescData return file_service_scene_proto_rawDescData
} }
var file_service_scene_proto_msgTypes = make([]protoimpl.MessageInfo, 4) var file_service_scene_proto_msgTypes = make([]protoimpl.MessageInfo, 6)
var file_service_scene_proto_goTypes = []interface{}{ var file_service_scene_proto_goTypes = []interface{}{
(*EnterReq)(nil), // 0: EnterReq (*EnterReq)(nil), // 0: EnterReq
(*EnterResp)(nil), // 1: EnterResp (*EnterResp)(nil), // 1: EnterResp
(*ActionReq)(nil), // 2: ActionReq (*LeaveReq)(nil), // 2: LeaveReq
(*ActionResp)(nil), // 3: ActionResp (*LeaveResp)(nil), // 3: LeaveResp
(*ActionReq)(nil), // 4: ActionReq
(*ActionResp)(nil), // 5: ActionResp
} }
var file_service_scene_proto_depIdxs = []int32{ var file_service_scene_proto_depIdxs = []int32{
0, // 0: Scene.Enter:input_type -> EnterReq 0, // 0: Scene.Enter:input_type -> EnterReq
2, // 1: Scene.Action:input_type -> ActionReq 2, // 1: Scene.Leave:input_type -> LeaveReq
1, // 2: Scene.Enter:output_type -> EnterResp 4, // 2: Scene.Action:input_type -> ActionReq
3, // 3: Scene.Action:output_type -> ActionResp 1, // 3: Scene.Enter:output_type -> EnterResp
2, // [2:4] is the sub-list for method output_type 3, // 4: Scene.Leave:output_type -> LeaveResp
0, // [0:2] is the sub-list for method input_type 5, // 5: Scene.Action:output_type -> ActionResp
3, // [3:6] is the sub-list for method output_type
0, // [0:3] is the sub-list for method input_type
0, // [0:0] is the sub-list for extension type_name 0, // [0:0] is the sub-list for extension type_name
0, // [0:0] is the sub-list for extension extendee 0, // [0:0] is the sub-list for extension extendee
0, // [0:0] is the sub-list for field type_name 0, // [0:0] is the sub-list for field type_name
@@ -343,7 +505,7 @@ func file_service_scene_proto_init() {
} }
} }
file_service_scene_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { file_service_scene_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*ActionReq); i { switch v := v.(*LeaveReq); i {
case 0: case 0:
return &v.state return &v.state
case 1: case 1:
@@ -355,6 +517,30 @@ func file_service_scene_proto_init() {
} }
} }
file_service_scene_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { file_service_scene_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*LeaveResp); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_service_scene_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*ActionReq); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_service_scene_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*ActionResp); i { switch v := v.(*ActionResp); i {
case 0: case 0:
return &v.state return &v.state
@@ -373,7 +559,7 @@ func file_service_scene_proto_init() {
GoPackagePath: reflect.TypeOf(x{}).PkgPath(), GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_service_scene_proto_rawDesc, RawDescriptor: file_service_scene_proto_rawDesc,
NumEnums: 0, NumEnums: 0,
NumMessages: 4, NumMessages: 6,
NumExtensions: 0, NumExtensions: 0,
NumServices: 1, NumServices: 1,
}, },

View File

@@ -23,6 +23,7 @@ const _ = grpc.SupportPackageIsVersion7
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
type SceneClient interface { type SceneClient interface {
Enter(ctx context.Context, in *EnterReq, opts ...grpc.CallOption) (*EnterResp, error) Enter(ctx context.Context, in *EnterReq, opts ...grpc.CallOption) (*EnterResp, error)
Leave(ctx context.Context, in *LeaveReq, opts ...grpc.CallOption) (*LeaveResp, error)
Action(ctx context.Context, opts ...grpc.CallOption) (Scene_ActionClient, error) Action(ctx context.Context, opts ...grpc.CallOption) (Scene_ActionClient, error)
} }
@@ -43,6 +44,15 @@ func (c *sceneClient) Enter(ctx context.Context, in *EnterReq, opts ...grpc.Call
return out, nil return out, nil
} }
func (c *sceneClient) Leave(ctx context.Context, in *LeaveReq, opts ...grpc.CallOption) (*LeaveResp, error) {
out := new(LeaveResp)
err := c.cc.Invoke(ctx, "/Scene/Leave", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *sceneClient) Action(ctx context.Context, opts ...grpc.CallOption) (Scene_ActionClient, error) { func (c *sceneClient) Action(ctx context.Context, opts ...grpc.CallOption) (Scene_ActionClient, error) {
stream, err := c.cc.NewStream(ctx, &Scene_ServiceDesc.Streams[0], "/Scene/Action", opts...) stream, err := c.cc.NewStream(ctx, &Scene_ServiceDesc.Streams[0], "/Scene/Action", opts...)
if err != nil { if err != nil {
@@ -82,6 +92,7 @@ func (x *sceneActionClient) CloseAndRecv() (*ActionResp, error) {
// for forward compatibility // for forward compatibility
type SceneServer interface { type SceneServer interface {
Enter(context.Context, *EnterReq) (*EnterResp, error) Enter(context.Context, *EnterReq) (*EnterResp, error)
Leave(context.Context, *LeaveReq) (*LeaveResp, error)
Action(Scene_ActionServer) error Action(Scene_ActionServer) error
mustEmbedUnimplementedSceneServer() mustEmbedUnimplementedSceneServer()
} }
@@ -93,6 +104,9 @@ type UnimplementedSceneServer struct {
func (UnimplementedSceneServer) Enter(context.Context, *EnterReq) (*EnterResp, error) { func (UnimplementedSceneServer) Enter(context.Context, *EnterReq) (*EnterResp, error) {
return nil, status.Errorf(codes.Unimplemented, "method Enter not implemented") return nil, status.Errorf(codes.Unimplemented, "method Enter not implemented")
} }
func (UnimplementedSceneServer) Leave(context.Context, *LeaveReq) (*LeaveResp, error) {
return nil, status.Errorf(codes.Unimplemented, "method Leave not implemented")
}
func (UnimplementedSceneServer) Action(Scene_ActionServer) error { func (UnimplementedSceneServer) Action(Scene_ActionServer) error {
return status.Errorf(codes.Unimplemented, "method Action not implemented") return status.Errorf(codes.Unimplemented, "method Action not implemented")
} }
@@ -127,6 +141,24 @@ func _Scene_Enter_Handler(srv interface{}, ctx context.Context, dec func(interfa
return interceptor(ctx, in, info, handler) return interceptor(ctx, in, info, handler)
} }
func _Scene_Leave_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(LeaveReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(SceneServer).Leave(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/Scene/Leave",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(SceneServer).Leave(ctx, req.(*LeaveReq))
}
return interceptor(ctx, in, info, handler)
}
func _Scene_Action_Handler(srv interface{}, stream grpc.ServerStream) error { func _Scene_Action_Handler(srv interface{}, stream grpc.ServerStream) error {
return srv.(SceneServer).Action(&sceneActionServer{stream}) return srv.(SceneServer).Action(&sceneActionServer{stream})
} }
@@ -164,6 +196,10 @@ var Scene_ServiceDesc = grpc.ServiceDesc{
MethodName: "Enter", MethodName: "Enter",
Handler: _Scene_Enter_Handler, Handler: _Scene_Enter_Handler,
}, },
{
MethodName: "Leave",
Handler: _Scene_Leave_Handler,
},
}, },
Streams: []grpc.StreamDesc{ Streams: []grpc.StreamDesc{
{ {

View File

@@ -19,11 +19,11 @@ serve:
ttl: 20 ttl: 20
socket: socket:
web: web:
address: "172.18.28.0" address: "127.0.0.1"
port: 8501 port: 8501
raw: raw:
address: "172.18.28.0" address: "127.0.0.1"
port: 8502 port: 8502
http: http:
address: "172.18.28.0" address: "127.0.0.1"
port: 8503 port: 8503

View File

@@ -28,6 +28,7 @@ func (s *Server) ToClient(server grpc_pb.Gateway_ToClientServer) error {
} }
} else { } else {
if client := ws_handler.UserMgr.GetByUID(int(args.UID)); client != nil { if client := ws_handler.UserMgr.GetByUID(int(args.UID)); client != nil {
if client := ws_handler.UserMgr.GetByUID(args.UID); client != nil {
client.WriteBytes(sc_pb.MessageID(args.MessageID), args.Payload) client.WriteBytes(sc_pb.MessageID(args.MessageID), args.Payload)
} }
} }

View File

@@ -24,13 +24,13 @@ type Client struct {
cancel context.CancelFunc // 取消上下文 cancel context.CancelFunc // 取消上下文
heartBeat time.Time // 最后一次心跳 heartBeat time.Time // 最后一次心跳
UID int UID int32 // 用户ID
SceneSID int64 // 场景服ID SceneSID int64 // 场景服ID
InstanceID int InstanceID int32 // 副本ID副本类型
UniqueNo int64 UniqueNo int64 // 副本唯一编号
} }
func NewClient(uid int, conn socket.ISocketConn) *Client { func NewClient(uid int32, conn socket.ISocketConn) *Client {
client := &Client{ client := &Client{
UID: uid, UID: uid,
conn: conn, conn: conn,
@@ -64,7 +64,7 @@ func (c *Client) Loop() {
} }
case <-t.C: case <-t.C:
_ = c.conn.Ping() _ = c.conn.Ping()
if time.Now().Sub(c.heartBeat) > 120*time.Second { if time.Now().Sub(c.heartBeat) > 60*time.Second {
return return
} }
} }
@@ -86,6 +86,9 @@ func (c *Client) OnEvent(event Event) {
// WriteMessage 向客户端发送消息 // WriteMessage 向客户端发送消息
func (c *Client) WriteMessage(id sc_pb.MessageID, data proto.Message) { func (c *Client) WriteMessage(id sc_pb.MessageID, data proto.Message) {
if c.conn.IsClose() {
return
}
d, err := proto.Marshal(data) d, err := proto.Marshal(data)
if err != nil { if err != nil {
c.logger.Errorf("WriteMessage proto.Marshal err: %v", err) c.logger.Errorf("WriteMessage proto.Marshal err: %v", err)
@@ -106,6 +109,9 @@ func (c *Client) WriteMessage(id sc_pb.MessageID, data proto.Message) {
// WriteBytes 向客户端发送字节数据 // WriteBytes 向客户端发送字节数据
func (c *Client) WriteBytes(id sc_pb.MessageID, data []byte) { func (c *Client) WriteBytes(id sc_pb.MessageID, data []byte) {
if c.conn.IsClose() {
return
}
m, err := proto.Marshal(&sc_pb.Message{ m, err := proto.Marshal(&sc_pb.Message{
ID: id, ID: id,
Payload: data, Payload: data,
@@ -137,5 +143,6 @@ func (c *Client) onClose() {
c.mailChan = nil c.mailChan = nil
} }
UserMgr.Delete(c.UID) UserMgr.Delete(c.UID)
c.onLeave()
c.Done() c.Done()
} }

View File

@@ -18,7 +18,6 @@ func (c *Client) handle(event Event) {
c.cancel() c.cancel()
return return
} }
c.logger.Infof("收到客户端消息:%v", msg.ID)
switch msg.ID { switch msg.ID {
case sc_pb.MessageID_MESSAGE_ID_ENTER_INSTANCE: case sc_pb.MessageID_MESSAGE_ID_ENTER_INSTANCE:
m := &sc_pb.C2S_EnterInstance{} m := &sc_pb.C2S_EnterInstance{}
@@ -49,7 +48,7 @@ func (c *Client) onEnter(msg *sc_pb.C2S_EnterInstance) {
return return
} }
resp, err := client.Enter(c.ctx, &grpc_pb.EnterReq{ resp, err := client.Enter(c.ctx, &grpc_pb.EnterReq{
UID: int32(c.UID), UID: c.UID,
GatewaySID: GatewaySID, GatewaySID: GatewaySID,
InstanceID: msg.InstanceID, InstanceID: msg.InstanceID,
}) })
@@ -59,14 +58,26 @@ func (c *Client) onEnter(msg *sc_pb.C2S_EnterInstance) {
} }
c.SceneSID = resp.SceneSID c.SceneSID = resp.SceneSID
c.UniqueNo = resp.UniqueNo c.UniqueNo = resp.UniqueNo
c.InstanceID = int(msg.InstanceID) c.InstanceID = msg.InstanceID
c.WriteMessage(sc_pb.MessageID_MESSAGE_ID_POSITION, &sc_pb.S2C_Position{ c.WriteBytes(sc_pb.MessageID(resp.MessageID), resp.Payload)
Info: []*sc_pb.PositionInfo{{ }
UID: int32(c.UID),
X: 1, func (c *Client) onLeave() {
Y: 1, client, err := service.SceneNewClient(c.SceneSID)
}}, if err != nil {
c.logger.Errorf("SceneNewClient err: %v", err)
return
}
_, err = client.Leave(c.ctx, &grpc_pb.LeaveReq{
UID: c.UID,
GatewaySID: GatewaySID,
InstanceID: c.InstanceID,
UniqueNo: c.UniqueNo,
}) })
if err != nil {
c.logger.Errorf("leave err: %v", err)
return
}
} }
func (c *Client) onAction(msg *sc_pb.C2S_Action) { func (c *Client) onAction(msg *sc_pb.C2S_Action) {
@@ -75,9 +86,11 @@ func (c *Client) onAction(msg *sc_pb.C2S_Action) {
} }
if err := stream_client.SendMessageToScene(c.SceneSID, stream_client.FunAction, &grpc_pb.ActionReq{ if err := stream_client.SendMessageToScene(c.SceneSID, stream_client.FunAction, &grpc_pb.ActionReq{
UniqueNo: c.UniqueNo, UniqueNo: c.UniqueNo,
UID: int32(c.UID), UID: c.UID,
Action: int32(msg.Action), Action: int32(msg.Action),
Payload: msg.Payload, DirX: msg.DirX,
DirY: msg.DirY,
SkillID: msg.SkillID,
}); err != nil { }); err != nil {
c.logger.Errorf("send action err: %v", err) c.logger.Errorf("send action err: %v", err)
} }

View File

@@ -7,35 +7,35 @@ import (
var UserMgr *userManager var UserMgr *userManager
type userManager struct { type userManager struct {
userMap map[int]*Client userMap map[int32]*Client
sync.RWMutex sync.RWMutex
} }
func init() { func init() {
UserMgr = &userManager{ UserMgr = &userManager{
userMap: make(map[int]*Client), userMap: make(map[int32]*Client),
} }
} }
func (m *userManager) Add(uid int, client *Client) { func (m *userManager) Add(uid int32, client *Client) {
m.Lock() m.Lock()
defer m.Unlock() defer m.Unlock()
m.userMap[uid] = client m.userMap[uid] = client
} }
func (m *userManager) Delete(uid int) { func (m *userManager) Delete(uid int32) {
m.Lock() m.Lock()
defer m.Unlock() defer m.Unlock()
delete(m.userMap, uid) delete(m.userMap, uid)
} }
func (m *userManager) GetAll() map[int]*Client { func (m *userManager) GetAll() map[int32]*Client {
m.RLock() m.RLock()
defer m.RUnlock() defer m.RUnlock()
return m.userMap return m.userMap
} }
func (m *userManager) GetByUID(uid int) *Client { func (m *userManager) GetByUID(uid int32) *Client {
m.RLock() m.RLock()
defer m.RUnlock() defer m.RUnlock()
return m.userMap[uid] return m.userMap[uid]

View File

@@ -30,11 +30,11 @@ func (g *GatewayWsServer) OnHandShake(conn socket.ISocketConn) {
if err != nil { if err != nil {
_ = conn.Close() _ = conn.Close()
} }
if oldClient := ws_handler.UserMgr.GetByUID(t); oldClient != nil { if oldClient := ws_handler.UserMgr.GetByUID(int32(t)); oldClient != nil {
oldClient.CloseClient() oldClient.CloseClient()
} }
client := ws_handler.NewClient(t, conn) client := ws_handler.NewClient(int32(t), conn)
ws_handler.UserMgr.Add(t, client) ws_handler.UserMgr.Add(int32(t), client)
conn.SetParam("client", client) conn.SetParam("client", client)
} }

View File

@@ -2,8 +2,10 @@ package server
import ( import (
"common/log" "common/log"
"common/proto/sc/sc_pb"
"common/proto/ss/grpc_pb" "common/proto/ss/grpc_pb"
"context" "context"
"google.golang.org/protobuf/proto"
"scene/instance" "scene/instance"
"sync" "sync"
) )
@@ -11,7 +13,7 @@ import (
func (s *Server) Enter(ctx context.Context, req *grpc_pb.EnterReq) (*grpc_pb.EnterResp, error) { func (s *Server) Enter(ctx context.Context, req *grpc_pb.EnterReq) (*grpc_pb.EnterResp, error) {
var i *instance.Instance var i *instance.Instance
if len(instance.Mgr.GetAll()) == 0 { 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) i.Start(s.EtcdTTL)
} else { } else {
for _, v := range instance.Mgr.GetAll() { 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 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{ return &grpc_pb.EnterResp{
SceneSID: s.SID, SceneSID: s.SID,
UniqueNo: i.UniqueNo, UniqueNo: i.UniqueNo,
MessageID: int32(sc_pb.MessageID_MESSAGE_ID_ENTER_INSTANCE),
Payload: payload,
}, nil }, 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 { func (s *Server) Action(server grpc_pb.Scene_ActionServer) error {
wg := &sync.WaitGroup{} wg := &sync.WaitGroup{}
wg.Add(1) wg.Add(1)

View File

@@ -20,25 +20,26 @@ import (
// Instance 场景类 // Instance 场景类
type Instance struct { type Instance struct {
wg sync.WaitGroup wg sync.WaitGroup
players map[int]*npc.PlayerNode // 存储所有玩家节点 [uid] players map[int32]*npc.PlayerNode // 存储所有玩家节点 [uid]
ctx context.Context // 停止指令 ctx context.Context // 停止指令
cancel context.CancelFunc // 停止函数 cancel context.CancelFunc // 停止函数
logger *zap.SugaredLogger // 日志 logger *zap.SugaredLogger // 日志
lastLogicTime int64 // 上次逻辑帧执行时间(毫秒时间戳)
SID int64 // 服务ID SID int64 // 服务ID
InstanceID int // 副本ID InstanceID int32 // 副本ID
UniqueNo int64 // 唯一编号 UniqueNo int64 // 唯一编号
EventIn chan proto.Message // 消息入口 EventIn chan proto.Message // 消息入口
} }
// NewScene 初始化场景 // NewScene 初始化场景
func NewScene(sid int64, instanceID int) *Instance { func NewScene(sid int64, instanceID int32) *Instance {
s := &Instance{ s := &Instance{
players: make(map[int]*npc.PlayerNode), players: make(map[int32]*npc.PlayerNode),
SID: sid, SID: sid,
InstanceID: instanceID, InstanceID: instanceID,
UniqueNo: utils.SnowflakeInstance().Generate().Int64(), UniqueNo: utils.SnowflakeInstance().Generate().Int64(),
EventIn: make(chan proto.Message), EventIn: make(chan proto.Message, 1024),
} }
s.logger = log.GetLogger().Named(fmt.Sprintf("instance %v:%v", s.InstanceID, s.UniqueNo)) s.logger = log.GetLogger().Named(fmt.Sprintf("instance %v:%v", s.InstanceID, s.UniqueNo))
s.ctx, s.cancel = context.WithCancel(context.Background()) s.ctx, s.cancel = context.WithCancel(context.Background())
@@ -69,12 +70,15 @@ func (i *Instance) Start(ttl int64) {
} }
// 场景心跳 // 场景心跳
tick := time.NewTicker(50 * time.Millisecond) tick := time.NewTicker(50 * time.Millisecond)
i.lastLogicTime = time.Now().UnixMilli()
for { for {
select { select {
case <-i.ctx.Done(): case <-i.ctx.Done():
return return
case <-tick.C: case <-tick.C:
i.onLogic() now := time.Now().UnixMilli()
i.onLogic(now - i.lastLogicTime)
i.lastLogicTime = now
case e := <-i.EventIn: case e := <-i.EventIn:
i.onEvent(e) i.onEvent(e)
} }
@@ -87,25 +91,27 @@ func (i *Instance) Start(ttl int64) {
func (i *Instance) onEvent(e proto.Message) { func (i *Instance) onEvent(e proto.Message) {
switch v := e.(type) { switch v := e.(type) {
case *grpc_pb.EnterReq: case *grpc_pb.EnterReq:
i.players[int(v.UID)] = npc.NewPlayerNode(v.GatewaySID, int(v.UID)) i.players[v.UID] = npc.NewPlayerNode(v.GatewaySID, v.UID)
case *grpc_pb.ActionReq: case *grpc_pb.ActionReq:
if node, ok := i.players[int(v.UID)]; ok { if node, ok := i.players[v.UID]; ok {
node.AddAction(v) node.AddAction(v)
} }
case *grpc_pb.LeaveReq:
delete(i.players, v.UID)
} }
} }
// 逻辑帧 // 逻辑帧
func (i *Instance) onLogic() { func (i *Instance) onLogic(delta int64) {
positionUpdate := make([]*sc_pb.PositionInfo, 0) positionUpdate := make([]*sc_pb.PositionInfo, 0)
sid := int64(0) sid := int64(0)
// 优先处理移动指令 // 处理玩家指令
for _, node := range i.players { for _, node := range i.players {
if node.LogicMove() { if node.LogicAction(delta) {
positionUpdate = append(positionUpdate, &sc_pb.PositionInfo{ positionUpdate = append(positionUpdate, &sc_pb.PositionInfo{
UID: int32(node.UID), UID: int32(node.UID),
X: node.Position[0], X: int32(node.Position[0] * 100),
Y: node.Position[1], Y: int32(node.Position[1] * 100),
}) })
sid = node.GatewaySID sid = node.GatewaySID
} }

View File

@@ -23,54 +23,3 @@ func NewNPCNode(gatewaySID int64, uid int) *NPCNode {
Action: make([]*grpc_pb.ActionReq, 0), Action: make([]*grpc_pb.ActionReq, 0),
} }
} }
// 逻辑帧-移动
func (p *NPCNode) logicMove() bool {
if p.MoveCross&DirUp != 0 && p.MoveCross&DirDown != 0 {
p.MoveCross &^= DirUp | DirDown
}
if p.MoveCross&DirLeft != 0 && p.MoveCross&DirRight != 0 {
p.MoveCross &^= DirLeft | DirRight
}
var moveX, moveY float64
if p.MoveCross&DirUp != 0 {
moveY += 1
}
if p.MoveCross&DirDown != 0 {
moveY -= 1
}
if p.MoveCross&DirLeft != 0 {
moveX -= 1
}
if p.MoveCross&DirRight != 0 {
moveX += 1
}
// 没有移动
if moveX == 0 && moveY == 0 {
return false
}
if moveX != 0 && moveY != 0 {
const diagonalFactor = 0.7071
moveX *= diagonalFactor
moveY *= diagonalFactor
}
speed := 10.0
p.Position[0] += moveX * speed
p.Position[1] += moveY * speed
if p.Position[0] < 0 {
p.Position[0] = 0
}
if p.Position[0] > 400 {
p.Position[0] = 400
}
if p.Position[1] < 0 {
p.Position[1] = 0
}
if p.Position[1] > 400 {
p.Position[1] = 400
}
return true
}

View File

@@ -1,92 +1,64 @@
package npc package npc
import ( import (
"common/proto/sc/sc_pb"
"common/proto/ss/grpc_pb" "common/proto/ss/grpc_pb"
) )
// PlayerNode 定义玩家节点结构体 // PlayerNode 定义玩家节点结构体
type PlayerNode struct { type PlayerNode struct {
UID int // 用户ID UID int32 // 用户ID
GatewaySID int64 // 网关服务ID GatewaySID int64 // 网关服务ID
MoveSpeed float32 // 移动速度
Position [2]float64 // 二维坐标 [x, y] Position [2]float32 // 二维坐标 [x, y]
MoveCross int8 // 移动十字1 上 2 下 4 左 8 右 MoveDirection [2]int8 // 移动方向 [x, y]
MoveCount int8 // 移动指令使用计数
Action []*grpc_pb.ActionReq // 其他操作 Action []*grpc_pb.ActionReq // 其他操作
} }
func NewPlayerNode(gatewaySID int64, uid int) *PlayerNode { func NewPlayerNode(gatewaySID int64, uid int32) *PlayerNode {
return &PlayerNode{ return &PlayerNode{
UID: uid, UID: uid,
GatewaySID: gatewaySID, GatewaySID: gatewaySID,
Position: [2]float64{0, 0}, MoveSpeed: 5 * 0.00001,
MoveCross: 0, Position: [2]float32{0, 0},
Action: make([]*grpc_pb.ActionReq, 0), Action: make([]*grpc_pb.ActionReq, 0),
} }
} }
// AddAction 将指令存储到玩家身上 // AddAction 将指令存储到玩家身上
func (p *PlayerNode) AddAction(e *grpc_pb.ActionReq) { func (p *PlayerNode) AddAction(e *grpc_pb.ActionReq) {
if e.Action < 16 {
p.MoveCross = int8(e.Action)
} else {
p.Action = append(p.Action, e) p.Action = append(p.Action, e)
}
} }
const ( // LogicAction 处理玩家操作指令
DirUp int8 = 1 << iota // 1 (00000001) // return 是否更新玩家状态
DirDown // 2 (00000010) func (p *PlayerNode) LogicAction(delta int64) bool {
DirLeft // 4 (00000100) for _, a := range p.Action {
DirRight // 8 (00001000) switch sc_pb.ActionID(a.Action) {
) case sc_pb.ActionID_ACTION_ID_MOVE:
p.MoveDirection = [2]int8{int8(a.DirX), int8(a.DirY)}
p.MoveCount = 0
case sc_pb.ActionID_ACTION_ID_ATTACK:
}
}
p.Action = make([]*grpc_pb.ActionReq, 0)
// LogicMove 逻辑帧-移动 return p.move(delta)
func (p *PlayerNode) LogicMove() bool { }
if p.MoveCross&DirUp != 0 && p.MoveCross&DirDown != 0 {
p.MoveCross &^= DirUp | DirDown
}
if p.MoveCross&DirLeft != 0 && p.MoveCross&DirRight != 0 {
p.MoveCross &^= DirLeft | DirRight
}
var moveX, moveY float64 func (p *PlayerNode) move(delta int64) bool {
if p.MoveCross&DirUp != 0 { if p.MoveDirection[0] == 0 && p.MoveDirection[1] == 0 {
moveY += 1
}
if p.MoveCross&DirDown != 0 {
moveY -= 1
}
if p.MoveCross&DirLeft != 0 {
moveX -= 1
}
if p.MoveCross&DirRight != 0 {
moveX += 1
}
// 没有移动
if moveX == 0 && moveY == 0 {
return false return false
} }
// 移动指令只能用2秒客户端需要定期续上
if moveX != 0 && moveY != 0 { if p.MoveCount >= 40 {
const diagonalFactor = 0.7071 p.MoveDirection = [2]int8{0, 0}
moveX *= diagonalFactor return false
moveY *= diagonalFactor
}
speed := 10.0
p.Position[0] += moveX * speed
p.Position[1] += moveY * speed
if p.Position[0] < 0 {
p.Position[0] = 0
}
if p.Position[0] > 400 {
p.Position[0] = 400
}
if p.Position[1] < 0 {
p.Position[1] = 0
}
if p.Position[1] > 400 {
p.Position[1] = 400
} }
p.Position[0] += float32(p.MoveDirection[0]) * float32(delta) * p.MoveSpeed
p.Position[1] += float32(p.MoveDirection[1]) * float32(delta) * p.MoveSpeed
p.MoveCount++
return true return true
} }