mirror of
https://github.com/statbate/special-pancake.git
synced 2026-08-11 03:12:42 +00:00
update
This commit is contained in:
parent
4b0b928cef
commit
e42f70e789
3 changed files with 43 additions and 44 deletions
18
app/main.go
18
app/main.go
|
|
@ -28,7 +28,7 @@ var (
|
||||||
Mysql, Clickhouse *sqlx.DB
|
Mysql, Clickhouse *sqlx.DB
|
||||||
|
|
||||||
json = jsoniter.ConfigCompatibleWithStandardLibrary
|
json = jsoniter.ConfigCompatibleWithStandardLibrary
|
||||||
|
|
||||||
socketServer = make(chan []byte, 100)
|
socketServer = make(chan []byte, 100)
|
||||||
|
|
||||||
save = make(chan saveData, 100)
|
save = make(chan saveData, 100)
|
||||||
|
|
@ -92,16 +92,16 @@ func initClickhouse() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func socketHandler() {
|
func socketHandler() {
|
||||||
|
|
||||||
var(
|
var (
|
||||||
err error
|
err error
|
||||||
conn net.Conn
|
conn net.Conn
|
||||||
)
|
)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case b := <-socketServer:
|
case b := <-socketServer:
|
||||||
|
|
||||||
if conn == nil {
|
if conn == nil {
|
||||||
conn, err = net.Dial("unix", "/tmp/echo.sock")
|
conn, err = net.Dial("unix", "/tmp/echo.sock")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -109,7 +109,7 @@ func socketHandler() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if conn != nil {
|
if conn != nil {
|
||||||
if _, err = conn.Write(b); err != nil {
|
if _, err = conn.Write(b); err != nil {
|
||||||
fmt.Println(err.Error())
|
fmt.Println(err.Error())
|
||||||
|
|
@ -117,7 +117,7 @@ func socketHandler() {
|
||||||
conn = nil
|
conn = nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -159,7 +159,7 @@ func fastStart() {
|
||||||
workerData := Info{
|
workerData := Info{
|
||||||
room: k,
|
room: k,
|
||||||
Id: v.Id,
|
Id: v.Id,
|
||||||
Auth: v.Auth,
|
Auth: v.Auth,
|
||||||
Proxy: v.Proxy,
|
Proxy: v.Proxy,
|
||||||
Online: v.Online,
|
Online: v.Online,
|
||||||
Start: v.Start,
|
Start: v.Start,
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,7 @@ func saveDB() {
|
||||||
|
|
||||||
ticker := time.NewTicker(10 * time.Second)
|
ticker := time.NewTicker(10 * time.Second)
|
||||||
defer ticker.Stop()
|
defer ticker.Stop()
|
||||||
|
|
||||||
cleanCache := time.NewTicker(12 * time.Hour)
|
cleanCache := time.NewTicker(12 * time.Hour)
|
||||||
defer cleanCache.Stop()
|
defer cleanCache.Stop()
|
||||||
|
|
||||||
|
|
@ -172,8 +172,8 @@ func saveDB() {
|
||||||
Chanel string `json:"chanel"`
|
Chanel string `json:"chanel"`
|
||||||
Index int64 `json:"index"`
|
Index int64 `json:"index"`
|
||||||
}{
|
}{
|
||||||
Chanel: "chaturbate",
|
Chanel: "chaturbate",
|
||||||
Index: index["tokens"] / int64(seconds) * 3600 / 1000 * 5 / 100,
|
Index: index["tokens"] / int64(seconds) * 3600 / 1000 * 5 / 100,
|
||||||
})
|
})
|
||||||
if err == nil {
|
if err == nil {
|
||||||
socketServer <- msg
|
socketServer <- msg
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,8 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
//"net/url"
|
//"net/url"
|
||||||
//"strconv"
|
//"strconv"
|
||||||
"time"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
jsoniter "github.com/json-iterator/go"
|
jsoniter "github.com/json-iterator/go"
|
||||||
|
|
@ -56,11 +56,11 @@ func announceCount() {
|
||||||
rooms.Count <- 0
|
rooms.Count <- 0
|
||||||
l := <-rooms.Count
|
l := <-rooms.Count
|
||||||
msg, err := json.Marshal(struct {
|
msg, err := json.Marshal(struct {
|
||||||
Chanel string `json:"chanel"`
|
Chanel string `json:"chanel"`
|
||||||
Count int `json:"count"`
|
Count int `json:"count"`
|
||||||
}{
|
}{
|
||||||
Chanel: "chaturbate",
|
Chanel: "chaturbate",
|
||||||
Count: l
|
Count: l,
|
||||||
})
|
})
|
||||||
if err == nil {
|
if err == nil {
|
||||||
socketServer <- msg
|
socketServer <- msg
|
||||||
|
|
@ -108,7 +108,7 @@ func xWorker(workerData Info, u url.URL) {
|
||||||
defer c.Close()
|
defer c.Close()
|
||||||
|
|
||||||
dons := make(map[string]struct{})
|
dons := make(map[string]struct{})
|
||||||
|
|
||||||
initMessages := []string{
|
initMessages := []string{
|
||||||
`{"action":10,"flags":327680,"channel":"room:tip_alert:` + workerData.Id + `","params":{}}`,
|
`{"action":10,"flags":327680,"channel":"room:tip_alert:` + workerData.Id + `","params":{}}`,
|
||||||
`{"action":10,"flags":327680,"channel":"room:purchase:` + workerData.Id + `","params":{}}`,
|
`{"action":10,"flags":327680,"channel":"room:purchase:` + workerData.Id + `","params":{}}`,
|
||||||
|
|
@ -129,60 +129,59 @@ func xWorker(workerData Info, u url.URL) {
|
||||||
`{"action":10,"flags":327680,"channel":"room:update:` + workerData.Id + `","params":{}}`,
|
`{"action":10,"flags":327680,"channel":"room:update:` + workerData.Id + `","params":{}}`,
|
||||||
`{"action":10,"flags":327680,"channel":"room:settings:` + workerData.Id + `","params":{}}`,
|
`{"action":10,"flags":327680,"channel":"room:settings:` + workerData.Id + `","params":{}}`,
|
||||||
}
|
}
|
||||||
|
|
||||||
c.SetReadDeadline(time.Now().Add(1 * time.Minute))
|
c.SetReadDeadline(time.Now().Add(1 * time.Minute))
|
||||||
_, message, err := c.ReadMessage()
|
_, message, err := c.ReadMessage()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error(), workerData.room)
|
fmt.Println(err.Error(), workerData.room)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
slog <- saveLog{Rid: workerData.Rid, Now: time.Now().Unix(), Mes: string(message)}
|
slog <- saveLog{Rid: workerData.Rid, Now: time.Now().Unix(), Mes: string(message)}
|
||||||
|
|
||||||
input := struct {
|
input := struct {
|
||||||
Action int `json:"action"`
|
Action int `json:"action"`
|
||||||
Key string `json:"connectionkey"`
|
Key string `json:"connectionkey"`
|
||||||
Error jsoniter.RawMessage `json:"error"`
|
Error jsoniter.RawMessage `json:"error"`
|
||||||
Channel string `json:"channel"`
|
Channel string `json:"channel"`
|
||||||
Messages jsoniter.RawMessage `json:"messages"`
|
Messages jsoniter.RawMessage `json:"messages"`
|
||||||
}{}
|
}{}
|
||||||
|
|
||||||
if err := json.Unmarshal(message, &input); err != nil {
|
if err := json.Unmarshal(message, &input); err != nil {
|
||||||
fmt.Println(err.Error(), workerData.room)
|
fmt.Println(err.Error(), workerData.room)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
//if input.Key == "" {
|
//if input.Key == "" {
|
||||||
// fmt.Println("no connectionKey", workerData.room, string(message))
|
// fmt.Println("no connectionKey", workerData.room, string(message))
|
||||||
// return
|
// return
|
||||||
//}
|
//}
|
||||||
|
|
||||||
if err = c.WriteMessage(websocket.TextMessage, []byte(`{"action":17, "auth":{"accessToken":"`+workerData.Auth+`"}}`)); err != nil {
|
if err = c.WriteMessage(websocket.TextMessage, []byte(`{"action":17, "auth":{"accessToken":"`+workerData.Auth+`"}}`)); err != nil {
|
||||||
fmt.Println(err.Error(), workerData.room)
|
fmt.Println(err.Error(), workerData.room)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
_, message, err = c.ReadMessage()
|
_, message, err = c.ReadMessage()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error(), workerData.room)
|
fmt.Println(err.Error(), workerData.room)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
//fmt.Println(`{"action":16, "connectionKey":"`+input.Key+`","connectionSerial": -1}`)
|
//fmt.Println(`{"action":16, "connectionKey":"`+input.Key+`","connectionSerial": -1}`)
|
||||||
|
|
||||||
//if err = c.WriteMessage(websocket.TextMessage, []byte(`{"action":16, "connectionKey":"`+input.Key+`","connectionSerial": -1}`)); err != nil {
|
//if err = c.WriteMessage(websocket.TextMessage, []byte(`{"action":16, "connectionKey":"`+input.Key+`","connectionSerial": -1}`)); err != nil {
|
||||||
// fmt.Println(err.Error(), workerData.room)
|
// fmt.Println(err.Error(), workerData.room)
|
||||||
// return
|
// return
|
||||||
//}
|
//}
|
||||||
|
|
||||||
for _, im := range initMessages {
|
for _, im := range initMessages {
|
||||||
if err = c.WriteMessage(websocket.TextMessage, []byte(im)); err != nil {
|
if err = c.WriteMessage(websocket.TextMessage, []byte(im)); err != nil {
|
||||||
fmt.Println(err.Error(), workerData.room)
|
fmt.Println(err.Error(), workerData.room)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
for {
|
for {
|
||||||
|
|
||||||
select {
|
select {
|
||||||
|
|
@ -218,27 +217,27 @@ func xWorker(workerData Info, u url.URL) {
|
||||||
fmt.Println("no_mes exit:", workerData.room)
|
fmt.Println("no_mes exit:", workerData.room)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := json.Unmarshal(message, &input); err != nil {
|
if err := json.Unmarshal(message, &input); err != nil {
|
||||||
fmt.Println(err.Error(), workerData.room)
|
fmt.Println(err.Error(), workerData.room)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
//if len(string(input.Error)) > 1 {
|
//if len(string(input.Error)) > 1 {
|
||||||
// fmt.Println(string(input.Error), workerData.room)
|
// fmt.Println(string(input.Error), workerData.room)
|
||||||
// return
|
// return
|
||||||
//}
|
//}
|
||||||
|
|
||||||
if input.Action == 15 {
|
if input.Action == 15 {
|
||||||
|
|
||||||
workerData.Last = now
|
workerData.Last = now
|
||||||
rooms.Add <- workerData
|
rooms.Add <- workerData
|
||||||
|
|
||||||
if input.Channel == "room:tip_alert:"+workerData.Id {
|
if input.Channel == "room:tip_alert:"+workerData.Id {
|
||||||
tips := []struct {
|
tips := []struct {
|
||||||
Data string `json:"data"`
|
Data string `json:"data"`
|
||||||
}{}
|
}{}
|
||||||
|
|
||||||
if err := json.Unmarshal(input.Messages, &tips); err != nil {
|
if err := json.Unmarshal(input.Messages, &tips); err != nil {
|
||||||
fmt.Println(err.Error(), workerData.room)
|
fmt.Println(err.Error(), workerData.room)
|
||||||
continue
|
continue
|
||||||
|
|
@ -255,26 +254,26 @@ func xWorker(workerData Info, u url.URL) {
|
||||||
fmt.Println(err.Error(), workerData.room)
|
fmt.Println(err.Error(), workerData.room)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if donate.Amount < 1 {
|
if donate.Amount < 1 {
|
||||||
fmt.Println("empty amount", workerData.room)
|
fmt.Println("empty amount", workerData.room)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(donate.From) < 4 {
|
if len(donate.From) < 4 {
|
||||||
donate.From = "anon_tips"
|
donate.From = "anon_tips"
|
||||||
}
|
}
|
||||||
|
|
||||||
workerData.Tips++
|
workerData.Tips++
|
||||||
if _, ok := dons[donate.From]; !ok {
|
if _, ok := dons[donate.From]; !ok {
|
||||||
dons[donate.From] = struct{}{}
|
dons[donate.From] = struct{}{}
|
||||||
workerData.Dons++
|
workerData.Dons++
|
||||||
}
|
}
|
||||||
|
|
||||||
save <- saveData{Room: workerData.room, From: donate.From, Rid: workerData.Rid, Amount: donate.Amount, Now: now}
|
save <- saveData{Room: workerData.room, From: donate.From, Rid: workerData.Rid, Amount: donate.Amount, Now: now}
|
||||||
workerData.Income += donate.Amount
|
workerData.Income += donate.Amount
|
||||||
rooms.Add <- workerData
|
rooms.Add <- workerData
|
||||||
|
|
||||||
fmt.Println(donate.From, "send", donate.Amount, "tokens")
|
fmt.Println(donate.From, "send", donate.Amount, "tokens")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue