Trunk_AdminOwner.patch

Patch made by Thomas Bruderer <[email protected]> - Mirco Bauer, 04/10/2009 01:31 PM

Download (23.6 KB)

 
IrcClient/Delegates.cs (working copy)
7 7
 *
8 8
 * SmartIrc4net - the IRC library for .NET/C# <http://smartirc4net.sf.net>
9 9
 *
10
 * Copyright (c) 2003-2005 Mirco Bauer <[email protected]> <http://www.meebey.net>
10
 * Copyright (c) 2003-2009 Mirco Bauer <[email protected]> <http://www.meebey.net>
11
 * Copyright (c) 2008-2009 Thomas Bruderer <[email protected]>
11 12
 *
12 13
 * Full LGPL License: <http://www.gnu.org/licenses/lgpl.txt>
13 14
 *
......
41 42
    public delegate void InviteEventHandler(object sender, InviteEventArgs e);
42 43
    public delegate void OpEventHandler(object sender, OpEventArgs e);
43 44
    public delegate void DeopEventHandler(object sender, DeopEventArgs e);
45
    public delegate void AdminEventHandler(object sender, AdminEventArgs e);
46
    public delegate void DeadminEventHandler(object sender, DeadminEventArgs e);
44 47
    public delegate void HalfopEventHandler(object sender, HalfopEventArgs e);
45 48
    public delegate void DehalfopEventHandler(object sender, DehalfopEventArgs e);
49
    public delegate void OwnerEventHandler(object sender, OwnerEventArgs e);
50
    public delegate void DeownerEventHandler(object sender, DeownerEventArgs e);
46 51
    public delegate void VoiceEventHandler(object sender, VoiceEventArgs e);
47 52
    public delegate void DevoiceEventHandler(object sender, DevoiceEventArgs e);
48 53
    public delegate void BanEventHandler(object sender, BanEventArgs e);
IrcClient/EventArgs.cs (working copy)
7 7
 *
8 8
 * SmartIrc4net - the IRC library for .NET/C# <http://smartirc4net.sf.net>
9 9
 *
10
 * Copyright (c) 2003-2005 Mirco Bauer <[email protected]> <http://www.meebey.net>
10
 * Copyright (c) 2003-2009 Mirco Bauer <[email protected]> <http://www.meebey.net>
11
 * Copyright (c) 2008-2009 Thomas Bruderer <[email protected]>
11 12
 * 
12 13
 * Full LGPL License: <http://www.gnu.org/licenses/lgpl.txt>
13 14
 * 
......
780 781
        }
781 782
    }
782 783
    
784
    public class AdminEventArgs : IrcEventArgs
785
    {
786
        private string   _Channel;
787
        private string   _Who;
788
        private string   _Whom;
789
        
790
        public string Channel {
791
            get {
792
                return _Channel;
793
            }
794
        }
795

  
796
        public string Who {
797
            get {
798
                return _Who;
799
            }
800
        }
801

  
802
        public string Whom {
803
            get {
804
                return _Whom;
805
            }
806
        }
807
        
808
        internal AdminEventArgs(IrcMessageData data, string channel, string who, string whom) : base(data)
809
        {
810
            _Channel = channel;
811
            _Who = who;
812
            _Whom = whom;
813
        }
814
    }
815
        
816
    public class DeadminEventArgs : IrcEventArgs
817
    {
818
        private string   _Channel;
819
        private string   _Who;
820
        private string   _Whom;
821
        
822
        public string Channel {
823
            get {
824
                return _Channel;
825
            }
826
        }
827

  
828
        public string Who {
829
            get {
830
                return _Who;
831
            }
832
        }
833

  
834
        public string Whom {
835
            get {
836
                return _Whom;
837
            }
838
        }
839
        
840
        internal DeadminEventArgs(IrcMessageData data, string channel, string who, string whom) : base(data)
841
        {
842
            _Channel = channel;
843
            _Who = who;
844
            _Whom = whom;
845
        }
846
    }
847
            
848
    public class OwnerEventArgs : IrcEventArgs
