Skip to content
This repository has been archived by the owner on Dec 31, 2022. It is now read-only.

Commit

Permalink
删除web前端;回退log;为默认配置文件添加注释;不再覆写配置文件;
Browse files Browse the repository at this point in the history
  • Loading branch information
BaiMeow committed Aug 3, 2021
1 parent 4bc367f commit 40fbf0e
Show file tree
Hide file tree
Showing 7 changed files with 415 additions and 354 deletions.
17 changes: 17 additions & 0 deletions config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# account 是你的登陆账号在offline时不用填写
# login 是你的登陆模式,可以在 microsoft,mojang,offline中选择
# name 在离线登陆(offline)时必填,在其他登陆模式时会被忽略
# passwd 是你的登陆密码在offline时不用填写
[profile]
account = "[email protected]"
login = "mojang"
name = "yourid"
passwd = "password"

# ip 请填写你的服务器ip
# port 一般情况都是25565,少数服务器会使用其他端口
# timeout 是钓鱼等待时间,超过这个时间即使没有钓到鱼也会收杆,一般而言tps20的服务器timeout应该设置为45
[setting]
ip = "minecraftserver.com"
port = 25565
timeout = 45
11 changes: 4 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ module github.com/MscBaiMeow/FishBot2
go 1.16

require (
github.com/Tnze/go-mc v1.16.6-0.20210621044034-c4551f1de997
github.com/gin-gonic/gin v1.7.2
github.com/google/uuid v1.1.1
github.com/gorilla/websocket v1.4.2
github.com/sirupsen/logrus v1.8.1
github.com/spf13/viper v1.7.1

github.com/Tnze/go-mc v1.17.1-0.20210802050337-ef89758ede27
github.com/google/uuid v1.3.0
github.com/mattn/go-colorable v0.1.8
github.com/spf13/viper v1.8.1
)
495 changes: 369 additions & 126 deletions go.sum

Large diffs are not rendered by default.

21 changes: 0 additions & 21 deletions hook/hook.go

This file was deleted.

59 changes: 25 additions & 34 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ package main

import (
"bufio"
_ "embed"
"io/ioutil"
"log"
"os"
"strconv"
"time"

"github.com/MscBaiMeow/FishBot2/hook"
"github.com/MscBaiMeow/FishBot2/web"
"github.com/sirupsen/logrus"

"github.com/Tnze/go-mc/bot"
"github.com/Tnze/go-mc/bot/basic"
"github.com/Tnze/go-mc/chat"
Expand All @@ -19,6 +18,7 @@ import (
pk "github.com/Tnze/go-mc/net/packet"
"github.com/Tnze/go-mc/yggdrasil"
"github.com/google/uuid"
"github.com/mattn/go-colorable"
"github.com/spf13/viper"
)

Expand All @@ -42,49 +42,40 @@ var newentity = bot.PacketHandler{
F: newbobber,
}

var log *logrus.Logger
//go:embed config.toml
var defaultConfig []byte

func main() {
log = logrus.New()
hook.InitHook(log)
go web.WebRun(sendMsg, log)

log.SetOutput(colorable.NewColorableStdout())
vp = viper.New()
vp.SetConfigName("config")
vp.SetConfigType("toml")
vp.AddConfigPath(".")
vp.SetDefault("profile", map[string]string{"account": "[email protected]", "passwd": "123456789", "name": "Steve"})
vp.SetDefault("setting", map[string]interface{}{
"timeout": 45,
"ip": "mc.hypixel.net",
"port": 25565,
})
if err := vp.ReadInConfig(); err != nil {
if _, ok := err.(viper.ConfigFileNotFoundError); ok {
vp.SafeWriteConfig()
ioutil.WriteFile("config.toml", defaultConfig, 0666)
log.Fatal("配置文件缺失,已创建默认配置文件,请打开\"config.toml\"修改并保存")
} else {
log.Fatal(err)
}
}
c = bot.NewClient()
player = basic.NewPlayer(c, basic.DefaultSettings)
if vp.GetString("profile.account") != "" {
switch vp.GetString("profile.login") {
case "offline":
c.Auth.Name = vp.GetString("profile.name")
case "mojang":
resp, err := yggdrasil.Authenticate(vp.GetString("profile.account"), vp.GetString("profile.passwd"))
if err != nil {
log.Fatal("Authenticate:", err)
}
log.Info("验证成功")
log.Println("验证成功")
c.Auth.UUID, c.Auth.Name = resp.SelectedProfile()
c.Auth.AsTk = resp.AccessToken()
vp.Set("profile.name", c.Auth.Name)
vp.Set("profile.uuid", c.Auth.UUID)
vp.Set("profile.astk", c.Auth.AsTk)
vp.Set("profile.account", vp.GetString("profile.account"))
vp.Set("profile.passwd", vp.GetString("profile.passwd"))
vp.WriteConfig()
} else {
c.Auth.Name = vp.GetString("profile.name")
case "microsoft":
log.Fatal("暂不支持微软登陆")
default:
log.Fatal("无效的登陆模式")
}
//注册事件
basic.EventsListener{
Expand All @@ -100,15 +91,15 @@ func main() {
log.Fatal(err)
}
if err := c.HandleGame(); err != nil {
log.Info(err)
log.Println(err)
}
log.Info("失去与服务器的连接,将在五秒后重连")
log.Println("失去与服务器的连接,将在五秒后重连")
time.Sleep(5 * time.Second)
}
}

func onGameStart() error {
log.Info("加入游戏")
log.Println("加入游戏")
watch = make(chan bool)
go watchdog()
go listenMsg()
Expand All @@ -118,7 +109,7 @@ func onGameStart() error {
}

func onDisconnect(c chat.Message) error {
log.Info("断开连接:", c)
log.Println("断开连接:", c)
return nil
}

Expand All @@ -136,7 +127,7 @@ func checkbobber(p pk.Packet) error {
if catchable {
throw(2)
watch <- true
log.Info("gra~")
log.Println("gra~")
}
return nil
}
Expand Down Expand Up @@ -178,7 +169,7 @@ func watchdog() {
for {
select {
case <-timer.C:
log.Info("WatchDog:超时")
log.Println("WatchDog:超时")
throw(1)
case <-watch:
}
Expand All @@ -187,7 +178,7 @@ func watchdog() {
}

func onChatMsg(msg chat.Message, pos byte, sender uuid.UUID) error {
log.Info(msg.ClearString())
log.Println(msg.ClearString())
return nil
}

Expand All @@ -197,7 +188,7 @@ func listenMsg() {
Reader := bufio.NewReader(os.Stdin)
send, _, _ = Reader.ReadLine()
if err := sendMsg(string(send)); err != nil {
log.Info(err)
log.Println(err)
}
}
}
Expand Down
84 changes: 0 additions & 84 deletions web/templates/index.html

This file was deleted.

82 changes: 0 additions & 82 deletions web/web.go

This file was deleted.

0 comments on commit 40fbf0e

Please sign in to comment.