init: add workspace files
This commit is contained in:
24
world/cmd/admin/call.js
Normal file
24
world/cmd/admin/call.js
Normal file
@@ -0,0 +1,24 @@
|
||||
this.inherits(COMMAND);
|
||||
this.command = "call";
|
||||
this.allow_busy = true;
|
||||
this.allow_state = true;
|
||||
this.allow_die = true;
|
||||
this.allow_faint = true;
|
||||
this.allow_level = 6;
|
||||
this.regex = /^(?:(\w+)\s)?(.+)$/;
|
||||
this.enter = function (me, target, arg) {
|
||||
try {
|
||||
var func = new Function(arg);
|
||||
var player = me;
|
||||
if (target) {
|
||||
player = WORLD.getUser(target);
|
||||
if (!player) return me.notify("没有这个玩家");
|
||||
}
|
||||
func.call(player);
|
||||
//me.recount();
|
||||
me.notify("ok");
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
me.notify("error:" + e);
|
||||
}
|
||||
}
|
||||
32
world/cmd/admin/notice.js
Normal file
32
world/cmd/admin/notice.js
Normal file
@@ -0,0 +1,32 @@
|
||||
this.inherits(COMMAND);
|
||||
this.command = "notice";
|
||||
this.allow_busy = true;
|
||||
this.allow_state = true;
|
||||
this.allow_die = true;
|
||||
this.allow_level = 1;
|
||||
const MESSAGE = WORLD.MESSAGE;
|
||||
this.enter = function (me, arg) {
|
||||
var nt = {
|
||||
content: arg,
|
||||
time: Date.now()
|
||||
};
|
||||
MESSAGE.NOTICES.push(nt);
|
||||
var item = {
|
||||
type: "dialog", dialog: "message", message: {
|
||||
time: nt.time,
|
||||
content: nt.content,
|
||||
id: "notice",
|
||||
name: "系统公告"
|
||||
}
|
||||
};
|
||||
var str = JSON.stringify(item);
|
||||
WORLD.sendAll(str);
|
||||
}
|
||||
|
||||
this.updatelast = function (me) {
|
||||
MESSAGE.NOTICES[MESSAGE.NOTICES.length - 1].content = `
|
||||
古大陆妖族营地在每周快速完成后,仍可以继续手动击杀,直到每周上限。
|
||||
降低营地1刷新速度10秒,其他营地暂时关闭
|
||||
`;
|
||||
me.send(MESSAGE.NOTICES[MESSAGE.NOTICES.length - 1].content);
|
||||
}
|
||||
20
world/cmd/admin/recover.js
Normal file
20
world/cmd/admin/recover.js
Normal file
@@ -0,0 +1,20 @@
|
||||
this.inherits(COMMAND);
|
||||
this.command = "recover";
|
||||
this.allow_busy = true;
|
||||
this.allow_state = true;
|
||||
this.allow_die = true;
|
||||
this.admin = true;
|
||||
this.regex = /^(.+?)(?:\s(\w+))?$/;
|
||||
this.allow_level = 2;
|
||||
this.enter = function (me, userid, objid) {
|
||||
|
||||
}
|
||||
|
||||
this.clear = function (user) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
this.add_obj = function (me, obj, type, key) {
|
||||
|
||||
}
|
||||
71
world/cmd/admin/send.js
Normal file
71
world/cmd/admin/send.js
Normal file
@@ -0,0 +1,71 @@
|
||||
this.inherits(COMMAND);
|
||||
this.command = "send";
|
||||
this.allow_busy = true;
|
||||
this.allow_state = true;
|
||||
this.allow_die = true;
|
||||
|
||||
this.regex = /^(\w+)\s(.+)$/;
|
||||
this.enter = function (me, user, arg) {
|
||||
if (me && me.allow_level < 5) return false;
|
||||
if (!arg) return me && me.send("没有消息内容。");
|
||||
var msg;
|
||||
var is_str = typeof arg == "string";
|
||||
if (is_str && arg[0] != "{") {
|
||||
msg = { content: arg, time: Date.now() };
|
||||
} else {
|
||||
msg = is_str ? JSON.toObject(arg) : arg;
|
||||
if (!msg.content || !msg.attach) return me && me.send("格式错误。");
|
||||
msg.time = Date.now();
|
||||
for (var i = 0; i < msg.attach.length; i++) {
|
||||
let attach = msg.attach[i];
|
||||
var obj = OBJ.CREATE(attach.obj, attach.count);
|
||||
if (obj) {
|
||||
attach.name = obj.unit_name(attach.count);
|
||||
}
|
||||
}
|
||||
}
|
||||
var users = [];
|
||||
if (user == "all") {
|
||||
users = WORLD.USERS;
|
||||
} else {
|
||||
var player = WORLD.getUser(user);
|
||||
if (!player) player = { id: user };
|
||||
users.push(player);
|
||||
}
|
||||
|
||||
var obj = {};
|
||||
obj.type = "dialog";
|
||||
obj.dialog = "message";
|
||||
obj.message = {
|
||||
id: msg.from || "system",
|
||||
name: msg.from_name || "系统",
|
||||
content: msg.content,
|
||||
time: msg.time,
|
||||
attach: msg.attach
|
||||
};
|
||||
for (var i = 0; i < users.length; i++) {
|
||||
let user_msg = {
|
||||
time: msg.time,
|
||||
content: msg.content,
|
||||
attach: msg.attach
|
||||
};
|
||||
let mail_type = obj.message.id;
|
||||
WORLD.MESSAGE.pushUserMessage(users[i].id, {
|
||||
id: mail_type, name: obj.message.name
|
||||
}, user_msg);
|
||||
obj.message.index = user_msg.index;
|
||||
if (users[i].socket) users[i].send(JSON.stringify(obj));
|
||||
if (RECORD[mail_type]) {
|
||||
WORLD.log(users[i], mail_type, msg.content);
|
||||
}
|
||||
}
|
||||
me && me.notify("发送完成,共发送" + users.length);
|
||||
|
||||
}
|
||||
|
||||
|
||||
const RECORD = {
|
||||
top: true,
|
||||
score: true,
|
||||
weapon: true
|
||||
};
|
||||
27
world/cmd/admin/shutdown.js
Normal file
27
world/cmd/admin/shutdown.js
Normal file
@@ -0,0 +1,27 @@
|
||||
this.inherits(COMMAND);
|
||||
this.command = "shutdown";
|
||||
this.allow_busy = true;
|
||||
this.allow_state = true;
|
||||
this.allow_die = true;
|
||||
this.allow_level = 6;
|
||||
this.handler = 0;
|
||||
this.enter = function (me, arg) {
|
||||
if (arg == "stop") {
|
||||
if (this.handler) {
|
||||
clearInterval(this.handler);
|
||||
WORLD.sendAll("<hic>服务器停止维护,谢谢大家支持。</hic>");
|
||||
}
|
||||
return;
|
||||
}
|
||||
WORLD.sendAll("<hir>服务器将要关闭维护,各位玩家请处理好自己的游戏状态。</hir>");
|
||||
|
||||
this.handler = this.call_interval(function (count) {
|
||||
WORLD.sendAll("<red>还有" + (100 - count * 10) + "秒后服务器将关闭维护,请处理好自己的游戏状态。</red>");
|
||||
|
||||
}, 10000, 10, function () {
|
||||
WORLD.sendAll("<red>服务器关闭。</red>");
|
||||
|
||||
WORLD.close();
|
||||
// WORLD.LISTENER.tcpServer._events.connection = null;
|
||||
});
|
||||
}
|
||||
120
world/cmd/admin/update.js
Normal file
120
world/cmd/admin/update.js
Normal file
@@ -0,0 +1,120 @@
|
||||
this.inherits(COMMAND);
|
||||
this.command = "update";
|
||||
this.allow_busy = true;
|
||||
this.allow_state = true;
|
||||
this.allow_die = true;
|
||||
this.allow_level = 6;
|
||||
|
||||
this.enter = function (me, arg) {
|
||||
try {
|
||||
if (!arg) return this.notify(me, "路径不合理");
|
||||
if (arg === 'room') {
|
||||
return this.update_room(me);
|
||||
} else if (arg === 'npc') {
|
||||
return this.update_npc(me);
|
||||
}
|
||||
arg = arg.replace(/\\/g, "/");
|
||||
if (arg.startsWith("doc/")) return;
|
||||
var index = arg.indexOf("/");
|
||||
if (index == -1) return this.notify(me, "路径不合理");
|
||||
var path = __PATH.WORLD + arg.substr(0, index + 1);
|
||||
var fname = arg.substr(index + 1);
|
||||
BASE.UPDATE(path, fname);
|
||||
this.notify(me, arg + "已更新。");
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
this.notify(me, "error:" + e);
|
||||
}
|
||||
}
|
||||
this.notify = function (me, msg) {
|
||||
if (me) return me.notify(msg);
|
||||
console.log(msg);
|
||||
}
|
||||
this.update_npc = function (me, path) {
|
||||
this.enter(me, "npc/" + path);
|
||||
let npc = me.environment.find_obj_bypath(path);
|
||||
if (npc) {
|
||||
npc.destroy();
|
||||
NPC.CREATE(path, me.environment);
|
||||
}
|
||||
let map = WORLD.NPC_STROE;
|
||||
npc = map.get(path);
|
||||
if (!npc.on_create) return;
|
||||
let keys = map.keys();
|
||||
path = path + "#";
|
||||
for (let key of keys) {
|
||||
if (key.startsWith(path)) {
|
||||
map.delete(key);
|
||||
me.send('delete' + key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.update_obj = function (me, path) {
|
||||
this.enter(me, "obj/" + path);
|
||||
let map = WORLD.OBJ_STROE;
|
||||
let obj = map.get(path);
|
||||
if (!obj.on_create) return;
|
||||
let keys = map.keys();
|
||||
path = path + "#";
|
||||
for (let key of keys) {
|
||||
|
||||
if (key.startsWith(path)) {
|
||||
map.delete(key);
|
||||
me.send('delete' + key);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
this.update_room = function () {
|
||||
|
||||
}
|
||||
if (WORLD.COMMANDS.update && WORLD.COMMANDS.update.clear_update) {
|
||||
WORLD.COMMANDS.update.clear_update();
|
||||
}
|
||||
this.clear_update = function () {
|
||||
if (this.update_hander)
|
||||
clearTimeout(this.update_hander);
|
||||
this.update_time = null;
|
||||
console.log('clear timeout');
|
||||
}
|
||||
this.wait_update = function (me, upd_time) {
|
||||
if (!upd_time) return me.send('没有设置更新时间');
|
||||
if (typeof upd_time === 'string') {
|
||||
upd_time = new Date(upd_time);
|
||||
}
|
||||
let time = upd_time - Date.now();
|
||||
if (!(time > 10000))
|
||||
return me.send('更新时间不能小于当前时间');
|
||||
this.update_hander = this.call_out(this.on_update, time);
|
||||
this.update_time = upd_time;
|
||||
this.format_time(me, this.update_time);
|
||||
}
|
||||
this.format_time = function (me, time) {
|
||||
|
||||
let str = ['已设置', time.toLocaleString(), '更新,在'];
|
||||
time = time - Date.now();
|
||||
if (time > 3600000) {
|
||||
str.push(Math.floor(time / 3600000), "小时");
|
||||
time = time % 3600000;
|
||||
}
|
||||
if (time > 60000) {
|
||||
str.push(Math.floor(time / 60000), "分钟");
|
||||
time = time % 60000;
|
||||
}
|
||||
time = Math.floor(time / 1000);
|
||||
str.push(time, '秒后');
|
||||
me.send(str.join(""));
|
||||
}
|
||||
this.on_update = function () {
|
||||
this.update_hander = null;
|
||||
this.update_time = null;
|
||||
}
|
||||
|
||||
this.wait = function (me) {
|
||||
let task = TASK.GET('time');
|
||||
let updtime = new Date(2026, 1, 15, 12);
|
||||
let time = updtime.getTime() - Date.now();
|
||||
task.handler = task.call_out(task.run2, time);
|
||||
this.format_time(me, updtime);
|
||||
}
|
||||
11
world/cmd/admin/user.js
Normal file
11
world/cmd/admin/user.js
Normal file
@@ -0,0 +1,11 @@
|
||||
|
||||
this.inherits(COMMAND);
|
||||
this.command = "user";
|
||||
this.allow_busy = true;
|
||||
this.allow_state = true;
|
||||
this.allow_die = true;
|
||||
this.allow_level = 3;
|
||||
const num_reg = /\d+/;
|
||||
this.enter = function (me, arg) {
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user