849
    {
850
        private string   _Channel;
851
        private string   _Who;
852
        private string   _Whom;
853
        
854
        public string Channel {
855
            get {
856
                return _Channel;
857
            }
858
        }
859

  
860
        public string Who {
861
            get {
862
                return _Who;
863
            }
864
        }
865

  
866
        public string Whom {
867
            get {
868
                return _Whom;
869
            }
870
        }
871
        
872
        internal OwnerEventArgs(IrcMessageData data, string channel, string who, string whom) : base(data)
873
        {
874
            _Channel = channel;
875
            _Who = who;
876
            _Whom = whom;
877
        }
878
    }
879
                
880
    public class DeownerEventArgs : IrcEventArgs
881
    {
882
        private string   _Channel;
883
        private string   _Who;
884
        private string   _Whom;
885
        
886
        public string Channel {
887
            get {
888
                return _Channel;
889
            }
890
        }
891

  
892
        public string Who {
893
            get {
894
                return _Who;
895
            }
896
        }
897

  
898
        public string Whom {
899
            get {
900
                return _Whom;
901
            }
902
        }
903
        
904
        internal DeownerEventArgs(IrcMessageData data, string channel, string who, string whom) : base(data)
905
        {
906
            _Channel = channel;
907
            _Who = who;
908
            _Whom = whom;
909
        }
910
    }
911
    
783 912
    /// <summary>
784 913
    ///
785 914
    /// </summary>
IrcClient/IrcClient.cs (working copy)
7 7
 *
8 8
 * SmartIrc4net - the IRC library for .NET/C# <http://smartirc4net.sf.net>
9 9
 *
10
 * Copyright (c) 2003-2008 Mirco Bauer <[email protected]>
10
 * Copyright (c) 2003-2009 Mirco Bauer <[email protected]>
11
 * Copyright (c) 2008-2009 Thomas Bruderer <[email protected]>
11 12
 *
12 13
 * Full LGPL License: <http://www.gnu.org/licenses/lgpl.txt>
13 14
 *
......
114 115
        public event UnbanEventHandler          OnUnban;
115 116
        public event OpEventHandler             OnOp;
116 117
        public event DeopEventHandler           OnDeop;
118
        public event AdminEventHandler          OnAdmin;
119
        public event DeadminEventHandler        OnDeadmin;
117 120
        public event HalfopEventHandler         OnHalfop;
118 121
        public event DehalfopEventHandler       OnDehalfop;
122
        public event OwnerEventHandler          OnOwner;
123
        public event DeownerEventHandler        OnDeowner;
119 124
        public event VoiceEventHandler          OnVoice;
120 125
        public event DevoiceEventHandler        OnDevoice;
121 126
        public event WhoEventHandler            OnWho;
......
311 316
                }
312 317
#endif
313 318
                _SupportNonRfc = value;
319
                
320
                if (SupportNonRfcChanged != null) {
321
                    SupportNonRfcChanged(this, EventArgs.Empty);
322
                }
314 323
            }
315 324
        }
325
        
326
        public event EventHandler SupportNonRfcChanged;
316 327

  
317 328
        /// <summary>
318 329
        /// Gets the nickname of us.
......
1366 1377
            chan.UnsafeVoices.Remove(nickname);
1367 1378
            if (SupportNonRfc) {
1368 1379
                NonRfcChannel nchan = (NonRfcChannel)chan;
1380
                nchan.UnsafeAdmins.Remove(nickname);
1369 1381
                nchan.UnsafeHalfops.Remove(nickname);
1382
                nchan.UnsafeOwners.Remove(nickname);
1370 1383
            } 
1371 1384
        }
1372 1385

  
......
1530 1543
                            }
1531 1544
                        }
1532 1545
                    break;
1546
                    case 'a':
