-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
71 lines (55 loc) · 1.93 KB
/
main.cpp
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
#include "system.h"
#include "client.h"
#include "server_list.h"
#include <stdio.h>
class TaggedConsole : public Console
{
const char *tag;
void VPrintf( const char *format, va_list va ) override {
fputs( tag, stdout );
fputs( ": ", stdout );
vfprintf( stdout, format, va );
}
public:
TaggedConsole( const char *tag_ ) : tag( tag_ ) {}
};
class DummyServerListListener : public ServerListListener
{
public:
void OnServerAdded( const PolledGameServer &server ) override {
printf( "A server %p (%s) has been added\n", &server, server.ServerName().Get() );
}
void OnServerRemoved( const PolledGameServer &server ) override {
printf( "A server %p has been removed\n", &server );
}
void OnServerUpdated( const PolledGameServer &server ) override {
printf( "A server %p has been updated\n", &server );
}
};
int main( int argc, const char **argv ) {
auto *globalConsole = new( malloc( sizeof( TaggedConsole ) ) )TaggedConsole( "System" );
System::Init( globalConsole );
System *system = System::Instance();
UnresolvedAddress master1Address( "188.226.221.185:27950" );
assert( master1Address.IsValidAsString() && master1Address.IsResolved() );
UnresolvedAddress master2Address( "92.62.40.72:27950" );
assert( master2Address.IsValidAsString() && master2Address.IsResolved() );
assert( system->AddMasterServer( master1Address.ToResolvedAddress() ) );
assert( system->AddMasterServer( master2Address.ToResolvedAddress() ) );
system->SetServerListUpdateOptions( false, true );
system->Frame( 16 );
system->Sleep( 16 );
auto *listener = new( malloc( sizeof( DummyServerListListener ) ) )DummyServerListListener;
assert( system->StartUpdatingServerList( listener ) );
for( int i = 0; i < 3000; ++i ) {
printf( "Frame #%d\n", i + 1 );
system->Sleep( 1000 - 16 );
system->Frame( 16 );
if( i >= 15 ) {
system->SetServerListUpdateOptions( true, false );
}
}
system->StopUpdatingServerList();
System::Shutdown();
return 0;
}