diff --git a/gorilla-server/main.go b/gorilla-server/main.go index 07defe8..ad0f721 100644 --- a/gorilla-server/main.go +++ b/gorilla-server/main.go @@ -153,38 +153,37 @@ func eventHandler(w http.ResponseWriter, r *http.Request) { // probably this should never happen since the client socket connection should have // already been dropped. If a user is doing this, the account should probably be // terminated as abuse - log.Println("echoHandler() GOT websocket.TextMessage (ERROR. NO HANDLER FOR THIS YET)") - log.Println("echoHandler() GOT websocket.TextMessage (ERROR. THIS SHOULD NEVER HAPPEN)") - log.Println("echoHandler() GOT websocket.TextMessage (ERROR. SUSPEND THIS USER)") + log.Println("\teventHandler() GOT websocket.TextMessage (ERROR. NO HANDLER FOR THIS YET)") + log.Println("\teventHandler() GOT websocket.TextMessage (ERROR. THIS SHOULD NEVER HAPPEN)") + log.Println("\teventHandler() GOT websocket.TextMessage (ERROR. SUSPEND THIS USER)") } if mytype == websocket.BinaryMessage { - log.Println("echoHandler() GOT websocket.BinaryMessage") + log.Println("\teventHandler() GOT websocket.BinaryMessage") pdata := new(pb.Event) + var e *pb.Event err = proto.Unmarshal(message, pdata) if (err != nil) { log.Printf("readConn() something fucked up happened in Unmarshal") } - log.Printf("recv binary: %s", pdata) + log.Printf("\teventHandler()recv binary: %s", pdata) if pdata.Type == pb.Event_GET { - log.Printf("GOT GET") - e := processGetEvent(pdata) - sendProtobuf(conn, e) + e = processGetEvent(pdata) + e.Comment = "\teventHandler() GOT Event_GET" } if pdata.Type == pb.Event_MIGRATE { - log.Printf("GOT MIGRATE") - e := processGetEvent(pdata) - sendProtobuf(conn, e) + e = processGetEvent(pdata) + e.Comment = "\teventHandler() GOT Event_MIGRATE" } if pdata.Type == pb.Event_LOGIN { - log.Printf("GOT LOGIN") - e := processLoginEvent(pdata) - sendProtobuf(conn, e) + e = processLoginEvent(pdata) + e.Comment = "\teventHandler() GOT Event_LOGIN" } if pdata.Type == pb.Event_ADD { - log.Printf("GOT ADD") - e := processAddEvent(pdata) - sendProtobuf(conn, e) + e = processAddEvent(pdata) + e.Comment = "\teventHandler() GOT Event_ADD" } + log.Println("\t", e.Comment) + sendProtobuf(conn, e) } } } @@ -220,7 +219,8 @@ func processGetEvent(ge *pb.Event) *pb.Event { log.Println("processGetEvent() START") if (checkLogin(ge) == false) { e := pb.MakeFailResponse() - e.Comment = "LOGIN FAILED" + e.Comment = "processGetEvent() LOGIN FAILED" + log.Println(e.Comment) return e } log.Println("processGetEvent() ge.Account.Token =", ge.Account.Token) @@ -266,13 +266,14 @@ func processLoginEvent(ge *pb.Event) *pb.Event { if (checkLogin(ge) == false) { e := pb.MakeFailResponse() e.Comment = "LOGIN FAILED" + log.Println(e.Comment) return e } - log.Println("processLoginEvent() LOGIN WORKED") e := pb.MakeOkResponse() e.Account = ge.Account - e.Comment = "LOGIN WORKED" + e.Comment = "processLoginEvent() LOGIN WORKED" + log.Println(e.Comment) return e } @@ -294,24 +295,28 @@ func origLoginCheck(ge *pb.Event) bool { log.Println("origLoginCheck() ", httpType, url) req, err := http.NewRequest(httpType, url, nil) if err != nil { - log.Println("origLoginCheck() FAILED ", "can't make new req") + ge.Comment = "origLoginCheck() FAILED can't make new req" + log.Println(ge.Comment) return false } req.Header.Set("X-Wit-Auth", ge.Account.Token) client := &http.Client{} resp, err := client.Do(req) if err != nil { - log.Println("origLoginCheck() FAILED ", "Can't exec the req to list networks: %s", err) + ge.Comment = "origLoginCheck() FAILED Can't exec the req to list networks " + err.Error() + log.Println(ge.Comment) return false } body, err := ioutil.ReadAll(resp.Body) if err != nil { - log.Println("origLoginCheck() FAILED ", "can't read resp") + ge.Comment = "origLoginCheck() FAILED can't read resp" + log.Println(ge.Comment) return false } log.Printf("origLoginCheck() ", "RESPONSE =", string(body)) if body == nil { - log.Println("origLoginCheck() FAILED ", "RESPONSE is nil") + ge.Comment = "origLoginCheck() FAILED RESPONSE is nil" + log.Println(ge.Comment) return false } else { len := len(body) @@ -321,10 +326,12 @@ func origLoginCheck(ge *pb.Event) bool { log.Println("origLoginCheck() ", "email = ", email.String()) log.Println("origLoginCheck() ", "ge.Account.Username = ", ge.Account.Username) if (email.String() == ge.Account.Username) { - log.Println("origLoginCheck() THIS TOTALLY WORKED MAN") + ge.Comment = "origLoginCheck() THIS TOTALLY WORKED MAN" + log.Println(ge.Comment) return true } } - log.Println("origLoginCheck() FAILED ") + ge.Comment = "origLoginCheck() FAILED " + log.Println(ge.Comment) return false }