1547
                        if (SupportNonRfc) {
1548
                            temp = (string)parametersEnumerator.Current;
1549
                            parametersEnumerator.MoveNext();
1550
                            
1551
                            if (add) {
1552
                                if (ActiveChannelSyncing) {
1553
                                    // sanity check
1554
                                    if (GetChannelUser(ircdata.Channel, temp) != null) {
1555
                                        // update the halfop list
1556
                                        try {
1557
                                            ((NonRfcChannel)channel).UnsafeAdmins.Add(temp, GetIrcUser(temp));
1558
#if LOG4NET
1559
                                            Logger.ChannelSyncing.Debug("added admin: "+temp+" to: "+ircdata.Channel);
1560
#endif
1561
                                        } catch (ArgumentException) {
1562
#if LOG4NET
1563
                                            Logger.ChannelSyncing.Debug("duplicate admin: "+temp+" in: "+ircdata.Channel+" not added");
1564
#endif
1565
                                        }
1566
                                        
1567
                                        // update the user halfop status
1568
                                        NonRfcChannelUser cuser = (NonRfcChannelUser)GetChannelUser(ircdata.Channel, temp);
1569
                                        cuser.IsAdmin = true;
1570
#if LOG4NET
1571
                                        Logger.ChannelSyncing.Debug("set admin status: " + temp + " for: "+ircdata.Channel);
1572
#endif
1573
                                    } else {
1574
#if LOG4NET
1575
                                        Logger.ChannelSyncing.Error("_InterpretChannelMode(): GetChannelUser(" + ircdata.Channel + "," + temp + ") returned null! Ignoring...");
1576
#endif
1577
                                    }
1578
                                }
1579
                                
1580
                                if (OnAdmin != null) {
1581
                                    OnAdmin(this, new AdminEventArgs(ircdata, ircdata.Channel, ircdata.Nick, temp));
1582
                                }
1583
                            }
1584
                            if (remove) {
1585
                                if (ActiveChannelSyncing) {
1586
                                    // sanity check
1587
                                    if (GetChannelUser(ircdata.Channel, temp) != null) {
1588
                                        // update the halfop list
1589
                                        ((NonRfcChannel)channel).UnsafeAdmins.Remove(temp);
1590
#if LOG4NET
1591
                                        Logger.ChannelSyncing.Debug("removed admin: "+temp+" from: "+ircdata.Channel);
1592
#endif
1593
                                        // update the user halfop status
1594
                                        NonRfcChannelUser cuser = (NonRfcChannelUser)GetChannelUser(ircdata.Channel, temp);
1595
                                        cuser.IsAdmin = false;
1596
#if LOG4NET
1597
                                        Logger.ChannelSyncing.Debug("unset admin status: " + temp + " for: "+ircdata.Channel);
1598
#endif
1599
                                    } else {
1600
#if LOG4NET
1601
                                        Logger.ChannelSyncing.Error("_InterpretChannelMode(): GetChannelUser(" + ircdata.Channel + "," + temp + ") returned null! Ignoring...");
1602
#endif
1603
                                    }
1604
                                }
1605
                                
1606
                                if (OnDeadmin != null) {
1607
                                    OnDeadmin(this, new DeadminEventArgs(ircdata, ircdata.Channel, ircdata.Nick, temp));
1608
                                }
1609
                            }
1610
                        }
1611
                    break;
1612
                    case 'r':
