(评论)
(comments)

原始链接: https://news.ycombinator.com/item?id=39572858

回答之前提出的问题:是否可以通过可编写脚本的 Bash 命令为 Minecraft 等商业流行游戏创建自定义服务器? 是的,可以为《我的世界》以及其他商业游戏编写自定义服务器,尽管创建自定义服务器可能会引发有关版权所有权的问题。 围绕 Minecraft(尤其是 Java 平台上的 Minecraft)等游戏的自定义服务器和模组的创建和分发,存在着蓬勃发展的社区。 这些社区严重依赖 Bash 和 Python 等脚本语言来促进模组管理、模组集成和其他游戏相关任务。 Minecraft 的自定义服务器允许玩家参加玩家对玩家 (PVP) 比赛、探索用户创建的世界并参与各种形式的竞争。 与《我的世界》相反,为商业游戏开发游戏客户端会带来更大的版权影响,因为它涉及更改通常受版权法保护的专有系统。 然而,游戏客户端修改(称为模组或替换)在《Runescape》和《魔兽世界》等多种游戏中仍然很常见,尽管受到游戏公司施加的特定限制。 最终,可编写脚本的 Bash 命令使用户能够通过实现游戏库存版本中缺少的功能来修改游戏,同时提供对游戏编程框架关键方面的洞察。 关于前面引用的文章,它令人印象深刻地展示了作者使用 Bash 为 Minecraft 构建完整且功能齐全的服务器设置的能力,强调了 Bash 作为传统使用的脚本语言的可行替代方案的适应性和多功能性。 考虑到其实际应用和易于实现,使用 Bash 来完成传统上为编译语言保留的任务所表现出的足智多谋值得钦佩。 虽然一些开发人员批评 Bash 阻碍了生产力,但批评者往往忽视了利用 Bash 进行游戏服务器管理所带来的众多好处,特别是在节省成本和降低系统复杂性方面。 此外,采用 Bash 作为主要脚本语言使开发人员能够对游戏行为的几乎每个方面(包括 mod 安装和配置过程)实现更高级别的精细控制。 总的来说,本文证明了 Bash 作为一种合适且强大的脚本语言的可行性,尽管存在效率和性能方面的担忧。 使用 Bash 来执行历史上分配给传统编译语言的任务,凸显了程序员在寻求克服技术障碍同时实现最佳结果的方法时所表现出的聪明才智。 通过使用B

相关文章

原文
Hacker News new | past | comments | ask | show | jobs | submit login
Writing a Minecraft server from scratch in Bash (2022) (sdomi.pl)
335 points by LorenDB 1 day ago | hide | past | favorite | 52 comments










As someone who's done a lot of work with scriptable Minecraft servers for both Java and Bedrock (ScraM), this is impressive. Bonus points for using "duckduckgoing" in a sentence.


Discussion at the time https://news.ycombinator.com/item?id=30347501 92 comments


Thanks! Macroexpanded:

My thoughts on writing a Minecraft server from scratch in Bash - https://news.ycombinator.com/item?id=30347501 - Feb 2022 (90 comments)



A negative power, i.e. 2^(-n) is just 1/(2^n). I'm surprised the author didn't remember that with their own 2^-1 = 0.5 example and eventually reached out to awk for it.


I don't understand how this would help the author. Since the bash doesn't support floating point numbers anyway


This. Also, gawk has netwoki support, so you can write an mc server with just gawk.


I had the same thought. bc would have been a lighter choice.

And tryauuum, I think the author only needed powers of two to emulate floating point in the first place. So they could just divide said number by 2 a number of times.



bash is one of my favorite, as favorite as vim and lua.

a single binary that is less than 2M bytes, universal, way more capable than many people think.

with shellcheck and good habits, bash can be readable and safe as well.

if you want something extra, you can always use C/C++ to add those utilities without using more involved FFI etc, and without pip/npm/etc to load who knows how many dependencies.



> with shellcheck and good habits, bash can be readable and safe as well.

My favorite thing to do with shellcheck: add it to CI. Developers hate this one trick!

