@@ -29,7 +29,13 @@ @implementation MainController
29
29
// Connect to or disconnect IRC connection
30
30
- (IBAction )toggleIrcConnection : (id )sender
31
31
{
32
- if (![ircConnection isConnected ]) {
32
+ if (![ircConnection isConnected ]) {
33
+ // Check if for valid irc login, create a random one if needed
34
+ if ([settings.username length ] == 0 ) {
35
+ NSString *randomUser = [NSString stringWithFormat: @" Serty%i%i%i " ,arc4random () % 10 ,arc4random () % 10 ,arc4random () % 10 ];
36
+ [settings setUsername: randomUser];
37
+ }
38
+
33
39
// Get connection data
34
40
NSArray *connectionArray = [[serverAddress stringValue ] componentsSeparatedByString: @" :" ];
35
41
NSString *ircServer;
@@ -62,6 +68,7 @@ - (IBAction)toggleIrcConnection:(id)sender
62
68
[serverAddress setEnabled: NO ];
63
69
[mainView selectTabViewItemAtIndex: 1 ];
64
70
[ircConnection connectToIRC: [connectionData objectAtIndex: 4 ] port: [[connectionData objectAtIndex: 5 ] intValue ]];
71
+ [self logMessage: @" Establishing connection to server" type: 1 ];
65
72
}
66
73
else {
67
74
[activityIndicator startAnimation: self ];
@@ -84,7 +91,7 @@ - (IBAction)parseCommand:(id)sender
84
91
return ;
85
92
}
86
93
if (![ircConnection isConnected ]) {
87
- [self logMessage: @" IRCBot - No IRC Connection\n › Type help for help\n " type: 1 ];
94
+ [self logMessage: @" No IRC Connection\n › Type help for help\n " type: 1 ];
88
95
[commandField setStringValue: @" " ];
89
96
return ;
90
97
}
@@ -114,7 +121,7 @@ - (IBAction)parseCommand:(id)sender
114
121
}
115
122
}
116
123
else {
117
- [self logMessage: @" IRCBot - Invalid Command\n › Type help for help" type: 4 ];
124
+ [self logMessage: @" Invalid Command\n › Type help for help" type: 4 ];
118
125
}
119
126
120
127
[commandField addPopUpItemWithTitle: commandString];
@@ -165,7 +172,7 @@ - (void)awakeFromNib
165
172
- (void )applicationDidFinishLaunching : (NSNotification *)aNotification
166
173
{
167
174
if (!(ircConnection = [[IRCConnection alloc ] initWithDelegate: self ]))
168
- [self logMessage: @" IRCBot - IRCConnection Allocation Error" type: 1 ];
175
+ [self logMessage: @" IRCConnection Allocation Error" type: 1 ];
169
176
170
177
lua = [[LuaController alloc ] init ];
171
178
[lua setParentClass: self ];
@@ -176,7 +183,7 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
176
183
[commandField setDisplaysMenu: YES ];
177
184
178
185
[self refreshConnectionData ];
179
- [self logMessage: @" Welcome to IRCBot\n › For help type help.\n " type: 4 ];
186
+ [self logMessage: @" Welcome to IRCBot -- For help type help.\n " type: 4 ];
180
187
}
181
188
182
189
// Application should quit but server is still connected
@@ -256,7 +263,7 @@ - (void)pingAlive:(NSString *)server
256
263
- (void )joinRoom : (NSString *)aRoom
257
264
{
258
265
if ([aRoom hasPrefix: @" #" ]) {
259
- [self logMessage: @" IRCBot - Joining Room" type: 1 ];
266
+ [self logMessage: @" Joining Room" type: 1 ];
260
267
NSString * joinMessage = [NSString stringWithFormat: @" JOIN %@ \r\n " , aRoom];
261
268
[ircConnection sendRawString: joinMessage logAs: 2 ];
262
269
[rooms addRoom: aRoom];
@@ -266,7 +273,7 @@ - (void)joinRoom:(NSString *)aRoom
266
273
- (void )partRoom : (NSString *)aRoom
267
274
{
268
275
if ([aRoom hasPrefix: @" #" ]) {
269
- [self logMessage: @" IRCBot - Parting Room" type: 1 ];
276
+ [self logMessage: @" Parting Room" type: 1 ];
270
277
NSString * partMessage = [NSString stringWithFormat: @" PART %@ \r\n " , aRoom];
271
278
[ircConnection sendRawString: partMessage logAs: 2 ];
272
279
[rooms setStatus: @" None" forRoom: aRoom];
@@ -276,7 +283,7 @@ - (void)partRoom:(NSString *)aRoom
276
283
- (void )authUser : (NSString *)aUsername pass : (NSString *)aPassword nick : (NSString *)aNick realName : (NSString *)aName
277
284
{
278
285
// Create auth messages
279
- [self logMessage: @" IRCBot - Authenticating User" type: 1 ];
286
+ [self logMessage: @" Authenticating User" type: 1 ];
280
287
NSString *userMessage, *passMessage, *nickMessage, *nickServMessage;
281
288
282
289
userMessage = [NSString stringWithFormat: @" USER %@ %@ %@ \r\n " , aUsername, @" 0 * :" , aName];
@@ -294,7 +301,7 @@ - (void)authUser:(NSString *)aUsername pass:(NSString *)aPassword nick:(NSString
294
301
[ircConnection sendMessage: nickServMessage To: @" NickServ" logAs: 2 ];
295
302
}
296
303
else {
297
- [self logMessage: @" IRCBot - No password specified!" type: 1 ];
304
+ [self logMessage: @" No password specified!" type: 1 ];
298
305
}
299
306
}
300
307
@@ -305,7 +312,7 @@ - (void)parseServerOutput:(NSString *)input type:(NSString *)type
305
312
NSDateFormatter *formatter = [[[NSDateFormatter alloc ] init ] autorelease ];
306
313
[formatter setDateFormat: @" hh:mm" ];
307
314
NSString *time = [formatter stringFromDate: [NSDate date ]];
308
- [self logMessage: [NSString stringWithFormat: @" %@ %@ %@ " ,time,type,input] type: 0 ];
315
+ [self logMessage: [NSString stringWithFormat: @" %@ [ %@ ] %@ " ,time,type,input] type: 0 ];
309
316
}
310
317
else
311
318
[self logMessage: [NSString stringWithFormat: @" %@ " ,input] type: 0 ];
@@ -356,7 +363,7 @@ - (void)parseServerOutput:(NSString *)input type:(NSString *)type
356
363
NSRange tempRange = [[tempArray objectAtIndex: 1 ] rangeOfString: [connectionData objectAtIndex: 2 ]];
357
364
NSString *room = [[tempArray objectAtIndex: 1 ] substringWithRange: NSMakeRange (0 ,tempRange.location-1 )];
358
365
NSString *reason = [[tempArray objectAtIndex: 1 ] substringFromIndex: tempRange.location+tempRange.length+2 ];
359
- [self logMessage: [NSString stringWithFormat: @" IRCBot - You have just been kicked from:%@ reason:%@ " ,room,reason] type: 1 ];
366
+ [self logMessage: [NSString stringWithFormat: @" You have just been kicked from:%@ reason:%@ " ,room,reason] type: 1 ];
360
367
[rooms setStatus: @" Warning" forRoom: room];
361
368
362
369
if ([rejoinKickedRooms state ]) {
@@ -426,31 +433,31 @@ - (void)logMessage:(NSString *)message type:(int)type
426
433
[secureMessage replaceCharactersInRange: [secureMessage rangeOfString: [connectionData objectAtIndex: 1 ]] withString: @" ******" ];
427
434
428
435
// Get the length of the textview contents
429
- NSRange theEnd= NSMakeRange ([[serverOutput string ] length ],0 );
436
+ NSRange theEnd = NSMakeRange ([[serverOutput string ] length ],0 );
430
437
431
438
NSMutableString *formatedMessage;
432
- NSColor *textColor;
439
+ NSColor *textColor;
433
440
NSFont *textFont = [NSFont fontWithName: @" Menlo" size: 12.0 ];
434
441
435
442
// Setup color of string depending on type
436
443
if (type == 1 ) {
437
- textColor = [NSColor colorWithCalibratedRed: 0.35 green: 0.00 blue: 0.00 alpha: 1.00 ];
444
+ textColor = [NSColor colorWithCalibratedRed: 0.35 green: 0.00 blue: 0.00 alpha: 1.00 ]; // Red -- Notice
438
445
formatedMessage = [NSString stringWithFormat: @" › %@ \n " ,secureMessage];
439
446
}
440
447
else if (type == 2 ) {
441
- textColor = [NSColor colorWithCalibratedRed: 0.00 green: 0.00 blue: 0.35 alpha: 1.00 ];
448
+ textColor = [NSColor colorWithCalibratedRed: 0.00 green: 0.00 blue: 0.35 alpha: 1.00 ]; // Blue -- Status
442
449
formatedMessage = [NSString stringWithFormat: @" › %@ " ,secureMessage];
443
450
}
444
451
else if (type == 3 ) {
445
- textColor = [NSColor colorWithCalibratedRed: 0.15 green: 0.30 blue: 0.00 alpha: 1.00 ];
452
+ textColor = [NSColor colorWithCalibratedRed: 0.15 green: 0.30 blue: 0.00 alpha: 1.00 ]; // Green -- Activity
446
453
formatedMessage = [NSString stringWithFormat: @" › %@ " ,secureMessage];
447
454
}
448
455
else if (type == 4 ) {
449
- textColor = [NSColor colorWithCalibratedRed: 0.24 green: 0.00 blue: 0.30 alpha: 1.00 ];
456
+ textColor = [NSColor colorWithCalibratedRed: 0.24 green: 0.00 blue: 0.30 alpha: 1.00 ]; // Purple -- Info
450
457
formatedMessage = [NSString stringWithFormat: @" › %@ \n " ,secureMessage];
451
458
}
452
459
else {
453
- textColor = [NSColor blackColor ];
460
+ textColor = [NSColor blackColor ]; // Black
454
461
formatedMessage = [NSString stringWithFormat: @" %@ \n " ,secureMessage];
455
462
}
456
463
@@ -496,7 +503,7 @@ - (void)didConnectToHost:(NSString *)host port:(UInt16)port
496
503
497
504
- (void )didDissconect
498
505
{
499
- [self logMessage: @" IRCBot - Socket disconnected\n " type: 1 ];
506
+ [self logMessage: @" Socket disconnected\n " type: 1 ];
500
507
501
508
// Stop activity indicator and disable and enable all relevant controls
502
509
[activityIndicator stopAnimation: self ];
@@ -505,7 +512,6 @@ - (void)didDissconect
505
512
[connectionButton setEnabled: YES ];
506
513
[connectionButton setTitle: @" Connect" ];
507
514
[mainView selectTabViewItemAtIndex: 0 ];
508
- [self clearLog: nil ];
509
515
}
510
516
511
517
0 commit comments