diff --git a/app/cmd.go b/app/cmd.go index a20245d..7beb440 100644 --- a/app/cmd.go +++ b/app/cmd.go @@ -113,5 +113,4 @@ func startRoom(workerData Info) { workerData.ch = make(chan struct{}) go xWorker(workerData, url.URL{Scheme: "wss", Host: "realtime.pa.highwebmedia.com", Path: "/", RawQuery: "access_token=" + workerData.Auth + "&format=json&heartbeats=true&v=1.2&agent=ably-js%2F1.2.13%20browser&remainPresentFor=0"}) - //go xWorker(workerData) } diff --git a/app/main.go b/app/main.go index a3584ef..2364d5e 100644 --- a/app/main.go +++ b/app/main.go @@ -3,7 +3,6 @@ package main import ( "fmt" "log" - "math/rand" "net" "net/http" "os" @@ -45,8 +44,6 @@ var ( ) func main() { - rand.Seed(time.Now().UnixNano()) - startConfig() initMysql() @@ -122,20 +119,6 @@ func socketHandler() { } } -func randInt(min int, max int) int { - return min + rand.Intn(max-min) -} - -func randString(n int) string { - const alphanum = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" - var bytes = make([]byte, n) - rand.Read(bytes) - for i, b := range bytes { - bytes[i] = alphanum[b%byte(len(alphanum))] - } - return string(bytes) -} - func fastStart() { defer func() { go updateFileRooms() diff --git a/app/save.go b/app/save.go index 0cca211..16344e7 100644 --- a/app/save.go +++ b/app/save.go @@ -80,8 +80,9 @@ func saveDB() { for { select { case <-sendIndex.C: - if time.Now().Minute() >= 5 && tokens > 0 { - passed := time.Now().Second() + time.Now().Minute()*60 + t := time.Now() + if t.Minute() >= 5 && tokens > 0 { + passed := t.Second() + t.Minute()*60 msg, err := json.Marshal(struct { Chanel string `json:"chanel"` Index int64 `json:"index"` @@ -93,7 +94,6 @@ func saveDB() { socketServer <- msg } } - case <-cleanCache.C: l := len(data) now := time.Now().Unix() diff --git a/app/worker.go b/app/worker.go index 4bf361e..4c6eacd 100644 --- a/app/worker.go +++ b/app/worker.go @@ -3,8 +3,6 @@ package main import ( "fmt" "net/http" - //"net/url" - //"strconv" "net/url" "time" @@ -68,15 +66,6 @@ func announceCount() { } } -func reconnectRoom(workerData Info) { - n := randInt(10, 30) - fmt.Printf("Sleeping %d seconds...\n", n) - time.Sleep(time.Duration(n) * time.Second) - fmt.Println("reconnect:", workerData.room, workerData.Id, workerData.Auth, workerData.Proxy) - workerData.Last = time.Now().Unix() - startRoom(workerData) -} - func xWorker(workerData Info, u url.URL) { fmt.Println("Start", workerData.room, "room_id", workerData.Id, "auth", workerData.Auth, "proxy", workerData.Proxy) @@ -152,11 +141,6 @@ func xWorker(workerData Info, u url.URL) { 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 @@ -168,13 +152,6 @@ func xWorker(workerData Info, u url.URL) { 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) @@ -195,9 +172,6 @@ func xWorker(workerData Info, u url.URL) { _, message, err := c.ReadMessage() if err != nil { fmt.Println(err.Error(), workerData.room) - //if workerData.Income > 1 { - // go reconnectRoom(workerData) - //} return }