Clan x86

Technical (Development, Security, etc.) => General Programming => New Project Announcements => Topic started by: Joe on December 06, 2009, 09:56:31 pm

Title: CocoaBot
Post by: Joe on December 06, 2009, 09:56:31 pm
Four reasons:
- I don't think anyone's written a bot in Objective-C yet.
- It tastes better than Java.
- Because I can.
- I feel like learning Objective-C and the Cocoa framework, and in my experience, a Battle.net bot is a hell of a crash-course.

That said, I'm not very far yet. Cocoa doesn't provide TCP sockets in it's framework, but since Objective-C is a superset of C, of course there's libraries. I'm personally using SmallSockets.

I'm also taking a new approach with this, which so far seems consistent with most Objective-C code, and that is that all functionality of objects is contained in the object. For example, instead of calling each get method on a ChatEvent, the ChatEvent itself is responsible for displaying it's contents to an NSTextView. This is a snippet for testing all Event ID's, as displayed in the screenshot.

Code: [Select]
- (IBAction)sendButtonClicked:(id)sender {

// Create new chat event
ChatEvent* event = [[ChatEvent alloc] init];

[event setUsername: @"TestUser"];
[event setText: [txtSend stringValue]];
for(int i = 0x01; i <= 0x17; i++) {
[event setEventID: i];
[event writeEventToNsTextView:chat];
}

[event release];

// Clear out the textbox
[txtSend setStringValue:@""];
}

My programming teacher recently gave the class an idea for a development technique, and that's to do it once and throw it away, then redo it when you know what you're doing. I think I'll do that with CocoaBot, since it's my first Objective-C project and I'm bound to do stuff totally wrong, and fixing them will take longer than rewriting the entire bot.

And lastly, if you haven't figured it out from the screenshot, it's for Mac. Objective-C can be compiled on Linux, but I don't know how much of Cocoa is open-source and how much is Apple code.
Title: Re: CocoaBot
Post by: rabbit on December 07, 2009, 08:04:34 am
Good luck.  Lead and I will shortly begin work on Legion.  It will make your stupid Mac explode in its sheer awesomeness.
Title: Re: CocoaBot
Post by: warz on December 07, 2009, 09:44:26 am
all i want to know is... does it mass load
Title: Re: CocoaBot
Post by: Camel on December 07, 2009, 11:42:10 am
None of it is open-source. Technically, it's a violation of some IP law (I forget which one) to even implement the API, because you have to sign the ADC contract to get the reference material.
Title: Re: CocoaBot
Post by: Joe on December 07, 2009, 11:46:01 am
I have an online membership to ADC, so I probably "signed" some contract. I know that I have access to a few pieces of prerelease software, but I didn't tell you that, cause it's confidential.

EDIT -
Xcode comes with all new MacBooks on the Applications DVD, and is freely downloadable to ADC members, even online-only. In the Documentation pane of Xcode Preferences, you can download all the documentation for iPhone OS 3.1 Library, Mac OS X 10.6 Core Library, Xcode 3.2 Developer Tools Library, Mac OS X Java, Mac OS X Legacy Library, Mac OS X Leopard Core Library. All the Cocoa documentation I've been referring to has been in the Mac OS X 1.6 Core Library.
Title: Re: CocoaBot
Post by: Joe on December 11, 2009, 09:06:22 pm
I'm really starting to get a grasp on the language now, and so far I've managed to implement a packet builder, based off of Slackchat and JavaOp2. Now I just have to implement a packet reader, hack together some socket work, write a packet thread, and then see what happens. :)
Title: Re: CocoaBot
Post by: warz on December 11, 2009, 10:39:24 pm
This has been done before, I believe. Somebody in #beta used to rant and rave about Obj-C back in the day. I can't remember who, otherwise I'd refer you to them.

You didn't answer me though... will this mass load so that I can hold ops in all the channels that I take over? I'm going to war TGK and DK at the same time. I'll need a bot that can hold its own.
Title: Re: CocoaBot
Post by: Joe on December 11, 2009, 10:49:36 pm
I thought you were kidding. I suppose at some point of maturity in the project, I'll add the option to pass the entire configuration on the command line, proxy included, so you can write a script to massload.

EDIT -
You'd be better off fixing up Slackchat, though.
Title: Re: CocoaBot
Post by: Joe on December 12, 2009, 12:42:29 am
I hacked up toString from iago's Buffer.java to work with tmp's packet buffer.. which I also hacked up, heavily.

2009-12-11 23:39:27.201 CocoaBot[28627:a0f] Buffer contents:
ff 25 44 00 01 00 00 00 02 00 00 00 03 00 00 00    .%D.............
04 00 00 00 05 00 00 00 06 00 00 00 07 00 00 00    ................
08 00 00 00 01 00 00 00 02 00 00 00 03 00 00 00    ................
04 00 00 00 05 00 00 00 06 00 00 00 07 00 00 00    ................
08 00 00 00                                        ....
 Length: 68 (0x44)


