forked from mirrors/webxoss-core
rename room by editing room name
This commit is contained in:
parent
66777f6dcc
commit
2f817654b3
3 changed files with 43 additions and 3 deletions
|
@ -75,6 +75,7 @@ RoomManager.prototype.createClient = function (socket,id) {
|
||||||
socket.on('getReplayList',this.getReplayList.bind(this,client));
|
socket.on('getReplayList',this.getReplayList.bind(this,client));
|
||||||
socket.on('getReplayContent',this.getReplayContent.bind(this,client));
|
socket.on('getReplayContent',this.getReplayContent.bind(this,client));
|
||||||
socket.on('watchLive',this.watchLive.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('ready',client.ready.bind(client));
|
||||||
socket.on('unready',client.unready.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('surrender',client.surrender.bind(client));
|
||||||
socket.on('drop',client.drop.bind(client));
|
socket.on('drop',client.drop.bind(client));
|
||||||
socket.on('tick',client.tick.bind(client));
|
socket.on('tick',client.tick.bind(client));
|
||||||
|
|
||||||
// socket.on('reloadCardInfo',this.reloadCardInfo.bind(this));
|
// socket.on('reloadCardInfo',this.reloadCardInfo.bind(this));
|
||||||
|
|
||||||
socket.emit('version',this.VERSION);
|
socket.emit('version',this.VERSION);
|
||||||
|
@ -211,6 +211,36 @@ RoomManager.prototype.checkLiveIP = function (client,room) {
|
||||||
if (address === guestAddress) return 'IP_BANNED';
|
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) {
|
RoomManager.prototype.createRoom = function (client,cfg) {
|
||||||
var errMsg;
|
var errMsg;
|
||||||
if (!isObj(cfg) || !isStr(cfg.roomName) || !isStr(cfg.nickname)) {
|
if (!isObj(cfg) || !isStr(cfg.roomName) || !isStr(cfg.nickname)) {
|
||||||
|
|
10
util.js
10
util.js
|
@ -34,3 +34,13 @@ global.isFunc = function (v) {
|
||||||
// function nextTick (callback) {
|
// function nextTick (callback) {
|
||||||
// setTimeout(callback,0);
|
// 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
|
Loading…
Reference in a new issue