mirror of
https://github.com/glest/glest-source.git
synced 2025-08-28 10:19:55 +02:00
remove libircclient from shared library
* removes libircclient from libzetaglest shared library because the editor and g3d_viewer also link against libzetaglest. Those 2 binaries don't need libircclient support * libircclient is now built directly into only the zetaglest binary * moved libircclient from source/shared_lib because it's no longer part of the shared library * libircclient put in dir "external/" because it is an "external" or "3rd" party library. The @Supertux project does something similar
This commit is contained in:
114
external/libircclient/cocoa/Classes/DDInvocationGrabber.h
vendored
Normal file
114
external/libircclient/cocoa/Classes/DDInvocationGrabber.h
vendored
Normal file
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* Copyright (c) 2007-2008 Dave Dribin
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person
|
||||
* obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without
|
||||
* restriction, including without limitation the rights to use, copy,
|
||||
* modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
* of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
||||
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* This class is based on CInvocationGrabber:
|
||||
*
|
||||
* Copyright (c) 2007, Toxic Software
|
||||
* All rights reserved.
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the Toxic Software nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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 <Foundation/Foundation.h>
|
||||
|
||||
/*
|
||||
* @class DDInvocationGrabber
|
||||
* @discussion DDInvocationGrabber is a helper object that makes it very easy to construct instances of NSInvocation for later use. The object is inspired by NSUndoManager's prepareWithInvocationTarget method. To use a DDInvocationGrabber object, you set its target to some object, then send it a message as if it were the target object (the DDInvocationGrabber object acts as a proxy), if the target message understands the message the DDInvocationGrabber object stores the message invocation.
|
||||
|
||||
DDInvocationGrabber *theGrabber = [DDInvocationGrabber invocationGrabber];
|
||||
[theGrabber setTarget:someObject]
|
||||
[theGrabber doSomethingWithParameter:someParameter]; // Send messages to 'theGrabber' as if it were 'someObject'
|
||||
NSInvocation *theInvocation = [theGrabber invocation];
|
||||
|
||||
A slightly more concise version (using the covenience category) follows:
|
||||
|
||||
DDInvocationGrabber *theGrabber = [DDInvocationGrabber invocationGrabber];
|
||||
[[theGrabber prepareWithInvocationTarget:someObject] doSomethingWithParameter:someParameter];
|
||||
NSInvocation *theInvocation = [theGrabber invocation];
|
||||
|
||||
*/
|
||||
@interface DDInvocationGrabber : NSProxy
|
||||
{
|
||||
id _target;
|
||||
NSInvocation * _invocation;
|
||||
BOOL _forwardInvokesOnMainThread;
|
||||
BOOL _waitUntilDone;
|
||||
}
|
||||
|
||||
/*
|
||||
* @method invocationGrabber
|
||||
* @abstract Returns a newly allocated, inited, autoreleased DDInvocationGrabber object.
|
||||
*/
|
||||
+ (id)invocationGrabber;
|
||||
|
||||
- (id)target;
|
||||
- (void)setTarget:(id)inTarget;
|
||||
|
||||
- (NSInvocation *)invocation;
|
||||
- (void)setInvocation:(NSInvocation *)inInvocation;
|
||||
|
||||
- (BOOL)forwardInvokesOnMainThread;
|
||||
- (void)setForwardInvokesOnMainThread:(BOOL)forwardInvokesOnMainThread;
|
||||
|
||||
- (BOOL)waitUntilDone;
|
||||
- (void)setWaitUntilDone:(BOOL)waitUntilDone;
|
||||
|
||||
@end
|
||||
|
||||
@interface DDInvocationGrabber (DDInvocationGrabber_Conveniences)
|
||||
|
||||
/*
|
||||
* @method prepareWithInvocationTarget:
|
||||
* @abstract Sets the target object of the receiver and returns itself. The sender can then send a message to the
|
||||
*/
|
||||
- (id)prepareWithInvocationTarget:(id)inTarget;
|
||||
|
||||
@end
|
171
external/libircclient/cocoa/Classes/DDInvocationGrabber.m
vendored
Normal file
171
external/libircclient/cocoa/Classes/DDInvocationGrabber.m
vendored
Normal file
@@ -0,0 +1,171 @@
|
||||
/*
|
||||
* Copyright (c) 2007-2008 Dave Dribin
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person
|
||||
* obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without
|
||||
* restriction, including without limitation the rights to use, copy,
|
||||
* modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
* of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
||||
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* This class is based on CInvocationGrabber:
|
||||
*
|
||||
* Copyright (c) 2007, Toxic Software
|
||||
* All rights reserved.
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the Toxic Software nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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 "DDInvocationGrabber.h"
|
||||
|
||||
|
||||
@implementation DDInvocationGrabber
|
||||
|
||||
+ (id)invocationGrabber
|
||||
{
|
||||
return([[[self alloc] init] autorelease]);
|
||||
}
|
||||
|
||||
- (id)init
|
||||
{
|
||||
_target = nil;
|
||||
_invocation = nil;
|
||||
_forwardInvokesOnMainThread = NO;
|
||||
_waitUntilDone = NO;
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
[self setTarget:NULL];
|
||||
[self setInvocation:NULL];
|
||||
//
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
|
||||
- (id)target
|
||||
{
|
||||
return _target;
|
||||
}
|
||||
|
||||
- (void)setTarget:(id)inTarget
|
||||
{
|
||||
if (_target != inTarget)
|
||||
{
|
||||
[_target autorelease];
|
||||
_target = [inTarget retain];
|
||||
}
|
||||
}
|
||||
|
||||
- (NSInvocation *)invocation
|
||||
{
|
||||
return _invocation;
|
||||
}
|
||||
|
||||
- (void)setInvocation:(NSInvocation *)inInvocation
|
||||
{
|
||||
if (_invocation != inInvocation)
|
||||
{
|
||||
[_invocation autorelease];
|
||||
_invocation = [inInvocation retain];
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)forwardInvokesOnMainThread;
|
||||
{
|
||||
return _forwardInvokesOnMainThread;
|
||||
}
|
||||
|
||||
- (void)setForwardInvokesOnMainThread:(BOOL)forwardInvokesOnMainThread;
|
||||
{
|
||||
_forwardInvokesOnMainThread = forwardInvokesOnMainThread;
|
||||
}
|
||||
|
||||
- (BOOL)waitUntilDone;
|
||||
{
|
||||
return _waitUntilDone;
|
||||
}
|
||||
|
||||
- (void)setWaitUntilDone:(BOOL)waitUntilDone;
|
||||
{
|
||||
_waitUntilDone = waitUntilDone;
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
|
||||
- (NSMethodSignature *)methodSignatureForSelector:(SEL)selector
|
||||
{
|
||||
return [[self target] methodSignatureForSelector:selector];
|
||||
}
|
||||
|
||||
- (void)forwardInvocation:(NSInvocation *)ioInvocation
|
||||
{
|
||||
[ioInvocation setTarget:[self target]];
|
||||
[self setInvocation:ioInvocation];
|
||||
if (_forwardInvokesOnMainThread)
|
||||
{
|
||||
if (!_waitUntilDone)
|
||||
[_invocation retainArguments];
|
||||
[_invocation performSelectorOnMainThread:@selector(invoke)
|
||||
withObject:nil
|
||||
waitUntilDone:_waitUntilDone];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
#pragma mark -
|
||||
|
||||
@implementation DDInvocationGrabber (DDnvocationGrabber_Conveniences)
|
||||
|
||||
- (id)prepareWithInvocationTarget:(id)inTarget
|
||||
{
|
||||
[self setTarget:inTarget];
|
||||
return(self);
|
||||
}
|
||||
|
||||
@end
|
153
external/libircclient/cocoa/Classes/IRCClientChannel.h
vendored
Normal file
153
external/libircclient/cocoa/Classes/IRCClientChannel.h
vendored
Normal file
@@ -0,0 +1,153 @@
|
||||
/*
|
||||
* Copyright (C) 2009 Nathan Ollerenshaw chrome@stupendous.net
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file IRCClientChannel.h
|
||||
* @author Nathan Ollerenshaw
|
||||
* @version 1.0
|
||||
* @date 01.2009
|
||||
* @brief Represents a connected IRC Channel.
|
||||
*/
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import <IRCClient/IRCClientChannelDelegate.h>
|
||||
|
||||
/** \class IRCClientChannel
|
||||
* @brief Represents a connected IRC Channel.
|
||||
*
|
||||
* IRCClientChannel objects are created by the IRCClientSession object
|
||||
* for a given session when the client joins an IRC channel. At that time
|
||||
* you are expected to register event handlers for each of the delegate
|
||||
* methods described in the IRCClientChannelDelegate interface.
|
||||
*/
|
||||
|
||||
@class IRCClientSession;
|
||||
@interface IRCClientChannel : NSObject {
|
||||
id delegate;
|
||||
NSString *name;
|
||||
NSStringEncoding encoding;
|
||||
IRCClientSession *session;
|
||||
NSString *topic;
|
||||
NSString *modes;
|
||||
NSMutableArray *names;
|
||||
}
|
||||
|
||||
/** Delegate to send events to */
|
||||
@property (assign) id delegate;
|
||||
|
||||
/** Name of the channel */
|
||||
@property (copy) NSString *name;
|
||||
|
||||
/** Encoding used by this channel */
|
||||
@property (assign) NSStringEncoding encoding;
|
||||
|
||||
/** Associated IRCClientSession object */
|
||||
@property (assign) IRCClientSession *session;
|
||||
|
||||
/** Topic of the channel */
|
||||
@property (copy) NSString *topic;
|
||||
|
||||
/** Mode of the channel */
|
||||
@property (copy) NSString *modes;
|
||||
|
||||
/** An array of nicknames stored as NSStrings that list the connected users
|
||||
for the channel */
|
||||
@property (assign, readonly) NSMutableArray *names;
|
||||
|
||||
/** initWithName:
|
||||
*
|
||||
* Returns an initialised IRCClientChannel with a given channel name. You
|
||||
* are not expected to initialise your own IRCClientChannel objects; if you
|
||||
* wish to join a channel you should send a [IRCClientSession join:key:] message
|
||||
* to your IRCClientSession object.
|
||||
*
|
||||
* @param aName Name of the channel.
|
||||
*/
|
||||
|
||||
- (id)initWithName:(NSString *)aName;
|
||||
|
||||
/** Parts the channel.
|
||||
*/
|
||||
|
||||
- (int)part;
|
||||
|
||||
/** Invites another IRC client to the channel.
|
||||
*
|
||||
* @param nick the nickname of the client to invite.
|
||||
*/
|
||||
|
||||
- (int)invite:(NSString *)nick;
|
||||
|
||||
/** Sets the topic of the channel.
|
||||
*
|
||||
* Note that not all users on a channel have permission to change the topic; if you fail
|
||||
* to set the topic, then you will not see an onTopic event on the IRCClientChannelDelegate.
|
||||
*
|
||||
* @param aTopic the topic the client wishes to set for the channel.
|
||||
*/
|
||||
|
||||
- (void)setTopic:(NSString *)aTopic;
|
||||
|
||||
/** Sets the mode of the channel.
|
||||
*
|
||||
* Note that not all users on a channel have permission to change the mode; if you fail
|
||||
* to set the mode, then you will not see an onMode event on the IRCClientChannelDelegate.
|
||||
*
|
||||
* @param mode the mode to set the channel to
|
||||
* @param params paramaters for the mode, if it requires parameters.
|
||||
*/
|
||||
|
||||
- (int)setMode:(NSString *)mode params:(NSString *)params;
|
||||
|
||||
/** Sends a public PRIVMSG to the channel. If you try to send more than can fit on an IRC
|
||||
* buffer, it will be truncated.
|
||||
*
|
||||
* @param message the message to send to the channel.
|
||||
*/
|
||||
|
||||
- (int)message:(NSString *)message;
|
||||
|
||||
/** Sends a public CTCP ACTION to the channel.
|
||||
*
|
||||
* @param action action to send to the channel.
|
||||
*/
|
||||
|
||||
- (int)action:(NSString *)action;
|
||||
|
||||
/** Sends a public NOTICE to the channel.
|
||||
*
|
||||
* @param notice message to send to the channel.
|
||||
*/
|
||||
|
||||
- (int)notice:(NSString *)notice;
|
||||
|
||||
/** Kicks someone from a channel.
|
||||
*
|
||||
* @param nick the IRC client to kick from the channel.
|
||||
* @param reason the message to give to the channel and the IRC client for the kick.
|
||||
*/
|
||||
|
||||
- (int)kick:(NSString *)nick reason:(NSString *)reason;
|
||||
|
||||
/** Sends a CTCP request to the channel.
|
||||
*
|
||||
* It is perfectly legal to send a CTCP request to an IRC channel, however many clients
|
||||
* decline to respond to them, and often they are percieved as annoying.
|
||||
*
|
||||
* @param request the string of the request, in CTCP format.
|
||||
*/
|
||||
|
||||
- (int)ctcpRequest:(NSString *)request;
|
||||
|
||||
@end
|
157
external/libircclient/cocoa/Classes/IRCClientChannel.m
vendored
Normal file
157
external/libircclient/cocoa/Classes/IRCClientChannel.m
vendored
Normal file
@@ -0,0 +1,157 @@
|
||||
/*
|
||||
* Copyright (C) 2009 Nathan Ollerenshaw chrome@stupendous.net
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*/
|
||||
|
||||
#import "IRCClientChannel.h"
|
||||
#import "IRCClientSession.h"
|
||||
#import "NSObject+DDExtensions.h"
|
||||
|
||||
@implementation IRCClientChannel
|
||||
|
||||
@synthesize delegate;
|
||||
@synthesize name;
|
||||
@synthesize encoding;
|
||||
@synthesize session;
|
||||
@synthesize topic;
|
||||
@synthesize modes;
|
||||
@synthesize names;
|
||||
|
||||
-(id)init
|
||||
{
|
||||
return [self initWithName:nil];
|
||||
}
|
||||
|
||||
-(id)initWithName:(NSString *)aName
|
||||
{
|
||||
if ((self = [super init])) {
|
||||
[self setName:aName];
|
||||
topic = [[NSString alloc] init];
|
||||
encoding = NSASCIIStringEncoding;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
-(void)dealloc
|
||||
{
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (int)part
|
||||
{
|
||||
return irc_cmd_part([session session], [name cStringUsingEncoding:NSASCIIStringEncoding]);
|
||||
}
|
||||
|
||||
- (int)invite:(NSString *)nick
|
||||
{
|
||||
return irc_cmd_invite([session session], [nick cStringUsingEncoding:NSASCIIStringEncoding], [name cStringUsingEncoding:NSASCIIStringEncoding]);
|
||||
}
|
||||
|
||||
- (int)refreshNames
|
||||
{
|
||||
return irc_cmd_names([session session], [name cStringUsingEncoding:NSASCIIStringEncoding]);
|
||||
}
|
||||
|
||||
- (void)setTopic:(NSString *)aTopic
|
||||
{
|
||||
irc_cmd_topic([session session], [name cStringUsingEncoding:NSASCIIStringEncoding], [topic cStringUsingEncoding:encoding]);
|
||||
}
|
||||
|
||||
- (int)setMode:(NSString *)mode params:(NSString *)params
|
||||
{
|
||||
return irc_cmd_channel_mode([session session], [name cStringUsingEncoding:NSASCIIStringEncoding], [mode cStringUsingEncoding:NSASCIIStringEncoding]);
|
||||
}
|
||||
|
||||
- (int)message:(NSString *)message
|
||||
{
|
||||
return irc_cmd_msg([session session], [name cStringUsingEncoding:NSASCIIStringEncoding], [message cStringUsingEncoding:encoding]);
|
||||
}
|
||||
|
||||
- (int)action:(NSString *)action
|
||||
{
|
||||
return irc_cmd_me([session session], [name cStringUsingEncoding:NSASCIIStringEncoding], [action cStringUsingEncoding:encoding]);
|
||||
}
|
||||
|
||||
- (int)notice:(NSString *)notice
|
||||
{
|
||||
return irc_cmd_notice([session session], [name cStringUsingEncoding:NSASCIIStringEncoding], [notice cStringUsingEncoding:encoding]);
|
||||
}
|
||||
|
||||
- (int)kick:(NSString *)nick reason:(NSString *)reason
|
||||
{
|
||||
return irc_cmd_kick([session session], [nick cStringUsingEncoding:NSASCIIStringEncoding], [name cStringUsingEncoding:NSASCIIStringEncoding], [reason cStringUsingEncoding:encoding]);
|
||||
}
|
||||
|
||||
- (int)ctcpRequest:(NSString *)request
|
||||
{
|
||||
return irc_cmd_ctcp_request([session session], [name cStringUsingEncoding:NSASCIIStringEncoding], [request cStringUsingEncoding:encoding]);
|
||||
}
|
||||
|
||||
|
||||
// event handlers
|
||||
//
|
||||
// These farm events out to the delegate on the main thread.
|
||||
|
||||
- (void)onJoin:(NSString *)nick
|
||||
{
|
||||
if ([delegate respondsToSelector:@selector(onJoin:)])
|
||||
[[delegate dd_invokeOnMainThread] onJoin:nick];
|
||||
}
|
||||
|
||||
- (void)onPart:(NSString *)nick reason:(NSString *)reason
|
||||
{
|
||||
if ([delegate respondsToSelector:@selector(onPart:reason:)])
|
||||
[[delegate dd_invokeOnMainThread] onPart:nick reason:reason];
|
||||
}
|
||||
|
||||
- (void)onMode:(NSString *)mode params:(NSString *)params nick:(NSString *)nick
|
||||
{
|
||||
if ([delegate respondsToSelector:@selector(onMode:params:nick:)])
|
||||
[[delegate dd_invokeOnMainThread] onMode:mode params:params nick:nick];
|
||||
}
|
||||
|
||||
- (void)onTopic:(NSString *)aTopic nick:(NSString *)nick
|
||||
{
|
||||
[topic release];
|
||||
topic = [NSString stringWithString:aTopic];
|
||||
|
||||
if ([delegate respondsToSelector:@selector(onTopic:nick:)])
|
||||
[[delegate dd_invokeOnMainThread] onTopic:aTopic nick:nick];
|
||||
}
|
||||
|
||||
- (void)onKick:(NSString *)nick reason:(NSString *)reason byNick:(NSString *)byNick
|
||||
{
|
||||
if ([delegate respondsToSelector:@selector(onKick:reason:byNick:)])
|
||||
[[delegate dd_invokeOnMainThread] onKick:nick reason:reason byNick:byNick];
|
||||
}
|
||||
|
||||
- (void)onPrivmsg:(NSString *)message nick:(NSString *)nick
|
||||
{
|
||||
if ([delegate respondsToSelector:@selector(onPrivmsg:nick:)])
|
||||
[[delegate dd_invokeOnMainThread] onPrivmsg:message nick:nick];
|
||||
}
|
||||
|
||||
- (void)onNotice:(NSString *)notice nick:(NSString *)nick
|
||||
{
|
||||
if ([delegate respondsToSelector:@selector(onNotice:nick:)])
|
||||
[[delegate dd_invokeOnMainThread] onNotice:notice nick:nick];
|
||||
}
|
||||
|
||||
- (void)onAction:(NSString *)action nick:(NSString *)nick
|
||||
{
|
||||
if ([delegate respondsToSelector:@selector(onAction:nick:)])
|
||||
[[delegate dd_invokeOnMainThread] onAction:action nick:nick];
|
||||
}
|
||||
|
||||
|
||||
@end
|
116
external/libircclient/cocoa/Classes/IRCClientChannelDelegate.h
vendored
Normal file
116
external/libircclient/cocoa/Classes/IRCClientChannelDelegate.h
vendored
Normal file
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
* Copyright (C) 2009 Nathan Ollerenshaw chrome@stupendous.net
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file IRCClientChannelDelegate.h
|
||||
* @author Nathan Ollerenshaw
|
||||
* @version 1.0
|
||||
* @date 01.2009
|
||||
* @brief Receives delegate messages from an IRCClientChannel.
|
||||
* @protocol IRCClientChannelDelegate
|
||||
*/
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
/** @brief Receives delegate messages from an IRCClientChannel.
|
||||
*
|
||||
* Each IRCClientChannel object needs a delegate. Delegate methods are called
|
||||
* for each event that occurs on an IRC channel that the client is current on.
|
||||
*
|
||||
* Note that for any given parameter, it may be optional, in which case a nil
|
||||
* object may be supplied instead of the given parameter.
|
||||
*/
|
||||
|
||||
@interface NSObject (IRCClientChannelDelegate)
|
||||
|
||||
/** When a client joins this channel, the onJoin event is fired. Note that
|
||||
* the nickname is most likely in nick!user\@host format, but may simply be a
|
||||
* nickname, depending on the server implementation.
|
||||
*
|
||||
* You should also expect to see this event when the client first joins a channel,
|
||||
* with a parameter of the client's nickname.
|
||||
*
|
||||
* @param nick The nickname of the user that joined the channel.
|
||||
*/
|
||||
|
||||
- (void)onJoin:(NSString *)nick;
|
||||
|
||||
/** When an IRC client parts a channel you are connect to, you will see
|
||||
* an onPart event. You will also see this event when you part a channel.
|
||||
*
|
||||
* @param nick (required) The nickname of the user that left the channel.
|
||||
* @param reason (optional) The reason, if any, that the user gave for leaving.
|
||||
*/
|
||||
|
||||
- (void)onPart:(NSString *)nick reason:(NSString *)reason;
|
||||
|
||||
/** Received when an IRC client changes the channel mode. What modes are available
|
||||
* for a given channel is an implementation detail for each server.
|
||||
*
|
||||
* @param mode the new channel mode.
|
||||
* @param params any parameters with the mode (such as channel key).
|
||||
* @param nick the nickname of the IRC client that changed the mode.
|
||||
*/
|
||||
|
||||
- (void)onMode:(NSString *)mode params:(NSString *)params nick:(NSString *)nick;
|
||||
|
||||
/** Received when the topic is changed for the channel.
|
||||
*
|
||||
* @param aTopic The new topic of the channel.
|
||||
* @param nick Nickname of the IRC client that changed the topic.
|
||||
*/
|
||||
|
||||
- (void)onTopic:(NSString *)aTopic nick:(NSString *)nick;
|
||||
|
||||
/** Received when an IRC client is kicked from a channel.
|
||||
*
|
||||
* @param nick nickname of the client that was kicked
|
||||
* @param reason reason message given for the kick
|
||||
* @param byNick nickname of the client that performed the kick command
|
||||
*/
|
||||
|
||||
- (void)onKick:(NSString *)nick reason:(NSString *)reason byNick:(NSString *)byNick;
|
||||
|
||||
/** Received when an IRC client sends a public PRIVMSG to the channel. Note that the
|
||||
* user may not necessarily be required to be on the channel to send a message
|
||||
* to it.
|
||||
*
|
||||
* @param message the message sent to the channel.
|
||||
* @param nick the nickname of the IRC client that sent the message.
|
||||
*/
|
||||
|
||||
- (void)onPrivmsg:(NSString *)message nick:(NSString *)nick;
|
||||
|
||||
/** Received when an IRC client sends a public NOTICE to the channel. Note that
|
||||
* the user may not necessarily be required to be on the channel to send a notice to
|
||||
* it. Furthermore, the RFC states that the only difference between PRIVMSG and
|
||||
* NOTICE is that a NOTICE may never be responded to automatically.
|
||||
*
|
||||
* @param notice the notice sent to the channel.
|
||||
* @param nick the nickname of the IRC client that sent the notice.
|
||||
*/
|
||||
|
||||
- (void)onNotice:(NSString *)notice nick:(NSString *)nick;
|
||||
|
||||
/** Received when an IRC client sends a CTCP ACTION message to the channel.
|
||||
* used by lamers with no life to pretend that they are playing some form of
|
||||
* MMORPG.
|
||||
*
|
||||
* @param action the action message sent to the channel.
|
||||
* @param nick the nickname of the IRC client that sent the message.
|
||||
*/
|
||||
|
||||
- (void)onAction:(NSString *)action nick:(NSString *)nick;
|
||||
|
||||
@end
|
264
external/libircclient/cocoa/Classes/IRCClientSession.h
vendored
Normal file
264
external/libircclient/cocoa/Classes/IRCClientSession.h
vendored
Normal file
@@ -0,0 +1,264 @@
|
||||
/*! \mainpage IRCClient - a Cocoa IRC Framework to create IRC clients
|
||||
*
|
||||
* \section intro_sec Introduction
|
||||
*
|
||||
* IRCClient is a Cocoa Framework that uses the excellent libircclient library
|
||||
* written by Georgy Yunaev.
|
||||
*
|
||||
* \section usage Basic Usage
|
||||
*
|
||||
* To use this framework, you will need to write an IRCClientSessionDelegate to
|
||||
* handle all of the events generated by the server, and an IRCClientChannelDelegate
|
||||
* to handle all of the events generated by channels on that server.
|
||||
*
|
||||
* You then create an IRCClientSession object in your code, assign the required
|
||||
* properties, and call connect: to connect to the server and run: to create
|
||||
* the new thread and start receiving events. For example:
|
||||
*
|
||||
* \code
|
||||
* IRCClientSession *session = [[IRCClientSession alloc] init];
|
||||
* MyIRCClientSessionDelegate *controller = [[MyIRCClientSessionDelegate alloc] init];
|
||||
*
|
||||
* [session setDelegate:controller];
|
||||
* [controller setSession:session];
|
||||
*
|
||||
* [session setServer:@"irc.dal.net"];
|
||||
* [session setPort:@"6667"];
|
||||
* [session setNickname:@"test"];
|
||||
* [session setUsername:@"test"];
|
||||
* [session setRealname:@"test"];
|
||||
* [session connect];
|
||||
*
|
||||
* [session run]; //starts the thread
|
||||
* \endcode
|
||||
*
|
||||
* \section author Author, copyright, support.
|
||||
*
|
||||
* If you have any questions, bug reports, suggestions regarding libircclient
|
||||
* or the IRCClient framework, please visit http://libircclient.sourceforge.net
|
||||
*
|
||||
* <PRE>
|
||||
* libircclient Copyright (C) 2004-2009 Georgy Yunaev gyunaev@ulduzsoft.com
|
||||
* IRCClient Copyright (C) 2009 Nathan Ollerenshaw chrome@stupendous.net
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
* </PRE>
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file IRCClientSession.h
|
||||
* @author Nathan Ollerenshaw
|
||||
* @version 1.0
|
||||
* @date 01.2009
|
||||
* @brief Represents a connected IRC Session.
|
||||
*/
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import <IRCClient/IRCClientSessionDelegate.h>
|
||||
#include <IRCClient/libircclient.h>
|
||||
|
||||
/** @class IRCClientSession
|
||||
* @brief Represents a connected IRC Session.
|
||||
*
|
||||
* IRCClientSession represents a single connection to an IRC server. On initialising
|
||||
* the object, and setting the delegate, server, port, password, nickname, username and realname
|
||||
* properties, you call the connect: and run: methods to connect to the IRC server
|
||||
* and start a new thread.
|
||||
*
|
||||
* This thread then sends messages back to the main runloop to the IRC server delegate,
|
||||
* or to the IRCClientChannel delegate as required.
|
||||
*/
|
||||
|
||||
@class IRCClientChannel;
|
||||
@interface IRCClientSession : NSObject {
|
||||
id delegate;
|
||||
irc_callbacks_t callbacks;
|
||||
irc_session_t *session;
|
||||
NSThread *thread;
|
||||
|
||||
NSString *version;
|
||||
NSString *server;
|
||||
NSString *port;
|
||||
NSString *password;
|
||||
|
||||
NSString *nickname;
|
||||
NSString *username;
|
||||
NSString *realname;
|
||||
|
||||
NSMutableDictionary *channels;
|
||||
NSMutableDictionary *nicks;
|
||||
NSStringEncoding encoding;
|
||||
}
|
||||
|
||||
/** delegate to send events to. */
|
||||
@property (assign) id delegate;
|
||||
|
||||
/** The underlying libircclient handle */
|
||||
@property (assign) irc_session_t *session;
|
||||
|
||||
/** The version string for the client to send back on CTCP VERSION requests */
|
||||
@property (copy) NSString *version;
|
||||
|
||||
/** IRC server to connect to */
|
||||
@property (copy) NSString *server;
|
||||
|
||||
/** IRC port to connect to */
|
||||
@property (copy) NSString *port;
|
||||
|
||||
/** Server password to provide on connect (may be left empty or nil) */
|
||||
@property (copy) NSString *password;
|
||||
|
||||
/** Nickname of the connected client. Note that setting this after connection will
|
||||
not result in the client renaming on IRC. You need to send a nick: message instead.
|
||||
*/
|
||||
@property (copy) NSString *nickname;
|
||||
|
||||
/** Username of the connected client. Also known as the ident.
|
||||
|
||||
Setting this after connection does nothing.
|
||||
*/
|
||||
@property (copy) NSString *username;
|
||||
|
||||
/** Realname of the connected client.
|
||||
|
||||
Setting this after connection does nothing. */
|
||||
@property (copy) NSString *realname;
|
||||
|
||||
/** An NSMutableDictionary of channels that the client is currently connected to.
|
||||
|
||||
You should not modify this. */
|
||||
@property (assign,readonly) NSMutableDictionary *channels;
|
||||
|
||||
/** The default text encoding for messages on this server.
|
||||
|
||||
This affects messages received via PRIVMSG and NOTICE, and TOPIC in a channel.
|
||||
You may change this at any time.
|
||||
*/
|
||||
|
||||
@property (assign) NSStringEncoding encoding;
|
||||
|
||||
/** Connect to the IRC server.
|
||||
|
||||
Note that this performs the initial DNS lookup and the TCP connection, so if
|
||||
there are any problems you will be notified via the return code of the message.
|
||||
|
||||
Look at the libircclient documentation for the different return codes. */
|
||||
|
||||
- (int)connect;
|
||||
|
||||
/** Disconnect from the IRC server.
|
||||
|
||||
This always works, as it simply shuts down the socket. If you want to disconnect
|
||||
in a friendly way, you should use the quit: message. */
|
||||
|
||||
- (void)disconnect;
|
||||
|
||||
/** returns YES if the server is currently connected successfully, and NO if
|
||||
it is not. */
|
||||
|
||||
- (bool)isConnected;
|
||||
|
||||
/** Starts a new thread and starts the libircclient runloop, processing events and
|
||||
firing messages back to the main runloop as required. Calling this again will
|
||||
do nothing other than raise a warning in your logs. */
|
||||
|
||||
- (void)run;
|
||||
|
||||
/** Sends a raw message to the IRC server. Please consult rfc1459 for the format
|
||||
of IRC commands. */
|
||||
|
||||
- (int)sendRawWithFormat:(NSString *)format, ...;
|
||||
|
||||
/** quits the IRC server with the given reason. On success, an onQuit event will be
|
||||
sent to the IRCClientSessionDelegate with the nickname of the IRC client.
|
||||
|
||||
The format is a standard NSString format string, followed by optional arguments.
|
||||
*/
|
||||
|
||||
- (int)quit:(NSString *)reason;
|
||||
|
||||
/** Joins a channel with a given name and key
|
||||
|
||||
@param channel the channel to join
|
||||
@param key they key for the channel (may be nil)
|
||||
*/
|
||||
|
||||
- (int)join:(NSString *)channel key:(NSString *)key;
|
||||
|
||||
/** lists channels on the IRC server.
|
||||
|
||||
@param channel a channel name or string to pass to the LIST command. Implementation specific.
|
||||
*/
|
||||
|
||||
- (int)list:(NSString *)channel;
|
||||
|
||||
/** sets the user mode for the IRC client
|
||||
|
||||
@param mode string to set
|
||||
*/
|
||||
|
||||
- (int)userMode:(NSString *)mode;
|
||||
|
||||
/** sets the IRC client nickname. On success, an onNick event will be sent to the delegate
|
||||
|
||||
@param newnick new nickname to set.
|
||||
*/
|
||||
|
||||
- (int)nick:(NSString *)newnick;
|
||||
|
||||
/** sends a WHOIS request to the IRC server
|
||||
|
||||
@param nick nickname of the irc client to whois.
|
||||
*/
|
||||
|
||||
- (int)whois:(NSString *)nick;
|
||||
|
||||
/** send a PRIVMSG to another IRC client
|
||||
|
||||
@param message message to send
|
||||
@param target the other IRC client to send the message to.
|
||||
*/
|
||||
|
||||
- (int)message:(NSString *)message to:(NSString *)target;
|
||||
|
||||
/** send a CTCP ACTION to another IRC client
|
||||
|
||||
@param action the action message to send
|
||||
@param target the nickname of the irc client to send the message to.
|
||||
*/
|
||||
|
||||
- (int)action:(NSString *)action to:(NSString *)target;
|
||||
|
||||
/** send a NOTICE to another IRC client
|
||||
|
||||
@param notice the message text to send
|
||||
@param target the nickname of the irc client to send the notice to.
|
||||
*/
|
||||
|
||||
- (int)notice:(NSString *)notice to:(NSString *)target;
|
||||
|
||||
/** send a CTCP request to another IRC client
|
||||
|
||||
@param request the CTCP request string to send
|
||||
@param target the nickname of the IRC client to send the request to.
|
||||
*/
|
||||
|
||||
- (int)ctcpRequest:(NSString *)request target:(NSString *)target;
|
||||
|
||||
/** send a CTCP reply to another IRC client
|
||||
|
||||
@param reply the CTCP reply string to send
|
||||
@param target the nickname of the IRC client to send the reply to.
|
||||
*/
|
||||
|
||||
- (int)ctcpReply:(NSString *)reply target:(NSString *)target;
|
||||
|
||||
@end
|
744
external/libircclient/cocoa/Classes/IRCClientSession.m
vendored
Normal file
744
external/libircclient/cocoa/Classes/IRCClientSession.m
vendored
Normal file
@@ -0,0 +1,744 @@
|
||||
/*
|
||||
* Copyright (C) 2009 Nathan Ollerenshaw chrome@stupendous.net
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*/
|
||||
|
||||
#define IRCCLIENTVERSION "1.0"
|
||||
|
||||
#import "IRCClientSession.h"
|
||||
#import "NSObject+DDExtensions.h"
|
||||
#import "IRCClientChannel.h"
|
||||
#include "string.h"
|
||||
|
||||
static void onConnect(irc_session_t *session, const char *event, const char *origin, const char **params, unsigned int count);
|
||||
static void onNick(irc_session_t *session, const char *event, const char *origin, const char **params, unsigned int count);
|
||||
static void onQuit(irc_session_t *session, const char *event, const char *origin, const char **params, unsigned int count);
|
||||
static void onJoinChannel(irc_session_t *session, const char *event, const char *origin, const char **params, unsigned int count);
|
||||
static void onPartChannel(irc_session_t *session, const char *event, const char *origin, const char **params, unsigned int count);
|
||||
static void onMode(irc_session_t *session, const char *event, const char *origin, const char **params, unsigned int count);
|
||||
static void onUserMode(irc_session_t *session, const char *event, const char *origin, const char **params, unsigned int count);
|
||||
static void onTopic(irc_session_t *session, const char *event, const char *origin, const char **params, unsigned int count);
|
||||
static void onKick(irc_session_t *session, const char *event, const char *origin, const char **params, unsigned int count);
|
||||
static void onChannelPrvmsg(irc_session_t *session, const char *event, const char *origin, const char **params, unsigned int count);
|
||||
static void onPrivmsg(irc_session_t *session, const char *event, const char *origin, const char **params, unsigned int count);
|
||||
static void onNotice(irc_session_t *session, const char *event, const char *origin, const char **params, unsigned int count);
|
||||
static void onInvite(irc_session_t *session, const char *event, const char *origin, const char **params, unsigned int count);
|
||||
static void onCtcpRequest(irc_session_t *session, const char *event, const char *origin, const char **params, unsigned int count);
|
||||
static void onCtcpReply(irc_session_t *session, const char *event, const char *origin, const char **params, unsigned int count);
|
||||
static void onCtcpAction(irc_session_t *session, const char *event, const char *origin, const char **params, unsigned int count);
|
||||
static void onUnknownEvent(irc_session_t *session, const char *event, const char *origin, const char **params, unsigned int count);
|
||||
static void onNumericEvent(irc_session_t * session, unsigned int event, const char * origin, const char ** params, unsigned int count);
|
||||
|
||||
@implementation IRCClientSession
|
||||
|
||||
@synthesize delegate;
|
||||
@synthesize session;
|
||||
@synthesize version;
|
||||
@synthesize server;
|
||||
@synthesize port;
|
||||
@synthesize password;
|
||||
@synthesize nickname;
|
||||
@synthesize username;
|
||||
@synthesize realname;
|
||||
@synthesize channels;
|
||||
@synthesize encoding;
|
||||
|
||||
-(id)init
|
||||
{
|
||||
if ((self = [super init])) {
|
||||
callbacks.event_connect = onConnect;
|
||||
callbacks.event_nick = onNick;
|
||||
callbacks.event_quit = onQuit;
|
||||
callbacks.event_join = onJoinChannel;
|
||||
callbacks.event_part = onPartChannel;
|
||||
callbacks.event_mode = onMode;
|
||||
callbacks.event_umode = onUserMode;
|
||||
callbacks.event_topic = onTopic;
|
||||
callbacks.event_kick = onKick;
|
||||
callbacks.event_channel = onChannelPrvmsg;
|
||||
callbacks.event_privmsg = onPrivmsg;
|
||||
callbacks.event_notice = onNotice;
|
||||
callbacks.event_invite = onInvite;
|
||||
callbacks.event_ctcp_req = onCtcpRequest;
|
||||
callbacks.event_ctcp_rep = onCtcpReply;
|
||||
callbacks.event_ctcp_action = onCtcpAction;
|
||||
callbacks.event_unknown = onUnknownEvent;
|
||||
callbacks.event_numeric = onNumericEvent;
|
||||
callbacks.event_dcc_chat_req = NULL;
|
||||
callbacks.event_dcc_send_req = NULL;
|
||||
|
||||
session = irc_create_session(&callbacks);
|
||||
|
||||
if (!session) {
|
||||
NSLog(@"Could not create irc_session.");
|
||||
return nil;
|
||||
}
|
||||
|
||||
irc_set_ctx(session, self);
|
||||
|
||||
unsigned int high, low;
|
||||
irc_get_version (&high, &low);
|
||||
|
||||
[self setVersion:[NSString stringWithFormat:@"IRCClient Framework v%s (Nathan Ollerenshaw) - libirc v%d.%d (Georgy Yunaev)", IRCCLIENTVERSION, high, low]];
|
||||
|
||||
channels = [[[NSMutableDictionary alloc] init] retain];
|
||||
encoding = NSASCIIStringEncoding;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-(void)dealloc
|
||||
{
|
||||
if (irc_is_connected(session))
|
||||
NSLog(@"Warning: IRC Session is not disconnected on dealloc");
|
||||
|
||||
irc_destroy_session(session);
|
||||
|
||||
[channels release];
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (int)connect;
|
||||
{
|
||||
unsigned short sPort = [port intValue];
|
||||
|
||||
return irc_connect(session, [server cStringUsingEncoding:encoding], sPort, [password length] > 0 ? [password cStringUsingEncoding:encoding] : NULL , [nickname cStringUsingEncoding:encoding], [username cStringUsingEncoding:encoding], [realname cStringUsingEncoding:encoding]);
|
||||
}
|
||||
|
||||
- (void)disconnect
|
||||
{
|
||||
irc_disconnect(session);
|
||||
}
|
||||
|
||||
- (bool)isConnected
|
||||
{
|
||||
return irc_is_connected(session);
|
||||
}
|
||||
|
||||
- (void)startThread
|
||||
{
|
||||
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
irc_run(session);
|
||||
|
||||
[pool drain];
|
||||
}
|
||||
|
||||
- (void)run
|
||||
{
|
||||
if (thread) {
|
||||
NSLog(@"Thread already running!");
|
||||
return;
|
||||
}
|
||||
|
||||
thread = [[NSThread alloc] initWithTarget:self selector:@selector(startThread) object:nil];
|
||||
[thread retain];
|
||||
[thread start];
|
||||
}
|
||||
|
||||
- (int)sendRawWithFormat:(NSString *)format, ...
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, format);
|
||||
NSString *line = [[NSString alloc] initWithFormat:format arguments:ap];
|
||||
va_end(ap);
|
||||
|
||||
return irc_send_raw(session, [line cStringUsingEncoding:encoding]);
|
||||
}
|
||||
|
||||
- (int)quit:(NSString *)reason
|
||||
{
|
||||
return irc_cmd_quit(session, [reason cStringUsingEncoding:encoding]);
|
||||
}
|
||||
|
||||
- (int)join:(NSString *)channel key:(NSString *)key
|
||||
{
|
||||
NSLog(@"Joining %@", channel);
|
||||
|
||||
if (!key || ![key length] > 0)
|
||||
return irc_cmd_join(session, [channel cStringUsingEncoding:encoding], NULL);
|
||||
|
||||
return irc_cmd_join(session, [channel cStringUsingEncoding:encoding], [key cStringUsingEncoding:encoding]);
|
||||
}
|
||||
|
||||
- (int)list:(NSString *)channel
|
||||
{
|
||||
return irc_cmd_list(session, [channel cStringUsingEncoding:encoding]);
|
||||
}
|
||||
|
||||
- (int)userMode:(NSString *)mode
|
||||
{
|
||||
return irc_cmd_user_mode(session, [mode cStringUsingEncoding:encoding]);
|
||||
}
|
||||
|
||||
- (int)nick:(NSString *)newnick
|
||||
{
|
||||
return irc_cmd_nick(session, [newnick cStringUsingEncoding:encoding]);
|
||||
}
|
||||
|
||||
- (int)whois:(NSString *)nick
|
||||
{
|
||||
return irc_cmd_whois(session, [nick cStringUsingEncoding:encoding]);
|
||||
}
|
||||
|
||||
- (int)message:(NSString *)message to:(NSString *)target
|
||||
{
|
||||
return irc_cmd_msg(session, [target cStringUsingEncoding:encoding], [message cStringUsingEncoding:encoding]);
|
||||
}
|
||||
|
||||
- (int)action:(NSString *)action to:(NSString *)target
|
||||
{
|
||||
return irc_cmd_me(session, [target cStringUsingEncoding:encoding], [action cStringUsingEncoding:encoding]);
|
||||
}
|
||||
|
||||
- (int)notice:(NSString *)notice to:(NSString *)target
|
||||
{
|
||||
return irc_cmd_notice(session, [target cStringUsingEncoding:encoding], [notice cStringUsingEncoding:encoding]);
|
||||
}
|
||||
|
||||
- (int)ctcpRequest:(NSString *)request target:(NSString *)target
|
||||
{
|
||||
return irc_cmd_ctcp_request(session, [target cStringUsingEncoding:encoding], [request cStringUsingEncoding:encoding]);
|
||||
}
|
||||
|
||||
- (int)ctcpReply:(NSString *)reply target:(NSString *)target
|
||||
{
|
||||
return irc_cmd_ctcp_reply(session, [target cStringUsingEncoding:encoding], [reply cStringUsingEncoding:encoding]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@end
|
||||
|
||||
NSString *
|
||||
getNickFromNickUserHost(NSString *nuh)
|
||||
{
|
||||
NSArray *nuhArray = [nuh componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"!@"]];
|
||||
|
||||
if ([nuhArray count] == 3)
|
||||
return [NSString stringWithString:[nuhArray objectAtIndex:0]];
|
||||
else
|
||||
return [NSString stringWithString:nuh];
|
||||
}
|
||||
|
||||
NSString *
|
||||
getUserFromNickUserHost(NSString *nuh)
|
||||
{
|
||||
NSArray *nuhArray = [nuh componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"!@"]];
|
||||
|
||||
if ([nuhArray count] == 3)
|
||||
return [NSString stringWithString:[nuhArray objectAtIndex:1]];
|
||||
else
|
||||
return nil;
|
||||
}
|
||||
|
||||
NSString *
|
||||
getHostFromNickUserHost(NSString *nuh)
|
||||
{
|
||||
NSArray *nuhArray = [nuh componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"!@"]];
|
||||
|
||||
if ([nuhArray count] == 3)
|
||||
return [NSString stringWithString:[nuhArray objectAtIndex:2]];
|
||||
else
|
||||
return nil;
|
||||
}
|
||||
|
||||
/*!
|
||||
* The "on_connect" event is triggered when the client successfully
|
||||
* connects to the server, and could send commands to the server.
|
||||
* No extra params supplied; \a params is 0.
|
||||
*/
|
||||
static void onConnect(irc_session_t *session, const char *event, const char *origin, const char **params, unsigned int count)
|
||||
{
|
||||
IRCClientSession *client = (IRCClientSession *) irc_get_ctx(session);
|
||||
|
||||
if ([[client delegate] respondsToSelector:@selector(onConnect)])
|
||||
[[[client delegate] dd_invokeOnMainThread] onConnect];
|
||||
}
|
||||
|
||||
/*!
|
||||
* The "nick" event is triggered when the client receives a NICK message,
|
||||
* meaning that someone (including you) on a channel with the client has
|
||||
* changed their nickname.
|
||||
*
|
||||
* \param origin the person, who changes the nick. Note that it can be you!
|
||||
* \param params[0] mandatory, contains the new nick.
|
||||
*/
|
||||
static void onNick(irc_session_t *session, const char *event, const char *origin, const char **params, unsigned int count)
|
||||
{
|
||||
IRCClientSession *client = (IRCClientSession *) irc_get_ctx(session);
|
||||
|
||||
NSString *nick = [NSString stringWithCString:params[0] encoding:NSASCIIStringEncoding];
|
||||
NSString *oldNick = [NSString stringWithCString:origin encoding:NSASCIIStringEncoding];
|
||||
|
||||
if ([[client nickname] compare:oldNick] == NSOrderedSame) {
|
||||
[client setNickname:nick];
|
||||
}
|
||||
|
||||
if ([[client delegate] respondsToSelector:@selector(onNick:oldNick:)])
|
||||
[[[client delegate] dd_invokeOnMainThread] onNick:nick oldNick:oldNick];
|
||||
}
|
||||
|
||||
/*!
|
||||
* The "quit" event is triggered upon receipt of a QUIT message, which
|
||||
* means that someone on a channel with the client has disconnected.
|
||||
*
|
||||
* \param origin the person, who is disconnected
|
||||
* \param params[0] optional, contains the reason message (user-specified).
|
||||
*/
|
||||
static void onQuit(irc_session_t *session, const char *event, const char *origin, const char **params, unsigned int count)
|
||||
{
|
||||
IRCClientSession *client = (IRCClientSession *) irc_get_ctx(session);
|
||||
|
||||
NSString *nick = [NSString stringWithCString:origin encoding:NSASCIIStringEncoding];
|
||||
NSString *reason = [NSString stringWithCString:params[0] encoding:[client encoding]];
|
||||
|
||||
if ([[client delegate] respondsToSelector:@selector(onQuit:reason:)])
|
||||
[[[client delegate] dd_invokeOnMainThread] onQuit:nick reason:reason];
|
||||
}
|
||||
|
||||
/*!
|
||||
* The "join" event is triggered upon receipt of a JOIN message, which
|
||||
* means that someone has entered a channel that the client is on.
|
||||
*
|
||||
* \param origin the person, who joins the channel. By comparing it with
|
||||
* your own nickname, you can check whether your JOIN
|
||||
* command succeed.
|
||||
* \param params[0] mandatory, contains the channel name.
|
||||
*/
|
||||
static void onJoinChannel(irc_session_t *session, const char *event, const char *origin, const char **params, unsigned int count)
|
||||
{
|
||||
IRCClientSession *client = (IRCClientSession *) irc_get_ctx(session);
|
||||
NSString *nick = [NSString stringWithCString:origin encoding:NSASCIIStringEncoding];
|
||||
NSString *channel = [NSString stringWithCString:params[0] encoding:NSASCIIStringEncoding];
|
||||
|
||||
NSString *nickOnly = getNickFromNickUserHost(nick);
|
||||
|
||||
if ([[client nickname] compare:nickOnly] == NSOrderedSame) {
|
||||
// We just joined a channel; allocate an IRCClientChannel object and send it
|
||||
// to the main thread.
|
||||
|
||||
IRCClientChannel *newChannel = [[IRCClientChannel alloc] initWithName:channel];
|
||||
[[client channels] setObject:newChannel forKey:channel];
|
||||
|
||||
if ([[client delegate] respondsToSelector:@selector(onJoinChannel:)])
|
||||
[[[client delegate] dd_invokeOnMainThread] onJoinChannel:newChannel];
|
||||
} else {
|
||||
// Someone joined a channel we're on.
|
||||
|
||||
IRCClientChannel *currentChannel = [[client channels] objectForKey:channel];
|
||||
[currentChannel onJoin:nick];
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* The "part" event is triggered upon receipt of a PART message, which
|
||||
* means that someone has left a channel that the client is on.
|
||||
*
|
||||
* \param origin the person, who leaves the channel. By comparing it with
|
||||
* your own nickname, you can check whether your PART
|
||||
* command succeed.
|
||||
* \param params[0] mandatory, contains the channel name.
|
||||
* \param params[1] optional, contains the reason message (user-defined).
|
||||
*/
|
||||
static void onPartChannel(irc_session_t *session, const char *event, const char *origin, const char **params, unsigned int count)
|
||||
{
|
||||
IRCClientSession *client = (IRCClientSession *) irc_get_ctx(session);
|
||||
|
||||
NSString *nick = [NSString stringWithCString:origin encoding:NSASCIIStringEncoding];
|
||||
NSString *channel = [NSString stringWithCString:params[0] encoding:NSASCIIStringEncoding];
|
||||
NSData *reason = nil;
|
||||
IRCClientChannel *currentChannel = nil;
|
||||
|
||||
if (count > 1)
|
||||
reason = [NSData dataWithBytes:params[1] length:strlen(params[1])];
|
||||
|
||||
if ([[client nickname] compare:nick] == NSOrderedSame) {
|
||||
// We just left a channel; remove it from the channels dict.
|
||||
|
||||
currentChannel = [[client channels] objectForKey:channel];
|
||||
[[client channels] removeObjectForKey:channel];
|
||||
} else {
|
||||
// Someone left a channel we're on.
|
||||
|
||||
currentChannel = [[client channels] objectForKey:channel];
|
||||
}
|
||||
|
||||
[currentChannel onPart:nick reason:[[NSString alloc] initWithData:reason encoding:[currentChannel encoding]]];
|
||||
}
|
||||
|
||||
/*!
|
||||
* The "mode" event is triggered upon receipt of a channel MODE message,
|
||||
* which means that someone on a channel with the client has changed the
|
||||
* channel's parameters.
|
||||
*
|
||||
* \param origin the person, who changed the channel mode.
|
||||
* \param params[0] mandatory, contains the channel name.
|
||||
* \param params[1] mandatory, contains the changed channel mode, like
|
||||
* '+t', '-i' and so on.
|
||||
* \param params[2] optional, contains the mode argument (for example, a
|
||||
* key for +k mode, or user who got the channel operator status for
|
||||
* +o mode)
|
||||
*/
|
||||
static void onMode(irc_session_t *session, const char *event, const char *origin, const char **params, unsigned int count)
|
||||
{
|
||||
IRCClientSession *client = (IRCClientSession *) irc_get_ctx(session);
|
||||
NSString *nick = [NSString stringWithCString:origin encoding:NSASCIIStringEncoding];
|
||||
NSString *channel = [NSString stringWithCString:params[0] encoding:NSASCIIStringEncoding];
|
||||
NSString *mode = [NSString stringWithCString:params[1] encoding:NSASCIIStringEncoding];
|
||||
NSString *modeParams = nil;
|
||||
|
||||
if (count > 2)
|
||||
modeParams = [NSString stringWithCString:params[2] encoding:NSASCIIStringEncoding];
|
||||
|
||||
IRCClientChannel *currentChannel = [[client channels] objectForKey:channel];
|
||||
|
||||
[currentChannel onMode:mode params:modeParams nick:nick];
|
||||
}
|
||||
|
||||
/*!
|
||||
* The "umode" event is triggered upon receipt of a user MODE message,
|
||||
* which means that your user mode has been changed.
|
||||
*
|
||||
* \param origin the person, who changed the channel mode.
|
||||
* \param params[0] mandatory, contains the user changed mode, like
|
||||
* '+t', '-i' and so on.
|
||||
*/
|
||||
static void onUserMode(irc_session_t *session, const char *event, const char *origin, const char **params, unsigned int count)
|
||||
{
|
||||
IRCClientSession *client = (IRCClientSession *) irc_get_ctx(session);
|
||||
NSString *mode = [NSString stringWithCString:params[0] encoding:NSASCIIStringEncoding];
|
||||
|
||||
if ([[client delegate] respondsToSelector:@selector(onMode:)])
|
||||
[[[client delegate] dd_invokeOnMainThread] onMode:mode];
|
||||
}
|
||||
|
||||
/*!
|
||||
* The "topic" event is triggered upon receipt of a TOPIC message, which
|
||||
* means that someone on a channel with the client has changed the
|
||||
* channel's topic.
|
||||
*
|
||||
* \param origin the person, who changes the channel topic.
|
||||
* \param params[0] mandatory, contains the channel name.
|
||||
* \param params[1] optional, contains the new topic.
|
||||
*/
|
||||
static void onTopic(irc_session_t *session, const char *event, const char *origin, const char **params, unsigned int count)
|
||||
{
|
||||
IRCClientSession *client = (IRCClientSession *) irc_get_ctx(session);
|
||||
NSString *nick = [NSString stringWithCString:origin encoding:NSASCIIStringEncoding];
|
||||
NSString *channel = [NSString stringWithCString:params[0] encoding:NSASCIIStringEncoding];
|
||||
NSData *topic = nil;
|
||||
|
||||
if (count > 1)
|
||||
topic = [NSData dataWithBytes:params[1] length:strlen(params[1])];
|
||||
|
||||
IRCClientChannel *currentChannel = [[client channels] objectForKey:channel];
|
||||
|
||||
[currentChannel onTopic:[[NSString alloc] initWithData:topic encoding:[currentChannel encoding]] nick:nick];
|
||||
}
|
||||
|
||||
/*!
|
||||
* The "kick" event is triggered upon receipt of a KICK message, which
|
||||
* means that someone on a channel with the client (or possibly the
|
||||
* client itself!) has been forcibly ejected.
|
||||
*
|
||||
* \param origin the person, who kicked the poor.
|
||||
* \param params[0] mandatory, contains the channel name.
|
||||
* \param params[1] optional, contains the nick of kicked person.
|
||||
* \param params[2] optional, contains the kick text
|
||||
*/
|
||||
static void onKick(irc_session_t *session, const char *event, const char *origin, const char **params, unsigned int count)
|
||||
{
|
||||
IRCClientSession *client = (IRCClientSession *) irc_get_ctx(session);
|
||||
NSString *byNick = [NSString stringWithCString:origin encoding:NSASCIIStringEncoding];
|
||||
NSString *channel = [NSString stringWithCString:params[0] encoding:NSASCIIStringEncoding];
|
||||
NSString *nick = nil;
|
||||
NSData *reason = nil;
|
||||
|
||||
if (count > 1)
|
||||
nick = [NSString stringWithCString:params[1] encoding:NSASCIIStringEncoding];
|
||||
|
||||
if (count > 2)
|
||||
reason = [NSData dataWithBytes:params[2] length:strlen(params[2])];
|
||||
|
||||
if (nick == nil) {
|
||||
// we got kicked
|
||||
IRCClientChannel *currentChannel = [[client channels] objectForKey:channel];
|
||||
[[client channels] removeObjectForKey:channel];
|
||||
|
||||
[currentChannel onKick:[client nickname] reason:[[NSString alloc] initWithData:reason encoding:[currentChannel encoding]] byNick:byNick];
|
||||
} else {
|
||||
// someone else got booted
|
||||
IRCClientChannel *currentChannel = [[client channels] objectForKey:channel];
|
||||
|
||||
[currentChannel onKick:nick reason:[[NSString alloc] initWithData:reason encoding:[currentChannel encoding]] byNick:byNick];
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* The "channel" event is triggered upon receipt of a PRIVMSG message
|
||||
* to an entire channel, which means that someone on a channel with
|
||||
* the client has said something aloud. Your own messages don't trigger
|
||||
* PRIVMSG event.
|
||||
*
|
||||
* \param origin the person, who generates the message.
|
||||
* \param params[0] mandatory, contains the channel name.
|
||||
* \param params[1] optional, contains the message text
|
||||
*/
|
||||
static void onChannelPrvmsg(irc_session_t *session, const char *event, const char *origin, const char **params, unsigned int count)
|
||||
{
|
||||
IRCClientSession *client = (IRCClientSession *) irc_get_ctx(session);
|
||||
NSString *nick = [NSString stringWithCString:origin encoding:NSASCIIStringEncoding];
|
||||
NSString *channel = [NSString stringWithCString:params[0] encoding:NSASCIIStringEncoding];
|
||||
NSData *message = nil;
|
||||
|
||||
if (count > 1) {
|
||||
message = [NSData dataWithBytes:params[1] length:strlen(params[1])];
|
||||
|
||||
IRCClientChannel *currentChannel = [[client channels] objectForKey:channel];
|
||||
|
||||
[currentChannel onPrivmsg:[[NSString alloc] initWithData:message encoding:[currentChannel encoding]] nick:nick];
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* The "privmsg" event is triggered upon receipt of a PRIVMSG message
|
||||
* which is addressed to one or more clients, which means that someone
|
||||
* is sending the client a private message.
|
||||
*
|
||||
* \param origin the person, who generates the message.
|
||||
* \param params[0] mandatory, contains your nick.
|
||||
* \param params[1] optional, contains the message text
|
||||
*/
|
||||
static void onPrivmsg(irc_session_t *session, const char *event, const char *origin, const char **params, unsigned int count)
|
||||
{
|
||||
IRCClientSession *client = (IRCClientSession *) irc_get_ctx(session);
|
||||
NSString *nick = [NSString stringWithCString:origin encoding:NSASCIIStringEncoding];
|
||||
NSData *message = nil;
|
||||
|
||||
if (count > 1) {
|
||||
message = [NSData dataWithBytes:params[1] length:strlen(params[1])];
|
||||
|
||||
if ([[client delegate] respondsToSelector:@selector(onPrivmsg:nick:)])
|
||||
[[[client delegate] dd_invokeOnMainThread] onPrivmsg:message nick:nick];
|
||||
}
|
||||
|
||||
// we eat privmsgs with no message
|
||||
}
|
||||
|
||||
/*!
|
||||
* The "notice" event is triggered upon receipt of a NOTICE message
|
||||
* which means that someone has sent the client a public or private
|
||||
* notice. According to RFC 1459, the only difference between NOTICE
|
||||
* and PRIVMSG is that you should NEVER automatically reply to NOTICE
|
||||
* messages. Unfortunately, this rule is frequently violated by IRC
|
||||
* servers itself - for example, NICKSERV messages require reply, and
|
||||
* are NOTICEs.
|
||||
*
|
||||
* \param origin the person, who generates the message.
|
||||
* \param params[0] mandatory, contains the channel name.
|
||||
* \param params[1] optional, contains the message text
|
||||
*/
|
||||
static void onNotice(irc_session_t *session, const char *event, const char *origin, const char **params, unsigned int count)
|
||||
{
|
||||
IRCClientSession *client = (IRCClientSession *) irc_get_ctx(session);
|
||||
NSString *nick = [NSString stringWithCString:origin encoding:NSASCIIStringEncoding];
|
||||
NSString *target = [NSString stringWithCString:params[0] encoding:NSASCIIStringEncoding];
|
||||
NSData *notice = nil;
|
||||
|
||||
IRCClientChannel *currentChannel = [[client channels] objectForKey:target];
|
||||
|
||||
if (count > 1) {
|
||||
notice = [NSData dataWithBytes:params[1] length:strlen(params[1])];
|
||||
|
||||
if (currentChannel != nil) {
|
||||
[currentChannel onNotice:[[NSString alloc] initWithData:notice encoding:[currentChannel encoding]] nick:nick];
|
||||
} else {
|
||||
if ([[client delegate] respondsToSelector:@selector(onNotice:nick:)])
|
||||
[[[client delegate] dd_invokeOnMainThread] onNotice:notice nick:nick];
|
||||
}
|
||||
}
|
||||
|
||||
// we eat notices with no message
|
||||
}
|
||||
|
||||
/*!
|
||||
* The "invite" event is triggered upon receipt of an INVITE message,
|
||||
* which means that someone is permitting the client's entry into a +i
|
||||
* channel.
|
||||
*
|
||||
* \param origin the person, who INVITEs you.
|
||||
* \param params[0] mandatory, contains your nick.
|
||||
* \param params[1] mandatory, contains the channel name you're invited into.
|
||||
*
|
||||
* \sa irc_cmd_invite irc_cmd_chanmode_invite
|
||||
*/
|
||||
static void onInvite(irc_session_t *session, const char *event, const char *origin, const char **params, unsigned int count)
|
||||
{
|
||||
IRCClientSession *client = (IRCClientSession *) irc_get_ctx(session);
|
||||
NSString *nick = [NSString stringWithCString:origin encoding:NSASCIIStringEncoding];
|
||||
NSString *channel = [NSString stringWithCString:params[1] encoding:NSASCIIStringEncoding];
|
||||
|
||||
if ([[client delegate] respondsToSelector:@selector(onInvite:nick:)])
|
||||
[[[client delegate] dd_invokeOnMainThread] onInvite:channel nick:nick];
|
||||
}
|
||||
|
||||
/*!
|
||||
* The "ctcp" event is triggered when the client receives the CTCP
|
||||
* request. By default, the built-in CTCP request handler is used. The
|
||||
* build-in handler automatically replies on most CTCP messages, so you
|
||||
* will rarely need to override it.
|
||||
*
|
||||
* \param origin the person, who generates the message.
|
||||
* \param params[0] mandatory, the complete CTCP message, including its
|
||||
* arguments.
|
||||
*
|
||||
* Mirc generates PING, FINGER, VERSION, TIME and ACTION messages,
|
||||
* check the source code of \c libirc_event_ctcp_internal function to
|
||||
* see how to write your own CTCP request handler. Also you may find
|
||||
* useful this question in FAQ: \ref faq4
|
||||
*/
|
||||
static void onCtcpRequest(irc_session_t *session, const char *event, const char *origin, const char **params, unsigned int count)
|
||||
{
|
||||
IRCClientSession *client = (IRCClientSession *) irc_get_ctx(session);
|
||||
NSString *nick = [NSString stringWithCString:origin encoding:NSASCIIStringEncoding];
|
||||
|
||||
if ( origin )
|
||||
{
|
||||
char nickbuf[128];
|
||||
irc_target_get_nick (origin, nickbuf, sizeof(nickbuf));
|
||||
|
||||
if ( strstr (params[0], "PING") == params[0] ) {
|
||||
irc_cmd_ctcp_reply (session, nickbuf, params[0]);
|
||||
}
|
||||
else if ( !strcmp (params[0], "VERSION") )
|
||||
{
|
||||
irc_cmd_ctcp_reply (session, nickbuf, [[NSString stringWithFormat:@"VERSION %@", [client version]] UTF8String]);
|
||||
}
|
||||
else if ( !strcmp (params[0], "FINGER") )
|
||||
{
|
||||
irc_cmd_ctcp_reply (session, nickbuf, [[NSString stringWithFormat:@"FINGER %@ (%@) Idle 0 seconds", [client username], [client realname]] UTF8String]);
|
||||
}
|
||||
else if ( !strcmp (params[0], "TIME") )
|
||||
{
|
||||
irc_cmd_ctcp_reply(session, nickbuf, [[[NSDate dateWithTimeIntervalSinceNow:0] descriptionWithCalendarFormat:@"TIME %a %b %e %H:%M:%S %Z %Y" timeZone:nil locale:[[NSUserDefaults standardUserDefaults] dictionaryRepresentation]] UTF8String]);
|
||||
} else {
|
||||
if ([[client delegate] respondsToSelector:@selector(onCtcpRequest:type:nick:)]) {
|
||||
NSString *requestString = [[NSString alloc] initWithData:[NSData dataWithBytes:params[0] length:strlen(params[0])] encoding:[client encoding]];
|
||||
|
||||
NSRange firstSpace = [requestString rangeOfString:@" "];
|
||||
|
||||
NSString *type = [requestString substringToIndex:firstSpace.location];
|
||||
NSString *request = [requestString substringFromIndex:(firstSpace.location + 1)];
|
||||
|
||||
[[[client delegate] dd_invokeOnMainThread] onCtcpRequest:request type:type nick:nick];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* The "ctcp" event is triggered when the client receives the CTCP reply.
|
||||
*
|
||||
* \param origin the person, who generates the message.
|
||||
* \param params[0] mandatory, the CTCP message itself with its arguments.
|
||||
*/
|
||||
static void onCtcpReply(irc_session_t *session, const char *event, const char *origin, const char **params, unsigned int count)
|
||||
{
|
||||
IRCClientSession *client = (IRCClientSession *) irc_get_ctx(session);
|
||||
|
||||
NSString *nick = [NSString stringWithCString:origin encoding:NSASCIIStringEncoding];
|
||||
NSData *reply = [NSData dataWithBytes:params[0] length:strlen(params[0])];
|
||||
|
||||
if ([[client delegate] respondsToSelector:@selector(onCtcpReply:nick:)])
|
||||
[[[client delegate] dd_invokeOnMainThread] onCtcpReply:reply nick:nick];
|
||||
}
|
||||
|
||||
/*!
|
||||
* The "action" event is triggered when the client receives the CTCP
|
||||
* ACTION message. These messages usually looks like:\n
|
||||
* \code
|
||||
* [23:32:55] * Tim gonna sleep.
|
||||
* \endcode
|
||||
*
|
||||
* \param origin the person, who generates the message.
|
||||
* \param params[0] mandatory, the target of the message.
|
||||
* \param params[1] mandatory, the ACTION message.
|
||||
*/
|
||||
static void onCtcpAction(irc_session_t *session, const char *event, const char *origin, const char **params, unsigned int count)
|
||||
{
|
||||
IRCClientSession *client = (IRCClientSession *) irc_get_ctx(session);
|
||||
|
||||
NSString *nick = [NSString stringWithCString:origin encoding:NSASCIIStringEncoding];
|
||||
NSString *target = [NSString stringWithCString:params[0] encoding:NSASCIIStringEncoding];
|
||||
NSData *action = [NSData dataWithBytes:params[1] length:strlen(params[1])];
|
||||
|
||||
IRCClientChannel *currentChannel = [[client channels] objectForKey:target];
|
||||
|
||||
if (currentChannel) {
|
||||
// An action on a channel we're on
|
||||
|
||||
[currentChannel onAction:[[NSString alloc] initWithData:action encoding:[currentChannel encoding]] nick:nick];
|
||||
} else {
|
||||
// An action in a private message
|
||||
|
||||
if ([[client delegate] respondsToSelector:@selector(onAction:nick:)])
|
||||
[[[client delegate] dd_invokeOnMainThread] onAction:action nick:nick];
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* The "unknown" event is triggered upon receipt of any number of
|
||||
* unclassifiable miscellaneous messages, which aren't handled by the
|
||||
* library.
|
||||
*/
|
||||
static void onUnknownEvent(irc_session_t *session, const char *event, const char *origin, const char **params, unsigned int count)
|
||||
{
|
||||
IRCClientSession *client = (IRCClientSession *) irc_get_ctx(session);
|
||||
NSString *eventString = [NSString stringWithCString:event encoding:NSASCIIStringEncoding];
|
||||
NSString *sender = nil;
|
||||
|
||||
if (origin != NULL)
|
||||
sender = [NSString stringWithCString:origin encoding:NSASCIIStringEncoding];
|
||||
|
||||
NSMutableArray *paramsArray = [[NSMutableArray alloc] init];
|
||||
|
||||
for (unsigned int i = 0; i < count; i++)
|
||||
[paramsArray addObject:[[NSString alloc] initWithData:[NSData dataWithBytes:params[i] length:strlen(params[i])] encoding:[client encoding]]];
|
||||
|
||||
if ([[client delegate] respondsToSelector:@selector(onUnknownEvent:origin:params:)])
|
||||
[[[client delegate] dd_invokeOnMainThread] onUnknownEvent:eventString origin:sender params:paramsArray];
|
||||
}
|
||||
|
||||
/*!
|
||||
* The "numeric" event is triggered upon receipt of any numeric response
|
||||
* from the server. There is a lot of such responses, see the full list
|
||||
* here: \ref rfcnumbers.
|
||||
*
|
||||
* See the params in ::irc_eventcode_callback_t specification.
|
||||
*/
|
||||
static void onNumericEvent(irc_session_t * session, unsigned int event, const char * origin, const char ** params, unsigned int count)
|
||||
{
|
||||
IRCClientSession *client = (IRCClientSession *) irc_get_ctx(session);
|
||||
NSUInteger eventNumber = event;
|
||||
NSString *originString = [NSString stringWithCString:origin encoding:NSASCIIStringEncoding];
|
||||
|
||||
NSMutableArray *paramsArray = [[NSMutableArray alloc] init];
|
||||
|
||||
for (unsigned int i = 0; i < count; i++)
|
||||
[paramsArray addObject:[[NSString alloc] initWithData:[NSData dataWithBytes:params[i] length:strlen(params[i])] encoding:[client encoding]]];
|
||||
|
||||
if ([[client delegate] respondsToSelector:@selector(onNumericEvent:origin:params:)])
|
||||
[[[client delegate] dd_invokeOnMainThread] onNumericEvent:eventNumber origin:originString params:paramsArray];
|
||||
}
|
152
external/libircclient/cocoa/Classes/IRCClientSessionDelegate.h
vendored
Normal file
152
external/libircclient/cocoa/Classes/IRCClientSessionDelegate.h
vendored
Normal file
@@ -0,0 +1,152 @@
|
||||
/*
|
||||
* Copyright (C) 2009 Nathan Ollerenshaw chrome@stupendous.net
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*/
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#include <IRCClient/libircclient.h>
|
||||
|
||||
/**
|
||||
* @file IRCClientChannelDelegate.h
|
||||
* @author Nathan Ollerenshaw
|
||||
* @version 1.0
|
||||
* @date 01.2009
|
||||
* @brief Receives delegate messages from an IRCClientSession.
|
||||
* @protocol IRCClientSessionDelegate
|
||||
*/
|
||||
|
||||
@class IRCClientChannel;
|
||||
|
||||
/** @brief Receives delegate messages from an IRCClientSession.
|
||||
*
|
||||
* Each IRCClientSession object needs a single delegate. Methods are called
|
||||
* for each event that occurs on an IRC server that the client is connected to.
|
||||
*
|
||||
* Note that for any given parameter, it may be optional, in which case a nil
|
||||
* object may be supplied instead of the given parameter.
|
||||
*/
|
||||
|
||||
@interface NSObject (IRCClientSessionDelegate)
|
||||
|
||||
/** The client has successfully connected to the IRC server. */
|
||||
|
||||
- (void)onConnect;
|
||||
|
||||
/** An IRC client on a channel that this client is connected to has changed nickname,
|
||||
* or this IRC client has changed nicknames.
|
||||
*
|
||||
* @param nick the new nickname
|
||||
* @param oldNick the old nickname
|
||||
*/
|
||||
|
||||
- (void)onNick:(NSString *)nick oldNick:(NSString *)oldNick;
|
||||
|
||||
/** An IRC client on a channel that this client is connected to has quit IRC.
|
||||
*
|
||||
* @param nick the nickname of the client that quit.
|
||||
* @param reason (optional) the quit message, if any.
|
||||
*/
|
||||
|
||||
- (void)onQuit:(NSString *)nick reason:(NSString *)reason;
|
||||
|
||||
/** The IRC client has joined (connected) successfully to a new channel. This
|
||||
* event creates an IRCClientChannel object, which you are expected to asign a
|
||||
* delegate to, to handle events from the channel.
|
||||
*
|
||||
* For example, on receipt of this message, a graphical IRC client would most
|
||||
* likely open a new window, create an IRCClientChannelDelegate for the window,
|
||||
* set the new IRCClientChannel's delegate to the new delegate, and then hook
|
||||
* it up so that new events sent to the IRCClientChannelDelegate are sent to
|
||||
* the window.
|
||||
*
|
||||
* @param channel the IRCClientChannel object for the newly joined channel.
|
||||
*/
|
||||
|
||||
- (void)onJoinChannel:(IRCClientChannel *)channel;
|
||||
|
||||
/** The client has changed it's user mode.
|
||||
*
|
||||
* @param mode the new mode.
|
||||
*/
|
||||
|
||||
- (void)onMode:(NSString *)mode;
|
||||
|
||||
/** The client has received a private PRIVMSG from another IRC client.
|
||||
*
|
||||
* @param message the text of the message
|
||||
* @param nick the other IRC Client that sent the message.
|
||||
*/
|
||||
|
||||
- (void)onPrivmsg:(NSData *)message nick:(NSString *)nick;
|
||||
|
||||
/** The client has received a private NOTICE from another client.
|
||||
*
|
||||
* @param notice the text of the message
|
||||
* @param nick the nickname of the other IRC client that sent the message.
|
||||
*/
|
||||
|
||||
- (void)onNotice:(NSData *)notice nick:(NSString *)nick;
|
||||
|
||||
/** The IRC client has been invited to a channel.
|
||||
*
|
||||
* @param channel the channel for the invitation.
|
||||
* @param nick the nickname of the user that sent the invitation.
|
||||
*/
|
||||
|
||||
- (void)onInvite:(NSString *)channel nick:(NSString *)nick;
|
||||
|
||||
/** A private CTCP request was sent to the IRC client.
|
||||
*
|
||||
* @param request the CTCP request string (after the type)
|
||||
* @param type the CTCP request type
|
||||
* @param nick the nickname of the user that sent the request.
|
||||
*/
|
||||
|
||||
- (void)onCtcpRequest:(NSString *)request type:(NSString *)type nick:(NSString *)nick;
|
||||
|
||||
/** A private CTCP reply was sent to the IRC client.
|
||||
*
|
||||
* @param reply an NSData containing the raw C string of the reply.
|
||||
* @param nick the nickname of the user that sent the reply.
|
||||
*/
|
||||
|
||||
- (void)onCtcpReply:(NSData *)reply nick:(NSString *)nick;
|
||||
|
||||
/** A private CTCP ACTION was sent to the IRC client.
|
||||
*
|
||||
* CTCP ACTION is not limited to channels; it may also be sent directly to other users.
|
||||
*
|
||||
* @param action the action message text.
|
||||
* @param nick the nickname of the client that sent the action.
|
||||
*/
|
||||
|
||||
- (void)onAction:(NSData *)action nick:(NSString *)nick;
|
||||
|
||||
/** An unhandled event was received from the IRC server.
|
||||
*
|
||||
* @param event the unknown event name
|
||||
* @param origin the sender of the event
|
||||
* @param params an NSArray of NSData objects that are the raw C strings of the event.
|
||||
*/
|
||||
|
||||
- (void)onUnknownEvent:(NSString *)event origin:(NSString *)origin params:(NSArray *)params;
|
||||
|
||||
/** An unhandled numeric was received from the IRC server
|
||||
*
|
||||
* @param event the unknown event number
|
||||
* @param origin the sender of the event
|
||||
* @param params an NSArray of NSData objects that are the raw C strings of the event.
|
||||
*/
|
||||
|
||||
- (void)onNumericEvent:(NSUInteger)event origin:(NSString *)origin params:(NSArray *)params;
|
||||
|
||||
@end
|
35
external/libircclient/cocoa/Classes/NSObject+DDExtensions.h
vendored
Normal file
35
external/libircclient/cocoa/Classes/NSObject+DDExtensions.h
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (c) 2007-2008 Dave Dribin
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person
|
||||
* obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without
|
||||
* restriction, including without limitation the rights to use, copy,
|
||||
* modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
* of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
||||
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
|
||||
@interface NSObject (DDExtensions)
|
||||
|
||||
- (id)dd_invokeOnMainThread;
|
||||
- (id)dd_invokeOnMainThreadAndWaitUntilDone:(BOOL)waitUntilDone;
|
||||
|
||||
@end
|
||||
|
||||
#define ddsynthesize(_X_) @synthesize _X_ = _##_X_
|
43
external/libircclient/cocoa/Classes/NSObject+DDExtensions.m
vendored
Normal file
43
external/libircclient/cocoa/Classes/NSObject+DDExtensions.m
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (c) 2007-2008 Dave Dribin
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person
|
||||
* obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without
|
||||
* restriction, including without limitation the rights to use, copy,
|
||||
* modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
* of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
||||
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#import "NSObject+DDExtensions.h"
|
||||
#import "DDInvocationGrabber.h"
|
||||
|
||||
@implementation NSObject (DDExtensions)
|
||||
|
||||
- (id)dd_invokeOnMainThread;
|
||||
{
|
||||
return [self dd_invokeOnMainThreadAndWaitUntilDone:NO];
|
||||
}
|
||||
|
||||
- (id)dd_invokeOnMainThreadAndWaitUntilDone:(BOOL)waitUntilDone;
|
||||
{
|
||||
DDInvocationGrabber * grabber = [DDInvocationGrabber invocationGrabber];
|
||||
[grabber setForwardInvokesOnMainThread:YES];
|
||||
[grabber setWaitUntilDone:waitUntilDone];
|
||||
return [grabber prepareWithInvocationTarget:self];
|
||||
}
|
||||
|
||||
@end
|
Reference in New Issue
Block a user