Modifications for first live test
This commit is contained in:
parent
c90662791e
commit
0ea82ff1f8
@ -3,6 +3,7 @@ use strict;
|
||||
use warnings;
|
||||
use POSIX;
|
||||
use Net::WebSocket::Server;
|
||||
use IO::Socket::SSL;
|
||||
use JSON;
|
||||
|
||||
use Data::Dumper; # For debuging only, REMOVE WHEN INITIAL CODE IS FINISH
|
||||
@ -14,7 +15,7 @@ my %sessions = ();
|
||||
sub generateSession {
|
||||
my $newSession = shift;
|
||||
unless (defined $newSession) { my $uniquifyer = sprintf("%.0f",rand()*1000); $newSession = time.$uniquifyer; }
|
||||
if ( grep( /$newSession/, keys %sessions ) ) {
|
||||
if ( grep( /^$newSession$/, keys %sessions ) ) {
|
||||
return 0 #failur to create session
|
||||
} else {
|
||||
print "Adding session ".$newSession." to database\n";
|
||||
@ -264,7 +265,7 @@ sub normalizeSession {
|
||||
|
||||
#########################Server Logic below##############################
|
||||
|
||||
my $origin = 'ws://localhost';
|
||||
my $origin = 'ws://test.murkfall.net';
|
||||
|
||||
sub joinSession {
|
||||
my ($sessionID, $userID) = @_;
|
||||
@ -284,8 +285,18 @@ sub joinSession {
|
||||
return 1;
|
||||
}
|
||||
|
||||
my $ssl_conn = IO::Socket::SSL->new(
|
||||
Listen => 5,
|
||||
LocalPort => 42024,
|
||||
Proto => 'tcp',
|
||||
# ssl.ca-file = "/etc/letsencrypt/live/murkfall.net/chain.pem"
|
||||
SSL_cert_file=> "/etc/letsencrypt/live/murkfall.net/fullchain.pem",
|
||||
SSL_key_file=> "/etc/letsencrypt/live/murkfall.net/privkey.pem"
|
||||
);
|
||||
|
||||
my $server = Net::WebSocket::Server->new(
|
||||
listen => 8080,
|
||||
listen => $ssl_conn,
|
||||
|
||||
on_connect => sub {
|
||||
my ($serv, $conn) = @_;
|
||||
$conn->on(
|
||||
@ -316,7 +327,9 @@ my $server = Net::WebSocket::Server->new(
|
||||
$conn->send_utf8('{"info":"session success", "request":"join"}');
|
||||
}
|
||||
if (defined($messageData->{action})) {
|
||||
if ($messageData->{action} =~ /join/ ) { if (joinSession($conn->{session},$conn->{user})) { $conn->send_utf8('{"info":"join success", "request":"update"}'); } }
|
||||
if ($messageData->{action} =~ /join/ ) {
|
||||
if (joinSession($conn->{session},$conn->{user})) { $conn->send_utf8('{"info":"join success", "request":"update"}');
|
||||
} else { $conn->send_utf8('{"error":201,"message":"could not create session","request":"session"}') } }
|
||||
if ($messageData->{action} =~ /update/ ) { my $sessionID = $conn->{session}; normalizeSession($conn->{session}); for ($conn->server->connections) { if ($_->{session} == $conn->{session}) {
|
||||
#This might be a lot to do at once, might need to break it up in the future.
|
||||
# Update all connections joined to this session.
|
||||
@ -447,14 +460,4 @@ print $count."\n";
|
||||
}
|
||||
);
|
||||
|
||||
my $ses = generateSession(50);
|
||||
addDeck($ses,"default");
|
||||
my @tCards = generateDeck('[{"data":["Male ","Female "]},{"data":["Ardvark ","Platipus ","Cat "]},{"data":["Jumping","Falling","Flying"]}]');
|
||||
addCards($ses,"default",\@tCards);
|
||||
addPool($ses,"default");
|
||||
addUser($ses,"Sergiy");
|
||||
drawCard($ses,"default","Sergiy","default");
|
||||
drawCard($ses,"default","Sergiy","default");
|
||||
playCard($ses,"Sergiy","default",0,"default");
|
||||
|
||||
$server->start;
|
||||
|
@ -9,7 +9,7 @@
|
||||
</body>
|
||||
<script>
|
||||
|
||||
window.server = "ws://localhost:8080/";
|
||||
window.server = "wss://test.murkfall.net:42024/";
|
||||
window.gameState = {};
|
||||
window.gameState.users = [];
|
||||
window.gameState.decks = [];
|
||||
|
Loading…
x
Reference in New Issue
Block a user