|
|
|
@ -46,6 +46,7 @@ func (s *Server) OnRegister(c *Connection) { |
|
|
|
func (s *Server) OnUnregister(c *Connection) { |
|
|
|
func (s *Server) OnUnregister(c *Connection) { |
|
|
|
//log.Println("OnUnregister", c.id)
|
|
|
|
//log.Println("OnUnregister", c.id)
|
|
|
|
if c.Hello { |
|
|
|
if c.Hello { |
|
|
|
|
|
|
|
s.UpdateRoomConnection(c, &RoomConnectionUpdate{Id: c.Roomid}) |
|
|
|
s.Broadcast(c, &DataUser{Type: "Left", Id: c.Id, Status: "hard"}) |
|
|
|
s.Broadcast(c, &DataUser{Type: "Left", Id: c.Id, Status: "hard"}) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
//log.Println("Ingoring OnUnregister because of no Hello", c.Idx)
|
|
|
|
//log.Println("Ingoring OnUnregister because of no Hello", c.Idx)
|
|
|
|
@ -72,11 +73,13 @@ func (s *Server) OnText(c *Connection, b []byte) { |
|
|
|
s.UpdateUser(c, &UserUpdate{Types: []string{"Roomid", "Ua"}, Roomid: msg.Hello.Id, Ua: msg.Hello.Ua}) |
|
|
|
s.UpdateUser(c, &UserUpdate{Types: []string{"Roomid", "Ua"}, Roomid: msg.Hello.Id, Ua: msg.Hello.Ua}) |
|
|
|
if c.Hello && c.Roomid != msg.Hello.Id { |
|
|
|
if c.Hello && c.Roomid != msg.Hello.Id { |
|
|
|
// Room changed.
|
|
|
|
// Room changed.
|
|
|
|
|
|
|
|
s.UpdateRoomConnection(c, &RoomConnectionUpdate{Id: c.Roomid}) |
|
|
|
s.Broadcast(c, &DataUser{Type: "Left", Id: c.Id, Status: "soft"}) |
|
|
|
s.Broadcast(c, &DataUser{Type: "Left", Id: c.Id, Status: "soft"}) |
|
|
|
} |
|
|
|
} |
|
|
|
c.Roomid = msg.Hello.Id |
|
|
|
c.Roomid = msg.Hello.Id |
|
|
|
if c.h.config.defaultRoomEnabled || !c.h.isDefaultRoomid(c.Roomid) { |
|
|
|
if c.h.config.defaultRoomEnabled || !c.h.isDefaultRoomid(c.Roomid) { |
|
|
|
c.Hello = true |
|
|
|
c.Hello = true |
|
|
|
|
|
|
|
s.UpdateRoomConnection(c, &RoomConnectionUpdate{Id: c.Roomid, Status: true}) |
|
|
|
s.Broadcast(c, &DataUser{Type: "Joined", Id: c.Id, Ua: msg.Hello.Ua}) |
|
|
|
s.Broadcast(c, &DataUser{Type: "Joined", Id: c.Id, Ua: msg.Hello.Ua}) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
c.Hello = false |
|
|
|
c.Hello = false |
|
|
|
@ -155,6 +158,19 @@ func (s *Server) Unicast(c *Connection, to string, m interface{}) { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (s *Server) Alive(c *Connection, alive *DataAlive) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
c.h.aliveHandler(c, alive) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (s *Server) UpdateUser(c *Connection, userupdate *UserUpdate) uint64 { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
userupdate.Id = c.Id |
|
|
|
|
|
|
|
return c.h.userupdateHandler(userupdate) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (s *Server) Broadcast(c *Connection, m interface{}) { |
|
|
|
func (s *Server) Broadcast(c *Connection, m interface{}) { |
|
|
|
|
|
|
|
|
|
|
|
b, err := json.Marshal(&DataOutgoing{From: c.Id, Data: m}) |
|
|
|
b, err := json.Marshal(&DataOutgoing{From: c.Id, Data: m}) |
|
|
|
@ -163,26 +179,31 @@ func (s *Server) Broadcast(c *Connection, m interface{}) { |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var msg = &MessageRequest{From: c.Id, Message: b, Id: c.Roomid} |
|
|
|
if c.h.isGlobalRoomid(c.Roomid) { |
|
|
|
c.h.broadcastHandler(msg) |
|
|
|
c.h.RunForAllRooms(func(room *RoomWorker) { |
|
|
|
|
|
|
|
var msg = &MessageRequest{From: c.Id, Message: b, Id: room.Id} |
|
|
|
|
|
|
|
room.broadcastHandler(msg) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
var msg = &MessageRequest{From: c.Id, Message: b, Id: c.Roomid} |
|
|
|
|
|
|
|
room := c.h.GetRoom(c.Roomid) |
|
|
|
|
|
|
|
room.broadcastHandler(msg) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (s *Server) Users(c *Connection) { |
|
|
|
func (s *Server) Users(c *Connection) { |
|
|
|
|
|
|
|
|
|
|
|
c.h.usersHandler(c) |
|
|
|
room := c.h.GetRoom(c.Roomid) |
|
|
|
|
|
|
|
room.usersHandler(c) |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (s *Server) Alive(c *Connection, alive *DataAlive) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
c.h.aliveHandler(c, alive) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (s *Server) UpdateUser(c *Connection, userupdate *UserUpdate) uint64 { |
|
|
|
func (s *Server) UpdateRoomConnection(c *Connection, rcu *RoomConnectionUpdate) { |
|
|
|
|
|
|
|
|
|
|
|
userupdate.Id = c.Id |
|
|
|
rcu.Userid = c.Id |
|
|
|
return c.h.userupdateHandler(userupdate) |
|
|
|
rcu.Connection = c |
|
|
|
|
|
|
|
room := c.h.GetRoom(c.Roomid) |
|
|
|
|
|
|
|
room.connectionHandler(rcu) |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|