summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorKyle Gunger <corechg@gmail.com>2020-02-28 02:33:14 -0500
committerKyle Gunger <corechg@gmail.com>2020-02-28 02:33:14 -0500
commitab88ba8d0e23999f4d55a2721f610eff2b1d2054 (patch)
treea98692cd60598d34c73b089ffac4dc263c13623c /scripts
parenta4d0d1190b74cd1bfb596b8a02a2deacce3ad86c (diff)
More comments
Diffstat (limited to 'scripts')
-rw-r--r--scripts/client.js8
-rw-r--r--scripts/lobby.js4
-rw-r--r--scripts/sock.js13
3 files changed, 20 insertions, 5 deletions
diff --git a/scripts/client.js b/scripts/client.js
index b5dd4bf..ea62e26 100644
--- a/scripts/client.js
+++ b/scripts/client.js
@@ -13,12 +13,13 @@ function Client(serveraddr, game) {
}
Client.prototype = {
+ // Initialize the connection
init: function() {
this.soc.init();
},
- // Entry point for a message.
- // If it's a close message, the
+ // Entry point for a message from the server.
+ // If it's a close message, we close the game if it is open and change the lobby to reflect the error/close.
cb: function(m) {
console.log(m);
@@ -42,6 +43,7 @@ Client.prototype = {
}
},
+ // Called when negotiating with the server for the first time and we are determining versions
handshake: function(m) {
switch (m.type) {
case "verr":
@@ -57,6 +59,7 @@ Client.prototype = {
}
},
+ // Lobby switch, called when in the lobby and a message arrives from the server
lobby: function (m) {
switch (m.type) {
case "plist":
@@ -87,6 +90,7 @@ Client.prototype = {
}
},
+ // Game switch, called when in game and a message arrives from the server
game: function (m) {
switch (m.type) {
diff --git a/scripts/lobby.js b/scripts/lobby.js
index b2fda06..4d8332d 100644
--- a/scripts/lobby.js
+++ b/scripts/lobby.js
@@ -46,6 +46,7 @@ Lobby.prototype = {
// { data.games[n].name } room name
// { data.games[n].packs } list of the pack names used by this game
// { data.games[n].id } room identifier (uuid)
+ // { data.games[n].max } max players in room
gameList: function(data) {
while (this.elements.games.firstChild != null) {
this.elements.games.remove(this.elements.games.firstChild)
@@ -194,7 +195,6 @@ TopBar.prototype = {
// #############
// GameEl represents a single game in the lobby view. It has methods for setting up the elements and such.
-
-function GameEl(name, packs, id) {
+function GameEl(name, packs, maxp, id) {
} \ No newline at end of file
diff --git a/scripts/sock.js b/scripts/sock.js
index 78c4195..cf06a5e 100644
--- a/scripts/sock.js
+++ b/scripts/sock.js
@@ -1,3 +1,4 @@
+// A wrapper around the wrapper
function SockWorker(serveraddr, version, callback) {
this.server = serveraddr;
this.version = version;
@@ -5,6 +6,7 @@ function SockWorker(serveraddr, version, callback) {
}
SockWorker.prototype = {
+ // Initialize the connection.
init: function() {
if(this.server == "" || this.server == null) {
return;
@@ -22,10 +24,13 @@ SockWorker.prototype = {
}
},
+ // Called when the connection connects to the server
o: function() {
this.send("version", this.version);
},
+ // Called when the connection gets a message from the server
+ // Attempts to turn the message into a usable object and pass it to the callback
msg: function(e) {
if(typeof e.data == "string") {
var dat = JSON.parse(e.data)
@@ -33,18 +38,24 @@ SockWorker.prototype = {
}
},
+ // Called when the connection closes.
+ // Passes a close object to the callback.
c: function() {
this.cb({type: "close", data: ""});
},
+ // Called when the connection encounters an error.
+ // Passes an error to the callback
err: function() {
this.cb({type: "error", data: ""});
},
-
+
+ // Call to close the connection to the server
close: function() {
this.socket.close();
},
+ // Send a message to the server
send: function(type, data) {
var m = new Message(type, data);
this.socket.send(m.stringify())