2022-08-12 01:12:24 +03:00
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"fmt"
|
|
|
|
|
"net/http"
|
|
|
|
|
"net/url"
|
2022-08-12 14:21:57 +03:00
|
|
|
"strconv"
|
2022-08-12 01:12:24 +03:00
|
|
|
"strings"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"github.com/gorilla/websocket"
|
|
|
|
|
)
|
|
|
|
|
|
2022-08-12 14:21:57 +03:00
|
|
|
type Amount struct {
|
|
|
|
|
value int
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (a Amount) Value() int {
|
|
|
|
|
return a.value
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (a *Amount) UnmarshalJSON(b []byte) error {
|
|
|
|
|
str := string(b)
|
|
|
|
|
s := 0
|
|
|
|
|
e := len(b)
|
|
|
|
|
if len(str) > 2 && str[0] == '"' && str[len(b)-1] == '"' {
|
|
|
|
|
s = 1
|
|
|
|
|
e = len(b) - 1
|
|
|
|
|
}
|
|
|
|
|
var err error
|
|
|
|
|
a.value, err = strconv.Atoi(str[s:e])
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-12 01:12:24 +03:00
|
|
|
type ServerResponse struct {
|
|
|
|
|
SubscriptionKey string `json:"subscriptionKey,omitempty"`
|
2022-08-12 14:21:57 +03:00
|
|
|
|
|
|
|
|
Params struct {
|
|
|
|
|
Model struct {
|
|
|
|
|
Status string `json:"status,omitempty"`
|
|
|
|
|
} `json:"model,omitempty"`
|
|
|
|
|
User struct {
|
|
|
|
|
Status string `json:"status,omitempty"`
|
|
|
|
|
} `json:"user,omitempty"`
|
2022-08-12 01:12:24 +03:00
|
|
|
ClientId string `json:"clientId,omitempty"`
|
|
|
|
|
Message struct {
|
|
|
|
|
Type string `json:"type,omitempty"`
|
|
|
|
|
Userdata struct {
|
|
|
|
|
Username string `json:"username,omitempty"`
|
|
|
|
|
} `json:"userdata,omitempty"`
|
|
|
|
|
Details struct {
|
2022-08-12 14:21:57 +03:00
|
|
|
Amount Amount `json:"amount,omitempty"`
|
2022-08-12 01:12:24 +03:00
|
|
|
LovenseDetails struct {
|
|
|
|
|
Type string `json:"type,omitempty"`
|
|
|
|
|
Detail struct {
|
2022-08-12 14:21:57 +03:00
|
|
|
Name string `json:"name,omitempty"`
|
|
|
|
|
Amount Amount `json:"amount,omitempty"`
|
2022-08-12 01:12:24 +03:00
|
|
|
} `json:"detail,omitempty"`
|
|
|
|
|
} `json:"lovenseDetails"`
|
|
|
|
|
} `json:"details,omitempty"`
|
|
|
|
|
} `json:"message,omitempty"`
|
|
|
|
|
} `json:"params,omitempty"`
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-12 01:20:31 +03:00
|
|
|
func startRoom(room, server, proxy string, u *url.URL, id string) {
|
2022-08-13 14:00:04 +03:00
|
|
|
|
2022-08-12 01:12:24 +03:00
|
|
|
fmt.Println("Start", room, "server", server, "proxy", proxy)
|
|
|
|
|
|
|
|
|
|
Dialer := *websocket.DefaultDialer
|
|
|
|
|
|
|
|
|
|
proxyMap := make(map[string]string)
|
|
|
|
|
proxyMap["us"] = "aaa:port"
|
|
|
|
|
proxyMap["fi"] = "bbb:port"
|
|
|
|
|
|
|
|
|
|
if _, ok := proxyMap[proxy]; ok {
|
|
|
|
|
Dialer = websocket.Dialer{
|
|
|
|
|
Proxy: http.ProxyURL(&url.URL{
|
|
|
|
|
Scheme: "http", // or "https" depending on your proxy
|
|
|
|
|
Host: proxyMap[proxy],
|
|
|
|
|
Path: "/",
|
|
|
|
|
}),
|
|
|
|
|
HandshakeTimeout: 45 * time.Second, // https://pkg.go.dev/github.com/gorilla/websocket
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
c, _, err := Dialer.Dial(u.String(), nil)
|
|
|
|
|
if err != nil {
|
|
|
|
|
fmt.Println(err.Error())
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
defer c.Close()
|
2022-08-13 14:00:04 +03:00
|
|
|
|
2022-08-12 01:12:24 +03:00
|
|
|
for {
|
|
|
|
|
_, message, err := c.ReadMessage()
|
|
|
|
|
if err != nil {
|
2022-08-13 14:00:04 +03:00
|
|
|
fmt.Println(err.Error())
|
2022-08-12 01:12:24 +03:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-13 14:00:04 +03:00
|
|
|
//fmt.Println(string(message))
|
2022-08-12 01:12:24 +03:00
|
|
|
|
|
|
|
|
m := &ServerResponse{}
|
|
|
|
|
|
|
|
|
|
if err = json.Unmarshal(message, m); err != nil {
|
|
|
|
|
fmt.Println(err.Error())
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if m.SubscriptionKey == "connected" {
|
2022-08-13 14:00:04 +03:00
|
|
|
messages := [][]byte{}
|
|
|
|
|
messages = append(messages, []byte(`{"id":"1660248194970-sub-lotteryChanged","method":"PUT","url":"/front/clients/`+m.Params.ClientId+`/subscriptions/lotteryChanged"}`))
|
|
|
|
|
messages = append(messages, []byte(`{"id":"1660248194970-sub-userBanned:`+id+`","method":"PUT","url":"/front/clients/`+m.Params.ClientId+`/subscriptions/userBanned:`+id+`"}`))
|
|
|
|
|
messages = append(messages, []byte(`{"id":"1660248194970-sub-goalChanged:`+id+`","method":"PUT","url":"/front/clients/`+m.Params.ClientId+`/subscriptions/goalChanged:`+id+`"}`))
|
|
|
|
|
messages = append(messages, []byte(`{"id":"1660248194970-sub-modelStatusChanged:`+id+`","method":"PUT","url":"/front/clients/`+m.Params.ClientId+`/subscriptions/modelStatusChanged:`+id+`"}`))
|
|
|
|
|
messages = append(messages, []byte(`{"id":"1660248194971-sub-broadcastSettingsChanged:`+id+`","method":"PUT","url":"/front/clients/`+m.Params.ClientId+`/subscriptions/broadcastSettingsChanged:`+id+`"}`))
|
|
|
|
|
messages = append(messages, []byte(`{"id":"1660248194971-sub-tipMenuUpdated:`+id+`","method":"PUT","url":"/front/clients/`+m.Params.ClientId+`/subscriptions/tipMenuUpdated:`+id+`"}`))
|
|
|
|
|
messages = append(messages, []byte(`{"id":"1660248194971-sub-topicChanged:`+id+`","method":"PUT","url":"/front/clients/`+m.Params.ClientId+`/subscriptions/topicChanged:`+id+`"}`))
|
|
|
|
|
messages = append(messages, []byte(`{"id":"1660248194971-sub-userUpdated:`+id+`","method":"PUT","url":"/front/clients/`+m.Params.ClientId+`/subscriptions/userUpdated:`+id+`"}`))
|
|
|
|
|
messages = append(messages, []byte(`{"id":"1660248194971-sub-interactiveToyStatusChanged:`+id+`","method":"PUT","url":"/front/clients/`+m.Params.ClientId+`/subscriptions/interactiveToyStatusChanged:`+id+`"}`))
|
|
|
|
|
messages = append(messages, []byte(`{"id":"1660248194971-sub-groupShow:`+id+`","method":"PUT","url":"/front/clients/`+m.Params.ClientId+`/subscriptions/groupShow:`+id+`"}`))
|
|
|
|
|
messages = append(messages, []byte(`{"id":"1660248194971-sub-deleteChatMessages:`+id+`","method":"PUT","url":"/front/clients/`+m.Params.ClientId+`/subscriptions/deleteChatMessages:`+id+`"}`))
|
|
|
|
|
messages = append(messages, []byte(`{"id":"1660248194971-sub-tipLeaderboardSettingsUpdated:`+id+`","method":"PUT","url":"/front/clients/`+m.Params.ClientId+`/subscriptions/tipLeaderboardSettingsUpdated:`+id+`"}`))
|
|
|
|
|
messages = append(messages, []byte(`{"id":"1660248194971-sub-modelAppUpdated:`+id+`","method":"PUT","url":"/front/clients/`+m.Params.ClientId+`/subscriptions/modelAppUpdated:`+id+`"}`))
|
|
|
|
|
messages = append(messages, []byte(`{"id":"1660248194972-sub-newKing:`+id+`","method":"PUT","url":"/front/clients/`+m.Params.ClientId+`/subscriptions/newKing:`+id+`"}`))
|
|
|
|
|
messages = append(messages, []byte(`{"id":"1660248194972-sub-privateMessageSettingsChanged:`+id+`","method":"PUT","url":"/front/clients/`+m.Params.ClientId+`/subscriptions/privateMessageSettingsChanged:`+id+`"}`))
|
|
|
|
|
messages = append(messages, []byte(`{"id":"1660248194972-sub-newChatMessage:`+id+`","method":"PUT","url":"/front/clients/`+m.Params.ClientId+`/subscriptions/newChatMessage:`+id+`"}`))
|
|
|
|
|
messages = append(messages, []byte(`{"id":"1660248194972-sub-fanClubUpdated:`+id+`","method":"PUT","url":"/front/clients/`+m.Params.ClientId+`/subscriptions/fanClubUpdated:`+id+`"}`))
|
|
|
|
|
messages = append(messages, []byte(`{"id":"1660248194972-sub-viewServerChanged:hls-07","method":"PUT","url":"/front/clients/`+m.Params.ClientId+`/subscriptions/viewServerChanged:hls-07"}`))
|
2022-08-12 01:12:24 +03:00
|
|
|
for _, msg := range messages {
|
2022-08-13 14:00:04 +03:00
|
|
|
if err = c.WriteMessage(websocket.TextMessage, msg); err != nil {
|
|
|
|
|
fmt.Println(err.Error())
|
2022-08-12 01:12:24 +03:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-08-13 14:00:04 +03:00
|
|
|
messages = nil
|
2022-08-12 01:12:24 +03:00
|
|
|
}
|
|
|
|
|
|
2022-08-13 14:00:04 +03:00
|
|
|
if strings.Contains(m.SubscriptionKey, "userUpdated") && m.Params.User.Status == "off" {
|
|
|
|
|
fmt.Println("user exiting")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if strings.Contains(m.SubscriptionKey, "modelStatusChanged") && m.Params.Model.Status == "off" {
|
|
|
|
|
fmt.Println("user exiting")
|
|
|
|
|
return
|
2022-08-12 14:21:57 +03:00
|
|
|
}
|
2022-08-13 14:00:04 +03:00
|
|
|
|
2022-08-12 01:12:24 +03:00
|
|
|
if !strings.Contains(m.SubscriptionKey, "newChatMessage") {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-13 14:00:04 +03:00
|
|
|
if m.Params.Message.Type == "tip" {
|
2022-08-12 14:21:57 +03:00
|
|
|
fmt.Println(m.Params.Message.Userdata.Username, " send ", m.Params.Message.Details.Amount.Value(), "tokens")
|
2022-08-12 01:12:24 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|