Code Monkey home page Code Monkey logo

go-mud's Introduction

GoMud

Go 语言写的,支持 UTF-8 的中文 MUD 客户端

如何使用如何安装如何配置常见问题

最新版本 Release workflow Build workflow Go Report pre-commit

本项目实现目标是一个 MUD 客户端,主要采用 Go 语言实现。

本项目基于**知名 MUD 游戏《北大侠客行》开发,但也应该可以适用于其它 MUD 服务。

什么是 MUD

MUD(/mʌd/, 参见维基百科),原指多用户地牢(Multi-User Dungeon), 通常将缩写直译为“网络泥巴”或是简称“泥巴”(英文 mud 的意思为泥巴)。

MUD 是一种多人即时的虚拟世界,通常以文字描述为基础。其中结合了角色扮演江湖互动小说在线聊天等元素,玩家可以阅读或查看房间、物品、其他玩家、非玩家角色的描述,并在虚拟世界中做特定动作。玩家通常会透过输入类似自然语言的指令(如drink, eat, bow)来与虚拟世界中的物品或其他玩家交互。

MUD 一般认为是最早的网络游戏,历史悠久,内涵丰富。在古朴的终端界面下,通过阅读文字展开想象,来构筑一个庞大的虚拟世界,因此富有独特的魅力。

什么是北大侠客行

北大侠客行(以下称北侠)于 1996 年开服,至今仍在运营,算是国内运行非常长的网络游戏了。 而且这些年一直都有更新,实属难能可贵。

基于 MUD 特有的文化,挂机在北侠也是被允许的,而在 MUD 下开发挂机程序也是一种别有风味的玩法。

GoMud 有什么用

GoMud 是一个 MUD 客户端,可以用来连接 MUD 服务器,提供纯文本的用户界面,以供玩家与 MUD 服务器交互。

GoMud 目前仍在开发当中,并不完善。 但已经能够提供必要的功能来连接 MUD 服务器。且有许多亮点:

  • 全程使用 UTF-8,天生免疫乱码
  • 支持运行有 GB2312/GBK/GB18030/BIG5/UTF-16/UTF-8 编码的 MUD 服务器
  • 纯文本界面,通过命令行和快捷键来操作
  • 支持 macOS、Linux、Windows、安卓四大平台
  • 支持路由器树莓派群晖电视机等小众平台
  • 支持 32 位和 64 位操作系统
  • 支持 Lua 机器人

GoMud 不能做什么

  • 不支持图形界面,没有丰富的代码编辑框或诸如此类的其它 UI 元素来帮助你写触发和机器人
  • 没有庞大的用户群,没有大量开箱即用的机器人,对伸手党不友好
  • 不能帮助没有丰富的计算机操作经验,特别是 *nix 命令行操作经验的人熟悉 *nix
  • 不能帮助没有编程经验或者没有学习过 Go 语言的人学会编程、学会 Go 语言

如何使用 GoMud

运行环境

  • GoMud 可在 Linux、macOS 及 Windows 上运行。运行时不依赖其它软件。
  • 通过 Termux 的帮助,GoMud 也可以在安卓下运行。你可以在运行安卓系统的手机或者电视机上使用 GoMud。
  • GoMud 也可以在群晖 NAS、运行有 OpenWRT 等 Linux 系统的智能路由器,或者树莓派上运行。

安装指南

本项目的发布页面 中包含了所有支持平台的预编译安装包,你可以根据自己的需要选择下载。

macOS 快速安装

macOS 用户推荐使用 Homebrew 来安装。如果你没用过它,不如趁此机会安装体验一下。

brew tap mudclient/tap
brew install go-mud

Termux 快速安装

运行了安卓系统的手机、平板电脑、电视机通过 Termux 也可以使用 GoMud,安装方法如下:

wget https://github.com/mudclient/go-mud/releases/download/v0.6.1/go-mud_v0.6.1_Termux_ARMv7.deb
apt install ./go-mud_v0.6.1_Termux_ARMv7.deb

以上命令以 ARMv7 架构上 v0.6.1 版本的为例, 其它版本及架构请前往发布页面选择相应的预编译安装包。 如果你不知道自己设备的 CPU 架构,可以通过 uname -m 命令获知。

手动安装

