1
0
Fork 0

Merge pull request #43 from Deardrops/rename-room

rename room by edit room name
This commit is contained in:
webxoss 2017-05-23 00:30:54 +08:00 committed by GitHub
commit 4b384f1b9d
3 changed files with 43 additions and 3 deletions

View file

@ -75,6 +75,7 @@ RoomManager.prototype.createClient = function (socket,id) {
socket.on('getReplayList',this.getReplayList.bind(this,client));
socket.on('getReplayContent',this.getReplayContent.bind(this,client));
socket.on('watchLive',this.watchLive.bind(this,client));
socket.on('renameRoom',this.renameRoom.bind(this,client));
socket.on('ready',client.ready.bind(client));
socket.on('unready',client.unready.bind(client));
@ -83,7 +84,6 @@ RoomManager.prototype.createClient = function (socket,id) {
socket.on('surrender',client.surrender.bind(client));
socket.on('drop',client.drop.bind(client));
socket.on('tick',client.tick.bind(client));
// socket.on('reloadCardInfo',this.reloadCardInfo.bind(this));
socket.emit('version',this.VERSION);
@ -211,6 +211,36 @@ RoomManager.prototype.checkLiveIP = function (client,room) {
if (address === guestAddress) return 'IP_BANNED';
};
RoomManager.prototype.renameRoom = function (client,cfg) {
var errMsg;
if (!isObj(cfg) || !isStr(cfg.roomName)) {
errMsg = 'INVALID_CONFIG';
}
var oldRoomName = client.room.name;
var newRoomName = cfg.roomName;
if (!errMsg) {
errMsg = this.checkRoomName(newRoomName);
}
var room;
if (!errMsg) {
room = this.roomMap[oldRoomName];
if (!room) {
errMsg = 'ROOM_DOES_NOT_EXIST';
} else if (client.getPosition() !== 'host') {
errMsg = 'YOU_ARE_NOT_ROOM_HOST';
}
}
if (errMsg) {
client.socket.emit('error message',errMsg);
return;
}
room.name = newRoomName;
renameProperty(this.roomMap, oldRoomName, newRoomName);
room.update();
this.updateRoomList();
};
RoomManager.prototype.createRoom = function (client,cfg) {
var errMsg;
if (!isObj(cfg) || !isStr(cfg.roomName) || !isStr(cfg.nickname)) {

12
util.js
View file

@ -33,4 +33,14 @@ global.isFunc = function (v) {
// function nextTick (callback) {
// setTimeout(callback,0);
// }
// }
global.renameProperty = function (obj, oldName, newName) {
if (!obj.hasOwnProperty(oldName) || obj.hasOwnProperty(newName)) {
return false;
} else if (oldName === newName) {
return true;
}
obj[newName] = obj[oldName];
delete obj[oldName];
};

@ -1 +1 @@
Subproject commit c6bfbf136d077c19ad88b3abd2af41d684014d05
Subproject commit 51a710f84c2931e55ca71009ad469468b5662863