1613
                        if (SupportNonRfc) {
1614
                            temp = (string)parametersEnumerator.Current;
1615
                            parametersEnumerator.MoveNext();
1616
                            
1617
                            if (add) {
1618
                                if (ActiveChannelSyncing) {
1619
                                    // sanity check
1620
                                    if (GetChannelUser(ircdata.Channel, temp) != null) {
1621
                                        // update the halfop list
1622
                                        try {
1623
                                            ((NonRfcChannel)channel).UnsafeOwners.Add(temp, GetIrcUser(temp));
1624
#if LOG4NET
1625
                                            Logger.ChannelSyncing.Debug("added owner: "+temp+" to: "+ircdata.Channel);
1626
#endif
1627
                                        } catch (ArgumentException) {
1628
#if LOG4NET
1629
                                            Logger.ChannelSyncing.Debug("duplicate owner: "+temp+" in: "+ircdata.Channel+" not added");
1630
#endif
1631
                                        }
1632
                                        
1633
                                        // update the user halfop status
1634
                                        NonRfcChannelUser cuser = (NonRfcChannelUser)GetChannelUser(ircdata.Channel, temp);
1635
                                        cuser.IsOwner = true;
1636
#if LOG4NET
1637
                                        Logger.ChannelSyncing.Debug("set owner status: " + temp + " for: "+ircdata.Channel);
1638
#endif
1639
                                    } else {
1640
#if LOG4NET
1641
                                        Logger.ChannelSyncing.Error("_InterpretChannelMode(): GetChannelUser(" + ircdata.Channel + "," + temp + ") returned null! Ignoring...");
1642
#endif
1643
                                    }
1644
                                }
1645
                                
1646
                                if (OnOwner != null) {
1647
                                    OnOwner(this, new OwnerEventArgs(ircdata, ircdata.Channel, ircdata.Nick, temp));
1648
                                }
1649
                            }
1650
                            if (remove) {
1651
                                if (ActiveChannelSyncing) {
1652
                                    // sanity check
1653
                                    if (GetChannelUser(ircdata.Channel, temp) != null) {
1654
                                        // update the halfop list
1655
                                        ((NonRfcChannel)channel).UnsafeOwners.Remove(temp);
1656
#if LOG4NET
1657
                                        Logger.ChannelSyncing.Debug("removed owner: "+temp+" from: "+ircdata.Channel);
1658
#endif
1659
                                        // update the user halfop status
1660
                                        NonRfcChannelUser cuser = (NonRfcChannelUser)GetChannelUser(ircdata.Channel, temp);
1661
                                        cuser.IsOwner = false;
1662
#if LOG4NET
1663
                                        Logger.ChannelSyncing.Debug("unset owner status: " + temp + " for: "+ircdata.Channel);
1664
#endif
1665
                                    } else {
1666
#if LOG4NET
1667
                                        Logger.ChannelSyncing.Error("_InterpretChannelMode(): GetChannelUser(" + ircdata.Channel + "," + temp + ") returned null! Ignoring...");
1668
#endif
1669
                                    }
1670
                                }
1671
                                
1672
                                if (OnDeowner != null) {
1673
                                    OnDeowner(this, new DeownerEventArgs(ircdata, ircdata.Channel, ircdata.Nick, temp));
1674
                                }
1675
                            }
1676
                        }
1677
                    break;
1533 1678
                    case 'v':
1534 1679
                        temp = (string)parametersEnumerator.Current;
1535 1680
                        parametersEnumerator.MoveNext();
......
2084 2229
                            channel.UnsafeOps.Remove(oldnickname);
2085 2230
                            channel.UnsafeOps.Add(newnickname, channeluser);
2086 2231
                        }
2087
                        if (SupportNonRfc && ((NonRfcChannelUser)channeluser).IsHalfop) {
2088
                            NonRfcChannel nchannel = (NonRfcChannel)channel;
2089
                            nchannel.UnsafeHalfops.Remove(oldnickname);
2090
                            nchannel.UnsafeHalfops.Add(newnickname, channeluser);
2091
                        }
2092 2232
                        if (channeluser.IsVoice) {
2093 2233
                            channel.UnsafeVoices.Remove(oldnickname);
2094 2234
                            channel.UnsafeVoices.Add(newnickname, channeluser);
2095 2235
                        }
2236
                        if (SupportNonRfc) {
2237
                            NonRfcChannel nchannel = (NonRfcChannel)channel;
2238
                        	if (((NonRfcChannelUser)channeluser).IsAdmin) {
2239
    	                        nchannel.UnsafeAdmins.Remove(oldnickname);
2240
        	                    nchannel.UnsafeAdmins.Add(newnickname, channeluser);            		
2241
                        	}
2242
                        	if (((NonRfcChannelUser)channeluser).IsHalfop) {
2243
    	                        nchannel.UnsafeHalfops.Remove(oldnickname);
2244
        	                    nchannel.UnsafeHalfops.Add(newnickname, channeluser);            		
2245
                        	}
2246
                        	if (((NonRfcChannelUser)channeluser).IsOwner) {
2247
    	                        nchannel.UnsafeOwners.Remove(oldnickname);
2248
        	                    nchannel.UnsafeOwners.Add(newnickname, channeluser);            		
2249
                        	}
2250
                        }