A lot of times CI and Dockerfiles have inline bash scripts. My next favorite thing to do is to move all of that inlined bash to their own script files. Now that CI has shellcheck: all that stuff gets checked too! Developers seem to hate this though because it's "less readable". Less readable my ass, it's way more safe.

Next problem: the same bash scripts are now in the same files in multiple repositories (a distributed build). I'm open to ideas for improvements here.



To skip the "move your scripts to standalone files" step some devs don't like, consider something like https://github.com/hadolint/hadolint which runs Shellcheck over inline scripts within Containerfiles.


I dislike bash because I'm not good with it. It sucks but is still often the best solution available. Actually, one of my regret was not to invest more time on it when I was a student (a while ago) because it's one of these rare tools that accompanied me my whole career.


It's true. The nice thing is that there are many many examples of how to use bash. Just open a script file in random repositories. Most scripts are super SUPER simple. But just copy-paste to shellcheck and it will give some feedback if you're looking to get in some really quick commits and PRs :)


They should have used my (dumb?) library, ctypes.sh:

https://github.com/taviso/ctypes.sh

Then they can access libm, poll(), select() and so on from bash :)



I‘m not sure you should have done that, but it is impressive for the sheer chuzpa of it. Like reanimating Frankenstein.


Lol, holy shit what did I just read?

Amazing, installing now. I want to be part of the problem.



Awesome, but beside the point of writing something in bash that never needed to be in bash for any technical reason.

Meaning if it requires bash plus some specially installed compiled c code, then it might as well require c or python or anything else and there is no point in calling it "written in bash", or writing it in mostly-bash-plus-special-plugin.

I do know who I'm speaking to so please assume I say this respectfully. :) I have no problem with a "pointless" project like that as I'll show in a second.

That said, this minecraft project itself relies on externals like xxd when it doesn't need to, so using ctypes.sh would be no worse in this case, so you are right, in this case they might as well have.

But for the record it is possible to read, store, manipulate, do math on, and output binary in pure bash without anything like dd or xxd.

The only byte that is a problem is null, and there is a way to deal with that. You can't directly store a null, but you can detect that you read one and store that info, and reconstruct it on output later, or do math on it, use it's numerical value as an array index or byte offset or whatever the byte is for.

For a minimal example, just copying a binary file: while LANG=C IFS= read -d '' -r -n 1 x ;do printf '%c' "$x" ;done bin2

That's a bit too minimal since it doesn't show what other kinds of things you can do that are more useful than cat-without-cat.

A bit more generic and useful: https://gist.github.com/bkw777/c1413d0e3de6c54524ddae890fe8d...

The LANG=C, IFS= , and -d'' all combine to render all bytes accessible except 0x00, and then the return value from read() tells you the difference between "we read a 0x00" and "we didn't read anything" and "input ended"

And it doesn't have to use on the overall while() comand either. You can exec 3file_or_fifo_or_tty and read -u3 / printf >&3 etc inside the loop instead.

An example reading from a serial port: https://gist.github.com/bkw777/ddde771cc85fdd888c7ec74953193...

Used in anger: https://github.com/bkw777/pdd.sh see tpdd_read, tpdd_write, file_to_fhex, str_to_shex reading and writing both a serial port and local files and doing all kinds of processing on the data.

And these loops are not even subshells let alone externals. You can manipulate variables inside the loop and you are still in the same original context. I'd say parent shell but there are no childern.

Those all read a single byte at a time with read -n 1, but they don't have to.

You can read without the -n1 and each iteration of the loop will collect as much as it can between nulls instead of always one byte. That would consume less ram and less loop iterations.

But the things I'm using them for want to slice & dice the individual bytes and byte-ranges at numerical offsets anyway and the data is always small (by todays standards) so the array-of-hex-pairs is just too convenient where a[n] == byte n, and all bytes are treated the same whether printable, non-printable, or null, and aside from merely storing and regenerating the bytes with printf you can also use the numerical values directly as well by simply prepending 0x, so 0x$n or 0x${a[n]} almost anywhere you would normally have a simple integer. So you can do math on them and use them as array indexes and byte offsets etc.

