From d62cdc70da01d2ed3b905147d68e1efd94f824e6 Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Tue, 28 Jul 2015 13:43:43 +0100 Subject: [PATCH 01/22] Precaching --- songqueue.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/songqueue.go b/songqueue.go index 67db542..cc773c1 100644 --- a/songqueue.go +++ b/songqueue.go @@ -30,6 +30,12 @@ func (q *SongQueue) AddSong(s Song) error { beforeLen := q.Len() q.queue = append(q.queue, s) if len(q.queue) == beforeLen+1 { + + // Caching as added to queue + if dj.conf.Cache.Enabled && c.GetCurrentTotalFileSize() > (dj.conf.Cache.MaximumSize*1048576) { + s.Download() + } + return nil } return errors.New("Could not add Song to the SongQueue.") From 26db170fd3e830e468dca5d35a6a2881cea45284 Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Tue, 28 Jul 2015 13:45:22 +0100 Subject: [PATCH 02/22] Fixing build issues --- songqueue.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/songqueue.go b/songqueue.go index cc773c1..c198219 100644 --- a/songqueue.go +++ b/songqueue.go @@ -32,7 +32,7 @@ func (q *SongQueue) AddSong(s Song) error { if len(q.queue) == beforeLen+1 { // Caching as added to queue - if dj.conf.Cache.Enabled && c.GetCurrentTotalFileSize() > (dj.conf.Cache.MaximumSize*1048576) { + if dj.conf.Cache.Enabled && dj.cache.GetCurrentTotalFileSize() > (dj.conf.Cache.MaximumSize*1048576) { s.Download() } From 87f70a7f8cb082fce014494361f5b7132219d212 Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Tue, 28 Jul 2015 13:47:02 +0100 Subject: [PATCH 03/22] Fixing build issues --- songqueue.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/songqueue.go b/songqueue.go index c198219..2b111e2 100644 --- a/songqueue.go +++ b/songqueue.go @@ -32,7 +32,7 @@ func (q *SongQueue) AddSong(s Song) error { if len(q.queue) == beforeLen+1 { // Caching as added to queue - if dj.conf.Cache.Enabled && dj.cache.GetCurrentTotalFileSize() > (dj.conf.Cache.MaximumSize*1048576) { + if dj.conf.Cache.Enabled && dj.cache.GetCurrentTotalFileSize() < (dj.conf.Cache.MaximumSize*1048576) { s.Download() } From dbed8d4569c03deabb8806eda6694e088cf28dd6 Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Tue, 28 Jul 2015 13:50:38 +0100 Subject: [PATCH 04/22] Removed 2 song limit of playlist --- service_youtube.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/service_youtube.go b/service_youtube.go index 7754935..da9b641 100644 --- a/service_youtube.go +++ b/service_youtube.go @@ -404,16 +404,16 @@ func NewYouTubePlaylist(user, id string) (*YouTubePlaylist, error) { title: title, } - // Retrieve items in playlist - url = fmt.Sprintf("https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=2&playlistId=%s&key=%s", + // Retrieve items in playlist &maxResults=25 + url = fmt.Sprintf("https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&playlistId=%s&key=%s", id, os.Getenv("YOUTUBE_API_KEY")) if apiResponse, err = PerformGetRequest(url); err != nil { return nil, err } numVideos, _ := apiResponse.Int("pageInfo", "totalResults") - if numVideos > 2 { - numVideos = 2 - } + // if numVideos > 2 { + // numVideos = 2 + // } for i := 0; i < numVideos; i++ { index := strconv.Itoa(i) From 61795cd0ad1c8f6f64f1a35ab336e3a0cf3dff9d Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Tue, 28 Jul 2015 13:56:41 +0100 Subject: [PATCH 05/22] Added 25 song limit of playlist --- service_youtube.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/service_youtube.go b/service_youtube.go index da9b641..644dea7 100644 --- a/service_youtube.go +++ b/service_youtube.go @@ -404,16 +404,16 @@ func NewYouTubePlaylist(user, id string) (*YouTubePlaylist, error) { title: title, } - // Retrieve items in playlist &maxResults=25 - url = fmt.Sprintf("https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&playlistId=%s&key=%s", + // Retrieve items in playlist + url = fmt.Sprintf("https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=25&playlistId=%s&key=%s", id, os.Getenv("YOUTUBE_API_KEY")) if apiResponse, err = PerformGetRequest(url); err != nil { return nil, err } numVideos, _ := apiResponse.Int("pageInfo", "totalResults") - // if numVideos > 2 { - // numVideos = 2 - // } + if numVideos > 25 { + numVideos = 25 + } for i := 0; i < numVideos; i++ { index := strconv.Itoa(i) From 1309f534288ac1bef97941ca3278329f7a55ca70 Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Tue, 28 Jul 2015 14:00:18 +0100 Subject: [PATCH 06/22] Increased to 50 song limit per playlist --- service_youtube.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/service_youtube.go b/service_youtube.go index 644dea7..b951164 100644 --- a/service_youtube.go +++ b/service_youtube.go @@ -405,14 +405,14 @@ func NewYouTubePlaylist(user, id string) (*YouTubePlaylist, error) { } // Retrieve items in playlist - url = fmt.Sprintf("https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=25&playlistId=%s&key=%s", + url = fmt.Sprintf("https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=50&playlistId=%s&key=%s", id, os.Getenv("YOUTUBE_API_KEY")) if apiResponse, err = PerformGetRequest(url); err != nil { return nil, err } numVideos, _ := apiResponse.Int("pageInfo", "totalResults") - if numVideos > 25 { - numVideos = 25 + if numVideos > 50 { + numVideos = 50 } for i := 0; i < numVideos; i++ { From 38fd0ab7cda080c40e9dd81838d224afa3168cdc Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Tue, 28 Jul 2015 14:18:43 +0100 Subject: [PATCH 07/22] Fixing build issues --- songqueue.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/songqueue.go b/songqueue.go index 2b111e2..67db542 100644 --- a/songqueue.go +++ b/songqueue.go @@ -30,12 +30,6 @@ func (q *SongQueue) AddSong(s Song) error { beforeLen := q.Len() q.queue = append(q.queue, s) if len(q.queue) == beforeLen+1 { - - // Caching as added to queue - if dj.conf.Cache.Enabled && dj.cache.GetCurrentTotalFileSize() < (dj.conf.Cache.MaximumSize*1048576) { - s.Download() - } - return nil } return errors.New("Could not add Song to the SongQueue.") From 7d585ce02ec0fa147ce0705579e0101acb2cc2a7 Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Tue, 28 Jul 2015 14:56:20 +0100 Subject: [PATCH 08/22] Starting web interface --- main.go | 10 ++++++---- service_youtube.go | 3 +-- songqueue.go | 14 ++++++++------ web.go | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 50 insertions(+), 12 deletions(-) create mode 100644 web.go diff --git a/main.go b/main.go index 6ef1170..bc8d710 100644 --- a/main.go +++ b/main.go @@ -13,9 +13,9 @@ import ( "fmt" "os" "os/user" + "reflect" "strings" "time" - "reflect" "github.com/layeh/gopus" "github.com/layeh/gumble/gumble" @@ -148,8 +148,8 @@ func Verbose(msg string) { } func isNil(a interface{}) bool { - defer func() { recover() }() - return a == nil || reflect.ValueOf(a).IsNil() + defer func() { recover() }() + return a == nil || reflect.ValueOf(a).IsNil() } // dj variable declaration. This is done outside of main() to allow global use. @@ -228,7 +228,9 @@ func main() { if err := dj.client.Connect(); err != nil { fmt.Printf("Could not connect to Mumble server at %s:%s.\n", address, port) os.Exit(1) - } + } + + Webserver() <-dj.keepAlive } diff --git a/service_youtube.go b/service_youtube.go index b951164..4c60cd0 100644 --- a/service_youtube.go +++ b/service_youtube.go @@ -39,8 +39,7 @@ var youtubeVideoPatterns = []string{ // YOUTUBE SERVICE // --------------- -type YouTube struct { -} +type YouTube struct {} // Name of the service func (y YouTube) ServiceName() string { diff --git a/songqueue.go b/songqueue.go index 67db542..f1bdc1c 100644 --- a/songqueue.go +++ b/songqueue.go @@ -42,14 +42,16 @@ func (q *SongQueue) CurrentSong() Song { // NextSong moves to the next Song in SongQueue. NextSong() removes the first Song in the queue. func (q *SongQueue) NextSong() { - if s, err := q.PeekNext(); err == nil { - if !isNil(q.CurrentSong().Playlist()) && !isNil(s.Playlist()) { - if q.CurrentSong().Playlist().ID() != s.Playlist().ID() { - q.CurrentSong().Playlist().DeleteSkippers() + if !isNil(q.CurrentSong().Playlist()) { + if s, err := q.PeekNext(); err == nil { + if !isNil(s.Playlist()) { + if q.CurrentSong().Playlist().ID() != s.Playlist().ID() { + q.CurrentSong().Playlist().DeleteSkippers() + } } + } else { + q.CurrentSong().Playlist().DeleteSkippers() } - } else { - q.CurrentSong().Playlist().DeleteSkippers() } q.queue = q.queue[1:] } diff --git a/web.go b/web.go new file mode 100644 index 0000000..1e9d95f --- /dev/null +++ b/web.go @@ -0,0 +1,35 @@ +package mumbledj + +import ( + "fmt" + "io/ioutil" + "net/http" +) + +type Page struct { + Title string + Body []byte +} + +func (p *Page) save() error { + filename := p.Title + ".txt" + return ioutil.WriteFile(filename, p.Body, 0600) +} + +func loadPage(title string) (*Page, error) { + filename := title + ".txt" + body, err := ioutil.ReadFile(filename) + if err != nil { + return nil, err + } + return &Page{Title: title, Body: body}, nil +} + +func handler(w http.ResponseWriter, r *http.Request) { + fmt.Fprintf(w, "Hi there, I love %s!", r.URL.Path[1:]) +} + +func Webserver(){ + http.HandleFunc("/", handler) + http.ListenAndServe(":8080", nil) +} From c17ff088e3c83fef53fa1c0f4ad03b1fe761b05b Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Tue, 28 Jul 2015 14:57:12 +0100 Subject: [PATCH 09/22] Fixing build issues --- web.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web.go b/web.go index 1e9d95f..79623a6 100644 --- a/web.go +++ b/web.go @@ -1,4 +1,4 @@ -package mumbledj +package main import ( "fmt" From 4d8496502655f330e240c4b29b4a87b9d9d52e19 Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Tue, 28 Jul 2015 14:59:03 +0100 Subject: [PATCH 10/22] Fixing build issues --- web.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web.go b/web.go index 79623a6..4f49fe9 100644 --- a/web.go +++ b/web.go @@ -31,5 +31,5 @@ func handler(w http.ResponseWriter, r *http.Request) { func Webserver(){ http.HandleFunc("/", handler) - http.ListenAndServe(":8080", nil) + http.ListenAndServe(":80", nil) } From 4fe2713a93aed2f1d15a801617ca481d83f5d0dd Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Tue, 28 Jul 2015 15:00:27 +0100 Subject: [PATCH 11/22] Fixing build issues --- web.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web.go b/web.go index 4f49fe9..9a61cf5 100644 --- a/web.go +++ b/web.go @@ -31,5 +31,5 @@ func handler(w http.ResponseWriter, r *http.Request) { func Webserver(){ http.HandleFunc("/", handler) - http.ListenAndServe(":80", nil) + http.ListenAndServe(":9563", nil) } From 66fad37e346f79cbdbccf151922ca853f032b8dc Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Tue, 28 Jul 2015 15:09:20 +0100 Subject: [PATCH 12/22] Fixing build issues --- commands.go | 12 ++++++++++++ config.gcfg | 8 ++++++++ parseconfig.go | 2 ++ 3 files changed, 22 insertions(+) diff --git a/commands.go b/commands.go index c5f282f..b3b3bf7 100644 --- a/commands.go +++ b/commands.go @@ -82,6 +82,13 @@ func parseCommand(user *gumble.User, username, command string) { } else { dj.SendPrivateMessage(user, NO_PERMISSION_MSG) } + // Web command + case dj.conf.Aliases.WebAlias: + if dj.HasPermission(username, dj.conf.Permissions.AdminWeb) { + web(user) + } else { + dj.SendPrivateMessage(user, NO_PERMISSION_MSG) + } // Move command case dj.conf.Aliases.MoveAlias: if dj.HasPermission(username, dj.conf.Permissions.AdminMove) { @@ -291,6 +298,11 @@ func volume(user *gumble.User, username, value string) { } } +// web performs !web functionality. Gives user URL to web interface +func web(user *gumble.User){ + +} + // move performs !move functionality. Determines if the supplied channel is valid and moves the bot // to the channel if it is. func move(user *gumble.User, channel string) { diff --git a/config.gcfg b/config.gcfg index db67c05..5c7a595 100644 --- a/config.gcfg +++ b/config.gcfg @@ -86,6 +86,10 @@ HelpAlias = "help" # DEFAULT VALUE: "volume" VolumeAlias = "volume" +# Alias used for web address command +# DEFAULT VALUE: "web" +WebAlias = "web" + # Alias used for move command # DEFAULT VALUE: "move" MoveAlias = "move" @@ -162,6 +166,10 @@ AdminHelp = false # DEFAULT VALUE: false AdminVolume = false +# Make web an admin command? +# DEFAULT VALUE: false +AdminWeb = false + # Make move an admin command? # DEFAULT VALUE: true AdminMove = true diff --git a/parseconfig.go b/parseconfig.go index 9da7ec2..4b4a16a 100644 --- a/parseconfig.go +++ b/parseconfig.go @@ -51,6 +51,7 @@ type DjConfig struct { NumCachedAlias string CacheSizeAlias string KillAlias string + WebAlias string } Permissions struct { AdminsEnabled bool @@ -70,6 +71,7 @@ type DjConfig struct { AdminNumCached bool AdminCacheSize bool AdminKill bool + AdminWeb bool } } From 6a17e9fe5b284af5d7eece68fb08b04428f2a945 Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Tue, 28 Jul 2015 16:07:43 +0100 Subject: [PATCH 13/22] Fixing build issues --- commands.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/commands.go b/commands.go index b3b3bf7..58c54ba 100644 --- a/commands.go +++ b/commands.go @@ -299,8 +299,9 @@ func volume(user *gumble.User, username, value string) { } // web performs !web functionality. Gives user URL to web interface -func web(user *gumble.User){ - +func web(user *gumble.User) { + Verbose("Sending user web address") + dj.SendPrivateMessage(user, "http://178.62.73.59:9563/"+user.Name()) } // move performs !move functionality. Determines if the supplied channel is valid and moves the bot From 232ea53ecec02e0a8f5370e8b5b1a66bd1e46aab Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Tue, 28 Jul 2015 16:08:35 +0100 Subject: [PATCH 14/22] Fixing build issues --- commands.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands.go b/commands.go index 58c54ba..0feed01 100644 --- a/commands.go +++ b/commands.go @@ -301,7 +301,7 @@ func volume(user *gumble.User, username, value string) { // web performs !web functionality. Gives user URL to web interface func web(user *gumble.User) { Verbose("Sending user web address") - dj.SendPrivateMessage(user, "http://178.62.73.59:9563/"+user.Name()) + dj.SendPrivateMessage(user, "http://178.62.73.59:9563/"+user.Name) } // move performs !move functionality. Determines if the supplied channel is valid and moves the bot From 9e7975be7db1bf2061e880baa29cafcc79adff44 Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Tue, 28 Jul 2015 16:31:37 +0100 Subject: [PATCH 15/22] Fixing build issues --- commands.go | 8 +------- strings.go | 5 +++++ web.go | 28 ++++++++++++++++++++++++++-- 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/commands.go b/commands.go index 0feed01..61c83fb 100644 --- a/commands.go +++ b/commands.go @@ -85,7 +85,7 @@ func parseCommand(user *gumble.User, username, command string) { // Web command case dj.conf.Aliases.WebAlias: if dj.HasPermission(username, dj.conf.Permissions.AdminWeb) { - web(user) + GetWebAddress(user) } else { dj.SendPrivateMessage(user, NO_PERMISSION_MSG) } @@ -298,12 +298,6 @@ func volume(user *gumble.User, username, value string) { } } -// web performs !web functionality. Gives user URL to web interface -func web(user *gumble.User) { - Verbose("Sending user web address") - dj.SendPrivateMessage(user, "http://178.62.73.59:9563/"+user.Name) -} - // move performs !move functionality. Determines if the supplied channel is valid and moves the bot // to the channel if it is. func move(user *gumble.User, channel string) { diff --git a/strings.go b/strings.go index d48e7a7..92f577b 100644 --- a/strings.go +++ b/strings.go @@ -170,3 +170,8 @@ const CURRENT_SONG_HTML = ` const CURRENT_SONG_PLAYLIST_HTML = ` The song currently playing is "%s", added %s from the playlist "%s". ` + +// URL of the server for connecting via a web address +const WEB_ADDRESS = ` + Control mumbledj from a web browser: http://%s/%s. +` \ No newline at end of file diff --git a/web.go b/web.go index 9a61cf5..0986856 100644 --- a/web.go +++ b/web.go @@ -6,6 +6,9 @@ import ( "net/http" ) +var client_token = new(map[string]string) +var external_ip = "" + type Page struct { Title string Body []byte @@ -26,10 +29,31 @@ func loadPage(title string) (*Page, error) { } func handler(w http.ResponseWriter, r *http.Request) { - fmt.Fprintf(w, "Hi there, I love %s!", r.URL.Path[1:]) + fmt.Fprintf(w, "Hi there, I love %s!", r.URL.Path[1:]) } -func Webserver(){ +func Webserver() { http.HandleFunc("/", handler) http.ListenAndServe(":9563", nil) } + +func GetWebAddress(user *gumble.User) { + dj.SendPrivateMessage(user, fmt.Sprintf(WEB_ADDRESS, getIP(), user.Name, getIP(), user.Name)) +} + +func getIP() string { + if external_ip != "" { + return external_ip + } else { + if response, err := http.Get("http://myexternalip.com/raw"); err == nil { + defer response.Body.Close() + if response.StatusCode == 200 { + if body, err := ioutil.ReadAll(response.Body); err == nil { + external_ip = string(body) + } + } + } + + return external_ip + } +} From ce8fe1aaa38dd94a1ced854255b64fa0f6357f18 Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Tue, 28 Jul 2015 16:32:36 +0100 Subject: [PATCH 16/22] Fixing build issues --- web.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/web.go b/web.go index 0986856..5a1887a 100644 --- a/web.go +++ b/web.go @@ -4,6 +4,8 @@ import ( "fmt" "io/ioutil" "net/http" + + "github.com/layeh/gumble/gumble" ) var client_token = new(map[string]string) @@ -53,7 +55,7 @@ func getIP() string { } } } - + return external_ip } } From f51583f4c629c76967584ff993c29d39c9b560ec Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Tue, 28 Jul 2015 16:35:01 +0100 Subject: [PATCH 17/22] Fixing build issues --- strings.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/strings.go b/strings.go index 92f577b..e8cf2b5 100644 --- a/strings.go +++ b/strings.go @@ -173,5 +173,5 @@ const CURRENT_SONG_PLAYLIST_HTML = ` // URL of the server for connecting via a web address const WEB_ADDRESS = ` - Control mumbledj from a web browser: http://%s/%s. + Control mumbledj from a web browser: http://%s:9563/%s ` \ No newline at end of file From 0f6b601be42f1b6259ce7a92d026629b425ace7c Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Tue, 28 Jul 2015 16:52:53 +0100 Subject: [PATCH 18/22] Fixing build issues --- web.go | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/web.go b/web.go index 5a1887a..68e8e4f 100644 --- a/web.go +++ b/web.go @@ -3,12 +3,15 @@ package main import ( "fmt" "io/ioutil" + "math/rand" "net/http" + "strings" "github.com/layeh/gumble/gumble" ) var client_token = new(map[string]string) +var token_client = new(map[string]string) var external_ip = "" type Page struct { @@ -31,16 +34,27 @@ func loadPage(title string) (*Page, error) { } func handler(w http.ResponseWriter, r *http.Request) { - fmt.Fprintf(w, "Hi there, I love %s!", r.URL.Path[1:]) + var uname = token_client[r.URL.Path[1:]] + if uname == nil { + fmt.Fprintf(w, "I don't know you") + } else { + fmt.Fprintf(w, "Hi there, I love %s!", uname) + } } func Webserver() { http.HandleFunc("/", handler) http.ListenAndServe(":9563", nil) + rand.Seed(time.Now().UnixNano()) } func GetWebAddress(user *gumble.User) { - dj.SendPrivateMessage(user, fmt.Sprintf(WEB_ADDRESS, getIP(), user.Name, getIP(), user.Name)) + if client_token[user.Name] != nil { + token_client[client_token[user.Name]] = nil + } + client_token[user.Name] = randSeq(10) + token_client[client_token[user.Name]] = user.Name + dj.SendPrivateMessage(user, fmt.Sprintf(WEB_ADDRESS, getIP(), client_token[user.Name], getIP(), client_token[user.Name])) } func getIP() string { @@ -51,11 +65,20 @@ func getIP() string { defer response.Body.Close() if response.StatusCode == 200 { if body, err := ioutil.ReadAll(response.Body); err == nil { - external_ip = string(body) + external_ip = strings.TrimSpace(string(body)) } } } - return external_ip } } + +var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") + +func randSeq(n int) string { + b := make([]rune, n) + for i := range b { + b[i] = letters[rand.Intn(len(letters))] + } + return string(b) +} From d19577faff5312986cacce11bbf16fe58175ec3e Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Tue, 28 Jul 2015 16:59:55 +0100 Subject: [PATCH 19/22] Fixing build issues --- web.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/web.go b/web.go index 68e8e4f..046d3ed 100644 --- a/web.go +++ b/web.go @@ -6,12 +6,13 @@ import ( "math/rand" "net/http" "strings" + "time" "github.com/layeh/gumble/gumble" ) -var client_token = new(map[string]string) -var token_client = new(map[string]string) +var client_token = make(map[string]string) +var token_client = make(map[string]string) var external_ip = "" type Page struct { From 7f40c20e2cee43666a346e497a7fe86273123830 Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Tue, 28 Jul 2015 17:01:10 +0100 Subject: [PATCH 20/22] Fixing build issues --- web.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/web.go b/web.go index 046d3ed..50bb4f0 100644 --- a/web.go +++ b/web.go @@ -36,7 +36,7 @@ func loadPage(title string) (*Page, error) { func handler(w http.ResponseWriter, r *http.Request) { var uname = token_client[r.URL.Path[1:]] - if uname == nil { + if uname == "" { fmt.Fprintf(w, "I don't know you") } else { fmt.Fprintf(w, "Hi there, I love %s!", uname) @@ -50,8 +50,8 @@ func Webserver() { } func GetWebAddress(user *gumble.User) { - if client_token[user.Name] != nil { - token_client[client_token[user.Name]] = nil + if client_token[user.Name] != "" { + token_client[client_token[user.Name]] = "" } client_token[user.Name] = randSeq(10) token_client[client_token[user.Name]] = user.Name From 5af3936660d153a86b67ebabf42d3ebd6c54b20f Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Tue, 28 Jul 2015 17:07:21 +0100 Subject: [PATCH 21/22] Fixing build issues --- web.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/web.go b/web.go index 50bb4f0..a478e04 100644 --- a/web.go +++ b/web.go @@ -53,7 +53,12 @@ func GetWebAddress(user *gumble.User) { if client_token[user.Name] != "" { token_client[client_token[user.Name]] = "" } - client_token[user.Name] = randSeq(10) + // dealing with collisions + var firstLoop = true + for !firstLoop && token_client[client_token[user.Name]] == "" { + client_token[user.Name] = randSeq(10) + firstLoop = false + } token_client[client_token[user.Name]] = user.Name dj.SendPrivateMessage(user, fmt.Sprintf(WEB_ADDRESS, getIP(), client_token[user.Name], getIP(), client_token[user.Name])) } From 84267809ca90ef134aaff3c37db3f9d91e027628 Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Tue, 28 Jul 2015 17:08:58 +0100 Subject: [PATCH 22/22] Fixing build issues --- web.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web.go b/web.go index a478e04..76f826b 100644 --- a/web.go +++ b/web.go @@ -55,7 +55,7 @@ func GetWebAddress(user *gumble.User) { } // dealing with collisions var firstLoop = true - for !firstLoop && token_client[client_token[user.Name]] == "" { + for firstLoop || token_client[client_token[user.Name]] != "" { client_token[user.Name] = randSeq(10) firstLoop = false }