Author Topic: CocoaBot  (Read 12724 times)

0 Members and 1 Guest are viewing this topic.

Offline Joe

  • B&
  • x86
  • Hero Member
  • *****
  • Posts: 10319
  • In Soviet Russia, text read you!
    • View Profile
    • Github
CocoaBot
« 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.
I'd personally do as Joe suggests

You might be right about that, Joe.


Offline rabbit

  • x86
  • Hero Member
  • *****
  • Posts: 8092
  • I speak for the entire clan (except Joe)
    • View Profile
Re: CocoaBot
« Reply #1 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.

Offline warz

  • Hero Member
  • *****
  • Posts: 1134
    • View Profile
    • chyea.org
Re: CocoaBot
« Reply #2 on: December 07, 2009, 09:44:26 am »
all i want to know is... does it mass load
http://www.chyea.org/ - web based markup debugger

Offline Camel

  • Hero Member
  • *****
  • Posts: 1703
    • View Profile
    • BNU Bot
Re: CocoaBot
« Reply #3 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.

<Camel> i said what what
<Blaze> in the butt
<Camel> you want to do it in my butt?
<Blaze> in my butt
<Camel> let's do it in the butt
<Blaze> Okay!

Offline Joe

  • B&
  • x86
  • Hero Member
  • *****
  • Posts: 10319
  • In Soviet Russia, text read you!
    • View Profile
    • Github
Re: CocoaBot
« Reply #4 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.
« Last Edit: December 07, 2009, 11:49:11 am by Joe »
I'd personally do as Joe suggests

You might be right about that, Joe.


Offline Joe

  • B&
  • x86
  • Hero Member
  • *****
  • Posts: 10319
  • In Soviet Russia, text read you!
    • View Profile
    • Github
Re: CocoaBot
« Reply #5 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. :)
I'd personally do as Joe suggests

You might be right about that, Joe.


Offline warz

  • Hero Member
  • *****
  • Posts: 1134
    • View Profile
    • chyea.org
Re: CocoaBot
« Reply #6 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.
http://www.chyea.org/ - web based markup debugger

Offline Joe

  • B&
  • x86
  • Hero Member
  • *****
  • Posts: 10319
  • In Soviet Russia, text read you!
    • View Profile
    • Github
Re: CocoaBot
« Reply #7 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.
I'd personally do as Joe suggests

You might be right about that, Joe.


Offline Joe

  • B&
  • x86
  • Hero Member
  • *****
  • Posts: 10319
  • In Soviet Russia, text read you!
    • View Profile
    • Github
Re: CocoaBot
« Reply #8 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];
}
I'd personally do as Joe suggests

You might be right about that, Joe.


Offline Joe

  • B&
  • x86
  • Hero Member
  • *****
  • Posts: 10319
  • In Soviet Russia, text read you!
    • View Profile
    • Github
Re: CocoaBot
« Reply #9 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.
I'd personally do as Joe suggests

You might be right about that, Joe.


Offline rabbit

  • x86
  • Hero Member
  • *****
  • Posts: 8092
  • I speak for the entire clan (except Joe)
    • View Profile
Re: CocoaBot
« Reply #10 on: December 12, 2009, 07:23:05 am »
made it look iTunes-like
I'm sorry for your loss.

Offline Newby

  • x86
  • Hero Member
  • *****
  • Posts: 10877
  • Thrash!
    • View Profile
Re: CocoaBot
« Reply #11 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
- Newby
http://www.x86labs.org

Quote
[17:32:45] * xar sets mode: -oooooooooo algorithm ban chris cipher newby stdio TehUser tnarongi|away vursed warz
[17:32:54] * xar sets mode: +o newby
[17:32:58] <xar> new rule
[17:33:02] <xar> me and newby rule all

I'd bet that you're currently bloated like a water ballon on a hot summer's day.

That analogy doesn't even make sense.  Why would a water balloon be especially bloated on a hot summer's day? For your sake, I hope there wasn't too much logic testing on your LSAT. 

Offline rabbit

  • x86
  • Hero Member
  • *****
  • Posts: 8092
  • I speak for the entire clan (except Joe)
    • View Profile
Re: CocoaBot
« Reply #12 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.

Offline Sidoh

  • x86
  • Hero Member
  • *****
  • Posts: 17634
  • MHNATY ~~~~~
    • View Profile
    • sidoh
Re: CocoaBot
« Reply #13 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?

Offline warz

  • Hero Member
  • *****
  • Posts: 1134
    • View Profile
    • chyea.org
Re: CocoaBot
« Reply #14 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.
http://www.chyea.org/ - web based markup debugger