added update function to server.pl
This commit is contained in:
parent
3cf8fa031f
commit
d9f0cd62cf
@ -1,6 +1,7 @@
|
|||||||
#!/usr/bin/perl -w
|
#!/usr/bin/perl -w
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
|
use POSIX;
|
||||||
use Net::WebSocket::Server;
|
use Net::WebSocket::Server;
|
||||||
use JSON;
|
use JSON;
|
||||||
|
|
||||||
@ -36,6 +37,20 @@ sub joinSession {
|
|||||||
print "A client has connected to session: ".$conn->{"currentSession"}{"id"}."\n";
|
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(
|
Net::WebSocket::Server->new(
|
||||||
listen => 8080,
|
listen => 8080,
|
||||||
on_connect => sub {
|
on_connect => sub {
|
||||||
@ -65,6 +80,12 @@ Net::WebSocket::Server->new(
|
|||||||
if ($_->{"currentSession"}{"id"} == $sessionID) { $_->send_utf8(to_json($messageData)); }
|
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)); }
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
BIN
UI/.index.html.swp
Normal file
BIN
UI/.index.html.swp
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user