This repository has been archived by the owner on Dec 31, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
415 additions
and
354 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
|
@@ -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" | ||
) | ||
|
||
|
@@ -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{ | ||
|
@@ -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() | ||
|
@@ -118,7 +109,7 @@ func onGameStart() error { | |
} | ||
|
||
func onDisconnect(c chat.Message) error { | ||
log.Info("断开连接:", c) | ||
log.Println("断开连接:", c) | ||
return nil | ||
} | ||
|
||
|
@@ -136,7 +127,7 @@ func checkbobber(p pk.Packet) error { | |
if catchable { | ||
throw(2) | ||
watch <- true | ||
log.Info("gra~") | ||
log.Println("gra~") | ||
} | ||
return nil | ||
} | ||
|
@@ -178,7 +169,7 @@ func watchdog() { | |
for { | ||
select { | ||
case <-timer.C: | ||
log.Info("WatchDog:超时") | ||
log.Println("WatchDog:超时") | ||
throw(1) | ||
case <-watch: | ||
} | ||
|
@@ -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 | ||
} | ||
|
||
|
@@ -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) | ||
} | ||
} | ||
} | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.