-
-
Notifications
You must be signed in to change notification settings - Fork 134
/
TPFakeHostsGenerator.m
101 lines (79 loc) · 2.03 KB
/
TPFakeHostsGenerator.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
//
// TPFakeHostsGenerator.m
// teleport
//
// Created by Julien Robert on 01/05/08.
// Copyright 2008 __MyCompanyName__. All rights reserved.
//
#import "TPFakeHostsGenerator.h"
#import "TPHostsManager.h"
#define SCREEN_SIZES (sizeof(TPScreenSizes) / sizeof(NSSize))
static NSSize TPScreenSizes[] = {
{640.0, 480.0},
{800.0, 600.0},
{1024.0, 768.0},
{1280.0, 1024.0},
{1600.0, 1200.0},
{1680.0, 1050.0},
{1920.0, 1200.0},
};
@implementation TPFakeHostsGenerator
- (instancetype) init
{
self = [super init];
_hosts = [[NSMutableArray alloc] init];
return self;
}
- (void)_addFakeHost
{
static int number = 1;
TPRemoteHost * host = [[TPRemoteHost alloc] initWithIdentifier:[[NSProcessInfo processInfo] globallyUniqueString] address:[NSString stringWithFormat:@"%ld:%ld:%ld:%ld", random()%255, random()%255, random()%255, random()%255] port:44186];
[host setCapabilities:TPHostEncryptionCapability];
NSRect screenFrame = NSZeroRect;
screenFrame.size = TPScreenSizes[random() % SCREEN_SIZES];
TPScreen * screen = [[TPScreen alloc] init];
[screen setFrame:screenFrame];
NSArray * screens = @[screen];
[host setScreens:screens];
NSString * computerName = [NSString stringWithFormat:@"Fake Mac %d", number++];
[host setComputerName:computerName];
[host setHostState:TPHostSharedState];
[[TPHostsManager defaultManager] addBonjourHost:host];
[_hosts addObject:host];
// if(number == 10) {
// [_timer invalidate];
// }
}
- (void)_removeRandomFakeHost
{
if([_hosts count] > 0) {
TPRemoteHost * host = _hosts[random() % [_hosts count]];
[[TPHostsManager defaultManager] removeBonjourHost:host];
[_hosts removeObject:host];
}
}
- (void)run
{
#if 1
int i;
for(i=0; i<10; i++) {
[self _addFakeHost];
}
#else
_timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(_addOrRemoveHost) userInfo:nil repeats:YES];
#endif
}
- (void)_addOrRemoveHost
{
#if 0
[self _addFakeHost];
#else
if(random() % 2 == 0) {
[self _removeRandomFakeHost];
}
else {
[self _addFakeHost];
}
#endif
}
@end