Read the 2nd byte of h[] as a length of the payload to follow, and clip out that payload: ${h[@]:2:0x${h[1]}}



woah that's cool :) also hello tavis


would love to see how poll() and select() etc work this way




I mean if it's good enough for python...


Now this is a proper hacker site. This is great.


[flagged]



There is a set of radio buttons in the top right corner you can use to choose a different one :)


Weird, the older I get the better that font is for me. I wonder if that's because of nostalgia as all of the terminals at that age looked like this.


This website is the one of the rare times where safari’s reader mode that changes the font was super nice to read.


You can always use reader mode of your browser.


100% right. I completely forgot about that. Thanks.


While I am not good at bash programming, I am surprised how capable / non horrible it actually is.


Just wondering, but is writing custom servers for commercial games still a thing?


For Minecraft, very much so. Minecraft, especially the Java version, is in a comparatively odd place in that it receives significant free content updates AND officially supports running any historical version AND has an extremely vibrant modding community.

Minecraft (Java) is as much of a game engine for others to build on as it is a game itself.



This is because in addition to being the most sold video game of all time, minecraft is effectively open source. It's not literally open source, but you can decompile java bytecode with standard tooling, and symbols are available, either community-reversed, or official.


Frustrating how game studios can see Minecraft's success here and not change a thing about their development practices.


I think Minecraft's position today has as much to do with the content of the game itself as it has to do with its architecture/Mojang's engineering choices.

The nearly-infinite expandability and modularity of Minecraft is partially due to the simplicity of the art, core game mechanics, and lack of storyline. Good mods are harder to make when the world they must integrate into is more complex.

I think this means a lot of games wouldn't see the kind of sustained success Minecraft has seen, even with more "open" development practices.

I hypothesize that the "open world" craze of years past was an attempt to capture Minecraft magic, but those games lacked the thematic open-endedness that really facilitates Minecraft's longevity.



There’s actually a very large and vibrant community for modding Unity games like this.

More competitive games can’t afford any type of easy reverse engineering due to the cheating factor.



Mods are the (amazing) end game for Lethal Company. So many fun, new tweaks and content.


For the curious: https://thunderstore.io/c/lethal-company/

Click on any mod, and you can see the decompiled source. The mods use function hooking to run before or after certain functions are called rather than the event based system you see in Minecraft plugins.



minetest is open source for real though


The four great game engines: Unreal, Unity, Minecraft and Godot.

I don’t think Minecraft is number four on the list. It might be number two.



Roblox is somewhere on that list too ....


How many thousand mods does it have?


Isn't each server its own mod, in effect?


Minetest is much more of a game engine.

I've heard from someone I know that played both extensively that minetest is less prone to losing everything for data corruption (never happened once in minetest, regularly in minecraft after a while. But sample size is 1).



I don't think I've ever witnessed data corruption in Minecraft, and that's even playing since Alpha 1.0.11 and multiple data format migrations... well, my sample size is 1, too.

I've also been on ZFS nearly the whole time. Are you certain Minecraft actually corrupted your data file, or do you suffer underlying hardware failure?



Is that sample size of one from the java edition or bedrock edition of minecraft?


java


Not just servers but for some games clients too https://runelite.net/


I find RuneLite a fascinatingly well-built piece of software. The lead dev, Adam, did a fantastic job with it, and good on Jagex for allowing its use, even as far as advertising it on their own front page.


It really papers over (some of) the tedium of the game and let's you enjoy the rest easier. Love it.


Although writing game servers for commercial games is already "difficult", isn't writing game clients for commercial games a huge issue copyright wise?


I think it will always be a thing for those who play games & like to dabble with tech, either to fix a bug, learn a language, or just see how the sausage is made.


AFAIK yes, the RE scene is still active.


Minecraft, one of greatest game since Quake


So that happened... Jesus. I've read a lot of articles about the way they implement stuff but this takes the cake. Hands down one of, if not the best write up of something wild I've ever read. Top shelf.






Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact



Search:
联系我们 contact @ memedata.com