Add protocol handler support

This lets the user click a link in a web browser to very easily join a Quake 3 multiplayer game. As browser-based matchmaking websites become more popular, this makes it a lot more convenient and simple to play Quake 3 with others.

The links have the following URI format: quake3://connect/example.com:27950. The format has been designed to be flexible to allow more types of links in the future and avoiding having to make a breaking change. At the moment, "connect" is the only supported command.
This commit is contained in:
Stefan Sundin authored and GitHub committed 2023-04-19 13:48:26 +01:00
1 parent 23a85089c2
commit 31c6d2f9d5
7 files changed
+217 -8

No files matched your search

+43
View File
@@ -34,6 +34,10 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#import <Carbon/Carbon.h>
#import <Cocoa/Cocoa.h>
#ifdef PROTOCOL_HANDLER
char *protocolCommand = NULL;
#endif
/*
==============
Sys_Dialog
@@ -115,3 +119,42 @@ char *Sys_StripAppBundle( char *dir )
Q_strncpyz(cwd, Sys_Dirname(cwd), sizeof(cwd));
return cwd;
}
#ifdef PROTOCOL_HANDLER
@interface AppDelegate : NSObject <NSApplicationDelegate>
@end
@implementation AppDelegate
- (void)handleAppleEvent:(NSAppleEventDescriptor *)event withReplyEvent: (NSAppleEventDescriptor *)replyEvent
{
NSString *input = [[event paramDescriptorForKeyword:keyDirectObject] stringValue];
protocolCommand = Sys_ParseProtocolUri( input.UTF8String );
}
- (void)applicationDidFinishLaunching:(NSNotification *)notification
{
[NSApp stop:nil];
}
@end
char *Sys_InitProtocolHandler( void )
{
[NSApplication sharedApplication];
AppDelegate *appDelegate = [AppDelegate new];
NSAppleEventManager *sharedAppleEventManager = [NSAppleEventManager new];
[sharedAppleEventManager setEventHandler:appDelegate
andSelector:@selector(handleAppleEvent:withReplyEvent:)
forEventClass:kInternetEventClass
andEventID:kAEGetURL];
[NSApp setDelegate:appDelegate];
[NSApp run];
return protocolCommand;
}
#endif