+ getVname: function(vid) {
+ const vIdx = this.st.variants.findIndex(v => v.id == vid);
+ return this.st.variants[vIdx].name;
+ },
+ sendSomethingTo: function(to, code, obj, warnDisconnected) {
+ const doSend = (code, obj, sid) => {
+ this.st.conn.send(JSON.stringify(Object.assign(
+ {},
+ {code: code},
+ obj,
+ {target: sid}
+ )));
+ };
+ const getSid = (pname) => {
+ const pIdx = this.players.findIndex(pl => pl.name == pname);
+ if (!!warnDisconnected && ctype == "live" && pIdx === -1)
+ alert("Warning: " + p.name + " is not connected");
+ return this.players[pIdx].sid;
+ };
+ if (!Array.isArray(to)) //pass sid directly
+ doSend(code, obj, to);
+ else if (!!to[0])
+ {
+ // Challenge with targeted players
+ to.forEach(pname => { doSend(code, obj, getSid(pname)); });
+ }
+ else
+ {
+ // Open challenge: send to all connected players (except us)
+ this.players.forEach(p => {
+ if (p.sid != this.st.user.sid) //only sid is always set
+ doSend(code, obj, p.sid);
+ });
+ }
+ },