Code: [Select]
PacketBuilder* b = [[PacketBuilder alloc] init];
[b setId:SID_PING];
[b addInt:1];
[b addInt:2];
[b addInt:3];
[b addInt:4];
[b addInt:5];
[b addInt:6];
[b addInt:7];
[b addInt:8];
[b addInt:1];
[b addInt:2];
[b addInt:3];
[b addInt:4];
[b addInt:5];
[b addInt:6];
[b addInt:7];
[b addInt:8];
[b dumphex];

Code: [Select]
-(void) dumphex {
// fill in header
packetbuf[0] = 0xff;
packetbuf[1] = packetId;
memcpy(packetbuf + 2, &position, 2);

NSMutableString* returnString = [[NSMutableString alloc] init];
[returnString appendString:@"Buffer contents:\n"];

for (int i = 0; i < position; i++) {
// If we're at the end of a line, write out the plaintext
if ((i != 0) && (i % 16 == 0)) {
[returnString appendString:@"\t"];
for (int j = i - 16; j < i; j++) {
// If the character is 'unsafe', use a period
if (packetbuf[j] < 0x20 || packetbuf[j] > 0x7F) {
[returnString appendString:@"."];
} else {
[returnString appendFormat:@"%c", (char)packetbuf[j]];
}
}
[returnString appendString:@"\n"];
}

[returnString appendFormat:@"%02x ", packetbuf[i] & 0xFF];
}

// Add padding spaces if it's not a multiple of 16
if (position != 0 && position % 16 != 0) {
for (int i = 0; i < (16 - position % 16) * 3; i++) {
[returnString appendString:@" "];
}
}
[returnString appendString:@"\t"];

// Print the last line
int i;
if (position > 0 && (position % 16) == 0) {
i = position - 16;
} else {
i = (position - (position % 16));
}
for (; i < position; i++) {
if (packetbuf[i] < 0x20 || packetbuf[i] > 0x7F) {
[returnString appendString:@"."];
} else {
[returnString appendFormat:@"%c", (char)packetbuf[i]];
}
}

[returnString appendFormat:@"\n Length: %d (0x%02x)\n", position, position];

// NSLog it
NSLog(@"%@", returnString);

// release the NSMutableString
[returnString release];
}
Title: Re: CocoaBot
Post by: Joe on December 12, 2009, 01:16:38 am
I added a channel list (NSTableView), made it look iTunes-like (Textured attribute of NSWindow), and thought up a really simple but intelligent version number system: year.mo.day. This is probably what the user interface will look like for quite a while.
Title: Re: CocoaBot
Post by: rabbit on December 12, 2009, 07:23:05 am
made it look iTunes-like
I'm sorry for your loss.
Title: Re: CocoaBot
Post by: Newby on December 12, 2009, 04:07:05 pm
... does this thing actually establish a connection yet, or are you simply demonstrating your ability to manipulate the rich text box? :P
Title: Re: CocoaBot
Post by: rabbit on December 12, 2009, 05:42:49 pm
It looks like it's just test cases for his RTB.  Also, your channel list is empty, but it say there's 1 person there.  Failure.
Title: Re: CocoaBot
Post by: Sidoh on December 12, 2009, 06:07:58 pm
It looks like it's just test cases for his RTB.  Also, your channel list is empty, but it say there's 1 person there.  Failure.

why are you such an asshole sometimes?
Title: Re: CocoaBot
Post by: warz on December 12, 2009, 07:05:58 pm
dude will this bot be the next damnbot or not? seriously. i need something to help me take over bnet.
Title: Re: CocoaBot
Post by: rabbit on December 12, 2009, 10:27:19 pm
It looks like it's just test cases for his RTB.  Also, your channel list is empty, but it say there's 1 person there.  Failure.

why are you such an asshole sometimes?
How was I an asshole?  The label fails :|
Title: Re: CocoaBot
Post by: Joe on December 12, 2009, 11:41:05 pm
Sorry. Go ahead and photoshop it to make yourself feel better.

But no, it doesn't connect yet.
Title: Re: CocoaBot
Post by: Pan on May 25, 2010, 05:51:05 pm
Hello,

Just a quick reply on this:

- No part of Cocoa itself is open source.

- There is a higher level socket API in Cocoa/CoreFoundation: CFNetwork (http://developer.apple.com/mac/library/documentation/Networking/Conceptual/CFNetwork/Concepts/Concepts.html) You can drop down into C-based sockets, but it's not necessary. There is even a higher level API called NSSocket.

- Yes, people have written bots in Cocoa before. In fact, I released a framework last summer to help in easily constructing them (http://www.sensoryresearch.net/thoughtconduit/dev?id=10). I have several IRC bots roaming the network universe that utilize the framework (e.g. FrequencyBot)

at any rate, just a heads up. cheers,

Pan
Title: Re: CocoaBot
Post by: Joe on May 26, 2010, 10:08:31 am
- I stand corrected.
- Awesome. That looks really useful.
- I stand corrected.