2251

  
2096 2252
                    }
2097 2253
                }
2098 2254
            }
......
2234 2390
            if (ActiveChannelSyncing &&
2235 2391
                IsJoined(channelname)) {
2236 2392
                string nickname;
2237
                bool   op;
2238
                bool   halfop;
2239
                bool   voice;
2393
                bool   op, voice;
2394
                bool   halfop, admin, owner;
2240 2395
                foreach (string user in userlist) {
2241 2396
                    if (user.Length <= 0) {
2242 2397
                        continue;
2243 2398
                    }
2244 2399

  
2245 2400
                    op = false;
2401
                    voice = false;
2246 2402
                    halfop = false;
2247
                    voice = false;
2403
                    admin = false;
2404
                    owner = false;
2248 2405
                    switch (user[0]) {
2249 2406
                        case '@':
2250 2407
                            op = true;
......
2266 2423
                        case '~':
2267 2424
                            nickname = user.Substring(1);
2268 2425
                        break;
2426
                        case '*':
2427
                            owner = true;
2428
                            nickname = user.Substring(1);
2429
                        break;
2430
                        case '!':
2431
                            admin = true;
2432
                            nickname = user.Substring(1);
2433
                        break;
2269 2434
                        default:
2270 2435
                            nickname = user;
2271 2436
                        break;
......
2297 2462
                            Logger.ChannelSyncing.Debug("added op: "+nickname+" to: "+channelname);
2298 2463
#endif
2299 2464
                        }
2300
                        if (SupportNonRfc && halfop)  {
2301
                            ((NonRfcChannel)channel).UnsafeHalfops.Add(nickname, channeluser);
2302
#if LOG4NET
2303
                            Logger.ChannelSyncing.Debug("added halfop: "+nickname+" to: "+channelname);
2304
#endif
2305
                        }
2306 2465
                        if (voice) {
2307 2466
                            channel.UnsafeVoices.Add(nickname, channeluser);
2308 2467
#if LOG4NET
2309 2468
                            Logger.ChannelSyncing.Debug("added voice: "+nickname+" to: "+channelname);
2310 2469
#endif
2311 2470
                        }
2471
                        if (SupportNonRfc) {
2472
                        	if (admin)  {
2473
	                            ((NonRfcChannel)channel).UnsafeAdmins.Add(nickname, channeluser);
2474
#if LOG4NET
2475
    	                        Logger.ChannelSyncing.Debug("added admin: "+nickname+" to: "+channelname);
2476
#endif
2477
                        	}
2478
                        	if (halfop)  {
2479
	                            ((NonRfcChannel)channel).UnsafeHalfops.Add(nickname, channeluser);
2480
#if LOG4NET
2481
    	                        Logger.ChannelSyncing.Debug("added halfop: "+nickname+" to: "+channelname);
2482
#endif
2483
                        	}
2484
                        	if (owner)  {
2485
	                            ((NonRfcChannel)channel).UnsafeOwners.Add(nickname, channeluser);
2486
#if LOG4NET
2487
    	                        Logger.ChannelSyncing.Debug("added owner: "+nickname+" to: "+channelname);
2488
#endif
2489
                        	}
2490

  
2491
                        }
2312 2492
                    }
2313 2493

  
2314 2494
                    channeluser.IsOp    = op;
2315 2495
                    channeluser.IsVoice = voice;
2316 2496
                    if (SupportNonRfc) {
2497
                        ((NonRfcChannelUser)channeluser).IsAdmin = admin;
2317 2498
                        ((NonRfcChannelUser)channeluser).IsHalfop = halfop;
2499
                        ((NonRfcChannelUser)channeluser).IsOwner = owner;
2318 2500
                    }
2319 2501
                }
2320 2502
            }
IrcClient/NonRfcChannel.cs (working copy)
8 8
 * SmartIrc4net - the IRC library for .NET/C# <http://smartirc4net.sf.net>
