From 6038a309d326422f48125c22dafe0fc646970e77 Mon Sep 17 00:00:00 2001 From: oiuv Date: Wed, 4 May 2022 17:03:12 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=8C=87=E4=BB=A4=E7=BB=93?= =?UTF-8?q?=E6=9E=84=EF=BC=8C=E4=BC=98=E5=8C=96=E7=A4=BA=E4=BE=8B=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 +- cmds/{ => cmd}/area_set.c | 0 cmds/{ => cmd}/bit_test.c | 0 cmds/{ => cmd}/cat.c | 0 cmds/{ => cmd}/color.c | 0 cmds/{ => cmd}/data.c | 0 cmds/{ => cmd}/emoji.c | 0 cmds/{ => cmd}/eval.c | 0 cmds/{ => cmd}/help.c | 5 +-- cmds/{ => cmd}/hi.c | 0 cmds/{ => cmd}/loadall.c | 0 cmds/{ => cmd}/mudinfo.c | 0 cmds/{ => cmd}/quit.c | 0 cmds/{ => cmd}/tutorial.c | 0 cmds/{ => cmd}/update.c | 0 cmds/{ => cmd}/variables.c | 0 cmds/{ => cmd}/wizard.c | 0 cmds/demo/2.4.1.c | 2 +- cmds/demo/2.5.1.c | 2 +- cmds/demo/6.3.2.c | 80 ++++++++++++++++++++++++++++++++++++++ config.cfg | 2 +- inherit/living.c | 48 +++++++++++++++++++++++ inherit/user.c | 55 +++----------------------- system/object/login.c | 6 +++ system/object/user.c | 20 ++++++---- 25 files changed, 160 insertions(+), 64 deletions(-) rename cmds/{ => cmd}/area_set.c (100%) rename cmds/{ => cmd}/bit_test.c (100%) rename cmds/{ => cmd}/cat.c (100%) rename cmds/{ => cmd}/color.c (100%) rename cmds/{ => cmd}/data.c (100%) rename cmds/{ => cmd}/emoji.c (100%) rename cmds/{ => cmd}/eval.c (100%) rename cmds/{ => cmd}/help.c (92%) rename cmds/{ => cmd}/hi.c (100%) rename cmds/{ => cmd}/loadall.c (100%) rename cmds/{ => cmd}/mudinfo.c (100%) rename cmds/{ => cmd}/quit.c (100%) rename cmds/{ => cmd}/tutorial.c (100%) rename cmds/{ => cmd}/update.c (100%) rename cmds/{ => cmd}/variables.c (100%) rename cmds/{ => cmd}/wizard.c (100%) create mode 100644 cmds/demo/6.3.2.c diff --git a/README.md b/README.md index 9b1837a..98932cf 100644 --- a/README.md +++ b/README.md @@ -37,13 +37,13 @@ LPC 开发测试 LIB,配合 fluffos v2019 以上版本使用。 . ├── README.md ├── cmds 游戏指令 -│   ├── demo 教程演示指令,请输入 demo/xxx 运行 +│   ├── demo 教程演示指令 │   │   └── ... │   ├── efun 教程 efun 指令 │   │   └── ... │   ├── test 个人测试目录,你可以把自己的测试指令放在这里 │   │   └── test.c -│   └── ... +│   └── cmd 基础指令 ├── config.cfg 运行时配置文件精简版(FluffOS v2019) ├── config.ini 运行时配置文件注释版(FluffOS v2019) ├── data 存档目录 diff --git a/cmds/area_set.c b/cmds/cmd/area_set.c similarity index 100% rename from cmds/area_set.c rename to cmds/cmd/area_set.c diff --git a/cmds/bit_test.c b/cmds/cmd/bit_test.c similarity index 100% rename from cmds/bit_test.c rename to cmds/cmd/bit_test.c diff --git a/cmds/cat.c b/cmds/cmd/cat.c similarity index 100% rename from cmds/cat.c rename to cmds/cmd/cat.c diff --git a/cmds/color.c b/cmds/cmd/color.c similarity index 100% rename from cmds/color.c rename to cmds/cmd/color.c diff --git a/cmds/data.c b/cmds/cmd/data.c similarity index 100% rename from cmds/data.c rename to cmds/cmd/data.c diff --git a/cmds/emoji.c b/cmds/cmd/emoji.c similarity index 100% rename from cmds/emoji.c rename to cmds/cmd/emoji.c diff --git a/cmds/eval.c b/cmds/cmd/eval.c similarity index 100% rename from cmds/eval.c rename to cmds/cmd/eval.c diff --git a/cmds/help.c b/cmds/cmd/help.c similarity index 92% rename from cmds/help.c rename to cmds/cmd/help.c index b3b4535..e821d80 100644 --- a/cmds/help.c +++ b/cmds/cmd/help.c @@ -31,9 +31,8 @@ int main(object me, string arg) 当你输入$HIY$tutorial user$NOR$后,会解锁更多功能,你慢慢变的能看、能动、能说、能战斗。 - 另外还可以可以直接使用 efun 目录下的指令,也可以直接运行 demo 目录下的示例。具体有哪些指令和示例 -可以输入以下指令查看: - $CYN$get_dir cmds/efun$NOR$ 和 $CYN$get_dir cmds/demo$NOR$ + 另外还可以可以直接使用 efun 目录下的指令。具体有哪些指令和示例可以输入以下指令查看: + $CYN$get_dir cmds/efun$NOR$ 提示:如有疑问,可以在输入$HIY$tutorial user3$NOR$后,在线$HIC$chat 问题内容$NOR$寻求QQ群中网友的帮助。 HELP; diff --git a/cmds/hi.c b/cmds/cmd/hi.c similarity index 100% rename from cmds/hi.c rename to cmds/cmd/hi.c diff --git a/cmds/loadall.c b/cmds/cmd/loadall.c similarity index 100% rename from cmds/loadall.c rename to cmds/cmd/loadall.c diff --git a/cmds/mudinfo.c b/cmds/cmd/mudinfo.c similarity index 100% rename from cmds/mudinfo.c rename to cmds/cmd/mudinfo.c diff --git a/cmds/quit.c b/cmds/cmd/quit.c similarity index 100% rename from cmds/quit.c rename to cmds/cmd/quit.c diff --git a/cmds/tutorial.c b/cmds/cmd/tutorial.c similarity index 100% rename from cmds/tutorial.c rename to cmds/cmd/tutorial.c diff --git a/cmds/update.c b/cmds/cmd/update.c similarity index 100% rename from cmds/update.c rename to cmds/cmd/update.c diff --git a/cmds/variables.c b/cmds/cmd/variables.c similarity index 100% rename from cmds/variables.c rename to cmds/cmd/variables.c diff --git a/cmds/wizard.c b/cmds/cmd/wizard.c similarity index 100% rename from cmds/wizard.c rename to cmds/cmd/wizard.c diff --git a/cmds/demo/2.4.1.c b/cmds/demo/2.4.1.c index c4f92f5..ece2705 100644 --- a/cmds/demo/2.4.1.c +++ b/cmds/demo/2.4.1.c @@ -1,4 +1,4 @@ -int main() +int main(object me, string arg) { float f = 251; int w = 19.427; diff --git a/cmds/demo/2.5.1.c b/cmds/demo/2.5.1.c index 9668633..6507ebe 100644 --- a/cmds/demo/2.5.1.c +++ b/cmds/demo/2.5.1.c @@ -1,5 +1,5 @@ // 转义字符输出 -int main() +int main(object me, string arg) { // 字符串 write("\61\11\62\11\63\12"); diff --git a/cmds/demo/6.3.2.c b/cmds/demo/6.3.2.c new file mode 100644 index 0000000..a11d3bb --- /dev/null +++ b/cmds/demo/6.3.2.c @@ -0,0 +1,80 @@ +int main(object me, string arg) +{ + // 声明映射变量 + mapping m1, m2, m3, m; + string *keys = ({"a", "b", "c"}); + // 初始化 + m = (["name":"mudren", "age":18, "gender":"男性"]); + printf("m = %O\n", m); + // 写 + m["name"] = "雪风"; + // 增 + m["title"] = "MUD游戏菜鸟"; + // m += (["title":"MUD游戏老鸟"]); + m += (["data":([ + "hp":100, + "mp":50, + "str":50, + "def":30, + "dex":20])]); + m += (["ob": me]); + printf("m = %O\n", m); + // 删 + map_delete(m, "gender"); + map_delete(m["data"], "mp"); + // 读 + printf("m = %O\n", m); + printf("name = %O\n", m["name"]); + printf("hp = %O\n", m["data"]["hp"]); + + // 取所有键值 + printf("keys = %O\n", keys(m)); + printf("values = %O\n", values(m)); + + // 判断 undefinedp() + printf("%d\n", undefinedp(m["age"])); + printf("%d\n", nullp(m["gender"])); + printf("%O\n", m["gender"]); + + // 映射与json转换(sefun) + printf("%s\n", json_encode(m)); + + // 初始化空映射 + m = allocate_mapping(100); + printf("m = %O\n", m); + m = ([]); + printf("m = %O\n", m); + + m1 = allocate_mapping(keys, ({"一", "二", "三"})); + m2 = allocate_mapping(keys, "mud"); + m3 = allocate_mapping(keys, (: repeat_string($1, 5) :)); + printf("m1 = %O\n", m1); + printf("m2 = %O\n", m2); + printf("m3 = %O\n", m3); + + // 运算 + m1 = ([]); + m2 = ([]); + m1["driver"] = "mudos"; + m2["mudos"] = "fluffos"; + m3 = m1 + m2; + printf("m3 = %O\n", m3); + m3 = m1 * m2; + printf("m3 = %O\n", m3); + + // copy + m2 = m1; + m3 = copy(m1); + printf("m1 = %O\n", m1); + m2["mudos"] = "fluffos"; + printf("m1 = %O\n", m1); + printf("m3 = %O\n", m3); + + // 关于映射中的键 + m[0] = "test"; + m[me] = "test"; + m[keys] = "test"; + printf("m = %O\n", m); + + return 1; +} diff --git a/config.cfg b/config.cfg index 553b284..88ca9b8 100644 --- a/config.cfg +++ b/config.cfg @@ -7,7 +7,7 @@ master file : /system/kernel/master simulated efun file : /system/kernel/simul_efun global include file : debug log file : debug.log -external_port_1 : telnet 4000 +external_port_1 : telnet 4004 external_port_2 : websocket 80 ; external_port_3 : websocket 443 ; external_port_3_tls : cert=cert.crt key=cert.key diff --git a/inherit/living.c b/inherit/living.c index c5f7782..dd8c464 100644 --- a/inherit/living.c +++ b/inherit/living.c @@ -2,6 +2,11 @@ inherit OBJECT; inherit VERB; +#define CMD_PATH "/cmds/cmd/" +#define DEMO_PATH "/cmds/demo/" +#define EFUN_PATH "/cmds/efun/" +#define TEST_PATH "/cmds/test/" + int is_living() { return 1; } void set_living(string id) @@ -12,6 +17,7 @@ void set_living(string id) set_living_name(id); seteuid(id); } + add_action("command_hook", "", 1); } // NPC消息界面 catch_tell() @@ -25,3 +31,45 @@ int command(string cmd) { return efun::command(cmd); } + +nomask int command_hook(string arg) +{ + string verb, cmd, test, efun_cmd, demo; + object me, cmd_ob; + + verb = query_verb(); + cmd = CMD_PATH + verb; + test = TEST_PATH + verb; + efun_cmd = EFUN_PATH + verb; + demo = DEMO_PATH + verb; + me = this_object(); + + if ((verb = trim(verb)) == "") + return 0; + + if (!arg && (objectp(environment()) && environment()->query("exits/" + verb))) + { + me->command("go " + verb); + } + else if (cmd_ob = load_object(cmd) || cmd_ob = load_object(test) || cmd_ob = load_object(efun_cmd) || cmd_ob = load_object(demo)) + { + return (int)cmd_ob->main(me, arg); + } + else + { + mixed err = parse_sentence(arg ? verb + " " + arg : verb, 0); + if (intp(err)) + { + switch (err) + { + case 1: // verb 匹配成功 + return 1; + default: + return 0; + } + } + return notify_fail(err); + } + + return 1; +} diff --git a/inherit/user.c b/inherit/user.c index c440a18..1df05a2 100644 --- a/inherit/user.c +++ b/inherit/user.c @@ -1,18 +1,13 @@ /* * @Author: 雪风@mud.ren * @Date: 2022-03-31 15:04:35 - * @LastEditTime: 2022-04-03 17:09:48 + * @LastEditTime: 2022-05-04 15:56:29 * @LastEditors: 雪风 * @Description: 自定义 user 对象 * https://bbs.mud.ren */ inherit LIVING; -#define CMD_PATH "/cmds/" -#define TEST_PATH "/cmds/test/" -#define EFUN_PATH "/cmds/efun/" -#define DEMO_PATH "/cmds/demo/" - varargs void create(string arg) { if (clonep()) @@ -24,7 +19,6 @@ varargs void create(string arg) set_living(arg); set("gender", random(2) ? "男" : "女"); set("name", element_of(name1) + element_of(name2)); - add_action("command_hook", "", 1); move_object(START_ROOM); } else @@ -36,48 +30,6 @@ varargs void create(string arg) } } -nomask int command_hook(string arg) -{ - string verb, cmd, test, efun_cmd, demo; - object me, cmd_ob; - - verb = query_verb(); - cmd = CMD_PATH + verb; - test = TEST_PATH + verb; - efun_cmd = EFUN_PATH + verb; - demo = DEMO_PATH + verb; - me = this_object(); - - if ((verb = trim(verb)) == "") - return 0; - - if (!arg && (objectp(environment()) && environment()->query("exits/" + verb))) - { - me->command("go " + verb); - } - else if (cmd_ob = load_object(cmd) || cmd_ob = load_object(test) || cmd_ob = load_object(efun_cmd) || cmd_ob = load_object(demo)) - { - return (int)cmd_ob->main(me, arg); - } - else - { - mixed err = parse_sentence(arg ? verb + " " + arg : verb, 0); - if (intp(err)) - { - switch (err) - { - case 1: // verb 匹配成功 - return 1; - default: - return 0; - } - } - return notify_fail(err); - } - - return 1; -} - int move_or_destruct(object dest) { debug("突然一阵时空扭曲,你被传送到虚空。"); @@ -85,3 +37,8 @@ int move_or_destruct(object dest) return 1; } + +void net_dead() +{ + destruct(); +} diff --git a/system/object/login.c b/system/object/login.c index 37e8fed..ab113d7 100644 --- a/system/object/login.c +++ b/system/object/login.c @@ -34,3 +34,9 @@ void logon() write("请输入你的ID:"); input_to("setup"); } + +void net_dead() +{ + debug_message(ctime() + " net_dead " + query_ip_number()); + destruct(); +} diff --git a/system/object/user.c b/system/object/user.c index a350194..cb88d23 100644 --- a/system/object/user.c +++ b/system/object/user.c @@ -1,8 +1,7 @@ -#define CMD_PATH "/cmds/" +#define CMD_PATH "/cmds/cmd/" +#define DEMO_PATH "/cmds/demo/" #define TEST_PATH "/cmds/test/" -int command_hook(string arg); - varargs void create(string arg) { if (clonep()) @@ -17,13 +16,15 @@ varargs void create(string arg) int command_hook(string arg) { - string cmd, test; + string verb, cmd, demo, test; object cmd_ob; - cmd = CMD_PATH + query_verb(); - test = TEST_PATH + query_verb(); + verb = query_verb(); + cmd = CMD_PATH + verb; + demo = DEMO_PATH + verb; + test = TEST_PATH + verb; - if (cmd_ob = load_object(cmd) || cmd_ob = load_object(test)) + if (cmd_ob = load_object(cmd) || cmd_ob = load_object(test) || cmd_ob = load_object(demo)) { return (int)cmd_ob->main(this_object(), arg); } @@ -32,3 +33,8 @@ int command_hook(string arg) return notify_fail("指令不存在,你可以输入 tutorial 寻求帮助。\n"); } } + +void net_dead() +{ + destruct(); +}