xy 6 روز پیش
والد
کامیت
8a661e03cc

+ 20 - 0
bin/client_msg/common.proto

@@ -266,6 +266,26 @@ message HistoryRecord{
   string user_id = 3;
 }
 
+message ReqLudoHistory{
+  string user_id = 1;
+}
+
+message ResLudoHistory{
+  bool success = 1;
+  MsgError err_msg = 2;
+  repeated HistoryRecord list = 3;
+}
+
+message ReqLudoRoomInfo{
+  int64 room_id = 1;
+}
+
+message ResLudoRoomInfo{
+  bool success = 1;
+  MsgError err_msg = 2;
+  RoomInfo info = 3;
+}
+
 message BuyShopItem{
   string id = 1;
 }

+ 6 - 3
src/server/hall/history/history.go

@@ -6,6 +6,7 @@ import (
 	"fmt"
 	mysqlmgr "server/db/mysql"
 	"server/msg"
+	"strings"
 	"time"
 )
 
@@ -14,15 +15,17 @@ func AddHistory(room_info *msg.RoomInfo) (int64, error) {
 	if err != nil {
 		return 0, fmt.Errorf("failed to marshal room info: %v", err)
 	}
-
-	room_id, err := mysqlmgr.Insert("INSERT INTO ludo_roominfo (room_info) VALUES (?)", jsonData)
+	now := time.Now()
+	room_id, err := mysqlmgr.Insert("INSERT INTO ludo_roominfo (create_time,room_info) VALUES (?,?)", now, jsonData)
 	if err != nil {
 		return 0, fmt.Errorf("failed to insert room info: %v", err)
 	}
 	var userIDs []string = make([]string, 0, 4)
 
 	for _, v := range room_info.Colors {
-		userIDs = append(userIDs, v.MId)
+		if !strings.Contains(v.MId, "robot") {
+			userIDs = append(userIDs, v.MId)
+		}
 	}
 
 	err = addUsersHistoryToRoom(room_id, userIDs)

+ 240 - 12
src/server/msg/common.pb.go

@@ -2392,6 +2392,214 @@ func (x *HistoryRecord) GetUserId() string {
 	return ""
 }
 
+type ReqLudoHistory struct {
+	state         protoimpl.MessageState `protogen:"open.v1"`
+	UserId        string                 `protobuf:"bytes,1,opt,name=user_id,json=userId,proto3" json:"user_id,omitempty"`
+	unknownFields protoimpl.UnknownFields
+	sizeCache     protoimpl.SizeCache
+}
+
+func (x *ReqLudoHistory) Reset() {
+	*x = ReqLudoHistory{}
+	mi := &file_common_proto_msgTypes[33]
+	ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+	ms.StoreMessageInfo(mi)
+}
+
+func (x *ReqLudoHistory) String() string {
+	return protoimpl.X.MessageStringOf(x)
+}
+
+func (*ReqLudoHistory) ProtoMessage() {}
+
+func (x *ReqLudoHistory) ProtoReflect() protoreflect.Message {
+	mi := &file_common_proto_msgTypes[33]
+	if x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
+}
+
+// Deprecated: Use ReqLudoHistory.ProtoReflect.Descriptor instead.
+func (*ReqLudoHistory) Descriptor() ([]byte, []int) {
+	return file_common_proto_rawDescGZIP(), []int{33}
+}
+
+func (x *ReqLudoHistory) GetUserId() string {
+	if x != nil {
+		return x.UserId
+	}
+	return ""
+}
+
+type ResLudoHistory struct {
+	state         protoimpl.MessageState `protogen:"open.v1"`
+	Success       bool                   `protobuf:"varint,1,opt,name=success,proto3" json:"success,omitempty"`
+	ErrMsg        *MsgError              `protobuf:"bytes,2,opt,name=err_msg,json=errMsg,proto3" json:"err_msg,omitempty"`
+	List          []*HistoryRecord       `protobuf:"bytes,3,rep,name=list,proto3" json:"list,omitempty"`
+	unknownFields protoimpl.UnknownFields
+	sizeCache     protoimpl.SizeCache
+}
+
+func (x *ResLudoHistory) Reset() {
+	*x = ResLudoHistory{}
+	mi := &file_common_proto_msgTypes[34]
+	ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+	ms.StoreMessageInfo(mi)
+}
+
+func (x *ResLudoHistory) String() string {
+	return protoimpl.X.MessageStringOf(x)
+}
+
+func (*ResLudoHistory) ProtoMessage() {}
+
+func (x *ResLudoHistory) ProtoReflect() protoreflect.Message {
+	mi := &file_common_proto_msgTypes[34]
+	if x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
+}
+
+// Deprecated: Use ResLudoHistory.ProtoReflect.Descriptor instead.
+func (*ResLudoHistory) Descriptor() ([]byte, []int) {
+	return file_common_proto_rawDescGZIP(), []int{34}
+}
+
+func (x *ResLudoHistory) GetSuccess() bool {
+	if x != nil {
+		return x.Success
+	}
+	return false
+}
+
+func (x *ResLudoHistory) GetErrMsg() *MsgError {
+	if x != nil {
+		return x.ErrMsg
+	}
+	return nil
+}
+
+func (x *ResLudoHistory) GetList() []*HistoryRecord {
+	if x != nil {
+		return x.List
+	}
+	return nil
+}
+
+type ReqLudoRoomInfo struct {
+	state         protoimpl.MessageState `protogen:"open.v1"`
+	RoomId        int64                  `protobuf:"varint,1,opt,name=room_id,json=roomId,proto3" json:"room_id,omitempty"`
+	unknownFields protoimpl.UnknownFields
+	sizeCache     protoimpl.SizeCache
+}
+
+func (x *ReqLudoRoomInfo) Reset() {
+	*x = ReqLudoRoomInfo{}
+	mi := &file_common_proto_msgTypes[35]
+	ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+	ms.StoreMessageInfo(mi)
+}
+
+func (x *ReqLudoRoomInfo) String() string {
+	return protoimpl.X.MessageStringOf(x)
+}
+
+func (*ReqLudoRoomInfo) ProtoMessage() {}
+
+func (x *ReqLudoRoomInfo) ProtoReflect() protoreflect.Message {
+	mi := &file_common_proto_msgTypes[35]
+	if x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
+}
+
+// Deprecated: Use ReqLudoRoomInfo.ProtoReflect.Descriptor instead.
+func (*ReqLudoRoomInfo) Descriptor() ([]byte, []int) {
+	return file_common_proto_rawDescGZIP(), []int{35}
+}
+
+func (x *ReqLudoRoomInfo) GetRoomId() int64 {
+	if x != nil {
+		return x.RoomId
+	}
+	return 0
+}
+
+type ResLudoRoomInfo struct {
+	state         protoimpl.MessageState `protogen:"open.v1"`
+	Success       bool                   `protobuf:"varint,1,opt,name=success,proto3" json:"success,omitempty"`
+	ErrMsg        *MsgError              `protobuf:"bytes,2,opt,name=err_msg,json=errMsg,proto3" json:"err_msg,omitempty"`
+	Info          *RoomInfo              `protobuf:"bytes,3,opt,name=info,proto3" json:"info,omitempty"`
+	unknownFields protoimpl.UnknownFields
+	sizeCache     protoimpl.SizeCache
+}
+
+func (x *ResLudoRoomInfo) Reset() {
+	*x = ResLudoRoomInfo{}
+	mi := &file_common_proto_msgTypes[36]
+	ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+	ms.StoreMessageInfo(mi)
+}
+
+func (x *ResLudoRoomInfo) String() string {
+	return protoimpl.X.MessageStringOf(x)
+}
+
+func (*ResLudoRoomInfo) ProtoMessage() {}
+
+func (x *ResLudoRoomInfo) ProtoReflect() protoreflect.Message {
+	mi := &file_common_proto_msgTypes[36]
+	if x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
+}
+
+// Deprecated: Use ResLudoRoomInfo.ProtoReflect.Descriptor instead.
+func (*ResLudoRoomInfo) Descriptor() ([]byte, []int) {
+	return file_common_proto_rawDescGZIP(), []int{36}
+}
+
+func (x *ResLudoRoomInfo) GetSuccess() bool {
+	if x != nil {
+		return x.Success
+	}
+	return false
+}
+
+func (x *ResLudoRoomInfo) GetErrMsg() *MsgError {
+	if x != nil {
+		return x.ErrMsg
+	}
+	return nil
+}
+
+func (x *ResLudoRoomInfo) GetInfo() *RoomInfo {
+	if x != nil {
+		return x.Info
+	}
+	return nil
+}
+
 type BuyShopItem struct {
 	state         protoimpl.MessageState `protogen:"open.v1"`
 	Id            string                 `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
@@ -2401,7 +2609,7 @@ type BuyShopItem struct {
 
 func (x *BuyShopItem) Reset() {
 	*x = BuyShopItem{}
-	mi := &file_common_proto_msgTypes[33]
+	mi := &file_common_proto_msgTypes[37]
 	ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
 	ms.StoreMessageInfo(mi)
 }
@@ -2413,7 +2621,7 @@ func (x *BuyShopItem) String() string {
 func (*BuyShopItem) ProtoMessage() {}
 
 func (x *BuyShopItem) ProtoReflect() protoreflect.Message {
-	mi := &file_common_proto_msgTypes[33]
+	mi := &file_common_proto_msgTypes[37]
 	if x != nil {
 		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
 		if ms.LoadMessageInfo() == nil {
@@ -2426,7 +2634,7 @@ func (x *BuyShopItem) ProtoReflect() protoreflect.Message {
 
 // Deprecated: Use BuyShopItem.ProtoReflect.Descriptor instead.
 func (*BuyShopItem) Descriptor() ([]byte, []int) {
-	return file_common_proto_rawDescGZIP(), []int{33}
+	return file_common_proto_rawDescGZIP(), []int{37}
 }
 
 func (x *BuyShopItem) GetId() string {
@@ -2590,7 +2798,19 @@ const file_common_proto_rawDesc = "" +
 	"\rHistoryRecord\x12\x0e\n" +
 	"\x02id\x18\x01 \x01(\x05R\x02id\x12\x17\n" +
 	"\aroom_id\x18\x02 \x01(\x05R\x06roomId\x12\x17\n" +
-	"\auser_id\x18\x03 \x01(\tR\x06userId\"\x1d\n" +
+	"\auser_id\x18\x03 \x01(\tR\x06userId\")\n" +
+	"\x0eReqLudoHistory\x12\x17\n" +
+	"\auser_id\x18\x01 \x01(\tR\x06userId\"r\n" +
+	"\x0eResLudoHistory\x12\x18\n" +
+	"\asuccess\x18\x01 \x01(\bR\asuccess\x12\"\n" +
+	"\aerr_msg\x18\x02 \x01(\v2\t.MsgErrorR\x06errMsg\x12\"\n" +
+	"\x04list\x18\x03 \x03(\v2\x0e.HistoryRecordR\x04list\"*\n" +
+	"\x0fReqLudoRoomInfo\x12\x17\n" +
+	"\aroom_id\x18\x01 \x01(\x03R\x06roomId\"n\n" +
+	"\x0fResLudoRoomInfo\x12\x18\n" +
+	"\asuccess\x18\x01 \x01(\bR\asuccess\x12\"\n" +
+	"\aerr_msg\x18\x02 \x01(\v2\t.MsgErrorR\x06errMsg\x12\x1d\n" +
+	"\x04info\x18\x03 \x01(\v2\t.RoomInfoR\x04info\"\x1d\n" +
 	"\vBuyShopItem\x12\x0e\n" +
 	"\x02id\x18\x01 \x01(\tR\x02id*K\n" +
 	"\broleType\x12\x15\n" +
@@ -2643,7 +2863,7 @@ func file_common_proto_rawDescGZIP() []byte {
 }
 
 var file_common_proto_enumTypes = make([]protoimpl.EnumInfo, 7)
-var file_common_proto_msgTypes = make([]protoimpl.MessageInfo, 34)
+var file_common_proto_msgTypes = make([]protoimpl.MessageInfo, 38)
 var file_common_proto_goTypes = []any{
 	(RoleType)(0),                // 0: roleType
 	(OptType)(0),                 // 1: OptType
@@ -2685,7 +2905,11 @@ var file_common_proto_goTypes = []any{
 	(*ReqShop)(nil),              // 37: ReqShop
 	(*ResShop)(nil),              // 38: ResShop
 	(*HistoryRecord)(nil),        // 39: HistoryRecord
-	(*BuyShopItem)(nil),          // 40: BuyShopItem
+	(*ReqLudoHistory)(nil),       // 40: ReqLudoHistory
+	(*ResLudoHistory)(nil),       // 41: ResLudoHistory
+	(*ReqLudoRoomInfo)(nil),      // 42: ReqLudoRoomInfo
+	(*ResLudoRoomInfo)(nil),      // 43: ResLudoRoomInfo
+	(*BuyShopItem)(nil),          // 44: BuyShopItem
 }
 var file_common_proto_depIdxs = []int32{
 	0,  // 0: round.m_color:type_name -> roleType
@@ -2734,11 +2958,15 @@ var file_common_proto_depIdxs = []int32{
 	31, // 43: BeKickLogin.err_msg:type_name -> MsgError
 	31, // 44: ResShop.err_msg:type_name -> MsgError
 	35, // 45: ResShop.list:type_name -> ShopItem
-	46, // [46:46] is the sub-list for method output_type
-	46, // [46:46] is the sub-list for method input_type
-	46, // [46:46] is the sub-list for extension type_name
-	46, // [46:46] is the sub-list for extension extendee
-	0,  // [0:46] is the sub-list for field type_name
+	31, // 46: ResLudoHistory.err_msg:type_name -> MsgError
+	39, // 47: ResLudoHistory.list:type_name -> HistoryRecord
+	31, // 48: ResLudoRoomInfo.err_msg:type_name -> MsgError
+	8,  // 49: ResLudoRoomInfo.info:type_name -> RoomInfo
+	50, // [50:50] is the sub-list for method output_type
+	50, // [50:50] is the sub-list for method input_type
+	50, // [50:50] is the sub-list for extension type_name
+	50, // [50:50] is the sub-list for extension extendee
+	0,  // [0:50] is the sub-list for field type_name
 }
 
 func init() { file_common_proto_init() }
@@ -2752,7 +2980,7 @@ func file_common_proto_init() {
 			GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
 			RawDescriptor: unsafe.Slice(unsafe.StringData(file_common_proto_rawDesc), len(file_common_proto_rawDesc)),
 			NumEnums:      7,
-			NumMessages:   34,
+			NumMessages:   38,
 			NumExtensions: 0,
 			NumServices:   0,
 		},

+ 7 - 0
src/server/msg/msg.go

@@ -47,6 +47,13 @@ func init() {
 	Processor.Register(&ResShop{})
 	Processor.Register(&BuyShopItem{})
 	Processor.Register(&HistoryRecord{})
+
+	Processor.Register(&ReqLudoHistory{})
+	Processor.Register(&ResLudoHistory{})
+
+	Processor.Register(&ReqLudoRoomInfo{})
+	Processor.Register(&ResLudoRoomInfo{})
+
 	Processor.Range(func(id uint16, t reflect.Type) {
 		log.Debug("消息ID: %d, 消息类型: %s\n", id, t.Elem().Name())
 		msgList = append(msgList, MsgInfo{

+ 55 - 0
src/server/webserver/history.go

@@ -0,0 +1,55 @@
+package main
+
+import (
+	"net/http"
+	"server/hall/history"
+	"server/msg"
+
+	"github.com/gin-gonic/gin"
+)
+
+func GetHistorList(c *gin.Context) {
+	req := c.MustGet("protobuf_data").(*msg.ReqLudoHistory)
+	list, err := history.GetHistoryByUserID(req.UserId)
+	if err != nil {
+		c.ProtoBuf(http.StatusOK, &msg.ResLudoHistory{
+
+			Success: false,
+			ErrMsg: &msg.MsgError{
+				ErrorCode: 101,
+				ErrorMsg:  "GetHistorList is error!",
+			},
+		})
+		return
+	}
+
+	c.ProtoBuf(http.StatusOK, &msg.ResLudoHistory{
+
+		Success: true,
+		ErrMsg:  nil,
+		List:    list,
+	})
+}
+
+func GetLudoRoomInfo(c *gin.Context) {
+	req := c.MustGet("protobuf_data").(*msg.ReqLudoRoomInfo)
+	info, err := history.GetRoomInfoByID(int(req.RoomId))
+	if err != nil {
+		c.ProtoBuf(http.StatusOK, &msg.ResLudoRoomInfo{
+
+			Success: false,
+			ErrMsg: &msg.MsgError{
+				ErrorCode: 101,
+				ErrorMsg:  "GetLudoRoomInfo is error!",
+			},
+		})
+		return
+	}
+
+	c.ProtoBuf(http.StatusOK, &msg.ResLudoRoomInfo{
+
+		Success: true,
+		ErrMsg:  nil,
+		Info:    info,
+	})
+}

+ 4 - 0
src/server/webserver/main.go

@@ -70,5 +70,9 @@ func main() {
 	r.POST("/ReqLogin", ParseProtoBuf(&msg.ReqLogin{}), ReqLogin)
 	r.POST("/ReqRegister", ParseProtoBuf(&msg.ReqRegister{}), ReqRegister)
 	r.POST("/ReqShop", ParseProtoBuf(&msg.ReqShop{}), ReqShop)
+
+	r.POST("/GetHistorList", ParseProtoBuf(&msg.ReqLudoHistory{}), GetHistorList)
+	r.POST("/GetLudoRoomInfo", ParseProtoBuf(&msg.ReqLudoRoomInfo{}), GetLudoRoomInfo)
+
 	r.Run(":8080") // 默认监听 :8080
 }