diff --git a/Server/server.pl b/Server/server.pl index 446c532..42775f3 100755 --- a/Server/server.pl +++ b/Server/server.pl @@ -1,6 +1,7 @@ #!/usr/bin/perl -w use strict; use warnings; +use POSIX; use Net::WebSocket::Server; use JSON; @@ -36,6 +37,20 @@ sub joinSession { print "A client has connected to session: ".$conn->{"currentSession"}{"id"}."\n"; } +#sub shuffleDeck { +# my @deck = @_; +# my $index = 0; +# for (@deck) { +# my $swapCardIndex = floor(rand() * @deck); +# my $swapCard = @deck[$swapCardIndex]; +# @deck[$swapCardIndex] = $_; +# $deck[$index] = $swapCard; +# $index++; +# } +#} + + + Net::WebSocket::Server->new( listen => 8080, on_connect => sub { @@ -65,6 +80,12 @@ Net::WebSocket::Server->new( if ($_->{"currentSession"}{"id"} == $sessionID) { $_->send_utf8(to_json($messageData)); } } } + if ($messageData->{"type"} eq "update") { + print "Updating session ".$sessionID."\n"; + for ($conn->server->connections) { + if ($_->{"currentSession"}{"id"} == $sessionID) {$_->send_utf(to_json($messageData)); } + } + } }, ); }, diff --git a/UI/.index.html.swp b/UI/.index.html.swp new file mode 100644 index 0000000..ab55ad3 Binary files /dev/null and b/UI/.index.html.swp differ