Skip to content

Commit

Permalink
优化掉落系统
Browse files Browse the repository at this point in the history
  • Loading branch information
flswld committed Nov 16, 2023
1 parent e9cacf0 commit c352746
Show file tree
Hide file tree
Showing 30 changed files with 348 additions and 202 deletions.
5 changes: 1 addition & 4 deletions cmd/gm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ var (
func main() {
flag.Parse()
go func() {
err := statsviz_serve.Serve("0.0.0.0:7890")
if err != nil {
panic(err)
}
_ = statsviz_serve.Serve("0.0.0.0:7890")
}()
err := app.Run(context.TODO(), *config)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions cmd/hk4e/dispatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import (
)

func DispatchCmd() *cobra.Command {
var cfg string
var configFile string
app.APPVERSION = VERSION
c := &cobra.Command{
Use: "dispatch",
Short: "dispatch server",
RunE: func(cmd *cobra.Command, args []string) error {
return app.Run(context.Background(), cfg)
return app.Run(context.Background(), configFile)
},
}
c.Flags().StringVar(&cfg, "config", "application.toml", "config file")
c.Flags().StringVar(&configFile, "config", "application.toml", "config file")
return c
}
6 changes: 3 additions & 3 deletions cmd/hk4e/gate.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import (
)

func GateCmd() *cobra.Command {
var cfg string
var configFile string
app.APPVERSION = VERSION
c := &cobra.Command{
Use: "gate",
Short: "gate server",
RunE: func(cmd *cobra.Command, args []string) error {
return app.Run(context.Background(), cfg)
return app.Run(context.Background(), configFile)
},
}
c.Flags().StringVar(&cfg, "config", "application.toml", "config file")
c.Flags().StringVar(&configFile, "config", "application.toml", "config file")
return c
}
6 changes: 3 additions & 3 deletions cmd/hk4e/gm.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import (
)

func GMCmd() *cobra.Command {
var cfg string
var configFile string
c := &cobra.Command{
Use: "gm",
Short: "gm server",
RunE: func(cmd *cobra.Command, args []string) error {
return app.Run(context.Background(), cfg)
return app.Run(context.Background(), configFile)
},
}
c.Flags().StringVar(&cfg, "config", "application.toml", "config file")
c.Flags().StringVar(&configFile, "config", "application.toml", "config file")
return c
}
6 changes: 3 additions & 3 deletions cmd/hk4e/gs.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import (
)

func GSCmd() *cobra.Command {
var cfg string
var configFile string
app.APPVERSION = VERSION
c := &cobra.Command{
Use: "gs",
Short: "game server",
RunE: func(cmd *cobra.Command, args []string) error {
return app.Run(context.Background(), cfg)
return app.Run(context.Background(), configFile)
},
}
c.Flags().StringVar(&cfg, "config", "application.toml", "config file")
c.Flags().StringVar(&configFile, "config", "application.toml", "config file")
return c
}
2 changes: 2 additions & 0 deletions cmd/hk4e/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ func main() {
GSCmd(),
MultiCmd(),
GMCmd(),
RobotCmd(),
NatsCmd(),
)

if err := rootCmd.Execute(); err != nil {
Expand Down
6 changes: 3 additions & 3 deletions cmd/hk4e/multi.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import (
)

func MultiCmd() *cobra.Command {
var cfg string
var configFile string
app.APPVERSION = VERSION
c := &cobra.Command{
Use: "multi",
Short: "multi server",
RunE: func(cmd *cobra.Command, args []string) error {
return app.Run(context.Background(), cfg)
return app.Run(context.Background(), configFile)
},
}
c.Flags().StringVar(&cfg, "config", "application.toml", "config file")
c.Flags().StringVar(&configFile, "config", "application.toml", "config file")
return c
}
80 changes: 80 additions & 0 deletions cmd/hk4e/nats.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package main

import (
"errors"
"os"
"os/signal"
"strconv"
"strings"
"syscall"
"time"

cfg "hk4e/common/config"

"github.com/nats-io/nats-server/v2/server"
"github.com/spf13/cobra"
)

func NatsCmd() *cobra.Command {
var configFile string
c := &cobra.Command{
Use: "nats",
Short: "nats server",
RunE: func(cmd *cobra.Command, args []string) error {
return RunNatsServer(configFile)
},
}
c.Flags().StringVar(&configFile, "config", "application.toml", "config file")
return c
}

func RunNatsServer(configFile string) error {
cfg.InitConfig(configFile)
natsAddr := strings.ReplaceAll(cfg.GetConfig().MQ.NatsUrl, "nats://", "")
if strings.Contains(natsAddr, ",") {
return errors.New("not support nats cluster")
}
split := strings.Split(natsAddr, ":")
if len(split) != 2 {
return errors.New("nats addr format error")
}
host := split[0]
port, err := strconv.Atoi(split[1])
if err != nil {
return err
}

opts := &server.Options{
Host: host,
Port: port,
NoLog: false,
NoSigs: true,
MaxControlLine: 4096,
DisableShortFirstPing: true,
Trace: true,
Debug: true,
}
natsServer, err := server.NewServer(opts)
if err != nil {
return err
}
natsServer.ConfigureLogger()
go natsServer.Start()
ok := natsServer.ReadyForConnections(time.Second * 5)
if !ok {
return errors.New("nats server start error")
}

c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
for {
s := <-c
switch s {
case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
return nil
case syscall.SIGHUP:
default:
return nil
}
}
}
6 changes: 3 additions & 3 deletions cmd/hk4e/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import (
)

func NodeCmd() *cobra.Command {
var cfg string
var configFile string
c := &cobra.Command{
Use: "node",
Short: "node server",
RunE: func(cmd *cobra.Command, args []string) error {
return app.Run(context.Background(), cfg)
return app.Run(context.Background(), configFile)
},
}
c.Flags().StringVar(&cfg, "config", "application.toml", "config file")
c.Flags().StringVar(&configFile, "config", "application.toml", "config file")
return c
}
23 changes: 23 additions & 0 deletions cmd/hk4e/robot.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package main

import (
"github.com/spf13/cobra"

"context"

"hk4e/robot/app"
)

func RobotCmd() *cobra.Command {
var configFile string
app.APPVERSION = VERSION
c := &cobra.Command{
Use: "robot",
Short: "robot server",
RunE: func(cmd *cobra.Command, args []string) error {
return app.Run(context.Background(), configFile)
},
}
c.Flags().StringVar(&configFile, "config", "application.toml", "config file")
return c
}
5 changes: 1 addition & 4 deletions cmd/node/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ var (
func main() {
flag.Parse()
go func() {
err := statsviz_serve.Serve("0.0.0.0:1234")
if err != nil {
panic(err)
}
_ = statsviz_serve.Serve("0.0.0.0:1234")
}()
err := app.Run(context.TODO(), *config)
if err != nil {
Expand Down
41 changes: 21 additions & 20 deletions common/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,14 @@ var CONF *Config = nil
// Config 配置
type Config struct {
HttpPort int32 `toml:"http_port"`
Hk4e Hk4e `toml:"hk4e"`
Hk4eRobot Hk4eRobot `toml:"hk4e_robot"`
Logger Logger `toml:"logger"`
Database Database `toml:"database"`
Redis Redis `toml:"redis"`
Hk4e Hk4e `toml:"hk4e"`
Hk4eRobot Hk4eRobot `toml:"hk4e_robot"`
MQ MQ `toml:"mq"`
}

// Logger 日志
type Logger struct {
Level string `toml:"level"`
Mode string `toml:"mode"`
Track bool `toml:"track"`
MaxSize int32 `toml:"max_size"`
}

// Database 数据库配置
type Database struct {
Url string `toml:"url"`
}

type Redis struct {
Addr string `toml:"addr"`
Password string `toml:"password"`
}

// Hk4e 原神服务器
type Hk4e struct {
KcpAddr string `toml:"kcp_addr"` // kcp地址 该地址只用来注册到节点服务器 填网关的外网地址 网关本地监听为0.0.0.0
Expand Down Expand Up @@ -81,6 +63,25 @@ type Hk4eRobot struct {
ForwardChecksumClientVersion string `toml:"forward_checksum_client_version"` // 转发模式强制指定校验和客户端版本
}

// Logger 日志
type Logger struct {
Level string `toml:"level"`
Mode string `toml:"mode"`
Track bool `toml:"track"`
MaxSize int32 `toml:"max_size"`
}

// Database 数据库
type Database struct {
Url string `toml:"url"`
}

// Redis 缓存
type Redis struct {
Addr string `toml:"addr"`
Password string `toml:"password"`
}

// MQ 消息队列
type MQ struct {
NatsUrl string `toml:"nats_url"`
Expand Down
2 changes: 2 additions & 0 deletions common/constant/item_constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const (
ITEM_ID_WEAPON_UPGRADE_MAGIC = 104013 // 精锻用魔矿
ITEM_ID_WEAPON_UPGRADE_GOOD = 104012 // 精锻用良矿
ITEM_ID_WEAPON_UPGRADE_MOTLEY = 104011 // 精锻用杂矿

ITEM_ID_AVATAR_EXP = 101 // 角色经验
)

// 虚拟物品对应玩家的属性
Expand Down
16 changes: 8 additions & 8 deletions gate/net/proto_endecode.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,14 @@ func ProtoDecode(kcpMsg *KcpMsg,
msg.PayloadMessage = protoMessage.message
protoMsgList = append(protoMsgList, msg)
}
for _, msg := range protoMsgList {
cmdName := "???"
if msg.PayloadMessage != nil {
cmdName = string(msg.PayloadMessage.ProtoReflect().Descriptor().FullName())
}
logger.Debug("[RECV UNION CMD] cmdId: %v, cmdName: %v, sessionId: %v, headMsg: %v",
msg.CmdId, cmdName, msg.SessionId, msg.HeadMessage)
}
// for _, msg := range protoMsgList {
// cmdName := "???"
// if msg.PayloadMessage != nil {
// cmdName = string(msg.PayloadMessage.ProtoReflect().Descriptor().FullName())
// }
// logger.Debug("[RECV UNION CMD] cmdId: %v, cmdName: %v, sessionId: %v, headMsg: %v",
// msg.CmdId, cmdName, msg.SessionId, msg.HeadMessage)
// }
} else {
protoMsg.PayloadMessage = protoMessageList[0].message
protoMsgList = append(protoMsgList, protoMsg)
Expand Down
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ require github.com/pierrec/lz4/v4 v4.1.17
require github.com/gorilla/websocket v1.4.2

require (
github.com/nats-io/nats-server/v2 v2.9.7
github.com/stretchr/testify v1.8.3
golang.org/x/net v0.10.0
golang.org/x/sys v0.8.0
Expand All @@ -79,9 +80,10 @@ require (
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/minio/highwayhash v1.0.2 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/nats-io/nats-server/v2 v2.9.7 // indirect
github.com/nats-io/jwt/v2 v2.3.0 // indirect
github.com/nats-io/nkeys v0.3.0 // indirect
github.com/nats-io/nuid v1.0.1 // indirect
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
Expand All @@ -99,5 +101,6 @@ require (
golang.org/x/crypto v0.9.0 // indirect
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e // indirect
golang.org/x/text v0.9.0 // indirect
golang.org/x/time v0.0.0-20220922220347-f3bd1da661af // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit c352746

Please sign in to comment.