mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-19 06:28:19 +00:00
a69dc599a9
Fix pointer and pointer array variable naming Huge renaming to match our rules Used regex: (?!(return|delete)\b)\b\w+ (m_|ms_|g_|gs_|s_)[^a]\w+\[ (?!(return|delete)\b)\b\w+ (?!(m_|ms_|g_|gs_|s_))[^a]\w+\[ Further format static variables Format almost all pointer names accordingly Used regex: (?!(return)\b)\b\w+ \*(?!(m_p|p|s_p|m_ap|s_ap|g_p|g_ap|ap|gs_ap|ms_ap|gs_p|ms_p))\w+\b[^:\(p] clang-format Fix CI fail Fix misnamed non pointer as pointer and non array as array Used regex: (?!(return|delete)\b)\b\w+ (m_|ms_|g_|gs_|s_)p\w+\b (?!return\b)\b\w+ (ms_|m_|g_|gs_|s_)a\w+\b[^\[] clang-format Revert to SCREAMING_SNAKE_CASE and reinstate dead code
123 lines
3.2 KiB
Plaintext
123 lines
3.2 KiB
Plaintext
#import <Cocoa/Cocoa.h>
|
|
|
|
@interface ServerView : NSTextView
|
|
{
|
|
NSTask *pTask;
|
|
NSFileHandle *pFile;
|
|
}
|
|
- (void)listenTo: (NSTask *)t;
|
|
@end
|
|
|
|
@implementation ServerView
|
|
- (void)listenTo: (NSTask *)t
|
|
{
|
|
NSPipe *pPipe;
|
|
pTask = t;
|
|
pPipe = [NSPipe pipe];
|
|
[pTask setStandardOutput: pPipe];
|
|
pFile = [pPipe fileHandleForReading];
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(outputNotification:) name: NSFileHandleReadCompletionNotification object: pFile];
|
|
|
|
[pFile readInBackgroundAndNotify];
|
|
}
|
|
|
|
- (void) outputNotification: (NSNotification *) notification
|
|
{
|
|
NSData *pData = [[[notification userInfo] objectForKey: NSFileHandleNotificationDataItem] retain];
|
|
NSString *pString = [[NSString alloc] initWithData: pData encoding: NSASCIIStringEncoding];
|
|
NSAttributedString *pAttrStr = [[NSAttributedString alloc] initWithString: pString];
|
|
|
|
[[self textStorage] appendAttributedString: pAttrStr];
|
|
int length = [[self textStorage] length];
|
|
NSRange range = NSMakeRange(length, 0);
|
|
[self scrollRangeToVisible: range];
|
|
|
|
[pAttrStr release];
|
|
[pString release];
|
|
[pFile readInBackgroundAndNotify];
|
|
}
|
|
|
|
-(void)windowWillClose:(NSNotification *)notification
|
|
{
|
|
[pTask terminate];
|
|
[NSApp terminate:self];
|
|
}
|
|
@end
|
|
|
|
void runServer()
|
|
{
|
|
NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];
|
|
NSApp = [NSApplication sharedApplication];
|
|
NSBundle *pMainBundle = [NSBundle mainBundle];
|
|
NSTask *pTask;
|
|
pTask = [[NSTask alloc] init];
|
|
[pTask setCurrentDirectoryPath: [pMainBundle resourcePath]]; // NOLINT(clang-analyzer-nullability.NullablePassedToNonnull)
|
|
|
|
NSArray *pArguments = [NSArray new];
|
|
|
|
NSAlert *pAlert = [[[NSAlert alloc] init] autorelease];
|
|
[pAlert setMessageText: @"Run DDNet Server"];
|
|
[pAlert addButtonWithTitle: @"Use default config"];
|
|
[pAlert addButtonWithTitle: @"Select config"];
|
|
[pAlert addButtonWithTitle: @"Cancel"];
|
|
switch([pAlert runModal])
|
|
{
|
|
case NSAlertFirstButtonReturn:
|
|
break;
|
|
case NSAlertThirdButtonReturn:
|
|
return;
|
|
case NSAlertSecondButtonReturn:
|
|
// get a server config
|
|
NSOpenPanel *pOpenDlg = [NSOpenPanel openPanel];
|
|
[pOpenDlg setCanChooseFiles:YES];
|
|
if([pOpenDlg runModal] != NSModalResponseOK)
|
|
return;
|
|
NSString *pFileName = [[pOpenDlg URL] path];
|
|
pArguments = [NSArray arrayWithObjects: @"-f", pFileName, nil];
|
|
break;
|
|
}
|
|
|
|
// run server
|
|
NSWindow *pWindow;
|
|
ServerView *pView;
|
|
NSRect GraphicsRect;
|
|
|
|
GraphicsRect = NSMakeRect(100.0, 1000.0, 600.0, 400.0);
|
|
|
|
pWindow = [[NSWindow alloc]
|
|
initWithContentRect: GraphicsRect
|
|
styleMask: NSWindowStyleMaskTitled
|
|
| NSWindowStyleMaskClosable
|
|
| NSWindowStyleMaskMiniaturizable
|
|
backing: NSBackingStoreBuffered
|
|
defer: NO];
|
|
|
|
[pWindow setTitle: @"DDNet Server"];
|
|
|
|
pView = [[[ServerView alloc] initWithFrame: GraphicsRect] autorelease];
|
|
[pView setEditable: NO];
|
|
[pView setRulerVisible: YES];
|
|
|
|
[pWindow setContentView: pView];
|
|
[pWindow setDelegate: (id<NSWindowDelegate>)pView];
|
|
[pWindow makeKeyAndOrderFront: nil];
|
|
|
|
[pView listenTo: pTask];
|
|
[pTask setLaunchPath: [pMainBundle pathForAuxiliaryExecutable: @"DDNet-Server"]];
|
|
[pTask setArguments: pArguments];
|
|
[pTask launch];
|
|
[NSApp run];
|
|
[pTask terminate];
|
|
|
|
[NSApp release];
|
|
[pPool release];
|
|
}
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
runServer();
|
|
|
|
return 0;
|
|
}
|