9 9
 *
10 10
 * Copyright (c) 2003-2005 Mirco Bauer <[email protected]> <http://www.meebey.net>
11
 * Copyright (c) 2008-2009 Thomas Bruderer <[email protected]>
11 12
 * 
12 13
 * Full LGPL License: <http://www.gnu.org/licenses/lgpl.txt>
13 14
 * 
......
38 39
    public class NonRfcChannel : Channel
39 40
    {
40 41
        private Hashtable _Halfops = Hashtable.Synchronized(new Hashtable(new CaseInsensitiveHashCodeProvider(), new CaseInsensitiveComparer()));
42
        private Hashtable _Admins = Hashtable.Synchronized(new Hashtable(new CaseInsensitiveHashCodeProvider(), new CaseInsensitiveComparer()));
43
        private Hashtable _Owners = Hashtable.Synchronized(new Hashtable(new CaseInsensitiveHashCodeProvider(), new CaseInsensitiveComparer()));
41 44
        
42 45
        /// <summary>
43 46
        /// 
......
73 76
                return _Halfops;
74 77
            }
75 78
        }
79
        
80
                /// <summary>
81
        /// 
82
        /// </summary>
83
        /// <value> </value>
84
        public Hashtable Admins {
85
            get {
86
                return (Hashtable) _Admins.Clone();
87
            }
88
        }
89

  
90
        /// <summary>
91
        /// 
92
        /// </summary>
93
        /// <value> </value>
94
        internal Hashtable UnsafeAdmins {
95
            get {
96
                return _Admins;
97
            }
98
        }
99
        
100
                /// <summary>
101
        /// 
102
        /// </summary>
103
        /// <value> </value>
104
        public Hashtable Owners {
105
            get {
106
                return (Hashtable) _Owners.Clone();
107
            }
108
        }
109

  
110
        /// <summary>
111
        /// 
112
        /// </summary>
113
        /// <value> </value>
114
        internal Hashtable UnsafeOwners {
115
            get {
116
                return _Owners;
117
            }
118
        }
76 119
    }
77 120
}
IrcClient/NonRfcChannelUser.cs (working copy)
8 8
 * SmartIrc4net - the IRC library for .NET/C# <http://smartirc4net.sf.net>
9 9
 *
10 10
 * Copyright (c) 2003-2005 Mirco Bauer <[email protected]> <http://www.meebey.net>
11
 * Copyright (c) 2008-2009 Thomas Bruderer <[email protected]>
11 12
 * 
12 13
 * Full LGPL License: <http://www.gnu.org/licenses/lgpl.txt>
13 14
 * 
......
34 35
    /// <threadsafety static="true" instance="true" />
35 36
    public class NonRfcChannelUser : ChannelUser
36 37
    {
37
        private bool _IsHalfop;
38
        private bool _IsOwner;
39
        private bool _IsAdmin;
38
        private bool _IsHalfop; //+h - halfop (%)
39
        private bool _IsOwner;  //+q - owner (*)
40
        private bool _IsAdmin;  //+a - admin/protect (!)
40 41
        
41 42
        /// <summary>
42 43
        /// 
......
58 59
        /// 
59 60
        /// </summary>
60 61
        /// <value> </value>
62
        public bool IsAdmin {
63
            get {
64
                return _IsAdmin;
65
            }
66
            set {
67
                _IsAdmin = value;
68
            }
69
        }
70
        
71
        /// <summary>
72
        /// 
73
        /// </summary>
74
        /// <value> </value>
61 75
        public bool IsHalfop {
62 76
            get {
63 77
                return _IsHalfop;
......
66 80
                _IsHalfop = value;
67 81
            }
68 82
        }
83

  
84
        /// <summary>
85
        /// 
86
        /// </summary>
87
        /// <value> </value>
88
        public bool IsOwner {
89
            get {
90
                return _IsOwner;
91
            }
92
            set {
93
                _IsOwner = value;
94
            }
95
        }
96

  
69 97
    }
70 98
}