delete(cc.Server.Clients, binary.BigEndian.Uint16(*cc.ID))
- cc.notifyOthers(*NewTransaction(tranNotifyDeleteUser, nil, NewField(fieldUserID, *cc.ID)))
+ for _, t := range cc.notifyOthers(*NewTransaction(tranNotifyDeleteUser, nil, NewField(fieldUserID, *cc.ID))) {
+ cc.Server.outbox <- t
+ }
if err := cc.Connection.Close(); err != nil {
cc.Server.Logger.Errorw("error closing client connection", "RemoteAddr", cc.RemoteAddr)
}
// notifyOthers sends transaction t to other clients connected to the server
-func (cc *ClientConn) notifyOthers(t Transaction) {
+func (cc *ClientConn) notifyOthers(t Transaction) (trans []Transaction) {
for _, c := range sortedClients(cc.Server.Clients) {
if c.ID != cc.ID && c.Agreed {
t.clientID = c.ID
- cc.Server.outbox <- t
+ trans = append(trans, t)
}
}
+ return trans
}
// NewReply returns a reply Transaction with fields for the ClientConn
}
// handleNewConnection takes a new net.Conn and performs the initial login sequence
-func (s *Server) handleNewConnection(ctx context.Context, conn net.Conn, remoteAddr string) error {
+func (s *Server) handleNewConnection(ctx context.Context, conn io.ReadWriteCloser, remoteAddr string) error {
defer dontPanic(s.Logger)
if err := Handshake(conn); err != nil {
// Used simplified hotline v1.2.3 login flow for clients that do not send login info in tranAgreed
if *c.Version == nil || bytes.Equal(*c.Version, nostalgiaVersion) {
c.Agreed = true
-
c.logger = c.logger.With("name", string(c.UserName))
- c.notifyOthers(
+ for _, t := range c.notifyOthers(
*NewTransaction(
tranNotifyChangeUser, nil,
NewField(fieldUserName, c.UserName),
NewField(fieldUserIconID, *c.Icon),
NewField(fieldUserFlags, *c.Flags),
),
- )
+ ) {
+ c.Server.outbox <- t
+ }
}
c.Server.Stats.LoginCount += 1
// iterate over all the transactions that were parsed from the byte slice and handle them
for _, t := range transactions {
if err := c.handleTransaction(&t); err != nil {
- c.Server.Logger.Errorw("Error handling transaction", "err", err)
+ c.logger.Errorw("Error handling transaction", "err", err)
}
}
}
cc.AutoReply = []byte{}
}
- cc.notifyOthers(
+ for _, t := range cc.notifyOthers(
*NewTransaction(
tranNotifyChangeUser, nil,
NewField(fieldUserName, cc.UserName),
NewField(fieldUserIconID, *cc.Icon),
NewField(fieldUserFlags, *cc.Flags),
),
- )
+ ) {
+ cc.Server.outbox <- t
+ }
res = append(res, cc.NewReply(t))