| Line 336... |
Line 336... |
| 336 |
my $qdbh = WebDB::connect ("session");
|
336 |
my $qdbh = WebDB::connect ("session");
|
| Line 337... |
Line 337... |
| 337 |
|
337 |
|
| 338 |
if ($RCAUTH) {
|
338 |
if ($RCAUTH) {
|
| 339 |
# If the user is already logged in, bypass the queue check.
|
339 |
# If the user is already logged in, bypass the queue check.
|
| 340 |
my ($email, $RCPASS, $RCLVL) = split /&/, $RCAUTH;
|
340 |
my ($email, $RCPASS, $RCLVL) = split /&/, $RCAUTH;
|
| 341 |
my ($active) = $qdbh->selectrow_array ("select count(*) from session where email = ? and timestamp > (now() - interval 30 minute)", undef, $email);
|
341 |
my ($active) = $qdbh->selectrow_array ("select count(*) from session where email = ? and timestampdiff(minute, timestamp, now()) < 30", undef, $email);
|
| 342 |
return if $active;
|
342 |
return if $active;
|
| Line 343... |
Line 343... |
| 343 |
}
|
343 |
}
|
| 344 |
|
344 |
|
| 345 |
my ($active_users) = $qdbh->selectrow_array ("select count(*) from session where timestamp > (now() - interval 30 minute)");
|
345 |
my ($active_users) = $qdbh->selectrow_array ("select count(*) from session where timestampdiff(minute, timestamp, now()) < 30)");
|
| 346 |
my ($current_wait) = $qdbh->selectrow_array ("select timestampdiff(minute, timestamp, now()) from queue where last_seen > now() - interval 7 minute limit 1");
|
346 |
my ($current_wait) = $qdbh->selectrow_array ("select timestampdiff(minute, timestamp, now()) from queue where timestampdiff(minute, last_seen, now()) < 7 and (timestamp <> last_seen or timestampdiff(second, last_seen, now()) <= 60) limit 1");
|
| Line 347... |
Line 347... |
| 347 |
my @queued_users;
|
347 |
my @queued_users;
|
| 348 |
push @queued_users, map { @{$_} } @{ $qdbh->selectall_arrayref ("select queueid from queue where last_seen > (now() - interval 7 minute) and (timestamp <> last_seen or timestampdiff(minute, last_seen, now()) <= 1) order by timestamp") };
|
348 |
push @queued_users, map { @{$_} } @{ $qdbh->selectall_arrayref ("select queueid from queue where timestampdiff(minute, last_seen, now()) < 7 and (timestamp <> last_seen or timestampdiff(second, last_seen, now()) <= 60) order by timestamp") };
|
| Line -... |
Line 349... |
| - |
|
349 |
|
| 349 |
|
350 |
my $RCqueueID = CGI::cookie('RCQUEUEID') // WebDB::trim CGI::param('RCqueueID') // "";
|
| 350 |
my $RCqueueID = CGI::cookie('RCQUEUEID') // WebDB::trim CGI::param('RCqueueID') // "";
|
351 |
$RCqueueID = "" unless inQueue ($RCqueueID, \@queued_users);
|
| 351 |
$RCqueueID = "" unless inQueue ($RCqueueID, \@queued_users);
|
352 |
|
| 352 |
|
353 |
my $your_wait = 0;
|
| 353 |
if ($active_users >= $max_users) {
|
354 |
if ($active_users >= $max_users) {
|
| 354 |
# We are at max users. People have to wait.
|
355 |
# We are at max users. People have to wait.
|
| 355 |
if (!$RCqueueID) {
|
356 |
if (!$RCqueueID) {
|
| 356 |
use Digest::MD5 qw/md5_hex/;
|
357 |
use Digest::MD5 qw/md5_hex/;
|
| - |
|
358 |
$RCqueueID = time () ."-". md5_hex (rand ());
|
| 357 |
$RCqueueID = time () ."-". md5_hex (rand ());
|
359 |
push @queued_users, $RCqueueID;
|
| 358 |
push @queued_users, $RCqueueID;
|
360 |
$qdbh->do ("replace into queue (queueid, timestamp, last_seen) values (?, now(), now())", undef, $RCqueueID);
|
| Line 359... |
Line 361... |
| 359 |
$qdbh->do ("replace into queue (queueid, timestamp, last_seen) values (?, now(), now())", undef, $RCqueueID);
|
361 |
} else {
|
| 360 |
} else {
|
362 |
($your_wait) = $qdbh->selectrow_array ("select timestampdiff(minute, timestamp, now()) from queue where queueid = ?", undef, $RCqueueID);
|
| Line 361... |
Line 363... |
| 361 |
$qdbh->do ("update queue set last_seen = now() where queueid = ?", undef, $RCqueueID);
|
363 |
$qdbh->do ("update queue set last_seen = now() where queueid = ?", undef, $RCqueueID);
|
| 362 |
}
|
364 |
}
|
| 363 |
|
365 |
|
| Line 371... |
Line 373... |
| 371 |
use Digest::MD5 qw/md5_hex/;
|
373 |
use Digest::MD5 qw/md5_hex/;
|
| 372 |
$RCqueueID = time () ."-". md5_hex (rand ());
|
374 |
$RCqueueID = time () ."-". md5_hex (rand ());
|
| 373 |
push @queued_users, $RCqueueID;
|
375 |
push @queued_users, $RCqueueID;
|
| 374 |
$qdbh->do ("replace into queue (queueid, timestamp, last_seen) values (?, now(), now())", undef, $RCqueueID);
|
376 |
$qdbh->do ("replace into queue (queueid, timestamp, last_seen) values (?, now(), now())", undef, $RCqueueID);
|
| 375 |
} else {
|
377 |
} else {
|
| - |
|
378 |
($your_wait) = $qdbh->selectrow_array ("select timestampdiff(minute, timestamp, now()) from queue where queueid = ?", undef, $RCqueueID);
|
| 376 |
$qdbh->do ("update queue set last_seen = now() where queueid = ?", undef, $RCqueueID);
|
379 |
$qdbh->do ("update queue set last_seen = now() where queueid = ?", undef, $RCqueueID);
|
| 377 |
}
|
380 |
}
|
| Line 378... |
Line 381... |
| 378 |
|
381 |
|
| 379 |
my $queue_position = inQueue ($RCqueueID, \@queued_users);
|
382 |
my $queue_position = inQueue ($RCqueueID, \@queued_users);
|
| 380 |
if ($queue_position > ($max_users - $active_users)) {
|
383 |
if ($queue_position > ($max_users - $active_users)) {
|
| 381 |
# If you're not at the head of the line, continue to wait.
|
384 |
# If you're not at the head of the line, continue to wait.
|
| 382 |
printQueuePage ($RCqueueID, "($queue_position of ".scalar @queued_users." users)", $current_wait);
|
385 |
printQueuePage ($RCqueueID, "($queue_position of ".scalar @queued_users." users)", $current_wait - $your_wait);
|
| 383 |
exit;
|
386 |
exit;
|
| 384 |
}
|
387 |
}
|
| Line 385... |
Line 388... |
| 385 |
}
|
388 |
}
|