95 |
96 |
97 |
--------------------------------------------------------------------------------
/tests/Feature/Http/Controllers/WebControllerTest.php:
--------------------------------------------------------------------------------
1 | create();
22 |
23 | $response = $this->get("/{$game->id}/motd");
24 | $response->assertStatus(200);
25 |
26 | $data = $response->getContent();
27 |
28 | $this->assertEmpty($data);
29 | }
30 |
31 | public function testMotdHasContent(): void
32 | {
33 | // Create 1 game
34 | $game = factory(\App\Models\Game::class)->create();
35 | $motd = factory(\App\Models\Motd::class)->create(['game_id' => $game->id]);
36 |
37 | $response = $this->get("/{$game->id}/motd");
38 | $response->assertStatus(200);
39 |
40 | $data = $response->getContent();
41 |
42 | $this->assertEquals($motd->content, $data);
43 | }
44 |
45 | public function testMotdGetsLatest(): void
46 | {
47 | // Create 1 game
48 | $game = factory(\App\Models\Game::class)->create();
49 |
50 | // This is not today! So this will never show up.
51 | $motdOutdated = factory(\App\Models\Motd::class)->create([
52 | 'game_id' => $game->id,
53 | 'created_at' => Carbon::create(1991, 12, 04),
54 | ]);
55 |
56 | // This is today! Which is probably after 1991..
57 | $motd = factory(\App\Models\Motd::class)->create(['game_id' => $game->id]);
58 |
59 | $response = $this->get("/{$game->id}/motd");
60 | $response->assertStatus(200);
61 |
62 | $data = $response->getContent();
63 |
64 | $this->assertEquals($motd->content, $data);
65 | }
66 |
67 | /**
68 | * Test to make sure we can have nullable version
69 | */
70 | public function testGameHasNoVersion(): void
71 | {
72 | $game = factory(\App\Models\Game::class)->create(['version' => null]);
73 |
74 | $response = $this->get("/{$game->id}/version");
75 | $response->assertStatus(200);
76 |
77 | $data = $response->getContent();
78 |
79 | $this->assertEmpty($data);
80 | }
81 |
82 | /**
83 | * Test to make sure we can have ACTUAL stuff and it returns correctly!
84 | */
85 | public function testGameHasVersion(): void
86 | {
87 | $game = factory(\App\Models\Game::class)->create(['version' => '3.14']);
88 |
89 | $response = $this->get("/{$game->id}/version");
90 | $response->assertStatus(200);
91 |
92 | $data = $response->getContent();
93 |
94 | $this->assertEquals($game->version, $data);
95 | }
96 |
97 | }
98 |
--------------------------------------------------------------------------------
/config/queue.php:
--------------------------------------------------------------------------------
1 | env('QUEUE_CONNECTION', 'sync'),
17 |
18 | /*
19 | |--------------------------------------------------------------------------
20 | | Queue Connections
21 | |--------------------------------------------------------------------------
22 | |
23 | | Here you may configure the connection information for each server that
24 | | is used by your application. A default configuration has been added
25 | | for each back-end shipped with Laravel. You are free to add more.
26 | |
27 | | Drivers: "sync", "database", "beanstalkd", "sqs", "redis", "null"
28 | |
29 | */
30 |
31 | 'connections' => [
32 |
33 | 'sync' => [
34 | 'driver' => 'sync',
35 | ],
36 |
37 | 'database' => [
38 | 'driver' => 'database',
39 | 'table' => 'jobs',
40 | 'queue' => 'default',
41 | 'retry_after' => 90,
42 | ],
43 |
44 | 'beanstalkd' => [
45 | 'driver' => 'beanstalkd',
46 | 'host' => 'localhost',
47 | 'queue' => 'default',
48 | 'retry_after' => 90,
49 | 'block_for' => 0,
50 | ],
51 |
52 | 'sqs' => [
53 | 'driver' => 'sqs',
54 | 'key' => env('AWS_ACCESS_KEY_ID'),
55 | 'secret' => env('AWS_SECRET_ACCESS_KEY'),
56 | 'prefix' => env('SQS_PREFIX', 'https://sqs.us-east-1.amazonaws.com/your-account-id'),
57 | 'queue' => env('SQS_QUEUE', 'your-queue-name'),
58 | 'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
59 | ],
60 |
61 | 'redis' => [
62 | 'driver' => 'redis',
63 | 'connection' => 'default',
64 | 'queue' => env('REDIS_QUEUE', 'default'),
65 | 'retry_after' => 90,
66 | 'block_for' => null,
67 | ],
68 |
69 | ],
70 |
71 | /*
72 | |--------------------------------------------------------------------------
73 | | Failed Queue Jobs
74 | |--------------------------------------------------------------------------
75 | |
76 | | These options configure the behavior of failed queue job logging so you
77 | | can control which database and table are used to store the jobs that
78 | | have failed. You may change them to any database / table you wish.
79 | |
80 | */
81 |
82 | 'failed' => [
83 | 'driver' => env('QUEUE_FAILED_DRIVER', 'database'),
84 | 'database' => env('DB_CONNECTION', 'mysql'),
85 | 'table' => 'failed_jobs',
86 | ],
87 |
88 | ];
89 |
--------------------------------------------------------------------------------
/app/Http/Kernel.php:
--------------------------------------------------------------------------------
1 | [
31 | \App\Http\Middleware\EncryptCookies::class,
32 | \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
33 | //\Illuminate\Session\Middleware\StartSession::class,
34 | // \Illuminate\Session\Middleware\AuthenticateSession::class,
35 | //\Illuminate\View\Middleware\ShareErrorsFromSession::class,
36 | \App\Http\Middleware\VerifyCsrfToken::class,
37 | \Illuminate\Routing\Middleware\SubstituteBindings::class,
38 | ],
39 |
40 | 'api' => [
41 | 'throttle:5,1',
42 | \Illuminate\Routing\Middleware\SubstituteBindings::class,
43 | ],
44 | ];
45 |
46 | /**
47 | * The application's route middleware.
48 | *
49 | * These middleware may be assigned to groups or used individually.
50 | *
51 | * @var array
52 | */
53 | protected $routeMiddleware = [
54 | 'auth' => \App\Http\Middleware\Authenticate::class,
55 | 'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
56 | 'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
57 | 'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
58 | 'can' => \Illuminate\Auth\Middleware\Authorize::class,
59 | 'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
60 | 'password.confirm' => \Illuminate\Auth\Middleware\RequirePassword::class,
61 | 'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
62 | 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
63 | 'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
64 | ];
65 |
66 | /**
67 | * The priority-sorted list of middleware.
68 | *
69 | * This forces non-global middleware to always be in the given order.
70 | *
71 | * @var array
72 | */
73 | protected $middlewarePriority = [
74 | \Illuminate\Session\Middleware\StartSession::class,
75 | \Illuminate\View\Middleware\ShareErrorsFromSession::class,
76 | \App\Http\Middleware\Authenticate::class,
77 | \Illuminate\Routing\Middleware\ThrottleRequests::class,
78 | \Illuminate\Session\Middleware\AuthenticateSession::class,
79 | \Illuminate\Routing\Middleware\SubstituteBindings::class,
80 | \Illuminate\Auth\Middleware\Authorize::class,
81 | ];
82 | }
83 |
--------------------------------------------------------------------------------
/config/logging.php:
--------------------------------------------------------------------------------
1 | env('LOG_CHANNEL', 'stack'),
21 |
22 | /*
23 | |--------------------------------------------------------------------------
24 | | Log Channels
25 | |--------------------------------------------------------------------------
26 | |
27 | | Here you may configure the log channels for your application. Out of
28 | | the box, Laravel uses the Monolog PHP logging library. This gives
29 | | you a variety of powerful log handlers / formatters to utilize.
30 | |
31 | | Available Drivers: "single", "daily", "slack", "syslog",
32 | | "errorlog", "monolog",
33 | | "custom", "stack"
34 | |
35 | */
36 |
37 | 'channels' => [
38 | 'stack' => [
39 | 'driver' => 'stack',
40 | 'channels' => ['daily'],
41 | 'ignore_exceptions' => false,
42 | ],
43 |
44 | 'single' => [
45 | 'driver' => 'single',
46 | 'path' => storage_path('logs/laravel.log'),
47 | 'level' => 'debug',
48 | ],
49 |
50 | 'daily' => [
51 | 'driver' => 'daily',
52 | 'path' => storage_path('logs/laravel.log'),
53 | 'level' => 'debug',
54 | 'days' => 4,
55 | ],
56 |
57 | 'slack' => [
58 | 'driver' => 'slack',
59 | 'url' => env('LOG_SLACK_WEBHOOK_URL'),
60 | 'username' => 'Laravel Log',
61 | 'emoji' => ':boom:',
62 | 'level' => 'critical',
63 | ],
64 |
65 | 'papertrail' => [
66 | 'driver' => 'monolog',
67 | 'level' => 'debug',
68 | 'handler' => SyslogUdpHandler::class,
69 | 'handler_with' => [
70 | 'host' => env('PAPERTRAIL_URL'),
71 | 'port' => env('PAPERTRAIL_PORT'),
72 | ],
73 | ],
74 |
75 | 'stderr' => [
76 | 'driver' => 'monolog',
77 | 'handler' => StreamHandler::class,
78 | 'formatter' => env('LOG_STDERR_FORMATTER'),
79 | 'with' => [
80 | 'stream' => 'php://stderr',
81 | ],
82 | ],
83 |
84 | 'syslog' => [
85 | 'driver' => 'syslog',
86 | 'level' => 'debug',
87 | ],
88 |
89 | 'errorlog' => [
90 | 'driver' => 'errorlog',
91 | 'level' => 'debug',
92 | ],
93 |
94 | 'null' => [
95 | 'driver' => 'monolog',
96 | 'handler' => NullHandler::class,
97 | ],
98 |
99 | 'emergency' => [
100 | 'path' => storage_path('logs/laravel.log'),
101 | ],
102 | ],
103 |
104 | ];
105 |
--------------------------------------------------------------------------------
/tests/Unit/Socket/Controllers/QueryControllerTest.php:
--------------------------------------------------------------------------------
1 | assertEmpty($connection->getData());
26 |
27 | $queryController = new QueryController($connection);
28 |
29 | // Empty query will exit early
30 | $queryController->onData($query);
31 | $this->assertEmpty($connection->getData());
32 | }
33 |
34 | public function testOnDataReturnsData(): void
35 | {
36 | $query = '\\gamename\\nolf2\\gamever\\1.3\\location\\0\\validate\\g3Fo6x\\final\\list\\\\gamename\\nolf2';
37 |
38 | $server = Server::create([
39 | 'name' => 'Test Server',
40 | 'address' => '127.0.0.1:1234',
41 | 'has_password' => false,
42 | 'game_name' => 'nolf2',
43 | 'game_version' => '1.3.3.7',
44 | 'status' => Server::STATUS_OPEN,
45 | ])->cache();
46 |
47 | $connection = new ConnectionStub();
48 | $this->assertEmpty($connection->getData());
49 |
50 | $queryController = new QueryController($connection);
51 |
52 | // 1. Empty query will exit early
53 | $queryController->onData($query);
54 |
55 | $data = $connection->getData();
56 |
57 | // Good enough for now.
58 | // This returns a binary string, which I can't figure out how to decode yet...unpack doesn't like me.
59 | $this->assertNotEmpty($data);
60 | $this->assertNotEquals("\\final\\", $data);
61 |
62 | }
63 |
64 | public function testLotsOfServersReturnProperly(): void
65 | {
66 | $faker = app(Generator::class);
67 |
68 | for($i = 0; $i < 1000; $i++) {
69 | $server = Server::create([
70 | 'name' => $faker->bs,
71 | 'address' => '127.0.0.1:' . $faker->unique()->numberBetween(100, 10000),
72 | 'has_password' => false,
73 | 'game_name' => 'nolf2',
74 | 'game_version' => '1.3.3.7',
75 | 'status' => Server::STATUS_OPEN,
76 | ])->cache();
77 | }
78 |
79 | $connection = new ConnectionStub();
80 | $this->assertEmpty($connection->getData());
81 |
82 | $gameName = 'nolf2';
83 | $servers = (new Server())->findAllInCache($gameName);
84 |
85 | $this->assertCount(1000, $servers);
86 | }
87 |
88 | /**
89 | * Covers the following:
90 | * 1. Empty query
91 | * 2. Query without a validate
92 | * 3. Query with a bad validate key
93 | */
94 | public function provideEmptyQueries(): array
95 | {
96 | return [
97 | [''],
98 | ['\\gamename\\nolf2\\gamever\\1.3\\location\\0\\final\\'],
99 | ['\\gamename\\nolf2\\gamever\\1.3\\location\\0\\validate\\12345\\final\\'],
100 | ];
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/config/cache.php:
--------------------------------------------------------------------------------
1 | env('CACHE_DRIVER', 'file'),
22 |
23 | /*
24 | |--------------------------------------------------------------------------
25 | | Cache Stores
26 | |--------------------------------------------------------------------------
27 | |
28 | | Here you may define all of the cache "stores" for your application as
29 | | well as their drivers. You may even define multiple stores for the
30 | | same cache driver to group types of items stored in your caches.
31 | |
32 | */
33 |
34 | 'stores' => [
35 |
36 | 'apc' => [
37 | 'driver' => 'apc',
38 | ],
39 |
40 | 'array' => [
41 | 'driver' => 'array',
42 | ],
43 |
44 | 'database' => [
45 | 'driver' => 'database',
46 | 'table' => 'cache',
47 | 'connection' => null,
48 | ],
49 |
50 | 'file' => [
51 | 'driver' => 'file',
52 | 'path' => storage_path('framework/cache/data'),
53 | ],
54 |
55 | 'memcached' => [
56 | 'driver' => 'memcached',
57 | 'persistent_id' => env('MEMCACHED_PERSISTENT_ID'),
58 | 'sasl' => [
59 | env('MEMCACHED_USERNAME'),
60 | env('MEMCACHED_PASSWORD'),
61 | ],
62 | 'options' => [
63 | // Memcached::OPT_CONNECT_TIMEOUT => 2000,
64 | ],
65 | 'servers' => [
66 | [
67 | 'host' => env('MEMCACHED_HOST', '127.0.0.1'),
68 | 'port' => env('MEMCACHED_PORT', 11211),
69 | 'weight' => 100,
70 | ],
71 | ],
72 | ],
73 |
74 | 'redis' => [
75 | 'driver' => 'redis',
76 | 'connection' => 'cache',
77 | ],
78 |
79 | 'dynamodb' => [
80 | 'driver' => 'dynamodb',
81 | 'key' => env('AWS_ACCESS_KEY_ID'),
82 | 'secret' => env('AWS_SECRET_ACCESS_KEY'),
83 | 'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
84 | 'table' => env('DYNAMODB_CACHE_TABLE', 'cache'),
85 | 'endpoint' => env('DYNAMODB_ENDPOINT'),
86 | ],
87 |
88 | ],
89 |
90 | /*
91 | |--------------------------------------------------------------------------
92 | | Cache Key Prefix
93 | |--------------------------------------------------------------------------
94 | |
95 | | When utilizing a RAM based store such as APC or Memcached, there might
96 | | be other applications utilizing the same cache. So, we'll specify a
97 | | value to get prefixed to all our keys so we can avoid collisions.
98 | |
99 | */
100 |
101 | 'prefix' => env('CACHE_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_cache'),
102 |
103 | ];
104 |
--------------------------------------------------------------------------------
/tests/Feature/Http/Controllers/ServerControllerTest.php:
--------------------------------------------------------------------------------
1 | get('/api/v1/servers');
17 | $response->assertStatus(400);
18 | }
19 |
20 | public function testServerIndexNoPassword()
21 | {
22 | $game = factory(Game::class)->create([
23 | 'game_name' => 'nolf2',
24 | 'server_count' => 1,
25 | ]);
26 | $response = $this->get('/api/v1/servers?gameName=nolf2');
27 | $response->assertStatus(400);
28 | }
29 |
30 | public function testServerIndexNoGame()
31 | {
32 | $game = factory(Game::class)->create([
33 | 'game_name' => 'nolf2',
34 | 'server_count' => 1,
35 | ]);
36 | $response = $this->get('/api/v1/servers?password=helloworld');
37 | $response->assertStatus(400);
38 | }
39 |
40 | public function testServerIndex()
41 | {
42 | $game = factory(Game::class)->create([
43 | 'game_name' => 'nolf2',
44 | 'server_count' => 1,
45 | ]);
46 |
47 | $server = Server::create([
48 | 'name' => 'Test Server',
49 | 'address' => '127.0.0.1:1234',
50 | 'has_password' => false,
51 | 'game_name' => 'nolf2',
52 | 'game_version' => '1.3.3.7',
53 | 'status' => Server::STATUS_OPEN,
54 | ]);
55 |
56 | $server->cache();
57 |
58 | $response = $this->get('/api/v1/servers?gameName=nolf2&password=helloworld');
59 | $response->assertStatus(200);
60 |
61 | $data = $response->decodeResponseJson();
62 |
63 | $this->assertCount(1, $data);
64 | $this->assertEquals($data[0]['address'], $server->address);
65 | $this->assertEquals($data[0]['name'], $server->name);
66 | }
67 |
68 | public function testServerIndexWithNoTrack()
69 | {
70 | $game = factory(Game::class)->create([
71 | 'game_name' => 'nolf2',
72 | 'server_count' => 1,
73 | ]);
74 |
75 | $server = Server::create([
76 | 'name' => 'Test Server',
77 | 'address' => '127.0.0.1:1234',
78 | 'has_password' => false,
79 | 'game_name' => 'nolf2',
80 | 'game_version' => '1.3.3.7',
81 | 'status' => Server::STATUS_OPEN,
82 | ]);
83 |
84 | $server->cache();
85 |
86 | $server2 = Server::create([
87 | 'name' => 'Test [NT] Server',
88 | 'address' => '127.0.0.1:56789',
89 | 'has_password' => false,
90 | 'game_name' => 'nolf2',
91 | 'game_version' => '1.3.3.7',
92 | 'status' => Server::STATUS_OPEN,
93 | ]);
94 |
95 | $server2->cache();
96 |
97 | $response = $this->get('/api/v1/servers?gameName=nolf2&password=helloworld');
98 | $response->assertStatus(200);
99 |
100 | $data = $response->decodeResponseJson();
101 |
102 | // Make sure only the first server shows up!
103 | $this->assertCount(1, $data);
104 | $this->assertEquals($data[0]['address'], $server->address);
105 | $this->assertEquals($data[0]['name'], $server->name);
106 | }
107 | }
108 |
--------------------------------------------------------------------------------
/app/Socket/Controllers/CommonController.php:
--------------------------------------------------------------------------------
1 | $request) {
25 | // This regex will match \queryid\%d.%d\
26 | $regex = '/[\\\\]?(queryid\\\\\d\.\d\\\\)[\\\\]?/m';
27 | $match = [];
28 |
29 | // Ok actually look for it, and we didn't find it, skip to the next map
30 | if(!preg_match($regex, $request, $match)) {
31 | continue;
32 | }
33 |
34 | // Remove the queryid from the request list (optional, we could just skip it!)
35 | $requests[$index] = str_replace($match[1], '', $requests[$index]);
36 |
37 | $regex = '/(\d\.\d)/m';
38 | $digitMatch = [];
39 |
40 | // Ok just extract the digits now, more reliable with regex
41 | if(!preg_match($regex, $match[1], $digitMatch)) {
42 | \Log::warning("[CommonController::messageToArray] Query somehow lost its digits! Data: {$request}");
43 | continue;
44 | }
45 |
46 | $queryId = $digitMatch[1];
47 | }
48 |
49 | // Bad query, but let's try to roll with it!
50 | if ($queryId === null) {
51 | //\Log::warning("[CommonController::messageToArray] No query id in query! Assigning 1.1. Data: {$message}");
52 | $queryId = '1.1';
53 | }
54 |
55 | // Loop through the number of requests we got
56 | foreach ($requests as $index => $request) {
57 | if ($request === '') {
58 | continue;
59 | }
60 |
61 | $request_array = explode("\\", $request);
62 |
63 | // Trim the array if needed
64 | if ($request_array[0] === '') {
65 | array_shift($request_array);
66 | }
67 |
68 | if ($request_array[count($request_array) - 1] === '') {
69 | array_pop($request_array);
70 | }
71 |
72 |
73 | $requestCount = count($request_array);
74 |
75 | // Loop through the individual requests!
76 | for ($i = 0; $i < $requestCount; $i += 2) {
77 | if($request_array[$i] === '') {
78 | $i--;
79 | continue;
80 | }
81 | $key = strtolower($request_array[$i]);
82 | $value = $request_array[$i + 1] ?? null;
83 |
84 | \Arr::set($query, "{$index}.{$key}", $value);
85 | }
86 | }
87 |
88 | // Append our query id to the end!
89 | $query[] = ['queryid' => $queryId];
90 |
91 |
92 | return $query;
93 | }
94 |
95 | public function packIP($ip)
96 | {
97 | // ip2long reverses endianess...so pack it and unpack it in reverse, and then pack it again.
98 | $packed_reversed = ip2long($ip);
99 | $packed_reversed = pack('N', $packed_reversed);
100 | $ip = unpack("V", $packed_reversed);
101 | $ip = array_shift($ip);
102 | return pack("V", $ip);
103 | }
104 | }
105 |
--------------------------------------------------------------------------------
/config/auth.php:
--------------------------------------------------------------------------------
1 | [
17 | 'guard' => 'web',
18 | 'passwords' => 'users',
19 | ],
20 |
21 | /*
22 | |--------------------------------------------------------------------------
23 | | Authentication Guards
24 | |--------------------------------------------------------------------------
25 | |
26 | | Next, you may define every authentication guard for your application.
27 | | Of course, a great default configuration has been defined for you
28 | | here which uses session storage and the Eloquent user provider.
29 | |
30 | | All authentication drivers have a user provider. This defines how the
31 | | users are actually retrieved out of your database or other storage
32 | | mechanisms used by this application to persist your user's data.
33 | |
34 | | Supported: "session", "token"
35 | |
36 | */
37 |
38 | 'guards' => [
39 | 'web' => [
40 | 'driver' => 'session',
41 | 'provider' => 'users',
42 | ],
43 |
44 | 'api' => [
45 | 'driver' => 'token',
46 | 'provider' => 'users',
47 | 'hash' => false,
48 | ],
49 | ],
50 |
51 | /*
52 | |--------------------------------------------------------------------------
53 | | User Providers
54 | |--------------------------------------------------------------------------
55 | |
56 | | All authentication drivers have a user provider. This defines how the
57 | | users are actually retrieved out of your database or other storage
58 | | mechanisms used by this application to persist your user's data.
59 | |
60 | | If you have multiple user tables or models you may configure multiple
61 | | sources which represent each model / table. These sources may then
62 | | be assigned to any extra authentication guards you have defined.
63 | |
64 | | Supported: "database", "eloquent"
65 | |
66 | */
67 |
68 | 'providers' => [
69 | 'users' => [
70 | 'driver' => 'eloquent',
71 | 'model' => App\User::class,
72 | ],
73 |
74 | // 'users' => [
75 | // 'driver' => 'database',
76 | // 'table' => 'users',
77 | // ],
78 | ],
79 |
80 | /*
81 | |--------------------------------------------------------------------------
82 | | Resetting Passwords
83 | |--------------------------------------------------------------------------
84 | |
85 | | You may specify multiple password reset configurations if you have more
86 | | than one user table or model in the application and you want to have
87 | | separate password reset settings based on the specific user types.
88 | |
89 | | The expire time is the number of minutes that the reset token should be
90 | | considered valid. This security feature keeps tokens short-lived so
91 | | they have less time to be guessed. You may change this as needed.
92 | |
93 | */
94 |
95 | 'passwords' => [
96 | 'users' => [
97 | 'provider' => 'users',
98 | 'table' => 'password_resets',
99 | 'expire' => 60,
100 | 'throttle' => 60,
101 | ],
102 | ],
103 |
104 | /*
105 | |--------------------------------------------------------------------------
106 | | Password Confirmation Timeout
107 | |--------------------------------------------------------------------------
108 | |
109 | | Here you may define the amount of seconds before a password confirmation
110 | | times out and the user is prompted to re-enter their password via the
111 | | confirmation screen. By default, the timeout lasts for three hours.
112 | |
113 | */
114 |
115 | 'password_timeout' => 10800,
116 |
117 | ];
118 |
--------------------------------------------------------------------------------
/config/mail.php:
--------------------------------------------------------------------------------
1 | env('MAIL_DRIVER', 'smtp'),
20 |
21 | /*
22 | |--------------------------------------------------------------------------
23 | | SMTP Host Address
24 | |--------------------------------------------------------------------------
25 | |
26 | | Here you may provide the host address of the SMTP server used by your
27 | | applications. A default option is provided that is compatible with
28 | | the Mailgun mail service which will provide reliable deliveries.
29 | |
30 | */
31 |
32 | 'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
33 |
34 | /*
35 | |--------------------------------------------------------------------------
36 | | SMTP Host Port
37 | |--------------------------------------------------------------------------
38 | |
39 | | This is the SMTP port used by your application to deliver e-mails to
40 | | users of the application. Like the host we have set this value to
41 | | stay compatible with the Mailgun e-mail application by default.
42 | |
43 | */
44 |
45 | 'port' => env('MAIL_PORT', 587),
46 |
47 | /*
48 | |--------------------------------------------------------------------------
49 | | Global "From" Address
50 | |--------------------------------------------------------------------------
51 | |
52 | | You may wish for all e-mails sent by your application to be sent from
53 | | the same address. Here, you may specify a name and address that is
54 | | used globally for all e-mails that are sent by your application.
55 | |
56 | */
57 |
58 | 'from' => [
59 | 'address' => env('MAIL_FROM_ADDRESS', 'hello@example.com'),
60 | 'name' => env('MAIL_FROM_NAME', 'Example'),
61 | ],
62 |
63 | /*
64 | |--------------------------------------------------------------------------
65 | | E-Mail Encryption Protocol
66 | |--------------------------------------------------------------------------
67 | |
68 | | Here you may specify the encryption protocol that should be used when
69 | | the application send e-mail messages. A sensible default using the
70 | | transport layer security protocol should provide great security.
71 | |
72 | */
73 |
74 | 'encryption' => env('MAIL_ENCRYPTION', 'tls'),
75 |
76 | /*
77 | |--------------------------------------------------------------------------
78 | | SMTP Server Username
79 | |--------------------------------------------------------------------------
80 | |
81 | | If your SMTP server requires a username for authentication, you should
82 | | set it here. This will get used to authenticate with your server on
83 | | connection. You may also set the "password" value below this one.
84 | |
85 | */
86 |
87 | 'username' => env('MAIL_USERNAME'),
88 |
89 | 'password' => env('MAIL_PASSWORD'),
90 |
91 | /*
92 | |--------------------------------------------------------------------------
93 | | Sendmail System Path
94 | |--------------------------------------------------------------------------
95 | |
96 | | When using the "sendmail" driver to send e-mails, we will need to know
97 | | the path to where Sendmail lives on this server. A default path has
98 | | been provided here, which will work well on most of your systems.
99 | |
100 | */
101 |
102 | 'sendmail' => '/usr/sbin/sendmail -bs',
103 |
104 | /*
105 | |--------------------------------------------------------------------------
106 | | Markdown Mail Settings
107 | |--------------------------------------------------------------------------
108 | |
109 | | If you are using Markdown based email rendering, you may configure your
110 | | theme and component paths here, allowing you to customize the design
111 | | of the emails. Or, you may simply stick with the Laravel defaults!
112 | |
113 | */
114 |
115 | 'markdown' => [
116 | 'theme' => 'default',
117 |
118 | 'paths' => [
119 | resource_path('views/vendor/mail'),
120 | ],
121 | ],
122 |
123 | /*
124 | |--------------------------------------------------------------------------
125 | | Log Channel
126 | |--------------------------------------------------------------------------
127 | |
128 | | If you are using the "log" driver, you may specify the logging channel
129 | | if you prefer to keep mail messages separate from other log entries
130 | | for simpler reading. Otherwise, the default channel will be used.
131 | |
132 | */
133 |
134 | 'log_channel' => env('MAIL_LOG_CHANNEL'),
135 |
136 | ];
137 |
--------------------------------------------------------------------------------
/config/database.php:
--------------------------------------------------------------------------------
1 | env('DB_CONNECTION', 'mysql'),
19 |
20 | /*
21 | |--------------------------------------------------------------------------
22 | | Database Connections
23 | |--------------------------------------------------------------------------
24 | |
25 | | Here are each of the database connections setup for your application.
26 | | Of course, examples of configuring each database platform that is
27 | | supported by Laravel is shown below to make development simple.
28 | |
29 | |
30 | | All database work in Laravel is done through the PHP PDO facilities
31 | | so make sure you have the driver for your particular database of
32 | | choice installed on your machine before you begin development.
33 | |
34 | */
35 |
36 | 'connections' => [
37 |
38 | 'sqlite' => [
39 | 'driver' => 'sqlite',
40 | 'url' => env('DATABASE_URL'),
41 | 'database' => env('DB_DATABASE', database_path('database.sqlite')),
42 | 'prefix' => '',
43 | 'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
44 | ],
45 |
46 | 'mysql' => [
47 | 'driver' => 'mysql',
48 | 'url' => env('DATABASE_URL'),
49 | 'host' => env('DB_HOST', '127.0.0.1'),
50 | 'port' => env('DB_PORT', '3306'),
51 | 'database' => env('DB_DATABASE', 'forge'),
52 | 'username' => env('DB_USERNAME', 'forge'),
53 | 'password' => env('DB_PASSWORD', ''),
54 | 'unix_socket' => env('DB_SOCKET', ''),
55 | 'charset' => 'utf8mb4',
56 | 'collation' => 'utf8mb4_unicode_ci',
57 | 'prefix' => '',
58 | 'prefix_indexes' => true,
59 | 'strict' => true,
60 | 'engine' => null,
61 | 'options' => extension_loaded('pdo_mysql') ? array_filter([
62 | PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
63 | ]) : [],
64 | ],
65 |
66 | 'pgsql' => [
67 | 'driver' => 'pgsql',
68 | 'url' => env('DATABASE_URL'),
69 | 'host' => env('DB_HOST', '127.0.0.1'),
70 | 'port' => env('DB_PORT', '5432'),
71 | 'database' => env('DB_DATABASE', 'forge'),
72 | 'username' => env('DB_USERNAME', 'forge'),
73 | 'password' => env('DB_PASSWORD', ''),
74 | 'charset' => 'utf8',
75 | 'prefix' => '',
76 | 'prefix_indexes' => true,
77 | 'schema' => 'public',
78 | 'sslmode' => 'prefer',
79 | ],
80 |
81 | 'sqlsrv' => [
82 | 'driver' => 'sqlsrv',
83 | 'url' => env('DATABASE_URL'),
84 | 'host' => env('DB_HOST', 'localhost'),
85 | 'port' => env('DB_PORT', '1433'),
86 | 'database' => env('DB_DATABASE', 'forge'),
87 | 'username' => env('DB_USERNAME', 'forge'),
88 | 'password' => env('DB_PASSWORD', ''),
89 | 'charset' => 'utf8',
90 | 'prefix' => '',
91 | 'prefix_indexes' => true,
92 | ],
93 |
94 | ],
95 |
96 | /*
97 | |--------------------------------------------------------------------------
98 | | Migration Repository Table
99 | |--------------------------------------------------------------------------
100 | |
101 | | This table keeps track of all the migrations that have already run for
102 | | your application. Using this information, we can determine which of
103 | | the migrations on disk haven't actually been run in the database.
104 | |
105 | */
106 |
107 | 'migrations' => 'migrations',
108 |
109 | /*
110 | |--------------------------------------------------------------------------
111 | | Redis Databases
112 | |--------------------------------------------------------------------------
113 | |
114 | | Redis is an open source, fast, and advanced key-value store that also
115 | | provides a richer body of commands than a typical key-value system
116 | | such as APC or Memcached. Laravel makes it easy to dig right in.
117 | |
118 | */
119 |
120 | 'redis' => [
121 |
122 | 'client' => env('REDIS_CLIENT', 'phpredis'),
123 |
124 | 'options' => [
125 | 'cluster' => env('REDIS_CLUSTER', 'redis'),
126 | 'prefix' => env('REDIS_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_database_'),
127 | ],
128 |
129 | 'default' => [
130 | 'url' => env('REDIS_URL'),
131 | 'host' => env('REDIS_HOST', '127.0.0.1'),
132 | 'password' => env('REDIS_PASSWORD', null),
133 | 'port' => env('REDIS_PORT', '6379'),
134 | 'database' => env('REDIS_DB', '0'),
135 | ],
136 |
137 | 'cache' => [
138 | 'url' => env('REDIS_URL'),
139 | 'host' => env('REDIS_HOST', '127.0.0.1'),
140 | 'password' => env('REDIS_PASSWORD', null),
141 | 'port' => env('REDIS_PORT', '6379'),
142 | 'database' => env('REDIS_CACHE_DB', '1'),
143 | ],
144 |
145 | ],
146 |
147 | ];
148 |
--------------------------------------------------------------------------------
/app/Socket/Controllers/ListingController.php:
--------------------------------------------------------------------------------
1 | false,
17 | 'currentQueryID' => '0.0',
18 | ];
19 |
20 | protected SocketInterface $connection;
21 | protected string $hashedAddress;
22 |
23 | public function __construct(SocketInterface $connection)
24 | {
25 | $this->connection = $connection;
26 | $this->hashedAddress = \Hash::make($connection->getRemoteAddress());
27 | }
28 |
29 | /**
30 | * On stream connection, behind the scenes it actually hooks up the rest of the events
31 | */
32 | public function onConnected(): void
33 | {
34 | Log::info("Client {$this->hashedAddress} connected");
35 | }
36 |
37 | /**
38 | * On error, when a ReactPHP error gets thrown, I could be handled here
39 | * @param Exception $e
40 | */
41 | public function onError(Exception $e): void
42 | {
43 | Log::info("Client received error {$e->getMessage()}");
44 | }
45 |
46 | /**
47 | * When a data stream is closed
48 | */
49 | public function onClosed(): void
50 | {
51 |
52 | }
53 |
54 | /**
55 | * When a data stream is ended
56 | */
57 | public function onEnded(): void
58 | {
59 | Log::info("Client {$this->hashedAddress} ended their connection");
60 | }
61 |
62 | /**
63 | * On data get! Handle any data incoming here
64 | * @param string $message
65 | * @param string $serverAddress
66 | */
67 | public function onData(string $message, $serverAddress): void
68 | {
69 | Log::info("Received data from client {$serverAddress}: {$message}");
70 |
71 | $queries = $this->messageToArray($message);
72 | $response = '';
73 |
74 | foreach ($queries as $query) {
75 | // Handle individual queries here!
76 | if (isset($query['heartbeat'])) {
77 | $response .= $this->handleHeartbeat($query, $serverAddress);
78 | } elseif (isset($query['hostname'])) {
79 | $this->handlePublish($query, $serverAddress);
80 | } elseif (isset($query['echo'])) {
81 | $response .= $this->handleEcho($query, $serverAddress);
82 | }
83 | }
84 |
85 | if ($response !== '') {
86 | $response .= '\\final\\';
87 | }
88 |
89 | $this->connection->send($response, $serverAddress);
90 |
91 | Log::info("Sent client {$serverAddress}: {$response}");
92 | }
93 |
94 | protected function handleEcho($query, $serverAddress): string
95 | {
96 | $echo = Arr::get($query, 'echo');
97 |
98 | \Log::info("Client {$serverAddress} wanted to echo {$echo}");
99 |
100 | // According to https://www.oldunreal.com/UnrealReference/IpServer.htm echo is identical
101 | return "\\echo\\{$echo}";
102 | }
103 |
104 | protected function handleHeartbeat($query, $serverAddress): string
105 | {
106 | $stateChanged = (bool) \Arr::has($query, 'statechanged');
107 | $response = '';
108 |
109 |
110 | $gameName = Arr::get($query, 'gamename');
111 |
112 | $hostAddress = $this->getHostAddress($query, $serverAddress);
113 |
114 | try {
115 | $server = (new Server())->findInCache($hostAddress, $gameName);
116 | } catch (\RuntimeException $e) {
117 | $server = null;
118 | }
119 |
120 | // Update the time, and update the cache
121 | if ($server) {
122 | $server->setUpdatedAt(now());
123 | $server->updateInCache($hostAddress, $server->toArray());
124 | }
125 |
126 | // While normally we'd wait for a state change, some games don't seem to request one.
127 | // So let's always ask for status on every heartbeat.
128 | $response .= '\\status\\';
129 |
130 | // If we don't have a server by them
131 | if (!$server) {
132 | Log::info("Requested updated server info from {$serverAddress}");
133 |
134 | // Not all games support \\status\\ request directly from the master server (lol, Unreal Engine 1 games)
135 | // So use the info we've got to mark the game server down.
136 | $publishQuery = [
137 | 'hostname' => 'Not Available',
138 | 'gamename' => Arr::get($query, 'gamename'),
139 | 'gamever' => '1.0',
140 | 'password' => 0,
141 | ];
142 |
143 | $this->handlePublish($publishQuery, $serverAddress);
144 | }
145 |
146 | return $response;
147 | }
148 |
149 | protected function handlePublish($query, $serverAddress): bool
150 | {
151 | $exclude_for_options = [
152 | 'hostname',
153 | 'hostip',
154 | 'hostport',
155 | 'password',
156 | 'gamename',
157 | 'gamever',
158 | 'gamemode',
159 | ];
160 |
161 | $hostAddress = $this->getHostAddress($query, $serverAddress);
162 |
163 | $server = new Server();
164 | $server->name = Arr::get($query, 'hostname');
165 | $server->address = $hostAddress;
166 |
167 | $server->has_password = (bool) Arr::get($query, 'password', 0);
168 | $server->game_name = Arr::get($query, 'gamename');
169 | $server->game_version = Arr::get($query, 'gamever');
170 |
171 | // Filter the options we already stored above
172 | $options = array_filter($query, function ($item) use ($exclude_for_options) {
173 | return !in_array($item, $exclude_for_options, true);
174 | }, ARRAY_FILTER_USE_KEY);
175 |
176 | $server->options = $options;
177 |
178 | $serverArray = $server->toArray();
179 |
180 | return $server->updateInCache($hostAddress, $serverArray);
181 | }
182 |
183 | private function getHostAddress($query, $serverAddress)
184 | {
185 | // Some games don't pass over the hostip, so default to the server trying to talk to us!
186 | $hostAddress = $serverAddress;
187 |
188 | // But some do. So if it's there, let's use it!
189 | if (isset($query['hostip'], $query['hostport'])) {
190 | $ip = Arr::get($query, 'hostip');
191 | $port = Arr::get($query, 'hostport');
192 |
193 | // Okay...some games give us the lan ip...parse the real ip from our request
194 | if (\Str::contains($ip, '192.168.'))
195 | {
196 | $ip = Arr::first(explode(':', $serverAddress));
197 | }
198 |
199 | $hostAddress = "{$ip}:{$port}";
200 | }
201 |
202 | return $hostAddress;
203 | }
204 |
205 | }
206 |
--------------------------------------------------------------------------------
/app/Socket/Controllers/QueryController.php:
--------------------------------------------------------------------------------
1 | false,
26 | 'currentQueryID' => '0.0',
27 | ];
28 |
29 | protected ConnectionInterface $connection;
30 | protected string $hashedAddress;
31 |
32 | public function __construct(ConnectionInterface $connection)
33 | {
34 | $this->connection = $connection;
35 | $this->hashedAddress = \Hash::make($connection->getRemoteAddress());
36 | }
37 |
38 | /**
39 | * On stream connection, behind the scenes it actually hooks up the rest of the events
40 | */
41 | public function onConnected(): void
42 | {
43 | Log::info("Client {$this->hashedAddress} connected. Sending initial request.");
44 |
45 | // Ask for validation!
46 | $this->connection->write('\\basic\\\\secure\\final\\');
47 | }
48 |
49 | /**
50 | * On error, when a ReactPHP error gets thrown, I could be handled here
51 | * @param Exception $e
52 | */
53 | public function onError(Exception $e): void
54 | {
55 | Log::info("Client received error {$e->getMessage()}");
56 | }
57 |
58 | /**
59 | * When a data stream is closed
60 | */
61 | public function onClosed(): void
62 | {
63 |
64 | }
65 |
66 | /**
67 | * When a data stream is ended
68 | */
69 | public function onEnded(): void
70 | {
71 | Log::info("Client {$this->hashedAddress} ended their connection");
72 | }
73 |
74 | /**
75 | * On data get! Handle any data incoming here
76 | * @param string $message
77 | */
78 | public function onData(string $message): void
79 | {
80 | Log::info("Received data from client {$this->hashedAddress}");
81 | Log::debug("DATA: {$message}");
82 |
83 |
84 | $queries = $this->messageToArray($message);
85 |
86 | $response = '';
87 |
88 | // For some responses, we always want to include the final!
89 | $forceFinal = false;
90 |
91 | foreach ($queries as $query) {
92 | // Handle individual queries here!
93 | if (isset($query['validate'])) {
94 | $result = $this->handleIdentify($query);
95 |
96 | // If they failed the validation, then stop here!
97 | if (!$result) {
98 | $this->connection->close();
99 | return;
100 | }
101 |
102 | } elseif (isset($query['list'])) {
103 | $response .= $this->handleList($query, $response);
104 | $forceFinal = true;
105 | } elseif (isset($query['queryid'])) {
106 | $this->handleQueryID($query);
107 | }
108 | }
109 |
110 | if ($response !== '' || $forceFinal) {
111 | $security = '';//"\\secure\\TXKOAT";
112 | $response = $security.$response."\\final\\";
113 | }
114 |
115 | Log::info("Sent client {$this->hashedAddress}: {$response}");
116 |
117 | $sent = $this->connection->write($response);
118 | }
119 |
120 | protected function handleIdentify($query): bool
121 | {
122 | try {
123 | $encoded_query = json_encode($query, JSON_THROW_ON_ERROR, 512);
124 | } catch (\ErrorException $exception) {
125 | \Log::warning('[QueryController::onData] Could not json encode query! Data will be invalid.');
126 | $encoded_query = '! COULD NOT ENCODE !';
127 | }
128 |
129 | // Not used right now!
130 | $validates = Config::get('games.keys', []);
131 | $gameKey = Arr::get($query, 'validate');
132 |
133 | // Validate the request - For now just validate that they pass something. Not really worth it to decode this stuff.
134 | if (!$this->client['valid'] && !$gameKey) {
135 | \Log::warning("[QueryController::onData] Client not valid! Data: {$encoded_query}");
136 | return false;
137 | }
138 |
139 | // Okie, we're good here!
140 | $this->client['valid'] = true;
141 |
142 | return true;
143 | }
144 |
145 | /**
146 | * Unreal Engine expects a response like
147 | * \\ip\\127.0.0.1:1234\\127.0.0.1:1235\\final\\
148 | * @param $query
149 | * @param $response
150 | * @return string
151 | */
152 | protected function handleListUnreal($query, $response): string
153 | {
154 | $gameName = Arr::get($query, 'gamename');
155 | $servers = (new Server())->findAllInCache($gameName);
156 |
157 | $response .= '\\ip\\';
158 |
159 | foreach ($servers as $server) {
160 | $response .= $server->address;
161 | $response .= '\\';
162 | }
163 |
164 | return $response;
165 | }
166 |
167 | /**
168 | * Lithtech expects a packed response
169 | * @param $query
170 | * @param $response
171 | * @return string
172 | */
173 | protected function handleListLithtech($query, $response): string
174 | {
175 | $gameName = Arr::get($query, 'gamename');
176 | $servers = (new Server())->findAllInCache($gameName);
177 |
178 | foreach ($servers as $server) {
179 | // Skip this for now
180 | if ($server->name === 'Not Available')
181 | {
182 | continue;
183 | }
184 |
185 | $arr = explode(':', $server->address);
186 | // Shove the ip address in, and make the port big endian
187 | $processed_server = [$this->packIP($arr[0]), pack('n', $arr[1])];
188 | $response .= implode('', $processed_server);
189 | }
190 |
191 | return $response;
192 | }
193 |
194 | /**
195 | * @param $query
196 | * @param $response
197 | * @return string
198 | */
199 | protected function handleList($query, $response)
200 | {
201 | $gameName = Arr::get($query, 'gamename');
202 |
203 | // Handle different versions of this request!
204 | switch ($gameName) {
205 | default:
206 | case 'nolf':
207 | case 'nolf2':
208 | return $this->handleListLithtech($query, $response);
209 | case 'deusex':
210 | return $this->handleListUnreal($query, $response);
211 | }
212 | }
213 |
214 | protected function handleQueryID($query): void
215 | {
216 | $queryIdRequest = Arr::last($query);
217 | $this->client['currentQueryID'] = Arr::get($queryIdRequest, 'queryid', '1.1');
218 | }
219 |
220 |
221 | }
222 |
--------------------------------------------------------------------------------
/app/Models/Server.php:
--------------------------------------------------------------------------------
1 | 'boolean',
70 | 'options' => 'array',
71 | ];
72 |
73 | /**
74 | * Cache $this model!
75 | * @return bool
76 | */
77 | public function cache(): bool
78 | {
79 | if (!$this->address) {
80 | throw new \RuntimeException('Address field is required in order to cache the server model.');
81 | }
82 |
83 | return (bool) \RedisManager::zadd($this->getCacheKey().".{$this->game_name}", $this->updated_at->timestamp,
84 | json_encode($this->toArray()));
85 | }
86 |
87 | /**
88 | * Get all the cache!
89 | * @param string $gameName Game Name
90 | * @param int $min
91 | * @param int $max
92 | * @return Collection
93 | */
94 | public function findAllInCache($gameName, $min = 0, $max = 10000): Collection
95 | {
96 | $results = \RedisManager::zrange($this->getCacheKey().".{$gameName}", $min, $max);
97 |
98 | $servers = [];
99 |
100 | foreach ($results as $result) {
101 | try {
102 | $server = json_decode($result, true, 512, JSON_THROW_ON_ERROR);
103 | } catch (\ErrorException $e) {
104 | continue;
105 | }
106 |
107 | // BUG: For some reason Laravel isn't casting our array to json on a later ->toArray()
108 | // So do it here.
109 | try {
110 | $server['options'] = json_encode($server['options'], JSON_THROW_ON_ERROR, 512);
111 | } catch (\ErrorException $e) {
112 | $server['options'] = '[]';
113 | }
114 |
115 | $servers[] = $server;
116 | }
117 |
118 | $results = self::hydrate($servers);
119 | return collect($results);
120 | }
121 |
122 | /**
123 | * Slightly slow, we have to go through all the items in the cache to find out specific server..
124 | * @param $address
125 | * @param $gameName
126 | * @return Server
127 | */
128 | public function findInCache($address, $gameName): Server
129 | {
130 | $servers = $this->findAllInCache($gameName);
131 |
132 | $cache = null;
133 |
134 | foreach ($servers as $server) {
135 | if ($server->address === $address) {
136 | $cache = $server;
137 | break;
138 | }
139 | }
140 |
141 | if (!$cache) {
142 | throw new \RuntimeException("Could not find server {$address} in cache.");
143 | }
144 |
145 | // Fill this model instance
146 | $this->fill($cache->toArray());
147 |
148 | return $this;
149 | }
150 |
151 | /**
152 | * FIXME: I'm probably real slow!
153 | * @param $address
154 | * @param $options
155 | * @return bool
156 | */
157 | public function updateInCache($address, $options): bool
158 | {
159 | $gameName = \Arr::get($options, 'game_name');
160 | $servers = $this->findAllInCache($gameName);
161 | $cache = null;
162 | $serverIndex = -1;
163 | $decoded_server = [];
164 |
165 | foreach ($servers as $index => $server) {
166 | try {
167 | $decoded_server = json_decode($server, true, 512, JSON_THROW_ON_ERROR);
168 |
169 | } catch (\ErrorException $e) {
170 | continue;
171 | }
172 |
173 | if (\Arr::get($decoded_server, 'address') === $address) {
174 | $cache = $decoded_server;
175 | $serverIndex = $index;
176 | break;
177 | }
178 | }
179 |
180 | // Make sure created_at is not modified
181 | if (!isset($decoded_server['created_at'])) {
182 | $options['created_at'] = Carbon::now();
183 | } else {
184 | $options['created_at'] = $decoded_server['created_at'];
185 | }
186 |
187 | if (!isset($options['updated_at'])) {
188 | $options['updated_at'] = Carbon::now();
189 | }
190 |
191 | // Fill this model instance
192 | $this->fill($options);
193 |
194 | if ($cache) {
195 | $key = $this->getCacheKey().".{$gameName}";
196 |
197 | // Remove the old entry
198 | $itemsRemoved = \RedisManager::zremRangeByRank($key, $serverIndex, $serverIndex);
199 |
200 | if ($itemsRemoved === 0) {
201 | \Log::warning("[Server::updateInCache] Didn't remove any items for cache {$key}!");
202 | }
203 | } else {
204 | // Cool new entry! Update our Game count!
205 | $game = Game::where('game_name', '=', $gameName)->firstOrCreate(['game_name' => $gameName]);
206 | $game->server_count++;
207 | $game->save();
208 | }
209 |
210 | return $this->cache();
211 | }
212 |
213 | public function getCacheTTL(): int
214 | {
215 | return self::CACHE_TTL;
216 | }
217 |
218 | public function getCacheKey(): string
219 | {
220 | $key = self::CACHE_KEY;
221 |
222 | if (\App::runningUnitTests()) {
223 | $key .= '.testing';
224 | }
225 |
226 | return $key;
227 | }
228 | }
229 |
--------------------------------------------------------------------------------
/.idea/php.xml:
--------------------------------------------------------------------------------
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 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
--------------------------------------------------------------------------------
/config/session.php:
--------------------------------------------------------------------------------
1 | env('SESSION_DRIVER', 'file'),
22 |
23 | /*
24 | |--------------------------------------------------------------------------
25 | | Session Lifetime
26 | |--------------------------------------------------------------------------
27 | |
28 | | Here you may specify the number of minutes that you wish the session
29 | | to be allowed to remain idle before it expires. If you want them
30 | | to immediately expire on the browser closing, set that option.
31 | |
32 | */
33 |
34 | 'lifetime' => env('SESSION_LIFETIME', 120),
35 |
36 | 'expire_on_close' => false,
37 |
38 | /*
39 | |--------------------------------------------------------------------------
40 | | Session Encryption
41 | |--------------------------------------------------------------------------
42 | |
43 | | This option allows you to easily specify that all of your session data
44 | | should be encrypted before it is stored. All encryption will be run
45 | | automatically by Laravel and you can use the Session like normal.
46 | |
47 | */
48 |
49 | 'encrypt' => false,
50 |
51 | /*
52 | |--------------------------------------------------------------------------
53 | | Session File Location
54 | |--------------------------------------------------------------------------
55 | |
56 | | When using the native session driver, we need a location where session
57 | | files may be stored. A default has been set for you but a different
58 | | location may be specified. This is only needed for file sessions.
59 | |
60 | */
61 |
62 | 'files' => storage_path('framework/sessions'),
63 |
64 | /*
65 | |--------------------------------------------------------------------------
66 | | Session Database Connection
67 | |--------------------------------------------------------------------------
68 | |
69 | | When using the "database" or "redis" session drivers, you may specify a
70 | | connection that should be used to manage these sessions. This should
71 | | correspond to a connection in your database configuration options.
72 | |
73 | */
74 |
75 | 'connection' => env('SESSION_CONNECTION', null),
76 |
77 | /*
78 | |--------------------------------------------------------------------------
79 | | Session Database Table
80 | |--------------------------------------------------------------------------
81 | |
82 | | When using the "database" session driver, you may specify the table we
83 | | should use to manage the sessions. Of course, a sensible default is
84 | | provided for you; however, you are free to change this as needed.
85 | |
86 | */
87 |
88 | 'table' => 'sessions',
89 |
90 | /*
91 | |--------------------------------------------------------------------------
92 | | Session Cache Store
93 | |--------------------------------------------------------------------------
94 | |
95 | | When using the "apc", "memcached", or "dynamodb" session drivers you may
96 | | list a cache store that should be used for these sessions. This value
97 | | must match with one of the application's configured cache "stores".
98 | |
99 | */
100 |
101 | 'store' => env('SESSION_STORE', null),
102 |
103 | /*
104 | |--------------------------------------------------------------------------
105 | | Session Sweeping Lottery
106 | |--------------------------------------------------------------------------
107 | |
108 | | Some session drivers must manually sweep their storage location to get
109 | | rid of old sessions from storage. Here are the chances that it will
110 | | happen on a given request. By default, the odds are 2 out of 100.
111 | |
112 | */
113 |
114 | 'lottery' => [2, 100],
115 |
116 | /*
117 | |--------------------------------------------------------------------------
118 | | Session Cookie Name
119 | |--------------------------------------------------------------------------
120 | |
121 | | Here you may change the name of the cookie used to identify a session
122 | | instance by ID. The name specified here will get used every time a
123 | | new session cookie is created by the framework for every driver.
124 | |
125 | */
126 |
127 | 'cookie' => env(
128 | 'SESSION_COOKIE',
129 | Str::slug(env('APP_NAME', 'laravel'), '_').'_session'
130 | ),
131 |
132 | /*
133 | |--------------------------------------------------------------------------
134 | | Session Cookie Path
135 | |--------------------------------------------------------------------------
136 | |
137 | | The session cookie path determines the path for which the cookie will
138 | | be regarded as available. Typically, this will be the root path of
139 | | your application but you are free to change this when necessary.
140 | |
141 | */
142 |
143 | 'path' => '/',
144 |
145 | /*
146 | |--------------------------------------------------------------------------
147 | | Session Cookie Domain
148 | |--------------------------------------------------------------------------
149 | |
150 | | Here you may change the domain of the cookie used to identify a session
151 | | in your application. This will determine which domains the cookie is
152 | | available to in your application. A sensible default has been set.
153 | |
154 | */
155 |
156 | 'domain' => env('SESSION_DOMAIN', null),
157 |
158 | /*
159 | |--------------------------------------------------------------------------
160 | | HTTPS Only Cookies
161 | |--------------------------------------------------------------------------
162 | |
163 | | By setting this option to true, session cookies will only be sent back
164 | | to the server if the browser has a HTTPS connection. This will keep
165 | | the cookie from being sent to you if it can not be done securely.
166 | |
167 | */
168 |
169 | 'secure' => env('SESSION_SECURE_COOKIE', false),
170 |
171 | /*
172 | |--------------------------------------------------------------------------
173 | | HTTP Access Only
174 | |--------------------------------------------------------------------------
175 | |
176 | | Setting this value to true will prevent JavaScript from accessing the
177 | | value of the cookie and the cookie will only be accessible through
178 | | the HTTP protocol. You are free to modify this option if needed.
179 | |
180 | */
181 |
182 | 'http_only' => true,
183 |
184 | /*
185 | |--------------------------------------------------------------------------
186 | | Same-Site Cookies
187 | |--------------------------------------------------------------------------
188 | |
189 | | This option determines how your cookies behave when cross-site requests
190 | | take place, and can be used to mitigate CSRF attacks. By default, we
191 | | do not enable this as other CSRF protection services are in place.
192 | |
193 | | Supported: "lax", "strict", "none"
194 | |
195 | */
196 |
197 | 'same_site' => null,
198 |
199 | ];
200 |
--------------------------------------------------------------------------------
/resources/lang/en/validation.php:
--------------------------------------------------------------------------------
1 | 'The :attribute must be accepted.',
17 | 'active_url' => 'The :attribute is not a valid URL.',
18 | 'after' => 'The :attribute must be a date after :date.',
19 | 'after_or_equal' => 'The :attribute must be a date after or equal to :date.',
20 | 'alpha' => 'The :attribute may only contain letters.',
21 | 'alpha_dash' => 'The :attribute may only contain letters, numbers, dashes and underscores.',
22 | 'alpha_num' => 'The :attribute may only contain letters and numbers.',
23 | 'array' => 'The :attribute must be an array.',
24 | 'before' => 'The :attribute must be a date before :date.',
25 | 'before_or_equal' => 'The :attribute must be a date before or equal to :date.',
26 | 'between' => [
27 | 'numeric' => 'The :attribute must be between :min and :max.',
28 | 'file' => 'The :attribute must be between :min and :max kilobytes.',
29 | 'string' => 'The :attribute must be between :min and :max characters.',
30 | 'array' => 'The :attribute must have between :min and :max items.',
31 | ],
32 | 'boolean' => 'The :attribute field must be true or false.',
33 | 'confirmed' => 'The :attribute confirmation does not match.',
34 | 'date' => 'The :attribute is not a valid date.',
35 | 'date_equals' => 'The :attribute must be a date equal to :date.',
36 | 'date_format' => 'The :attribute does not match the format :format.',
37 | 'different' => 'The :attribute and :other must be different.',
38 | 'digits' => 'The :attribute must be :digits digits.',
39 | 'digits_between' => 'The :attribute must be between :min and :max digits.',
40 | 'dimensions' => 'The :attribute has invalid image dimensions.',
41 | 'distinct' => 'The :attribute field has a duplicate value.',
42 | 'email' => 'The :attribute must be a valid email address.',
43 | 'ends_with' => 'The :attribute must end with one of the following: :values.',
44 | 'exists' => 'The selected :attribute is invalid.',
45 | 'file' => 'The :attribute must be a file.',
46 | 'filled' => 'The :attribute field must have a value.',
47 | 'gt' => [
48 | 'numeric' => 'The :attribute must be greater than :value.',
49 | 'file' => 'The :attribute must be greater than :value kilobytes.',
50 | 'string' => 'The :attribute must be greater than :value characters.',
51 | 'array' => 'The :attribute must have more than :value items.',
52 | ],
53 | 'gte' => [
54 | 'numeric' => 'The :attribute must be greater than or equal :value.',
55 | 'file' => 'The :attribute must be greater than or equal :value kilobytes.',
56 | 'string' => 'The :attribute must be greater than or equal :value characters.',
57 | 'array' => 'The :attribute must have :value items or more.',
58 | ],
59 | 'image' => 'The :attribute must be an image.',
60 | 'in' => 'The selected :attribute is invalid.',
61 | 'in_array' => 'The :attribute field does not exist in :other.',
62 | 'integer' => 'The :attribute must be an integer.',
63 | 'ip' => 'The :attribute must be a valid IP address.',
64 | 'ipv4' => 'The :attribute must be a valid IPv4 address.',
65 | 'ipv6' => 'The :attribute must be a valid IPv6 address.',
66 | 'json' => 'The :attribute must be a valid JSON string.',
67 | 'lt' => [
68 | 'numeric' => 'The :attribute must be less than :value.',
69 | 'file' => 'The :attribute must be less than :value kilobytes.',
70 | 'string' => 'The :attribute must be less than :value characters.',
71 | 'array' => 'The :attribute must have less than :value items.',
72 | ],
73 | 'lte' => [
74 | 'numeric' => 'The :attribute must be less than or equal :value.',
75 | 'file' => 'The :attribute must be less than or equal :value kilobytes.',
76 | 'string' => 'The :attribute must be less than or equal :value characters.',
77 | 'array' => 'The :attribute must not have more than :value items.',
78 | ],
79 | 'max' => [
80 | 'numeric' => 'The :attribute may not be greater than :max.',
81 | 'file' => 'The :attribute may not be greater than :max kilobytes.',
82 | 'string' => 'The :attribute may not be greater than :max characters.',
83 | 'array' => 'The :attribute may not have more than :max items.',
84 | ],
85 | 'mimes' => 'The :attribute must be a file of type: :values.',
86 | 'mimetypes' => 'The :attribute must be a file of type: :values.',
87 | 'min' => [
88 | 'numeric' => 'The :attribute must be at least :min.',
89 | 'file' => 'The :attribute must be at least :min kilobytes.',
90 | 'string' => 'The :attribute must be at least :min characters.',
91 | 'array' => 'The :attribute must have at least :min items.',
92 | ],
93 | 'not_in' => 'The selected :attribute is invalid.',
94 | 'not_regex' => 'The :attribute format is invalid.',
95 | 'numeric' => 'The :attribute must be a number.',
96 | 'password' => 'The password is incorrect.',
97 | 'present' => 'The :attribute field must be present.',
98 | 'regex' => 'The :attribute format is invalid.',
99 | 'required' => 'The :attribute field is required.',
100 | 'required_if' => 'The :attribute field is required when :other is :value.',
101 | 'required_unless' => 'The :attribute field is required unless :other is in :values.',
102 | 'required_with' => 'The :attribute field is required when :values is present.',
103 | 'required_with_all' => 'The :attribute field is required when :values are present.',
104 | 'required_without' => 'The :attribute field is required when :values is not present.',
105 | 'required_without_all' => 'The :attribute field is required when none of :values are present.',
106 | 'same' => 'The :attribute and :other must match.',
107 | 'size' => [
108 | 'numeric' => 'The :attribute must be :size.',
109 | 'file' => 'The :attribute must be :size kilobytes.',
110 | 'string' => 'The :attribute must be :size characters.',
111 | 'array' => 'The :attribute must contain :size items.',
112 | ],
113 | 'starts_with' => 'The :attribute must start with one of the following: :values.',
114 | 'string' => 'The :attribute must be a string.',
115 | 'timezone' => 'The :attribute must be a valid zone.',
116 | 'unique' => 'The :attribute has already been taken.',
117 | 'uploaded' => 'The :attribute failed to upload.',
118 | 'url' => 'The :attribute format is invalid.',
119 | 'uuid' => 'The :attribute must be a valid UUID.',
120 |
121 | /*
122 | |--------------------------------------------------------------------------
123 | | Custom Validation Language Lines
124 | |--------------------------------------------------------------------------
125 | |
126 | | Here you may specify custom validation messages for attributes using the
127 | | convention "attribute.rule" to name the lines. This makes it quick to
128 | | specify a specific custom language line for a given attribute rule.
129 | |
130 | */
131 |
132 | 'custom' => [
133 | 'attribute-name' => [
134 | 'rule-name' => 'custom-message',
135 | ],
136 | ],
137 |
138 | /*
139 | |--------------------------------------------------------------------------
140 | | Custom Validation Attributes
141 | |--------------------------------------------------------------------------
142 | |
143 | | The following language lines are used to swap our attribute placeholder
144 | | with something more reader friendly such as "E-Mail Address" instead
145 | | of "email". This simply helps us make our message more expressive.
146 | |
147 | */
148 |
149 | 'attributes' => [],
150 |
151 | ];
152 |
--------------------------------------------------------------------------------
/resources/views/privacy.blade.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Userface
8 |
9 |
10 |
11 |
12 |
13 |
78 |
79 |
80 |
81 |
82 |
83 | Privacy Policy
84 |
85 |
86 | Jake Breen built the MGMSE app as an Open Source application and is hosting it on Userface.me. MGMSE known as the SERVICE, is provided by Jake Breen at no cost and is intended for use as is.
87 |
88 | This page is used to inform users regarding our policies with the collection, processing, and disclosure of Personal Information if anyone decided to use the Service.
89 |
90 | If you choose to use the Service, then you agree to the collection and use of information in relation to this policy. The Personal Information that we collect is used for providing and improving the Service. We will not use or share your information with anyone except as described in this Privacy Policy.
91 |
92 | This policy is only applicable to the Service provided directly by Userface.me.
93 |
94 |
95 | What Data Does The Service Collect?
96 |
97 |
98 | In order for the Service to function we store your Internet Protocol ("IP") address when you a host a multi-player server.
99 |
100 | We also store non-unique data such as your player name and latency.
101 |
102 |
103 | How Do You Use My Data?
104 |
105 |
106 | Your data is given out to other users of the Service in order to directly connect with your multi-player server.
107 |
108 | For the sole purpose of creating web widgets to display multi-player server statuses, this information may also be shared with individuals through Application Programming Interface ("API") access.
109 |
110 | If you have any concerns about third party processing of your data, please refer to the Restricting Third Party Data Processing section.
111 |
112 |
113 | How Do You Store My Data?
114 |
115 |
116 | For the duration of your multi-player server and for 10 minutes after you discontinue the multi-player server we store the data in memory. After such time the data is removed automatically.
117 |
118 | Non-unique data will be stored as long as you're on a multi-player server.
119 |
120 | We also may store your data in Logs. They are used solely for fixing and diagnosing problems with the Service, and will be deleted automatically after 4 days.
121 |
122 | Individuals with Application Programming Interface ("API") access may hold your data for longer.
123 |
124 | If you have any concerns about third party processing of your data, please refer to the Restricting Third Party Data Processing section.
125 |
126 |
127 | Restricting Third Party Data Processing
128 |
129 |
130 | If you wish to exclude your multi-player server from third party API processing, you can do so in one of two ways.
131 |
132 | - Add [NT] to your multi-player server's name field.
133 | - Email me at the address in the Contact Us section with your multi-player's server address and proof that you own the address.
134 |
135 | Due to the nature of non-unique data we can't verify and remove this data on request. If you are concerned we recommend you stop using the Service.
136 |
137 |
138 | Removal Of Data
139 |
140 |
141 | If wish to have any of your data removed, feel free to email us at the address listed in the Contact Us section.
142 |
143 |
144 | Cookies
145 |
146 |
147 | Cookies are files with a small amount of data that are commonly used as anonymous unique identifiers. These are sent to your browser from the websites that you visit and are stored on your computer.
148 |
149 | This Service does not use these “cookies”, however the API ("Application Programming Interface") used by developers does use cookies. If you are a developer using this API you will be notified ahead of time.
150 |
151 |
152 | Security
153 |
154 |
155 | I value your trust in providing us your Personal Information, thus we are striving to use commercially acceptable means of protecting it. But remember that no method of transmission over the internet, or method of electronic storage is 100% secure and reliable, and I cannot guarantee its absolute security.
156 |
157 |
158 | Links to Other Sites
159 |
160 |
161 | This Service may contain links to other sites. If you click on a third-party link, you will be directed to that site. Note that these external sites are not operated by me. Therefore, I strongly advise you to review the Privacy Policy of these websites. I have no control over and assume no responsibility for the content, privacy policies, or practices of any third-party sites or services.
162 |
163 |
164 | Children’s Privacy
165 |
166 |
167 | These Services do not address anyone under the age of 16. We do not knowingly collect personally identifiable information from children under 16. In the case we discover that a child under 16 has provided us with personal information, We will immediately delete the data from the Service. If you are a parent or guardian and you are aware that your child has provided us with personal information, please contact us so that we will be able to do necessary actions.
168 |
169 |
170 | Changes to This Privacy Policy
171 |
172 |
173 | We may update our Privacy Policy from time to time. Thus, you are advised to review this page periodically for any changes. We will notify you of any changes by posting the new Privacy Policy on this page. These changes are effective immediately after they are posted on this page.
174 |
175 |
176 | Contact Us
177 |
178 |
179 | If you have any questions or suggestions about the Privacy Policy or usage of the Service, do not hesitate to contact us at userface.contact@gmail.com.
180 |
181 |
182 |
183 |
184 |
185 |
186 |
--------------------------------------------------------------------------------
/.idea/lara_game_web_api.iml:
--------------------------------------------------------------------------------
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 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
--------------------------------------------------------------------------------
/tests/Unit/Socket/Controllers/ListingControllerTest.php:
--------------------------------------------------------------------------------
1 | assertEmpty($connection->getData());
29 |
30 | $listingController = new ListingController($connection);
31 |
32 | // Empty query will exit early
33 | $listingController->onData($query, '127.0.0.1:1234');
34 | $this->assertEmpty($connection->getData());
35 | }
36 |
37 | /**
38 | * Test our good friend echo!
39 | * It'll just spit back what you send it.
40 | */
41 | public function testOnDataEcho(): void
42 | {
43 | $connection = new UDPSocketStub();
44 | $this->assertEmpty($connection->getData());
45 |
46 | $listingController = new ListingController($connection);
47 |
48 | $query = "\\echo\\hello world\\final\\";
49 |
50 | $listingController->onData($query, '127.0.0.1:1234');
51 | $data = $connection->getData();
52 | $this->assertNotEmpty($data);
53 | $this->assertEquals($query, $data);
54 | }
55 |
56 | /**
57 | * Test out a heartbeat with no "statechange" query or actual server in our cache
58 | * This should return a \status\ query
59 | */
60 | public function testOnDataHeartbeatNoStateChangedNoServer(): void
61 | {
62 | $socket = new UDPSocketStub();
63 | $this->assertEmpty($socket->getData());
64 |
65 | $listingServer = new ListingController($socket);
66 |
67 | $query = "\\heartbeat\\27889\\gamename\\nolf2\\final\\\\queryid\\1.0";
68 |
69 | $listingServer->onData($query, '127.0.0.1:27889');
70 | $data = $socket->getData();
71 |
72 | $this->assertNotEmpty($data);
73 |
74 | // Because we don't have a server with that address, we need more info
75 | $this->assertEquals("\\status\\\\final\\", $data);
76 | }
77 |
78 | /**
79 | * Note: We now call statechange on every heartbeat. The test has been updated to represent this.
80 | * --
81 | * Test out a heartbeat with no "statechange" query
82 | * We have a server in cache,
83 | * so all we're doing here is updating the timestamp so it doesn't get removed in 5 minutes.
84 | */
85 | public function testOnDataHeartbeatNoStateChanged(): void
86 | {
87 | $socket = new UDPSocketStub();
88 | $this->assertEmpty($socket->getData());
89 |
90 | // Use make so we don't store it in db.
91 | $server = factory(Server::class)->make(['game_name' => 'nolf2']);
92 | $server->cache();
93 |
94 | $listingServer = new ListingController($socket);
95 |
96 | $query = "\\heartbeat\\27889\\gamename\\nolf2\\final\\\\queryid\\1.0";
97 |
98 | $listingServer->onData($query, $server->address);
99 | $data = $socket->getData();
100 |
101 | // No update
102 | $this->assertEquals('\\status\\\\final\\', $data);
103 | }
104 |
105 | public function testOnDataHeartbeatStateChanged(): void
106 | {
107 | $socket = new UDPSocketStub();
108 | $this->assertEmpty($socket->getData());
109 |
110 | // Use make so we don't store it in db.
111 | $server = factory(Server::class)->make(['game_name' => 'nolf2']);
112 | $server->cache();
113 |
114 | $listingController = new ListingController($socket);
115 |
116 | $query = "\\heartbeat\\27889\\gamename\\nolf2\\statechanged\\\\final\\\\queryid\\1.0";
117 |
118 | $listingController->onData($query, $server->address);
119 | $data = $socket->getData();
120 |
121 | $this->assertNotEmpty($data);
122 |
123 | // They requested a statechange, we need more info
124 | $this->assertEquals("\\status\\\\final\\", $data);
125 | }
126 |
127 | public function testOnDataPublish(): void
128 | {
129 | $socket = new UDPSocketStub();
130 | $this->assertEmpty($socket->getData());
131 |
132 | $listingServer = new ListingController($socket);
133 |
134 | $serverAddress = '192.168.1.1:27888';
135 | $gameName = 'nolf2';
136 |
137 | $query = '\\hostname\\JakeDM\\gamename\\nolf2\\hostport\\27888\\gamemode\\openplaying\\gamever\\1.0.0.4M\\gametype\\DeathMatch\\hostip\\192.168.1.1\\frag_0\\0\\mapname\\DD_02\\maxplayers\\16\\numplayers\\1\\fraglimit\\25\\options\\\\password\\0\\timelimit\\10\\ping_0\\0\\player_0\\Jake\\final\\queryid\\2.1';
138 |
139 | $listingServer->onData($query, $serverAddress);
140 | $data = $socket->getData();
141 |
142 | // No response
143 | $this->assertEmpty($data);
144 |
145 | $server = (new Server())->findInCache($serverAddress, $gameName);
146 |
147 | $this->assertNotNull($server);
148 |
149 | // TODO: Add more equals, address is a good indicator though.
150 | $this->assertEquals($serverAddress, $server->address);
151 | }
152 |
153 | public function testOnDataPublishWithMultipleServers(): void
154 | {
155 | // Setup our lots of servers!
156 | $faker = app(Generator::class);
157 | $query = '\\gamename\\nolf2\\gamever\\1.3\\location\\0\\validate\\g3Fo6x\\final\\list\\\\gamename\\nolf2';
158 |
159 | for($i = 0; $i < 1000; $i++) {
160 | $server = Server::create([
161 | 'name' => $faker->bs,
162 | 'address' => '127.0.0.1:' . $faker->numberBetween(100, 10000),
163 | 'has_password' => false,
164 | 'game_name' => 'nolf2',
165 | 'game_version' => '1.3.3.7',
166 | 'status' => Server::STATUS_OPEN,
167 | ])->cache();
168 | }
169 |
170 | $socket = new UDPSocketStub();
171 | $this->assertEmpty($socket->getData());
172 |
173 | $listingServer = new ListingController($socket);
174 |
175 | $serverAddress = '192.168.1.1:27888';
176 | $gameName = 'nolf2';
177 |
178 | $query = '\\hostname\\JakeDM\\gamename\\nolf2\\hostport\\27888\\gamemode\\openplaying\\gamever\\1.0.0.4M\\gametype\\DeathMatch\\hostip\\192.168.1.1\\frag_0\\0\\mapname\\DD_02\\maxplayers\\16\\numplayers\\1\\fraglimit\\25\\options\\\\password\\0\\timelimit\\10\\ping_0\\0\\player_0\\Jake\\final\\queryid\\2.1';
179 |
180 | $listingServer->onData($query, $serverAddress);
181 | $data = $socket->getData();
182 |
183 | // No response
184 | $this->assertEmpty($data);
185 |
186 | $server = (new Server())->findInCache($serverAddress, $gameName);
187 |
188 | $this->assertNotNull($server);
189 |
190 | // TODO: Add more equals, address is a good indicator though.
191 | $this->assertEquals($serverAddress, $server->address);
192 | }
193 |
194 | public function testOnHeartbeatWontCreateDuplicates(): void
195 | {
196 | // Setup our lots of servers!
197 | $faker = app(Generator::class);
198 | $query = '\\gamename\\nolf2\\gamever\\1.3\\location\\0\\validate\\g3Fo6x\\final\\list\\\\gamename\\nolf2';
199 |
200 | $socket = new UDPSocketStub();
201 | $this->assertEmpty($socket->getData());
202 |
203 | $listingServer = new ListingController($socket);
204 |
205 | $serverAddress = '192.168.1.1:27888';
206 | $gameName = 'nolf2';
207 |
208 | $query = '\\hostname\\JakeDM\\gamename\\nolf2\\hostport\\27888\\gamemode\\openplaying\\gamever\\1.0.0.4M\\gametype\\DeathMatch\\hostip\\192.168.1.1\\frag_0\\0\\mapname\\DD_02\\maxplayers\\16\\numplayers\\1\\fraglimit\\25\\options\\\\password\\0\\timelimit\\10\\ping_0\\0\\player_0\\Jake\\final\\queryid\\1.1';
209 | $listingServer->onData($query, $serverAddress);
210 |
211 | for ($i = 0; $i < 5; $i++) {
212 | $localQuery = "\\heartbeat\\27888\\gamename\\nolf2\\final\\\\queryid\\{$i}.1";
213 | $listingServer->onData($localQuery, $serverAddress);
214 |
215 | $data = $socket->getData();
216 | $this->assertEquals('\\status\\\\final\\', $data);
217 | }
218 |
219 | $servers = (new Server())->findAllInCache($gameName);
220 |
221 | // There should only be 1!
222 | $this->assertNotNull($servers);
223 | $this->assertCount(1, $servers);
224 | }
225 |
226 | /**
227 | * Covers the following:
228 | * 1. Empty query
229 | * 2. Query without a validate
230 | * 3. Query with a bad validate key
231 | */
232 | public function provideEmptyQueries(): array
233 | {
234 | return [
235 | [''],
236 | ];
237 | }
238 | }
239 |
--------------------------------------------------------------------------------
/config/app.php:
--------------------------------------------------------------------------------
1 | env('APP_NAME', 'Laravel'),
17 |
18 | /*
19 | |--------------------------------------------------------------------------
20 | | Application Environment
21 | |--------------------------------------------------------------------------
22 | |
23 | | This value determines the "environment" your application is currently
24 | | running in. This may determine how you prefer to configure various
25 | | services the application utilizes. Set this in your ".env" file.
26 | |
27 | */
28 |
29 | 'env' => env('APP_ENV', 'production'),
30 |
31 | /*
32 | |--------------------------------------------------------------------------
33 | | Application Debug Mode
34 | |--------------------------------------------------------------------------
35 | |
36 | | When your application is in debug mode, detailed error messages with
37 | | stack traces will be shown on every error that occurs within your
38 | | application. If disabled, a simple generic error page is shown.
39 | |
40 | */
41 |
42 | 'debug' => env('APP_DEBUG', false),
43 |
44 | /*
45 | |--------------------------------------------------------------------------
46 | | Application URL
47 | |--------------------------------------------------------------------------
48 | |
49 | | This URL is used by the console to properly generate URLs when using
50 | | the Artisan command line tool. You should set this to the root of
51 | | your application so that it is used when running Artisan tasks.
52 | |
53 | */
54 |
55 | 'url' => env('APP_URL', 'http://localhost'),
56 |
57 | 'asset_url' => env('ASSET_URL', null),
58 |
59 | /*
60 | |--------------------------------------------------------------------------
61 | | Application Timezone
62 | |--------------------------------------------------------------------------
63 | |
64 | | Here you may specify the default timezone for your application, which
65 | | will be used by the PHP date and date-time functions. We have gone
66 | | ahead and set this to a sensible default for you out of the box.
67 | |
68 | */
69 |
70 | 'timezone' => 'UTC',
71 |
72 | /*
73 | |--------------------------------------------------------------------------
74 | | Application Locale Configuration
75 | |--------------------------------------------------------------------------
76 | |
77 | | The application locale determines the default locale that will be used
78 | | by the translation service provider. You are free to set this value
79 | | to any of the locales which will be supported by the application.
80 | |
81 | */
82 |
83 | 'locale' => 'en',
84 |
85 | /*
86 | |--------------------------------------------------------------------------
87 | | Application Fallback Locale
88 | |--------------------------------------------------------------------------
89 | |
90 | | The fallback locale determines the locale to use when the current one
91 | | is not available. You may change the value to correspond to any of
92 | | the language folders that are provided through your application.
93 | |
94 | */
95 |
96 | 'fallback_locale' => 'en',
97 |
98 | /*
99 | |--------------------------------------------------------------------------
100 | | Faker Locale
101 | |--------------------------------------------------------------------------
102 | |
103 | | This locale will be used by the Faker PHP library when generating fake
104 | | data for your database seeds. For example, this will be used to get
105 | | localized telephone numbers, street address information and more.
106 | |
107 | */
108 |
109 | 'faker_locale' => 'en_US',
110 |
111 | /*
112 | |--------------------------------------------------------------------------
113 | | Encryption Key
114 | |--------------------------------------------------------------------------
115 | |
116 | | This key is used by the Illuminate encrypter service and should be set
117 | | to a random, 32 character string, otherwise these encrypted strings
118 | | will not be safe. Please do this before deploying an application!
119 | |
120 | */
121 |
122 | 'key' => env('APP_KEY'),
123 |
124 | 'cipher' => 'AES-256-CBC',
125 |
126 | /*
127 | |--------------------------------------------------------------------------
128 | | Autoloaded Service Providers
129 | |--------------------------------------------------------------------------
130 | |
131 | | The service providers listed here will be automatically loaded on the
132 | | request to your application. Feel free to add your own services to
133 | | this array to grant expanded functionality to your applications.
134 | |
135 | */
136 |
137 | 'providers' => [
138 |
139 | /*
140 | * Laravel Framework Service Providers...
141 | */
142 | Illuminate\Auth\AuthServiceProvider::class,
143 | Illuminate\Broadcasting\BroadcastServiceProvider::class,
144 | Illuminate\Bus\BusServiceProvider::class,
145 | Illuminate\Cache\CacheServiceProvider::class,
146 | Illuminate\Foundation\Providers\ConsoleSupportServiceProvider::class,
147 | Illuminate\Cookie\CookieServiceProvider::class,
148 | Illuminate\Database\DatabaseServiceProvider::class,
149 | Illuminate\Encryption\EncryptionServiceProvider::class,
150 | Illuminate\Filesystem\FilesystemServiceProvider::class,
151 | Illuminate\Foundation\Providers\FoundationServiceProvider::class,
152 | Illuminate\Hashing\HashServiceProvider::class,
153 | Illuminate\Mail\MailServiceProvider::class,
154 | Illuminate\Notifications\NotificationServiceProvider::class,
155 | Illuminate\Pagination\PaginationServiceProvider::class,
156 | Illuminate\Pipeline\PipelineServiceProvider::class,
157 | Illuminate\Queue\QueueServiceProvider::class,
158 | Illuminate\Redis\RedisServiceProvider::class,
159 | Illuminate\Auth\Passwords\PasswordResetServiceProvider::class,
160 | Illuminate\Session\SessionServiceProvider::class,
161 | Illuminate\Translation\TranslationServiceProvider::class,
162 | Illuminate\Validation\ValidationServiceProvider::class,
163 | Illuminate\View\ViewServiceProvider::class,
164 |
165 | /*
166 | * Package Service Providers...
167 | */
168 |
169 | /*
170 | * Application Service Providers...
171 | */
172 | App\Providers\AppServiceProvider::class,
173 | App\Providers\AuthServiceProvider::class,
174 | // App\Providers\BroadcastServiceProvider::class,
175 | App\Providers\EventServiceProvider::class,
176 | App\Providers\RouteServiceProvider::class,
177 |
178 | ],
179 |
180 | /*
181 | |--------------------------------------------------------------------------
182 | | Class Aliases
183 | |--------------------------------------------------------------------------
184 | |
185 | | This array of class aliases will be registered when this application
186 | | is started. However, feel free to register as many as you wish as
187 | | the aliases are "lazy" loaded so they don't hinder performance.
188 | |
189 | */
190 |
191 | 'aliases' => [
192 |
193 | 'App' => Illuminate\Support\Facades\App::class,
194 | 'Arr' => Illuminate\Support\Arr::class,
195 | 'Artisan' => Illuminate\Support\Facades\Artisan::class,
196 | 'Auth' => Illuminate\Support\Facades\Auth::class,
197 | 'Blade' => Illuminate\Support\Facades\Blade::class,
198 | 'Broadcast' => Illuminate\Support\Facades\Broadcast::class,
199 | 'Bus' => Illuminate\Support\Facades\Bus::class,
200 | 'Cache' => Illuminate\Support\Facades\Cache::class,
201 | 'Config' => Illuminate\Support\Facades\Config::class,
202 | 'Cookie' => Illuminate\Support\Facades\Cookie::class,
203 | 'Crypt' => Illuminate\Support\Facades\Crypt::class,
204 | 'DB' => Illuminate\Support\Facades\DB::class,
205 | 'Eloquent' => Illuminate\Database\Eloquent\Model::class,
206 | 'Event' => Illuminate\Support\Facades\Event::class,
207 | 'File' => Illuminate\Support\Facades\File::class,
208 | 'Gate' => Illuminate\Support\Facades\Gate::class,
209 | 'Hash' => Illuminate\Support\Facades\Hash::class,
210 | 'Lang' => Illuminate\Support\Facades\Lang::class,
211 | 'Log' => Illuminate\Support\Facades\Log::class,
212 | 'Mail' => Illuminate\Support\Facades\Mail::class,
213 | 'Notification' => Illuminate\Support\Facades\Notification::class,
214 | 'Password' => Illuminate\Support\Facades\Password::class,
215 | 'Queue' => Illuminate\Support\Facades\Queue::class,
216 | 'Redirect' => Illuminate\Support\Facades\Redirect::class,
217 | 'RedisManager' => Illuminate\Support\Facades\Redis::class,
218 | // Avoid conflict with php-redis
219 | //'Redis' => Illuminate\Support\Facades\Redis::class,
220 | 'Request' => Illuminate\Support\Facades\Request::class,
221 | 'Response' => Illuminate\Support\Facades\Response::class,
222 | 'Route' => Illuminate\Support\Facades\Route::class,
223 | 'Schema' => Illuminate\Support\Facades\Schema::class,
224 | 'Session' => Illuminate\Support\Facades\Session::class,
225 | 'Storage' => Illuminate\Support\Facades\Storage::class,
226 | 'Str' => Illuminate\Support\Str::class,
227 | 'URL' => Illuminate\Support\Facades\URL::class,
228 | 'Validator' => Illuminate\Support\Facades\Validator::class,
229 | 'View' => Illuminate\Support\Facades\View::class,
230 |
231 | ],
232 |
233 | ];
234 |
--------------------------------------------------------------------------------