]> 127.0.0.1 Git - bili_danmu/.git/commitdiff
弹幕时间戳偏离过大重新连接
authorqydysky <qydysky@foxmail.com>
Mon, 31 May 2021 15:04:03 +0000 (23:04 +0800)
committerqydysky <qydysky@foxmail.com>
Mon, 31 May 2021 15:04:03 +0000 (23:04 +0800)
Reply/Reply.go
bili_danmu.go

index cb08b67e57133f8fab4aa4cf82770d29e48ee29e..ee3ada98f8762d52404abff3c4e8d9f209088cd7 100644 (file)
@@ -11,6 +11,7 @@ import (
 
        p "github.com/qydysky/part"
        mq "github.com/qydysky/part/msgq"
+       limit "github.com/qydysky/part/limit"
        F "github.com/qydysky/bili_danmu/F"
        ws_msg "github.com/qydysky/bili_danmu/Reply/ws_msg"
        send "github.com/qydysky/bili_danmu/Send"
@@ -783,33 +784,44 @@ func (replyF) roominfo(s string){
 }
 
 //Msg-弹幕处理
+var flash_limit = limit.New(1, 10000, -1)//-1 马上超时
 func (replyF) danmu(s string) {
-       if info := p.Json().GetValFromS(s, "info");info == nil {
-               msglog.L(`E: `, "info", info)
-               return
-       } else {
-               infob := info.([]interface{})
-               msg := infob[1].(string)
-               auth := infob[2].([]interface{})[1]
-               uid := strconv.Itoa(int(infob[2].([]interface{})[0].(float64)))
-
-               msglog := msglog.Log_show_control(false)
-
-               {//附加功能 弹幕机 封禁 弹幕合并
-                       Danmujif(msg)
-                       if Autobanf(msg) {
-                               Gui_show(Itos([]interface{}{"风险", auth, ":", msg}))
-                               fmt.Println("风险", auth, ":", msg)
-                               msglog.Base_add("风险").L(`I: `, auth, ":", msg)
-                               return
-                       }
-                       if i := Autoskipf(msg); i > 0 {
-                               msglog.L(`I: `, auth, ":", msg)
-                               return
-                       }
+       var j struct {
+               Cmd  string        `json:"cmd"`
+               Info []interface{} `json:"info"`
+       }
+
+       if e := json.Unmarshal([]byte(s), &j);e != nil {
+               msglog.L(`E: `, e)
+       }
+       
+       infob := j.Info
+       msg := infob[1].(string)
+       auth := infob[2].([]interface{})[1]
+       uid := strconv.Itoa(int(infob[2].([]interface{})[0].(float64)))
+       timeStramp := int64(infob[0].([]interface{})[4].(float64))
+       if t := p.Sys().GetMTime() - timeStramp; t > 60*1000 {
+               if flash_limit.TO() {return}
+               msglog.L(`W: `, `重进,弹幕时间戳偏离`, t, `ms`)
+               c.Danmu_Main_mq.Push_tag(`flash_room`,nil)
+       }
+
+       msglog := msglog.Log_show_control(false)
+
+       {//附加功能 弹幕机 封禁 弹幕合并
+               Danmujif(msg)
+               if Autobanf(msg) {
+                       Gui_show(Itos([]interface{}{"风险", auth, ":", msg}))
+                       fmt.Println("风险", auth, ":", msg)
+                       msglog.Base_add("风险").L(`I: `, auth, ":", msg)
+                       return
+               }
+               if i := Autoskipf(msg); i > 0 {
+                       msglog.L(`I: `, auth, ":", msg)
+                       return
                }
-               Msg_showdanmu(auth, msg, uid)
        }
+       Msg_showdanmu(auth, msg, uid)
 }
 
 //弹幕发送
index 7b8cae83e6603e60bc9fb0420cf4dbe809d04b4f..736346a08e4155a5245b418996be210cd914960e 100644 (file)
@@ -52,7 +52,10 @@ func Demo(roomid ...int) {
                var groomid = flag.Int("r", 0, "roomid")
                flag.Parse()
 
-               var change_room_chan = make(chan struct{})
+               var (
+                       change_room_chan = make(chan struct{})
+                       flash_room_chan = make(chan struct{})
+               )
 
                go func(){
                        var room = *groomid
@@ -78,6 +81,13 @@ func Demo(roomid ...int) {
                
                //使用带tag的消息队列在功能间传递消息
                c.Danmu_Main_mq.Pull_tag(msgq.FuncMap{
+                       `flash_room`:func(data interface{})(bool){//房间重进
+                               select {
+                               case flash_room_chan <- struct{}{}:;
+                               default:;
+                               }
+                               return false
+                       },
                        `change_room`:func(data interface{})(bool){//房间改变
                                c.Rev = 0.0 //营收
                                c.Renqi = 1//人气置1
@@ -167,7 +177,8 @@ func Demo(roomid ...int) {
 
                        //对每个弹幕服务器尝试
                        F.Get(`WSURL`)
-                       for _, v := range c.WSURL {
+                       for i:=0;i<len(c.WSURL);i+=1 {
+                               v := c.WSURL[i]
                                //ws启动
                                u, _ := url.Parse(v)
                                ws_c := ws.New_client(ws.Client{
@@ -223,6 +234,9 @@ func Demo(roomid ...int) {
                                                                go F.Get(`GuardNum`)
                                                                return false
                                                        },
+                                                       `flash_room`:func(data interface{})(bool){//重进房时退出当前房间
+                                                               return true
+                                                       },
                                                        `change_room`:func(data interface{})(bool){//换房时退出当前房间
                                                                return true
                                                        },
@@ -280,6 +294,11 @@ func Demo(roomid ...int) {
                                                danmulog.L(`I: `,"停止,等待服务器断开连接")
                                                break_sign = true
                                                exit_sign = false
+                                       case <- flash_room_chan:
+                                               ws_c.Close()
+                                               danmulog.L(`I: `,"停止,等待服务器断开连接")
+                                               F.Get(`WSURL`)
+                                               i = 0
                                        case <- change_room_chan:
                                                ws_c.Close()
                                                danmulog.L(`I: `,"停止,等待服务器断开连接")