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