本项目的发布页面中包含了所有支持平台的预编译可执行文件。 各平台的可执行文件名称略有不同,你可以下载和你的运行环境相对应的版本。 GoMud 支持的平台非常丰富,限于篇幅,此处不再赘述。 更多内容请查看支持平台与安装指南

通过源码安装

GoMud 采用 Go 语言实现,如果你要通过源码安装,则需要自行准备 Golang 开发环境。 推荐使用 Go 1.13 或以上的版本。Golang 安装完毕后,通过如下命令序列即可安装:

git clone https://github.com/mudclient/go-mud.git
cd go-mud
go generate ./...
go build

启动并进入北侠

下述示例中的程序文件名假定为 go-mud,如果你采用的是预编译的可执行文件, 你可能需要下载后改名或者将下述命令中的程序文件名替换为真实的程序文件名称。

$ go-mud
初始化 Lua 环境...
Lua 环境初始化完成。
连接到服务器 mud.pkuxkx.net:8080...连接成功。
...

配置 GoMud

GoMud 支持通过配置文件或者命令行选项的方式来指定程序运行参数, 目前已有的命令行选项如下:

$ go-mud --help       # 可以获得使用帮助
GoMud(version v0.6.1)

Usage:
  go-mud [flags]

Flags:
  -c, --config FILENAME            config FILENAME, default to `config.yaml` or `config.json`
      --version                    just print version number only
  -h, --help                       show this message
      --gen-yaml                   generate config.yaml
      --gen-json                   generate config.json
      --ui.ambiguouswidth string   二义性字符宽度,可选值: auto/single/double/space (default "auto")
      --ui.historylines int        历史记录保留行数 (default 100000)
      --ui.rttvheight int          历史查看模式下实时文本区域高度 (default 10)
  -H, --mud.host IP/Domain         服务器 IP/Domain (default "mud.pkuxkx.net")
  -P, --mud.port Port              服务器 Port (default 8080)
      --mud.encodings Encodings    服务器的 Encodings,允许指定多个,用逗号分隔 (default "UTF-8,GB18030,GBK,GB2312")
      --lua.enable                 是否加载 Lua 机器人 (default true)
  -p, --lua.path path              Lua 插件路径 path (default "lua")

配置文件同时支持 YAMLJSON 两种格式, 两种配置文件效果是一样的,用户可根据个人偏好选择使用,下面分别给出示例。 配置项的说明参见配置与运行

config.yaml 示例

默认的 YAML 配置文件名为 config.yaml,如果省略配置文件,等同默认内容如下:

UI:
  AmbiguousWidth: auto
  HistoryLines: 100000
  RTTVHeight: 10
MUD:
  Host: mud.pkuxkx.net
  Port: 8080
  Encodings: UTF-8,GB18030,GBK,GB2312
Lua:
  Enable: true
  Path: lua

config.json 示例

默认的 JSON 配置文件名为 config.json,如果省略配置文件,等同默认内容如下:

{
  "UI": {
    "AmbiguousWidth": "auto",
    "HistoryLines": 100000,
    "RTTVHeight": 10
  },
  "Mud": {
    "Host": "mud.pkuxkx.net",
    "Port": 8080,
    "Encodings": "UTF-8,GB18030,GBK,GB2312"
  },
  "Lua": {
    "Enable": true,
    "Path": "lua"
  }
}

通过 Docker 来启动

GoMud 也可支持通过 Docker 来运行,推荐使用 Docker 来挂机。

待完善

如何贡献

  • 体验并向周围的人分享你的体验结果
  • 通过提交 issue 来反馈意见
  • 通过 PR 来贡献代码,贡献代码时请先阅读贡献指南

go-mud's People

Contributors

defsky avatar dzpao avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

go-mud's Issues

新函数需求

为了支持在Lua下对客户端的扩展操作,需要 gomud 提供以下功能的函数:

  1. 获取 gomud 所在安装目录的绝对路径 - 便于在 Lua 中读写 gomud 目录下的文件
  2. 获取 gomud 所在终端的尺寸(宽高值)- 便于 Lua 输出格式化根据显示窗口大小动态调整
  3. 支持文字和背景颜色设置的 Print()

实现一门脚本语言

如果没有脚本语言,特别是能够在命令行下即时使用的脚本语言,那么手动玩家就很难使用。

