func sendReply(ws *websocket.Conn, req bsimjson.Bsimjson) { bsimdb.InsertSendMsg(req) s, _ := bsimjson.Bsimjson2json(req) if err := websocket.Message.Send(ws, "sendReply: "+s); err != nil { fmt.Println("Can't not send to client") } }
func addFriend(ws *websocket.Conn, req bsimjson.Bsimjson) { _, mname, _, _, _ := bsimdb.FindUserBySession(req.Who) err := bsimdb.AddFriendToGroup(mname, req.ToWho[0], "friends") fmt.Println("add err=", err) req.Msg = "OK" if err != nil { req.Msg = "NO" } s, _ := bsimjson.Bsimjson2json(req) if err := websocket.Message.Send(ws, s); err != nil { fmt.Println("Can't not send to client") } }
func pingReply(ws *websocket.Conn, req bsimjson.Bsimjson) { if req.Msg == "start" { var ret bsimjson.Bsimjson _, mname, _, _, _ := bsimdb.FindUserBySession(req.Who) ret.Type = "ping" ret.Who = mname var friends []string friends, _ = bsimdb.FindUsersFriends(mname) ret.ToWho = friends ret.Msg = "friends" s, _ := bsimjson.Bsimjson2json(ret) if err := websocket.Message.Send(ws, s); err != nil { fmt.Println("Can't not send to client") } } else if req.Msg == "msg" || req.Msg == "msgAll" { ret, err := bsimdb.PingMsgReply(req) if err != nil { log.Fatal(err) return } if req.Msg == "msg" && len(ret) > 50 { ret = ret[len(ret)-50:] } for i := 0; i < len(ret); i++ { if ma, _ := regexp.MatchString("(?i:\\<script[\\S\\s]+?\\</script\\>)", ret[i].Msg); ma { ret[i].Msg = `<div class="alert alert-warning" role="alert"> <strong>Sorry.</strong> We modify this massage a little bit for safty.</div>` + html.EscapeString(ret[i].Msg) } ret[i].Msg = string(blackfriday.MarkdownCommon([]byte(ret[i].Msg))) s, _ := bsimjson.Bsimjson2json(ret[i]) if err := websocket.Message.Send(ws, s); err != nil { fmt.Println("Can't not send to client") } } } }