ADDED src/ServerInfo.h Index: src/ServerInfo.h ================================================================== --- /dev/null +++ src/ServerInfo.h @@ -0,0 +1,15 @@ +#import + +#include + +@interface ServerInfo: OFObject +@property (readonly, nonatomic) OFString *name; +@property (copy, nonatomic) OFString *full; +@property (copy, nonatomic) OFString *map; +@property (copy, nonatomic) OFString *sdesc; +@property (nonatomic) int mode, numplayers, ping, protocol, minremain; +@property (nonatomic) ENetAddress address; + +- (instancetype)init OF_UNAVAILABLE; +- (instancetype)initWithName:(OFString *)name; +@end ADDED src/ServerInfo.mm Index: src/ServerInfo.mm ================================================================== --- /dev/null +++ src/ServerInfo.mm @@ -0,0 +1,37 @@ +#import "ServerInfo.h" + +#include "cube.h" + +@implementation ServerInfo +- (instancetype)initWithName:(OFString *)name +{ + self = [super init]; + + _name = [name copy]; + _full = @""; + _mode = 0; + _numplayers = 0; + _ping = 9999; + _protocol = 0; + _minremain = 0; + _map = @""; + _sdesc = @""; + _address.host = ENET_HOST_ANY; + _address.port = CUBE_SERVINFO_PORT; + + return self; +} + +- (OFComparisonResult)compare:(id)otherObject +{ + if (![otherObject isKindOfClass:ServerInfo.class]) + @throw [OFInvalidArgumentException exception]; + + if (_ping > [otherObject ping]) + return OFOrderedDescending; + if (_ping < [otherObject ping]) + return OFOrderedAscending; + + return [_name compare:[otherObject name]]; +} +@end Index: src/meson.build ================================================================== --- src/meson.build +++ src/meson.build @@ -9,10 +9,11 @@ 'MD2.mm', 'MapModelInfo.m', 'Menu.m', 'MenuItem.m', 'Projectile.m', + 'ServerInfo.mm', 'Variable.mm', 'client.mm', 'clientextras.mm', 'clientgame.mm', 'clients2c.mm', Index: src/serverbrowser.mm ================================================================== --- src/serverbrowser.mm +++ src/serverbrowser.mm @@ -1,10 +1,12 @@ // serverbrowser.cpp: eihrul's concurrent resolver, and server browser window // management #include "SDL_thread.h" #include "cube.h" + +#import "ServerInfo.h" @interface ResolverThread: OFThread { volatile bool _stop; } @@ -165,34 +167,10 @@ } return false; } -@interface ServerInfo: OFObject -@property (nonatomic) OFString *name; -@property (nonatomic) OFString *full; -@property (nonatomic) OFString *map; -@property (nonatomic) OFString *sdesc; -@property (nonatomic) int mode, numplayers, ping, protocol, minremain; -@property (nonatomic) ENetAddress address; -@end - -@implementation ServerInfo -- (OFComparisonResult)compare:(id)otherObject -{ - if (![otherObject isKindOfClass:ServerInfo.class]) - @throw [OFInvalidArgumentException exception]; - - if (_ping > [otherObject ping]) - return OFOrderedDescending; - if (_ping < [otherObject ping]) - return OFOrderedAscending; - - return [_name compare:[otherObject name]]; -} -@end - static OFMutableArray *servers; static ENetSocket pingsock = ENET_SOCKET_NULL; static int lastinfo = 0; OFString * @@ -207,28 +185,15 @@ @autoreleasepool { for (ServerInfo *si in servers) if ([si.name isEqual:servername]) return; - ServerInfo *si = [[ServerInfo alloc] init]; - si.name = servername; - si.full = @""; - si.mode = 0; - si.numplayers = 0; - si.ping = 9999; - si.protocol = 0; - si.minremain = 0; - si.map = @""; - si.sdesc = @""; - ENetAddress address = { .host = ENET_HOST_ANY, - .port = CUBE_SERVINFO_PORT }; - si.address = address; - if (servers == nil) servers = [[OFMutableArray alloc] init]; - [servers addObject:si]; + [servers + addObject:[[ServerInfo alloc] initWithName:servername]]; } } void pingservers()