这门语言最好能够兼容 TinTin,目前这套语法还是比较流行。
光 lua 不行,lua 会的人很少、使用门槛比较高不说,就算是会写,写起机器来也不够简洁。

/reload-lua 功能报错

重新加载 Lua 的功能可以成功实现,但在加载后会有个小报错:
Lua 环境已关闭。
初始化 Lua 环境...
Lua 环境初始化完成。
Error: %!s()

当使用 Ctrl+C 结束回滚分屏时,优先调用了终端的 Ctrl+C 效果,直接退出 gomud

重现方法:
启动go-mud连接服务器,exit退回终端,重复多次后在游戏界面输入 Ctrl+C

$ ~/go-mud/go-mud --mud.encoding GBK -c ~/go-mud/profile/JHL/config.json
$ ~/go-mud/go-mud --mud.encoding GBK -c ~/go-mud/profile/JHL/config.json
$ ~/go-mud/go-mud --mud.encoding GBK -c ~/go-mud/profile/JHL/config.json
panic: runtime error: slice bounds out of range [-3:] [recovered]
panic: runtime error: slice bounds out of range [-3:]

goroutine 10 [running]:
github.com/rivo/tview.(*Application).Run.func1(0xc000106580)
github.com/rivo/[email protected]/application.go:149 +0x82
panic(0x162c400, 0xc000528000)
runtime/panic.go:679 +0x1b2
github.com/mudclient/go-mud/ui.(*UI).stopScrolling(0xc0000b6580)
github.com/mudclient/go-mud@/ui/ui.go:239 +0x235
github.com/mudclient/go-mud/ui.(*UI).InputCapture(0xc0000b6580, 0xc0002a6000, 0xc000106580)
github.com/mudclient/go-mud@/ui/ui.go:118 +0x5d
github.com/rivo/tview.(*Application).Run(0xc000106580, 0x0, 0x0)
github.com/rivo/[email protected]/application.go:219 +0x486
github.com/mudclient/go-mud/ui.(*UI).Run(0xc0000b6580)
github.com/mudclient/go-mud@/ui/ui.go:197 +0x67
created by main.(*Client).Run
github.com/mudclient/go-mud@/main.go:66 +0x202

0.51 arm64版本运行异常

异常后shell错位,无法键入命令

命令: panic: runtime error: invalid memory address or nil pointer dereference                                                                                   [signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x166870]

                                                                 goroutine 24 [running]:
     github.com/yuin/gopher-lua.(*LState).metatable(0x400009e820, 0x0, 0x0, 0x1b201, 0x4000056d01, 0x0)
                        /Users/flw/.go/src/github.com/yuin/gopher-lua/state.go:630 +0x250
      github.com/yuin/gopher-lua.(*LState).metaOp1(0x400009e820, 0x0, 0x0, 0x29dc6a, 0x6, 0x0, 0x2)
                        /Users/flw/.go/src/github.com/yuin/gopher-lua/state.go:649 +0x40
     github.com/yuin/gopher-lua.(*LState).metaCall(0x400009e820, 0x0, 0x0, 0x40002ec1e0, 0x4a)
                /Users/flw/.go/src/github.com/yuin/gopher-lua/state.go:677 +0x64
                                                                                github.com/yuin/gopher-lua.(*LState).callR(0x400009e820, 0x2, 0x0, 0x0)
                                                                        /Users/flw/.go/src/github.com/yuin/gopher-lua/state.go:859 +0x8c
                                                     github.com/yuin/gopher-lua.(*LState).Call(...)
                        /Users/flw/.go/src/github.com/yuin/gopher-lua/state.go:1613                                                                                  github.com/yuin/gopher-lua.(*LState).CallByParam(0x400009e820, 0x0, 0x0, 0x0, 0x0, 0x0, 0x4000056ed0, 0x2, 0x2, 0x50, ...)
                                        /Users/flw/.go/src/github.com/yuin/gopher-lua/state.go:1696 +0x154
                       main.(*LuaRobot).OnReceive(0x4000114630, 0x40000aa2d0, 0x4a, 0x40002ec230, 0x4a)
                        /Users/flw/code/git/github/go-mud/main.go:120 +0xec
                                                                           main.main.func2(0x4000095260)
                        /Users/flw/code/git/github/go-mud/main.go:335 +0x198
                                                                            created by main.main
                /Users/flw/code/git/github/go-mud/main.go:330 +0x288

