Move ServerInfo to separate file
FossilOrigin-Name: 53f10f3320267c06cbe2ba5325fbc8fc3fc652b35a8e2ac0d0fdbcf7e96aa352
This commit is contained in:
parent
a084fb1cab
commit
2c939e6535
4 changed files with 57 additions and 39 deletions
15
src/ServerInfo.h
Normal file
15
src/ServerInfo.h
Normal file
|
@ -0,0 +1,15 @@
|
|||
#import <ObjFW/ObjFW.h>
|
||||
|
||||
#include <enet/enet.h>
|
||||
|
||||
@interface ServerInfo: OFObject <OFComparing>
|
||||
@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
|
37
src/ServerInfo.mm
Normal file
37
src/ServerInfo.mm
Normal file
|
@ -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
|
|
@ -11,6 +11,7 @@ executable('client',
|
|||
'Menu.m',
|
||||
'MenuItem.m',
|
||||
'Projectile.m',
|
||||
'ServerInfo.mm',
|
||||
'Variable.mm',
|
||||
'client.mm',
|
||||
'clientextras.mm',
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
#include "SDL_thread.h"
|
||||
#include "cube.h"
|
||||
|
||||
#import "ServerInfo.h"
|
||||
|
||||
@interface ResolverThread: OFThread
|
||||
{
|
||||
volatile bool _stop;
|
||||
|
@ -167,30 +169,6 @@ resolvercheck(OFString **name, ENetAddress *address)
|
|||
return false;
|
||||
}
|
||||
|
||||
@interface ServerInfo: OFObject <OFComparing>
|
||||
@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<ServerInfo *> *servers;
|
||||
static ENetSocket pingsock = ENET_SOCKET_NULL;
|
||||
static int lastinfo = 0;
|
||||
|
@ -209,24 +187,11 @@ addserver(OFString *servername)
|
|||
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]];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue