summaryrefslogtreecommitdiff
path: root/websocket_server.go
diff options
context:
space:
mode:
Diffstat (limited to 'websocket_server.go')
-rw-r--r--websocket_server.go33
1 files changed, 30 insertions, 3 deletions
diff --git a/websocket_server.go b/websocket_server.go
index 80d49d2..4079ed1 100644
--- a/websocket_server.go
+++ b/websocket_server.go
@@ -10,15 +10,42 @@ import (
"encoding/json"
"errors"
"fmt"
+ "log"
"net/http"
liberrors "github.com/shuLhan/share/lib/errors"
"github.com/shuLhan/share/lib/websocket"
)
-const (
- apiAttackHttp = "/_trunks/api/attack/http"
-)
+func (trunks *Trunks) wsBroadcastAttackFinish(result *AttackResult) {
+ if result == nil {
+ return
+ }
+
+ logp := "wsBroadcastAttackFinish"
+
+ jsonb, err := json.Marshal(result)
+ if err != nil {
+ log.Printf("%s: %s", logp, err)
+ return
+ }
+
+ packet, err := websocket.NewBroadcast(
+ apiAttackResult,
+ base64.StdEncoding.EncodeToString(jsonb),
+ )
+ if err != nil {
+ log.Printf("%s: %s", logp, err)
+ return
+ }
+
+ for _, conn := range trunks.Wsd.Clients.All() {
+ err = websocket.Send(conn, packet)
+ if err != nil {
+ log.Printf("%s: %s", logp, err)
+ }
+ }
+}
func (trunks *Trunks) initWebSocketServer() (err error) {
opts := &websocket.ServerOptions{