mirror of
https://github.com/smogon/pokemon-showdown.git
synced 2026-05-05 21:17:43 -05:00
24 lines
717 B
JavaScript
24 lines
717 B
JavaScript
function createConnection (ip, workerid, socketid) {
|
|
if (!workerid || !socketid) {
|
|
workerid = Object.keys(Sockets.workers)[0];
|
|
socketid = 1;
|
|
while (Users.connections[workerid + '-' + socketid]) {
|
|
socketid++;
|
|
}
|
|
}
|
|
var connectionid = workerid + '-' + socketid;
|
|
var connection = Users.connections[connectionid] = new Users.Connection(connectionid, Sockets.workers[workerid], socketid, null, ip || '127.0.0.1');
|
|
return connection;
|
|
}
|
|
|
|
function createUser (connection) {
|
|
if (!connection) connection = createConnection();
|
|
var user = new Users.User(connection);
|
|
connection.user = user;
|
|
user.joinRoom('global', connection);
|
|
return user;
|
|
}
|
|
|
|
exports.Connection = createConnection;
|
|
exports.User = createUser;
|