系统优化
This commit is contained in:
parent
13eb99f410
commit
4190880b15
@ -48,6 +48,8 @@ var Server struct {
|
|||||||
TELOGDIR string
|
TELOGDIR string
|
||||||
GoogleVerify bool
|
GoogleVerify bool
|
||||||
Partition int
|
Partition int
|
||||||
|
KafkaAddr string
|
||||||
|
KafkaPort string
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|||||||
@ -31,5 +31,7 @@
|
|||||||
"GoogleVerify":true,
|
"GoogleVerify":true,
|
||||||
|
|
||||||
"RemoteAddr":"host.docker.internal:9001",
|
"RemoteAddr":"host.docker.internal:9001",
|
||||||
"Partition":3
|
"Partition":3,
|
||||||
|
"KafkaHost":"kafka-server",
|
||||||
|
"KafkaPort":"9092"
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import (
|
|||||||
friendTreasureCfg "server/conf/friendTreasure"
|
friendTreasureCfg "server/conf/friendTreasure"
|
||||||
"server/game/mod/item"
|
"server/game/mod/item"
|
||||||
"server/msg"
|
"server/msg"
|
||||||
|
"server/pkg/github.com/name5566/leaf/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
type FriendTreasureMod struct {
|
type FriendTreasureMod struct {
|
||||||
@ -60,7 +61,9 @@ func (f *FriendTreasureMod) Flip(Pos int) ([]*item.Item, error) {
|
|||||||
}
|
}
|
||||||
f.Shift++
|
f.Shift++
|
||||||
Info := f.List[Pos]
|
Info := f.List[Pos]
|
||||||
|
log.Debug("pos:%v, info:%v", Pos, Info)
|
||||||
if Info.Uid != 0 {
|
if Info.Uid != 0 {
|
||||||
|
log.Debug("uid:%v", Info.Uid)
|
||||||
f.Uids = append(f.Uids, Info.Uid)
|
f.Uids = append(f.Uids, Info.Uid)
|
||||||
}
|
}
|
||||||
if Info.Type == FRIEND_TYPE_ALIVE {
|
if Info.Type == FRIEND_TYPE_ALIVE {
|
||||||
|
|||||||
@ -13,15 +13,10 @@ import (
|
|||||||
var KafkaMod *kafka.Conn
|
var KafkaMod *kafka.Conn
|
||||||
var topic string
|
var topic string
|
||||||
|
|
||||||
const (
|
|
||||||
HOST = "kafka-server"
|
|
||||||
PORT = "9092"
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
topic = conf.Server.GameName
|
topic = conf.Server.GameName
|
||||||
// 连接至Kafka集群的Leader节点
|
// 连接至Kafka集群的Leader节点
|
||||||
conn, err := kafka.DialContext(context.Background(), "tcp", fmt.Sprintf("%s:%s", HOST, PORT))
|
conn, err := kafka.DialContext(context.Background(), "tcp", fmt.Sprintf("%s:%s", conf.Server.KafkaAddr, conf.Server.KafkaPort))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debug("kafka.DialContext err: %v", err)
|
log.Debug("kafka.DialContext err: %v", err)
|
||||||
go reconnectKafka()
|
go reconnectKafka()
|
||||||
@ -33,9 +28,9 @@ func init() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
for _, p := range Partitions {
|
for _, p := range Partitions {
|
||||||
if p.Leader.Host == HOST {
|
if p.Leader.Host == conf.Server.KafkaAddr {
|
||||||
log.Debug("Kafka connected partition :%v", p)
|
log.Debug("Kafka connected partition :%v", p)
|
||||||
conn, err := kafka.DialLeader(context.Background(), "tcp", fmt.Sprintf("%s:%s", HOST, PORT), topic, p.ID)
|
conn, err := kafka.DialLeader(context.Background(), "tcp", fmt.Sprintf("%s:%s", conf.Server.KafkaAddr, conf.Server.KafkaPort), topic, p.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("kafka.DialLeader err: %v", err)
|
log.Fatal("kafka.DialLeader err: %v", err)
|
||||||
return
|
return
|
||||||
@ -56,7 +51,7 @@ func reconnectKafka() {
|
|||||||
log.Debug("Reconnected to Kafka failed")
|
log.Debug("Reconnected to Kafka failed")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
conn, err := kafka.DialContext(context.Background(), "tcp", fmt.Sprintf("%s:%s", HOST, PORT))
|
conn, err := kafka.DialContext(context.Background(), "tcp", fmt.Sprintf("%s:%s", conf.Server.KafkaAddr, conf.Server.KafkaPort))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("kafka.DialContext err: %v", err)
|
log.Fatal("kafka.DialContext err: %v", err)
|
||||||
return
|
return
|
||||||
@ -64,8 +59,8 @@ func reconnectKafka() {
|
|||||||
Partitions, err := conn.ReadPartitions(topic)
|
Partitions, err := conn.ReadPartitions(topic)
|
||||||
|
|
||||||
for _, p := range Partitions {
|
for _, p := range Partitions {
|
||||||
if p.Leader.Host == HOST {
|
if p.Leader.Host == conf.Server.KafkaAddr {
|
||||||
conn, err := kafka.DialLeader(context.Background(), "tcp", fmt.Sprintf("%s:%s", HOST, PORT), topic, p.ID)
|
conn, err := kafka.DialLeader(context.Background(), "tcp", fmt.Sprintf("%s:%s", conf.Server.KafkaAddr, conf.Server.KafkaPort), topic, p.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("kafka.DialLeader err: %v", err)
|
log.Fatal("kafka.DialLeader err: %v", err)
|
||||||
return
|
return
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user