xy hai 1 día
pai
achega
4bd86c7d2f

+ 4 - 0
bin/client_msg/common.proto

@@ -257,4 +257,8 @@ message ResShop {
   bool success = 1;
   MsgError err_msg = 2;
   repeated ShopItem list = 3;
+}
+
+message BuyShopItem{
+  string id = 1;
 }

+ 1 - 0
bin/client_msg/msg.ts

@@ -24,4 +24,5 @@ export enum MsgID {
     UpdateUserInfo = 21,
     ReqShop = 22,
     ResShop = 23,
+    BuyShopItem = 24,
 }

+ 1 - 1
src/server/conf/json.go

@@ -27,7 +27,7 @@ func init() {
 	if tools.IsDebug {
 		path = fmt.Sprintf("../../bin/conf/server_%s.json", "debug")
 	} else {
-
+		// path = fmt.Sprintf("../../bin/conf/server_%s.json", "release")
 		path = fmt.Sprintf("/home/ludo_server/bin/conf/server_%s.json", "release")
 	}
 	data, err := os.ReadFile(path)

+ 2 - 0
src/server/gate/router.go

@@ -11,7 +11,9 @@ func init() {
 	msg.Processor.SetRouter(&msg.ReqLogin{}, login.ChanRPC)
 	msg.Processor.SetRouter(&msg.ReqRegister{}, login.ChanRPC)
 
+	msg.Processor.SetRouter(&msg.BuyShopItem{}, hall.ChanRPC)
 	msg.Processor.SetRouter(&msg.EnterHall{}, hall.ChanRPC)
+
 	msg.Processor.SetRouter(&msg.ReqHeartBeat{}, game.ChanRPC)
 	msg.Processor.SetRouter(&msg.SendColorSz{}, game.ChanRPC)
 	msg.Processor.SetRouter(&msg.SendRoleMove{}, game.ChanRPC)

+ 3 - 3
src/server/hall/internal/handler.go

@@ -12,14 +12,14 @@ import (
 	"github.com/name5566/leaf/log"
 )
 
-func handleMsg(m interface{}, h interface{}) {
+func HandleMsg(m interface{}, h interface{}) {
 	skeleton.RegisterChanRPC(reflect.TypeOf(m), h)
 }
 
 // 大厅有进入大厅,离开大厅,加入房间,玩法列表,商城
 func init() {
-	handleMsg(&msg.EnterHall{}, enterHall)
-	handleMsg(&msg.LeaveHall{}, leaveHall)
+	HandleMsg(&msg.EnterHall{}, enterHall)
+	HandleMsg(&msg.LeaveHall{}, leaveHall)
 }
 
 func enterHall(args []interface{}) {

+ 22 - 0
src/server/hall/shop/shop.go

@@ -0,0 +1,22 @@
+package hall
+
+import (
+	"fmt"
+	"server/hall/internal"
+	"server/msg"
+	"server/user"
+
+	"github.com/name5566/leaf/gate"
+)
+
+func init() {
+	internal.HandleMsg(&msg.BuyShopItem{}, onBuy)
+}
+
+func onBuy(args []interface{}) {
+	m := args[0].(*msg.BuyShopItem)
+	fmt.Printf("玩家购买了商品id为:%d\n", m.Id)
+	a := args[1].(gate.Agent)
+	user_id := a.UserData().(*msg.UserInfo).UserId
+	user.AddUserCoin(100, user_id)
+}

+ 50 - 3
src/server/msg/common.pb.go

@@ -2332,6 +2332,50 @@ func (x *ResShop) GetList() []*ShopItem {
 	return nil
 }
 
+type BuyShopItem struct {
+	state         protoimpl.MessageState `protogen:"open.v1"`
+	Id            string                 `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
+	unknownFields protoimpl.UnknownFields
+	sizeCache     protoimpl.SizeCache
+}
+
+func (x *BuyShopItem) Reset() {
+	*x = BuyShopItem{}
+	mi := &file_common_proto_msgTypes[32]
+	ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+	ms.StoreMessageInfo(mi)
+}
+
+func (x *BuyShopItem) String() string {
+	return protoimpl.X.MessageStringOf(x)
+}
+
+func (*BuyShopItem) ProtoMessage() {}
+
+func (x *BuyShopItem) ProtoReflect() protoreflect.Message {
+	mi := &file_common_proto_msgTypes[32]
+	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 BuyShopItem.ProtoReflect.Descriptor instead.
+func (*BuyShopItem) Descriptor() ([]byte, []int) {
+	return file_common_proto_rawDescGZIP(), []int{32}
+}
+
+func (x *BuyShopItem) GetId() string {
+	if x != nil {
+		return x.Id
+	}
+	return ""
+}
+
 var File_common_proto protoreflect.FileDescriptor
 
 const file_common_proto_rawDesc = "" +
@@ -2482,7 +2526,9 @@ const file_common_proto_rawDesc = "" +
 	"\aResShop\x12\x18\n" +
 	"\asuccess\x18\x01 \x01(\bR\asuccess\x12\"\n" +
 	"\aerr_msg\x18\x02 \x01(\v2\t.MsgErrorR\x06errMsg\x12\x1d\n" +
-	"\x04list\x18\x03 \x03(\v2\t.ShopItemR\x04list*K\n" +
+	"\x04list\x18\x03 \x03(\v2\t.ShopItemR\x04list\"\x1d\n" +
+	"\vBuyShopItem\x12\x0e\n" +
+	"\x02id\x18\x01 \x01(\tR\x02id*K\n" +
 	"\broleType\x12\x15\n" +
 	"\x11ROLE_TYPE_UNKNOWN\x10\x00\x12\a\n" +
 	"\x03RED\x10\x01\x12\b\n" +
@@ -2533,7 +2579,7 @@ func file_common_proto_rawDescGZIP() []byte {
 }
 
 var file_common_proto_enumTypes = make([]protoimpl.EnumInfo, 7)
-var file_common_proto_msgTypes = make([]protoimpl.MessageInfo, 32)
+var file_common_proto_msgTypes = make([]protoimpl.MessageInfo, 33)
 var file_common_proto_goTypes = []any{
 	(RoleType)(0),                // 0: roleType
 	(OptType)(0),                 // 1: OptType
@@ -2574,6 +2620,7 @@ var file_common_proto_goTypes = []any{
 	(*BeKickLogin)(nil),          // 36: BeKickLogin
 	(*ReqShop)(nil),              // 37: ReqShop
 	(*ResShop)(nil),              // 38: ResShop
+	(*BuyShopItem)(nil),          // 39: BuyShopItem
 }
 var file_common_proto_depIdxs = []int32{
 	0,  // 0: round.m_color:type_name -> roleType
@@ -2640,7 +2687,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:   32,
+			NumMessages:   33,
 			NumExtensions: 0,
 			NumServices:   0,
 		},

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

@@ -45,6 +45,7 @@ func init() {
 	Processor.Register(&UpdateUserInfo{})
 	Processor.Register(&ReqShop{})
 	Processor.Register(&ResShop{})
+	Processor.Register(&BuyShopItem{})
 	Processor.Range(func(id uint16, t reflect.Type) {
 		log.Debug("消息ID: %d, 消息类型: %s\n", id, t.Elem().Name())
 		msgList = append(msgList, MsgInfo{

+ 1 - 1
src/server/tools/conifg.go

@@ -1,5 +1,5 @@
 package tools
 
 const (
-	IsDebug = false
+	IsDebug = true
 )