File tree Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ package gateway
33import  (
44"fmt" 
55"math/rand" 
6+ "sync" 
67"time" 
78
89"github.com/blobs-io/blobsgame/models/player" 
@@ -14,8 +15,9 @@ import (
1415)
1516
1617type  WebSocketConnection  struct  {
17- Conn  * websocket.Conn 
18- ID  string 
18+ Conn  * websocket.Conn 
19+ Mutex  sync.Mutex 
20+ ID  string 
1921}
2022
2123var  connections  =  make (map [string ]WebSocketConnection , 0 )
@@ -168,10 +170,20 @@ func handleClose(c *WebSocketConnection) {
168170}
169171
170172func  (c  * WebSocketConnection ) Send (d  AnyMessage ) error  {
173+ c .Mutex .Lock ()
174+ defer  c .Mutex .Unlock ()
171175return  c .Conn .WriteJSON (d )
172176}
173177
174178func  (c  * WebSocketConnection ) Kick (r  * room.Room , kickType  uint8 , reason  string ) error  {
179+ fmt .Println (AnyMessage {
180+ Op : OpClose ,
181+ T : PlayerKickEvent ,
182+ Data : map [string ]interface {}{
183+ "type" : kickType ,
184+ "message" : reason ,
185+ },
186+ })
175187err  :=  c .Send (AnyMessage {
176188Op : OpClose ,
177189T : PlayerKickEvent ,
                         You can’t perform that action at this time. 
           
                  
0 commit comments