- for (let p of chall.to)
- {
- if (p.name != "")
- {
- const pIdx = this.players.findIndex(pl => pl.name == p.name);
- // NOTE: id (server DB) and sid (socket ID).
- // Anonymous players just have a socket ID.
- // NOTE: for correspondance play we don't require players to be online
- // (==> we don't have IDs, and no sid)
- if (liveGame && pIdx === -1)
- return alert(p.name + " is not connected");
- p.id = this.players[pIdx].id;
- p.sid = this.players[pIdx].sid;
- }
- }
- const finishAddChallenge = (cid) => {
- chall.id = cid || "c" + getRandString();
- this.challenges.push(chall);
- // Send challenge to peers
- let challSock =
- {
- code: "newchallenge",
- chall: chall,
- target: "",
+ const sendSomethingTo = (to, code, obj) => {
+ const doSend = (code, obj, sid) => {
+ this.st.conn.send(JSON.stringify(Object.assign(
+ {},
+ {code: code},
+ obj,
+ {target: sid}
+ )));