Remove the IRCChannels class.
It was only overcomplicating things with no gain at all. Instead, strings are used to describe channels now and the storage of users in a channel is inside IRCConnection now. FossilOrigin-Name: 620b9b2a3087ddf679bb44eaa5e7e1a688c4cb99ffdc450e1073ab31e693c556
This commit is contained in:
parent
c29ff783e2
commit
5f6b64efbd
7 changed files with 90 additions and 250 deletions
|
@ -7,8 +7,6 @@
|
||||||
objects = {
|
objects = {
|
||||||
|
|
||||||
/* Begin PBXBuildFile section */
|
/* Begin PBXBuildFile section */
|
||||||
4BBE6ECC1338258D007EE595 /* IRCChannel.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BBE6EC81338258D007EE595 /* IRCChannel.h */; };
|
|
||||||
4BBE6ECD1338258D007EE595 /* IRCChannel.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BBE6EC91338258D007EE595 /* IRCChannel.m */; };
|
|
||||||
4BBE6ECE1338258D007EE595 /* IRCConnection.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BBE6ECA1338258D007EE595 /* IRCConnection.h */; };
|
4BBE6ECE1338258D007EE595 /* IRCConnection.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BBE6ECA1338258D007EE595 /* IRCConnection.h */; };
|
||||||
4BBE6ECF1338258D007EE595 /* IRCConnection.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BBE6ECB1338258D007EE595 /* IRCConnection.m */; };
|
4BBE6ECF1338258D007EE595 /* IRCConnection.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BBE6ECB1338258D007EE595 /* IRCConnection.m */; };
|
||||||
4BBE6EE313382DAE007EE595 /* IRCUser.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BBE6EE113382DAE007EE595 /* IRCUser.h */; };
|
4BBE6EE313382DAE007EE595 /* IRCUser.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BBE6EE113382DAE007EE595 /* IRCUser.h */; };
|
||||||
|
@ -44,8 +42,6 @@
|
||||||
/* Begin PBXFileReference section */
|
/* Begin PBXFileReference section */
|
||||||
4BBE6EB013382479007EE595 /* ObjIRC.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = ObjIRC.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
4BBE6EB013382479007EE595 /* ObjIRC.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = ObjIRC.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||||
4BBE6EC713382541007EE595 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = SOURCE_ROOT; };
|
4BBE6EC713382541007EE595 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = SOURCE_ROOT; };
|
||||||
4BBE6EC81338258D007EE595 /* IRCChannel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = IRCChannel.h; path = src/IRCChannel.h; sourceTree = SOURCE_ROOT; };
|
|
||||||
4BBE6EC91338258D007EE595 /* IRCChannel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = IRCChannel.m; path = src/IRCChannel.m; sourceTree = SOURCE_ROOT; };
|
|
||||||
4BBE6ECA1338258D007EE595 /* IRCConnection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = IRCConnection.h; path = src/IRCConnection.h; sourceTree = SOURCE_ROOT; };
|
4BBE6ECA1338258D007EE595 /* IRCConnection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = IRCConnection.h; path = src/IRCConnection.h; sourceTree = SOURCE_ROOT; };
|
||||||
4BBE6ECB1338258D007EE595 /* IRCConnection.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = IRCConnection.m; path = src/IRCConnection.m; sourceTree = SOURCE_ROOT; };
|
4BBE6ECB1338258D007EE595 /* IRCConnection.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = IRCConnection.m; path = src/IRCConnection.m; sourceTree = SOURCE_ROOT; };
|
||||||
4BBE6EE113382DAE007EE595 /* IRCUser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = IRCUser.h; path = src/IRCUser.h; sourceTree = SOURCE_ROOT; };
|
4BBE6EE113382DAE007EE595 /* IRCUser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = IRCUser.h; path = src/IRCUser.h; sourceTree = SOURCE_ROOT; };
|
||||||
|
@ -109,8 +105,6 @@
|
||||||
children = (
|
children = (
|
||||||
4BBE6F0213383A19007EE595 /* Frameworks */,
|
4BBE6F0213383A19007EE595 /* Frameworks */,
|
||||||
4BBE6EBA1338247A007EE595 /* Supporting Files */,
|
4BBE6EBA1338247A007EE595 /* Supporting Files */,
|
||||||
4BBE6EC81338258D007EE595 /* IRCChannel.h */,
|
|
||||||
4BBE6EC91338258D007EE595 /* IRCChannel.m */,
|
|
||||||
4BBE6ECA1338258D007EE595 /* IRCConnection.h */,
|
4BBE6ECA1338258D007EE595 /* IRCConnection.h */,
|
||||||
4BBE6ECB1338258D007EE595 /* IRCConnection.m */,
|
4BBE6ECB1338258D007EE595 /* IRCConnection.m */,
|
||||||
4BBE6EE113382DAE007EE595 /* IRCUser.h */,
|
4BBE6EE113382DAE007EE595 /* IRCUser.h */,
|
||||||
|
@ -151,7 +145,6 @@
|
||||||
isa = PBXHeadersBuildPhase;
|
isa = PBXHeadersBuildPhase;
|
||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
4BBE6ECC1338258D007EE595 /* IRCChannel.h in Headers */,
|
|
||||||
4BBE6ECE1338258D007EE595 /* IRCConnection.h in Headers */,
|
4BBE6ECE1338258D007EE595 /* IRCConnection.h in Headers */,
|
||||||
4BBE6EE313382DAE007EE595 /* IRCUser.h in Headers */,
|
4BBE6EE313382DAE007EE595 /* IRCUser.h in Headers */,
|
||||||
);
|
);
|
||||||
|
@ -234,7 +227,6 @@
|
||||||
isa = PBXSourcesBuildPhase;
|
isa = PBXSourcesBuildPhase;
|
||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
4BBE6ECD1338258D007EE595 /* IRCChannel.m in Sources */,
|
|
||||||
4BBE6ECF1338258D007EE595 /* IRCConnection.m in Sources */,
|
4BBE6ECF1338258D007EE595 /* IRCConnection.m in Sources */,
|
||||||
4BBE6EE413382DAE007EE595 /* IRCUser.m in Sources */,
|
4BBE6EE413382DAE007EE595 /* IRCUser.m in Sources */,
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,45 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2010, 2011, Jonathan Schleifer <js@webkeks.org>
|
|
||||||
*
|
|
||||||
* https://webkeks.org/git/?p=objirc.git
|
|
||||||
*
|
|
||||||
* Permission to use, copy, modify, and/or distribute this software for any
|
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
|
||||||
* copyright notice and this permission notice is present in all copies.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
||||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
||||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
||||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
||||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
||||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
||||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
||||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
||||||
* POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#import <ObjFW/OFObject.h>
|
|
||||||
#import <ObjFW/OFSet.h>
|
|
||||||
|
|
||||||
@class OFString;
|
|
||||||
|
|
||||||
@interface IRCChannel: OFObject
|
|
||||||
{
|
|
||||||
OFString *name;
|
|
||||||
OFMutableSet *users;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef OF_HAVE_PROPERTIES
|
|
||||||
@property (readonly) OFString *name;
|
|
||||||
@property (readonly, copy) OFSet *users;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
+ channelWithName: (OFString*)name;
|
|
||||||
- initWithName: (OFString*)name;
|
|
||||||
- (OFString*)name;
|
|
||||||
- (OFSet*)users;
|
|
||||||
- (void)IRC_addUser: (OFString*)user;
|
|
||||||
- (void)IRC_removeUser: (OFString*)user;
|
|
||||||
@end
|
|
|
@ -1,82 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2010, 2011, Jonathan Schleifer <js@webkeks.org>
|
|
||||||
*
|
|
||||||
* https://webkeks.org/git/?p=objirc.git
|
|
||||||
*
|
|
||||||
* Permission to use, copy, modify, and/or distribute this software for any
|
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
|
||||||
* copyright notice and this permission notice is present in all copies.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
||||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
||||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
||||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
||||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
||||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
||||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
||||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
||||||
* POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#import <ObjFW/OFString.h>
|
|
||||||
|
|
||||||
#import <ObjFW/macros.h>
|
|
||||||
|
|
||||||
#import "IRCChannel.h"
|
|
||||||
|
|
||||||
@implementation IRCChannel
|
|
||||||
+ channelWithName: (OFString*)name
|
|
||||||
{
|
|
||||||
return [[[self alloc] initWithName: name] autorelease];
|
|
||||||
}
|
|
||||||
|
|
||||||
- initWithName: (OFString*)name_
|
|
||||||
{
|
|
||||||
self = [super init];
|
|
||||||
|
|
||||||
@try {
|
|
||||||
name = [name_ copy];
|
|
||||||
users = [[OFMutableSet alloc] init];
|
|
||||||
} @catch (id e) {
|
|
||||||
[self release];
|
|
||||||
@throw e;
|
|
||||||
}
|
|
||||||
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)dealloc
|
|
||||||
{
|
|
||||||
[name release];
|
|
||||||
[users release];
|
|
||||||
|
|
||||||
[super dealloc];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (OFString*)name
|
|
||||||
{
|
|
||||||
OF_GETTER(name, YES)
|
|
||||||
}
|
|
||||||
|
|
||||||
- (OFSet*)users
|
|
||||||
{
|
|
||||||
return [[users copy] autorelease];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (OFString*)description
|
|
||||||
{
|
|
||||||
return [[name copy] autorelease];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)IRC_addUser: (OFString*)user
|
|
||||||
{
|
|
||||||
[users addObject: user];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)IRC_removeUser: (OFString*)user
|
|
||||||
{
|
|
||||||
[users removeObject: user];
|
|
||||||
}
|
|
||||||
@end
|
|
|
@ -20,14 +20,10 @@
|
||||||
* POSSIBILITY OF SUCH DAMAGE.
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#import <ObjFW/OFObject.h>
|
#import <ObjFW/ObjFW.h>
|
||||||
|
|
||||||
@class OFString;
|
|
||||||
@class OFMutableDictionary;
|
|
||||||
@class OFTCPSocket;
|
|
||||||
@class IRCConnection;
|
@class IRCConnection;
|
||||||
@class IRCUser;
|
@class IRCUser;
|
||||||
@class IRCChannel;
|
|
||||||
|
|
||||||
#ifndef IRC_CONNECTION_M
|
#ifndef IRC_CONNECTION_M
|
||||||
@protocol IRCConnectionDelegate <OFObject>
|
@protocol IRCConnectionDelegate <OFObject>
|
||||||
|
@ -44,10 +40,10 @@
|
||||||
- (void)connectionWasEstablished: (IRCConnection*)connection;
|
- (void)connectionWasEstablished: (IRCConnection*)connection;
|
||||||
- (void)connection: (IRCConnection*)connection
|
- (void)connection: (IRCConnection*)connection
|
||||||
didSeeUser: (IRCUser*)user
|
didSeeUser: (IRCUser*)user
|
||||||
joinChannel: (IRCChannel*)channel;
|
joinChannel: (OFString*)channel;
|
||||||
- (void)connection: (IRCConnection*)connection
|
- (void)connection: (IRCConnection*)connection
|
||||||
didSeeUser: (IRCUser*)user
|
didSeeUser: (IRCUser*)user
|
||||||
leaveChannel: (IRCChannel*)channel
|
leaveChannel: (OFString*)channel
|
||||||
reason: (OFString*)reason;
|
reason: (OFString*)reason;
|
||||||
- (void)connection: (IRCConnection*)connection
|
- (void)connection: (IRCConnection*)connection
|
||||||
didSeeUser: (IRCUser*)user
|
didSeeUser: (IRCUser*)user
|
||||||
|
@ -55,15 +51,15 @@
|
||||||
- (void)connection: (IRCConnection*)connection
|
- (void)connection: (IRCConnection*)connection
|
||||||
didSeeUser: (IRCUser*)user
|
didSeeUser: (IRCUser*)user
|
||||||
kickUser: (OFString*)kickedUser
|
kickUser: (OFString*)kickedUser
|
||||||
channel: (IRCChannel*)channel
|
channel: (OFString*)channel
|
||||||
reason: (OFString*)reason;
|
reason: (OFString*)reason;
|
||||||
- (void)connection: (IRCConnection*)connection
|
- (void)connection: (IRCConnection*)connection
|
||||||
didSeeUserQuit: (IRCUser*)user
|
didSeeUserQuit: (IRCUser*)user
|
||||||
reason: (OFString*)reason;
|
reason: (OFString*)reason;
|
||||||
- (void)connection: (IRCConnection*)connection
|
- (void)connection: (IRCConnection*)connection
|
||||||
didReceiveMessage: (OFString*)msg
|
didReceiveMessage: (OFString*)msg
|
||||||
user: (IRCUser*)user
|
channel: (OFString*)channel
|
||||||
channel: (IRCChannel*)channel;
|
user: (IRCUser*)user;
|
||||||
- (void)connection: (IRCConnection*)connection
|
- (void)connection: (IRCConnection*)connection
|
||||||
didReceivePrivateMessage: (OFString*)msg
|
didReceivePrivateMessage: (OFString*)msg
|
||||||
user: (IRCUser*)user;
|
user: (IRCUser*)user;
|
||||||
|
@ -72,10 +68,10 @@
|
||||||
user: (IRCUser*)user;
|
user: (IRCUser*)user;
|
||||||
- (void)connection: (IRCConnection*)connection
|
- (void)connection: (IRCConnection*)connection
|
||||||
didReceiveNotice: (OFString*)notice
|
didReceiveNotice: (OFString*)notice
|
||||||
user: (IRCUser*)user
|
channel: (OFString*)channel
|
||||||
channel: (IRCChannel*)channel;
|
user: (IRCUser*)user;
|
||||||
- (void)connection: (IRCConnection*)connection
|
- (void)connection: (IRCConnection*)connection
|
||||||
didReceiveNamesForChannel: (IRCChannel*)channel;
|
didReceiveNamesForChannel: (OFString*)channel;
|
||||||
- (void)connectionWasClosed: (IRCConnection*)connection;
|
- (void)connectionWasClosed: (IRCConnection*)connection;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@ -116,23 +112,20 @@
|
||||||
- (void)disconnect;
|
- (void)disconnect;
|
||||||
- (void)disconnectWithReason: (OFString*)reason;
|
- (void)disconnectWithReason: (OFString*)reason;
|
||||||
- (void)joinChannel: (OFString*)channelName;
|
- (void)joinChannel: (OFString*)channelName;
|
||||||
- (void)leaveChannel: (IRCChannel*)channel;
|
- (void)leaveChannel: (OFString*)channel;
|
||||||
- (void)leaveChannel: (IRCChannel*)channel
|
- (void)leaveChannel: (OFString*)channel
|
||||||
reason: (OFString*)reason;
|
reason: (OFString*)reason;
|
||||||
- (void)sendMessage: (OFString*)msg
|
- (void)sendMessage: (OFString*)msg
|
||||||
channel: (IRCChannel*)channel;
|
to: (OFString*)to;
|
||||||
- (void)sendMessage: (OFString*)msg
|
|
||||||
user: (OFString*)user;
|
|
||||||
- (void)sendNotice: (OFString*)notice
|
- (void)sendNotice: (OFString*)notice
|
||||||
user: (OFString*)user;
|
to: (OFString*)to;
|
||||||
- (void)sendNotice: (OFString*)notice
|
|
||||||
channel: (IRCChannel*)channel;
|
|
||||||
- (void)kickUser: (OFString*)user
|
- (void)kickUser: (OFString*)user
|
||||||
channel: (IRCChannel*)channel
|
channel: (OFString*)channel
|
||||||
reason: (OFString*)reason;
|
reason: (OFString*)reason;
|
||||||
- (void)changeNicknameTo: (OFString*)nickname;
|
- (void)changeNicknameTo: (OFString*)nickname;
|
||||||
- (void)processLine: (OFString*)line;
|
- (void)processLine: (OFString*)line;
|
||||||
- (void)handleConnection;
|
- (void)handleConnection;
|
||||||
|
- (OFSet*)usersInChannel: (OFString*)channel;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@interface OFObject (IRCConnectionDelegate) <IRCConnectionDelegate>
|
@interface OFObject (IRCConnectionDelegate) <IRCConnectionDelegate>
|
||||||
|
|
|
@ -36,7 +36,6 @@
|
||||||
|
|
||||||
#import "IRCConnection.h"
|
#import "IRCConnection.h"
|
||||||
#import "IRCUser.h"
|
#import "IRCUser.h"
|
||||||
#import "IRCChannel.h"
|
|
||||||
|
|
||||||
@implementation IRCConnection
|
@implementation IRCConnection
|
||||||
- init
|
- init
|
||||||
|
@ -146,27 +145,26 @@
|
||||||
[self sendLineWithFormat: @"QUIT :%@", reason];
|
[self sendLineWithFormat: @"QUIT :%@", reason];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)joinChannel: (OFString*)channelName
|
- (void)joinChannel: (OFString*)channel
|
||||||
{
|
{
|
||||||
[self sendLineWithFormat: @"JOIN %@", channelName];
|
[self sendLineWithFormat: @"JOIN %@", channel];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)leaveChannel: (IRCChannel*)channel
|
- (void)leaveChannel: (OFString*)channel
|
||||||
{
|
{
|
||||||
[self leaveChannel: channel
|
[self leaveChannel: channel
|
||||||
reason: nil];
|
reason: nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)leaveChannel: (IRCChannel*)channel
|
- (void)leaveChannel: (OFString*)channel
|
||||||
reason: (OFString*)reason
|
reason: (OFString*)reason
|
||||||
{
|
{
|
||||||
if (reason == nil)
|
if (reason == nil)
|
||||||
[self sendLineWithFormat: @"PART %@", [channel name]];
|
[self sendLineWithFormat: @"PART %@", channel];
|
||||||
else
|
else
|
||||||
[self sendLineWithFormat: @"PART %@ :%@",
|
[self sendLineWithFormat: @"PART %@ :%@", channel, reason];
|
||||||
[channel name], reason];
|
|
||||||
|
|
||||||
[channels removeObjectForKey: [channel name]];
|
[channels removeObjectForKey: channel];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)sendLine: (OFString*)line
|
- (void)sendLine: (OFString*)line
|
||||||
|
@ -194,35 +192,22 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)sendMessage: (OFString*)msg
|
- (void)sendMessage: (OFString*)msg
|
||||||
channel: (IRCChannel*)channel
|
to: (OFString*)to
|
||||||
{
|
{
|
||||||
[self sendLineWithFormat: @"PRIVMSG %@ :%@", [channel name], msg];
|
[self sendLineWithFormat: @"PRIVMSG %@ :%@", to, msg];
|
||||||
}
|
|
||||||
|
|
||||||
- (void)sendMessage: (OFString*)msg
|
|
||||||
user: (OFString*)user
|
|
||||||
{
|
|
||||||
[self sendLineWithFormat: @"PRIVMSG %@ :%@", user, msg];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)sendNotice: (OFString*)notice
|
- (void)sendNotice: (OFString*)notice
|
||||||
user: (OFString*)user
|
to: (OFString*)to
|
||||||
{
|
{
|
||||||
[self sendLineWithFormat: @"NOTICE %@ :%@", user, notice];
|
[self sendLineWithFormat: @"NOTICE %@ :%@", to, notice];
|
||||||
}
|
|
||||||
|
|
||||||
- (void)sendNotice: (OFString*)notice
|
|
||||||
channel: (IRCChannel*)channel
|
|
||||||
{
|
|
||||||
[self sendLineWithFormat: @"NOTICE %@ :%@", [channel name], notice];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)kickUser: (OFString*)user
|
- (void)kickUser: (OFString*)user
|
||||||
channel: (IRCChannel*)channel
|
channel: (OFString*)channel
|
||||||
reason: (OFString*)reason
|
reason: (OFString*)reason
|
||||||
{
|
{
|
||||||
[self sendLineWithFormat: @"KICK %@ %@ :%@",
|
[self sendLineWithFormat: @"KICK %@ %@ :%@", channel, user, reason];
|
||||||
[channel name], user, reason];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)changeNicknameTo: (OFString*)nickname_
|
- (void)changeNicknameTo: (OFString*)nickname_
|
||||||
|
@ -264,38 +249,39 @@
|
||||||
OFString *who = [components objectAtIndex: 0];
|
OFString *who = [components objectAtIndex: 0];
|
||||||
OFString *where = [components objectAtIndex: 2];
|
OFString *where = [components objectAtIndex: 2];
|
||||||
IRCUser *user;
|
IRCUser *user;
|
||||||
IRCChannel *channel;
|
OFMutableSet *channel;
|
||||||
|
|
||||||
who = [who substringWithRange: of_range(1, [who length] - 1)];
|
who = [who substringWithRange: of_range(1, [who length] - 1)];
|
||||||
user = [IRCUser IRCUserWithString: who];
|
user = [IRCUser IRCUserWithString: who];
|
||||||
|
|
||||||
if ([who hasPrefix: [nickname stringByAppendingString: @"!"]]) {
|
if ([who hasPrefix: [nickname stringByAppendingString: @"!"]]) {
|
||||||
channel = [IRCChannel channelWithName: where];
|
channel = [OFMutableSet set];
|
||||||
[channels setObject: channel
|
[channels setObject: channel
|
||||||
forKey: where];
|
forKey: where];
|
||||||
} else
|
} else
|
||||||
channel = [channels objectForKey: where];
|
channel = [channels objectForKey: where];
|
||||||
|
|
||||||
[channel IRC_addUser: [user nickname]];
|
[channel addObject: [user nickname]];
|
||||||
|
|
||||||
[delegate connection: self
|
[delegate connection: self
|
||||||
didSeeUser: user
|
didSeeUser: user
|
||||||
joinChannel: channel];
|
joinChannel: where];
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* NAMES reply */
|
/* NAMES reply */
|
||||||
if ([action isEqual: @"353"] && [components count] >= 6) {
|
if ([action isEqual: @"353"] && [components count] >= 6) {
|
||||||
IRCChannel *channel;
|
OFString *where;
|
||||||
|
OFMutableSet *channel;
|
||||||
OFArray *users;
|
OFArray *users;
|
||||||
size_t pos;
|
size_t pos;
|
||||||
OFEnumerator *enumerator;
|
OFEnumerator *enumerator;
|
||||||
OFString *user;
|
OFString *user;
|
||||||
|
|
||||||
channel = [channels
|
where = [components objectAtIndex: 4];
|
||||||
objectForKey: [components objectAtIndex: 4]];
|
|
||||||
if (channel == nil) {
|
if ((channel = [channels objectForKey: where]) == nil) {
|
||||||
/* We did not request that */
|
/* We did not request that */
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -317,11 +303,11 @@
|
||||||
user = [user substringWithRange:
|
user = [user substringWithRange:
|
||||||
of_range(1, [user length] - 1)];
|
of_range(1, [user length] - 1)];
|
||||||
|
|
||||||
[channel IRC_addUser: user];
|
[channel addObject: user];
|
||||||
}
|
}
|
||||||
|
|
||||||
[delegate connection: self
|
[delegate connection: self
|
||||||
didReceiveNamesForChannel: channel];
|
didReceiveNamesForChannel: where];
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -331,7 +317,7 @@
|
||||||
OFString *who = [components objectAtIndex: 0];
|
OFString *who = [components objectAtIndex: 0];
|
||||||
OFString *where = [components objectAtIndex: 2];
|
OFString *where = [components objectAtIndex: 2];
|
||||||
IRCUser *user;
|
IRCUser *user;
|
||||||
IRCChannel *channel;
|
OFMutableSet *channel;
|
||||||
OFString *reason = nil;
|
OFString *reason = nil;
|
||||||
size_t pos = [who length] + 1 +
|
size_t pos = [who length] + 1 +
|
||||||
[[components objectAtIndex: 1] length] + 1 + [where length];
|
[[components objectAtIndex: 1] length] + 1 + [where length];
|
||||||
|
@ -344,11 +330,11 @@
|
||||||
reason = [line substringWithRange:
|
reason = [line substringWithRange:
|
||||||
of_range(pos + 2, [line length] - pos - 2)];
|
of_range(pos + 2, [line length] - pos - 2)];
|
||||||
|
|
||||||
[channel IRC_removeUser: [user nickname]];
|
[channel removeObject: [user nickname]];
|
||||||
|
|
||||||
[delegate connection: self
|
[delegate connection: self
|
||||||
didSeeUser: user
|
didSeeUser: user
|
||||||
leaveChannel: channel
|
leaveChannel: where
|
||||||
reason: reason];
|
reason: reason];
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
@ -360,7 +346,7 @@
|
||||||
OFString *where = [components objectAtIndex: 2];
|
OFString *where = [components objectAtIndex: 2];
|
||||||
OFString *whom = [components objectAtIndex: 3];
|
OFString *whom = [components objectAtIndex: 3];
|
||||||
IRCUser *user;
|
IRCUser *user;
|
||||||
IRCChannel *channel;
|
OFMutableSet *channel;
|
||||||
OFString *reason = nil;
|
OFString *reason = nil;
|
||||||
size_t pos = [who length] + 1 +
|
size_t pos = [who length] + 1 +
|
||||||
[[components objectAtIndex: 1] length] + 1 +
|
[[components objectAtIndex: 1] length] + 1 +
|
||||||
|
@ -374,12 +360,12 @@
|
||||||
reason = [line substringWithRange:
|
reason = [line substringWithRange:
|
||||||
of_range(pos + 2, [line length] - pos - 2)];
|
of_range(pos + 2, [line length] - pos - 2)];
|
||||||
|
|
||||||
[channel IRC_removeUser: [user nickname]];
|
[channel removeObject: [user nickname]];
|
||||||
|
|
||||||
[delegate connection: self
|
[delegate connection: self
|
||||||
didSeeUser: user
|
didSeeUser: user
|
||||||
kickUser: whom
|
kickUser: whom
|
||||||
channel: channel
|
channel: where
|
||||||
reason: reason];
|
reason: reason];
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
@ -393,7 +379,7 @@
|
||||||
size_t pos = [who length] + 1 +
|
size_t pos = [who length] + 1 +
|
||||||
[[components objectAtIndex: 1] length];
|
[[components objectAtIndex: 1] length];
|
||||||
OFEnumerator *enumerator;
|
OFEnumerator *enumerator;
|
||||||
IRCChannel *channel;
|
OFMutableSet *channel;
|
||||||
|
|
||||||
who = [who substringWithRange: of_range(1, [who length] - 1)];
|
who = [who substringWithRange: of_range(1, [who length] - 1)];
|
||||||
user = [IRCUser IRCUserWithString: who];
|
user = [IRCUser IRCUserWithString: who];
|
||||||
|
@ -402,9 +388,9 @@
|
||||||
reason = [line substringWithRange:
|
reason = [line substringWithRange:
|
||||||
of_range(pos + 2, [line length] - pos - 2)];
|
of_range(pos + 2, [line length] - pos - 2)];
|
||||||
|
|
||||||
enumerator = [channels keyEnumerator];
|
enumerator = [channels objectEnumerator];
|
||||||
while ((channel = [enumerator nextObject]) != nil)
|
while ((channel = [enumerator nextObject]) != nil)
|
||||||
[channel IRC_removeUser: [user nickname]];
|
[channel removeObject: [user nickname]];
|
||||||
|
|
||||||
[delegate connection: self
|
[delegate connection: self
|
||||||
didSeeUserQuit: user
|
didSeeUserQuit: user
|
||||||
|
@ -419,7 +405,7 @@
|
||||||
OFString *newNickname = [components objectAtIndex: 2];
|
OFString *newNickname = [components objectAtIndex: 2];
|
||||||
IRCUser *user;
|
IRCUser *user;
|
||||||
OFEnumerator *enumerator;
|
OFEnumerator *enumerator;
|
||||||
IRCChannel *channel;
|
OFMutableSet *channel;
|
||||||
|
|
||||||
who = [who substringWithRange: of_range(1, [who length] - 1)];
|
who = [who substringWithRange: of_range(1, [who length] - 1)];
|
||||||
newNickname = [newNickname substringWithRange:
|
newNickname = [newNickname substringWithRange:
|
||||||
|
@ -434,9 +420,9 @@
|
||||||
|
|
||||||
enumerator = [channels keyEnumerator];
|
enumerator = [channels keyEnumerator];
|
||||||
while ((channel = [enumerator nextObject]) != nil) {
|
while ((channel = [enumerator nextObject]) != nil) {
|
||||||
if ([[channel users] containsObject: [user nickname]]) {
|
if ([channel containsObject: [user nickname]]) {
|
||||||
[channel IRC_removeUser: [user nickname]];
|
[channel removeObject: [user nickname]];
|
||||||
[channel IRC_addUser: newNickname];
|
[channel addObject: newNickname];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -462,16 +448,12 @@
|
||||||
of_range(pos + 2, [line length] - pos - 2)];
|
of_range(pos + 2, [line length] - pos - 2)];
|
||||||
user = [IRCUser IRCUserWithString: from];
|
user = [IRCUser IRCUserWithString: from];
|
||||||
|
|
||||||
if (![to isEqual: nickname]) {
|
if (![to isEqual: nickname])
|
||||||
IRCChannel *channel;
|
|
||||||
|
|
||||||
channel = [channels objectForKey: to];
|
|
||||||
|
|
||||||
[delegate connection: self
|
[delegate connection: self
|
||||||
didReceiveMessage: msg
|
didReceiveMessage: msg
|
||||||
user: user
|
channel: to
|
||||||
channel: channel];
|
user: user];
|
||||||
} else
|
else
|
||||||
[delegate connection: self
|
[delegate connection: self
|
||||||
didReceivePrivateMessage: msg
|
didReceivePrivateMessage: msg
|
||||||
user: user];
|
user: user];
|
||||||
|
@ -500,16 +482,12 @@
|
||||||
|
|
||||||
user = [IRCUser IRCUserWithString: from];
|
user = [IRCUser IRCUserWithString: from];
|
||||||
|
|
||||||
if (![to isEqual: nickname]) {
|
if (![to isEqual: nickname])
|
||||||
IRCChannel *channel;
|
|
||||||
|
|
||||||
channel = [channels objectForKey: to];
|
|
||||||
|
|
||||||
[delegate connection: self
|
[delegate connection: self
|
||||||
didReceiveNotice: notice
|
didReceiveNotice: notice
|
||||||
user: user
|
channel: to
|
||||||
channel: channel];
|
user: user];
|
||||||
} else
|
else
|
||||||
[delegate connection: self
|
[delegate connection: self
|
||||||
didReceiveNotice: notice
|
didReceiveNotice: notice
|
||||||
user: user];
|
user: user];
|
||||||
|
@ -568,6 +546,11 @@
|
||||||
exception:)];
|
exception:)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (OFSet*)usersInChannel: (OFString*)channel
|
||||||
|
{
|
||||||
|
return [[[channels objectForKey: channel] copy] autorelease];
|
||||||
|
}
|
||||||
|
|
||||||
- (void)dealloc
|
- (void)dealloc
|
||||||
{
|
{
|
||||||
[sock release];
|
[sock release];
|
||||||
|
@ -598,13 +581,13 @@
|
||||||
|
|
||||||
- (void)connection: (IRCConnection*)connection
|
- (void)connection: (IRCConnection*)connection
|
||||||
didSeeUser: (IRCUser*)user
|
didSeeUser: (IRCUser*)user
|
||||||
joinChannel: (IRCChannel*)channel
|
joinChannel: (OFString*)channel
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)connection: (IRCConnection*)connection
|
- (void)connection: (IRCConnection*)connection
|
||||||
didSeeUser: (IRCUser*)user
|
didSeeUser: (IRCUser*)user
|
||||||
leaveChannel: (IRCChannel*)channel
|
leaveChannel: (OFString*)channel
|
||||||
reason: (OFString*)reason
|
reason: (OFString*)reason
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -618,7 +601,7 @@
|
||||||
- (void)connection: (IRCConnection*)connection
|
- (void)connection: (IRCConnection*)connection
|
||||||
didSeeUser: (IRCUser*)user
|
didSeeUser: (IRCUser*)user
|
||||||
kickUser: (OFString*)kickedUser
|
kickUser: (OFString*)kickedUser
|
||||||
channel: (IRCChannel*)channel
|
channel: (OFString*)channel
|
||||||
reason: (OFString*)reason
|
reason: (OFString*)reason
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -631,8 +614,8 @@
|
||||||
|
|
||||||
- (void)connection: (IRCConnection*)connection
|
- (void)connection: (IRCConnection*)connection
|
||||||
didReceiveMessage: (OFString*)msg
|
didReceiveMessage: (OFString*)msg
|
||||||
fromUser: (IRCUser*)user
|
channel: (OFString*)channel
|
||||||
channel: (IRCChannel*)channel
|
user: (IRCUser*)user
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -644,6 +627,7 @@
|
||||||
|
|
||||||
- (void)connection: (IRCConnection*)connection
|
- (void)connection: (IRCConnection*)connection
|
||||||
didReceiveNotice: (OFString*)notice
|
didReceiveNotice: (OFString*)notice
|
||||||
|
channel: (OFString*)channel
|
||||||
user: (IRCUser*)user
|
user: (IRCUser*)user
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -651,12 +635,11 @@
|
||||||
- (void)connection: (IRCConnection*)connection
|
- (void)connection: (IRCConnection*)connection
|
||||||
didReceiveNotice: (OFString*)notice
|
didReceiveNotice: (OFString*)notice
|
||||||
user: (IRCUser*)user
|
user: (IRCUser*)user
|
||||||
channel: (IRCChannel*)channel
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)connection: (IRCConnection*)connection
|
- (void)connection: (IRCConnection*)connection
|
||||||
didReceiveNamesForChannel: (IRCChannel*)channel
|
didReceiveNamesForChannel: (OFString*)channel
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,5 +21,4 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#import "IRCConnection.h"
|
#import "IRCConnection.h"
|
||||||
#import "IRCChannel.h"
|
|
||||||
#import "IRCUser.h"
|
#import "IRCUser.h"
|
||||||
|
|
44
tests/test.m
44
tests/test.m
|
@ -26,7 +26,6 @@
|
||||||
|
|
||||||
#import "IRCConnection.h"
|
#import "IRCConnection.h"
|
||||||
#import "IRCUser.h"
|
#import "IRCUser.h"
|
||||||
#import "IRCChannel.h"
|
|
||||||
|
|
||||||
@interface TestApp: OFObject
|
@interface TestApp: OFObject
|
||||||
@end
|
@end
|
||||||
|
@ -67,15 +66,15 @@ OF_APPLICATION_DELEGATE(TestApp)
|
||||||
|
|
||||||
- (void)connection: (IRCConnection*)connection
|
- (void)connection: (IRCConnection*)connection
|
||||||
didSeeUser: (IRCUser*)user
|
didSeeUser: (IRCUser*)user
|
||||||
joinChannel: (IRCChannel*)channel
|
joinChannel: (OFString*)channel
|
||||||
{
|
{
|
||||||
of_log(@"%@ joined %@.", user, channel);
|
of_log(@"%@ joined %@.", user, channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)connection: (IRCConnection*)connection
|
- (void)connection: (IRCConnection*)connection
|
||||||
didSeeUser: (IRCUser*)user
|
didSeeUser: (IRCUser*)user
|
||||||
leaveChannel: (IRCChannel*)channel
|
leaveChannel: (OFString*)channel
|
||||||
withReason: (OFString*)reason
|
reason: (OFString*)reason
|
||||||
{
|
{
|
||||||
of_log(@"%@ left %@ (%@).", user, channel, reason);
|
of_log(@"%@ left %@ (%@).", user, channel, reason);
|
||||||
}
|
}
|
||||||
|
@ -83,15 +82,15 @@ OF_APPLICATION_DELEGATE(TestApp)
|
||||||
- (void)connection: (IRCConnection*)connection
|
- (void)connection: (IRCConnection*)connection
|
||||||
didSeeUser: (IRCUser*)user
|
didSeeUser: (IRCUser*)user
|
||||||
kickUser: (OFString*)kickedUser
|
kickUser: (OFString*)kickedUser
|
||||||
fromChannel: (IRCChannel*)channel
|
channel: (OFString*)channel
|
||||||
withReason: (OFString*)reason
|
reason: (OFString*)reason
|
||||||
{
|
{
|
||||||
of_log(@"%@ kicked %@ from %@: %@", user, kickedUser, channel, reason);
|
of_log(@"%@ kicked %@ from %@: %@", user, kickedUser, channel, reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)connection: (IRCConnection*)connection
|
- (void)connection: (IRCConnection*)connection
|
||||||
didSeeUserQuit: (IRCUser*)user
|
didSeeUserQuit: (IRCUser*)user
|
||||||
withReason: (OFString*)reason
|
reason: (OFString*)reason
|
||||||
{
|
{
|
||||||
of_log(@"%@ quit (%@).", user, reason);
|
of_log(@"%@ quit (%@).", user, reason);
|
||||||
}
|
}
|
||||||
|
@ -105,37 +104,38 @@ OF_APPLICATION_DELEGATE(TestApp)
|
||||||
|
|
||||||
- (void)connection: (IRCConnection*)connection
|
- (void)connection: (IRCConnection*)connection
|
||||||
didReceiveMessage: (OFString*)msg
|
didReceiveMessage: (OFString*)msg
|
||||||
fromUser: (IRCUser*)user
|
channel: (OFString*)channel
|
||||||
inChannel: (IRCChannel*)channel
|
user: (IRCUser*)user
|
||||||
{
|
{
|
||||||
of_log(@"[%@] %@: %@", channel, user, msg);
|
of_log(@"[%@] %@: %@", channel, [user nickname], msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)connection: (IRCConnection*)connection
|
- (void)connection: (IRCConnection*)connection
|
||||||
didReceivePrivateMessage: (OFString*)msg
|
didReceivePrivateMessage: (OFString*)msg
|
||||||
fromUser: (IRCUser*)user
|
user: (IRCUser*)user
|
||||||
{
|
{
|
||||||
of_log(@"(%@): %@", user, msg);
|
of_log(@"(%@): %@", user, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)connection: (IRCConnection*)connection
|
- (void)connection: (IRCConnection*)connection
|
||||||
didReceiveNotice: (OFString*)notice
|
didReceiveNotice: (OFString*)notice
|
||||||
fromUser: (IRCUser*)user
|
channel: (OFString*)channel
|
||||||
|
user: (IRCUser*)user
|
||||||
|
{
|
||||||
|
of_log(@"NOTICE: [%@] %@: %@", channel, [user nickname], notice);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)connection: (IRCConnection*)connection
|
||||||
|
didReceiveNotice: (OFString*)notice
|
||||||
|
user: (IRCUser*)user
|
||||||
{
|
{
|
||||||
of_log(@"NOTICE: (%@): %@", user, notice);
|
of_log(@"NOTICE: (%@): %@", user, notice);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)connection: (IRCConnection*)connection
|
- (void)connection: (IRCConnection*)connection
|
||||||
didReceiveNotice: (OFString*)notice
|
didReceiveNamesForChannel: (OFString*)channel
|
||||||
fromUser: (IRCUser*)user
|
|
||||||
inChannel: (IRCChannel*)channel
|
|
||||||
{
|
{
|
||||||
of_log(@"NOTICE: [%@] %@: %@", channel, user, notice);
|
of_log(@"Users in %@: %@", channel,
|
||||||
}
|
[connection usersInChannel: channel]);
|
||||||
|
|
||||||
- (void)connection: (IRCConnection*)connection
|
|
||||||
didReceiveNamesForChannel: (IRCChannel*)channel
|
|
||||||
{
|
|
||||||
of_log(@"Users in %@: %@", channel, [channel users]);
|
|
||||||
}
|
}
|
||||||
@end
|
@end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue