Skip to content

Commit

Permalink
Sockets: Go rewrite
Browse files Browse the repository at this point in the history
WIP

Fixes smogon#2943
  • Loading branch information
Morfent committed Dec 11, 2016
1 parent e8fa447 commit 5e33476
Show file tree
Hide file tree
Showing 6 changed files with 1,338 additions and 427 deletions.
9 changes: 1 addition & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,10 @@
"preferGlobal": true,
"description": "The server for the Pokémon Showdown battle simulator",
"version": "0.10.2",
"dependencies": {
"sockjs": "0.3.18"
},
"optionalDependencies": {
"cloud-env": "0.1.1",
"http-proxy": "0.10.0",
"nodemailer": "1.4.0",
"node-static": "0.7.7"
},
"nonDefaultDependencies": {
"ofe": "0.1.2"
"nodemailer": "1.4.0"
},
"engines": {
"node": ">=6.0.0"
Expand Down
10 changes: 9 additions & 1 deletion rooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -702,11 +702,13 @@ class GlobalRoom {
}
}
onConnect(user, connection) {
console.log('connected:', user.name, this.id, connection.socketid);
let initdata = '|updateuser|' + user.name + '|' + (user.named ? '1' : '0') + '|' + user.avatar + '\n';
connection.send(initdata + this.formatListText);
if (this.chatRooms.length > 2) connection.send('|queryresponse|rooms|null'); // should display room list
}
onJoin(user, connection) {
console.log('joined:', user.name, this.id, connection.socketid);
if (!user) return false; // ???
if (this.users[user.userid]) return user;

Expand Down Expand Up @@ -1249,10 +1251,12 @@ class BattleRoom extends Room {
}
}
onConnect(user, connection) {
console.log('connected:', user.name, this.id, connection.socketid);
this.sendUser(connection, '|init|battle\n|title|' + this.title + '\n' + this.getLogForUser(user).join('\n'));
if (this.game && this.game.onConnect) this.game.onConnect(user, connection);
}
onJoin(user, connection) {
console.log('joined:', user.name, this.id, connection.socketid);
if (!user) return false;
if (this.users[user.userid]) return user;

Expand Down Expand Up @@ -1546,6 +1550,7 @@ class ChatRoom extends Room {
return message;
}
onConnect(user, connection) {
console.log('connected:', user.name, this.id, connection.socketid);
let userList = this.userList ? this.userList : this.getUserList();
this.sendUser(connection, '|init|chat\n|title|' + this.title + '\n' + userList + '\n' + this.getLogSlice(-100).join('\n') + this.getIntroMessage(user));
if (this.poll) this.poll.onConnect(user, connection);
Expand All @@ -1556,7 +1561,10 @@ class ChatRoom extends Room {
if (this.users[user.userid]) return user;

if (user.named) {
this.reportJoin('j', user.getIdentity(this.id));
// Prevents a race condition where this message would send before
// Connection#joinRoom has a chance to finish, preventing it from
// reaching users joining empty rooms.
process.nextTick(() => this.reportJoin('j', user.getIdentity(this.id)));
}

this.users[user.userid] = user;
Expand Down
Loading

0 comments on commit 5e33476

Please sign in to comment.