From: Florian Zeitz Date: Thu, 5 Jul 2012 22:06:14 +0000 (+0200) Subject: Initial command support X-Git-Url: https://cgit.babelmonkeys.de/?a=commitdiff_plain;p=mpdbot.git Initial command support --- diff --git a/src/PEPThread.h b/src/PEPThread.h index a752eca..19663ab 100644 --- a/src/PEPThread.h +++ b/src/PEPThread.h @@ -24,6 +24,6 @@ @interface PEPThread: OFThread { -MPDConnection *conn; + MPDConnection *conn; } @end diff --git a/src/mpdbot.m b/src/mpdbot.m index eb92876..8ef781b 100644 --- a/src/mpdbot.m +++ b/src/mpdbot.m @@ -31,6 +31,7 @@ @interface AppDelegate: OFObject { PEPThread *pepper; + MPDConnection *mpdConn; } @end @@ -40,6 +41,12 @@ OF_APPLICATION_DELEGATE(AppDelegate) - (void)applicationDidFinishLaunching { XMPPConnection *conn; + + OFString *mpd_host; + uint16_t mpd_port; + OFString *mpd_port_string; + + OFDictionary *environment = [OFApplication environment]; OFArray *arguments = [OFApplication arguments]; conn = [[XMPPConnection alloc] init]; @@ -56,6 +63,20 @@ OF_APPLICATION_DELEGATE(AppDelegate) conn.password = [arguments objectAtIndex: 2]; conn.resource = @"ObjXMPP"; + mpd_host = [environment objectForKey: @"MPD_HOST"]; + if (mpd_host == nil) + mpd_host = @"localhost"; + + mpd_port_string = [environment objectForKey: @"MPD_PORT"]; + if (mpd_port_string && [mpd_port_string decimalValue] <= UINT16_MAX) + mpd_port = (uint16_t) [mpd_port_string decimalValue]; + else + mpd_port = 6600; + + mpdConn = [[MPDConnection alloc] initWithHost: mpd_host + port: mpd_port]; + [mpdConn connect]; + @try { [conn connect]; [conn handleConnection]; @@ -107,8 +128,7 @@ OF_APPLICATION_DELEGATE(AppDelegate) stringValue] isEqual: @"pubsub"] && [[[identity attributeForName: @"type"] stringValue] isEqual: @"pep"]) { - pepper = [[PEPThread alloc] - initWithObject: conn]; + pepper = [[PEPThread alloc] initWithObject: conn]; [pepper start]; return YES; @@ -131,6 +151,15 @@ OF_APPLICATION_DELEGATE(AppDelegate) } } +- (void)connection: (XMPPConnection*)conn + didReceiveMessage: (XMPPMessage*)mesg +{ + if ([mesg.body isEqual: @"pause"]) { + [mpdConn send: @"pause"]; + [mpdConn response]; + } +} + - (void)connectionWasClosed: (XMPPConnection*)conn { [of_stdout writeLine: @"Connection was closed!"];