连接utf8站点乱码

是要在config里配置什么选项吗?我默认连上是乱码,用tt++或者putty是可以的

Help junior users to create/transfer the correct #action

Some sentenses may be difficult for junior users to make Actions. I sugguest to add a new function to help junior users to create/transfer the correct #action. For example:
[original sentense]
陆乘风说道:请姑娘代替本座于5日后前往苏州沧浪亭抓那个杀手。
Users want to catch the key variables of the designed job as follows:
#action { 陆乘风说道:请%1代替本座于%2日后前往%3抓那个%4。 }
Suppose that, as a very beginner of a mud player, I don't know how to write this action. However, I will be very grateful if there is a COMMAND which can transfer the sentense to the correct action, e.g. a COMMAND named #transaction will transfer all things in {} to thee correct way:
#transaction { 陆乘风说道:请{姑娘}代替本座于{5}日后前往{苏州沧浪亭}抓那个{杀手}。 };
will generate
#action { 陆乘风说道:请{\S}代替本座于{\d}日后前往{\S}抓那个{\S}。 } {do sth};
I think this function, no matter in what way it is created, will be very popular esp. with the junior users.

version v0.6.1-RC1启动时指定了错误的参数会报错

误用参数-h报错信息

[~]$ ./go-mud -h 123.57.24.152
GoMud(version v0.6.1-RC1)

Usage:
  ./go-mud [flags]

Flags:
  -c, --config FILENAME            config FILENAME, default to `config.yaml` or `config.json`
      --version                    just print version number only
      --help                       show this message
      --gen-yaml                   generate config.yaml
      --gen-json                   generate config.json
      --ui.ambiguouswidth string   二义性字符宽度,可选值: auto/single/double/space (default "auto")
      --ui.historylines int        历史记录保留行数 (default 100000)
      --ui.rttvheight int          历史查看模式下实时文本区域高度 (default 10)
  -H, --mud.host IP/Domain         服务器 IP/Domain (default "mud.pkuxkx.net")
  -P, --mud.port Port              服务器 Port (default 8080)
      --lua.enable                 是否加载 Lua 机器人 (default true)
  -p, --lua.path path              Lua 插件路径 path (default "lua")
panic: runtime error: index out of range [-1]

goroutine 22 [running]:
github.com/dzpao/go-mud/ui.(*UI).Print(0x4000190580, 0x4000093e18, 0x1, 0x1, 0x0, 0x0, 0x0)
        github.com/dzpao/go-mud@/ui/ui.go:342 +0x46c
github.com/dzpao/go-mud/ui.(*UI).Println(0x4000190580, 0x400021da60, 0x1, 0x1, 0xee6b2800, 0x0, 0x0)
        github.com/dzpao/go-mud@/ui/ui.go:364 +0x84
github.com/dzpao/go-mud/mud.(*MudServer).Run(0x40001f8480)
        github.com/dzpao/go-mud@/mud/mud.go:67 +0x95c
created by main.(*Client).Run
        github.com/dzpao/go-mud@/main.go:67 +0x238

quit 指令作用域不正确

在游戏中使用 quit 命令的结果是退出 gomud 而不是退出游戏,导致 quit 后游戏人物在游戏中处于断线状态

RegEx() 在大量快速调用时有概率出现错误

重现方法:
for i=1,100000 do Print(tostring(i)..": "..RegEx("test", "(^.*$)")) end

Lua error: :1: bad argument #1 to ? (string expected, got nil)
stack traceback:
:0: in function </Users/ibm/go-mud/script/frame/timer.lua:5>
:1: in function <:0>
/Users/ibm/go-mud/script/client.lua:182: in main chunk

没有机器,没法用

目前可以用 lua 开发机器,但需要一些必要的开发指南,最好能够移植一些实用的机器过来,以做示范。

运行或编译报错找不到模块

在手机上termux中启用go module 后,运行go run main.go或者go build main.go都会报错:
build command-line-arguments: cannot find module for path golang.org/x/sys/unix

聊天信息要能够分屏显示

正常游戏过程中,聊天信息和游戏内容混合在一起,看得眼花也很容易错过信息。
希望能够把聊天信息分开显示到另一个画面,可以通过快捷键或者任务栏切换。

更进一步地,是否可以任意开辟新的窗口,并且指定里面显示的内容。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.