diff --git a/answer/server_state_checker.go b/answer/server_state_checker.go new file mode 100644 index 0000000..ba9d79c --- /dev/null +++ b/answer/server_state_checker.go @@ -0,0 +1,37 @@ +package answer + +import ( + "fmt" + "github.com/ggmolly/belfast/connection" + "github.com/ggmolly/belfast/logger" + "github.com/ggmolly/belfast/orm" + "github.com/ggmolly/belfast/protobuf" + "google.golang.org/protobuf/proto" +) + +func Forge_SC10019(buffer *[]byte, client *connection.Client) (int, int, error) { + response := protobuf.SC_10019{} + + // Update server list + var belfastServers []orm.Server + // Decrease by 1 the state of all servers + err := orm.GormDB.Order("id asc").Find(&belfastServers).Error + if err != nil { + logger.LogEvent("Server", "SC_10019", fmt.Sprintf("failed to fetch servers: %s", err.Error()), logger.LOG_LEVEL_ERROR) + return 0, 10019, err + } + Servers = make([]*protobuf.SERVERINFO, len(belfastServers)) + for i, server := range belfastServers { + Servers[i] = &protobuf.SERVERINFO{ + Ids: []uint32{server.ID}, + Ip: proto.String(server.IP), + Port: proto.Uint32(server.Port), + State: proto.Uint32(*server.StateID - 1), // StateID is 0-based in Azur Lane, but 1-based in the database + Name: proto.String(server.Name), + Sort: proto.Uint32(uint32(i + 1)), + } + } + response.Serverlist = Servers + logger.LogEvent("Server", "SC_10019", fmt.Sprintf("sending %d servers", len(response.Serverlist)), logger.LOG_LEVEL_WARN) + return client.SendMessage(10019, &response) +} diff --git a/main.go b/main.go index 8a30c9c..bd5b6fc 100644 --- a/main.go +++ b/main.go @@ -84,6 +84,7 @@ func init() { JP: &[]packets.PacketHandler{answer.Forge_SC10803_CN_JP_KR_TW}, KR: &[]packets.PacketHandler{answer.Forge_SC10803_CN_JP_KR_TW}, }) + packets.RegisterPacketHandler(10018, []packets.PacketHandler{answer.Forge_SC10019}) packets.RegisterPacketHandler(10022, []packets.PacketHandler{answer.JoinServer}) packets.RegisterPacketHandler(10026, []packets.PacketHandler{answer.PlayerExist}) packets.RegisterPacketHandler(11001, []packets.PacketHandler{ diff --git a/protobuf/CS_10018.pb.go b/protobuf/CS_10018.pb.go new file mode 100644 index 0000000..3a10b25 --- /dev/null +++ b/protobuf/CS_10018.pb.go @@ -0,0 +1,141 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.28.1 +// protoc v4.24.0 +// source: CS_10018.proto + +package protobuf + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type CS_10018 struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Arg *uint32 `protobuf:"varint,1,req,name=arg" json:"arg,omitempty"` +} + +func (x *CS_10018) Reset() { + *x = CS_10018{} + if protoimpl.UnsafeEnabled { + mi := &file_CS_10018_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *CS_10018) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CS_10018) ProtoMessage() {} + +func (x *CS_10018) ProtoReflect() protoreflect.Message { + mi := &file_CS_10018_proto_msgTypes[0] + 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 CS_10018.ProtoReflect.Descriptor instead. +func (*CS_10018) Descriptor() ([]byte, []int) { + return file_CS_10018_proto_rawDescGZIP(), []int{0} +} + +func (x *CS_10018) GetArg() uint32 { + if x != nil && x.Arg != nil { + return *x.Arg + } + return 0 +} + +var File_CS_10018_proto protoreflect.FileDescriptor + +var file_CS_10018_proto_rawDesc = []byte{ + 0x0a, 0x0e, 0x43, 0x53, 0x5f, 0x31, 0x30, 0x30, 0x31, 0x38, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x12, 0x08, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x22, 0x1c, 0x0a, 0x08, 0x43, 0x53, + 0x5f, 0x31, 0x30, 0x30, 0x31, 0x38, 0x12, 0x10, 0x0a, 0x03, 0x61, 0x72, 0x67, 0x18, 0x01, 0x20, + 0x02, 0x28, 0x0d, 0x52, 0x03, 0x61, 0x72, 0x67, 0x42, 0x0b, 0x5a, 0x09, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x62, 0x75, 0x66, 0x2f, +} + +var ( + file_CS_10018_proto_rawDescOnce sync.Once + file_CS_10018_proto_rawDescData = file_CS_10018_proto_rawDesc +) + +func file_CS_10018_proto_rawDescGZIP() []byte { + file_CS_10018_proto_rawDescOnce.Do(func() { + file_CS_10018_proto_rawDescData = protoimpl.X.CompressGZIP(file_CS_10018_proto_rawDescData) + }) + return file_CS_10018_proto_rawDescData +} + +var file_CS_10018_proto_msgTypes = make([]protoimpl.MessageInfo, 1) +var file_CS_10018_proto_goTypes = []interface{}{ + (*CS_10018)(nil), // 0: protobuf.CS_10018 +} +var file_CS_10018_proto_depIdxs = []int32{ + 0, // [0:0] is the sub-list for method output_type + 0, // [0:0] 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 extendee + 0, // [0:0] is the sub-list for field type_name +} + +func init() { file_CS_10018_proto_init() } +func file_CS_10018_proto_init() { + if File_CS_10018_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_CS_10018_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*CS_10018); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_CS_10018_proto_rawDesc, + NumEnums: 0, + NumMessages: 1, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_CS_10018_proto_goTypes, + DependencyIndexes: file_CS_10018_proto_depIdxs, + MessageInfos: file_CS_10018_proto_msgTypes, + }.Build() + File_CS_10018_proto = out.File + file_CS_10018_proto_rawDesc = nil + file_CS_10018_proto_goTypes = nil + file_CS_10018_proto_depIdxs = nil +} diff --git a/protobuf/SC_10019.pb.go b/protobuf/SC_10019.pb.go new file mode 100644 index 0000000..cf73594 --- /dev/null +++ b/protobuf/SC_10019.pb.go @@ -0,0 +1,147 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.28.1 +// protoc v4.24.0 +// source: SC_10019.proto + +package protobuf + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type SC_10019 struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Serverlist []*SERVERINFO `protobuf:"bytes,1,rep,name=serverlist" json:"serverlist,omitempty"` +} + +func (x *SC_10019) Reset() { + *x = SC_10019{} + if protoimpl.UnsafeEnabled { + mi := &file_SC_10019_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *SC_10019) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SC_10019) ProtoMessage() {} + +func (x *SC_10019) ProtoReflect() protoreflect.Message { + mi := &file_SC_10019_proto_msgTypes[0] + 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 SC_10019.ProtoReflect.Descriptor instead. +func (*SC_10019) Descriptor() ([]byte, []int) { + return file_SC_10019_proto_rawDescGZIP(), []int{0} +} + +func (x *SC_10019) GetServerlist() []*SERVERINFO { + if x != nil { + return x.Serverlist + } + return nil +} + +var File_SC_10019_proto protoreflect.FileDescriptor + +var file_SC_10019_proto_rawDesc = []byte{ + 0x0a, 0x0e, 0x53, 0x43, 0x5f, 0x31, 0x30, 0x30, 0x31, 0x39, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x12, 0x08, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x1a, 0x0c, 0x70, 0x31, 0x30, 0x5f, + 0x70, 0x62, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x40, 0x0a, 0x08, 0x53, 0x43, 0x5f, 0x31, + 0x30, 0x30, 0x31, 0x39, 0x12, 0x34, 0x0a, 0x0a, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x6c, 0x69, + 0x73, 0x74, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x62, 0x75, 0x66, 0x2e, 0x53, 0x45, 0x52, 0x56, 0x45, 0x52, 0x49, 0x4e, 0x46, 0x4f, 0x52, 0x0a, + 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x6c, 0x69, 0x73, 0x74, 0x42, 0x0b, 0x5a, 0x09, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, +} + +var ( + file_SC_10019_proto_rawDescOnce sync.Once + file_SC_10019_proto_rawDescData = file_SC_10019_proto_rawDesc +) + +func file_SC_10019_proto_rawDescGZIP() []byte { + file_SC_10019_proto_rawDescOnce.Do(func() { + file_SC_10019_proto_rawDescData = protoimpl.X.CompressGZIP(file_SC_10019_proto_rawDescData) + }) + return file_SC_10019_proto_rawDescData +} + +var file_SC_10019_proto_msgTypes = make([]protoimpl.MessageInfo, 1) +var file_SC_10019_proto_goTypes = []interface{}{ + (*SC_10019)(nil), // 0: protobuf.SC_10019 + (*SERVERINFO)(nil), // 1: protobuf.SERVERINFO +} +var file_SC_10019_proto_depIdxs = []int32{ + 1, // 0: protobuf.SC_10019.serverlist:type_name -> protobuf.SERVERINFO + 1, // [1:1] is the sub-list for method output_type + 1, // [1:1] is the sub-list for method input_type + 1, // [1:1] is the sub-list for extension type_name + 1, // [1:1] is the sub-list for extension extendee + 0, // [0:1] is the sub-list for field type_name +} + +func init() { file_SC_10019_proto_init() } +func file_SC_10019_proto_init() { + if File_SC_10019_proto != nil { + return + } + file_SERVERINFO_proto_init() + if !protoimpl.UnsafeEnabled { + file_SC_10019_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*SC_10019); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_SC_10019_proto_rawDesc, + NumEnums: 0, + NumMessages: 1, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_SC_10019_proto_goTypes, + DependencyIndexes: file_SC_10019_proto_depIdxs, + MessageInfos: file_SC_10019_proto_msgTypes, + }.Build() + File_SC_10019_proto = out.File + file_SC_10019_proto_rawDesc = nil + file_SC_10019_proto_goTypes = nil + file_SC_10019_proto_depIdxs = nil +}