Finished translating formspec.md.

This commit is contained in:
debiankaios 2022-09-18 17:43:26 +02:00
parent 498669e55a
commit 06b5765234
2 changed files with 118 additions and 112 deletions

View File

@ -8,10 +8,10 @@ redirect_from: /de/chapters/formspecs.html
submit_vuln: submit_vuln:
level: warning level: warning
title: Malicious clients can submit anything at anytime title: Malicious clients can submit anything at anytime
message: You should never trust a formspec submission. A malicious client message: Sie sollten niemals einer formspec-Übermittlung vertrauen. Ein böswilliger Client
can submit anything they like at any time - even if you never showed kann jederzeit alles übermitteln, was er will - auch wenn Sie ihm nie die
them the formspec. This means that you should check privileges den formspec gezeigt haben. Das bedeutet, dass Sie die Berechtigungen prüfen sollten
and make sure that they should be allowed to perform the action. und sicherstellen, dass sie die Aktion durchführen dürfen.
--- ---
## Einleitung <!-- omit in toc --> ## Einleitung <!-- omit in toc -->
@ -37,14 +37,14 @@ unerwartete Fenster das Spielgeschehen stören können.
- [Anatomie eines formspecs](#anatomie-eines-a-formspecs) - [Anatomie eines formspecs](#anatomie-eines-a-formspecs)
- [Elemente](#elemente) - [Elemente](#elemente)
- [Header](#header) - [Header](#header)
- [Guessing Game](#guessing-game) - [Ratespiel](#ratespiel)
- [Padding and Spacing](#padding-and-spacing) - [Padding und Abstände](#padding-und-abstände)
- [Receiving Formspec Submissions](#receiving-formspec-submissions) - [Empfang von Formspec-Übermittlungen](#empfang-von-formspec-übermittlungen)
- [Contexts](#contexts) - [Contexts](#contexts)
- [Formspec Sources](#formspec-sources) - [Formspec-Quellen](#formspec-quellen)
- [Node Meta Formspecs](#node-meta-formspecs) - [Node Meta Formspecs](#node-meta-formspecs)
- [Player Inventory Formspecs](#player-inventory-formspecs) - [Spieler Inventar Formspecs](#spieler-inventar-formspecs)
- [Your Turn](#your-turn) - [Sie sind dran](#sie-sind-dran)
## Reale oder Legacy-Koordinaten ## Reale oder Legacy-Koordinaten
@ -117,22 +117,22 @@ Dadurch wird der Anker an den linken mittleren Rand des formspec-Feldes gesetzt,
Position dieses Ankers auf der linken Seite des Bildschirms. Position dieses Ankers auf der linken Seite des Bildschirms.
## Guessing Game ## Ratespiel
<figure class="right_image"> <figure class="right_image">
<img src="{{ page.root }}/static/formspec_guessing.png" alt="Guessing Formspec"> <img src="{{ page.root }}/static/formspec_guessing.png" alt="Rate-Formspec">
<figcaption> <figcaption>
The guessing game formspec. Das Ratespiel formspec.
</figcaption> </figcaption>
</figure> </figure>
The best way to learn is to make something, so let's make a guessing game. Der beste Weg, etwas zu lernen, ist, etwas zu machen, also lasst uns ein Ratespiel machen.
The principle is simple: the mod decides on a number, then the player makes Das Prinzip ist einfach: Der Mod entscheidet sich für eine Zahl, und die Spieler
guesses on the number. The mod then says if the guess is higher or lower then errät die Zahl. Der Mod sagt dann, ob die erratene Zahl höher oder niedriger ist als
the actual number. die tatsächliche Zahl.
First, let's make a function to create the formspec code. It's good practice to Zunächst erstellen wir eine Funktion, die den formspec-Code erzeugt. Es ist gute Praxis, dies
do this, as it makes it easier to reuse elsewhere. zu tun, da es die Wiederverwendung an anderer Stelle erleichtert.
<div style="clear: both;"></div> <div style="clear: both;"></div>
@ -140,29 +140,29 @@ do this, as it makes it easier to reuse elsewhere.
guessing = {} guessing = {}
function guessing.get_formspec(name) function guessing.get_formspec(name)
-- TODO: display whether the last guess was higher or lower -- TODO: Anzeige, ob die letzte Schätzung höher oder niedriger war
local text = "I'm thinking of a number... Make a guess!" local text = "Ich denke an eine Zahl... Raten Sie mal!"
local formspec = { local formspec = {
"formspec_version[4]", "formspec_version[4]",
"size[6,3.476]", "size[6,3.476]",
"label[0.375,0.5;", minetest.formspec_escape(text), "]", "label[0.375,0.5;", minetest.formspec_escape(text), "]",
"field[0.375,1.25;5.25,0.8;number;Number;]", "field[0.375,1.25;5.25,0.8;nummer;Nummer;]",
"button[1.5,2.3;3,0.8;guess;Guess]" "button[1.5,2.3;3,0.8;raten;Raten]"
} }
-- table.concat is faster than string concatenation - `..` -- table.concat ist schneller als String-Verkettung - `..`
return table.concat(formspec, "") return table.concat(formspec, "")
end end
``` ```
In the above code, we place a field, a label, and a button. A field allows text Im obigen Code platzieren wir ein Feld, eine Beschriftung und eine Schaltfläche.
entry, and a button is used to submit the form. You'll notice that the elements Ein Feld erlaubt die Eingabe von Text Texteingabe, und eine Schaltfläche dient zum
are positioned carefully in order to add padding and spacing, this will be explained Absenden des Forms. Sie werden feststellen, dass die Elemente
later. sorgfältig positioniert sind, um Padding und Abstände hinzuzufügen, was später erklärt wird.
Next, we want to allow the player to show the formspec. The main way to do this Als Nächstes wollen wir dem Spieler erlauben, den formspec anzuzeigen. Der beste Weg, dies zu tun
is using `show_formspec`: ist die Verwendung von `show_formspec`:
```lua ```lua
function guessing.show_to(name) function guessing.show_to(name)
@ -176,34 +176,35 @@ minetest.register_chatcommand("game", {
}) })
``` ```
The `show_formspec` function accepts a player name, the formspec name, and the Die Funktion `show_formspec` akzeptiert einen Spielernamen, den Namen der formspec und die
formspec itself. The formspec name should be a valid itemname, ie: in the format formspec selbst. Der formspec-Name sollte ein gültiger Itemname sein, d.h. im Format
`modname:itemname`. `Modname:Gegenstandsname`.
### Padding and Spacing ### Padding und Abstände
<figure class="right_image"> <figure class="right_image">
<img src="{{ page.root }}/static/formspec_padding_spacing.png" alt="Padding and spacing"> <img src="{{ page.root }}/static/formspec_padding_spacing.png" alt="Padding und Abstände">
<figcaption> <figcaption>
The guessing game formspec. The guessing game formspec.
</figcaption> </figcaption>
</figure> </figure>
Padding is the gap between the edge of the formspec and its contents, or between unrelated Padding ist der Abstand zwischen dem Rand des formspec und seinem Inhalt oder zwischen nicht verwandten Elementen,
elements, shown in red. Spacing is the gap between related elements, shown in blue. dargestellt in Rot. Abstand ist der Abstand zwischen zusammenhängenden Elementen, der blau dargestellt wird.
It is fairly standard to have a padding of `0.375` and a spacing of `0.25`.
Ein Padding von `0,375` und ein Abstand von `0,25` sind üblich.
<div style="clear: both;"></div> <div style="clear: both;"></div>
### Receiving Formspec Submissions ### Empfang von Formspec-Übermittlungen
When `show_formspec` is called, the formspec is sent to the client to be displayed. Wenn `show_formspec` aufgerufen wird, wird der formspec an den Client gesendet, um angezeigt zu werden.
For formspecs to be useful, information needs to be returned from the client to server. Damit formspecs nützlich sind, müssen Informationen vom Client zum Server zurückgeschickt werden.
The method for this is called formspec field submission, and for `show_formspec`, that Die Methode dafür heißt formspec field submission, und für `show_formspec` wird diese
submission is received using a global callback: Übermittlung über einen globalen Callback empfangen:
```lua ```lua
minetest.register_on_player_receive_fields(function(player, formname, fields) minetest.register_on_player_receive_fields(function(player, formname, fields)
@ -213,39 +214,39 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
if fields.guess then if fields.guess then
local pname = player:get_player_name() local pname = player:get_player_name()
minetest.chat_send_all(pname .. " guessed " .. fields.number) minetest.chat_send_all(pname .. " riet " .. fields.number)
end end
end) end)
``` ```
The function given in `minetest.register_on_player_receive_fields` is called Die in `minetest.register_on_player_receive_fields` angegebene Funktion wird
every time a user submits a form. Most callbacks will need to check the formname given jedes Mal aufgerufen, wenn ein Benutzer ein Formular absendet. Die meisten Callbacks müssen den der Funktion übergebenen Formularnamen prüfen
to the function, and exit if it is not the right form; however, some callbacks an die Funktion übergebenen Formularnamen überprüfen und beenden, wenn es sich nicht um das richtige Form handelt; einige
may need to work on multiple forms, or on all forms. müssen jedoch möglicherweise für mehrere Formulare oder für alle Formulare funktionieren.
The `fields` parameter to the function is a table of the values submitted by the Der Parameter `fields` der Funktion ist eine Tabelle mit den vom Benutzer übermittelten Werten
user, indexed by strings. Named elements will appear in the field under their own Benutzer übermittelten Werte, die durch Zeichenketten indiziert sind. Benannte Elemente erscheinen in dem Feld unter ihrem eigenen
name, but only if they are relevent for the event that caused the submission. Namen, aber nur, wenn sie für das Ereignis, das die Übermittlung verursacht hat, relevant sind.
For example, a button element will only appear in fields if that particular button Ein Schaltflächenelement erscheint beispielsweise nur dann in Feldern, wenn die betreffende Schaltfläche
was pressed. gedrückt wurde.
{% include notice.html notice=page.submit_vuln %} {% include notice.html notice=page.submit_vuln %}
So, now the formspec is sent to the client and the client sends information back. Der formspec wird also an den Client gesendet, und der Client sendet Informationen zurück.
The next step is to somehow generate and remember the target value, and to update Der nächste Schritt besteht darin, den Zielwert irgendwie zu generieren und zu speichern, und die
the formspec based on guesses. The way to do this is using a concept called die formspec auf der Grundlage von Schätzungen zu aktualisieren. Dies geschieht mit Hilfe eines Konzepts namens
"contexts". "contexts".
### Contexts ### Contexts
In many cases you want minetest.show_formspec to give information In vielen Fällen möchten Sie, dass minetest.show_formspec Informationen
to the callback which you don't want to send to the client. This might include an den Callback weitergeben, die nicht an den Client gesendet werden sollen.
what a chat command was called with, or what the dialog is about. In this case, Dies könnte beinhalten dass ein Chat-Befehl aufgerufen wurde, oder worum es
the target value that needs to be remembered. in dem Dialog geht. In diesem Fall, der Zielwert, der gespeichert werden muss.
A context is a per-player table to store information, and the contexts for all Ein Context ist eine pro-Spieler-Tabelle zum Speichern von Informationen, und die Contexts für alle
online players are stored in a file-local variable: Online-Spieler werden in einer dateilokalen Variablen gespeichert:
```lua ```lua
local _contexts = {} local _contexts = {}
@ -255,13 +256,13 @@ local function get_context(name)
return context return context
end end
minetest.register_on_leaveplayer(function(player) minetest.register_on_leaveplayer(function(spieler)
_contexts[player:get_player_name()] = nil _contexts[spieler:get_player_name()] = nil
end) end)
``` ```
Next, we need to modify the show code to update the context Als nächstes müssen wir den Show-Code ändern, um den Context zu aktualisieren
before showing the formspec: zu aktualisieren, bevor der Formspec angezeigt wird:
```lua ```lua
function guessing.show_to(name) function guessing.show_to(name)
@ -273,7 +274,7 @@ function guessing.show_to(name)
end end
``` ```
We also need to modify the formspec generation code to use the context: Wir müssen auch den Code für die Generierung von Formularen ändern, um den Context zu verwenden:
```lua ```lua
function guessing.get_formspec(name, context) function guessing.get_formspec(name, context)
@ -289,14 +290,14 @@ function guessing.get_formspec(name, context)
end end
``` ```
Note that it's good practice for `get_formspec` to only read the context, and not Beachten Sie, dass es gute Praxis ist, wenn `get_formspec` den Context nur liest und nicht
update it at all. This can make the function simpler, and also easier to test. überhaupt nicht zu aktualisieren. Dies kann die Funktion einfacher machen, und auch leichter zu testen.
And finally, we need to update the handler to update the context with the guess: Und schließlich müssen wir den Handler aktualisieren, um den Context mit der Vermutung zu aktualisieren:
```lua ```lua
if fields.guess then if fields.guess then
local name = player:get_player_name() local name = spieler:get_player_name()
local context = get_context(name) local context = get_context(name)
context.guess = tonumber(fields.number) context.guess = tonumber(fields.number)
guessing.show_to(name) guessing.show_to(name)
@ -304,43 +305,44 @@ end
``` ```
## Formspec Sources ## Formspec-Quellen
There are three different ways that a formspec can be delivered to the client: Es gibt drei verschiedene Möglichkeiten, wie ein Formspec an den client übermittelt werden kann:
* [show_formspec](#guessing-game): the method used above, fields are received by `register_on_player_receive_fields`. * [show_formspec](#ratespiel): Bei der oben beschriebenen Methode werden die Felder durch
* [Node Meta Formspecs](#node-meta-formspecs): the node contains a formspec in its meta data, and the client `register_on_player_receive_fields` empfangen.
shows it *immediately* when the player rightclicks. Fields are received by a * [Node Meta Formspecs](#node-meta-formspecs): der Node enthält in seinen Metadaten eine Formularvorgabe,
method in the node definition called `on_receive_fields`. und der Client zeigt es *sofort* an, wenn der Spieler mit der rechten Maustaste klickt. Felder werden
* [Player Inventory Formspecs](#player-inventory-formspecs): the formspec is sent to the client at some point, and then durch eine Methode in der Node-Definition namens `on_receive_fields` empfangen.
shown immediately when the player presses `i`. Fields are received by * [Player Inventory Formspecs](#spieler-inventar-formspecs): der formspec wird irgendwann an den Client gesendet und dann
`register_on_player_receive_fields`. sofort angezeigt, wenn der Spieler auf "i" drückt. Felder werden empfangen durch
`register_on_player_receive_fields` empfangen.
### Node Meta Formspecs ### Node Meta Formspecs
`minetest.show_formspec` is not the only way to show a formspec; you can also `minetest.show_formspec` ist nicht die einzige Möglichkeit, einen formspec anzuzeigen; Sie können auch
add formspecs to a [node's metadata](node_metadata.html). For example, formspecs zu den Metadaten eines [Nodes](node_metadata.html) hinzufügen. Zum Beispiel,
this is used with chests to allow for faster opening times - wird dieses bei Truhen verwendet, um ein schnelleres Öffnen zu ermöglichen -
you don't need to wait for the server to send the player the chest formspec. man muss nicht darauf warten, dass der Server dem Spieler den formspec für die Truhe schickt.
```lua ```lua
minetest.register_node("mymod:rightclick", { minetest.register_node("meinemod:rechtsclick", {
description = "Rightclick me!", description = "Rechtsclicke me!",
tiles = {"mymod_rightclick.png"}, tiles = {"mymod_rechtsclick.png"},
groups = {cracky = 1}, groups = {cracky = 1},
after_place_node = function(pos, placer) after_place_node = function(pos, placer)
-- This function is run when the chest node is placed. -- Diese Funktion wird ausgeführt, wenn das Kisten-Node platziert wird.
-- The following code sets the formspec for chest. -- Der folgende Code setzt den formspec für Kiste.
-- Meta is a way of storing data onto a node. -- Meta ist eine Möglichkeit, Daten in einem Node zu speichern.
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
meta:set_string("formspec", meta:set_string("formspec",
"formspec_version[4]" .. "formspec_version[4]" ..
"size[5,5]" .. "size[5,5]" ..
"label[1,1;This is shown on right click]" .. "label[1,1;Dies wird beim Rechtsklick angezeigt]" ..
"field[1,2;2,1;x;x;]") "field[1,2;2,1;x;x;]")
end, end,
on_receive_fields = function(pos, formname, fields, player) on_receive_fields = function(pos, formname, fields, spieler)
if fields.quit then if fields.quit then
return return
end end
@ -350,30 +352,32 @@ minetest.register_node("mymod:rightclick", {
}) })
``` ```
Formspecs set this way do not trigger the same callback. In order to Auf diese Weise eingestellte formspecs lösen nicht denselben Callback aus. Um
receive form input for meta formspecs, you must include an Formulareingaben für meta formspecs zu erhalten, müssen Sie einen
`on_receive_fields` entry when registering the node. `on_receive_fields`-Eintrag bei der Registrierung des Nodes enthalten.
This style of callback triggers when you press enter Diese Art von Callback wird ausgelöst, wenn Sie die Eingabetaste
in a field, which is impossible with `minetest.show_formspec`; in einem Feld drücken, was mit `minetest.show_formspec` unmöglich ist;
however, this kind of form can only be shown by right-clicking on a allerdings kann diese Art von Formular nur durch Rechtsklick auf einen
node. It cannot be triggered programmatically. Node. Sie kann nicht programmatisch ausgelöst werden.
### Player Inventory Formspecs ### Spieler Inventar Formspecs
The player inventory formspec is the one shown when the player presses i. Der formspec für das Spielerinventar wird angezeigt, wenn der Spieler auf i drückt.
The global callback is used to receive events from this formspec, and the Der globale Callback wird verwendet, um Ereignisse von diesem formspec zu empfangen, und der
formname is `""`. formname ist `""`.
There are a number of different mods which allow multiple mods to customise Es gibt eine Reihe von verschiedenen Mods, die es ermöglichen, das
the player inventory. The officially recommended mod is das Spielerinventar anzupassen. Die offiziell empfohlene Mod ist
[Simple Fast Inventory (sfinv)](sfinv.html), and is included in Minetest Game. [Simple Fast Inventory (sfinv)](https://github.com/rubenwardy/sfinv/blob/master/Tutorial.md),
und ist in Minetest Game enthalten. Ich als Übersetzer emphele jedoch
eher [i3](https://github.com/minetest-mods/i3) oder [unified inventory](https://github.com/minetest-mods/unified_inventory)
### Your Turn ### Sie sind dran
* Extend the Guessing Game to keep track of each player's top score, where the * Erweitern Sie das Ratespiel, um die höchste Punktzahl jedes Spielers zu ermitteln, wobei
top score is how many guesses it took. die höchste Punktzahl angibt, wie viele Ratschläge nötig waren.
* Make a node called "Inbox" where users can open up a formspec and leave messages. * Erstellen Sie einen Node namens "Inbox", in dem Benutzer ein formspec öffnen und Nachrichten hinterlassen können.
This node should store the placers' name as `owner` in the meta, and should use Dieser Node sollte den Namen des Placers als `owner` in der Meta speichern, und sollte
`show_formspec` to show different formspecs to different players. `show_formspec` verwenden, um verschiedene formspecs für verschiedene Spieler anzuzeigen.

View File

@ -12,6 +12,7 @@ chat message = Chat-Nachricht
child = Kind child = Kind
client = Client client = Client
Command = Befehl Command = Befehl
Context = Context
Cubic Nodes = Würfelförmiger Block Cubic Nodes = Würfelförmiger Block
craft slots = Handwerksplätze craft slots = Handwerksplätze
Damage = Schaden Damage = Schaden
@ -80,6 +81,7 @@ Object properties = Objekt-Eigenschaften
Overrides = Overrides Overrides = Overrides
path = Verzeichnis path = Verzeichnis
parent = Elternteil parent = Elternteil
per-player = pro-Spieler
pixel art = Pixel-Art pixel art = Pixel-Art
physics overrides = Physik-Overrides physics overrides = Physik-Overrides
placer = plazierer placer = plazierer