- Timestamp:
- Apr 7, 2020, 5:45:29 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/downstream.go
r242 r245 223 223 } 224 224 225 func (dc *downstreamConn) sendFromUpstream(msg *irc.Message, uc *upstreamConn) { 225 // marshalMessage re-formats a message coming from an upstream connection so 226 // that it's suitable for being sent on this downstream connection. Only 227 // messages that may appear in logs are supported. 228 func (dc *downstreamConn) marshalMessage(msg *irc.Message, uc *upstreamConn) *irc.Message { 226 229 msg = msg.Copy() 230 msg.Prefix = dc.marshalUserPrefix(uc, msg.Prefix) 231 227 232 switch msg.Command { 228 233 case "PRIVMSG", "NOTICE": 229 msg.Prefix = dc.marshalUserPrefix(uc, msg.Prefix)230 234 msg.Params[0] = dc.marshalEntity(uc, msg.Params[0]) 235 case "NICK": 236 // Nick change for another user 237 msg.Params[0] = dc.marshalNick(uc, msg.Params[0]) 238 case "JOIN", "PART": 239 msg.Params[0] = dc.marshalChannel(uc, msg.Params[0]) 240 case "KICK": 241 msg.Params[0] = dc.marshalChannel(uc, msg.Params[0]) 242 msg.Params[1] = dc.marshalNick(uc, msg.Params[1]) 243 case "TOPIC": 244 msg.Params[0] = dc.marshalChannel(uc, msg.Params[0]) 245 case "MODE": 246 msg.Params[0] = dc.marshalEntity(uc, msg.Params[0]) 247 case "QUIT": 248 // This space is intentinally left blank 231 249 default: 232 250 panic(fmt.Sprintf("unexpected %q message", msg.Command)) 233 251 } 234 252 235 dc.SendMessage(msg)253 return msg 236 254 } 237 255 … … 685 703 } 686 704 687 dc.sendFromUpstream(msg, uc) 705 // Don't replay all messages, because that would mess up client 706 // state. For instance we just sent the list of users, sending 707 // PART messages for one of these users would be incorrect. 708 ignore := true 709 switch msg.Command { 710 case "PRIVMSG", "NOTICE": 711 ignore = false 712 } 713 if ignore { 714 continue 715 } 716 717 dc.SendMessage(dc.marshalMessage(msg, uc)) 688 718 } 689 719 }) -
trunk/upstream.go
r244 r245 563 563 564 564 if !me { 565 uc.network.ring.Produce(msg) 565 566 uc.forEachDownstream(func(dc *downstreamConn) { 566 dc.SendMessage(&irc.Message{ 567 Prefix: dc.marshalUserPrefix(uc, msg.Prefix), 568 Command: "NICK", 569 Params: []string{dc.marshalEntity(uc, newNick)}, 570 }) 567 dc.SendMessage(dc.marshalMessage(msg, uc)) 571 568 }) 572 569 } … … 602 599 } 603 600 604 uc.appendLog(ch, msg) 605 606 uc.forEachDownstream(func(dc *downstreamConn) { 607 dc.SendMessage(&irc.Message{ 608 Prefix: dc.marshalUserPrefix(uc, msg.Prefix), 609 Command: "JOIN", 610 Params: []string{dc.marshalChannel(uc, ch)}, 611 }) 612 }) 601 chMsg := msg.Copy() 602 chMsg.Params[0] = ch 603 uc.produce(ch, chMsg, nil) 613 604 } 614 605 case "PART": … … 620 611 if err := parseMessageParams(msg, &channels); err != nil { 621 612 return err 622 }623 624 var reason string625 if len(msg.Params) > 1 {626 reason = msg.Params[1]627 613 } 628 614 … … 639 625 } 640 626 641 uc.appendLog(ch, msg) 642 643 uc.forEachDownstream(func(dc *downstreamConn) { 644 params := []string{dc.marshalChannel(uc, ch)} 645 if reason != "" { 646 params = append(params, reason) 647 } 648 dc.SendMessage(&irc.Message{ 649 Prefix: dc.marshalUserPrefix(uc, msg.Prefix), 650 Command: "PART", 651 Params: params, 652 }) 653 }) 627 chMsg := msg.Copy() 628 chMsg.Params[0] = ch 629 uc.produce(ch, chMsg, nil) 654 630 } 655 631 case "KICK": … … 661 637 if err := parseMessageParams(msg, &channel, &user); err != nil { 662 638 return err 663 }664 665 var reason string666 if len(msg.Params) > 2 {667 reason = msg.Params[2]668 639 } 669 640 … … 679 650 } 680 651 681 uc.appendLog(channel, msg) 682 683 uc.forEachDownstream(func(dc *downstreamConn) { 684 params := []string{dc.marshalChannel(uc, channel), dc.marshalNick(uc, user)} 685 if reason != "" { 686 params = append(params, reason) 687 } 688 dc.SendMessage(&irc.Message{ 689 Prefix: dc.marshalUserPrefix(uc, msg.Prefix), 690 Command: "KICK", 691 Params: params, 692 }) 693 }) 652 uc.produce(channel, msg, nil) 694 653 case "QUIT": 695 654 if msg.Prefix == nil { … … 710 669 711 670 if msg.Prefix.Name != uc.nick { 671 uc.network.ring.Produce(msg) 712 672 uc.forEachDownstream(func(dc *downstreamConn) { 713 dc.SendMessage(&irc.Message{ 714 Prefix: dc.marshalUserPrefix(uc, msg.Prefix), 715 Command: "QUIT", 716 Params: msg.Params, 717 }) 673 dc.SendMessage(dc.marshalMessage(msg, uc)) 718 674 }) 719 675 } … … 746 702 ch.Topic = "" 747 703 } 748 uc.appendLog(ch.Name, msg) 749 uc.forEachDownstream(func(dc *downstreamConn) { 750 params := []string{dc.marshalChannel(uc, name)} 751 if ch.Topic != "" { 752 params = append(params, ch.Topic) 753 } 754 dc.SendMessage(&irc.Message{ 755 Prefix: dc.marshalUserPrefix(uc, msg.Prefix), 756 Command: "TOPIC", 757 Params: params, 758 }) 759 }) 704 uc.produce(ch.Name, msg, nil) 760 705 case "MODE": 761 706 var name, modeStr string … … 782 727 } 783 728 784 uc.appendLog(ch.Name, msg) 785 786 uc.forEachDownstream(func(dc *downstreamConn) { 787 params := []string{dc.marshalChannel(uc, name), modeStr} 788 params = append(params, msg.Params[2:]...) 789 790 dc.SendMessage(&irc.Message{ 791 Prefix: dc.marshalUserPrefix(uc, msg.Prefix), 792 Command: "MODE", 793 Params: params, 794 }) 795 }) 729 uc.produce(ch.Name, msg, nil) 796 730 } 797 731 case irc.RPL_UMODEIS: … … 1363 1297 } 1364 1298 1299 // produce appends a message to the logs, adds it to the history and forwards 1300 // it to connected downstream connections. 1301 // 1302 // If origin is not nil and origin doesn't support echo-message, the message is 1303 // forwarded to all connections except origin. 1365 1304 func (uc *upstreamConn) produce(target string, msg *irc.Message, origin *downstreamConn) { 1366 1305 if target != "" { … … 1372 1311 uc.forEachDownstream(func(dc *downstreamConn) { 1373 1312 if dc != origin || dc.caps["echo-message"] { 1374 dc. sendFromUpstream(msg, uc)1313 dc.SendMessage(dc.marshalMessage(msg, uc)) 1375 1314 } 1376 1315 })
Note:
See TracChangeset
for help on using the changeset viewer.