From 5265c0a1e21f5a158b37e02d55bb35c22dac733b Mon Sep 17 00:00:00 2001 From: liuxiaobo <1224730913@qq.com> Date: Sun, 15 Jun 2025 22:03:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/pb/match.proto | 5 +-- common/proto/pb/match.pb.go | 58 +++++++++++++++++-------------- server/client/server/chat.go | 4 +-- server/client/server/colorgame.go | 24 +++++++++++++ server/client/server/login.go | 16 ++++++--- server/client/server/service.go | 9 +++-- 6 files changed, 79 insertions(+), 37 deletions(-) create mode 100644 server/client/server/colorgame.go diff --git a/common/pb/match.proto b/common/pb/match.proto index b5253bf..0035b57 100644 --- a/common/pb/match.proto +++ b/common/pb/match.proto @@ -4,11 +4,12 @@ option go_package = "common/proto/pb"; import "code.proto"; import "user.proto"; +import "service.proto"; // 房间匹配 message ReqMatchRoom { - int32 gameId = 1; // 玩法id + ServiceTypeId gameId = 1; // 玩法id int32 roomType = 2; // 房间类型,低级,中级,高级等 } @@ -22,7 +23,7 @@ message RspMatchRoom } ErrCode code = 1; - int32 gameId = 2; // 玩法id + ServiceTypeId gameId = 2; // 玩法id int32 roomType = 3; // 房间类型,低级,中级,高级等 GameUser User = 4; // 玩家数据 diff --git a/common/proto/pb/match.pb.go b/common/proto/pb/match.pb.go index 8647b3f..862659c 100644 --- a/common/proto/pb/match.pb.go +++ b/common/proto/pb/match.pb.go @@ -24,8 +24,8 @@ const ( // 房间匹配 type ReqMatchRoom struct { state protoimpl.MessageState `protogen:"open.v1"` - GameId int32 `protobuf:"varint,1,opt,name=gameId,proto3" json:"gameId,omitempty"` // 玩法id - RoomType int32 `protobuf:"varint,2,opt,name=roomType,proto3" json:"roomType,omitempty"` // 房间类型,低级,中级,高级等 + GameId ServiceTypeId `protobuf:"varint,1,opt,name=gameId,proto3,enum=pb.ServiceTypeId" json:"gameId,omitempty"` // 玩法id + RoomType int32 `protobuf:"varint,2,opt,name=roomType,proto3" json:"roomType,omitempty"` // 房间类型,低级,中级,高级等 unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } @@ -60,11 +60,11 @@ func (*ReqMatchRoom) Descriptor() ([]byte, []int) { return file_match_proto_rawDescGZIP(), []int{0} } -func (x *ReqMatchRoom) GetGameId() int32 { +func (x *ReqMatchRoom) GetGameId() ServiceTypeId { if x != nil { return x.GameId } - return 0 + return ServiceTypeId_STI_Unknown } func (x *ReqMatchRoom) GetRoomType() int32 { @@ -78,10 +78,10 @@ func (x *ReqMatchRoom) GetRoomType() int32 { type RspMatchRoom struct { state protoimpl.MessageState `protogen:"open.v1"` Code ErrCode `protobuf:"varint,1,opt,name=code,proto3,enum=pb.ErrCode" json:"code,omitempty"` - GameId int32 `protobuf:"varint,2,opt,name=gameId,proto3" json:"gameId,omitempty"` // 玩法id - RoomType int32 `protobuf:"varint,3,opt,name=roomType,proto3" json:"roomType,omitempty"` // 房间类型,低级,中级,高级等 - User *GameUser `protobuf:"bytes,4,opt,name=User,proto3" json:"User,omitempty"` // 玩家数据 - ColorInfo *RspMatchRoom_ColorInfo `protobuf:"bytes,20,opt,name=colorInfo,proto3" json:"colorInfo,omitempty"` // color玩法配置信息 + GameId ServiceTypeId `protobuf:"varint,2,opt,name=gameId,proto3,enum=pb.ServiceTypeId" json:"gameId,omitempty"` // 玩法id + RoomType int32 `protobuf:"varint,3,opt,name=roomType,proto3" json:"roomType,omitempty"` // 房间类型,低级,中级,高级等 + User *GameUser `protobuf:"bytes,4,opt,name=User,proto3" json:"User,omitempty"` // 玩家数据 + ColorInfo *RspMatchRoom_ColorInfo `protobuf:"bytes,20,opt,name=colorInfo,proto3" json:"colorInfo,omitempty"` // color玩法配置信息 unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } @@ -123,11 +123,11 @@ func (x *RspMatchRoom) GetCode() ErrCode { return ErrCode_OK } -func (x *RspMatchRoom) GetGameId() int32 { +func (x *RspMatchRoom) GetGameId() ServiceTypeId { if x != nil { return x.GameId } - return 0 + return ServiceTypeId_STI_Unknown } func (x *RspMatchRoom) GetRoomType() int32 { @@ -238,13 +238,13 @@ const file_match_proto_rawDesc = "" + "\n" + "\vmatch.proto\x12\x02pb\x1a\n" + "code.proto\x1a\n" + - "user.proto\"B\n" + - "\fReqMatchRoom\x12\x16\n" + - "\x06gameId\x18\x01 \x01(\x05R\x06gameId\x12\x1a\n" + - "\broomType\x18\x02 \x01(\x05R\broomType\"\xcc\x01\n" + + "user.proto\x1a\rservice.proto\"U\n" + + "\fReqMatchRoom\x12)\n" + + "\x06gameId\x18\x01 \x01(\x0e2\x11.pb.ServiceTypeIdR\x06gameId\x12\x1a\n" + + "\broomType\x18\x02 \x01(\x05R\broomType\"\xdf\x01\n" + "\fRspMatchRoom\x12\x1f\n" + - "\x04code\x18\x01 \x01(\x0e2\v.pb.ErrCodeR\x04code\x12\x16\n" + - "\x06gameId\x18\x02 \x01(\x05R\x06gameId\x12\x1a\n" + + "\x04code\x18\x01 \x01(\x0e2\v.pb.ErrCodeR\x04code\x12)\n" + + "\x06gameId\x18\x02 \x01(\x0e2\x11.pb.ServiceTypeIdR\x06gameId\x12\x1a\n" + "\broomType\x18\x03 \x01(\x05R\broomType\x12 \n" + "\x04User\x18\x04 \x01(\v2\f.pb.GameUserR\x04User\x128\n" + "\tcolorInfo\x18\x14 \x01(\v2\x1a.pb.RspMatchRoom.ColorInfoR\tcolorInfo\x1a\v\n" + @@ -270,19 +270,22 @@ var file_match_proto_goTypes = []any{ (*RspMatchRoom)(nil), // 1: pb.RspMatchRoom (*NotifyUserEnterRoom)(nil), // 2: pb.NotifyUserEnterRoom (*RspMatchRoom_ColorInfo)(nil), // 3: pb.RspMatchRoom.ColorInfo - (ErrCode)(0), // 4: pb.ErrCode - (*GameUser)(nil), // 5: pb.GameUser + (ServiceTypeId)(0), // 4: pb.ServiceTypeId + (ErrCode)(0), // 5: pb.ErrCode + (*GameUser)(nil), // 6: pb.GameUser } var file_match_proto_depIdxs = []int32{ - 4, // 0: pb.RspMatchRoom.code:type_name -> pb.ErrCode - 5, // 1: pb.RspMatchRoom.User:type_name -> pb.GameUser - 3, // 2: pb.RspMatchRoom.colorInfo:type_name -> pb.RspMatchRoom.ColorInfo - 5, // 3: pb.NotifyUserEnterRoom.User:type_name -> pb.GameUser - 4, // [4:4] is the sub-list for method output_type - 4, // [4:4] is the sub-list for method input_type - 4, // [4:4] is the sub-list for extension type_name - 4, // [4:4] is the sub-list for extension extendee - 0, // [0:4] is the sub-list for field type_name + 4, // 0: pb.ReqMatchRoom.gameId:type_name -> pb.ServiceTypeId + 5, // 1: pb.RspMatchRoom.code:type_name -> pb.ErrCode + 4, // 2: pb.RspMatchRoom.gameId:type_name -> pb.ServiceTypeId + 6, // 3: pb.RspMatchRoom.User:type_name -> pb.GameUser + 3, // 4: pb.RspMatchRoom.colorInfo:type_name -> pb.RspMatchRoom.ColorInfo + 6, // 5: pb.NotifyUserEnterRoom.User:type_name -> pb.GameUser + 6, // [6:6] is the sub-list for method output_type + 6, // [6:6] is the sub-list for method input_type + 6, // [6:6] is the sub-list for extension type_name + 6, // [6:6] is the sub-list for extension extendee + 0, // [0:6] is the sub-list for field type_name } func init() { file_match_proto_init() } @@ -292,6 +295,7 @@ func file_match_proto_init() { } file_code_proto_init() file_user_proto_init() + file_service_proto_init() type x struct{} out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ diff --git a/server/client/server/chat.go b/server/client/server/chat.go index ebce578..9f7527e 100644 --- a/server/client/server/chat.go +++ b/server/client/server/chat.go @@ -19,10 +19,10 @@ func (s *ClientService) chat() { // 收到登陆成功消息,判断是否顶号 func (s *ClientService) onChat(cMsg *pb.ClientMsg, msg *pb.RspUserLogin) { if msg.Code != pb.ErrCode_OK { - log.ErrorF("login error: %v", msg.Code) + log.ErrorF("reqLogin error: %v", msg.Code) return } _ = cMsg s.userId = msg.UserId - log.DebugF("user:%v id:%v login success", s.username, msg.UserId) + log.DebugF("user:%v id:%v reqLogin success", s.username, msg.UserId) } diff --git a/server/client/server/colorgame.go b/server/client/server/colorgame.go new file mode 100644 index 0000000..5ac05f5 --- /dev/null +++ b/server/client/server/colorgame.go @@ -0,0 +1,24 @@ +package server + +//func (s *ClientService) reqLogin() { +// log.DebugF("user:%v ready reqLogin", s.username) +// s.SendMsg(pb.ServiceTypeId_STI_Login, int32(pb.MsgId_ReqUserLoginId), &pb.ReqUserLogin{ +// Username: s.username, +// Password: s.password, +// Ip: "", +// DeviceId: "", +// Version: "20250604123030", +// }) +//} +// +//// 收到登陆成功消息,判断是否顶号 +//func (s *ClientService) onLogin(cMsg *pb.ClientMsg, msg *pb.RspUserLogin) { +// if msg.Code != pb.ErrCode_OK { +// log.ErrorF("reqLogin error:%v :%v", msg.Code, msg.Code.String()) +// return +// } +// _ = cMsg +// s.userId = msg.UserId +// s.client.SetUid(msg.UserId) +// log.DebugF("user:%v id:%v reqLogin success", s.username, msg.UserId) +//} diff --git a/server/client/server/login.go b/server/client/server/login.go index 8509b66..e0dd99b 100644 --- a/server/client/server/login.go +++ b/server/client/server/login.go @@ -5,8 +5,8 @@ import ( "github.com/fox/fox/log" ) -func (s *ClientService) login() { - log.DebugF("user:%v ready login", s.username) +func (s *ClientService) reqLogin() { + log.DebugF("user:%v ready reqLogin", s.username) s.SendMsg(pb.ServiceTypeId_STI_Login, int32(pb.MsgId_ReqUserLoginId), &pb.ReqUserLogin{ Username: s.username, Password: s.password, @@ -19,11 +19,19 @@ func (s *ClientService) login() { // 收到登陆成功消息,判断是否顶号 func (s *ClientService) onLogin(cMsg *pb.ClientMsg, msg *pb.RspUserLogin) { if msg.Code != pb.ErrCode_OK { - log.ErrorF("login error:%v :%v", msg.Code, msg.Code.String()) + log.ErrorF("reqLogin error:%v :%v", msg.Code, msg.Code.String()) return } _ = cMsg s.userId = msg.UserId s.client.SetUid(msg.UserId) - log.DebugF("user:%v id:%v login success", s.username, msg.UserId) + log.DebugF("user:%v id:%v reqLogin success", s.username, msg.UserId) +} + +func (s *ClientService) reqMatchRoom() { + log.DebugF(s.Log("ready reqMatch")) + s.SendMsg(pb.ServiceTypeId_STI_Match, int32(pb.MsgId_ReqMatchRoomId), &pb.ReqMatchRoom{ + GameId: pb.ServiceTypeId_STI_ColorGame, + RoomType: 0, + }) } diff --git a/server/client/server/service.go b/server/client/server/service.go index 96eb18c..63c4bcf 100644 --- a/server/client/server/service.go +++ b/server/client/server/service.go @@ -60,8 +60,8 @@ func newClientService(serviceId int) *ClientService { } func (s *ClientService) loopLoginHour() { - s.login() - time.AfterFunc(5*time.Minute, s.loopLoginHour) + s.reqLogin() + //time.AfterFunc(5*time.Minute, s.loopLoginHour) } func (s *ClientService) OnInit() { @@ -108,3 +108,8 @@ func (s *ClientService) SendMsg(serviceTypeId pb.ServiceTypeId, msgId int32, msg data, _ := proto.Marshal(msg) s.SendData(serviceTypeId, msgId, data) } + +func (s *ClientService) Log(format string, a ...any) string { + head := fmt.Sprintf("user:%v ", s.userId) + return head + fmt.Sprintf(format, a...) +}