diff --git a/docs/pylib/copy_from_wiki.py b/docs/pylib/copy_from_wiki.py index 8c5372bd25..caf81efa96 100644 --- a/docs/pylib/copy_from_wiki.py +++ b/docs/pylib/copy_from_wiki.py @@ -16,6 +16,7 @@ We also need to build the toc-tree and should do so automatically for now. import glob import re import datetime +import textwrap _RE_MD_LINK = re.compile(r"\[(?P[\w -\[\]]+?)\]\((?P.+?)\)", re.I + re.S + re.U) _RE_REF_LINK = re.compile(r"\[[\w -\[\]]*?\]\(.+?\)", re.I + re.S + re.U) @@ -32,13 +33,13 @@ _INDEX_PREFIX = f""" # VERSION WARNING -> This is the experimental static v0.9 documentation of Evennia, _automatically_ generated from the +> This is the experimental static v0.95 documentation of Evennia, _automatically_ generated from the > [evennia wiki](https://github.com/evennia/evennia/wiki/) at {datetime.datetime.now()}. -> There are known conversion issues which will _not_ be addressed in this version - refer to +> There are known conversion issues which will _not_ be addressed in this version - refer to > the original wiki if you have trouble. > > Manual conversion and cleanup will instead happen during development of the upcoming v1.0 -> version of this static documentation. +> version of this static documentation. """ @@ -265,11 +266,20 @@ def convert_links(files, outdir): if text.split("\n")[0].strip().startswith("[]") else text.split("\n") ) - text = "\n".join(text) + + # wrap text + formatted_lines = [] + for line in text: + if line.strip(): + formatted_lines.append(textwrap.fill(line, width=100)) + else: + formatted_lines.append(line) + text = "\n".join(formatted_lines) if not is_index: text = f"# {title}\n\n{text}" + with open(outfile, "w") as fil: fil.write(text) diff --git a/docs/source/A-voice-operated-elevator-using-events.md b/docs/source/A-voice-operated-elevator-using-events.md index a3706fea8a..4a38d40e20 100644 --- a/docs/source/A-voice-operated-elevator-using-events.md +++ b/docs/source/A-voice-operated-elevator-using-events.md @@ -3,13 +3,24 @@ - Previous tutorial: [Adding dialogues in events](./Dialogues-in-events) -This tutorial will walk you through the steps to create a voice-operated elevator, using the [in-game Python system](https://github.com/evennia/evennia/blob/master/evennia/contrib/ingame_python/README.md). This tutorial assumes the in-game Python system is installed in your game. If it isn't, you can follow the installation steps given in [the documentation on in-game Python](https://github.com/evennia/evennia/blob/master/evennia/contrib/ingame_python/README.md), and come back on this tutorial once the system is installed. **You do not need to read** the entire documentation, it's a good reference, but not the easiest way to learn about it. Hence these tutorials. +This tutorial will walk you through the steps to create a voice-operated elevator, using the [in- +game Python +system](https://github.com/evennia/evennia/blob/master/evennia/contrib/ingame_python/README.md). +This tutorial assumes the in-game Python system is installed in your game. If it isn't, you can +follow the installation steps given in [the documentation on in-game +Python](https://github.com/evennia/evennia/blob/master/evennia/contrib/ingame_python/README.md), and +come back on this tutorial once the system is installed. **You do not need to read** the entire +documentation, it's a good reference, but not the easiest way to learn about it. Hence these +tutorials. -The in-game Python system allows to run code on individual objects in some situations. You don't have to modify the source code to add these features, past the installation. The entire system makes it easy to add specific features to some objects, but not all. +The in-game Python system allows to run code on individual objects in some situations. You don't +have to modify the source code to add these features, past the installation. The entire system +makes it easy to add specific features to some objects, but not all. > What will we try to do? -In this tutorial, we are going to create a simple voice-operated elevator. In terms of features, we will: +In this tutorial, we are going to create a simple voice-operated elevator. In terms of features, we +will: - Explore events with parameters. - Work on more interesting callbacks. @@ -18,17 +29,27 @@ In this tutorial, we are going to create a simple voice-operated elevator. In t ## Our study case -Let's summarize what we want to achieve first. We would like to create a room that will represent the inside of our elevator. In this room, a character could just say "1", "2" or "3", and the elevator will start moving. The doors will close and open on the new floor (the exits leading in and out of the elevator will be modified). +Let's summarize what we want to achieve first. We would like to create a room that will represent +the inside of our elevator. In this room, a character could just say "1", "2" or "3", and the +elevator will start moving. The doors will close and open on the new floor (the exits leading in +and out of the elevator will be modified). -We will work on basic features first, and then will adjust some, showing you how easy and powerfully independent actions can be configured through the in-game Python system. +We will work on basic features first, and then will adjust some, showing you how easy and powerfully +independent actions can be configured through the in-game Python system. ## Creating the rooms and exits we need -We'll create an elevator right in our room (generally called "Limbo", of ID 2). You could easily adapt the following instructions if you already have some rooms and exits, of course, just remember to check the IDs. +We'll create an elevator right in our room (generally called "Limbo", of ID 2). You could easily +adapt the following instructions if you already have some rooms and exits, of course, just remember +to check the IDs. -> Note: the in-game Python system uses IDs for a lot of things. While it is not mandatory, it is good practice to know the IDs you have for your callbacks, because it will make manipulation much quicker. There are other ways to identify objects, but as they depend on many factors, IDs are usually the safest path in our callbacks. +> Note: the in-game Python system uses IDs for a lot of things. While it is not mandatory, it is +good practice to know the IDs you have for your callbacks, because it will make manipulation much +quicker. There are other ways to identify objects, but as they depend on many factors, IDs are +usually the safest path in our callbacks. -Let's go into limbo (`#2`) to add our elevator. We'll add it to the north. To create this room, in-game you could type: +Let's go into limbo (`#2`) to add our elevator. We'll add it to the north. To create this room, +in-game you could type: tunnel n = Inside of an elevator @@ -49,9 +70,12 @@ Keep these IDs somewhere for the demonstration. You will shortly see why they a > Why have we created exits to our elevator and back to Limbo? Isn't the elevator supposed to move? -It is. But we need to have exits that will represent the way inside the elevator and out. What we will do, at every floor, will be to change these exits so they become connected to the right room. You'll see this process a bit later. +It is. But we need to have exits that will represent the way inside the elevator and out. What we +will do, at every floor, will be to change these exits so they become connected to the right room. +You'll see this process a bit later. -We have two more rooms to create: our floor 2 and 3. This time, we'll use `dig`, because we don't need exits leading there, not yet anyway. +We have two more rooms to create: our floor 2 and 3. This time, we'll use `dig`, because we don't +need exits leading there, not yet anyway. dig The second floor dig The third floor @@ -67,23 +91,38 @@ Add these IDs to your list, we will use them too. Let's go to the elevator (you could use `tel #3` if you have the same IDs I have). -This is our elevator room. It looks a bit empty, feel free to add a prettier description or other things to decorate it a bit. +This is our elevator room. It looks a bit empty, feel free to add a prettier description or other +things to decorate it a bit. -But what we want now is to be able to say "1", "2" or "3" and have the elevator move in that direction. +But what we want now is to be able to say "1", "2" or "3" and have the elevator move in that +direction. -If you have read [the previous tutorial about adding dialogues in events](./Dialogues-in-events), you may remember what we need to do. If not, here's a summary: we need to run some code when somebody speaks in the room. So we need to create a callback (the callback will contain our lines of code). We just need to know on which event this should be set. You can enter `call here` to see the possible events in this room. +If you have read [the previous tutorial about adding dialogues in events](./Dialogues-in-events), you +may remember what we need to do. If not, here's a summary: we need to run some code when somebody +speaks in the room. So we need to create a callback (the callback will contain our lines of code). +We just need to know on which event this should be set. You can enter `call here` to see the +possible events in this room. -In the table, you should see the "say" event, which is called when somebody says something in the room. So we'll need to add a callback to this event. Don't worry if you're a bit lost, just follow the following steps, the way they connect together will become more obvious. +In the table, you should see the "say" event, which is called when somebody says something in the +room. So we'll need to add a callback to this event. Don't worry if you're a bit lost, just follow +the following steps, the way they connect together will become more obvious. call/add here = say 1, 2, 3 -1. We need to add a callback. A callback contains the code that will be executed at a given time. So we use the `call/add` command and switch. +1. We need to add a callback. A callback contains the code that will be executed at a given time. +So we use the `call/add` command and switch. 2. `here` is our object, the room in which we are. 3. An equal sign. -4. The name of the event to which the callback should be connected. Here, the event is "say". Meaning this callback will be executed every time somebody says something in the room. -5. But we add an event parameter to indicate the keywords said in the room that should execute our callback. Otherwise, our callback would be called every time somebody speaks, no matter what. Here we limit, indicating our callback should be executed only if the spoken message contains "1", "2" or "3". +4. The name of the event to which the callback should be connected. Here, the event is "say". +Meaning this callback will be executed every time somebody says something in the room. +5. But we add an event parameter to indicate the keywords said in the room that should execute our +callback. Otherwise, our callback would be called every time somebody speaks, no matter what. Here +we limit, indicating our callback should be executed only if the spoken message contains "1", "2" or +"3". -An editor should open, inviting you to enter the Python code that should be executed. The first thing to remember is to read the text provided (it can contain important information) and, most of all, the list of variables that are available in this callback: +An editor should open, inviting you to enter the Python code that should be executed. The first +thing to remember is to read the text provided (it can contain important information) and, most of +all, the list of variables that are available in this callback: ``` Variables you can use in this event: @@ -93,29 +132,34 @@ Variables you can use in this event: message: the text having been spoken by the character. ----------Line Editor [Callback say of Inside of an elevator]--------------------- -01| +01| ----------[l:01 w:000 c:0000]------------(:h for help)---------------------------- ``` -This is important, in order to know what variables we can use in our callback out-of-the-box. Let's write a single line to be sure our callback is called when we expect it to: +This is important, in order to know what variables we can use in our callback out-of-the-box. Let's +write a single line to be sure our callback is called when we expect it to: ```python character.msg("You just said {}.".format(message)) ``` -You can paste this line in-game, then type the `:wq` command to exit the editor and save your modifications. +You can paste this line in-game, then type the `:wq` command to exit the editor and save your +modifications. -Let's check. Try to say "hello" in the room. You should see the standard message, but nothing more. Now try to say "1". Below the standard message, you should see: +Let's check. Try to say "hello" in the room. You should see the standard message, but nothing +more. Now try to say "1". Below the standard message, you should see: You just said 1. -You can try it. Our callback is only called when we say "1", "2" or "3". Which is just what we want. +You can try it. Our callback is only called when we say "1", "2" or "3". Which is just what we +want. Let's go back in our code editor and add something more useful. call/edit here = say -> Notice that we used the "edit" switch this time, since the callback exists, we just want to edit it. +> Notice that we used the "edit" switch this time, since the callback exists, we just want to edit +it. The editor opens again. Let's empty it first: @@ -125,16 +169,19 @@ And turn off automatic indentation, which will help us: := -> Auto-indentation is an interesting feature of the code editor, but we'd better not use it at this point, it will make copy/pasting more complicated. +> Auto-indentation is an interesting feature of the code editor, but we'd better not use it at this +point, it will make copy/pasting more complicated. ## Our entire callback in the elevator So here's the time to truly code our callback in-game. Here's a little reminder: 1. We have all the IDs of our three rooms and two exits. -2. When we say "1", "2" or "3", the elevator should move to the right room, that is change the exits. Remember, we already have the exits, we just need to change their location and destination. +2. When we say "1", "2" or "3", the elevator should move to the right room, that is change the +exits. Remember, we already have the exits, we just need to change their location and destination. -It's a good idea to try to write this callback yourself, but don't feel bad about checking the solution right now. Here's a possible code that you could paste in the code editor: +It's a good idea to try to write this callback yourself, but don't feel bad about checking the +solution right now. Here's a possible code that you could paste in the code editor: ```python # First let's have some constants @@ -164,32 +211,52 @@ else: Let's review this longer callback: -1. We first obtain the objects of both exits and our three floors. We use the `get()` eventfunc, which is a shortcut to obtaining objects. We usually use it to retrieve specific objects with an ID. We put the floors in a dictionary. The keys of the dictionary are the floor number (as str), the values are room objects. -2. Remember, the `message` variable contains the message spoken in the room. So either "1", "2", or "3". We still need to check it, however, because if the character says something like "1 2" in the room, our callback will be executed. Let's be sure what she says is a floor number. -3. We then check if the elevator is already at this floor. Notice that we use `TO_EXIT.location`. `TO_EXIT` contains our "north" exit, leading inside of our elevator. Therefore, its `location` will be the room where the elevator currently is. -4. If the floor is a different one, have the elevator "move", changing just the location and destination of both exits. - - The `BACK_EXIT` (that is "north") should change its location. The elevator shouldn't be accessible through our old floor. - - The `TO_EXIT` (that is "south", the exit leading out of the elevator) should have a different destination. When we go out of the elevator, we should find ourselves in the new floor, not the old one. +1. We first obtain the objects of both exits and our three floors. We use the `get()` eventfunc, +which is a shortcut to obtaining objects. We usually use it to retrieve specific objects with an +ID. We put the floors in a dictionary. The keys of the dictionary are the floor number (as str), +the values are room objects. +2. Remember, the `message` variable contains the message spoken in the room. So either "1", "2", or +"3". We still need to check it, however, because if the character says something like "1 2" in the +room, our callback will be executed. Let's be sure what she says is a floor number. +3. We then check if the elevator is already at this floor. Notice that we use `TO_EXIT.location`. +`TO_EXIT` contains our "north" exit, leading inside of our elevator. Therefore, its `location` will +be the room where the elevator currently is. +4. If the floor is a different one, have the elevator "move", changing just the location and +destination of both exits. + - The `BACK_EXIT` (that is "north") should change its location. The elevator shouldn't be +accessible through our old floor. + - The `TO_EXIT` (that is "south", the exit leading out of the elevator) should have a different +destination. When we go out of the elevator, we should find ourselves in the new floor, not the old +one. -Feel free to expand on this example, changing messages, making further checks. Usage and practice are keys. +Feel free to expand on this example, changing messages, making further checks. Usage and practice +are keys. You can quit the editor as usual with `:wq` and test it out. ## Adding a pause in our callback -Let's improve our callback. One thing that's worth adding would be a pause: for the time being, when we say the floor number in the elevator, the doors close and open right away. It would be better to have a pause of several seconds. More logical. +Let's improve our callback. One thing that's worth adding would be a pause: for the time being, +when we say the floor number in the elevator, the doors close and open right away. It would be +better to have a pause of several seconds. More logical. -This is a great opportunity to learn about chained events. Chained events are very useful to create pauses. Contrary to the events we have seen so far, chained events aren't called automatically. They must be called by you, and can be called after some time. +This is a great opportunity to learn about chained events. Chained events are very useful to create +pauses. Contrary to the events we have seen so far, chained events aren't called automatically. +They must be called by you, and can be called after some time. -- Chained events always have the name "chain_X". Usually, X is a number, but you can give the chained event a more explicit name. +- Chained events always have the name "chain_X". Usually, X is a number, but you can give the +chained event a more explicit name. - In our original callback, we will call our chained events in, say, 15 seconds. - We'll also have to make sure the elevator isn't already moving. -Other than that, a chained event can be connected to a callback as usual. We'll create a chained event in our elevator, that will only contain the code necessary to open the doors to the new floor. +Other than that, a chained event can be connected to a callback as usual. We'll create a chained +event in our elevator, that will only contain the code necessary to open the doors to the new floor. call/add here = chain_1 -The callback is added to the "chain_1" event, an event that will not be automatically called by the system when something happens. Inside this event, you can paste the code to open the doors at the new floor. You can notice a few differences: +The callback is added to the "chain_1" event, an event that will not be automatically called by the +system when something happens. Inside this event, you can paste the code to open the doors at the +new floor. You can notice a few differences: ```python TO_EXIT.location = floor @@ -248,20 +315,37 @@ else: What changed? -1. We added a little test to make sure the elevator wasn't already moving. If it is, the `BACK_EXIT.location` (the "south" exit leading out of the elevator) should be `None`. We'll remove the exit while the elevator is moving. -2. When the doors close, we set both exits' `location` to `None`. Which "removes" them from their room but doesn't destroy them. The exits still exist but they don't connect anything. If you say "2" in the elevator and look around while the elevator is moving, you won't see any exits. -3. Instead of opening the doors immediately, we call `call_event`. We give it the object containing the event to be called (here, our elevator), the name of the event to be called (here, "chain_1") and the number of seconds from now when the event should be called (here, `15`). -4. The `chain_1` callback we have created contains the code to "re-open" the elevator doors. That is, besides displaying a message, it reset the exits' `location` and `destination`. +1. We added a little test to make sure the elevator wasn't already moving. If it is, the +`BACK_EXIT.location` (the "south" exit leading out of the elevator) should be `None`. We'll remove +the exit while the elevator is moving. +2. When the doors close, we set both exits' `location` to `None`. Which "removes" them from their +room but doesn't destroy them. The exits still exist but they don't connect anything. If you say +"2" in the elevator and look around while the elevator is moving, you won't see any exits. +3. Instead of opening the doors immediately, we call `call_event`. We give it the object containing +the event to be called (here, our elevator), the name of the event to be called (here, "chain_1") +and the number of seconds from now when the event should be called (here, `15`). +4. The `chain_1` callback we have created contains the code to "re-open" the elevator doors. That +is, besides displaying a message, it reset the exits' `location` and `destination`. -If you try to say "3" in the elevator, you should see the doors closing. Look around you and you won't see any exit. Then, 15 seconds later, the doors should open, and you can leave the elevator to go to the third floor. While the elevator is moving, the exit leading to it will be inaccessible. +If you try to say "3" in the elevator, you should see the doors closing. Look around you and you +won't see any exit. Then, 15 seconds later, the doors should open, and you can leave the elevator +to go to the third floor. While the elevator is moving, the exit leading to it will be +inaccessible. -> Note: we don't define the variables again in our chained event, we just call them. When we execute `call_event`, a copy of our current variables is placed in the database. These variables will be restored and accessible again when the chained event is called. +> Note: we don't define the variables again in our chained event, we just call them. When we +execute `call_event`, a copy of our current variables is placed in the database. These variables +will be restored and accessible again when the chained event is called. -You can use the `call/tasks` command to see the tasks waiting to be executed. For instance, say "2" in the room, notice the doors closing, and then type the `call/tasks` command. You will see a task in the elevator, waiting to call the `chain_1` event. +You can use the `call/tasks` command to see the tasks waiting to be executed. For instance, say "2" +in the room, notice the doors closing, and then type the `call/tasks` command. You will see a task +in the elevator, waiting to call the `chain_1` event. ## Changing exit messages -Here's another nice little feature of events: you can modify the message of a single exit without altering the others. In this case, when someone goes north into our elevator, we'd like to see something like: "someone walks into the elevator." Something similar for the back exit would be great too. +Here's another nice little feature of events: you can modify the message of a single exit without +altering the others. In this case, when someone goes north into our elevator, we'd like to see +something like: "someone walks into the elevator." Something similar for the back exit would be +great too. Inside of the elevator, you can look at the available events on the exit leading outside (south). @@ -276,11 +360,14 @@ You should see two interesting rows in this table: | | | through this exit. | ``` -So we can change the message others see when a character leaves, by editing the "msg_leave" event. Let's do that: +So we can change the message others see when a character leaves, by editing the "msg_leave" event. +Let's do that: call/add south = msg_leave -Take the time to read the help. It gives you all the information you should need. We'll need to change the "message" variable, and use custom mapping (between braces) to alter the message. We're given an example, let's use it. In the code editor, you can paste the following line: +Take the time to read the help. It gives you all the information you should need. We'll need to +change the "message" variable, and use custom mapping (between braces) to alter the message. We're +given an example, let's use it. In the code editor, you can paste the following line: ```python message = "{character} walks out of the elevator." @@ -295,11 +382,13 @@ Again, save and quit the editor by entering `:wq`. You can create a new charact py self.search("beggar").move_to(self.search("south")) -This is a crude way to force our beggar out of the elevator, but it allows us to test. You should see: +This is a crude way to force our beggar out of the elevator, but it allows us to test. You should +see: A beggar(#8) walks out of the elevator. -Great! Let's do the same thing for the exit leading inside of the elevator. Follow the beggar, then edit "msg_leave" of "north": +Great! Let's do the same thing for the exit leading inside of the elevator. Follow the beggar, +then edit "msg_leave" of "north": call/add north = msg_leave @@ -307,21 +396,41 @@ Great! Let's do the same thing for the exit leading inside of the elevator. Fo message = "{character} walks into the elevator." ``` -Again, you can force our beggar to move and see the message we have just set. This modification applies to these two exits, obviously: the custom message won't be used for other exits. Since we use the same exits for every floor, this will be available no matter at what floor the elevator is, which is pretty neat! +Again, you can force our beggar to move and see the message we have just set. This modification +applies to these two exits, obviously: the custom message won't be used for other exits. Since we +use the same exits for every floor, this will be available no matter at what floor the elevator is, +which is pretty neat! ## Tutorial F.A.Q. - **Q:** what happens if the game reloads or shuts down while a task is waiting to happen? -- **A:** if your game reloads while a task is in pause (like our elevator between floors), when the game is accessible again, the task will be called (if necessary, with a new time difference to take into account the reload). If the server shuts down, obviously, the task will not be called, but will be stored and executed when the server is up again. +- **A:** if your game reloads while a task is in pause (like our elevator between floors), when the +game is accessible again, the task will be called (if necessary, with a new time difference to take +into account the reload). If the server shuts down, obviously, the task will not be called, but +will be stored and executed when the server is up again. - **Q:** can I use all kinds of variables in my callback? Whether chained or not? -- **A:** you can use every variable type you like in your original callback. However, if you execute `call_event`, since your variables are stored in the database, they will need to respect the constraints on persistent attributes. A callback will not be stored in this way, for instance. This variable will not be available in your chained event. -- **Q:** when you say I can call my chained events something else than "chain_1", "chain_2" and such, what is the naming convention? -- **A:** chained events have names beginning by "chain_". This is useful for you and for the system. But after the underscore, you can give a more useful name, like "chain_open_doors" in our case. +- **A:** you can use every variable type you like in your original callback. However, if you +execute `call_event`, since your variables are stored in the database, they will need to respect the +constraints on persistent attributes. A callback will not be stored in this way, for instance. +This variable will not be available in your chained event. +- **Q:** when you say I can call my chained events something else than "chain_1", "chain_2" and +such, what is the naming convention? +- **A:** chained events have names beginning by "chain_". This is useful for you and for the +system. But after the underscore, you can give a more useful name, like "chain_open_doors" in our +case. - **Q:** do I have to pause several seconds to call a chained event? -- **A:** no, you can call it right away. Just leave the third parameter of `call_event` out (it will default to 0, meaning the chained event will be called right away). This will not create a task. +- **A:** no, you can call it right away. Just leave the third parameter of `call_event` out (it +will default to 0, meaning the chained event will be called right away). This will not create a +task. - **Q:** can I have chained events calling themselves? -- **A:** you can. There's no limitation. Just be careful, a callback that calls itself, particularly without delay, might be a good recipe for an infinite loop. However, in some cases, it is useful to have chained events calling themselves, to do the same repeated action every X seconds for instance. +- **A:** you can. There's no limitation. Just be careful, a callback that calls itself, +particularly without delay, might be a good recipe for an infinite loop. However, in some cases, it +is useful to have chained events calling themselves, to do the same repeated action every X seconds +for instance. - **Q:** what if I need several elevators, do I need to copy/paste these callbacks each time? -- **A:** not advisable. There are definitely better ways to handle this situation. One of them is to consider adding the code in the source itself. Another possibility is to call chained events with the expected behavior, which makes porting code very easy. This side of chained events will be shown in the next tutorial. +- **A:** not advisable. There are definitely better ways to handle this situation. One of them is +to consider adding the code in the source itself. Another possibility is to call chained events +with the expected behavior, which makes porting code very easy. This side of chained events will be +shown in the next tutorial. - Previous tutorial: [Adding dialogues in events](./Dialogues-in-events) diff --git a/docs/source/API-refactoring.md b/docs/source/API-refactoring.md index 5ca45a2779..689b5893f5 100644 --- a/docs/source/API-refactoring.md +++ b/docs/source/API-refactoring.md @@ -1,24 +1,37 @@ # API refactoring -Building up to Evennia 1.0 and beyond, it's time to comb through the Evennia API for old cruft. This whitepage is for anyone interested to contribute with their views on what part of the API needs refactoring, cleanup or clarification (or extension!) +Building up to Evennia 1.0 and beyond, it's time to comb through the Evennia API for old cruft. This +whitepage is for anyone interested to contribute with their views on what part of the API needs +refactoring, cleanup or clarification (or extension!) -Note that this is not a forum. To keep things clean, each opinion text should ideally present a clear argument or lay out a suggestion. Asking for clarification and any side-discussions should be held in chat or forum. +Note that this is not a forum. To keep things clean, each opinion text should ideally present a +clear argument or lay out a suggestion. Asking for clarification and any side-discussions should be +held in chat or forum. --- ### Griatch (Aug 13, 2019) -This is how to enter an opinion. Use any markdown needed but stay within your section. Also remember to copy your text to the clipboard before saving since if someone else edited the wiki in the meantime you'll have to start over. +This is how to enter an opinion. Use any markdown needed but stay within your section. Also remember +to copy your text to the clipboard before saving since if someone else edited the wiki in the +meantime you'll have to start over. ### Griatch (Sept 2, 2019) -I don't agree with removing explicit keywords as suggested by [Johnny on Aug 29 below](./API-refactoring#reduce-usage-of-optionalpositional-arguments-aug-29-2019). Overriding such a method can still be done by `get(self, **kwargs)` if so desired, making the kwargs explicit helps IMO readability of the API. If just giving a generic `**kwargs`, one must read the docstring or even the code to see which keywords are valid. +I don't agree with removing explicit keywords as suggested by [Johnny on Aug 29 below](API- +refactoring#reduce-usage-of-optionalpositional-arguments-aug-29-2019). Overriding such a method can +still be done by `get(self, **kwargs)` if so desired, making the kwargs explicit helps IMO +readability of the API. If just giving a generic `**kwargs`, one must read the docstring or even the +code to see which keywords are valid. -On the other hand, I think it makes sense to as a standard offer an extra `**kwargs` at the end of arg-lists for common methods that are expected to be over-ridden. This make the API more flexible by hinting to the dev that they could expand their own over-ridden implementation with their own keyword arguments if so desired. +On the other hand, I think it makes sense to as a standard offer an extra `**kwargs` at the end of +arg-lists for common methods that are expected to be over-ridden. This make the API more flexible by +hinting to the dev that they could expand their own over-ridden implementation with their own +keyword arguments if so desired. --- -### Johnny +### Johnny #### Reduce usage of optional/positional arguments (Aug 29, 2019) ``` @@ -27,4 +40,7 @@ def get(self, key=None, default=None, category=None, return_obj=False, strattr=False, raise_exception=False, accessing_obj=None, default_access=True, return_list=False): ``` -Many classes have methods requiring lengthy positional argument lists, which are tedious and error-prone to extend and override especially in cases where not all arguments are even required. It would be useful if arguments were reserved for required inputs and anything else relegated to kwargs for easier passthrough on extension. +Many classes have methods requiring lengthy positional argument lists, which are tedious and error- +prone to extend and override especially in cases where not all arguments are even required. It would +be useful if arguments were reserved for required inputs and anything else relegated to kwargs for +easier passthrough on extension. diff --git a/docs/source/Accounts.md b/docs/source/Accounts.md index 81bb777e45..04b0c2d27a 100644 --- a/docs/source/Accounts.md +++ b/docs/source/Accounts.md @@ -4,7 +4,7 @@ All *users* (real people) that starts a game [Session](./Sessions) on Evennia are doing so through an object called *Account*. The Account object has no in-game representation, it represents a unique game account. In order to actually get on the game the Account must *puppet* an [Object](./Objects) -(normally a [Character](./Objects#Character)). +(normally a [Character](./Objects#Character)). Exactly how many Sessions can interact with an Account and its Puppets at once is determined by Evennia's [MULTISESSION_MODE](./Sessions#Multisession-mode) setting. @@ -12,13 +12,13 @@ Evennia's [MULTISESSION_MODE](./Sessions#Multisession-mode) setting. Apart from storing login information and other account-specific data, the Account object is what is chatting on [Channels](./Communications). It is also a good place to store [Permissions](./Locks) to be consistent between different in-game characters as well as configuration options. The Account -object also has its own [CmdSet](./Command-Sets), the `AccountCmdSet`. +object also has its own [CmdSet](./Command-Sets), the `AccountCmdSet`. Logged into default evennia, you can use the `ooc` command to leave your current [character](./Objects) and go into OOC mode. You are quite limited in this mode, basically it works like a simple chat program. It acts as a staging area for switching between Characters (if your game supports that) or as a safety mode if your Character gets deleted. Use `ic` to attempt to -(re)puppet a Character. +(re)puppet a Character. Note that the Account object can have, and often does have, a different set of [Permissions](./Locks#Permissions) from the Character they control. Normally you should put your @@ -26,32 +26,33 @@ permissions on the Account level - this will overrule permissions set on the Cha the permissions of the Character to come into play the default `quell` command can be used. This allows for exploring the game using a different permission set (but you can't escalate your permissions this way - for hierarchical permissions like `Builder`, `Admin` etc, the *lower* of the -permissions on the Character/Account will always be used). +permissions on the Character/Account will always be used). ## How to create your own Account types You will usually not want more than one Account typeclass for all new accounts (but you could in -principle create a system that changes an account's typeclass dynamically). +principle create a system that changes an account's typeclass dynamically). An Evennia Account is, per definition, a Python class that includes `evennia.DefaultAccount` among its parents. In `mygame/typeclasses/accounts.py` there is an empty class ready for you to modify. -Evennia defaults to using this (it inherits directly from `DefaultAccount`). +Evennia defaults to using this (it inherits directly from `DefaultAccount`). -Here's an example of modifying the default Account class in code: +Here's an example of modifying the default Account class in code: -```python +```python # in mygame/typeclasses/accounts.py from evennia import DefaultAccount class Account(DefaultAccount): # [...] - at_account_creation(self): "this is called only once, when account is first created" - self.db.real_name = None # this is set later self.db.real_address = None # " - self.db.config_1 = True # default config self.db.config_2 = False # " - self.db.config_3 = 1 # " + at_account_creation(self): "this is called only once, when account is first created" + self.db.real_name = None # this is set later self.db.real_address = None # +" + self.db.config_1 = True # default config self.db.config_2 = False # " + self.db.config_3 = 1 # " - # ... whatever else our game needs to know ``` Reload the server with `reload`. + # ... whatever else our game needs to know ``` Reload the server with `reload`. ``` @@ -65,7 +66,7 @@ using `py`: ``` py [account.at_account_creation() for account in evennia.managers.accounts.all()] ``` -You should now see the Attributes on yourself. +You should now see the Attributes on yourself. > If you wanted Evennia to default to a completely *different* Account class located elsewhere, you @@ -77,7 +78,7 @@ You should now see the Attributes on yourself. ## Properties on Accounts Beyond those properties assigned to all typeclassed objects (see [Typeclasses](./Typeclasses)), the -Account also has the following custom properties: +Account also has the following custom properties: - `user` - a unique link to a `User` Django object, representing the logged-in user. - `obj` - an alias for `character`. @@ -85,7 +86,8 @@ Account also has the following custom properties: - `sessions` - an instance of [ObjectSessionHandler](github:evennia.objects.objects#objectsessionhandler) managing all connected Sessions (physical connections) this object listens to (Note: In older - versions of Evennia, this was a list). The so-called `session-id` (used in many places) is found as + versions of Evennia, this was a list). The so-called `session-id` (used in many places) is found +as a property `sessid` on each Session instance. - `is_superuser` (bool: True/False) - if this account is a superuser. @@ -93,7 +95,8 @@ Special handlers: - `cmdset` - This holds all the current [Commands](./Commands) of this Account. By default these are the commands found in the cmdset defined by `settings.CMDSET_ACCOUNT`. - `nicks` - This stores and handles [Nicks](./Nicks), in the same way as nicks it works on Objects. - For Accounts, nicks are primarily used to store custom aliases for [Channels](./Communications#Channels). + For Accounts, nicks are primarily used to store custom aliases for +[Channels](./Communications#Channels). Selection of special methods (see `evennia.DefaultAccount` for details): - `get_puppet` - get a currently puppeted object connected to the Account and a given session id, if diff --git a/docs/source/Add-a-simple-new-web-page.md b/docs/source/Add-a-simple-new-web-page.md index da734c1476..f960c5a3e9 100644 --- a/docs/source/Add-a-simple-new-web-page.md +++ b/docs/source/Add-a-simple-new-web-page.md @@ -4,7 +4,7 @@ Evennia leverages [Django](https://docs.djangoproject.com) which is a web development framework. Huge professional websites are made in Django and there is extensive documentation (and books) on it . You are encouraged to at least look at the Django basic tutorials. Here we will just give a brief -introduction for how things hang together, to get you started. +introduction for how things hang together, to get you started. We assume you have installed and set up Evennia to run. A webserver and website comes out of the box. You can get to that by entering `http://localhost:4001` in your web browser - you should see a @@ -37,7 +37,7 @@ template some information from the request, for instance, the game name, and the We need to find a place where Evennia (and Django) looks for html files (called *templates* in Django parlance). You can specify such places in your settings (see the `TEMPLATES` variable in `default_settings.py` for more info), but here we'll use an existing one. Go to -`mygame/template/overrides/website/` and create a page `story.html` there. +`mygame/template/overrides/website/` and create a page `story.html` there. This is not a HTML tutorial, so we'll go simple: @@ -75,8 +75,9 @@ If you'd rather not take advantage of Evennia's base styles, you can do somethin When you enter the address `http://localhost:4001/story` in your web browser, Django will parse that field to figure out which page you want to go to. You tell it which patterns are relevant in the file -[mygame/web/urls.py](https://github.com/evennia/evennia/blob/master/evennia/game_template/web/urls.py). -Open it now. +[mygame/web/urls.py](https://github.com/evennia/evennia/blob/master/evennia/game_template/web/urls.p +y). +Open it now. Django looks for the variable `urlpatterns` in this file. You want to add your new pattern to the `custom_patterns` list we have prepared - that is then merged with the default `urlpatterns`. Here's diff --git a/docs/source/Add-a-wiki-on-your-website.md b/docs/source/Add-a-wiki-on-your-website.md index 161f15e33f..ab81e08bef 100644 --- a/docs/source/Add-a-wiki-on-your-website.md +++ b/docs/source/Add-a-wiki-on-your-website.md @@ -1,8 +1,8 @@ # Add a wiki on your website -**Before doing this tutorial you will probably want to read the intro in -[Basic Web tutorial](./Web-Tutorial).** Reading the three first parts of the +**Before doing this tutorial you will probably want to read the intro in +[Basic Web tutorial](./Web-Tutorial).** Reading the three first parts of the [Django tutorial](https://docs.djangoproject.com/en/1.9/intro/tutorial01/) might help as well. This tutorial will provide a step-by-step process to installing a wiki on your website. @@ -10,9 +10,12 @@ Fortunately, you don't have to create the features manually, since it has been d we can integrate their work quite easily with Django. I have decided to focus on the [Django-wiki](http://django-wiki.readthedocs.io/). -> Note: this article has been updated for Evennia 0.9. If you're not yet using this version, be careful, as the django wiki doesn't support Python 2 anymore. (Remove this note when enough time has passed.) +> Note: this article has been updated for Evennia 0.9. If you're not yet using this version, be +careful, as the django wiki doesn't support Python 2 anymore. (Remove this note when enough time +has passed.) -The [Django-wiki](http://django-wiki.readthedocs.io/) offers a lot of features associated with wikis, is +The [Django-wiki](http://django-wiki.readthedocs.io/) offers a lot of features associated with +wikis, is actively maintained (at this time, anyway), and isn't too difficult to install in Evennia. You can see a [demonstration of Django-wiki here](https://demo.django.wiki). @@ -37,14 +40,17 @@ Install the wiki using pip: pip install wiki -> Note: this will install the last version of Django wiki. Version >0.4 doesn't support Python 2, so install wiki 0.3 if you haven't updated to Python 3 yet. +> Note: this will install the last version of Django wiki. Version >0.4 doesn't support Python 2, so +install wiki 0.3 if you haven't updated to Python 3 yet. It might take some time, the Django-wiki having some dependencies. ### Adding the wiki in the settings You will need to add a few settings to have the wiki app on your website. Open your -`server/conf/settings.py` file and add the following at the bottom (but before importing `secret_settings`). Here's what you'll find in my own setting file (add the whole Django-wiki section): +`server/conf/settings.py` file and add the following at the bottom (but before importing +`secret_settings`). Here's what you'll find in my own setting file (add the whole Django-wiki +section): ```python r""" @@ -101,7 +107,7 @@ you will need to add two URLs in `custom_patterns` and add one import line: from django.conf.urls import url, include from django.urls import path # NEW! -# default evenni a patterns +# default evenni a patterns from evennia.web.urls import urlpatterns # eventual custom patterns @@ -144,7 +150,8 @@ who can write, a specific article. These settings must be placed, as usual, in your `server/conf/settings.py` file. They take a function as argument, said function (or callback) will be called with the article and the user. Remember, a Django user, for us, is an account. So we could check lockstrings on them if needed. -Here is a default setting to restrict the wiki: only builders can write in it, but anyone (including non-logged in users) can read it. The superuser has some additional privileges. +Here is a default setting to restrict the wiki: only builders can write in it, but anyone (including +non-logged in users) can read it. The superuser has some additional privileges. ```python # In server/conf/settings.py @@ -181,7 +188,9 @@ WIKI_CAN_READ = is_anyone ``` Here, we have created three functions: one to return `True` if the user is the superuser, one to -return `True` if the user is a builder, one to return `True` no matter what (this includes if the user is anonymous, E.G. if it's not logged-in). We then change settings to allow either the superuser or +return `True` if the user is a builder, one to return `True` no matter what (this includes if the +user is anonymous, E.G. if it's not logged-in). We then change settings to allow either the +superuser or each builder to moderate, read, write, delete, and more. You can, of course, add more functions, adapting them to your need. This is just a demonstration. @@ -191,21 +200,33 @@ need something more custom, you will have to expand on the functions you use. ### Managing wiki pages from Evennia -Unfortunately, Django wiki doesn't provide a clear and clean entry point to read and write articles from Evennia and it doesn't seem to be a very high priority. If you really need to keep Django wiki and to create and manage wiki pages from your code, you can do so, but this article won't elaborate, as this is somewhat more technical. +Unfortunately, Django wiki doesn't provide a clear and clean entry point to read and write articles +from Evennia and it doesn't seem to be a very high priority. If you really need to keep Django wiki +and to create and manage wiki pages from your code, you can do so, but this article won't elaborate, +as this is somewhat more technical. -However, it is a good opportunity to present a small project that has been created more recently: [evennia-wiki](https://github.com/vincent-lg/evennia-wiki) has been created to provide a simple wiki, more tailored to Evennia and easier to connect. It doesn't, as yet, provide as many options as does Django wiki, but it's perfectly usable: +However, it is a good opportunity to present a small project that has been created more recently: +[evennia-wiki](https://github.com/vincent-lg/evennia-wiki) has been created to provide a simple +wiki, more tailored to Evennia and easier to connect. It doesn't, as yet, provide as many options +as does Django wiki, but it's perfectly usable: - Pages have an inherent and much-easier to understand hierarchy based on URLs. -- Article permissions are connected to Evennia groups and are much easier to accommodate specific requirements. +- Article permissions are connected to Evennia groups and are much easier to accommodate specific +requirements. - Articles can easily be created, read or updated from the Evennia code itself. -- Markdown is fully-supported with a default integration to Bootstrap to look good on an Evennia website. Tables and table of contents are supported as well as wiki links. +- Markdown is fully-supported with a default integration to Bootstrap to look good on an Evennia +website. Tables and table of contents are supported as well as wiki links. - The process to override wiki templates makes full use of the `template_overrides` directory. However evennia-wiki doesn't yet support: -- Images in markdown and the uploading schema. If images are important to you, please consider contributing to this new project. +- Images in markdown and the uploading schema. If images are important to you, please consider +contributing to this new project. - Modifying permissions on a per page/setting basis. - Moving pages to new locations. - Viewing page history. -Considering the list of features in Django wiki, obviously other things could be added to the list. However, these features may be the most important and useful. Additional ones might not be that necessary. If you're interested in supporting this little project, you are more than welcome to [contribute to it](https://github.com/vincent-lg/evennia-wiki). Thanks! \ No newline at end of file +Considering the list of features in Django wiki, obviously other things could be added to the list. +However, these features may be the most important and useful. Additional ones might not be that +necessary. If you're interested in supporting this little project, you are more than welcome to +[contribute to it](https://github.com/vincent-lg/evennia-wiki). Thanks! \ No newline at end of file diff --git a/docs/source/Adding-Command-Tutorial.md b/docs/source/Adding-Command-Tutorial.md index 57babec47b..36e1600542 100644 --- a/docs/source/Adding-Command-Tutorial.md +++ b/docs/source/Adding-Command-Tutorial.md @@ -1,19 +1,23 @@ # Adding Command Tutorial -This is a quick first-time tutorial expanding on the [Commands](./Commands) documentation. +This is a quick first-time tutorial expanding on the [Commands](./Commands) documentation. Let's assume you have just downloaded Evennia, installed it and created your game folder (let's call -it just `mygame` here). Now you want to try to add a new command. This is the fastest way to do it. +it just `mygame` here). Now you want to try to add a new command. This is the fastest way to do it. ## Step 1: Creating a custom command -1. Open `mygame/commands/command.py` in a text editor. This is just one place commands could be placed but you get it setup from the onset as an easy place to start. It also already contains some example code. +1. Open `mygame/commands/command.py` in a text editor. This is just one place commands could be +placed but you get it setup from the onset as an easy place to start. It also already contains some +example code. 1. Create a new class in `command.py` inheriting from `default_cmds.MuxCommand`. Let's call it `CmdEcho` in this example. 1. Set the class variable `key` to a good command name, like `echo`. -1. Give your class a useful _docstring_. A docstring is the string at the very top of a class or function/method. The docstring at the top of the command class is read by Evennia to become the help entry for the Command (see +1. Give your class a useful _docstring_. A docstring is the string at the very top of a class or +function/method. The docstring at the top of the command class is read by Evennia to become the help +entry for the Command (see [Command Auto-help](./Help-System#command-auto-help-system)). -1. Define a class method `func(self)` that echoes your input back to you. +1. Define a class method `func(self)` that echoes your input back to you. Below is an example how this all could look for the echo command: @@ -25,7 +29,7 @@ Below is an example how this all could look for the echo command: """ Simple command example - Usage: + Usage: echo [text] This command simply echoes text back to the caller. @@ -34,9 +38,9 @@ Below is an example how this all could look for the echo command: key = "echo" def func(self): - "This actually does things" + "This actually does things" if not self.args: - self.caller.msg("You didn't enter anything!") + self.caller.msg("You didn't enter anything!") else: self.caller.msg("You gave the string: '%s'" % self.args) ``` @@ -45,12 +49,12 @@ Below is an example how this all could look for the echo command: The command is not available to use until it is part of a [Command Set](./Command-Sets). In this example we will go the easiest route and add it to the default Character commandset that already -exists. +exists. 1. Edit `mygame/commands/default_cmdsets.py` 1. Import your new command with `from commands.command import CmdEcho`. 1. Add a line `self.add(CmdEcho())` to `CharacterCmdSet`, in the `at_cmdset_creation` method (the - template tells you where). + template tells you where). This is approximately how it should look at this point: @@ -66,10 +70,10 @@ This is approximately how it should look at this point: def at_cmdset_creation(self): # this first adds all default commands - super(DefaultSet, self).at_cmdset_creation() + super().at_cmdset_creation() - # all commands added after this point will extend or - # overwrite the default commands. + # all commands added after this point will extend or + # overwrite the default commands. self.add(CmdEcho()) ``` @@ -79,12 +83,15 @@ the game. Use `help echo` to see the documentation for the command. If you have trouble, make sure to check the log for error messages (probably due to syntax errors in your command definition). -> Note: Typing `echotest` will also work. It will be handled as the command `echo` directly followed by -its argument `test` (which will end up in `self.args). To change this behavior, you can add the `arg_regex` property alongside `key`, `help_category` etc. [See the arg_regex documentation](./Commands#on-arg_regex) for more info. +> Note: Typing `echotest` will also work. It will be handled as the command `echo` directly followed +by +its argument `test` (which will end up in `self.args). To change this behavior, you can add the +`arg_regex` property alongside `key`, `help_category` etc. [See the arg_regex +documentation](Commands#on-arg_regex) for more info. If you want to overload existing default commands (such as `look` or `get`), just add your new command with the same key as the old one - it will then replace it. Just remember that you must use -`@reload` to see any changes. +`@reload` to see any changes. See [Commands](./Commands) for many more details and possibilities when defining Commands and using Cmdsets in various ways. @@ -107,7 +114,7 @@ documentation](Command-Sets)). key = "MyCmdSet" - def at_cmdset_creation(self): + def at_cmdset_creation(self): self.add(CmdEcho()) ``` Now you just need to add this to an object. To test things (as superuser) you can do @@ -124,7 +131,7 @@ only make the new merged cmdset permanent on that *single* object. Often you wan this particular class to have this cmdset. To make sure all new created objects get your new merged set, put the `cmdset.add` call in your -custom [Typeclasses](./Typeclasses)' `at_object_creation` method: +custom [Typeclasses](./Typeclasses)' `at_object_creation` method: ```python # e.g. in mygame/typeclasses/objects.py @@ -135,24 +142,25 @@ custom [Typeclasses](./Typeclasses)' `at_object_creation` method: def at_object_creation(self): "called when the object is first created" self.cmdset.add("mycmdset.MyCmdSet", permanent=True) -``` +``` -All new objects of this typeclass will now start with this cmdset and it will survive a `@reload`. +All new objects of this typeclass will now start with this cmdset and it will survive a `@reload`. *Note:* An important caveat with this is that `at_object_creation` is only called *once*, when the object is first created. This means that if you already have existing objects in your databases using that typeclass, they will not have been initiated the same way. There are many ways to update them; since it's a one-time update you can usually just simply loop through them. As superuser, try -the following: +the following: - @py from typeclasses.objects import MyObject; [o.cmdset.add("mycmdset.MyCmdSet") for o in MyObject.objects.all()] + @py from typeclasses.objects import MyObject; [o.cmdset.add("mycmdset.MyCmdSet") for o in +MyObject.objects.all()] This goes through all objects in your database having the right typeclass, adding the new cmdset to each. The good news is that you only have to do this if you want to post-add *cmdsets*. If you just want to add a new *command*, you can simply add that command to the cmdset's `at_cmdset_creation` and `@reload` to make the Command immediately available. -## Change where Evennia looks for command sets +## Change where Evennia looks for command sets Evennia uses settings variables to know where to look for its default command sets. These are normally not changed unless you want to re-organize your game folder in some way. For example, the @@ -160,4 +168,4 @@ default character cmdset defaults to being defined as CMDSET_CHARACTER="commands.default_cmdset.CharacterCmdSet" -See `evennia/settings_default.py` for the other settings. +See `evennia/settings_default.py` for the other settings. diff --git a/docs/source/Adding-Object-Typeclass-Tutorial.md b/docs/source/Adding-Object-Typeclass-Tutorial.md index 2108f61d2b..4e532a5c75 100644 --- a/docs/source/Adding-Object-Typeclass-Tutorial.md +++ b/docs/source/Adding-Object-Typeclass-Tutorial.md @@ -3,7 +3,7 @@ Evennia comes with a few very basic classes of in-game entities: DefaultObject - | + | DefaultCharacter DefaultRoom DefaultExit @@ -11,7 +11,7 @@ Evennia comes with a few very basic classes of in-game entities: When you create a new Evennia game (with for example `evennia --init mygame`) Evennia will automatically create empty child classes `Object`, `Character`, `Room` and `Exit` respectively. They -are found `mygame/typeclasses/objects.py`, `mygame/typeclasses/rooms.py` etc. +are found `mygame/typeclasses/objects.py`, `mygame/typeclasses/rooms.py` etc. > Technically these are all [Typeclassed](./Typeclasses), which can be ignored for now. In > `mygame/typeclasses` are also base typeclasses for out-of-character things, notably @@ -20,7 +20,7 @@ are found `mygame/typeclasses/objects.py`, `mygame/typeclasses/rooms.py` etc. For your own game you will most likely want to expand on these very simple beginnings. It's normal to want your Characters to have various attributes, for example. Maybe Rooms should hold extra -information or even *all* Objects in your game should have properties not included in basic Evennia. +information or even *all* Objects in your game should have properties not included in basic Evennia. ## Change Default Rooms, Exits, Character Typeclass @@ -29,7 +29,7 @@ This is the simplest case. The default build commands of a new Evennia game is set up to use the `Room`, `Exit` and `Character` classes found in the same-named modules under `mygame/typeclasses/`. By default these are empty and just implements the default parents from the Evennia library (`DefaultRoom`etc). Just add the -changes you want to these classes and run `@reload` to add your new functionality. +changes you want to these classes and run `@reload` to add your new functionality. ## Create a new type of object @@ -60,7 +60,7 @@ up. rock:objects.Heavy` to drop a new heavy "rock" object in your location. Next try to pick it up (`@quell` yourself first if you are a superuser). If you get errors, look at your log files where you will find the traceback. The most common error is that you have some sort of syntax error in -your class. +your class. Note that the [Locks](./Locks) and [Attribute](./Attributes) which are set in the typeclass could just as well have been set using commands in-game, so this is a *very* simple example. @@ -71,10 +71,10 @@ The `at_object_creation` is only called once, when the object is first created. for database-bound things like [Attributes](./Attributes). But sometimes you want to create temporary properties (things that are not to be stored in the database but still always exist every time the object is created). Such properties can be initialized in the `at_init` method on the object. -`at_init` is called every time the object is loaded into memory. +`at_init` is called every time the object is loaded into memory. > Note: It's usually pointless and wasteful to assign database data in `at_init`, since this will -> hit the database with the same value over and over. Put those in `at_object_creation` instead. +> hit the database with the same value over and over. Put those in `at_object_creation` instead. You are wise to use `ndb` (non-database Attributes) to store these non-persistent properties, since ndb-properties are protected against being cached out in various ways and also allows you to list @@ -88,7 +88,7 @@ def at_init(self): > Note: As mentioned in the [Typeclasses](./Typeclasses) documentation, `at_init` replaces the use of > the standard `__init__` method of typeclasses due to how the latter may be called in situations -> other than you'd expect. So use `at_init` where you would normally use `__init__`. +> other than you'd expect. So use `at_init` where you would normally use `__init__`. ## Updating existing objects @@ -96,14 +96,14 @@ def at_init(self): If you already have some `Heavy` objects created and you add a new `Attribute` in `at_object_creation`, you will find that those existing objects will not have this Attribute. This is not so strange, since `at_object_creation` is only called once, it will not be called again just -because you update it. You need to update existing objects manually. +because you update it. You need to update existing objects manually. If the number of objects is limited, you can use `@typeclass/force/reload objectname` to force a re-load of the `at_object_creation` method (only) on the object. This case is common enough that there is an alias `@update objectname` you can use to get the same effect. If there are multiple -objects you can use `@py` to loop over the objects you need: +objects you can use `@py` to loop over the objects you need: ``` @py from typeclasses.objects import Heavy; [obj.at_object_creation() for obj in Heavy.objects.all()] -``` +``` diff --git a/docs/source/Administrative-Docs.md b/docs/source/Administrative-Docs.md index 00997fc793..e67c8be5c9 100644 --- a/docs/source/Administrative-Docs.md +++ b/docs/source/Administrative-Docs.md @@ -1,6 +1,7 @@ # Administrative Docs -The following pages are aimed at game administrators -- the higher-ups that possess shell access and are responsible for managing the game. +The following pages are aimed at game administrators -- the higher-ups that possess shell access and +are responsible for managing the game. ### Installation and Early Life @@ -13,12 +14,14 @@ The following pages are aimed at game administrators -- the higher-ups that poss - [Making your game available online](./Online-Setup) - [Hosting options](./Online-Setup#hosting-options) - [Securing your server with SSL/Let's Encrypt](./Online-Setup#ssl) -- [Listing your game](./Evennia-Game-Index) at the online [Evennia game index](http://games.evennia.com) +- [Listing your game](./Evennia-Game-Index) at the online [Evennia game +index](http://games.evennia.com) ### Customizing the server -- [Changing the Settings](./Server-Conf#Settings-file) - - [Available Master Settings](https://github.com/evennia/evennia/blob/master/evennia/settings_default.py) +- [Changing the Settings](./Server-Conf#Settings-file) + - [Available Master +Settings](https://github.com/evennia/evennia/blob/master/evennia/settings_default.py) - [Change Evennia's language](./Internationalization) (internationalization) - [Apache webserver configuration](./Apache-Config) (optional) - [Changing text encodings used by the server](./Text-Encodings) diff --git a/docs/source/Apache-Config.md b/docs/source/Apache-Config.md index 40f911f618..76a21ee24f 100644 --- a/docs/source/Apache-Config.md +++ b/docs/source/Apache-Config.md @@ -9,7 +9,7 @@ tweaking) on a third-party web server. One reason for wanting to use an external webserver like Apache would be to act as a *proxy* in front of the Evennia webserver. Getting this working with TLS (encryption) requires some extra work -covered at the end of this page. +covered at the end of this page. Note that the Apache instructions below might be outdated. If something is not working right, or you use Evennia with a different server, please let us know. Also, if there is a particular Linux distro @@ -19,13 +19,15 @@ you would like covered, please let us know. ### Install `mod_wsgi` -- *Fedora/RHEL* - Apache HTTP Server and `mod_wsgi` are available in the standard package repositories for Fedora and RHEL: +- *Fedora/RHEL* - Apache HTTP Server and `mod_wsgi` are available in the standard package +repositories for Fedora and RHEL: ``` $ dnf install httpd mod_wsgi or $ yum install httpd mod_wsgi ``` -- *Ubuntu/Debian* - Apache HTTP Server and `mod_wsgi` are available in the standard package repositories for Ubuntu and Debian: +- *Ubuntu/Debian* - Apache HTTP Server and `mod_wsgi` are available in the standard package +repositories for Ubuntu and Debian: ``` $ apt-get update $ apt-get install apache2 libapache2-mod-wsgi @@ -67,14 +69,15 @@ Ubuntu), you may tell `mod_wsgi` to reload by using the `touch` command on changed, it will force a code reload. Any modifications to the code will not be propagated to the live instance of your site until reloaded. -If you are not running in daemon mode or want to force the issue, simply restart or reload apache2 to apply your changes. +If you are not running in daemon mode or want to force the issue, simply restart or reload apache2 +to apply your changes. ### Further notes and hints: If you get strange (and usually uninformative) `Permission denied` errors from Apache, make sure that your `evennia` directory is located in a place the webserver may actually access. For example, some Linux distributions may default to very restrictive access permissions on a user's `/home` -directory. +directory. One user commented that they had to add the following to their Apache config to get things to work. Not confirmed, but worth trying if there are trouble. @@ -87,23 +90,27 @@ Not confirmed, but worth trying if there are trouble. ## `mod_proxy` and `mod_ssl` setup Below are steps on running Evennia using a front-end proxy (Apache HTTP), `mod_proxy_http`, -`mod_proxy_wstunnel`, and `mod_ssl`. `mod_proxy_http` and `mod_proxy_wstunnel` will simply be referred to as -`mod_proxy` below. +`mod_proxy_wstunnel`, and `mod_ssl`. `mod_proxy_http` and `mod_proxy_wstunnel` will simply be +referred to as +`mod_proxy` below. ### Install `mod_ssl` -- *Fedora/RHEL* - Apache HTTP Server and `mod_ssl` are available in the standard package repositories for Fedora and RHEL: +- *Fedora/RHEL* - Apache HTTP Server and `mod_ssl` are available in the standard package +repositories for Fedora and RHEL: ``` $ dnf install httpd mod_ssl or $ yum install httpd mod_ssl ``` -- *Ubuntu/Debian* - Apache HTTP Server and `mod_sslj`kl are installed together in the `apache2` package and available in the -standard package repositories for Ubuntu and Debian. `mod_ssl` needs to be enabled after installation: +- *Ubuntu/Debian* - Apache HTTP Server and `mod_sslj`kl are installed together in the `apache2` +package and available in the +standard package repositories for Ubuntu and Debian. `mod_ssl` needs to be enabled after +installation: ``` $ apt-get update - $ apt-get install apache2 + $ apt-get install apache2 $ a2enmod ssl ``` @@ -161,4 +168,4 @@ The setting above is what the client's browser will actually use. Note the use o because our client will be communicating over an encrypted connection ("wss" indicates websocket over SSL/TLS). Also, especially note the additional path `/ws` at the end of the URL. This is how Apache HTTP Server identifies that a particular request should be proxied to Evennia's websocket -port but this should be applicable also to other types of proxies (like nginx). +port but this should be applicable also to other types of proxies (like nginx). diff --git a/docs/source/Arxcode-installing-help.md b/docs/source/Arxcode-installing-help.md index 557b439762..3876b841f9 100644 --- a/docs/source/Arxcode-installing-help.md +++ b/docs/source/Arxcode-installing-help.md @@ -1,6 +1,6 @@ # Arxcode installing help -## Introduction +## Introduction [Arx - After the Reckoning](http://play.arxmush.org/) is a big and very popular [Evennia](http://www.evennia.com)-based game. Arx is heavily roleplaying-centric, relying on game @@ -10,20 +10,24 @@ Arx on github](https://github.com/Arx-Game/arxcode). This is a treasure-trove fo to pick ideas or even get a starting game to build on. These instructions are based on the Arx-code released as of *Aug 12, 2018*. -If you are not familiar with what Evennia is, you can read -[an introduction here](./Evennia-Introduction). +If you are not familiar with what Evennia is, you can read +[an introduction here](./Evennia-Introduction). It's not too hard to run Arx from the sources (of course you'll start with an empty database) but since part of Arx has grown organically, it doesn't follow standard Evennia paradigms everywhere. This page covers one take on installing and setting things up while making your new Arx-based game -better match with the vanilla Evennia install. +better match with the vanilla Evennia install. ## Installing Evennia -Firstly, set aside a folder/directory on your drive for everything to follow. +Firstly, set aside a folder/directory on your drive for everything to follow. -You need to start by installing [Evennia](http://www.evennia.com) by following most of the [Getting Started -Instructions](Getting-Started) for your OS. The difference is that you need to `git clone https://github.com/TehomCD/evennia.git` instead of Evennia's repo because Arx uses TehomCD's older Evennia 0.8 [fork](https://github.com/TehomCD/evennia), notably still using Python2. This detail is important if referring to newer Evennia documentation. +You need to start by installing [Evennia](http://www.evennia.com) by following most of the [Getting +Started +Instructions](Getting-Started) for your OS. The difference is that you need to `git clone +https://github.com/TehomCD/evennia.git` instead of Evennia's repo because Arx uses TehomCD's older +Evennia 0.8 [fork](https://github.com/TehomCD/evennia), notably still using Python2. This detail is +important if referring to newer Evennia documentation. If you are new to Evennia it's *highly* recommended that you run through the instructions in full - including initializing and starting a new empty game and connecting to it. @@ -31,9 +35,10 @@ That way you can be sure Evennia works correctly as a base line. If you have tro read the [Troubleshooting instructions](./Getting-Started#troubleshooting) for your operating system. You can also drop into our [forums](https://groups.google.com/forum/#%21forum/evennia), join `#evennia` on `irc.freenode.net` -or chat from the linked [Discord Server](https://discord.gg/NecFePw). +or chat from the linked [Discord Server](https://discord.gg/NecFePw). -After installing you should have a `virtualenv` running and you should have the following file structure in your set-aside folder: +After installing you should have a `virtualenv` running and you should have the following file +structure in your set-aside folder: ``` vienv/ @@ -45,30 +50,31 @@ mygame/ Here `mygame` is the empty game you created during the Evennia install, with `evennia --init`. Go to that and run `evennia stop` to make sure your empty game is not running. We'll instead let Evenna run Arx, so in principle you could erase `mygame` - but it could also be good to have a clean game -to compare to. +to compare to. ## Installing Arxcode ### Clone the arxcode repo -Cd to the root of your directory and clone the released source code from github: +Cd to the root of your directory and clone the released source code from github: - git clone https://github.com/Arx-Game/arxcode.git myarx + git clone https://github.com/Arx-Game/arxcode.git myarx A new folder `myarx` should appear next to the ones you already had. You could rename this to -something else if you want. +something else if you want. -Cd into `myarx`. If you wonder about the structure of the game dir, you can [read more about it here](./Directory-Overview). +Cd into `myarx`. If you wonder about the structure of the game dir, you can [read more about it +here](Directory-Overview). ### Clean up settings Arx has split evennia's normal settings into `base_settings.py` and `production_settings.py`. It also has its own solution for managing 'secret' parts of the settings file. We'll keep most of Arx -way but remove the secret-handling and replace it with the normal Evennia method. +way but remove the secret-handling and replace it with the normal Evennia method. Cd into `myarx/server/conf/` and open the file `settings.py` in a text editor. The top part (within `"""..."""`) is just help text. Wipe everything underneath that and make it look like this instead -(don't forget to save): +(don't forget to save): ``` from base_settings import * @@ -84,14 +90,15 @@ except ImportError: ``` > Note: Indents and capitalization matter in Python. Make indents 4 spaces (not tabs) for your own -> sanity. If you want a starter on Python in Evennia, [you can look here](./Python-basic-introduction). +> sanity. If you want a starter on Python in Evennia, [you can look here](Python-basic- +introduction). This will import Arx' base settings and override them with the Evennia-default telnet port and give the game a name. The slogan changes the sub-text shown under the name of your game in the website header. You can tweak these to your own liking later. Next, create a new, empty file `secret_settings.py` in the same location as the `settings.py` file. -This can just contain the following: +This can just contain the following: ```python SECRET_KEY = "sefsefiwwj3 jnwidufhjw4545_oifej whewiu hwejfpoiwjrpw09&4er43233fwefwfw" @@ -99,35 +106,35 @@ SECRET_KEY = "sefsefiwwj3 jnwidufhjw4545_oifej whewiu hwejfpoiwjrpw09&4er43233fw ``` Replace the long random string with random ASCII characters of your own. The secret key should not -be shared. +be shared. Next, open `myarx/server/conf/base_settings.py` in your text editor. We want to remove/comment out all mentions of the `decouple` package, which Evennia doesn't use (we use `private_settings.py` to -hide away settings that should not be shared). +hide away settings that should not be shared). Comment out `from decouple import config` by adding a `#` to the start of the line: `# from decouple import config`. Then search for `config(` in the file and comment out all lines where this is used. Many of these are specific to the server environment where the original Arx runs, so is not that -relevant to us. +relevant to us. -### Install Arx dependencies +### Install Arx dependencies Arx has some further dependencies beyond vanilla Evennia. Start by `cd`:ing to the root of your -`myarx` folder. +`myarx` folder. > If you run *Linux* or *Mac*: Edit `myarx/requirements.txt` and comment out the line -> `pypiwin32==219` - it's only needed on Windows and will give an error on other platforms. +> `pypiwin32==219` - it's only needed on Windows and will give an error on other platforms. Make sure your `virtualenv` is active, then run pip install -r requirements.txt -The needed Python packages will be installed for you. +The needed Python packages will be installed for you. ### Adding logs/ folder The Arx repo does not contain the `myarx/server/logs/` folder Evennia expects for storing server -logs. This is simple to add: +logs. This is simple to add: # linux/mac mkdir server/logs @@ -136,7 +143,7 @@ logs. This is simple to add: ### Setting up the database and starting -From the `myarx` folder, run +From the `myarx` folder, run evennia migrate @@ -147,7 +154,7 @@ This creates the database and will step through all database migrations needed. If all goes well Evennia will now start up, running Arx! You can connect to it on `localhost` (or `127.0.0.1` if your platform doesn't alias `localhost`), port `4000` using a Telnet client. Alternatively, you can use your web browser to browse to `http://localhost:4001` to see the game's -website and get to the web client. +website and get to the web client. When you log in you'll get the standard Evennia greeting (since the database is empty), but you can try `help` to see that it's indeed Arx that is running. @@ -158,7 +165,7 @@ The first time you start Evennia after creating the database with the `evennia m it should create a few starting objects for you - your superuser account, which it will prompt you to enter, a starting room (Limbo), and a character object for you. If for some reason this does not occur, you may have to follow the steps below. For the first time Superuser login you may have to -run steps 7-8 and 10 to create and connect to your in-came Character. +run steps 7-8 and 10 to create and connect to your in-came Character. 1. Login to the game website with your Superuser account. 2. Press the `Admin` button to get into the (Django-) Admin Interface. @@ -166,24 +173,27 @@ run steps 7-8 and 10 to create and connect to your in-came Character. 4. Add a new Account named for the new staffer. Use a place holder password and dummy e-mail address. 5. Flag account as `Staff` and apply the `Admin` permission group (This assumes you have already set - up an Admin Group in Django). -6. Add Tags named `player` and `developer`. + up an Admin Group in Django). +6. Add Tags named `player` and `developer`. 7. Log into the game using the web client (or a third-party telnet client) using your superuser - account. Move to where you want the new staffer character to appear. + account. Move to where you want the new staffer character to appear. 8. In the game client, run `@create/drop :typeclasses.characters.Character`, where `` is usually the same name you used for the Staffer account you created in the - Admin earlier (if you are creating a Character for your superuser, use your superuser account name). + Admin earlier (if you are creating a Character for your superuser, use your superuser account +name). This creates a new in-game Character and places it in your current location. 9. Have the new Admin player log into the game. -10. Have the new Admin puppet the character with `@ic StafferName`. +10. Have the new Admin puppet the character with `@ic StafferName`. 11. Have the new Admin change their password - `@password = `. Now that you have a Character and an Account object, there's a few additional things you may need to do in order for some commands to function properly. You can either execute these as in-game commands while `@ic` (controlling your character object). -1. `@py from web.character.models import RosterEntry;RosterEntry.objects.create(player=self.player, character=self)` -2. `@py from world.dominion.models import PlayerOrNpc, AssetOwner;dompc = PlayerOrNpc.objects.create(player = self.player);AssetOwner.objects.create(player=dompc)` +1. `@py from web.character.models import RosterEntry;RosterEntry.objects.create(player=self.player, +character=self)` +2. `@py from world.dominion.models import PlayerOrNpc, AssetOwner;dompc = +PlayerOrNpc.objects.create(player = self.player);AssetOwner.objects.create(player=dompc)` Those steps will give you a 'RosterEntry', 'PlayerOrNpc', and 'AssetOwner' objects. RosterEntry explicitly connects a character and account object together, even while offline, and contains @@ -195,7 +205,9 @@ AssetOwner holds information about a character or organization's money and resou ## Alternate guide by Pax for installing on Windows -If for some reason you cannot use the Windows Subsystem for Linux (which would use instructions identical to the ones above), it's possible to get Evennia running under Anaconda for Windows. The process is a little bit trickier. +If for some reason you cannot use the Windows Subsystem for Linux (which would use instructions +identical to the ones above), it's possible to get Evennia running under Anaconda for Windows. The +process is a little bit trickier. Make sure you have: * Git for Windows https://git-scm.com/download/win @@ -214,14 +226,14 @@ cd Source mkdir Arx cd Arx - Replace the SSH git clone links below with your own github forks. - If you don't plan to change Evennia at all, you can use the + Replace the SSH git clone links below with your own github forks. + If you don't plan to change Evennia at all, you can use the evennia/evennia.git repo instead of a forked one. git clone git@github.com:/evennia.git git clone git@github.com:/arxcode.git - Evennia is a package itself, so we want to install it and all of its + Evennia is a package itself, so we want to install it and all of its prerequisites, after switching to the appropriately-tagged branch for Arxcode. @@ -236,7 +248,7 @@ cd ../arxcode pip install -r requirements.txt The git repo doesn't include the empty log directory and Evennia is unhappy if you - don't have it, so while still in the arxcode directory... + don't have it, so while still in the arxcode directory... mkdir server/logs diff --git a/docs/source/Async-Process.md b/docs/source/Async-Process.md index 3091d3c235..f994d63ea4 100644 --- a/docs/source/Async-Process.md +++ b/docs/source/Async-Process.md @@ -75,7 +75,8 @@ line quite pointless for processing any data from the function. Instead one has print(r) ``` -- `at_return_kwargs` - an optional dictionary that will be fed as keyword arguments to the `at_return` callback. +- `at_return_kwargs` - an optional dictionary that will be fed as keyword arguments to the +`at_return` callback. - `at_err(e)` (the *errback*) is called if the asynchronous function fails and raises an exception. This exception is passed to the errback wrapped in a *Failure* object `e`. If you do not supply an errback of your own, Evennia will automatically add one that silently writes errors to the evennia @@ -98,9 +99,9 @@ An example of making an asynchronous call from inside a [Command](./Commands) de key = "asynccommand" - def func(self): + def func(self): - def long_running_function(): + def long_running_function(): #[... lots of time-consuming code ...] return final_value @@ -111,12 +112,14 @@ An example of making an asynchronous call from inside a [Command](./Commands) de self.caller.msg("There was an error: %s" % e) # do the async call, setting all callbacks - utils.run_async(long_running_function, at_return=at_return_function, at_err=at_err_function) + utils.run_async(long_running_function, at_return=at_return_function, +at_err=at_err_function) ``` That's it - from here on we can forget about `long_running_function` and go on with what else need -to be done. *Whenever* it finishes, the `at_return_function` function will be called and the final value will -pop up for us to see. If not we will see an error message. +to be done. *Whenever* it finishes, the `at_return_function` function will be called and the final +value will +pop up for us to see. If not we will see an error message. ## delay @@ -145,9 +148,10 @@ You can also try the following snippet just see how it works: Wait 10 seconds and 'Test!' should be echoed back to you. -## The @interactive decorator +## The @interactive decorator -As of Evennia 0.9, the `@interactive` [decorator](https://realpython.com/primer-on-python-decorators/) +As of Evennia 0.9, the `@interactive` [decorator](https://realpython.com/primer-on-python- +decorators/) is available. This makes any function or method possible to 'pause' and/or await player input in an interactive way. @@ -162,10 +166,10 @@ in an interactive way. yield(5) caller.msg("Now 5 seconds have passed.") - response = yield("Do you want to wait another 5 secs?") + response = yield("Do you want to wait another 5 secs?") if response.lower() not in ("yes", "y"): - break + break ``` The `@interactive` decorator gives the function the ability to pause. The use @@ -179,15 +183,15 @@ allows you to ask the user for input. You can then process the input, just like you would if you used the Python `input` function. There is one caveat to this functionality though - _it will only work if the function/method has an argument named exactly `caller`_. This is because internally Evennia will look -for the `caller` argument and treat that as the source of input. +for the `caller` argument and treat that as the source of input. All of this makes the `@interactive` decorator very useful. But it comes with a few caveats. Notably, decorating a function/method with `@interactive` turns it into a Python [generator](https://wiki.python.org/moin/Generators). The most common issue is that you cannot use `return ` from a generator (just an empty `return` works). To return a value from a function/method you have decorated -with `@interactive`, you must instead use a special Twisted function -`twisted.internet.defer.returnValue`. Evennia also makes this function +with `@interactive`, you must instead use a special Twisted function +`twisted.internet.defer.returnValue`. Evennia also makes this function conveniently available from `evennia.utils`: ```python @@ -196,7 +200,7 @@ conveniently available from `evennia.utils`: @interactive def myfunc(): - # ... + # ... result = 10 # this must be used instead of `return result` @@ -223,7 +227,8 @@ expected, but they may appear with delays or in groups. ## Further reading Technically, `run_async` is just a very thin and simplified wrapper around a -[Twisted Deferred](http://twistedmatrix.com/documents/9.0.0/core/howto/defer.html) object; the wrapper sets +[Twisted Deferred](http://twistedmatrix.com/documents/9.0.0/core/howto/defer.html) object; the +wrapper sets up a default errback also if none is supplied. If you know what you are doing there is nothing stopping you from bypassing the utility function, building a more sophisticated callback chain after your own liking. diff --git a/docs/source/Attributes.md b/docs/source/Attributes.md index 6bd71f8180..e8f91e7529 100644 --- a/docs/source/Attributes.md +++ b/docs/source/Attributes.md @@ -15,7 +15,8 @@ specific names and require very specific types of data (for example you couldn't *list* to the `key` property no matter how hard you tried). `Attributes` come into play when you want to assign arbitrary data to arbitrary names. -**Attributes are _not_ secure by default and any player may be able to change them unless you [prevent this behavior](./Attributes#locking-and-checking-attributes).** +**Attributes are _not_ secure by default and any player may be able to change them unless you +[prevent this behavior](./Attributes#locking-and-checking-attributes).** ## The .db and .ndb shortcuts @@ -52,7 +53,8 @@ is tracked by the server and will not be purged in various cache-cleanup operati while it runs. Data stored on `ndb` (as well as `db`) will also be easily listed by example the `@examine` command. -You can also `del` properties on `db` and `ndb` as normal. This will for example delete an `Attribute`: +You can also `del` properties on `db` and `ndb` as normal. This will for example delete an +`Attribute`: ```python del rose.db.has_thorns @@ -116,12 +118,15 @@ An Attribute object is stored in the database. It has the following properties: to `attrname`. - `value` - this is the value of the Attribute. This value can be anything which can be pickled - objects, lists, numbers or what have you (see - [this section](./Attributes#What_types_of_data_can_I_save_in_an_Attribute) for more info). In the example + [this section](./Attributes#What_types_of_data_can_I_save_in_an_Attribute) for more info). In the +example `obj.db.attrname = value`, the `value` is stored here. - `category` - this is an optional property that is set to None for most Attributes. Setting this allows to use Attributes for different functionality. This is usually not needed unless you want - to use Attributes for very different functionality ([Nicks](./Nicks) is an example of using Attributes - in this way). To modify this property you need to use the [Attribute Handler](./Attributes#The_Attribute_Handler). + to use Attributes for very different functionality ([Nicks](./Nicks) is an example of using +Attributes + in this way). To modify this property you need to use the [Attribute +Handler](Attributes#The_Attribute_Handler). - `strvalue` - this is a separate value field that only accepts strings. This severely limits the data possible to store, but allows for easier database lookups. This property is usually not used except when re-using Attributes for some other purpose ([Nicks](./Nicks) use it). It is only @@ -151,13 +156,15 @@ useful in a few situations though. this is not an issue unless you are reading *and* writing to your Attribute very often (like many times per second). Reading from an already cached Attribute is as fast as reading any Python property. But even then this is not likely something to worry about: Apart from Evennia's own - caching, modern database systems themselves also cache data very efficiently for speed. Our default + caching, modern database systems themselves also cache data very efficiently for speed. Our +default database even runs completely in RAM if possible, alleviating much of the need to write to disk during heavy loads. - A more valid reason for using non-persistent data is if you *want* to lose your state when logging off. Maybe you are storing throw-away data that are re-initialized at server startup. Maybe you are implementing some caching of your own. Or maybe you are testing a buggy [Script](./Scripts) that - does potentially harmful stuff to your character object. With non-persistent storage you can be sure + does potentially harmful stuff to your character object. With non-persistent storage you can be +sure that whatever is messed up, it's nothing a server reboot can't clear up. - NAttributes have no restrictions at all on what they can store (see next section), since they don't need to worry about being saved to the database - they work very well for temporary storage. @@ -185,11 +192,13 @@ not a big deal. But if you are accessing the Attribute as part of some big loop amount of reads/writes you should first extract it to a temporary variable, operate on *that* and then save the result back to the Attribute. If you are storing a more complex structure like a `dict` or a `list` you should make sure to "disconnect" it from the database before looping over it, -as mentioned in the [Retrieving Mutable Objects](./Attributes#retrieving-mutable-objects) section below. +as mentioned in the [Retrieving Mutable Objects](./Attributes#retrieving-mutable-objects) section +below. ### Storing single objects -With a single object, we mean anything that is *not iterable*, like numbers, strings or custom class instances without the `__iter__` method. +With a single object, we mean anything that is *not iterable*, like numbers, strings or custom class +instances without the `__iter__` method. * You can generally store any non-iterable Python entity that can be [pickled](http://docs.python.org/library/pickle.html). @@ -223,17 +232,23 @@ This means storing objects in a collection of some kind and are examples of *ite entities you can loop over in a for-loop. Attribute-saving supports the following iterables: * [Tuples](https://docs.python.org/2/library/functions.html#tuple), like `(1,2,"test", )`. -* [Lists](https://docs.python.org/2/tutorial/datastructures.html#more-on-lists), like `[1,2,"test", ]`. -* [Dicts](https://docs.python.org/2/tutorial/datastructures.html#dictionaries), like `{1:2, "test":]`. +* [Lists](https://docs.python.org/2/tutorial/datastructures.html#more-on-lists), like `[1,2,"test", +]`. +* [Dicts](https://docs.python.org/2/tutorial/datastructures.html#dictionaries), like `{1:2, +"test":]`. * [Sets](https://docs.python.org/2/tutorial/datastructures.html#sets), like `{1,2,"test",}`. -* [collections.OrderedDict](https://docs.python.org/2/library/collections.html#collections.OrderedDict), like `OrderedDict((1,2), ("test", ))`. -* [collections.Deque](https://docs.python.org/2/library/collections.html#collections.deque), like `deque((1,2,"test",))`. -* *Nestings* of any combinations of the above, like lists in dicts or an OrderedDict of tuples, each containing dicts, etc. +* [collections.OrderedDict](https://docs.python.org/2/library/collections.html#collections.OrderedDi +ct), like `OrderedDict((1,2), ("test", ))`. +* [collections.Deque](https://docs.python.org/2/library/collections.html#collections.deque), like +`deque((1,2,"test",))`. +* *Nestings* of any combinations of the above, like lists in dicts or an OrderedDict of tuples, each +containing dicts, etc. * All other iterables (i.e. entities with the `__iter__` method) will be converted to a *list*. Since you can use any combination of the above iterables, this is generally not much of a limitation. -Any entity listed in the [Single object](./Attributes#Storing-Single-Objects) section above can be stored in the iterable. +Any entity listed in the [Single object](./Attributes#Storing-Single-Objects) section above can be +stored in the iterable. > As mentioned in the previous section, database entities (aka typeclasses) are not possible to > pickle. So when storing an iterable, Evennia must recursively traverse the iterable *and all its @@ -339,7 +354,8 @@ already disconnected from the database from the onset. Attributes are normally not locked down by default, but you can easily change that for individual Attributes (like those that may be game-sensitive in games with user-level building). -First you need to set a *lock string* on your Attribute. Lock strings are specified [Locks](./Locks). The relevant lock types are +First you need to set a *lock string* on your Attribute. Lock strings are specified [Locks](./Locks). +The relevant lock types are - `attrread` - limits who may read the value of the Attribute - `attredit` - limits who may set/change this Attribute diff --git a/docs/source/Banning.md b/docs/source/Banning.md index 5e236ad802..5234bbfeae 100644 --- a/docs/source/Banning.md +++ b/docs/source/Banning.md @@ -3,69 +3,88 @@ Whether due to abuse, blatant breaking of your rules, or some other reason, you will eventually find no other recourse but to kick out a particularly troublesome player. The default command set has -admin tools to handle this, primarily `@ban`, `@unban`, and `@boot`. +admin tools to handle this, primarily `@ban`, `@unban`, and `@boot`. ## Creating a ban -Say we have a troublesome player "YouSuck" - this is a person that refuses common courtesy - an abusive +Say we have a troublesome player "YouSuck" - this is a person that refuses common courtesy - an +abusive and spammy account that is clearly created by some bored internet hooligan only to cause grief. You -have tried to be nice. Now you just want this troll gone. +have tried to be nice. Now you just want this troll gone. ### Name ban -The easiest recourse is to block the account YouSuck from ever connecting again. +The easiest recourse is to block the account YouSuck from ever connecting again. @ban YouSuck -This will lock the name YouSuck (as well as 'yousuck' and any other capitalization combination), and next time they try to log in with this name the server will not let them! +This will lock the name YouSuck (as well as 'yousuck' and any other capitalization combination), and +next time they try to log in with this name the server will not let them! -You can also give a reason so you remember later why this was a good thing (the banned account will never see this) +You can also give a reason so you remember later why this was a good thing (the banned account will +never see this) @ban YouSuck:This is just a troll. -If you are sure this is just a spam account, you might even consider deleting the player account outright: +If you are sure this is just a spam account, you might even consider deleting the player account +outright: @delaccount YouSuck -Generally, banning the name is the easier and safer way to stop the use of an account -- if you change your mind you can always remove the block later whereas a deletion is permanent. +Generally, banning the name is the easier and safer way to stop the use of an account -- if you +change your mind you can always remove the block later whereas a deletion is permanent. ### IP ban -Just because you block YouSuck's name might not mean the trolling human behind that account gives up. They can just create a new account YouSuckMore and be back at it. One way to make things harder for them is to tell the server to not allow connections from their particular IP address. +Just because you block YouSuck's name might not mean the trolling human behind that account gives +up. They can just create a new account YouSuckMore and be back at it. One way to make things harder +for them is to tell the server to not allow connections from their particular IP address. -First, when the offending account is online, check which IP address they use. This you can do with the `who` command, which will show you something like this: +First, when the offending account is online, check which IP address they use. This you can do with +the `who` command, which will show you something like this: - Account Name On for Idle Room Cmds Host - YouSuckMore 01:12 2m 22 212 237.333.0.223 + Account Name On for Idle Room Cmds Host + YouSuckMore 01:12 2m 22 212 237.333.0.223 -The "Host" bit is the IP address from which the account is connecting. Use this to define the ban instead of the name: +The "Host" bit is the IP address from which the account is connecting. Use this to define the ban +instead of the name: @ban 237.333.0.223 -This will stop YouSuckMore connecting from their computer. Note however that IP address might change easily - either due to how the player's Internet Service Provider operates or by the user simply changing computers. You can make a more general ban by putting asterisks `*` as wildcards for the groups of three digits in the address. So if you figure out that !YouSuckMore mainly connects from 237.333.0.223, 237.333.0.225, and 237.333.0.256 (only changes in their subnet), it might be an idea to put down a ban like this to include any number in that subnet: +This will stop YouSuckMore connecting from their computer. Note however that IP address might change +easily - either due to how the player's Internet Service Provider operates or by the user simply +changing computers. You can make a more general ban by putting asterisks `*` as wildcards for the +groups of three digits in the address. So if you figure out that !YouSuckMore mainly connects from +237.333.0.223, 237.333.0.225, and 237.333.0.256 (only changes in their subnet), it might be an idea +to put down a ban like this to include any number in that subnet: @ban 237.333.0.* -You should combine the IP ban with a name-ban too of course, so the account YouSuckMore is truly locked regardless of where they connect from. +You should combine the IP ban with a name-ban too of course, so the account YouSuckMore is truly +locked regardless of where they connect from. -Be careful with too general IP bans however (more asterisks above). If you are unlucky you could be blocking out innocent players who just happen to connect from the same subnet as the offender. +Be careful with too general IP bans however (more asterisks above). If you are unlucky you could be +blocking out innocent players who just happen to connect from the same subnet as the offender. ## Booting -YouSuck is not really noticing all this banning yet though - and won't until having logged out and trying to log back in again. Let's help the troll along. +YouSuck is not really noticing all this banning yet though - and won't until having logged out and +trying to log back in again. Let's help the troll along. @boot YouSuck -Good riddance. You can give a reason for booting too (to be echoed to the player before getting kicked out). +Good riddance. You can give a reason for booting too (to be echoed to the player before getting +kicked out). @boot YouSuck:Go troll somewhere else. ### Lifting a ban -Use the `@unban` (or `@ban`) command without any arguments and you will see a list of all currently active bans: +Use the `@unban` (or `@ban`) command without any arguments and you will see a list of all currently +active bans: Active bans - id name/ip date reason + id name/ip date reason 1 yousuck Fri Jan 3 23:00:22 2020 This is just a Troll. 2 237.333.0.* Fri Jan 3 23:01:03 2020 YouSuck's IP. @@ -79,8 +98,11 @@ Use the `id` from this list to find out which ban to lift. Below are other useful commands for dealing with annoying players. -- **who** -- (as admin) Find the IP of a account. Note that one account can be connected to from multiple IPs depending on what you allow in your settings. -- **examine/account thomas** -- Get all details about an account. You can also use `*thomas` to get the account. If not given, you will get the *Object* thomas if it exists in the same location, which is not what you want in this case. +- **who** -- (as admin) Find the IP of a account. Note that one account can be connected to from +multiple IPs depending on what you allow in your settings. +- **examine/account thomas** -- Get all details about an account. You can also use `*thomas` to get +the account. If not given, you will get the *Object* thomas if it exists in the same location, which +is not what you want in this case. - **boot thomas** -- Boot all sessions of the given account name. - **boot 23** -- Boot one specific client session/IP by its unique id. - **ban** -- List all bans (listed with ids) @@ -91,22 +113,36 @@ Below are other useful commands for dealing with annoying players. - **unban 34** -- Remove ban with id #34 - **cboot mychannel = thomas** -- Boot a subscriber from a channel you control -- **clock mychannel = control:perm(Admin);listen:all();send:all()** -- Fine control of access to your channel using [lock definitions](./Locks). +- **clock mychannel = control:perm(Admin);listen:all();send:all()** -- Fine control of access to +your channel using [lock definitions](./Locks). -Locking a specific command (like `page`) is accomplished like so: -1. Examine the source of the command. [The default `page` command class]( https://github.com/evennia/evennia/blob/master/evennia/commands/default/comms.py#L686) has the lock string **"cmd:not pperm(page_banned)"**. This means that unless the player has the 'permission' "page_banned" they can use this command. You can assign any lock string to allow finer customization in your commands. You might look for the value of an [Attribute](./Attributes) or [Tag](./Tags), your current location etc. -2. **perm/account thomas = page_banned** -- Give the account the 'permission' which causes (in this case) the lock to fail. +Locking a specific command (like `page`) is accomplished like so: +1. Examine the source of the command. [The default `page` command class]( +https://github.com/evennia/evennia/blob/master/evennia/commands/default/comms.py#L686) has the lock +string **"cmd:not pperm(page_banned)"**. This means that unless the player has the 'permission' +"page_banned" they can use this command. You can assign any lock string to allow finer customization +in your commands. You might look for the value of an [Attribute](./Attributes) or [Tag](./Tags), your +current location etc. +2. **perm/account thomas = page_banned** -- Give the account the 'permission' which causes (in this +case) the lock to fail. - **perm/del/account thomas = page_banned** -- Remove the given permission - **tel thomas = jail** -- Teleport a player to a specified location or #dbref -- **type thomas = FlowerPot** -- Turn an annoying player into a flower pot (assuming you have a `FlowerPot` typeclass ready) +- **type thomas = FlowerPot** -- Turn an annoying player into a flower pot (assuming you have a +`FlowerPot` typeclass ready) - **userpassword thomas = fooBarFoo** -- Change a user's password - **delaccount thomas** -- Delete a player account (not recommended, use **ban** instead) -- **server** -- Show server statistics, such as CPU load, memory usage, and how many objects are cached +- **server** -- Show server statistics, such as CPU load, memory usage, and how many objects are +cached - **time** -- Gives server uptime, runtime, etc - **reload** -- Reloads the server without disconnecting anyone - **reset** -- Restarts the server, kicking all connections - **shutdown** -- Stops the server cold without it auto-starting again -- **py** -- Executes raw Python code, allows for direct inspection of the database and account objects on the fly. For advanced users. +- **py** -- Executes raw Python code, allows for direct inspection of the database and account +objects on the fly. For advanced users. + + +**Useful Tip:** `evennia changepassword ` entered into the command prompt will reset the +password of any account, including the superuser or admin accounts. This is a feature of Django. diff --git a/docs/source/Batch-Code-Processor.md b/docs/source/Batch-Code-Processor.md index a3738a5d5c..eeb82b8879 100644 --- a/docs/source/Batch-Code-Processor.md +++ b/docs/source/Batch-Code-Processor.md @@ -1,42 +1,67 @@ # Batch Code Processor -For an introduction and motivation to using batch processors, see [here](./Batch-Processors). This page describes the Batch-*code* processor. The Batch-*command* one is covered [here](./Batch-Command-Processor). +For an introduction and motivation to using batch processors, see [here](./Batch-Processors). This +page describes the Batch-*code* processor. The Batch-*command* one is covered [here](Batch-Command- +Processor). ## Basic Usage -The batch-code processor is a superuser-only function, invoked by +The batch-code processor is a superuser-only function, invoked by > @batchcode path.to.batchcodefile -Where `path.to.batchcodefile` is the path to a *batch-code file*. Such a file should have a name ending in "`.py`" (but you shouldn't include that in the path). The path is given like a python path relative to a folder you define to hold your batch files, set by `BATCH_IMPORT_PATH` in your settings. Default folder is (assuming your game is called "mygame") `mygame/world/`. So if you want to run the example batch file in `mygame/world/batch_code.py`, you could simply use +Where `path.to.batchcodefile` is the path to a *batch-code file*. Such a file should have a name +ending in "`.py`" (but you shouldn't include that in the path). The path is given like a python path +relative to a folder you define to hold your batch files, set by `BATCH_IMPORT_PATH` in your +settings. Default folder is (assuming your game is called "mygame") `mygame/world/`. So if you want +to run the example batch file in `mygame/world/batch_code.py`, you could simply use > @batchcode batch_code -This will try to run through the entire batch file in one go. For more gradual, *interactive* control you can use the `/interactive` switch. The switch `/debug` will put the processor in *debug* mode. Read below for more info. +This will try to run through the entire batch file in one go. For more gradual, *interactive* +control you can use the `/interactive` switch. The switch `/debug` will put the processor in +*debug* mode. Read below for more info. ## The batch file -A batch-code file is a normal Python file. The difference is that since the batch processor loads and executes the file rather than importing it, you can reliably update the file, then call it again, over and over and see your changes without needing to `@reload` the server. This makes for easy testing. In the batch-code file you have also access to the following global variables: +A batch-code file is a normal Python file. The difference is that since the batch processor loads +and executes the file rather than importing it, you can reliably update the file, then call it +again, over and over and see your changes without needing to `@reload` the server. This makes for +easy testing. In the batch-code file you have also access to the following global variables: - `caller` - This is a reference to the object running the batchprocessor. -- `DEBUG` - This is a boolean that lets you determine if this file is currently being run in debug-mode or not. See below how this can be useful. +- `DEBUG` - This is a boolean that lets you determine if this file is currently being run in debug- +mode or not. See below how this can be useful. -Running a plain Python file through the processor will just execute the file from beginning to end. If you want to get more control over the execution you can use the processor's *interactive* mode. This runs certain code blocks on their own, rerunning only that part until you are happy with it. In order to do this you need to add special markers to your file to divide it up into smaller chunks. These take the form of comments, so the file remains valid Python. +Running a plain Python file through the processor will just execute the file from beginning to end. +If you want to get more control over the execution you can use the processor's *interactive* mode. +This runs certain code blocks on their own, rerunning only that part until you are happy with it. In +order to do this you need to add special markers to your file to divide it up into smaller chunks. +These take the form of comments, so the file remains valid Python. -Here are the rules of syntax of the batch-code `*.py` file. +Here are the rules of syntax of the batch-code `*.py` file. -- `#CODE` as the first on a line marks the start of a *code* block. It will last until the beginning of another marker or the end of the file. Code blocks contain functional python code. Each `#CODE` block will be run in complete isolation from other parts of the file, so make sure it's self-contained. -- `#HEADER` as the first on a line marks the start of a *header* block. It lasts until the next marker or the end of the file. This is intended to hold imports and variables you will need for all other blocks .All python code defined in a header block will always be inserted at the top of every `#CODE` blocks in the file. You may have more than one `#HEADER` block, but that is equivalent to having one big one. Note that you can't exchange data between code blocks, so editing a header-variable in one code block won't affect that variable in any other code block! +- `#CODE` as the first on a line marks the start of a *code* block. It will last until the beginning +of another marker or the end of the file. Code blocks contain functional python code. Each `#CODE` +block will be run in complete isolation from other parts of the file, so make sure it's self- +contained. +- `#HEADER` as the first on a line marks the start of a *header* block. It lasts until the next +marker or the end of the file. This is intended to hold imports and variables you will need for all +other blocks .All python code defined in a header block will always be inserted at the top of every +`#CODE` blocks in the file. You may have more than one `#HEADER` block, but that is equivalent to +having one big one. Note that you can't exchange data between code blocks, so editing a header- +variable in one code block won't affect that variable in any other code block! - `#INSERT path.to.file` will insert another batchcode (Python) file at that position. - A `#` that is not starting a `#HEADER`, `#CODE` or `#INSERT` instruction is considered a comment. -- Inside a block, normal Python syntax rules apply. For the sake of indentation, each block acts as a separate python module. +- Inside a block, normal Python syntax rules apply. For the sake of indentation, each block acts as +a separate python module. -Below is a version of the example file found in `evennia/contrib/tutorial_examples/`. +Below is a version of the example file found in `evennia/contrib/tutorial_examples/`. ```python # - # This is an example batch-code build file for Evennia. + # This is an example batch-code build file for Evennia. # #HEADER @@ -50,9 +75,9 @@ Below is a version of the example file found in `evennia/contrib/tutorial_exampl limbo = search_object('Limbo')[0] - #CODE + #CODE - red_button = create_object(red_button.RedButton, key="Red button", + red_button = create_object(red_button.RedButton, key="Red button", location=limbo, aliases=["button"]) # caller points to the one running the script @@ -71,35 +96,47 @@ Below is a version of the example file found in `evennia/contrib/tutorial_exampl table.delete() chair.delete() string += " Since debug was active, " \ - "they were deleted again." + "they were deleted again." caller.msg(string % (table, chair)) ``` -This uses Evennia's Python API to create three objects in sequence. +This uses Evennia's Python API to create three objects in sequence. ## Debug mode -Try to run the example script with +Try to run the example script with > @batchcode/debug tutorial_examples.example_batch_code -The batch script will run to the end and tell you it completed. You will also get messages that the button and the two pieces of furniture were created. Look around and you should see the button there. But you won't see any chair nor a table! This is because we ran this with the `/debug` switch, which is directly visible as `DEBUG==True` inside the script. In the above example we handled this state by deleting the chair and table again. +The batch script will run to the end and tell you it completed. You will also get messages that the +button and the two pieces of furniture were created. Look around and you should see the button +there. But you won't see any chair nor a table! This is because we ran this with the `/debug` +switch, which is directly visible as `DEBUG==True` inside the script. In the above example we +handled this state by deleting the chair and table again. -The debug mode is intended to be used when you test out a batchscript. Maybe you are looking for bugs in your code or try to see if things behave as they should. Running the script over and over would then create an ever-growing stack of chairs and tables, all with the same name. You would have to go back and painstakingly delete them later. +The debug mode is intended to be used when you test out a batchscript. Maybe you are looking for +bugs in your code or try to see if things behave as they should. Running the script over and over +would then create an ever-growing stack of chairs and tables, all with the same name. You would have +to go back and painstakingly delete them later. ## Interactive mode -Interactive mode works very similar to the [batch-command processor counterpart](./Batch-Command-Processor). It allows you more step-wise control over how the batch file is executed. This is useful for debugging or for picking and choosing only particular blocks to run. Use `@batchcode` with the `/interactive` flag to enter interactive mode. +Interactive mode works very similar to the [batch-command processor counterpart](Batch-Command- +Processor). It allows you more step-wise control over how the batch file is executed. This is useful +for debugging or for picking and choosing only particular blocks to run. Use `@batchcode` with the +`/interactive` flag to enter interactive mode. - > @batchcode/interactive tutorial_examples.batch_code + > @batchcode/interactive tutorial_examples.example_batch_code You should see the following: - 01/02: red_button = create_object(red_button.RedButton, [...] (hh for help) + 01/02: red_button = create_object(red_button.RedButton, [...] (hh for help) -This shows that you are on the first `#CODE` block, the first of only two commands in this batch file. Observe that the block has *not* actually been executed at this point! +This shows that you are on the first `#CODE` block, the first of only two commands in this batch +file. Observe that the block has *not* actually been executed at this point! -To take a look at the full code snippet you are about to run, use `ll` (a batch-processor version of `look`). +To take a look at the full code snippet you are about to run, use `ll` (a batch-processor version of +`look`). ```python from evennia.utils import create, search @@ -108,51 +145,85 @@ To take a look at the full code snippet you are about to run, use `ll` (a batch- limbo = search.objects(caller, 'Limbo', global_search=True)[0] - red_button = create.create_object(red_button.RedButton, key="Red button", + red_button = create.create_object(red_button.RedButton, key="Red button", location=limbo, aliases=["button"]) # caller points to the one running the script caller.msg("A red button was created.") ``` -Compare with the example code given earlier. Notice how the content of `#HEADER` has been pasted at the top of the `#CODE` block. Use `pp` to actually execute this block (this will create the button and give you a message). Use `nn` (next) to go to the next command. Use `hh` for a list of commands. +Compare with the example code given earlier. Notice how the content of `#HEADER` has been pasted at +the top of the `#CODE` block. Use `pp` to actually execute this block (this will create the button +and give you a message). Use `nn` (next) to go to the next command. Use `hh` for a list of commands. -If there are tracebacks, fix them in the batch file, then use `rr` to reload the file. You will still be at the same code block and can rerun it easily with `pp` as needed. This makes for a simple debug cycle. It also allows you to rerun individual troublesome blocks - as mentioned, in a large batch file this can be very useful (don't forget the `/debug` mode either). +If there are tracebacks, fix them in the batch file, then use `rr` to reload the file. You will +still be at the same code block and can rerun it easily with `pp` as needed. This makes for a simple +debug cycle. It also allows you to rerun individual troublesome blocks - as mentioned, in a large +batch file this can be very useful (don't forget the `/debug` mode either). -Use `nn` and `bb` (next and back) to step through the file; e.g. `nn 12` will jump 12 steps forward (without processing any blocks in between). All normal commands of Evennia should work too while working in interactive mode. +Use `nn` and `bb` (next and back) to step through the file; e.g. `nn 12` will jump 12 steps forward +(without processing any blocks in between). All normal commands of Evennia should work too while +working in interactive mode. ## Limitations and Caveats -The batch-code processor is by far the most flexible way to build a world in Evennia. There are however some caveats you need to keep in mind. +The batch-code processor is by far the most flexible way to build a world in Evennia. There are +however some caveats you need to keep in mind. ### Safety -Or rather the lack of it. There is a reason only *superusers* are allowed to run the batch-code processor by default. The code-processor runs **without any Evennia security checks** and allows full access to Python. If an untrusted party could run the code-processor they could execute arbitrary python code on your machine, which is potentially a very dangerous thing. If you want to allow other users to access the batch-code processor you should make sure to run Evennia as a separate and very limited-access user on your machine (i.e. in a 'jail'). By comparison, the batch-command processor is much safer since the user running it is still 'inside' the game and can't really do anything outside what the game commands allow them to. +Or rather the lack of it. There is a reason only *superusers* are allowed to run the batch-code +processor by default. The code-processor runs **without any Evennia security checks** and allows +full access to Python. If an untrusted party could run the code-processor they could execute +arbitrary python code on your machine, which is potentially a very dangerous thing. If you want to +allow other users to access the batch-code processor you should make sure to run Evennia as a +separate and very limited-access user on your machine (i.e. in a 'jail'). By comparison, the batch- +command processor is much safer since the user running it is still 'inside' the game and can't +really do anything outside what the game commands allow them to. ### No communication between code blocks -Global variables won't work in code batch files, each block is executed as stand-alone environments. `#HEADER` blocks are literally pasted on top of each `#CODE` block so updating some header-variable in your block will not make that change available in another block. Whereas a python execution limitation, allowing this would also lead to very hard-to-debug code when using the interactive mode - this would be a classical example of "spaghetti code". +Global variables won't work in code batch files, each block is executed as stand-alone environments. +`#HEADER` blocks are literally pasted on top of each `#CODE` block so updating some header-variable +in your block will not make that change available in another block. Whereas a python execution +limitation, allowing this would also lead to very hard-to-debug code when using the interactive mode +- this would be a classical example of "spaghetti code". -The main practical issue with this is when building e.g. a room in one code block and later want to connect that room with a room you built in the current block. There are two ways to do this: +The main practical issue with this is when building e.g. a room in one code block and later want to +connect that room with a room you built in the current block. There are two ways to do this: -- Perform a database search for the name of the room you created (since you cannot know in advance which dbref it got assigned). The problem is that a name may not be unique (you may have a lot of "A dark forest" rooms). There is an easy way to handle this though - use [Tags](./Tags) or *Aliases*. You can assign any number of tags and/or aliases to any object. Make sure that one of those tags or aliases is unique to the room (like "room56") and you will henceforth be able to always uniquely search and find it later. -- Use the `caller` global property as an inter-block storage. For example, you could have a dictionary of room references in an `ndb`: +- Perform a database search for the name of the room you created (since you cannot know in advance +which dbref it got assigned). The problem is that a name may not be unique (you may have a lot of "A +dark forest" rooms). There is an easy way to handle this though - use [Tags](./Tags) or *Aliases*. You +can assign any number of tags and/or aliases to any object. Make sure that one of those tags or +aliases is unique to the room (like "room56") and you will henceforth be able to always uniquely +search and find it later. +- Use the `caller` global property as an inter-block storage. For example, you could have a +dictionary of room references in an `ndb`: ```python - #HEADER + #HEADER if caller.ndb.all_rooms is None: caller.ndb.all_rooms = {} - #CODE + #CODE # create and store the castle castle = create_object("rooms.Room", key="Castle") caller.ndb.all_rooms["castle"] = castle - #CODE + #CODE # in another node we want to access the castle castle = caller.ndb.all_rooms.get("castle") ``` -Note how we check in `#HEADER` if `caller.ndb.all_rooms` doesn't already exist before creating the dict. Remember that `#HEADER` is copied in front of every `#CODE` block. Without that `if` statement we'd be wiping the dict every block! +Note how we check in `#HEADER` if `caller.ndb.all_rooms` doesn't already exist before creating the +dict. Remember that `#HEADER` is copied in front of every `#CODE` block. Without that `if` statement +we'd be wiping the dict every block! -### Don't treat a batchcode file like any Python file -Despite being a valid Python file, a batchcode file should *only* be run by the batchcode processor. You should not do things like define Typeclasses or Commands in them, or import them into other code. Importing a module in Python will execute base level of the module, which in the case of your average batchcode file could mean creating a lot of new objects every time. +### Don't treat a batchcode file like any Python file +Despite being a valid Python file, a batchcode file should *only* be run by the batchcode processor. +You should not do things like define Typeclasses or Commands in them, or import them into other +code. Importing a module in Python will execute base level of the module, which in the case of your +average batchcode file could mean creating a lot of new objects every time. ### Don't let code rely on the batch-file's real file path -When you import things into your batchcode file, don't use relative imports but always import with paths starting from the root of your game directory or evennia library. Code that relies on the batch file's "actual" location *will fail*. Batch code files are read as text and the strings executed. When the code runs it has no knowledge of what file those strings where once a part of. +When you import things into your batchcode file, don't use relative imports but always import with +paths starting from the root of your game directory or evennia library. Code that relies on the +batch file's "actual" location *will fail*. Batch code files are read as text and the strings +executed. When the code runs it has no knowledge of what file those strings where once a part of. diff --git a/docs/source/Batch-Command-Processor.md b/docs/source/Batch-Command-Processor.md index e2ed69d49f..9999e7e8f5 100644 --- a/docs/source/Batch-Command-Processor.md +++ b/docs/source/Batch-Command-Processor.md @@ -1,121 +1,182 @@ # Batch Command Processor -For an introduction and motivation to using batch processors, see [here](./Batch-Processors). This page describes the Batch-*command* processor. The Batch-*code* one is covered [here](./Batch-Code-Processor). +For an introduction and motivation to using batch processors, see [here](./Batch-Processors). This +page describes the Batch-*command* processor. The Batch-*code* one is covered [here](Batch-Code- +Processor). ## Basic Usage -The batch-command processor is a superuser-only function, invoked by +The batch-command processor is a superuser-only function, invoked by > @batchcommand path.to.batchcmdfile -Where `path.to.batchcmdfile` is the path to a *batch-command file* with the "`.ev`" file ending. This path is given like a python path relative to a folder you define to hold your batch files, set with `BATCH_IMPORT_PATH` in your settings. Default folder is (assuming your game is in the `mygame` folder) `mygame/world`. So if you want to run the example batch file in `mygame/world/batch_cmds.ev`, you could use +Where `path.to.batchcmdfile` is the path to a *batch-command file* with the "`.ev`" file ending. +This path is given like a python path relative to a folder you define to hold your batch files, set +with `BATCH_IMPORT_PATH` in your settings. Default folder is (assuming your game is in the `mygame` +folder) `mygame/world`. So if you want to run the example batch file in +`mygame/world/batch_cmds.ev`, you could use > @batchcommand batch_cmds -A batch-command file contains a list of Evennia in-game commands separated by comments. The processor will run the batch file from beginning to end. Note that *it will not stop if commands in it fail* (there is no universal way for the processor to know what a failure looks like for all different commands). So keep a close watch on the output, or use *Interactive mode* (see below) to run the file in a more controlled, gradual manner. +A batch-command file contains a list of Evennia in-game commands separated by comments. The +processor will run the batch file from beginning to end. Note that *it will not stop if commands in +it fail* (there is no universal way for the processor to know what a failure looks like for all +different commands). So keep a close watch on the output, or use *Interactive mode* (see below) to +run the file in a more controlled, gradual manner. ## The batch file -The batch file is a simple plain-text file containing Evennia commands. Just like you would write them in-game, except you have more freedom with line breaks. +The batch file is a simple plain-text file containing Evennia commands. Just like you would write +them in-game, except you have more freedom with line breaks. Here are the rules of syntax of an `*.ev` file. You'll find it's really, really simple: -- All lines having the `#` (hash)-symbol *as the first one on the line* are considered *comments*. All non-comment lines are treated as a command and/or their arguments. -- Comment lines have an actual function -- they mark the *end of the previous command definition*. So never put two commands directly after one another in the file - separate them with a comment, or the second of the two will be considered an argument to the first one. Besides, using plenty of comments is good practice anyway. -- A line that starts with the word `#INSERT` is a comment line but also signifies a special instruction. The syntax is `#INSERT ` and tries to import a given batch-cmd file into this one. The inserted batch file (file ending `.ev`) will run normally from the point of the `#INSERT` instruction. -- Extra whitespace in a command definition is *ignored*. - A completely empty line translates in to a line break in texts. Two empty lines thus means a new paragraph (this is obviously only relevant for commands accepting such formatting, such as the `@desc` command). +- All lines having the `#` (hash)-symbol *as the first one on the line* are considered *comments*. +All non-comment lines are treated as a command and/or their arguments. +- Comment lines have an actual function -- they mark the *end of the previous command definition*. +So never put two commands directly after one another in the file - separate them with a comment, or +the second of the two will be considered an argument to the first one. Besides, using plenty of +comments is good practice anyway. +- A line that starts with the word `#INSERT` is a comment line but also signifies a special +instruction. The syntax is `#INSERT ` and tries to import a given batch-cmd file +into this one. The inserted batch file (file ending `.ev`) will run normally from the point of the +`#INSERT` instruction. +- Extra whitespace in a command definition is *ignored*. - A completely empty line translates in to +a line break in texts. Two empty lines thus means a new paragraph (this is obviously only relevant +for commands accepting such formatting, such as the `@desc` command). - The very last command in the file is not required to end with a comment. -- You *cannot* nest another `@batchcommand` statement into your batch file. If you want to link many batch-files together, use the `#INSERT` batch instruction instead. You also cannot launch the `@batchcode` command from your batch file, the two batch processors are not compatible. +- You *cannot* nest another `@batchcommand` statement into your batch file. If you want to link many +batch-files together, use the `#INSERT` batch instruction instead. You also cannot launch the +`@batchcode` command from your batch file, the two batch processors are not compatible. -Below is a version of the example file found in `evennia/contrib/tutorial_examples/batch_cmds.ev`. +Below is a version of the example file found in `evennia/contrib/tutorial_examples/batch_cmds.ev`. ```bash # - # This is an example batch build file for Evennia. + # This is an example batch build file for Evennia. # # This creates a red button @create button:tutorial_examples.red_button.RedButton # (This comment ends input for @create) - # Next command. Let's create something. - @set button/desc = - This is a large red button. Now and then - it flashes in an evil, yet strangely tantalizing way. + # Next command. Let's create something. + @set button/desc = + This is a large red button. Now and then + it flashes in an evil, yet strangely tantalizing way. A big sign sits next to it. It says: ----------- - Press me! + Press me! ----------- - ... It really begs to be pressed! You - know you want to! + ... It really begs to be pressed! You + know you want to! # This inserts the commands from another batch-cmd file named # batch_insert_file.ev. #INSERT examples.batch_insert_file - # (This ends the @set command). Note that single line breaks - # and extra whitespace in the argument are ignored. Empty lines + # (This ends the @set command). Note that single line breaks + # and extra whitespace in the argument are ignored. Empty lines # translate into line breaks in the output. - # Now let's place the button where it belongs (let's say limbo #2 is + # Now let's place the button where it belongs (let's say limbo #2 is # the evil lair in our example) @teleport #2 - # (This comments ends the @teleport command.) - # Now we drop it so others can see it. + # (This comments ends the @teleport command.) + # Now we drop it so others can see it. # The very last command in the file needs not be ended with #. drop button ``` -To test this, run `@batchcommand` on the file: +To test this, run `@batchcommand` on the file: > @batchcommand contrib.tutorial_examples.batch_cmds -A button will be created, described and dropped in Limbo. All commands will be executed by the user calling the command. +A button will be created, described and dropped in Limbo. All commands will be executed by the user +calling the command. -> Note that if you interact with the button, you might find that its description changes, loosing your custom-set description above. This is just the way this particular object works. +> Note that if you interact with the button, you might find that its description changes, loosing +your custom-set description above. This is just the way this particular object works. ## Interactive mode -Interactive mode allows you to more step-wise control over how the batch file is executed. This is useful for debugging and also if you have a large batch file and is only updating a small part of it -- running the entire file again would be a waste of time (and in the case of `@create`-ing objects you would to end up with multiple copies of same-named objects, for example). Use `@batchcommand` with the `/interactive` flag to enter interactive mode. +Interactive mode allows you to more step-wise control over how the batch file is executed. This is +useful for debugging and also if you have a large batch file and is only updating a small part of it +-- running the entire file again would be a waste of time (and in the case of `@create`-ing objects +you would to end up with multiple copies of same-named objects, for example). Use `@batchcommand` +with the `/interactive` flag to enter interactive mode. > @batchcommand/interactive tutorial_examples.batch_cmds You will see this: - 01/04: @create button:tutorial_examples.red_button.RedButton (hh for help) + 01/04: @create button:tutorial_examples.red_button.RedButton (hh for help) -This shows that you are on the `@create` command, the first out of only four commands in this batch file. Observe that the command `@create` has *not* been actually processed at this point! +This shows that you are on the `@create` command, the first out of only four commands in this batch +file. Observe that the command `@create` has *not* been actually processed at this point! -To take a look at the full command you are about to run, use `ll` (a batch-processor version of `look`). Use `pp` to actually process the current command (this will actually `@create` the button) -- and make sure it worked as planned. Use `nn` (next) to go to the next command. Use `hh` for a list of commands. +To take a look at the full command you are about to run, use `ll` (a batch-processor version of +`look`). Use `pp` to actually process the current command (this will actually `@create` the button) +-- and make sure it worked as planned. Use `nn` (next) to go to the next command. Use `hh` for a +list of commands. -If there are errors, fix them in the batch file, then use `rr` to reload the file. You will still be at the same command and can rerun it easily with `pp` as needed. This makes for a simple debug cycle. It also allows you to rerun individual troublesome commands - as mentioned, in a large batch file this can be very useful. Do note that in many cases, commands depend on the previous ones (e.g. if `@create` in the example above had failed, the following commands would have had nothing to operate on). +If there are errors, fix them in the batch file, then use `rr` to reload the file. You will still be +at the same command and can rerun it easily with `pp` as needed. This makes for a simple debug +cycle. It also allows you to rerun individual troublesome commands - as mentioned, in a large batch +file this can be very useful. Do note that in many cases, commands depend on the previous ones (e.g. +if `@create` in the example above had failed, the following commands would have had nothing to +operate on). -Use `nn` and `bb` (next and back) to step through the file; e.g. `nn 12` will jump 12 steps forward (without processing any command in between). All normal commands of Evennia should work too while working in interactive mode. +Use `nn` and `bb` (next and back) to step through the file; e.g. `nn 12` will jump 12 steps forward +(without processing any command in between). All normal commands of Evennia should work too while +working in interactive mode. ## Limitations and Caveats -The batch-command processor is great for automating smaller builds or for testing new commands and objects repeatedly without having to write so much. There are several caveats you have to be aware of when using the batch-command processor for building larger, complex worlds though. +The batch-command processor is great for automating smaller builds or for testing new commands and +objects repeatedly without having to write so much. There are several caveats you have to be aware +of when using the batch-command processor for building larger, complex worlds though. -The main issue is that when you run a batch-command script you (*you*, as in your superuser character) are actually moving around in the game creating and building rooms in sequence, just as if you had been entering those commands manually, one by one. You have to take this into account when creating the file, so that you can 'walk' (or teleport) to the right places in order. +The main issue is that when you run a batch-command script you (*you*, as in your superuser +character) are actually moving around in the game creating and building rooms in sequence, just as +if you had been entering those commands manually, one by one. You have to take this into account +when creating the file, so that you can 'walk' (or teleport) to the right places in order. -This also means there are several pitfalls when designing and adding certain types of objects. Here are some examples: +This also means there are several pitfalls when designing and adding certain types of objects. Here +are some examples: -- *Rooms that change your [Command Set](./Command-Sets)*: Imagine that you build a 'dark' room, which severely limits the cmdsets of those entering it (maybe you have to find the light switch to proceed). In your batch script you would create this room, then teleport to it - and promptly be shifted into the dark state where none of your normal build commands work ... -- *Auto-teleportation*: Rooms that automatically teleport those that enter them to another place (like a trap room, for example). You would be teleported away too. -- *Mobiles*: If you add aggressive mobs, they might attack you, drawing you into combat. If they have AI they might even follow you around when building - or they might move away from you before you've had time to finish describing and equipping them! +- *Rooms that change your [Command Set](./Command-Sets)*: Imagine that you build a 'dark' room, which +severely limits the cmdsets of those entering it (maybe you have to find the light switch to +proceed). In your batch script you would create this room, then teleport to it - and promptly be +shifted into the dark state where none of your normal build commands work ... +- *Auto-teleportation*: Rooms that automatically teleport those that enter them to another place +(like a trap room, for example). You would be teleported away too. +- *Mobiles*: If you add aggressive mobs, they might attack you, drawing you into combat. If they +have AI they might even follow you around when building - or they might move away from you before +you've had time to finish describing and equipping them! -The solution to all these is to plan ahead. Make sure that superusers are never affected by whatever effects are in play. Add an on/off switch to objects and make sure it's always set to *off* upon creation. It's all doable, one just needs to keep it in mind. +The solution to all these is to plan ahead. Make sure that superusers are never affected by whatever +effects are in play. Add an on/off switch to objects and make sure it's always set to *off* upon +creation. It's all doable, one just needs to keep it in mind. ## Assorted notes -The fact that you build as 'yourself' can also be considered an advantage however, should you ever decide to change the default command to allow others than superusers to call the processor. Since normal access-checks are still performed, a malevolent builder with access to the processor should not be able to do all that much damage (this is the main drawback of the [Batch Code Processor](./Batch-Code-Processor)) +The fact that you build as 'yourself' can also be considered an advantage however, should you ever +decide to change the default command to allow others than superusers to call the processor. Since +normal access-checks are still performed, a malevolent builder with access to the processor should +not be able to do all that much damage (this is the main drawback of the [Batch Code +Processor](Batch-Code-Processor)) -- [GNU Emacs](https://www.gnu.org/software/emacs/) users might find it interesting to use emacs' *evennia mode*. This is an Emacs major mode found in `evennia/utils/evennia-mode.el`. It offers correct syntax highlighting and indentation with `` when editing `.ev` files in Emacs. See the header of that file for installation instructions. -- [VIM](http://www.vim.org/) users can use amfl's [vim-evennia](https://github.com/amfl/vim-evennia) mode instead, see its readme for install instructions. \ No newline at end of file +- [GNU Emacs](https://www.gnu.org/software/emacs/) users might find it interesting to use emacs' +*evennia mode*. This is an Emacs major mode found in `evennia/utils/evennia-mode.el`. It offers +correct syntax highlighting and indentation with `` when editing `.ev` files in Emacs. See the +header of that file for installation instructions. +- [VIM](http://www.vim.org/) users can use amfl's [vim-evennia](https://github.com/amfl/vim-evennia) +mode instead, see its readme for install instructions. \ No newline at end of file diff --git a/docs/source/Batch-Processors.md b/docs/source/Batch-Processors.md index a1a0eb0443..ff634d7ce7 100644 --- a/docs/source/Batch-Processors.md +++ b/docs/source/Batch-Processors.md @@ -1,39 +1,82 @@ # Batch Processors -Building a game world is a lot of work, especially when starting out. Rooms should be created, descriptions have to be written, objects must be detailed and placed in their proper places. In many traditional MUD setups you had to do all this online, line by line, over a telnet session. +Building a game world is a lot of work, especially when starting out. Rooms should be created, +descriptions have to be written, objects must be detailed and placed in their proper places. In many +traditional MUD setups you had to do all this online, line by line, over a telnet session. -Evennia already moves away from much of this by shifting the main coding work to external Python modules. But also building would be helped if one could do some or all of it externally. Enter Evennia's *batch processors* (there are two of them). The processors allows you, as a game admin, to build your game completely offline in normal text files (*batch files*) that the processors understands. Then, when you are ready, you use the processors to read it all into Evennia (and into the database) in one go. +Evennia already moves away from much of this by shifting the main coding work to external Python +modules. But also building would be helped if one could do some or all of it externally. Enter +Evennia's *batch processors* (there are two of them). The processors allows you, as a game admin, to +build your game completely offline in normal text files (*batch files*) that the processors +understands. Then, when you are ready, you use the processors to read it all into Evennia (and into +the database) in one go. -You can of course still build completely online should you want to - this is certainly the easiest way to go when learning and for small build projects. But for major building work, the advantages of using the batch-processors are many: -- It's hard to compete with the comfort of a modern desktop text editor; Compared to a traditional MUD line input, you can get much better overview and many more features. Also, accidentally pressing Return won't immediately commit things to the database. -- You might run external spell checkers on your batch files. In the case of one of the batch-processors (the one that deals with Python code), you could also run external debuggers and code analyzers on your file to catch problems before feeding it to Evennia. -- The batch files (as long as you keep them) are records of your work. They make a natural starting point for quickly re-building your world should you ever decide to start over. -- If you are an Evennia developer, using a batch file is a fast way to setup a test-game after having reset the database. -- The batch files might come in useful should you ever decide to distribute all or part of your world to others. +You can of course still build completely online should you want to - this is certainly the easiest +way to go when learning and for small build projects. But for major building work, the advantages of +using the batch-processors are many: +- It's hard to compete with the comfort of a modern desktop text editor; Compared to a traditional +MUD line input, you can get much better overview and many more features. Also, accidentally pressing +Return won't immediately commit things to the database. +- You might run external spell checkers on your batch files. In the case of one of the batch- +processors (the one that deals with Python code), you could also run external debuggers and code +analyzers on your file to catch problems before feeding it to Evennia. +- The batch files (as long as you keep them) are records of your work. They make a natural starting +point for quickly re-building your world should you ever decide to start over. +- If you are an Evennia developer, using a batch file is a fast way to setup a test-game after +having reset the database. +- The batch files might come in useful should you ever decide to distribute all or part of your +world to others. -There are two batch processors, the Batch-*command* processor and the Batch-*code* processor. The first one is the simpler of the two. It doesn't require any programming knowledge - you basically just list in-game commands in a text file. The code-processor on the other hand is much more powerful but also more complex - it lets you use Evennia's API to code your world in full-fledged Python code. +There are two batch processors, the Batch-*command* processor and the Batch-*code* processor. The +first one is the simpler of the two. It doesn't require any programming knowledge - you basically +just list in-game commands in a text file. The code-processor on the other hand is much more +powerful but also more complex - it lets you use Evennia's API to code your world in full-fledged +Python code. - The [Batch Command Processor](./Batch-Command-Processor) - The [Batch Code Processor](./Batch-Code-Processor) -If you plan to use international characters in your batchfiles you are wise to read about *file encodings* below. +If you plan to use international characters in your batchfiles you are wise to read about *file +encodings* below. ## A note on File Encodings -As mentioned, both the processors take text files as input and then proceed to process them. As long as you stick to the standard [ASCII](http://en.wikipedia.org/wiki/Ascii) character set (which means the normal English characters, basically) you should not have to worry much about this section. +As mentioned, both the processors take text files as input and then proceed to process them. As long +as you stick to the standard [ASCII](http://en.wikipedia.org/wiki/Ascii) character set (which means +the normal English characters, basically) you should not have to worry much about this section. -Many languages however use characters outside the simple `ASCII` table. Common examples are various apostrophes and umlauts but also completely different symbols like those of the greek or cyrillic alphabets. +Many languages however use characters outside the simple `ASCII` table. Common examples are various +apostrophes and umlauts but also completely different symbols like those of the greek or cyrillic +alphabets. -First, we should make it clear that Evennia itself handles international characters just fine. It (and Django) uses [unicode](http://en.wikipedia.org/wiki/Unicode) strings internally. +First, we should make it clear that Evennia itself handles international characters just fine. It +(and Django) uses [unicode](http://en.wikipedia.org/wiki/Unicode) strings internally. -The problem is that when reading a text file like the batchfile, we need to know how to decode the byte-data stored therein to universal unicode. That means we need an *encoding* (a mapping) for how the file stores its data. There are many, many byte-encodings used around the world, with opaque names such as `Latin-1`, `ISO-8859-3` or `ARMSCII-8` to pick just a few examples. Problem is that it's practially impossible to determine which encoding was used to save a file just by looking at it (it's just a bunch of bytes!). You have to *know*. +The problem is that when reading a text file like the batchfile, we need to know how to decode the +byte-data stored therein to universal unicode. That means we need an *encoding* (a mapping) for how +the file stores its data. There are many, many byte-encodings used around the world, with opaque +names such as `Latin-1`, `ISO-8859-3` or `ARMSCII-8` to pick just a few examples. Problem is that +it's practially impossible to determine which encoding was used to save a file just by looking at it +(it's just a bunch of bytes!). You have to *know*. -With this little introduction it should be clear that Evennia can't guess but has to *assume* an encoding when trying to load a batchfile. The text editor and Evennia must speak the same "language" so to speak. Evennia will by default first try the international `UTF-8` encoding, but you can have Evennia try any sequence of different encodings by customizing the `ENCODINGS` list in your settings file. Evennia will use the first encoding in the list that do not raise any errors. Only if none work will the server give up and return an error message. +With this little introduction it should be clear that Evennia can't guess but has to *assume* an +encoding when trying to load a batchfile. The text editor and Evennia must speak the same "language" +so to speak. Evennia will by default first try the international `UTF-8` encoding, but you can have +Evennia try any sequence of different encodings by customizing the `ENCODINGS` list in your settings +file. Evennia will use the first encoding in the list that do not raise any errors. Only if none +work will the server give up and return an error message. -You can often change the text editor encoding (this depends on your editor though), otherwise you need to add the editor's encoding to Evennia's `ENCODINGS` list. If you are unsure, write a test file with lots of non-ASCII letters in the editor of your choice, then import to make sure it works as it should. +You can often change the text editor encoding (this depends on your editor though), otherwise you +need to add the editor's encoding to Evennia's `ENCODINGS` list. If you are unsure, write a test +file with lots of non-ASCII letters in the editor of your choice, then import to make sure it works +as it should. -More help with encodings can be found in the entry [Text Encodings](./Text-Encodings) and also in the Wikipedia article [here](http://en.wikipedia.org/wiki/Text_encodings). +More help with encodings can be found in the entry [Text Encodings](./Text-Encodings) and also in the +Wikipedia article [here](http://en.wikipedia.org/wiki/Text_encodings). -**A footnote for the batch-code processor**: Just because *Evennia* can parse your file and your fancy special characters, doesn't mean that *Python* allows their use. Python syntax only allows international characters inside *strings*. In all other source code only `ASCII` set characters are allowed. +**A footnote for the batch-code processor**: Just because *Evennia* can parse your file and your +fancy special characters, doesn't mean that *Python* allows their use. Python syntax only allows +international characters inside *strings*. In all other source code only `ASCII` set characters are +allowed. diff --git a/docs/source/Bootstrap-&-Evennia.md b/docs/source/Bootstrap-&-Evennia.md index 641d4495ca..8f9781af51 100644 --- a/docs/source/Bootstrap-&-Evennia.md +++ b/docs/source/Bootstrap-&-Evennia.md @@ -1,35 +1,56 @@ # Bootstrap & Evennia # What is Bootstrap? -Evennia's new default web page uses a framework called [Bootstrap](https://getbootstrap.com/). This framework is in use across the internet - you'll probably start to recognize its influence once you learn some of the common design patterns. This switch is great for web developers, perhaps like yourself, because instead of wondering about setting up different grid systems or what custom class another designer used, we have a base, a bootstrap, to work from. Bootstrap is responsive by default, and comes with some default styles that Evennia has lightly overrode to keep some of the same colors and styles you're used to from the previous design. +Evennia's new default web page uses a framework called [Bootstrap](https://getbootstrap.com/). This +framework is in use across the internet - you'll probably start to recognize its influence once you +learn some of the common design patterns. This switch is great for web developers, perhaps like +yourself, because instead of wondering about setting up different grid systems or what custom class +another designer used, we have a base, a bootstrap, to work from. Bootstrap is responsive by +default, and comes with some default styles that Evennia has lightly overrode to keep some of the +same colors and styles you're used to from the previous design. -For your reading pleasure, a brief overview of Bootstrap follows. For more in-depth info, please read [the documentation](https://getbootstrap.com/docs/4.0/getting-started/introduction/). +For your reading pleasure, a brief overview of Bootstrap follows. For more in-depth info, please +read [the documentation](https://getbootstrap.com/docs/4.0/getting-started/introduction/). *** ## The Layout System -Other than the basic styling Bootstrap includes, it also includes [a built in layout and grid system](https://getbootstrap.com/docs/4.0/layout/overview/). -The first part of this system is [the container](https://getbootstrap.com/docs/4.0/layout/overview/#containers). +Other than the basic styling Bootstrap includes, it also includes [a built in layout and grid +system](https://getbootstrap.com/docs/4.0/layout/overview/). +The first part of this system is [the +container](https://getbootstrap.com/docs/4.0/layout/overview/#containers). -The container is meant to hold all your page content. Bootstrap provides two types: fixed-width and full-width. -Fixed-width containers take up a certain max-width of the page - they're useful for limiting the width on Desktop or Tablet platforms, instead of making the content span the width of the page. +The container is meant to hold all your page content. Bootstrap provides two types: fixed-width and +full-width. +Fixed-width containers take up a certain max-width of the page - they're useful for limiting the +width on Desktop or Tablet platforms, instead of making the content span the width of the page. ```
``` -Full width containers take up the maximum width available to them - they'll span across a wide-screen desktop or a smaller screen phone, edge-to-edge. +Full width containers take up the maximum width available to them - they'll span across a wide- +screen desktop or a smaller screen phone, edge-to-edge. ```
``` -The second part of the layout system is [the grid](https://getbootstrap.com/docs/4.0/layout/grid/). This is the bread-and-butter of the layout of Bootstrap - it allows you to change the size of elements depending on the size of the screen, without writing any media queries. We'll briefly go over it - to learn more, please read the docs or look at the source code for Evennia's home page in your browser. -> Important! Grid elements should be in a .container or .container-fluid. This will center the contents of your site. +The second part of the layout system is [the grid](https://getbootstrap.com/docs/4.0/layout/grid/). +This is the bread-and-butter of the layout of Bootstrap - it allows you to change the size of +elements depending on the size of the screen, without writing any media queries. We'll briefly go +over it - to learn more, please read the docs or look at the source code for Evennia's home page in +your browser. +> Important! Grid elements should be in a .container or .container-fluid. This will center the +contents of your site. -Bootstrap's grid system allows you to create rows and columns by applying classes based on breakpoints. The default breakpoints are extra small, small, medium, large, and extra-large. If you'd like to know more about these breakpoints, please [take a look at the documentation for them.](https://getbootstrap.com/docs/4.0/layout/overview/#responsive-breakpoints) +Bootstrap's grid system allows you to create rows and columns by applying classes based on +breakpoints. The default breakpoints are extra small, small, medium, large, and extra-large. If +you'd like to know more about these breakpoints, please [take a look at the documentation for +them.](https://getbootstrap.com/docs/4.0/layout/overview/#responsive-breakpoints) -To use the grid system, first create a container for your content, then add your rows and columns like so: +To use the grid system, first create a container for your content, then add your rows and columns +like so: ```
@@ -47,7 +68,8 @@ To use the grid system, first create a container for your content, then add your ``` This layout would create three equal-width columns. -To specify your sizes - for instance, Evennia's default site has three columns on desktop and tablet, but reflows to single-column on smaller screens. Try it out! +To specify your sizes - for instance, Evennia's default site has three columns on desktop and +tablet, but reflows to single-column on smaller screens. Try it out! ```
@@ -66,10 +88,14 @@ To specify your sizes - for instance, Evennia's default site has three columns o
``` -This layout would be 4 columns on large screens, 2 columns on medium screens, and 1 column on anything smaller. +This layout would be 4 columns on large screens, 2 columns on medium screens, and 1 column on +anything smaller. -To learn more about Bootstrap's grid, please [take a look at the docs](https://getbootstrap.com/docs/4.0/layout/grid/) +To learn more about Bootstrap's grid, please [take a look at the +docs](https://getbootstrap.com/docs/4.0/layout/grid/) *** ## More Bootstrap -Bootstrap also provides a huge amount of utilities, as well as styling and content elements. To learn more about them, please [read the Bootstrap docs](https://getbootstrap.com/docs/4.0/getting-started/introduction/) or read one of our other web tutorials. \ No newline at end of file +Bootstrap also provides a huge amount of utilities, as well as styling and content elements. To +learn more about them, please [read the Bootstrap docs](https://getbootstrap.com/docs/4.0/getting- +started/introduction/) or read one of our other web tutorials. \ No newline at end of file diff --git a/docs/source/Bootstrap-Components-and-Utilities.md b/docs/source/Bootstrap-Components-and-Utilities.md index 6dc64eeddd..f8590fcc7e 100644 --- a/docs/source/Bootstrap-Components-and-Utilities.md +++ b/docs/source/Bootstrap-Components-and-Utilities.md @@ -1,17 +1,25 @@ # Bootstrap Components and Utilities -Bootstrap provides many utilities and components you can use when customizing Evennia's web presence. We'll go over a few examples here that you might find useful. -> Please take a look at either [the basic web tutorial](./Add-a-simple-new-web-page) or [the web character view tutorial](./Web-Character-View-Tutorial) +Bootstrap provides many utilities and components you can use when customizing Evennia's web +presence. We'll go over a few examples here that you might find useful. +> Please take a look at either [the basic web tutorial](./Add-a-simple-new-web-page) or [the web +character view tutorial](Web-Character-View-Tutorial) > to get a feel for how to add pages to Evennia's website to test these examples. ## General Styling -Bootstrap provides base styles for your site. These can be customized through CSS, but the default styles are intended to provide a consistent, clean look for sites. +Bootstrap provides base styles for your site. These can be customized through CSS, but the default +styles are intended to provide a consistent, clean look for sites. ### Color -Most elements can be styled with default colors. [Take a look at the documentation](https://getbootstrap.com/docs/4.0/utilities/colors/) to learn more about these colors - suffice to say, adding a class of text-* or bg-*, for instance, text-primary, sets the text color or background color. +Most elements can be styled with default colors. [Take a look at the +documentation](https://getbootstrap.com/docs/4.0/utilities/colors/) to learn more about these colors +- suffice to say, adding a class of text-* or bg-*, for instance, text-primary, sets the text color +or background color. ### Borders -Simply adding a class of 'border' to an element adds a border to the element. For more in-depth info, please [read the documentation on borders.](https://getbootstrap.com/docs/4.0/utilities/borders/). +Simply adding a class of 'border' to an element adds a border to the element. For more in-depth +info, please [read the documentation on +borders.](https://getbootstrap.com/docs/4.0/utilities/borders/). ``` ``` @@ -21,13 +29,17 @@ You can also easily round corners just by adding a class. ``` ### Spacing -Bootstrap provides classes to easily add responsive margin and padding. Most of the time, you might like to add margins or padding through CSS itself - however these classes are used in the default Evennia site. [Take a look at the docs](https://getbootstrap.com/docs/4.0/utilities/spacing/) to learn more. +Bootstrap provides classes to easily add responsive margin and padding. Most of the time, you might +like to add margins or padding through CSS itself - however these classes are used in the default +Evennia site. [Take a look at the docs](https://getbootstrap.com/docs/4.0/utilities/spacing/) to +learn more. *** ## Components ### Buttons -[Buttons](https://getbootstrap.com/docs/4.0/components/buttons/) in Bootstrap are very easy to use - button styling can be added to ` @@ -36,7 +48,10 @@ Bootstrap provides classes to easily add responsive margin and padding. Most of ``` ### Cards -[Cards](https://getbootstrap.com/docs/4.0/components/card/) provide a container for other elements that stands out from the rest of the page. The "Accounts", "Recently Connected", and "Database Stats" on the default webpage are all in cards. Cards provide quite a bit of formatting options - the following is a simple example, but read the documentation or look at the site's source for more. +[Cards](https://getbootstrap.com/docs/4.0/components/card/) provide a container for other elements +that stands out from the rest of the page. The "Accounts", "Recently Connected", and "Database +Stats" on the default webpage are all in cards. Cards provide quite a bit of formatting options - +the following is a simple example, but read the documentation or look at the site's source for more. ```
@@ -49,7 +64,9 @@ Bootstrap provides classes to easily add responsive margin and padding. Most of ``` ### Jumbotron -[Jumbotrons](https://getbootstrap.com/docs/4.0/components/jumbotron/) are useful for featuring an image or tagline for your game. They can flow with the rest of your content or take up the full width of the page - Evennia's base site uses the former. +[Jumbotrons](https://getbootstrap.com/docs/4.0/components/jumbotron/) are useful for featuring an +image or tagline for your game. They can flow with the rest of your content or take up the full +width of the page - Evennia's base site uses the former. ```
@@ -60,4 +77,6 @@ Bootstrap provides classes to easily add responsive margin and padding. Most of ``` ### Forms -[Forms](https://getbootstrap.com/docs/4.0/components/forms/) are highly customizable with Bootstrap. For a more in-depth look at how to use forms and their styles in your own Evennia site, please read over [the web character gen tutorial.](./Web-Character-Generation) \ No newline at end of file +[Forms](https://getbootstrap.com/docs/4.0/components/forms/) are highly customizable with Bootstrap. +For a more in-depth look at how to use forms and their styles in your own Evennia site, please read +over [the web character gen tutorial.](./Web-Character-Generation) \ No newline at end of file diff --git a/docs/source/Builder-Docs.md b/docs/source/Builder-Docs.md index c8a7ff57ce..5aab2b62bb 100644 --- a/docs/source/Builder-Docs.md +++ b/docs/source/Builder-Docs.md @@ -1,6 +1,6 @@ # Builder Docs -This section contains information useful to world builders. +This section contains information useful to world builders. ### Building basics diff --git a/docs/source/Building-Permissions.md b/docs/source/Building-Permissions.md index f100361258..38e7e80c8d 100644 --- a/docs/source/Building-Permissions.md +++ b/docs/source/Building-Permissions.md @@ -1,25 +1,47 @@ # Building Permissions -*OBS: This gives only a brief introduction to the access system. Locks and permissions are fully detailed* [here](./Locks). +*OBS: This gives only a brief introduction to the access system. Locks and permissions are fully +detailed* [here](./Locks). ## The super user -There are strictly speaking two types of users in Evennia, the *super user* and everyone else. The superuser is the first user you create, object `#1`. This is the all-powerful server-owner account. Technically the superuser not only has access to everything, it *bypasses* the permission checks entirely. This makes the superuser impossible to lock out, but makes it unsuitable to actually play-test the game's locks and restrictions with (see `@quell` below). Usually there is no need to have but one superuser. +There are strictly speaking two types of users in Evennia, the *super user* and everyone else. The +superuser is the first user you create, object `#1`. This is the all-powerful server-owner account. +Technically the superuser not only has access to everything, it *bypasses* the permission checks +entirely. This makes the superuser impossible to lock out, but makes it unsuitable to actually play- +test the game's locks and restrictions with (see `@quell` below). Usually there is no need to have +but one superuser. ## Assigning permissions -Whereas permissions can be used for anything, those put in `settings.PERMISSION_HIERARCHY` will have a ranking relative each other as well. We refer to these types of permissions as *hierarchical permissions*. When building locks to check these permissions, the `perm()` [lock function](./Locks) is used. By default Evennia creates the following hierarchy (spelled exactly like this): +Whereas permissions can be used for anything, those put in `settings.PERMISSION_HIERARCHY` will have +a ranking relative each other as well. We refer to these types of permissions as *hierarchical +permissions*. When building locks to check these permissions, the `perm()` [lock function](./Locks) is +used. By default Evennia creates the following hierarchy (spelled exactly like this): -1. **Developers** basically have the same access as superusers except that they do *not* sidestep the Permission system. Assign only to really trusted server-admin staff since this level gives access both to server reload/shutdown functionality as well as (and this may be more critical) gives access to the all-powerful `@py` command that allows the execution of arbitrary Python code on the command line. -1. **Admins** can do everything *except* affecting the server functions themselves. So an Admin couldn't reload or shutdown the server for example. They also cannot execute arbitrary Python code on the console or import files from the hard drive. -1. **Builders** - have all the build commands, but cannot affect other accounts or mess with the server. +1. **Developers** basically have the same access as superusers except that they do *not* sidestep +the Permission system. Assign only to really trusted server-admin staff since this level gives +access both to server reload/shutdown functionality as well as (and this may be more critical) gives +access to the all-powerful `@py` command that allows the execution of arbitrary Python code on the +command line. +1. **Admins** can do everything *except* affecting the server functions themselves. So an Admin +couldn't reload or shutdown the server for example. They also cannot execute arbitrary Python code +on the console or import files from the hard drive. +1. **Builders** - have all the build commands, but cannot affect other accounts or mess with the +server. 1. **Helpers** are almost like a normal *Player*, but they can also add help files to the database. -1. **Players** is the default group that new players end up in. A new player have permission to use tells and to use and create new channels. +1. **Players** is the default group that new players end up in. A new player have permission to use +tells and to use and create new channels. -A user having a certain level of permission automatically have access to locks specifying access of a lower level. +A user having a certain level of permission automatically have access to locks specifying access of +a lower level. -To assign a new permission from inside the game, you need to be able to use the `@perm` command. This is an *Developer*-level command, but it could in principle be made lower-access since it only allows assignments equal or lower to your current level (so you cannot use it to escalate your own permission level). So, assuming you yourself have *Developer* access (or is superuser), you assign a new account "Tommy" to your core staff with the command +To assign a new permission from inside the game, you need to be able to use the `@perm` command. +This is an *Developer*-level command, but it could in principle be made lower-access since it only +allows assignments equal or lower to your current level (so you cannot use it to escalate your own +permission level). So, assuming you yourself have *Developer* access (or is superuser), you assign +a new account "Tommy" to your core staff with the command @perm/account Tommy = Developer @@ -27,12 +49,24 @@ or @perm *Tommy = Developer -We use a switch or the `*name` format to make sure to put the permission on the *Account* and not on any eventual *Character* that may also be named "Tommy". This is usually what you want since the Account will then remain an Developer regardless of which Character they are currently controlling. To limit permission to a per-Character level you should instead use *quelling* (see below). Normally permissions can be any string, but for these special hierarchical permissions you can also use plural ("Developer" and "Developers" both grant the same powers). +We use a switch or the `*name` format to make sure to put the permission on the *Account* and not on +any eventual *Character* that may also be named "Tommy". This is usually what you want since the +Account will then remain an Developer regardless of which Character they are currently controlling. +To limit permission to a per-Character level you should instead use *quelling* (see below). Normally +permissions can be any string, but for these special hierarchical permissions you can also use +plural ("Developer" and "Developers" both grant the same powers). ## Quelling your permissions -When developing it can be useful to check just how things would look had your permission-level been lower. For this you can use *quelling*. Normally, when you puppet a Character you are using your Account-level permission. So even if your Character only has *Accounts* level permissions, your *Developer*-level Account will take precedence. With the `@quell` command you can change so that the Character's permission takes precedence instead: +When developing it can be useful to check just how things would look had your permission-level been +lower. For this you can use *quelling*. Normally, when you puppet a Character you are using your +Account-level permission. So even if your Character only has *Accounts* level permissions, your +*Developer*-level Account will take precedence. With the `@quell` command you can change so that the +Character's permission takes precedence instead: @quell -This will allow you to test out the game using the current Character's permission level. A developer or builder can thus in principle maintain several test characters, all using different permission levels. Note that you cannot escalate your permissions this way; If the Character happens to have a *higher* permission level than the Account, the *Account's* (lower) permission will still be used. +This will allow you to test out the game using the current Character's permission level. A developer +or builder can thus in principle maintain several test characters, all using different permission +levels. Note that you cannot escalate your permissions this way; If the Character happens to have a +*higher* permission level than the Account, the *Account's* (lower) permission will still be used. diff --git a/docs/source/Building-Quickstart.md b/docs/source/Building-Quickstart.md index 09140ccdf2..be4ad9d290 100644 --- a/docs/source/Building-Quickstart.md +++ b/docs/source/Building-Quickstart.md @@ -3,7 +3,7 @@ The [default command](./Default-Command-Help) definitions coming with Evennia follows a style [similar](./Using-MUX-as-a-Standard) to that of MUX, so the -commands should be familiar if you used any such code bases before. +commands should be familiar if you used any such code bases before. > Throughout the larger documentation you may come across commands prefixed > with `@`. This is just an optional marker used in some places to make a @@ -14,43 +14,62 @@ The default commands have the following style (where `[...]` marks optional part command[/switch/switch...] [arguments ...] -A _switch_ is a special, optional flag to the command to make it behave differently. It is always put directly after the command name, and begins with a forward slash (`/`). The _arguments_ are one or more inputs to the commands. It's common to use an equal sign (`=`) when assigning something to an object. +A _switch_ is a special, optional flag to the command to make it behave differently. It is always +put directly after the command name, and begins with a forward slash (`/`). The _arguments_ are one +or more inputs to the commands. It's common to use an equal sign (`=`) when assigning something to +an object. -Below are some examples of commands you can try when logged in to the game. Use `help ` for learning more about each command and their detailed options. +Below are some examples of commands you can try when logged in to the game. Use `help ` for +learning more about each command and their detailed options. ## Stepping Down From Godhood -If you just installed Evennia, your very first player account is called user #1, also known as the _superuser_ or _god user_. This user is very powerful, so powerful that it will override many game restrictions such as locks. This can be useful, but it also hides some functionality that you might want to test. +If you just installed Evennia, your very first player account is called user #1, also known as the +_superuser_ or _god user_. This user is very powerful, so powerful that it will override many game +restrictions such as locks. This can be useful, but it also hides some functionality that you might +want to test. To temporarily step down from your superuser position you can use the `quell` command in-game: quell -This will make you start using the permission of your current character's level instead of your superuser level. If you didn't change any settings your game Character should have an _Developer_ level permission - high as can be without bypassing locks like the superuser does. This will work fine for the examples on this page. Use `unquell` to get back to superuser status again afterwards. +This will make you start using the permission of your current character's level instead of your +superuser level. If you didn't change any settings your game Character should have an _Developer_ +level permission - high as can be without bypassing locks like the superuser does. This will work +fine for the examples on this page. Use `unquell` to get back to superuser status again afterwards. ## Creating an Object -Basic objects can be anything -- swords, flowers and non-player characters. They are created using the `create` command: +Basic objects can be anything -- swords, flowers and non-player characters. They are created using +the `create` command: create box -This created a new 'box' (of the default object type) in your inventory. Use the command `inventory` (or `i`) to see it. Now, 'box' is a rather short name, let's rename it and tack on a few aliases. +This created a new 'box' (of the default object type) in your inventory. Use the command `inventory` +(or `i`) to see it. Now, 'box' is a rather short name, let's rename it and tack on a few aliases. name box = very large box;box;very;crate -We now renamed the box to _very large box_ (and this is what we will see when looking at it), but we will also recognize it by any of the other names we give - like _crate_ or simply _box_ as before. We could have given these aliases directly after the name in the `create` command, this is true for all creation commands - you can always tag on a list of `;`-separated aliases to the name of your new object. If you had wanted to not change the name itself, but to only add aliases, you could have used the `alias` command. +We now renamed the box to _very large box_ (and this is what we will see when looking at it), but we +will also recognize it by any of the other names we give - like _crate_ or simply _box_ as before. +We could have given these aliases directly after the name in the `create` command, this is true for +all creation commands - you can always tag on a list of `;`-separated aliases to the name of your +new object. If you had wanted to not change the name itself, but to only add aliases, you could have +used the `alias` command. -We are currently carrying the box. Let's drop it (there is also a short cut to create and drop in one go by using the `/drop` switch, for example `create/drop box`). +We are currently carrying the box. Let's drop it (there is also a short cut to create and drop in +one go by using the `/drop` switch, for example `create/drop box`). - drop box + drop box Hey presto - there it is on the ground, in all its normality. examine box -This will show some technical details about the box object. For now we will ignore what this information means. +This will show some technical details about the box object. For now we will ignore what this +information means. -Try to `look` at the box to see the (default) description. +Try to `look` at the box to see the (default) description. look box You see nothing special. @@ -59,82 +78,127 @@ The description you get is not very exciting. Let's add some flavor. describe box = This is a large and very heavy box. -If you try the `get` command we will pick up the box. So far so good, but if we really want this to be a large and heavy box, people should _not_ be able to run off with it that easily. To prevent this we need to lock it down. This is done by assigning a _Lock_ to it. Make sure the box was dropped in the room, then try this: +If you try the `get` command we will pick up the box. So far so good, but if we really want this to +be a large and heavy box, people should _not_ be able to run off with it that easily. To prevent +this we need to lock it down. This is done by assigning a _Lock_ to it. Make sure the box was +dropped in the room, then try this: lock box = get:false() -Locks represent a rather [big topic](./Locks), but for now that will do what we want. This will lock the box so noone can lift it. The exception is superusers, they override all locks and will pick it up anyway. Make sure you are quelling your superuser powers and try to get the box now: +Locks represent a rather [big topic](./Locks), but for now that will do what we want. This will lock +the box so noone can lift it. The exception is superusers, they override all locks and will pick it +up anyway. Make sure you are quelling your superuser powers and try to get the box now: > get box You can't get that. -Think thís default error message looks dull? The `get` command looks for an [Attribute](./Attributes) named `get_err_msg` for returning a nicer error message (we just happen to know this, you would need to peek into the [code](https://github.com/evennia/evennia/blob/master/evennia/commands/default/general.py#L235) for the `get` command to find out.). You set attributes using the `set` command: +Think thís default error message looks dull? The `get` command looks for an [Attribute](./Attributes) +named `get_err_msg` for returning a nicer error message (we just happen to know this, you would need +to peek into the +[code](https://github.com/evennia/evennia/blob/master/evennia/commands/default/general.py#L235) for +the `get` command to find out.). You set attributes using the `set` command: - set box/get_err_msg = It's way too heavy for you to lift. + set box/get_err_msg = It's way too heavy for you to lift. -Try to get it now and you should see a nicer error message echoed back to you. To see what this message string is in the future, you can use 'examine.' +Try to get it now and you should see a nicer error message echoed back to you. To see what this +message string is in the future, you can use 'examine.' examine box/get_err_msg -Examine will return the value of attributes, including color codes. `examine here/desc` would return the raw description of your current room (including color codes), so that you can copy-and-paste to set its description to something else. +Examine will return the value of attributes, including color codes. `examine here/desc` would return +the raw description of your current room (including color codes), so that you can copy-and-paste to +set its description to something else. -You create new Commands (or modify existing ones) in Python outside the game. See the [Adding Commands tutorial](./Adding-Command-Tutorial) for help with creating your first own Command. +You create new Commands (or modify existing ones) in Python outside the game. See the [Adding +Commands tutorial](Adding-Command-Tutorial) for help with creating your first own Command. ## Get a Personality -[Scripts](./Scripts) are powerful out-of-character objects useful for many "under the hood" things. One of their optional abilities is to do things on a timer. To try out a first script, let's put one on ourselves. There is an example script in `evennia/contrib/tutorial_examples/bodyfunctions.py` that is called `BodyFunctions`. To add this to us we will use the `script` command: +[Scripts](./Scripts) are powerful out-of-character objects useful for many "under the hood" things. +One of their optional abilities is to do things on a timer. To try out a first script, let's put one +on ourselves. There is an example script in `evennia/contrib/tutorial_examples/bodyfunctions.py` +that is called `BodyFunctions`. To add this to us we will use the `script` command: script self = tutorial_examples.bodyfunctions.BodyFunctions -(note that you don't have to give the full path as long as you are pointing to a place inside the `contrib` directory, it's one of the places Evennia looks for Scripts). Wait a while and you will notice yourself starting making random observations. +(note that you don't have to give the full path as long as you are pointing to a place inside the +`contrib` directory, it's one of the places Evennia looks for Scripts). Wait a while and you will +notice yourself starting making random observations. - script self + script self -This will show details about scripts on yourself (also `examine` works). You will see how long it is until it "fires" next. Don't be alarmed if nothing happens when the countdown reaches zero - this particular script has a randomizer to determine if it will say something or not. So you will not see output every time it fires. +This will show details about scripts on yourself (also `examine` works). You will see how long it is +until it "fires" next. Don't be alarmed if nothing happens when the countdown reaches zero - this +particular script has a randomizer to determine if it will say something or not. So you will not see +output every time it fires. When you are tired of your character's "insights", kill the script with script/stop self = tutorial_examples.bodyfunctions.BodyFunctions -You create your own scripts in Python, outside the game; the path you give to `script` is literally the Python path to your script file. The [Scripts](./Scripts) page explains more details. +You create your own scripts in Python, outside the game; the path you give to `script` is literally +the Python path to your script file. The [Scripts](./Scripts) page explains more details. ## Pushing Your Buttons -If we get back to the box we made, there is only so much fun you can do with it at this point. It's just a dumb generic object. If you renamed it to `stone` and changed its description noone would be the wiser. However, with the combined use of custom [Typeclasses](./Typeclasses), [Scripts](./Scripts) and object-based [Commands](./Commands), you could expand it and other items to be as unique, complex and interactive as you want. +If we get back to the box we made, there is only so much fun you can do with it at this point. It's +just a dumb generic object. If you renamed it to `stone` and changed its description noone would be +the wiser. However, with the combined use of custom [Typeclasses](./Typeclasses), [Scripts](./Scripts) +and object-based [Commands](./Commands), you could expand it and other items to be as unique, complex +and interactive as you want. -Let's take an example. So far we have only created objects that use the default object typeclass named simply `Object`. Let's create an object that is a little more interesting. Under `evennia/contrib/tutorial_examples` there is a module `red_button.py`. It contains the enigmatic `RedButton` typeclass. +Let's take an example. So far we have only created objects that use the default object typeclass +named simply `Object`. Let's create an object that is a little more interesting. Under +`evennia/contrib/tutorial_examples` there is a module `red_button.py`. It contains the enigmatic +`RedButton` typeclass. Let's make us one of _those_! create/drop button:tutorial_examples.red_button.RedButton -We import the RedButton python class the same way you would import it in Python except Evennia makes sure to look in`evennia/contrib/` so you don't have to write the full path every time. There you go - one red button. +We import the RedButton python class the same way you would import it in Python except Evennia makes +sure to look in`evennia/contrib/` so you don't have to write the full path every time. There you go +- one red button. -The RedButton is an example object intended to show off a few of Evennia's features. You will find that the [Typeclass](./Typeclasses) and [Commands](./Commands) controlling it are inside `evennia/contrib/tutorial_examples/`. +The RedButton is an example object intended to show off a few of Evennia's features. You will find +that the [Typeclass](./Typeclasses) and [Commands](./Commands) controlling it are inside +`evennia/contrib/tutorial_examples/`. -If you wait for a while (make sure you dropped it!) the button will blink invitingly. Why don't you try to push it ...? Surely a big red button is meant to be pushed. You know you want to. +If you wait for a while (make sure you dropped it!) the button will blink invitingly. Why don't you +try to push it ...? Surely a big red button is meant to be pushed. You know you want to. ## Making Yourself a House -The main command for shaping the game world is `dig`. For example, if you are standing in Limbo you can dig a route to your new house location like this: +The main command for shaping the game world is `dig`. For example, if you are standing in Limbo you +can dig a route to your new house location like this: dig house = large red door;door;in,to the outside;out -This will create a new room named 'house'. Spaces at the start/end of names and aliases are ignored so you could put more air if you wanted. This call will directly create an exit from your current location named 'large red door' and a corresponding exit named 'to the outside' in the house room leading back to Limbo. We also define a few aliases to those exits, so people don't have to write the full thing all the time. +This will create a new room named 'house'. Spaces at the start/end of names and aliases are ignored +so you could put more air if you wanted. This call will directly create an exit from your current +location named 'large red door' and a corresponding exit named 'to the outside' in the house room +leading back to Limbo. We also define a few aliases to those exits, so people don't have to write +the full thing all the time. -If you wanted to use normal compass directions (north, west, southwest etc), you could do that with `dig` too. But Evennia also has a limited version of `dig` that helps for compass directions (and also up/down and in/out). It's called `tunnel`: +If you wanted to use normal compass directions (north, west, southwest etc), you could do that with +`dig` too. But Evennia also has a limited version of `dig` that helps for compass directions (and +also up/down and in/out). It's called `tunnel`: tunnel sw = cliff -This will create a new room "cliff" with an exit "southwest" leading there and a path "northeast" leading back from the cliff to your current location. +This will create a new room "cliff" with an exit "southwest" leading there and a path "northeast" +leading back from the cliff to your current location. -You can create new exits from where you are using the `open` command: +You can create new exits from where you are using the `open` command: open north;n = house This opens an exit `north` (with an alias `n`) to the previously created room `house`. -If you have many rooms named `house` you will get a list of matches and have to select which one you want to link to. You can also give its database (#dbref) number, which is unique to every object. This can be found with the `examine` command or by looking at the latest constructions with `objects`. +If you have many rooms named `house` you will get a list of matches and have to select which one you +want to link to. You can also give its database (#dbref) number, which is unique to every object. +This can be found with the `examine` command or by looking at the latest constructions with +`objects`. Follow the north exit to your 'house' or `teleport` to it: @@ -152,46 +216,59 @@ To manually open an exit back to Limbo (if you didn't do so with the `dig` comma ## Reshuffling the World -You can find things using the `find` command. Assuming you are back at `Limbo`, let's teleport the _large box to our house_. +You can find things using the `find` command. Assuming you are back at `Limbo`, let's teleport the +_large box to our house_. > teleport box = house very large box is leaving Limbo, heading for house. Teleported very large box -> house. -We can still find the box by using find: +We can still find the box by using find: > find box One Match(#1-#8): very large box(#8) - src.objects.objects.Object -Knowing the `#dbref` of the box (#8 in this example), you can grab the box and get it back here without actually yourself going to `house` first: +Knowing the `#dbref` of the box (#8 in this example), you can grab the box and get it back here +without actually yourself going to `house` first: teleport #8 = here -(You can usually use `here` to refer to your current location. To refer to yourself you can use `self` or `me`). The box should now be back in Limbo with you. +(You can usually use `here` to refer to your current location. To refer to yourself you can use +`self` or `me`). The box should now be back in Limbo with you. We are getting tired of the box. Let's destroy it. destroy box -You can destroy many objects in one go by giving a comma-separated list of objects (or their #dbrefs, if they are not in the same location) to the command. +You can destroy many objects in one go by giving a comma-separated list of objects (or their +#dbrefs, if they are not in the same location) to the command. ## Adding a Help Entry -An important part of building is keeping the help files updated. You can add, delete and append to existing help entries using the `sethelp` command. +An important part of building is keeping the help files updated. You can add, delete and append to +existing help entries using the `sethelp` command. - sethelp/add MyTopic = This help topic is about ... + sethelp/add MyTopic = This help topic is about ... ## Adding a World -After this brief introduction to building you may be ready to see a more fleshed-out example. Evennia comes with a tutorial world for you to explore. +After this brief introduction to building you may be ready to see a more fleshed-out example. +Evennia comes with a tutorial world for you to explore. -First you need to switch back to _superuser_ by using the `unquell` command. Next, place yourself in `Limbo` and run the following command: +First you need to switch back to _superuser_ by using the `unquell` command. Next, place yourself in +`Limbo` and run the following command: batchcommand tutorial_world.build -This will take a while (be patient and don't re-run the command). You will see all the commands used to build the world scroll by as the world is built for you. +This will take a while (be patient and don't re-run the command). You will see all the commands used +to build the world scroll by as the world is built for you. -You will end up with a new exit from Limbo named _tutorial_. Apart from being a little solo-adventure in its own right, the tutorial world is a good source for learning Evennia building (and coding). +You will end up with a new exit from Limbo named _tutorial_. Apart from being a little solo- +adventure in its own right, the tutorial world is a good source for learning Evennia building (and +coding). -Read [the batch file](https://github.com/evennia/evennia/blob/master/evennia/contrib/tutorial_world/build.ev) to see exactly how it's built, step by step. See also more info about the tutorial world [here](./Tutorial-World-Introduction). +Read [the batch +file](https://github.com/evennia/evennia/blob/master/evennia/contrib/tutorial_world/build.ev) to see +exactly how it's built, step by step. See also more info about the tutorial world [here](Tutorial- +World-Introduction). diff --git a/docs/source/Building-a-mech-tutorial.md b/docs/source/Building-a-mech-tutorial.md index 7fb2bf20ea..48601ebcdf 100644 --- a/docs/source/Building-a-mech-tutorial.md +++ b/docs/source/Building-a-mech-tutorial.md @@ -1,14 +1,18 @@ # Building a mech tutorial -> This page was adapted from the article "Building a Giant Mech in Evennia" by Griatch, published in Imaginary Realities Volume 6, issue 1, 2014. The original article is no longer available online, this is a version adopted to be compatible with the latest Evennia. +> This page was adapted from the article "Building a Giant Mech in Evennia" by Griatch, published in +Imaginary Realities Volume 6, issue 1, 2014. The original article is no longer available online, +this is a version adopted to be compatible with the latest Evennia. ## Creating the Mech -Let us create a functioning giant mech using the Python MUD-creation system Evennia. Everyone likes a giant mech, right? Start in-game as a character with build privileges (or the superuser). +Let us create a functioning giant mech using the Python MUD-creation system Evennia. Everyone likes +a giant mech, right? Start in-game as a character with build privileges (or the superuser). @create/drop Giant Mech ; mech -Boom. We created a Giant Mech Object and dropped it in the room. We also gave it an alias *mech*. Let’s describe it. +Boom. We created a Giant Mech Object and dropped it in the room. We also gave it an alias *mech*. +Let’s describe it. @desc mech = This is a huge mech. It has missiles and stuff. @@ -16,36 +20,51 @@ Next we define who can “puppet” the mech object. @lock mech = puppet:all() -This makes it so that everyone can control the mech. More mechs to the people! (Note that whereas Evennia’s default commands may look vaguely MUX-like, you can change the syntax to look like whatever interface style you prefer.) +This makes it so that everyone can control the mech. More mechs to the people! (Note that whereas +Evennia’s default commands may look vaguely MUX-like, you can change the syntax to look like +whatever interface style you prefer.) -Before we continue, let’s make a brief detour. Evennia is very flexible about its objects and even more flexible about using and adding commands to those objects. Here are some ground rules well worth remembering for the remainder of this article: +Before we continue, let’s make a brief detour. Evennia is very flexible about its objects and even +more flexible about using and adding commands to those objects. Here are some ground rules well +worth remembering for the remainder of this article: - The [Account](./Accounts) represents the real person logging in and has no game-world existence. - Any [Object](./Objects) can be puppeted by an Account (with proper permissions). -- [Characters](./Objects#characters), [Rooms](./Objects#rooms), and [Exits](./Objects#exits) are just children of normal Objects. +- [Characters](./Objects#characters), [Rooms](./Objects#rooms), and [Exits](./Objects#exits) are just +children of normal Objects. - Any Object can be inside another (except if it creates a loop). - Any Object can store custom sets of commands on it. Those commands can: - be made available to the puppeteer (Account), - be made available to anyone in the same location as the Object, and - be made available to anyone “inside” the Object - - Also Accounts can store commands on themselves. Account commands are always available unless commands on a puppeted Object explicitly override them. + - Also Accounts can store commands on themselves. Account commands are always available unless +commands on a puppeted Object explicitly override them. -In Evennia, using the `@ic` command will allow you to puppet a given Object (assuming you have puppet-access to do so). As mentioned above, the bog-standard Character class is in fact like any Object: it is auto-puppeted when logging in and just has a command set on it containing the normal in-game commands, like look, inventory, get and so on. +In Evennia, using the `@ic` command will allow you to puppet a given Object (assuming you have +puppet-access to do so). As mentioned above, the bog-standard Character class is in fact like any +Object: it is auto-puppeted when logging in and just has a command set on it containing the normal +in-game commands, like look, inventory, get and so on. @ic mech -You just jumped out of your Character and *are* now the mech! If people look at you in-game, they will look at a mech. The problem at this point is that the mech Object has no commands of its own. The usual things like look, inventory and get sat on the Character object, remember? So at the moment the mech is not quite as cool as it could be. +You just jumped out of your Character and *are* now the mech! If people look at you in-game, they +will look at a mech. The problem at this point is that the mech Object has no commands of its own. +The usual things like look, inventory and get sat on the Character object, remember? So at the +moment the mech is not quite as cool as it could be. @ic You just jumped back to puppeting your normal, mundane Character again. All is well. -> (But, you ask, where did that `@ic` command come from, if the mech had no commands on it? The answer is that it came from the Account's command set. This is important. Without the Account being the one with the `@ic` command, we would not have been able to get back out of our mech again.) +> (But, you ask, where did that `@ic` command come from, if the mech had no commands on it? The +answer is that it came from the Account's command set. This is important. Without the Account being +the one with the `@ic` command, we would not have been able to get back out of our mech again.) ### Arming the Mech -Let us make the mech a little more interesting. In our favorite text editor, we will create some new mech-suitable commands. In Evennia, commands are defined as Python classes. +Let us make the mech a little more interesting. In our favorite text editor, we will create some new +mech-suitable commands. In Evennia, commands are defined as Python classes. ```python # in a new file mygame/commands/mechcommands.py @@ -89,7 +108,11 @@ class CmdLaunch(Command): ``` -This is saved as a normal Python module (let’s call it `mechcommands.py`), in a place Evennia looks for such modules (`mygame/commands/`). This command will trigger when the player gives the command “shoot”, “fire,” or even “fire!” with an exclamation mark. The mech can shoot in the air or at a target if you give one. In a real game the gun would probably be given a chance to hit and give damage to the target, but this is enough for now. +This is saved as a normal Python module (let’s call it `mechcommands.py`), in a place Evennia looks +for such modules (`mygame/commands/`). This command will trigger when the player gives the command +“shoot”, “fire,” or even “fire!” with an exclamation mark. The mech can shoot in the air or at a +target if you give one. In a real game the gun would probably be given a chance to hit and give +damage to the target, but this is enough for now. We also make a second command for launching missiles (`CmdLaunch`). To save space we won’t describe it here; it looks the same except it returns a text @@ -97,7 +120,8 @@ about the missiles being fired and has different `key` and `aliases`. We leave that up to you to create as an exercise. You could have it print "WOOSH! The mech launches missiles against !", for example. -Now we shove our commands into a command set. A [Command Set](./Command-Sets) (CmdSet) is a container holding any number of commands. The command set is what we will store on the mech. +Now we shove our commands into a command set. A [Command Set](./Command-Sets) (CmdSet) is a container +holding any number of commands. The command set is what we will store on the mech. ```python # in the same file mygame/commands/mechcommands.py @@ -117,11 +141,14 @@ class MechCmdSet(CmdSet): self.add(CmdLaunch()) ``` -This simply groups all the commands we want. We add our new shoot/launch commands. Let’s head back into the game. For testing we will manually attach our new CmdSet to the mech. +This simply groups all the commands we want. We add our new shoot/launch commands. Let’s head back +into the game. For testing we will manually attach our new CmdSet to the mech. @py self.search("mech").cmdset.add("commands.mechcommands.MechCmdSet") -This is a little Python snippet (run from the command line as an admin) that searches for the mech in our current location and attaches our new MechCmdSet to it. What we add is actually the Python path to our cmdset class. Evennia will import and initialize it behind the scenes. +This is a little Python snippet (run from the command line as an admin) that searches for the mech +in our current location and attaches our new MechCmdSet to it. What we add is actually the Python +path to our cmdset class. Evennia will import and initialize it behind the scenes. @ic mech @@ -130,15 +157,24 @@ We are back as the mech! Let’s do some shooting! fire! BOOM! The mech fires its gun in the air! -There we go, one functioning mech. Try your own `launch` command and see that it works too. We can not only walk around as the mech — since the CharacterCmdSet is included in our MechCmdSet, the mech can also do everything a Character could do, like look around, pick up stuff, and have an inventory. We could now shoot the gun at a target or try the missile launch command. Once you have your own mech, what else do you need? +There we go, one functioning mech. Try your own `launch` command and see that it works too. We can +not only walk around as the mech — since the CharacterCmdSet is included in our MechCmdSet, the mech +can also do everything a Character could do, like look around, pick up stuff, and have an inventory. +We could now shoot the gun at a target or try the missile launch command. Once you have your own +mech, what else do you need? -> Note: You'll find that the mech's commands are available to you by just standing in the same location (not just by puppeting it). We'll solve this with a *lock* in the next section. +> Note: You'll find that the mech's commands are available to you by just standing in the same +location (not just by puppeting it). We'll solve this with a *lock* in the next section. ## Making a Mech production line -What we’ve done so far is just to make a normal Object, describe it and put some commands on it. This is great for testing. The way we added it, the MechCmdSet will even go away if we reload the server. Now we want to make the mech an actual object “type” so we can create mechs without those extra steps. For this we need to create a new Typeclass. +What we’ve done so far is just to make a normal Object, describe it and put some commands on it. +This is great for testing. The way we added it, the MechCmdSet will even go away if we reload the +server. Now we want to make the mech an actual object “type” so we can create mechs without those +extra steps. For this we need to create a new Typeclass. -A [Typeclass](./Typeclasses) is a near-normal Python class that stores its existence to the database behind the scenes. A Typeclass is created in a normal Python source file: +A [Typeclass](./Typeclasses) is a near-normal Python class that stores its existence to the database +behind the scenes. A Typeclass is created in a normal Python source file: ```python # in the new file mygame/typeclasses/mech.py @@ -159,15 +195,24 @@ class Mech(Object): self.db.desc = "This is a huge mech. It has missiles and stuff." ``` -For convenience we include the full contents of the default `CharacterCmdSet` in there. This will make a Character’s normal commands available to the mech. We also add the mech-commands from before, making sure they are stored persistently in the database. The locks specify that anyone can puppet the meck and no-one can "call" the mech's Commands from 'outside' it - you have to puppet it to be able to shoot. +For convenience we include the full contents of the default `CharacterCmdSet` in there. This will +make a Character’s normal commands available to the mech. We also add the mech-commands from before, +making sure they are stored persistently in the database. The locks specify that anyone can puppet +the meck and no-one can "call" the mech's Commands from 'outside' it - you have to puppet it to be +able to shoot. -That’s it. When Objects of this type are created, they will always start out with the mech’s command set and the correct lock. We set a default description, but you would probably change this with `@desc` to individualize your mechs as you build them. +That’s it. When Objects of this type are created, they will always start out with the mech’s command +set and the correct lock. We set a default description, but you would probably change this with +`@desc` to individualize your mechs as you build them. Back in the game, just exit the old mech (`@ic` back to your old character) then do @create/drop The Bigger Mech ; bigmech : mech.Mech -We create a new, bigger mech with an alias bigmech. Note how we give the python-path to our Typeclass at the end — this tells Evennia to create the new object based on that class (we don't have to give the full path in our game dir `typeclasses.mech.Mech` because Evennia knows to look in the `typeclasses` folder already). A shining new mech will appear in the room! Just use +We create a new, bigger mech with an alias bigmech. Note how we give the python-path to our +Typeclass at the end — this tells Evennia to create the new object based on that class (we don't +have to give the full path in our game dir `typeclasses.mech.Mech` because Evennia knows to look in +the `typeclasses` folder already). A shining new mech will appear in the room! Just use @ic bigmech @@ -175,10 +220,17 @@ to take it on a test drive. ## Future Mechs -To expand on this you could add more commands to the mech and remove others. Maybe the mech shouldn’t work just like a Character after all. Maybe it makes loud noises every time it passes from room to room. Maybe it cannot pick up things without crushing them. Maybe it needs fuel, ammo and repairs. Maybe you’ll lock it down so it can only be puppeted by emo teenagers. +To expand on this you could add more commands to the mech and remove others. Maybe the mech +shouldn’t work just like a Character after all. Maybe it makes loud noises every time it passes from +room to room. Maybe it cannot pick up things without crushing them. Maybe it needs fuel, ammo and +repairs. Maybe you’ll lock it down so it can only be puppeted by emo teenagers. -Having you puppet the mech-object directly is also just one way to implement a giant mech in Evennia. +Having you puppet the mech-object directly is also just one way to implement a giant mech in +Evennia. -For example, you could instead picture a mech as a “vehicle” that you “enter” as your normal Character (since any Object can move inside another). In that case the “insides” of the mech Object could be the “cockpit”. The cockpit would have the `MechCommandSet` stored on itself and all the shooting goodness would be made available to you only when you enter it. +For example, you could instead picture a mech as a “vehicle” that you “enter” as your normal +Character (since any Object can move inside another). In that case the “insides” of the mech Object +could be the “cockpit”. The cockpit would have the `MechCommandSet` stored on itself and all the +shooting goodness would be made available to you only when you enter it. And of course you could put more guns on it. And make it fly. diff --git a/docs/source/Building-menus.md b/docs/source/Building-menus.md index 3ae8fdcccd..4389a44695 100644 --- a/docs/source/Building-menus.md +++ b/docs/source/Building-menus.md @@ -3,23 +3,36 @@ # The building_menu contrib -This contrib allows you to write custom and easy to use building menus. As the name implies, these menus are most useful for building things, that is, your builders might appreciate them, although you can use them for your players as well. +This contrib allows you to write custom and easy to use building menus. As the name implies, these +menus are most useful for building things, that is, your builders might appreciate them, although +you can use them for your players as well. -Building menus are somewhat similar to `EvMenu` although they don't use the same system at all and are intended to make building easier. They replicate what other engines refer to as "building editors", which allow to you to build in a menu instead of having to enter a lot of complex commands. Builders might appreciate this simplicity, and if the code that was used to create them is simple as well, coders could find this contrib useful. +Building menus are somewhat similar to `EvMenu` although they don't use the same system at all and +are intended to make building easier. They replicate what other engines refer to as "building +editors", which allow to you to build in a menu instead of having to enter a lot of complex +commands. Builders might appreciate this simplicity, and if the code that was used to create them +is simple as well, coders could find this contrib useful. ## A simple menu Before diving in, there are some things to point out: -- Building menus work on an object. This object will be edited by manipulations in the menu. So you can create a menu to add/edit a room, an exit, a character and so on. -- Building menus are arranged in layers of choices. A choice gives access to an option or to a sub-menu. Choices are linked to commands (usually very short). For instance, in the example shown below, to edit the room key, after opening the building menu, you can type `k`. That will lead you to the key choice where you can enter a new key for the room. Then you can enter `@` to leave this choice and go back to the entire menu. (All of this can be changed). -- To open the menu, you will need something like a command. This contrib offers a basic command for demonstration, but we will override it in this example, using the same code with more flexibility. +- Building menus work on an object. This object will be edited by manipulations in the menu. So +you can create a menu to add/edit a room, an exit, a character and so on. +- Building menus are arranged in layers of choices. A choice gives access to an option or to a sub- +menu. Choices are linked to commands (usually very short). For instance, in the example shown +below, to edit the room key, after opening the building menu, you can type `k`. That will lead you +to the key choice where you can enter a new key for the room. Then you can enter `@` to leave this +choice and go back to the entire menu. (All of this can be changed). +- To open the menu, you will need something like a command. This contrib offers a basic command for +demonstration, but we will override it in this example, using the same code with more flexibility. So let's add a very basic example to begin with. ### A generic editing command -Let's begin by adding a new command. You could add or edit the following file (there's no trick here, feel free to organize the code differently): +Let's begin by adding a new command. You could add or edit the following file (there's no trick +here, feel free to organize the code differently): ```python # file: commands/building.py @@ -60,7 +73,8 @@ class EditCmd(Command): if obj.typename == "Room": Menu = RoomBuildingMenu else: - self.msg("|rThe object {} cannot be edited.|n".format(obj.get_display_name(self.caller))) + self.msg("|rThe object {} cannot be +edited.|n".format(obj.get_display_name(self.caller))) return menu = Menu(self.caller, obj) @@ -70,19 +84,29 @@ class EditCmd(Command): This command is rather simple in itself: 1. It has a key `@edit` and a lock to only allow builders to use it. -2. In its `func` method, it begins by checking the arguments, returning an error if no argument is specified. -3. It then searches for the given argument. We search globally. The `search` method used in this way will return the found object or `None`. It will also send the error message to the caller if necessary. -4. Assuming we have found an object, we check the object `typename`. This will be used later when we want to display several building menus. For the time being, we only handle `Room`. If the caller specified something else, we'll display an error. -5. Assuming this object is a `Room`, we have defined a `Menu` object containing the class of our building menu. We build this class (creating an instance), giving it the caller and the object to edit. +2. In its `func` method, it begins by checking the arguments, returning an error if no argument is +specified. +3. It then searches for the given argument. We search globally. The `search` method used in this +way will return the found object or `None`. It will also send the error message to the caller if +necessary. +4. Assuming we have found an object, we check the object `typename`. This will be used later when +we want to display several building menus. For the time being, we only handle `Room`. If the +caller specified something else, we'll display an error. +5. Assuming this object is a `Room`, we have defined a `Menu` object containing the class of our +building menu. We build this class (creating an instance), giving it the caller and the object to +edit. 6. We then open the building menu, using the `open` method. -The end might sound a bit surprising at first glance. But the process is still very simple: we create an instance of our building menu and call its `open` method. Nothing more. +The end might sound a bit surprising at first glance. But the process is still very simple: we +create an instance of our building menu and call its `open` method. Nothing more. > Where is our building menu? -If you go ahead and add this command and test it, you'll get an error. We haven't defined `RoomBuildingMenu` yet. +If you go ahead and add this command and test it, you'll get an error. We haven't defined +`RoomBuildingMenu` yet. -To add this command, edit `commands/default_cmdsets.py`. Import our command, adding an import line at the top of the file: +To add this command, edit `commands/default_cmdsets.py`. Import our command, adding an import line +at the top of the file: ```python """ @@ -119,7 +143,8 @@ class CharacterCmdSet(default_cmds.CharacterCmdSet): ### Our first menu -So far, we can't use our building menu. Our `@edit` command will throw an error. We have to define the `RoomBuildingMenu` class. Open the `commands/building.py` file and add to the end of the file: +So far, we can't use our building menu. Our `@edit` command will throw an error. We have to define +the `RoomBuildingMenu` class. Open the `commands/building.py` file and add to the end of the file: ```python # ... at the end of commands/building.py @@ -138,7 +163,9 @@ class RoomBuildingMenu(BuildingMenu): self.add_choice("key", "k", attr="key") ``` -Save these changes, reload your game. You can now use the `@edit` command. Here's what we get (notice that the commands we enter into the game are prefixed with `> `, though this prefix will probably not appear in your MUD client): +Save these changes, reload your game. You can now use the `@edit` command. Here's what we get +(notice that the commands we enter into the game are prefixed with `> `, though this prefix will +probably not appear in your MUD client): ``` > look @@ -204,10 +231,12 @@ Before diving into the code, let's examine what we have: - When we use the `@edit here` command, a building menu for this room appears. - This menu has two choices: - - Enter `k` to edit the room key. You will go into a choice where you can simply type the key room key (the way we have done here). You can use `@` to go back to the menu. + - Enter `k` to edit the room key. You will go into a choice where you can simply type the key +room key (the way we have done here). You can use `@` to go back to the menu. - You can use `q` to quit the menu. -We then check, with the `look` command, that the menu has modified this room key. So by adding a class, with a method and a single line of code within, we've added a menu with two choices. +We then check, with the `look` command, that the menu has modified this room key. So by adding a +class, with a method and a single line of code within, we've added a menu with two choices. ### Code explanation @@ -227,34 +256,53 @@ class RoomBuildingMenu(BuildingMenu): self.add_choice("key", "k", attr="key") ``` -- We first create a class inheriting from `BuildingMenu`. This is usually the case when we want to create a building menu with this contrib. +- We first create a class inheriting from `BuildingMenu`. This is usually the case when we want to +create a building menu with this contrib. - In this class, we override the `init` method, which is called when the menu opens. -- In this `init` method, we call `add_choice`. This takes several arguments, but we've defined only three here: - - The choice name. This is mandatory and will be used by the building menu to know how to display this choice. - - The command key to access this choice. We've given a simple `"k"`. Menu commands usually are pretty short (that's part of the reason building menus are appreciated by builders). You can also specify additional aliases, but we'll see that later. - - We've added a keyword argument, `attr`. This tells the building menu that when we are in this choice, the text we enter goes into this attribute name. It's called `attr`, but it could be a room attribute or a typeclass persistent or non-persistent attribute (we'll see other examples as well). +- In this `init` method, we call `add_choice`. This takes several arguments, but we've defined only +three here: + - The choice name. This is mandatory and will be used by the building menu to know how to +display this choice. + - The command key to access this choice. We've given a simple `"k"`. Menu commands usually are +pretty short (that's part of the reason building menus are appreciated by builders). You can also +specify additional aliases, but we'll see that later. + - We've added a keyword argument, `attr`. This tells the building menu that when we are in this +choice, the text we enter goes into this attribute name. It's called `attr`, but it could be a room +attribute or a typeclass persistent or non-persistent attribute (we'll see other examples as well). > We've added the menu choice for `key` here, why is another menu choice defined for `quit`? -Our building menu creates a choice at the end of our choice list if it's a top-level menu (sub-menus don't have this feature). You can, however, override it to provide a different "quit" message or to perform some actions. +Our building menu creates a choice at the end of our choice list if it's a top-level menu (sub-menus +don't have this feature). You can, however, override it to provide a different "quit" message or to +perform some actions. I encourage you to play with this code. As simple as it is, it offers some functionalities already. ## Customizing building menus -This somewhat long section explains how to customize building menus. There are different ways depending on what you would like to achieve. We'll go from specific to more advanced here. +This somewhat long section explains how to customize building menus. There are different ways +depending on what you would like to achieve. We'll go from specific to more advanced here. ### Generic choices -In the previous example, we've used `add_choice`. This is one of three methods you can use to add choices. The other two are to handle more generic actions: +In the previous example, we've used `add_choice`. This is one of three methods you can use to add +choices. The other two are to handle more generic actions: -- `add_choice_edit`: this is called to add a choice which points to the `EvEditor`. It is used to edit a description in most cases, although you could edit other things. We'll see an example shortly. `add_choice_edit` uses most of the `add_choice` keyword arguments we'll see, but usually we specify only two (sometimes three): +- `add_choice_edit`: this is called to add a choice which points to the `EvEditor`. It is used to +edit a description in most cases, although you could edit other things. We'll see an example +shortly. `add_choice_edit` uses most of the `add_choice` keyword arguments we'll see, but usually +we specify only two (sometimes three): - The choice title as usual. - The choice key (command key) as usual. - - Optionally, the attribute of the object to edit, with the `attr` keyword argument. By default, `attr` contains `db.desc`. It means that this persistent data attribute will be edited by the `EvEditor`. You can change that to whatever you want though. -- `add_choice_quit`: this allows to add a choice to quit the editor. Most advisable! If you don't do it, the building menu will do it automatically, except if you really tell it not to. Again, you can specify the title and key of this menu. You can also call a function when this menu closes. + - Optionally, the attribute of the object to edit, with the `attr` keyword argument. By +default, `attr` contains `db.desc`. It means that this persistent data attribute will be edited by +the `EvEditor`. You can change that to whatever you want though. +- `add_choice_quit`: this allows to add a choice to quit the editor. Most advisable! If you don't +do it, the building menu will do it automatically, except if you really tell it not to. Again, you +can specify the title and key of this menu. You can also call a function when this menu closes. -So here's a more complete example (you can replace your `RoomBuildingMenu` class in `commands/building.py` to see it): +So here's a more complete example (you can replace your `RoomBuildingMenu` class in +`commands/building.py` to see it): ```python class RoomBuildingMenu(BuildingMenu): @@ -269,7 +317,9 @@ class RoomBuildingMenu(BuildingMenu): self.add_choice_quit("quit this editor", "q") ``` -So far, our building menu class is still thin... and yet we already have some interesting feature. See for yourself the following MUD client output (again, the commands are prefixed with `> ` to distinguish them): +So far, our building menu class is still thin... and yet we already have some interesting feature. +See for yourself the following MUD client output (again, the commands are prefixed with `> ` to +distinguish them): ``` > @reload @@ -278,7 +328,7 @@ So far, our building menu class is still thin... and yet we already have some in Building menu: A beautiful meadow [K]ey: A beautiful meadow - [D]escription: + [D]escription: Welcome to your new Evennia-based game! Visit http://www.evennia.com if you need help, want to contribute, report issues or just join the community. As Account #1 you can create a demo/tutorial area with @batchcommand tutorial_world.build. @@ -304,7 +354,7 @@ Cleared 3 lines from buffer. Building menu: A beautiful meadow [K]ey: A beautiful meadow - [D]escription: + [D]escription: This is a beautiful meadow. But so beautiful I can't describe it. [Q]uit this editor @@ -316,27 +366,52 @@ A beautiful meadow(#2) This is a beautiful meadow. But so beautiful I can't describe it. ``` -So by using the `d` shortcut in our building menu, an `EvEditor` opens. You can use the `EvEditor` commands (like we did here, `:DD` to remove all, `:wq` to save and quit). When you quit the editor, the description is saved (here, in `room.db.desc`) and you go back to the building menu. +So by using the `d` shortcut in our building menu, an `EvEditor` opens. You can use the `EvEditor` +commands (like we did here, `:DD` to remove all, `:wq` to save and quit). When you quit the editor, +the description is saved (here, in `room.db.desc`) and you go back to the building menu. -Notice that the choice to quit has changed too, which is due to our adding `add_choice_quit`. In most cases, you will probably not use this method, since the quit menu is added automatically. +Notice that the choice to quit has changed too, which is due to our adding `add_choice_quit`. In +most cases, you will probably not use this method, since the quit menu is added automatically. ### `add_choice` options -`add_choice` and the two methods `add_choice_edit` and `add_choice_quit` take a lot of optional arguments to make customization easier. Some of these options might not apply to `add_choice_edit` or `add_choice_quit` however. +`add_choice` and the two methods `add_choice_edit` and `add_choice_quit` take a lot of optional +arguments to make customization easier. Some of these options might not apply to `add_choice_edit` +or `add_choice_quit` however. Below are the options of `add_choice`, specify them as arguments: -- The first positional, mandatory argument is the choice title, as we have seen. This will influence how the choice appears in the menu. -- The second positional, mandatory argument is the command key to access to this menu. It is best to use keyword arguments for the other arguments. -- The `aliases` keyword argument can contain a list of aliases that can be used to access to this menu. For instance: `add_choice(..., aliases=['t'])` -- The `attr` keyword argument contains the attribute to edit when this choice is selected. It's a string, it has to be the name, from the object (specified in the menu constructor) to reach this attribute. For instance, a `attr` of `"key"` will try to find `obj.key` to read and write the attribute. You can specify more complex attribute names, for instance, `attr="db.desc"` to set the `desc` persistent attribute, or `attr="ndb.something"` so use a non-persistent data attribute on the object. -- The `text` keyword argument is used to change the text that will be displayed when the menu choice is selected. Menu choices provide a default text that you can change. Since this is a long text, it's useful to use multi-line strings (see an example below). -- The `glance` keyword argument is used to specify how to display the current information while in the menu, when the choice hasn't been opened. If you examine the previous examples, you will see that the current (`key` or `db.desc`) was shown in the menu, next to the command key. This is useful for seeing at a glance the current value (hence the name). Again, menu choices will provide a default glance if you don't specify one. -- The `on_enter` keyword argument allows to add a callback to use when the menu choice is opened. This is more advanced, but sometimes useful. -- The `on_nomatch` keyword argument is called when, once in the menu, the caller enters some text that doesn't match any command (including the `@` command). By default, this will edit the specified `attr`. -- The `on_leave` keyword argument allows to specify a callback used when the caller leaves the menu choice. This can be useful for cleanup as well. +- The first positional, mandatory argument is the choice title, as we have seen. This will +influence how the choice appears in the menu. +- The second positional, mandatory argument is the command key to access to this menu. It is best +to use keyword arguments for the other arguments. +- The `aliases` keyword argument can contain a list of aliases that can be used to access to this +menu. For instance: `add_choice(..., aliases=['t'])` +- The `attr` keyword argument contains the attribute to edit when this choice is selected. It's a +string, it has to be the name, from the object (specified in the menu constructor) to reach this +attribute. For instance, a `attr` of `"key"` will try to find `obj.key` to read and write the +attribute. You can specify more complex attribute names, for instance, `attr="db.desc"` to set the +`desc` persistent attribute, or `attr="ndb.something"` so use a non-persistent data attribute on the +object. +- The `text` keyword argument is used to change the text that will be displayed when the menu choice +is selected. Menu choices provide a default text that you can change. Since this is a long text, +it's useful to use multi-line strings (see an example below). +- The `glance` keyword argument is used to specify how to display the current information while in +the menu, when the choice hasn't been opened. If you examine the previous examples, you will see +that the current (`key` or `db.desc`) was shown in the menu, next to the command key. This is +useful for seeing at a glance the current value (hence the name). Again, menu choices will provide +a default glance if you don't specify one. +- The `on_enter` keyword argument allows to add a callback to use when the menu choice is opened. +This is more advanced, but sometimes useful. +- The `on_nomatch` keyword argument is called when, once in the menu, the caller enters some text +that doesn't match any command (including the `@` command). By default, this will edit the +specified `attr`. +- The `on_leave` keyword argument allows to specify a callback used when the caller leaves the menu +choice. This can be useful for cleanup as well. -These are a lot of possibilities, and most of the time you won't need them all. Here is a short example using some of these arguments (again, replace the `RoomBuildingMenu` class in `commands/building.py` with the following code to see it working): +These are a lot of possibilities, and most of the time you won't need them all. Here is a short +example using some of these arguments (again, replace the `RoomBuildingMenu` class in +`commands/building.py` with the following code to see it working): ```python class RoomBuildingMenu(BuildingMenu): @@ -368,7 +443,7 @@ Reload your game and see it in action: Building menu: A beautiful meadow [T]itle: A beautiful meadow - [D]escription: + [D]escription: This is a beautiful meadow. But so beautiful I can't describe it. [Q]uit the menu @@ -387,7 +462,7 @@ Current title: A beautiful meadow Building menu: A beautiful meadow [T]itle: A beautiful meadow - [D]escription: + [D]escription: This is a beautiful meadow. But so beautiful I can't describe it. [Q]uit the menu @@ -395,18 +470,27 @@ Building menu: A beautiful meadow Closing the building menu. ``` -The most surprising part is no doubt the text. We use the multi-line syntax (with `"""`). Excessive spaces will be removed from the left for each line automatically. We specify some information between braces... sometimes using double braces. What might be a bit odd: +The most surprising part is no doubt the text. We use the multi-line syntax (with `"""`). +Excessive spaces will be removed from the left for each line automatically. We specify some +information between braces... sometimes using double braces. What might be a bit odd: - `{back}` is a direct format argument we'll use (see the `.format` specifiers). -- `{{obj...}} refers to the object being edited. We use two braces, because `.format` will remove them. +- `{{obj...}} refers to the object being edited. We use two braces, because `.format` will remove +them. In `glance`, we also use `{obj.key}` to indicate we want to show the room's key. ### Everything can be a function -The keyword arguments of `add_choice` are often strings (type `str`). But each of these arguments can also be a function. This allows for a lot of customization, since we define the callbacks that will be executed to achieve such and such an operation. +The keyword arguments of `add_choice` are often strings (type `str`). But each of these arguments +can also be a function. This allows for a lot of customization, since we define the callbacks that +will be executed to achieve such and such an operation. -To demonstrate, we will try to add a new feature. Our building menu for rooms isn't that bad, but it would be great to be able to edit exits too. So we can add a new menu choice below description... but how to actually edit exits? Exits are not just an attribute to set: exits are objects (of type `Exit` by default) which stands between two rooms (object of type `Room`). So how can we show that? +To demonstrate, we will try to add a new feature. Our building menu for rooms isn't that bad, but +it would be great to be able to edit exits too. So we can add a new menu choice below +description... but how to actually edit exits? Exits are not just an attribute to set: exits are +objects (of type `Exit` by default) which stands between two rooms (object of type `Room`). So how +can we show that? First let's add a couple of exits in limbo, so we have something to work with: @@ -431,9 +515,11 @@ We can access room exits with the `exits` property: [, ] ``` -So what we need is to display this list in our building menu... and to allow to edit it would be great. Perhaps even add new exits? +So what we need is to display this list in our building menu... and to allow to edit it would be +great. Perhaps even add new exits? -First of all, let's write a function to display the `glance` on existing exits. Here's the code, it's explained below: +First of all, let's write a function to display the `glance` on existing exits. Here's the code, +it's explained below: ```python class RoomBuildingMenu(BuildingMenu): @@ -470,16 +556,19 @@ def glance_exits(room): return "\n |gNo exit yet|n" ``` -When the building menu opens, it displays each choice to the caller. A choice is displayed with its title (rendered a bit nicely to show the key as well) and the glance. In the case of the `exits` choice, the glance is a function, so the building menu calls this function giving it the object being edited (the room here). The function should return the text to see. +When the building menu opens, it displays each choice to the caller. A choice is displayed with its +title (rendered a bit nicely to show the key as well) and the glance. In the case of the `exits` +choice, the glance is a function, so the building menu calls this function giving it the object +being edited (the room here). The function should return the text to see. ``` > @edit here Building menu: A beautiful meadow [T]itle: A beautiful meadow - [D]escription: + [D]escription: This is a beautiful meadow. But so beautiful I can't describe it. - [E]xits: + [E]xits: north south [Q]uit the menu @@ -490,13 +579,24 @@ Closing the editor. > How do I know the parameters of the function to give? -The function you give can accept a lot of different parameters. This allows for a flexible approach but might seem complicated at first. Basically, your function can accept any parameter, and the building menu will send only the parameter based on their names. If your function defines an argument named `caller` for instance (like `def func(caller):` ), then the building menu knows that the first argument should contain the caller of the building menu. Here are the arguments, you don't have to specify them (if you do, they need to have the same name): +The function you give can accept a lot of different parameters. This allows for a flexible approach +but might seem complicated at first. Basically, your function can accept any parameter, and the +building menu will send only the parameter based on their names. If your function defines an +argument named `caller` for instance (like `def func(caller):` ), then the building menu knows that +the first argument should contain the caller of the building menu. Here are the arguments, you +don't have to specify them (if you do, they need to have the same name): -- `menu`: if your function defines an argument named `menu`, it will contain the building menu itself. -- `choice`: if your function defines an argument named `choice`, it will contain the `Choice` object representing this menu choice. -- `string`: if your function defines an argument named `string`, it will contain the user input to reach this menu choice. This is not very useful, except on `nomatch` callbacks which we'll see later. -- `obj`: if your function defines an argument named `obj`, it will contain the building menu edited object. -- `caller`: if your function defines an argument named `caller`, it will contain the caller of the building menu. +- `menu`: if your function defines an argument named `menu`, it will contain the building menu +itself. +- `choice`: if your function defines an argument named `choice`, it will contain the `Choice` object +representing this menu choice. +- `string`: if your function defines an argument named `string`, it will contain the user input to +reach this menu choice. This is not very useful, except on `nomatch` callbacks which we'll see +later. +- `obj`: if your function defines an argument named `obj`, it will contain the building menu edited +object. +- `caller`: if your function defines an argument named `caller`, it will contain the caller of the +building menu. - Anything else: any other argument will contain the object being edited by the building menu. So in our case: @@ -505,13 +605,18 @@ So in our case: def glance_exits(room): ``` -The only argument we need is `room`. It's not present in the list of possible arguments, so the editing object of the building menu (the room, here) is given. +The only argument we need is `room`. It's not present in the list of possible arguments, so the +editing object of the building menu (the room, here) is given. > Why is it useful to get the menu or choice object? -Most of the time, you will not need these arguments. In very rare cases, you will use them to get specific data (like the default attribute that was set). This tutorial will not elaborate on these possibilities. Just know that they exist. +Most of the time, you will not need these arguments. In very rare cases, you will use them to get +specific data (like the default attribute that was set). This tutorial will not elaborate on these +possibilities. Just know that they exist. -We should also define a text callback, so that we can enter our menu to see the room exits. We'll see how to edit them in the next section but this is a good opportunity to show a more complete callback. To see it in action, as usual, replace the class and functions in `commands/building.py`: +We should also define a text callback, so that we can enter our menu to see the room exits. We'll +see how to edit them in the next section but this is a good opportunity to show a more complete +callback. To see it in action, as usual, replace the class and functions in `commands/building.py`: ```python # Our building menu @@ -569,16 +674,18 @@ def text_exits(caller, room): return text ``` -Look at the second callback in particular. It takes an additional argument, the caller (remember, the argument names are important, their order is not relevant). This is useful for displaying destination of exits accurately. Here is a demonstration of this menu: +Look at the second callback in particular. It takes an additional argument, the caller (remember, +the argument names are important, their order is not relevant). This is useful for displaying +destination of exits accurately. Here is a demonstration of this menu: ``` > @edit here Building menu: A beautiful meadow [T]itle: A beautiful meadow - [D]escription: + [D]escription: This is a beautiful meadow. But so beautiful I can't describe it. - [E]xits: + [E]xits: north south [Q]uit the menu @@ -597,9 +704,9 @@ Existing exits: Building menu: A beautiful meadow [T]itle: A beautiful meadow - [D]escription: + [D]escription: This is a beautiful meadow. But so beautiful I can't describe it. - [E]xits: + [E]xits: north south [Q]uit the menu @@ -612,21 +719,36 @@ Using callbacks allows a great flexibility. We'll now see how to handle sub-men ### Sub-menus for complex menus -A menu is relatively flat: it has a root (where you see all the menu choices) and individual choices you can go to using the menu choice keys. Once in a choice you can type some input or go back to the root menu by entering the return command (usually `@`). +A menu is relatively flat: it has a root (where you see all the menu choices) and individual choices +you can go to using the menu choice keys. Once in a choice you can type some input or go back to +the root menu by entering the return command (usually `@`). -Why shouldn't individual exits have their own menu though? Say, you edit an exit and can change its key, description or aliases... perhaps even destination? Why ever not? It would make building much easier! +Why shouldn't individual exits have their own menu though? Say, you edit an exit and can change its +key, description or aliases... perhaps even destination? Why ever not? It would make building much +easier! -The building menu system offers two ways to do that. The first is nested keys: nested keys allow to go beyond just one menu/choice, to have menus with more layers. Using them is quick but might feel a bit counter-intuitive at first. Another option is to create a different menu class and redirect from the first to the second. This option might require more lines but is more explicit and can be re-used for multiple menus. Adopt one of them depending of your taste. +The building menu system offers two ways to do that. The first is nested keys: nested keys allow to +go beyond just one menu/choice, to have menus with more layers. Using them is quick but might feel +a bit counter-intuitive at first. Another option is to create a different menu class and redirect +from the first to the second. This option might require more lines but is more explicit and can be +re-used for multiple menus. Adopt one of them depending of your taste. #### Nested menu keys -So far, we've only used menu keys with one letter. We can add more, of course, but menu keys in their simple shape are just command keys. Press "e" to go to the "exits" choice. +So far, we've only used menu keys with one letter. We can add more, of course, but menu keys in +their simple shape are just command keys. Press "e" to go to the "exits" choice. -But menu keys can be nested. Nested keys allow to add choices with sub-menus. For instance, type "e" to go to the "exits" choice, and then you can type "c" to open a menu to create a new exit, or "d" to open a menu to delete an exit. The first menu would have the "e.c" key (first e, then c), the second menu would have key as "e.d". +But menu keys can be nested. Nested keys allow to add choices with sub-menus. For instance, type +"e" to go to the "exits" choice, and then you can type "c" to open a menu to create a new exit, or +"d" to open a menu to delete an exit. The first menu would have the "e.c" key (first e, then c), +the second menu would have key as "e.d". -That's more advanced and, if the following code doesn't sound very friendly to you, try the next section which provides a different approach of the same problem. +That's more advanced and, if the following code doesn't sound very friendly to you, try the next +section which provides a different approach of the same problem. -So we would like to edit exits. That is, you can type "e" to go into the choice of exits, then enter `@e` followed by the exit name to edit it... which will open another menu. In this sub-menu you could change the exit key or description. +So we would like to edit exits. That is, you can type "e" to go into the choice of exits, then +enter `@e` followed by the exit name to edit it... which will open another menu. In this sub-menu +you could change the exit key or description. So we have a menu hierarchy similar to that: @@ -650,9 +772,9 @@ Exits: north(#4) and south(#7) Building menu: A beautiful meadow [T]itle: A beautiful meadow - [D]escription: + [D]escription: This is a beautiful meadow. But so beautiful I can't describe it. - [E]xits: + [E]xits: north south [Q]uit the menu @@ -696,9 +818,9 @@ Existing exits: Building menu: A beautiful meadow [T]itle: A beautiful meadow - [D]escription: + [D]escription: This is a beautiful meadow. But so beautiful I can't describe it. - [E]xits: + [E]xits: door south [Q]uit the menu @@ -707,7 +829,8 @@ Building menu: A beautiful meadow Closing the building menu. ``` -This needs a bit of code and a bit of explanation. So here we go... the code first, the explanations next! +This needs a bit of code and a bit of explanation. So here we go... the code first, the +explanations next! ```python # ... from commands/building.py @@ -733,7 +856,8 @@ class RoomBuildingMenu(BuildingMenu): Current title: |c{{obj.key}}|n """.format(back="|n or |y".join(self.keys_go_back))) self.add_choice_edit("description", "d") - self.add_choice("exits", "e", glance=glance_exits, text=text_exits, on_nomatch=nomatch_exits) + self.add_choice("exits", "e", glance=glance_exits, text=text_exits, +on_nomatch=nomatch_exits) # Exit sub-menu self.add_choice("exit", "e.*", text=text_single_exit, on_nomatch=nomatch_single_exit) @@ -815,16 +939,37 @@ def nomatch_single_exit(menu, caller, room, string): > That's a lot of code! And we only handle editing the exit key! -That's why at some point you might want to write a real sub-menu, instead of using simple nested keys. But you might need both to build pretty menus too! +That's why at some point you might want to write a real sub-menu, instead of using simple nested +keys. But you might need both to build pretty menus too! -1. The first thing new is in our menu class. After creating a `on_nomatch` callback for the exits menu (that shouldn't be a surprised), we need to add a nested key. We give this menu a key of `"e.*"`. That's a bit odd! "e" is our key to the exits menu, . is the separator to indicate a nested menu, and * means anything. So basically, we create a nested menu that is contains within the exits menu and anything. We'll see what this "anything" is in practice. +1. The first thing new is in our menu class. After creating a `on_nomatch` callback for the exits +menu (that shouldn't be a surprised), we need to add a nested key. We give this menu a key of +`"e.*"`. That's a bit odd! "e" is our key to the exits menu, . is the separator to indicate a +nested menu, and * means anything. So basically, we create a nested menu that is contains within +the exits menu and anything. We'll see what this "anything" is in practice. 2. The `glance_exits` and `text_exits` are basically the same. -3. The `nomatch_exits` is short but interesting. It's called when we enter some text in the "exits" menu (that is, in the list of exits). We have said that the user should enter `@e` followed by the exit name to edit it. So in the `nomatch_exits` callbac, we check for that input. If the entered text begins by `@e`, we try to find the exit in the room. If we do... -4. We call the `menu.move` method. That's where things get a bit complicated with nested menus: we need to use `menu.move` to change from layer to layer. Here, we are in the choice of exits (the exits menu, of key "e"). We need to go down one layer to edit an exit. So we call `menu.move` and give it an exit object. The menu system remembers what position the user is based on the keys she has entered: when the user opens the menu, there is no key. If she selects the exits choice, the menu key being "e", the position of the user is `["e"]` (a list with the menu keys). If we call `menu.move`, whatever we give to this method will be appended to the list of keys, so that the user position becomes `["e", ]`. -5. In the menu class, we have defined the menu "e.*", meaning "the menu contained in the exits choice plus anything". The "anything" here is an exit: we have called `menu.move(exit)`, so the `"e.*"` menu choice is chosen. -6. In this menu, the text is set to a callback. There is also a `on_nomatch` callback that is called whenever the user enters some text. If so, we change the exit name. +3. The `nomatch_exits` is short but interesting. It's called when we enter some text in the "exits" +menu (that is, in the list of exits). We have said that the user should enter `@e` followed by the +exit name to edit it. So in the `nomatch_exits` callbac, we check for that input. If the entered +text begins by `@e`, we try to find the exit in the room. If we do... +4. We call the `menu.move` method. That's where things get a bit complicated with nested menus: we +need to use `menu.move` to change from layer to layer. Here, we are in the choice of exits (the +exits menu, of key "e"). We need to go down one layer to edit an exit. So we call `menu.move` and +give it an exit object. The menu system remembers what position the user is based on the keys she +has entered: when the user opens the menu, there is no key. If she selects the exits choice, the +menu key being "e", the position of the user is `["e"]` (a list with the menu keys). If we call +`menu.move`, whatever we give to this method will be appended to the list of keys, so that the user +position becomes `["e", ]`. +5. In the menu class, we have defined the menu "e.*", meaning "the menu contained in the exits +choice plus anything". The "anything" here is an exit: we have called `menu.move(exit)`, so the +`"e.*"` menu choice is chosen. +6. In this menu, the text is set to a callback. There is also a `on_nomatch` callback that is +called whenever the user enters some text. If so, we change the exit name. -Using `menu.move` like this is a bit confusing at first. Sometimes it's useful. In this case, if we want a more complex menu for exits, it makes sense to use a real sub-menu, not nested keys like this. But sometimes, you will find yourself in a situation where you don't need a full menu to handle a choice. +Using `menu.move` like this is a bit confusing at first. Sometimes it's useful. In this case, if +we want a more complex menu for exits, it makes sense to use a real sub-menu, not nested keys like +this. But sometimes, you will find yourself in a situation where you don't need a full menu to +handle a choice. #### Full sub-menu as separate classes @@ -833,7 +978,8 @@ The best way to handle individual exits is to create two separate classes: - One for the room menu. - One for the individual exit menu. -The first one will have to redirect on the second. This might be more intuitive and flexible, depending on what you want to achieve. So let's build two menus: +The first one will have to redirect on the second. This might be more intuitive and flexible, +depending on what you want to achieve. So let's build two menus: ```python # Still in commands/building.py, replace the menu class and functions by... @@ -856,7 +1002,8 @@ class RoomBuildingMenu(BuildingMenu): Current title: |c{{obj.key}}|n """.format(back="|n or |y".join(self.keys_go_back))) self.add_choice_edit("description", "d") - self.add_choice("exits", "e", glance=glance_exits, text=text_exits, on_nomatch=nomatch_exits) + self.add_choice("exits", "e", glance=glance_exits, text=text_exits, +on_nomatch=nomatch_exits) # Menu functions @@ -916,16 +1063,17 @@ class ExitBuildingMenu(BuildingMenu): self.add_choice_edit("description", "d") ``` -The code might be much easier to read. But before detailing it, let's see how it behaves in the game: +The code might be much easier to read. But before detailing it, let's see how it behaves in the +game: ``` > @edit here Building menu: A beautiful meadow [T]itle: A beautiful meadow - [D]escription: + [D]escription: This is a beautiful meadow. But so beautiful I can't describe it. - [E]xits: + [E]xits: door south [Q]uit the menu @@ -946,7 +1094,7 @@ Editing: door Building menu: door [K]ey: door - [D]escription: + [D]escription: None > k @@ -974,7 +1122,7 @@ Current value: north Building menu: north [K]ey: north - [D]escription: + [D]escription: None > d @@ -991,7 +1139,7 @@ Cleared 1 lines from buffer. > :wq Building menu: north [K]ey: north - [D]escription: + [D]escription: This is the northern exit. Cool huh? > @ @@ -1007,9 +1155,9 @@ Existing exits: Building menu: A beautiful meadow [T]itle: A beautiful meadow - [D]escription: + [D]escription: This is a beautiful meadow. But so beautiful I can't describe it. - [E]xits: + [E]xits: north south [Q]uit the menu @@ -1029,28 +1177,43 @@ north This is the northern exit. Cool huh? ``` -Very simply, we created two menus and bridged them together. This needs much less callbacks. There is only one line in the `nomatch_exits` to add: +Very simply, we created two menus and bridged them together. This needs much less callbacks. There +is only one line in the `nomatch_exits` to add: ```python menu.open_submenu("commands.building.ExitBuildingMenu", exit, parent_keys=["e"]) ``` -We have to call `open_submenu` on the menu object (which opens, as its name implies, a sub menu) with three arguments: +We have to call `open_submenu` on the menu object (which opens, as its name implies, a sub menu) +with three arguments: -- The path of the menu class to create. It's the Python class leading to the menu (notice the dots). +- The path of the menu class to create. It's the Python class leading to the menu (notice the +dots). - The object that will be edited by the menu. Here, it's our exit, so we give it to the sub-menu. -- The keys of the parent to open when the sub-menu closes. Basically, when we're in the root of the sub-menu and press `@`, we'll open the parent menu, with the parent keys. So we specify `["e"]`, since the parent menus is the "exits" choice. +- The keys of the parent to open when the sub-menu closes. Basically, when we're in the root of the +sub-menu and press `@`, we'll open the parent menu, with the parent keys. So we specify `["e"]`, +since the parent menus is the "exits" choice. -And that's it. The new class will be automatically created. As you can see, we have to create a `on_nomatch` callback to open the sub-menu, but once opened, it automatically close whenever needed. +And that's it. The new class will be automatically created. As you can see, we have to create a +`on_nomatch` callback to open the sub-menu, but once opened, it automatically close whenever needed. ### Generic menu options -There are some options that can be set on any menu class. These options allow for greater customization. They are class attributes (see the example below), so just set them in the class body: +There are some options that can be set on any menu class. These options allow for greater +customization. They are class attributes (see the example below), so just set them in the class +body: -- `keys_go_back` (default to `["@"]`): the keys to use to go back in the menu hierarchy, from choice to root menu, from sub-menu to parent-menu. By default, only a `@` is used. You can change this key for one menu or all of them. You can define multiple return commands if you want. -- `sep_keys` (default `"."`): this is the separator for nested keys. There is no real need to redefine it except if you really need the dot as a key, and need nested keys in your menu. -- `joker_key` (default to `"*"`): used for nested keys to indicate "any key". Again, you shouldn't need to change it unless you want to be able to use the @*@ in a command key, and also need nested keys in your menu. -- `min_shortcut` (default to `1`): although we didn't see it here, one can create a menu choice without giving it a key. If so, the menu system will try to "guess" the key. This option allows to change the minimum length of any key for security reasons. +- `keys_go_back` (default to `["@"]`): the keys to use to go back in the menu hierarchy, from choice +to root menu, from sub-menu to parent-menu. By default, only a `@` is used. You can change this +key for one menu or all of them. You can define multiple return commands if you want. +- `sep_keys` (default `"."`): this is the separator for nested keys. There is no real need to +redefine it except if you really need the dot as a key, and need nested keys in your menu. +- `joker_key` (default to `"*"`): used for nested keys to indicate "any key". Again, you shouldn't +need to change it unless you want to be able to use the @*@ in a command key, and also need nested +keys in your menu. +- `min_shortcut` (default to `1`): although we didn't see it here, one can create a menu choice +without giving it a key. If so, the menu system will try to "guess" the key. This option allows to +change the minimum length of any key for security reasons. To set one of them just do so in your menu class(es): @@ -1062,4 +1225,9 @@ class RoomBuildingMenu(BuildingMenu): ## Conclusion -Building menus mean to save you time and create a rich yet simple interface. But they can be complicated to learn and require reading the source code to find out how to do such and such a thing. This documentation, however long, is an attempt at describing this system, but chances are you'll still have questions about it after reading it, especially if you try to push this system to a great extent. Do not hesitate to read the documentation of this contrib, it's meant to be exhaustive but user-friendly. \ No newline at end of file +Building menus mean to save you time and create a rich yet simple interface. But they can be +complicated to learn and require reading the source code to find out how to do such and such a +thing. This documentation, however long, is an attempt at describing this system, but chances are +you'll still have questions about it after reading it, especially if you try to push this system to +a great extent. Do not hesitate to read the documentation of this contrib, it's meant to be +exhaustive but user-friendly. \ No newline at end of file diff --git a/docs/source/Choosing-An-SQL-Server.md b/docs/source/Choosing-An-SQL-Server.md index fff698dd3d..b0cb784826 100644 --- a/docs/source/Choosing-An-SQL-Server.md +++ b/docs/source/Choosing-An-SQL-Server.md @@ -7,56 +7,90 @@ This page gives an overview of the supported SQL databases as well as instructio - PostgreSQL - MySQL / MariaDB -Since Evennia uses [Django](http://djangoproject.com), most of our notes are based off of what we know from the community and their documentation. While the information below may be useful, you can always find the most up-to-date and "correct" information at Django's [Notes about supported Databases](http://docs.djangoproject.com/en/dev/ref/databases/#ref-databases) page. +Since Evennia uses [Django](http://djangoproject.com), most of our notes are based off of what we +know from the community and their documentation. While the information below may be useful, you can +always find the most up-to-date and "correct" information at Django's [Notes about supported +Databases](http://docs.djangoproject.com/en/dev/ref/databases/#ref-databases) page. ## SQLite3 -[SQLite3](https://sqlite.org/) is a light weight single-file database. It is our default database and Evennia will set this up for you automatically if you give no other options. SQLite stores the database in a single file (`mygame/server/evennia.db3`). This means it's very easy to reset this database - just delete (or move) that `evennia.db3` file and run `evennia migrate` again! No server process is needed and the administrative overhead and resource consumption is tiny. It is also very fast since it's run in-memory. For the vast majority of Evennia installs it will probably be all that's ever needed. +[SQLite3](https://sqlite.org/) is a light weight single-file database. It is our default database +and Evennia will set this up for you automatically if you give no other options. SQLite stores the +database in a single file (`mygame/server/evennia.db3`). This means it's very easy to reset this +database - just delete (or move) that `evennia.db3` file and run `evennia migrate` again! No server +process is needed and the administrative overhead and resource consumption is tiny. It is also very +fast since it's run in-memory. For the vast majority of Evennia installs it will probably be all +that's ever needed. -SQLite will generally be much faster than MySQL/PostgreSQL but its performance comes with two drawbacks: +SQLite will generally be much faster than MySQL/PostgreSQL but its performance comes with two +drawbacks: -* SQLite [ignores length constraints by design](https://www.sqlite.org/faq.html#q9); it is possible to store very large strings and numbers in fields that technically should not accept them. This is not something you will notice; your game will read and write them and function normally, but this *can* create some data migration problems requiring careful thought if you do need to change databases later. -* SQLite can scale well to storage of millions of objects, but if you end up with a thundering herd of users trying to access your MUD and web site at the same time, or you find yourself writing long-running functions to update large numbers of objects on a live game, either will yield errors and interference. SQLite does not work reliably with multiple concurrent threads or processes accessing its records. This has to do with file-locking clashes of the database file. So for a production server making heavy use of process- or thread pools (or when using a third-party webserver like Apache), a proper database is a more appropriate choice. +* SQLite [ignores length constraints by design](https://www.sqlite.org/faq.html#q9); it is possible +to store very large strings and numbers in fields that technically should not accept them. This is +not something you will notice; your game will read and write them and function normally, but this +*can* create some data migration problems requiring careful thought if you do need to change +databases later. +* SQLite can scale well to storage of millions of objects, but if you end up with a thundering herd +of users trying to access your MUD and web site at the same time, or you find yourself writing long- +running functions to update large numbers of objects on a live game, either will yield errors and +interference. SQLite does not work reliably with multiple concurrent threads or processes accessing +its records. This has to do with file-locking clashes of the database file. So for a production +server making heavy use of process- or thread pools (or when using a third-party webserver like +Apache), a proper database is a more appropriate choice. ### Install of SQlite3 -This is installed and configured as part of Evennia. The database file is created as `mygame/server/evennia.db3` when you run +This is installed and configured as part of Evennia. The database file is created as +`mygame/server/evennia.db3` when you run evennia migrate -without changing any database options. An optional requirement is the `sqlite3` client program - this is required if you want to inspect the database data manually. A shortcut for using it with the evennia database is `evennia dbshell`. Linux users should look for the `sqlite3` package for their distro while Mac/Windows should get the [sqlite-tools package from this page](https://sqlite.org/download.html). +without changing any database options. An optional requirement is the `sqlite3` client program - +this is required if you want to inspect the database data manually. A shortcut for using it with the +evennia database is `evennia dbshell`. Linux users should look for the `sqlite3` package for their +distro while Mac/Windows should get the [sqlite-tools package from this +page](https://sqlite.org/download.html). -To inspect the default Evennia database (once it's been created), go to your game dir and do +To inspect the default Evennia database (once it's been created), go to your game dir and do ```bash sqlite3 server/evennia.db3 - # or + # or evennia dbshell ``` -This will bring you into the sqlite command line. Use `.help` for instructions and `.quit` to exit. See [here](https://gist.github.com/vincent178/10889334) for a cheat-sheet of commands. +This will bring you into the sqlite command line. Use `.help` for instructions and `.quit` to exit. +See [here](https://gist.github.com/vincent178/10889334) for a cheat-sheet of commands. ## PostgreSQL -[PostgreSQL](https://www.postgresql.org/) is an open-source database engine, recommended by Django. While not as fast as SQLite for normal usage, it will scale better than SQLite, especially if your game has an very large database and/or extensive web presence through a separate server process. +[PostgreSQL](https://www.postgresql.org/) is an open-source database engine, recommended by Django. +While not as fast as SQLite for normal usage, it will scale better than SQLite, especially if your +game has an very large database and/or extensive web presence through a separate server process. -### Install and initial setup of PostgreSQL +### Install and initial setup of PostgreSQL -First, install the posgresql server. Version `9.6` is tested with Evennia. Packages are readily available for all distributions. You need to also get the `psql` client (this is called `postgresql-client` on debian-derived systems). Windows/Mac users can [find what they need on the postgresql download page](https://www.postgresql.org/download/). You should be setting up a password for your database-superuser (always called `postgres`) when you install. +First, install the posgresql server. Version `9.6` is tested with Evennia. Packages are readily +available for all distributions. You need to also get the `psql` client (this is called `postgresql- +client` on debian-derived systems). Windows/Mac users can [find what they need on the postgresql +download page](https://www.postgresql.org/download/). You should be setting up a password for your +database-superuser (always called `postgres`) when you install. -For interaction with Evennia you need to also install `psycopg2` to your Evennia install (`pip install psycopg2-binary` in your virtualenv). This acts as the python bridge to the database server. +For interaction with Evennia you need to also install `psycopg2` to your Evennia install (`pip +install psycopg2-binary` in your virtualenv). This acts as the python bridge to the database server. Next, start the postgres client: ```bash psql -U postgres --password ``` -> :warning: **Warning:** With the `--password` argument, Postgres should prompt you for a password. -If it won't, replace that with `-p yourpassword` instead. Do not use the `-p` argument unless you have to since the resulting command, and your password, will be logged in the shell history. +> :warning: **Warning:** With the `--password` argument, Postgres should prompt you for a password. +If it won't, replace that with `-p yourpassword` instead. Do not use the `-p` argument unless you +have to since the resulting command, and your password, will be logged in the shell history. -This will open a console to the postgres service using the psql client. +This will open a console to the postgres service using the psql client. -On the psql command line: +On the psql command line: ```sql CREATE USER evennia WITH PASSWORD 'somepassword'; @@ -69,19 +103,23 @@ ALTER ROLE evennia SET default_transaction_isolation TO 'read committed'; ALTER ROLE evennia SET timezone TO 'UTC'; GRANT ALL PRIVILEGES ON DATABASE evennia TO evennia; --- Other useful commands: +-- Other useful commands: -- \l (list all databases and permissions) -- \q (exit) ``` [Here](https://gist.github.com/Kartones/dd3ff5ec5ea238d4c546) is a cheat-sheet for psql commands. -We create a database user 'evennia' and a new database named `evennia` (you can call them whatever you want though). We then grant the 'evennia' user full privileges to the new database so it can read/write etc to it. -If you in the future wanted to completely wipe the database, an easy way to do is to log in as the `postgres` superuser again, then do `DROP DATABASE evennia;`, then `CREATE` and `GRANT` steps above again to recreate the database and grant privileges. +We create a database user 'evennia' and a new database named `evennia` (you can call them whatever +you want though). We then grant the 'evennia' user full privileges to the new database so it can +read/write etc to it. +If you in the future wanted to completely wipe the database, an easy way to do is to log in as the +`postgres` superuser again, then do `DROP DATABASE evennia;`, then `CREATE` and `GRANT` steps above +again to recreate the database and grant privileges. ### Evennia PostgreSQL configuration -Edit `mygame/server/conf/secret_settings.py and add the following section: +Edit `mygame/server/conf/secret_settings.py and add the following section: ```python # @@ -102,23 +140,34 @@ If you used some other name for the database and user, enter those instead. Run evennia migrate -to populate your database. Should you ever want to inspect the database directly you can from now on also use +to populate your database. Should you ever want to inspect the database directly you can from now on +also use evennia dbshell as a shortcut to get into the postgres command line for the right database and user. -With the database setup you should now be able to start start Evennia normally with your new database. +With the database setup you should now be able to start start Evennia normally with your new +database. ## MySQL / MariaDB -[MySQL](https://www.mysql.com/) is a commonly used proprietary database system, on par with PostgreSQL. There is an open-source alternative called [MariaDB](https://mariadb.org/) that mimics all functionality and command syntax of the former. So this section covers both. +[MySQL](https://www.mysql.com/) is a commonly used proprietary database system, on par with +PostgreSQL. There is an open-source alternative called [MariaDB](https://mariadb.org/) that mimics +all functionality and command syntax of the former. So this section covers both. ### Installing and initial setup of MySQL/MariaDB -First, install and setup MariaDB or MySQL for your specific server. Linux users should look for the `mysql-server` or `mariadb-server` packages for their respective distributions. Windows/Mac users will find what they need from the [MySQL downloads](https://www.mysql.com/downloads/) or [MariaDB downloads](https://mariadb.org/download/) pages. You also need the respective database clients (`mysql`, `mariadb-client`), so you can setup the database itself. When you install the server you should usually be asked to set up the database root user and password. +First, install and setup MariaDB or MySQL for your specific server. Linux users should look for the +`mysql-server` or `mariadb-server` packages for their respective distributions. Windows/Mac users +will find what they need from the [MySQL downloads](https://www.mysql.com/downloads/) or [MariaDB +downloads](https://mariadb.org/download/) pages. You also need the respective database clients +(`mysql`, `mariadb-client`), so you can setup the database itself. When you install the server you +should usually be asked to set up the database root user and password. -You will finally also need a Python interface to allow Evennia to talk to the database. Django recommends the `mysqlclient` one. Install this into the evennia virtualenv with `pip install mysqlclient`. +You will finally also need a Python interface to allow Evennia to talk to the database. Django +recommends the `mysqlclient` one. Install this into the evennia virtualenv with `pip install +mysqlclient`. Start the database client (this is named the same for both mysql and mariadb): @@ -126,29 +175,43 @@ Start the database client (this is named the same for both mysql and mariadb): mysql -u root -p ``` -You should get to enter your database root password (set this up when you installed the database server). +You should get to enter your database root password (set this up when you installed the database +server). Inside the database client interface: ```sql CREATE USER 'evennia'@'localhost' IDENTIFIED BY 'somepassword'; CREATE DATABASE evennia; -ALTER DATABASE `evennia` CHARACTER SET utf8; -- note that it's `evennia` with back-ticks, not quotes! +ALTER DATABASE `evennia` CHARACTER SET utf8; -- note that it's `evennia` with back-ticks, not +quotes! GRANT ALL PRIVILEGES ON evennia.* TO 'evennia'@'localhost'; FLUSH PRIVILEGES; -- use 'exit' to quit client ``` -[Here](https://gist.github.com/hofmannsven/9164408) is a mysql command cheat sheet. +[Here](https://gist.github.com/hofmannsven/9164408) is a mysql command cheat sheet. -Above we created a new local user and database (we called both 'evennia' here, you can name them what you prefer). We set the character set to `utf8` to avoid an issue with prefix character length that can pop up on some installs otherwise. Next we grant the 'evennia' user all privileges on the `evennia` database and make sure the privileges are applied. Exiting the client brings us back to the normal terminal/console. +Above we created a new local user and database (we called both 'evennia' here, you can name them +what you prefer). We set the character set to `utf8` to avoid an issue with prefix character length +that can pop up on some installs otherwise. Next we grant the 'evennia' user all privileges on the +`evennia` database and make sure the privileges are applied. Exiting the client brings us back to +the normal terminal/console. -> Note: If you are not using MySQL for anything else you might consider granting the 'evennia' user full privileges with `GRANT ALL PRIVILEGES ON *.* TO 'evennia'@'localhost';`. If you do, it means you can use `evennia dbshell` later to connect to mysql, drop your database and re-create it as a way of easy reset. Without this extra privilege you will be able to drop the database but not re-create it without first switching to the database-root user. +> Note: If you are not using MySQL for anything else you might consider granting the 'evennia' user +full privileges with `GRANT ALL PRIVILEGES ON *.* TO 'evennia'@'localhost';`. If you do, it means +you can use `evennia dbshell` later to connect to mysql, drop your database and re-create it as a +way of easy reset. Without this extra privilege you will be able to drop the database but not re- +create it without first switching to the database-root user. ## Add MySQL configuration to Evennia -To tell Evennia to use your new database you need to edit `mygame/server/conf/settings.py` (or `secret_settings.py` if you don't want your db info passed around on git repositories). +To tell Evennia to use your new database you need to edit `mygame/server/conf/settings.py` (or +`secret_settings.py` if you don't want your db info passed around on git repositories). -> Note: The Django documentation suggests using an external `db.cnf` or other external conf-formatted file. Evennia users have however found that this leads to problems (see e.g. [issue #1184](https://git.io/vQdiN)). To avoid trouble we recommend you simply put the configuration in your settings as below. +> Note: The Django documentation suggests using an external `db.cnf` or other external conf- +formatted file. Evennia users have however found that this leads to problems (see e.g. [issue +#1184](https://git.io/vQdiN)). To avoid trouble we recommend you simply put the configuration in +your settings as below. ```python # @@ -157,9 +220,9 @@ To tell Evennia to use your new database you need to edit `mygame/server/conf/se DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', - 'NAME': 'evennia', - 'USER': 'evennia', - 'PASSWORD': 'somepassword', + 'NAME': 'evennia', + 'USER': 'evennia', + 'PASSWORD': 'somepassword', 'HOST': 'localhost', # or an IP Address that your DB is hosted on 'PORT': '', # use default port } @@ -169,14 +232,18 @@ Change this to fit your database setup. Next, run: evennia migrate -to populate your database. Should you ever want to inspect the database directly you can from now on also use +to populate your database. Should you ever want to inspect the database directly you can from now on +also use evennia dbshell as a shortcut to get into the postgres command line for the right database and user. -With the database setup you should now be able to start start Evennia normally with your new database. +With the database setup you should now be able to start start Evennia normally with your new +database. ## Others -No testing has been performed with Oracle, but it is also supported through Django. There are community maintained drivers for [MS SQL](http://code.google.com/p/django-mssql/) and possibly a few others. If you try other databases out, consider expanding this page with instructions. +No testing has been performed with Oracle, but it is also supported through Django. There are +community maintained drivers for [MS SQL](http://code.google.com/p/django-mssql/) and possibly a few +others. If you try other databases out, consider expanding this page with instructions. diff --git a/docs/source/Client-Support-Grid.md b/docs/source/Client-Support-Grid.md index 503882b122..63e18f89b6 100644 --- a/docs/source/Client-Support-Grid.md +++ b/docs/source/Client-Support-Grid.md @@ -1,12 +1,15 @@ # Client Support Grid -This grid tries to gather Evennia-specific knowledge about the various clients and protocols used. Everyone's welcome to report their findings. +This grid tries to gather Evennia-specific knowledge about the various clients and protocols used. +Everyone's welcome to report their findings. -##### Legend: +##### Legend: - - **Name**: The name of the client. If it's only available for a specific OS, it should be noted here too. + - **Name**: The name of the client. If it's only available for a specific OS, it should be noted +here too. - **Version**: Which version or range of client versions were tested. - - **Comments**: Any comments or quirks on using this client with Evennia should be added here. Also note if some other protocol than Telnet is used (like Websockets, SSH etc). + - **Comments**: Any comments or quirks on using this client with Evennia should be added here. Also +note if some other protocol than Telnet is used (like Websockets, SSH etc). ## Client Grid @@ -16,22 +19,29 @@ Name | Version | Comments [tintin++][3] | 2.0+ | No MXP support [tinyfugue][4] | 5.0+ | No UTF-8 support [MUSHclient][5] (Win) | 4.94 | NAWS reports full text area -[Zmud][6] (Win) | 7.21 | *UNTESTED* -[Cmud][7] (Win) | v3 | *UNTESTED* -[Potato][8] | 2.0.0b16 | No MXP, MCCP support. Win 32bit does not understand "localhost", must use `127.0.0.1`. [Newline issue](https://github.com/evennia/evennia/issues/1131). *Won't send a single blank line on Enter press. +[Zmud][6] (Win) | 7.21 | *UNTESTED* +[Cmud][7] (Win) | v3 | *UNTESTED* +[Potato][8] | 2.0.0b16 | No MXP, MCCP support. Win 32bit does not understand +"localhost", must use `127.0.0.1`. [Newline issue](https://github.com/evennia/evennia/issues/1131). +*Won't send a single blank line on Enter press. [Mudlet][9] | 3.4+ | No known issues. Some older versions showed <> as html under MXP. [SimpleMU][10] (Win) | full | *UNTESTED*. Discontinued. NAWS reports pixel size. [Atlantis][11] (Mac) | 0.9.9.4 | No known issues. [GMUD][12] | 0.0.1 | Can't handle any telnet handshakes. Not recommended. -[BeipMU][13] (Win) | 3.0.255 | No MXP support. Best to enable "MUD prompt handling", disable "Handle HTML tags". +[BeipMU][13] (Win) | 3.0.255 | No MXP support. Best to enable "MUD prompt handling", disable +"Handle HTML tags". [MudRammer][14] (IOS) | 1.8.7 | Bad Telnet Protocol compliance: displays spurious characters. -[MUDMaster][15] (IOS) | 1.3.1 | *UNTESTED* +[MUDMaster][15] (IOS) | 1.3.1 | *UNTESTED* [BlowTorch][16] (Andr) | 1.1.3 | *Telnet NOP displays as spurious character. -[Mukluk][17] (Andr) | 2015.11.20| *Telnet NOP displays as spurious character. Has UTF-8/Emoji support. -[Gnome-MUD][18] (Unix) | 0.11.2 | Telnet handshake errors. First (only) attempt at logging in fails. +[Mukluk][17] (Andr) | 2015.11.20| *Telnet NOP displays as spurious character. Has UTF-8/Emoji +support. +[Gnome-MUD][18] (Unix) | 0.11.2 | Telnet handshake errors. First (only) attempt at logging in +fails. [Spyrit][19] | 0.4 | No MXP, OOB support. [JamochaMUD][20] | 5.2 | Does not support ANSI within MXP text. -[DuckClient][21] (Chrome)| 4.2 | No MXP support. Displays Telnet Go-Ahead and WILL SUPPRESS-GO-AHEAD as ù character. Also seems to run the `version` command on connection, which will not work in `MULTISESSION_MODES` above 1. +[DuckClient][21] (Chrome)| 4.2 | No MXP support. Displays Telnet Go-Ahead and WILL SUPPRESS-GO-AHEAD +as ù character. Also seems to run the `version` command on connection, which will not work in +`MULTISESSION_MODES` above 1. [KildClient][22] | 2.11.1 | No known issues. [1]: https://github.com/evennia/evennia/wiki/Web%20features#web-client @@ -68,16 +78,17 @@ Known clients: Workaround: -* Set the command in game to `@option NOPKEEPALIVE=off` for the session, or use the `/save` parameter to disable it for that Evennian account permanently. +* Set the command in game to `@option NOPKEEPALIVE=off` for the session, or use the `/save` +parameter to disable it for that Evennian account permanently. * Client-side: Set a gag-type trigger on the NOP character to make it invisible to the client. ### Issue: Won't send blank line on Enter key press. -Known clients: +Known clients: * [Potato][8] -Workaround: +Workaround: * Press Control Enter, then Enter key again to send blank line. diff --git a/docs/source/Coding-FAQ.md b/docs/source/Coding-FAQ.md index b1e9a61f41..fe5b569266 100644 --- a/docs/source/Coding-FAQ.md +++ b/docs/source/Coding-FAQ.md @@ -1,31 +1,54 @@ # Coding FAQ -*This FAQ page is for users to share their solutions to coding problems. Keep it brief and link to the docs if you can rather than too lengthy explanations. Don't forget to check if an answer already exists before answering - maybe you can clarify that answer rather than to make a new Q&A section.* +*This FAQ page is for users to share their solutions to coding problems. Keep it brief and link to +the docs if you can rather than too lengthy explanations. Don't forget to check if an answer already +exists before answering - maybe you can clarify that answer rather than to make a new Q&A section.* ## Table of Contents +- [Will I run out of dbrefs?](./Coding-FAQ#will-i-run-out-of-dbrefs) - [Removing default commands](./Coding-FAQ#removing-default-commands) -- [Preventing character from moving based on a condition](./Coding-FAQ#preventing-character-from-moving-based-on-a-condition) -- [Reference initiating object in an EvMenu command](./Coding-FAQ#reference-initiating-object-in-an-evmenu-command) +- [Preventing character from moving based on a condition](./Coding-FAQ#preventing-character-from- +moving-based-on-a-condition) +- [Reference initiating object in an EvMenu command](./Coding-FAQ#reference-initiating-object-in-an- +evmenu-command) - [Adding color to default Evennia Channels](./Coding-FAQ#adding-color-to-default-evennia-channels) - [Selectively turn off commands in a room](./Coding-FAQ#selectively-turn-off-commands-in-a-room) - [Select Command based on a condition](./Coding-FAQ#select-command-based-on-a-condition) -- [Automatically updating code when reloading](./Coding-FAQ#automatically-updating-code-when-reloading) +- [Automatically updating code when reloading](./Coding-FAQ#automatically-updating-code-when- +reloading) - [Changing all exit messages](./Coding-FAQ#changing-all-exit-messages) - [Add parsing with the "to" delimiter](./Coding-FAQ#add-parsing-with-the-to-delimiter) - [Store last used session IP address](./Coding-FAQ#store-last-used-session-ip-address) - [Use wide characters with EvTable](./Coding-FAQ#non-latin-characters-in-evtable) -## Removing default commands -**Q:** How does one *remove* (not replace) e.g. the default `get` [Command](./Commands) from the Character [Command Set](./Command-Sets)? +## Will I run out of dbrefs? +**Q:** The `#dbref` of a database object is ever-increasing. Evennia doesn't allow you to change or +reuse them. Will not a big/old game run out of dbref integers eventually? -**A:** Go to `mygame/commands/default_cmdsets.py`. Find the `CharacterCmdSet` class. It has one method named `at_cmdset_creation`. At the end of that method, add the following line: `self.remove(default_cmds.CmdGet())`. See the [Adding Commands Tutorial](./Adding-Command-Tutorial) for more info. +**A:** No. For example, the default sqlite3 database's max dbref is `2**64`. If you created `10 000` +objects every second every minute and every day of the year it would take ~60 million years for you +to run out of dbref numbers. That's a database of 140 TeraBytes, if every row was empty. If you are +still using Evennia at that point and has this concern, get back to us and we can discuss adding +dbref reuse then. + +## Removing default commands +**Q:** How does one *remove* (not replace) e.g. the default `get` [Command](./Commands) from the +Character [Command Set](./Command-Sets)? + +**A:** Go to `mygame/commands/default_cmdsets.py`. Find the `CharacterCmdSet` class. It has one +method named `at_cmdset_creation`. At the end of that method, add the following line: +`self.remove(default_cmds.CmdGet())`. See the [Adding Commands Tutorial](./Adding-Command-Tutorial) +for more info. ## Preventing character from moving based on a condition -**Q:** How does one keep a character from using any exit, if they meet a certain condition? (I.E. in combat, immobilized, etc.) +**Q:** How does one keep a character from using any exit, if they meet a certain condition? (I.E. in +combat, immobilized, etc.) -**A:** The `at_before_move` hook is called by Evennia just before performing any move. If it returns `False`, the move is aborted. Let's say we want to check for an [Attribute](./Attributes) `cantmove`. Add the following code to the `Character` class: +**A:** The `at_before_move` hook is called by Evennia just before performing any move. If it returns +`False`, the move is aborted. Let's say we want to check for an [Attribute](./Attributes) `cantmove`. +Add the following code to the `Character` class: ```python def at_before_move(self, destination): @@ -37,9 +60,13 @@ def at_before_move(self, destination): ``` ## Reference initiating object in an EvMenu command. -**Q:** An object has a Command on it starts up an EvMenu instance. How do I capture a reference to that object for use in the menu? +**Q:** An object has a Command on it starts up an EvMenu instance. How do I capture a reference to +that object for use in the menu? -**A:** When an [EvMenu](./EvMenu) is started, the menu object is stored as `caller.ndb._menutree`. This is a good place to store menu-specific things since it will clean itself up when the menu closes. When initiating the menu, any additional keywords you give will be available for you as properties on this menu object: +**A:** When an [EvMenu](./EvMenu) is started, the menu object is stored as `caller.ndb._menutree`. +This is a good place to store menu-specific things since it will clean itself up when the menu +closes. When initiating the menu, any additional keywords you give will be available for you as +properties on this menu object: ```python class MyObjectCommand(Command): @@ -57,7 +84,8 @@ Inside the menu you can now access the object through `caller.ndb._menutree.stor ## Adding color to default Evennia Channels **Q:** How do I add colors to the names of Evennia channels? -**A:** The Channel typeclass' `channel_prefix` method decides what is shown at the beginning of a channel send. Edit `mygame/typeclasses/channels.py` (and then `@reload`): +**A:** The Channel typeclass' `channel_prefix` method decides what is shown at the beginning of a +channel send. Edit `mygame/typeclasses/channels.py` (and then `@reload`): ```python # define our custom color names @@ -75,13 +103,18 @@ CHANNEL_COLORS = {'public': '|015Public|n', prefix_string = "[%s] " % self.key.capitalize() return prefix_string ``` -Additional hint: To make colors easier to change from one place you could instead put the `CHANNEL_COLORS` dict in your settings file and import it as `from django.conf.settings import CHANNEL_COLORS`. +Additional hint: To make colors easier to change from one place you could instead put the +`CHANNEL_COLORS` dict in your settings file and import it as `from django.conf.settings import +CHANNEL_COLORS`. ## Selectively turn off commands in a room -**Q:** I want certain commands to turn off in a given room. They should still work normally for staff. +**Q:** I want certain commands to turn off in a given room. They should still work normally for +staff. -**A:** This is done using a custom cmdset on a room [locked with the 'call' lock type](./Locks). Only if this lock is passed will the commands on the room be made available to an object inside it. Here is an example of a room where certain commands are disabled for non-staff: +**A:** This is done using a custom cmdset on a room [locked with the 'call' lock type](./Locks). Only +if this lock is passed will the commands on the room be made available to an object inside it. Here +is an example of a room where certain commands are disabled for non-staff: ```python # in mygame/typeclasses/rooms.py @@ -109,12 +142,19 @@ class BlockingRoom(Room): # are NOT Builders or higher self.locks.add("call:not perm(Builders)") ``` -After `@reload`, make some `BlockingRooms` (or switch a room to it with `@typeclass`). Entering one will now replace the given commands for anyone that does not have the `Builders` or higher permission. Note that the 'call' lock is special in that even the superuser will be affected by it (otherwise superusers would always see other player's cmdsets and a game would be unplayable for superusers). +After `@reload`, make some `BlockingRooms` (or switch a room to it with `@typeclass`). Entering one +will now replace the given commands for anyone that does not have the `Builders` or higher +permission. Note that the 'call' lock is special in that even the superuser will be affected by it +(otherwise superusers would always see other player's cmdsets and a game would be unplayable for +superusers). ## Select Command based on a condition -**Q:** I want a command to be available only based on a condition. For example I want the "werewolf" command to only be available on a full moon, from midnight to three in-game time. +**Q:** I want a command to be available only based on a condition. For example I want the "werewolf" +command to only be available on a full moon, from midnight to three in-game time. -**A:** This is easiest accomplished by putting the "werewolf" command on the Character as normal, but to [lock](./Locks) it with the "cmd" type lock. Only if the "cmd" lock type is passed will the command be available. +**A:** This is easiest accomplished by putting the "werewolf" command on the Character as normal, +but to [lock](./Locks) it with the "cmd" type lock. Only if the "cmd" lock type is passed will the +command be available. ```python # in mygame/commands/command.py @@ -128,7 +168,8 @@ class CmdWerewolf(Command): def func(self): # ... ``` -Add this to the [default cmdset as usual](./Adding-Command-Tutorial). The `is_full_moon` [lock function](./Locks#lock-functions) does not yet exist. We must create that: +Add this to the [default cmdset as usual](./Adding-Command-Tutorial). The `is_full_moon` [lock +function](Locks#lock-functions) does not yet exist. We must create that: ```python # in mygame/server/conf/lockfuncs.py @@ -140,12 +181,17 @@ def is_full_moon(accessing_obj, accessed_obj, # return True or False ``` -After a `@reload`, the `werewolf` command will be available only at the right time, that is when the `is_full_moon` lock function returns True. +After a `@reload`, the `werewolf` command will be available only at the right time, that is when the +`is_full_moon` lock function returns True. ## Automatically updating code when reloading -**Q:** I have a development server running Evennia. Can I have the server update its code-base when I reload? +**Q:** I have a development server running Evennia. Can I have the server update its code-base when +I reload? -**A:** Having a development server that pulls updated code whenever you reload it can be really useful if you have limited shell access to your server, or want to have it done automatically. If you have your project in a configured Git environment, it's a matter of automatically calling `git pull` when you reload. And that's pretty straightforward: +**A:** Having a development server that pulls updated code whenever you reload it can be really +useful if you have limited shell access to your server, or want to have it done automatically. If +you have your project in a configured Git environment, it's a matter of automatically calling `git +pull` when you reload. And that's pretty straightforward: In `/server/conf/at_server_startstop.py`: @@ -162,28 +208,45 @@ def at_server_reload_stop(): process = subprocess.call(["git", "pull"], shell=False) ``` -That's all. We call `subprocess` to execute a shell command (that code works on Windows and Linux, assuming the current directory is your game directory, which is probably the case when you run Evennia). `call` waits for the process to complete, because otherwise, Evennia would reload on partially-modified code, which would be problematic. +That's all. We call `subprocess` to execute a shell command (that code works on Windows and Linux, +assuming the current directory is your game directory, which is probably the case when you run +Evennia). `call` waits for the process to complete, because otherwise, Evennia would reload on +partially-modified code, which would be problematic. -Now, when you enter `@reload` on your development server, the game repository is updated from the configured remote repository (Github, for instance). Your development cycle could resemble something like: +Now, when you enter `@reload` on your development server, the game repository is updated from the +configured remote repository (Github, for instance). Your development cycle could resemble +something like: 1. Coding on the local machine. 2. Testing modifications. -3. Committing once, twice or more (being sure the code is still working, unittests are pretty useful here). +3. Committing once, twice or more (being sure the code is still working, unittests are pretty useful +here). 4. When the time comes, login to the development server and run `@reload`. -The reloading might take one or two additional seconds, since Evennia will pull from your remote Git repository. But it will reload on it and you will have your modifications ready, without needing connecting to your server using SSH or something similar. +The reloading might take one or two additional seconds, since Evennia will pull from your remote Git +repository. But it will reload on it and you will have your modifications ready, without needing +connecting to your server using SSH or something similar. ## Changing all exit messages -**Q:** How can I change the default exit messages to something like "XXX leaves east" or "XXX arrives from the west"? +**Q:** How can I change the default exit messages to something like "XXX leaves east" or "XXX +arrives from the west"? -**A:** the default exit messages are stored in two hooks, namely `announce_move_from` and `announce_move_to`, on the `Character` typeclass (if what you want to change is the message other characters will see when a character exits). +**A:** the default exit messages are stored in two hooks, namely `announce_move_from` and +`announce_move_to`, on the `Character` typeclass (if what you want to change is the message other +characters will see when a character exits). -These two hooks provide some useful features to easily update the message to be displayed. They take both the default message and mapping as argument. You can easily call the parent hook with these information: +These two hooks provide some useful features to easily update the message to be displayed. They +take both the default message and mapping as argument. You can easily call the parent hook with +these information: -* The message represents the string of characters sent to characters in the room when a character leaves. -* The mapping is a dictionary containing additional mappings (you will probably not need it for simple customization). +* The message represents the string of characters sent to characters in the room when a character +leaves. +* The mapping is a dictionary containing additional mappings (you will probably not need it for +simple customization). -It is advisable to look in the [code of both hooks](https://github.com/evennia/evennia/tree/master/evennia/objects/objects.py), and read the hooks' documentation. The explanations on how to quickly update the message are shown below: +It is advisable to look in the [code of both +hooks](https://github.com/evennia/evennia/tree/master/evennia/objects/objects.py), and read the +hooks' documentation. The explanations on how to quickly update the message are shown below: ```python # In typeclasses/characters.py @@ -244,13 +307,18 @@ class Character(DefaultCharacter): super().announce_move_to(source_location, msg="{object} arrives from the {exit}.") ``` -We override both hooks, but call the parent hook to display a different message. If you read the provided docstrings, you will better understand why and how we use mappings (information between braces). You can provide additional mappings as well, if you want to set a verb to move, for instance, or other, extra information. +We override both hooks, but call the parent hook to display a different message. If you read the +provided docstrings, you will better understand why and how we use mappings (information between +braces). You can provide additional mappings as well, if you want to set a verb to move, for +instance, or other, extra information. ## Add parsing with the "to" delimiter -**Q:** How do I change commands to undestand say `give obj to target` as well as the default `give obj = target`? +**Q:** How do I change commands to undestand say `give obj to target` as well as the default `give +obj = target`? -**A:** You can make change the default `MuxCommand` parent with your own class making a small change in its `parse` method: +**A:** You can make change the default `MuxCommand` parent with your own class making a small change +in its `parse` method: ```python # in mygame/commands/command.py @@ -273,7 +341,8 @@ MuxCommand class is also found commented-out in the `mygame/commands/command.py` ## Store last used session IP address -**Q:** If a user has already logged out of an Evennia account, their IP is no longer visible to staff that wants to ban-by-ip (instead of the user) with `@ban/ip`? +**Q:** If a user has already logged out of an Evennia account, their IP is no longer visible to +staff that wants to ban-by-ip (instead of the user) with `@ban/ip`? **A:** One approach is to write the IP from the last session onto the "account" account object. @@ -283,7 +352,10 @@ MuxCommand class is also found commented-out in the `mygame/commands/command.py` super().at_post_login(session=session, **kwargs) self.db.lastsite = self.sessions.all()[-1].address ``` -Adding timestamp for login time and appending to a list to keep the last N login IP addresses and timestamps is possible, also. Additionally, if you don't want the list to grow beyond a `do_not_exceed` length, conditionally pop a value after you've added it, if the length has grown too long. +Adding timestamp for login time and appending to a list to keep the last N login IP addresses and +timestamps is possible, also. Additionally, if you don't want the list to grow beyond a +`do_not_exceed` length, conditionally pop a value after you've added it, if the length has grown too +long. **NOTE:** You'll need to add `import time` to generate the login timestamp. ```python @@ -297,7 +369,8 @@ Adding timestamp for login time and appending to a list to keep the last N login if len(self.db.lastsite) > do_not_exceed: self.db.lastsite.pop() ``` -This only stores the data. You may want to interface the `@ban` command or make a menu-driven viewer for staff to browse the list and display how long ago the login occurred. +This only stores the data. You may want to interface the `@ban` command or make a menu-driven viewer +for staff to browse the list and display how long ago the login occurred. ## Non-latin characters in EvTable @@ -309,4 +382,8 @@ This only stores the data. You may want to interface the `@ban` command or make | | | +~~~~~~+~~~~~~+ ``` -**A:** The reason for this is because certain non-latin characters are *visually* much wider than their len() suggests. There is little Evennia can (reliably) do about this. If you are using such characters, you need to make sure to use a suitable mono-spaced font where are width are equal. You can set this in your web client and need to recommend it for telnet-client users. See [this discussion](https://github.com/evennia/evennia/issues/1522) where some suitable fonts are suggested. +**A:** The reason for this is because certain non-latin characters are *visually* much wider than +their len() suggests. There is little Evennia can (reliably) do about this. If you are using such +characters, you need to make sure to use a suitable mono-spaced font where are width are equal. You +can set this in your web client and need to recommend it for telnet-client users. See [this +discussion](https://github.com/evennia/evennia/issues/1522) where some suitable fonts are suggested. diff --git a/docs/source/Coding-Introduction.md b/docs/source/Coding-Introduction.md index 258d9e2a34..6a072b1516 100644 --- a/docs/source/Coding-Introduction.md +++ b/docs/source/Coding-Introduction.md @@ -1,17 +1,23 @@ # Coding Introduction -Evennia allows for a lot of freedom when designing your game - but to code efficiently you still need to adopt some best practices as well as find a good place to start to learn. +Evennia allows for a lot of freedom when designing your game - but to code efficiently you still +need to adopt some best practices as well as find a good place to start to learn. Here are some pointers to get you going. ### Python -Evennia is developed using Python. Even if you are more of a designer than a coder, it is wise to learn how to read and understand basic Python code. If you are new to Python, or need a refresher, take a look at our two-part [Python introduction](./Python-basic-introduction). +Evennia is developed using Python. Even if you are more of a designer than a coder, it is wise to +learn how to read and understand basic Python code. If you are new to Python, or need a refresher, +take a look at our two-part [Python introduction](./Python-basic-introduction). ### Explore Evennia interactively -When new to Evennia it can be hard to find things or figure out what is available. Evennia offers a special interactive python shell that allows you to experiment and try out things. It's recommended to use [ipython](http://ipython.org/) for this since the vanilla python prompt is very limited. Here are some simple commands to get started: +When new to Evennia it can be hard to find things or figure out what is available. Evennia offers a +special interactive python shell that allows you to experiment and try out things. It's recommended +to use [ipython](http://ipython.org/) for this since the vanilla python prompt is very limited. Here +are some simple commands to get started: # [open a new console/terminal] # [activate your evennia virtualenv in this console/terminal] @@ -24,39 +30,70 @@ This will open an Evennia-aware python shell (using ipython). From within this s import evennia evennia. -That is, enter `evennia.` and press the `` key. This will show you all the resources made available at the top level of Evennia's "flat API". See the [flat API](./Evennia-API) page for more info on how to explore it efficiently. +That is, enter `evennia.` and press the `` key. This will show you all the resources made +available at the top level of Evennia's "flat API". See the [flat API](./Evennia-API) page for more +info on how to explore it efficiently. -You can complement your exploration by peeking at the sections of the much more detailed [Developer Central](./Developer-Central). The [Tutorials](./Tutorials) section also contains a growing collection of system- or implementation-specific help. +You can complement your exploration by peeking at the sections of the much more detailed +[Developer Central](./Developer-Central). The [Tutorials](./Tutorials) section also contains a growing collection +of system- or implementation-specific help. ### Use a python syntax checker -Evennia works by importing your own modules and running them as part of the server. Whereas Evennia should just gracefully tell you what errors it finds, it can nevertheless be a good idea for you to check your code for simple syntax errors *before* you load it into the running server. There are many python syntax checkers out there. A fast and easy one is [pyflakes](https://pypi.python.org/pypi/pyflakes), a more verbose one is [pylint](http://www.pylint.org/). You can also check so that your code looks up to snuff using [pep8](https://pypi.python.org/pypi/pep8). Even with a syntax checker you will not be able to catch every possible problem - some bugs or problems will only appear when you actually run the code. But using such a checker can be a good start to weed out the simple problems. +Evennia works by importing your own modules and running them as part of the server. Whereas Evennia +should just gracefully tell you what errors it finds, it can nevertheless be a good idea for you to +check your code for simple syntax errors *before* you load it into the running server. There are +many python syntax checkers out there. A fast and easy one is +[pyflakes](https://pypi.python.org/pypi/pyflakes), a more verbose one is +[pylint](http://www.pylint.org/). You can also check so that your code looks up to snuff using +[pep8](https://pypi.python.org/pypi/pep8). Even with a syntax checker you will not be able to catch +every possible problem - some bugs or problems will only appear when you actually run the code. But +using such a checker can be a good start to weed out the simple problems. ### Plan before you code -Before you start coding away at your dream game, take a look at our [Game Planning](./Game-Planning) page. It might hopefully help you avoid some common pitfalls and time sinks. +Before you start coding away at your dream game, take a look at our [Game Planning](./Game-Planning) +page. It might hopefully help you avoid some common pitfalls and time sinks. ### Code in your game folder, not in the evennia/ repository -As part of the Evennia setup you will create a game folder to host your game code. This is your home. You should *never* need to modify anything in the `evennia` library (anything you download from us, really). You import useful functionality from here and if you see code you like, copy&paste it out into your game folder and edit it there. +As part of the Evennia setup you will create a game folder to host your game code. This is your +home. You should *never* need to modify anything in the `evennia` library (anything you download +from us, really). You import useful functionality from here and if you see code you like, copy&paste +it out into your game folder and edit it there. -If you find that Evennia doesn't support some functionality you need, make a [Feature Request](feature-request) about it. Same goes for [bugs][bug]. If you add features or fix bugs yourself, please consider [Contributing](./Contributing) your changes upstream! +If you find that Evennia doesn't support some functionality you need, make a +[Feature Request](github:issue) about it. Same goes for [bugs](github:issue). If you add features or fix bugs +yourself, please consider [Contributing](./Contributing) your changes upstream! ### Learn to read tracebacks -Python is very good at reporting when and where things go wrong. A *traceback* shows everything you need to know about crashing code. The text can be pretty long, but you usually are only interested in the last bit, where it says what the error is and at which module and line number it happened - armed with this info you can resolve most problems. +Python is very good at reporting when and where things go wrong. A *traceback* shows everything you +need to know about crashing code. The text can be pretty long, but you usually are only interested +in the last bit, where it says what the error is and at which module and line number it happened - +armed with this info you can resolve most problems. -Evennia will usually not show the full traceback in-game though. Instead the server outputs errors to the terminal/console from which you started Evennia in the first place. If you want more to show in-game you can add `IN_GAME_ERRORS = True` to your settings file. This will echo most (but not all) tracebacks both in-game as well as to the terminal/console. This is a potential security problem though, so don't keep this active when your game goes into production. +Evennia will usually not show the full traceback in-game though. Instead the server outputs errors +to the terminal/console from which you started Evennia in the first place. If you want more to show +in-game you can add `IN_GAME_ERRORS = True` to your settings file. This will echo most (but not all) +tracebacks both in-game as well as to the terminal/console. This is a potential security problem +though, so don't keep this active when your game goes into production. -> A common confusing error is finding that objects in-game are suddenly of the type `DefaultObject` rather than your custom typeclass. This happens when you introduce a critical Syntax error to the module holding your custom class. Since such a module is not valid Python, Evennia can't load it at all. Instead of crashing, Evennia will then print the full traceback to the terminal/console and temporarily fall back to the safe `DefaultObject` until you fix the problem and reload. +> A common confusing error is finding that objects in-game are suddenly of the type `DefaultObject` +rather than your custom typeclass. This happens when you introduce a critical Syntax error to the +module holding your custom class. Since such a module is not valid Python, Evennia can't load it at +all. Instead of crashing, Evennia will then print the full traceback to the terminal/console and +temporarily fall back to the safe `DefaultObject` until you fix the problem and reload. ### Docs are here to help you -Some people find reading documentation extremely dull and shun it out of principle. That's your call, but reading docs really *does* help you, promise! Evennia's documentation is pretty thorough and knowing what is possible can often give you a lot of new cool game ideas. That said, if you can't find the answer in the docs, don't be shy to ask questions! The [discussion group](https://sites.google.com/site/evenniaserver/discussions) and the [irc chat](http://webchat.freenode.net/?channels=evennia) are also there for you. +Some people find reading documentation extremely dull and shun it out of principle. That's your +call, but reading docs really *does* help you, promise! Evennia's documentation is pretty thorough +and knowing what is possible can often give you a lot of new cool game ideas. That said, if you +can't find the answer in the docs, don't be shy to ask questions! The +[discussion group](https://sites.google.com/site/evenniaserver/discussions) and the +[irc chat](http://webchat.freenode.net/?channels=evennia) are also there for you. ### The most important point -And finally, of course, have fun! - -[feature-request]: https://github.com/evennia/evennia/issues/new?title=Feature+Request%3a+%3Cdescriptive+title+here%3E&body=%23%23%23%23+Description+of+the+suggested+feature+and+how+it+is+supposed+to+work+for+the+admin%2fend+user%3a%0D%0A%0D%0A%0D%0A%23%23%23%23+A+list+of+arguments+for+why+you+think+this+new+feature+should+be+included+in+Evennia%3a%0D%0A%0D%0A1.%0D%0A2.%0D%0A%0D%0A%23%23%23%23+Extra+information%2c+such+as+requirements+or+ideas+on+implementation%3a%0D%0A%0D%0A -[bug]: https://github.com/evennia/evennia/issues/new?title=Bug%3a+%3Cdescriptive+title+here%3E&body=%23%23%23%23+Steps+to+reproduce+the+issue%3a%0D%0A%0D%0A1.+%0D%0A2.+%0D%0A3.+%0D%0A%0D%0A%23%23%23%23+What+I+expect+to+see+and+what+I+actually+see+%28tracebacks%2c+error+messages+etc%29%3a%0D%0A%0D%0A%0D%0A%0D%0A%23%23%23%23+Extra+information%2c+such+as+Evennia+revision%2frepo%2fbranch%2c+operating+system+and+ideas+for+how+to+solve%3a%0D%0A%0D%0A +And finally, of course, have fun! \ No newline at end of file diff --git a/docs/source/Coding-Utils.md b/docs/source/Coding-Utils.md index d32cb9783a..7ec359aecd 100644 --- a/docs/source/Coding-Utils.md +++ b/docs/source/Coding-Utils.md @@ -1,21 +1,28 @@ # Coding Utils -Evennia comes with many utilities to help with common coding tasks. Most are accessible directly from the flat API, otherwise you can find them in the `evennia/utils/` folder. +Evennia comes with many utilities to help with common coding tasks. Most are accessible directly +from the flat API, otherwise you can find them in the `evennia/utils/` folder. ## Searching -A common thing to do is to search for objects. There it's easiest to use the `search` method defined on all objects. This will search for objects in the same location and inside the self object: +A common thing to do is to search for objects. There it's easiest to use the `search` method defined +on all objects. This will search for objects in the same location and inside the self object: ```python obj = self.search(objname) ``` -The most common time one needs to do this is inside a command body. `obj = self.caller.search(objname)` will search inside the caller's (typically, the character that typed the command) `.contents` (their "inventory") and `.location` (their "room"). +The most common time one needs to do this is inside a command body. `obj = +self.caller.search(objname)` will search inside the caller's (typically, the character that typed +the command) `.contents` (their "inventory") and `.location` (their "room"). -Give the keyword `global_search=True` to extend search to encompass entire database. Aliases will also be matched by this search. You will find multiple examples of this functionality in the default command set. +Give the keyword `global_search=True` to extend search to encompass entire database. Aliases will +also be matched by this search. You will find multiple examples of this functionality in the default +command set. -If you need to search for objects in a code module you can use the functions in `evennia.utils.search`. You can access these as shortcuts `evennia.search_*`. +If you need to search for objects in a code module you can use the functions in +`evennia.utils.search`. You can access these as shortcuts `evennia.search_*`. ```python from evennia import search_object @@ -30,11 +37,13 @@ If you need to search for objects in a code module you can use the functions in - [evennia.search_message](../wiki/evennia.comms.managers#msgmanagersearch_message) - [evennia.search_help](../wiki/evennia.help.manager#helpentrymanagersearch_help) -Note that these latter methods will always return a `list` of results, even if the list has one or zero entries. +Note that these latter methods will always return a `list` of results, even if the list has one or +zero entries. ## Create -Apart from the in-game build commands (`@create` etc), you can also build all of Evennia's game entities directly in code (for example when defining new create commands). +Apart from the in-game build commands (`@create` etc), you can also build all of Evennia's game +entities directly in code (for example when defining new create commands). ```python import evennia @@ -48,11 +57,14 @@ Apart from the in-game build commands (`@create` etc), you can also build all of - [evennia.create_help_entry](../wiki/evennia.utils.create#create_help_entry) - [evennia.create_message](../wiki/evennia.utils.create#create_message) -Each of these create-functions have a host of arguments to further customize the created entity. See `evennia/utils/create.py` for more information. +Each of these create-functions have a host of arguments to further customize the created entity. See +`evennia/utils/create.py` for more information. ## Logging -Normally you can use Python `print` statements to see output to the terminal/log. The `print` statement should only be used for debugging though. For producion output, use the `logger` which will create proper logs either to terminal or to file. +Normally you can use Python `print` statements to see output to the terminal/log. The `print` +statement should only be used for debugging though. For producion output, use the `logger` which +will create proper logs either to terminal or to file. ```python from evennia import logger @@ -63,7 +75,9 @@ Normally you can use Python `print` statements to see output to the terminal/log logger.log_dep("This feature is deprecated") ``` -There is a special log-message type, `log_trace()` that is intended to be called from inside a traceback - this can be very useful for relaying the traceback message back to log without having it kill the server. +There is a special log-message type, `log_trace()` that is intended to be called from inside a +traceback - this can be very useful for relaying the traceback message back to log without having it +kill the server. ```python try: @@ -72,18 +86,25 @@ There is a special log-message type, `log_trace()` that is intended to be called logger.log_trace("This text will show beneath the traceback itself.") ``` -The `log_file` logger, finally, is a very useful logger for outputting arbitrary log messages. This is a heavily optimized asynchronous log mechanism using [threads](https://en.wikipedia.org/wiki/Thread_%28computing%29) to avoid overhead. You should be able to use it for very heavy custom logging without fearing disk-write delays. +The `log_file` logger, finally, is a very useful logger for outputting arbitrary log messages. This +is a heavily optimized asynchronous log mechanism using +[threads](https://en.wikipedia.org/wiki/Thread_%28computing%29) to avoid overhead. You should be +able to use it for very heavy custom logging without fearing disk-write delays. ```python logger.log_file(message, filename="mylog.log") ``` -If not an absolute path is given, the log file will appear in the `mygame/server/logs/` directory. If the file already exists, it will be appended to. Timestamps on the same format as the normal Evennia logs will be automatically added to each entry. If a filename is not specified, output will be written to a file `game/logs/game.log`. +If not an absolute path is given, the log file will appear in the `mygame/server/logs/` directory. +If the file already exists, it will be appended to. Timestamps on the same format as the normal +Evennia logs will be automatically added to each entry. If a filename is not specified, output will +be written to a file `game/logs/game.log`. ## Time Utilities ### Game time -Evennia tracks the current server time. You can access this time via the `evennia.gametime` shortcut: +Evennia tracks the current server time. You can access this time via the `evennia.gametime` +shortcut: ```python from evennia import gametime @@ -110,9 +131,13 @@ gametime.reset_gametime() ``` -The setting `TIME_FACTOR` determines how fast/slow in-game time runs compared to the real world. The setting `TIME_GAME_EPOCH` sets the starting game epoch (in seconds). The functions from the `gametime` module all return their times in seconds. You can convert this to whatever units of time you desire for your game. You can use the `@time` command to view the server time info. +The setting `TIME_FACTOR` determines how fast/slow in-game time runs compared to the real world. The +setting `TIME_GAME_EPOCH` sets the starting game epoch (in seconds). The functions from the +`gametime` module all return their times in seconds. You can convert this to whatever units of time +you desire for your game. You can use the `@time` command to view the server time info. -You can also *schedule* things to happen at specific in-game times using the [gametime.schedule](github:evennia.utils.gametime#schedule) function: +You can also *schedule* things to happen at specific in-game times using the +[gametime.schedule](github:evennia.utils.gametime#schedule) function: ```python import evennia @@ -126,7 +151,9 @@ gametime.schedule(church_clock, hour=2) ### utils.time_format() -This function takes a number of seconds as input (e.g. from the `gametime` module above) and converts it to a nice text output in days, hours etc. It's useful when you want to show how old something is. It converts to four different styles of output using the *style* keyword: +This function takes a number of seconds as input (e.g. from the `gametime` module above) and +converts it to a nice text output in days, hours etc. It's useful when you want to show how old +something is. It converts to four different styles of output using the *style* keyword: - style 0 - `5d:45m:12s` (standard colon output) - style 1 - `5d` (shows only the longest time unit) @@ -148,20 +175,38 @@ deferred = utils.delay(10, _callback, obj, "Echo!", persistent=False) ``` -This creates an asynchronous delayed call. It will fire the given callback function after the given number of seconds. This is a very light wrapper over a Twisted [Deferred](https://twistedmatrix.com/documents/current/core/howto/defer.html). Normally this is run non-persistently, which means that if the server is `@reload`ed before the delay is over, the callback will never run (the server forgets it). If setting `persistent` to True, the delay will be stored in the database and survive a `@reload` - but for this to work it is susceptible to the same limitations incurred when saving to an [Attribute](./Attributes). +This creates an asynchronous delayed call. It will fire the given callback function after the given +number of seconds. This is a very light wrapper over a Twisted +[Deferred](https://twistedmatrix.com/documents/current/core/howto/defer.html). Normally this is run +non-persistently, which means that if the server is `@reload`ed before the delay is over, the +callback will never run (the server forgets it). If setting `persistent` to True, the delay will be +stored in the database and survive a `@reload` - but for this to work it is susceptible to the same +limitations incurred when saving to an [Attribute](./Attributes). -The `deferred` return object can usually be ignored, but calling its `.cancel()` method will abort the delay prematurely. +The `deferred` return object can usually be ignored, but calling its `.cancel()` method will abort +the delay prematurely. -`utils.delay` is the lightest form of delayed call in Evennia. For other way to create time-bound tasks, see the [TickerHandler](./TickerHandler) and [Scripts](./Scripts). +`utils.delay` is the lightest form of delayed call in Evennia. For other way to create time-bound +tasks, see the [TickerHandler](./TickerHandler) and [Scripts](./Scripts). -> Note that many delayed effects can be achieved without any need for an active timer. For example if you have a trait that should recover a point every 5 seconds you might just need its value when it's needed, but checking the current time and calculating on the fly what value it should have. +> Note that many delayed effects can be achieved without any need for an active timer. For example +if you have a trait that should recover a point every 5 seconds you might just need its value when +it's needed, but checking the current time and calculating on the fly what value it should have. ## Object Classes ### utils.inherits_from() -This useful function takes two arguments - an object to check and a parent. It returns `True` if object inherits from parent *at any distance* (as opposed to Python's in-built `is_instance()` that will only catch immediate dependence). This function also accepts as input any combination of classes, instances or python-paths-to-classes. +This useful function takes two arguments - an object to check and a parent. It returns `True` if +object inherits from parent *at any distance* (as opposed to Python's in-built `is_instance()` that +will only catch immediate dependence). This function also accepts as input any combination of +classes, instances or python-paths-to-classes. -Note that Python code should usually work with [duck typing](http://en.wikipedia.org/wiki/Duck_typing). But in Evennia's case it can sometimes be useful to check if an object inherits from a given [Typeclass](./Typeclasses) as a way of identification. Say for example that we have a typeclass *Animal*. This has a subclass *Felines* which in turn has a subclass *HouseCat*. Maybe there are a bunch of other animal types too, like horses and dogs. Using `inherits_from` will allow you to check for all animals in one go: +Note that Python code should usually work with [duck +typing](http://en.wikipedia.org/wiki/Duck_typing). But in Evennia's case it can sometimes be useful +to check if an object inherits from a given [Typeclass](./Typeclasses) as a way of identification. Say +for example that we have a typeclass *Animal*. This has a subclass *Felines* which in turn has a +subclass *HouseCat*. Maybe there are a bunch of other animal types too, like horses and dogs. Using +`inherits_from` will allow you to check for all animals in one go: ```python from evennia import utils @@ -173,11 +218,14 @@ Note that Python code should usually work with [duck typing](http://en.wikipedia ## Text utilities -In a text game, you are naturally doing a lot of work shuffling text back and forth. Here is a *non-complete* selection of text utilities found in `evennia/utils/utils.py` (shortcut `evennia.utils`). If nothing else it can be good to look here before starting to develop a solution of your own. +In a text game, you are naturally doing a lot of work shuffling text back and forth. Here is a *non- +complete* selection of text utilities found in `evennia/utils/utils.py` (shortcut `evennia.utils`). +If nothing else it can be good to look here before starting to develop a solution of your own. ### utils.fill() -This flood-fills a text to a given width (shuffles the words to make each line evenly wide). It also indents as needed. +This flood-fills a text to a given width (shuffles the words to make each line evenly wide). It also +indents as needed. ```python outtxt = fill(intxt, width=78, indent=4) @@ -185,7 +233,8 @@ This flood-fills a text to a given width (shuffles the words to make each line e ### utils.crop() -This function will crop a very long line, adding a suffix to show the line actually continues. This can be useful in listings when showing multiple lines would mess up things. +This function will crop a very long line, adding a suffix to show the line actually continues. This +can be useful in listings when showing multiple lines would mess up things. ```python intxt = "This is a long text that we want to crop." @@ -195,7 +244,11 @@ This function will crop a very long line, adding a suffix to show the line actua ### utils.dedent() -This solves what may at first glance appear to be a trivial problem with text - removing indentations. It is used to shift entire paragraphs to the left, without disturbing any further formatting they may have. A common case for this is when using Python triple-quoted strings in code - they will retain whichever indentation they have in the code, and to make easily-readable source code one usually don't want to shift the string to the left edge. +This solves what may at first glance appear to be a trivial problem with text - removing +indentations. It is used to shift entire paragraphs to the left, without disturbing any further +formatting they may have. A common case for this is when using Python triple-quoted strings in code +- they will retain whichever indentation they have in the code, and to make easily-readable source +code one usually don't want to shift the string to the left edge. ```python #python code is entered at a given indentation @@ -209,7 +262,8 @@ This solves what may at first glance appear to be a trivial problem with text - # but be shifted all the way to the left. ``` -Normally you do the dedent in the display code (this is for example how the help system homogenizes help entries). +Normally you do the dedent in the display code (this is for example how the help system homogenizes +help entries). ### to_str() and to_bytes() @@ -228,9 +282,16 @@ never raise a traceback but instead echo errors through logging. See ## Display utilities ### Making ascii tables -The [EvTable](github:evennia.utils.evtable#evtable) class (`evennia/utils/evtable.py`) can be used to create correctly formatted text tables. There is also [EvForm](github:evennia.utils.evform#evform) (`evennia/utils/evform.py`). This reads a fixed-format text template from a file in order to create any level of sophisticated ascii layout. Both evtable and evform have lots of options and inputs so see the header of each module for help. +The [EvTable](github:evennia.utils.evtable#evtable) class (`evennia/utils/evtable.py`) can be used +to create correctly formatted text tables. There is also +[EvForm](github:evennia.utils.evform#evform) (`evennia/utils/evform.py`). This reads a fixed-format +text template from a file in order to create any level of sophisticated ascii layout. Both evtable +and evform have lots of options and inputs so see the header of each module for help. -The third-party [PrettyTable](https://code.google.com/p/prettytable/) module is also included in Evennia. PrettyTable is considered deprecated in favor of EvTable since PrettyTable cannot handle ANSI colour. PrettyTable can be found in `evennia/utils/prettytable/`. See its homepage above for instructions. +The third-party [PrettyTable](https://code.google.com/p/prettytable/) module is also included in +Evennia. PrettyTable is considered deprecated in favor of EvTable since PrettyTable cannot handle +ANSI colour. PrettyTable can be found in `evennia/utils/prettytable/`. See its homepage above for +instructions. ### Menus - [evennia.EvMenu](github:evennia.utils.evmenu#evmenu) diff --git a/docs/source/Command-Cooldown.md b/docs/source/Command-Cooldown.md index 35cb34ef82..cd134c5eb1 100644 --- a/docs/source/Command-Cooldown.md +++ b/docs/source/Command-Cooldown.md @@ -5,12 +5,12 @@ Some types of games want to limit how often a command can be run. If a character casts the spell *Firestorm*, you might not want them to spam that command over and over. Or in an advanced combat system, a massive swing may offer a chance of lots of damage at the cost of not being able to re-do it for -a while. Such effects are called *cooldowns*. +a while. Such effects are called *cooldowns*. This page exemplifies a very resource-efficient way to do cooldowns. A more 'active' way is to use asynchronous delays as in the [command duration tutorial](Command-Duration#Blocking-Commands), the two might be useful to -combine if you want to echo some message to the user after the cooldown ends. +combine if you want to echo some message to the user after the cooldown ends. ## Non-persistent cooldown @@ -19,21 +19,21 @@ Commands are class instances, and those are cached in memory, a command instance will remember things you store on it. So just store the current time of execution! Next time the command is run, it just needs to check if it has that time stored, and compare it with the current time to see if a desired -delay has passed. +delay has passed. ```python -import time +import time from evennia import default_cmds class CmdSpellFirestorm(default_cmds.MuxCommand): """ Spell - Firestorm - Usage: + Usage: cast firestorm - This will unleash a storm of flame. You can only release one - firestorm every five minutes (assuming you have the mana). + This will unleash a storm of flame. You can only release one + firestorm every five minutes (assuming you have the mana). """ key = "cast firestorm" locks = "cmd:isFireMage()" @@ -42,17 +42,17 @@ class CmdSpellFirestorm(default_cmds.MuxCommand): "Implement the spell" # check cooldown (5 minute cooldown) - now = time.time() + now = time.time() if hasattr(self, "lastcast") and \ now - self.lastcast < 5 * 60: message = "You cannot cast this spell again yet." self.caller.msg(message) - return + return #[the spell effect is implemented] # if the spell was successfully cast, store the casting time - self.lastcast = now + self.lastcast = now ``` We just check the `lastcast` flag, and update it if everything works out. @@ -60,7 +60,7 @@ Simple and very effective since everything is just stored in memory. The drawback of this simple scheme is that it's non-persistent. If you do `@reload`, the cache is cleaned and all such ongoing cooldowns will be forgotten. It is also limited only to this one command, other commands cannot -(easily) check for this value. +(easily) check for this value. ## Persistent cooldown @@ -75,12 +75,12 @@ database, you need to use the caster for the storage. # check cooldown (5 minute cooldown) now = time.time() - lastcast = self.caller.db.firestorm_lastcast + lastcast = self.caller.db.firestorm_lastcast if lastcast and now - lastcast < 5 * 60: message = "You need to wait before casting this spell again." self.caller.msg(message) - return + return #[the spell effect is implemented] @@ -95,4 +95,4 @@ using cooldowns also has the advantage of working *between* commands - you can for example let all fire-related spells check the same cooldown to make sure the casting of *Firestorm* blocks all fire-related spells for a while. Or, in the case of taking that big swing with the sword, this could now block all -other types of attacks for a while before the warrior can recover. +other types of attacks for a while before the warrior can recover. diff --git a/docs/source/Command-Duration.md b/docs/source/Command-Duration.md index 1047ef5c39..903fad30d1 100644 --- a/docs/source/Command-Duration.md +++ b/docs/source/Command-Duration.md @@ -9,7 +9,7 @@ In some types of games a command should not start and finish immediately. Loading a crossbow might take a bit of time to do - time you don't have when the enemy comes rushing at you. Crafting that armour will not be immediate either. For some types of games the very act of moving or changing pose all -comes with a certain time associated with it. +comes with a certain time associated with it. ## The simple way to pause commands with yield @@ -58,7 +58,8 @@ This syntax will not "freeze" all commands. While the command is "pausing", ## The more advanced way with utils.delay -The `yield` syntax is easy to read, easy to understand, easy to use. But it's not that flexible if you want more advanced options. Learning to use alternatives might be much worth it in the end. +The `yield` syntax is easy to read, easy to understand, easy to use. But it's not that flexible if +you want more advanced options. Learning to use alternatives might be much worth it in the end. Below is a simple command example for adding a duration for a command to finish. @@ -69,7 +70,7 @@ class CmdEcho(default_cmds.MuxCommand): """ wait for an echo - Usage: + Usage: echo Calls and waits for an echo @@ -79,7 +80,7 @@ class CmdEcho(default_cmds.MuxCommand): def func(self): """ - This is called at the initial shout. + This is called at the initial shout. """ self.caller.msg("You shout '%s' and wait for an echo ..." % self.args) # this waits non-blocking for 10 seconds, then calls self.echo @@ -93,20 +94,40 @@ class CmdEcho(default_cmds.MuxCommand): self.caller.msg(string) ``` -Import this new echo command into the default command set and reload the server. You will find that it will take 10 seconds before you see your shout coming back. You will also find that this is a *non-blocking* effect; you can issue other commands in the interim and the game will go on as usual. The echo will come back to you in its own time. +Import this new echo command into the default command set and reload the server. You will find that +it will take 10 seconds before you see your shout coming back. You will also find that this is a +*non-blocking* effect; you can issue other commands in the interim and the game will go on as usual. +The echo will come back to you in its own time. ### About utils.delay() -`utils.delay(timedelay, callback, persistent=False, *args, **kwargs)` is a useful function. It will wait `timedelay` seconds, then call the `callback` function, optionally passing to it the arguments provided to utils.delay by way of *args and/or **kwargs`. +`utils.delay(timedelay, callback, persistent=False, *args, **kwargs)` is a useful function. It will +wait `timedelay` seconds, then call the `callback` function, optionally passing to it the arguments +provided to utils.delay by way of *args and/or **kwargs`. -> Note: The callback argument should be provided with a python path to the desired function, for instance `my_object.my_function` instead of `my_object.my_function()`. Otherwise my_function would get called and run immediately upon attempting to pass it to the delay function. -If you want to provide arguments for utils.delay to use, when calling your callback function, you have to do it separatly, for instance using the utils.delay *args and/or **kwargs, as mentioned above. +> Note: The callback argument should be provided with a python path to the desired function, for +instance `my_object.my_function` instead of `my_object.my_function()`. Otherwise my_function would +get called and run immediately upon attempting to pass it to the delay function. +If you want to provide arguments for utils.delay to use, when calling your callback function, you +have to do it separatly, for instance using the utils.delay *args and/or **kwargs, as mentioned +above. -> If you are not familiar with the syntax `*args` and `**kwargs`, [see the Python documentation here](https://docs.python.org/2/tutorial/controlflow.html#arbitrary-argument-lists). +> If you are not familiar with the syntax `*args` and `**kwargs`, [see the Python documentation +here](https://docs.python.org/2/tutorial/controlflow.html#arbitrary-argument-lists). -Looking at it you might think that `utils.delay(10, callback)` in the code above is just an alternative to some more familiar thing like `time.sleep(10)`. This is *not* the case. If you do `time.sleep(10)` you will in fact freeze the *entire server* for ten seconds! The `utils.delay()`is a thin wrapper around a Twisted [Deferred](http://twistedmatrix.com/documents/11.0.0/core/howto/defer.html) that will delay execution until 10 seconds have passed, but will do so asynchronously, without bothering anyone else (not even you - you can continue to do stuff normally while it waits to continue). +Looking at it you might think that `utils.delay(10, callback)` in the code above is just an +alternative to some more familiar thing like `time.sleep(10)`. This is *not* the case. If you do +`time.sleep(10)` you will in fact freeze the *entire server* for ten seconds! The `utils.delay()`is +a thin wrapper around a Twisted +[Deferred](http://twistedmatrix.com/documents/11.0.0/core/howto/defer.html) that will delay +execution until 10 seconds have passed, but will do so asynchronously, without bothering anyone else +(not even you - you can continue to do stuff normally while it waits to continue). -The point to remember here is that the `delay()` call will not "pause" at that point when it is called (the way `yield` does in the previous section). The lines after the `delay()` call will actually execute *right away*. What you must do is to tell it which function to call *after the time has passed* (its "callback"). This may sound strange at first, but it is normal practice in asynchronous systems. You can also link such calls together as seen below: +The point to remember here is that the `delay()` call will not "pause" at that point when it is +called (the way `yield` does in the previous section). The lines after the `delay()` call will +actually execute *right away*. What you must do is to tell it which function to call *after the time +has passed* (its "callback"). This may sound strange at first, but it is normal practice in +asynchronous systems. You can also link such calls together as seen below: ```python from evennia import default_cmds, utils @@ -115,7 +136,7 @@ class CmdEcho(default_cmds.MuxCommand): """ waits for an echo - Usage: + Usage: echo Calls and waits for an echo @@ -148,7 +169,8 @@ class CmdEcho(default_cmds.MuxCommand): self.caller.msg("... %s ..." % self.args.lower()) ``` -The above version will have the echoes arrive one after another, each separated by a two second delay. +The above version will have the echoes arrive one after another, each separated by a two second +delay. > echo Hello! ... HELLO! @@ -157,9 +179,19 @@ The above version will have the echoes arrive one after another, each separated ## Blocking commands -As mentioned, a great thing about the delay introduced by `yield` or `utils.delay()` is that it does not block. It just goes on in the background and you are free to play normally in the interim. In some cases this is not what you want however. Some commands should simply "block" other commands while they are running. If you are in the process of crafting a helmet you shouldn't be able to also start crafting a shield at the same time, or if you just did a huge power-swing with your weapon you should not be able to do it again immediately. +As mentioned, a great thing about the delay introduced by `yield` or `utils.delay()` is that it does +not block. It just goes on in the background and you are free to play normally in the interim. In +some cases this is not what you want however. Some commands should simply "block" other commands +while they are running. If you are in the process of crafting a helmet you shouldn't be able to also +start crafting a shield at the same time, or if you just did a huge power-swing with your weapon you +should not be able to do it again immediately. -The simplest way of implementing blocking is to use the technique covered in the [Command Cooldown](./Command-Cooldown) tutorial. In that tutorial we implemented cooldowns by having the Command store the current time. Next time the Command was called, we compared the current time to the stored time to determine if enough time had passed for a renewed use. This is a *very* efficient, reliable and passive solution. The drawback is that there is nothing to tell the Player when enough time has passed unless they keep trying. +The simplest way of implementing blocking is to use the technique covered in the [Command +Cooldown](Command-Cooldown) tutorial. In that tutorial we implemented cooldowns by having the +Command store the current time. Next time the Command was called, we compared the current time to +the stored time to determine if enough time had passed for a renewed use. This is a *very* +efficient, reliable and passive solution. The drawback is that there is nothing to tell the Player +when enough time has passed unless they keep trying. Here is an example where we will use `utils.delay` to tell the player when the cooldown has passed: @@ -174,44 +206,51 @@ class CmdBigSwing(default_cmds.MuxCommand): swing Makes a mighty swing. Doing so will make you vulnerable - to counter-attacks before you can recover. + to counter-attacks before you can recover. """ key = "bigswing" locks = "cmd:all()" def func(self): - "Makes the swing" + "Makes the swing" if self.caller.ndb.off_balance: # we are still off-balance. self.caller.msg("You are off balance and need time to recover!") - return + return # [attack/hit code goes here ...] - self.caller.msg("You swing big! You are off balance now.") + self.caller.msg("You swing big! You are off balance now.") # set the off-balance flag self.caller.ndb.off_balance = True - # wait 8 seconds before we can recover. During this time - # we won't be able to swing again due to the check at the top. + # wait 8 seconds before we can recover. During this time + # we won't be able to swing again due to the check at the top. utils.delay(8, self.recover) def recover(self): "This will be called after 8 secs" - del self.caller.ndb.off_balance + del self.caller.ndb.off_balance self.caller.msg("You regain your balance.") -``` +``` -Note how, after the cooldown, the user will get a message telling them they are now ready for another swing. +Note how, after the cooldown, the user will get a message telling them they are now ready for +another swing. -By storing the `off_balance` flag on the character (rather than on, say, the Command instance itself) it can be accessed by other Commands too. Other attacks may also not work when you are off balance. You could also have an enemy Command check your `off_balance` status to gain bonuses, to take another example. +By storing the `off_balance` flag on the character (rather than on, say, the Command instance +itself) it can be accessed by other Commands too. Other attacks may also not work when you are off +balance. You could also have an enemy Command check your `off_balance` status to gain bonuses, to +take another example. ## Abortable commands -One can imagine that you will want to abort a long-running command before it has a time to finish. If you are in the middle of crafting your armor you will probably want to stop doing that when a monster enters your smithy. +One can imagine that you will want to abort a long-running command before it has a time to finish. +If you are in the middle of crafting your armor you will probably want to stop doing that when a +monster enters your smithy. -You can implement this in the same way as you do the "blocking" command above, just in reverse. Below is an example of a crafting command that can be aborted by starting a fight: +You can implement this in the same way as you do the "blocking" command above, just in reverse. +Below is an example of a crafting command that can be aborted by starting a fight: ```python from evennia import utils, default_cmds @@ -225,8 +264,8 @@ class CmdCraftArmour(default_cmds.MuxCommand): This will craft a suit of armour, assuming you have all the components and tools. Doing some - other action (such as attacking someone) will - abort the crafting process. + other action (such as attacking someone) will + abort the crafting process. """ key = "craft" locks = "cmd:all()" @@ -236,13 +275,13 @@ class CmdCraftArmour(default_cmds.MuxCommand): if self.caller.ndb.is_crafting: self.caller.msg("You are already crafting!") - return + return if self._is_fighting(): self.caller.msg("You can't start to craft " "in the middle of a fight!") return - # [Crafting code, checking of components, skills etc] + # [Crafting code, checking of components, skills etc] # Start crafting self.caller.ndb.is_crafting = True @@ -251,28 +290,28 @@ class CmdCraftArmour(default_cmds.MuxCommand): def _is_fighting(self): "checks if we are in a fight." - if self.caller.ndb.is_fighting: - del self.caller.ndb.is_crafting + if self.caller.ndb.is_fighting: + del self.caller.ndb.is_crafting return True def step1(self): "first step of armour construction" - if self._is_fighting(): + if self._is_fighting(): return self.msg("You create the first part of the armour.") utils.delay(60, callback=self.step2) def step2(self): "second step of armour construction" - if self._is_fighting(): + if self._is_fighting(): return - self.msg("You create the second part of the armour.") + self.msg("You create the second part of the armour.") utils.delay(60, step3) def step3(self): "last step of armour construction" if self._is_fighting(): - return + return # [code for creating the armour object etc] @@ -290,7 +329,7 @@ class CmdAttack(default_cmds.MuxCommand): attack Try to cause harm to someone. This will abort - eventual crafting you may be currently doing. + eventual crafting you may be currently doing. """ key = "attack" aliases = ["hit", "stab"] @@ -304,17 +343,24 @@ class CmdAttack(default_cmds.MuxCommand): # [...] ``` -The above code creates a delayed crafting command that will gradually create the armour. If the `attack` command is issued during this process it will set a flag that causes the crafting to be quietly canceled next time it tries to update. +The above code creates a delayed crafting command that will gradually create the armour. If the +`attack` command is issued during this process it will set a flag that causes the crafting to be +quietly canceled next time it tries to update. ## Persistent delays -In the latter examples above we used `.ndb` storage. This is fast and easy but it will reset all cooldowns/blocks/crafting etc if you reload the server. If you don't want that you can replace `.ndb` with `.db`. But even this won't help because the `yield` keyword is not persisent and nor is the use of `delay` shown above. To resolve this you can use `delay` with the `persistent=True` keyword. But wait! Making something persistent will add some extra complications, because now you must make sure Evennia can properly store things to the database. +In the latter examples above we used `.ndb` storage. This is fast and easy but it will reset all +cooldowns/blocks/crafting etc if you reload the server. If you don't want that you can replace +`.ndb` with `.db`. But even this won't help because the `yield` keyword is not persisent and nor is +the use of `delay` shown above. To resolve this you can use `delay` with the `persistent=True` +keyword. But wait! Making something persistent will add some extra complications, because now you +must make sure Evennia can properly store things to the database. -Here is the original echo-command reworked to function with persistence: +Here is the original echo-command reworked to function with persistence: ```python from evennia import default_cmds, utils -# this is now in the outermost scope and takes two args! +# this is now in the outermost scope and takes two args! def echo(caller, args): "Called after 10 seconds." shout = args @@ -326,7 +372,7 @@ class CmdEcho(default_cmds.MuxCommand): """ wait for an echo - Usage: + Usage: echo Calls and waits for an echo @@ -336,16 +382,22 @@ class CmdEcho(default_cmds.MuxCommand): def func(self): """ - This is called at the initial shout. + This is called at the initial shout. """ self.caller.msg("You shout '%s' and wait for an echo ..." % self.args) # this waits non-blocking for 10 seconds, then calls echo(self.caller, self.args) - utils.delay(10, echo, self.caller, self.args, persistent=True) # changes! + utils.delay(10, echo, self.caller, self.args, persistent=True) # changes! ``` -Above you notice two changes: -- The callback (`echo`) was moved out of the class and became its own stand-alone function in the outermost scope of the module. It also now takes `caller` and `args` as arguments (it doesn't have access to them directly since this is now a stand-alone function). -- `utils.delay` specifies the `echo` function (not `self.echo` - it's no longer a method!) and sends `self.caller` and `self.args` as arguments for it to use. We also set `persistent=True`. +Above you notice two changes: +- The callback (`echo`) was moved out of the class and became its own stand-alone function in the +outermost scope of the module. It also now takes `caller` and `args` as arguments (it doesn't have +access to them directly since this is now a stand-alone function). +- `utils.delay` specifies the `echo` function (not `self.echo` - it's no longer a method!) and sends +`self.caller` and `self.args` as arguments for it to use. We also set `persistent=True`. -The reason for this change is because Evennia needs to `pickle` the callback into storage and it cannot do this correctly when the method sits on the command class. Now this behave the same as the first version except if you reload (or even shut down) the server mid-delay it will still fire the callback when the server comes back up (it will resume the countdown and ignore the downtime). +The reason for this change is because Evennia needs to `pickle` the callback into storage and it +cannot do this correctly when the method sits on the command class. Now this behave the same as the +first version except if you reload (or even shut down) the server mid-delay it will still fire the +callback when the server comes back up (it will resume the countdown and ignore the downtime). diff --git a/docs/source/Command-Prompt.md b/docs/source/Command-Prompt.md index 70d662c1ae..47db5d62f4 100644 --- a/docs/source/Command-Prompt.md +++ b/docs/source/Command-Prompt.md @@ -1,11 +1,16 @@ # Command Prompt -A *prompt* is quite common in MUDs. The prompt display useful details about your character that you are likely to want to keep tabs on at all times, such as health, magical power etc. It might also show things like in-game time, weather and so on. Many modern MUD clients (including Evennia's own webclient) allows for identifying the prompt and have it appear in a correct location (usually just above the input line). Usually it will remain like that until it is explicitly updated. +A *prompt* is quite common in MUDs. The prompt display useful details about your character that you +are likely to want to keep tabs on at all times, such as health, magical power etc. It might also +show things like in-game time, weather and so on. Many modern MUD clients (including Evennia's own +webclient) allows for identifying the prompt and have it appear in a correct location (usually just +above the input line). Usually it will remain like that until it is explicitly updated. ## Sending a prompt -A prompt is sent using the `prompt` keyword to the `msg()` method on objects. The prompt will be sent without any line breaks. +A prompt is sent using the `prompt` keyword to the `msg()` method on objects. The prompt will be +sent without any line breaks. ```python self.msg(prompt="HP: 5, MP: 2, SP: 8") @@ -16,9 +21,11 @@ You can combine the sending of normal text with the sending (updating of the pro self.msg("This is a text", prompt="This is a prompt") ``` -You can update the prompt on demand, this is normally done using [OOB](./OOB)-tracking of the relevant Attributes (like the character's health). You could also make sure that attacking commands update the prompt when they cause a change in health, for example. +You can update the prompt on demand, this is normally done using [OOB](./OOB)-tracking of the relevant +Attributes (like the character's health). You could also make sure that attacking commands update +the prompt when they cause a change in health, for example. -Here is a simple example of the prompt sent/updated from a command class: +Here is a simple example of the prompt sent/updated from a command class: ```python from evennia import Command @@ -27,12 +34,12 @@ Here is a simple example of the prompt sent/updated from a command class: """ see how hurt your are - Usage: + Usage: diagnose [target] This will give an estimate of the target's health. Also - the target's prompt will be updated. - """ + the target's prompt will be updated. + """ key = "diagnose" def func(self): @@ -48,9 +55,9 @@ Here is a simple example of the prompt sent/updated from a command class: sp = target.db.sp if None in (hp, mp, sp): - # Attributes not defined + # Attributes not defined self.caller.msg("Not a valid target!") - return + return text = "You diagnose %s as having " \ "%i health, %i mana and %i stamina." \ @@ -60,9 +67,16 @@ Here is a simple example of the prompt sent/updated from a command class: ``` ## A prompt sent with every command -The prompt sent as described above uses a standard telnet instruction (the Evennia web client gets a special flag). Most MUD telnet clients will understand and allow users to catch this and keep the prompt in place until it updates. So *in principle* you'd not need to update the prompt every command. +The prompt sent as described above uses a standard telnet instruction (the Evennia web client gets a +special flag). Most MUD telnet clients will understand and allow users to catch this and keep the +prompt in place until it updates. So *in principle* you'd not need to update the prompt every +command. -However, with a varying user base it can be unclear which clients are used and which skill level the users have. So sending a prompt with every command is a safe catch-all. You don't need to manually go in and edit every command you have though. Instead you edit the base command class for your custom commands (like `MuxCommand` in your `mygame/commands/command.py` folder) and overload the `at_post_cmd()` hook. This hook is always called *after* the main `func()` method of the Command. +However, with a varying user base it can be unclear which clients are used and which skill level the +users have. So sending a prompt with every command is a safe catch-all. You don't need to manually +go in and edit every command you have though. Instead you edit the base command class for your +custom commands (like `MuxCommand` in your `mygame/commands/command.py` folder) and overload the +`at_post_cmd()` hook. This hook is always called *after* the main `func()` method of the Command. ```python from evennia import default_cmds @@ -71,9 +85,9 @@ class MuxCommand(default_cmds.MuxCommand): # ... def at_post_cmd(self): "called after self.func()." - caller = self.caller - prompt = "%i HP, %i MP, %i SP" % (caller.db.hp, - caller.db.mp, + caller = self.caller + prompt = "%i HP, %i MP, %i SP" % (caller.db.hp, + caller.db.mp, caller.db.sp) caller.msg(prompt=prompt) @@ -81,7 +95,8 @@ class MuxCommand(default_cmds.MuxCommand): ### Modifying default commands -If you want to add something small like this to Evennia's default commands without modifying them directly the easiest way is to just wrap those with a multiple inheritance to your own base class: +If you want to add something small like this to Evennia's default commands without modifying them +directly the easiest way is to just wrap those with a multiple inheritance to your own base class: ```python # in (for example) mygame/commands/mycommands.py @@ -95,7 +110,8 @@ class CmdLook(default_cmds.CmdLook, MuxCommand): pass ``` -The result of this is that the hooks from your custom `MuxCommand` will be mixed into the default `CmdLook` through multiple inheritance. Next you just add this to your default command set: +The result of this is that the hooks from your custom `MuxCommand` will be mixed into the default +`CmdLook` through multiple inheritance. Next you just add this to your default command set: ```python # in mygame/commands/default_cmdsets.py @@ -110,4 +126,4 @@ class CharacterCmdSet(default_cmds.CharacterCmdSet): self.add(mycommands.CmdLook()) ``` -This will automatically replace the default `look` command in your game with your own version. \ No newline at end of file +This will automatically replace the default `look` command in your game with your own version. \ No newline at end of file diff --git a/docs/source/Command-Sets.md b/docs/source/Command-Sets.md index 8ce6cf462d..be5c452119 100644 --- a/docs/source/Command-Sets.md +++ b/docs/source/Command-Sets.md @@ -1,60 +1,84 @@ # Command Sets -Command Sets are intimately linked with [Commands](./Commands) and you should be familiar with Commands before reading this page. The two pages were split for ease of reading. +Command Sets are intimately linked with [Commands](./Commands) and you should be familiar with +Commands before reading this page. The two pages were split for ease of reading. -A *Command Set* (often referred to as a CmdSet or cmdset) is the basic unit for storing one or more *Commands*. A given Command can go into any number of different command sets. Storing Command classes in a command set is the way to make commands available to use in your game. +A *Command Set* (often referred to as a CmdSet or cmdset) is the basic unit for storing one or more +*Commands*. A given Command can go into any number of different command sets. Storing Command +classes in a command set is the way to make commands available to use in your game. -When storing a CmdSet on an object, you will make the commands in that command set available to the object. An example is the default command set stored on new Characters. This command set contains all the useful commands, from `look` and `inventory` to `@dig` and `@reload` ([permissions](./Locks#Permissions) then limit which players may use them, but that's a separate topic). +When storing a CmdSet on an object, you will make the commands in that command set available to the +object. An example is the default command set stored on new Characters. This command set contains +all the useful commands, from `look` and `inventory` to `@dig` and `@reload` +([permissions](./Locks#Permissions) then limit which players may use them, but that's a separate +topic). -When an account enters a command, cmdsets from the Account, Character, its location, and elsewhere are pulled together into a *merge stack*. This stack is merged together in a specific order to create a single "merged" cmdset, representing the pool of commands available at that very moment. +When an account enters a command, cmdsets from the Account, Character, its location, and elsewhere +are pulled together into a *merge stack*. This stack is merged together in a specific order to +create a single "merged" cmdset, representing the pool of commands available at that very moment. -An example would be a `Window` object that has a cmdset with two commands in it: `look through window` and `open window`. The command set would be visible to players in the room with the window, allowing them to use those commands only there. You could imagine all sorts of clever uses of this, like a `Television` object which had multiple commands for looking at it, switching channels and so on. The tutorial world included with Evennia showcases a dark room that replaces certain critical commands with its own versions because the Character cannot see. +An example would be a `Window` object that has a cmdset with two commands in it: `look through +window` and `open window`. The command set would be visible to players in the room with the window, +allowing them to use those commands only there. You could imagine all sorts of clever uses of this, +like a `Television` object which had multiple commands for looking at it, switching channels and so +on. The tutorial world included with Evennia showcases a dark room that replaces certain critical +commands with its own versions because the Character cannot see. -If you want a quick start into defining your first commands and using them with command sets, you can head over to the [Adding Command Tutorial](./Adding-Command-Tutorial) which steps through things without the explanations. +If you want a quick start into defining your first commands and using them with command sets, you +can head over to the [Adding Command Tutorial](./Adding-Command-Tutorial) which steps through things +without the explanations. ## Defining Command Sets -A CmdSet is, as most things in Evennia, defined as a Python class inheriting from the correct parent (`evennia.CmdSet`, which is a shortcut to `evennia.commands.cmdset.CmdSet`). The CmdSet class only needs to define one method, called `at_cmdset_creation()`. All other class parameters are optional, but are used for more advanced set manipulation and coding (see the [merge rules](./Command-Sets#merge-rules) section). +A CmdSet is, as most things in Evennia, defined as a Python class inheriting from the correct parent +(`evennia.CmdSet`, which is a shortcut to `evennia.commands.cmdset.CmdSet`). The CmdSet class only +needs to define one method, called `at_cmdset_creation()`. All other class parameters are optional, +but are used for more advanced set manipulation and coding (see the [merge rules](Command- +Sets#merge-rules) section). ```python # file mygame/commands/mycmdset.py from evennia import CmdSet -# this is a theoretical custom module with commands we +# this is a theoretical custom module with commands we # created previously: mygame/commands/mycommands.py from commands import mycommands -class MyCmdSet(CmdSet): +class MyCmdSet(CmdSet): def at_cmdset_creation(self): """ The only thing this method should need to do is to add commands to the set. - """ + """ self.add(mycommands.MyCommand1()) self.add(mycommands.MyCommand2()) self.add(mycommands.MyCommand3()) ``` -The CmdSet's `add()` method can also take another CmdSet as input. In this case all the commands from that CmdSet will be appended to this one as if you added them line by line: +The CmdSet's `add()` method can also take another CmdSet as input. In this case all the commands +from that CmdSet will be appended to this one as if you added them line by line: ```python - def at_cmdset_creation(): + def at_cmdset_creation(): ... self.add(AdditionalCmdSet) # adds all command from this set ... ``` -If you added your command to an existing cmdset (like to the default cmdset), that set is already loaded into memory. You need to make the server aware of the code changes: +If you added your command to an existing cmdset (like to the default cmdset), that set is already +loaded into memory. You need to make the server aware of the code changes: ``` -@reload +@reload ``` -You should now be able to use the command. +You should now be able to use the command. -If you created a new, fresh cmdset, this must be added to an object in order to make the commands within available. A simple way to temporarily test a cmdset on yourself is use the `@py` command to execute a python snippet: +If you created a new, fresh cmdset, this must be added to an object in order to make the commands +within available. A simple way to temporarily test a cmdset on yourself is use the `@py` command to +execute a python snippet: ```python @py self.cmdset.add('commands.mycmdset.MyCmdSet') @@ -66,124 +90,254 @@ This will stay with you until you `@reset` or `@shutdown` the server, or you run @py self.cmdset.delete('commands.mycmdset.MyCmdSet') ``` -In the example above, a specific Cmdset class is removed. Calling `delete` without arguments will remove the latest added cmdset. +In the example above, a specific Cmdset class is removed. Calling `delete` without arguments will +remove the latest added cmdset. -> Note: Command sets added using `cmdset.add` are, by default, *not* persistent in the database. +> Note: Command sets added using `cmdset.add` are, by default, *not* persistent in the database. -If you want the cmdset to survive a reload, you can do: +If you want the cmdset to survive a reload, you can do: ``` @py self.cmdset.add(commands.mycmdset.MyCmdSet, permanent=True) ``` -Or you could add the cmdset as the *default* cmdset: +Or you could add the cmdset as the *default* cmdset: ``` @py self.cmdset.add_default(commands.mycmdset.MyCmdSet) ``` -An object can only have one "default" cmdset (but can also have none). This is meant as a safe fall-back even if all other cmdsets fail or are removed. It is always persistent and will not be affected by `cmdset.delete()`. To remove a default cmdset you must explicitly call `cmdset.remove_default()`. +An object can only have one "default" cmdset (but can also have none). This is meant as a safe fall- +back even if all other cmdsets fail or are removed. It is always persistent and will not be affected +by `cmdset.delete()`. To remove a default cmdset you must explicitly call `cmdset.remove_default()`. -Command sets are often added to an object in its `at_object_creation` method. For more examples of adding commands, read the [Step by step tutorial](./Adding-Command-Tutorial). Generally you can customize which command sets are added to your objects by using `self.cmdset.add()` or `self.cmdset.add_default()`. +Command sets are often added to an object in its `at_object_creation` method. For more examples of +adding commands, read the [Step by step tutorial](./Adding-Command-Tutorial). Generally you can +customize which command sets are added to your objects by using `self.cmdset.add()` or +`self.cmdset.add_default()`. -> Important: Commands are identified uniquely by key *or* alias (see [Commands](./Commands)). If any overlap exists, two commands are considered identical. Adding a Command to a command set that already has an identical command will *replace* the previous command. This is very important. You must take this behavior into account when attempting to overload any default Evennia commands with your own. Otherwise, you may accidentally "hide" your own command in your command set when adding a new one that has a matching alias. +> Important: Commands are identified uniquely by key *or* alias (see [Commands](./Commands)). If any +overlap exists, two commands are considered identical. Adding a Command to a command set that +already has an identical command will *replace* the previous command. This is very important. You +must take this behavior into account when attempting to overload any default Evennia commands with +your own. Otherwise, you may accidentally "hide" your own command in your command set when adding a +new one that has a matching alias. ### Properties on Command Sets -There are several extra flags that you can set on CmdSets in order to modify how they work. All are optional and will be set to defaults otherwise. Since many of these relate to *merging* cmdsets, you might want to read the [Adding and Merging Command Sets](./Command-Sets#adding-and-merging-command-sets) section for some of these to make sense. +There are several extra flags that you can set on CmdSets in order to modify how they work. All are +optional and will be set to defaults otherwise. Since many of these relate to *merging* cmdsets, +you might want to read the [Adding and Merging Command Sets](./Command-Sets#adding-and-merging- +command-sets) section for some of these to make sense. -- `key` (string) - an identifier for the cmdset. This is optional, but should be unique. It is used for display in lists, but also to identify special merging behaviours using the `key_mergetype` dictionary below. -- `mergetype` (string) - allows for one of the following string values: "*Union*", "*Intersect*", "*Replace*", or "*Remove*". -- `priority` (int) - This defines the merge order of the merge stack - cmdsets will merge in rising order of priority with the highest priority set merging last. During a merger, the commands from the set with the higher priority will have precedence (just what happens depends on the [merge type](./Command-Sets#adding-and-merging-command-sets)). If priority is identical, the order in the merge stack determines preference. The priority value must be greater or equal to `-100`. Most in-game sets should usually have priorities between `0` and `100`. Evennia default sets have priorities as follows (these can be changed if you want a different distribution): +- `key` (string) - an identifier for the cmdset. This is optional, but should be unique. It is used +for display in lists, but also to identify special merging behaviours using the `key_mergetype` +dictionary below. +- `mergetype` (string) - allows for one of the following string values: "*Union*", "*Intersect*", +"*Replace*", or "*Remove*". +- `priority` (int) - This defines the merge order of the merge stack - cmdsets will merge in rising +order of priority with the highest priority set merging last. During a merger, the commands from the +set with the higher priority will have precedence (just what happens depends on the [merge +type](Command-Sets#adding-and-merging-command-sets)). If priority is identical, the order in the +merge stack determines preference. The priority value must be greater or equal to `-100`. Most in- +game sets should usually have priorities between `0` and `100`. Evennia default sets have priorities +as follows (these can be changed if you want a different distribution): - EmptySet: `-101` (should be lower than all other sets) - SessionCmdSet: `-20` - AccountCmdSet: `-10` - CharacterCmdSet: `0` - ExitCmdSet: ` 101` (generally should always be available) - - ChannelCmdSet: `101` (should usually always be available) - since exits never accept arguments, there is no collision between exits named the same as a channel even though the commands "collide". -- `key_mergetype` (dict) - a dict of `key:mergetype` pairs. This allows this cmdset to merge differently with certain named cmdsets. If the cmdset to merge with has a `key` matching an entry in `key_mergetype`, it will not be merged according to the setting in `mergetype` but according to the mode in this dict. Please note that this is more complex than it may seem due to the [merge order](./Command-Sets#adding-and-merging-command-sets) of command sets. Please review that section before using `key_mergetype`. -- `duplicates` (bool/None default `None`) - this determines what happens when merging same-priority cmdsets containing same-key commands together. The`dupicate` option will *only* apply when merging the cmdset with this option onto one other cmdset with the same priority. The resulting cmdset will *not* retain this `duplicate` setting. - - `None` (default): No duplicates are allowed and the cmdset being merged "onto" the old one will take precedence. The result will be unique commands. *However*, the system will assume this value to be `True` for cmdsets on Objects, to avoid dangerous clashes. This is usually the safe bet. - - `False`: Like `None` except the system will not auto-assume any value for cmdsets defined on Objects. - - `True`: Same-named, same-prio commands will merge into the same cmdset. This will lead to a multimatch error (the user will get a list of possibilities in order to specify which command they meant). This is is useful e.g. for on-object cmdsets (example: There is a `red button` and a `green button` in the room. Both have a `press button` command, in cmdsets with the same priority. This flag makes sure that just writing `press button` will force the Player to define just which object's command was intended). -- `no_objs` this is a flag for the cmdhandler that builds the set of commands available at every moment. It tells the handler not to include cmdsets from objects around the account (nor from rooms or inventory) when building the merged set. Exit commands will still be included. This option can have three values: - - `None` (default): Passthrough of any value set explicitly earlier in the merge stack. If never set explicitly, this acts as `False`. - - `True`/`False`: Explicitly turn on/off. If two sets with explicit `no_objs` are merged, priority determines what is used. -- `no_exits` - this is a flag for the cmdhandler that builds the set of commands available at every moment. It tells the handler not to include cmdsets from exits. This flag can have three values: - - `None` (default): Passthrough of any value set explicitly earlier in the merge stack. If never set explicitly, this acts as `False`. - - `True`/`False`: Explicitly turn on/off. If two sets with explicit `no_exits` are merged, priority determines what is used. -- `no_channels` (bool) - this is a flag for the cmdhandler that builds the set of commands available at every moment. It tells the handler not to include cmdsets from available in-game channels. This flag can have three values: - - `None` (default): Passthrough of any value set explicitly earlier in the merge stack. If never set explicitly, this acts as `False`. - - `True`/`False`: Explicitly turn on/off. If two sets with explicit `no_channels` are merged, priority determines what is used. + - ChannelCmdSet: `101` (should usually always be available) - since exits never accept +arguments, there is no collision between exits named the same as a channel even though the commands +"collide". +- `key_mergetype` (dict) - a dict of `key:mergetype` pairs. This allows this cmdset to merge +differently with certain named cmdsets. If the cmdset to merge with has a `key` matching an entry in +`key_mergetype`, it will not be merged according to the setting in `mergetype` but according to the +mode in this dict. Please note that this is more complex than it may seem due to the [merge +order](Command-Sets#adding-and-merging-command-sets) of command sets. Please review that section +before using `key_mergetype`. +- `duplicates` (bool/None default `None`) - this determines what happens when merging same-priority +cmdsets containing same-key commands together. The`dupicate` option will *only* apply when merging +the cmdset with this option onto one other cmdset with the same priority. The resulting cmdset will +*not* retain this `duplicate` setting. + - `None` (default): No duplicates are allowed and the cmdset being merged "onto" the old one +will take precedence. The result will be unique commands. *However*, the system will assume this +value to be `True` for cmdsets on Objects, to avoid dangerous clashes. This is usually the safe bet. + - `False`: Like `None` except the system will not auto-assume any value for cmdsets defined on +Objects. + - `True`: Same-named, same-prio commands will merge into the same cmdset. This will lead to a +multimatch error (the user will get a list of possibilities in order to specify which command they +meant). This is is useful e.g. for on-object cmdsets (example: There is a `red button` and a `green +button` in the room. Both have a `press button` command, in cmdsets with the same priority. This +flag makes sure that just writing `press button` will force the Player to define just which object's +command was intended). +- `no_objs` this is a flag for the cmdhandler that builds the set of commands available at every +moment. It tells the handler not to include cmdsets from objects around the account (nor from rooms +or inventory) when building the merged set. Exit commands will still be included. This option can +have three values: + - `None` (default): Passthrough of any value set explicitly earlier in the merge stack. If never +set explicitly, this acts as `False`. + - `True`/`False`: Explicitly turn on/off. If two sets with explicit `no_objs` are merged, +priority determines what is used. +- `no_exits` - this is a flag for the cmdhandler that builds the set of commands available at every +moment. It tells the handler not to include cmdsets from exits. This flag can have three values: + - `None` (default): Passthrough of any value set explicitly earlier in the merge stack. If +never set explicitly, this acts as `False`. + - `True`/`False`: Explicitly turn on/off. If two sets with explicit `no_exits` are merged, +priority determines what is used. +- `no_channels` (bool) - this is a flag for the cmdhandler that builds the set of commands available +at every moment. It tells the handler not to include cmdsets from available in-game channels. This +flag can have three values: + - `None` (default): Passthrough of any value set explicitly earlier in the merge stack. If +never set explicitly, this acts as `False`. + - `True`/`False`: Explicitly turn on/off. If two sets with explicit `no_channels` are merged, +priority determines what is used. ## Command Sets Searched -When a user issues a command, it is matched against the [merged](./Command-Sets#adding-and-merging-command-sets) command sets available to the player at the moment. Which those are may change at any time (such as when the player walks into the room with the `Window` object described earlier). +When a user issues a command, it is matched against the [merged](./Command-Sets#adding-and-merging- +command-sets) command sets available to the player at the moment. Which those are may change at any +time (such as when the player walks into the room with the `Window` object described earlier). The currently valid command sets are collected from the following sources: -- The cmdsets stored on the currently active [Session](./Sessions). Default is the empty `SessionCmdSet` with merge priority `-20`. -- The cmdsets defined on the [Account](./Accounts). Default is the AccountCmdSet with merge priority `-10`. -- All cmdsets on the Character/Object (assuming the Account is currently puppeting such a Character/Object). Merge priority `0`. -- The cmdsets of all objects carried by the puppeted Character (checks the `call` lock). Will not be included if `no_objs` option is active in the merge stack. -- The cmdsets of the Character's current location (checks the `call` lock). Will not be included if `no_objs` option is active in the merge stack. -- The cmdsets of objects in the current location (checks the `call` lock). Will not be included if `no_objs` option is active in the merge stack. -- The cmdsets of Exits in the location. Merge priority `+101`. Will not be included if `no_exits` *or* `no_objs` option is active in the merge stack. -- The [channel](./Communications) cmdset containing commands for posting to all channels the account or character is currently connected to. Merge priority `+101`. Will not be included if `no_channels` option is active in the merge stack. +- The cmdsets stored on the currently active [Session](./Sessions). Default is the empty +`SessionCmdSet` with merge priority `-20`. +- The cmdsets defined on the [Account](./Accounts). Default is the AccountCmdSet with merge priority +`-10`. +- All cmdsets on the Character/Object (assuming the Account is currently puppeting such a +Character/Object). Merge priority `0`. +- The cmdsets of all objects carried by the puppeted Character (checks the `call` lock). Will not be +included if `no_objs` option is active in the merge stack. +- The cmdsets of the Character's current location (checks the `call` lock). Will not be included if +`no_objs` option is active in the merge stack. +- The cmdsets of objects in the current location (checks the `call` lock). Will not be included if +`no_objs` option is active in the merge stack. +- The cmdsets of Exits in the location. Merge priority `+101`. Will not be included if `no_exits` +*or* `no_objs` option is active in the merge stack. +- The [channel](./Communications) cmdset containing commands for posting to all channels the account +or character is currently connected to. Merge priority `+101`. Will not be included if `no_channels` +option is active in the merge stack. -Note that an object does not *have* to share its commands with its surroundings. A Character's cmdsets should not be shared for example, or all other Characters would get multi-match errors just by being in the same room. The ability of an object to share its cmdsets is managed by its `call` [lock](./Locks). For example, [Character objects](./Objects) defaults to `call:false()` so that any cmdsets on them can only be accessed by themselves, not by other objects around them. Another example might be to lock an object with `call:inside()` to only make their commands available to objects inside them, or `cmd:holds()` to make their commands available only if they are held. +Note that an object does not *have* to share its commands with its surroundings. A Character's +cmdsets should not be shared for example, or all other Characters would get multi-match errors just +by being in the same room. The ability of an object to share its cmdsets is managed by its `call` +[lock](./Locks). For example, [Character objects](./Objects) defaults to `call:false()` so that any +cmdsets on them can only be accessed by themselves, not by other objects around them. Another +example might be to lock an object with `call:inside()` to only make their commands available to +objects inside them, or `cmd:holds()` to make their commands available only if they are held. ## Adding and Merging Command Sets -*Note: This is an advanced topic. It's very useful to know about, but you might want to skip it if this is your first time learning about commands.* +*Note: This is an advanced topic. It's very useful to know about, but you might want to skip it if +this is your first time learning about commands.* -CmdSets have the special ability that they can be *merged* together into new sets. Which of the ingoing commands end up in the merged set is defined by the *merge rule* and the relative *priorities* of the two sets. Removing the latest added set will restore things back to the way it was before the addition. +CmdSets have the special ability that they can be *merged* together into new sets. Which of the +ingoing commands end up in the merged set is defined by the *merge rule* and the relative +*priorities* of the two sets. Removing the latest added set will restore things back to the way it +was before the addition. -CmdSets are non-destructively stored in a stack inside the cmdset handler on the object. This stack is parsed to create the "combined" cmdset active at the moment. CmdSets from other sources are also included in the merger such as those on objects in the same room (like buttons to press) or those introduced by state changes (such as when entering a menu). The cmdsets are all ordered after priority and then merged together in *reverse order*. That is, the higher priority will be merged "onto" lower-prio ones. By defining a cmdset with a merge-priority between that of two other sets, you will make sure it will be merged in between them. -The very first cmdset in this stack is called the *Default cmdset* and is protected from accidental deletion. Running `obj.cmdset.delete()` will never delete the default set. Instead one should add new cmdsets on top of the default to "hide" it, as described below. Use the special `obj.cmdset.delete_default()` only if you really know what you are doing. +CmdSets are non-destructively stored in a stack inside the cmdset handler on the object. This stack +is parsed to create the "combined" cmdset active at the moment. CmdSets from other sources are also +included in the merger such as those on objects in the same room (like buttons to press) or those +introduced by state changes (such as when entering a menu). The cmdsets are all ordered after +priority and then merged together in *reverse order*. That is, the higher priority will be merged +"onto" lower-prio ones. By defining a cmdset with a merge-priority between that of two other sets, +you will make sure it will be merged in between them. +The very first cmdset in this stack is called the *Default cmdset* and is protected from accidental +deletion. Running `obj.cmdset.delete()` will never delete the default set. Instead one should add +new cmdsets on top of the default to "hide" it, as described below. Use the special +`obj.cmdset.delete_default()` only if you really know what you are doing. -CmdSet merging is an advanced feature useful for implementing powerful game effects. Imagine for example a player entering a dark room. You don't want the player to be able to find everything in the room at a glance - maybe you even want them to have a hard time to find stuff in their backpack! You can then define a different CmdSet with commands that override the normal ones. While they are in the dark room, maybe the `look` and `inv` commands now just tell the player they cannot see anything! Another example would be to offer special combat commands only when the player is in combat. Or when being on a boat. Or when having taken the super power-up. All this can be done on the fly by merging command sets. +CmdSet merging is an advanced feature useful for implementing powerful game effects. Imagine for +example a player entering a dark room. You don't want the player to be able to find everything in +the room at a glance - maybe you even want them to have a hard time to find stuff in their backpack! +You can then define a different CmdSet with commands that override the normal ones. While they are +in the dark room, maybe the `look` and `inv` commands now just tell the player they cannot see +anything! Another example would be to offer special combat commands only when the player is in +combat. Or when being on a boat. Or when having taken the super power-up. All this can be done on +the fly by merging command sets. ### Merge Rules -Basic rule is that command sets are merged in *reverse priority order*. That is, lower-prio sets are merged first and higher prio sets are merged "on top" of them. Think of it like a layered cake with the highest priority on top. +Basic rule is that command sets are merged in *reverse priority order*. That is, lower-prio sets are +merged first and higher prio sets are merged "on top" of them. Think of it like a layered cake with +the highest priority on top. -To further understand how sets merge, we need to define some examples. Let's call the first command set **A** and the second **B**. We assume **B** is the command set already active on our object and we will merge **A** onto **B**. In code terms this would be done by `object.cdmset.add(A)`. Remember, B is already active on `object` from before. +To further understand how sets merge, we need to define some examples. Let's call the first command +set **A** and the second **B**. We assume **B** is the command set already active on our object and +we will merge **A** onto **B**. In code terms this would be done by `object.cdmset.add(A)`. +Remember, B is already active on `object` from before. -We let the **A** set have higher priority than **B**. A priority is simply an integer number. As seen in the list above, Evennia's default cmdsets have priorities in the range `-101` to `120`. You are usually safe to use a priority of `0` or `1` for most game effects. +We let the **A** set have higher priority than **B**. A priority is simply an integer number. As +seen in the list above, Evennia's default cmdsets have priorities in the range `-101` to `120`. You +are usually safe to use a priority of `0` or `1` for most game effects. -In our examples, both sets contain a number of commands which we'll identify by numbers, like `A1, A2` for set **A** and `B1, B2, B3, B4` for **B**. So for that example both sets contain commands with the same keys (or aliases) "1" and "2" (this could for example be "look" and "get" in the real game), whereas commands 3 and 4 are unique to **B**. To describe a merge between these sets, we would write `A1,A2 + B1,B2,B3,B4 = ?` where `?` is a list of commands that depend on which merge type **A** has, and which relative priorities the two sets have. By convention, we read this statement as "New command set **A** is merged onto the old command set **B** to form **?**". +In our examples, both sets contain a number of commands which we'll identify by numbers, like `A1, +A2` for set **A** and `B1, B2, B3, B4` for **B**. So for that example both sets contain commands +with the same keys (or aliases) "1" and "2" (this could for example be "look" and "get" in the real +game), whereas commands 3 and 4 are unique to **B**. To describe a merge between these sets, we +would write `A1,A2 + B1,B2,B3,B4 = ?` where `?` is a list of commands that depend on which merge +type **A** has, and which relative priorities the two sets have. By convention, we read this +statement as "New command set **A** is merged onto the old command set **B** to form **?**". -Below are the available merge types and how they work. Names are partly borrowed from [Set theory](http://en.wikipedia.org/wiki/Set_theory). +Below are the available merge types and how they work. Names are partly borrowed from [Set +theory](http://en.wikipedia.org/wiki/Set_theory). -- **Union** (default) - The two cmdsets are merged so that as many commands as possible from each cmdset ends up in the merged cmdset. Same-key commands are merged by priority. +- **Union** (default) - The two cmdsets are merged so that as many commands as possible from each +cmdset ends up in the merged cmdset. Same-key commands are merged by priority. # Union - A1,A2 + B1,B2,B3,B4 = A1,A2,B3,B4 + A1,A2 + B1,B2,B3,B4 = A1,A2,B3,B4 -- **Intersect** - Only commands found in *both* cmdsets (i.e. which have the same keys) end up in the merged cmdset, with the higher-priority cmdset replacing the lower one's commands. +- **Intersect** - Only commands found in *both* cmdsets (i.e. which have the same keys) end up in +the merged cmdset, with the higher-priority cmdset replacing the lower one's commands. - # Intersect + # Intersect A1,A3,A5 + B1,B2,B4,B5 = A1,A5 -- **Replace** - The commands of the higher-prio cmdset completely replaces the lower-priority cmdset's commands, regardless of if same-key commands exist or not. +- **Replace** - The commands of the higher-prio cmdset completely replaces the lower-priority +cmdset's commands, regardless of if same-key commands exist or not. # Replace A1,A3 + B1,B2,B4,B5 = A1,A3 -- **Remove** - The high-priority command sets removes same-key commands from the lower-priority cmdset. They are not replaced with anything, so this is a sort of filter that prunes the low-prio set using the high-prio one as a template. +- **Remove** - The high-priority command sets removes same-key commands from the lower-priority +cmdset. They are not replaced with anything, so this is a sort of filter that prunes the low-prio +set using the high-prio one as a template. # Remove A1,A3 + B1,B2,B3,B4,B5 = B2,B4,B5 -Besides `priority` and `mergetype`, a command-set also takes a few other variables to control how they merge: +Besides `priority` and `mergetype`, a command-set also takes a few other variables to control how +they merge: -- `duplicates` (bool) - determines what happens when two sets of equal priority merge. Default is that the new set in the merger (i.e. **A** above) automatically takes precedence. But if *duplicates* is true, the result will be a merger with more than one of each name match. This will usually lead to the player receiving a multiple-match error higher up the road, but can be good for things like cmdsets on non-player objects in a room, to allow the system to warn that more than one 'ball' in the room has the same 'kick' command defined on it and offer a chance to select which ball to kick ... Allowing duplicates only makes sense for *Union* and *Intersect*, the setting is ignored for the other mergetypes. -- `key_mergetypes` (dict) - allows the cmdset to define a unique mergetype for particular cmdsets, identified by their cmdset `key`. Format is `{CmdSetkey:mergetype}`. Example: `{'Myevilcmdset','Replace'}` which would make sure for this set to always use 'Replace' on the cmdset with the key `Myevilcmdset` only, no matter what the main `mergetype` is set to. +- `duplicates` (bool) - determines what happens when two sets of equal priority merge. Default is +that the new set in the merger (i.e. **A** above) automatically takes precedence. But if +*duplicates* is true, the result will be a merger with more than one of each name match. This will +usually lead to the player receiving a multiple-match error higher up the road, but can be good for +things like cmdsets on non-player objects in a room, to allow the system to warn that more than one +'ball' in the room has the same 'kick' command defined on it and offer a chance to select which +ball to kick ... Allowing duplicates only makes sense for *Union* and *Intersect*, the setting is +ignored for the other mergetypes. +- `key_mergetypes` (dict) - allows the cmdset to define a unique mergetype for particular cmdsets, +identified by their cmdset `key`. Format is `{CmdSetkey:mergetype}`. Example: +`{'Myevilcmdset','Replace'}` which would make sure for this set to always use 'Replace' on the +cmdset with the key `Myevilcmdset` only, no matter what the main `mergetype` is set to. -> Warning: The `key_mergetypes` dictionary *can only work on the cmdset we merge onto*. When using `key_mergetypes` it is thus important to consider the merge priorities - you must make sure that you pick a priority *between* the cmdset you want to detect and the next higher one, if any. That is, if we define a cmdset with a high priority and set it to affect a cmdset that is far down in the merge stack, we would not "see" that set when it's time for us to merge. Example: Merge stack is `A(prio=-10), B(prio=-5), C(prio=0), D(prio=5)`. We now merge a cmdset `E(prio=10)` onto this stack, with a `key_mergetype={"B":"Replace"}`. But priorities dictate that we won't be merged onto B, we will be merged onto E (which is a merger of the lower-prio sets at this point). Since we are merging onto E and not B, our `key_mergetype` directive won't trigger. To make sure it works we must make sure we merge onto B. Setting E's priority to, say, -4 will make sure to merge it onto B and affect it appropriately. +> Warning: The `key_mergetypes` dictionary *can only work on the cmdset we merge onto*. When using +`key_mergetypes` it is thus important to consider the merge priorities - you must make sure that you +pick a priority *between* the cmdset you want to detect and the next higher one, if any. That is, if +we define a cmdset with a high priority and set it to affect a cmdset that is far down in the merge +stack, we would not "see" that set when it's time for us to merge. Example: Merge stack is +`A(prio=-10), B(prio=-5), C(prio=0), D(prio=5)`. We now merge a cmdset `E(prio=10)` onto this stack, +with a `key_mergetype={"B":"Replace"}`. But priorities dictate that we won't be merged onto B, we +will be merged onto E (which is a merger of the lower-prio sets at this point). Since we are merging +onto E and not B, our `key_mergetype` directive won't trigger. To make sure it works we must make +sure we merge onto B. Setting E's priority to, say, -4 will make sure to merge it onto B and affect +it appropriately. -More advanced cmdset example: +More advanced cmdset example: ```python from commands import mycommands @@ -193,13 +347,13 @@ class MyCmdSet(CmdSet): key = "MyCmdSet" priority = 4 mergetype = "Replace" - key_mergetypes = {'MyOtherCmdSet':'Union'} + key_mergetypes = {'MyOtherCmdSet':'Union'} def at_cmdset_creation(self): """ The only thing this method should need to do is to add commands to the set. - """ + """ self.add(mycommands.MyCommand1()) self.add(mycommands.MyCommand2()) self.add(mycommands.MyCommand3()) @@ -207,11 +361,16 @@ class MyCmdSet(CmdSet): ### Assorted Notes -It is very important to remember that two commands are compared *both* by their `key` properties *and* by their `aliases` properties. If either keys or one of their aliases match, the two commands are considered the *same*. So consider these two Commands: +It is very important to remember that two commands are compared *both* by their `key` properties +*and* by their `aliases` properties. If either keys or one of their aliases match, the two commands +are considered the *same*. So consider these two Commands: - A Command with key "kick" and alias "fight" - A Command with key "punch" also with an alias "fight" -During the cmdset merging (which happens all the time since also things like channel commands and exits are merged in), these two commands will be considered *identical* since they share alias. It means only one of them will remain after the merger. Each will also be compared with all other commands having any combination of the keys and/or aliases "kick", "punch" or "fight". +During the cmdset merging (which happens all the time since also things like channel commands and +exits are merged in), these two commands will be considered *identical* since they share alias. It +means only one of them will remain after the merger. Each will also be compared with all other +commands having any combination of the keys and/or aliases "kick", "punch" or "fight". -... So avoid duplicate aliases, it will only cause confusion. \ No newline at end of file +... So avoid duplicate aliases, it will only cause confusion. \ No newline at end of file diff --git a/docs/source/Command-System.md b/docs/source/Command-System.md index 7b267bf302..1288202ce5 100644 --- a/docs/source/Command-System.md +++ b/docs/source/Command-System.md @@ -1,6 +1,6 @@ # Command System -- [Commands](./Commands) +- [Commands](./Commands) - [Command Sets](./Command-Sets) - [Command Auto-help](./Help-System#command-auto-help-system) diff --git a/docs/source/Commands.md b/docs/source/Commands.md index b527735af0..d59ddc0f69 100644 --- a/docs/source/Commands.md +++ b/docs/source/Commands.md @@ -1,22 +1,43 @@ # Commands -Commands are intimately linked to [Command Sets](./Command-Sets) and you need to read that page too to be familiar with how the command system works. The two pages were split for easy reading. +Commands are intimately linked to [Command Sets](./Command-Sets) and you need to read that page too to +be familiar with how the command system works. The two pages were split for easy reading. -The basic way for users to communicate with the game is through *Commands*. These can be commands directly related to the game world such as *look*, *get*, *drop* and so on, or administrative commands such as *examine* or *@dig*. +The basic way for users to communicate with the game is through *Commands*. These can be commands +directly related to the game world such as *look*, *get*, *drop* and so on, or administrative +commands such as *examine* or *@dig*. -The [default commands](./Default-Command-Help) coming with Evennia are 'MUX-like' in that they use @ for admin commands, support things like switches, syntax with the '=' symbol etc, but there is nothing that prevents you from implementing a completely different command scheme for your game. You can find the default commands in `evennia/commands/default`. You should not edit these directly - they will be updated by the Evennia team as new features are added. Rather you should look to them for inspiration and inherit your own designs from them. +The [default commands](./Default-Command-Help) coming with Evennia are 'MUX-like' in that they use @ +for admin commands, support things like switches, syntax with the '=' symbol etc, but there is +nothing that prevents you from implementing a completely different command scheme for your game. You +can find the default commands in `evennia/commands/default`. You should not edit these directly - +they will be updated by the Evennia team as new features are added. Rather you should look to them +for inspiration and inherit your own designs from them. -There are two components to having a command running - the *Command* class and the [Command Set](./Command-Sets) (command sets were split into a separate wiki page for ease of reading). +There are two components to having a command running - the *Command* class and the [Command +Set](Command-Sets) (command sets were split into a separate wiki page for ease of reading). -1. A *Command* is a python class containing all the functioning code for what a command does - for example, a *get* command would contain code for picking up objects. -1. A *Command Set* (often referred to as a CmdSet or cmdset) is like a container for one or more Commands. A given Command can go into any number of different command sets. Only by putting the command set on a character object you will make all the commands therein available to use by that character. You can also store command sets on normal objects if you want users to be able to use the object in various ways. Consider a "Tree" object with a cmdset defining the commands *climb* and *chop down*. Or a "Clock" with a cmdset containing the single command *check time*. +1. A *Command* is a python class containing all the functioning code for what a command does - for +example, a *get* command would contain code for picking up objects. +1. A *Command Set* (often referred to as a CmdSet or cmdset) is like a container for one or more +Commands. A given Command can go into any number of different command sets. Only by putting the +command set on a character object you will make all the commands therein available to use by that +character. You can also store command sets on normal objects if you want users to be able to use the +object in various ways. Consider a "Tree" object with a cmdset defining the commands *climb* and +*chop down*. Or a "Clock" with a cmdset containing the single command *check time*. -This page goes into full detail about how to use Commands. To fully use them you must also read the page detailing [Command Sets](./Command-Sets). There is also a step-by-step [Adding Command Tutorial](./Adding-Command-Tutorial) that will get you started quickly without the extra explanations. +This page goes into full detail about how to use Commands. To fully use them you must also read the +page detailing [Command Sets](./Command-Sets). There is also a step-by-step [Adding Command +Tutorial](Adding-Command-Tutorial) that will get you started quickly without the extra explanations. ## Defining Commands -All commands are implemented as normal Python classes inheriting from the base class `Command` (`evennia.Command`). You will find that this base class is very "bare". The default commands of Evennia actually inherit from a child of `Command` called `MuxCommand` - this is the class that knows all the mux-like syntax like `/switches`, splitting by "=" etc. Below we'll avoid mux-specifics and use the base `Command` class directly. +All commands are implemented as normal Python classes inheriting from the base class `Command` +(`evennia.Command`). You will find that this base class is very "bare". The default commands of +Evennia actually inherit from a child of `Command` called `MuxCommand` - this is the class that +knows all the mux-like syntax like `/switches`, splitting by "=" etc. Below we'll avoid mux- +specifics and use the base `Command` class directly. ```python # basic Command definition @@ -47,78 +68,158 @@ Here is a minimalistic command with no custom parsing: ``` -You define a new command by assigning a few class-global properties on your inherited class and overloading one or two hook functions. The full gritty mechanic behind how commands work are found towards the end of this page; for now you only need to know that the command handler creates an instance of this class and uses that instance whenever you use this command - it also dynamically assigns the new command instance a few useful properties that you can assume to always be available. +You define a new command by assigning a few class-global properties on your inherited class and +overloading one or two hook functions. The full gritty mechanic behind how commands work are found +towards the end of this page; for now you only need to know that the command handler creates an +instance of this class and uses that instance whenever you use this command - it also dynamically +assigns the new command instance a few useful properties that you can assume to always be available. ### Who is calling the command? -In Evennia there are three types of objects that may call the command. It is important to be aware of this since this will also assign appropriate `caller`, `session`, `sessid` and `account` properties on the command body at runtime. Most often the calling type is `Session`. +In Evennia there are three types of objects that may call the command. It is important to be aware +of this since this will also assign appropriate `caller`, `session`, `sessid` and `account` +properties on the command body at runtime. Most often the calling type is `Session`. -* A [Session](./Sessions). This is by far the most common case when a user is entering a command in their client. - * `caller` - this is set to the puppeted [Object](./Objects) if such an object exists. If no puppet is found, `caller` is set equal to `account`. Only if an Account is not found either (such as before being logged in) will this be set to the Session object itself. +* A [Session](./Sessions). This is by far the most common case when a user is entering a command in +their client. + * `caller` - this is set to the puppeted [Object](./Objects) if such an object exists. If no +puppet is found, `caller` is set equal to `account`. Only if an Account is not found either (such as +before being logged in) will this be set to the Session object itself. * `session` - a reference to the [Session](./Sessions) object itself. * `sessid` - `sessid.id`, a unique integer identifier of the session. * `account` - the [Account](./Accounts) object connected to this Session. None if not logged in. -* An [Account](./Accounts). This only happens if `account.execute_cmd()` was used. No Session information can be obtained in this case. - * `caller` - this is set to the puppeted Object if such an object can be determined (without Session info this can only be determined in `MULTISESSION_MODE=0` or `1`). If no puppet is found, this is equal to `account`. +* An [Account](./Accounts). This only happens if `account.execute_cmd()` was used. No Session +information can be obtained in this case. + * `caller` - this is set to the puppeted Object if such an object can be determined (without +Session info this can only be determined in `MULTISESSION_MODE=0` or `1`). If no puppet is found, +this is equal to `account`. * `session` - `None*` * `sessid` - `None*` * `account` - Set to the Account object. -* An [Object](./Objects). This only happens if `object.execute_cmd()` was used (for example by an NPC). +* An [Object](./Objects). This only happens if `object.execute_cmd()` was used (for example by an +NPC). * `caller` - This is set to the calling Object in question. * `session` - `None*` * `sessid` - `None*` * `account` - `None` -> `*)`: There is a way to make the Session available also inside tests run directly on Accounts and Objects, and that is to pass it to `execute_cmd` like so: `account.execute_cmd("...", session=)`. Doing so *will* make the `.session` and `.sessid` properties available in the command. +> `*)`: There is a way to make the Session available also inside tests run directly on Accounts and +Objects, and that is to pass it to `execute_cmd` like so: `account.execute_cmd("...", +session=)`. Doing so *will* make the `.session` and `.sessid` properties available in the +command. ### Properties assigned to the command instance at run-time -Let's say account *Bob* with a character *BigGuy* enters the command *look at sword*. After the system having successfully identified this as the "look" command and determined that BigGuy really has access to a command named `look`, it chugs the `look` command class out of storage and either loads an existing Command instance from cache or creates one. After some more checks it then assigns it the following properties: +Let's say account *Bob* with a character *BigGuy* enters the command *look at sword*. After the +system having successfully identified this as the "look" command and determined that BigGuy really +has access to a command named `look`, it chugs the `look` command class out of storage and either +loads an existing Command instance from cache or creates one. After some more checks it then assigns +it the following properties: -- `caller` - The character BigGuy, in this example. This is a reference to the object executing the command. The value of this depends on what type of object is calling the command; see the previous section. -- `session` - the [Session](./Sessions) Bob uses to connect to the game and control BigGuy (see also previous section). +- `caller` - The character BigGuy, in this example. This is a reference to the object executing the +command. The value of this depends on what type of object is calling the command; see the previous +section. +- `session` - the [Session](./Sessions) Bob uses to connect to the game and control BigGuy (see also +previous section). - `sessid` - the unique id of `self.session`, for quick lookup. - `account` - the [Account](./Accounts) Bob (see previous section). - `cmdstring` - the matched key for the command. This would be *look* in our example. -- `args` - this is the rest of the string, except the command name. So if the string entered was *look at sword*, `args` would be " *at sword*". Note the space kept - Evennia would correctly interpret `lookat sword` too. This is useful for things like `/switches` that should not use space. In the `MuxCommand` class used for default commands, this space is stripped. Also see the `arg_regex` property if you want to enforce a space to make `lookat sword` give a command-not-found error. -- `obj` - the game [Object](./Objects) on which this command is defined. This need not be the caller, but since `look` is a common (default) command, this is probably defined directly on *BigGuy* - so `obj` will point to BigGuy. Otherwise `obj` could be an Account or any interactive object with commands defined on it, like in the example of the "check time" command defined on a "Clock" object. -- `cmdset` - this is a reference to the merged CmdSet (see below) from which this command was matched. This variable is rarely used, it's main use is for the [auto-help system](./Help-System#command-auto-help-system) (*Advanced note: the merged cmdset need NOT be the same as `BigGuy.cmdset`. The merged set can be a combination of the cmdsets from other objects in the room, for example*). -- `raw_string` - this is the raw input coming from the user, without stripping any surrounding whitespace. The only thing that is stripped is the ending newline marker. +- `args` - this is the rest of the string, except the command name. So if the string entered was +*look at sword*, `args` would be " *at sword*". Note the space kept - Evennia would correctly +interpret `lookat sword` too. This is useful for things like `/switches` that should not use space. +In the `MuxCommand` class used for default commands, this space is stripped. Also see the +`arg_regex` property if you want to enforce a space to make `lookat sword` give a command-not-found +error. +- `obj` - the game [Object](./Objects) on which this command is defined. This need not be the caller, +but since `look` is a common (default) command, this is probably defined directly on *BigGuy* - so +`obj` will point to BigGuy. Otherwise `obj` could be an Account or any interactive object with +commands defined on it, like in the example of the "check time" command defined on a "Clock" object. +- `cmdset` - this is a reference to the merged CmdSet (see below) from which this command was +matched. This variable is rarely used, it's main use is for the [auto-help system](Help- +System#command-auto-help-system) (*Advanced note: the merged cmdset need NOT be the same as +`BigGuy.cmdset`. The merged set can be a combination of the cmdsets from other objects in the room, +for example*). +- `raw_string` - this is the raw input coming from the user, without stripping any surrounding +whitespace. The only thing that is stripped is the ending newline marker. -#### Other useful utility methods: +#### Other useful utility methods: -- `.get_help(caller, cmdset)` - Get the help entry for this command. By default the arguments are not +- `.get_help(caller, cmdset)` - Get the help entry for this command. By default the arguments are +not used, but they could be used to implement alternate help-display systems. -- `.client_width()` - Shortcut for getting the client's screen-width. Note that not all clients will +- `.client_width()` - Shortcut for getting the client's screen-width. Note that not all clients will truthfully report this value - that case the `settings.DEFAULT_SCREEN_WIDTH` will be returned. -- `.styled_table(*args, **kwargs)` - This returns an [EvTable](api:evennia.utils#module-evennia.utils.evtable) styled based on the - session calling this command. The args/kwargs are the same as for EvTable, except styling defaults are set. -- `.styled_header`, `_footer`, `separator` - These will produce styled decorations for - display to the user. They are useful for creating listings and forms with colors adjustable per-user. +- `.styled_table(*args, **kwargs)` - This returns an [EvTable](api:evennia.utils#module- +evennia.utils.evtable) styled based on the + session calling this command. The args/kwargs are the same as for EvTable, except styling defaults +are set. +- `.styled_header`, `_footer`, `separator` - These will produce styled decorations for + display to the user. They are useful for creating listings and forms with colors adjustable per- +user. ### Defining your own command classes -Beyond the properties Evennia always assigns to the command at run-time (listed above), your job is to define the following class properties: +Beyond the properties Evennia always assigns to the command at run-time (listed above), your job is +to define the following class properties: -- `key` (string) - the identifier for the command, like `look`. This should (ideally) be unique. A key can consist of more than one word, like "press button" or "pull left lever". Note that *both* `key` and `aliases` below determine the identity of a command. So two commands are considered if either matches. This is important for merging cmdsets described below. -- `aliases` (optional list) - a list of alternate names for the command (`["glance", "see", "l"]`). Same name rules as for `key` applies. -- `locks` (string) - a [lock definition](./Locks), usually on the form `cmd:`. Locks is a rather big topic, so until you learn more about locks, stick to giving the lockstring `"cmd:all()"` to make the command available to everyone (if you don't provide a lock string, this will be assigned for you). -- `help_category` (optional string) - setting this helps to structure the auto-help into categories. If none is set, this will be set to *General*. -- `save_for_next` (optional boolean). This defaults to `False`. If `True`, a copy of this command object (along with any changes you have done to it) will be stored by the system and can be accessed by the next command by retrieving `self.caller.ndb.last_cmd`. The next run command will either clear or replace the storage. -- `arg_regex` (optional raw string): Used to force the parser to limit itself and tell it when the command-name ends and arguments begin (such as requiring this to be a space or a /switch). This is done with a regular expression. [See the arg_regex section](./Commands#on-arg_regex) for the details. -- `auto_help` (optional boolean). Defaults to `True`. This allows for turning off the [auto-help system](./Help-System#command-auto-help-system) on a per-command basis. This could be useful if you either want to write your help entries manually or hide the existence of a command from `help`'s generated list. -- `is_exit` (bool) - this marks the command as being used for an in-game exit. This is, by default, set by all Exit objects and you should not need to set it manually unless you make your own Exit system. It is used for optimization and allows the cmdhandler to easily disregard this command when the cmdset has its `no_exits` flag set. -- `is_channel` (bool)- this marks the command as being used for an in-game channel. This is, by default, set by all Channel objects and you should not need to set it manually unless you make your own Channel system. is used for optimization and allows the cmdhandler to easily disregard this command when its cmdset has its `no_channels` flag set. -- `msg_all_sessions` (bool): This affects the behavior of the `Command.msg` method. If unset (default), calling `self.msg(text)` from the Command will always only send text to the Session that actually triggered this Command. If set however, `self.msg(text)` will send to all Sessions relevant to the object this Command sits on. Just which Sessions receives the text depends on the object and the server's `MULTISESSION_MODE`. +- `key` (string) - the identifier for the command, like `look`. This should (ideally) be unique. A +key can consist of more than one word, like "press button" or "pull left lever". Note that *both* +`key` and `aliases` below determine the identity of a command. So two commands are considered if +either matches. This is important for merging cmdsets described below. +- `aliases` (optional list) - a list of alternate names for the command (`["glance", "see", "l"]`). +Same name rules as for `key` applies. +- `locks` (string) - a [lock definition](./Locks), usually on the form `cmd:`. Locks is a +rather big topic, so until you learn more about locks, stick to giving the lockstring `"cmd:all()"` +to make the command available to everyone (if you don't provide a lock string, this will be assigned +for you). +- `help_category` (optional string) - setting this helps to structure the auto-help into categories. +If none is set, this will be set to *General*. +- `save_for_next` (optional boolean). This defaults to `False`. If `True`, a copy of this command +object (along with any changes you have done to it) will be stored by the system and can be accessed +by the next command by retrieving `self.caller.ndb.last_cmd`. The next run command will either clear +or replace the storage. +- `arg_regex` (optional raw string): Used to force the parser to limit itself and tell it when the +command-name ends and arguments begin (such as requiring this to be a space or a /switch). This is +done with a regular expression. [See the arg_regex section](./Commands#on-arg_regex) for the details. +- `auto_help` (optional boolean). Defaults to `True`. This allows for turning off the [auto-help +system](Help-System#command-auto-help-system) on a per-command basis. This could be useful if you +either want to write your help entries manually or hide the existence of a command from `help`'s +generated list. +- `is_exit` (bool) - this marks the command as being used for an in-game exit. This is, by default, +set by all Exit objects and you should not need to set it manually unless you make your own Exit +system. It is used for optimization and allows the cmdhandler to easily disregard this command when +the cmdset has its `no_exits` flag set. +- `is_channel` (bool)- this marks the command as being used for an in-game channel. This is, by +default, set by all Channel objects and you should not need to set it manually unless you make your +own Channel system. is used for optimization and allows the cmdhandler to easily disregard this +command when its cmdset has its `no_channels` flag set. +- `msg_all_sessions` (bool): This affects the behavior of the `Command.msg` method. If unset +(default), calling `self.msg(text)` from the Command will always only send text to the Session that +actually triggered this Command. If set however, `self.msg(text)` will send to all Sessions relevant +to the object this Command sits on. Just which Sessions receives the text depends on the object and +the server's `MULTISESSION_MODE`. -You should also implement at least two methods, `parse()` and `func()` (You could also implement `perm()`, but that's not needed unless you want to fundamentally change how access checks work). +You should also implement at least two methods, `parse()` and `func()` (You could also implement +`perm()`, but that's not needed unless you want to fundamentally change how access checks work). -- `at_pre_cmd()` is called very first on the command. If this function returns anything that evaluates to `True` the command execution is aborted at this point. -- `parse()` is intended to parse the arguments (`self.args`) of the function. You can do this in any way you like, then store the result(s) in variable(s) on the command object itself (i.e. on `self`). To take an example, the default mux-like system uses this method to detect "command switches" and store them as a list in `self.switches`. Since the parsing is usually quite similar inside a command scheme you should make `parse()` as generic as possible and then inherit from it rather than re-implementing it over and over. In this way, the default `MuxCommand` class implements a `parse()` for all child commands to use. -- `func()` is called right after `parse()` and should make use of the pre-parsed input to actually do whatever the command is supposed to do. This is the main body of the command. The return value from this method will be returned from the execution as a Twisted Deferred. +- `at_pre_cmd()` is called very first on the command. If this function returns anything that +evaluates to `True` the command execution is aborted at this point. +- `parse()` is intended to parse the arguments (`self.args`) of the function. You can do this in any +way you like, then store the result(s) in variable(s) on the command object itself (i.e. on `self`). +To take an example, the default mux-like system uses this method to detect "command switches" and +store them as a list in `self.switches`. Since the parsing is usually quite similar inside a command +scheme you should make `parse()` as generic as possible and then inherit from it rather than re- +implementing it over and over. In this way, the default `MuxCommand` class implements a `parse()` +for all child commands to use. +- `func()` is called right after `parse()` and should make use of the pre-parsed input to actually +do whatever the command is supposed to do. This is the main body of the command. The return value +from this method will be returned from the execution as a Twisted Deferred. - `at_post_cmd()` is called after `func()` to handle eventual cleanup. -Finally, you should always make an informative [doc string](http://www.python.org/dev/peps/pep-0257/#what-is-a-docstring) (`__doc__`) at the top of your class. This string is dynamically read by the [Help System](./Help-System) to create the help entry for this command. You should decide on a way to format your help and stick to that. +Finally, you should always make an informative [doc +string](http://www.python.org/dev/peps/pep-0257/#what-is-a-docstring) (`__doc__`) at the top of your +class. This string is dynamically read by the [Help System](./Help-System) to create the help entry +for this command. You should decide on a way to format your help and stick to that. Below is how you define a simple alternative "`smile`" command: @@ -158,8 +259,8 @@ class CmdSmile(Command): string = f"{caller.key} smiles" else: target = caller.search(self.target) - if not target: - return + if not target: + return string = f"{caller.key} smiles at {target.key}" caller.location.msg_contents(string) @@ -179,19 +280,39 @@ within a *command set*. See the [Command Sets](./Command-Sets) page. ### On arg_regex -The command parser is very general and does not require a space to end your command name. This means that the alias `:` to `emote` can be used like `:smiles` without modification. It also means `getstone` will get you the stone (unless there is a command specifically named `getstone`, then that will be used). If you want to tell the parser to require a certain separator between the command name and its arguments (so that `get stone` works but `getstone` gives you a 'command not found' error) you can do so with the `arg_regex` property. +The command parser is very general and does not require a space to end your command name. This means +that the alias `:` to `emote` can be used like `:smiles` without modification. It also means +`getstone` will get you the stone (unless there is a command specifically named `getstone`, then +that will be used). If you want to tell the parser to require a certain separator between the +command name and its arguments (so that `get stone` works but `getstone` gives you a 'command not +found' error) you can do so with the `arg_regex` property. -The `arg_regex` is a [raw regular expression string](http://docs.python.org/library/re.html). The regex will be compiled by the system at runtime. This allows you to customize how the part *immediately following* the command name (or alias) must look in order for the parser to match for this command. Some examples: +The `arg_regex` is a [raw regular expression string](http://docs.python.org/library/re.html). The +regex will be compiled by the system at runtime. This allows you to customize how the part +*immediately following* the command name (or alias) must look in order for the parser to match for +this command. Some examples: -- `commandname argument` (`arg_regex = r"\s.+"`): This forces the parser to require the command name to be followed by one or more spaces. Whatever is entered after the space will be treated as an argument. However, if you'd forget the space (like a command having no arguments), this would *not* match `commandname`. -- `commandname` or `commandname argument` (`arg_regex = r"\s.+|$"`): This makes both `look` and `look me` work but `lookme` will not. -- `commandname/switches arguments` (`arg_regex = r"(?:^(?:\s+|\/).*$)|^$"`. If you are using Evennia's `MuxCommand` Command parent, you may wish to use this since it will allow `/switche`s to work as well as having or not having a space. +- `commandname argument` (`arg_regex = r"\s.+"`): This forces the parser to require the command name +to be followed by one or more spaces. Whatever is entered after the space will be treated as an +argument. However, if you'd forget the space (like a command having no arguments), this would *not* +match `commandname`. +- `commandname` or `commandname argument` (`arg_regex = r"\s.+|$"`): This makes both `look` and +`look me` work but `lookme` will not. +- `commandname/switches arguments` (`arg_regex = r"(?:^(?:\s+|\/).*$)|^$"`. If you are using +Evennia's `MuxCommand` Command parent, you may wish to use this since it will allow `/switche`s to +work as well as having or not having a space. -The `arg_regex` allows you to customize the behavior of your commands. You can put it in the parent class of your command to customize all children of your Commands. However, you can also change the base default behavior for all Commands by modifying `settings.COMMAND_DEFAULT_ARG_REGEX`. +The `arg_regex` allows you to customize the behavior of your commands. You can put it in the parent +class of your command to customize all children of your Commands. However, you can also change the +base default behavior for all Commands by modifying `settings.COMMAND_DEFAULT_ARG_REGEX`. ## Exiting a command -Normally you just use `return` in one of your Command class' hook methods to exit that method. That will however still fire the other hook methods of the Command in sequence. That's usually what you want but sometimes it may be useful to just abort the command, for example if you find some unacceptable input in your parse method. To exit the command this way you can raise `evennia.InterruptCommand`: +Normally you just use `return` in one of your Command class' hook methods to exit that method. That +will however still fire the other hook methods of the Command in sequence. That's usually what you +want but sometimes it may be useful to just abort the command, for example if you find some +unacceptable input in your parse method. To exit the command this way you can raise +`evennia.InterruptCommand`: ```python from evennia import InterruptCommand @@ -210,11 +331,19 @@ class MyCommand(Command): ## Pauses in commands -Sometimes you want to pause the execution of your command for a little while before continuing - maybe you want to simulate a heavy swing taking some time to finish, maybe you want the echo of your voice to return to you with an ever-longer delay. Since Evennia is running asynchronously, you cannot use `time.sleep()` in your commands (or anywhere, really). If you do, the *entire game* will be frozen for everyone! So don't do that. Fortunately, Evennia offers a really quick syntax for making pauses in commands. +Sometimes you want to pause the execution of your command for a little while before continuing - +maybe you want to simulate a heavy swing taking some time to finish, maybe you want the echo of your +voice to return to you with an ever-longer delay. Since Evennia is running asynchronously, you +cannot use `time.sleep()` in your commands (or anywhere, really). If you do, the *entire game* will +be frozen for everyone! So don't do that. Fortunately, Evennia offers a really quick syntax for +making pauses in commands. -In your `func()` method, you can use the `yield` keyword. This is a Python keyword that will freeze the current execution of your command and wait for more before processing. +In your `func()` method, you can use the `yield` keyword. This is a Python keyword that will freeze +the current execution of your command and wait for more before processing. -> Note that you *cannot* just drop `yield` into any code and expect it to pause. Evennia will only pause for you if you `yield` inside the Command's `func()` method. Don't expect it to work anywhere else. +> Note that you *cannot* just drop `yield` into any code and expect it to pause. Evennia will only +pause for you if you `yield` inside the Command's `func()` method. Don't expect it to work anywhere +else. Here's an example of a command using a small pause of five seconds between messages: @@ -243,12 +372,20 @@ class CmdWait(Command): self.msg("... And now another 2 seconds have passed.") ``` -The important line is the `yield 5` and `yield 2` lines. It will tell Evennia to pause execution here and not continue until the number of seconds given has passed. +The important line is the `yield 5` and `yield 2` lines. It will tell Evennia to pause execution +here and not continue until the number of seconds given has passed. There are two things to remember when using `yield` in your Command's `func` method: -1. The paused state produced by the `yield` is not saved anywhere. So if the server reloads in the middle of your command pausing, it will *not* resume when the server comes back up - the remainder of the command will never fire. So be careful that you are not freezing the character or account in a way that will not be cleared on reload. -2. If you use `yield` you may not also use `return ` in your `func` method. You'll get an error explaining this. This is due to how Python generators work. You can however use a "naked" `return` just fine. Usually there is no need for `func` to return a value, but if you ever do need to mix `yield` with a final return value in the same `func`, look at [twisted.internet.defer.returnValue](https://twistedmatrix.com/documents/current/api/twisted.internet.defer.html#returnValue). +1. The paused state produced by the `yield` is not saved anywhere. So if the server reloads in the +middle of your command pausing, it will *not* resume when the server comes back up - the remainder +of the command will never fire. So be careful that you are not freezing the character or account in +a way that will not be cleared on reload. +2. If you use `yield` you may not also use `return ` in your `func` method. You'll get an +error explaining this. This is due to how Python generators work. You can however use a "naked" +`return` just fine. Usually there is no need for `func` to return a value, but if you ever do need +to mix `yield` with a final return value in the same `func`, look at [twisted.internet.defer.returnV +alue](https://twistedmatrix.com/documents/current/api/twisted.internet.defer.html#returnValue). ## Asking for user input @@ -284,28 +421,52 @@ class CmdConfirm(Command): self.msg("No!") ``` -This time, when the user enters the 'confirm' command, she will be asked if she wants to go on. Entering 'yes' or "y" (regardless of case) will give the first reply, otherwise the second reply will show. +This time, when the user enters the 'confirm' command, she will be asked if she wants to go on. +Entering 'yes' or "y" (regardless of case) will give the first reply, otherwise the second reply +will show. -> Note again that the `yield` keyword does not store state. If the game reloads while waiting for the user to answer, the user will have to start over. It is not a good idea to use `yield` for important or complex choices, a persistent [EvMenu](./EvMenu) might be more appropriate in this case. +> Note again that the `yield` keyword does not store state. If the game reloads while waiting for +the user to answer, the user will have to start over. It is not a good idea to use `yield` for +important or complex choices, a persistent [EvMenu](./EvMenu) might be more appropriate in this case. ## System commands *Note: This is an advanced topic. Skip it if this is your first time learning about commands.* -There are several command-situations that are exceptional in the eyes of the server. What happens if the account enters an empty string? What if the 'command' given is infact the name of a channel the user wants to send a message to? Or if there are multiple command possibilities? +There are several command-situations that are exceptional in the eyes of the server. What happens if +the account enters an empty string? What if the 'command' given is infact the name of a channel the +user wants to send a message to? Or if there are multiple command possibilities? -Such 'special cases' are handled by what's called *system commands*. A system command is defined in the same way as other commands, except that their name (key) must be set to one reserved by the engine (the names are defined at the top of `evennia/commands/cmdhandler.py`). You can find (unused) implementations of the system commands in `evennia/commands/default/system_commands.py`. Since these are not (by default) included in any `CmdSet` they are not actually used, they are just there for show. When the special situation occurs, Evennia will look through all valid `CmdSet`s for your custom system command. Only after that will it resort to its own, hard-coded implementation. +Such 'special cases' are handled by what's called *system commands*. A system command is defined +in the same way as other commands, except that their name (key) must be set to one reserved by the +engine (the names are defined at the top of `evennia/commands/cmdhandler.py`). You can find (unused) +implementations of the system commands in `evennia/commands/default/system_commands.py`. Since these +are not (by default) included in any `CmdSet` they are not actually used, they are just there for +show. When the special situation occurs, Evennia will look through all valid `CmdSet`s for your +custom system command. Only after that will it resort to its own, hard-coded implementation. -Here are the exceptional situations that triggers system commands. You can find the command keys they use as properties on `evennia.syscmdkeys`: +Here are the exceptional situations that triggers system commands. You can find the command keys +they use as properties on `evennia.syscmdkeys`: -- No input (`syscmdkeys.CMD_NOINPUT`) - the account just pressed return without any input. Default is to do nothing, but it can be useful to do something here for certain implementations such as line editors that interpret non-commands as text input (an empty line in the editing buffer). -- Command not found (`syscmdkeys.CMD_NOMATCH`) - No matching command was found. Default is to display the "Huh?" error message. -- Several matching commands where found (`syscmdkeys.CMD_MULTIMATCH`) - Default is to show a list of matches. -- User is not allowed to execute the command (`syscmdkeys.CMD_NOPERM`) - Default is to display the "Huh?" error message. -- Channel (`syscmdkeys.CMD_CHANNEL`) - This is a [Channel](./Communications) name of a channel you are subscribing to - Default is to relay the command's argument to that channel. Such commands are created by the Comm system on the fly depending on your subscriptions. -- New session connection (`syscmdkeys.CMD_LOGINSTART`). This command name should be put in the `settings.CMDSET_UNLOGGEDIN`. Whenever a new connection is established, this command is always called on the server (default is to show the login screen). +- No input (`syscmdkeys.CMD_NOINPUT`) - the account just pressed return without any input. Default +is to do nothing, but it can be useful to do something here for certain implementations such as line +editors that interpret non-commands as text input (an empty line in the editing buffer). +- Command not found (`syscmdkeys.CMD_NOMATCH`) - No matching command was found. Default is to +display the "Huh?" error message. +- Several matching commands where found (`syscmdkeys.CMD_MULTIMATCH`) - Default is to show a list of +matches. +- User is not allowed to execute the command (`syscmdkeys.CMD_NOPERM`) - Default is to display the +"Huh?" error message. +- Channel (`syscmdkeys.CMD_CHANNEL`) - This is a [Channel](./Communications) name of a channel you are +subscribing to - Default is to relay the command's argument to that channel. Such commands are +created by the Comm system on the fly depending on your subscriptions. +- New session connection (`syscmdkeys.CMD_LOGINSTART`). This command name should be put in the +`settings.CMDSET_UNLOGGEDIN`. Whenever a new connection is established, this command is always +called on the server (default is to show the login screen). -Below is an example of redefining what happens when the account doesn't provide any input (e.g. just presses return). Of course the new system command must be added to a cmdset as well before it will work. +Below is an example of redefining what happens when the account doesn't provide any input (e.g. just +presses return). Of course the new system command must be added to a cmdset as well before it will +work. ```python from evennia import syscmdkeys, Command @@ -321,9 +482,13 @@ Below is an example of redefining what happens when the account doesn't provide *Note: This is an advanced topic.* -Normally Commands are created as fixed classes and used without modification. There are however situations when the exact key, alias or other properties is not possible (or impractical) to pre-code ([Exits](./Commands#Exits) is an example of this). +Normally Commands are created as fixed classes and used without modification. There are however +situations when the exact key, alias or other properties is not possible (or impractical) to pre- +code ([Exits](./Commands#Exits) is an example of this). -To create a command with a dynamic call signature, first define the command body normally in a class (set your `key`, `aliases` to default values), then use the following call (assuming the command class you created is named `MyCommand`): +To create a command with a dynamic call signature, first define the command body normally in a class +(set your `key`, `aliases` to default values), then use the following call (assuming the command +class you created is named `MyCommand`): ```python cmd = MyCommand(key="newname", @@ -332,9 +497,12 @@ To create a command with a dynamic call signature, first define the command body ...) ``` -*All* keyword arguments you give to the Command constructor will be stored as a property on the command object. This will overload existing properties defined on the parent class. +*All* keyword arguments you give to the Command constructor will be stored as a property on the +command object. This will overload existing properties defined on the parent class. -Normally you would define your class and only overload things like `key` and `aliases` at run-time. But you could in principle also send method objects (like `func`) as keyword arguments in order to make your command completely customized at run-time. +Normally you would define your class and only overload things like `key` and `aliases` at run-time. +But you could in principle also send method objects (like `func`) as keyword arguments in order to +make your command completely customized at run-time. ## Exits @@ -342,14 +510,28 @@ Normally you would define your class and only overload things like `key` and `al Exits are examples of the use of a [Dynamic Command](./Commands#Dynamic_Commands). -The functionality of [Exit](./Objects) objects in Evennia is not hard-coded in the engine. Instead Exits are normal [typeclassed](./Typeclasses) objects that auto-create a [CmdSet](./Commands#CmdSets) on themselves when they load. This cmdset has a single dynamically created Command with the same properties (key, aliases and locks) as the Exit object itself. When entering the name of the exit, this dynamic exit-command is triggered and (after access checks) moves the Character to the exit's destination. -Whereas you could customize the Exit object and its command to achieve completely different behaviour, you will usually be fine just using the appropriate `traverse_*` hooks on the Exit object. But if you are interested in really changing how things work under the hood, check out `evennia/objects/objects.py` for how the `Exit` typeclass is set up. +The functionality of [Exit](./Objects) objects in Evennia is not hard-coded in the engine. Instead +Exits are normal [typeclassed](./Typeclasses) objects that auto-create a [CmdSet](./Commands#CmdSets) on +themselves when they load. This cmdset has a single dynamically created Command with the same +properties (key, aliases and locks) as the Exit object itself. When entering the name of the exit, +this dynamic exit-command is triggered and (after access checks) moves the Character to the exit's +destination. +Whereas you could customize the Exit object and its command to achieve completely different +behaviour, you will usually be fine just using the appropriate `traverse_*` hooks on the Exit +object. But if you are interested in really changing how things work under the hood, check out +`evennia/objects/objects.py` for how the `Exit` typeclass is set up. ## Command instances are re-used *Note: This is an advanced topic that can be skipped when first learning about Commands.* -A Command class sitting on an object is instantiated once and then re-used. So if you run a command from object1 over and over you are in fact running the same command instance over and over (if you run the same command but sitting on object2 however, it will be a different instance). This is usually not something you'll notice, since every time the Command-instance is used, all the relevant properties on it will be overwritten. But armed with this knowledge you can implement some of the more exotic command mechanism out there, like the command having a 'memory' of what you last entered so that you can back-reference the previous arguments etc. +A Command class sitting on an object is instantiated once and then re-used. So if you run a command +from object1 over and over you are in fact running the same command instance over and over (if you +run the same command but sitting on object2 however, it will be a different instance). This is +usually not something you'll notice, since every time the Command-instance is used, all the relevant +properties on it will be overwritten. But armed with this knowledge you can implement some of the +more exotic command mechanism out there, like the command having a 'memory' of what you last entered +so that you can back-reference the previous arguments etc. > Note: On a server reload, all Commands are rebuilt and memory is flushed. @@ -386,7 +568,8 @@ Note how the in-memory address of the `testid` command never changes, but `xval` *This is also an advanced topic.* -Commands can also be created and added to a cmdset on the fly. Creating a class instance with a keyword argument, will assign that keyword argument as a property on this paricular command: +Commands can also be created and added to a cmdset on the fly. Creating a class instance with a +keyword argument, will assign that keyword argument as a property on this paricular command: ``` class MyCmdSet(CmdSet): @@ -397,39 +580,64 @@ class MyCmdSet(CmdSet): ``` -This will start the `MyCommand` with `myvar` and `foo` set as properties (accessable as `self.myvar` and `self.foo`). How they are used is up to the Command. Remember however the discussion from the previous section - since the Command instance is re-used, those properties will *remain* on the command as long as this cmdset and the object it sits is in memory (i.e. until the next reload). Unless `myvar` and `foo` are somehow reset when the command runs, they can be modified and that change will be remembered for subsequent uses of the command. +This will start the `MyCommand` with `myvar` and `foo` set as properties (accessable as `self.myvar` +and `self.foo`). How they are used is up to the Command. Remember however the discussion from the +previous section - since the Command instance is re-used, those properties will *remain* on the +command as long as this cmdset and the object it sits is in memory (i.e. until the next reload). +Unless `myvar` and `foo` are somehow reset when the command runs, they can be modified and that +change will be remembered for subsequent uses of the command. ## How commands actually work *Note: This is an advanced topic mainly of interest to server developers.* -Any time the user sends text to Evennia, the server tries to figure out if the text entered corresponds to a known command. This is how the command handler sequence looks for a logged-in user: +Any time the user sends text to Evennia, the server tries to figure out if the text entered +corresponds to a known command. This is how the command handler sequence looks for a logged-in user: 1. A user enters a string of text and presses enter. -2. The user's Session determines the text is not some protocol-specific control sequence or OOB command, but sends it on to the command handler. -3. Evennia's *command handler* analyzes the Session and grabs eventual references to Account and eventual puppeted Characters (these will be stored on the command object later). The *caller* property is set appropriately. -4. If input is an empty string, resend command as `CMD_NOINPUT`. If no such command is found in cmdset, ignore. +2. The user's Session determines the text is not some protocol-specific control sequence or OOB +command, but sends it on to the command handler. +3. Evennia's *command handler* analyzes the Session and grabs eventual references to Account and +eventual puppeted Characters (these will be stored on the command object later). The *caller* +property is set appropriately. +4. If input is an empty string, resend command as `CMD_NOINPUT`. If no such command is found in +cmdset, ignore. 5. If command.key matches `settings.IDLE_COMMAND`, update timers but don't do anything more. 6. The command handler gathers the CmdSets available to *caller* at this time: - The caller's own currently active CmdSet. - CmdSets defined on the current account, if caller is a puppeted object. - CmdSets defined on the Session itself. - - The active CmdSets of eventual objects in the same location (if any). This includes commands on [Exits](./Objects#Exits). - - Sets of dynamically created *System commands* representing available [Communications](./Communications#Channels). -7. All CmdSets *of the same priority* are merged together in groups. Grouping avoids order-dependent issues of merging multiple same-prio sets onto lower ones. -8. All the grouped CmdSets are *merged* in reverse priority into one combined CmdSet according to each set's merge rules. -9. Evennia's *command parser* takes the merged cmdset and matches each of its commands (using its key and aliases) against the beginning of the string entered by *caller*. This produces a set of candidates. -10. The *cmd parser* next rates the matches by how many characters they have and how many percent matches the respective known command. Only if candidates cannot be separated will it return multiple matches. - - If multiple matches were returned, resend as `CMD_MULTIMATCH`. If no such command is found in cmdset, return hard-coded list of matches. - - If no match was found, resend as `CMD_NOMATCH`. If no such command is found in cmdset, give hard-coded error message. -11. If a single command was found by the parser, the correct command object is plucked out of storage. This usually doesn't mean a re-initialization. -12. It is checked that the caller actually has access to the command by validating the *lockstring* of the command. If not, it is not considered as a suitable match and `CMD_NOMATCH` is triggered. -13. If the new command is tagged as a channel-command, resend as `CMD_CHANNEL`. If no such command is found in cmdset, use hard-coded implementation. + - The active CmdSets of eventual objects in the same location (if any). This includes commands +on [Exits](./Objects#Exits). + - Sets of dynamically created *System commands* representing available +[Communications](./Communications#Channels). +7. All CmdSets *of the same priority* are merged together in groups. Grouping avoids order- +dependent issues of merging multiple same-prio sets onto lower ones. +8. All the grouped CmdSets are *merged* in reverse priority into one combined CmdSet according to +each set's merge rules. +9. Evennia's *command parser* takes the merged cmdset and matches each of its commands (using its +key and aliases) against the beginning of the string entered by *caller*. This produces a set of +candidates. +10. The *cmd parser* next rates the matches by how many characters they have and how many percent +matches the respective known command. Only if candidates cannot be separated will it return multiple +matches. + - If multiple matches were returned, resend as `CMD_MULTIMATCH`. If no such command is found in +cmdset, return hard-coded list of matches. + - If no match was found, resend as `CMD_NOMATCH`. If no such command is found in cmdset, give +hard-coded error message. +11. If a single command was found by the parser, the correct command object is plucked out of +storage. This usually doesn't mean a re-initialization. +12. It is checked that the caller actually has access to the command by validating the *lockstring* +of the command. If not, it is not considered as a suitable match and `CMD_NOMATCH` is triggered. +13. If the new command is tagged as a channel-command, resend as `CMD_CHANNEL`. If no such command +is found in cmdset, use hard-coded implementation. 14. Assign several useful variables to the command instance (see previous sections). 15. Call `at_pre_command()` on the command instance. -16. Call `parse()` on the command instance. This is fed the remainder of the string, after the name of the command. It's intended to pre-parse the string into a form useful for the `func()` method. -17. Call `func()` on the command instance. This is the functional body of the command, actually doing useful things. +16. Call `parse()` on the command instance. This is fed the remainder of the string, after the name +of the command. It's intended to pre-parse the string into a form useful for the `func()` method. +17. Call `func()` on the command instance. This is the functional body of the command, actually +doing useful things. 18. Call `at_post_command()` on the command instance. ## Assorted notes @@ -447,6 +655,9 @@ thus do so asynchronously, using callbacks. deferred.addCallback(callback, self.caller) ``` -This is probably not relevant to any but the most advanced/exotic designs (one might use it to create a "nested" command structure for example). +This is probably not relevant to any but the most advanced/exotic designs (one might use it to +create a "nested" command structure for example). -The `save_for_next` class variable can be used to implement state-persistent commands. For example it can make a command operate on "it", where it is determined by what the previous command operated on. +The `save_for_next` class variable can be used to implement state-persistent commands. For example +it can make a command operate on "it", where it is determined by what the previous command operated +on. diff --git a/docs/source/Communications.md b/docs/source/Communications.md index e64496949e..dba169650a 100644 --- a/docs/source/Communications.md +++ b/docs/source/Communications.md @@ -1,58 +1,100 @@ # Communications -Apart from moving around in the game world and talking, players might need other forms of communication. This is offered by Evennia's `Comm` system. Stock evennia implements a 'MUX-like' system of channels, but there is nothing stopping you from changing things to better suit your taste. +Apart from moving around in the game world and talking, players might need other forms of +communication. This is offered by Evennia's `Comm` system. Stock evennia implements a 'MUX-like' +system of channels, but there is nothing stopping you from changing things to better suit your +taste. -Comms rely on two main database objects - `Msg` and `Channel`. There is also the `TempMsg` which mimics the API of a `Msg` but has no connection to the database. +Comms rely on two main database objects - `Msg` and `Channel`. There is also the `TempMsg` which +mimics the API of a `Msg` but has no connection to the database. ## Msg -The `Msg` object is the basic unit of communication in Evennia. A message works a little like an e-mail; it always has a sender (a [Account](./Accounts)) and one or more recipients. The recipients may be either other Accounts, or a *Channel* (see below). You can mix recipients to send the message to both Channels and Accounts if you like. +The `Msg` object is the basic unit of communication in Evennia. A message works a little like an +e-mail; it always has a sender (a [Account](./Accounts)) and one or more recipients. The recipients +may be either other Accounts, or a *Channel* (see below). You can mix recipients to send the message +to both Channels and Accounts if you like. -Once created, a `Msg` is normally not changed. It is peristently saved in the database. This allows for comprehensive logging of communications. This could be useful for allowing senders/receivers to have 'mailboxes' with the messages they want to keep. +Once created, a `Msg` is normally not changed. It is peristently saved in the database. This allows +for comprehensive logging of communications. This could be useful for allowing senders/receivers to +have 'mailboxes' with the messages they want to keep. ### Properties defined on `Msg` -- `senders` - this is a reference to one or many [Account](./Accounts) or [Objects](./Objects) (normally *Characters*) sending the message. This could also be an *External Connection* such as a message coming in over IRC/IMC2 (see below). There is usually only one sender, but the types can also be mixed in any combination. -- `receivers` - a list of target [Accounts](./Accounts), [Objects](./Objects) (usually *Characters*) or *Channels* to send the message to. The types of receivers can be mixed in any combination. -- `header` - this is a text field for storing a title or header for the message. +- `senders` - this is a reference to one or many [Account](./Accounts) or [Objects](./Objects) (normally +*Characters*) sending the message. This could also be an *External Connection* such as a message +coming in over IRC/IMC2 (see below). There is usually only one sender, but the types can also be +mixed in any combination. +- `receivers` - a list of target [Accounts](./Accounts), [Objects](./Objects) (usually *Characters*) or +*Channels* to send the message to. The types of receivers can be mixed in any combination. +- `header` - this is a text field for storing a title or header for the message. - `message` - the actual text being sent. - `date_sent` - when message was sent (auto-created). - `locks` - a [lock definition](./Locks). -- `hide_from` - this can optionally hold a list of objects, accounts or channels to hide this `Msg` from. This relationship is stored in the database primarily for optimization reasons, allowing for quickly post-filter out messages not intended for a given target. There is no in-game methods for setting this, it's intended to be done in code. +- `hide_from` - this can optionally hold a list of objects, accounts or channels to hide this `Msg` +from. This relationship is stored in the database primarily for optimization reasons, allowing for +quickly post-filter out messages not intended for a given target. There is no in-game methods for +setting this, it's intended to be done in code. -You create new messages in code using `evennia.create_message` (or `evennia.utils.create.create_message.`) +You create new messages in code using `evennia.create_message` (or +`evennia.utils.create.create_message.`) ## TempMsg -`evennia.comms.models` also has `TempMsg` which mimics the API of `Msg` but is not connected to the database. TempMsgs are used by Evennia for channel messages by default. They can be used for any system expecting a `Msg` but when you don't actually want to save anything. +`evennia.comms.models` also has `TempMsg` which mimics the API of `Msg` but is not connected to the +database. TempMsgs are used by Evennia for channel messages by default. They can be used for any +system expecting a `Msg` but when you don't actually want to save anything. ## Channels -Channels are [Typeclassed](./Typeclasses) entities, which mean they can be easily extended and their functionality modified. To change which channel typeclass Evennia uses, change settings.BASE_CHANNEL_TYPECLASS. +Channels are [Typeclassed](./Typeclasses) entities, which mean they can be easily extended and their +functionality modified. To change which channel typeclass Evennia uses, change +settings.BASE_CHANNEL_TYPECLASS. -Channels act as generic distributors of messages. Think of them as "switch boards" redistributing `Msg` or `TempMsg` objects. Internally they hold a list of "listening" objects and any `Msg` (or `TempMsg`) sent to the channel will be distributed out to all channel listeners. Channels have [Locks](./Locks) to limit who may listen and/or send messages through them. +Channels act as generic distributors of messages. Think of them as "switch boards" redistributing +`Msg` or `TempMsg` objects. Internally they hold a list of "listening" objects and any `Msg` (or +`TempMsg`) sent to the channel will be distributed out to all channel listeners. Channels have +[Locks](./Locks) to limit who may listen and/or send messages through them. -The *sending* of text to a channel is handled by a dynamically created [Command](./Commands) that always have the same name as the channel. This is created for each channel by the global `ChannelHandler`. The Channel command is added to the Account's cmdset and normal command locks are used to determine which channels are possible to write to. When subscribing to a channel, you can then just write the channel name and the text to send. +The *sending* of text to a channel is handled by a dynamically created [Command](./Commands) that +always have the same name as the channel. This is created for each channel by the global +`ChannelHandler`. The Channel command is added to the Account's cmdset and normal command locks are +used to determine which channels are possible to write to. When subscribing to a channel, you can +then just write the channel name and the text to send. -The default ChannelCommand (which can be customized by pointing `settings.CHANNEL_COMMAND_CLASS` to your own command), implements a few convenient features: +The default ChannelCommand (which can be customized by pointing `settings.CHANNEL_COMMAND_CLASS` to +your own command), implements a few convenient features: - - It only sends `TempMsg` objects. Instead of storing individual entries in the database it instead dumps channel output a file log in `server/logs/channel_.log`. This is mainly for practical reasons - we find one rarely need to query individual Msg objects at a later date. Just stupidly dumping the log to a file also means a lot less database overhead. - - It adds a `/history` switch to view the 20 last messages in the channel. These are read from the end of the log file. One can also supply a line number to start further back in the file (but always 20 entries at a time). It's used like this: + - It only sends `TempMsg` objects. Instead of storing individual entries in the database it instead +dumps channel output a file log in `server/logs/channel_.log`. This is mainly for +practical reasons - we find one rarely need to query individual Msg objects at a later date. Just +stupidly dumping the log to a file also means a lot less database overhead. + - It adds a `/history` switch to view the 20 last messages in the channel. These are read from the +end of the log file. One can also supply a line number to start further back in the file (but always +20 entries at a time). It's used like this: - > public/history + > public/history > public/history 35 -There are two default channels created in stock Evennia - `MudInfo` and `Public`. `MudInfo` receives server-related messages meant for Admins whereas `Public` is open to everyone to chat on (all new accounts are automatically joined to it when logging in, it is useful for asking questions). The default channels are defined by the `DEFAULT_CHANNELS` list (see `evennia/settings_default.py` for more details). +There are two default channels created in stock Evennia - `MudInfo` and `Public`. `MudInfo` +receives server-related messages meant for Admins whereas `Public` is open to everyone to chat on +(all new accounts are automatically joined to it when logging in, it is useful for asking +questions). The default channels are defined by the `DEFAULT_CHANNELS` list (see +`evennia/settings_default.py` for more details). You create new channels with `evennia.create_channel` (or `evennia.utils.create.create_channel`). -In code, messages are sent to a channel using the `msg` or `tempmsg` methods of channels: +In code, messages are sent to a channel using the `msg` or `tempmsg` methods of channels: channel.msg(msgobj, header=None, senders=None, persistent=True) -The argument `msgobj` can be either a string, a previously constructed `Msg` or a `TempMsg` - in the latter cases all the following keywords are ignored since the message objects already contains all this information. If `msgobj` is a string, the other keywords are used for creating a new `Msg` or `TempMsg` on the fly, depending on if `persistent` is set or not. By default, a `TempMsg` is emitted for channel communication (since the default ChannelCommand instead logs to a file). +The argument `msgobj` can be either a string, a previously constructed `Msg` or a `TempMsg` - in the +latter cases all the following keywords are ignored since the message objects already contains all +this information. If `msgobj` is a string, the other keywords are used for creating a new `Msg` or +`TempMsg` on the fly, depending on if `persistent` is set or not. By default, a `TempMsg` is emitted +for channel communication (since the default ChannelCommand instead logs to a file). ```python # assume we have a 'sender' object and a channel named 'mychan' @@ -67,4 +109,5 @@ The argument `msgobj` can be either a string, a previously constructed `Msg` or - `aliases` - alternative native names for channels - `desc` - optional description of channel (seen in listings) - `keep_log` (bool) - if the channel should store messages (default) -- `locks` - A [lock definition](./Locks). Channels normally use the access_types `send, control` and `listen`. \ No newline at end of file +- `locks` - A [lock definition](./Locks). Channels normally use the access_types `send, control` and +`listen`. \ No newline at end of file diff --git a/docs/source/Connection-Screen.md b/docs/source/Connection-Screen.md index 3b44c67a79..d0b4f37275 100644 --- a/docs/source/Connection-Screen.md +++ b/docs/source/Connection-Screen.md @@ -1,7 +1,7 @@ # Connection Screen -When you first connect to your game you are greeted by Evennia's default connection screen. +When you first connect to your game you are greeted by Evennia's default connection screen. ============================================================== @@ -16,10 +16,11 @@ When you first connect to your game you are greeted by Evennia's default connect Enter help for more info. look will re-show this screen. ============================================================== -Effective, but not very exciting. You will most likely want to change this to be more unique for your game. This is simple: +Effective, but not very exciting. You will most likely want to change this to be more unique for +your game. This is simple: 1. Edit `mygame/server/conf/connection_screens.py`. -1. [Reload](./Start-Stop-Reload) Evennia. +1. [Reload](./Start-Stop-Reload) Evennia. Evennia will look into this module and locate all *globally defined strings* in it. These strings are used as the text in your connection screen and are shown to the user at startup. If more than diff --git a/docs/source/Continuous-Integration.md b/docs/source/Continuous-Integration.md index 52c923ba0b..f6323cc9f3 100644 --- a/docs/source/Continuous-Integration.md +++ b/docs/source/Continuous-Integration.md @@ -20,22 +20,25 @@ For Evennia, continuous integration allows an automated build process to: * Reload the game. ## Preparation -To prepare a CI environment for your `MU*`, it will be necessary to set up some prerequisite software for your server. +To prepare a CI environment for your `MU*`, it will be necessary to set up some prerequisite +software for your server. Among those you will need: * A Continuous Integration Environment. - * I recommend [TeamCity](https://www.jetbrains.com/teamcity/) which has an in-depth [Setup Guide](https://confluence.jetbrains.com/display/TCD8/Installing+and+Configuring+the+TeamCity+Server) + * I recommend [TeamCity](https://www.jetbrains.com/teamcity/) which has an in-depth [Setup +Guide](https://confluence.jetbrains.com/display/TCD8/Installing+and+Configuring+the+TeamCity+Server) * [Source Control](./Version-Control) * This could be Git or SVN or any other available SC. ## Linux TeamCity Setup For this part of the guide, an example setup will be provided for administrators running a TeamCity -build integration environment on Linux. +build integration environment on Linux. After meeting the preparation steps for your specific environment, log on to your teamcity interface at `http://:8111/`. -Create a new project named "Evennia" and in it construct a new template called continuous-integration. +Create a new project named "Evennia" and in it construct a new template called continuous- +integration. ### A Quick Overview Templates are fancy objects in TeamCity that allow an administrator to define build steps that are @@ -59,18 +62,20 @@ flow. For this example, we will be doing a few basic example steps: For each step we'll being use the "Command Line Runner" (a fancy name for a shell script executor). * Create a build step with the name: Transform Configuration -* For the script add: +* For the script add: ```bash #!/bin/bash - # Replaces the game configuration with one + # Replaces the game configuration with one # appropriate for this deployment. CONFIG="%system.teamcity.build.checkoutDir%/server/conf/settings.py" MYCONF="%system.teamcity.build.checkoutDir%/server/conf/my.cnf" - sed -e 's/TELNET_PORTS = [4000]/TELNET_PORTS = [%game.ports%]/g' "$CONFIG" > "$CONFIG".tmp && mv "$CONFIG".tmp "$CONFIG" - sed -e 's/WEBSERVER_PORTS = [(4001, 4002)]/WEBSERVER_PORTS = [%game.webports%]/g' "$CONFIG" > "$CONFIG".tmp && mv "$CONFIG".tmp "$CONFIG" + sed -e 's/TELNET_PORTS = [4000]/TELNET_PORTS = [%game.ports%]/g' "$CONFIG" > "$CONFIG".tmp && mv +"$CONFIG".tmp "$CONFIG" + sed -e 's/WEBSERVER_PORTS = [(4001, 4002)]/WEBSERVER_PORTS = [%game.webports%]/g' "$CONFIG" > +"$CONFIG".tmp && mv "$CONFIG".tmp "$CONFIG" # settings.py MySQL DB configuration echo Configuring Game Database... @@ -102,7 +107,8 @@ parameters that are populated when the build itself is ran. When creating projec template, we'll be able to fill in or override those parameters for project-specific configuration. * Go ahead and create another build step called "Make Database Migration" - * If you're using SQLLite on your game, it will be prudent to change working directory on this step to: %game.dir% + * If you're using SQLLite on your game, it will be prudent to change working directory on this +step to: %game.dir% * In this script include: ```bash @@ -123,7 +129,8 @@ template, we'll be able to fill in or override those parameters for project-spec ``` * Create yet another build step, this time named: "Execute Database Migration": - * If you're using SQLLite on your game, it will be prudent to change working directory on this step to: %game.dir% + * If you're using SQLLite on your game, it will be prudent to change working directory on this +step to: %game.dir% ```bash #!/bin/bash # Apply the database migration. @@ -147,7 +154,8 @@ done in a 'work' directory on TeamCity's build agent. From that directory we wil to where our game actually exists on the local server. * Create a new build step called "Publish Build": - * If you're using SQLLite on your game, be sure to order this step ABOVE the Database Migration steps. The build order will matter! + * If you're using SQLLite on your game, be sure to order this step ABOVE the Database Migration +steps. The build order will matter! ```bash #!/bin/bash # Publishes the build to the proper build directory. @@ -198,14 +206,16 @@ set the evenv parameter to the directory where your virtualenv exists: IE "/srv/ Now it's time for the last few steps to set up a CI environment. -* Return to the Evennia Project overview/administration page. +* Return to the Evennia Project overview/administration page. * Create a new Sub-Project called "Production" * This will be the category that holds our actual game. * Create a new Build Configuration in Production with the name of your MUSH. * Base this configuration off of the continuous-integration template we made earlier. -* In the build configuration, enter VCS roots and create a new VCS root that points to the branch/version control that you are using. +* In the build configuration, enter VCS roots and create a new VCS root that points to the +branch/version control that you are using. * Go to the parameters page and fill in the undefined parameters for your specific configuration. -* If you wish for the CI to run every time a commit is made, go to the VCS triggers and add one for "On Every Commit". +* If you wish for the CI to run every time a commit is made, go to the VCS triggers and add one for +"On Every Commit". And you're done! At this point, you can return to the project overview page and queue a new build for your game. If everything was set up correctly, the build will complete successfully. Additional diff --git a/docs/source/Contributing.md b/docs/source/Contributing.md index 8735648cc4..a26229fa42 100644 --- a/docs/source/Contributing.md +++ b/docs/source/Contributing.md @@ -1,7 +1,7 @@ # Contributing -Wanna help out? Great! Here's how. +Wanna help out? Great! Here's how. ## Spreading the word @@ -18,7 +18,7 @@ open-source project and any monetary donations you want to offer are completely a way of announcing that you appreciate the work done - a tip of the hat! A patron donates a (usually small) sum every month to show continued support. If this is not your thing you can also show your appreciation via a [one-time donation][donate] (this is a PayPal link but you don't need -PayPal yourself). +PayPal yourself). ## Help with Documentation @@ -37,8 +37,9 @@ We always need more eyes and hands on the code. Even if you don't feel confident and reporting when stuff doesn't make sense helps us a lot. The most elegant way to contribute code to Evennia is to use GitHub to create a *fork* of the -Evennia repository and make your changes to that. Refer to the [Forking Evennia](./Version-Control#forking-evennia) version -control instructions for detailed instructions. +Evennia repository and make your changes to that. Refer to the [Forking Evennia](Version- +Control#forking-evennia) version +control instructions for detailed instructions. Once you have a fork set up, you can not only work on your own game in a separate branch, you can also commit your fixes to Evennia itself. Make separate branches for all Evennia additions you do - @@ -56,7 +57,7 @@ fixes/addendums as a [patch][patch]. You can include your patch in an Issue or a Mailing list post. Please avoid pasting the full patch text directly in your post though, best is to use a site like [Pastebin](http://pastebin.com/) and -just supply the link. +just supply the link. ## Contributing with Contribs @@ -65,23 +66,53 @@ directory contains game systems that are specialized or useful only to certain t are welcome to contribute to the `contrib/` directory. Such contributions should always happen via a Forked repository as described above. -* If you are unsure if your idea/code is suitable as a contrib, *ask the devs before putting any work into it*. This can also be a good idea in order to not duplicate efforts. This can also act as a check that your implementation idea is sound. We are, for example, unlikely to accept contribs that require large modifications of the game directory structure. -* If your code is intended *primarily* as an example or shows a concept/principle rather than a working system, it is probably not suitable for `contrib/`. You are instead welcome to use it as part of a [new tutorial][tutorials]! -* The code should ideally be contained within a single Python module. But if the contribution is large this may not be practical and it should instead be grouped in its own subdirectory (not as loose modules). -* The contribution should preferably be isolated (only make use of core Evennia) so it can easily be dropped into use. If it does depend on other contribs or third-party modules, these must be clearly documented and part of the installation instructions. +* If you are unsure if your idea/code is suitable as a contrib, *ask the devs before putting any +work into it*. This can also be a good idea in order to not duplicate efforts. This can also act as +a check that your implementation idea is sound. We are, for example, unlikely to accept contribs +that require large modifications of the game directory structure. +* If your code is intended *primarily* as an example or shows a concept/principle rather than a +working system, it is probably not suitable for `contrib/`. You are instead welcome to use it as +part of a [new tutorial][tutorials]! +* The code should ideally be contained within a single Python module. But if the contribution is +large this may not be practical and it should instead be grouped in its own subdirectory (not as +loose modules). +* The contribution should preferably be isolated (only make use of core Evennia) so it can easily be +dropped into use. If it does depend on other contribs or third-party modules, these must be clearly +documented and part of the installation instructions. * The code itself should follow Evennia's [Code style guidelines][codestyle]. -* The code must be well documented as described in our [documentation style guide](https://github.com/evennia/evennia/blob/master/CODING_STYLE.md#doc-strings). Expect that your code will be read and should be possible to understand by others. Include comments as well as a header in all modules. If a single file, the header should include info about how to include the contrib in a game (installation instructions). If stored in a subdirectory, this info should go into a new `README.md` file within that directory. -* Within reason, your contribution should be designed as genre-agnostic as possible. Limit the amount of game-style-specific code. Assume your code will be applied to a very different game than you had in mind when creating it. -* To make the licensing situation clear we assume all contributions are released with the same [license as Evennia](./Licensing). If this is not possible for some reason, talk to us and we'll handle it on a case-by-case basis. -* Your contribution must be covered by [unit tests](./Unit-Testing). Having unit tests will both help make your code more stable and make sure small changes does not break it without it being noticed, it will also help us test its functionality and merge it quicker. If your contribution is a single module, you can add your unit tests to `evennia/contribs/tests.py`. If your contribution is bigger and in its own sub-directory you could just put the tests in your own `tests.py` file (Evennia will find it automatically). -* Merging of your code into Evennia is not guaranteed. Be ready to receive feedback and to be asked to make corrections or fix bugs. Furthermore, merging a contrib means the Evennia project takes on the responsibility of maintaining and supporting it. For various reasons this may be deemed to be beyond our manpower. However, if your code were to *not* be accepted for merger for some reason, we will instead add a link to your online repository so people can still find and use your work if they want. +* The code must be well documented as described in our [documentation style +guide](https://github.com/evennia/evennia/blob/master/CODING_STYLE.md#doc-strings). Expect that your +code will be read and should be possible to understand by others. Include comments as well as a +header in all modules. If a single file, the header should include info about how to include the +contrib in a game (installation instructions). If stored in a subdirectory, this info should go into +a new `README.md` file within that directory. +* Within reason, your contribution should be designed as genre-agnostic as possible. Limit the +amount of game-style-specific code. Assume your code will be applied to a very different game than +you had in mind when creating it. +* To make the licensing situation clear we assume all contributions are released with the same +[license as Evennia](./Licensing). If this is not possible for some reason, talk to us and we'll +handle it on a case-by-case basis. +* Your contribution must be covered by [unit tests](./Unit-Testing). Having unit tests will both help +make your code more stable and make sure small changes does not break it without it being noticed, +it will also help us test its functionality and merge it quicker. If your contribution is a single +module, you can add your unit tests to `evennia/contribs/tests.py`. If your contribution is bigger +and in its own sub-directory you could just put the tests in your own `tests.py` file (Evennia will +find it automatically). +* Merging of your code into Evennia is not guaranteed. Be ready to receive feedback and to be asked +to make corrections or fix bugs. Furthermore, merging a contrib means the Evennia project takes on +the responsibility of maintaining and supporting it. For various reasons this may be deemed to be +beyond our manpower. However, if your code were to *not* be accepted for merger for some reason, we +will instead add a link to your online repository so people can still find and use your work if they +want. [ohloh]: http://www.ohloh.net/p/evennia [patron]: https://www.patreon.com/griatch -[donate]: https://www.paypal.com/en/cgi-bin/webscr?cmd=_flow&SESSION=TWy_epDPSWqNr4UJCOtVWxl-pO1X1jbKiv_-UBBFWIuVDEZxC0M_2pM6ywO&dispatch=5885d80a13c0db1f8e263663d3faee8d66f31424b43e9a70645c907a6cbd8fb4 +[donate]: https://www.paypal.com/en/cgi-bin/webscr?cmd=_flow&SESSION=TWy_epDPSWqNr4UJCOtVWxl- +pO1X1jbKiv_- +UBBFWIuVDEZxC0M_2pM6ywO&dispatch=5885d80a13c0db1f8e263663d3faee8d66f31424b43e9a70645c907a6cbd8fb4 [forking]: https://github.com/evennia/evennia/wiki/Version-Control#wiki-forking-from-evennia [pullrequest]: https://github.com/evennia/evennia/pulls [issues]: https://github.com/evennia/evennia/issues -[patch]: https://secure.wikimedia.org/wikipedia/en/wiki/Patch_%28computing%29 +[patch]: https://secure.wikimedia.org/wikipedia/en/wiki/Patch_%28computing%29 [codestyle]: https://github.com/evennia/evennia/blob/master/CODING_STYLE.md [tutorials]: https://github.com/evennia/evennia/wiki/Tutorials diff --git a/docs/source/Coordinates.md b/docs/source/Coordinates.md index f73b950755..410b779c95 100644 --- a/docs/source/Coordinates.md +++ b/docs/source/Coordinates.md @@ -4,7 +4,9 @@ This tutorial is moderately difficult in content. You might want to be familiar and at ease with some Python concepts (like properties) and possibly Django concepts (like queries), although this -tutorial will try to walk you through the process and give enough explanations each time. If you don't feel very confident with math, don't hesitate to pause, go to the example section, which shows a tiny map, and try to walk around the code or read the explanation. +tutorial will try to walk you through the process and give enough explanations each time. If you +don't feel very confident with math, don't hesitate to pause, go to the example section, which shows +a tiny map, and try to walk around the code or read the explanation. Evennia doesn't have a coordinate system by default. Rooms and other objects are linked by location and content: @@ -97,7 +99,8 @@ class Room(DefaultRoom): ``` If you aren't familiar with the concept of properties in Python, I encourage you to read a good -tutorial on the subject. [This article on Python properties](https://www.programiz.com/python-programming/property) +tutorial on the subject. [This article on Python properties](https://www.programiz.com/python- +programming/property) is well-explained and should help you understand the idea. Let's look at our properties for `x`. First of all is the read property. @@ -170,7 +173,8 @@ class methods, since we want to get rooms. ### Finding one room -First, a simple one: how to find a room at a given coordinate? Say, what is the room at X=0, Y=0, Z=0? +First, a simple one: how to find a room at a given coordinate? Say, what is the room at X=0, Y=0, +Z=0? ```python class Room(DefaultRoom): @@ -199,7 +203,8 @@ class Room(DefaultRoom): return None ``` -This solution includes a bit of [Django queries](https://docs.djangoproject.com/en/1.11/topics/db/queries/). +This solution includes a bit of [Django +queries](https://docs.djangoproject.com/en/1.11/topics/db/queries/). Basically, what we do is reach for the object manager and search for objects with the matching tags. Again, don't spend too much time worrying about the mechanism, the method is quite easy to use: @@ -207,14 +212,16 @@ Again, don't spend too much time worrying about the mechanism, the method is qui Room.get_room_at(5, 2, -3) ``` -Notice that this is a class method: you will call it from `Room` (the class), not an instance. Though you still can: +Notice that this is a class method: you will call it from `Room` (the class), not an instance. +Though you still can: @py here.get_room_at(3, 8, 0) ### Finding several rooms Here's another useful method that allows us to look for rooms around a given coordinate. This is -more advanced search and doing some calculation, beware! Look at the following section if you're lost. +more advanced search and doing some calculation, beware! Look at the following section if you're +lost. ```python from math import sqrt @@ -280,7 +287,8 @@ This gets more serious. 1. We have specified coordinates as parameters. We determine a broad range using the distance. That is, for each coordinate, we create a list of possible matches. See the example below. 2. We then search for the rooms within this broader range. It gives us a square - around our location. Some rooms are definitely outside the range. Again, see the example below to follow the logic. + around our location. Some rooms are definitely outside the range. Again, see the example below +to follow the logic. 3. We filter down the list and sort it by distance from the specified coordinates. Notice that we only search starting at step 2. Thus, the Django search doesn't look and cache all @@ -301,7 +309,10 @@ An example might help. Consider this very simple map (a textual description fol 1 2 3 4 ``` -The X coordinates are given below. The Y coordinates are given on the left. This is a simple square with 16 rooms: 4 on each line, 4 lines of them. All the rooms are identified by letters in this example: the first line at the top has rooms A to D, the second E to H, the third I to L and the fourth M to P. The bottom-left room, X=1 and Y=1, is M. The upper-right room X=4 and Y=4 is D. +The X coordinates are given below. The Y coordinates are given on the left. This is a simple +square with 16 rooms: 4 on each line, 4 lines of them. All the rooms are identified by letters in +this example: the first line at the top has rooms A to D, the second E to H, the third I to L and +the fourth M to P. The bottom-left room, X=1 and Y=1, is M. The upper-right room X=4 and Y=4 is D. So let's say we want to find all the neighbors, distance 1, from the room J. J is at X=2, Y=2. @@ -310,8 +321,12 @@ So we use: Room.get_rooms_around(x=2, y=2, z=0, distance=1) # we'll assume a z coordinate of 0 for simplicity -1. First, this method gets all the rooms in a square around J. So it gets E F G, I J K, M N O. If you want, draw the square around these coordinates to see what's happening. -2. Next, we browse over this list and check the real distance between J (X=2, Y=2) and the room. The four corners of the square are not in this circle. For instance, the distance between J and M is not 1. If you draw a circle of center J and radius 1, you'll notice that the four corners of our square (E, G, M and O) are not in this circle. So we remove them. +1. First, this method gets all the rooms in a square around J. So it gets E F G, I J K, M N O. If +you want, draw the square around these coordinates to see what's happening. +2. Next, we browse over this list and check the real distance between J (X=2, Y=2) and the room. +The four corners of the square are not in this circle. For instance, the distance between J and M +is not 1. If you draw a circle of center J and radius 1, you'll notice that the four corners of our +square (E, G, M and O) are not in this circle. So we remove them. 3. We sort by distance from J. So in the end we might obtain something like this: diff --git a/docs/source/Custom-Protocols.md b/docs/source/Custom-Protocols.md index 481050e66b..805e7c4f0c 100644 --- a/docs/source/Custom-Protocols.md +++ b/docs/source/Custom-Protocols.md @@ -5,27 +5,32 @@ their own custom client protocol.* -A [PortalSession](./Sessions#Portal-and-Server-Sessions) is the basic data object representing an external +A [PortalSession](./Sessions#Portal-and-Server-Sessions) is the basic data object representing an +external connection to the Evennia [Portal](./Portal-And-Server) -- usually a human player running a mud client of some kind. The way they connect (the language the player's client and Evennia use to talk to each other) is called the connection *Protocol*. The most common such protocol for MUD:s is the *Telnet* protocol. All Portal Sessions are stored and managed by the Portal's *sessionhandler*. It's technically sometimes hard to separate the concept of *PortalSession* from the concept of -*Protocol* since both depend heavily on the other (they are often created as the same class). When data flows through this part of the system, this is how it goes +*Protocol* since both depend heavily on the other (they are often created as the same class). When +data flows through this part of the system, this is how it goes ``` # In the Portal -You <-> - Protocol + PortalSession <-> +You <-> + Protocol + PortalSession <-> PortalSessionHandler <-> - (AMP) <-> + (AMP) <-> ServerSessionHandler <-> ServerSession <-> - InputFunc + InputFunc ``` -(See the [Message Path](./Messagepath) for the bigger picture of how data flows through Evennia). The parts that needs to be customized to make your own custom protocol is the `Protocol + PortalSession` (which translates between data coming in/out over the wire to/from Evennia internal representation) as well as the `InputFunc` (which handles incoming data). +(See the [Message Path](./Messagepath) for the bigger picture of how data flows through Evennia). The +parts that needs to be customized to make your own custom protocol is the `Protocol + PortalSession` +(which translates between data coming in/out over the wire to/from Evennia internal representation) +as well as the `InputFunc` (which handles incoming data). ## Adding custom Protocols @@ -47,7 +52,8 @@ modules, you could do the following: PORTAL_SERVICES_PLUGIN_MODULES.append('server.conf.my_portal_plugins') ``` -When adding a new connection you'll most likely only need to add new things to the `PORTAL_SERVICES_PLUGIN_MODULES`. +When adding a new connection you'll most likely only need to add new things to the +`PORTAL_SERVICES_PLUGIN_MODULES`. This module can contain whatever you need to define your protocol, but it *must* contain a function `start_plugin_services(app)`. This is called by the Portal as part of its upstart. The function @@ -93,27 +99,30 @@ Writing a stable communication protocol from scratch is not something we'll cove trivial task. The good news is that Twisted offers implementations of many common protocols, ready for adapting. -Writing a protocol implementation in Twisted usually involves creating a class inheriting from an already existing Twisted protocol class and from `evennia.server.session.Session` (multiple inheritance), then overloading the methods that particular protocol uses to link them to the Evennia-specific inputs. +Writing a protocol implementation in Twisted usually involves creating a class inheriting from an +already existing Twisted protocol class and from `evennia.server.session.Session` (multiple +inheritance), then overloading the methods that particular protocol uses to link them to the +Evennia-specific inputs. -Here's a example to show the concept: +Here's a example to show the concept: ```python # In module that we'll later add to the system through PORTAL_SERVICE_PLUGIN_MODULES -# pseudo code +# pseudo code from twisted.something import TwistedClient # this class is used both for Portal- and Server Sessions -from evennia.server.session import Session +from evennia.server.session import Session from evennia.server.portal.portalsessionhandler import PORTAL_SESSIONS -class MyCustomClient(TwistedClient, Session): +class MyCustomClient(TwistedClient, Session): - def __init__(self, *args, **kwargs): + def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.sessionhandler = PORTAL_SESSIONS - # these are methods we must know that TwistedClient uses for + # these are methods we must know that TwistedClient uses for # communication. Name and arguments could vary for different Twisted protocols def onOpen(self, *args, **kwargs): # let's say this is called when the client first connects @@ -131,39 +140,39 @@ class MyCustomClient(TwistedClient, Session): # link to the Evennia equivalent self.disconnect(reason) - def onMessage(self, indata, *args, **kwargs): + def onMessage(self, indata, *args, **kwargs): # called with incoming data - # convert as needed here - self.data_in(data=indata) + # convert as needed here + self.data_in(data=indata) def sendMessage(self, outdata, *args, **kwargs): # called to send data out - # modify if needed + # modify if needed super().sendMessage(self, outdata, *args, **kwargs) # these are Evennia methods. They must all exist and look exactly like this # The above twisted-methods call them and vice-versa. This connects the protocol - # the Evennia internals. + # the Evennia internals. - def disconnect(self, reason=None): + def disconnect(self, reason=None): """ - Called when connection closes. + Called when connection closes. This can also be called directly by Evennia when manually closing the connection. Do any cleanups here. """ self.sessionhandler.disconnect(self) - def at_login(self): + def at_login(self): """ Called when this session authenticates by the server (if applicable) - """ + """ def data_in(self, **kwargs): """ - Data going into the server should go through this method. It + Data going into the server should go through this method. It should pass data into `sessionhandler.data_in`. THis will be called - by the sessionhandler with the data it gets from the approrpriate - send_* method found later in this protocol. + by the sessionhandler with the data it gets from the approrpriate + send_* method found later in this protocol. """ self.sessionhandler.data_in(self, text=kwargs['data']) @@ -175,38 +184,46 @@ class MyCustomClient(TwistedClient, Session): # we assume we have a 'text' outputfunc self.onMessage(kwargs['text']) - # 'outputfuncs' are defined as `send_`. From in-code, they are called - # with `msg(outfunc_name=)`. + # 'outputfuncs' are defined as `send_`. From in-code, they are called + # with `msg(outfunc_name=)`. - def send_text(self, txt, *args, **kwargs): + def send_text(self, txt, *args, **kwargs): """ Send text, used with e.g. `session.msg(text="foo")` """ - # we make use of the + # we make use of the self.data_out(text=txt) - def send_default(self, cmdname, *args, **kwargs): + def send_default(self, cmdname, *args, **kwargs): """ Handles all outputfuncs without an explicit `send_*` method to handle them. """ self.data_out(**{cmdname: str(args)}) ``` -The principle here is that the Twisted-specific methods are overridden to redirect inputs/outputs to the Evennia-specific methods. +The principle here is that the Twisted-specific methods are overridden to redirect inputs/outputs to +the Evennia-specific methods. ### Sending data out -To send data out through this protocol, you'd need to get its Session and then you could e.g. +To send data out through this protocol, you'd need to get its Session and then you could e.g. ```python session.msg(text="foo") ``` -The message will pass through the system such that the sessionhandler will dig out the session and check if it has a `send_text` method (it has). It will then pass the "foo" into that method, which in our case means sending "foo" across the network. +The message will pass through the system such that the sessionhandler will dig out the session and +check if it has a `send_text` method (it has). It will then pass the "foo" into that method, which +in our case means sending "foo" across the network. -### Receiving data +### Receiving data -Just because the protocol is there, does not mean Evennia knows what to do with it. An [Inputfunc](./Inputfuncs) must exist to receive it. In the case of the `text` input exemplified above, Evennia alredy handles this input - it will parse it as a Command name followed by its inputs. So handle that you need to simply add a cmdset with commands on your receiving Session (and/or the Object/Character it is puppeting). If not you may need to add your own Inputfunc (see the [Inputfunc](./Inputfuncs) page for how to do this. +Just because the protocol is there, does not mean Evennia knows what to do with it. An +[Inputfunc](./Inputfuncs) must exist to receive it. In the case of the `text` input exemplified above, +Evennia alredy handles this input - it will parse it as a Command name followed by its inputs. So +handle that you need to simply add a cmdset with commands on your receiving Session (and/or the +Object/Character it is puppeting). If not you may need to add your own Inputfunc (see the +[Inputfunc](./Inputfuncs) page for how to do this. These might not be as clear-cut in all protocols, but the principle is there. These four basic components - however they are accessed - links to the *Portal Session*, which is the actual common @@ -219,4 +236,4 @@ websockets. You'll find that whereas telnet is a textbook example of a Twisted p above, the ajax protocol looks quite different due to how it interacts with the webserver through long-polling (comet) style requests. All the necessary parts mentioned above are still there, but by necessity implemented in very different -ways. +ways. diff --git a/docs/source/Customize-channels.md b/docs/source/Customize-channels.md index 7c548084af..aeed0f4cd4 100644 --- a/docs/source/Customize-channels.md +++ b/docs/source/Customize-channels.md @@ -15,7 +15,7 @@ So it may be useful even if you don't plan to make the exact changes shown here. Our mission: change the default channel commands to have a different syntax. -This tutorial will do the following changes: +This tutorial will do the following changes: - Remove all the default commands to handle channels. - Add a `+` and `-` command to join and leave a channel. So, assuming there is @@ -97,13 +97,25 @@ class CmdConnect(Command): Okay, let's review this code, but if you're used to Evennia commands, it shouldn't be too strange: -1. We import `search_channel`. This is a little helper function that we will use to search for channels by name and aliases, found in `evennia.utils.search`. It's just more convenient. +1. We import `search_channel`. This is a little helper function that we will use to search for +channels by name and aliases, found in `evennia.utils.search`. It's just more convenient. 2. Our class `CmdConnect` contains the body of our command to join a channel. -3. Notice the key of this command is simply `"+"`. When you enter `+something` in the game, it will try to find a command key `+something`. Failing that, it will look at other potential matches. Evennia is smart enough to understand that when we type `+something`, `+` is the command key and `something` is the command argument. This will, of course, fail if you have a command beginning by `+` conflicting with the `CmdConnect` key. -4. We have altered some class attributes, like `auto_help`. If you want to know what they do and why they have changed here, you can check the [documentation on commands](./Commands). -5. In the command body, we begin by extracting the channel name. Remember that this name should be in the command arguments (that is, in `self.args`). Following the same example, if a player enters `+something`, `self.args` should contain `"something"`. We use `search_channel` to see if this channel exists. -6. We then check the access level of the channel, to see if the caller can listen to it (not necessarily use it to speak, mind you, just listen to others speak, as these are two different locks on Evennia). -7. Finally, we connect the caller if he's not already connected to the channel. We use the channel's `connect` method to do this. Pretty straightforward eh? +3. Notice the key of this command is simply `"+"`. When you enter `+something` in the game, it will +try to find a command key `+something`. Failing that, it will look at other potential matches. +Evennia is smart enough to understand that when we type `+something`, `+` is the command key and +`something` is the command argument. This will, of course, fail if you have a command beginning by +`+` conflicting with the `CmdConnect` key. +4. We have altered some class attributes, like `auto_help`. If you want to know what they do and +why they have changed here, you can check the [documentation on commands](./Commands). +5. In the command body, we begin by extracting the channel name. Remember that this name should be +in the command arguments (that is, in `self.args`). Following the same example, if a player enters +`+something`, `self.args` should contain `"something"`. We use `search_channel` to see if this +channel exists. +6. We then check the access level of the channel, to see if the caller can listen to it (not +necessarily use it to speak, mind you, just listen to others speak, as these are two different locks +on Evennia). +7. Finally, we connect the caller if he's not already connected to the channel. We use the +channel's `connect` method to do this. Pretty straightforward eh? Now we'll add a command to leave a channel. It's almost the same, turned upside down: @@ -426,7 +438,8 @@ add: caller (TypedObject): A Character or Account who has entered an ambiguous command. Returns: - A string with identifying information to disambiguate the object, conventionally with a preceding space. + A string with identifying information to disambiguate the object, conventionally with a +preceding space. """ return " (channel)" ``` @@ -467,4 +480,5 @@ close from the code I've provided here. Notice, however, that this resource is external to Evennia and not maintained by anyone but the original author of this article. -[Read the full example on Github](https://github.com/vincent-lg/avenew/blob/master/commands/comms.py) +[Read the full example on Github](https://github.com/vincent- +lg/avenew/blob/master/commands/comms.py) diff --git a/docs/source/Debugging.md b/docs/source/Debugging.md index bbbffe099b..62e199037e 100644 --- a/docs/source/Debugging.md +++ b/docs/source/Debugging.md @@ -2,7 +2,8 @@ Sometimes, an error is not trivial to resolve. A few simple `print` statements is not enough to find -the cause of the issue. Running a *debugger* can then be very helpful and save a lot of time. Debugging +the cause of the issue. Running a *debugger* can then be very helpful and save a lot of time. +Debugging means running Evennia under control of a special *debugger* program. This allows you to stop the action at a given point, view the current state and step forward through the program to see how its logic works. @@ -87,7 +88,8 @@ in your console, and you will find it here. Below is an example with `pdb`. ### Listing surrounding lines of code -When you have the `pdb` prompt `(Pdb)`, you can type in different commands to explore the code. The first one you should know is `list` (you can type `l` for short): +When you have the `pdb` prompt `(Pdb)`, you can type in different commands to explore the code. The +first one you should know is `list` (you can type `l` for short): ``` (Pdb) l @@ -205,7 +207,8 @@ None (Pdb) ``` -We have entered the `test` command without parameter, so no object could be found in the search (`self.args` is an empty string). +We have entered the `test` command without parameter, so no object could be found in the search +(`self.args` is an empty string). Let's allow the command to continue and try to use an object name as parameter (although, we should fix that bug too, it would be better): @@ -279,12 +282,15 @@ command is not needed much in `pudb` since it displays the code directly in its | Pdb/PuDB command | To do what | | ----------- | ---------- | -| list (or l) | List the lines around the point of execution (not needed for `pudb`, it will show this directly). | +| list (or l) | List the lines around the point of execution (not needed for `pudb`, it will show +this directly). | | print (or p) | Display one or several variables. | | `!` | Run Python code (using a `!` is often optional). | | continue (or c) | Continue execution and terminate the debugger for this time. | | next (or n) | Execute the current line and goes to the next one. | | step (or s) | Step inside of a function or method to examine it. | -| `` | Repeat the last command (don't type `n` repeatedly, just type it once and then press `` to repeat it). | +| `` | Repeat the last command (don't type `n` repeatedly, just type it once and then press +`` to repeat it). | -If you want to learn more about debugging with Pdb, you will find an [interesting tutorial on that topic here](https://pymotw.com/3/pdb/). +If you want to learn more about debugging with Pdb, you will find an [interesting tutorial on that +topic here](https://pymotw.com/3/pdb/). diff --git a/docs/source/Default-Command-Help.md b/docs/source/Default-Command-Help.md index b9989fb42c..11aeea97a7 100644 --- a/docs/source/Default-Command-Help.md +++ b/docs/source/Default-Command-Help.md @@ -12,15 +12,18 @@ information about how commands work can be found in the documentation for [Comma ## A-Z -- [`__unloggedin_look_command`](https://github.com/evennia/evennia/wiki/Default-Command-Help#wiki-`--unloggedin-look-command`-cmdunconnectedlook) - look when in unlogged-in state +- [`__unloggedin_look_command`](https://github.com/evennia/evennia/wiki/Default-Command- +Help#wiki-`--unloggedin-look-command`-cmdunconnectedlook) - look when in unlogged-in state - [about](./Default-Command-Help#wiki-about-cmdabout) - show Evennia info - [access](./Default-Command-Help#wiki-access-cmdaccess) - show your current game access -- [addcom](./Default-Command-Help#wiki-addcom-cmdaddcom) - add a channel alias and/or subscribe to a channel +- [addcom](./Default-Command-Help#wiki-addcom-cmdaddcom) - add a channel alias and/or subscribe to a +channel - [alias](./Default-Command-Help#wiki-alias-cmdsetobjalias) - adding permanent aliases for object - [allcom](./Default-Command-Help#wiki-allcom-cmdallcom) - perform admin operations on all channels - [ban](./Default-Command-Help#wiki-ban-cmdban) - ban an account from the server - [batchcode](./Default-Command-Help#wiki-batchcode-cmdbatchcode) - build from batch-code file -- [batchcommands](./Default-Command-Help#wiki-batchcommands-cmdbatchcommands) - build from batch-command file +- [batchcommands](./Default-Command-Help#wiki-batchcommands-cmdbatchcommands) - build from batch- +command file - [boot](./Default-Command-Help#wiki-boot-cmdboot) - kick an account from the server. - [cboot](./Default-Command-Help#wiki-cboot-cmdcboot) - kick an account from a channel you control - [ccreate](./Default-Command-Help#wiki-ccreate-cmdchannelcreate) - create a new channel @@ -29,23 +32,29 @@ information about how commands work can be found in the documentation for [Comma - [cemit](./Default-Command-Help#wiki-cemit-cmdcemit) - send an admin message to a channel you control - [channels](./Default-Command-Help#wiki-channels-cmdchannels) - list all channels available to you - [charcreate](./Default-Command-Help#wiki-charcreate-cmdcharcreate) - create a new character -- [chardelete](./Default-Command-Help#wiki-chardelete-cmdchardelete) - delete a character - this cannot be undone! +- [chardelete](./Default-Command-Help#wiki-chardelete-cmdchardelete) - delete a character - this +cannot be undone! - [clock](./Default-Command-Help#wiki-clock-cmdclock) - change channel locks of a channel you control -- [cmdsets](./Default-Command-Help#wiki-cmdsets-cmdlistcmdsets) - list command sets defined on an object +- [cmdsets](./Default-Command-Help#wiki-cmdsets-cmdlistcmdsets) - list command sets defined on an +object - [color](./Default-Command-Help#wiki-color-cmdcolortest) - testing which colors your client support -- [command](./Default-Command-Help#wiki-command-objmanipcommand) - This is a parent class for some of the defining objmanip commands +- [command](./Default-Command-Help#wiki-command-objmanipcommand) - This is a parent class for some of +the defining objmanip commands - [connect](./Default-Command-Help#wiki-connect-cmdunconnectedconnect) - connect to the game - [copy](./Default-Command-Help#wiki-copy-cmdcopy) - copy an object and its properties - [cpattr](./Default-Command-Help#wiki-cpattr-cmdcpattr) - copy attributes between objects - [create](./Default-Command-Help#wiki-create-cmdunconnectedcreate) - create a new account account - [create](./Default-Command-Help#wiki-create-cmdcreate) - create new objects - [cwho](./Default-Command-Help#wiki-cwho-cmdcwho) - show who is listening to a channel -- [delcom](./Default-Command-Help#wiki-delcom-cmddelcom) - remove a channel alias and/or unsubscribe from channel +- [delcom](./Default-Command-Help#wiki-delcom-cmddelcom) - remove a channel alias and/or unsubscribe +from channel - [desc](./Default-Command-Help#wiki-desc-cmddesc) - describe an object or the current room. - [destroy](./Default-Command-Help#wiki-destroy-cmddestroy) - permanently delete objects -- [dig](./Default-Command-Help#wiki-dig-cmddig) - build new rooms and connect them to the current location +- [dig](./Default-Command-Help#wiki-dig-cmddig) - build new rooms and connect them to the current +location - [drop](./Default-Command-Help#wiki-drop-cmddrop) - drop something -- [emit](./Default-Command-Help#wiki-emit-cmdemit) - admin command for emitting message to multiple objects +- [emit](./Default-Command-Help#wiki-emit-cmdemit) - admin command for emitting message to multiple +objects - [examine](./Default-Command-Help#wiki-examine-cmdexamine) - get detailed information about an object - [find](./Default-Command-Help#wiki-find-cmdfind) - search the database for objects - [force](./Default-Command-Help#wiki-force-cmdforce) - forces an object to execute a command @@ -56,14 +65,16 @@ information about how commands work can be found in the documentation for [Comma - [home](./Default-Command-Help#wiki-home-cmdhome) - move to your character's home location - [ic](./Default-Command-Help#wiki-ic-cmdic) - control an object you have permission to puppet - [inventory](./Default-Command-Help#wiki-inventory-cmdinventory) - view inventory -- [irc2chan](./Default-Command-Help#wiki-irc2chan-cmdirc2chan) - Link an evennia channel to an external IRC channel +- [irc2chan](./Default-Command-Help#wiki-irc2chan-cmdirc2chan) - Link an evennia channel to an +external IRC channel - [link](./Default-Command-Help#wiki-link-cmdlink) - link existing rooms together with exits - [lock](./Default-Command-Help#wiki-lock-cmdlock) - assign a lock definition to an object - [look](./Default-Command-Help#wiki-look-cmdlook) - look at location or object - [look](./Default-Command-Help#wiki-look-cmdooclook) - look while out-of-character - [mvattr](./Default-Command-Help#wiki-mvattr-cmdmvattr) - move attributes between objects - [name](./Default-Command-Help#wiki-name-cmdname) - change the name and/or aliases of an object -- [nick](./Default-Command-Help#wiki-nick-cmdnick) - define a personal alias/nick by defining a string to +- [nick](./Default-Command-Help#wiki-nick-cmdnick) - define a personal alias/nick by defining a string +to - [objects](./Default-Command-Help#wiki-objects-cmdobjects) - statistics on objects in the database - [ooc](./Default-Command-Help#wiki-ooc-cmdooc) - stop puppeting and go ooc - [open](./Default-Command-Help#wiki-open-cmdopen) - open a new exit from the current room @@ -73,12 +84,14 @@ information about how commands work can be found in the documentation for [Comma - [perm](./Default-Command-Help#wiki-perm-cmdperm) - set the permissions of an account/object - [pose](./Default-Command-Help#wiki-pose-cmdpose) - strike a pose - [py](./Default-Command-Help#wiki-py-cmdpy) - execute a snippet of python code -- [quell](./Default-Command-Help#wiki-quell-cmdquell) - use character's permissions instead of account's +- [quell](./Default-Command-Help#wiki-quell-cmdquell) - use character's permissions instead of +account's - [quit](./Default-Command-Help#wiki-quit-cmdunconnectedquit) - quit when in unlogged-in state - [quit](./Default-Command-Help#wiki-quit-cmdquit) - quit the game - [reload](./Default-Command-Help#wiki-reload-cmdreload) - reload the server - [reset](./Default-Command-Help#wiki-reset-cmdreset) - reset and reboot the server -- [rss2chan](./Default-Command-Help#wiki-rss2chan-cmdrss2chan) - link an evennia channel to an external RSS feed +- [rss2chan](./Default-Command-Help#wiki-rss2chan-cmdrss2chan) - link an evennia channel to an +external RSS feed - [say](./Default-Command-Help#wiki-say-cmdsay) - speak as your character - [script](./Default-Command-Help#wiki-script-cmdscript) - attach a script to an object - [scripts](./Default-Command-Help#wiki-scripts-cmdscripts) - list and manage all running scripts @@ -95,13 +108,17 @@ information about how commands work can be found in the documentation for [Comma - [tag](./Default-Command-Help#wiki-tag-cmdtag) - handles the tags of an object - [tel](./Default-Command-Help#wiki-tel-cmdteleport) - teleport object to another location - [time](./Default-Command-Help#wiki-time-cmdtime) - show server time statistics -- [tunnel](./Default-Command-Help#wiki-tunnel-cmdtunnel) - create new rooms in cardinal directions only -- [typeclass](./Default-Command-Help#wiki-typeclass-cmdtypeclass) - set or change an object's typeclass +- [tunnel](./Default-Command-Help#wiki-tunnel-cmdtunnel) - create new rooms in cardinal directions +only +- [typeclass](./Default-Command-Help#wiki-typeclass-cmdtypeclass) - set or change an object's +typeclass - [unban](./Default-Command-Help#wiki-unban-cmdunban) - remove a ban from an account - [unlink](./Default-Command-Help#wiki-unlink-cmdunlink) - remove exit-connections between rooms -- [userpassword](./Default-Command-Help#wiki-userpassword-cmdnewpassword) - change the password of an account +- [userpassword](./Default-Command-Help#wiki-userpassword-cmdnewpassword) - change the password of an +account - [wall](./Default-Command-Help#wiki-wall-cmdwall) - make an announcement to all -- [whisper](./Default-Command-Help#wiki-whisper-cmdwhisper) - Speak privately as your character to another +- [whisper](./Default-Command-Help#wiki-whisper-cmdwhisper) - Speak privately as your character to +another - [who](./Default-Command-Help#wiki-who-cmdwho) - list who is currently online - [wipe](./Default-Command-Help#wiki-wipe-cmdwipe) - clear all attributes from an object @@ -120,12 +137,14 @@ information about how commands work can be found in the documentation for [Comma ## Command details These are generated from the auto-documentation and are ordered by their source file location in -[evennia/commands/default/](https://github.com/evennia/evennia/tree/master/evennia/commands/default/) +[evennia/commands/default/](https://github.com/evennia/evennia/tree/master/evennia/commands/default/ +) ### `account.py` -[View account.py source](https://github.com/evennia/evennia/tree/master/evennia/commands/default/account.py) +[View account.py +source](https://github.com/evennia/evennia/tree/master/evennia/commands/default/account.py) #### charcreate (CmdCharCreate) @@ -141,11 +160,13 @@ These are generated from the auto-documentation and are ordered by their source if you want. ``` - **key:** *charcreate* -- **aliases:** +- **aliases:** - **[locks](./Locks):** *"cmd:pperm(Player)"* - **[`help_category`](./Help-System):** *"General"* -- **Source:** class `CmdCharCreate` in [account.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/account.py). -Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_account.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_account.py). +- **Source:** class `CmdCharCreate` in +[account.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/account.py). +Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_account.py](https://gi +thub.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_account.py). #### chardelete (CmdCharDelete) @@ -158,11 +179,13 @@ Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_ac Permanently deletes one of your characters. ``` - **key:** *chardelete* -- **aliases:** +- **aliases:** - **[locks](./Locks):** *"cmd:pperm(Player)"* - **[`help_category`](./Help-System):** *"General"* -- **Source:** class `CmdCharDelete` in [account.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/account.py). -Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_account.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_account.py). +- **Source:** class `CmdCharDelete` in +[account.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/account.py). +Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_account.py](https://gi +thub.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_account.py). #### color (CmdColorTest) @@ -179,11 +202,13 @@ Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_ac color - if not you will see rubbish appear. ``` - **key:** *color* -- **aliases:** +- **aliases:** - **[locks](./Locks):** *"cmd:all()"* - **[`help_category`](./Help-System):** *"General"* -- **Source:** class `CmdColorTest` in [account.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/account.py). -Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_account.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_account.py). +- **Source:** class `CmdColorTest` in +[account.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/account.py). +Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_account.py](https://gi +thub.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_account.py). #### ic (CmdIC) @@ -207,8 +232,10 @@ Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_ac - **aliases:** *puppet* - **[locks](./Locks):** *"cmd:all()"* - **[`help_category`](./Help-System):** *"General"* -- **Source:** class `CmdIC` in [account.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/account.py). -Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_account.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_account.py). +- **Source:** class `CmdIC` in +[account.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/account.py). +Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_account.py](https://gi +thub.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_account.py). #### look (CmdOOCLook) @@ -224,8 +251,10 @@ Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_ac - **aliases:** *l*, *ls* - **[locks](./Locks):** *"cmd:all()"* - **[`help_category`](./Help-System):** *"General"* -- **Source:** class `CmdOOCLook` in [account.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/account.py). -Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_account.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_account.py). +- **Source:** class `CmdOOCLook` in +[account.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/account.py). +Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_account.py](https://gi +thub.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_account.py). #### ooc (CmdOOC) @@ -243,8 +272,10 @@ Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_ac - **aliases:** *unpuppet* - **[locks](./Locks):** *"cmd:pperm(Player)"* - **[`help_category`](./Help-System):** *"General"* -- **Source:** class `CmdOOC` in [account.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/account.py). -Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_account.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_account.py). +- **Source:** class `CmdOOC` in +[account.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/account.py). +Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_account.py](https://gi +thub.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_account.py). #### option (CmdOption) @@ -266,8 +297,10 @@ Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_ac - **aliases:** *options* - **[locks](./Locks):** *"cmd:all()"* - **[`help_category`](./Help-System):** *"General"* -- **Source:** class `CmdOption` in [account.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/account.py). -Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_account.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_account.py). +- **Source:** class `CmdOption` in +[account.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/account.py). +Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_account.py](https://gi +thub.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_account.py). #### password (CmdPassword) @@ -280,11 +313,13 @@ Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_ac Changes your password. Make sure to pick a safe one. ``` - **key:** *password* -- **aliases:** +- **aliases:** - **[locks](./Locks):** *"cmd:pperm(Player)"* - **[`help_category`](./Help-System):** *"General"* -- **Source:** class `CmdPassword` in [account.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/account.py). -Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_account.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_account.py). +- **Source:** class `CmdPassword` in +[account.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/account.py). +Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_account.py](https://gi +thub.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_account.py). #### quell (CmdQuell) @@ -307,8 +342,10 @@ Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_ac - **aliases:** *unquell* - **[locks](./Locks):** *"cmd:pperm(Player)"* - **[`help_category`](./Help-System):** *"General"* -- **Source:** class `CmdQuell` in [account.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/account.py). -Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_account.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_account.py). +- **Source:** class `CmdQuell` in +[account.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/account.py). +Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_account.py](https://gi +thub.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_account.py). #### quit (CmdQuit) @@ -325,11 +362,13 @@ Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_ac game. Use the /all switch to disconnect from all sessions. ``` - **key:** *quit* -- **aliases:** +- **aliases:** - **[locks](./Locks):** *"cmd:all()"* - **[`help_category`](./Help-System):** *"General"* -- **Source:** class `CmdQuit` in [account.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/account.py). -Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_account.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_account.py). +- **Source:** class `CmdQuit` in +[account.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/account.py). +Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_account.py](https://gi +thub.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_account.py). #### sessions (CmdSessions) @@ -342,11 +381,13 @@ Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_ac Lists the sessions currently connected to your account. ``` - **key:** *sessions* -- **aliases:** +- **aliases:** - **[locks](./Locks):** *"cmd:all()"* - **[`help_category`](./Help-System):** *"General"* -- **Source:** class `CmdSessions` in [account.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/account.py). -Belongs to command set *'DefaultSession'* of class `SessionCmdSet` in [cmdset_session.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_session.py). +- **Source:** class `CmdSessions` in +[account.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/account.py). +Belongs to command set *'DefaultSession'* of class `SessionCmdSet` in [cmdset_session.py](https://gi +thub.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_session.py). #### style (CmdStyle) @@ -361,11 +402,13 @@ Belongs to command set *'DefaultSession'* of class `SessionCmdSet` in [cmdset_se entriest etc. Use without arguments to see all available options. ``` - **key:** *style* -- **aliases:** +- **aliases:** - **[locks](./Locks):** *"cmd:all()"* - **[`help_category`](./Help-System):** *"General"* -- **Source:** class `CmdStyle` in [account.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/account.py). -Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_account.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_account.py). +- **Source:** class `CmdStyle` in +[account.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/account.py). +Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_account.py](https://gi +thub.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_account.py). #### who (CmdWho) @@ -383,13 +426,16 @@ Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_ac - **aliases:** *doing* - **[locks](./Locks):** *"cmd:all()"* - **[`help_category`](./Help-System):** *"General"* -- **Source:** class `CmdWho` in [account.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/account.py). -Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_account.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_account.py). +- **Source:** class `CmdWho` in +[account.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/account.py). +Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_account.py](https://gi +thub.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_account.py). ### `admin.py` -[View admin.py source](https://github.com/evennia/evennia/tree/master/evennia/commands/default/admin.py) +[View admin.py +source](https://github.com/evennia/evennia/tree/master/evennia/commands/default/admin.py) #### ban (CmdBan) @@ -428,8 +474,10 @@ Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_ac - **aliases:** *bans* - **[locks](./Locks):** *"cmd:perm(ban) or perm(Developer)"* - **[`help_category`](./Help-System):** *"Admin"* -- **Source:** class `CmdBan` in [admin.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/admin.py). -Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). +- **Source:** class `CmdBan` in +[admin.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/admin.py). +Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](http +s://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). #### boot (CmdBoot) @@ -447,11 +495,13 @@ Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdse supplied it will be echoed to the user unless /quiet is set. ``` - **key:** *boot* -- **aliases:** +- **aliases:** - **[locks](./Locks):** *"cmd:perm(boot) or perm(Admin)"* - **[`help_category`](./Help-System):** *"Admin"* -- **Source:** class `CmdBoot` in [admin.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/admin.py). -Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). +- **Source:** class `CmdBoot` in +[admin.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/admin.py). +Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](http +s://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). #### emit (CmdEmit) @@ -478,8 +528,10 @@ Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdse - **aliases:** *remit*, *pemit* - **[locks](./Locks):** *"cmd:perm(emit) or perm(Builder)"* - **[`help_category`](./Help-System):** *"Admin"* -- **Source:** class `CmdEmit` in [admin.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/admin.py). -Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). +- **Source:** class `CmdEmit` in +[admin.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/admin.py). +Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](http +s://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). #### force (CmdForce) @@ -493,11 +545,13 @@ Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdse force bob=get stick ``` - **key:** *force* -- **aliases:** +- **aliases:** - **[locks](./Locks):** *"cmd:perm(spawn) or perm(Builder)"* - **[`help_category`](./Help-System):** *"Building"* -- **Source:** class `CmdForce` in [admin.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/admin.py). -Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). +- **Source:** class `CmdForce` in +[admin.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/admin.py). +Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](http +s://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). #### perm (CmdPerm) @@ -519,8 +573,10 @@ Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdse - **aliases:** *setperm* - **[locks](./Locks):** *"cmd:perm(perm) or perm(Developer)"* - **[`help_category`](./Help-System):** *"Admin"* -- **Source:** class `CmdPerm` in [admin.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/admin.py). -Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). +- **Source:** class `CmdPerm` in +[admin.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/admin.py). +Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](http +s://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). #### unban (CmdUnban) @@ -536,11 +592,13 @@ Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdse unban. ``` - **key:** *unban* -- **aliases:** +- **aliases:** - **[locks](./Locks):** *"cmd:perm(unban) or perm(Developer)"* - **[`help_category`](./Help-System):** *"Admin"* -- **Source:** class `CmdUnban` in [admin.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/admin.py). -Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). +- **Source:** class `CmdUnban` in +[admin.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/admin.py). +Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](http +s://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). #### userpassword (CmdNewPassword) @@ -553,11 +611,13 @@ Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdse Set an account's password. ``` - **key:** *userpassword* -- **aliases:** +- **aliases:** - **[locks](./Locks):** *"cmd:perm(newpassword) or perm(Admin)"* - **[`help_category`](./Help-System):** *"Admin"* -- **Source:** class `CmdNewPassword` in [admin.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/admin.py). -Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_account.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_account.py). +- **Source:** class `CmdNewPassword` in +[admin.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/admin.py). +Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_account.py](https://gi +thub.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_account.py). #### wall (CmdWall) @@ -571,16 +631,19 @@ Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_ac including all currently unlogged in. ``` - **key:** *wall* -- **aliases:** +- **aliases:** - **[locks](./Locks):** *"cmd:perm(wall) or perm(Admin)"* - **[`help_category`](./Help-System):** *"Admin"* -- **Source:** class `CmdWall` in [admin.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/admin.py). -Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). +- **Source:** class `CmdWall` in +[admin.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/admin.py). +Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](http +s://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). ### `batchprocess.py` -[View batchprocess.py source](https://github.com/evennia/evennia/tree/master/evennia/commands/default/batchprocess.py) +[View batchprocess.py +source](https://github.com/evennia/evennia/tree/master/evennia/commands/default/batchprocess.py) #### batchcode (CmdBatchCode) @@ -605,8 +668,10 @@ Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdse - **aliases:** *batchcodes* - **[locks](./Locks):** *"cmd:superuser()"* - **[`help_category`](./Help-System):** *"Building"* -- **Source:** class `CmdBatchCode` in [batchprocess.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/batchprocess.py). -Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). +- **Source:** class `CmdBatchCode` in [batchprocess.py](https://github.com/evennia/evennia/tree/mast +er/evennia/commands/default/batchprocess.py). +Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](http +s://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). #### batchcommands (CmdBatchCommands) @@ -627,13 +692,16 @@ Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdse - **aliases:** *batchcmd*, *batchcommand* - **[locks](./Locks):** *"cmd:perm(batchcommands) or perm(Developer)"* - **[`help_category`](./Help-System):** *"Building"* -- **Source:** class `CmdBatchCommands` in [batchprocess.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/batchprocess.py). -Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). +- **Source:** class `CmdBatchCommands` in [batchprocess.py](https://github.com/evennia/evennia/tree/ +master/evennia/commands/default/batchprocess.py). +Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](http +s://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). ### `building.py` -[View building.py source](https://github.com/evennia/evennia/tree/master/evennia/commands/default/building.py) +[View building.py +source](https://github.com/evennia/evennia/tree/master/evennia/commands/default/building.py) #### alias (CmdSetObjAlias) @@ -662,8 +730,10 @@ Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdse - **aliases:** *setobjalias* - **[locks](./Locks):** *"cmd:perm(setobjalias) or perm(Builder)"* - **[`help_category`](./Help-System):** *"Building"* -- **Source:** class `CmdSetObjAlias` in [building.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/building.py). -Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). +- **Source:** class `CmdSetObjAlias` in +[building.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/building.py). +Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](http +s://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). #### cmdsets (CmdListCmdSets) @@ -680,8 +750,10 @@ Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdse - **aliases:** *listcmsets* - **[locks](./Locks):** *"cmd:perm(listcmdsets) or perm(Builder)"* - **[`help_category`](./Help-System):** *"Building"* -- **Source:** class `CmdListCmdSets` in [building.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/building.py). -Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). +- **Source:** class `CmdListCmdSets` in +[building.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/building.py). +Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](http +s://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). #### command (ObjManipCommand) @@ -704,11 +776,13 @@ Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdse objname/attr/attr/attr, objname/attr, ... ``` - **key:** *command* -- **aliases:** +- **aliases:** - **[locks](./Locks):** *"cmd:all()"* - **[`help_category`](./Help-System):** *"General"* -- **Source:** class `ObjManipCommand` in [building.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/building.py). -Belongs to command set *''* of class `` in [](https://github.com/evennia/evennia/tree/master/evennia/commands/default/). +- **Source:** class `ObjManipCommand` in +[building.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/building.py). +Belongs to command set *''* of class `` in +[](https://github.com/evennia/evennia/tree/master/evennia/commands/default/). #### copy (CmdCopy) @@ -728,11 +802,13 @@ Belongs to command set *''* of class `` in [](https://github.c one exact copy of the original object will be created with the name *_copy. ``` - **key:** *copy* -- **aliases:** +- **aliases:** - **[locks](./Locks):** *"cmd:perm(copy) or perm(Builder)"* - **[`help_category`](./Help-System):** *"Building"* -- **Source:** class `CmdCopy` in [building.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/building.py). -Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). +- **Source:** class `CmdCopy` in +[building.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/building.py). +Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](http +s://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). #### cpattr (CmdCpAttr) @@ -758,11 +834,13 @@ Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdse If you don't supply a source object, yourself is used. ``` - **key:** *cpattr* -- **aliases:** +- **aliases:** - **[locks](./Locks):** *"cmd:perm(cpattr) or perm(Builder)"* - **[`help_category`](./Help-System):** *"Building"* -- **Source:** class `CmdCpAttr` in [building.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/building.py). -Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). +- **Source:** class `CmdCpAttr` in +[building.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/building.py). +Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](http +s://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). #### create (CmdCreate) @@ -788,11 +866,13 @@ Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdse create/drop button;red : examples.red_button.RedButton ``` - **key:** *create* -- **aliases:** +- **aliases:** - **[locks](./Locks):** *"cmd:perm(create) or perm(Builder)"* - **[`help_category`](./Help-System):** *"Building"* -- **Source:** class `CmdCreate` in [building.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/building.py). -Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). +- **Source:** class `CmdCreate` in +[building.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/building.py). +Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](http +s://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). #### desc (CmdDesc) @@ -812,8 +892,10 @@ Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdse - **aliases:** *describe* - **[locks](./Locks):** *"cmd:perm(desc) or perm(Builder)"* - **[`help_category`](./Help-System):** *"Building"* -- **Source:** class `CmdDesc` in [building.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/building.py). -Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). +- **Source:** class `CmdDesc` in +[building.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/building.py). +Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](http +s://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). #### destroy (CmdDestroy) @@ -841,8 +923,10 @@ Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdse - **aliases:** *del*, *delete* - **[locks](./Locks):** *"cmd:perm(destroy) or perm(Builder)"* - **[`help_category`](./Help-System):** *"Building"* -- **Source:** class `CmdDestroy` in [building.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/building.py). -Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). +- **Source:** class `CmdDestroy` in +[building.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/building.py). +Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](http +s://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). #### dig (CmdDig) @@ -869,11 +953,13 @@ Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdse would be 'north;no;n'. ``` - **key:** *dig* -- **aliases:** +- **aliases:** - **[locks](./Locks):** *"cmd:perm(dig) or perm(Builder)"* - **[`help_category`](./Help-System):** *"Building"* -- **Source:** class `CmdDig` in [building.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/building.py). -Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). +- **Source:** class `CmdDig` in +[building.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/building.py). +Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](http +s://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). #### examine (CmdExamine) @@ -898,8 +984,10 @@ Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdse - **aliases:** *exam*, *ex* - **[locks](./Locks):** *"cmd:perm(examine) or perm(Builder)"* - **[`help_category`](./Help-System):** *"Building"* -- **Source:** class `CmdExamine` in [building.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/building.py). -Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_account.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_account.py). +- **Source:** class `CmdExamine` in +[building.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/building.py). +Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_account.py](https://gi +thub.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_account.py). #### find (CmdFind) @@ -928,8 +1016,10 @@ Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_ac - **aliases:** *locate*, *search* - **[locks](./Locks):** *"cmd:perm(find) or perm(Builder)"* - **[`help_category`](./Help-System):** *"Building"* -- **Source:** class `CmdFind` in [building.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/building.py). -Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). +- **Source:** class `CmdFind` in +[building.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/building.py). +Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](http +s://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). #### link (CmdLink) @@ -953,11 +1043,13 @@ Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdse currently set destination. ``` - **key:** *link* -- **aliases:** +- **aliases:** - **[locks](./Locks):** *"cmd:perm(link) or perm(Builder)"* - **[`help_category`](./Help-System):** *"Building"* -- **Source:** class `CmdLink` in [building.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/building.py). -Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). +- **Source:** class `CmdLink` in +[building.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/building.py). +Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](http +s://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). #### lock (CmdLock) @@ -995,8 +1087,10 @@ Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdse - **aliases:** *locks* - **[locks](./Locks):** *"cmd: perm(locks) or perm(Builder)"* - **[`help_category`](./Help-System):** *"Building"* -- **Source:** class `CmdLock` in [building.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/building.py). -Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). +- **Source:** class `CmdLock` in +[building.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/building.py). +Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](http +s://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). #### mvattr (CmdMvAttr) @@ -1016,11 +1110,13 @@ Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdse object. If you don't supply a source object, yourself is used. ``` - **key:** *mvattr* -- **aliases:** +- **aliases:** - **[locks](./Locks):** *"cmd:perm(mvattr) or perm(Builder)"* - **[`help_category`](./Help-System):** *"Building"* -- **Source:** class `CmdMvAttr` in [building.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/building.py). -Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). +- **Source:** class `CmdMvAttr` in +[building.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/building.py). +Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](http +s://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). #### name (CmdName) @@ -1037,8 +1133,10 @@ Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdse - **aliases:** *rename* - **[locks](./Locks):** *"cmd:perm(rename) or perm(Builder)"* - **[`help_category`](./Help-System):** *"Building"* -- **Source:** class `CmdName` in [building.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/building.py). -Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). +- **Source:** class `CmdName` in +[building.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/building.py). +Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](http +s://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). #### open (CmdOpen) @@ -1046,7 +1144,8 @@ Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdse open a new exit from the current room Usage: - open [;alias;alias..][:typeclass] [,[;alias;..][:typeclass]]] = + open [;alias;alias..][:typeclass] [,[;alias;..][:typeclass]]] = + Handles the creation of exits. If a destination is given, the exit will point there. The argument sets up an exit at the @@ -1055,11 +1154,13 @@ Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdse unique. ``` - **key:** *open* -- **aliases:** +- **aliases:** - **[locks](./Locks):** *"cmd:perm(open) or perm(Builder)"* - **[`help_category`](./Help-System):** *"Building"* -- **Source:** class `CmdOpen` in [building.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/building.py). -Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). +- **Source:** class `CmdOpen` in +[building.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/building.py). +Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](http +s://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). #### script (CmdScript) @@ -1085,8 +1186,10 @@ Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdse - **aliases:** *addscript* - **[locks](./Locks):** *"cmd:perm(script) or perm(Builder)"* - **[`help_category`](./Help-System):** *"Building"* -- **Source:** class `CmdScript` in [building.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/building.py). -Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). +- **Source:** class `CmdScript` in +[building.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/building.py). +Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](http +s://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). #### set (CmdSetAttribute) @@ -1129,11 +1232,13 @@ Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdse around your strings or you will get an error. ``` - **key:** *set* -- **aliases:** +- **aliases:** - **[locks](./Locks):** *"cmd:perm(set) or perm(Builder)"* - **[`help_category`](./Help-System):** *"Building"* -- **Source:** class `CmdSetAttribute` in [building.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/building.py). -Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). +- **Source:** class `CmdSetAttribute` in +[building.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/building.py). +Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](http +s://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). #### sethome (CmdSetHome) @@ -1152,11 +1257,13 @@ Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdse If no location is given, just view the object's home location. ``` - **key:** *sethome* -- **aliases:** +- **aliases:** - **[locks](./Locks):** *"cmd:perm(sethome) or perm(Builder)"* - **[`help_category`](./Help-System):** *"Building"* -- **Source:** class `CmdSetHome` in [building.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/building.py). -Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). +- **Source:** class `CmdSetHome` in +[building.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/building.py). +Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](http +s://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). #### spawn (CmdSpawn) @@ -1225,8 +1332,10 @@ Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdse - **aliases:** *olc* - **[locks](./Locks):** *"cmd:perm(spawn) or perm(Builder)"* - **[`help_category`](./Help-System):** *"Building"* -- **Source:** class `CmdSpawn` in [building.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/building.py). -Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). +- **Source:** class `CmdSpawn` in +[building.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/building.py). +Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](http +s://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). #### tag (CmdTag) @@ -1254,8 +1363,10 @@ Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdse - **aliases:** *tags* - **[locks](./Locks):** *"cmd:perm(tag) or perm(Builder)"* - **[`help_category`](./Help-System):** *"Building"* -- **Source:** class `CmdTag` in [building.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/building.py). -Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). +- **Source:** class `CmdTag` in +[building.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/building.py). +Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](http +s://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). #### tel (CmdTeleport) @@ -1289,8 +1400,10 @@ Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdse - **aliases:** *teleport* - **[locks](./Locks):** *"cmd:perm(teleport) or perm(Builder)"* - **[`help_category`](./Help-System):** *"Building"* -- **Source:** class `CmdTeleport` in [building.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/building.py). -Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). +- **Source:** class `CmdTeleport` in +[building.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/building.py). +Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](http +s://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). #### tunnel (CmdTunnel) @@ -1323,8 +1436,10 @@ Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdse - **aliases:** *tun* - **[locks](./Locks):** *"cmd: perm(tunnel) or perm(Builder)"* - **[`help_category`](./Help-System):** *"Building"* -- **Source:** class `CmdTunnel` in [building.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/building.py). -Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). +- **Source:** class `CmdTunnel` in +[building.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/building.py). +Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](http +s://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). #### typeclass (CmdTypeclass) @@ -1378,8 +1493,10 @@ Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdse - **aliases:** *swap*, *parent*, *type*, *update* - **[locks](./Locks):** *"cmd:perm(typeclass) or perm(Builder)"* - **[`help_category`](./Help-System):** *"Building"* -- **Source:** class `CmdTypeclass` in [building.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/building.py). -Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). +- **Source:** class `CmdTypeclass` in +[building.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/building.py). +Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](http +s://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). #### unlink (CmdUnLink) @@ -1393,11 +1510,13 @@ Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdse it from whatever it was connected to. ``` - **key:** *unlink* -- **aliases:** +- **aliases:** - **[locks](./Locks):** *"cmd:perm(unlink) or perm(Builder)"* - **[`help_category`](./Help-System):** *"Building"* -- **Source:** class `CmdUnLink` in [building.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/building.py). -Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). +- **Source:** class `CmdUnLink` in +[building.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/building.py). +Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](http +s://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). #### wipe (CmdWipe) @@ -1415,16 +1534,19 @@ Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdse matching the given attribute-wildcard search string. ``` - **key:** *wipe* -- **aliases:** +- **aliases:** - **[locks](./Locks):** *"cmd:perm(wipe) or perm(Builder)"* - **[`help_category`](./Help-System):** *"Building"* -- **Source:** class `CmdWipe` in [building.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/building.py). -Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). +- **Source:** class `CmdWipe` in +[building.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/building.py). +Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](http +s://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). ### `comms.py` -[View comms.py source](https://github.com/evennia/evennia/tree/master/evennia/commands/default/comms.py) +[View comms.py +source](https://github.com/evennia/evennia/tree/master/evennia/commands/default/comms.py) #### addcom (CmdAddCom) @@ -1443,8 +1565,10 @@ Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdse - **aliases:** *aliaschan*, *chanalias* - **[locks](./Locks):** *"cmd:not pperm(channel_banned)"* - **[`help_category`](./Help-System):** *"Comms"* -- **Source:** class `CmdAddCom` in [comms.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/comms.py). -Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_account.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_account.py). +- **Source:** class `CmdAddCom` in +[comms.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/comms.py). +Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_account.py](https://gi +thub.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_account.py). #### allcom (CmdAllCom) @@ -1461,11 +1585,13 @@ Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_ac Without argument, works like comlist. ``` - **key:** *allcom* -- **aliases:** +- **aliases:** - **[locks](./Locks):** *"cmd: not pperm(channel_banned)"* - **[`help_category`](./Help-System):** *"Comms"* -- **Source:** class `CmdAllCom` in [comms.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/comms.py). -Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_account.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_account.py). +- **Source:** class `CmdAllCom` in +[comms.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/comms.py). +Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_account.py](https://gi +thub.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_account.py). #### cboot (CmdCBoot) @@ -1481,11 +1607,13 @@ Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_ac Kicks an account or object from a channel you control. ``` - **key:** *cboot* -- **aliases:** +- **aliases:** - **[locks](./Locks):** *"cmd: not pperm(channel_banned)"* - **[`help_category`](./Help-System):** *"Comms"* -- **Source:** class `CmdCBoot` in [comms.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/comms.py). -Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_account.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_account.py). +- **Source:** class `CmdCBoot` in +[comms.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/comms.py). +Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_account.py](https://gi +thub.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_account.py). #### ccreate (CmdChannelCreate) @@ -1501,8 +1629,10 @@ Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_ac - **aliases:** *channelcreate* - **[locks](./Locks):** *"cmd:not pperm(channel_banned) and pperm(Player)"* - **[`help_category`](./Help-System):** *"Comms"* -- **Source:** class `CmdChannelCreate` in [comms.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/comms.py). -Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_account.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_account.py). +- **Source:** class `CmdChannelCreate` in +[comms.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/comms.py). +Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_account.py](https://gi +thub.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_account.py). #### cdesc (CmdCdesc) @@ -1516,11 +1646,13 @@ Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_ac channel lists. ``` - **key:** *cdesc* -- **aliases:** +- **aliases:** - **[locks](./Locks):** *"cmd:not pperm(channel_banned)"* - **[`help_category`](./Help-System):** *"Comms"* -- **Source:** class `CmdCdesc` in [comms.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/comms.py). -Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_account.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_account.py). +- **Source:** class `CmdCdesc` in +[comms.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/comms.py). +Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_account.py](https://gi +thub.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_account.py). #### cdestroy (CmdCdestroy) @@ -1533,11 +1665,13 @@ Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_ac Destroys a channel that you control. ``` - **key:** *cdestroy* -- **aliases:** +- **aliases:** - **[locks](./Locks):** *"cmd: not pperm(channel_banned)"* - **[`help_category`](./Help-System):** *"Comms"* -- **Source:** class `CmdCdestroy` in [comms.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/comms.py). -Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_account.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_account.py). +- **Source:** class `CmdCdestroy` in +[comms.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/comms.py). +Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_account.py](https://gi +thub.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_account.py). #### cemit (CmdCemit) @@ -1559,8 +1693,10 @@ Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_ac - **aliases:** *cmsg* - **[locks](./Locks):** *"cmd: not pperm(channel_banned) and pperm(Player)"* - **[`help_category`](./Help-System):** *"Comms"* -- **Source:** class `CmdCemit` in [comms.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/comms.py). -Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_account.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_account.py). +- **Source:** class `CmdCemit` in +[comms.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/comms.py). +Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_account.py](https://gi +thub.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_account.py). #### channels (CmdChannels) @@ -1580,8 +1716,10 @@ Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_ac - **aliases:** *chanlist*, *channellist*, *clist*, *comlist*, *all channels* - **[locks](./Locks):** *"cmd: not pperm(channel_banned)"* - **[`help_category`](./Help-System):** *"Comms"* -- **Source:** class `CmdChannels` in [comms.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/comms.py). -Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_account.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_account.py). +- **Source:** class `CmdChannels` in +[comms.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/comms.py). +Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_account.py](https://gi +thub.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_account.py). #### clock (CmdClock) @@ -1595,11 +1733,13 @@ Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_ac lockstring was given, view the current lock definitions. ``` - **key:** *clock* -- **aliases:** +- **aliases:** - **[locks](./Locks):** *"cmd:not pperm(channel_banned)"* - **[`help_category`](./Help-System):** *"Comms"* -- **Source:** class `CmdClock` in [comms.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/comms.py). -Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_account.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_account.py). +- **Source:** class `CmdClock` in +[comms.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/comms.py). +Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_account.py](https://gi +thub.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_account.py). #### cwho (CmdCWho) @@ -1612,11 +1752,13 @@ Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_ac List who is connected to a given channel you have access to. ``` - **key:** *cwho* -- **aliases:** +- **aliases:** - **[locks](./Locks):** *"cmd: not pperm(channel_banned)"* - **[`help_category`](./Help-System):** *"Comms"* -- **Source:** class `CmdCWho` in [comms.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/comms.py). -Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_account.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_account.py). +- **Source:** class `CmdCWho` in +[comms.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/comms.py). +Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_account.py](https://gi +thub.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_account.py). #### delcom (CmdDelCom) @@ -1636,8 +1778,10 @@ Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_ac - **aliases:** *delaliaschan*, *delchanalias* - **[locks](./Locks):** *"cmd:not perm(channel_banned)"* - **[`help_category`](./Help-System):** *"Comms"* -- **Source:** class `CmdDelCom` in [comms.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/comms.py). -Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_account.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_account.py). +- **Source:** class `CmdDelCom` in +[comms.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/comms.py). +Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_account.py](https://gi +thub.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_account.py). #### irc2chan (CmdIRC2Chan) @@ -1671,11 +1815,13 @@ Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_ac Provide an optional bot class path to use a custom bot. ``` - **key:** *irc2chan* -- **aliases:** +- **aliases:** - **[locks](./Locks):** *"cmd:serversetting(IRC_ENABLED) and pperm(Developer)"* - **[`help_category`](./Help-System):** *"Comms"* -- **Source:** class `CmdIRC2Chan` in [comms.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/comms.py). -Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_account.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_account.py). +- **Source:** class `CmdIRC2Chan` in +[comms.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/comms.py). +Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_account.py](https://gi +thub.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_account.py). #### page (CmdPage) @@ -1698,8 +1844,10 @@ Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_ac - **aliases:** *tell* - **[locks](./Locks):** *"cmd:not pperm(page_banned)"* - **[`help_category`](./Help-System):** *"Comms"* -- **Source:** class `CmdPage` in [comms.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/comms.py). -Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_account.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_account.py). +- **Source:** class `CmdPage` in +[comms.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/comms.py). +Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_account.py](https://gi +thub.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_account.py). #### rss2chan (CmdRSS2Chan) @@ -1727,16 +1875,19 @@ Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_ac to identify the connection uniquely. ``` - **key:** *rss2chan* -- **aliases:** +- **aliases:** - **[locks](./Locks):** *"cmd:serversetting(RSS_ENABLED) and pperm(Developer)"* - **[`help_category`](./Help-System):** *"Comms"* -- **Source:** class `CmdRSS2Chan` in [comms.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/comms.py). -Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_account.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_account.py). +- **Source:** class `CmdRSS2Chan` in +[comms.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/comms.py). +Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_account.py](https://gi +thub.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_account.py). ### `general.py` -[View general.py source](https://github.com/evennia/evennia/tree/master/evennia/commands/default/general.py) +[View general.py +source](https://github.com/evennia/evennia/tree/master/evennia/commands/default/general.py) #### access (CmdAccess) @@ -1753,8 +1904,10 @@ Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_ac - **aliases:** *groups*, *hierarchy* - **[locks](./Locks):** *"cmd:all()"* - **[`help_category`](./Help-System):** *"General"* -- **Source:** class `CmdAccess` in [general.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/general.py). -Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). +- **Source:** class `CmdAccess` in +[general.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/general.py). +Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](http +s://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). #### drop (CmdDrop) @@ -1768,11 +1921,13 @@ Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdse location you are currently in. ``` - **key:** *drop* -- **aliases:** +- **aliases:** - **[locks](./Locks):** *"cmd:all()"* - **[`help_category`](./Help-System):** *"General"* -- **Source:** class `CmdDrop` in [general.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/general.py). -Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). +- **Source:** class `CmdDrop` in +[general.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/general.py). +Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](http +s://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). #### get (CmdGet) @@ -1789,8 +1944,10 @@ Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdse - **aliases:** *grab* - **[locks](./Locks):** *"cmd:all()"* - **[`help_category`](./Help-System):** *"General"* -- **Source:** class `CmdGet` in [general.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/general.py). -Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). +- **Source:** class `CmdGet` in +[general.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/general.py). +Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](http +s://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). #### give (CmdGive) @@ -1804,11 +1961,13 @@ Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdse placing it in their inventory. ``` - **key:** *give* -- **aliases:** +- **aliases:** - **[locks](./Locks):** *"cmd:all()"* - **[`help_category`](./Help-System):** *"General"* -- **Source:** class `CmdGive` in [general.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/general.py). -Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). +- **Source:** class `CmdGive` in +[general.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/general.py). +Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](http +s://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). #### home (CmdHome) @@ -1821,11 +1980,13 @@ Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdse Teleports you to your home location. ``` - **key:** *home* -- **aliases:** +- **aliases:** - **[locks](./Locks):** *"cmd:perm(home) or perm(Builder)"* - **[`help_category`](./Help-System):** *"General"* -- **Source:** class `CmdHome` in [general.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/general.py). -Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). +- **Source:** class `CmdHome` in +[general.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/general.py). +Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](http +s://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). #### inventory (CmdInventory) @@ -1842,8 +2003,10 @@ Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdse - **aliases:** *i*, *inv* - **[locks](./Locks):** *"cmd:all()"* - **[`help_category`](./Help-System):** *"General"* -- **Source:** class `CmdInventory` in [general.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/general.py). -Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). +- **Source:** class `CmdInventory` in +[general.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/general.py). +Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](http +s://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). #### look (CmdLook) @@ -1861,8 +2024,10 @@ Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdse - **aliases:** *l*, *ls* - **[locks](./Locks):** *"cmd:all()"* - **[`help_category`](./Help-System):** *"General"* -- **Source:** class `CmdLook` in [general.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/general.py). -Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). +- **Source:** class `CmdLook` in +[general.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/general.py). +Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](http +s://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). #### nick (CmdNick) @@ -1910,8 +2075,10 @@ Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdse - **aliases:** *nicks*, *nickname* - **[locks](./Locks):** *"cmd:all()"* - **[`help_category`](./Help-System):** *"General"* -- **Source:** class `CmdNick` in [general.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/general.py). -Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_account.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_account.py). +- **Source:** class `CmdNick` in +[general.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/general.py). +Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_account.py](https://gi +thub.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_account.py). #### pose (CmdPose) @@ -1934,8 +2101,10 @@ Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_ac - **aliases:** *:*, *emote* - **[locks](./Locks):** *"cmd:all()"* - **[`help_category`](./Help-System):** *"General"* -- **Source:** class `CmdPose` in [general.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/general.py). -Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). +- **Source:** class `CmdPose` in +[general.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/general.py). +Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](http +s://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). #### say (CmdSay) @@ -1951,8 +2120,10 @@ Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdse - **aliases:** *'*, *"* - **[locks](./Locks):** *"cmd:all()"* - **[`help_category`](./Help-System):** *"General"* -- **Source:** class `CmdSay` in [general.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/general.py). -Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). +- **Source:** class `CmdSay` in +[general.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/general.py). +Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](http +s://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). #### setdesc (CmdSetDesc) @@ -1967,11 +2138,13 @@ Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdse look at you. ``` - **key:** *setdesc* -- **aliases:** +- **aliases:** - **[locks](./Locks):** *"cmd:all()"* - **[`help_category`](./Help-System):** *"General"* -- **Source:** class `CmdSetDesc` in [general.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/general.py). -Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). +- **Source:** class `CmdSetDesc` in +[general.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/general.py). +Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](http +s://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). #### whisper (CmdWhisper) @@ -1986,16 +2159,19 @@ Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdse others in the room being informed. ``` - **key:** *whisper* -- **aliases:** +- **aliases:** - **[locks](./Locks):** *"cmd:all()"* - **[`help_category`](./Help-System):** *"General"* -- **Source:** class `CmdWhisper` in [general.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/general.py). -Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). +- **Source:** class `CmdWhisper` in +[general.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/general.py). +Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](http +s://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). ### `help.py` -[View help.py source](https://github.com/evennia/evennia/tree/master/evennia/commands/default/help.py) +[View help.py +source](https://github.com/evennia/evennia/tree/master/evennia/commands/default/help.py) #### help (CmdHelp) @@ -2014,8 +2190,10 @@ Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdse - **aliases:** *?* - **[locks](./Locks):** *"cmd:all()"* - **[`help_category`](./Help-System):** *"General"* -- **Source:** class `CmdHelp` in [help.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/help.py). -Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_account.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_account.py). +- **Source:** class `CmdHelp` in +[help.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/help.py). +Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_account.py](https://gi +thub.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_account.py). #### sethelp (CmdSetHelp) @@ -2044,16 +2222,19 @@ Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_ac is to let everyone read the help file. ``` - **key:** *sethelp* -- **aliases:** +- **aliases:** - **[locks](./Locks):** *"cmd:perm(Helper)"* - **[`help_category`](./Help-System):** *"Building"* -- **Source:** class `CmdSetHelp` in [help.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/help.py). -Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). +- **Source:** class `CmdSetHelp` in +[help.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/help.py). +Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](http +s://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). ### `system.py` -[View system.py source](https://github.com/evennia/evennia/tree/master/evennia/commands/default/system.py) +[View system.py +source](https://github.com/evennia/evennia/tree/master/evennia/commands/default/system.py) #### about (CmdAbout) @@ -2069,8 +2250,10 @@ Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdse - **aliases:** *version* - **[locks](./Locks):** *"cmd:all()"* - **[`help_category`](./Help-System):** *"System"* -- **Source:** class `CmdAbout` in [system.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/system.py). -Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). +- **Source:** class `CmdAbout` in +[system.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/system.py). +Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](http +s://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). #### objects (CmdObjects) @@ -2088,8 +2271,10 @@ Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdse - **aliases:** *db*, *listobjs*, *stats*, *listobjects* - **[locks](./Locks):** *"cmd:perm(listobjects) or perm(Builder)"* - **[`help_category`](./Help-System):** *"System"* -- **Source:** class `CmdObjects` in [system.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/system.py). -Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). +- **Source:** class `CmdObjects` in +[system.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/system.py). +Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](http +s://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). #### py (CmdPy) @@ -2142,8 +2327,10 @@ Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdse - **aliases:** *!* - **[locks](./Locks):** *"cmd:perm(py) or perm(Developer)"* - **[`help_category`](./Help-System):** *"System"* -- **Source:** class `CmdPy` in [system.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/system.py). -Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_account.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_account.py). +- **Source:** class `CmdPy` in +[system.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/system.py). +Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_account.py](https://gi +thub.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_account.py). #### reload (CmdReload) @@ -2161,8 +2348,10 @@ Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_ac - **aliases:** *restart* - **[locks](./Locks):** *"cmd:perm(reload) or perm(Developer)"* - **[`help_category`](./Help-System):** *"System"* -- **Source:** class `CmdReload` in [system.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/system.py). -Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_account.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_account.py). +- **Source:** class `CmdReload` in +[system.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/system.py). +Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_account.py](https://gi +thub.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_account.py). #### reset (CmdReset) @@ -2188,8 +2377,10 @@ Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_ac - **aliases:** *reboot* - **[locks](./Locks):** *"cmd:perm(reload) or perm(Developer)"* - **[`help_category`](./Help-System):** *"System"* -- **Source:** class `CmdReset` in [system.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/system.py). -Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_account.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_account.py). +- **Source:** class `CmdReset` in +[system.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/system.py). +Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_account.py](https://gi +thub.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_account.py). #### scripts (CmdScripts) @@ -2217,8 +2408,10 @@ Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_ac - **aliases:** *globalscript*, *listscripts* - **[locks](./Locks):** *"cmd:perm(listscripts) or perm(Admin)"* - **[`help_category`](./Help-System):** *"System"* -- **Source:** class `CmdScripts` in [system.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/system.py). -Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). +- **Source:** class `CmdScripts` in +[system.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/system.py). +Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](http +s://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). #### server (CmdServerLoad) @@ -2260,8 +2453,10 @@ Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdse - **aliases:** *serverprocess*, *serverload* - **[locks](./Locks):** *"cmd:perm(list) or perm(Developer)"* - **[`help_category`](./Help-System):** *"System"* -- **Source:** class `CmdServerLoad` in [system.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/system.py). -Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). +- **Source:** class `CmdServerLoad` in +[system.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/system.py). +Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](http +s://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). #### service (CmdService) @@ -2287,8 +2482,10 @@ Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdse - **aliases:** *services* - **[locks](./Locks):** *"cmd:perm(service) or perm(Developer)"* - **[`help_category`](./Help-System):** *"System"* -- **Source:** class `CmdService` in [system.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/system.py). -Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). +- **Source:** class `CmdService` in +[system.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/system.py). +Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](http +s://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). #### shutdown (CmdShutdown) @@ -2301,11 +2498,13 @@ Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdse Gracefully shut down both Server and Portal. ``` - **key:** *shutdown* -- **aliases:** +- **aliases:** - **[locks](./Locks):** *"cmd:perm(shutdown) or perm(Developer)"* - **[`help_category`](./Help-System):** *"System"* -- **Source:** class `CmdShutdown` in [system.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/system.py). -Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_account.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_account.py). +- **Source:** class `CmdShutdown` in +[system.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/system.py). +Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_account.py](https://gi +thub.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_account.py). #### time (CmdTime) @@ -2322,13 +2521,16 @@ Belongs to command set *'DefaultAccount'* of class `AccountCmdSet` in [cmdset_ac - **aliases:** *uptime* - **[locks](./Locks):** *"cmd:perm(time) or perm(Player)"* - **[`help_category`](./Help-System):** *"System"* -- **Source:** class `CmdTime` in [system.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/system.py). -Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). +- **Source:** class `CmdTime` in +[system.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/system.py). +Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdset_character.py](http +s://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_character.py). ### `unloggedin.py` -[View unloggedin.py source](https://github.com/evennia/evennia/tree/master/evennia/commands/default/unloggedin.py) +[View unloggedin.py +source](https://github.com/evennia/evennia/tree/master/evennia/commands/default/unloggedin.py) #### __unloggedin_look_command (CmdUnconnectedLook) @@ -2347,10 +2549,13 @@ Belongs to command set *'DefaultCharacter'* of class `CharacterCmdSet` in [cmdse - **aliases:** *l*, *look* - **[locks](./Locks):** *"cmd:all()"* - **[`help_category`](./Help-System):** *"General"* -- **Source:** class `CmdUnconnectedLook` in [unloggedin.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/unloggedin.py). -Belongs to command set *'DefaultUnloggedin'* of class `UnloggedinCmdSet` in [cmdset_unloggedin.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_unloggedin.py). +- **Source:** class `CmdUnconnectedLook` in [unloggedin.py](https://github.com/evennia/evennia/tree/ +master/evennia/commands/default/unloggedin.py). +Belongs to command set *'DefaultUnloggedin'* of class `UnloggedinCmdSet` in [cmdset_unloggedin.py](h +ttps://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_unloggedin.py). -*OBS: This is a [[System Command|Commands]]. System commands have fixed keys and are called by the server in specific situations.* +*OBS: This is a [[System Command|Commands]]. System commands have fixed keys and are called by the +server in specific situations.* #### connect (CmdUnconnectedConnect) ``` @@ -2368,8 +2573,10 @@ Belongs to command set *'DefaultUnloggedin'* of class `UnloggedinCmdSet` in [cmd - **aliases:** *con*, *conn*, *co* - **[locks](./Locks):** *"cmd:all()"* - **[`help_category`](./Help-System):** *"General"* -- **Source:** class `CmdUnconnectedConnect` in [unloggedin.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/unloggedin.py). -Belongs to command set *'DefaultUnloggedin'* of class `UnloggedinCmdSet` in [cmdset_unloggedin.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_unloggedin.py). +- **Source:** class `CmdUnconnectedConnect` in [unloggedin.py](https://github.com/evennia/evennia/tr +ee/master/evennia/commands/default/unloggedin.py). +Belongs to command set *'DefaultUnloggedin'* of class `UnloggedinCmdSet` in [cmdset_unloggedin.py](h +ttps://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_unloggedin.py). #### create (CmdUnconnectedCreate) @@ -2388,8 +2595,10 @@ Belongs to command set *'DefaultUnloggedin'* of class `UnloggedinCmdSet` in [cmd - **aliases:** *cre*, *cr* - **[locks](./Locks):** *"cmd:all()"* - **[`help_category`](./Help-System):** *"General"* -- **Source:** class `CmdUnconnectedCreate` in [unloggedin.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/unloggedin.py). -Belongs to command set *'DefaultUnloggedin'* of class `UnloggedinCmdSet` in [cmdset_unloggedin.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_unloggedin.py). +- **Source:** class `CmdUnconnectedCreate` in [unloggedin.py](https://github.com/evennia/evennia/tre +e/master/evennia/commands/default/unloggedin.py). +Belongs to command set *'DefaultUnloggedin'* of class `UnloggedinCmdSet` in [cmdset_unloggedin.py](h +ttps://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_unloggedin.py). #### help (CmdUnconnectedHelp) @@ -2406,8 +2615,10 @@ Belongs to command set *'DefaultUnloggedin'* of class `UnloggedinCmdSet` in [cmd - **aliases:** *?*, *h* - **[locks](./Locks):** *"cmd:all()"* - **[`help_category`](./Help-System):** *"General"* -- **Source:** class `CmdUnconnectedHelp` in [unloggedin.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/unloggedin.py). -Belongs to command set *'DefaultUnloggedin'* of class `UnloggedinCmdSet` in [cmdset_unloggedin.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_unloggedin.py). +- **Source:** class `CmdUnconnectedHelp` in [unloggedin.py](https://github.com/evennia/evennia/tree/ +master/evennia/commands/default/unloggedin.py). +Belongs to command set *'DefaultUnloggedin'* of class `UnloggedinCmdSet` in [cmdset_unloggedin.py](h +ttps://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_unloggedin.py). #### quit (CmdUnconnectedQuit) @@ -2425,6 +2636,8 @@ Belongs to command set *'DefaultUnloggedin'* of class `UnloggedinCmdSet` in [cmd - **aliases:** *qu*, *q* - **[locks](./Locks):** *"cmd:all()"* - **[`help_category`](./Help-System):** *"General"* -- **Source:** class `CmdUnconnectedQuit` in [unloggedin.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/unloggedin.py). -Belongs to command set *'DefaultUnloggedin'* of class `UnloggedinCmdSet` in [cmdset_unloggedin.py](https://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_unloggedin.py). +- **Source:** class `CmdUnconnectedQuit` in [unloggedin.py](https://github.com/evennia/evennia/tree/ +master/evennia/commands/default/unloggedin.py). +Belongs to command set *'DefaultUnloggedin'* of class `UnloggedinCmdSet` in [cmdset_unloggedin.py](h +ttps://github.com/evennia/evennia/tree/master/evennia/commands/default/cmdset_unloggedin.py). diff --git a/docs/source/Default-Exit-Errors.md b/docs/source/Default-Exit-Errors.md index f3476bbc6e..0c6132ef30 100644 --- a/docs/source/Default-Exit-Errors.md +++ b/docs/source/Default-Exit-Errors.md @@ -1,23 +1,34 @@ # Default Exit Errors -Evennia allows for exits to have any name. The command "kitchen" is a valid exit name as well as "jump out the window" or "north". An exit actually consists of two parts: an [Exit Object](./Objects) and an [Exit Command](./Commands) stored on said exit object. The command has the same key and aliases as the object, which is why you can see the exit in the room and just write its name to traverse it. +Evennia allows for exits to have any name. The command "kitchen" is a valid exit name as well as +"jump out the window" or "north". An exit actually consists of two parts: an [Exit Object](./Objects) +and an [Exit Command](./Commands) stored on said exit object. The command has the same key and aliases +as the object, which is why you can see the exit in the room and just write its name to traverse it. -If you try to enter the name of a non-existing exit, it is thus the same as trying a non-exising command; Evennia doesn't care about the difference: +If you try to enter the name of a non-existing exit, it is thus the same as trying a non-exising +command; Evennia doesn't care about the difference: > jump out the window Command 'jump out the window' is not available. Type "help" for help. -Many games don't need this type of freedom however. They define only the cardinal directions as valid exit names (Evennia's `@tunnel` command also offers this functionality). In this case, the error starts to look less logical: +Many games don't need this type of freedom however. They define only the cardinal directions as +valid exit names (Evennia's `@tunnel` command also offers this functionality). In this case, the +error starts to look less logical: > west Command 'west' is not available. Maybe you meant "@set" or "@reset"? -Since we for our particular game *know* that west is an exit direction, it would be better if the error message just told us that we couldn't go there. +Since we for our particular game *know* that west is an exit direction, it would be better if the +error message just told us that we couldn't go there. ## Adding default error commands -To solve this you need to be aware of how to [write and add new commands](./Adding-Command-Tutorial). What you need to do is to create new commands for all directions you want to support in your game. In this example all we'll do is echo an error message, but you could certainly consider more advanced uses. You add these commands to the default command set. Here is an example of such a set of commands: +To solve this you need to be aware of how to [write and add new commands](./Adding-Command-Tutorial). +What you need to do is to create new commands for all directions you want to support in your game. +In this example all we'll do is echo an error message, but you could certainly consider more +advanced uses. You add these commands to the default command set. Here is an example of such a set +of commands: ```python # for example in a file mygame/commands/movecommands.py @@ -25,13 +36,13 @@ To solve this you need to be aware of how to [write and add new commands](./Addi from evennia import default_cmds class CmdExitError(default_cmds.MuxCommand): - "Parent class for all exit-errors." + "Parent class for all exit-errors." locks = "cmd:all()" arg_regex = r"\s|$" auto_help = False def func(self): "returns the error" - self.caller.msg("You cannot move %s." % self.key) + self.caller.msg("You cannot move %s." % self.key) class CmdExitErrorNorth(CmdExitError): key = "north" @@ -50,7 +61,8 @@ class CmdExitErrorWest(CmdExitError): aliases = ["w"] ``` -Make sure to add the directional commands (not their parent) to the `CharacterCmdSet` class in `mygame/commands/default_cmdsets.py`: +Make sure to add the directional commands (not their parent) to the `CharacterCmdSet` class in +`mygame/commands/default_cmdsets.py`: ```python # in mygame/commands/default_cmdsets.py @@ -63,34 +75,48 @@ class CharacterCmdSet(default_cmds.CharacterCmdSet): def at_cmdset_creation(self): # [...] self.add(movecommands.CmdExitErrorNorth()) - self.add(movecommands.CmdExitErrorEast()) + self.add(movecommands.CmdExitErrorEast()) self.add(movecommands.CmdExitErrorSouth()) self.add(movecommands.CmdExitErrorWest()) ``` -After a `@reload` these commands (assuming you don't get any errors - check your log) will be loaded. What happens henceforth is that if you are in a room with an Exitobject (let's say it's "north"), the proper Exit-command will overload your error command (also named "north"). But if you enter an direction without having a matching exit for it, you will fallback to your default error commands: +After a `@reload` these commands (assuming you don't get any errors - check your log) will be +loaded. What happens henceforth is that if you are in a room with an Exitobject (let's say it's +"north"), the proper Exit-command will overload your error command (also named "north"). But if you +enter an direction without having a matching exit for it, you will fallback to your default error +commands: > east You cannot move east. -Further expansions by the exit system (including manipulating the way the Exit command itself is created) can be done by modifying the [Exit typeclass](./Typeclasses) directly. +Further expansions by the exit system (including manipulating the way the Exit command itself is +created) can be done by modifying the [Exit typeclass](./Typeclasses) directly. ## Additional Comments -So why didn't we create a single error command above? Something like this: +So why didn't we create a single error command above? Something like this: ```python class CmdExitError(default_cmds.MuxCommand): "Handles all exit-errors." key = "error_cmd" - aliases = ["north", "n", + aliases = ["north", "n", "east", "e", "south", "s", "west", "w"] #[...] ``` -The anwer is that this would *not* work and understanding why is important in order to not be confused when working with commands and command sets. +The anwer is that this would *not* work and understanding why is important in order to not be +confused when working with commands and command sets. -The reason it doesn't work is because Evennia's [command system](./Commands) compares commands *both* by `key` and by `aliases`. If *either* of those match, the two commands are considered *identical* as far as cmdset merging system is concerned. +The reason it doesn't work is because Evennia's [command system](./Commands) compares commands *both* +by `key` and by `aliases`. If *either* of those match, the two commands are considered *identical* +as far as cmdset merging system is concerned. -So the above example would work fine as long as there were no Exits at all in the room. But what happens when we enter a room with an exit "north"? The Exit's cmdset is merged onto the default one, and since there is an alias match, the system determines our `CmdExitError` to be identical. It is thus overloaded by the Exit command (which also correctly defaults to a higher priority). The result is that you can go through the north exit normally but none of the error messages for the other directions are available since the single error command was completely overloaded by the single matching "north" exit-command. +So the above example would work fine as long as there were no Exits at all in the room. But what +happens when we enter a room with an exit "north"? The Exit's cmdset is merged onto the default one, +and since there is an alias match, the system determines our `CmdExitError` to be identical. It is +thus overloaded by the Exit command (which also correctly defaults to a higher priority). The result +is that you can go through the north exit normally but none of the error messages for the other +directions are available since the single error command was completely overloaded by the single +matching "north" exit-command. diff --git a/docs/source/Developer-Central.md b/docs/source/Developer-Central.md index 974f2519f5..b1513d0a26 100644 --- a/docs/source/Developer-Central.md +++ b/docs/source/Developer-Central.md @@ -1,7 +1,8 @@ # Developer Central -This page serves as a central nexus for information on using Evennia as well as developing the library itself. +This page serves as a central nexus for information on using Evennia as well as developing the +library itself. ### General Evennia development information @@ -26,7 +27,7 @@ This page serves as a central nexus for information on using Evennia as well as #### Core components and protocols -- [Server and Portal](./Portal-And-Server) +- [Server and Portal](./Portal-And-Server) - [Sessions](./Sessions) - [Configuration and module plugins](./Server-Conf) - [The message path](./Messagepath) @@ -34,14 +35,14 @@ This page serves as a central nexus for information on using Evennia as well as - [Inputfuncs](./Inputfuncs) - [Adding new protocols (client APIs) and services](./Custom-Protocols) - [Adding new database models](./New-Models) -- [Running and writing unit tests](./Unit-Testing) -- [Running profiling](./Profiling) +- [Unit Testing](./Unit-Testing) +- [Running profiling](./Profiling) - [Debugging your code](./Debugging) #### In-game Commands - [Command System overview](./Command-System) -- [Commands](./Commands) +- [Commands](./Commands) - [Command Sets](./Command-Sets) - [Command Auto-help](./Help-System#command-auto-help-system) @@ -65,7 +66,7 @@ This page serves as a central nexus for information on using Evennia as well as - [Tags](./Tags) - [Tags for Aliases and Permissions](./Tags#using-aliases-and-permissions) -#### Web +#### Web - [Web features overview](./Web-Features) - [The Webclient](./Webclient) @@ -91,13 +92,17 @@ This page serves as a central nexus for information on using Evennia as well as ### Developer brainstorms and whitepages -- [API refactoring](./API-refactoring), discussing what parts of the Evennia API needs a refactoring/cleanup/simplification -- [Docs refactoring](./Docs-refactoring), discussing how to reorganize and structure this wiki/docs better going forward +- [API refactoring](./API-refactoring), discussing what parts of the Evennia API needs a +refactoring/cleanup/simplification +- [Docs refactoring](./Docs-refactoring), discussing how to reorganize and structure this wiki/docs +better going forward - [Webclient brainstorm](./Webclient-brainstorm), some ideas for a future webclient gui - [Roadmap](./Roadmap), a tentative list of future major features -- [Change log](https://github.com/evennia/evennia/blob/master/CHANGELOG.md) of big Evennia updates over time +- [Change log](https://github.com/evennia/evennia/blob/master/CHANGELOG.md) of big Evennia updates +over time [group]: https://groups.google.com/forum/#!forum/evennia -[online-form]: https://docs.google.com/spreadsheet/viewform?hl=en_US&formkey=dGN0VlJXMWpCT3VHaHpscDEzY1RoZGc6MQ#gid=0 +[online-form]: https://docs.google.com/spreadsheet/viewform?hl=en_US&formkey=dGN0VlJXMWpCT3VHaHpscDE +zY1RoZGc6MQ#gid=0 [issues]: https://github.com/evennia/evennia/issues diff --git a/docs/source/Dialogues-in-events.md b/docs/source/Dialogues-in-events.md index ff4b6bf3da..9e4760c6ba 100644 --- a/docs/source/Dialogues-in-events.md +++ b/docs/source/Dialogues-in-events.md @@ -1,15 +1,28 @@ # Dialogues in events -- Next tutorial: [adding a voice-operated elevator with events](./A-voice-operated-elevator-using-events). +- Next tutorial: [adding a voice-operated elevator with events](A-voice-operated-elevator-using- +events). -This tutorial will walk you through the steps to create several dialogues with characters, using the [in-game Python system](https://github.com/evennia/evennia/blob/master/evennia/contrib/ingame_python/README.md). This tutorial assumes the in-game Python system is installed in your game. If it isn't, you can follow the installation steps given in [the documentation on in-game Python](https://github.com/evennia/evennia/blob/master/evennia/contrib/ingame_python/README.md), and come back on this tutorial once the system is installed. **You do not need to read** the entire documentation, it's a good reference, but not the easiest way to learn about it. Hence these tutorials. +This tutorial will walk you through the steps to create several dialogues with characters, using the +[in-game Python +system](https://github.com/evennia/evennia/blob/master/evennia/contrib/ingame_python/README.md). +This tutorial assumes the in-game Python system is installed in your game. If it isn't, you can +follow the installation steps given in [the documentation on in-game +Python](https://github.com/evennia/evennia/blob/master/evennia/contrib/ingame_python/README.md), and +come back on this tutorial once the system is installed. **You do not need to read** the entire +documentation, it's a good reference, but not the easiest way to learn about it. Hence these +tutorials. -The in-game Python system allows to run code on individual objects in some situations. You don't have to modify the source code to add these features, past the installation. The entire system makes it easy to add specific features to some objects, but not all. This is why it can be very useful to create a dialogue system taking advantage of the in-game Python system. +The in-game Python system allows to run code on individual objects in some situations. You don't +have to modify the source code to add these features, past the installation. The entire system +makes it easy to add specific features to some objects, but not all. This is why it can be very +useful to create a dialogue system taking advantage of the in-game Python system. > What will we try to do? -In this tutorial, we are going to create a basic dialogue to have several characters automatically respond to specific messages said by others. +In this tutorial, we are going to create a basic dialogue to have several characters automatically +respond to specific messages said by others. ## A first example with a first character @@ -17,15 +30,25 @@ Let's create a character to begin with. @charcreate a merchant -This will create a merchant in the room where you currently are. It doesn't have anything, like a description, you can decorate it a bit if you like. +This will create a merchant in the room where you currently are. It doesn't have anything, like a +description, you can decorate it a bit if you like. -As said above, the in-game Python system consists in linking objects with arbitrary code. This code will be executed in some circumstances. Here, the circumstance is "when someone says something in the same room", and might be more specific like "when someone says hello". We'll decide what code to run (we'll actually type the code in-game). Using the vocabulary of the in-game Python system, we'll create a callback: a callback is just a set of lines of code that will run under some conditions. +As said above, the in-game Python system consists in linking objects with arbitrary code. This code +will be executed in some circumstances. Here, the circumstance is "when someone says something in +the same room", and might be more specific like "when someone says hello". We'll decide what code +to run (we'll actually type the code in-game). Using the vocabulary of the in-game Python system, +we'll create a callback: a callback is just a set of lines of code that will run under some +conditions. -You can have an overview of every "conditions" in which callbacks can be created using the `@call` command (short for `@callback`). You need to give it an object as argument. Here for instance, we could do: +You can have an overview of every "conditions" in which callbacks can be created using the `@call` +command (short for `@callback`). You need to give it an object as argument. Here for instance, we +could do: @call a merchant -You should see a table with three columns, showing the list of events existing on our newly-created merchant. There are quite a lot of them, as it is, althougn no line of code has been set yet. For our system, you might be more interested by the line describing the `say` event: +You should see a table with three columns, showing the list of events existing on our newly-created +merchant. There are quite a lot of them, as it is, althougn no line of code has been set yet. For +our system, you might be more interested by the line describing the `say` event: | say | 0 (0) | After another character has said something in | | | | the character's room. | @@ -36,11 +59,18 @@ We'll create a callback on the `say` event, called when we say "hello" in the me Before seeing what this command displays, let's see the command syntax itself: -- `@call` is the command name, `/add` is a switch. You can read the help of the command to get the help of available switches and a brief overview of syntax. -- We then enter the object's name, here "a merchant". You can enter the ID too ("#3" in my case), which is useful to edit the object when you're not in the same room. You can even enter part of the name, as usual. +- `@call` is the command name, `/add` is a switch. You can read the help of the command to get the +help of available switches and a brief overview of syntax. +- We then enter the object's name, here "a merchant". You can enter the ID too ("#3" in my case), +which is useful to edit the object when you're not in the same room. You can even enter part of the +name, as usual. - An equal sign, a simple separator. -- The event's name. Here, it's "say". The available events are displayed when you use `@call` without switch. -- After a space, we enter the conditions in which this callback should be called. Here, the conditions represent what the other character should say. We enter "hello". Meaning that if someone says something containing "hello" in the room, the callback we are now creating will be called. +- The event's name. Here, it's "say". The available events are displayed when you use `@call` +without switch. +- After a space, we enter the conditions in which this callback should be called. Here, the +conditions represent what the other character should say. We enter "hello". Meaning that if +someone says something containing "hello" in the room, the callback we are now creating will be +called. When you enter this command, you should see something like this: @@ -70,23 +100,30 @@ Variables you can use in this event: That's some list of information. What's most important to us now is: - The "say" event is called whenever someone else speaks in the room. -- We can set callbacks to fire when specific keywords are present in the phrase by putting them as additional parameters. Here we have set this parameter to "hello". We can have several keywords separated by a comma (we'll see this in more details later). -- We have three default variables we can use in this callback: `speaker` which contains the character who speaks, `character` which contains the character who's modified by the in-game Python system (here, or merchant), and `message` which contains the spoken phrase. +- We can set callbacks to fire when specific keywords are present in the phrase by putting them as +additional parameters. Here we have set this parameter to "hello". We can have several keywords +separated by a comma (we'll see this in more details later). +- We have three default variables we can use in this callback: `speaker` which contains the +character who speaks, `character` which contains the character who's modified by the in-game Python +system (here, or merchant), and `message` which contains the spoken phrase. -This concept of variables is important. If it makes things more simple to you, think of them as parameters in a function: they can be used inside of the function body because they have been set when the function was called. +This concept of variables is important. If it makes things more simple to you, think of them as +parameters in a function: they can be used inside of the function body because they have been set +when the function was called. This command has opened an editor where we can type our Python code. ``` ----------Line Editor [Callback say of a merchant]-------------------------------- -01| +01| ----------[l:01 w:000 c:0000]------------(:h for help)---------------------------- ``` For our first test, let's type something like: ```python -character.location.msg_contents("{character} shrugs and says: 'well, yes, hello to you!'", mapping=dict(character=character)) +character.location.msg_contents("{character} shrugs and says: 'well, yes, hello to you!'", +mapping=dict(character=character)) ``` Once you have entered this line, you can type `:wq` to save the editor and quit it. @@ -102,10 +139,16 @@ If you say something that doesn't contain "hello", our callback won't execute. **In summary**: -1. When we say something in the room, using the "say" command, the "say" event of all characters (except us) is called. -2. The in-game Python system looks at what we have said, and checks whether one of our callbacks in the "say" event contains a keyword that we have spoken. +1. When we say something in the room, using the "say" command, the "say" event of all characters +(except us) is called. +2. The in-game Python system looks at what we have said, and checks whether one of our callbacks in +the "say" event contains a keyword that we have spoken. 3. If so, call it, defining the event variables as we have seen. -4. The callback is then executed as normal Python code. Here we have called the `msg_contents` method on the character's location (probably a room) to display a message to the entire room. We have also used mapping to easily display the character's name. This is not specific to the in-game Python system. If you feel overwhelmed by the code we've used, just shorten it and use something more simple, for instance: +4. The callback is then executed as normal Python code. Here we have called the `msg_contents` +method on the character's location (probably a room) to display a message to the entire room. We +have also used mapping to easily display the character's name. This is not specific to the in-game +Python system. If you feel overwhelmed by the code we've used, just shorten it and use something +more simple, for instance: ```python speaker.msg("You have said something to me.") @@ -113,17 +156,20 @@ speaker.msg("You have said something to me.") ## The same callback for several keywords -It's easy to create a callback that will be triggered if the sentence contains one of several keywords. +It's easy to create a callback that will be triggered if the sentence contains one of several +keywords. @call/add merchant = say trade, trader, goods And in the editor that opens: ```python -character.location.msg_contents("{character} says: 'Ho well, trade's fine as long as roads are safe.'", mapping=dict(character=character)) +character.location.msg_contents("{character} says: 'Ho well, trade's fine as long as roads are +safe.'", mapping=dict(character=character)) ``` -Then you can say something with either "trade", "trader" or "goods" in your sentence, which should call the callback: +Then you can say something with either "trade", "trader" or "goods" in your sentence, which should +call the callback: ``` You say, "and how is your trade going?" @@ -134,18 +180,25 @@ We can set several keywords when adding the callback. We just need to separate ## A longer callback -So far, we have only set one line in our callbacks. Which is useful, but we often need more. For an entire dialogue, you might want to do a bit more than that. +So far, we have only set one line in our callbacks. Which is useful, but we often need more. For +an entire dialogue, you might want to do a bit more than that. @call/add merchant = say bandit, bandits And in the editor you can paste the following lines: ```python -character.location.msg_contents("{character} says: 'Bandits he?'", mapping=dict(character=character)) -character.location.msg_contents("{character} scratches his head, considering.", mapping=dict(character=character)) -character.location.msg_contents("{character} whispers: 'Aye, saw some of them, north from here. No trouble o' mine, but...'", mapping=dict(character=character)) -speaker.msg("{character} looks at you more closely.".format(character=character.get_display_name(speaker))) -speaker.msg("{character} continues in a low voice: 'Ain't my place to say, but if you need to find 'em, they're encamped some distance away from the road, I guess near a cave or something.'.".format(character=character.get_display_name(speaker))) +character.location.msg_contents("{character} says: 'Bandits he?'", +mapping=dict(character=character)) +character.location.msg_contents("{character} scratches his head, considering.", +mapping=dict(character=character)) +character.location.msg_contents("{character} whispers: 'Aye, saw some of them, north from here. No +trouble o' mine, but...'", mapping=dict(character=character)) +speaker.msg("{character} looks at you more +closely.".format(character=character.get_display_name(speaker))) +speaker.msg("{character} continues in a low voice: 'Ain't my place to say, but if you need to find +'em, they're encamped some distance away from the road, I guess near a cave or +something.'.".format(character=character.get_display_name(speaker))) ``` Now try to ask the merchant about bandits: @@ -156,24 +209,40 @@ a merchant(#3) says: 'Bandits he?' a merchant(#3) scratches his head, considering. a merchant(#3) whispers: 'Aye, saw some of them, north from here. No trouble o' mine, but...' a merchant(#3) looks at you more closely. -a merchant(#3) continues in a low voice: 'Ain't my place to say, but if you need to find 'em, they're encamped some distance away from the road, I guess near a cave or something.'. +a merchant(#3) continues in a low voice: 'Ain't my place to say, but if you need to find 'em, +they're encamped some distance away from the road, I guess near a cave or something.'. ``` -Notice here that the first lines of dialogue are spoken to the entire room, but then the merchant is talking directly to the speaker, and only the speaker hears it. There's no real limit to what you can do with this. +Notice here that the first lines of dialogue are spoken to the entire room, but then the merchant is +talking directly to the speaker, and only the speaker hears it. There's no real limit to what you +can do with this. -- You can set a mood system, storing attributes in the NPC itself to tell you in what mood he is, which will influence the information he will give... perhaps the accuracy of it as well. +- You can set a mood system, storing attributes in the NPC itself to tell you in what mood he is, +which will influence the information he will give... perhaps the accuracy of it as well. - You can add random phrases spoken in some context. -- You can use other actions (you're not limited to having the merchant say something, you can ask him to move, gives you something, attack if you have a combat system, or whatever else). +- You can use other actions (you're not limited to having the merchant say something, you can ask +him to move, gives you something, attack if you have a combat system, or whatever else). - The callbacks are in pure Python, so you can write conditions or loops. -- You can add in "pauses" between some instructions using chained events. This tutorial won't describe how to do that however. You already have a lot to play with. +- You can add in "pauses" between some instructions using chained events. This tutorial won't +describe how to do that however. You already have a lot to play with. ## Tutorial F.A.Q. - **Q:** can I create several characters who would answer to specific dialogue? -- **A:** of course. Te in-game Python system is so powerful because you can set unique code for various objects. You can have several characters answering to different things. You can even have different characters in the room answering to greetings. All callbacks will be executed one after another. +- **A:** of course. Te in-game Python system is so powerful because you can set unique code for +various objects. You can have several characters answering to different things. You can even have +different characters in the room answering to greetings. All callbacks will be executed one after +another. - **Q:** can I have two characters answering to the same dialogue in exactly the same way? -- **A:** It's possible but not so easy to do. Usually, event grouping is set in code, and depends on different games. However, if it is for some infrequent occurrences, it's easy to do using [chained events](https://github.com/evennia/evennia/blob/master/evennia/contrib/ingame_python/README.md#chained-events). +- **A:** It's possible but not so easy to do. Usually, event grouping is set in code, and depends +on different games. However, if it is for some infrequent occurrences, it's easy to do using +[chained events](https://github.com/evennia/evennia/blob/master/evennia/contrib/ingame_python/README +.md#chained-events). - **Q:** is it possible to deploy callbacks on all characters sharing the same prototype? -- **A:** not out of the box. This depends on individual settings in code. One can imagine that all characters of some type would share some events, but this is game-specific. Rooms of the same zone could share the same events as well. It is possible to do but requires modification of the source code. +- **A:** not out of the box. This depends on individual settings in code. One can imagine that all +characters of some type would share some events, but this is game-specific. Rooms of the same zone +could share the same events as well. It is possible to do but requires modification of the source +code. -- Next tutorial: [adding a voice-operated elevator with events](./A-voice-operated-elevator-using-events). +- Next tutorial: [adding a voice-operated elevator with events](A-voice-operated-elevator-using- +events). diff --git a/docs/source/Directory-Overview.md b/docs/source/Directory-Overview.md index a479d29c6d..e4f6b49f0e 100644 --- a/docs/source/Directory-Overview.md +++ b/docs/source/Directory-Overview.md @@ -1,48 +1,68 @@ # Directory Overview -This is an overview of the directories relevant to Evennia coding. +This is an overview of the directories relevant to Evennia coding. ## The Game directory -The game directory is created with `evennia --init `. In the Evennia documentation we always assume it's called `mygame`. Apart from the `server/` subfolder within, you could reorganize this folder if you preferred a different code structure for your game. +The game directory is created with `evennia --init `. In the Evennia documentation we always +assume it's called `mygame`. Apart from the `server/` subfolder within, you could reorganize this +folder if you preferred a different code structure for your game. - `mygame/` - - `commands/` - Overload default [Commands](./Commands) or add your own Commands/[Command sets](./Command-Sets) here. - - `server`/ - The structure of this folder should not change since Evennia expects it. - - [`conf/`](https://github.com/evennia/evennia/tree/master/evennia/game_template/server) - All server configuration files sits here. The most important file is `settings.py`. + - `commands/` - Overload default [Commands](./Commands) or add your own Commands/[Command +sets](Command-Sets) here. + - `server`/ - The structure of this folder should not change since Evennia expects it. + - [`conf/`](https://github.com/evennia/evennia/tree/master/evennia/game_template/server) - All +server configuration files sits here. The most important file is `settings.py`. - `logs/` - Portal log files are stored here (Server is logging to the terminal by default) - - `typeclasses/` - this folder contains empty templates for overloading default game entities of Evennia. Evennia will automatically use the changes in those templates for the game entities it creates. - - `web/` - This holds the [Web features](./Web-Features) of your game. - - `world/` - this is a "miscellaneous" folder holding everything related to the world you are building, such as build scripts and rules modules that don't fit with one of the other folders. + - `typeclasses/` - this folder contains empty templates for overloading default game entities of +Evennia. Evennia will automatically use the changes in those templates for the game entities it +creates. + - `web/` - This holds the [Web features](./Web-Features) of your game. + - `world/` - this is a "miscellaneous" folder holding everything related to the world you are +building, such as build scripts and rules modules that don't fit with one of the other folders. ## Evennia library layout: -If you cloned the GIT repo following the instructions, you will have a folder named `evennia`. The top level of it contains Python package specific stuff such as a readme file, `setup.py` etc. It also has two subfolders`bin/` and `evennia/` (again). +If you cloned the GIT repo following the instructions, you will have a folder named `evennia`. The +top level of it contains Python package specific stuff such as a readme file, `setup.py` etc. It +also has two subfolders`bin/` and `evennia/` (again). -The `bin/` directory holds OS-specific binaries that will be used when installing Evennia with `pip` as per the [Getting started](./Getting-Started) instructions. The library itself is in the `evennia` subfolder. From your code you will access this subfolder simply by `import evennia`. +The `bin/` directory holds OS-specific binaries that will be used when installing Evennia with `pip` +as per the [Getting started](./Getting-Started) instructions. The library itself is in the `evennia` +subfolder. From your code you will access this subfolder simply by `import evennia`. - evennia - - [`__init__.py`](./Evennia-API) - The "flat API" of Evennia resides here. + - [`__init__.py`](./Evennia-API) - The "flat API" of Evennia resides here. - [`commands/`](./Commands) - The command parser and handler. - - `default/` - The [default commands](./Default-Command-Help) and cmdsets. - - [`comms/`](./Communications) - Systems for communicating in-game. + - `default/` - The [default commands](./Default-Command-Help) and cmdsets. + - [`comms/`](./Communications) - Systems for communicating in-game. - `contrib/` - Optional plugins too game-specific for core Evennia. - - `game_template/` - Copied to become the "game directory" when using `evennia --init`. + - `game_template/` - Copied to become the "game directory" when using `evennia --init`. - [`help/`](./Help-System) - Handles the storage and creation of help entries. - `locale/` - Language files ([i18n](./Internationalization)). - [`locks/`](./Locks) - Lock system for restricting access to in-game entities. - [`objects/`](./Objects) - In-game entities (all types of items and Characters). - [`prototypes/`](./Spawner-and-Prototypes) - Object Prototype/spawning system and OLC menu - [`accounts/`](./Accounts) - Out-of-game Session-controlled entities (accounts, bots etc) - - [`scripts/`](./Scripts) - Out-of-game entities equivalence to Objects, also with timer support. - - [`server/`](./Portal-And-Server) - Core server code and Session handling. + - [`scripts/`](./Scripts) - Out-of-game entities equivalence to Objects, also with timer support. + - [`server/`](./Portal-And-Server) - Core server code and Session handling. - `portal/` - Portal proxy and connection protocols. - - [`settings_default.py`](./Server-Conf#Settings-file) - Root settings of Evennia. Copy settings from here to `mygame/server/settings.py` file. + - [`settings_default.py`](./Server-Conf#Settings-file) - Root settings of Evennia. Copy settings +from here to `mygame/server/settings.py` file. - [`typeclasses/`](./Typeclasses) - Abstract classes for the typeclass storage and database system. - [`utils/`](./Coding-Utils) - Various miscellaneous useful coding resources. - - [`web/`](./Web-Features) - Web resources and webserver. Partly copied into game directory on initialization. + - [`web/`](./Web-Features) - Web resources and webserver. Partly copied into game directory on +initialization. -All directories contain files ending in `.py`. These are Python *modules* and are the basic units of Python code. The roots of directories also have (usually empty) files named `__init__.py`. These are required by Python so as to be able to find and import modules in other directories. When you have run Evennia at least once you will find that there will also be `.pyc` files appearing, these are pre-compiled binary versions of the `.py` files to speed up execution. +All directories contain files ending in `.py`. These are Python *modules* and are the basic units of +Python code. The roots of directories also have (usually empty) files named `__init__.py`. These are +required by Python so as to be able to find and import modules in other directories. When you have +run Evennia at least once you will find that there will also be `.pyc` files appearing, these are +pre-compiled binary versions of the `.py` files to speed up execution. -The root of the `evennia` folder has an `__init__.py` file containing the "[flat API](./Evennia-API)". This holds shortcuts to various subfolders in the evennia library. It is provided to make it easier to find things; it allows you to just import `evennia` and access things from that rather than having to import from their actual locations inside the source tree. +The root of the `evennia` folder has an `__init__.py` file containing the "[flat API](./Evennia-API)". +This holds shortcuts to various subfolders in the evennia library. It is provided to make it easier +to find things; it allows you to just import `evennia` and access things from that rather than +having to import from their actual locations inside the source tree. diff --git a/docs/source/Docs-refactoring.md b/docs/source/Docs-refactoring.md index e1554cfcf5..0f97bd50cb 100644 --- a/docs/source/Docs-refactoring.md +++ b/docs/source/Docs-refactoring.md @@ -1,20 +1,29 @@ # Docs refactoring -This is a whitepage for free discussion about the wiki docs and refactorings needed. +This is a whitepage for free discussion about the wiki docs and refactorings needed. -Note that this is not a forum. To keep things clean, each opinion text should ideally present a clear argument or lay out a suggestion. Asking for clarification and any side-discussions should be held in chat or forum. +Note that this is not a forum. To keep things clean, each opinion text should ideally present a +clear argument or lay out a suggestion. Asking for clarification and any side-discussions should be +held in chat or forum. ### Griatch (Aug 13, 2019) -This is how to make a discussion entry for the whitepage. Use any markdown formatting you need. Also remember to copy your work to the clipboard before saving the page since if someone else edited the page since you started, you'll have to reload and write again. +This is how to make a discussion entry for the whitepage. Use any markdown formatting you need. Also +remember to copy your work to the clipboard before saving the page since if someone else edited the +page since you started, you'll have to reload and write again. #### (Sept 23, 2019) -[This (now closed) issue by DamnedScholar](https://github.com/evennia/evennia/issues/1431) gives the following suggestion: -> I think it would be useful for the pages that explain how to use various features of Evennia to have explicit and easily visible links to the respective API entry or entries. Some pages do, but not all. I imagine this as a single entry at the top of the page [...]. +[This (now closed) issue by DamnedScholar](https://github.com/evennia/evennia/issues/1431) gives the +following suggestion: +> I think it would be useful for the pages that explain how to use various features of Evennia to +have explicit and easily visible links to the respective API entry or entries. Some pages do, but +not all. I imagine this as a single entry at the top of the page [...]. -[This (now closed) issue by taladan](https://github.com/evennia/evennia/issues/1578) gives the following suggestion: -> It would help me (and probably a couple of others) if there is a way to show the file path where a particular thing exists. Maybe up under the 'last edited' line we could have a line like: +[This (now closed) issue by taladan](https://github.com/evennia/evennia/issues/1578) gives the +following suggestion: +> It would help me (and probably a couple of others) if there is a way to show the file path where a +particular thing exists. Maybe up under the 'last edited' line we could have a line like: evennia/locks/lockhandler.py This would help in development to quickly refer to where a resource is located. @@ -22,15 +31,22 @@ This would help in development to quickly refer to where a resource is located. ### Kovitikus (Sept. 11, 2019) -[Batch Code](./Batch-Code-Processor) should have a link in the developer area. It is currently only listed in the tutorials section as an afterthought to a tutorial title. +[Batch Code](./Batch-Code-Processor) should have a link in the developer area. It is currently only +listed in the tutorials section as an afterthought to a tutorial title. *** -In regards to the general structure of each wiki page: I'd like to see a table of contents at the top of each one, so that it can be quickly navigated and is immediately apparent what sections are covered on the page. Similar to the current [Getting Started](./Getting-Started) page. +In regards to the general structure of each wiki page: I'd like to see a table of contents at the +top of each one, so that it can be quickly navigated and is immediately apparent what sections are +covered on the page. Similar to the current [Getting Started](./Getting-Started) page. *** -The structuring of the page should also include a quick reference cheatsheet for certain aspects. Such as [Tags](./Tags) including a quick reference section at the top that lists an example of every available method you can use in a clear and consistent format, along with a comment. Readers shouldn't have to decipher the article to gather such basic information and it should instead be available at first glance. +The structuring of the page should also include a quick reference cheatsheet for certain aspects. +Such as [Tags](./Tags) including a quick reference section at the top that lists an example of every +available method you can use in a clear and consistent format, along with a comment. Readers +shouldn't have to decipher the article to gather such basic information and it should instead be +available at first glance. Example of a quick reference: @@ -49,7 +65,7 @@ obj.tags.clear() store_result = evennia.search_tag("label") # Return a list of all tags. -obj.tags.all() +obj.tags.all() ``` **Aliases** @@ -62,7 +78,10 @@ ETC... *** -In regards to comment structure, I often find that smushing together lines with comments to be too obscure. White space should be used to clearly delineate what information the comment is for. I understand that the current format is that a comment references whatever is below it, but newbies may not know that until they realize it. +In regards to comment structure, I often find that smushing together lines with comments to be too +obscure. White space should be used to clearly delineate what information the comment is for. I +understand that the current format is that a comment references whatever is below it, but newbies +may not know that until they realize it. Example of poor formatting: ``` @@ -90,6 +109,9 @@ If I want to find information on the correct syntax for is_typeclass(), here's w * Ctrl+F on utils page. No results. * Ctrl+F on utils.utils page. No results. * Ctrl+F in my IDE. Results. -* Fortunately, there's only one result for def is_typeclass. If this was at_look, there would be several results, and I'd have to go through each of those individually, and most of them would just call return_appearance +* Fortunately, there's only one result for def is_typeclass. If this was at_look, there would be +several results, and I'd have to go through each of those individually, and most of them would just +call return_appearance -An important part of a refactor, in my opinion, is separating out the "Tutorials" from the "Reference" documentation. +An important part of a refactor, in my opinion, is separating out the "Tutorials" from the +"Reference" documentation. diff --git a/docs/source/Dynamic-In-Game-Map.md b/docs/source/Dynamic-In-Game-Map.md index b0bd588d5a..2ae0291b48 100644 --- a/docs/source/Dynamic-In-Game-Map.md +++ b/docs/source/Dynamic-In-Game-Map.md @@ -1,22 +1,40 @@ # Dynamic In Game Map -## Introduction +## Introduction -An often desired feature in a MUD is to show an in-game map to help navigation. The [Static in-game map](./Static-In-Game-Map) tutorial solves this by creating a *static* map, meaning the map is pre-drawn once and for all - the rooms are then created to match that map. When walking around, parts of the static map is then cut out and displayed next to the room description. +An often desired feature in a MUD is to show an in-game map to help navigation. The [Static in-game +map](Static-In-Game-Map) tutorial solves this by creating a *static* map, meaning the map is pre- +drawn once and for all - the rooms are then created to match that map. When walking around, parts of +the static map is then cut out and displayed next to the room description. -In this tutorial we'll instead do it the other way around; We will dynamically draw the map based on the relationships we find between already existing rooms. +In this tutorial we'll instead do it the other way around; We will dynamically draw the map based on +the relationships we find between already existing rooms. ## The Grid of Rooms -There are at least two requirements needed for this tutorial to work. +There are at least two requirements needed for this tutorial to work. -1. The structure of your mud has to follow a logical layout. Evennia supports the layout of your world to be 'logically' impossible with rooms looping to themselves or exits leading to the other side of the map. Exits can also be named anything, from "jumping out the window" to "into the fifth dimension". This tutorial assumes you can only move in the cardinal directions (N, E, S and W). -2. Rooms must be connected and linked together for the map to be generated correctly. Vanilla Evennia comes with a admin command [@tunnel](./Default-Command-Help#tunnel-cmdtunnel) that allows a user to create rooms in the cardinal directions, but additional work is needed to assure that rooms are connected. For example, if you `@tunnel east` and then immediately do `@tunnel west` you'll find that you have created two completely stand-alone rooms. So care is needed if you want to create a "logical" layout. In this tutorial we assume you have such a grid of rooms that we can generate the map from. +1. The structure of your mud has to follow a logical layout. Evennia supports the layout of your +world to be 'logically' impossible with rooms looping to themselves or exits leading to the other +side of the map. Exits can also be named anything, from "jumping out the window" to "into the fifth +dimension". This tutorial assumes you can only move in the cardinal directions (N, E, S and W). +2. Rooms must be connected and linked together for the map to be generated correctly. Vanilla +Evennia comes with a admin command [@tunnel](./Default-Command-Help#tunnel-cmdtunnel) that allows a +user to create rooms in the cardinal directions, but additional work is needed to assure that rooms +are connected. For example, if you `@tunnel east` and then immediately do `@tunnel west` you'll find +that you have created two completely stand-alone rooms. So care is needed if you want to create a +"logical" layout. In this tutorial we assume you have such a grid of rooms that we can generate the +map from. ## Concept -Before getting into the code, it is beneficial to understand and conceptualize how this is going to work. The idea is analogous to a worm that starts at your current position. It chooses a direction and 'walks' outward from it, mapping its route as it goes. Once it has traveled a pre-set distance it stops and starts over in another direction. An important note is that we want a system which is easily callable and not too complicated. Therefore we will wrap this entire code into a custom Python class (not a typeclass as this doesn't use any core objects from evennia itself). +Before getting into the code, it is beneficial to understand and conceptualize how this is going to +work. The idea is analogous to a worm that starts at your current position. It chooses a direction +and 'walks' outward from it, mapping its route as it goes. Once it has traveled a pre-set distance +it stops and starts over in another direction. An important note is that we want a system which is +easily callable and not too complicated. Therefore we will wrap this entire code into a custom +Python class (not a typeclass as this doesn't use any core objects from evennia itself). We are going to create something that displays like this when you type 'look': @@ -33,23 +51,31 @@ We are going to create something that displays like this when you type 'look': Exits: North, East, South ``` -Your current location is defined by `[@]` while the `[.]`s are other rooms that the "worm" has seen since departing from your location. +Your current location is defined by `[@]` while the `[.]`s are other rooms that the "worm" has seen +since departing from your location. -## Setting up the Map Display +## Setting up the Map Display -First we must define the components for displaying the map. For the "worm" to know what symbol to draw on the map we will have it check an Attribute on the room it visits called `sector_type`. For this tutorial we understand two symbols - a normal room and the room with us in it. We also define a fallback symbol for rooms without said Attribute - that way the map will still work even if we didn't prepare the room correctly. Assuming your game folder is named `mygame`, we create this code in `mygame/world/map.py.` +First we must define the components for displaying the map. For the "worm" to know what symbol to +draw on the map we will have it check an Attribute on the room it visits called `sector_type`. For +this tutorial we understand two symbols - a normal room and the room with us in it. We also define a +fallback symbol for rooms without said Attribute - that way the map will still work even if we +didn't prepare the room correctly. Assuming your game folder is named `mygame`, we create this code +in `mygame/world/map.py.` ```python # in mygame/world/map.py -# the symbol is identified with a key "sector_type" on the -# Room. Keys None and "you" must always exist. -SYMBOLS = { None : ' . ', # for rooms without sector_type Attribute +# the symbol is identified with a key "sector_type" on the +# Room. Keys None and "you" must always exist. +SYMBOLS = { None : ' . ', # for rooms without sector_type Attribute 'you' : '[@]', 'SECT_INSIDE': '[.]' } ``` -Since trying to access an unset Attribute returns `None`, this means rooms without the `sector_type` Atttribute will show as ` . `. Next we start building the custom class `Map`. It will hold all methods we need. +Since trying to access an unset Attribute returns `None`, this means rooms without the `sector_type` +Atttribute will show as ` . `. Next we start building the custom class `Map`. It will hold all +methods we need. ```python # in mygame/world/map.py @@ -66,12 +92,18 @@ class Map(object): ``` - `self.caller` is normally your Character object, the one using the map. -- `self.max_width/length` determine the max width and length of the map that will be generated. Note that it's important that these variables are set to *odd* numbers to make sure the display area has a center point. -- ` self.worm_has_mapped` is building off the worm analogy above. This dictionary will store all rooms the "worm" has mapped as well as its relative position within the grid. This is the most important variable as it acts as a 'checker' and 'address book' that is able to tell us where the worm has been and what it has mapped so far. +- `self.max_width/length` determine the max width and length of the map that will be generated. Note +that it's important that these variables are set to *odd* numbers to make sure the display area has +a center point. +- ` self.worm_has_mapped` is building off the worm analogy above. This dictionary will store all +rooms the "worm" has mapped as well as its relative position within the grid. This is the most +important variable as it acts as a 'checker' and 'address book' that is able to tell us where the +worm has been and what it has mapped so far. - `self.curX/Y` are coordinates representing the worm's current location on the grid. -Before any sort of mapping can actually be done we need to create an empty display area and do some sanity checks on it by using the following methods. +Before any sort of mapping can actually be done we need to create an empty display area and do some +sanity checks on it by using the following methods. ```python # in mygame/world/map.py @@ -90,13 +122,14 @@ class Map(object): return board def check_grid(self): - # this method simply checks the grid to make sure + # this method simply checks the grid to make sure # that both max_l and max_w are odd numbers. return True if self.max_length % 2 != 0 or self.max_width % 2 != 0\ else False ``` -Before we can set our worm on its way, we need to know some of the computer science behind all this called 'Graph Traversing'. In Pseudo code what we are trying to accomplish is this: +Before we can set our worm on its way, we need to know some of the computer science behind all this +called 'Graph Traversing'. In Pseudo code what we are trying to accomplish is this: ```python # pseudo code @@ -108,7 +141,7 @@ def draw_room_on_map(room, max_distance): return for exit in room.exits: - if self.has_drawn(exit.destination): + if self.has_drawn(exit.destination): # skip drawing if we already visited the destination continue else: @@ -116,33 +149,47 @@ def draw_room_on_map(room, max_distance): self.draw_room_on_map(exit.destination, max_distance - 1) ``` -The beauty of Python is that our actual code of doing this doesn't differ much if at all from this Pseudo code example. +The beauty of Python is that our actual code of doing this doesn't differ much if at all from this +Pseudo code example. -- `max_distance` is a variable indicating to our Worm how many rooms AWAY from your current location will it map. Obviously the larger the number the more time it will take if your current location has many many rooms around you. +- `max_distance` is a variable indicating to our Worm how many rooms AWAY from your current location +will it map. Obviously the larger the number the more time it will take if your current location has +many many rooms around you. -The first hurdle here is what value to use for 'max_distance'. There is no reason for the worm to travel further than what is actually displayed to you. For example, if your current location is placed in the center of a display area of size `max_length = max_width = 9`, then the worm need only go `4` spaces in either direction: +The first hurdle here is what value to use for 'max_distance'. There is no reason for the worm to +travel further than what is actually displayed to you. For example, if your current location is +placed in the center of a display area of size `max_length = max_width = 9`, then the worm need only +go `4` spaces in either direction: ``` [.][.][.][.][@][.][.][.][.] - 4 3 2 1 0 1 2 3 4 + 4 3 2 1 0 1 2 3 4 ``` -The max_distance can be set dynamically based on the size of the display area. As your width/length changes it becomes a simple algebraic linear relationship which is simply `max_distance = (min(max_width, max_length) -1) / 2`. +The max_distance can be set dynamically based on the size of the display area. As your width/length +changes it becomes a simple algebraic linear relationship which is simply `max_distance = +(min(max_width, max_length) -1) / 2`. -## Building the Mapper +## Building the Mapper -Now we can start to fill our Map object with some methods. We are still missing a few methods that are very important: +Now we can start to fill our Map object with some methods. We are still missing a few methods that +are very important: * `self.draw(self, room)` - responsible for actually drawing room to grid. -* `self.has_drawn(self, room)` - checks to see if the room has been mapped and worm has already been here. -* `self.median(self, number)` - a simple utility method that finds the median (middle point) from 0, n -* `self.update_pos(self, room, exit_name)` - updates the worm's physical position by reassigning self.curX/Y. .accordingly -* `self.start_loc_on_grid(self)` - the very first initial draw on the grid representing your location in the middle of the grid +* `self.has_drawn(self, room)` - checks to see if the room has been mapped and worm has already been +here. +* `self.median(self, number)` - a simple utility method that finds the median (middle point) from 0, +n +* `self.update_pos(self, room, exit_name)` - updates the worm's physical position by reassigning +self.curX/Y. .accordingly +* `self.start_loc_on_grid(self)` - the very first initial draw on the grid representing your +location in the middle of the grid * 'self.show_map` - after everything is done convert the map into a readable string` * `self.draw_room_on_map(self, room, max_distance)` - the main method that ties it all together.` -Now that we know which methods we need, let's refine our initial `__init__(self)` to pass some conditional statements and set it up to start building the display. +Now that we know which methods we need, let's refine our initial `__init__(self)` to pass some +conditional statements and set it up to start building the display. ```python @@ -162,14 +209,16 @@ class Map(object): # we have to store the grid into a variable self.grid = self.create_grid() # we use the algebraic relationship - self.draw_room_on_map(caller.location, + self.draw_room_on_map(caller.location, ((min(max_width, max_length) -1 ) / 2) ``` -Here we check to see if the parameters for the grid are okay, then we create an empty canvas and map our initial location as the first room! +Here we check to see if the parameters for the grid are okay, then we create an empty canvas and map +our initial location as the first room! -As mentioned above, the code for the `self.draw_room_on_map()` is not much different than the Pseudo code. The method is shown below: +As mentioned above, the code for the `self.draw_room_on_map()` is not much different than the Pseudo +code. The method is shown below: ```python # in mygame/world/map.py, in the Map class @@ -185,7 +234,7 @@ def draw_room_on_map(self, room, max_distance): # we only map in the cardinal directions. Mapping up/down would be # an interesting learning project for someone who wanted to try it. continue - if self.has_drawn(exit.destination): + if self.has_drawn(exit.destination): # we've been to the destination already, skip ahead. continue @@ -196,7 +245,7 @@ def draw_room_on_map(self, room, max_distance): The first thing the "worm" does is to draw your current location in `self.draw`. Lets define that... ```python -#in mygame/word/map.py, in the Map class +#in mygame/word/map.py, in the Map class def draw(self, room): # draw initial ch location on map first! @@ -223,13 +272,16 @@ def start_loc_on_grid(self): x = self.median(self.max_width) y = self.median(self.max_length) # x and y are floats by default, can't index lists with float types - x, y = int(x), int(y) + x, y = int(x), int(y) self.grid[x][y] = SYMBOLS['you'] self.curX, self.curY = x, y # updating worms current location ``` -After the system has drawn the current map it checks to see if the `max_distance` is `0` (since this is the inital start phase it is not). Now we handle the iteration once we have each individual exit in the room. The first thing it does is check if the room the Worm is in has been mapped already.. lets define that... +After the system has drawn the current map it checks to see if the `max_distance` is `0` (since this +is the inital start phase it is not). Now we handle the iteration once we have each individual exit +in the room. The first thing it does is check if the room the Worm is in has been mapped already.. +lets define that... ```python @@ -237,16 +289,18 @@ def has_drawn(self, room): return True if room in self.worm_has_mapped.keys() else False ``` -If `has_drawn` returns `False` that means the worm has found a room that hasn't been mapped yet. It will then 'move' there. The self.curX/Y sort of lags behind, so we have to make sure to track the position of the worm; we do this in `self.update_pos()` below. +If `has_drawn` returns `False` that means the worm has found a room that hasn't been mapped yet. It +will then 'move' there. The self.curX/Y sort of lags behind, so we have to make sure to track the +position of the worm; we do this in `self.update_pos()` below. ```python def update_pos(self, room, exit_name): - # this ensures the coordinates stays up to date + # this ensures the coordinates stays up to date # to where the worm is currently at. self.curX, self.curY = \ self.worm_has_mapped[room][0], self.worm_has_mapped[room][1] - # now we have to actually move the pointer + # now we have to actually move the pointer # variables depending on which 'exit' it found if exit_name == 'east': self.curY += 1 @@ -258,9 +312,11 @@ def update_pos(self, room, exit_name): self.curX += 1 ``` -Once the system updates the position of the worm it feeds the new room back into the original `draw_room_on_map()` and starts the process all over again.. +Once the system updates the position of the worm it feeds the new room back into the original +`draw_room_on_map()` and starts the process all over again.. -That is essentially the entire thing. The final method is to bring it all together and make a nice presentational string out of it using the `self.show_map()` method. +That is essentially the entire thing. The final method is to bring it all together and make a nice +presentational string out of it using the `self.show_map()` method. ```python def show_map(self): @@ -274,9 +330,11 @@ def show_map(self): ## Using the Map -In order for the map to get triggered we store it on the Room typeclass. If we put it in `return_appearance` we will get the map back every time we look at the room. +In order for the map to get triggered we store it on the Room typeclass. If we put it in +`return_appearance` we will get the map back every time we look at the room. -> `return_appearance` is a default Evennia hook available on all objects; it is called e.g. by the `look` command to get the description of something (the room in this case). +> `return_appearance` is a default Evennia hook available on all objects; it is called e.g. by the +`look` command to get the description of something (the room in this case). ```python # in mygame/typeclasses/rooms.py @@ -289,17 +347,30 @@ class Room(DefaultRoom): def return_appearance(self, looker): # [...] string = "%s\n" % Map(looker).show_map() - # Add all the normal stuff like room description, - # contents, exits etc. + # Add all the normal stuff like room description, + # contents, exits etc. string += "\n" + super().return_appearance(looker) - return string + return string ``` -Obviously this method of generating maps doesn't take into account of any doors or exits that are hidden.. etc.. but hopefully it serves as a good base to start with. Like previously mentioned, it is very important to have a solid foundation on rooms before implementing this. You can try this on vanilla evennia by using @tunnel and essentially you can just create a long straight/edgy non-looping rooms that will show on your in-game map. +Obviously this method of generating maps doesn't take into account of any doors or exits that are +hidden.. etc.. but hopefully it serves as a good base to start with. Like previously mentioned, it +is very important to have a solid foundation on rooms before implementing this. You can try this on +vanilla evennia by using @tunnel and essentially you can just create a long straight/edgy non- +looping rooms that will show on your in-game map. -The above example will display the map above the room description. You could also use an [EvTable](github:evennia.utils.evtable) to place description and map next to each other. Some other things you can do is to have a [Command](./Commands) that displays with a larger radius, maybe with a legend and other features. +The above example will display the map above the room description. You could also use an +[EvTable](github:evennia.utils.evtable) to place description and map next to each other. Some other +things you can do is to have a [Command](./Commands) that displays with a larger radius, maybe with a +legend and other features. -Below is the whole `map.py` for your reference. You need to update your `Room` typeclass (see above) to actually call it. Remember that to see different symbols for a location you also need to set the `sector_type` Attribute on the room to one of the keys in the `SYMBOLS` dictionary. So in this example, to make a room be mapped as `[.]` you would set the room's `sector_type` to `"SECT_INSIDE"`. Try it out with `@set here/sector_type = "SECT_INSIDE"`. If you wanted all new rooms to have a given sector symbol, you could change the default in the `SYMBOLS´ dictionary below, or you could add the Attribute in the Room's `at_object_creation` method. +Below is the whole `map.py` for your reference. You need to update your `Room` typeclass (see above) +to actually call it. Remember that to see different symbols for a location you also need to set the +`sector_type` Attribute on the room to one of the keys in the `SYMBOLS` dictionary. So in this +example, to make a room be mapped as `[.]` you would set the room's `sector_type` to +`"SECT_INSIDE"`. Try it out with `@set here/sector_type = "SECT_INSIDE"`. If you wanted all new +rooms to have a given sector symbol, you could change the default in the `SYMBOLS´ dictionary below, +or you could add the Attribute in the Room's `at_object_creation` method. ```python #mygame/world/map.py @@ -307,7 +378,7 @@ Below is the whole `map.py` for your reference. You need to update your `Room` t # These are keys set with the Attribute sector_type on the room. # The keys None and "you" must always exist. SYMBOLS = { None : ' . ', # for rooms without a sector_type attr - 'you' : '[@]', + 'you' : '[@]', 'SECT_INSIDE': '[.]' } class Map(object): @@ -323,16 +394,16 @@ class Map(object): if self.check_grid(): # we actually have to store the grid into a variable self.grid = self.create_grid() - self.draw_room_on_map(caller.location, + self.draw_room_on_map(caller.location, ((min(max_width, max_length) -1 ) / 2)) def update_pos(self, room, exit_name): - # this ensures the pointer variables always + # this ensures the pointer variables always # stays up to date to where the worm is currently at. self.curX, self.curY = \ self.worm_has_mapped[room][0], self.worm_has_mapped[room][1] - # now we have to actually move the pointer + # now we have to actually move the pointer # variables depending on which 'exit' it found if exit_name == 'east': self.curY += 1 @@ -354,7 +425,7 @@ class Map(object): # we only map in the cardinal directions. Mapping up/down would be # an interesting learning project for someone who wanted to try it. continue - if self.has_drawn(exit.destination): + if self.has_drawn(exit.destination): # we've been to the destination already, skip ahead. continue @@ -370,7 +441,7 @@ class Map(object): # map all other rooms self.worm_has_mapped[room] = [self.curX, self.curY] # this will use the sector_type Attribute or None if not set. - self.grid[self.curX][self.curY] = SYMBOLS[room.db.sector_type] + self.grid[self.curX][self.curY] = SYMBOLS[room.db.sector_type] def median(self, num): lst = sorted(range(0, num)) @@ -382,7 +453,7 @@ class Map(object): x = self.median(self.max_width) y = self.median(self.max_length) # x and y are floats by default, can't index lists with float types - x, y = int(x), int(y) + x, y = int(x), int(y) self.grid[x][y] = SYMBOLS['you'] self.curX, self.curY = x, y # updating worms current location @@ -393,7 +464,7 @@ class Map(object): def create_grid(self): - # This method simply creates an empty grid + # This method simply creates an empty grid # with the specified variables from __init__(self): board = [] for row in range(self.max_width): @@ -403,7 +474,7 @@ class Map(object): return board def check_grid(self): - # this method simply checks the grid to make sure + # this method simply checks the grid to make sure # both max_l and max_w are odd numbers return True if self.max_length % 2 != 0 or \ self.max_width % 2 != 0 else False @@ -419,4 +490,6 @@ class Map(object): ## Final Comments -The Dynamic map could be expanded with further capabilities. For example, it could mark exits or allow NE, SE etc directions as well. It could have colors for different terrain types. One could also look into up/down directions and figure out how to display that in a good way. +The Dynamic map could be expanded with further capabilities. For example, it could mark exits or +allow NE, SE etc directions as well. It could have colors for different terrain types. One could +also look into up/down directions and figure out how to display that in a good way. diff --git a/docs/source/EvEditor.md b/docs/source/EvEditor.md index 670f1390f8..4b9dde97d7 100644 --- a/docs/source/EvEditor.md +++ b/docs/source/EvEditor.md @@ -1,25 +1,32 @@ # EvEditor -Evennia offers a powerful in-game line editor in `evennia.utils.eveditor.EvEditor`. This editor, mimicking the well-known VI line editor. It offers line-by-line editing, undo/redo, line deletes, search/replace, fill, dedent and more. +Evennia offers a powerful in-game line editor in `evennia.utils.eveditor.EvEditor`. This editor, +mimicking the well-known VI line editor. It offers line-by-line editing, undo/redo, line deletes, +search/replace, fill, dedent and more. ### Launching the editor -The editor is created as follows: +The editor is created as follows: ```python from evennia.utils.eveditor import EvEditor -EvEditor(caller, - loadfunc=None, savefunc=None, quitfunc=None, +EvEditor(caller, + loadfunc=None, savefunc=None, quitfunc=None, key="") ``` - `caller` (Object or Account): The user of the editor. - - `loadfunc` (callable, optional): This is a function called when the editor is first started. It is called with `caller` as its only argument. The return value from this function is used as the starting text in the editor buffer. - - `savefunc` (callable, optional): This is called when the user saves their buffer in the editor is called with two arguments, `caller` and `buffer`, where `buffer` is the current buffer. - - `quitfunc` (callable, optional): This is called when the user quits the editor. If given, all cleanup and exit messages to the user must be handled by this function. - - `key` (str, optional): This text will be displayed as an identifier and reminder while editing. It has no other mechanical function. + - `loadfunc` (callable, optional): This is a function called when the editor is first started. It +is called with `caller` as its only argument. The return value from this function is used as the +starting text in the editor buffer. + - `savefunc` (callable, optional): This is called when the user saves their buffer in the editor is +called with two arguments, `caller` and `buffer`, where `buffer` is the current buffer. + - `quitfunc` (callable, optional): This is called when the user quits the editor. If given, all +cleanup and exit messages to the user must be handled by this function. + - `key` (str, optional): This text will be displayed as an identifier and reminder while editing. +It has no other mechanical function. - `persistent` (default `False`): if set to `True`, the editor will survive a reboot. ### Example of usage @@ -32,7 +39,7 @@ from evennia.utils import eveditor class CmdSetTestAttr(Command): """ - Set the "test" Attribute using + Set the "test" Attribute using the line editor. Usage: @@ -53,14 +60,17 @@ class CmdSetTestAttr(Command): caller.msg("Editor exited") key = "%s/test" % self.caller # launch the editor - eveditor.EvEditor(self.caller, - loadfunc=load, savefunc=save, quitfunc=quit, - key=key) + eveditor.EvEditor(self.caller, + loadfunc=load, savefunc=save, quitfunc=quit, + key=key) ``` ### Persistent editor -If you set the `persistent` keyword to `True` when creating the editor, it will remain open even when reloading the game. In order to be persistent, an editor needs to have its callback functions (`loadfunc`, `savefunc` and `quitfunc`) as top-level functions defined in the module. Since these functions will be stored, Python will need to find them. +If you set the `persistent` keyword to `True` when creating the editor, it will remain open even +when reloading the game. In order to be persistent, an editor needs to have its callback functions +(`loadfunc`, `savefunc` and `quitfunc`) as top-level functions defined in the module. Since these +functions will be stored, Python will need to find them. ```python from evennia import Command @@ -80,7 +90,7 @@ def quit(caller): class CmdSetTestAttr(Command): """ - Set the "test" Attribute using + Set the "test" Attribute using the line editor. Usage: @@ -92,14 +102,15 @@ class CmdSetTestAttr(Command): "Set up the callbacks and launch the editor" key = "%s/test" % self.caller # launch the editor - eveditor.EvEditor(self.caller, - loadfunc=load, savefunc=save, quitfunc=quit, - key=key, persistent=True) + eveditor.EvEditor(self.caller, + loadfunc=load, savefunc=save, quitfunc=quit, + key=key, persistent=True) ``` ### Line editor usage -The editor mimics the `VIM` editor as best as possible. The below is an excerpt of the return from the in-editor help command (`:h`). +The editor mimics the `VIM` editor as best as possible. The below is an excerpt of the return from +the in-editor help command (`:h`). ``` - any non-command is appended to the end of the buffer. @@ -145,14 +156,26 @@ The editor mimics the `VIM` editor as best as possible. The below is an excerpt ### The EvEditor to edit code -The `EvEditor` is also used to edit some Python code in Evennia. The `@py` command supports an `/edit` switch that will open the EvEditor in code mode. This mode isn't significantly different from the standard one, except it handles automatic indentation of blocks and a few options to control this behavior. +The `EvEditor` is also used to edit some Python code in Evennia. The `@py` command supports an +`/edit` switch that will open the EvEditor in code mode. This mode isn't significantly different +from the standard one, except it handles automatic indentation of blocks and a few options to +control this behavior. - `:<` to remove a level of indentation for the future lines. - `:+` to add a level of indentation for the future lines. - `:=` to disable automatic indentation altogether. -Automatic indentation is there to make code editing more simple. Python needs correct indentation, not as an aesthetic addition, but as a requirement to determine beginning and ending of blocks. The EvEditor will try to guess the next level of indentation. If you type a block "if", for instance, the EvEditor will propose you an additional level of indentation at the next line. This feature cannot be perfect, however, and sometimes, you will have to use the above options to handle indentation. +Automatic indentation is there to make code editing more simple. Python needs correct indentation, +not as an aesthetic addition, but as a requirement to determine beginning and ending of blocks. The +EvEditor will try to guess the next level of indentation. If you type a block "if", for instance, +the EvEditor will propose you an additional level of indentation at the next line. This feature +cannot be perfect, however, and sometimes, you will have to use the above options to handle +indentation. -`:=` can be used to turn automatic indentation off completely. This can be very useful when trying to paste several lines of code that are already correctly indented, for instance. +`:=` can be used to turn automatic indentation off completely. This can be very useful when trying +to paste several lines of code that are already correctly indented, for instance. -To see the EvEditor in code mode, you can use the `@py/edit` command. Type in your code (on one or several lines). You can then use the `:w` option (save without quitting) and the code you have typed will be executed. The `:!` will do the same thing. Executing code while not closing the editor can be useful if you want to test the code you have typed but add new lines after your test. \ No newline at end of file +To see the EvEditor in code mode, you can use the `@py/edit` command. Type in your code (on one or +several lines). You can then use the `:w` option (save without quitting) and the code you have +typed will be executed. The `:!` will do the same thing. Executing code while not closing the +editor can be useful if you want to test the code you have typed but add new lines after your test. \ No newline at end of file diff --git a/docs/source/EvMenu.md b/docs/source/EvMenu.md index 3a33b489a3..58a7020525 100644 --- a/docs/source/EvMenu.md +++ b/docs/source/EvMenu.md @@ -25,9 +25,26 @@ This is an example of a menu *node*. Think of a node as a point where the menu s and waits for user to give some input. By jumping to different nodes depending on the input, a menu is constructed. -To create the menu, EvMenu uses normal Python functions, one per node. It will load all those +## Ways to create the menu + +### node functions + +The native way to define an EvMenu is to define Python functions, one per node. It will load all +those functions/nodes either from a module or by being passed a dictionary mapping the node's names to -said functions, like `{"nodename": , ...}` +said functions, like `{"nodename": , ...}`. Since you are dealing with raw code, this is +by +far the most powerful way - for example you could have dynamic nodes that change content depending +on game context, time and what you picked before. + +### menu templating + +For a simpler menu you often don't need the full flexibility you get from defining each node as a +Python function. For that, there is the _EvMenu templating_ language. This allows you to define the +menu +in a more human-readable string with a simple format. This is then parsed to produce the +`{"nodename": , ...}` mapping for you, for the EvMenu to use normally. The templating +language is described in the [Menu templating section](./EvMenu#Evmenu-templating-language). ## Launching the menu @@ -46,12 +63,38 @@ class CmdTestMenu(Command): def func(self): - EvMenu(caller, "world.mymenu") + EvMenu(caller, "world.mymenu") ``` When running this command, the menu will start using the menu nodes loaded from -`mygame/world/mymenu.py`. See next section on how to define menu nodes. +`mygame/world/mymenu.py` and use this to build the menu-tree - each function name becomes +the name of a node in the tree. See next section on how to define menu nodes. + +Alternatively, you could pass the menu-tree to EvMenu directly: + +```python + + menutree = {"start": nodestartfunc, + "node1": nodefunc1, + "node2": nodefunc2,, ...} + EvMenu(caller, menutree) + +``` +This menutree can also be generated from an *EvMenu template* + +```python + from evennia.utils.evmenu import parse_menu_template + + menutree = parse_menu_template(caller, template_string, goto_callables) + EvMenu(caller, menutree) +``` + +The `template_string` and `goto_callables` are described in [Template language +section](EvMenu#Evmenu-templating-language). + + +## The EvMenu class The `EvMenu` has the following optional callsign: @@ -73,26 +116,34 @@ EvMenu(caller, menu_data, new [CmdSet](./Command-Sets) assigned to it, for handling the menu. - `menu_data` (str, module or dict): is a module or python path to a module where the global-level functions will each be considered to be a menu node. Their names in the module will be the names - by which they are referred to in the module. Importantly, function names starting with an underscore - `_` will be ignored by the loader. Alternatively, this can be a direct mapping `{"nodename":function, ...}`. + by which they are referred to in the module. Importantly, function names starting with an +underscore + `_` will be ignored by the loader. Alternatively, this can be a direct mapping +`{"nodename":function, ...}`. - `startnode` (str): is the name of the menu-node to start the menu at. Changing this means that you can jump into a menu tree at different positions depending on circumstance and thus possibly re-use menu entries. - - `cmdset_mergetype` (str): This is usually one of "Replace" or "Union" (see [CmdSets](./Command-Sets). + - `cmdset_mergetype` (str): This is usually one of "Replace" or "Union" (see [CmdSets](Command- +Sets). The first means that the menu is exclusive - the user has no access to any other commands while - in the menu. The Union mergetype means the menu co-exists with previous commands (and may overload + in the menu. The Union mergetype means the menu co-exists with previous commands (and may +overload them, so be careful as to what to name your menu entries in this case). - `cmdset_priority` (int): The priority with which to merge in the menu cmdset. This allows for advanced usage. - `auto_quit`, `auto_look`, `auto_help` (bool): If either of these are `True`, the menu automatically makes a `quit`, `look` or `help` command available to the user. The main reason why - you'd want to turn this off is if you want to use the aliases "q", "l" or "h" for something in your - menu. Nevertheless, at least `quit` is highly recommend - if `False`, the menu *must* itself supply - an "exit node" (a node without any options), or the user will be stuck in the menu until the server + you'd want to turn this off is if you want to use the aliases "q", "l" or "h" for something in +your + menu. Nevertheless, at least `quit` is highly recommend - if `False`, the menu *must* itself +supply + an "exit node" (a node without any options), or the user will be stuck in the menu until the +server reloads (or eternally if the menu is `persistent`)! - `cmd_on_exit` (str): This command string will be executed right *after* the menu has closed down. From experience, it's useful to trigger a "look" command to make sure the user is aware of the - change of state; but any command can be used. If set to `None`, no command will be triggered after + change of state; but any command can be used. If set to `None`, no command will be triggered +after exiting the menu. - `persistent` (bool) - if `True`, the menu will survive a reload (so the user will not be kicked out by the reload - make sure they can exit on their own!) @@ -134,7 +185,8 @@ def menunodename3(caller, raw_string, **kwargs): ``` -> While all of the above forms are okay, it's recommended to stick to the third and last form since it +> While all of the above forms are okay, it's recommended to stick to the third and last form since +it > gives the most flexibility. The previous forms are mainly there for backwards compatibility with > existing menus from a time when EvMenu was less able. @@ -173,11 +225,13 @@ help text is not given, the menu will give a generic error message when using `h #### options -The `options` list describe all the choices available to the user when viewing this node. If `options` is +The `options` list describe all the choices available to the user when viewing this node. If +`options` is returned as `None`, it means that this node is an *Exit node* - any text is displayed and then the menu immediately exits, running the `exit_cmd` if given. -Otherwise, `options` should be a list (or tuple) of dictionaries, one for each option. If only one option is +Otherwise, `options` should be a list (or tuple) of dictionaries, one for each option. If only one +option is available, a single dictionary can also be returned. This is how it could look: @@ -187,10 +241,10 @@ def node_test(caller, raw_string, **kwargs): text = "A goblin attacks you!" options = ( - {"key": ("Attack", "a", "att"), + {"key": ("Attack", "a", "att"), "desc": "Strike the enemy with all your might", "goto": "node_attack"}, - {"key": ("Defend", "d", "def"), + {"key": ("Defend", "d", "def"), "desc": "Hold back and defend yourself", "goto": (_defend, {"str": 10, "enemyname": "Goblin"})}) @@ -212,7 +266,8 @@ Defend: Hold back and defend yourself ##### option-key 'key' -The option's `key` is what the user should enter in order to choose that option. If given as a tuple, the +The option's `key` is what the user should enter in order to choose that option. If given as a +tuple, the first string of that tuple will be what is shown on-screen while the rest are aliases for picking that option. In the above example, the user could enter "Attack" (or "attack", it's not case-sensitive), "a" or "att" in order to attack the goblin. Aliasing is useful for adding custom @@ -284,11 +339,11 @@ def node_select(caller, raw_string, **kwargs): "help - they all do different things ...") options = ({"desc": "Option one", - "goto": "node_one"}, - {"desc": "Option two", - "goto": _action_two}, - {"desc": "Option three", - "goto": (_action_three, {"key": 1, "key2": 2})} + "goto": "node_one"}, + {"desc": "Option two", + "goto": _action_two}, + {"desc": "Option three", + "goto": (_action_three, {"key": 1, "key2": 2})} ) return text, options @@ -306,7 +361,8 @@ function as Here, `raw_string` is always the input the user entered to make that choice and `kwargs` are the same as those `kwargs` that already entered the *current* node (they are passed on). -Alternatively the `goto` could point to a "goto-callable". Such callables are usually defined in the same +Alternatively the `goto` could point to a "goto-callable". Such callables are usually defined in the +same module as the menu nodes and given names starting with `_` (to avoid being parsed as nodes themselves). These callables will be called the same as a node function - `callable(caller, raw_string, **kwargs)`, where `raw_string` is what the user entered on this node and `**kwargs` is @@ -318,7 +374,8 @@ kwargs passed into it depending on which option was actually chosen. The "goto callable" must either return a string `"nodename"` or a tuple `("nodename", mykwargs)`. This will lead to the next node being called as either `nodename(caller, raw_string, **kwargs)` or -`nodename(caller, raw_string, **mykwargs)` - so this allows changing (or replacing) the options going +`nodename(caller, raw_string, **mykwargs)` - so this allows changing (or replacing) the options +going into the next node depending on what option was chosen. There is one important case - if the goto-callable returns `None` for a `nodename`, *the current @@ -412,21 +469,293 @@ class MyEvMenu(EvMenu): See `evennia/utils/evmenu.py` for the details of their default implementations. + +## Evmenu templating language + +The EvMenu is very powerful and flexible. But often your menu is simple enough to +not require the full power of EvMenu. For this you can use the Evmenu templating language. + +This is how the templating is used: + +```python +from evennia.utils.evmenu import parse_menu_template, EvMenu + +template_string = "(will be described below)" +# this could be empty if you don't need to access any callables +# in your template +goto_callables = {"mycallable1": function, ...} + +# generate the menutree +menutree = parse_menu_template(caller, template_string, goto_callables) +# a normal EvMenu call +EvMenu(caller, menutree, ...) + +``` + +... So the `parse_menu_template` is just another way to generate the `menutree` dict needed by +EvMenu - after this EvMenu works normally. + +The good thing with this two-step procedude is that you can mix- and match - if you wanted +you could insert a normal, fully flexible function-based node-function in the `menutree` before +passing +the whole thing into `EvMenu` and get the best of both worlds. It also makes it +easy to substitute base EvMenu with a child class that changes the menu display. + +... But if you really don't need any such customization, you can also apply the template in one step +using +the `template2menu` helper: + + +```python +from evennia.utils.evmenu import template2menu + +template_string = "(will be described below)" +goto_callables = {"mycallable1": function, ...} + +template2menu(caller, template_string, goto_callables, startnode="start", ...) + +``` +In addition to the template-related arguments, `template2menu` takes all the same `**kwargs` +as `EvMenu` and will parse the template and start the menu for you in one go. + +### The templating string + +The template is a normal string with a very simple format. Each node begins +with a marker `## Node `, follwowed by a `## Options` separator (the `Node` and +`Options` are +case-insensitive). + +```python +template_string = """ + +## NODE start + + + +## OPTIONS + +# this is a comment. Only line-comments are allowed. + +key;alias;alias: description -> goto_str_or_callable +key;alias;alias: goto_str_or_callable +>pattern: goto_str_or_callable + +""" +``` + +- The text after `## NODE` defines the name of the node. This must be unique within the + menu because this is what you use for `goto` statements. The name could have spaces. +- The area between `## NODE` and `## OPTIONS` contains the text of the node. It can have + normal formatting and will retain intentation. +- The `## OPTIONS` section, until the next `## NODE` or the end of the string, + holds the options, one per line. +- Option-indenting is ignored but can be useful for readability. +- The options-section can also have line-comments, marked by starting the line with `#`. +- A node without a following `## OPTIONS` section indicates an end node, and reaching + it will print the text and immediately exit the menu (same as for regular EvMenu). + +### Templating options format + +The normal, full syntax is: + + key;alias;alias: description -> goto_str_or_callable + +An example would be + + next;n: Go to node Two -> node2 + +In the menu, this will become an option + + next: Go to node Two + +where you can enter `next` or `n` to go to the menu node named `node2`. + +To skip the description, just add the goto without the `->`: + + next;n: node2 + +This will create a menu option without any description: + + next + +A special key is `>`. This acts as a _pattern matcher_. Between `>` and the `:` one +can fit an optional _pattern_. This +pattern will first be parsed with [glob-style +parsing](https://docs.python.org/2/library/fnmatch.html) and then +with [regex](https://docs.python.org/3/library/re.html#module-re), and only if +the player's input matches either will the option be chosen. An input-matching +option cannot have a description. + +``` + # this matches the empty string (just pressing return) + >: node2 + + # this matches input starting with 'test' (regex match) + > ^test.+?: testnode + + # this matches any number input (regex match) + > [0-9]+?: countnode + + # this matches everything not covered by previous options + # (glob-matching, space is stripped without quotes) + > *: node3 +``` + +You can have multiple pattern-matchers for a node but remember that options are +checked in the order they are listed. So make sure to put your pattern-matchers +in decending order of generality; if you have a 'catch-all' pattern, +it should be put last or those behind it will never be tried. + +``` + next;n: node2 + back;b: node1 + >: node2 +``` + +The above would give you the option to write next/back but you can also just press return to move on +to the next node. + +### Templating goto-callables + +Instead of giving the name of a node to go to, you can also give the name +of a _goto_callable_, which in turn returns the name of the node to go to. You +tell the template it's a callable by simply adding `()` at the end. + + next: Go to node 2 -> goto_node2() + +You can also add keyword arguments: + + back: myfunction(from=foo) + +> Note: ONLY keyword-arguments are supported! Trying to pass a positional +> argument will lead to an error. + +The contents of the kwargs-values will be evaluated by `literal_eval` so +you don't need to add quotes to strings _unless they have spaces in them_. Numbers +will be converted correctly, but more complex input structures (like lists or dicts) will +_not_ - if you want more complex input you should use a full function-based EvMenu +node instead. + +The goto-callable is defined just like any Evmenu goto-func. You must always +use the full form (including `**kwargs`): + +```python +def mygotocallable(caller, raw_string, **kwargs): + # ... + return "nodename_to_goto" + +``` + +Return `None` to re-run the current node. Any keyword arguments you specify in +your template will be passed to your goto-callable in `**kwargs`. Unlike in +regular EvMenu nodes you _can't_ return kwargs to pass it between nodes and other dynamic +tricks. + +All goto-callables you use in your menu-template must be added to the +`goto_callable` mapping that you pass to `parse_menu_template` or +`template2menu`. + +### Templating example to show all possible options: + + +```python + +template_string = """ + +## NODE start + +This is the text of the start node. +Both ## NODE, ## node or ## Node works. The node-name can have +spaces. + +The text area can have multiple lines, line breaks etc. + +## OPTIONS + + # here starts the option-defition + # comments are only allowed from beginning of line. + # Indenting is not necessary, but good for readability + + 1: Option number 1 -> node1 + 2: Option number 2 -> node2 + next: This steps next -> go_back() + # the -> can be ignored if there is no desc + back: go_back(from_node=start) + abort: abort + +# ----------------------------------- this is ignored + +## NODE node1 + +Text for Node1. Enter a message! + to go back. + +## options + + # Starting the option-line with > + # allows to perform different actions depending on + # what is inserted. + + # this catches everything starting with foo + > foo*: handle_foo_message() + + # regex are also allowed (this catches number inputs) + > [0-9]+?: handle_numbers() + + # this catches the empty return + >: start + + # this catches everything else + > *: handle_message(from_node=node1) + +# ----------------------------------------- + +## NODE node2 + +Text for Node2. Just go back. + +## options + + >: start + +# node abort + +This exits the menu since there is no `## options` section. + + +""" + +# we assume the callables are defined earlier +goto_callables = {"go_back": go_back_func, + "handle_foo_message": handle_message, + "handle_numbers": my_number_handler, + "handle_message": handle_message2} + +# boom - a menu +template2menu(caller, template_string, goto_callables) + +``` + + ## Examples: - **[Simple branching menu](./EvMenu#example-simple-branching-menu)** - choose from options - **[Dynamic goto](./EvMenu#example-dynamic-goto)** - jumping to different nodes based on response - **[Set caller properties](./EvMenu#example-set-caller-properties)** - a menu that changes things - **[Getting arbitrary input](./EvMenu#example-get-arbitrary-input)** - entering text -- **[Storing data between nodes](./EvMenu#example-storing-data-between-nodes)** - keeping states and information while in the menu -- **[Repeating the same node](./EvMenu#example-repeating-the-same-node)** - validating within the node before moving to the next -- **[Full Menu](./EvMenu#example-full-menu):** a complete example -- **[Yes/No prompt](./EvMenu#example-yesno-prompt)** - entering text with limited possible responses (this is *not* using EvMenu but the conceptually similar yet technically unrelated `get_input` helper function accessed as `evennia.utils.evmenu.get_input`). +- **[Storing data between nodes](./EvMenu#example-storing-data-between-nodes)** - keeping states and +information while in the menu +- **[Repeating the same node](./EvMenu#example-repeating-the-same-node)** - validating within the node +before moving to the next +- **[Yes/No prompt](./EvMenu#example-yesno-prompt)** - entering text with limited possible responses +(this is *not* using EvMenu but the conceptually similar yet technically unrelated `get_input` +helper function accessed as `evennia.utils.evmenu.get_input`). ### Example: Simple branching menu -Below is an example of a simple branching menu node leading to different other nodes depending on choice: +Below is an example of a simple branching menu node leading to different other nodes depending on +choice: ```python # in mygame/world/mychargen.py @@ -520,11 +849,11 @@ def node_background(caller): options = ({"key": "death", "desc": "A violent death in the family", "goto": (_set_attribute, {"attr": ("experienced_violence", True), - "next_node": "node_violent_background"})}, + "next_node": "node_violent_background"})}, {"key": "betrayal", "desc": "The betrayal of a trusted grown-up", "goto": (_set_attribute, {"attr": ("experienced_betrayal", True), - "next_node": "node_betrayal_background"})}) + "next_node": "node_betrayal_background"})}) return text, options ``` @@ -564,8 +893,8 @@ def _set_name(caller, raw_string, **kwargs): caller.msg("Set name to {}.".format(prev_entry)) return "node_background" else: - caller.msg("Aborted.") - return "node_exit" + caller.msg("Aborted.") + return "node_exit" else: # re-run old node, but pass in the name given return None, {"prev_entry": inp} @@ -577,9 +906,9 @@ def enter_name(caller, raw_string, **kwargs): prev_entry = kwargs.get("prev_entry") if prev_entry: - text = "Current name: {}.\nEnter another name or to accept." + text = "Current name: {}.\nEnter another name or to accept." else: - text = "Enter your character's name or to abort." + text = "Enter your character's name or to abort." options = {"key": "_default", "goto": (_set_name, {"prev_entry": prev_entry})} @@ -643,7 +972,7 @@ def node_view_sheet(caller): options = ({"key": "Accept", "goto": "finish_chargen"}, - {"key": "Decline", + {"key": "Decline", "goto": "start_over"}) return text, options @@ -656,7 +985,8 @@ all nodes. At the end we look at it and, if we accept the character the menu wil result to permanent storage and exit. > One point to remember though is that storage on `caller.ndb._menutree` is not persistent across -> `@reloads`. If you are using a persistent menu (using `EvMenu(..., persistent=True)` you should use +> `@reloads`. If you are using a persistent menu (using `EvMenu(..., persistent=True)` you should +use > `caller.db` to store in-menu data like this as well. You must then yourself make sure to clean it > when the user exits the menu. @@ -673,12 +1003,12 @@ node is ok. A common example is a login menu: def _check_username(caller, raw_string, **kwargs): # we assume lookup_username() exists if not lookup_username(raw_string): - # re-run current node by returning `None` - caller.msg("|rUsername not found. Try again.") - return None + # re-run current node by returning `None` + caller.msg("|rUsername not found. Try again.") + return None else: - # username ok - continue to next node - return "node_password" + # username ok - continue to next node + return "node_password" def node_username(caller): @@ -692,19 +1022,19 @@ def _check_password(caller, raw_string, **kwargs): nattempts = kwargs.get("nattempts", 0) if nattempts > 3: - caller.msg("Too many failed attempts. Logging out") - return "node_abort" + caller.msg("Too many failed attempts. Logging out") + return "node_abort" elif not validate_password(raw_string): caller.msg("Password error. Try again.") - return None, {"nattempts", nattempts + 1} + return None, {"nattempts", nattempts + 1} else: - # password accepted - return "node_login" + # password accepted + return "node_login" def node_password(caller, raw_string, **kwargs): text = "Enter your password." options = {"key": "_default", - "goto": _check_password} + "goto": _check_password} return text, options ``` @@ -885,7 +1215,7 @@ Normally, the `get_input` function quits after any input, but as seen in the exa return True from the callback to repeat the prompt until you pass whatever check you want. > Note: You *cannot* link consecutive questions by putting a new `get_input` call inside the -> callback If you want that you should use an EvMenu instead (see the [Repeating the same +> callback. If you want that you should use an EvMenu instead (see the [Repeating the same > node](EvMenu#example-repeating-the-same-node) example above). Otherwise you can either peek at the > implementation of `get_input` and implement your own mechanism (it's just using cmdset nesting) or > you can look at [this extension suggested on the mailing @@ -947,14 +1277,15 @@ _options(caller): _select(caller, menuchoice, available_choices): # analyze choice - return "next_node" + return node_matching_the_choice -@list_node(options, select=_select, pagesize=10) +@list_node(_options, select=_select, pagesize=10) def node_mylist(caller, raw_string, **kwargs): ... - return text, options - + # the decorator auto-creates the options; any options + # returned here would be appended to the auto-options + return node_text, {} ``` The `options` argument to `list_node` is either a list, a generator or a callable returning a list diff --git a/docs/source/Evennia-API.md b/docs/source/Evennia-API.md index 0bd56ac26a..ec0d4e2d7e 100644 --- a/docs/source/Evennia-API.md +++ b/docs/source/Evennia-API.md @@ -1,11 +1,18 @@ # Evennia API -Evennia makes much of its programming tools available directly from the top-level `evennia` package. This is often referred to as Evennia's "flat" [Application Programming Interface](https://en.wikipedia.org/wiki/Application_programming_interface) (API). The flat API tries to collect and bring the most commonly used resources to the front in a way where everything is available at a glance (in a flat display), making it a good place to start to learn Evennia. +Evennia makes much of its programming tools available directly from the top-level `evennia` package. +This is often referred to as Evennia's "flat" [Application Programming +Interface](https://en.wikipedia.org/wiki/Application_programming_interface) (API). The flat API +tries to collect and bring the most commonly used resources to the front in a way where everything +is available at a glance (in a flat display), making it a good place to start to learn Evennia. -> Evennia's flat (and full) API can be perused through the auto-generated [API Library refence](github:evennia). +> Evennia's flat (and full) API can be perused through the auto-generated [API Library +refence](github:evennia). -A good, interactive way to explore the flat API is to use [IPython](http://ipython.org/), a more flexible version of the default Python shell. Inside your virtual environment you can install IPython simply by +A good, interactive way to explore the flat API is to use [IPython](http://ipython.org/), a more +flexible version of the default Python shell. Inside your virtual environment you can install +IPython simply by pip install ipython @@ -26,16 +33,22 @@ Followed by evennia. -That is, write `evennia.` and press the TAB key. What pops up is the contents of the `evennia` top-level package - in other words [the "flat" API](github:evennia#the-flat-api). +That is, write `evennia.` and press the TAB key. What pops up is the contents of the `evennia` top- +level package - in other words [the "flat" API](github:evennia#the-flat-api). evennia.DefaultObject? -Starting to write the name of an API entity and pressing `` will auto-complete the name. Adding a question mark (`?`) to its name will show you its documentation. Append `??` to get the actual source code. This way you can quickly explore Evennia and see what is available. +Starting to write the name of an API entity and pressing `` will auto-complete the name. Adding +a question mark (`?`) to its name will show you its documentation. Append `??` to get the actual +source code. This way you can quickly explore Evennia and see what is available. ## To remember when importing from `evennia` -Properties on the root of the `evennia` package are *not* modules in their own right. They are just shortcut properties stored in the `evennia/__init__.py` module. That means that you cannot use dot-notation to `import` nested module-names over `evennia`. The rule of thumb is that you cannot use `import` for more than one level down. Hence you can do +Properties on the root of the `evennia` package are *not* modules in their own right. They are just +shortcut properties stored in the `evennia/__init__.py` module. That means that you cannot use dot- +notation to `import` nested module-names over `evennia`. The rule of thumb is that you cannot use +`import` for more than one level down. Hence you can do ```python import evennia @@ -55,4 +68,10 @@ but you *cannot* import two levels down from evennia.default_cmds import CmdLook # error! ``` -This will give you an `ImportError` telling you that the module `default_cmds` cannot be found - this is becasue `default_cmds` is just a *variable* stored in `evennia.__init__.py`; this cannot be imported from. If you really want full control over which level of package you import you can always bypass the root package and import directly from from the real location. For example `evennia.DefaultObject` is a shortcut to `evennia.objects.objects.DefaultObject`. Using this full path will have the import mechanism work normally. See `evennia/__init__.py` to see where the package imports from. +This will give you an `ImportError` telling you that the module `default_cmds` cannot be found - +this is becasue `default_cmds` is just a *variable* stored in `evennia.__init__.py`; this cannot be +imported from. If you really want full control over which level of package you import you can always +bypass the root package and import directly from from the real location. For example +`evennia.DefaultObject` is a shortcut to `evennia.objects.objects.DefaultObject`. Using this full +path will have the import mechanism work normally. See `evennia/__init__.py` to see where the +package imports from. diff --git a/docs/source/Evennia-Game-Index.md b/docs/source/Evennia-Game-Index.md index a1d0440220..9f47bbc322 100644 --- a/docs/source/Evennia-Game-Index.md +++ b/docs/source/Evennia-Game-Index.md @@ -5,16 +5,16 @@ The [Evennia game index](http://games.evennia.com) is a list of games built or being built with Evennia. Anyone is allowed to add their game to the index - also if you have just started development and don't yet accept external players. It's a chance for us to know you are out there and for you to make us -intrigued about or excited for your upcoming game! +intrigued about or excited for your upcoming game! All we ask is that you check so your game-name does not collide with one -already in the list - be nice! +already in the list - be nice! ## Connect with the wizard From your game dir, run - evennia connections + evennia connections This will start the Evennia _Connection wizard_. From the menu, select to add your game to the Evennia Game Index. Follow the prompts and don't forget to @@ -27,27 +27,29 @@ mind. > want, but remember that if you run the wizard again, your changes may get > over-written. -## Manual Settings +## Manual Settings -If you don't want to use the wizard (maybe because you already have the client installed from an earlier version), you can also configure your index entry in your settings file (`mygame/server/conf/settings.py`). Add the following: +If you don't want to use the wizard (maybe because you already have the client installed from an +earlier version), you can also configure your index entry in your settings file +(`mygame/server/conf/settings.py`). Add the following: ```python -GAME_INDEX_ENABLED = True +GAME_INDEX_ENABLED = True GAME_INDEX_LISTING = { - # required + # required 'game_status': 'pre-alpha', # pre-alpha, alpha, beta, launched 'listing_contact': "dummy@dummy.com", # not publicly shown. - 'short_description': 'Short blurb', + 'short_description': 'Short blurb', - # optional + # optional 'long_description': "Longer description that can use Markdown like *bold*, _italic_" "and [linkname](http://link.com). Use \n for line breaks." - 'telnet_hostname': 'dummy.com', - 'telnet_port': '1234', - 'web_client_url': 'dummy.com/webclient', - 'game_website': 'dummy.com', + 'telnet_hostname': 'dummy.com', + 'telnet_port': '1234', + 'web_client_url': 'dummy.com/webclient', + 'game_website': 'dummy.com', # 'game_name': 'MyGame', # set only if different than settings.SERVERNAME } ``` @@ -57,8 +59,8 @@ required. The `listing_contact` is not publicly visible and is only meant as a last resort if we need to get in touch with you over any listing issue/bug (so far this has never happened). -If `game_name` is not set, the `settings.SERVERNAME` will be used. Use empty strings -(`''`) for optional fields you don't want to specify at this time. +If `game_name` is not set, the `settings.SERVERNAME` will be used. Use empty strings +(`''`) for optional fields you don't want to specify at this time. ## Non-public games diff --git a/docs/source/Evennia-Introduction.md b/docs/source/Evennia-Introduction.md index be60a6dc2e..4e5c5d122a 100644 --- a/docs/source/Evennia-Introduction.md +++ b/docs/source/Evennia-Introduction.md @@ -1,35 +1,75 @@ # Evennia Introduction -> *A MUD (originally Multi-User Dungeon, with later variants Multi-User Dimension and Multi-User Domain) is a multiplayer real-time virtual world described primarily in text. MUDs combine elements of role-playing games, hack and slash, player versus player, interactive fiction and online chat. Players can read or view descriptions of rooms, objects, other players, non-player characters, and actions performed in the virtual world. Players typically interact with each other and the world by typing commands that resemble a natural language.* - [Wikipedia](http://en.wikipedia.org/wiki/MUD) +> *A MUD (originally Multi-User Dungeon, with later variants Multi-User Dimension and Multi-User +Domain) is a multiplayer real-time virtual world described primarily in text. MUDs combine elements +of role-playing games, hack and slash, player versus player, interactive fiction and online chat. +Players can read or view descriptions of rooms, objects, other players, non-player characters, and +actions performed in the virtual world. Players typically interact with each other and the world by +typing commands that resemble a natural language.* - [Wikipedia](http://en.wikipedia.org/wiki/MUD) -If you are reading this, it's quite likely you are dreaming of creating and running a text-based massively-multiplayer game ([MUD/MUX/MUSH](http://tinyurl.com/c5sc4bm) etc) of your very own. You might just be starting to think about it, or you might have lugged around that *perfect* game in your mind for years ... you know *just* how good it would be, if you could only make it come to reality. We know how you feel. That is, after all, why Evennia came to be. +If you are reading this, it's quite likely you are dreaming of creating and running a text-based +massively-multiplayer game ([MUD/MUX/MUSH](http://tinyurl.com/c5sc4bm) etc) of your very own. You +might just be starting to think about it, or you might have lugged around that *perfect* game in +your mind for years ... you know *just* how good it would be, if you could only make it come to +reality. We know how you feel. That is, after all, why Evennia came to be. -Evennia is in principle a MUD-building system: a bare-bones Python codebase and server intended to be highly extendable for any style of game. "Bare-bones" in this context means that we try to impose as few game-specific things on you as possible. So whereas we for convenience offer basic building blocks like objects, characters, rooms, default commands for building and administration etc, we don't prescribe any combat rules, mob AI, races, skills, character classes or other things that will be different from game to game anyway. It is possible that we will offer some such systems as contributions in the future, but these will in that case all be optional. +Evennia is in principle a MUD-building system: a bare-bones Python codebase and server intended to +be highly extendable for any style of game. "Bare-bones" in this context means that we try to impose +as few game-specific things on you as possible. So whereas we for convenience offer basic building +blocks like objects, characters, rooms, default commands for building and administration etc, we +don't prescribe any combat rules, mob AI, races, skills, character classes or other things that will +be different from game to game anyway. It is possible that we will offer some such systems as +contributions in the future, but these will in that case all be optional. -What we *do* however, is to provide a solid foundation for all the boring database, networking, and behind-the-scenes administration stuff that all online games need whether they like it or not. Evennia is *fully persistent*, that means things you drop on the ground somewhere will still be there a dozen server reboots later. Through Django we support a large variety of different database systems (a database is created for you automatically if you use the defaults). +What we *do* however, is to provide a solid foundation for all the boring database, networking, and +behind-the-scenes administration stuff that all online games need whether they like it or not. +Evennia is *fully persistent*, that means things you drop on the ground somewhere will still be +there a dozen server reboots later. Through Django we support a large variety of different database +systems (a database is created for you automatically if you use the defaults). -Using the full power of Python throughout the server offers some distinct advantages. All your coding, from object definitions and custom commands to AI scripts and economic systems is done in normal Python modules rather than some ad-hoc scripting language. The fact that you script the game in the same high-level language that you code it in allows for very powerful and custom game implementations indeed. +Using the full power of Python throughout the server offers some distinct advantages. All your +coding, from object definitions and custom commands to AI scripts and economic systems is done in +normal Python modules rather than some ad-hoc scripting language. The fact that you script the game +in the same high-level language that you code it in allows for very powerful and custom game +implementations indeed. -The server ships with a default set of player commands that are similar to the MUX command set. We *do not* aim specifically to be a MUX server, but we had to pick some default to go with (see [this](./Soft-Code) for more about our original motivations). It's easy to remove or add commands, or to have the command syntax mimic other systems, like Diku, LP, MOO and so on. Or why not create a new and better command system of your own design. +The server ships with a default set of player commands that are similar to the MUX command set. We +*do not* aim specifically to be a MUX server, but we had to pick some default to go with (see +[this](./Soft-Code) for more about our original motivations). It's easy to remove or add commands, or +to have the command syntax mimic other systems, like Diku, LP, MOO and so on. Or why not create a +new and better command system of your own design. ## Can I test it somewhere? -Evennia's demo server can be found at [demo.evennia.com](http://demo.evennia.com). If you prefer to connect to the demo via your own telnet client you can do so at `silvren.com`, port `4280`. Here is a [screenshot](./Screenshot). +Evennia's demo server can be found at [demo.evennia.com](http://demo.evennia.com). If you prefer to +connect to the demo via your own telnet client you can do so at `silvren.com`, port `4280`. Here is +a [screenshot](./Screenshot). -Once you installed Evennia yourself it comes with its own tutorial - this shows off some of the possibilities _and_ gives you a small single-player quest to play. The tutorial takes only one single in-game command to install as explained [here](./Tutorial-World-Introduction). +Once you installed Evennia yourself it comes with its own tutorial - this shows off some of the +possibilities _and_ gives you a small single-player quest to play. The tutorial takes only one +single in-game command to install as explained [here](./Tutorial-World-Introduction). ## Brief summary of features ### Technical -- Game development is done by the server importing your normal Python modules. Specific server features are implemented by overloading hooks that the engine calls appropriately. -- All game entities are simply Python classes that handle database negotiations behind the scenes without you needing to worry. -- Command sets are stored on individual objects (including characters) to offer unique functionality and object-specific commands. Sets can be updated and modified on the fly to expand/limit player input options during play. -- Scripts are used to offer asynchronous/timed execution abilities. Scripts can also be persistent. There are easy mechanisms to thread particularly long-running processes and built-in ways to start "tickers" for games that wants them. -- In-game communication channels are modular and can be modified to any functionality, including mailing systems and full logging of all messages. +- Game development is done by the server importing your normal Python modules. Specific server +features are implemented by overloading hooks that the engine calls appropriately. +- All game entities are simply Python classes that handle database negotiations behind the scenes +without you needing to worry. +- Command sets are stored on individual objects (including characters) to offer unique functionality +and object-specific commands. Sets can be updated and modified on the fly to expand/limit player +input options during play. +- Scripts are used to offer asynchronous/timed execution abilities. Scripts can also be persistent. +There are easy mechanisms to thread particularly long-running processes and built-in ways to start +"tickers" for games that wants them. +- In-game communication channels are modular and can be modified to any functionality, including +mailing systems and full logging of all messages. - Server can be fully rebooted/reloaded without users disconnecting. -- An Account can freely connect/disconnect from game-objects, offering an easy way to implement multi-character systems and puppeting. -- Each Account can optionally control multiple Characters/Objects at the same time using the same login information. +- An Account can freely connect/disconnect from game-objects, offering an easy way to implement +multi-character systems and puppeting. +- Each Account can optionally control multiple Characters/Objects at the same time using the same +login information. - Spawning of individual objects via a prototypes-like system. - Tagging can be used to implement zones and object groupings. - All source code is extensively documented. @@ -38,15 +78,21 @@ Once you installed Evennia yourself it comes with its own tutorial - this shows ### Default content - Basic classes for Objects, Characters, Rooms and Exits -- Basic login system, using the Account's login name as their in-game Character's name for simplicity +- Basic login system, using the Account's login name as their in-game Character's name for +simplicity - "MUX-like" command set with administration, building, puppeting, channels and social commands - In-game Tutorial -- Contributions folder with working, but optional, code such as alternative login, menus, character generation and more +- Contributions folder with working, but optional, code such as alternative login, menus, character +generation and more ### Standards/Protocols supported - TCP/websocket HTML5 browser web client, with ajax/comet fallback for older browsers -- Telnet and Telnet + SSL with mud-specific extensions ([MCCP](http://tintin.sourceforge.net/mccp/), [MSSP](http://tintin.sourceforge.net/mssp/), [TTYPE](http://tintin.sourceforge.net/mtts/), [MSDP](http://tintin.sourceforge.net/msdp/), [GMCP](https://www.ironrealms.com/rapture/manual/files/FeatGMCP-txt.html), [MXP](https://www.zuggsoft.com/zmud/mxp.htm) links) +- Telnet and Telnet + SSL with mud-specific extensions ([MCCP](http://tintin.sourceforge.net/mccp/), +[MSSP](http://tintin.sourceforge.net/mssp/), [TTYPE](http://tintin.sourceforge.net/mtts/), +[MSDP](http://tintin.sourceforge.net/msdp/), +[GMCP](https://www.ironrealms.com/rapture/manual/files/FeatGMCP-txt.html), +[MXP](https://www.zuggsoft.com/zmud/mxp.htm) links) - ANSI and xterm256 colours - SSH - HTTP - Website served by in-built webserver and connected to same database as game. @@ -58,37 +104,75 @@ For more extensive feature information, see the [Developer Central](./Developer- ## What you need to know to work with Evennia -Assuming you have Evennia working (see the [quick start instructions](./Getting-Started)) and have gotten as far as to start the server and connect to it with the client of your choice, here's what you need to know depending on your skills and needs. +Assuming you have Evennia working (see the [quick start instructions](./Getting-Started)) and have +gotten as far as to start the server and connect to it with the client of your choice, here's what +you need to know depending on your skills and needs. ### I don't know (or don't want to do) any programming - I just want to run a game! -Evennia comes with a default set of commands for the Python newbies and for those who need to get a game running *now*. Stock Evennia is enough for running a simple 'Talker'-type game - you can build and describe rooms and basic objects, have chat channels, do emotes and other things suitable for a social or free-form MU\*. Combat, mobs and other game elements are not included, so you'll have a very basic game indeed if you are not willing to do at least *some* coding. +Evennia comes with a default set of commands for the Python newbies and for those who need to get a +game running *now*. Stock Evennia is enough for running a simple 'Talker'-type game - you can build +and describe rooms and basic objects, have chat channels, do emotes and other things suitable for a +social or free-form MU\*. Combat, mobs and other game elements are not included, so you'll have a +very basic game indeed if you are not willing to do at least *some* coding. ### I know basic Python, or I am willing to learn -Evennia's source code is extensively documented and is [viewable online](https://github.com/evennia/evennia). We also have a comprehensive [online manual](https://github.com/evennia/evennia/wiki) with lots of examples. But while Python is considered a very easy programming language to get into, you do have a learning curve to climb if you are new to programming. You should probably sit down -with a Python beginner's [tutorial](http://docs.python.org/tutorial/) (there are plenty of them on the web if you look around) so you at least know what you are seeing. See also our [link page](./Links#wiki-litterature) for some reading suggestions. To efficiently code your dream game in Evennia you don't need to be a Python guru, but you do need to be able to read example code containing at least these basic Python features: +Evennia's source code is extensively documented and is [viewable online](https://github.com/evennia/evennia). +We also have a comprehensive [online manual](https://github.com/evennia/evennia/wiki) with lots of examples. +But while Python is +considered a very easy programming language to get into, you do have a learning curve to climb if +you are new to programming. You should probably sit down +with a Python beginner's [tutorial](http://docs.python.org/tutorial/) (there are plenty of them on +the web if you look around) so you at least know what you are seeing. See also our +[link page](./Links#wiki-litterature) for some reading suggestions. To efficiently code your dream game in +Evennia you don't need to be a Python guru, but you do need to be able to read example code +containing at least these basic Python features: - Importing and using python [modules](http://docs.python.org/3.7/tutorial/modules.html) -- Using [variables](http://www.tutorialspoint.com/python/python_variable_types.htm), [conditional statements](http://docs.python.org/tutorial/controlflow.html#if-statements), [loops](http://docs.python.org/tutorial/controlflow.html#for-statements) and [functions](http://docs.python.org/tutorial/controlflow.html#defining-functions) +- Using [variables](http://www.tutorialspoint.com/python/python_variable_types.htm), +[conditional statements](http://docs.python.org/tutorial/controlflow.html#if-statements), +[loops](http://docs.python.org/tutorial/controlflow.html#for-statements) and +[functions](http://docs.python.org/tutorial/controlflow.html#defining-functions) - Using [lists, dictionaries and list comprehensions](http://docs.python.org/tutorial/datastructures.html) - Doing [string handling and formatting](http://docs.python.org/tutorial/introduction.html#strings) -- Have a basic understanding of [object-oriented programming](http://www.tutorialspoint.com/python/python_classes_objects.htm), using [Classes](http://docs.python.org/tutorial/classes.html), their methods and properties +- Have a basic understanding of [object-oriented programming](http://www.tutorialspoint.com/python/python_classes_objects.htm), using +[Classes](http://docs.python.org/tutorial/classes.html), their methods and properties -Obviously, the more things you feel comfortable with, the easier time you'll have to find your way. With just basic knowledge you should be able to define your own [Commands](./Commands), create custom [Objects](./Objects) as well as make your world come alive with basic [Scripts](./Scripts). You can definitely build a whole advanced and customized game from extending Evennia's examples only. +Obviously, the more things you feel comfortable with, the easier time you'll have to find your way. +With just basic knowledge you should be able to define your own [Commands](./Commands), create custom +[Objects](./Objects) as well as make your world come alive with basic [Scripts](./Scripts). You can +definitely build a whole advanced and customized game from extending Evennia's examples only. ### I know my Python stuff and I am willing to use it! -Even if you started out as a Python beginner, you will likely get to this point after working on your game for a while. With more general knowledge in Python the full power of Evennia opens up for you. Apart from modifying commands, objects and scripts, you can develop everything from advanced mob AI and economic systems, through sophisticated combat and social mini games, to redefining how commands, players, rooms or channels themselves work. Since you code your game by importing normal Python modules, there are few limits to what you can accomplish. +Even if you started out as a Python beginner, you will likely get to this point after working on +your game for a while. With more general knowledge in Python the full power of Evennia opens up for +you. Apart from modifying commands, objects and scripts, you can develop everything from advanced +mob AI and economic systems, through sophisticated combat and social mini games, to redefining how +commands, players, rooms or channels themselves work. Since you code your game by importing normal +Python modules, there are few limits to what you can accomplish. -If you *also* happen to know some web programming (HTML, CSS, Javascript) there is also a web presence (a website and a mud web client) to play around with ... +If you *also* happen to know some web programming (HTML, CSS, Javascript) there is also a web +presence (a website and a mud web client) to play around with ... ### Where to from here? -From here you can continue browsing the [online documentation]([online documentation](index)) to find more info about Evennia. Or you can jump into the [Tutorials](./Tutorials) and get your hands dirty with code right away. You can also read the developer's [dev blog](https://evennia.blogspot.com/) for many tidbits and snippets about Evennia's development and structure. +From here you can continue browsing the [online documentation](./index) to +find more info about Evennia. Or you can jump into the [Tutorials](./Tutorials) and get your hands +dirty with code right away. You can also read the developer's [dev blog](https://evennia.blogspot.com/) for many tidbits and snippets about Evennia's development and +structure. -Some more hints: +Some more hints: -1. Get engaged in the community. Make an introductory post to our [mailing list/forum](https://groups.google.com/forum/#!forum/evennia) and get to know people. It's also highly recommended you hop onto our [Developer chat](http://webchat.freenode.net/?channels=evennia&uio=MT1mYWxzZSY5PXRydWUmMTE9MTk1JjEyPXRydWUbb) on IRC. This allows you to chat directly with other developers new and old as well as with the devs of Evennia itself. This chat is logged (you can find links on http://www.evennia.com) and can also be searched from the same place for discussion topics you are interested in. -2. Read the [Game Planning](./Game-Planning) wiki page. It gives some ideas for your work flow and the state of mind you should aim for - including cutting down the scope of your game for its first release. -3. Do the [Tutorial for basic MUSH-like game](./Tutorial-for-basic-MUSH-like-game) carefully from beginning to end and try to understand what does what. Even if you are not interested in a MUSH for your own game, you will end up with a small (very small) game that you can build or learn from. +1. Get engaged in the community. Make an introductory post to our [mailing list/forum](https://groups.google.com/forum/#!forum/evennia) and get to know people. It's also +highly recommended you hop onto our [Developer chat](http://webchat.freenode.net/?channels=evennia&uio=MT1mYWxzZSY5PXRydWUmMTE9MTk1JjEyPXRydWUbb) +on IRC. This allows you to chat directly with other developers new and old as well as with the devs +of Evennia itself. This chat is logged (you can find links on http://www.evennia.com) and can also +be searched from the same place for discussion topics you are interested in. +2. Read the [Game Planning](./Game-Planning) wiki page. It gives some ideas for your work flow and the +state of mind you should aim for - including cutting down the scope of your game for its first +release. +3. Do the [Tutorial for basic MUSH-like game](./Tutorial-for-basic-MUSH-like-game) carefully from +beginning to end and try to understand what does what. Even if you are not interested in a MUSH for +your own game, you will end up with a small (very small) game that you can build or learn from. diff --git a/docs/source/Evennia-for-Diku-Users.md b/docs/source/Evennia-for-Diku-Users.md index 726b663c75..5ce7b14352 100644 --- a/docs/source/Evennia-for-Diku-Users.md +++ b/docs/source/Evennia-for-Diku-Users.md @@ -1,20 +1,41 @@ # Evennia for Diku Users -Evennia represents a learning curve for those who used to code on [Diku](https://en.wikipedia.org/wiki/DikuMUD) type MUDs. While coding in Python is easy if you already know C, the main effort is to get rid of old C programming habits. Trying to code Python the way you code C will not only look ugly, it will lead to less optimal and harder to maintain code. Reading Evennia example code is a good way to get a feel for how different problems are approached in Python. +Evennia represents a learning curve for those who used to code on +[Diku](https://en.wikipedia.org/wiki/DikuMUD) type MUDs. While coding in Python is easy if you +already know C, the main effort is to get rid of old C programming habits. Trying to code Python the +way you code C will not only look ugly, it will lead to less optimal and harder to maintain code. +Reading Evennia example code is a good way to get a feel for how different problems are approached +in Python. -Overall, Python offers an extensive library of resources, safe memory management and excellent handling of errors. While Python code does not run as fast as raw C code does, the difference is not all that important for a text-based game. The main advantage of Python is an extremely fast development cycle with and easy ways to create game systems that would take many times more code and be much harder to make stable and maintainable in C. +Overall, Python offers an extensive library of resources, safe memory management and excellent +handling of errors. While Python code does not run as fast as raw C code does, the difference is not +all that important for a text-based game. The main advantage of Python is an extremely fast +development cycle with and easy ways to create game systems that would take many times more code and +be much harder to make stable and maintainable in C. ### Core Differences -- As mentioned, the main difference between Evennia and a Diku-derived codebase is that Evennia is written purely in Python. Since Python is an interpreted language there is no compile stage. It is modified and extended by the server loading Python modules at run-time. It also runs on all computer platforms Python runs on (which is basically everywhere). -- Vanilla Diku type engines save their data in custom *flat file* type storage solutions. By contrast, Evennia stores all game data in one of several supported SQL databases. Whereas flat files have the advantage of being easier to implement, they (normally) lack many expected safety features and ways to effectively extract subsets of the stored data. For example, if the server loses power while writing to a flatfile it may become corrupt and the data lost. A proper database solution is not susceptible to this - at no point is the data in a state where it cannot be recovered. Databases are also highly optimized for querying large data sets efficiently. +- As mentioned, the main difference between Evennia and a Diku-derived codebase is that Evennia is +written purely in Python. Since Python is an interpreted language there is no compile stage. It is +modified and extended by the server loading Python modules at run-time. It also runs on all computer +platforms Python runs on (which is basically everywhere). +- Vanilla Diku type engines save their data in custom *flat file* type storage solutions. By +contrast, Evennia stores all game data in one of several supported SQL databases. Whereas flat files +have the advantage of being easier to implement, they (normally) lack many expected safety features +and ways to effectively extract subsets of the stored data. For example, if the server loses power +while writing to a flatfile it may become corrupt and the data lost. A proper database solution is +not susceptible to this - at no point is the data in a state where it cannot be recovered. Databases +are also highly optimized for querying large data sets efficiently. ### Some Familiar Things Diku expresses the character object referenced normally by: -`struct char ch*` then all character-related fields can be accessed by `ch->`. In Evennia, one must pay attention to what object you are using, and when you are accessing another through back-handling, that you are accessing the right object. In Diku C, accessing character object is normally done by: +`struct char ch*` then all character-related fields can be accessed by `ch->`. In Evennia, one must +pay attention to what object you are using, and when you are accessing another through back- +handling, that you are accessing the right object. In Diku C, accessing character object is normally +done by: ```c /* creating pointer of both character and room struct */ @@ -28,7 +49,10 @@ void(struct char ch*, struct room room*){ }; ``` -As an example for creating Commands in Evennia via the `from evennia import Command` the character object that calls the command is denoted by a class property as `self.caller`. In this example `self.caller` is essentially the 'object' that has called the Command, but most of the time it is an Account object. For a more familiar Diku feel, create a variable that becomes the account object as: +As an example for creating Commands in Evennia via the `from evennia import Command` the character +object that calls the command is denoted by a class property as `self.caller`. In this example +`self.caller` is essentially the 'object' that has called the Command, but most of the time it is an +Account object. For a more familiar Diku feel, create a variable that becomes the account object as: ```python #mygame/commands/command.py @@ -51,7 +75,8 @@ class CmdMyCmd(Command): ``` -As mentioned above, care must be taken what specific object you are working with. If focused on a room object and you need to access the account object: +As mentioned above, care must be taken what specific object you are working with. If focused on a +room object and you need to access the account object: ```python #mygame/typeclasses/room.py @@ -78,11 +103,17 @@ class MyRoom(DefaultRoom): ## Emulating Evennia to Look and Feel Like A Diku/ROM -To emulate a Diku Mud on Evennia some work has to be done before hand. If there is anything that all coders and builders remember from Diku/Rom days is the presence of VNUMs. Essentially all data was saved in flat files and indexed by VNUMs for easy access. Evennia has the ability to emulate VNUMS to the extent of categorising rooms/mobs/objs/trigger/zones[...] into vnum ranges. +To emulate a Diku Mud on Evennia some work has to be done before hand. If there is anything that all +coders and builders remember from Diku/Rom days is the presence of VNUMs. Essentially all data was +saved in flat files and indexed by VNUMs for easy access. Evennia has the ability to emulate VNUMS +to the extent of categorising rooms/mobs/objs/trigger/zones[...] into vnum ranges. -Evennia has objects that are called Scripts. As defined, they are the 'out of game' instances that exist within the mud, but never directly interacted with. Scripts can be used for timers, mob AI, and even a stand alone databases. +Evennia has objects that are called Scripts. As defined, they are the 'out of game' instances that +exist within the mud, but never directly interacted with. Scripts can be used for timers, mob AI, +and even a stand alone databases. -Because of their wonderful structure all mob, room, zone, triggers, etc.. data can be saved in independently created global scripts. +Because of their wonderful structure all mob, room, zone, triggers, etc.. data can be saved in +independently created global scripts. Here is a sample mob file from a Diku Derived flat file. @@ -105,7 +136,7 @@ Puff~ Puff the Fractal Dragon is here, contemplating a higher reality. ~ Is that some type of differential curve involving some strange, and unknown -calculus that she seems to be made out of? +calculus that she seems to be made out of? ~ 516106 0 0 0 2128 0 0 0 1000 E 34 9 -10 6d6+340 5d5+5 @@ -114,10 +145,15 @@ calculus that she seems to be made out of? BareHandAttack: 12 E T 95 -``` -Each line represents something that the MUD reads in and does something with it. This isn't easy to read, but let's see if we can emulate this as a dictionary to be stored on a database script created in Evennia. +``` +Each line represents something that the MUD reads in and does something with it. This isn't easy to +read, but let's see if we can emulate this as a dictionary to be stored on a database script created +in Evennia. -First, let's create a global script that does absolutely nothing and isn't attached to anything. You can either create this directly in-game with the @py command or create it in another file to do some checks and balances if for whatever reason the script needs to be created again. Progmatically it can be done like so: +First, let's create a global script that does absolutely nothing and isn't attached to anything. You +can either create this directly in-game with the @py command or create it in another file to do some +checks and balances if for whatever reason the script needs to be created again. Progmatically it +can be done like so: ```python from evennia import create_script @@ -126,7 +162,8 @@ mob_db = create_script("typeclasses.scripts.DefaultScript", key="mobdb", persistent=True, obj=None) mob_db.db.vnums = {} ``` -Just by creating a simple script object and assigning it a 'vnums' attribute as a type dictionary. Next we have to create the mob layout.. +Just by creating a simple script object and assigning it a 'vnums' attribute as a type dictionary. +Next we have to create the mob layout.. ```python # vnum : mob_data @@ -146,13 +183,17 @@ mob_vnum_1 = { mob_db.db.vnums[1] = mob_vnum_1 ``` -This is a very 'caveman' example, but it gets the idea across. You can use the keys in the `mob_db.vnums` to act as the mob vnum while the rest contains the data.. +This is a very 'caveman' example, but it gets the idea across. You can use the keys in the +`mob_db.vnums` to act as the mob vnum while the rest contains the data.. -Much simpler to read and edit. If you plan on taking this route, you must keep in mind that by default evennia 'looks' at different properties when using the `look` command for instance. If you create an instance of this mob and make its `self.key = 1`, by default evennia will say +Much simpler to read and edit. If you plan on taking this route, you must keep in mind that by +default evennia 'looks' at different properties when using the `look` command for instance. If you +create an instance of this mob and make its `self.key = 1`, by default evennia will say `Here is : 1` -You must restructure all default commands so that the mud looks at different properties defined on your mob. +You must restructure all default commands so that the mud looks at different properties defined on +your mob. diff --git a/docs/source/Evennia-for-MUSH-Users.md b/docs/source/Evennia-for-MUSH-Users.md index 3d9147e0f3..ad579dc68c 100644 --- a/docs/source/Evennia-for-MUSH-Users.md +++ b/docs/source/Evennia-for-MUSH-Users.md @@ -1,40 +1,95 @@ # Evennia for MUSH Users -*This page is adopted from an article originally posted for the MUSH community [here on musoapbox.net](http://musoapbox.net/topic/1150/evennia-for-mushers).* +*This page is adopted from an article originally posted for the MUSH community [here on +musoapbox.net](http://musoapbox.net/topic/1150/evennia-for-mushers).* -[MUSH](https://en.wikipedia.org/wiki/MUSH)es are text multiplayer games traditionally used for heavily roleplay-focused game styles. They are often (but not always) utilizing game masters and human oversight over code automation. MUSHes are traditionally built on the TinyMUSH-family of game servers, like PennMUSH, TinyMUSH, TinyMUX and RhostMUSH. Also their siblings [MUCK](https://en.wikipedia.org/wiki/TinyMUCK) and [MOO](https://en.wikipedia.org/wiki/MOO) are often mentioned together with MUSH since they all inherit from the same [TinyMUD](https://en.wikipedia.org/wiki/MUD_trees#TinyMUD_family_tree) base. A major feature is the ability to modify and program the game world from inside the game by using a custom scripting language. We will refer to this online scripting as *softcode* here. +[MUSH](https://en.wikipedia.org/wiki/MUSH)es are text multiplayer games traditionally used for +heavily roleplay-focused game styles. They are often (but not always) utilizing game masters and +human oversight over code automation. MUSHes are traditionally built on the TinyMUSH-family of game +servers, like PennMUSH, TinyMUSH, TinyMUX and RhostMUSH. Also their siblings +[MUCK](https://en.wikipedia.org/wiki/TinyMUCK) and [MOO](https://en.wikipedia.org/wiki/MOO) are +often mentioned together with MUSH since they all inherit from the same +[TinyMUD](https://en.wikipedia.org/wiki/MUD_trees#TinyMUD_family_tree) base. A major feature is the +ability to modify and program the game world from inside the game by using a custom scripting +language. We will refer to this online scripting as *softcode* here. -Evennia works quite differently from a MUSH both in its overall design and under the hood. The same things are achievable, just in a different way. Here are some fundamental differences to keep in mind if you are coming from the MUSH world. +Evennia works quite differently from a MUSH both in its overall design and under the hood. The same +things are achievable, just in a different way. Here are some fundamental differences to keep in +mind if you are coming from the MUSH world. ## Developers vs Players -In MUSH, users tend to code and expand all aspects of the game from inside it using softcode. A MUSH can thus be said to be managed solely by *Players* with different levels of access. Evennia on the other hand, differentiates between the role of the *Player* and the *Developer*. +In MUSH, users tend to code and expand all aspects of the game from inside it using softcode. A MUSH +can thus be said to be managed solely by *Players* with different levels of access. Evennia on the +other hand, differentiates between the role of the *Player* and the *Developer*. -- An Evennia *Developer* works in Python from *outside* the game, in what MUSH would consider “hardcode”. Developers implement larger-scale code changes and can fundamentally change how the game works. They then load their changes into the running Evennia server. Such changes will usually not drop any connected players. -- An Evennia *Player* operates from *inside* the game. Some staff-level players are likely to double as developers. Depending on access level, players can modify and expand the game's world by digging new rooms, creating new objects, alias commands, customize their experience and so on. Trusted staff may get access to Python via the `@py` command, but this would be a security risk for normal Players to use. So the *Player* usually operates by making use of the tools prepared for them by the *Developer* - tools that can be as rigid or flexible as the developer desires. +- An Evennia *Developer* works in Python from *outside* the game, in what MUSH would consider +“hardcode”. Developers implement larger-scale code changes and can fundamentally change how the game +works. They then load their changes into the running Evennia server. Such changes will usually not +drop any connected players. +- An Evennia *Player* operates from *inside* the game. Some staff-level players are likely to double +as developers. Depending on access level, players can modify and expand the game's world by digging +new rooms, creating new objects, alias commands, customize their experience and so on. Trusted staff +may get access to Python via the `@py` command, but this would be a security risk for normal Players +to use. So the *Player* usually operates by making use of the tools prepared for them by the +*Developer* - tools that can be as rigid or flexible as the developer desires. ## Collaborating on a game - Python vs Softcode -For a *Player*, collaborating on a game need not be too different between MUSH and Evennia. The building and description of the game world can still happen mostly in-game using build commands, using text tags and [inline functions](./TextTags#inline-functions) to prettify and customize the experience. Evennia offers external ways to build a world but those are optional. There is also nothing *in principle* stopping a Developer from offering a softcode-like language to Players if that is deemed necessary. +For a *Player*, collaborating on a game need not be too different between MUSH and Evennia. The +building and description of the game world can still happen mostly in-game using build commands, +using text tags and [inline functions](./TextTags#inline-functions) to prettify and customize the +experience. Evennia offers external ways to build a world but those are optional. There is also +nothing *in principle* stopping a Developer from offering a softcode-like language to Players if +that is deemed necessary. -For *Developers* of the game, the difference is larger: Code is mainly written outside the game in Python modules rather than in-game on the command line. Python is a very popular and well-supported language with tons of documentation and help to be found. The Python standard library is also a great help for not having to reinvent the wheel. But that said, while Python is considered one of the easier languages to learn and use it is undoubtedly very different from MUSH softcode. +For *Developers* of the game, the difference is larger: Code is mainly written outside the game in +Python modules rather than in-game on the command line. Python is a very popular and well-supported +language with tons of documentation and help to be found. The Python standard library is also a +great help for not having to reinvent the wheel. But that said, while Python is considered one of +the easier languages to learn and use it is undoubtedly very different from MUSH softcode. -While softcode allows collaboration in-game, Evennia's external coding instead opens up the possibility for collaboration using professional version control tools and bug tracking using websites like github (or bitbucket for a free private repo). Source code can be written in proper text editors and IDEs with refactoring, syntax highlighting and all other conveniences. In short, collaborative development of an Evennia game is done in the same way most professional collaborative development is done in the world, meaning all the best tools can be used. +While softcode allows collaboration in-game, Evennia's external coding instead opens up the +possibility for collaboration using professional version control tools and bug tracking using +websites like github (or bitbucket for a free private repo). Source code can be written in proper +text editors and IDEs with refactoring, syntax highlighting and all other conveniences. In short, +collaborative development of an Evennia game is done in the same way most professional collaborative +development is done in the world, meaning all the best tools can be used. ## `@parent` vs `@typeclass` and `@spawn` -Inheritance works differently in Python than in softcode. Evennia has no concept of a "master object" that other objects inherit from. There is in fact no reason at all to introduce "virtual objects" in the game world - code and data are kept separate from one another. +Inheritance works differently in Python than in softcode. Evennia has no concept of a "master +object" that other objects inherit from. There is in fact no reason at all to introduce "virtual +objects" in the game world - code and data are kept separate from one another. -In Python (which is an [object oriented](https://en.wikipedia.org/wiki/Object-oriented_programming) language) one instead creates *classes* - these are like blueprints from which you spawn any number of *object instances*. Evennia also adds the extra feature that every instance is persistent in the database (this means no SQL is ever needed). To take one example, a unique character in Evennia is an instances of the class `Character`. +In Python (which is an [object oriented](https://en.wikipedia.org/wiki/Object-oriented_programming) +language) one instead creates *classes* - these are like blueprints from which you spawn any number +of *object instances*. Evennia also adds the extra feature that every instance is persistent in the +database (this means no SQL is ever needed). To take one example, a unique character in Evennia is +an instances of the class `Character`. -One parallel to MUSH's `@parent` command may be Evennia's `@typeclass` command, which changes which class an already existing object is an instance of. This way you can literally turn a `Character` into a `Flowerpot` on the spot. +One parallel to MUSH's `@parent` command may be Evennia's `@typeclass` command, which changes which +class an already existing object is an instance of. This way you can literally turn a `Character` +into a `Flowerpot` on the spot. -if you are new to object oriented design it's important to note that all object instances of a class does *not* have to be identical. If they did, all Characters would be named the same. Evennia allows to customize individual objects in many different ways. One way is through *Attributes*, which are database-bound properties that can be linked to any object. For example, you could have an `Orc` class that defines all the stuff an Orc should be able to do (probably in turn inheriting from some `Monster` class shared by all monsters). Setting different Attributes on different instances (different strength, equipment, looks etc) would make each Orc unique despite all sharing the same class. +if you are new to object oriented design it's important to note that all object instances of a class +does *not* have to be identical. If they did, all Characters would be named the same. Evennia allows +to customize individual objects in many different ways. One way is through *Attributes*, which are +database-bound properties that can be linked to any object. For example, you could have an `Orc` +class that defines all the stuff an Orc should be able to do (probably in turn inheriting from some +`Monster` class shared by all monsters). Setting different Attributes on different instances +(different strength, equipment, looks etc) would make each Orc unique despite all sharing the same +class. - The `@spawn` command allows one to conveniently choose between different "sets" of Attributes to put on each new Orc (like the "warrior" set or "shaman" set) . Such sets can even inherit one another which is again somewhat remniscent at least of the *effect* of `@parent` and the object-based inheritance of MUSH. + The `@spawn` command allows one to conveniently choose between different "sets" of Attributes to +put on each new Orc (like the "warrior" set or "shaman" set) . Such sets can even inherit one +another which is again somewhat remniscent at least of the *effect* of `@parent` and the object- +based inheritance of MUSH. -There are other differences for sure, but that should give some feel for things. Enough with the theory. Let's get down to more practical matters next. To install, see the [Getting Started instructions](./Getting-Started). +There are other differences for sure, but that should give some feel for things. Enough with the +theory. Let's get down to more practical matters next. To install, see the [Getting Started +instructions](Getting-Started). ## A first step making things more familiar @@ -42,15 +97,21 @@ We will here give two examples of customizing Evennia to be more familiar to a M ### Activating a multi-descer -By default Evennia’s `desc` command updates your description and that’s it. There is a more feature-rich optional “multi-descer” in `evennia/contrib/multidesc.py` though. This alternative allows for managing and combining a multitude of keyed descriptions. +By default Evennia’s `desc` command updates your description and that’s it. There is a more feature- +rich optional “multi-descer” in `evennia/contrib/multidesc.py` though. This alternative allows for +managing and combining a multitude of keyed descriptions. -To activate the multi-descer, `cd` to your game folder and into the `commands` sub-folder. There you’ll find the file `default_cmdsets.py`. In Python lingo all `*.py` files are called *modules*. Open the module in a text editor. We won’t go into Evennia in-game *Commands* and *Command sets* further here, but suffice to say Evennia allows you to change which commands (or versions of commands) are available to the player from moment to moment depending on circumstance. +To activate the multi-descer, `cd` to your game folder and into the `commands` sub-folder. There +you’ll find the file `default_cmdsets.py`. In Python lingo all `*.py` files are called *modules*. +Open the module in a text editor. We won’t go into Evennia in-game *Commands* and *Command sets* +further here, but suffice to say Evennia allows you to change which commands (or versions of +commands) are available to the player from moment to moment depending on circumstance. Add two new lines to the module as seen below: ```python # the file mygame/commands/default_cmdsets.py -# [...] +# [...] from evennia.contrib import multidescer # <- added now @@ -70,57 +131,92 @@ class CharacterCmdSet(default_cmds.CharacterCmdSet): # # any commands you add below will overload the default ones. # - self.add(multidescer.CmdMultiDesc()) # <- added now + self.add(multidescer.CmdMultiDesc()) # <- added now # [...] ``` -Note that Python cares about indentation, so make sure to indent with the same number of spaces as shown above! +Note that Python cares about indentation, so make sure to indent with the same number of spaces as +shown above! -So what happens above? We [import the module](http://www.linuxtopia.org/online_books/programming_books/python_programming/python_ch28s03.html) `evennia/contrib/multidescer.py` at the top. Once imported we can access stuff inside that module using full stop (`.`). The multidescer is defined as a class `CmdMultiDesc` (we could find this out by opening said module in a text editor). At the bottom we create a new instance of this class and add it to the `CharacterCmdSet` class. For the sake of this tutorial we only need to know that `CharacterCmdSet` contains all commands that should be be available to the `Character` by default. +So what happens above? We [import the module](http://www.linuxtopia.org/online_books/programming_boo +ks/python_programming/python_ch28s03.html) `evennia/contrib/multidescer.py` at the top. Once +imported we can access stuff inside that module using full stop (`.`). The multidescer is defined as +a class `CmdMultiDesc` (we could find this out by opening said module in a text editor). At the +bottom we create a new instance of this class and add it to the `CharacterCmdSet` class. For the +sake of this tutorial we only need to know that `CharacterCmdSet` contains all commands that should +be be available to the `Character` by default. -This whole thing will be triggered when the command set is first created, which happens on server start. So we need to reload Evennia with `@reload` - no one will be disconnected by doing this. If all went well you should now be able to use `desc` (or `+desc`) and find that you have more possibilities: +This whole thing will be triggered when the command set is first created, which happens on server +start. So we need to reload Evennia with `@reload` - no one will be disconnected by doing this. If +all went well you should now be able to use `desc` (or `+desc`) and find that you have more +possibilities: ```text > help +desc # get help on the command -> +desc eyes = His eyes are blue. +> +desc eyes = His eyes are blue. > +desc basic = A big guy. > +desc/set basic + + eyes # we add an extra space between > look me A big guy. His eyes are blue. ``` -If there are errors, a *traceback* will show in the server log - several lines of text showing where the error occurred. Find where the error is by locating the line number related to the `default_cmdsets.py` file (it's the only one you've changed so far). Most likely you mis-spelled something or missed the indentation. Fix it and either `@reload` again or run `evennia start` as needed. +If there are errors, a *traceback* will show in the server log - several lines of text showing +where the error occurred. Find where the error is by locating the line number related to the +`default_cmdsets.py` file (it's the only one you've changed so far). Most likely you mis-spelled +something or missed the indentation. Fix it and either `@reload` again or run `evennia start` as +needed. -### Customizing the multidescer syntax +### Customizing the multidescer syntax -As seen above the multidescer uses syntax like this (where `|/` are Evennia's tags for line breaks) : +As seen above the multidescer uses syntax like this (where `|/` are Evennia's tags for line breaks) +: ```text -> +desc/set basic + |/|/ + cape + footwear + |/|/ + attitude -``` +> +desc/set basic + |/|/ + cape + footwear + |/|/ + attitude +``` -This use of `+ ` was prescribed by the *Developer* that coded this `+desc` command. What if the *Player* doesn’t like this syntax though? Do players need to pester the dev to change it? Not necessarily. While Evennia does not allow the player to build their own multi-descer on the command line, it does allow for *re-mapping* the command syntax to one they prefer. This is done using the `nick` command. +This use of `+ ` was prescribed by the *Developer* that coded this `+desc` command. What if the +*Player* doesn’t like this syntax though? Do players need to pester the dev to change it? Not +necessarily. While Evennia does not allow the player to build their own multi-descer on the command +line, it does allow for *re-mapping* the command syntax to one they prefer. This is done using the +`nick` command. -Here’s a nick that changes how to input the command above: +Here’s a nick that changes how to input the command above: ```text > nick setdesc $1 $2 $3 $4 = +desc/set $1 + |/|/ + $2 + $3 + |/|/ + $4 ``` -The string on the left will be matched against your input and if matching, it will be replaced with the string on the right. The `$`-type tags will store space-separated arguments and put them into the replacement. The nick allows [shell-like wildcards](http://www.linfo.org/wildcard.html), so you can use `*`, `?`, `[...]`, `[!...]` etc to match parts of the input. +The string on the left will be matched against your input and if matching, it will be replaced with +the string on the right. The `$`-type tags will store space-separated arguments and put them into +the replacement. The nick allows [shell-like wildcards](http://www.linfo.org/wildcard.html), so you +can use `*`, `?`, `[...]`, `[!...]` etc to match parts of the input. -The same description as before can now be set as +The same description as before can now be set as ```text -> setdesc basic cape footwear attitude +> setdesc basic cape footwear attitude ``` -With the `nick` functionality players can mitigate a lot of syntax dislikes even without the developer changing the underlying Python code. +With the `nick` functionality players can mitigate a lot of syntax dislikes even without the +developer changing the underlying Python code. ## Next steps -If you are a *Developer* and are interested in making a more MUSH-like Evennia game, a good start is to look into the Evennia [Tutorial for a first MUSH-like game](./Tutorial-for-basic-MUSH-like-game). That steps through building a simple little game from scratch and helps to acquaint you with the various corners of Evennia. There is also the [Tutorial for running roleplaying sessions](./Evennia-for-roleplaying-sessions) that can be of interest. +If you are a *Developer* and are interested in making a more MUSH-like Evennia game, a good start is +to look into the Evennia [Tutorial for a first MUSH-like game](./Tutorial-for-basic-MUSH-like-game). +That steps through building a simple little game from scratch and helps to acquaint you with the +various corners of Evennia. There is also the [Tutorial for running roleplaying sessions](Evennia- +for-roleplaying-sessions) that can be of interest. -An important aspect of making things more familiar for *Players* is adding new and tweaking existing commands. How this is done is covered by the [Tutorial on adding new commands](./Adding-Command-Tutorial). You may also find it useful to shop through the `evennia/contrib/` folder. The [Tutorial world](./Tutorial-World-Introduction) is a small single-player quest you can try (it’s not very MUSH-like but it does show many Evennia concepts in action). Beyond that there are [many more tutorials](./Tutorials) to try out. If you feel you want a more visual overview you can also look at [Evennia in pictures](https://evennia.blogspot.se/2016/05/evennia-in-pictures.html). +An important aspect of making things more familiar for *Players* is adding new and tweaking existing +commands. How this is done is covered by the [Tutorial on adding new commands](Adding-Command- +Tutorial). You may also find it useful to shop through the `evennia/contrib/` folder. The [Tutorial +world](Tutorial-World-Introduction) is a small single-player quest you can try (it’s not very MUSH- +like but it does show many Evennia concepts in action). Beyond that there are [many more +tutorials](Tutorials) to try out. If you feel you want a more visual overview you can also look at +[Evennia in pictures](https://evennia.blogspot.se/2016/05/evennia-in-pictures.html). -… And of course, if you need further help you can always drop into the [Evennia chatroom](http://webchat.freenode.net/?channels=evennia&uio=MT1mYWxzZSY5PXRydWUmMTE9MTk1JjEyPXRydWUbb) or post a question in our [forum/mailing list](https://groups.google.com/forum/#%21forum/evennia)! +… And of course, if you need further help you can always drop into the [Evennia chatroom](http://web +chat.freenode.net/?channels=evennia&uio=MT1mYWxzZSY5PXRydWUmMTE9MTk1JjEyPXRydWUbb) or post a +question in our [forum/mailing list](https://groups.google.com/forum/#%21forum/evennia)! diff --git a/docs/source/Evennia-for-roleplaying-sessions.md b/docs/source/Evennia-for-roleplaying-sessions.md index ef1c1b5dc7..2f980a8b58 100644 --- a/docs/source/Evennia-for-roleplaying-sessions.md +++ b/docs/source/Evennia-for-roleplaying-sessions.md @@ -1,46 +1,72 @@ # Evennia for roleplaying sessions -This tutorial will explain how to set up a realtime or play-by-post tabletop style game using a fresh Evennia server. +This tutorial will explain how to set up a realtime or play-by-post tabletop style game using a +fresh Evennia server. -The scenario is thus: You and a bunch of friends want to play a tabletop role playing game online. One of you will be the game master and you are all okay with playing using written text. You want both the ability to role play in real-time (when people happen to be online at the same time) as well as the ability for people to post when they can and catch up on what happened since they were last online. +The scenario is thus: You and a bunch of friends want to play a tabletop role playing game online. +One of you will be the game master and you are all okay with playing using written text. You want +both the ability to role play in real-time (when people happen to be online at the same time) as +well as the ability for people to post when they can and catch up on what happened since they were +last online. This is the functionality we will be needing and using: * The ability to make one of you the *GM* (game master), with special abilities. -* A *Character sheet* that players can create, view and fill in. It can also be locked so only the GM can modify it. +* A *Character sheet* that players can create, view and fill in. It can also be locked so only the +GM can modify it. * A *dice roller* mechanism, for whatever type of dice the RPG rules require. -* *Rooms*, to give a sense of location and to compartmentalize play going on- This means both Character movements from location to location and GM explicitly moving them around. +* *Rooms*, to give a sense of location and to compartmentalize play going on- This means both +Character movements from location to location and GM explicitly moving them around. * *Channels*, for easily sending text to all subscribing accounts, regardless of location. -* Account-to-Account *messaging* capability, including sending to multiple recipients simultaneously, regardless of location. +* Account-to-Account *messaging* capability, including sending to multiple recipients +simultaneously, regardless of location. -We will find most of these things are already part of vanilla Evennia, but that we can expand on the defaults for our particular use-case. Below we will flesh out these components from start to finish. +We will find most of these things are already part of vanilla Evennia, but that we can expand on the +defaults for our particular use-case. Below we will flesh out these components from start to finish. ## Starting out -We will assume you start from scratch. You need Evennia installed, as per the [Getting Started](./Getting-Started) instructions. Initialize a new game directory with `evennia init `. In this tutorial we assume your game dir is simply named `mygame`. You can use the default database and keep all other settings to default for now. Familiarize yourself with the `mygame` folder before continuing. You might want to browse the [First Steps Coding](./First-Steps-Coding) tutorial, just to see roughly where things are modified. +We will assume you start from scratch. You need Evennia installed, as per the [Getting +Started](Getting-Started) instructions. Initialize a new game directory with `evennia init +`. In this tutorial we assume your game dir is simply named `mygame`. You can use the +default database and keep all other settings to default for now. Familiarize yourself with the +`mygame` folder before continuing. You might want to browse the [First Steps Coding](First-Steps- +Coding) tutorial, just to see roughly where things are modified. ## The Game Master role -In brief: +In brief: -* Simplest way: Being an admin, just give one account `Admins` permission using the standard `@perm` command. -* Better but more work: Make a custom command to set/unset the above, while tweaking the Character to show your renewed GM status to the other accounts. +* Simplest way: Being an admin, just give one account `Admins` permission using the standard `@perm` +command. +* Better but more work: Make a custom command to set/unset the above, while tweaking the Character +to show your renewed GM status to the other accounts. ### The permission hierarchy -Evennia has the following [permission hierarchy](./Building-Permissions#assigning-permissions) out of the box: *Players, Helpers, Builders, Admins* and finally *Developers*. We could change these but then we'd need to update our Default commands to use the changes. We want to keep this simple, so instead we map our different roles on top of this permission ladder. +Evennia has the following [permission hierarchy](./Building-Permissions#assigning-permissions) out of +the box: *Players, Helpers, Builders, Admins* and finally *Developers*. We could change these but +then we'd need to update our Default commands to use the changes. We want to keep this simple, so +instead we map our different roles on top of this permission ladder. -1. `Players` is the permission set on normal players. This is the default for anyone creating a new account on the server. -2. `Helpers` are like `Players` except they also have the ability to create/edit new help entries. This could be granted to players who are willing to help with writing lore or custom logs for everyone. +1. `Players` is the permission set on normal players. This is the default for anyone creating a new +account on the server. +2. `Helpers` are like `Players` except they also have the ability to create/edit new help entries. +This could be granted to players who are willing to help with writing lore or custom logs for +everyone. 3. `Builders` is not used in our case since the GM should be the only world-builder. -4. `Admins` is the permission level the GM should have. Admins can do everything builders can (create/describe rooms etc) but also kick accounts, rename them and things like that. -5. `Developers`-level permission are the server administrators, the ones with the ability to restart/shutdown the server as well as changing the permission levels. +4. `Admins` is the permission level the GM should have. Admins can do everything builders can +(create/describe rooms etc) but also kick accounts, rename them and things like that. +5. `Developers`-level permission are the server administrators, the ones with the ability to +restart/shutdown the server as well as changing the permission levels. -> The [superuser](./Building-Permissions#the-super-user) is not part of the hierarchy and actually completely bypasses it. We'll assume server admin(s) will "just" be Developers. +> The [superuser](./Building-Permissions#the-super-user) is not part of the hierarchy and actually +completely bypasses it. We'll assume server admin(s) will "just" be Developers. ### How to grant permissions -Only `Developers` can (by default) change permission level. Only they have access to the `@perm` command: +Only `Developers` can (by default) change permission level. Only they have access to the `@perm` +command: ``` > @perm Yvonne @@ -55,21 +81,30 @@ Permissions on Yvonne: accounts, admins Permissions on Yvonne: accounts ``` -There is no need to remove the basic `Players` permission when adding the higher permission: the highest will be used. Permission level names are *not* case sensitive. You can also use both plural and singular, so "Admins" gives the same powers as "Admin". +There is no need to remove the basic `Players` permission when adding the higher permission: the +highest will be used. Permission level names are *not* case sensitive. You can also use both plural +and singular, so "Admins" gives the same powers as "Admin". ### Optional: Making a GM-granting command -Use of `@perm` works out of the box, but it's really the bare minimum. Would it not be nice if other accounts could tell at a glance who the GM is? Also, we shouldn't really need to remember that the permission level is called "Admins". It would be easier if we could just do `@gm ` and `@notgm ` and at the same time change something make the new GM status apparent. +Use of `@perm` works out of the box, but it's really the bare minimum. Would it not be nice if other +accounts could tell at a glance who the GM is? Also, we shouldn't really need to remember that the +permission level is called "Admins". It would be easier if we could just do `@gm ` and +`@notgm ` and at the same time change something make the new GM status apparent. So let's make this possible. This is what we'll do: -1. We'll customize the default Character class. If an object of this class has a particular flag, its name will have the string`(GM)` added to the end. +1. We'll customize the default Character class. If an object of this class has a particular flag, +its name will have the string`(GM)` added to the end. 2. We'll add a new command, for the server admin to assign the GM-flag properly. #### Character modification -Let's first start by customizing the Character. We recommend you browse the beginning of the [Account](./Accounts) page to make sure you know how Evennia differentiates between the OOC "Account objects" (not to be confused with the `Accounts` permission, which is just a string specifying your access) and the IC "Character objects". +Let's first start by customizing the Character. We recommend you browse the beginning of the +[Account](./Accounts) page to make sure you know how Evennia differentiates between the OOC "Account +objects" (not to be confused with the `Accounts` permission, which is just a string specifying your +access) and the IC "Character objects". Open `mygame/typeclasses/characters.py` and modify the default `Character` class: @@ -103,13 +138,23 @@ class Character(DefaultCharacter): ``` -Above, we change how the Character's name is displayed: If the account controlling this Character is a GM, we attach the string `(GM)` to the Character's name so everyone can tell who's the boss. If we ourselves are Developers or GM's we will see database ids attached to Characters names, which can help if doing database searches against Characters of exactly the same name. We base the "gm-ingness" on having an flag (an [Attribute](./Attributes)) named `is_gm`. We'll make sure new GM's actually get this flag below. +Above, we change how the Character's name is displayed: If the account controlling this Character is +a GM, we attach the string `(GM)` to the Character's name so everyone can tell who's the boss. If we +ourselves are Developers or GM's we will see database ids attached to Characters names, which can +help if doing database searches against Characters of exactly the same name. We base the "gm- +ingness" on having an flag (an [Attribute](./Attributes)) named `is_gm`. We'll make sure new GM's +actually get this flag below. -> **Extra exercise:** This will only show the `(GM)` text on *Characters* puppeted by a GM account, that is, it will show only to those in the same location. If we wanted it to also pop up in, say, `who` listings and channels, we'd need to make a similar change to the `Account` typeclass in `mygame/typeclasses/accounts.py`. We leave this as an exercise to the reader. +> **Extra exercise:** This will only show the `(GM)` text on *Characters* puppeted by a GM account, +that is, it will show only to those in the same location. If we wanted it to also pop up in, say, +`who` listings and channels, we'd need to make a similar change to the `Account` typeclass in +`mygame/typeclasses/accounts.py`. We leave this as an exercise to the reader. #### New @gm/@ungm command -We will describe in some detail how to create and add an Evennia [command](./Commands) here with the hope that we don't need to be as detailed when adding commands in the future. We will build on Evennia's default "mux-like" commands here. +We will describe in some detail how to create and add an Evennia [command](./Commands) here with the +hope that we don't need to be as detailed when adding commands in the future. We will build on +Evennia's default "mux-like" commands here. Open `mygame/commands/command.py` and add a new Command class at the bottom: @@ -176,11 +221,17 @@ class CmdMakeGM(default_cmds.MuxCommand): ``` -All the command does is to locate the account target and assign it the `Admins` permission if we used `@gm` or revoke it if using the `@ungm` alias. We also set/unset the `is_gm` Attribute that is expected by our new `Character.get_display_name` method from earlier. +All the command does is to locate the account target and assign it the `Admins` permission if we +used `@gm` or revoke it if using the `@ungm` alias. We also set/unset the `is_gm` Attribute that is +expected by our new `Character.get_display_name` method from earlier. -> We could have made this into two separate commands or opted for a syntax like `@gm/revoke `. Instead we examine how this command was called (stored in `self.cmdstring`) in order to act accordingly. Either way works, practicality and coding style decides which to go with. +> We could have made this into two separate commands or opted for a syntax like `@gm/revoke +`. Instead we examine how this command was called (stored in `self.cmdstring`) in order +to act accordingly. Either way works, practicality and coding style decides which to go with. -To actually make this command available (only to Developers, due to the lock on it), we add it to the default Account command set. Open the file `mygame/commands/default_cmdsets.py` and find the `AccountCmdSet` class: +To actually make this command available (only to Developers, due to the lock on it), we add it to +the default Account command set. Open the file `mygame/commands/default_cmdsets.py` and find the +`AccountCmdSet` class: ```python # mygame/commands/default_cmdsets.py @@ -196,11 +247,12 @@ class AccountCmdSet(default_cmds.AccountCmdSet): ``` -Finally, issue the `@reload` command to update the server to your changes. Developer-level players (or the superuser) should now have the `@gm/@ungm` command available. +Finally, issue the `@reload` command to update the server to your changes. Developer-level players +(or the superuser) should now have the `@gm/@ungm` command available. ## Character sheet -In brief: +In brief: * Use Evennia's EvTable/EvForm to build a Character sheet * Tie individual sheets to a given Character. @@ -209,13 +261,18 @@ In brief: ### Building a Character sheet -There are many ways to build a Character sheet in text, from manually pasting strings together to more automated ways. Exactly what is the best/easiest way depends on the sheet one tries to create. We will here show two examples using the *EvTable* and *EvForm* utilities.Later we will create Commands to edit and display the output from those utilities. +There are many ways to build a Character sheet in text, from manually pasting strings together to +more automated ways. Exactly what is the best/easiest way depends on the sheet one tries to create. +We will here show two examples using the *EvTable* and *EvForm* utilities.Later we will create +Commands to edit and display the output from those utilities. -> Note that due to the limitations of the wiki, no color is used in any of the examples. See [the text tag documentation](./TextTags) for how to add color to the tables and forms. +> Note that due to the limitations of the wiki, no color is used in any of the examples. See [the +text tag documentation](TextTags) for how to add color to the tables and forms. #### Making a sheet with EvTable -[EvTable](github:evennia.utils.evtable) is a text-table generator. It helps with displaying text in ordered rows and columns. This is an example of using it in code: +[EvTable](github:evennia.utils.evtable) is a text-table generator. It helps with displaying text in +ordered rows and columns. This is an example of using it in code: ````python # this can be tried out in a Python shell like iPython @@ -232,7 +289,13 @@ table = evtable.EvTable("Attr", "Value", ], align='r', border="incols") ```` -Above, we create a two-column table by supplying the two columns directly. We also tell the table to be right-aligned and to use the "incols" border type (borders drawns only in between columns). The `EvTable` class takes a lot of arguments for customizing its look, you can see [some of the possible keyword arguments here](github:evennia.utils.evtable#evtable__init__). Once you have the `table` you could also retroactively add new columns and rows to it with `table.add_row()` and `table.add_column()`: if necessary the table will expand with empty rows/columns to always remain rectangular. +Above, we create a two-column table by supplying the two columns directly. We also tell the table to +be right-aligned and to use the "incols" border type (borders drawns only in between columns). The +`EvTable` class takes a lot of arguments for customizing its look, you can see [some of the possible +keyword arguments here](github:evennia.utils.evtable#evtable__init__). Once you have the `table` you +could also retroactively add new columns and rows to it with `table.add_row()` and +`table.add_column()`: if necessary the table will expand with empty rows/columns to always remain +rectangular. The result from printing the above table will be @@ -251,17 +314,29 @@ print(table_string) CHA | 13 ``` -This is a minimalistic but effective Character sheet. By combining the `table_string` with other strings one could build up a reasonably full graphical representation of a Character. For more advanced layouts we'll look into EvForm next. +This is a minimalistic but effective Character sheet. By combining the `table_string` with other +strings one could build up a reasonably full graphical representation of a Character. For more +advanced layouts we'll look into EvForm next. #### Making a sheet with EvForm -[EvForm](github:evennia.utils.evform) allows the creation of a two-dimensional "graphic" made by text characters. On this surface, one marks and tags rectangular regions ("cells") to be filled with content. This content can be either normal strings or `EvTable` instances (see the previous section, one such instance would be the `table` variable in that example). +[EvForm](github:evennia.utils.evform) allows the creation of a two-dimensional "graphic" made by +text characters. On this surface, one marks and tags rectangular regions ("cells") to be filled with +content. This content can be either normal strings or `EvTable` instances (see the previous section, +one such instance would be the `table` variable in that example). -In the case of a Character sheet, these cells would be comparable to a line or box where you could enter the name of your character or their strength score. EvMenu also easily allows to update the content of those fields in code (it use EvTables so you rebuild the table first before re-sending it to EvForm). +In the case of a Character sheet, these cells would be comparable to a line or box where you could +enter the name of your character or their strength score. EvMenu also easily allows to update the +content of those fields in code (it use EvTables so you rebuild the table first before re-sending it +to EvForm). -The drawback of EvForm is that its shape is static; if you try to put more text in a region than it was sized for, the text will be cropped. Similarly, if you try to put an EvTable instance in a field too small for it, the EvTable will do its best to try to resize to fit, but will eventually resort to cropping its data or even give an error if too small to fit any data. +The drawback of EvForm is that its shape is static; if you try to put more text in a region than it +was sized for, the text will be cropped. Similarly, if you try to put an EvTable instance in a field +too small for it, the EvTable will do its best to try to resize to fit, but will eventually resort +to cropping its data or even give an error if too small to fit any data. -An EvForm is defined in a Python module. Create a new file `mygame/world/charsheetform.py` and modify it thus: +An EvForm is defined in a Python module. Create a new file `mygame/world/charsheetform.py` and +modify it thus: ````python #coding=utf-8 @@ -291,9 +366,16 @@ FORM = """ +--------------------------------------+ """ ```` -The `#coding` statement (which must be put on the very first line to work) tells Python to use the utf-8 encoding for the file. Using the `FORMCHAR` and `TABLECHAR` we define what single-character we want to use to "mark" the regions of the character sheet holding cells and tables respectively. Within each block (which must be separated from one another by at least one non-marking character) we embed identifiers 1-4 to identify each block. The identifier could be any single character except for the `FORMCHAR` and `TABLECHAR` +The `#coding` statement (which must be put on the very first line to work) tells Python to use the +utf-8 encoding for the file. Using the `FORMCHAR` and `TABLECHAR` we define what single-character we +want to use to "mark" the regions of the character sheet holding cells and tables respectively. +Within each block (which must be separated from one another by at least one non-marking character) +we embed identifiers 1-4 to identify each block. The identifier could be any single character except +for the `FORMCHAR` and `TABLECHAR` -> You can still use `FORMCHAR` and `TABLECHAR` elsewhere in your sheet, but not in a way that it would identify a cell/table. The smallest identifiable cell/table area is 3 characters wide including the identifier (for example `x2x`). +> You can still use `FORMCHAR` and `TABLECHAR` elsewhere in your sheet, but not in a way that it +would identify a cell/table. The smallest identifiable cell/table area is 3 characters wide +including the identifier (for example `x2x`). Now we will map content to this form. @@ -318,9 +400,13 @@ form.map(cells={"1":NAME, "3": ADVANTAGES, "4": DISADVANTAGES}, tables={"2":table}) ```` -We create some RP-sounding input and re-use the `table` variable from the previous `EvTable` example. +We create some RP-sounding input and re-use the `table` variable from the previous `EvTable` +example. -> Note, that if you didn't want to create the form in a separate module you *could* also load it directly into the `EvForm` call like this: `EvForm(form={"FORMCHAR":"x", "TABLECHAR":"c", "FORM": formstring})` where `FORM` specifies the form as a string in the same way as listed in the module above. Note however that the very first line of the `FORM` string is ignored, so start with a `\n`. +> Note, that if you didn't want to create the form in a separate module you *could* also load it +directly into the `EvForm` call like this: `EvForm(form={"FORMCHAR":"x", "TABLECHAR":"c", "FORM": +formstring})` where `FORM` specifies the form as a string in the same way as listed in the module +above. Note however that the very first line of the `FORM` string is ignored, so start with a `\n`. We then map those to the cells of the form: @@ -347,11 +433,15 @@ print(form) +--------------------------------------+ ```` -As seen, the texts and tables have been slotted into the text areas and line breaks have been added where needed. We chose to just enter the Advantages/Disadvantages as plain strings here, meaning long names ended up split between rows. If we wanted more control over the display we could have inserted `\n` line breaks after each line or used a borderless `EvTable` to display those as well. +As seen, the texts and tables have been slotted into the text areas and line breaks have been added +where needed. We chose to just enter the Advantages/Disadvantages as plain strings here, meaning +long names ended up split between rows. If we wanted more control over the display we could have +inserted `\n` line breaks after each line or used a borderless `EvTable` to display those as well. ### Tie a Character sheet to a Character -We will assume we go with the `EvForm` example above. We now need to attach this to a Character so it can be modified. For this we will modify our `Character` class a little more: +We will assume we go with the `EvForm` example above. We now need to attach this to a Character so +it can be modified. For this we will modify our `Character` class a little more: ```python # mygame/typeclasses/character.py @@ -397,7 +487,10 @@ class Character(DefaultCharacter): ``` -Use `@reload` to make this change available to all *newly created* Characters. *Already existing* Characters will *not* have the charsheet defined, since `at_object_creation` is only called once. The easiest to force an existing Character to re-fire its `at_object_creation` is to use the `@typeclass` command in-game: +Use `@reload` to make this change available to all *newly created* Characters. *Already existing* +Characters will *not* have the charsheet defined, since `at_object_creation` is only called once. +The easiest to force an existing Character to re-fire its `at_object_creation` is to use the +`@typeclass` command in-game: ``` @typeclass/force @@ -405,7 +498,8 @@ Use `@reload` to make this change available to all *newly created* Characters. * ### Command for Account to change Character sheet -We will add a command to edit the sections of our Character sheet. Open `mygame/commands/command.py`. +We will add a command to edit the sections of our Character sheet. Open +`mygame/commands/command.py`. ```python # at the end of mygame/commands/command.py @@ -480,13 +574,16 @@ class CmdSheet(MuxCommand): ``` -Most of this command is error-checking to make sure the right type of data was input. Note how the `sheet_locked` Attribute is checked and will return if not set. +Most of this command is error-checking to make sure the right type of data was input. Note how the +`sheet_locked` Attribute is checked and will return if not set. -This command you import into `mygame/commands/default_cmdsets.py` and add to the `CharacterCmdSet`, in the same way the `@gm` command was added to the `AccountCmdSet` earlier. +This command you import into `mygame/commands/default_cmdsets.py` and add to the `CharacterCmdSet`, +in the same way the `@gm` command was added to the `AccountCmdSet` earlier. ### Commands for GM to change Character sheet -Game masters use basically the same input as Players do to edit a character sheet, except they can do it on other players than themselves. They are also not stopped by any `sheet_locked` flags. +Game masters use basically the same input as Players do to edit a character sheet, except they can +do it on other players than themselves. They are also not stopped by any `sheet_locked` flags. ```python # continuing in mygame/commands/command.py @@ -564,44 +661,63 @@ class CmdGMsheet(MuxCommand): caller.msg(character.db.charsheet) ``` -The `@gmsheet` command takes an additional argument to specify which Character's character sheet to edit. It also takes `/lock` and `/unlock` switches to block the Player from tweaking their sheet. +The `@gmsheet` command takes an additional argument to specify which Character's character sheet to +edit. It also takes `/lock` and `/unlock` switches to block the Player from tweaking their sheet. -Before this can be used, it should be added to the default `CharacterCmdSet` in the same way as the normal `@sheet`. Due to the lock set on it, this command will only be available to `Admins` (i.e. GMs) or higher permission levels. +Before this can be used, it should be added to the default `CharacterCmdSet` in the same way as the +normal `@sheet`. Due to the lock set on it, this command will only be available to `Admins` (i.e. +GMs) or higher permission levels. ## Dice roller -Evennia's *contrib* folder already comes with a full dice roller. To add it to the game, simply import `contrib.dice.CmdDice` into `mygame/commands/default_cmdsets.py` and add `CmdDice` to the `CharacterCmdset` as done with other commands in this tutorial. After a `@reload` you will be able to roll dice using normal RPG-style format: +Evennia's *contrib* folder already comes with a full dice roller. To add it to the game, simply +import `contrib.dice.CmdDice` into `mygame/commands/default_cmdsets.py` and add `CmdDice` to the +`CharacterCmdset` as done with other commands in this tutorial. After a `@reload` you will be able +to roll dice using normal RPG-style format: ``` roll 2d6 + 3 7 ``` -Use `help dice` to see what syntax is supported or look at `evennia/contrib/dice.py` to see how it's implemented. +Use `help dice` to see what syntax is supported or look at `evennia/contrib/dice.py` to see how it's +implemented. ## Rooms -Evennia comes with rooms out of the box, so no extra work needed. A GM will automatically have all needed building commands available. A fuller go-through is found in the [Building tutorial](./Building-Quickstart). Here are some useful highlights: +Evennia comes with rooms out of the box, so no extra work needed. A GM will automatically have all +needed building commands available. A fuller go-through is found in the [Building +tutorial](Building-Quickstart). Here are some useful highlights: -* `@dig roomname;alias = exit_there;alias, exit_back;alias` - this is the basic command for digging a new room. You can specify any exit-names and just enter the name of that exit to go there. -* `@tunnel direction = roomname` - this is a specialized command that only accepts directions in the cardinal directions (n,ne,e,se,s,sw,w,nw) as well as in/out and up/down. It also automatically builds "matching" exits back in the opposite direction. +* `@dig roomname;alias = exit_there;alias, exit_back;alias` - this is the basic command for digging +a new room. You can specify any exit-names and just enter the name of that exit to go there. +* `@tunnel direction = roomname` - this is a specialized command that only accepts directions in the +cardinal directions (n,ne,e,se,s,sw,w,nw) as well as in/out and up/down. It also automatically +builds "matching" exits back in the opposite direction. * `@create/drop objectname` - this creates and drops a new simple object in the current location. * `@desc obj` - change the look-description of the object. * `@tel object = location` - teleport an object to a named location. * `@search objectname` - locate an object in the database. -> TODO: Describe how to add a logging room, that logs says and poses to a log file that people can access after the fact. +> TODO: Describe how to add a logging room, that logs says and poses to a log file that people can +access after the fact. ## Channels -Evennia comes with [Channels](./Communications#Channels) in-built and they are described fully in the documentation. For brevity, here are the relevant commands for normal use: +Evennia comes with [Channels](./Communications#Channels) in-built and they are described fully in the +documentation. For brevity, here are the relevant commands for normal use: * `@ccreate new_channel;alias;alias = short description` - Creates a new channel. -* `addcom channel` - join an existing channel. Use `addcom alias = channel` to add a new alias you can use to talk to the channel, as many as desired. -* `delcom alias or channel` - remove an alias from a channel or, if the real channel name is given, unsubscribe completely. -* `@channels` lists all available channels, including your subscriptions and any aliases you have set up for them. +* `addcom channel` - join an existing channel. Use `addcom alias = channel` to add a new alias you +can use to talk to the channel, as many as desired. +* `delcom alias or channel` - remove an alias from a channel or, if the real channel name is given, +unsubscribe completely. +* `@channels` lists all available channels, including your subscriptions and any aliases you have +set up for them. -You can read channel history: if you for example are chatting on the `public` channel you can do `public/history` to see the 20 last posts to that channel or `public/history 32` to view twenty posts backwards, starting with the 32nd from the end. +You can read channel history: if you for example are chatting on the `public` channel you can do +`public/history` to see the 20 last posts to that channel or `public/history 32` to view twenty +posts backwards, starting with the 32nd from the end. ## PMs @@ -612,4 +728,5 @@ page recipient = message page recipient, recipient, ... = message ``` -Players can use `page` alone to see the latest messages. This also works if they were not online when the message was sent. +Players can use `page` alone to see the latest messages. This also works if they were not online +when the message was sent. diff --git a/docs/source/Execute-Python-Code.md b/docs/source/Execute-Python-Code.md index 188754ae67..0bb37928b2 100644 --- a/docs/source/Execute-Python-Code.md +++ b/docs/source/Execute-Python-Code.md @@ -1,60 +1,85 @@ # Execute Python Code -The `@py` command supplied with the default command set of Evennia allows you to execute Python commands directly from inside the game. An alias to `@py` is simply "`!`". *Access to the `@py` command should be severely restricted*. This is no joke - being able to execute arbitrary Python code on the server is not something you should entrust to just anybody. +The `@py` command supplied with the default command set of Evennia allows you to execute Python +commands directly from inside the game. An alias to `@py` is simply "`!`". *Access to the `@py` +command should be severely restricted*. This is no joke - being able to execute arbitrary Python +code on the server is not something you should entrust to just anybody. - @py 1+2 + @py 1+2 <<< 3 -## Available variables +## Available variables -A few local variables are made available when running `@py`. These offer entry into the running system. +A few local variables are made available when running `@py`. These offer entry into the running +system. - **self** / **me** - the calling object (i.e. you) - **here** - the current caller's location - **obj** - a dummy [Object](./Objects) instance - **evennia** - Evennia's [flat API](./Evennia-API) - through this you can access all of Evennia. -For accessing other objects in the same room you need to use `self.search(name)`. For objects in other locations, use one of the `evennia.search_*` methods. See [below](./Execute-Python-Code#finding-objects). +For accessing other objects in the same room you need to use `self.search(name)`. For objects in +other locations, use one of the `evennia.search_*` methods. See [below](./Execute-Python-Code#finding- +objects). ## Returning output -This is an example where we import and test one of Evennia's utilities found in `src/utils/utils.py`, but also accessible through `ev.utils`: +This is an example where we import and test one of Evennia's utilities found in +`src/utils/utils.py`, but also accessible through `ev.utils`: @py from ev import utils; utils.time_format(33333) <<< Done. -Note that we didn't get any return value, all we where told is that the code finished executing without error. This is often the case in more complex pieces of code which has no single obvious return value. To see the output from the `time_format()` function we need to tell the system to echo it to us explicitly with `self.msg()`. +Note that we didn't get any return value, all we where told is that the code finished executing +without error. This is often the case in more complex pieces of code which has no single obvious +return value. To see the output from the `time_format()` function we need to tell the system to +echo it to us explicitly with `self.msg()`. @py from ev import utils; self.msg(str(utils.time_format(33333))) 09:15 <<< Done. -> Warning: When using the `msg` function wrap our argument in `str()` to convert it into a string above. This is not strictly necessary for most types of data (Evennia will usually convert to a string behind the scenes for you). But for *lists* and *tuples* you will be confused by the output if you don't wrap them in `str()`: only the first item of the iterable will be returned. This is because doing `msg(text)` is actually just a convenience shortcut; the full argument that `msg` accepts is something called an *outputfunc* on the form `(cmdname, (args), {kwargs})` (see [the message path](./Messagepath) for more info). Sending a list/tuple confuses Evennia to think you are sending such a structure. Converting it to a string however makes it clear it should just be displayed as-is. +> Warning: When using the `msg` function wrap our argument in `str()` to convert it into a string +above. This is not strictly necessary for most types of data (Evennia will usually convert to a +string behind the scenes for you). But for *lists* and *tuples* you will be confused by the output +if you don't wrap them in `str()`: only the first item of the iterable will be returned. This is +because doing `msg(text)` is actually just a convenience shortcut; the full argument that `msg` +accepts is something called an *outputfunc* on the form `(cmdname, (args), {kwargs})` (see [the +message path](Messagepath) for more info). Sending a list/tuple confuses Evennia to think you are +sending such a structure. Converting it to a string however makes it clear it should just be +displayed as-is. -If you were to use Python's standard `print`, you will see the result in your current `stdout` (your terminal by default, otherwise your log file). +If you were to use Python's standard `print`, you will see the result in your current `stdout` (your +terminal by default, otherwise your log file). ## Finding objects -A common use for `@py` is to explore objects in the database, for debugging and performing specific operations that are not covered by a particular command. +A common use for `@py` is to explore objects in the database, for debugging and performing specific +operations that are not covered by a particular command. Locating an object is best done using `self.search()`: @py self.search("red_ball") - <<< Ball + <<< Ball @py self.search("red_ball").db.color = "red" - <<< Done. + <<< Done. @py self.search("red_ball").db.color <<< red -`self.search()` is by far the most used case, but you can also search other database tables for other Evennia entities like scripts or configuration entities. To do this you can use the generic search entries found in `ev.search_*`. +`self.search()` is by far the most used case, but you can also search other database tables for +other Evennia entities like scripts or configuration entities. To do this you can use the generic +search entries found in `ev.search_*`. @py evennia.search_script("sys_game_time") <<< [] -(Note that since this becomes a simple statement, we don't have to wrap it in `self.msg()` to get the output). You can also use the database model managers directly (accessible through the `objects` properties of database models or as `evennia.managers.*`). This is a bit more flexible since it gives you access to the full range of database search methods defined in each manager. +(Note that since this becomes a simple statement, we don't have to wrap it in `self.msg()` to get +the output). You can also use the database model managers directly (accessible through the `objects` +properties of database models or as `evennia.managers.*`). This is a bit more flexible since it +gives you access to the full range of database search methods defined in each manager. @py evennia.managers.scripts.script_search("sys_game_time") <<< [] @@ -66,15 +91,22 @@ The managers are useful for all sorts of database studies. ## Testing code outside the game -`@py` has the advantage of operating inside a running server (sharing the same process), where you can test things in real time. Much of this *can* be done from the outside too though. +`@py` has the advantage of operating inside a running server (sharing the same process), where you +can test things in real time. Much of this *can* be done from the outside too though. -In a terminal, cd to the top of your game directory (this bit is important since we need access to your config file) and run +In a terminal, cd to the top of your game directory (this bit is important since we need access to +your config file) and run evennia shell -Your default Python interpreter will start up, configured to be able to work with and import all modules of your Evennia installation. From here you can explore the database and test-run individual modules as desired. +Your default Python interpreter will start up, configured to be able to work with and import all +modules of your Evennia installation. From here you can explore the database and test-run individual +modules as desired. -It's recommended that you get a more fully featured Python interpreter like [iPython](http://ipython.scipy.org/moin/). If you use a virtual environment, you can just get it with `pip install ipython`. IPython allows you to better work over several lines, and also has a lot of other editing features, such as tab-completion and `__doc__`-string reading. +It's recommended that you get a more fully featured Python interpreter like +[iPython](http://ipython.scipy.org/moin/). If you use a virtual environment, you can just get it +with `pip install ipython`. IPython allows you to better work over several lines, and also has a lot +of other editing features, such as tab-completion and `__doc__`-string reading. $ evennia shell @@ -85,4 +117,4 @@ It's recommended that you get a more fully featured Python interpreter like [iPy In [2]: evennia.managers.objects.all() Out[3]: [, , ...] -See the page about the [Evennia-API](./Evennia-API) for more things to explore. +See the page about the [Evennia-API](./Evennia-API) for more things to explore. diff --git a/docs/source/First-Steps-Coding.md b/docs/source/First-Steps-Coding.md index d352210f30..76b1f4cf8c 100644 --- a/docs/source/First-Steps-Coding.md +++ b/docs/source/First-Steps-Coding.md @@ -1,24 +1,38 @@ # First Steps Coding -This section gives a brief step-by-step introduction on how to set up Evennia for the first time so you can modify and overload the defaults easily. You should only need to do these steps once. It also walks through you making your first few tweaks. +This section gives a brief step-by-step introduction on how to set up Evennia for the first time so +you can modify and overload the defaults easily. You should only need to do these steps once. It +also walks through you making your first few tweaks. -Before continuing, make sure you have Evennia installed and running by following the [Getting Started](./Getting-Started) instructions. You should have initialized a new game folder with the `evennia --init foldername` command. We will in the following assume this folder is called "mygame". +Before continuing, make sure you have Evennia installed and running by following the [Getting +Started](Getting-Started) instructions. You should have initialized a new game folder with the +`evennia --init foldername` command. We will in the following assume this folder is called +"mygame". -It might be a good idea to eye through the brief [Coding Introduction](./Coding-Introduction) too (especially the recommendations in the section about the evennia "flat" API and about using `evennia shell` will help you here and in the future). +It might be a good idea to eye through the brief [Coding Introduction](./Coding-Introduction) too +(especially the recommendations in the section about the evennia "flat" API and about using `evennia +shell` will help you here and in the future). -To follow this tutorial you also need to know the basics of operating your computer's terminal/command line. You also need to have a text editor to edit and create source text files. There are plenty of online tutorials on how to use the terminal and plenty of good free text editors. We will assume these things are already familiar to you henceforth. +To follow this tutorial you also need to know the basics of operating your computer's +terminal/command line. You also need to have a text editor to edit and create source text files. +There are plenty of online tutorials on how to use the terminal and plenty of good free text +editors. We will assume these things are already familiar to you henceforth. ## Your First Changes -Below are some first things to try with your new custom modules. You can test these to get a feel for the system. See also [Tutorials](./Tutorials) for more step-by-step help and special cases. +Below are some first things to try with your new custom modules. You can test these to get a feel +for the system. See also [Tutorials](./Tutorials) for more step-by-step help and special cases. ### Tweak Default Character -We will add some simple rpg attributes to our default Character. In the next section we will follow up with a new command to view those attributes. +We will add some simple rpg attributes to our default Character. In the next section we will follow +up with a new command to view those attributes. -1. Edit `mygame/typeclasses/characters.py` and modify the `Character` class. The `at_object_creation` method also exists on the `DefaultCharacter` parent and will overload it. The `get_abilities` method is unique to our version of `Character`. +1. Edit `mygame/typeclasses/characters.py` and modify the `Character` class. The +`at_object_creation` method also exists on the `DefaultCharacter` parent and will overload it. The +`get_abilities` method is unique to our version of `Character`. ```python class Character(DefaultCharacter): @@ -43,11 +57,18 @@ We will add some simple rpg attributes to our default Character. In the next sec return self.db.strength, self.db.agility, self.db.magic ``` -1. [Reload](./Start-Stop-Reload) the server (you will still be connected to the game after doing this). Note that if you examine *yourself* you will *not* see any new Attributes appear yet. Read the next section to understand why. +1. [Reload](./Start-Stop-Reload) the server (you will still be connected to the game after doing +this). Note that if you examine *yourself* you will *not* see any new Attributes appear yet. Read +the next section to understand why. #### Updating Yourself -It's important to note that the new [Attributes](./Attributes) we added above will only be stored on *newly* created characters. The reason for this is simple: The `at_object_creation` method, where we added those Attributes, is per definition only called when the object is *first created*, then never again. This is usually a good thing since those Attributes may change over time - calling that hook would reset them back to start values. But it also means that your existing character doesn't have them yet. You can see this by calling the `get_abilities` hook on yourself at this point: +It's important to note that the new [Attributes](./Attributes) we added above will only be stored on +*newly* created characters. The reason for this is simple: The `at_object_creation` method, where we +added those Attributes, is per definition only called when the object is *first created*, then never +again. This is usually a good thing since those Attributes may change over time - calling that hook +would reset them back to start values. But it also means that your existing character doesn't have +them yet. You can see this by calling the `get_abilities` hook on yourself at this point: ``` # (you have to be superuser to use @py) @@ -61,14 +82,19 @@ This is easily remedied. @update self ``` -This will (only) re-run `at_object_creation` on yourself. You should henceforth be able to get the abilities successfully: +This will (only) re-run `at_object_creation` on yourself. You should henceforth be able to get the +abilities successfully: ``` @py self.get_abilities() <<< (5, 4, 2) ``` -This is something to keep in mind if you start building your world before your code is stable - startup-hooks will not (and should not) automatically run on *existing* objects - you have to update your existing objects manually. Luckily this is a one-time thing and pretty simple to do. If the typeclass you want to update is in `typeclasses.myclass.MyClass`, you can do the following (e.g. from `evennia shell`): +This is something to keep in mind if you start building your world before your code is stable - +startup-hooks will not (and should not) automatically run on *existing* objects - you have to update +your existing objects manually. Luckily this is a one-time thing and pretty simple to do. If the +typeclass you want to update is in `typeclasses.myclass.MyClass`, you can do the following (e.g. +from `evennia shell`): ```python from typeclasses.myclass import MyClass @@ -78,17 +104,25 @@ for obj in MyClass.objects.all(): obj.swap_typeclass(MyClass, run_start_hooks="at_object_creation") ``` -Using `swap_typeclass` to the same typeclass we already have will re-run the creation hooks (this is what the `@update` command does under the hood). From in-game you can do the same with `@py`: +Using `swap_typeclass` to the same typeclass we already have will re-run the creation hooks (this is +what the `@update` command does under the hood). From in-game you can do the same with `@py`: ``` -@py typeclasses.myclass import MyClass;[obj.swap_typeclass(MyClass) for obj in MyClass.objects.all()] +@py typeclasses.myclass import MyClass;[obj.swap_typeclass(MyClass) for obj in +MyClass.objects.all()] ``` -See the [Object Typeclass tutorial](./Adding-Object-Typeclass-Tutorial) for more help and the [Typeclasses](./Typeclasses) and [Attributes](./Attributes) page for detailed documentation about Typeclasses and Attributes. +See the [Object Typeclass tutorial](./Adding-Object-Typeclass-Tutorial) for more help and the +[Typeclasses](./Typeclasses) and [Attributes](./Attributes) page for detailed documentation about +Typeclasses and Attributes. #### Troubleshooting: Updating Yourself -One may experience errors for a number of reasons. Common beginner errors are spelling mistakes, wrong indentations or code omissions leading to a `SyntaxError`. Let's say you leave out a colon from the end of a class function like so: ```def at_object_creation(self)```. The client will reload without issue. *However*, if you look at the terminal/console (i.e. not in-game), you will see Evennia complaining (this is called a *traceback*): +One may experience errors for a number of reasons. Common beginner errors are spelling mistakes, +wrong indentations or code omissions leading to a `SyntaxError`. Let's say you leave out a colon +from the end of a class function like so: ```def at_object_creation(self)```. The client will reload +without issue. *However*, if you look at the terminal/console (i.e. not in-game), you will see +Evennia complaining (this is called a *traceback*): ``` Traceback (most recent call last): @@ -98,21 +132,39 @@ File "C:\mygame\typeclasses\characters.py", line 33 SyntaxError: invalid syntax ``` -Evennia will still be restarting and following the tutorial, doing `@py self.get_abilities()` will return the right response `(None, None, None)`. But when attempting to `@typeclass/force self` you will get this response: +Evennia will still be restarting and following the tutorial, doing `@py self.get_abilities()` will +return the right response `(None, None, None)`. But when attempting to `@typeclass/force self` you +will get this response: ```python AttributeError: 'DefaultObject' object has no attribute 'get_abilities' ``` -The full error will show in the terminal/console but this is confusing since you did add `get_abilities` before. Note however what the error says - you (`self`) should be a `Character` but the error talks about `DefaultObject`. What has happened is that due to your unhandled `SyntaxError` earlier, Evennia could not load the `character.py` module at all (it's not valid Python). Rather than crashing, Evennia handles this by temporarily falling back to a safe default - `DefaultObject` - in order to keep your MUD running. Fix the original `SyntaxError` and reload the server. Evennia will then be able to use your modified `Character` class again and things should work. +The full error will show in the terminal/console but this is confusing since you did add +`get_abilities` before. Note however what the error says - you (`self`) should be a `Character` but +the error talks about `DefaultObject`. What has happened is that due to your unhandled `SyntaxError` +earlier, Evennia could not load the `character.py` module at all (it's not valid Python). Rather +than crashing, Evennia handles this by temporarily falling back to a safe default - `DefaultObject` +- in order to keep your MUD running. Fix the original `SyntaxError` and reload the server. Evennia +will then be able to use your modified `Character` class again and things should work. -> Note: Learning how to interpret an error traceback is a critical skill for anyone learning Python. Full tracebacks will appear in the terminal/Console you started Evennia from. The traceback text can sometimes be quite long, but you are usually just looking for the last few lines: The description of the error and the filename + line number for where the error occurred. In the example above, we see it's a `SyntaxError` happening at `line 33` of `mygame\typeclasses\characters.py`. In this case it even points out *where* on the line it encountered the error (the missing colon). Learn to read tracebacks and you'll be able to resolve the vast majority of common errors easily. +> Note: Learning how to interpret an error traceback is a critical skill for anyone learning Python. +Full tracebacks will appear in the terminal/Console you started Evennia from. The traceback text can +sometimes be quite long, but you are usually just looking for the last few lines: The description of +the error and the filename + line number for where the error occurred. In the example above, we see +it's a `SyntaxError` happening at `line 33` of `mygame\typeclasses\characters.py`. In this case it +even points out *where* on the line it encountered the error (the missing colon). Learn to read +tracebacks and you'll be able to resolve the vast majority of common errors easily. ### Add a New Default Command -The `@py` command used above is only available to privileged users. We want any player to be able to see their stats. Let's add a new [command](./Commands) to list the abilities we added in the previous section. +The `@py` command used above is only available to privileged users. We want any player to be able to +see their stats. Let's add a new [command](./Commands) to list the abilities we added in the previous +section. -1. Open `mygame/commands/command.py`. You could in principle put your command anywhere but this module has all the imports already set up along with some useful documentation. Make a new class at the bottom of this file: +1. Open `mygame/commands/command.py`. You could in principle put your command anywhere but this +module has all the imports already set up along with some useful documentation. Make a new class at +the bottom of this file: ```python class CmdAbilities(Command): @@ -151,18 +203,21 @@ The `@py` command used above is only available to privileged users. We want any 1. [Reload](./Start-Stop-Reload) the server (noone will be disconnected by doing this). -You (and anyone else) should now be able to use `abilities` (or its alias `abi`) as part of your normal commands in-game: +You (and anyone else) should now be able to use `abilities` (or its alias `abi`) as part of your +normal commands in-game: ``` abilities STR: 5, AGI: 4, MAG: 2 ``` -See the [Adding a Command tutorial](./Adding-Command-Tutorial) for more examples and the [Commands](./Commands) section for detailed documentation about the Command system. +See the [Adding a Command tutorial](./Adding-Command-Tutorial) for more examples and the +[Commands](./Commands) section for detailed documentation about the Command system. ### Make a New Type of Object -Let's test to make a new type of object. This example is an "wise stone" object that returns some random comment when you look at it, like this: +Let's test to make a new type of object. This example is an "wise stone" object that returns some +random comment when you look at it, like this: > look stone @@ -172,8 +227,10 @@ Let's test to make a new type of object. This example is an "wise stone" object It grumbles and says: 'The world is like a rock of chocolate.' 1. Create a new module in `mygame/typeclasses/`. Name it `wiseobject.py` for this example. -1. In the module import the base `Object` (`typeclasses.objects.Object`). This is empty by default, meaning it is just a proxy for the default `evennia.DefaultObject`. -1. Make a new class in your module inheriting from `Object`. Overload hooks on it to add new functionality. Here is an example of how the file could look: +1. In the module import the base `Object` (`typeclasses.objects.Object`). This is empty by default, +meaning it is just a proxy for the default `evennia.DefaultObject`. +1. Make a new class in your module inheriting from `Object`. Overload hooks on it to add new +functionality. Here is an example of how the file could look: ```python from random import choice @@ -204,14 +261,32 @@ Let's test to make a new type of object. This example is an "wise stone" object return string + wisewords ``` -1. Check your code for bugs. Tracebacks will appear on your command line or log. If you have a grave Syntax Error in your code, the source file itself will fail to load which can cause issues with the entire cmdset. If so, fix your bug and [reload the server from the command line](./Start-Stop-Reload) (noone will be disconnected by doing this). -1. Use `@create/drop stone:wiseobject.WiseObject` to create a talkative stone. If the `@create` command spits out a warning or cannot find the typeclass (it will tell you which paths it searched), re-check your code for bugs and that you gave the correct path. The `@create` command starts looking for Typeclasses in `mygame/typeclasses/`. -1. Use `look stone` to test. You will see the default description ("You see nothing special") followed by a random message of stony wisdom. Use `@desc stone = This is a wise old stone.` to make it look nicer. See the [Builder Docs](./Builder-Docs) for more information. +1. Check your code for bugs. Tracebacks will appear on your command line or log. If you have a grave +Syntax Error in your code, the source file itself will fail to load which can cause issues with the +entire cmdset. If so, fix your bug and [reload the server from the command line](./Start-Stop-Reload) +(noone will be disconnected by doing this). +1. Use `@create/drop stone:wiseobject.WiseObject` to create a talkative stone. If the `@create` +command spits out a warning or cannot find the typeclass (it will tell you which paths it searched), +re-check your code for bugs and that you gave the correct path. The `@create` command starts looking +for Typeclasses in `mygame/typeclasses/`. +1. Use `look stone` to test. You will see the default description ("You see nothing special") +followed by a random message of stony wisdom. Use `@desc stone = This is a wise old stone.` to make +it look nicer. See the [Builder Docs](./Builder-Docs) for more information. -Note that `at_object_creation` is only called once, when the stone is first created. If you make changes to this method later, already existing stones will not see those changes. As with the `Character` example above you can use `@typeclass/force` to tell the stone to re-run its initialization. +Note that `at_object_creation` is only called once, when the stone is first created. If you make +changes to this method later, already existing stones will not see those changes. As with the +`Character` example above you can use `@typeclass/force` to tell the stone to re-run its +initialization. -The `at_object_creation` is a special case though. Changing most other aspects of the typeclass does *not* require manual updating like this - you just need to `@reload` to have all changes applied automatically to all existing objects. +The `at_object_creation` is a special case though. Changing most other aspects of the typeclass does +*not* require manual updating like this - you just need to `@reload` to have all changes applied +automatically to all existing objects. ## Where to Go From Here? -There are more [Tutorials](./Tutorials), including one for building a [whole little MUSH-like game](./Tutorial-for-basic-MUSH-like-game) - that is instructive also if you have no interest in MUSHes per se. A good idea is to also get onto the [IRC chat](http://webchat.freenode.net/?channels=evennia) and the [mailing list](https://groups.google.com/forum/#!forum/evennia) to get in touch with the community and other developers. +There are more [Tutorials](./Tutorials), including one for building a [whole little MUSH-like +game](Tutorial-for-basic-MUSH-like-game) - that is instructive also if you have no interest in +MUSHes per se. A good idea is to also get onto the [IRC +chat](http://webchat.freenode.net/?channels=evennia) and the [mailing +list](https://groups.google.com/forum/#!forum/evennia) to get in touch with the community and other +developers. diff --git a/docs/source/Game-Planning.md b/docs/source/Game-Planning.md index a7953c932e..f272d978f9 100644 --- a/docs/source/Game-Planning.md +++ b/docs/source/Game-Planning.md @@ -1,29 +1,58 @@ # Game Planning -So you have Evennia up and running. You have a great game idea in mind. Now it's time to start cracking! But where to start? Here are some ideas for a workflow. Note that the suggestions on this page are just that - suggestions. Also, they are primarily aimed at a lone hobby designer or a small team developing a game in their free time. There is an article in the Imaginary Realities e-zine which was written by the Evennia lead dev. It focuses more on you finding out your motivations for making a game - you can [read the article here](http://journal.imaginary-realities.com/volume-07/issue-03/where-do-i-begin/index.html). +So you have Evennia up and running. You have a great game idea in mind. Now it's time to start +cracking! But where to start? Here are some ideas for a workflow. Note that the suggestions on this +page are just that - suggestions. Also, they are primarily aimed at a lone hobby designer or a small +team developing a game in their free time. There is an article in the Imaginary Realities e-zine +which was written by the Evennia lead dev. It focuses more on you finding out your motivations for +making a game - you can [read the article here](http://journal.imaginary- +realities.com/volume-07/issue-03/where-do-i-begin/index.html). -Below are some minimal steps for getting the first version of a new game world going with players. It's worth to at least make the attempt to do these steps in order even if you are itching to jump ahead in the development cycle. On the other hand, you should also make sure to keep your work fun for you, or motivation will falter. Making a full game is a lot of work as it is, you'll need all your motivation to make it a reality. +Below are some minimal steps for getting the first version of a new game world going with players. +It's worth to at least make the attempt to do these steps in order even if you are itching to jump +ahead in the development cycle. On the other hand, you should also make sure to keep your work fun +for you, or motivation will falter. Making a full game is a lot of work as it is, you'll need all +your motivation to make it a reality. -Remember that *99.99999% of all great game ideas never lead to a game*. Especially not to an online game that people can actually play and enjoy. So our first all overshadowing goal is to beat those odds and get *something* out the door! Even if it's a scaled-down version of your dream game, lacking many "must-have" features! It's better to get it out there and expand on it later than to code in isolation forever until you burn out, lose interest or your hard drive crashes. +Remember that *99.99999% of all great game ideas never lead to a game*. Especially not to an online +game that people can actually play and enjoy. So our first all overshadowing goal is to beat those +odds and get *something* out the door! Even if it's a scaled-down version of your dream game, +lacking many "must-have" features! It's better to get it out there and expand on it later than to +code in isolation forever until you burn out, lose interest or your hard drive crashes. -Like is common with online games, getting a game out the door does not mean you are going to be "finished" with the game - most MUDs add features gradually over the course of years - it's often part of the fun! +Like is common with online games, getting a game out the door does not mean you are going to be +"finished" with the game - most MUDs add features gradually over the course of years - it's often +part of the fun! ## Planning (step 1) -This is what you do before having coded a single line or built a single room. Many prospective game developers are very good at *parts* of this process, namely in defining what their world is "about": The theme, the world concept, cool monsters and so on. It is by all means very important to define what is the unique appeal of your game. But it's unfortunately not enough to make your game a reality. To do that you must also have an idea of how to actually map those great ideas onto Evennia. +This is what you do before having coded a single line or built a single room. Many prospective game +developers are very good at *parts* of this process, namely in defining what their world is "about": +The theme, the world concept, cool monsters and so on. It is by all means very important to define +what is the unique appeal of your game. But it's unfortunately not enough to make your game a +reality. To do that you must also have an idea of how to actually map those great ideas onto +Evennia. -A good start is to begin by planning out the basic primitives of the game and what they need to be able to do. Below are a far-from-complete list of examples (and for your first version you should definitely try for a much shorter list): +A good start is to begin by planning out the basic primitives of the game and what they need to be +able to do. Below are a far-from-complete list of examples (and for your first version you should +definitely try for a much shorter list): -### Systems +### Systems -These are the behind-the-scenes features that exist in your game, often without being represented by a specific in-game object. +These are the behind-the-scenes features that exist in your game, often without being represented by +a specific in-game object. -- Should your game rules be enforced by coded systems or are you planning for human game masters to run and arbitrate rules? -- What are the actual mechanical game rules? How do you decide if an action succeeds or fails? What "rolls" does the game need to be able to do? Do you base your game off an existing system or make up your own? -- Does the flow of time matter in your game - does night and day change? What about seasons? Maybe your magic system is affected by the phase of the moon? -- Do you want changing, global weather? This might need to operate in tandem over a large number of rooms. +- Should your game rules be enforced by coded systems or are you planning for human game masters to +run and arbitrate rules? +- What are the actual mechanical game rules? How do you decide if an action succeeds or fails? What +"rolls" does the game need to be able to do? Do you base your game off an existing system or make up +your own? +- Does the flow of time matter in your game - does night and day change? What about seasons? Maybe +your magic system is affected by the phase of the moon? +- Do you want changing, global weather? This might need to operate in tandem over a large number of +rooms. - Do you want a game-wide economy or just a simple barter system? Or no formal economy at all? - Should characters be able to send mail to each other in-game? - Should players be able to post on Bulletin boards? @@ -31,12 +60,15 @@ These are the behind-the-scenes features that exist in your game, often without - What should a Builder be able to build and what commands do they need in order to do that? - etc. -### Rooms +### Rooms Consider the most basic room in your game. - - Is a simple description enough or should the description be able to change (such as with time, by light conditions, weather or season)? - - Should the room have different statuses? Can it have smells, sounds? Can it be affected by dramatic weather, fire or magical effects? If so, how would this affect things in the room? Or are these things something admins/game masters should handle manually? + - Is a simple description enough or should the description be able to change (such as with time, by +light conditions, weather or season)? + - Should the room have different statuses? Can it have smells, sounds? Can it be affected by +dramatic weather, fire or magical effects? If so, how would this affect things in the room? Or are +these things something admins/game masters should handle manually? - Can objects be hidden in the room? Can a person hide in the room? How does the room display this? - etc. @@ -44,15 +76,22 @@ Consider the most basic room in your game. Consider the most basic (non-player-controlled) object in your game. -- How numerous are your objects? Do you want large loot-lists or are objects just role playing props created on demand? -- Does the game use money? If so, is each coin a separate object or do you just store a bank account value? -- What about multiple identical objects? Do they form stacks and how are those stacks handled in that case? +- How numerous are your objects? Do you want large loot-lists or are objects just role playing props +created on demand? +- Does the game use money? If so, is each coin a separate object or do you just store a bank account +value? +- What about multiple identical objects? Do they form stacks and how are those stacks handled in +that case? - Does an object have weight or volume (so you cannot carry an infinite amount of them)? -- Can objects be broken? If so, does it have a health value? Is burning it causing the same damage as smashing it? Can it be repaired? -- Is a weapon a specific type of object or are you supposed to be able to fight with a chair too? Can you fight with a flower or piece of paper as well? +- Can objects be broken? If so, does it have a health value? Is burning it causing the same damage +as smashing it? Can it be repaired? +- Is a weapon a specific type of object or are you supposed to be able to fight with a chair too? +Can you fight with a flower or piece of paper as well? - NPCs/mobs are also objects. Should they just stand around or should they have some sort of AI? -- Are NPCs/mobs differet entities? How is an Orc different from a Kobold, in code - are they the same object with different names or completely different types of objects, with custom code? -- Should there be NPCs giving quests? If so, how would you track quest status and what happens when multiple players try to do the same quest? Do you use instances or some other mechanism? +- Are NPCs/mobs differet entities? How is an Orc different from a Kobold, in code - are they the +same object with different names or completely different types of objects, with custom code? +- Should there be NPCs giving quests? If so, how would you track quest status and what happens when +multiple players try to do the same quest? Do you use instances or some other mechanism? - etc. ### Characters @@ -60,54 +99,120 @@ Consider the most basic (non-player-controlled) object in your game. These are the objects controlled directly by Players. - Can players have more than one Character active at a time or are they allowed to multi-play? -- How does a Player create their Character? A Character-creation screen? Answering questions? Filling in a form? +- How does a Player create their Character? A Character-creation screen? Answering questions? +Filling in a form? - Do you want to use classes (like "Thief", "Warrior" etc) or some other system, like Skill-based? -- How do you implement different "classes" or "races"? Are they separate types of objects or do you simply load different stats on a basic object depending on what the Player wants? +- How do you implement different "classes" or "races"? Are they separate types of objects or do you +simply load different stats on a basic object depending on what the Player wants? - If a Character can hide in a room, what skill will decide if they are detected? -- What skill allows a Character to wield a weapon and hit? Do they need a special skill to wield a chair rather than a sword? -- Does a Character need a Strength attribute to tell how much they can carry or which objects they can smash? -- What does the skill tree look like? Can a Character gain experience to improve? By killing enemies? Solving quests? By roleplaying? +- What skill allows a Character to wield a weapon and hit? Do they need a special skill to wield a +chair rather than a sword? +- Does a Character need a Strength attribute to tell how much they can carry or which objects they +can smash? +- What does the skill tree look like? Can a Character gain experience to improve? By killing +enemies? Solving quests? By roleplaying? - etc. -A MUD's a lot more involved than you would think and these things hang together in a complex web. It can easily become overwhelming and it's tempting to want *all* functionality right out of the door. Try to identify the basic things that "make" your game and focus *only* on them for your first release. Make a list. Keep future expansions in mind but limit yourself. +A MUD's a lot more involved than you would think and these things hang together in a complex web. It +can easily become overwhelming and it's tempting to want *all* functionality right out of the door. +Try to identify the basic things that "make" your game and focus *only* on them for your first +release. Make a list. Keep future expansions in mind but limit yourself. ## Coding (step 2) -This is the actual work of creating the "game" part of your game. Many "game-designer" types tend to gloss over this bit and jump directly to **World Building**. Vice versa, many "game-coder" types tend to jump directly to this part without doing the **Planning** first. Neither way is good and *will* lead to you having to redo all your hard work at least once, probably more. +This is the actual work of creating the "game" part of your game. Many "game-designer" types tend to +gloss over this bit and jump directly to **World Building**. Vice versa, many "game-coder" types +tend to jump directly to this part without doing the **Planning** first. Neither way is good and +*will* lead to you having to redo all your hard work at least once, probably more. -Evennia's [Developer Central](./Developer-Central) tries to help you with this bit of development. We also have a slew of [Tutorials](./Tutorials) with worked examples. Evennia tries hard to make this part easier for you, but there is no way around the fact that if you want anything but a very basic Talker-type game you *will* have to bite the bullet and code your game (or find a coder willing to do it for you). +Evennia's [Developer Central](./Developer-Central) tries to help you with this bit of development. We +also have a slew of [Tutorials](./Tutorials) with worked examples. Evennia tries hard to make this +part easier for you, but there is no way around the fact that if you want anything but a very basic +Talker-type game you *will* have to bite the bullet and code your game (or find a coder willing to +do it for you). -Even if you won't code anything yourself, as a designer you need to at least understand the basic paradigms of Evennia, such as [Objects](./Objects), [Commands](./Commands) and [Scripts](./Scripts) and how they hang together. We recommend you go through the [Tutorial World](./Tutorial-World-Introduction) in detail (as well as glancing at its code) to get at least a feel for what is involved behind the scenes. You could also look through the tutorial for [building a game from scratch](./Tutorial-for-basic-MUSH-like-game). +Even if you won't code anything yourself, as a designer you need to at least understand the basic +paradigms of Evennia, such as [Objects](./Objects), [Commands](./Commands) and [Scripts](./Scripts) and +how they hang together. We recommend you go through the [Tutorial World](Tutorial-World- +Introduction) in detail (as well as glancing at its code) to get at least a feel for what is +involved behind the scenes. You could also look through the tutorial for [building a game from +scratch](Tutorial-for-basic-MUSH-like-game). -During Coding you look back at the things you wanted during the **Planning** phase and try to implement them. Don't be shy to update your plans if you find things easier/harder than you thought. The earlier you revise problems, the easier they will be to fix. +During Coding you look back at the things you wanted during the **Planning** phase and try to +implement them. Don't be shy to update your plans if you find things easier/harder than you thought. +The earlier you revise problems, the easier they will be to fix. -A good idea is to host your code online (publicly or privately) using version control. Not only will this make it easy for multiple coders to collaborate (and have a bug-tracker etc), it also means your work is backed up at all times. The [Version Control](./Version-Control) tutorial has instructions for setting up a sane developer environment with proper version control. +A good idea is to host your code online (publicly or privately) using version control. Not only will +this make it easy for multiple coders to collaborate (and have a bug-tracker etc), it also means +your work is backed up at all times. The [Version Control](./Version-Control) tutorial has +instructions for setting up a sane developer environment with proper version control. ### "Tech Demo" Building -This is an integral part of your Coding. It might seem obvious to experienced coders, but it cannot be emphasized enough that you should *test things on a small scale* before putting your untested code into a large game-world. The earlier you test, the easier and cheaper it will be to fix bugs and even rework things that didn't work out the way you thought they would. You might even have to go back to the **Planning** phase if your ideas can't handle their meet with reality. +This is an integral part of your Coding. It might seem obvious to experienced coders, but it cannot +be emphasized enough that you should *test things on a small scale* before putting your untested +code into a large game-world. The earlier you test, the easier and cheaper it will be to fix bugs +and even rework things that didn't work out the way you thought they would. You might even have to +go back to the **Planning** phase if your ideas can't handle their meet with reality. -This means building singular in-game examples. Make one room and one object of each important type and test so they work correctly in isolation. Then add more if they are supposed to interact with each other in some way. Build a small series of rooms to test how mobs move around ... and so on. In short, a test-bed for your growing code. It should be done gradually until you have a fully functioning (if not guaranteed bug-free) miniature tech demo that shows *all* the features you want in the first release of your game. There does not need to be any game play or even a theme to your tests, this is only for you and your co-coders to see. The more testing you do on this small scale, the less headaches you will have in the next phase. +This means building singular in-game examples. Make one room and one object of each important type +and test so they work correctly in isolation. Then add more if they are supposed to interact with +each other in some way. Build a small series of rooms to test how mobs move around ... and so on. In +short, a test-bed for your growing code. It should be done gradually until you have a fully +functioning (if not guaranteed bug-free) miniature tech demo that shows *all* the features you want +in the first release of your game. There does not need to be any game play or even a theme to your +tests, this is only for you and your co-coders to see. The more testing you do on this small scale, +the less headaches you will have in the next phase. -## World Building (step 3) +## World Building (step 3) -Up until this point we've only had a few tech-demo objects in the database. This step is the act of populating the database with a larger, thematic world. Too many would-be developers jump to this stage too soon (skipping the **Coding** or even **Planning** stages). What if the rooms you build now doesn't include all the nice weather messages the code grows to support? Or the way you store data changes under the hood? Your building work would at best require some rework and at worst you would have to redo the whole thing. And whereas Evennia's typeclass system does allow you to edit the properties of existing objects, some hooks are only called at object creation ... Suffice to say you are in for a *lot* of unnecessary work if you build stuff en masse without having the underlying code systems in some reasonable shape first. +Up until this point we've only had a few tech-demo objects in the database. This step is the act of +populating the database with a larger, thematic world. Too many would-be developers jump to this +stage too soon (skipping the **Coding** or even **Planning** stages). What if the rooms you build +now doesn't include all the nice weather messages the code grows to support? Or the way you store +data changes under the hood? Your building work would at best require some rework and at worst you +would have to redo the whole thing. And whereas Evennia's typeclass system does allow you to edit +the properties of existing objects, some hooks are only called at object creation ... Suffice to +say you are in for a *lot* of unnecessary work if you build stuff en masse without having the +underlying code systems in some reasonable shape first. -So before starting to build, the "game" bit (**Coding** + **Testing**) should be more or less **complete**, *at least to the level of your initial release*. +So before starting to build, the "game" bit (**Coding** + **Testing**) should be more or less +**complete**, *at least to the level of your initial release*. -Before starting to build, you should also plan ahead again. Make sure it is clear to yourself and your eventual builders just which parts of the world you want for your initial release. Establish for everyone which style, quality and level of detail you expect. Your goal should *not* be to complete your entire world in one go. You want just enough to make the game's "feel" come across. You want a minimal but functioning world where the intended game play can be tested and roughly balanced. You can always add new areas later. +Before starting to build, you should also plan ahead again. Make sure it is clear to yourself and +your eventual builders just which parts of the world you want for your initial release. Establish +for everyone which style, quality and level of detail you expect. Your goal should *not* be to +complete your entire world in one go. You want just enough to make the game's "feel" come across. +You want a minimal but functioning world where the intended game play can be tested and roughly +balanced. You can always add new areas later. -During building you get free and extensive testing of whatever custom build commands and systems you have made at this point. Since Building often involves different people than those Coding, you also get a chance to hear if some things are hard to understand or non-intuitive. Make sure to respond to this feedback. +During building you get free and extensive testing of whatever custom build commands and systems you +have made at this point. Since Building often involves different people than those Coding, you also +get a chance to hear if some things are hard to understand or non-intuitive. Make sure to respond +to this feedback. ## Alpha Release -As mentioned, don't hold onto your world more than necessary. *Get it out there* with a huge *Alpha* flag and let people try it! Call upon your alpha-players to try everything - they *will* find ways to break your game in ways that you never could have imagined. In Alpha you might be best off to focus on inviting friends and maybe other MUD developers, people who you can pester to give proper feedback and bug reports (there *will* be bugs, there is no way around it). Follow the quick instructions for [Online Setup](./Online-Setup) to make your game visible online. If you hadn't already, make sure to put up your game on the [Evennia game index](http://games.evennia.com/) so people know it's in the works (actually, even pre-alpha games are allowed in the index so don't be shy)! +As mentioned, don't hold onto your world more than necessary. *Get it out there* with a huge *Alpha* +flag and let people try it! Call upon your alpha-players to try everything - they *will* find ways +to break your game in ways that you never could have imagined. In Alpha you might be best off to +focus on inviting friends and maybe other MUD developers, people who you can pester to give proper +feedback and bug reports (there *will* be bugs, there is no way around it). Follow the quick +instructions for [Online Setup](./Online-Setup) to make your game visible online. If you hadn't +already, make sure to put up your game on the [Evennia game index](http://games.evennia.com/) so +people know it's in the works (actually, even pre-alpha games are allowed in the index so don't be +shy)! ## Beta Release/Perpetual Beta -Once things stabilize in Alpha you can move to *Beta* and let more people in. Many MUDs are in [perpetual beta](http://en.wikipedia.org/wiki/Perpetual_beta), meaning they are never considered "finished", but just repeat the cycle of Planning, Coding, Testing and Building over and over as new features get implemented or Players come with suggestions. As the game designer it is now up to you to gradually perfect your vision. +Once things stabilize in Alpha you can move to *Beta* and let more people in. Many MUDs are in +[perpetual beta](http://en.wikipedia.org/wiki/Perpetual_beta), meaning they are never considered +"finished", but just repeat the cycle of Planning, Coding, Testing and Building over and over as new +features get implemented or Players come with suggestions. As the game designer it is now up to you +to gradually perfect your vision. -## Congratulate yourself! +## Congratulate yourself! -You are worthy of a celebration since at this point you have joined the small, exclusive crowd who have made their dream game a reality! +You are worthy of a celebration since at this point you have joined the small, exclusive crowd who +have made their dream game a reality! diff --git a/docs/source/Gametime-Tutorial.md b/docs/source/Gametime-Tutorial.md index 3de44d3aa5..9aa76110b6 100644 --- a/docs/source/Gametime-Tutorial.md +++ b/docs/source/Gametime-Tutorial.md @@ -1,20 +1,30 @@ # Gametime Tutorial -A lot of games use a separate time system we refer to as *game time*. This runs in parallel to what we usually think of as *real time*. The game time might run at a different speed, use different names for its time units or might even use a completely custom calendar. You don't need to rely on a game time system at all. But if you do, Evennia offers basic tools to handle these various situations. This tutorial will walk you through these features. +A lot of games use a separate time system we refer to as *game time*. This runs in parallel to what +we usually think of as *real time*. The game time might run at a different speed, use different +names for its time units or might even use a completely custom calendar. You don't need to rely on a +game time system at all. But if you do, Evennia offers basic tools to handle these various +situations. This tutorial will walk you through these features. ### A game time with a standard calendar -Many games let their in-game time run faster or slower than real time, but still use our normal real-world calendar. This is common both for games set in present day as well as for games in historical or futuristic settings. Using a standard calendar has some advantages: +Many games let their in-game time run faster or slower than real time, but still use our normal +real-world calendar. This is common both for games set in present day as well as for games in +historical or futuristic settings. Using a standard calendar has some advantages: -- Handling repetitive actions is much easier, since converting from the real time experience to the in-game perceived one is easy. -- The intricacies of the real world calendar, with leap years and months of different length etc are automatically handled by the system. +- Handling repetitive actions is much easier, since converting from the real time experience to the +in-game perceived one is easy. +- The intricacies of the real world calendar, with leap years and months of different length etc are +automatically handled by the system. -Evennia's game time features assume a standard calendar (see the relevant section below for a custom calendar). +Evennia's game time features assume a standard calendar (see the relevant section below for a custom +calendar). #### Setting up game time for a standard calendar -All is done through the settings. Here are the settings you should use if you want a game time with a standard calendar: +All is done through the settings. Here are the settings you should use if you want a game time with +a standard calendar: ```python # in a file settings.py in mygame/server/conf @@ -29,9 +39,16 @@ TIME_FACTOR = 2.0 TIME_GAME_EPOCH = None ``` -By default, the game time runs twice as fast as the real time. You can set the time factor to be 1 (the game time would run exactly at the same speed than the real time) or lower (the game time will be slower than the real time). Most games choose to have the game time spinning faster (you will find some games that have a time factor of 60, meaning the game time runs sixty times as fast as the real time, a minute in real time would be an hour in game time). +By default, the game time runs twice as fast as the real time. You can set the time factor to be 1 +(the game time would run exactly at the same speed than the real time) or lower (the game time will +be slower than the real time). Most games choose to have the game time spinning faster (you will +find some games that have a time factor of 60, meaning the game time runs sixty times as fast as the +real time, a minute in real time would be an hour in game time). -The epoch is a slightly more complex setting. It should contain a number of seconds that would indicate the time your game started. As indicated, an epoch of 0 would mean January 1st, 1970. If you want to set your time in the future, you just need to find the starting point in seconds. There are several ways to do this in Python, this method will show you how to do it in local time: +The epoch is a slightly more complex setting. It should contain a number of seconds that would +indicate the time your game started. As indicated, an epoch of 0 would mean January 1st, 1970. If +you want to set your time in the future, you just need to find the starting point in seconds. There +are several ways to do this in Python, this method will show you how to do it in local time: ```python # We're looking for the number of seconds representing @@ -42,14 +59,16 @@ start = datetime(2020, 1, 1) time.mktime(start.timetuple()) ``` -This should return a huge number - the number of seconds since Jan 1 1970. Copy that directly into your settings (editing `server/conf/settings.py`): +This should return a huge number - the number of seconds since Jan 1 1970. Copy that directly into +your settings (editing `server/conf/settings.py`): ```python # in a file settings.py in mygame/server/conf TIME_GAME_EPOCH = 1577865600 ``` -Reload the game with `@reload`, and then use the `@time` command. You should see something like this: +Reload the game with `@reload`, and then use the `@time` command. You should see something like +this: ``` +----------------------------+-------------------------------------+ @@ -68,26 +87,35 @@ Reload the game with `@reload`, and then use the `@time` command. You should se +----------------------------+-------------------------------------+ ``` -The line that is most relevant here is the game time epoch. You see it shown at 2020-01-01. From this point forward, the game time keeps increasing. If you keep typing `@time`, you'll see the game time updated correctly... and going (by default) twice as fast as the real time. +The line that is most relevant here is the game time epoch. You see it shown at 2020-01-01. From +this point forward, the game time keeps increasing. If you keep typing `@time`, you'll see the game +time updated correctly... and going (by default) twice as fast as the real time. #### Time-related events -The `gametime` utility also has a way to schedule game-related events, taking into account your game time, and assuming a standard calendar (see below for the same feature with a custom calendar). For instance, it can be used to have a specific message every (in-game) day at 6:00 AM showing how the sun rises. +The `gametime` utility also has a way to schedule game-related events, taking into account your game +time, and assuming a standard calendar (see below for the same feature with a custom calendar). For +instance, it can be used to have a specific message every (in-game) day at 6:00 AM showing how the +sun rises. -The function `schedule()` should be used here. It will create a [script](./Scripts) with some additional features to make sure the script is always executed when the game time matches the given parameters. +The function `schedule()` should be used here. It will create a [script](./Scripts) with some +additional features to make sure the script is always executed when the game time matches the given +parameters. The `schedule` function takes the following arguments: - The *callback*, a function to be called when time is up. -- The keyword `repeat` (`False` by default) to indicate whether this function should be called repeatedly. -- Additional keyword arguments `sec`, `min`, `hour`, `day`, `month` and `year` to describe the time to schedule. If the parameter isn't given, it assumes the current time value of this specific unit. +- The keyword `repeat` (`False` by default) to indicate whether this function should be called +repeatedly. +- Additional keyword arguments `sec`, `min`, `hour`, `day`, `month` and `year` to describe the time +to schedule. If the parameter isn't given, it assumes the current time value of this specific unit. -Here is a short example for making the sun rise every day: +Here is a short example for making the sun rise every day: ```python # in a file ingame_time.py in mygame/world/ -from evennia.utils import gametime +from evennia.utils import gametime from typeclasses.rooms import Room def at_sunrise(): @@ -108,25 +136,46 @@ If you want to test this function, you can easily do something like: @py from world import ingame_time; ingame_time.start_sunrise_event() ``` -The script will be created silently. The `at_sunrise` function will now be called every in-game day at 6 AM. You can use the `@scripts` command to see it. You could stop it using `@scripts/stop`. If we hadn't set `repeat` the sun would only have risen once and then never again. +The script will be created silently. The `at_sunrise` function will now be called every in-game day +at 6 AM. You can use the `@scripts` command to see it. You could stop it using `@scripts/stop`. If +we hadn't set `repeat` the sun would only have risen once and then never again. -We used the `@py` command here: nothing prevents you from adding the system into your game code. Remember to be careful not to add each event at startup, however, otherwise there will be a lot of overlapping events scheduled when the sun rises. +We used the `@py` command here: nothing prevents you from adding the system into your game code. +Remember to be careful not to add each event at startup, however, otherwise there will be a lot of +overlapping events scheduled when the sun rises. -The `schedule` function when using `repeat` set to `True` works with the higher, non-specified unit. In our example, we have specified hour, minute and second. The higher unit we haven't specified is day: `schedule` assumes we mean "run the callback every day at the specified time". Therefore, you can have an event that runs every hour at HH:30, or every month on the 3rd day. +The `schedule` function when using `repeat` set to `True` works with the higher, non-specified unit. +In our example, we have specified hour, minute and second. The higher unit we haven't specified is +day: `schedule` assumes we mean "run the callback every day at the specified time". Therefore, you +can have an event that runs every hour at HH:30, or every month on the 3rd day. -> A word of caution for repeated scripts on a monthly or yearly basis: due to the variations in the real-life calendar you need to be careful when scheduling events for the end of the month or year. For example, if you set a script to run every month on the 31st it will run in January but find no such day in February, April etc. Similarly, leap years may change the number of days in the year. +> A word of caution for repeated scripts on a monthly or yearly basis: due to the variations in the +real-life calendar you need to be careful when scheduling events for the end of the month or year. +For example, if you set a script to run every month on the 31st it will run in January but find no +such day in February, April etc. Similarly, leap years may change the number of days in the year. ### A game time with a custom calendar -Using a custom calendar to handle game time is sometimes needed if you want to place your game in a fictional universe. For instance you may want to create the Shire calendar which Tolkien described having 12 months, each which 30 days. That would give only 360 days per year (presumably hobbits weren't really fond of the hassle of following the astronomical calendar). Another example would be creating a planet in a different solar system with, say, days 29 hours long and months of only 18 days. +Using a custom calendar to handle game time is sometimes needed if you want to place your game in a +fictional universe. For instance you may want to create the Shire calendar which Tolkien described +having 12 months, each which 30 days. That would give only 360 days per year (presumably hobbits +weren't really fond of the hassle of following the astronomical calendar). Another example would be +creating a planet in a different solar system with, say, days 29 hours long and months of only 18 +days. -Evennia handles custom calendars through an optional *contrib* module, called `custom_gametime`. Contrary to the normal `gametime` module described above it is not active by default. +Evennia handles custom calendars through an optional *contrib* module, called `custom_gametime`. +Contrary to the normal `gametime` module described above it is not active by default. #### Setting up the custom calendar -In our first example of the Shire calendar, used by hobbits in books by Tolkien, we don't really need the notion of weeks... but we need the notion of months having 30 days, not 28. +In our first example of the Shire calendar, used by hobbits in books by Tolkien, we don't really +need the notion of weeks... but we need the notion of months having 30 days, not 28. -The custom calendar is defined by adding the `TIME_UNITS` setting to your settings file. It's a dictionary containing as keys the name of the units, and as value the number of seconds (the smallest unit for us) in this unit. Its keys must be picked among the following: "sec", "min", "hour", "day", "week", "month" and "year" but you don't have to include them all. Here is the configuration for the Shire calendar: +The custom calendar is defined by adding the `TIME_UNITS` setting to your settings file. It's a +dictionary containing as keys the name of the units, and as value the number of seconds (the +smallest unit for us) in this unit. Its keys must be picked among the following: "sec", "min", +"hour", "day", "week", "month" and "year" but you don't have to include them all. Here is the +configuration for the Shire calendar: ```python # in a file settings.py in mygame/server/conf @@ -138,11 +187,14 @@ TIME_UNITS = {"sec": 1, "year": 60 * 60 * 24 * 30 * 12 } ``` -We give each unit we want as keys. Values represent the number of seconds in that unit. Hour is set to 60 * 60 (that is, 3600 seconds per hour). Notice that we don't specify the week unit in this configuration: instead, we skip from days to months directly. +We give each unit we want as keys. Values represent the number of seconds in that unit. Hour is +set to 60 * 60 (that is, 3600 seconds per hour). Notice that we don't specify the week unit in this +configuration: instead, we skip from days to months directly. -In order for this setting to work properly, remember all units have to be multiples of the previous units. If you create "day", it needs to be multiple of hours, for instance. +In order for this setting to work properly, remember all units have to be multiples of the previous +units. If you create "day", it needs to be multiple of hours, for instance. -So for our example, our settings may look like this: +So for our example, our settings may look like this: ```python # in a file settings.py in mygame/server/conf @@ -163,13 +215,19 @@ TIME_UNITS = { } ``` -Notice we have set a time epoch of 0. Using a custom calendar, we will come up with a nice display of time on our own. In our case the game time starts at year 0, month 0, day 0, and at midnight. +Notice we have set a time epoch of 0. Using a custom calendar, we will come up with a nice display +of time on our own. In our case the game time starts at year 0, month 0, day 0, and at midnight. -Note that while we use "month", "week" etc in the settings, your game may not use those terms in-game, instead referring to them as "cycles", "moons", "sand falls" etc. This is just a matter of you displaying them differently. See next section. +Note that while we use "month", "week" etc in the settings, your game may not use those terms in- +game, instead referring to them as "cycles", "moons", "sand falls" etc. This is just a matter of you +displaying them differently. See next section. #### A command to display the current game time -As pointed out earlier, the `@time` command is meant to be used with a standard calendar, not a custom one. We can easily create a new command though. We'll call it `time`, as is often the case on other MU*. Here's an example of how we could write it (for the example, you can create a file `showtime.py` in your `commands` directory and paste this code in it): +As pointed out earlier, the `@time` command is meant to be used with a standard calendar, not a +custom one. We can easily create a new command though. We'll call it `time`, as is often the case +on other MU*. Here's an example of how we could write it (for the example, you can create a file +`showtime.py` in your `commands` directory and paste this code in it): ```python # in a file mygame/commands/gametime.py @@ -206,7 +264,7 @@ Don't forget to add it in your CharacterCmdSet to see this command: ```python # in mygame/commands/default_cmdset.py -from commands.gametime import CmdTime # <-- Add +from commands.gametime import CmdTime # <-- Add # ... @@ -223,17 +281,22 @@ class CharacterCmdSet(default_cmds.CharacterCmdSet): Populates the cmdset """ super().at_cmdset_creation() - # ... + # ... self.add(CmdTime()) # <- Add ``` -Reload your game with the `@reload` command. You should now see the `time` command. If you enter it, you might see something like: +Reload your game with the `@reload` command. You should now see the `time` command. If you enter +it, you might see something like: We are in year 0, day 0, month 0. It's 00:52:17. -You could display it a bit more prettily with names for months and perhaps even days, if you want. And if "months" are called "moons" in your game, this is where you'd add that. +You could display it a bit more prettily with names for months and perhaps even days, if you want. +And if "months" are called "moons" in your game, this is where you'd add that. #### Time-related events in custom gametime -The `custom_gametime` module also has a way to schedule game-related events, taking into account your game time (and your custom calendar). It can be used to have a specific message every day at 6:00 AM, to show the sun rises, for instance. The `custom_gametime.schedule` function works in the same way as described for the default one above. +The `custom_gametime` module also has a way to schedule game-related events, taking into account +your game time (and your custom calendar). It can be used to have a specific message every day at +6:00 AM, to show the sun rises, for instance. The `custom_gametime.schedule` function works in the +same way as described for the default one above. diff --git a/docs/source/Getting-Started.md b/docs/source/Getting-Started.md index 67ae373aac..ecc38aa7d0 100644 --- a/docs/source/Getting-Started.md +++ b/docs/source/Getting-Started.md @@ -27,13 +27,15 @@ more detailed instructions for your platform. `/home/anna/muddev/` on Linux or a folder in your personal user directory on Windows). 3. `git clone https://github.com/evennia/evennia.git` 4. `virtualenv evenv` -5. `source evenv/bin/activate` (Linux, Mac), `evenv\Scripts\activate` (Windows) +5. `source evenv/bin/activate` (Linux, Mac), `evenv\Scripts\activate` (Windows) 6. `pip install -e evennia` 7. `evennia --init mygame` 8. `cd mygame` 9. `evennia migrate` 10. `evennia start` (make sure to make a superuser when asked) -Evennia should now be running and you can connect to it by pointing a web browser to `http://localhost:4001` or a MUD telnet client to `localhost:4000` (use `127.0.0.1` if your OS does not recognize `localhost`). +Evennia should now be running and you can connect to it by pointing a web browser to +`http://localhost:4001` or a MUD telnet client to `localhost:4000` (use `127.0.0.1` if your OS does +not recognize `localhost`). We also release [Docker images](./Running-Evennia-in-Docker) based on `master` and `develop` branches. @@ -55,9 +57,11 @@ updating Evennia itself - Mac users can use the [git-osx-installer](http://code.google.com/p/git-osx-installer/) or the [MacPorts version](http://git-scm.com/book/en/Getting-Started-Installing-Git#Installing-on-Mac). - [Twisted](http://twistedmatrix.com) (v19.0+) - - [ZopeInterface](http://www.zope.org/Products/ZopeInterface) (v3.0+) - usually included in Twisted packages + - [ZopeInterface](http://www.zope.org/Products/ZopeInterface) (v3.0+) - usually included in +Twisted packages - Linux/Mac users may need the `gcc` and `python-dev` packages or equivalent. - - Windows users need [MS Visual C++](https://aka.ms/vs/16/release/vs_buildtools.exe) and *maybe* [pypiwin32](https://pypi.python.org/pypi/pypiwin32). + - Windows users need [MS Visual C++](https://aka.ms/vs/16/release/vs_buildtools.exe) and *maybe* +[pypiwin32](https://pypi.python.org/pypi/pypiwin32). - [Django](http://www.djangoproject.com) (v2.2.x), be warned that latest dev version is usually untested with Evennia) @@ -71,14 +75,16 @@ install the [dependencies](./Getting-Started#requirements): ``` sudo apt-get update -sudo apt-get install python3 python3-pip python3-dev python3-setuptools python3-git python3-virtualenv gcc +sudo apt-get install python3 python3-pip python3-dev python3-setuptools python3-git +python3-virtualenv gcc # If you are using an Ubuntu version that defaults to Python3, like 18.04+, use this instead: sudo apt-get update sudo apt-get install python3.7 python3-pip python3.7-dev python3-setuptools virtualenv gcc ``` -Note that, the default Python version for your distribution may still not be Python3.7 after this. This is ok - we'll specify exactly which Python to use later. +Note that, the default Python version for your distribution may still not be Python3.7 after this. +This is ok - we'll specify exactly which Python to use later. You should make sure to *not* be `root` after this step, running as `root` is a security risk. Now create a folder where you want to do all your Evennia development: @@ -98,7 +104,7 @@ contains the source code though, it is not *installed* yet. To isolate the Evennia install and its dependencies from the rest of the system, it is good Python practice to install into a _virtualenv_. If you are unsure about what a virtualenv is and why it's useful, see the [Glossary entry on -virtualenv](Glossary#virtualenv). +virtualenv](Glossary#virtualenv). Run `python -V` to see which version of Python your system defaults to. @@ -106,7 +112,7 @@ Run `python -V` to see which version of Python your system defaults to. # If your Linux defaults to Python3.7+: virtualenv evenv -# If your Linux defaults to Python2 or an older version +# If your Linux defaults to Python2 or an older version # of Python3, you must instead point to Python3.7+ explicitly: virtualenv -p /usr/bin/python3.7 evenv ``` @@ -114,7 +120,7 @@ virtualenv -p /usr/bin/python3.7 evenv A new folder `evenv` will appear (we could have called it anything). This folder will hold a self-contained setup of Python packages without interfering with default Python packages on your system (or the Linux distro lagging behind -on Python package versions). It will also always use the right version of Python. +on Python package versions). It will also always use the right version of Python. Activate the virtualenv: ``` @@ -122,7 +128,7 @@ source evenv/bin/activate ``` The text `(evenv)` should appear next to your prompt to show that the virtual -environment is active. +environment is active. > Remember that you need to activate the virtualenv like this *every time* you > start a new terminal to get access to the Python packages (notably the @@ -175,7 +181,8 @@ created. Check out [where to go next](./Getting-Started#where-to-go-next). ## Mac Install The Evennia server is a terminal program. Open the terminal e.g. from -*Applications->Utilities->Terminal*. [Here is an introduction to the Mac terminal](http://blog.teamtreehouse.com/introduction-to-the-mac-os-x-command-line) +*Applications->Utilities->Terminal*. [Here is an introduction to the Mac +terminal](http://blog.teamtreehouse.com/introduction-to-the-mac-os-x-command-line) if you are unsure how it works. If you run into any issues during the installation, please check out [Mac Troubleshooting](./Getting-Started#mac-troubleshooting). @@ -189,7 +196,7 @@ here](http://git-scm.com/book/en/Getting-Started-Installing-Git#Installing-on-Ma * If you run into issues with installing `Twisted` later you may need to install gcc and the Python headers. -After this point you should not need `sudo` or any higher privileges to install anything. +After this point you should not need `sudo` or any higher privileges to install anything. Now create a folder where you want to do all your Evennia development: @@ -208,9 +215,9 @@ A new folder `evennia` will appear containing the Evennia library. This only contains the source code though, it is not *installed* yet. To isolate the Evennia install and its dependencies from the rest of the system, it is good Python practice to install into a _virtualenv_. If you are unsure about what a -virtualenv is and why it's useful, see the [Glossary entry on virtualenv](./Glossary#virtualenv). +virtualenv is and why it's useful, see the [Glossary entry on virtualenv](./Glossary#virtualenv). -Run `python -V` to check which Python your system defaults to. +Run `python -V` to check which Python your system defaults to. ``` @@ -230,7 +237,7 @@ source evenv/bin/activate ``` The text `(evenv)` should appear next to your prompt to show the virtual -environment is active. +environment is active. > Remember that you need to activate the virtualenv like this *every time* you > start a new terminal to get access to the Python packages (notably the @@ -285,20 +292,23 @@ created. Check out [where to go next](./Getting-Started#where-to-go-next). ## Windows Install -If you run into any issues during the installation, please check out -[Windows Troubleshooting](./Getting-Started#windows-troubleshooting). +If you run into any issues during the installation, please check out +[Windows Troubleshooting](./Getting-Started#windows-troubleshooting). -> If you are running Windows10, consider using the Windows Subsystem for Linux +> If you are running Windows10, consider using the Windows Subsystem for Linux > ([WSL](https://en.wikipedia.org/wiki/Windows_Subsystem_for_Linux)) instead. > You should then follow the Linux install instructions above. The Evennia server itself is a command line program. In the Windows launch menu, start *All Programs -> Accessories -> command prompt* and you will get -the Windows command line interface. Here is [one of many tutorials on using the Windows command line](http://www.bleepingcomputer.com/tutorials/windows-command-prompt-introduction/) +the Windows command line interface. Here is [one of many tutorials on using the Windows command +line](http://www.bleepingcomputer.com/tutorials/windows-command-prompt-introduction/) if you are unfamiliar with it. -* Install Python [from the Python homepage](https://www.python.org/downloads/windows/). You will need to be a -Windows Administrator to install packages. You want Python version **3.7.0** (latest verified version), usually +* Install Python [from the Python homepage](https://www.python.org/downloads/windows/). You will +need to be a +Windows Administrator to install packages. You want Python version **3.7.0** (latest verified +version), usually the 64-bit version (although it doesn't matter too much). **When installing, make sure to check-mark *all* install options, especially the one about making Python available on the path (you may have to scroll to see it)**. This allows you to @@ -310,9 +320,12 @@ environment", you should select the second option "Use Git from the Windows Command Prompt", which gives you more freedom as to where you can use the program. * Finally you must install the [Microsoft Visual C++ compiler for -Python](https://aka.ms/vs/16/release/vs_buildtools.exe). Download and run the linked installer and -install the C++ tools. Keep all the defaults. Allow the install of the "Win10 SDK", even if you are on Win7 (not tested on older Windows versions). If you later have issues with installing Evennia due to a failure to build the "Twisted wheels", this is where you are missing things. -* You *may* need the [pypiwin32](https://pypi.python.org/pypi/pypiwin32) Python headers. Install these only if you have issues. +Python](https://aka.ms/vs/16/release/vs_buildtools.exe). Download and run the linked installer and +install the C++ tools. Keep all the defaults. Allow the install of the "Win10 SDK", even if you are +on Win7 (not tested on older Windows versions). If you later have issues with installing Evennia due +to a failure to build the "Twisted wheels", this is where you are missing things. +* You *may* need the [pypiwin32](https://pypi.python.org/pypi/pypiwin32) Python headers. Install +these only if you have issues. You can install Evennia wherever you want. `cd` to that location and create a new folder for all your Evennia development (let's call it `muddev`). @@ -335,7 +348,7 @@ A new folder `evennia` will appear containing the Evennia library. This only contains the source code though, it is not *installed* yet. To isolate the Evennia install and its dependencies from the rest of the system, it is good Python practice to install into a _virtualenv_. If you are unsure about what a -virtualenv is and why it's useful, see the [Glossary entry on virtualenv](./Glossary#virtualenv). +virtualenv is and why it's useful, see the [Glossary entry on virtualenv](./Glossary#virtualenv). In your console, try `python -V` to see which version of Python your system defaults to. @@ -367,7 +380,7 @@ evenv\scripts\activate.bat ``` The text `(evenv)` should appear next to your prompt to show the virtual -environment is active. +environment is active. > Remember that you need to activate the virtualenv like this *every time* you > start a new console window if you want to get access to the Python packages @@ -381,8 +394,10 @@ folders when you use the `dir` command) and run pip install -e evennia ``` For more info about `pip`, see the [Glossary entry on pip](./Glossary#pip). If -the install failed with any issues, see [Windows Troubleshooting](./Getting-Started#windows-troubleshooting). -Next we'll start our new game, we'll call it "mygame" here. This creates a new folder where you will be +the install failed with any issues, see [Windows Troubleshooting](./Getting-Started#windows- +troubleshooting). +Next we'll start our new game, we'll call it "mygame" here. This creates a new folder where you will +be creating your new game: ``` @@ -423,13 +438,29 @@ logged in, stand in the `Limbo` room and run @batchcommand tutorial_world.build -to build [Evennia's tutorial world](./Tutorial-World-Introduction) - it's a small solo quest to explore. Only run the instructed `@batchcommand` once. You'll get a lot of text scrolling by as the tutorial is built. Once done, the `tutorial` exit will have appeared out of Limbo - just write `tutorial` to enter it. +to build [Evennia's tutorial world](./Tutorial-World-Introduction) - it's a small solo quest to +explore. Only run the instructed `@batchcommand` once. You'll get a lot of text scrolling by as the +tutorial is built. Once done, the `tutorial` exit will have appeared out of Limbo - just write +`tutorial` to enter it. -Once you get back to `Limbo` from the tutorial (if you get stuck in the tutorial quest you can do `@tel #2` to jump to Limbo), a good idea is to learn how to [start, stop and reload](./Start-Stop-Reload) the Evennia server. You may also want to familiarize yourself with some [commonly used terms in our Glossary](./Glossary). After that, why not experiment with [creating some new items and build some new rooms](./Building-Quickstart) out from Limbo. +Once you get back to `Limbo` from the tutorial (if you get stuck in the tutorial quest you can do +`@tel #2` to jump to Limbo), a good idea is to learn how to [start, stop and reload](Start-Stop- +Reload) the Evennia server. You may also want to familiarize yourself with some [commonly used terms +in our Glossary](Glossary). After that, why not experiment with [creating some new items and build +some new rooms](Building-Quickstart) out from Limbo. -From here on, you could move on to do one of our [introductory tutorials](./Tutorials) or simply dive headlong into Evennia's comprehensive [manual](https://github.com/evennia/evennia/wiki). While Evennia has no major game systems out of the box, we do supply a range of optional *contribs* that you can use or borrow from. They range from dice rolling and alternative color schemes to barter and combat systems. You can find the [growing list of contribs here](https://github.com/evennia/evennia/blob/master/evennia/contrib/README.md). +From here on, you could move on to do one of our [introductory tutorials](./Tutorials) or simply dive +headlong into Evennia's comprehensive [manual](https://github.com/evennia/evennia/wiki). While +Evennia has no major game systems out of the box, we do supply a range of optional *contribs* that +you can use or borrow from. They range from dice rolling and alternative color schemes to barter and +combat systems. You can find the [growing list of contribs +here](https://github.com/evennia/evennia/blob/master/evennia/contrib/README.md). -If you have any questions, you can always ask in [the developer chat](http://webchat.freenode.net/?channels=evennia&uio=MT1mYWxzZSY5PXRydWUmMTE9MTk1JjEyPXRydWUbb) `#evennia` on `irc.freenode.net` or by posting to the [Evennia forums](https://groups.google.com/forum/#%21forum/evennia). You can also join the [Discord Server](https://discord.gg/NecFePw). +If you have any questions, you can always ask in [the developer +chat](http://webchat.freenode.net/?channels=evennia&uio=MT1mYWxzZSY5PXRydWUmMTE9MTk1JjEyPXRydWUbb) +`#evennia` on `irc.freenode.net` or by posting to the [Evennia +forums](https://groups.google.com/forum/#%21forum/evennia). You can also join the [Discord +Server](https://discord.gg/NecFePw). Finally, if you are itching to help out or support Evennia (awesome!) have an issue to report or a feature to request, [see here](./How-To-Get-And-Give-Help). @@ -450,25 +481,59 @@ you can run `evennia -l`, or (in the future) start the server with `evennia star ### Linux Troubleshooting - If you get an error when installing Evennia (especially with lines mentioning - failing to include `Python.h`) then try `sudo apt-get install python3-setuptools python3-dev`. + failing to include `Python.h`) then try `sudo apt-get install python3-setuptools python3-dev`. Once installed, run `pip install -e evennia` again. - Under some not-updated Linux distributions you may run into errors with a too-old `setuptools` or missing `functools`. If so, update your environment with `pip install --upgrade pip wheel setuptools`. Then try `pip install -e evennia` again. -- One user reported a rare issue on Ubuntu 16 is an install error on installing Twisted; `Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-vnIFTg/twisted/` with errors like `distutils.errors.DistutilsError: Could not find suitable distribution for Requirement.parse('incremental>=16.10.1')`. This appears possible to solve by simply updating Ubuntu with `sudo apt-get update && sudo apt-get dist-upgrade`. -- Users of Fedora (notably Fedora 24) has reported a `gcc` error saying the directory `/usr/lib/rpm/redhat/redhat-hardened-cc1` is missing, despite `gcc` itself being installed. [The confirmed work-around](https://gist.github.com/yograterol/99c8e123afecc828cb8c) seems to be to install the `redhat-rpm-config` package with e.g. `sudo dnf install redhat-rpm-config`. -- Some users trying to set up a virtualenv on an NTFS filesystem find that it fails due to issues with symlinks not being supported. Answer is to not use NTFS (seriously, why would you do that to yourself?) +- One user reported a rare issue on Ubuntu 16 is an install error on installing Twisted; `Command +"python setup.py egg_info" failed with error code 1 in /tmp/pip-build-vnIFTg/twisted/` with errors +like `distutils.errors.DistutilsError: Could not find suitable distribution for +Requirement.parse('incremental>=16.10.1')`. This appears possible to solve by simply updating Ubuntu +with `sudo apt-get update && sudo apt-get dist-upgrade`. +- Users of Fedora (notably Fedora 24) has reported a `gcc` error saying the directory +`/usr/lib/rpm/redhat/redhat-hardened-cc1` is missing, despite `gcc` itself being installed. [The +confirmed work-around](https://gist.github.com/yograterol/99c8e123afecc828cb8c) seems to be to +install the `redhat-rpm-config` package with e.g. `sudo dnf install redhat-rpm-config`. +- Some users trying to set up a virtualenv on an NTFS filesystem find that it fails due to issues +with symlinks not being supported. Answer is to not use NTFS (seriously, why would you do that to +yourself?) ### Mac Troubleshooting -- Mac users have reported a critical `MemoryError` when trying to start Evennia on Mac with a Python version below `2.7.12`. If you get this error, update to the latest XCode and Python2 version. -- Some Mac users have reported not being able to connect to `localhost` (i.e. your own computer). If so, try to connect to `127.0.0.1` instead, which is the same thing. Use port 4000 from mud clients and port 4001 from the web browser as usual. +- Mac users have reported a critical `MemoryError` when trying to start Evennia on Mac with a Python +version below `2.7.12`. If you get this error, update to the latest XCode and Python2 version. +- Some Mac users have reported not being able to connect to `localhost` (i.e. your own computer). If +so, try to connect to `127.0.0.1` instead, which is the same thing. Use port 4000 from mud clients +and port 4001 from the web browser as usual. ### Windows Troubleshooting -- If you installed Python but the `python` command is not available (even in a new console), then you might have missed installing Python on the path. In the Windows Python installer you get a list of options for what to install. Most or all options are pre-checked except this one, and you may even have to scroll down to see it. Reinstall Python and make sure it's checked. -- If your MUD client cannot connect to `localhost:4000`, try the equivalent `127.0.0.1:4000` instead. Some MUD clients on Windows does not appear to understand the alias `localhost`. -- If you run `virtualenv evenv` and get a `'virtualenv' is not recognized as an internal or external command, -operable program or batch file.` error, you can `mkdir evenv`, `cd evenv` and then `python -m virtualenv .` as a workaround. -- Some Windows users get an error installing the Twisted 'wheel'. A wheel is a pre-compiled binary package for Python. A common reason for this error is that you are using a 32-bit version of Python, but Twisted has not yet uploaded the latest 32-bit wheel. Easiest way to fix this is to install a slightly older Twisted version. So if, say, version `18.1` failed, install `18.0` manually with `pip install twisted==18.0`. Alternatively you could try to get a 64-bit version of Python (uninstall the 32bit one). If so, you must then `deactivate` the virtualenv, delete the `evenv` folder and recreate it anew (it will then use the new Python executable). -- If your server won't start, with no error messages (and no log files at all when starting from scratch), try to start with `evennia ipstart` instead. If you then see an error about `system cannot find the path specified`, it may be that the file `evennia/evennia/server/twistd.bat` has the wrong path to the `twistd` executable. This file is auto-generated, so try to delete it and then run `evennia start` to rebuild it and see if it works. If it still doesn't work you need to open it in a text editor like Notepad. It's just one line containing the path to the `twistd.exe` executable as determined by Evennia. If you installed Twisted in a non-standard location this might be wrong and you should update the line to the real location. +- If you installed Python but the `python` command is not available (even in a new console), then +you might have missed installing Python on the path. In the Windows Python installer you get a list +of options for what to install. Most or all options are pre-checked except this one, and you may +even have to scroll down to see it. Reinstall Python and make sure it's checked. +- If your MUD client cannot connect to `localhost:4000`, try the equivalent `127.0.0.1:4000` +instead. Some MUD clients on Windows does not appear to understand the alias `localhost`. +- If you run `virtualenv evenv` and get a `'virtualenv' is not recognized as an internal or external +command, +operable program or batch file.` error, you can `mkdir evenv`, `cd evenv` and then `python -m +virtualenv .` as a workaround. +- Some Windows users get an error installing the Twisted 'wheel'. A wheel is a pre-compiled binary +package for Python. A common reason for this error is that you are using a 32-bit version of Python, +but Twisted has not yet uploaded the latest 32-bit wheel. Easiest way to fix this is to install a +slightly older Twisted version. So if, say, version `18.1` failed, install `18.0` manually with `pip +install twisted==18.0`. Alternatively you could try to get a 64-bit version of Python (uninstall the +32bit one). If so, you must then `deactivate` the virtualenv, delete the `evenv` folder and recreate +it anew (it will then use the new Python executable). +- If your server won't start, with no error messages (and no log files at all when starting from +scratch), try to start with `evennia ipstart` instead. If you then see an error about `system cannot +find the path specified`, it may be that the file `evennia/evennia/server/twistd.bat` has the wrong +path to the `twistd` executable. This file is auto-generated, so try to delete it and then run +`evennia start` to rebuild it and see if it works. If it still doesn't work you need to open it in a +text editor like Notepad. It's just one line containing the path to the `twistd.exe` executable as +determined by Evennia. If you installed Twisted in a non-standard location this might be wrong and +you should update the line to the real location. +- Some users have reported issues with Windows WSL and anti-virus software during Evennia +development. Timeout errors and the inability to run `evennia connections` may be due to your anti- +virus software interfering. Try disabling or changing your anti-virus software settings. \ No newline at end of file diff --git a/docs/source/Glossary.md b/docs/source/Glossary.md index d710c2dd32..cb93d7c731 100644 --- a/docs/source/Glossary.md +++ b/docs/source/Glossary.md @@ -1,31 +1,36 @@ # Glossary -This explains common recurring terms used in the Evennia docs. It will be expanded as needed. +This explains common recurring terms used in the Evennia docs. It will be expanded as needed. - _[account](./Glossary#account)_ - the player's account on the game - _[admin-site](./Glossary#admin-site)_ - the Django web page for manipulating the database - _[attribute](./Glossary#attribute)_ - persistent, custom data stored on typeclasses - _[channel](./Glossary#channel)_ - game communication channels -- _[character](./Glossary#character)_ - the player's avatar in the game, controlled from _[account](./Glossary#account)_ +- _[character](./Glossary#character)_ - the player's avatar in the game, controlled from +_[account](./Glossary#account)_ - _[core](./Glossary#core)_ - a term used for the code distributed with Evennia proper - _[django](./Glossary#django)_ - web framework Evennia uses for database access and web integration -- _[field](./Glossary#field)_ - a _[typeclass](./Glossary#typeclass)_ property representing a database column +- _[field](./Glossary#field)_ - a _[typeclass](./Glossary#typeclass)_ property representing a database +column - _[git](./Glossary#git)_ - the version-control system we use - _[github](./Glossary#github)_ - the online hosting of our source code - _[migrate](./Glossary#migrate)_ - updating the database schema - _[multisession mode`](#multisession-mode)_ - a setting defining how users connect to Evennia -- _[object](./Glossary#object)_ - Python instance, general term or in-game _[typeclass](./Glossary#typeclass)_ +- _[object](./Glossary#object)_ - Python instance, general term or in-game +_[typeclass](./Glossary#typeclass)_ - _[pip](./Glossary#pip)_ - the Python installer - _player_ - the human connecting to the game with their client -- _[puppet](./Glossary#puppet)_ - when an [account](./Glossary#account) controls an in-game [object](./Glossary#object) +- _[puppet](./Glossary#puppet)_ - when an [account](./Glossary#account) controls an in-game +[object](./Glossary#object) - _[property](./Glossary#property)_ - a python property - _evenv_ - see _[virtualenv](./Glossary#virtualenv)_ - _[repository](./Glossary#repository)_ - a store of source code + source history - _[script](./Glossary#script)_ - a building block for custom storage, systems and time-keepint - _[session](./Glossary#session)_ - represents one client connection - _[ticker](./Glossary#ticker)_ - Allows to run events on a steady 'tick' -- _[twisted](./Glossary#twisted)_ - networking engine responsible for Evennia's event loop and communications +- _[twisted](./Glossary#twisted)_ - networking engine responsible for Evennia's event loop and +communications - _[typeclass](./Glossary#typeclass)_ - Evennia's database-connected Python class - _upstream_ - see _[github](./Glossary#github)_ - _[virtualenv](./Glossary#virtualenv)_ - a Python program and way to make an isolated Python install @@ -35,175 +40,333 @@ This explains common recurring terms used in the Evennia docs. It will be expand ### _account_ -The term 'account' refers to the [player's](./Glossary#player) unique account on the game. It is represented by the `Account` [typeclass](./Glossary#typeclass) and holds things like email, password, configuration etc. +The term 'account' refers to the [player's](./Glossary#player) unique account on the game. It is +represented by the `Account` [typeclass](./Glossary#typeclass) and holds things like email, password, +configuration etc. -When a player connects to the game, they connect to their account. The account has *no* representation in the game world. Through their Account they can instead choose to [puppet](./Glossary#puppet) one (or more, depending on game mode) [Characters](./Glossary#character) in the game. +When a player connects to the game, they connect to their account. The account has *no* +representation in the game world. Through their Account they can instead choose to +[puppet](./Glossary#puppet) one (or more, depending on game mode) [Characters](./Glossary#character) in +the game. -In the default [multisession mode](./Sessions#multisession-mode) of Evennia, you immediately start puppeting a Character with the same name as your Account when you log in - mimicking how older servers used to work. +In the default [multisession mode](./Sessions#multisession-mode) of Evennia, you immediately start +puppeting a Character with the same name as your Account when you log in - mimicking how older +servers used to work. ### _admin-site_ -This usually refers to [Django's](./Glossary#django) *Admin site* or database-administration web page ([link to Django docs](https://docs.djangoproject.com/en/2.1/ref/contrib/admin/)). The admin site is an automatically generated web interface to the database (it can be customized extensively). It's reachable from the `admin` link on the default Evennia website you get with your server. +This usually refers to [Django's](./Glossary#django) *Admin site* or database-administration web page +([link to Django docs](https://docs.djangoproject.com/en/2.1/ref/contrib/admin/)). The admin site is +an automatically generated web interface to the database (it can be customized extensively). It's +reachable from the `admin` link on the default Evennia website you get with your server. ### _attribute_ -The term _Attribute_ should not be confused with ([properties](./Glossary#property) or [fields](./Glossary#field). The `Attribute` represents arbitrary pieces of data that can be attached to any [typeclassed](./Glossary#typeclass) entity in Evennia. Attributes allows storing new persistent data on typeclasses without changing their underlying database schemas. [Read more about Attributes here](./Attributes). +The term _Attribute_ should not be confused with ([properties](./Glossary#property) or +[fields](./Glossary#field). The `Attribute` represents arbitrary pieces of data that can be attached +to any [typeclassed](./Glossary#typeclass) entity in Evennia. Attributes allows storing new persistent +data on typeclasses without changing their underlying database schemas. [Read more about Attributes +here](Attributes). ### _channel_ -A _Channel_ refers to an in-game communication channel. It's an entity that people subscribe to and which re-distributes messages between all subscribers. Such subscribers default to being [Accounts](./Glossary#account), for out-of-game communication but could also be [Objects (usually Characters)](./Glossary#character) if one wanted to adopt Channels for things like in-game walkie-talkies or phone systems. It is represented by the `Channel` typeclass. [You can read more about the comm system here](./Communications#channels). +A _Channel_ refers to an in-game communication channel. It's an entity that people subscribe to and +which re-distributes messages between all subscribers. Such subscribers default to being +[Accounts](./Glossary#account), for out-of-game communication but could also be [Objects (usually +Characters)](Glossary#character) if one wanted to adopt Channels for things like in-game walkie- +talkies or phone systems. It is represented by the `Channel` typeclass. [You can read more about the +comm system here](Communications#channels). ### _character_ -The _Character_ is the term we use for the default avatar being [puppeted](./Glossary#puppet) by the [account](./Glossary#account) in the game world. It is represented by the `Character` typeclass (which is a child of [Object](./Glossary#object)). Many developers use children of this class to represent monsters and other NPCs. You can [read more about it here](./Objects#subclasses-of-object). +The _Character_ is the term we use for the default avatar being [puppeted](./Glossary#puppet) by the +[account](./Glossary#account) in the game world. It is represented by the `Character` typeclass (which +is a child of [Object](./Glossary#object)). Many developers use children of this class to represent +monsters and other NPCs. You can [read more about it here](./Objects#subclasses-of-object). ### _django_ -[Django](https://www.djangoproject.com/) is a professional and very popular Python web framework, similar to Rails for the Ruby language. It is one of Evennia's central library dependencies (the other one is [Twisted](./Glossary#twisted)). Evennia uses Django for two main things - to map all database operations to Python and for structuring our web site. +[Django](https://www.djangoproject.com/) is a professional and very popular Python web framework, +similar to Rails for the Ruby language. It is one of Evennia's central library dependencies (the +other one is [Twisted](./Glossary#twisted)). Evennia uses Django for two main things - to map all +database operations to Python and for structuring our web site. -Through Django, we can work with any supported database (SQlite3, Postgres, MySQL ...) using generic Python instead of database-specific SQL: A database table is represented in Django as a Python class (called a *model*). An Python instance of such a class represents a row in that table. +Through Django, we can work with any supported database (SQlite3, Postgres, MySQL ...) using generic +Python instead of database-specific SQL: A database table is represented in Django as a Python class +(called a *model*). An Python instance of such a class represents a row in that table. -There is usually no need to know the details of Django's database handling in order to use Evennia - it will handle most of the complexity for you under the hood using what we call [typeclasses](./Glossary#typeclass). But should you need the power of Django you can always get it. Most commonly people want to use "raw" Django when doing more advanced/custom database queries than offered by Evennia's [default search functions](./Tutorial-Searching-For-Objects). One will then need to read about Django's _querysets_. Querysets are Python method calls on a special form that lets you build complex queries. They get converted into optimized SQL queries under the hood, suitable for your current database. [Here is our tutorial/explanation of Django queries](./Tutorial-Searching-For-Objects#queries-in-django). +There is usually no need to know the details of Django's database handling in order to use Evennia - +it will handle most of the complexity for you under the hood using what we call +[typeclasses](./Glossary#typeclass). But should you need the power of Django you can always get it. +Most commonly people want to use "raw" Django when doing more advanced/custom database queries than +offered by Evennia's [default search functions](./Tutorial-Searching-For-Objects). One will then need +to read about Django's _querysets_. Querysets are Python method calls on a special form that lets +you build complex queries. They get converted into optimized SQL queries under the hood, suitable +for your current database. [Here is our tutorial/explanation of Django queries](Tutorial-Searching- +For-Objects#queries-in-django). -> By the way, Django (and Evennia) does allow you to fall through and send raw SQL if you really want to. It's highly unlikely to be needed though; the Django database abstraction is very, very powerful. +> By the way, Django (and Evennia) does allow you to fall through and send raw SQL if you really +want to. It's highly unlikely to be needed though; the Django database abstraction is very, very +powerful. -The other aspect where Evennia uses Django is for web integration. On one end Django gives an infrastructure for wiring Python functions (called *views*) to URLs: the view/function is called when a user goes that URL in their browser, enters data into a form etc. The return is the web page to show. Django also offers templating with features such as being able to add special markers in HTML where it will insert the values of Python variables on the fly (like showing the current player count on the web page). [Here is one of our tutorials on wiring up such a web page](./Add-a-simple-new-web-page). Django also comes with the [admin site](./Glossary#admin-site), which automatically maps the database into a form accessible from a web browser. +The other aspect where Evennia uses Django is for web integration. On one end Django gives an +infrastructure for wiring Python functions (called *views*) to URLs: the view/function is called +when a user goes that URL in their browser, enters data into a form etc. The return is the web page +to show. Django also offers templating with features such as being able to add special markers in +HTML where it will insert the values of Python variables on the fly (like showing the current player +count on the web page). [Here is one of our tutorials on wiring up such a web page](Add-a-simple- +new-web-page). Django also comes with the [admin site](./Glossary#admin-site), which automatically +maps the database into a form accessible from a web browser. ### _core_ -This term is sometimes used to represent the main Evennia library code suite, *excluding* its [contrib](./Glossary#contrib) directory. It can sometimes come up in code reviews, such as +This term is sometimes used to represent the main Evennia library code suite, *excluding* its +[contrib](./Glossary#contrib) directory. It can sometimes come up in code reviews, such as -> Evennia is game-agnostic but this feature is for a particular game genre. So it does not belong in core. Better make it a contrib. +> Evennia is game-agnostic but this feature is for a particular game genre. So it does not belong in +core. Better make it a contrib. ### _field_ -A _field_ or _database field_ in Evennia refers to a [property](./Glossary#property) on a [typeclass](./Glossary#typeclass) directly linked to an underlying database column. Only a few fixed properties per typeclass are database fields but they are often tied to the core functionality of that base typeclass (for example [Objects](./Glossary#object) store its location as a field). In all other cases, [attributes](./Glossary#attribute) are used to add new persistent data to the typeclass. [Read more about typeclass properties here](./Typeclasses#about-typeclass-properties). +A _field_ or _database field_ in Evennia refers to a [property](./Glossary#property) on a +[typeclass](./Glossary#typeclass) directly linked to an underlying database column. Only a few fixed +properties per typeclass are database fields but they are often tied to the core functionality of +that base typeclass (for example [Objects](./Glossary#object) store its location as a field). In all +other cases, [attributes](./Glossary#attribute) are used to add new persistent data to the typeclass. +[Read more about typeclass properties here](./Typeclasses#about-typeclass-properties). ### _git_ -[Git](https://git-scm.com/) is a [version control](https://en.wikipedia.org/wiki/Version_control) tool. It allows us to track the development of the Evennia code by dividing it into units called *commits*. A 'commit' is sort of a save-spot - you save the current state of your code and can then come back to it later if later changes caused problems. By tracking commits we know what 'version' of the code we are currently using. +[Git](https://git-scm.com/) is a [version control](https://en.wikipedia.org/wiki/Version_control) +tool. It allows us to track the development of the Evennia code by dividing it into units called +*commits*. A 'commit' is sort of a save-spot - you save the current state of your code and can then +come back to it later if later changes caused problems. By tracking commits we know what 'version' +of the code we are currently using. -Evennia's source code + its source history is jointly called a [repository](./Glossary#repository). This is centrally stored at our online home on [GitHub](./Glossary#github). Everyone using or developing Evennia makes a 'clone' of this repository to their own computer - everyone automatically gets everything that is online, including all the code history. +Evennia's source code + its source history is jointly called a [repository](./Glossary#repository). +This is centrally stored at our online home on [GitHub](./Glossary#github). Everyone using or +developing Evennia makes a 'clone' of this repository to their own computer - everyone +automatically gets everything that is online, including all the code history. -> Don't confuse Git and [GitHub](./Glossary#github). The former is the version control system. The latter is a website (run by a company) that allows you to upload source code controlled by Git for others to see (among other things). +> Don't confuse Git and [GitHub](./Glossary#github). The former is the version control system. The +latter is a website (run by a company) that allows you to upload source code controlled by Git for +others to see (among other things). -Git allows multiple users from around the world to efficiently collaborate on Evennia's code: People can make local commits on their cloned code. The commits they do can then be uploaded to GitHub and reviewed by the Evennia lead devs - and if the changes look ok they can be safely *merged* into the central Evennia code - and everyone can *pull* those changes to update their local copies. +Git allows multiple users from around the world to efficiently collaborate on Evennia's code: People +can make local commits on their cloned code. The commits they do can then be uploaded to GitHub and +reviewed by the Evennia lead devs - and if the changes look ok they can be safely *merged* into the +central Evennia code - and everyone can *pull* those changes to update their local copies. -Developers using Evennia often uses Git on their own games in the same way - to track their changes and to help collaboration with team mates. This is done completely independently of Evennia's Git usage. +Developers using Evennia often uses Git on their own games in the same way - to track their changes +and to help collaboration with team mates. This is done completely independently of Evennia's Git +usage. -Common usage (for non-Evennia developers): -- `git clone ` - clone an online repository to your computer. This is what you do when you 'download' Evennia. You only need to do this once. +Common usage (for non-Evennia developers): +- `git clone ` - clone an online repository to your computer. This is what you do when +you 'download' Evennia. You only need to do this once. - `git pull` (inside local copy of repository) - sync your local repository with what is online. -> Full usage of Git is way beyond the scope of this glossary. See [Tutorial - version control](./Version-Control) for more info and links to the Git documentation. +> Full usage of Git is way beyond the scope of this glossary. See [Tutorial - version +control](Version-Control) for more info and links to the Git documentation. ### _migrate_ -This term is used for upgrading the database structure (it's _schema_ )to a new version. Most often this is due to Evennia's [upstream](./Glossary#github) schema changing. When that happens you need to migrate that schema to the new version as well. Once you have used [git](./Glossary#git) to pull the latest changes, just `cd` into your game dir and run +This term is used for upgrading the database structure (it's _schema_ )to a new version. Most often +this is due to Evennia's [upstream](./Glossary#github) schema changing. When that happens you need to +migrate that schema to the new version as well. Once you have used [git](./Glossary#git) to pull the +latest changes, just `cd` into your game dir and run - evennia migrate + evennia migrate -That should be it (see [virtualenv](./Glossary#virtualenv) if you get a warning that the `evennia` command is not available). See also [Updating your game](./Updating-Your-Game) for more details. +That should be it (see [virtualenv](./Glossary#virtualenv) if you get a warning that the `evennia` +command is not available). See also [Updating your game](./Updating-Your-Game) for more details. -> Technically, migrations are shipped as little Python snippets of code that explains which database actions must be taken to upgrade from one version of the schema to the next. When you run the command above, those snippets are run in sequence. +> Technically, migrations are shipped as little Python snippets of code that explains which database +actions must be taken to upgrade from one version of the schema to the next. When you run the +command above, those snippets are run in sequence. ### _multisession mode_ -This term refers to the `MULTISESSION_MODE` setting, which has a value of 0 to 3. The mode alters how players can connect to the game, such as how many Sessions a player can start with one account and how many Characters they can control at the same time. It is [described in detail here](./Sessions#multisession-mode). +This term refers to the `MULTISESSION_MODE` setting, which has a value of 0 to 3. The mode alters +how players can connect to the game, such as how many Sessions a player can start with one account +and how many Characters they can control at the same time. It is [described in detail +here](Sessions#multisession-mode). ### _github_ -[Github](https://github.com/evennia) is where Evennia's source code and documentation is hosted. This online [repository](./Glossary#repository) of code we also sometimes refer to as _upstream_. +[Github](https://github.com/evennia) is where Evennia's source code and documentation is hosted. +This online [repository](./Glossary#repository) of code we also sometimes refer to as _upstream_. -GitHub is a business, offering free hosting to Open-source projects like Evennia. Despite the similarity in name, don't confuse GitHub the website with [Git](./Glossary#git), the versioning system. Github hosts Git [repositories](./Glossary#repository) online and helps with collaboration and infrastructure. Git itself is a separate project. +GitHub is a business, offering free hosting to Open-source projects like Evennia. Despite the +similarity in name, don't confuse GitHub the website with [Git](./Glossary#git), the versioning +system. Github hosts Git [repositories](./Glossary#repository) online and helps with collaboration and +infrastructure. Git itself is a separate project. ### _object_ -In general Python (and other [object-oriented languages](https://en.wikipedia.org/wiki/Object-oriented_programming)), an `object` is what we call the instance of a *class*. But one of Evennia's core [typeclasses](./Glossary#typeclasss) is also called "Object". To separate these in the docs we try to use `object` to refer to the general term and capitalized `Object` when we refer to the typeclass. +In general Python (and other [object-oriented languages](https://en.wikipedia.org/wiki/Object- +oriented_programming)), an `object` is what we call the instance of a *class*. But one of Evennia's +core [typeclasses](./Glossary#typeclasss) is also called "Object". To separate these in the docs we +try to use `object` to refer to the general term and capitalized `Object` when we refer to the +typeclass. -The `Object` is a typeclass that represents all *in-game* entities, including [Characters](./Glossary#character), rooms, trees, weapons etc. [Read more about Objects here](./Objects). +The `Object` is a typeclass that represents all *in-game* entities, including +[Characters](./Glossary#character), rooms, trees, weapons etc. [Read more about Objects +here](Objects). ### _pip_ -_[pip](https://pypi.org/project/pip/)_ comes with Python and is the main tool for installing third-party Python packages from the web. Once a python package is installed you can do `import ` in your Python code. +_[pip](https://pypi.org/project/pip/)_ comes with Python and is the main tool for installing third- +party Python packages from the web. Once a python package is installed you can do `import +` in your Python code. Common usage: - `pip install ` - install the given package along with all its dependencies. -- `pip search ` - search Python's central package repository [PyPi](https://pypi.org/) for a package of that name. +- `pip search ` - search Python's central package repository [PyPi](https://pypi.org/) for a +package of that name. - `pip install --upgrade ` - upgrade a package you already have to the latest version. - `pip install ==1.5` - install exactly a specific package version. -- `pip install ` - install a Python package you have downloaded earlier (or cloned using git). -- `pip install -e ` - install a local package by just making a soft link to the folder. This means that if the code in `` changes, the installed Python package is immediately updated. If not using `-e`, one would need to run `pip install --upgrade ` every time to make the changes available when you import this package into your code. Evennia is installed this way. +- `pip install ` - install a Python package you have downloaded earlier (or cloned using +git). +- `pip install -e ` - install a local package by just making a soft link to the folder. This +means that if the code in `` changes, the installed Python package is immediately updated. +If not using `-e`, one would need to run `pip install --upgrade ` every time to make the +changes available when you import this package into your code. Evennia is installed this way. -For development, `pip` is usually used together with a [virtualenv](./Glossary#virtualenv) to install all packages and dependencies needed for a project in one, isolated location on the hard drive. +For development, `pip` is usually used together with a [virtualenv](./Glossary#virtualenv) to install +all packages and dependencies needed for a project in one, isolated location on the hard drive. ### _puppet_ -An [account](./Glossary#account) can take control and "play as" any [Object](./Glossary#object). When doing so, we call this _puppeting_, (like [puppeteering](https://en.wikipedia.org/wiki/Puppeteer)). Normally the entity being puppeted is of the [Character](./Glossary#character) subclass but it does not have to be. +An [account](./Glossary#account) can take control and "play as" any [Object](./Glossary#object). When +doing so, we call this _puppeting_, (like [puppeteering](https://en.wikipedia.org/wiki/Puppeteer)). +Normally the entity being puppeted is of the [Character](./Glossary#character) subclass but it does +not have to be. ### _property_ -A _property_ is a general term used for properties on any Python object. The term also sometimes refers to the `property` built-in function of Python ([read more here](https://www.python-course.eu/python3_properties.php)). Note the distinction between properties, [fields](./Glossary#field) and [Attributes](./Glossary#attribute). +A _property_ is a general term used for properties on any Python object. The term also sometimes +refers to the `property` built-in function of Python ([read more here](https://www.python- +course.eu/python3_properties.php)). Note the distinction between properties, +[fields](./Glossary#field) and [Attributes](./Glossary#attribute). ### _repository_ -A _repository_ is a version control/[git](./Glossary#git) term. It represents a folder containing source code plus its versioning history. +A _repository_ is a version control/[git](./Glossary#git) term. It represents a folder containing +source code plus its versioning history. -> In Git's case, that history is stored in a hidden folder `.git`. If you ever feel the need to look into this folder you probably already know enough Git to know why. +> In Git's case, that history is stored in a hidden folder `.git`. If you ever feel the need to look +into this folder you probably already know enough Git to know why. -The `evennia` folder you download from us with `git clone` is a repository. The code on [GitHub](./Glossary#github) is often referred to as the 'online repository' (or the _upstream_ repository). If you put your game dir under version control, that of course becomes a repository as well. +The `evennia` folder you download from us with `git clone` is a repository. The code on +[GitHub](./Glossary#github) is often referred to as the 'online repository' (or the _upstream_ +repository). If you put your game dir under version control, that of course becomes a repository as +well. ### _script_ -When we refer to _Scripts_, we generally refer to the `Script` [typeclass](./Typeclasses). Scripts are the mavericks of Evennia - they are like [Objects](./Glossary#object) but without any in-game existence. They are useful as custom places to store data but also as building blocks in persistent game systems. Since the can be initialized with timing capabilities they can also be used for long-time persistent time keeping (for fast updates other types of timers may be better though). [Read more about Scripts here](./Scripts) +When we refer to _Scripts_, we generally refer to the `Script` [typeclass](./Typeclasses). Scripts are +the mavericks of Evennia - they are like [Objects](./Glossary#object) but without any in-game +existence. They are useful as custom places to store data but also as building blocks in persistent +game systems. Since the can be initialized with timing capabilities they can also be used for long- +time persistent time keeping (for fast updates other types of timers may be better though). [Read +more about Scripts here](Scripts) ### _session_ -A [Session](./Sessions) is a Python object representing a single client connection to the server. A given human player could connect to the game from different clients and each would get a Session (even if you did not allow them to actually log in and get access to an [account](./Glossary#account)). +A [Session](./Sessions) is a Python object representing a single client connection to the server. A +given human player could connect to the game from different clients and each would get a Session +(even if you did not allow them to actually log in and get access to an +[account](./Glossary#account)). -Sessions are _not_ [typeclassed](./Glossary#typeclass) and has no database persistence. But since they always exist (also when not logged in), they share some common functionality with typeclasses that can be useful for certain game states. +Sessions are _not_ [typeclassed](./Glossary#typeclass) and has no database persistence. But since they +always exist (also when not logged in), they share some common functionality with typeclasses that +can be useful for certain game states. ### _ticker_ -The [Ticker handler](./TickerHandler) runs Evennia's optional 'ticker' system. In other engines, such as [DIKU](https://en.wikipedia.org/wiki/DikuMUD), all game events are processed only at specific intervals called 'ticks'. Evennia has no such technical limitation (events are processed whenever needed) but using a fixed tick can still be useful for certain types of game systems, like combat. Ticker Handler allows you to emulate any number of tick rates (not just one) and subscribe actions to be called when those ticks come around. +The [Ticker handler](./TickerHandler) runs Evennia's optional 'ticker' system. In other engines, such +as [DIKU](https://en.wikipedia.org/wiki/DikuMUD), all game events are processed only at specific +intervals called 'ticks'. Evennia has no such technical limitation (events are processed whenever +needed) but using a fixed tick can still be useful for certain types of game systems, like combat. +Ticker Handler allows you to emulate any number of tick rates (not just one) and subscribe actions +to be called when those ticks come around. ### _typeclass_ -The [typeclass](./Typeclasses) is an Evennia-specific term. A typeclass allows developers to work with database-persistent objects as if they were normal Python objects. It makes use of specific [Django](./Glossary#django) features to link a Python class to a database table. Sometimes we refer to such code entities as _being typeclassed_. +The [typeclass](./Typeclasses) is an Evennia-specific term. A typeclass allows developers to work with +database-persistent objects as if they were normal Python objects. It makes use of specific +[Django](./Glossary#django) features to link a Python class to a database table. Sometimes we refer to +such code entities as _being typeclassed_. -Evennia's main typeclasses are [Account](./Glossary#account), [Object](./Glossary#object), [Script](./Glossary#script) and [Channel](./Glossary#channel). Children of the base class (such as [Character](./Glossary#character)) will use the same database table as the parent, but can have vastly different Python capabilities (and persistent features through [Attributes](./Glossary#attributes) and [Tags](./Glossary#tags). A typeclass can be coded and treated pretty much like any other Python class except it must inherit (at any distance) from one of the base typeclasses. Also, creating a new instance of a typeclass will add a new row to the database table to which it is linked. +Evennia's main typeclasses are [Account](./Glossary#account), [Object](./Glossary#object), +[Script](./Glossary#script) and [Channel](./Glossary#channel). Children of the base class (such as +[Character](./Glossary#character)) will use the same database table as the parent, but can have vastly +different Python capabilities (and persistent features through [Attributes](./Glossary#attributes) and +[Tags](./Glossary#tags). A typeclass can be coded and treated pretty much like any other Python class +except it must inherit (at any distance) from one of the base typeclasses. Also, creating a new +instance of a typeclass will add a new row to the database table to which it is linked. -The [core](./Glossary#core) typeclasses in the Evennia library are all named `DefaultAccount`, `DefaultObject` etc. When you initialize your [game dir] you automatically get empty children of these, called `Account`, `Object` etc that you can start working with. +The [core](./Glossary#core) typeclasses in the Evennia library are all named `DefaultAccount`, +`DefaultObject` etc. When you initialize your [game dir] you automatically get empty children of +these, called `Account`, `Object` etc that you can start working with. ### _twisted_ -[Twisted](https://twistedmatrix.com/trac/) is a heavy-duty asynchronous networking engine. It is one of Evennia's two major library dependencies (the other one is [Django](./Glossary#django)). Twisted is what "runs" Evennia - it handles Evennia's event loop. Twisted also has the building blocks we need to construct network protocols and communicate with the outside world; such as our MUD-custom version of Telnet, Telnet+SSL, SSH, webclient-websockets etc. Twisted also runs our integrated web server, serving the Django-based website for your game. +[Twisted](https://twistedmatrix.com/trac/) is a heavy-duty asynchronous networking engine. It is one +of Evennia's two major library dependencies (the other one is [Django](./Glossary#django)). Twisted is +what "runs" Evennia - it handles Evennia's event loop. Twisted also has the building blocks we need +to construct network protocols and communicate with the outside world; such as our MUD-custom +version of Telnet, Telnet+SSL, SSH, webclient-websockets etc. Twisted also runs our integrated web +server, serving the Django-based website for your game. ### _virtualenv_ -The standard [virtualenv](https://virtualenv.pypa.io/en/stable/) program comes with Python. It is used to isolate all Python packages needed by a given Python project into one folder (we call that folder `evenv` but it could be called anything). A package environment created this way is usually referred to as "a virtualenv". If you ever try to run the `evennia` program and get an error saying something like "the command 'evennia' is not available" - it's probably because your virtualenv is not 'active' yet (see below). +The standard [virtualenv](https://virtualenv.pypa.io/en/stable/) program comes with Python. It is +used to isolate all Python packages needed by a given Python project into one folder (we call that +folder `evenv` but it could be called anything). A package environment created this way is usually +referred to as "a virtualenv". If you ever try to run the `evennia` program and get an error saying +something like "the command 'evennia' is not available" - it's probably because your virtualenv is +not 'active' yet (see below). -Usage: -- `virtualenv ` - initialize a new virtualenv `` in a new folder `` in the current location. Called `evenv` in these docs. -- `virtualenv -p path/to/alternate/python_executable ` - create a virtualenv using another Python version than default. +Usage: +- `virtualenv ` - initialize a new virtualenv `` in a new folder `` in the current +location. Called `evenv` in these docs. +- `virtualenv -p path/to/alternate/python_executable ` - create a virtualenv using another +Python version than default. - `source /bin/activate`(linux/mac) - activate the virtualenv in ``. -- `\Scripts\activate` (windows) +- `\Scripts\activate` (windows) - `deactivate` - turn off the currently activated virtualenv. -A virtualenv is 'activated' only for the console/terminal it was started in, but it's safe to activate the same virtualenv many times in different windows if you want. Once activated, all Python packages now installed with [pip](./Glossary#pip) will install to `evenv` rather than to a global location like `/usr/local/bin` or `C:\Program Files`. +A virtualenv is 'activated' only for the console/terminal it was started in, but it's safe to +activate the same virtualenv many times in different windows if you want. Once activated, all Python +packages now installed with [pip](./Glossary#pip) will install to `evenv` rather than to a global +location like `/usr/local/bin` or `C:\Program Files`. -> Note that if you have root/admin access you *could* install Evennia globally just fine, without using a virtualenv. It's strongly discouraged and considered bad practice though. Experienced Python developers tend to rather create one new virtualenv per project they are working on, to keep the varying installs cleanly separated from one another. +> Note that if you have root/admin access you *could* install Evennia globally just fine, without +using a virtualenv. It's strongly discouraged and considered bad practice though. Experienced Python +developers tend to rather create one new virtualenv per project they are working on, to keep the +varying installs cleanly separated from one another. -When you execute Python code within this activated virtualenv, *only* those packages installed within will be possible to `import` into your code. So if you installed a Python package globally on your computer, you'll need to install it again in your virtualenv. +When you execute Python code within this activated virtualenv, *only* those packages installed +within will be possible to `import` into your code. So if you installed a Python package globally on +your computer, you'll need to install it again in your virtualenv. -> Virtualenvs *only* deal with Python programs/packages. Other programs on your computer couldn't care less if your virtualenv is active or not. So you could use `git` without the virtualenv being active, for example. +> Virtualenvs *only* deal with Python programs/packages. Other programs on your computer couldn't +care less if your virtualenv is active or not. So you could use `git` without the virtualenv being +active, for example. -When your virtualenv is active you should see your console/terminal prompt change to +When your virtualenv is active you should see your console/terminal prompt change to (evenv) ... -... or whatever name you gave the virtualenv when you initialized it. +... or whatever name you gave the virtualenv when you initialized it. -> We sometimes say that we are "in" the virtualenv when it's active. But just to be clear - you never have to actually `cd` into the `evenv` folder. You can activate it from anywhere and will still be considered "in" the virtualenv wherever you go until you `deactivate` or close the console/terminal. +> We sometimes say that we are "in" the virtualenv when it's active. But just to be clear - you +never have to actually `cd` into the `evenv` folder. You can activate it from anywhere and will +still be considered "in" the virtualenv wherever you go until you `deactivate` or close the +console/terminal. -So, when do I *need* to activate my virtualenv? If the virtualenv is not active, none of the Python packages/programs you installed in it will be available to you. So at a minimum, *it needs to be activated whenever you want to use the `evennia` command* for any reason. +So, when do I *need* to activate my virtualenv? If the virtualenv is not active, none of the Python +packages/programs you installed in it will be available to you. So at a minimum, *it needs to be +activated whenever you want to use the `evennia` command* for any reason. diff --git a/docs/source/Grapevine.md b/docs/source/Grapevine.md index 44389ffabe..fb8ede4372 100644 --- a/docs/source/Grapevine.md +++ b/docs/source/Grapevine.md @@ -8,20 +8,20 @@ can chat with players in other games, also non-Evennia ones. ## Configuring Grapevine To use Grapevine, you first need the `pyopenssl` module. Install it into your -Evennia python environment with +Evennia python environment with pip install pyopenssl -To configure Grapevine, you'll need to activate it in your settings file. +To configure Grapevine, you'll need to activate it in your settings file. ```python GRAPEVINE_ENABLED = True ``` -Next, register an account at https://grapevine.haus. When you have logged in, -go to your Settings/Profile and to the `Games` sub menu. Here you register your +Next, register an account at https://grapevine.haus. When you have logged in, +go to your Settings/Profile and to the `Games` sub menu. Here you register your new game by filling in its information. At the end of registration you are going -to get a `Client ID` and a `Client Secret`. These should not be shared. +to get a `Client ID` and a `Client Secret`. These should not be shared. Open/create the file `mygame/server/conf/secret_settings.py` and add the following: @@ -30,8 +30,8 @@ Open/create the file `mygame/server/conf/secret_settings.py` and add the followi GRAPEVINE_CLIENT_SECRET = "" ``` -You can also customize the Grapevine channels you are allowed to connect to. This -is added to the `GRAPEVINE_CHANNELS` setting. You can see which channels are available +You can also customize the Grapevine channels you are allowed to connect to. This +is added to the `GRAPEVINE_CHANNELS` setting. You can see which channels are available by going to the Grapevine online chat here: https://grapevine.haus/chat. Start/reload Evennia and log in as a privileged user. You should now have a new @@ -39,8 +39,8 @@ command available: `@grapevine2chan`. This command is called like this: @grapevine2chan[/switches] = -Here, the `evennia_channel` must be the name of an existing Evennia channel and -`grapevine_channel` one of the supported channels in `GRAPEVINE_CHANNELS`. +Here, the `evennia_channel` must be the name of an existing Evennia channel and +`grapevine_channel` one of the supported channels in `GRAPEVINE_CHANNELS`. > At the time of writing, the Grapevine network only has two channels: > `testing` and `gossip`. Evennia defaults to allowing connecting to both. Use @@ -61,11 +61,11 @@ Next we will create a connection to the Grapevine network. @grapevine2chan gw = gossip Evennia will now create a new connection and connect it to Grapevine. Connect -to https://grapevine.haus/chat to check. +to https://grapevine.haus/chat to check. Write something in the Evennia channel *gw* and check so a message appears in the Grapevine chat. Write a reply in the chat and the grapevine bot should echo -it to your channel in-game. +it to your channel in-game. Your Evennia gamers can now chat with users on external Grapevine channels! diff --git a/docs/source/Guest-Logins.md b/docs/source/Guest-Logins.md index cdcb8c479f..b3b3786b60 100644 --- a/docs/source/Guest-Logins.md +++ b/docs/source/Guest-Logins.md @@ -1,18 +1,29 @@ # Guest Logins -Evennia supports *guest logins* out of the box. A guest login is an anonymous, low-access account and can be useful if you want users to have a chance to try out your game without committing to creating a real account. +Evennia supports *guest logins* out of the box. A guest login is an anonymous, low-access account +and can be useful if you want users to have a chance to try out your game without committing to +creating a real account. Guest accounts are turned off by default. To activate, add this to your `game/settings.py` file: GUEST_ENABLED = True -Henceforth users can use `connect guest` (in the default command set) to login with a guest account. You may need to change your [Connection Screen](./Connection-Screen) to inform them of this possibility. Guest accounts work differently from normal accounts - they are automatically *deleted* whenever the user logs off or the server resets (but not during a reload). They are literally re-usable throw-away accounts. +Henceforth users can use `connect guest` (in the default command set) to login with a guest account. +You may need to change your [Connection Screen](./Connection-Screen) to inform them of this +possibility. Guest accounts work differently from normal accounts - they are automatically *deleted* +whenever the user logs off or the server resets (but not during a reload). They are literally re- +usable throw-away accounts. You can add a few more variables to your `settings.py` file to customize your guests: -- `BASE_GUEST_TYPECLASS` - the python-path to the default [typeclass](./Typeclasses) for guests. Defaults to `"typeclasses.accounts.Guest"`. -- `PERMISSION_GUEST_DEFAULT` - [permission level](./Locks) for guest accounts. Defaults to `"Guests"`, which is the lowest permission level in the hierarchy. -- `GUEST_START_LOCATION` - the `#dbref` to the starting location newly logged-in guests should appear at. Defaults to `"#2` (Limbo). +- `BASE_GUEST_TYPECLASS` - the python-path to the default [typeclass](./Typeclasses) for guests. +Defaults to `"typeclasses.accounts.Guest"`. +- `PERMISSION_GUEST_DEFAULT` - [permission level](./Locks) for guest accounts. Defaults to `"Guests"`, +which is the lowest permission level in the hierarchy. +- `GUEST_START_LOCATION` - the `#dbref` to the starting location newly logged-in guests should +appear at. Defaults to `"#2` (Limbo). - `GUEST_HOME` - guest home locations. Defaults to Limbo as well. -- `GUEST_LIST` - this is a list holding the possible guest names to use when entering the game. The length of this list also sets how many guests may log in at the same time. By default this is a list of nine names from `"Guest1"` to `"Guest9"`. +- `GUEST_LIST` - this is a list holding the possible guest names to use when entering the game. The +length of this list also sets how many guests may log in at the same time. By default this is a list +of nine names from `"Guest1"` to `"Guest9"`. diff --git a/docs/source/HAProxy-Config-(Optional).md b/docs/source/HAProxy-Config-(Optional).md deleted file mode 100644 index 82d3fc44b9..0000000000 --- a/docs/source/HAProxy-Config-(Optional).md +++ /dev/null @@ -1,59 +0,0 @@ -# HAProxy Config (Optional) - -### Evennia, HTTPS and Secure Websockets can play nicely together, quickly. -May I suggest giving HAProxy 1.5+ a chance... - -Installing HAProxy is usually as simple as: -``` -# Redhat derivatives -yum install haproxy -# dnf instead of yum for very recent Fedora distros. -``` -or -``` -# Debian derivatives -apt install haproxy -``` - -Configuration of HAProxy requires a single file given as an argument on the command line: -``` -haproxy -f /path/to/config.file -``` - -In it (example using haproxy 1.5.18 on Centos7): -``` -# stuff provided by the default haproxy installs -global - log /dev/log local0 - chroot /var/lib/haproxy - maxconn 4000 - user haproxy -defaults - mode http - option forwardfor - -# Evennia Specifics -listen evennia-https-website - bind : ssl no-sslv3 no-tlsv10 crt /path/to/your-cert.pem - server localhost 127.0.0.1: - -listen evennia-secure-websocket - bind : ssl no-sslv3 no-tlsv10 crt /path/to/your-cert.pem - server localhost 127.0.0.1: - timeout client 10m - timeout server 10m -``` - -Then edit mygame/server/conf/settings.py and add: -``` -WEBSERVER_INTERFACES = ['127.0.0.1'] -WEBSOCKET_CLIENT_INTERFACE = '127.0.0.1' -``` -or -``` -LOCKDOWN_MODE=True -``` -and -``` -WEBSOCKET_CLIENT_URL="wss://yourhost.com:4002/" -``` \ No newline at end of file diff --git a/docs/source/HAProxy-Config.md b/docs/source/HAProxy-Config.md new file mode 100644 index 0000000000..7bdf1f99a5 --- /dev/null +++ b/docs/source/HAProxy-Config.md @@ -0,0 +1,176 @@ +# HAProxy Config (Optional) + +## Making Evennia, HTTPS and Secure Websockets play nicely together + +This we can do by installing a _proxy_ between Evennia and the outgoing ports of your server. +Essentially, +Evennia will think it's only running locally (on localhost, IP 127.0.0.1) - the proxy will +transparently +map that to the "real" outgoing ports and handle HTTPS/WSS for us. + +``` +Evennia <-> (inside-visible IP/ports) <-> Proxy <-> (outside-visible IP/ports) <-> Internet +``` + + +Here we will use [HAProxy](https://www.haproxy.org/), an open-source proxy that is easy to set up +and use. We will +also be using [LetsEncrypt](https://letsencrypt.org/getting-started/), especially the excellent +helper-program [Certbot](https://certbot.eff.org/instructions) which pretty much automates the whole +certificate setup process for us. + +Before starting you also need the following: + +- (optional) The host name of your game (like `myawesomegame.com`). This is something you must +previously have purchased from a _domain registrar_ and set up with DNS to point to the IP of your +server. +- If you don't have a domain name or haven't set it up yet, you must at least know the IP of your +server. Find this with `ifconfig` or similar from inside the server. If you use a hosting service +like DigitalOcean you can also find the droplet's IP address in the control panel. +- You must open port 80 in your firewall. This is used by Certbot below to auto-renew certificates. +So you can't really run another webserver alongside this setup without tweaking. +- You must open port 443 (HTTPS) in your firewall. +- You must open port 4002 (the default Websocket port) in your firewall. + + +## Getting certificates + +Certificates guarantee that you are you. Easiest is to get this with +[Letsencrypt](https://letsencrypt.org/getting-started/) and the +[Certbot](https://certbot.eff.org/instructions) program. Certbot has a lot of install instructions +for various operating systems. Here's for Debian/Ubuntu: + +``` +sudo apt install certbot +``` + +Make sure to stop Evennia and that no port-80 using service is running, then + +``` +sudo certbot certonly --standalone +``` + +You will get some questions you need to answer, such as an email to send certificate errors to and +the host name (or IP, supposedly) to use with this certificate. After this, the certificates will +end up in `/etc/letsencrypt/live//*pem` (example from Ubuntu). The critical files +for our purposes are `fullchain.pem` and `privkey.pem`. + +Certbot sets up a cron-job/systemd job to regularly renew the certificate. To check this works, try + +``` +sudo certbot renew --dry-run +``` + +The certificate is only valid for 3 months at a time, so make sure this test works (it requires port +80 to be open). Look up Certbot's page for more help. + +We are not quite done. HAProxy expects these two files to be _one_ file. + +``` +sudo cp /etc/letsencrypt/live//privkey.pem /etc/letsencrypt/live//.pem +sudo bash -c "cat /etc/letsencrypt/live//fullchain.pem >> +/etc/letsencrypt/live//.pem" +``` + +This will create a new `.pem` file by concatenating the two files together. The `yourhostname.pem` +file (or whatever you named it) is what we will use when the the HAProxy config file (below) asks +for "your-certificate.pem". + +## Installing and configuring HAProxy + +Installing HaProxy is usually as simple as: +``` +# Debian derivatives (Ubuntu, Mint etc) +sudo apt install haproxy + +# Redhat derivatives (dnf instead of yum for very recent Fedora distros) +sudo yum install haproxy + +``` + +Configuration of HAProxy is done in a single file. Put this wherever you like, for example in +your game dir; name it something like haproxy.conf. + +Here is an example tested on Centos7 and Ubuntu. Make sure to change the file to put in your own +values. + +``` +# base stuff to set up haproxy +global + log /dev/log local0 + chroot /var/lib/haproxy + maxconn 4000 + user haproxy + tune.ssl.default-dh-param 2048 + ## uncomment this when everything works + # daemon +defaults + mode http + option forwardfor + +# Evennia Specifics +listen evennia-https-website + bind : ssl no-sslv3 no-tlsv10 crt +/etc/letsencrypt/live//.pem + server localhost 127.0.0.1: + timeout client 10m + timeout server 10m + timeout connect 5m + +listen evennia-secure-websocket + bind : ssl no-sslv3 no-tlsv10 crt +/etc/letsencrypt/live//.pem + server localhost 127.0.0.1: + timeout client 10m + timeout server 10m + timeout connect 5m +``` + +## Putting it all together + +Get back to the Evennia game dir and edit mygame/server/conf/settings.py. Add: + +``` +WEBSERVER_INTERFACES = ['127.0.0.1'] +WEBSOCKET_CLIENT_INTERFACE = '127.0.0.1' +``` +and +``` +WEBSOCKET_CLIENT_URL="wss://fullhost.domain.name:4002/" +``` + +Make sure to reboot (stop + start) evennia completely: + +``` +evennia reboot +``` + + +Finally you start the proxy: + +``` +sudo haproxy -f /path/to/the/above/config_file.cfg +``` + +Make sure you can connect to your game from your browser and that you end up with an `https://` page +and can use the websocket webclient. + +Once everything works you may want to start the proxy automatically and in the background. Stop the +proxy with `Ctrl-C` and uncomment the line `# daemon` in the config file, then start the proxy again +- it will now start in the bacground. + +You may also want to have the proxy start automatically; this you can do with `cron`, the inbuilt +Linux mechanism for running things at specific times. + +``` +sudo crontab -e +``` + +Choose your editor and add a new line at the end of the crontab file that opens: + +``` +@reboot haproxy -f /path/to/the/above/config_file.cfg +``` + +Save the file and haproxy should start up automatically when you reboot the server. \ No newline at end of file diff --git a/docs/source/Help-System-Tutorial.md b/docs/source/Help-System-Tutorial.md index 95e485d648..c191838bd0 100644 --- a/docs/source/Help-System-Tutorial.md +++ b/docs/source/Help-System-Tutorial.md @@ -1,9 +1,12 @@ # Help System Tutorial -**Before doing this tutorial you will probably want to read the intro in [Basic Web tutorial](./Web-Tutorial).** Reading the three first parts of the [Django tutorial](https://docs.djangoproject.com/en/1.9/intro/tutorial01/) might help as well. +**Before doing this tutorial you will probably want to read the intro in [Basic Web tutorial](Web- +Tutorial).** Reading the three first parts of the [Django +tutorial](https://docs.djangoproject.com/en/2.2/) might help as well. -This tutorial will show you how to access the help system through your website. Both help commands and regular help entries will be visible, depending on the logged-in user or an anonymous character. +This tutorial will show you how to access the help system through your website. Both help commands +and regular help entries will be visible, depending on the logged-in user or an anonymous character. This tutorial will show you how to: @@ -14,15 +17,23 @@ This tutorial will show you how to: ## Creating our app -The first step is to create our new Django *app*. An app in Django can contain pages and mechanisms: your website may contain different apps. Actually, the website provided out-of-the-box by Evennia has already three apps: a "webclient" app, to handle the entire webclient, a "website" app to contain your basic pages, and a third app provided by Django to create a simple admin interface. So we'll create another app in parallel, giving it a clear name to represent our help system. +The first step is to create our new Django *app*. An app in Django can contain pages and +mechanisms: your website may contain different apps. Actually, the website provided out-of-the-box +by Evennia has already three apps: a "webclient" app, to handle the entire webclient, a "website" +app to contain your basic pages, and a third app provided by Django to create a simple admin +interface. So we'll create another app in parallel, giving it a clear name to represent our help +system. From your game directory, use the following command: evennia startapp help_system -> Note: calling the app "help" would have been more explicit, but this name is already used by Django. +> Note: calling the app "help" would have been more explicit, but this name is already used by +Django. -This will create a directory named `help_system` at the root of your game directory. It's a good idea to keep things organized and move this directory in the "web" directory of your game. Your game directory should look like: +This will create a directory named `help_system` at the root of your game directory. It's a good +idea to keep things organized and move this directory in the "web" directory of your game. Your +game directory should look like: mygame/ ... @@ -30,9 +41,13 @@ This will create a directory named `help_system` at the root of your game direct help_system/ ... -The "web/help_system" directory contains files created by Django. We'll use some of them, but if you want to learn more about them all, you should read [the Django tutorial](https://docs.djangoproject.com/en/1.9/intro/tutorial01/). +The "web/help_system" directory contains files created by Django. We'll use some of them, but if +you want to learn more about them all, you should read [the Django +tutorial](https://docs.djangoproject.com/en/1.9/intro/tutorial01/). -There is a last thing to be done: your folder has been added, but Django doesn't know about it, it doesn't know it's a new app. We need to tell it, and we do so by editing a simple setting. Open your "server/conf/settings.py" file and add, or edit, these lines: +There is a last thing to be done: your folder has been added, but Django doesn't know about it, it +doesn't know it's a new app. We need to tell it, and we do so by editing a simple setting. Open +your "server/conf/settings.py" file and add, or edit, these lines: ```python # Web configuration @@ -41,23 +56,30 @@ INSTALLED_APPS += ( ) ``` -You can start Evennia if you want, and go to your website, probably at [http://localhost:4001](http://localhost:4001) . You won't see anything different though: we added the app but it's fairly empty. +You can start Evennia if you want, and go to your website, probably at +[http://localhost:4001](http://localhost:4001) . You won't see anything different though: we added +the app but it's fairly empty. ## Our new page -At this point, our new *app* contains mostly empty files that you can explore. In order to create a page for our help system, we need to add: +At this point, our new *app* contains mostly empty files that you can explore. In order to create +a page for our help system, we need to add: - A *view*, dealing with the logic of our page. - A *template* to display our new page. - A new *URL* pointing to our page. -> We could get away by creating just a view and a new URL, but that's not a recommended way to work with your website. Building on templates is so much more convenient. +> We could get away by creating just a view and a new URL, but that's not a recommended way to work +with your website. Building on templates is so much more convenient. ### Create a view -A *view* in Django is a simple Python function placed in the "views.py" file in your app. It will handle the behavior that is triggered when a user asks for this information by entering a *URL* (the connection between *views* and *URLs* will be discussed later). +A *view* in Django is a simple Python function placed in the "views.py" file in your app. It will +handle the behavior that is triggered when a user asks for this information by entering a *URL* (the +connection between *views* and *URLs* will be discussed later). -So let's create our view. You can open the "web/help_system/view.py" file and paste the following lines: +So let's create our view. You can open the "web/help_system/views.py" file and paste the following +lines: ```python from django.shortcuts import render @@ -67,11 +89,16 @@ def index(request): return render(request, "help_system/index.html") ``` -Our view handles all code logic. This time, there's not much: when this function is called, it will render the template we will now create. But that's where we will do most of our work afterward. +Our view handles all code logic. This time, there's not much: when this function is called, it will +render the template we will now create. But that's where we will do most of our work afterward. ### Create a template -The `render` function called into our *view* asks the *template* `help_system/index.html`. The *templates* of our apps are stored in the app directory, "templates" sub-directory. Django may have created the "templates" folder already. If not, create it yourself. In it, create another folder "help_system", and inside of this folder, create a file named "index.html". Wow, that's some hierarchy. Your directory structure (starting from `web`) should look like this: +The `render` function called into our *view* asks the *template* `help_system/index.html`. The +*templates* of our apps are stored in the app directory, "templates" sub-directory. Django may have +created the "templates" folder already. If not, create it yourself. In it, create another folder +"help_system", and inside of this folder, create a file named "index.html". Wow, that's some +hierarchy. Your directory structure (starting from `web`) should look like this: web/ help_system/ @@ -92,48 +119,62 @@ Open the "index.html" file and paste in the following lines: Here's a little explanation line by line of what this template does: -1. It loads the "base.html" *template*. This describes the basic structure of all your pages, with a menu at the top and a footer, and perhaps other information like images and things to be present on each page. You can create templates that do not inherit from "base.html", but you should have a good reason for doing so. -2. The "base.html" *template* defines all the structure of the page. What is left is to override some sections of our pages. These sections are called *blocks*. On line 2, we override the block named "blocktitle", which contains the title of our page. -3. Same thing here, we override the *block* named "content", which contains the main content of our web page. This block is bigger, so we define it on several lines. +1. It loads the "base.html" *template*. This describes the basic structure of all your pages, with +a menu at the top and a footer, and perhaps other information like images and things to be present +on each page. You can create templates that do not inherit from "base.html", but you should have a +good reason for doing so. +2. The "base.html" *template* defines all the structure of the page. What is left is to override +some sections of our pages. These sections are called *blocks*. On line 2, we override the block +named "blocktitle", which contains the title of our page. +3. Same thing here, we override the *block* named "content", which contains the main content of our +web page. This block is bigger, so we define it on several lines. 4. This is perfectly normal HTML code to display a level-2 heading. 5. And finally we close the *block* named "content". ### Create a new URL -Last step to add our page: we need to add a *URL* leading to it... otherwise users won't be able to access it. The URLs of our apps are stored in the app's directory "urls.py" file. +Last step to add our page: we need to add a *URL* leading to it... otherwise users won't be able to +access it. The URLs of our apps are stored in the app's directory "urls.py" file. Open the "web/help_system/urls.py" file (you might have to create it) and write in it: ```python # URL patterns for the help_system app -from django.conf.urls import url +from django.urls import include, path from web.help_system.views import index urlpatterns = [ - url(r'^$', index, name="index") + path(r'', index, name="help-index") ] ``` -We also need to add our app as a namespace holder for URLS. Edit the file "web/urls.py". In it you will find the `custom_patterns` variable. Replace it with: +We also need to add our app as a namespace holder for URLS. Edit the file "web/urls.py" (you might +have to create this one too). In it you will find the `custom_patterns` variable. Replace it with: ```python custom_patterns = [ - url(r'^help/', include('web.help_system.urls', - namespace='help_system', app_name='help_system')), + path(r'help_system/', include('web.help_system.urls')), ] ``` When a user will ask for a specific *URL* on your site, Django will: -1. Read the list of custom patterns defined in "web/urls.py". There's one pattern here, which describes to Django that all URLs beginning by 'help/' should be sent to the 'help_system' app. The 'help/' part is removed. -2. Then Django will check the "web.help_system/urls.py" file. It contains only one URL, which is empty (`^$`). +1. Read the list of custom patterns defined in "web/urls.py". There's one pattern here, which +describes to Django that all URLs beginning by 'help/' should be sent to the 'help_system' app. The +'help/' part is removed. +2. Then Django will check the "web.help_system/urls.py" file. It contains only one URL, which is +empty. In other words, if the URL is '/help/', then Django will execute our defined view. ### Let's see it work -You can now reload or start Evennia. Open a tab in your browser and go to [http://localhost:4001/help/](http://localhost:4001/help/) . If everything goes well, you should see your new page... which isn't empty since Evennia uses our "base.html" *template*. In the content of our page, there's only a heading that reads "help index". Notice that the title of our page is "mygame - Help index" ("mygame" is replaced by the name of your game). +You can now reload or start Evennia. Open a tab in your browser and go to +[http://localhost:4001/help_system/](http://localhost:4001/help_system/) . If everything goes well, +you should see your new page... which isn't empty since Evennia uses our "base.html" *template*. In +the content of our page, there's only a heading that reads "help index". Notice that the title of +our page is "mygame - Help index" ("mygame" is replaced by the name of your game). From now on, it will be easier to move forward and add features. @@ -153,17 +194,31 @@ The first one would link to the second. > Should we create two URLs? -The answer is... maybe. It depends on what you want to do. We have our help index accessible through the "/help/" URL. We could have the detail of a help entry accessible through "/help/desc" (to see the detail of the "desc" command). The problem is that our commands or help topics may contain special characters that aren't to be present in URLs. There are different ways around this problem. I have decided to use a *GET variable* here, which would create URLs like this: +The answer is... maybe. It depends on what you want to do. We have our help index accessible +through the "/help_system/" URL. We could have the detail of a help entry accessible through +"/help_system/desc" (to see the detail of the "desc" command). The problem is that our commands or +help topics may contain special characters that aren't to be present in URLs. There are different +ways around this problem. I have decided to use a *GET variable* here, which would create URLs like +this: - /help?name=desc + /help_system?name=desc -If you use this system, you don't have to add a new URL: GET and POST variables are accessible through our requests and we'll see how soon enough. +If you use this system, you don't have to add a new URL: GET and POST variables are accessible +through our requests and we'll see how soon enough. ## Handling logged-in users -One of our requirements is to have a help system tailored to our accounts. If an account with admin access logs in, the page should display a lot of commands that aren't accessible to common users. And perhaps even some additional help topics. +One of our requirements is to have a help system tailored to our accounts. If an account with admin +access logs in, the page should display a lot of commands that aren't accessible to common users. +And perhaps even some additional help topics. -Fortunately, it's fairly easy to get the logged in account in our view (remember that we'll do most of our coding there). The *request* object, passed to our function, contains a `user` attribute. This attribute will always be there: we cannot test whether it's `None` or not, for instance. But when the request comes from a user that isn't logged in, the `user` attribute will contain an anonymous Django user. We then can use the `is_anonymous` method to see whether the user is logged-in or not. Last gift by Evennia, if the user is logged in, `request.user` contains a reference to an account object, which will help us a lot in coupling the game and online system. +Fortunately, it's fairly easy to get the logged in account in our view (remember that we'll do most +of our coding there). The *request* object, passed to our function, contains a `user` attribute. +This attribute will always be there: we cannot test whether it's `None` or not, for instance. But +when the request comes from a user that isn't logged in, the `user` attribute will contain an +anonymous Django user. We then can use the `is_anonymous` method to see whether the user is logged- +in or not. Last gift by Evennia, if the user is logged in, `request.user` contains a reference to +an account object, which will help us a lot in coupling the game and online system. So we might end up with something like: @@ -175,7 +230,8 @@ def index(request): character = user.character ``` -> Note: this code works when your MULTISESSION_MODE is set to 0 or 1. When it's above, you would have something like: +> Note: this code works when your MULTISESSION_MODE is set to 0 or 1. When it's above, you would +have something like: ```python def index(request): @@ -187,7 +243,9 @@ def index(request): In this second case, it will select the first character of the account. -But what if the user's not logged in? Again, we have different solutions. One of the most simple is to create a character that will behave as our default character for the help system. You can create it through your game: connect to it and enter: +But what if the user's not logged in? Again, we have different solutions. One of the most simple +is to create a character that will behave as our default character for the help system. You can +create it through your game: connect to it and enter: @charcreate anonymous @@ -209,13 +267,16 @@ def index(request): character = Character.objects.get(db_key="anonymous") ``` -This time, we have a valid character no matter what: remember to adapt this code if you're running in multisession mode above 1. +This time, we have a valid character no matter what: remember to adapt this code if you're running +in multisession mode above 1. ## The full system -What we're going to do is to browse through all commands and help entries, and list all the commands that can be seen by this character (either our 'anonymous' character, or our logged-in character). +What we're going to do is to browse through all commands and help entries, and list all the commands +that can be seen by this character (either our 'anonymous' character, or our logged-in character). -The code is longer, but it presents the entire concept in our view. Edit the "web/help_system/views.py" file and paste into it: +The code is longer, but it presents the entire concept in our view. Edit the +"web/help_system/views.py" file and paste into it: ```python from django.http import Http404 @@ -310,16 +371,25 @@ That's a bit more complicated here, but all in all, it can be divided in small c - The `index` function is our view: - It begins by getting the character as we saw in the previous section. - - It gets the help topics (commands and help entries) accessible to this character. It's another function that handles that part. - - If there's a *GET variable* "name" in our URL (like "/help?name=drop"), it will retrieve it. If it's not a valid topic's name, it returns a *404*. Otherwise, it renders the template called "detail.html", to display the detail of our topic. + - It gets the help topics (commands and help entries) accessible to this character. It's another +function that handles that part. + - If there's a *GET variable* "name" in our URL (like "/help?name=drop"), it will retrieve it. If +it's not a valid topic's name, it returns a *404*. Otherwise, it renders the template called +"detail.html", to display the detail of our topic. - If there's no *GET variable* "name", render "index.html", to display the list of topics. -- The `_get_topics` is a private function. Its sole mission is to retrieve the commands a character can execute, and the help entries this same character can see. This code is more Evennia-specific than Django-specific, it will not be detailed in this tutorial. Just notice that all help topics are stored in a dictionary. This is to simplify our job when displaying them in our templates. +- The `_get_topics` is a private function. Its sole mission is to retrieve the commands a character +can execute, and the help entries this same character can see. This code is more Evennia-specific +than Django-specific, it will not be detailed in this tutorial. Just notice that all help topics +are stored in a dictionary. This is to simplify our job when displaying them in our templates. -Notice that, in both cases when we asked to render a *template*, we passed to `render` a third argument which is the dictionary of variables used in our templates. We can pass variables this way, and we will use them in our templates. +Notice that, in both cases when we asked to render a *template*, we passed to `render` a third +argument which is the dictionary of variables used in our templates. We can pass variables this +way, and we will use them in our templates. ### The index template -Let's look at our full "index" *template*. You can open the "web/help_system/templates/help_sstem/index.html" file and paste the following into it: +Let's look at our full "index" *template*. You can open the +"web/help_system/templates/help_system/index.html" file and paste the following into it: ``` {% extends "base.html" %} @@ -336,7 +406,7 @@ Let's look at our full "index" *template*. You can open the "web/help_system/te {% endif %} - + {{ topic.name }} {% endfor %} @@ -350,12 +420,17 @@ This template is definitely more detailed. What it does is: 1. Browse through all categories. 2. For all categories, display a level-2 heading with the name of the category. -3. All topics in a category (remember, they can be either commands or help entries) are displayed in a table. The trickier part may be that, when the loop is above 5, it will create a new line. The table will have 5 columns at the most per row. -4. For every cell in the table, we create a link redirecting to the detail page (see below). The URL would look something like "help?name=say". We use `urlencode` to ensure special characters are properly escaped. +3. All topics in a category (remember, they can be either commands or help entries) are displayed in +a table. The trickier part may be that, when the loop is above 5, it will create a new line. The +table will have 5 columns at the most per row. +4. For every cell in the table, we create a link redirecting to the detail page (see below). The +URL would look something like "help?name=say". We use `urlencode` to ensure special characters are +properly escaped. ### The detail template -It's now time to show the detail of a topic (command or help entry). You can create the file "web/help_system/templates/help_system/detail.html". You can paste into it the following code: +It's now time to show the detail of a topic (command or help entry). You can create the file +"web/help_system/templates/help_system/detail.html". You can paste into it the following code: ``` {% extends "base.html" %} @@ -367,17 +442,26 @@ It's now time to show the detail of a topic (command or help entry). You can cr {% endblock %} ``` -This template is much easier to read. Some *filters* might be unknown to you, but they are just used to format here. +This template is much easier to read. Some *filters* might be unknown to you, but they are just +used to format here. ### Put it all together -Remember to reload or start Evennia, and then go to [http://localhost:4001/help](http://localhost:4001/help/). You should see the list of commands and topics accessible by all characters. Try to login (click the "login" link in the menu of your website) and go to the same page again. You should now see a more detailed list of commands and help entries. Click on one to see its detail. +Remember to reload or start Evennia, and then go to +[http://localhost:4001/help_system](http://localhost:4001/help_system/). You should see the list of +commands and topics accessible by all characters. Try to login (click the "login" link in the menu +of your website) and go to the same page again. You should now see a more detailed list of commands +and help entries. Click on one to see its detail. ## To improve this feature -As always, a tutorial is here to help you feel comfortable adding new features and code by yourself. Here are some ideas of things to improve this little feature: +As always, a tutorial is here to help you feel comfortable adding new features and code by yourself. +Here are some ideas of things to improve this little feature: - Links at the bottom of the detail template to go back to the index might be useful. -- A link in the main menu to link to this page would be great... for the time being you have to enter the URL, users won't guess it's there. +- A link in the main menu to link to this page would be great... for the time being you have to +enter the URL, users won't guess it's there. - Colors aren't handled at this point, which isn't exactly surprising. You could add it though. -- Linking help entries between one another won't be simple, but it would be great. For instance, if you see a help entry about how to use several commands, it would be great if these commands were themselves links to display their details. +- Linking help entries between one another won't be simple, but it would be great. For instance, if +you see a help entry about how to use several commands, it would be great if these commands were +themselves links to display their details. diff --git a/docs/source/Help-System.md b/docs/source/Help-System.md index 5e27174003..47d2c8d906 100644 --- a/docs/source/Help-System.md +++ b/docs/source/Help-System.md @@ -1,31 +1,46 @@ # Help System -An important part of Evennia is the online help system. This allows the players and staff alike to learn how to use the game's commands as well as other information pertinent to the game. The help system has many different aspects, from the normal editing of help entries from inside the game, to auto-generated help entries during code development using the *auto-help system*. +An important part of Evennia is the online help system. This allows the players and staff alike to +learn how to use the game's commands as well as other information pertinent to the game. The help +system has many different aspects, from the normal editing of help entries from inside the game, to +auto-generated help entries during code development using the *auto-help system*. ## Viewing the help database -The main command is `help`: +The main command is `help`: help [searchstring] -This will show a list of help entries, ordered after categories. You will find two sections, *Command help entries* and *Other help entries* (initially you will only have the first one). You can use help to get more info about an entry; you can also give partial matches to get suggestions. If you give category names you will only be shown the topics in that category. +This will show a list of help entries, ordered after categories. You will find two sections, +*Command help entries* and *Other help entries* (initially you will only have the first one). You +can use help to get more info about an entry; you can also give partial matches to get suggestions. +If you give category names you will only be shown the topics in that category. ## Command Auto-help system -A common item that requires help entries are in-game commands. Keeping these entries up-to-date with the actual source code functionality can be a chore. Evennia's commands are therefore auto-documenting straight from the sources through its *auto-help system*. Only commands that you and your character can actually currently use are picked up by the auto-help system. That means an admin will see a considerably larger amount of help topics than a normal player when using the default `help` command. +A common item that requires help entries are in-game commands. Keeping these entries up-to-date with +the actual source code functionality can be a chore. Evennia's commands are therefore auto- +documenting straight from the sources through its *auto-help system*. Only commands that you and +your character can actually currently use are picked up by the auto-help system. That means an admin +will see a considerably larger amount of help topics than a normal player when using the default +`help` command. -The auto-help system uses the `__doc__` strings of your command classes and formats this to a nice-looking help entry. This makes for a very easy way to keep the help updated - just document your commands well and updating the help file is just a `@reload` away. There is no need to manually create and maintain help database entries for commands; as long as you keep the docstrings updated your help will be dynamically updated for you as well. +The auto-help system uses the `__doc__` strings of your command classes and formats this to a nice- +looking help entry. This makes for a very easy way to keep the help updated - just document your +commands well and updating the help file is just a `@reload` away. There is no need to manually +create and maintain help database entries for commands; as long as you keep the docstrings updated +your help will be dynamically updated for you as well. -Example (from a module with command definitions): +Example (from a module with command definitions): ```python class CmdMyCmd(Command): """ mycmd - my very own command - Usage: + Usage: mycmd[/switches] Switches: @@ -43,44 +58,65 @@ Example (from a module with command definitions): # [...] ``` -The text at the very top of the command class definition is the class' `__doc__`-string and will be shown to users looking for help. Try to use a consistent format - all default commands are using the structure shown above. +The text at the very top of the command class definition is the class' `__doc__`-string and will be +shown to users looking for help. Try to use a consistent format - all default commands are using the +structure shown above. -You should also supply the `help_category` class property if you can; this helps to group help entries together for people to more easily find them. See the `help` command in-game to see the default categories. If you don't specify the category, "General" is assumed. +You should also supply the `help_category` class property if you can; this helps to group help +entries together for people to more easily find them. See the `help` command in-game to see the +default categories. If you don't specify the category, "General" is assumed. -If you don't want your command to be picked up by the auto-help system at all (like if you want to write its docs manually using the info in the next section or you use a [cmdset](./Command-Sets) that has its own help functionality) you can explicitly set `auto_help` class property to `False` in your command definition. +If you don't want your command to be picked up by the auto-help system at all (like if you want to +write its docs manually using the info in the next section or you use a [cmdset](./Command-Sets) that +has its own help functionality) you can explicitly set `auto_help` class property to `False` in your +command definition. -Alternatively, you can keep the advantages of *auto-help* in commands, but control the display of command helps. You can do so by overriding the command's `get_help()` method. By default, this method will return the class docstring. You could modify it to add custom behavior: the text returned by this method will be displayed to the character asking for help in this command. +Alternatively, you can keep the advantages of *auto-help* in commands, but control the display of +command helps. You can do so by overriding the command's `get_help()` method. By default, this +method will return the class docstring. You could modify it to add custom behavior: the text +returned by this method will be displayed to the character asking for help in this command. ## Database help entries -These are all help entries not involving commands (this is handled automatically by the [Command Auto-help system](./Help-System#command-auto-help-system)). Non-automatic help entries describe how your particular game is played - its rules, world descriptions and so on. +These are all help entries not involving commands (this is handled automatically by the [Command +Auto-help system](Help-System#command-auto-help-system)). Non-automatic help entries describe how +your particular game is played - its rules, world descriptions and so on. -A help entry consists of four parts: +A help entry consists of four parts: -- The *topic*. This is the name of the help entry. This is what players search for when they are looking for help. The topic can contain spaces and also partial matches will be found. -- The *help category*. Examples are *Administration*, *Building*, *Comms* or *General*. This is an overall grouping of similar help topics, used by the engine to give a better overview. +- The *topic*. This is the name of the help entry. This is what players search for when they are +looking for help. The topic can contain spaces and also partial matches will be found. +- The *help category*. Examples are *Administration*, *Building*, *Comms* or *General*. This is an +overall grouping of similar help topics, used by the engine to give a better overview. - The *text* - the help text itself, of any length. -- locks - a [lock definition](./Locks). This can be used to limit access to this help entry, maybe because it's staff-only or otherwise meant to be restricted. Help commands check for `access_type`s `view` and `edit`. An example of a lock string would be `view:perm(Builders)`. +- locks - a [lock definition](./Locks). This can be used to limit access to this help entry, maybe +because it's staff-only or otherwise meant to be restricted. Help commands check for `access_type`s +`view` and `edit`. An example of a lock string would be `view:perm(Builders)`. You can create new help entries in code by using `evennia.create_help_entry()`. ```python from evennia import create_help_entry -entry = create_help_entry("emote", - "Emoting is important because ...", +entry = create_help_entry("emote", + "Emoting is important because ...", category="Roleplaying", locks="view:all()") ``` -From inside the game those with the right permissions can use the `@sethelp` command to add and modify help entries. +From inside the game those with the right permissions can use the `@sethelp` command to add and +modify help entries. > @sethelp/add emote = The emote command is ... -Using `@sethelp` you can add, delete and append text to existing entries. By default new entries will go in the *General* help category. You can change this using a different form of the `@sethelp` command: +Using `@sethelp` you can add, delete and append text to existing entries. By default new entries +will go in the *General* help category. You can change this using a different form of the `@sethelp` +command: > @sethelp/add emote, Roleplaying = Emoting is important because ... -If the category *Roleplaying* did not already exist, it is created and will appear in the help index. +If the category *Roleplaying* did not already exist, it is created and will appear in the help +index. -You can, finally, define a lock for the help entry by following the category with a [lock definition](./Locks): +You can, finally, define a lock for the help entry by following the category with a [lock +definition](Locks): - > @sethelp/add emote, Roleplaying, view:all() = Emoting is ... + > @sethelp/add emote, Roleplaying, view:all() = Emoting is ... diff --git a/docs/source/How-To-Get-And-Give-Help.md b/docs/source/How-To-Get-And-Give-Help.md index ee382df329..03de9701b7 100644 --- a/docs/source/How-To-Get-And-Give-Help.md +++ b/docs/source/How-To-Get-And-Give-Help.md @@ -3,36 +3,71 @@ ### How to *get* Help -If you cannot find what you are looking for in the [online documentation]([online documentation](index)), here's what to do: +If you cannot find what you are looking for in the [online documentation](./index), here's what to do: -- If you think the documentation is not clear enough and are short on time, fill in our quick little [online form][form] and let us know - no login required. Maybe the docs need to be improved or a new tutorial added! Note that while this form is useful as a suggestion box we cannot answer questions or reply to you. Use the discussion group or chat (linked below) if you want feedback. -- If you have trouble with a missing feature or a problem you think is a bug, go to the [issue tracker][issues] and search to see if has been reported/suggested already. If you can't find an existing entry create a new one. -- If you need help, want to start a discussion or get some input on something you are working on, make a post to the [discussions group][group] This is technically a 'mailing list', but you don't need to use e-mail; you can post and read all messages just as easily from your browser via the online interface. -- If you want more direct discussions with developers and other users, consider dropping into our IRC chat channel [#evennia][chat] on the *Freenode* network. Please note however that you have to be patient if you don't get any response immediately; we are all in very different time zones and many have busy personal lives. So you might have to hang around for a while - you'll get noticed eventually! +- If you think the documentation is not clear enough and are short on time, fill in our quick little +[online form][form] and let us know - no login required. Maybe the docs need to be improved or a new +tutorial added! Note that while this form is useful as a suggestion box we cannot answer questions +or reply to you. Use the discussion group or chat (linked below) if you want feedback. +- If you have trouble with a missing feature or a problem you think is a bug, go to the +[issue tracker][issues] and search to see if has been reported/suggested already. If you can't find an +existing entry create a new one. +- If you need help, want to start a discussion or get some input on something you are working on, +make a post to the [discussions group][group] This is technically a 'mailing list', but you don't +need to use e-mail; you can post and read all messages just as easily from your browser via the +online interface. +- If you want more direct discussions with developers and other users, consider dropping into our +IRC chat channel [#evennia][chat] on the *Freenode* network. Please note however that you have to be +patient if you don't get any response immediately; we are all in very different time zones and many +have busy personal lives. So you might have to hang around for a while - you'll get noticed +eventually! ### How to *give* Help -Evennia is a completely non-funded project. It relies on the time donated by its users and developers in order to progress. +Evennia is a completely non-funded project. It relies on the time donated by its users and +developers in order to progress. -The first and easiest way you as a user can help us out is by taking part in [community discussions][group] and by giving feedback on what is good or bad. Report bugs you find and features you lack to our [issue tracker][issues]. Just the simple act of letting developers know you are out there using their program is worth a lot. Generally mentioning and reviewing Evennia elsewhere is also a nice way to spread the word. +The first and easiest way you as a user can help us out is by taking part in [community +discussions][group] and by giving feedback on what is good or bad. Report bugs you find and features +you lack to our [issue tracker][issues]. Just the simple act of letting developers know you are out +there using their program is worth a lot. Generally mentioning and reviewing Evennia elsewhere is +also a nice way to spread the word. If you'd like to help develop Evennia more hands-on, here are some ways to get going: -- Look through our [online documentation wiki]([online documentation wiki](index)) and see if you can help improve or expand the documentation (even small things like fixing typos!). You don't need any particular permissions to edit the wiki. -- Send a message to our [discussion group][group] and/or our [IRC chat][chat] asking about what needs doing, along with what your interests and skills are. -- Take a look at our [issue tracker][issues] and see if there's something you feel like taking on. [here are bugs][issues-master] that need fixes. At any given time there may also be some [bounties][issues-bounties] open - these are issues members of the community has put up money to see fixed (if you want to put up a bounty yourself you can do so via our page on [bountysource][bountysource]). -- Check out the [Contributing](./Contributing) page on how to practically contribute with code using github. +- Look through our [online documentation wiki](./index) and see if you +can help improve or expand the documentation (even small things like fixing typos!). You don't need +any particular permissions to edit the wiki. +- Send a message to our [discussion group][group] and/or our [IRC chat][chat] asking about what +needs doing, along with what your interests and skills are. +- Take a look at our [issue tracker][issues] and see if there's something you feel like taking on. +[here are bugs][issues-master] that need fixes. At any given time there may also be some +[bounties][issues-bounties] open - these are issues members of the community has put up money to see +fixed (if you want to put up a bounty yourself you can do so via our page on +[bountysource][bountysource]). +- Check out the [Contributing](./Contributing) page on how to practically contribute with code using +github. -... And finally, if you want to help motivate and support development you can also drop some coins in the developer's cup. You can [make a donation via PayPal][paypal] or, even better, [become an Evennia patron on Patreon][patreon]! This is a great way to tip your hat and show that you appreciate the work done with the server! Finally, if you want to encourage the community to resolve a particular +... And finally, if you want to help motivate and support development you can also drop some coins +in the developer's cup. You can [make a donation via PayPal][paypal] or, even better, [become an +Evennia patron on Patreon][patreon]! This is a great way to tip your hat and show that you +appreciate the work done with the server! Finally, if you want to encourage the community to resolve +a particular -[form]: https://docs.google.com/spreadsheet/viewform?hl=en_US&formkey=dGN0VlJXMWpCT3VHaHpscDEzY1RoZGc6MQ#gid=0 +[form]: https://docs.google.com/spreadsheet/viewform?hl=en_US&formkey=dGN0VlJXMWpCT3VHaHpscDEzY1RoZG +c6MQ#gid=0 [group]: http://groups.google.com/group/evennia/ [issues]: https://github.com/evennia/evennia/issues -[issues-master]: https://github.com/evennia/evennia/issues?utf8=%E2%9C%93&q=is%3Aissue%20is%3Aopen%20label%3Abug%20label%3Amaster-branch +[issues-master]: https://github.com/evennia/evennia/issues?utf8=%E2%9C%93&q=is%3Aissue%20is%3Aopen%2 +0label%3Abug%20label%3Amaster-branch [chat]: http://webchat.freenode.net/?channels=evennia -[paypal]: https://www.paypal.com/se/cgi-bin/webscr?cmd=_flow&SESSION=Z-VlOvfGjYq2qvCDOUGpb6C8Due7skT0qOklQEy5EbaD1f0eyEQaYlmCc8O&dispatch=5885d80a13c0db1f8e263663d3faee8d64ad11bbf4d2a5a1a0d303a50933f9b2 -[donate-img]: http://images-focus-opensocial.googleusercontent.com/gadgets/proxy?url=https://www.paypalobjects.com/en%255fUS/SE/i/btn/btn%255fdonateCC%255fLG.gif&container=focus&gadget=a&rewriteMime=image/* +[paypal]: https://www.paypal.com/se/cgi-bin/webscr?cmd=_flow&SESSION=Z-VlOvfGjYq2qvCDOUGpb6C8Due7skT +0qOklQEy5EbaD1f0eyEQaYlmCc8O&dispatch=5885d80a13c0db1f8e263663d3faee8d64ad11bbf4d2a5a1a0d303a50933f9 +b2 +[donate-img]: http://images-focus-opensocial.googleusercontent.com/gadgets/proxy?url=https://www.pay +palobjects.com/en%255fUS/SE/i/btn/btn%255fdonateCC%255fLG.gif&container=focus&gadget=a&rewriteMime=i +mage/* [patreon]: https://www.patreon.com/griatch [patreon-img]: http://www.evennia.com/_/rsrc/1424724909023/home/evennia_patreon_100x100.png [issues-bounties]: https://github.com/evennia/evennia/labels/bounty diff --git a/docs/source/How-to-connect-Evennia-to-Twitter.md b/docs/source/How-to-connect-Evennia-to-Twitter.md index 314241da2d..0abab35bf6 100644 --- a/docs/source/How-to-connect-Evennia-to-Twitter.md +++ b/docs/source/How-to-connect-Evennia-to-Twitter.md @@ -1,15 +1,22 @@ # How to connect Evennia to Twitter -[Twitter](http://en.wikipedia.org/wiki/twitter) is an online social networking service that enables users to send and read short 280-character messages called "tweets". Following is a short tutorial explaining how to enable users to send tweets from inside Evennia. +[Twitter](http://en.wikipedia.org/wiki/twitter) is an online social networking service that enables +users to send and read short 280-character messages called "tweets". Following is a short tutorial +explaining how to enable users to send tweets from inside Evennia. ## Configuring Twitter -You must first have a Twitter account. Log in and register an App at the [Twitter Dev Site](https://apps.twitter.com/). Make sure you enable access to "write" tweets! +You must first have a Twitter account. Log in and register an App at the [Twitter Dev +Site](https://apps.twitter.com/). Make sure you enable access to "write" tweets! -To tweet from Evennia you will need both the "API Token" and the "API secret" strings as well as the "Access Token" and "Access Secret" strings. +To tweet from Evennia you will need both the "API Token" and the "API secret" strings as well as the +"Access Token" and "Access Secret" strings. -Twitter changed their requirements to require a Mobile number on the Twitter account to register new apps with write access. If you're unable to do this, please see [this Dev post](https://dev.twitter.com/notifications/new-apps-registration) which describes how to get around it. +Twitter changed their requirements to require a Mobile number on the Twitter account to register new +apps with write access. If you're unable to do this, please see [this Dev +post](https://dev.twitter.com/notifications/new-apps-registration) which describes how to get around +it. ## Install the twitter python module @@ -21,11 +28,15 @@ pip install python-twitter ## A basic tweet command -Evennia doesn't have a `tweet` command out of the box so you need to write your own little [Command](./Commands) in order to tweet. If you are unsure about how commands work and how to add them, it can be an idea to go through the [Adding a Command Tutorial](./Adding-Command-Tutorial) before continuing. +Evennia doesn't have a `tweet` command out of the box so you need to write your own little +[Command](./Commands) in order to tweet. If you are unsure about how commands work and how to add +them, it can be an idea to go through the [Adding a Command Tutorial](./Adding-Command-Tutorial) +before continuing. -You can create the command in a separate command module (something like `mygame/commands/tweet.py`) or together with your other custom commands, as you prefer. +You can create the command in a separate command module (something like `mygame/commands/tweet.py`) +or together with your other custom commands, as you prefer. -This is how it can look: +This is how it can look: ```python import twitter @@ -42,11 +53,11 @@ class CmdTweet(Command): """ Tweet a message - Usage: + Usage: tweet This will send a Twitter tweet to a pre-configured Twitter account. - A tweet has a maximum length of 280 characters. + A tweet has a maximum length of 280 characters. """ key = "tweet" @@ -60,7 +71,7 @@ class CmdTweet(Command): tweet = self.args if not tweet: - caller.msg("Usage: tweet ") + caller.msg("Usage: tweet ") return tlen = len(tweet) @@ -68,17 +79,22 @@ class CmdTweet(Command): caller.msg("Your tweet was %i chars long (max 280)." % tlen) return - # post the tweet + # post the tweet TWITTER_API.PostUpdate(tweet) caller.msg("You tweeted:\n%s" % tweet) ``` -Be sure to substitute your own actual API/Access keys and secrets in the appropriate places. +Be sure to substitute your own actual API/Access keys and secrets in the appropriate places. -We default to limiting tweet access to players with `Developers`-level access *or* to those players that have the permission "tweet" (allow individual characters to tweet with `@perm/player playername = tweet`). You may change the [lock](./Locks) as you feel is appropriate. Change the overall permission to `Players` if you want everyone to be able to tweet. +We default to limiting tweet access to players with `Developers`-level access *or* to those players +that have the permission "tweet" (allow individual characters to tweet with `@perm/player playername += tweet`). You may change the [lock](./Locks) as you feel is appropriate. Change the overall +permission to `Players` if you want everyone to be able to tweet. -Now add this command to your default command set (e.g in `mygame/commands/defalt_cmdsets.py`") and reload the server. From now on those with access can simply use `tweet ` to see the tweet posted from the game's Twitter account. +Now add this command to your default command set (e.g in `mygame/commands/defalt_cmdsets.py`") and +reload the server. From now on those with access can simply use `tweet ` to see the tweet +posted from the game's Twitter account. ## Next Steps @@ -89,4 +105,6 @@ This shows only a basic tweet setup, other things to do could be: * Changing locks to make tweeting open to more people * Echo your tweets to an in-game channel -Rather than using an explicit command you can set up a Script to send automatic tweets, for example to post updated game stats. See the [Tweeting Game Stats tutorial](./Tutorial-Tweeting-Game-Stats) for help. +Rather than using an explicit command you can set up a Script to send automatic tweets, for example +to post updated game stats. See the [Tweeting Game Stats tutorial](./Tutorial-Tweeting-Game-Stats) for +help. diff --git a/docs/source/IRC.md b/docs/source/IRC.md index 02013f816e..2b360f3953 100644 --- a/docs/source/IRC.md +++ b/docs/source/IRC.md @@ -1,60 +1,89 @@ # IRC -_Disambiguation: This page is related to using IRC inside an Evennia game. To join the official Evennia IRC chat, connect to irc.freenode.net and join #evennia. Alternatively, you can [join our Discord](https://discord.gg/NecFePw), which is mirrored to IRC._ +_Disambiguation: This page is related to using IRC inside an Evennia game. To join the official +Evennia IRC chat, connect to irc.freenode.net and join #evennia. Alternatively, you can [join our +Discord](https://discord.gg/NecFePw), which is mirrored to IRC._ -[IRC (Internet Relay Chat)](http://en.wikipedia.org/wiki/Internet_Relay_Chat) is a long standing chat protocol used by many open-source projects for communicating in real time. By connecting one of Evennia's [Channels](./Communications) to an IRC channel you can communicate also with people not on an mud themselves. You can also use IRC if you are only running your Evennia MUD locally on your computer (your game doesn't need to be open to the public)! All you need is an internet connection. For IRC operation you also need [twisted.words](http://twistedmatrix.com/trac/wiki/TwistedWords). This is available simply as a package *python-twisted-words* in many Linux distros, or directly downloadable from the link. +[IRC (Internet Relay Chat)](http://en.wikipedia.org/wiki/Internet_Relay_Chat) is a long standing +chat protocol used by many open-source projects for communicating in real time. By connecting one of +Evennia's [Channels](./Communications) to an IRC channel you can communicate also with people not on +an mud themselves. You can also use IRC if you are only running your Evennia MUD locally on your +computer (your game doesn't need to be open to the public)! All you need is an internet connection. +For IRC operation you also need [twisted.words](http://twistedmatrix.com/trac/wiki/TwistedWords). +This is available simply as a package *python-twisted-words* in many Linux distros, or directly +downloadable from the link. ## Configuring IRC -To configure IRC, you'll need to activate it in your settings file. +To configure IRC, you'll need to activate it in your settings file. ```python IRC_ENABLED = True ``` -Start Evennia and log in as a privileged user. You should now have a new command available: `@irc2chan`. This command is called like this: +Start Evennia and log in as a privileged user. You should now have a new command available: +`@irc2chan`. This command is called like this: @irc2chan[/switches] = <#irchannel> -If you already know how IRC works, this should be pretty self-evident to use. Read the help entry for more features. +If you already know how IRC works, this should be pretty self-evident to use. Read the help entry +for more features. ## Setting up IRC, step by step -You can connect IRC to any Evennia channel (so you could connect it to the default *public* channel if you like), but for testing, let's set up a new channel `irc`. +You can connect IRC to any Evennia channel (so you could connect it to the default *public* channel +if you like), but for testing, let's set up a new channel `irc`. @ccreate irc = This is connected to an irc channel! You will automatically join the new channel. -Next we will create a connection to an external IRC network and channel. There are many, many IRC nets. [Here is a list](http://www.irchelp.org/irchelp/networks/popular.html) of some of the biggest ones, the one you choose is not really very important unless you want to connect to a particular channel (also make sure that the network allows for "bots" to connect). +Next we will create a connection to an external IRC network and channel. There are many, many IRC +nets. [Here is a list](http://www.irchelp.org/irchelp/networks/popular.html) of some of the biggest +ones, the one you choose is not really very important unless you want to connect to a particular +channel (also make sure that the network allows for "bots" to connect). -For testing, we choose the *Freenode* network, `irc.freenode.net`. We will connect to a test channel, let's call it *#myevennia-test* (an IRC channel always begins with `#`). It's best if you pick an obscure channel name that didn't exist previously - if it didn't exist it will be created for you. +For testing, we choose the *Freenode* network, `irc.freenode.net`. We will connect to a test +channel, let's call it *#myevennia-test* (an IRC channel always begins with `#`). It's best if you +pick an obscure channel name that didn't exist previously - if it didn't exist it will be created +for you. -> *Don't* connect to `#evennia` for testing and debugging, that is Evennia's official chat channel! You *are* welcome to connect your game to `#evennia` once you have everything working though - it can be a good way to get help and ideas. But if you do, please do so with an in-game channel open only to your game admins and developers). +> *Don't* connect to `#evennia` for testing and debugging, that is Evennia's official chat channel! +You *are* welcome to connect your game to `#evennia` once you have everything working though - it +can be a good way to get help and ideas. But if you do, please do so with an in-game channel open +only to your game admins and developers). The *port* needed depends on the network. For Freenode this is `6667`. -What will happen is that your Evennia server will connect to this IRC channel as a normal user. This "user" (or "bot") needs a name, which you must also supply. Let's call it "mud-bot". +What will happen is that your Evennia server will connect to this IRC channel as a normal user. This +"user" (or "bot") needs a name, which you must also supply. Let's call it "mud-bot". -To test that the bot connects correctly you also want to log onto this channel with a separate, third-party IRC client. There are hundreds of such clients available. If you use Firefox, the *Chatzilla* plugin is good and easy. Freenode also offers its own web-based chat page. Once you have connected to a network, the command to join is usually `/join #channelname` (don't forget the #). +To test that the bot connects correctly you also want to log onto this channel with a separate, +third-party IRC client. There are hundreds of such clients available. If you use Firefox, the +*Chatzilla* plugin is good and easy. Freenode also offers its own web-based chat page. Once you +have connected to a network, the command to join is usually `/join #channelname` (don't forget the +#). Next we connect Evennia with the IRC channel. @irc2chan irc = irc.freenode.net 6667 #myevennia-test mud-bot -Evennia will now create a new IRC bot `mud-bot` and connect it to the IRC network and the channel #myevennia. If you are connected to the IRC channel you will soon see the user *mud-bot* connect. +Evennia will now create a new IRC bot `mud-bot` and connect it to the IRC network and the channel +#myevennia. If you are connected to the IRC channel you will soon see the user *mud-bot* connect. Write something in the Evennia channel *irc*. irc Hello, World! [irc] Anna: Hello, World! -If you are viewing your IRC channel with a separate IRC client you should see your text appearing there, spoken by the bot: +If you are viewing your IRC channel with a separate IRC client you should see your text appearing +there, spoken by the bot: mud-bot> [irc] Anna: Hello, World! -Write `Hello!` in your IRC client window and it will appear in your normal channel, marked with the name of the IRC channel you used (#evennia here). +Write `Hello!` in your IRC client window and it will appear in your normal channel, marked with the +name of the IRC channel you used (#evennia here). [irc] Anna@#myevennia-test: Hello! diff --git a/docs/source/Implementing-a-game-rule-system.md b/docs/source/Implementing-a-game-rule-system.md index 8ef30a5ad3..fc30001a6e 100644 --- a/docs/source/Implementing-a-game-rule-system.md +++ b/docs/source/Implementing-a-game-rule-system.md @@ -36,10 +36,25 @@ We strongly recommend that you code your rule system as stand-alone as possible. spread your skill check code, race bonus calculation, die modifiers or what have you all over your game. -- Put everything you would need to look up in a rule book into a module in `mygame/world`. Hide away as much as you can. Think of it as a black box (or maybe the code representation of an all-knowing game master). The rest of your game will ask this black box questions and get answers back. Exactly how it arrives at those results should not need to be known outside the box. Doing it this way makes it easier to change and update things in one place later. -- Store only the minimum stuff you need with each game object. That is, if your Characters need values for Health, a list of skills etc, store those things on the Character - don't store how to roll or change them. -- Next is to determine just how you want to store things on your Objects and Characters. You can choose to either store things as individual [Attributes](./Attributes), like `character.db.STR=34` and `character.db.Hunting_skill=20`. But you could also use some custom storage method, like a dictionary `character.db.skills = {"Hunting":34, "Fishing":20, ...}`. A much more fancy solution is to look at the Ainneve [Trait handler](https://github.com/evennia/ainneve/blob/master/world/traits.py). Finally you could even go with a [custom django model](./New-Models). Which is the better depends on your game and the complexity of your system. -- Make a clear [API](http://en.wikipedia.org/wiki/Application_programming_interface) into your rules. That is, make methods/functions that you feed with, say, your Character and which skill you want to check. That is, you want something similar to this: +- Put everything you would need to look up in a rule book into a module in `mygame/world`. Hide away +as much as you can. Think of it as a black box (or maybe the code representation of an all-knowing +game master). The rest of your game will ask this black box questions and get answers back. Exactly +how it arrives at those results should not need to be known outside the box. Doing it this way +makes it easier to change and update things in one place later. +- Store only the minimum stuff you need with each game object. That is, if your Characters need +values for Health, a list of skills etc, store those things on the Character - don't store how to +roll or change them. +- Next is to determine just how you want to store things on your Objects and Characters. You can +choose to either store things as individual [Attributes](./Attributes), like `character.db.STR=34` and +`character.db.Hunting_skill=20`. But you could also use some custom storage method, like a +dictionary `character.db.skills = {"Hunting":34, "Fishing":20, ...}`. A much more fancy solution is +to look at the Ainneve [Trait +handler](https://github.com/evennia/ainneve/blob/master/world/traits.py). Finally you could even go +with a [custom django model](./New-Models). Which is the better depends on your game and the +complexity of your system. +- Make a clear [API](http://en.wikipedia.org/wiki/Application_programming_interface) into your +rules. That is, make methods/functions that you feed with, say, your Character and which skill you +want to check. That is, you want something similar to this: ```python from world import rules @@ -47,19 +62,33 @@ game. result = rules.roll_challenge(character1, character2, "swords") ``` -You might need to make these functions more or less complex depending on your game. For example the properties of the room might matter to the outcome of a roll (if the room is dark, burning etc). Establishing just what you need to send into your game mechanic module is a great way to also get a feel for what you need to add to your engine. +You might need to make these functions more or less complex depending on your game. For example the +properties of the room might matter to the outcome of a roll (if the room is dark, burning etc). +Establishing just what you need to send into your game mechanic module is a great way to also get a +feel for what you need to add to your engine. ## Coded systems -Inspired by tabletop role playing games, most game systems mimic some sort of die mechanic. To this end Evennia offers a full [dice roller](https://github.com/evennia/evennia/blob/master/evennia/contrib/dice.py) in its `contrib` folder. For custom implementations, Python offers many ways to randomize a result using its in-built `random` module. No matter how it's implemented, we will in this text refer to the action of determining an outcome as a "roll". +Inspired by tabletop role playing games, most game systems mimic some sort of die mechanic. To this +end Evennia offers a full [dice +roller](https://github.com/evennia/evennia/blob/master/evennia/contrib/dice.py) in its `contrib` +folder. For custom implementations, Python offers many ways to randomize a result using its in-built +`random` module. No matter how it's implemented, we will in this text refer to the action of +determining an outcome as a "roll". -In a freeform system, the result of the roll is just compared with values and people (or the game master) just agree on what it means. In a coded system the result now needs to be processed somehow. There are many things that may happen as a result of rule enforcement: +In a freeform system, the result of the roll is just compared with values and people (or the game +master) just agree on what it means. In a coded system the result now needs to be processed somehow. +There are many things that may happen as a result of rule enforcement: - Health may be added or deducted. This can effect the character in various ways. -- Experience may need to be added, and if a level-based system is used, the player might need to be informed they have increased a level. +- Experience may need to be added, and if a level-based system is used, the player might need to be +informed they have increased a level. - Room-wide effects need to be reported to the room, possibly affecting everyone in the room. -There are also a slew of other things that fall under "Coded systems", including things like weather, NPC artificial intelligence and game economy. Basically everything about the world that a Game master would control in a tabletop role playing game can be mimicked to some level by coded systems. +There are also a slew of other things that fall under "Coded systems", including things like +weather, NPC artificial intelligence and game economy. Basically everything about the world that a +Game master would control in a tabletop role playing game can be mimicked to some level by coded +systems. ## Example of Rule module @@ -67,17 +96,25 @@ There are also a slew of other things that fall under "Coded systems", including Here is a simple example of a rule module. This is what we assume about our simple example game: - Characters have only four numerical values: - Their `level`, which starts at 1. - - A skill `combat`, which determines how good they are at hitting things. Starts between 5 and 10. + - A skill `combat`, which determines how good they are at hitting things. Starts between 5 and +10. - Their Strength, `STR`, which determine how much damage they do. Starts between 1 and 10. - Their Health points, `HP`, which starts at 100. -- When a Character reaches `HP = 0`, they are presumed "defeated". Their HP is reset and they get a failure message (as a stand-in for death code). +- When a Character reaches `HP = 0`, they are presumed "defeated". Their HP is reset and they get a +failure message (as a stand-in for death code). - Abilities are stored as simple Attributes on the Character. -- "Rolls" are done by rolling a 100-sided die. If the result is below the `combat` value, it's a success and damage is rolled. Damage is rolled as a six-sided die + the value of `STR` (for this example we ignore weapons and assume `STR` is all that matters). -- Every successful `attack` roll gives 1-3 experience points (`XP`). Every time the number of `XP` reaches `(level + 1) ** 2`, the Character levels up. When leveling up, the Character's `combat` value goes up by 2 points and `STR` by one (this is a stand-in for a real progression system). +- "Rolls" are done by rolling a 100-sided die. If the result plus the `combat`value is greater than +the other character, it's a success and damage is rolled. Damage is rolled as a six-sided die + the +value of `STR` (for this example we ignore weapons and assume `STR` is all that matters). +- Every successful `attack` roll gives 1-3 experience points (`XP`). Every time the number of `XP` +reaches `(level + 1) ** 2`, the Character levels up. When leveling up, the Character's `combat` +value goes up by 2 points and `STR` by one (this is a stand-in for a real progression system). +- Characters with the name `dummy` will gain no XP. Allowing us to make a dummy to train with. ### Character -The Character typeclass is simple. It goes in `mygame/typeclasses/characters.py`. There is already an empty `Character` class there that Evennia will look to and use. +The Character typeclass is simple. It goes in `mygame/typeclasses/characters.py`. There is already +an empty `Character` class there that Evennia will look to and use. ```python from random import randint @@ -97,7 +134,10 @@ class Character(DefaultCharacter): self.db.combat = randint(5, 10) ``` -`@reload` the server to load up the new code. Doing `examine self` will however *not* show the new Attributes on yourself. This is because the `at_object_creation` hook is only called on *new* Characters. Your Character was already created and will thus not have them. To force a reload, use the following command: +`@reload` the server to load up the new code. Doing `examine self` will however *not* show the new +Attributes on yourself. This is because the `at_object_creation` hook is only called on *new* +Characters. Your Character was already created and will thus not have them. To force a reload, use +the following command: ``` @typeclass/force/reset self @@ -110,30 +150,42 @@ The `examine self` command will now show the new Attributes. This is a module `mygame/world/rules.py`. ```python +""" +mygame/world/rules.py +""" from random import randint + def roll_hit(): "Roll 1d100" return randint(1, 100) + def roll_dmg(): "Roll 1d6" return randint(1, 6) + def check_defeat(character): "Checks if a character is 'defeated'." if character.db.HP <= 0: - character.msg("You fall down, defeated!") - character.db.HP = 100 # reset + character.msg("You fall down, defeated!") + character.db.HP = 100 # reset + def add_XP(character, amount): "Add XP to character, tracking level increases." - character.db.XP += amount - if character.db.XP >= (character.db.level + 1) ** 2: - character.db.level += 1 - character.db.STR += 1 - character.db.combat += 2 - character.msg("You are now level %i!" % character.db.level) + if "training_dummy" in character.tags.all(): # don't allow the training dummy to level + character.location.msg_contents("Training Dummies can not gain XP.") + return + else: + character.db.XP += amount + if character.db.XP >= (character.db.level + 1) ** 2: + character.db.level += 1 + character.db.STR += 1 + character.db.combat += 2 + character.msg("You are now level %i!" % character.db.level) + def skill_combat(*args): """ @@ -146,7 +198,17 @@ def skill_combat(*args): failtext = "You are hit by %s for %i damage!" wintext = "You hit %s for %i damage!" xp_gain = randint(1, 3) - if char1.db.combat >= roll1 > roll2: + + # display messages showing attack numbers + attack_message = f"{char1.name} rolls {roll1} + combat {char1.db.combat} " \ + f"= {char1.db.combat+roll1} | {char2.name} rolls {roll2} + combat " \ + f"{char2.db.combat} = {char2.db.combat+roll2}" + char1.location.msg_contents(attack_message) + attack_summary = f"{char1.name} {char1.db.combat+roll1} " \ + f"vs {char2.name} {char2.db.combat+roll2}" + char1.location.msg_contents(attack_summary) + + if char1.db.combat+roll1 > char2.db.combat+roll2: # char 1 hits dmg = roll_dmg() + char1.db.STR char1.msg(wintext % (char2, dmg)) @@ -154,7 +216,7 @@ def skill_combat(*args): char2.msg(failtext % (char1, dmg)) char2.db.HP -= dmg check_defeat(char2) - elif char2.db.combat >= roll2 > roll1: + elif char2.db.combat+roll2 > char1.db.combat+roll1: # char 2 hits dmg = roll_dmg() + char2.db.STR char1.msg(failtext % (char2, dmg)) @@ -168,8 +230,10 @@ def skill_combat(*args): char1.msg(drawtext) char2.msg(drawtext) + SKILLS = {"combat": skill_combat} + def roll_challenge(character1, character2, skillname): """ Determine the outcome of a skill challenge between @@ -181,9 +245,16 @@ def roll_challenge(character1, character2, skillname): raise RunTimeError("Skillname %s not found." % skillname) ``` -These few functions implement the entirety of our simple rule system. We have a function to check the "defeat" condition and reset the `HP` back to 100 again. We define a generic "skill" function. Multiple skills could all be added with the same signature; our `SKILLS` dictionary makes it easy to look up the skills regardless of what their actual functions are called. Finally, the access function `roll_challenge` just picks the skill and gets the result. +These few functions implement the entirety of our simple rule system. We have a function to check +the "defeat" condition and reset the `HP` back to 100 again. We define a generic "skill" function. +Multiple skills could all be added with the same signature; our `SKILLS` dictionary makes it easy to +look up the skills regardless of what their actual functions are called. Finally, the access +function `roll_challenge` just picks the skill and gets the result. -In this example, the skill function actually does a lot - it not only rolls results, it also informs everyone of their results via `character.msg()` calls. +In this example, the skill function actually does a lot - it not only rolls results, it also informs +everyone of their results via `character.msg()` calls. + +### Attack Command Here is an example of usage in a game command: @@ -219,3 +290,13 @@ number of Combat commands by just extending this functionality - you can easily pick different skills to check. And if you ever decided to, say, change how to determine hit chance, you don't have to change every command, but need only change the single `roll_hit` function inside your `rules` module. + +### Training dummy +Create a dummy to test the attack command. Give it a `training_dummy` tag anything with the tag +`training_dummy` will not gain xp.
+> create/drop dummy:characters.Character
+tag dummy=training_dummy + +Attack it with your new command + +> attack dummy \ No newline at end of file diff --git a/docs/source/Inputfuncs.md b/docs/source/Inputfuncs.md index 88bd3e304c..5b76d56eef 100644 --- a/docs/source/Inputfuncs.md +++ b/docs/source/Inputfuncs.md @@ -1,7 +1,10 @@ # Inputfuncs -An *inputfunc* is an Evennia function that handles a particular input (an [inputcommand](./OOB)) from the client. The inputfunc is the last destination for the inputcommand along the [ingoing message path](./Messagepath#the-ingoing-message-path). The inputcommand always has the form `(commandname, (args), {kwargs})` and Evennia will use this to try to find and call an inputfunc on the form +An *inputfunc* is an Evennia function that handles a particular input (an [inputcommand](./OOB)) from +the client. The inputfunc is the last destination for the inputcommand along the [ingoing message +path](Messagepath#the-ingoing-message-path). The inputcommand always has the form `(commandname, +(args), {kwargs})` and Evennia will use this to try to find and call an inputfunc on the form ```python def commandname(session, *args, **kwargs): @@ -18,31 +21,42 @@ Or, if no match was found, it will call an inputfunc named "default" on this for ## Adding your own inputfuncs -This is simple. Add a function on the above form to `mygame/server/conf/inputfuncs.py`. Your function must be in the global, outermost scope of that module and not start with an underscore (`_`) to be recognized as an inputfunc. Reload the server. That's it. To overload a default inputfunc (see below), just add a function with the same name. +This is simple. Add a function on the above form to `mygame/server/conf/inputfuncs.py`. Your +function must be in the global, outermost scope of that module and not start with an underscore +(`_`) to be recognized as an inputfunc. Reload the server. That's it. To overload a default +inputfunc (see below), just add a function with the same name. -The modules Evennia looks into for inputfuncs are defined in the list `settings.INPUT_FUNC_MODULES`. This list will be imported from left to right and later imported functions will replace earlier ones. +The modules Evennia looks into for inputfuncs are defined in the list `settings.INPUT_FUNC_MODULES`. +This list will be imported from left to right and later imported functions will replace earlier +ones. ## Default inputfuncs -Evennia defines a few default inputfuncs to handle the common cases. These are defined in `evennia/server/inputfuncs.py`. +Evennia defines a few default inputfuncs to handle the common cases. These are defined in +`evennia/server/inputfuncs.py`. ### text - Input: `("text", (textstring,), {})` - Output: Depends on Command triggered -This is the most common of inputcommands, and the only one supported by every traditional mud. The argument is usually what the user sent from their command line. Since all text input from the user like this is considered a [Command](./Commands), this inputfunc will do things like nick-replacement and then pass on the input to the central Commandhandler. +This is the most common of inputcommands, and the only one supported by every traditional mud. The +argument is usually what the user sent from their command line. Since all text input from the user +like this is considered a [Command](./Commands), this inputfunc will do things like nick-replacement +and then pass on the input to the central Commandhandler. ### echo - Input: `("echo", (args), {})` - Output: `("text", ("Echo returns: %s" % args), {})` -This is a test input, which just echoes the argument back to the session as text. Can be used for testing custom client input. +This is a test input, which just echoes the argument back to the session as text. Can be used for +testing custom client input. ### default -The default function, as mentioned above, absorbs all non-recognized inputcommands. The default one will just log an error. +The default function, as mentioned above, absorbs all non-recognized inputcommands. The default one +will just log an error. ### client_options @@ -51,9 +65,12 @@ The default function, as mentioned above, absorbs all non-recognized inputcomman - normal: None - get: `("client_options", (), {key:value, ...})` -This is a direct command for setting protocol options. These are settable with the `@option` command, but this offers a client-side way to set them. Not all connection protocols makes use of all flags, but here are the possible keywords: +This is a direct command for setting protocol options. These are settable with the `@option` +command, but this offers a client-side way to set them. Not all connection protocols makes use of +all flags, but here are the possible keywords: - - get (bool): If this is true, ignore all other kwargs and immediately return the current settings as an outputcommand `("client_options", (), {key=value, ...})`- + - get (bool): If this is true, ignore all other kwargs and immediately return the current settings +as an outputcommand `("client_options", (), {key=value, ...})`- - client (str): A client identifier, like "mushclient". - version (str): A client version - ansi (bool): Supports ansi colors @@ -66,23 +83,26 @@ This is a direct command for setting protocol options. These are settable with t - screenwidth (int): Screen width in characters - inputdebug (bool): Debug input functions - nomarkup (bool): Strip all text tags - - raw (bool): Leave text tags unparsed + - raw (bool): Leave text tags unparsed -> Note that there are two GMCP aliases to this inputfunc - `hello` and `supports_set`, which means it will be accessed via the GMCP `Hello` and `Supports.Set` instructions assumed by some clients. +> Note that there are two GMCP aliases to this inputfunc - `hello` and `supports_set`, which means +it will be accessed via the GMCP `Hello` and `Supports.Set` instructions assumed by some clients. ### get_client_options - Input: `("get_client_options, (), {key:value, ...})` - Output: `("client_options, (), {key:value, ...})` -This is a convenience wrapper that retrieves the current options by sending "get" to `client_options` above. +This is a convenience wrapper that retrieves the current options by sending "get" to +`client_options` above. ### get_inputfuncs - Input: `("get_inputfuncs", (), {})` - Output: `("get_inputfuncs", (), {funcname:docstring, ...})` -Returns an outputcommand on the form `("get_inputfuncs", (), {funcname:docstring, ...})` - a list of all the available inputfunctions along with their docstrings. +Returns an outputcommand on the form `("get_inputfuncs", (), {funcname:docstring, ...})` - a list of +all the available inputfunctions along with their docstrings. ### login @@ -98,38 +118,51 @@ This performs the inputfunc version of a login operation on the current Session. Input: `("get_value", (name, ), {})` Output: `("get_value", (value, ), {})` -Retrieves a value from the Character or Account currently controlled by this Session. Takes one argument, This will only accept particular white-listed names, you'll need to overload the function to expand. By default the following values can be retrieved: +Retrieves a value from the Character or Account currently controlled by this Session. Takes one +argument, This will only accept particular white-listed names, you'll need to overload the function +to expand. By default the following values can be retrieved: - "name" or "key": The key of the Account or puppeted Character. - "location": Name of the current location, or "None". - "servername": Name of the Evennia server connected to. -### repeat +### repeat - - Input: `("repeat", (), {"callback":funcname, - "interval": secs, "stop": False})` - - Output: Depends on the repeated function. Will return `("text", (repeatlist),{}` with a list of accepted names if given an unfamiliar callback name. + - Input: `("repeat", (), {"callback":funcname, + "interval": secs, "stop": False})` + - Output: Depends on the repeated function. Will return `("text", (repeatlist),{}` with a list of +accepted names if given an unfamiliar callback name. -This will tell evennia to repeatedly call a named function at a given interval. Behind the scenes this will set up a [Ticker](./TickerHandler). Only previously acceptable functions are possible to repeat-call in this way, you'll need to overload this inputfunc to add the ones you want to offer. By default only two example functions are allowed, "test1" and "test2", which will just echo a text back at the given interval. Stop the repeat by sending `"stop": True` (note that you must include both the callback name and interval for Evennia to know what to stop). +This will tell evennia to repeatedly call a named function at a given interval. Behind the scenes +this will set up a [Ticker](./TickerHandler). Only previously acceptable functions are possible to +repeat-call in this way, you'll need to overload this inputfunc to add the ones you want to offer. +By default only two example functions are allowed, "test1" and "test2", which will just echo a text +back at the given interval. Stop the repeat by sending `"stop": True` (note that you must include +both the callback name and interval for Evennia to know what to stop). ### unrepeat - - Input: `("unrepeat", (), ("callback":funcname, + - Input: `("unrepeat", (), ("callback":funcname, "interval": secs)` - Output: None -This is a convenience wrapper for sending "stop" to the `repeat` inputfunc. +This is a convenience wrapper for sending "stop" to the `repeat` inputfunc. ### monitor - Input: `("monitor", (), ("name":field_or_argname, stop=False)` - Output (on change): `("monitor", (), {"name":name, "value":value})` -This sets up on-object monitoring of Attributes or database fields. Whenever the field or Attribute changes in any way, the outputcommand will be sent. This is using the [MonitorHandler](./MonitorHandler) behind the scenes. Pass the "stop" key to stop monitoring. Note that you must supply the name also when stopping to let the system know which monitor should be cancelled. +This sets up on-object monitoring of Attributes or database fields. Whenever the field or Attribute +changes in any way, the outputcommand will be sent. This is using the +[MonitorHandler](./MonitorHandler) behind the scenes. Pass the "stop" key to stop monitoring. Note +that you must supply the name also when stopping to let the system know which monitor should be +cancelled. -Only fields/attributes in a whitelist are allowed to be used, you have to overload this function to add more. By default the following fields/attributes can be monitored: +Only fields/attributes in a whitelist are allowed to be used, you have to overload this function to +add more. By default the following fields/attributes can be monitored: - - "name": The current character name + - "name": The current character name - "location": The current location - "desc": The description Argument @@ -138,4 +171,4 @@ Only fields/attributes in a whitelist are allowed to be used, you have to overlo - Input: `("unmonitor", (), {"name":name})` - Output: None -A convenience wrapper that sends "stop" to the `monitor` function. \ No newline at end of file +A convenience wrapper that sends "stop" to the `monitor` function. \ No newline at end of file diff --git a/docs/source/Installing-on-Android.md b/docs/source/Installing-on-Android.md index cf876039fb..4b8d80c50a 100644 --- a/docs/source/Installing-on-Android.md +++ b/docs/source/Installing-on-Android.md @@ -7,12 +7,19 @@ this before starting. ## Install Termux -The first thing to do is install a terminal emulator that allows a "full" version of linux to be run. Note that Android is essentially running on top of linux so if you have a rooted phone, you may be able to skip this step. You *don't* require a rooted phone to install Evennia though. +The first thing to do is install a terminal emulator that allows a "full" version of linux to be +run. Note that Android is essentially running on top of linux so if you have a rooted phone, you may +be able to skip this step. You *don't* require a rooted phone to install Evennia though. -Assuming we do not have root, we will install [Termux](https://play.google.com/store/apps/details?id=com.termux&hl=en). -Termux provides a base installation of Linux essentials, including apt and Python, and makes them available under a writeable directory. It also gives us a terminal where we can enter commands. By default, Android doesn't give you permissions to the root folder, so Termux pretends that its own installation directory is the root directory. +Assuming we do not have root, we will install +[Termux](https://play.google.com/store/apps/details?id=com.termux&hl=en). +Termux provides a base installation of Linux essentials, including apt and Python, and makes them +available under a writeable directory. It also gives us a terminal where we can enter commands. By +default, Android doesn't give you permissions to the root folder, so Termux pretends that its own +installation directory is the root directory. -Termux will set up a base system for us on first launch, but we will need to install some prerequisites for Evennia. Commands you should run in Termux will look like this: +Termux will set up a base system for us on first launch, but we will need to install some +prerequisites for Evennia. Commands you should run in Termux will look like this: ``` $ cat file.txt @@ -21,14 +28,17 @@ The `$` symbol is your prompt - do not include it when running commands. ## Prerequisites -To install some of the libraries Evennia requires, namely Pillow and Twisted, we have to first install some packages they depend on. In Termux, run the following +To install some of the libraries Evennia requires, namely Pillow and Twisted, we have to first +install some packages they depend on. In Termux, run the following ``` $ pkg install -y clang git zlib ndk-sysroot libjpeg-turbo libcrypt python ``` -Termux ships with Python 3, perfect. Python 3 has venv (virtualenv) and pip (Python's module installer) built-in. +Termux ships with Python 3, perfect. Python 3 has venv (virtualenv) and pip (Python's module +installer) built-in. -So, let's set up our virtualenv. This keeps the Python packages we install separate from the system versions. +So, let's set up our virtualenv. This keeps the Python packages we install separate from the system +versions. ``` $ cd @@ -36,7 +46,8 @@ $ python3 -m venv evenv ``` This will create a new folder, called `evenv`, containing the new python executable. -Next, let's activate our new virtualenv. Every time you want to work on Evennia, you need to run the following command: +Next, let's activate our new virtualenv. Every time you want to work on Evennia, you need to run the +following command: ``` $ source evenv/bin/activate @@ -64,16 +75,20 @@ export CFLAGS="-I/data/data/com.termux/files/usr/include/" Install the latest Evennia in a way that lets you edit the source ``` -(evenv) $ pip install --upgrade -e 'git+https://github.com/evennia/evennia#egg=evennia' +(evenv) $ pip install --upgrade -e 'git+https://github.com/evennia/evennia#egg=evennia' ``` -This step will possibly take quite a while - we are downloading Evennia and are then installing it, building all of the requirements for Evennia to run. If you run into trouble on this step, please see [Troubleshooting](./Installing-on-Android#troubleshooting). +This step will possibly take quite a while - we are downloading Evennia and are then installing it, +building all of the requirements for Evennia to run. If you run into trouble on this step, please +see [Troubleshooting](./Installing-on-Android#troubleshooting). -You can go to the dir where Evennia is installed with `cd $VIRTUAL_ENV/src/evennia`. `git grep (something)` can be handy, as can `git diff` +You can go to the dir where Evennia is installed with `cd $VIRTUAL_ENV/src/evennia`. `git grep +(something)` can be handy, as can `git diff` ### Final steps -At this point, Evennia is installed on your phone! You can now continue with the original [Getting Started](./Getting-Started) instruction, we repeat them here for clarity. +At this point, Evennia is installed on your phone! You can now continue with the original [Getting +Started](Getting-Started) instruction, we repeat them here for clarity. To start a new game: @@ -91,11 +106,13 @@ To start the game for the first time: (evenv) $ evennia start ``` -Your game should now be running! Open a web browser at http://localhost:4001 or point a telnet client to localhost:4000 and log in with the user you created. +Your game should now be running! Open a web browser at http://localhost:4001 or point a telnet +client to localhost:4000 and log in with the user you created. ## Running Evennia -When you wish to run Evennia, get into your Termux console and make sure you have activated your virtualenv as well as are in your game's directory. You can then run evennia start as normal. +When you wish to run Evennia, get into your Termux console and make sure you have activated your +virtualenv as well as are in your game's directory. You can then run evennia start as normal. ``` $ cd ~ && source evenv/bin/activate @@ -107,9 +124,11 @@ You may wish to look at the [Linux Instructions](./Getting-Started#linux-install ## Caveats -- Android's os module doesn't support certain functions - in particular getloadavg. Thusly, running the command @server in-game will throw an exception. So far, there is no fix for this problem. +- Android's os module doesn't support certain functions - in particular getloadavg. Thusly, running +the command @server in-game will throw an exception. So far, there is no fix for this problem. - As you might expect, performance is not amazing. -- Android is fairly aggressive about memory handling, and you may find that your server process is killed if your phone is heavily taxed. Termux seems to keep a notification up to discourage this. +- Android is fairly aggressive about memory handling, and you may find that your server process is +killed if your phone is heavily taxed. Termux seems to keep a notification up to discourage this. ## Troubleshooting diff --git a/docs/source/Internationalization.md b/docs/source/Internationalization.md index 3c035b7015..6abf9981cd 100644 --- a/docs/source/Internationalization.md +++ b/docs/source/Internationalization.md @@ -15,31 +15,59 @@ Change language by adding the following to your `mygame/server/conf/settings.py` LANGUAGE_CODE = 'en' ``` -Here `'en'` should be changed to the abbreviation for one of the supported languages found in `locale/`. Restart the server to activate i18n. The two-character international language codes are found [here](http://www.science.co.il/Language/Codes.asp). +Here `'en'` should be changed to the abbreviation for one of the supported languages found in +`locale/`. Restart the server to activate i18n. The two-character international language codes are +found [here](http://www.science.co.il/Language/Codes.asp). -> Windows Note: If you get errors concerning `gettext` or `xgettext` on Windows, see the [Django documentation](https://docs.djangoproject.com/en/1.7/topics/i18n/translation/#gettext-on-windows). A self-installing and up-to-date version of gettext for Windows (32/64-bit) is available on [Github](https://github.com/mlocati/gettext-iconv-windows). +> Windows Note: If you get errors concerning `gettext` or `xgettext` on Windows, see the [Django +documentation](https://docs.djangoproject.com/en/1.7/topics/i18n/translation/#gettext-on-windows). A +self-installing and up-to-date version of gettext for Windows (32/64-bit) is available on +[Github](https://github.com/mlocati/gettext-iconv-windows). ## Translating Evennia -> **Important Note:** Evennia offers translations of hard-coded strings in the server, things like "Connection closed" or "Server restarted", strings that end users will see and which game devs are not supposed to change on their own. Text you see in the log file or on the command line (like error messages) are generally *not* translated (this is a part of Python). +> **Important Note:** Evennia offers translations of hard-coded strings in the server, things like +"Connection closed" or "Server restarted", strings that end users will see and which game devs are +not supposed to change on their own. Text you see in the log file or on the command line (like error +messages) are generally *not* translated (this is a part of Python). -> In addition, text in default Commands and in default Typeclasses will *not* be translated by switching *i18n* language. To translate Commands and Typeclass hooks you must overload them in your game directory and translate their returns to the language you want. This is because from Evennia's perspective, adding *i18n* code to commands tend to add complexity to code that is *meant* to be changed anyway. One of the goals of Evennia is to keep the user-changeable code as clean and easy-to-read as possible. +> In addition, text in default Commands and in default Typeclasses will *not* be translated by +switching *i18n* language. To translate Commands and Typeclass hooks you must overload them in your +game directory and translate their returns to the language you want. This is because from Evennia's +perspective, adding *i18n* code to commands tend to add complexity to code that is *meant* to be +changed anyway. One of the goals of Evennia is to keep the user-changeable code as clean and easy- +to-read as possible. -If you cannot find your language in `evennia/locale/` it's because noone has translated it yet. Alternatively you might have the language but find the translation bad ... You are welcome to help improve the situation! +If you cannot find your language in `evennia/locale/` it's because noone has translated it yet. +Alternatively you might have the language but find the translation bad ... You are welcome to help +improve the situation! -To start a new translation you need to first have cloned the Evennia repositry with GIT and activated a python virtualenv as described on the [Getting Started](./Getting-Started) page. You now need to `cd` to the `evennia/` directory. This is *not* your created game folder but the main Evennia library folder. If you see a folder `locale/` then you are in the right place. From here you run: +To start a new translation you need to first have cloned the Evennia repositry with GIT and +activated a python virtualenv as described on the [Getting Started](./Getting-Started) page. You now +need to `cd` to the `evennia/` directory. This is *not* your created game folder but the main +Evennia library folder. If you see a folder `locale/` then you are in the right place. From here you +run: evennia makemessages -where `` is the [two-letter locale code](http://www.science.co.il/Language/Codes.asp) for the language you want, like 'sv' for Swedish or 'es' for Spanish. After a moment it will tell you the language has been processed. For instance: +where `` is the [two-letter locale code](http://www.science.co.il/Language/Codes.asp) +for the language you want, like 'sv' for Swedish or 'es' for Spanish. After a moment it will tell +you the language has been processed. For instance: evennia makemessages sv -If you started a new language a new folder for that language will have emerged in the `locale/` folder. Otherwise the system will just have updated the existing translation with eventual new strings found in the server. Running this command will not overwrite any existing strings so you can run it as much as you want. +If you started a new language a new folder for that language will have emerged in the `locale/` +folder. Otherwise the system will just have updated the existing translation with eventual new +strings found in the server. Running this command will not overwrite any existing strings so you can +run it as much as you want. -> Note: in Django, the `makemessages` command prefixes the locale name by the `-l` option (`... makemessages -l sv` for instance). This syntax is not allowed in Evennia, due to the fact that `-l` is the option to tail log files. Hence, `makemessages` doesn't use the `-l` flag. +> Note: in Django, the `makemessages` command prefixes the locale name by the `-l` option (`... +makemessages -l sv` for instance). This syntax is not allowed in Evennia, due to the fact that `-l` +is the option to tail log files. Hence, `makemessages` doesn't use the `-l` flag. -Next head to `locale//LC_MESSAGES` and edit the `**.po` file you find there. You can edit this with a normal text editor but it is easiest if you use a special po-file editor from the web (search the web for "po editor" for many free alternatives). +Next head to `locale//LC_MESSAGES` and edit the `**.po` file you find there. You can +edit this with a normal text editor but it is easiest if you use a special po-file editor from the +web (search the web for "po editor" for many free alternatives). The concept of translating is simple, it's just a matter of taking the english strings you find in the `**.po` file and add your language's translation best you can. The `**.po` format (and many @@ -47,11 +75,14 @@ supporting editors) allow you to mark translations as "fuzzy". This tells the sy translators) that you are unsure about the translation, or that you couldn't find a translation that exactly matched the intention of the original text. Other translators will see this and might be able to improve it later. -Finally, you need to compile your translation into a more efficient form. Do so from the `evennia` folder +Finally, you need to compile your translation into a more efficient form. Do so from the `evennia` +folder again: evennia compilemessages -This will go through all languages and create/update compiled files (`**.mo`) for them. This needs to be done whenever a `**.po` file is updated. +This will go through all languages and create/update compiled files (`**.mo`) for them. This needs +to be done whenever a `**.po` file is updated. -When you are done, send the `**.po` and `*.mo` file to the Evennia developer list (or push it into your own repository clone) so we can integrate your translation into Evennia! +When you are done, send the `**.po` and `*.mo` file to the Evennia developer list (or push it into +your own repository clone) so we can integrate your translation into Evennia! diff --git a/docs/source/Learn-Python-for-Evennia-The-Hard-Way.md b/docs/source/Learn-Python-for-Evennia-The-Hard-Way.md index b16f181de9..fd7e22a3c6 100644 --- a/docs/source/Learn-Python-for-Evennia-The-Hard-Way.md +++ b/docs/source/Learn-Python-for-Evennia-The-Hard-Way.md @@ -2,19 +2,48 @@ # WORK IN PROGRESS - DO NOT USE -Evennia provides a great foundation to build your very own MU* whether you have programming experience or none at all. Whilst Evennia has a number of in-game building commands and tutorials available to get you started, when approaching game systems of any complexity it is advisable to have the basics of Python under your belt before jumping into the code. There are many Python tutorials freely available online however this page focuses on Learn Python the Hard Way (LPTHW) by Zed Shaw. This tutorial takes you through the basics of Python and progresses you to creating your very own online text based game. Whilst completing the course feel free to install Evennia and try out some of our beginner tutorials. On completion you can return to this page, which will act as an overview to the concepts separating your online text based game and the inner-workings of Evennia. --The latter portion of the tutorial focuses working your engine into a webpage and is not strictly required for development in Evennia. +Evennia provides a great foundation to build your very own MU* whether you have programming +experience or none at all. Whilst Evennia has a number of in-game building commands and tutorials +available to get you started, when approaching game systems of any complexity it is advisable to +have the basics of Python under your belt before jumping into the code. There are many Python +tutorials freely available online however this page focuses on Learn Python the Hard Way (LPTHW) by +Zed Shaw. This tutorial takes you through the basics of Python and progresses you to creating your +very own online text based game. Whilst completing the course feel free to install Evennia and try +out some of our beginner tutorials. On completion you can return to this page, which will act as an +overview to the concepts separating your online text based game and the inner-workings of Evennia. +-The latter portion of the tutorial focuses working your engine into a webpage and is not strictly +required for development in Evennia. ## Exercise 23 -You may have returned here when you were invited to read some code. If you haven’t already, you should now have the knowledge necessary to install Evennia. Head over to the Getting Started page for install instructions. You can also try some of our tutorials to get you started on working with Evennia. +You may have returned here when you were invited to read some code. If you haven’t already, you +should now have the knowledge necessary to install Evennia. Head over to the Getting Started page +for install instructions. You can also try some of our tutorials to get you started on working with +Evennia. ## Bridging the gap. -If you have successfully completed the Learn Python the Hard Way tutorial you should now have a simple browser based Interactive Fiction engine which looks similar to this. -This engine is built using a single interactive object type, the Room class. The Room class holds a description of itself that is presented to the user and a list of hardcoded commands which if selected correctly will present you with the next rooms’ description and commands. Whilst your game only has one interactive object, MU* have many more: Swords and shields, potions and scrolls or even laser guns and robots. Even the player has an in-game representation in the form of your character. Each of these examples are represented by their own object with their own description that can be presented to the user. +If you have successfully completed the Learn Python the Hard Way tutorial you should now have a +simple browser based Interactive Fiction engine which looks similar to this. +This engine is built using a single interactive object type, the Room class. The Room class holds a +description of itself that is presented to the user and a list of hardcoded commands which if +selected correctly will present you with the next rooms’ description and commands. Whilst your game +only has one interactive object, MU* have many more: Swords and shields, potions and scrolls or even +laser guns and robots. Even the player has an in-game representation in the form of your character. +Each of these examples are represented by their own object with their own description that can be +presented to the user. -A basic object in Evennia has a number of default functions but perhaps most important is the idea of location. In your text engine you receive a description of a room but you are not really in the room because you have no in-game representation. However, in Evennia when you enter a Dungeon you ARE in the dungeon. That is to say your character.location = Dungeon whilst the Dungeon.contents now has a spunky young adventurer added to it. In turn, your character.contents may have amongst it a number of swords and potions to help you on your adventure and their location would be you. +A basic object in Evennia has a number of default functions but perhaps most important is the idea +of location. In your text engine you receive a description of a room but you are not really in the +room because you have no in-game representation. However, in Evennia when you enter a Dungeon you +ARE in the dungeon. That is to say your character.location = Dungeon whilst the Dungeon.contents now +has a spunky young adventurer added to it. In turn, your character.contents may have amongst it a +number of swords and potions to help you on your adventure and their location would be you. -In reality each of these “objects” are just an entry in your Evennia projects database which keeps track of all these attributes, such as location and contents. Making changes to those attributes and the rules in which they are changed is the most fundamental perspective of how your game works. We define those rules in the objects Typeclass. The Typeclass is a Python class with a special connection to the games database which changes values for us through various class methods. Let’s look at your characters Typeclass rules for changing location. +In reality each of these “objects” are just an entry in your Evennia projects database which keeps +track of all these attributes, such as location and contents. Making changes to those attributes and +the rules in which they are changed is the most fundamental perspective of how your game works. We +define those rules in the objects Typeclass. The Typeclass is a Python class with a special +connection to the games database which changes values for us through various class methods. Let’s +look at your characters Typeclass rules for changing location. 1. `self.at_before_move(destination)` (if this returns False, move is aborted) 2. `self.announce_move_from(destination)` @@ -22,6 +51,20 @@ In reality each of these “objects” are just an entry in your Evennia project 4. `self.announce_move_to(source_location)` 5. `self.at_after_move(source_location)` -First we check if it’s okay to leave our current location, then we tell everyone there that we’re leaving. We move locations and tell everyone at our new location that we’ve arrived before checking we’re okay to be there. By default stages 1 and 5 are empty ready for us to add some rules. We’ll leave an explanation as to how to make those changes for the tutorial section, but imagine if you were an astronaut. A smart astronaut might stop at step 1 to remember to put his helmet on whilst a slower astronaut might realise he’s forgotten in step 5 before shortly after ceasing to be an astronaut. +First we check if it’s okay to leave our current location, then we tell everyone there that we’re +leaving. We move locations and tell everyone at our new location that we’ve arrived before checking +we’re okay to be there. By default stages 1 and 5 are empty ready for us to add some rules. We’ll +leave an explanation as to how to make those changes for the tutorial section, but imagine if you +were an astronaut. A smart astronaut might stop at step 1 to remember to put his helmet on whilst a +slower astronaut might realise he’s forgotten in step 5 before shortly after ceasing to be an +astronaut. -With all these objects and all this moving around it raises another problem. In your text engine the commands available to the player were hard-coded to the room. That means if we have commands we always want available to the player we’ll need to have those commands hard-coded on every single room. What about an armoury? When all the swords are gone the command to take a sword would still remain causing confusion. Evennia solves this problem by giving each object the ability to hold commands. Rooms can have commands attached to them specific to that location, like climbing a tree; Players can have commands which are always available to them, like ‘look’, ‘get’ and ‘say’; and objects can have commands attached to them which unlock when taking possession of it, like attack commands when obtaining a weapon. +With all these objects and all this moving around it raises another problem. In your text engine the +commands available to the player were hard-coded to the room. That means if we have commands we +always want available to the player we’ll need to have those commands hard-coded on every single +room. What about an armoury? When all the swords are gone the command to take a sword would still +remain causing confusion. Evennia solves this problem by giving each object the ability to hold +commands. Rooms can have commands attached to them specific to that location, like climbing a tree; +Players can have commands which are always available to them, like ‘look’, ‘get’ and ‘say’; and +objects can have commands attached to them which unlock when taking possession of it, like attack +commands when obtaining a weapon. diff --git a/docs/source/Links.md b/docs/source/Links.md index 9a053c0efb..92ca8974f1 100644 --- a/docs/source/Links.md +++ b/docs/source/Links.md @@ -6,10 +6,13 @@ - [evennia.com](http://www.evennia.com) - Main Evennia portal page. Links to all corners of Evennia. - [Evennia github page](https://github.com/evennia/evennia) - Download code and read documentation. -- [Evennia official chat channel](http://webchat.freenode.net/?channels=evennia&uio=MT1mYWxzZSY5PXRydWUmMTE9MTk1JjEyPXRydWUbb) - Our official IRC chat #evennia at irc.freenode.net:6667. -- [Evennia forums/mailing list](http://groups.google.com/group/evennia) - Web interface to our google group. +- [Evennia official chat channel](http://webchat.freenode.net/?channels=evennia&uio=MT1mYWxzZSY5PXRy +dWUmMTE9MTk1JjEyPXRydWUbb) - Our official IRC chat #evennia at irc.freenode.net:6667. +- [Evennia forums/mailing list](http://groups.google.com/group/evennia) - Web interface to our +google group. - [Evennia development blog](http://evennia.blogspot.se/) - Musings from the lead developer. -- [Evennia's manual on ReadTheDocs](http://readthedocs.org/projects/evennia/) - Read and download offline in html, PDF or epub formats. +- [Evennia's manual on ReadTheDocs](http://readthedocs.org/projects/evennia/) - Read and download +offline in html, PDF or epub formats. - [Evennia Game Index](http://games.evennia.com/) - An automated listing of Evennia games. ---- - [Evennia on Open Hub](https://www.openhub.net/p/6906) @@ -19,66 +22,130 @@ ### Third-party Evennia utilities and resources -*For publicly available games running on Evennia, add and find those in the [Evennia game index](http://games.evennia.com) instead!* +*For publicly available games running on Evennia, add and find those in the [Evennia game +index](http://games.evennia.com) instead!* -- [Discord Evennia channel](https://discord.gg/NecFePw) - This is a fan-driven Discord channel with a bridge to the official Evennia IRC channel. +- [Discord Evennia channel](https://discord.gg/NecFePw) - This is a fan-driven Discord channel with +a bridge to the official Evennia IRC channel. ---- +--- -- [Discord live blog](https://discordapp.com/channels/517176782357528616/517176782781415434) of the _Blackbirds_ Evennia game project. -- [Unreal Engine Evennia plugin](https://www.unrealengine.com/marketplace/en-US/slug/evennia-plugin) - an in-progress Unreal plugin for integrating Evennia with Epic Games' Unreal Engine. -- [The dark net/March Hare MUD](https://github.com/thedarknet/evennia) from the 2019 [DEF CON 27](https://www.defcon.org/html/defcon-27/dc-27-index.html) hacker conference in Paris. This is an Evennia game dir with batchcode to build the custom _Hackers_ style cyberspace zone with puzzles and challenges [used during the conference](https://dcdark.net/home#). -- [Arx sources](https://github.com/Arx-Game/arxcode) - Open-source code release of the very popular [Arx](http://play.arxmush.org/) Evennia game. [Here are instructions for installing](./Arxcode-installing-help) -- [Evennia-wiki](https://github.com/vincent-lg/evennia-wiki) - An Evennia-specific Wiki for your website. -- [Evcolor](https://github.com/taladan/Pegasus/blob/origin/world/utilities/evcolor) - Optional coloration for Evennia unit-test output. -- [Paxboards](https://github.com/aurorachain/paxboards) - Evennia bulletin board system (both for telnet/web). -- [Encarnia sources](https://github.com/whitehorse-io/encarnia) - An open-sourced game dir for Evennia with things like races, combat etc. [Summary here](https://www.reddit.com/r/MUD/comments/6z6s3j/encarnia_an_evennia_python_mud_code_base_with/). -- [The world of Cool battles sources](https://github.com/FlutterSprite/coolbattles) - Open source turn-based battle system for Evennia. It also has a [live demo](http://wcb.battlestudio.com/). -- [nextRPI](https://github.com/cluebyte/nextrpi) - A github project for making a toolbox for people to make [RPI](http://www.topmudsites.com/forums/showthread.php?t=4804)-style Evennia games. -- [Muddery](https://github.com/muddery/muddery) - A mud framework under development, based on an older fork of Evennia. It has some specific design goals for building and extending the game based on input files. -- [vim-evennia](https://github.com/amfl/vim-evennia) - A mode for editing batch-build files (`.ev`) files in the [vim](http://www.vim.org/) text editor (Emacs users can use [evennia-mode.el](https://github.com/evennia/evennia/blob/master/evennia/utils/evennia-mode.el)). +- [Discord live blog](https://discordapp.com/channels/517176782357528616/517176782781415434) of the +_Blackbirds_ Evennia game project. +- [Unreal Engine Evennia plugin](https://www.unrealengine.com/marketplace/en-US/slug/evennia-plugin) +- an in-progress Unreal plugin for integrating Evennia with Epic Games' Unreal Engine. +- [The dark net/March Hare MUD](https://github.com/thedarknet/evennia) from the 2019 [DEF CON +27](https://www.defcon.org/html/defcon-27/dc-27-index.html) hacker conference in Paris. This is an +Evennia game dir with batchcode to build the custom _Hackers_ style cyberspace zone with puzzles and +challenges [used during the conference](https://dcdark.net/home#). +- [Arx sources](https://github.com/Arx-Game/arxcode) - Open-source code release of the very popular +[Arx](http://play.arxmush.org/) Evennia game. [Here are instructions for installing](Arxcode- +installing-help) +- [Evennia-wiki](https://github.com/vincent-lg/evennia-wiki) - An Evennia-specific Wiki for your +website. +- [Evcolor](https://github.com/taladan/Pegasus/blob/origin/world/utilities/evcolor) - Optional +coloration for Evennia unit-test output. +- [Paxboards](https://github.com/aurorachain/paxboards) - Evennia bulletin board system (both for +telnet/web). +- [Encarnia sources](https://github.com/whitehorse-io/encarnia) - An open-sourced game dir for +Evennia with things like races, combat etc. [Summary +here](https://www.reddit.com/r/MUD/comments/6z6s3j/encarnia_an_evennia_python_mud_code_base_with/). +- [The world of Cool battles sources](https://github.com/FlutterSprite/coolbattles) - Open source +turn-based battle system for Evennia. It also has a [live demo](http://wcb.battlestudio.com/). +- [nextRPI](https://github.com/cluebyte/nextrpi) - A github project for making a toolbox for people +to make [RPI](http://www.topmudsites.com/forums/showthread.php?t=4804)-style Evennia games. +- [Muddery](https://github.com/muddery/muddery) - A mud framework under development, based on an +older fork of Evennia. It has some specific design goals for building and extending the game based +on input files. +- [vim-evennia](https://github.com/amfl/vim-evennia) - A mode for editing batch-build files (`.ev`) +files in the [vim](http://www.vim.org/) text editor (Emacs users can use [evennia- +mode.el](https://github.com/evennia/evennia/blob/master/evennia/utils/evennia-mode.el)). - [Other Evennia-related repos on github](https://github.com/search?p=1&q=evennia) ---- -- [EvCast video series](https://www.youtube.com/playlist?list=PLyYMNttpc-SX1hvaqlUNmcxrhmM64pQXl) - Tutorial videos explaining installing Evennia, basic Python etc. -- [Evennia-docker](https://github.com/gtaylor/evennia-docker) - Evennia in a [Docker container](https://www.docker.com/) for quick install and deployment in just a few commands. -- [Evennia's docs in Chinese](http://www.evenniacn.com/) - A translated mirror of a slightly older Evennia version. Announcement [here](https://groups.google.com/forum/#!topic/evennia/3AXS8ZTzJaA). -- [Evennia for MUSHers](http://musoapbox.net/topic/1150/evennia-for-mushers) - An article describing Evennia for those used to the MUSH way of doing things. -- *[Language Understanding for Text games using Deep reinforcement learning](http://news.mit.edu/2015/learning-language-playing-computer-games-0924#_msocom_1)* ([PDF](http://people.csail.mit.edu/karthikn/pdfs/mud-play15.pdf)) - MIT research paper using Evennia to train AIs. +- [EvCast video series](https://www.youtube.com/playlist?list=PLyYMNttpc-SX1hvaqlUNmcxrhmM64pQXl) - +Tutorial videos explaining installing Evennia, basic Python etc. +- [Evennia-docker](https://github.com/gtaylor/evennia-docker) - Evennia in a [Docker +container](https://www.docker.com/) for quick install and deployment in just a few commands. +- [Evennia's docs in Chinese](http://www.evenniacn.com/) - A translated mirror of a slightly older +Evennia version. Announcement [here](https://groups.google.com/forum/#!topic/evennia/3AXS8ZTzJaA). +- [Evennia for MUSHers](http://musoapbox.net/topic/1150/evennia-for-mushers) - An article describing +Evennia for those used to the MUSH way of doing things. +- *[Language Understanding for Text games using Deep reinforcement +learning](http://news.mit.edu/2015/learning-language-playing-computer-games-0924#_msocom_1)* +([PDF](http://people.csail.mit.edu/karthikn/pdfs/mud-play15.pdf)) - MIT research paper using Evennia +to train AIs. ### Other useful mud development resources -- [ROM area reader](https://github.com/ctoth/area_reader) - Parser for converting ROM area files to Python objects. +- [ROM area reader](https://github.com/ctoth/area_reader) - Parser for converting ROM area files to +Python objects. - [Gossip MUD chat network](https://gossip.haus/) -### General MUD forums and discussions +### General MUD forums and discussions -- [MUD Coder's Guild](https://mudcoders.com/) - A blog and [associated Slack channel](https://slack.mudcoders.com/) with discussions on MUD development. -- [MuSoapbox](http://www.musoapbox.net/) - Very active Mu* game community mainly focused on MUSH-type gaming. -- [Imaginary Realities](http://journal.imaginary-realities.com/) - An e-magazine on game and MUD design that has several articles about Evennia. There is also an [archive of older issues](http://disinterest.org/resource/imaginary-realities/) from 1998-2001 that are still very relevant. -- [Optional Realities](http://optionalrealities.com/) - Mud development discussion forums that has regular articles on MUD development focused on roleplay-intensive games. After a HD crash it's not as content-rich as it once was. +- [MUD Coder's Guild](https://mudcoders.com/) - A blog and [associated Slack +channel](https://slack.mudcoders.com/) with discussions on MUD development. +- [MuSoapbox](http://www.musoapbox.net/) - Very active Mu* game community mainly focused on MUSH- +type gaming. +- [Imaginary Realities](http://journal.imaginary-realities.com/) - An e-magazine on game and MUD +design that has several articles about Evennia. There is also an [archive of older +issues](http://disinterest.org/resource/imaginary-realities/) from 1998-2001 that are still very +relevant. +- [Optional Realities](http://optionalrealities.com/) - Mud development discussion forums that has +regular articles on MUD development focused on roleplay-intensive games. After a HD crash it's not +as content-rich as it once was. - [MudLab](http://mudlab.org/) - Mud design discussion forum - [MudConnector](http://www.mudconnect.com/) - Mud listing and forums - [MudBytes](http://www.mudbytes.net/) - Mud listing and forums - [Top Mud Sites](http://www.topmudsites.com/) - Mud listing and forums -- [Planet Mud-Dev](http://planet-muddev.disinterest.org/) - A blog aggregator following blogs of current MUD development (including Evennia) around the 'net. Worth to put among your RSS subscriptions. -- Mud Dev mailing list archive ([mirror](http://www.disinterest.org/resource/MUD-Dev/)) - Influential mailing list active 1996-2004. Advanced game design discussions. +- [Planet Mud-Dev](http://planet-muddev.disinterest.org/) - A blog aggregator following blogs of +current MUD development (including Evennia) around the 'net. Worth to put among your RSS +subscriptions. +- Mud Dev mailing list archive ([mirror](http://www.disinterest.org/resource/MUD-Dev/)) - +Influential mailing list active 1996-2004. Advanced game design discussions. - [Mud-dev wiki](http://mud-dev.wikidot.com/) - A (very) slowly growing resource on MUD creation. -- [Mud Client/Server Interaction](http://cryosphere.net/mud-protocol.html) - A page on classic MUD telnet protocols. -- [Mud Tech's fun/cool but ...](http://gc-taylor.com/blog/2013/01/08/mud-tech-funcool-dont-forget-ship-damned-thing/) - Greg Taylor gives good advice on mud design. -- [Lost Library of MOO](http://www.hayseed.net/MOO/) - Archive of scientific articles on mudding (in particular moo). -- [Nick Gammon's hints thread](http://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=5959) - Contains a very useful list of things to think about when starting your new MUD. -- [Lost Garden](http://www.lostgarden.com/) - A game development blog with long and interesting articles (not MUD-specific) +- [Mud Client/Server Interaction](http://cryosphere.net/mud-protocol.html) - A page on classic MUD +telnet protocols. +- [Mud Tech's fun/cool but ...](http://gc-taylor.com/blog/2013/01/08/mud-tech-funcool-dont-forget- +ship-damned-thing/) - Greg Taylor gives good advice on mud design. +- [Lost Library of MOO](http://www.hayseed.net/MOO/) - Archive of scientific articles on mudding (in +particular moo). +- [Nick Gammon's hints thread](http://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=5959) - +Contains a very useful list of things to think about when starting your new MUD. +- [Lost Garden](http://www.lostgarden.com/) - A game development blog with long and interesting +articles (not MUD-specific) - [What Games Are](http://whatgamesare.com/) - A blog about general game design (not MUD-specific) -- [The Alexandrian](http://thealexandrian.net/) - A blog about tabletop roleplaying and board games, but with lots of general discussion about rule systems and game balance that could be applicable also for MUDs. -- [Raph Koster's laws of game design](https://www.raphkoster.com/games/laws-of-online-world-design/the-laws-of-online-world-design/) - thought-provoking guidelines and things to think about when designing a virtual multiplayer world (Raph is known for *Ultima Online* among other things). +- [The Alexandrian](http://thealexandrian.net/) - A blog about tabletop roleplaying and board games, +but with lots of general discussion about rule systems and game balance that could be applicable +also for MUDs. +- [Raph Koster's laws of game design](https://www.raphkoster.com/games/laws-of-online-world- +design/the-laws-of-online-world-design/) - thought-provoking guidelines and things to think about +when designing a virtual multiplayer world (Raph is known for *Ultima Online* among other things). ### Literature -- Richard Bartle *Designing Virtual Worlds* ([amazon page](http://www.amazon.com/Designing-Virtual-Worlds-Richard-Bartle/dp/0131018167)) - Essential reading for the design of any persistent game world, written by the co-creator of the original game *MUD*. Published in 2003 but it's still as relevant now as when it came out. Covers everything you need to know and then some. -- Zed A. Shaw *Learn Python the Hard way* ([homepage](https://learnpythonthehardway.org/)) - Despite the imposing name this book is for the absolute Python/programming beginner. One learns the language by gradually creating a small text game! It has been used by multiple users before moving on to Evennia. *Update: This used to be free to read online, this is no longer the case.* -- David M. Beazley *Python Essential Reference (4th ed)* ([amazon page](http://www.amazon.com/Python-Essential-Reference-David-Beazley/dp/0672329786/)) - Our recommended book on Python; it not only efficiently summarizes the language but is also an excellent reference to the standard library for more experienced Python coders. -- Luciano Ramalho, *Fluent Python* ([o'reilly page](http://shop.oreilly.com/product/0636920032519.do)) - This is an excellent book for experienced Python coders willing to take their code to the next level. A great read with a lot of useful info also for veteran Pythonistas. -- Richard Cantillon *An Essay on Economic Theory* ([free pdf](http://mises.org/books/essay_on_economic_theory_cantillon.pdf)) - A very good English translation of *Essai sur la Nature du Commerce en Général*, one of the foundations of modern economic theory. Written in 1730 but the translation is annotated and the essay is actually very easy to follow also for a modern reader. Required reading if you think of implementing a sane game economic system. +- Richard Bartle *Designing Virtual Worlds* ([amazon page](http://www.amazon.com/Designing-Virtual- +Worlds-Richard-Bartle/dp/0131018167)) - Essential reading for the design of any persistent game +world, written by the co-creator of the original game *MUD*. Published in 2003 but it's still as +relevant now as when it came out. Covers everything you need to know and then some. +- Zed A. Shaw *Learn Python the Hard way* ([homepage](https://learnpythonthehardway.org/)) - Despite +the imposing name this book is for the absolute Python/programming beginner. One learns the language +by gradually creating a small text game! It has been used by multiple users before moving on to +Evennia. *Update: This used to be free to read online, this is no longer the case.* +- David M. Beazley *Python Essential Reference (4th ed)* ([amazon +page](http://www.amazon.com/Python-Essential-Reference-David-Beazley/dp/0672329786/)) - Our +recommended book on Python; it not only efficiently summarizes the language but is also an excellent +reference to the standard library for more experienced Python coders. +- Luciano Ramalho, *Fluent Python* ([o'reilly +page](http://shop.oreilly.com/product/0636920032519.do)) - This is an excellent book for experienced +Python coders willing to take their code to the next level. A great read with a lot of useful info +also for veteran Pythonistas. +- Richard Cantillon *An Essay on Economic Theory* ([free +pdf](http://mises.org/books/essay_on_economic_theory_cantillon.pdf)) - A very good English +translation of *Essai sur la Nature du Commerce en Général*, one of the foundations of modern +economic theory. Written in 1730 but the translation is annotated and the essay is actually very +easy to follow also for a modern reader. Required reading if you think of implementing a sane game +economic system. ### Frameworks @@ -103,8 +170,11 @@ - [Library Reference](http://docs.python.org/lib/lib.html) - [Language Reference](http://docs.python.org/ref/ref.html) - [Python tips and tricks](http://www.siafoo.net/article/52) - - [Jetbrains Python academy](https://hyperskill.org/onboarding?track=python) - free online programming curriculum for different skill levels + - [Jetbrains Python academy](https://hyperskill.org/onboarding?track=python) - free online +programming curriculum for different skill levels ### Credits - - Wiki [Home](./index) Icons made by [Freepik](http://www.freepik.com"-title="Freepik">Freepik) from [flaticon.com](http://www.flaticon.com), licensed under [Creative Commons BY 3.0](http://creativecommons.org/licenses/by/3.0). \ No newline at end of file + - Wiki [Home](./index) Icons made by [Freepik](http://www.freepik.com"-title="Freepik">Freepik) from +[flaticon.com](http://www.flaticon.com), licensed under [Creative Commons BY +3.0](http://creativecommons.org/licenses/by/3.0). \ No newline at end of file diff --git a/docs/source/Locks.md b/docs/source/Locks.md index 7ef63b06da..238f045c23 100644 --- a/docs/source/Locks.md +++ b/docs/source/Locks.md @@ -1,11 +1,22 @@ # Locks -For most games it is a good idea to restrict what people can do. In Evennia such restrictions are applied and checked by something called *locks*. All Evennia entities ([Commands](./Commands), [Objects](./Objects), [Scripts](./Scripts), [Accounts](./Accounts), [Help System](./Help-System), [messages](./Communications#Msg) and [channels](./Communications#Channels)) are accessed through locks. +For most games it is a good idea to restrict what people can do. In Evennia such restrictions are +applied and checked by something called *locks*. All Evennia entities ([Commands](./Commands), +[Objects](./Objects), [Scripts](./Scripts), [Accounts](./Accounts), [Help System](./Help-System), +[messages](./Communications#Msg) and [channels](./Communications#Channels)) are accessed through locks. -A lock can be thought of as an "access rule" restricting a particular use of an Evennia entity. Whenever another entity wants that kind of access the lock will analyze that entity in different ways to determine if access should be granted or not. Evennia implements a "lockdown" philosophy - all entities are inaccessible unless you explicitly define a lock that allows some or full access. +A lock can be thought of as an "access rule" restricting a particular use of an Evennia entity. +Whenever another entity wants that kind of access the lock will analyze that entity in different +ways to determine if access should be granted or not. Evennia implements a "lockdown" philosophy - +all entities are inaccessible unless you explicitly define a lock that allows some or full access. -Let's take an example: An object has a lock on itself that restricts how people may "delete" that object. Apart from knowing that it restricts deletion, the lock also knows that only players with the specific ID of, say, `34` are allowed to delete it. So whenever a player tries to run `delete` on the object, the `delete` command makes sure to check if this player is really allowed to do so. It calls the lock, which in turn checks if the player's id is `34`. Only then will it allow `delete` to go on with its job. +Let's take an example: An object has a lock on itself that restricts how people may "delete" that +object. Apart from knowing that it restricts deletion, the lock also knows that only players with +the specific ID of, say, `34` are allowed to delete it. So whenever a player tries to run `delete` +on the object, the `delete` command makes sure to check if this player is really allowed to do so. +It calls the lock, which in turn checks if the player's id is `34`. Only then will it allow `delete` +to go on with its job. ## Setting and checking a lock @@ -13,63 +24,84 @@ The in-game command for setting locks on objects is `lock`: > lock obj = -The `` is a string of a certain form that defines the behaviour of the lock. We will go into more detail on how `` should look in the next section. +The `` is a string of a certain form that defines the behaviour of the lock. We will go +into more detail on how `` should look in the next section. -Code-wise, Evennia handles locks through what is usually called `locks` on all relevant entities. This is a handler that allows you to add, delete and check locks. +Code-wise, Evennia handles locks through what is usually called `locks` on all relevant entities. +This is a handler that allows you to add, delete and check locks. ```python myobj.locks.add() ``` -One can call `locks.check()` to perform a lock check, but to hide the underlying implementation all objects also have a convenience function called `access`. This should preferably be used. In the example below, `accessing_obj` is the object requesting the 'delete' access whereas `obj` is the object that might get deleted. This is how it would look (and does look) from inside the `delete` command: +One can call `locks.check()` to perform a lock check, but to hide the underlying implementation all +objects also have a convenience function called `access`. This should preferably be used. In the +example below, `accessing_obj` is the object requesting the 'delete' access whereas `obj` is the +object that might get deleted. This is how it would look (and does look) from inside the `delete` +command: ```python if not obj.access(accessing_obj, 'delete'): accessing_obj.msg("Sorry, you may not delete that.") - return + return ``` ## Defining locks -Defining a lock (i.e. an access restriction) in Evennia is done by adding simple strings of lock definitions to the object's `locks` property using `obj.locks.add()`. +Defining a lock (i.e. an access restriction) in Evennia is done by adding simple strings of lock +definitions to the object's `locks` property using `obj.locks.add()`. -Here are some examples of lock strings (not including the quotes): +Here are some examples of lock strings (not including the quotes): ```python delete:id(34) # only allow obj #34 to delete - edit:all() # let everyone edit + edit:all() # let everyone edit # only those who are not "very_weak" or are Admins may pick this up - get: not attr(very_weak) or perm(Admin) + get: not attr(very_weak) or perm(Admin) ``` -Formally, a lockstring has the following syntax: +Formally, a lockstring has the following syntax: ```python access_type: [NOT] lockfunc1([arg1,..]) [AND|OR] [NOT] lockfunc2([arg1,...]) [...] ``` -where `[]` marks optional parts. `AND`, `OR` and `NOT` are not case sensitive and excess spaces are ignored. `lockfunc1, lockfunc2` etc are special _lock functions_ available to the lock system. +where `[]` marks optional parts. `AND`, `OR` and `NOT` are not case sensitive and excess spaces are +ignored. `lockfunc1, lockfunc2` etc are special _lock functions_ available to the lock system. -So, a lockstring consists of the type of restriction (the `access_type`), a colon (`:`) and then an expression involving function calls that determine what is needed to pass the lock. Each function returns either `True` or `False`. `AND`, `OR` and `NOT` work as they do normally in Python. If the total result is `True`, the lock is passed. +So, a lockstring consists of the type of restriction (the `access_type`), a colon (`:`) and then an +expression involving function calls that determine what is needed to pass the lock. Each function +returns either `True` or `False`. `AND`, `OR` and `NOT` work as they do normally in Python. If the +total result is `True`, the lock is passed. -You can create several lock types one after the other by separating them with a semicolon (`;`) in the lockstring. The string below yields the same result as the previous example: +You can create several lock types one after the other by separating them with a semicolon (`;`) in +the lockstring. The string below yields the same result as the previous example: - delete:id(34);edit:all();get: not attr(very_weak) or perm(Admin) + delete:id(34);edit:all();get: not attr(very_weak) or perm(Admin) ### Valid access_types -An `access_type`, the first part of a lockstring, defines what kind of capability a lock controls, such as "delete" or "edit". You may in principle name your `access_type` anything as long as it is unique for the particular object. The name of the access types is not case-sensitive. +An `access_type`, the first part of a lockstring, defines what kind of capability a lock controls, +such as "delete" or "edit". You may in principle name your `access_type` anything as long as it is +unique for the particular object. The name of the access types is not case-sensitive. -If you want to make sure the lock is used however, you should pick `access_type` names that you (or the default command set) actually checks for, as in the example of `delete` above that uses the 'delete' `access_type`. +If you want to make sure the lock is used however, you should pick `access_type` names that you (or +the default command set) actually checks for, as in the example of `delete` above that uses the +'delete' `access_type`. Below are the access_types checked by the default commandset. -- [Commands](./Commands) +- [Commands](./Commands) - `cmd` - this defines who may call this command at all. - [Objects](./Objects): - - `control` - who is the "owner" of the object. Can set locks, delete it etc. Defaults to the creator of the object. - - `call` - who may call Object-commands stored on this Object except for the Object itself. By default, Objects share their Commands with anyone in the same location (e.g. so you can 'press' a `Button` object in the room). For Characters and Mobs (who likely only use those Commands for themselves and don't want to share them) this should usually be turned off completely, using something like `call:false()`. + - `control` - who is the "owner" of the object. Can set locks, delete it etc. Defaults to the +creator of the object. + - `call` - who may call Object-commands stored on this Object except for the Object itself. By +default, Objects share their Commands with anyone in the same location (e.g. so you can 'press' a +`Button` object in the room). For Characters and Mobs (who likely only use those Commands for +themselves and don't want to share them) this should usually be turned off completely, using +something like `call:false()`. - `examine` - who may examine this object's properties. - `delete` - who may delete the object. - `edit` - who may edit properties and attributes of the object. @@ -77,10 +109,10 @@ Below are the access_types checked by the default commandset. - `get`- who may pick up the object and carry it around. - `puppet` - who may "become" this object and control it as their "character". - `attrcreate` - who may create new attributes on the object (default True) -- [Characters](./Objects#Characters): +- [Characters](./Objects#Characters): + - Same as for Objects +- [Exits](./Objects#Exits): - Same as for Objects -- [Exits](./Objects#Exits): - - Same as for Objects - `traverse` - who may pass the exit. - [Accounts](./Accounts): - `examine` - who may examine the account's properties. @@ -92,38 +124,56 @@ Below are the access_types checked by the default commandset. - `attrread` - see/access attribute - `attredit` - change/delete attribute - [Channels](./Communications#Channels): - - `control` - who is administrating the channel. This means the ability to delete the channel, boot listeners etc. + - `control` - who is administrating the channel. This means the ability to delete the channel, +boot listeners etc. - `send` - who may send to the channel. - `listen` - who may subscribe and listen to the channel. - [HelpEntry](./Help-System): - `examine` - who may view this help entry (usually everyone) - `edit` - who may edit this help entry. -So to take an example, whenever an exit is to be traversed, a lock of the type *traverse* will be checked. Defining a suitable lock type for an exit object would thus involve a lockstring `traverse: `. +So to take an example, whenever an exit is to be traversed, a lock of the type *traverse* will be +checked. Defining a suitable lock type for an exit object would thus involve a lockstring `traverse: +`. ### Custom access_types -As stated above, the `access_type` part of the lock is simply the 'name' or 'type' of the lock. The text is an arbitrary string that must be unique for an object. If adding a lock with the same `access_type` as one that already exists on the object, the new one override the old one. +As stated above, the `access_type` part of the lock is simply the 'name' or 'type' of the lock. The +text is an arbitrary string that must be unique for an object. If adding a lock with the same +`access_type` as one that already exists on the object, the new one override the old one. -For example, if you wanted to create a bulletin board system and wanted to restrict who can either read a board or post to a board. You could then define locks such as: +For example, if you wanted to create a bulletin board system and wanted to restrict who can either +read a board or post to a board. You could then define locks such as: ```python obj.locks.add("read:perm(Player);post:perm(Admin)") -``` +``` -This will create a 'read' access type for Characters having the `Player` permission or above and a 'post' access type for those with `Admin` permissions or above (see below how the `perm()` lock function works). When it comes time to test these permissions, simply check like this (in this example, the `obj` may be a board on the bulletin board system and `accessing_obj` is the player trying to read the board): +This will create a 'read' access type for Characters having the `Player` permission or above and a +'post' access type for those with `Admin` permissions or above (see below how the `perm()` lock +function works). When it comes time to test these permissions, simply check like this (in this +example, the `obj` may be a board on the bulletin board system and `accessing_obj` is the player +trying to read the board): ```python if not obj.access(accessing_obj, 'read'): accessing_obj.msg("Sorry, you may not read that.") - return + return ``` ### Lock functions -A lock function is a normal Python function put in a place Evennia looks for such functions. The modules Evennia looks at is the list `settings.LOCK_FUNC_MODULES`. *All functions* in any of those modules will automatically be considered a valid lock function. The default ones are found in `evennia/locks/lockfuncs.py` and you can start adding your own in `mygame/server/conf/lockfuncs.py`. You can append the setting to add more module paths. To replace a default lock function, just add your own with the same name. +A lock function is a normal Python function put in a place Evennia looks for such functions. The +modules Evennia looks at is the list `settings.LOCK_FUNC_MODULES`. *All functions* in any of those +modules will automatically be considered a valid lock function. The default ones are found in +`evennia/locks/lockfuncs.py` and you can start adding your own in `mygame/server/conf/lockfuncs.py`. +You can append the setting to add more module paths. To replace a default lock function, just add +your own with the same name. -A lock function must always accept at least two arguments - the *accessing object* (this is the object wanting to get access) and the *accessed object* (this is the object with the lock). Those two are fed automatically as the first two arguments to the function when the lock is checked. Any arguments explicitly given in the lock definition will appear as extra arguments. +A lock function must always accept at least two arguments - the *accessing object* (this is the +object wanting to get access) and the *accessed object* (this is the object with the lock). Those +two are fed automatically as the first two arguments to the function when the lock is checked. Any +arguments explicitly given in the lock definition will appear as extra arguments. ```python # A simple example lock function. Called with e.g. `id(34)`. This is @@ -133,10 +183,10 @@ A lock function must always accept at least two arguments - the *accessing objec if args: wanted_id = args[0] return accessing_obj.id == wanted_id - return False + return False ``` -The above could for example be used in a lock function like this: +The above could for example be used in a lock function like this: ```python # we have `obj` and `owner_object` from before @@ -152,29 +202,40 @@ We could check if the "edit" lock is passed with something like this: return ``` -In this example, everyone except the `caller` with the right `id` will get the error. +In this example, everyone except the `caller` with the right `id` will get the error. -> (Using the `*` and `**` syntax causes Python to magically put all extra arguments into a list `args` and all keyword arguments into a dictionary `kwargs` respectively. If you are unfamiliar with how `*args` and `**kwargs` work, see the Python manuals). +> (Using the `*` and `**` syntax causes Python to magically put all extra arguments into a list +`args` and all keyword arguments into a dictionary `kwargs` respectively. If you are unfamiliar with +how `*args` and `**kwargs` work, see the Python manuals). Some useful default lockfuncs (see `src/locks/lockfuncs.py` for more): - `true()/all()` - give access to everyone -- `false()/none()/superuser()` - give access to none. Superusers bypass the check entirely and are thus the only ones who will pass this check. -- `perm(perm)` - this tries to match a given `permission` property, on an Account firsthand, on a Character second. See [below](./Locks#permissions). +- `false()/none()/superuser()` - give access to none. Superusers bypass the check entirely and are +thus the only ones who will pass this check. +- `perm(perm)` - this tries to match a given `permission` property, on an Account firsthand, on a +Character second. See [below](./Locks#permissions). - `perm_above(perm)` - like `perm` but requires a "higher" permission level than the one given. - `id(num)/dbref(num)` - checks so the access_object has a certain dbref/id. - `attr(attrname)` - checks if a certain [Attribute](./Attributes) exists on accessing_object. -- `attr(attrname, value)` - checks so an attribute exists on accessing_object *and* has the given value. -- `attr_gt(attrname, value)` - checks so accessing_object has a value larger (`>`) than the given value. +- `attr(attrname, value)` - checks so an attribute exists on accessing_object *and* has the given +value. +- `attr_gt(attrname, value)` - checks so accessing_object has a value larger (`>`) than the given +value. - `attr_ge, attr_lt, attr_le, attr_ne` - corresponding for `>=`, `<`, `<=` and `!=`. - `holds(objid)` - checks so the accessing objects contains an object of given name or dbref. -- `inside()` - checks so the accessing object is inside the accessed object (the inverse of `holds()`). -- `pperm(perm)`, `pid(num)/pdbref(num)` - same as `perm`, `id/dbref` but always looks for permissions and dbrefs of *Accounts*, not on Characters. -- `serversetting(settingname, value)` - Only returns True if Evennia has a given setting or a setting set to a given value. +- `inside()` - checks so the accessing object is inside the accessed object (the inverse of +`holds()`). +- `pperm(perm)`, `pid(num)/pdbref(num)` - same as `perm`, `id/dbref` but always looks for +permissions and dbrefs of *Accounts*, not on Characters. +- `serversetting(settingname, value)` - Only returns True if Evennia has a given setting or a +setting set to a given value. ## Checking simple strings -Sometimes you don't really need to look up a certain lock, you just want to check a lockstring. A common use is inside Commands, in order to check if a user has a certain permission. The lockhandler has a method `check_lockstring(accessing_obj, lockstring, bypass_superuser=False)` that allows this. +Sometimes you don't really need to look up a certain lock, you just want to check a lockstring. A +common use is inside Commands, in order to check if a user has a certain permission. The lockhandler +has a method `check_lockstring(accessing_obj, lockstring, bypass_superuser=False)` that allows this. ```python # inside command definition @@ -183,19 +244,32 @@ Sometimes you don't really need to look up a certain lock, you just want to chec return ``` -Note here that the `access_type` can be left to a dummy value since this method does not actually do a Lock lookup. +Note here that the `access_type` can be left to a dummy value since this method does not actually do +a Lock lookup. ## Default locks -Evennia sets up a few basic locks on all new objects and accounts (if we didn't, noone would have any access to anything from the start). This is all defined in the root [Typeclasses](./Typeclasses) of the respective entity, in the hook method `basetype_setup()` (which you usually don't want to edit unless you want to change how basic stuff like rooms and exits store their internal variables). This is called once, before `at_object_creation`, so just put them in the latter method on your child object to change the default. Also creation commands like `create` changes the locks of objects you create - for example it sets the `control` lock_type so as to allow you, its creator, to control and delete the object. +Evennia sets up a few basic locks on all new objects and accounts (if we didn't, noone would have +any access to anything from the start). This is all defined in the root [Typeclasses](./Typeclasses) +of the respective entity, in the hook method `basetype_setup()` (which you usually don't want to +edit unless you want to change how basic stuff like rooms and exits store their internal variables). +This is called once, before `at_object_creation`, so just put them in the latter method on your +child object to change the default. Also creation commands like `create` changes the locks of +objects you create - for example it sets the `control` lock_type so as to allow you, its creator, to +control and delete the object. # Permissions -> This section covers the underlying code use of permissions. If you just want to learn how to practically assign permissions in-game, refer to the [Building Permissions](./Building-Permissions) page, which details how you use the `perm` command. +> This section covers the underlying code use of permissions. If you just want to learn how to +practically assign permissions in-game, refer to the [Building Permissions](./Building-Permissions) +page, which details how you use the `perm` command. -A *permission* is simply a list of text strings stored in the handler `permissions` on `Objects` and `Accounts`. Permissions can be used as a convenient way to structure access levels and hierarchies. It is set by the `perm` command. Permissions are especially handled by the `perm()` and `pperm()` lock functions listed above. +A *permission* is simply a list of text strings stored in the handler `permissions` on `Objects` +and `Accounts`. Permissions can be used as a convenient way to structure access levels and +hierarchies. It is set by the `perm` command. Permissions are especially handled by the `perm()` and +`pperm()` lock functions listed above. -Let's say we have a `red_key` object. We also have red chests that we want to unlock with this key. +Let's say we have a `red_key` object. We also have red chests that we want to unlock with this key. perm red_key = unlocks_red_chests @@ -203,23 +277,28 @@ This gives the `red_key` object the permission "unlocks_red_chests". Next we lo lock red chest = unlock:perm(unlocks_red_chests) -What this lock will expect is to the fed the actual key object. The `perm()` lock function will check the permissions set on the key and only return true if the permission is the one given. +What this lock will expect is to the fed the actual key object. The `perm()` lock function will +check the permissions set on the key and only return true if the permission is the one given. -Finally we need to actually check this lock somehow. Let's say the chest has an command `open ` sitting on itself. Somewhere in its code the command needs to figure out which key you are using and test if this key has the correct permission: +Finally we need to actually check this lock somehow. Let's say the chest has an command `open ` +sitting on itself. Somewhere in its code the command needs to figure out which key you are using and +test if this key has the correct permission: ```python - # self.obj is the chest + # self.obj is the chest # and used_key is the key we used as argument to # the command. The self.caller is the one trying # to unlock the chest if not self.obj.access(used_key, "unlock"): self.caller.msg("The key does not fit!") - return + return ``` -All new accounts are given a default set of permissions defined by `settings.PERMISSION_ACCOUNT_DEFAULT`. +All new accounts are given a default set of permissions defined by +`settings.PERMISSION_ACCOUNT_DEFAULT`. -Selected permission strings can be organized in a *permission hierarchy* by editing the tuple `settings.PERMISSION_HIERARCHY`. Evennia's default permission hierarchy is as follows: +Selected permission strings can be organized in a *permission hierarchy* by editing the tuple +`settings.PERMISSION_HIERARCHY`. Evennia's default permission hierarchy is as follows: Developer # like superuser but affected by locks Admin # can administrate accounts @@ -227,22 +306,38 @@ Selected permission strings can be organized in a *permission hierarchy* by edit Helper # can edit help files Player # can chat and send tells (default level) -(Also the plural form works, so you could use `Developers` etc too). +(Also the plural form works, so you could use `Developers` etc too). -> There is also a `Guest` level below `Player` that is only active if `settings.GUEST_ENABLED` is set. This is never part of `settings.PERMISSION_HIERARCHY`. +> There is also a `Guest` level below `Player` that is only active if `settings.GUEST_ENABLED` is +set. This is never part of `settings.PERMISSION_HIERARCHY`. -The main use of this is that if you use the lock function `perm()` mentioned above, a lock check for a particular permission in the hierarchy will *also* grant access to those with *higher* hierarchy access. So if you have the permission "Admin" you will also pass a lock defined as `perm(Builder)` or any of those levels below "Admin". +The main use of this is that if you use the lock function `perm()` mentioned above, a lock check for +a particular permission in the hierarchy will *also* grant access to those with *higher* hierarchy +access. So if you have the permission "Admin" you will also pass a lock defined as `perm(Builder)` +or any of those levels below "Admin". -When doing an access check from an [Object](./Objects) or Character, the `perm()` lock function will always first use the permissions of any Account connected to that Object before checking for permissions on the Object. In the case of hierarchical permissions (Admins, Builders etc), the Account permission will always be used (this stops an Account from escalating their permission by puppeting a high-level Character). If the permission looked for is not in the hierarchy, an exact match is required, first on the Account and if not found there (or if no Account is connected), then on the Object itself. +When doing an access check from an [Object](./Objects) or Character, the `perm()` lock function will +always first use the permissions of any Account connected to that Object before checking for +permissions on the Object. In the case of hierarchical permissions (Admins, Builders etc), the +Account permission will always be used (this stops an Account from escalating their permission by +puppeting a high-level Character). If the permission looked for is not in the hierarchy, an exact +match is required, first on the Account and if not found there (or if no Account is connected), then +on the Object itself. -Here is how you use `perm` to give an account more permissions: +Here is how you use `perm` to give an account more permissions: perm/account Tommy = Builders perm/account/del Tommy = Builders # remove it again -Note the use of the `/account` switch. It means you assign the permission to the [Accounts](./Accounts) Tommy instead of any [Character](./Objects) that also happens to be named "Tommy". +Note the use of the `/account` switch. It means you assign the permission to the +[Accounts](./Accounts) Tommy instead of any [Character](./Objects) that also happens to be named +"Tommy". -Putting permissions on the *Account* guarantees that they are kept, *regardless* of which Character they are currently puppeting. This is especially important to remember when assigning permissions from the *hierarchy tree* - as mentioned above, an Account's permissions will overrule that of its character. So to be sure to avoid confusion you should generally put hierarchy permissions on the Account, not on their Characters (but see also [quelling](./Locks#Quelling)). +Putting permissions on the *Account* guarantees that they are kept, *regardless* of which Character +they are currently puppeting. This is especially important to remember when assigning permissions +from the *hierarchy tree* - as mentioned above, an Account's permissions will overrule that of its +character. So to be sure to avoid confusion you should generally put hierarchy permissions on the +Account, not on their Characters (but see also [quelling](./Locks#Quelling)). Below is an example of an object without any connected account @@ -265,51 +360,78 @@ And one example of a puppet with a connected account: ## Superusers -There is normally only one *superuser* account and that is the one first created when starting Evennia (User #1). This is sometimes known as the "Owner" or "God" user. A superuser has more than full access - it completely *bypasses* all locks so no checks are even run. This allows for the superuser to always have access to everything in an emergency. But it also hides any eventual errors you might have made in your lock definitions. So when trying out game systems you should either use quelling (see below) or make a second Developer-level character so your locks get tested correctly. +There is normally only one *superuser* account and that is the one first created when starting +Evennia (User #1). This is sometimes known as the "Owner" or "God" user. A superuser has more than +full access - it completely *bypasses* all locks so no checks are even run. This allows for the +superuser to always have access to everything in an emergency. But it also hides any eventual errors +you might have made in your lock definitions. So when trying out game systems you should either use +quelling (see below) or make a second Developer-level character so your locks get tested correctly. ## Quelling -The `quell` command can be used to enforce the `perm()` lockfunc to ignore permissions on the Account and instead use the permissions on the Character only. This can be used e.g. by staff to test out things with a lower permission level. Return to the normal operation with `unquell`. Note that quelling will use the smallest of any hierarchical permission on the Account or Character, so one cannot escalate one's Account permission by quelling to a high-permission Character. Also the superuser can quell their powers this way, making them affectable by locks. +The `quell` command can be used to enforce the `perm()` lockfunc to ignore permissions on the +Account and instead use the permissions on the Character only. This can be used e.g. by staff to +test out things with a lower permission level. Return to the normal operation with `unquell`. Note +that quelling will use the smallest of any hierarchical permission on the Account or Character, so +one cannot escalate one's Account permission by quelling to a high-permission Character. Also the +superuser can quell their powers this way, making them affectable by locks. ## More Lock definition examples examine: attr(eyesight, excellent) or perm(Builders) -You are only allowed to do *examine* on this object if you have 'excellent' eyesight (that is, has an Attribute `eyesight` with the value `excellent` defined on yourself) or if you have the "Builders" permission string assigned to you. +You are only allowed to do *examine* on this object if you have 'excellent' eyesight (that is, has +an Attribute `eyesight` with the value `excellent` defined on yourself) or if you have the +"Builders" permission string assigned to you. - open: holds('the green key') or perm(Builder) + open: holds('the green key') or perm(Builder) -This could be called by the `open` command on a "door" object. The check is passed if you are a Builder or has the right key in your inventory. +This could be called by the `open` command on a "door" object. The check is passed if you are a +Builder or has the right key in your inventory. cmd: perm(Builders) -Evennia's command handler looks for a lock of type `cmd` to determine if a user is allowed to even call upon a particular command or not. When you define a command, this is the kind of lock you must set. See the default command set for lots of examples. If a character/account don't pass the `cmd` lock type the command will not even appear in their `help` list. +Evennia's command handler looks for a lock of type `cmd` to determine if a user is allowed to even +call upon a particular command or not. When you define a command, this is the kind of lock you must +set. See the default command set for lots of examples. If a character/account don't pass the `cmd` +lock type the command will not even appear in their `help` list. cmd: not perm(no_tell) -"Permissions" can also be used to block users or implement highly specific bans. The above example would be be added as a lock string to the `tell` command. This will allow everyone *not* having the "permission" `no_tell` to use the `tell` command. You could easily give an account the "permission" `no_tell` to disable their use of this particular command henceforth. +"Permissions" can also be used to block users or implement highly specific bans. The above example +would be be added as a lock string to the `tell` command. This will allow everyone *not* having the +"permission" `no_tell` to use the `tell` command. You could easily give an account the "permission" +`no_tell` to disable their use of this particular command henceforth. ```python dbref = caller.id - lockstring = "control:id(%s);examine:perm(Builders);delete:id(%s) or perm(Admin);get:all()" % (dbref, dbref) + lockstring = "control:id(%s);examine:perm(Builders);delete:id(%s) or perm(Admin);get:all()" % +(dbref, dbref) new_obj.locks.add(lockstring) ``` -This is how the `create` command sets up new objects. In sequence, this permission string sets the owner of this object be the creator (the one running `create`). Builders may examine the object whereas only Admins and the creator may delete it. Everyone can pick it up. +This is how the `create` command sets up new objects. In sequence, this permission string sets the +owner of this object be the creator (the one running `create`). Builders may examine the object +whereas only Admins and the creator may delete it. Everyone can pick it up. ## A complete example of setting locks on an object -Assume we have two objects - one is ourselves (not superuser) and the other is an [Object](./Objects) called `box`. +Assume we have two objects - one is ourselves (not superuser) and the other is an [Object](./Objects) +called `box`. > create/drop box > desc box = "This is a very big and heavy box." -We want to limit which objects can pick up this heavy box. Let's say that to do that we require the would-be lifter to to have an attribute *strength* on themselves, with a value greater than 50. We assign it to ourselves to begin with. +We want to limit which objects can pick up this heavy box. Let's say that to do that we require the +would-be lifter to to have an attribute *strength* on themselves, with a value greater than 50. We +assign it to ourselves to begin with. > set self/strength = 45 -Ok, so for testing we made ourselves strong, but not strong enough. Now we need to look at what happens when someone tries to pick up the the box - they use the `get` command (in the default set). This is defined in `evennia/commands/default/general.py`. In its code we find this snippet: +Ok, so for testing we made ourselves strong, but not strong enough. Now we need to look at what +happens when someone tries to pick up the the box - they use the `get` command (in the default set). +This is defined in `evennia/commands/default/general.py`. In its code we find this snippet: ```python if not obj.access(caller, 'get'): @@ -320,17 +442,23 @@ Ok, so for testing we made ourselves strong, but not strong enough. Now we need return ``` -So the `get` command looks for a lock with the type *get* (not so surprising). It also looks for an [Attribute](./Attributes) on the checked object called _get_err_msg_ in order to return a customized error message. Sounds good! Let's start by setting that on the box: +So the `get` command looks for a lock with the type *get* (not so surprising). It also looks for an +[Attribute](./Attributes) on the checked object called _get_err_msg_ in order to return a customized +error message. Sounds good! Let's start by setting that on the box: > set box/get_err_msg = You are not strong enough to lift this box. -Next we need to craft a Lock of type *get* on our box. We want it to only be passed if the accessing object has the attribute *strength* of the right value. For this we would need to create a lock function that checks if attributes have a value greater than a given value. Luckily there is already such a one included in evennia (see `evennia/locks/lockfuncs.py`), called `attr_gt`. +Next we need to craft a Lock of type *get* on our box. We want it to only be passed if the accessing +object has the attribute *strength* of the right value. For this we would need to create a lock +function that checks if attributes have a value greater than a given value. Luckily there is already +such a one included in evennia (see `evennia/locks/lockfuncs.py`), called `attr_gt`. -So the lock string will look like this: `get:attr_gt(strength, 50)`. We put this on the box now: +So the lock string will look like this: `get:attr_gt(strength, 50)`. We put this on the box now: lock box = get:attr_gt(strength, 50) -Try to `get` the object and you should get the message that we are not strong enough. Increase your strength above 50 however and you'll pick it up no problem. Done! A very heavy box! +Try to `get` the object and you should get the message that we are not strong enough. Increase your +strength above 50 however and you'll pick it up no problem. Done! A very heavy box! If you wanted to set this up in python code, it would look something like this: @@ -354,6 +482,14 @@ If you wanted to set this up in python code, it would look something like this: ## On Django's permission system -Django also implements a comprehensive permission/security system of its own. The reason we don't use that is because it is app-centric (app in the Django sense). Its permission strings are of the form `appname.permstring` and it automatically adds three of them for each database model in the app - for the app evennia/object this would be for example 'object.create', 'object.admin' and 'object.edit'. This makes a lot of sense for a web application, not so much for a MUD, especially when we try to hide away as much of the underlying architecture as possible. +Django also implements a comprehensive permission/security system of its own. The reason we don't +use that is because it is app-centric (app in the Django sense). Its permission strings are of the +form `appname.permstring` and it automatically adds three of them for each database model in the app +- for the app evennia/object this would be for example 'object.create', 'object.admin' and +'object.edit'. This makes a lot of sense for a web application, not so much for a MUD, especially +when we try to hide away as much of the underlying architecture as possible. -The django permissions are not completely gone however. We use it for validating passwords during login. It is also used exclusively for managing Evennia's web-based admin site, which is a graphical front-end for the database of Evennia. You edit and assign such permissions directly from the web interface. It's stand-alone from the permissions described above. +The django permissions are not completely gone however. We use it for validating passwords during +login. It is also used exclusively for managing Evennia's web-based admin site, which is a graphical +front-end for the database of Evennia. You edit and assign such permissions directly from the web +interface. It's stand-alone from the permissions described above. diff --git a/docs/source/Manually-Configuring-Color.md b/docs/source/Manually-Configuring-Color.md index 4bf7a8c476..f0cc5d62fe 100644 --- a/docs/source/Manually-Configuring-Color.md +++ b/docs/source/Manually-Configuring-Color.md @@ -1,11 +1,19 @@ # Manually Configuring Color -This is a small tutorial for customizing your character objects, using the example of letting users turn on and off ANSI color parsing as an example. `@options NOCOLOR=True` will now do what this tutorial shows, but the tutorial subject can be applied to other toggles you may want, as well. +This is a small tutorial for customizing your character objects, using the example of letting users +turn on and off ANSI color parsing as an example. `@options NOCOLOR=True` will now do what this +tutorial shows, but the tutorial subject can be applied to other toggles you may want, as well. -In the Building guide's [Colors](./TextTags#coloured-text) page you can learn how to add color to your game by using special markup. Colors enhance the gaming experience, but not all users want color. Examples would be users working from clients that don't support color, or people with various seeing disabilities that rely on screen readers to play your game. Also, whereas Evennia normally automatically detects if a client supports color, it may get it wrong. Being able to turn it on manually if you know it **should** work could be a nice feature. +In the Building guide's [Colors](./TextTags#coloured-text) page you can learn how to add color to your +game by using special markup. Colors enhance the gaming experience, but not all users want color. +Examples would be users working from clients that don't support color, or people with various seeing +disabilities that rely on screen readers to play your game. Also, whereas Evennia normally +automatically detects if a client supports color, it may get it wrong. Being able to turn it on +manually if you know it **should** work could be a nice feature. -So here's how to allow those users to remove color. It basically means you implementing a simple configuration system for your characters. This is the basic sequence: +So here's how to allow those users to remove color. It basically means you implementing a simple +configuration system for your characters. This is the basic sequence: 1. Define your own default character typeclass, inheriting from Evennia's default. 1. Set an attribute on the character to control markup on/off. @@ -15,9 +23,11 @@ So here's how to allow those users to remove color. It basically means you imple ## Setting up a custom Typeclass -Create a new module in `mygame/typeclasses` named, for example, `mycharacter.py`. Alternatively you can simply add a new class to 'mygamegame/typeclasses/characters.py'. +Create a new module in `mygame/typeclasses` named, for example, `mycharacter.py`. Alternatively you +can simply add a new class to 'mygamegame/typeclasses/characters.py'. -In your new module(or characters.py), create a new [Typeclass](./Typeclasses) inheriting from `evennia.DefaultCharacter`. We will also import `evennia.utils.ansi`, which we will use later. +In your new module(or characters.py), create a new [Typeclass](./Typeclasses) inheriting from +`evennia.DefaultCharacter`. We will also import `evennia.utils.ansi`, which we will use later. ```python from evennia import Character @@ -31,21 +41,33 @@ In your new module(or characters.py), create a new [Typeclass](./Typeclasses) in Above we set a simple config value as an [Attribute](./Attributes). -Let's make sure that new characters are created of this type. Edit your `mygame/server/conf/settings.py` file and add/change `BASE_CHARACTER_TYPECLASS` to point to your new character class. Observe that this will only affect *new* characters, not those already created. You have to convert already created characters to the new typeclass by using the `@typeclass` command (try on a secondary character first though, to test that everything works - you don't want to render your root user unusable!). +Let's make sure that new characters are created of this type. Edit your +`mygame/server/conf/settings.py` file and add/change `BASE_CHARACTER_TYPECLASS` to point to your new +character class. Observe that this will only affect *new* characters, not those already created. You +have to convert already created characters to the new typeclass by using the `@typeclass` command +(try on a secondary character first though, to test that everything works - you don't want to render +your root user unusable!). @typeclass/reset/force Bob = mycharacter.ColorableCharacter -`@typeclass` changes Bob's typeclass and runs all its creation hooks all over again. The `/reset` switch clears all attributes and properties back to the default for the new typeclass - this is useful in this case to avoid ending up with an object having a "mixture" of properties from the old typeclass and the new one. `/force` might be needed if you edit the typeclass and want to update the object despite the actual typeclass name not having changed. +`@typeclass` changes Bob's typeclass and runs all its creation hooks all over again. The `/reset` +switch clears all attributes and properties back to the default for the new typeclass - this is +useful in this case to avoid ending up with an object having a "mixture" of properties from the old +typeclass and the new one. `/force` might be needed if you edit the typeclass and want to update the +object despite the actual typeclass name not having changed. ## Overload the `msg()` method -Next we need to overload the `msg()` method. What we want is to check the configuration value before calling the main function. The original `msg` method call is seen in `evennia/objects/objects.py` and is called like this: +Next we need to overload the `msg()` method. What we want is to check the configuration value before +calling the main function. The original `msg` method call is seen in `evennia/objects/objects.py` +and is called like this: ```python msg(self, text=None, from_obj=None, session=None, options=None, **kwargs): ``` -As long as we define a method on our custom object with the same name and keep the same number of arguments/keywords we will overload the original. Here's how it could look: +As long as we define a method on our custom object with the same name and keep the same number of +arguments/keywords we will overload the original. Here's how it could look: ```python class ColorableCharacter(Character): @@ -61,17 +83,24 @@ As long as we define a method on our custom object with the same name and keep t session=session, **kwargs) ``` -Above we create a custom version of the `msg()` method. If the configuration Attribute is set, it strips the ANSI from the text it is about to send, and then calls the parent `msg()` as usual. You need to `@reload` before your changes become visible. +Above we create a custom version of the `msg()` method. If the configuration Attribute is set, it +strips the ANSI from the text it is about to send, and then calls the parent `msg()` as usual. You +need to `@reload` before your changes become visible. -There we go! Just flip the attribute `config_color` to False and your users will not see any color. As superuser (assuming you use the Typeclass `ColorableCharacter`) you can test this with the `@py` command: +There we go! Just flip the attribute `config_color` to False and your users will not see any color. +As superuser (assuming you use the Typeclass `ColorableCharacter`) you can test this with the `@py` +command: @py self.db.config_color = False ## Custom color config command -For completeness, let's add a custom command so users can turn off their color display themselves if they want. +For completeness, let's add a custom command so users can turn off their color display themselves if +they want. -In `mygame/commands`, create a new file, call it for example `configcmds.py` (it's likely that you'll want to add other commands for configuration down the line). You can also copy/rename the command template. +In `mygame/commands`, create a new file, call it for example `configcmds.py` (it's likely that +you'll want to add other commands for configuration down the line). You can also copy/rename the +command template. ```python from evennia import Command @@ -106,7 +135,9 @@ In `mygame/commands`, create a new file, call it for example `configcmds.py` (it self.caller.msg("Color was turned off.") ``` -Lastly, we make this command available to the user by adding it to the default `CharacterCmdSet` in `mygame/commands/default_cmdsets.py` and reloading the server. Make sure you also import the command: +Lastly, we make this command available to the user by adding it to the default `CharacterCmdSet` in +`mygame/commands/default_cmdsets.py` and reloading the server. Make sure you also import the +command: ```python from mygame.commands import configcmds @@ -127,7 +158,10 @@ class CharacterCmdSet(default_cmds.CharacterCmdSet): ## More colors -Apart from ANSI colors, Evennia also supports **Xterm256** colors (See [Colors](./TextTags#colored-text)). The `msg()` method supports the `xterm256` keyword for manually activating/deactiving xterm256. It should be easy to expand the above example to allow players to customize xterm256 regardless of if Evennia thinks their client supports it or not. +Apart from ANSI colors, Evennia also supports **Xterm256** colors (See [Colors](./TextTags#colored- +text)). The `msg()` method supports the `xterm256` keyword for manually activating/deactiving +xterm256. It should be easy to expand the above example to allow players to customize xterm256 +regardless of if Evennia thinks their client supports it or not. To get a better understanding of how `msg()` works with keywords, you can try this as superuser: diff --git a/docs/source/Mass-and-weight-for-objects.md b/docs/source/Mass-and-weight-for-objects.md index 0dfd39c959..d8a43571c0 100644 --- a/docs/source/Mass-and-weight-for-objects.md +++ b/docs/source/Mass-and-weight-for-objects.md @@ -40,7 +40,8 @@ non-default mass would be stored on the `mass` [[Attributes]] of the objects. You can add a `get_mass` definition to characters and rooms, also. -If you were in a one metric-ton elevator with four other friends also wearing armor and carrying gold bricks, you might wonder if this elevator's going to move, and how fast. +If you were in a one metric-ton elevator with four other friends also wearing armor and carrying +gold bricks, you might wonder if this elevator's going to move, and how fast. Assuming the unit is grams and the elevator itself weights 1,000 kilograms, it would already be `@set elevator/mass=1000000`, we're `@set me/mass=85000` and our armor is `@set armor/mass=50000`. @@ -57,10 +58,13 @@ else: ``` #### Inventory -Example of listing mass of items in your inventory: +Example of listing mass of items in your inventory, don't forget to add it to your +default_cmdsets.py file: ```python -class CmdInventory(MuxCommand): +from evennia import utils + +class CmdInventory(Command): """ view inventory Usage: @@ -81,15 +85,11 @@ class CmdInventory(MuxCommand): if not items: string = "You are not carrying anything." else: - table = prettytable.PrettyTable(["name", "desc"]) - table.header = False - table.border = False + table = utils.evtable.EvTable("name", "weight") for item in items: - second = item.get_mass() \ - if 'weight' in self.switches else item.db.desc - table.add_row(["%s" % item.get_display_name(self.caller.sessions), - second and second or ""]) - string = "|wYou are carrying:\n%s" % table + mass = item.get_mass() + table.add_row(item.name, mass) + string = f"|wYou are carrying:|n\n{table}" self.caller.msg(string) ``` diff --git a/docs/source/Messagepath.md b/docs/source/Messagepath.md index 31e56bbc90..ee8e8672ec 100644 --- a/docs/source/Messagepath.md +++ b/docs/source/Messagepath.md @@ -1,7 +1,10 @@ # Messagepath -The main functionality of Evennia is to communicate with clients connected to it; a player enters commands or their client queries for a gui update (ingoing data). The server responds or sends data on its own as the game changes (outgoing data). It's important to understand how this flow of information works in Evennia. +The main functionality of Evennia is to communicate with clients connected to it; a player enters +commands or their client queries for a gui update (ingoing data). The server responds or sends data +on its own as the game changes (outgoing data). It's important to understand how this flow of +information works in Evennia. ## The ingoing message path @@ -40,47 +43,72 @@ depends on the [Protocol](./Custom-Protocols) used: ### Portal Session (ingoing) -Each client is connected to the game via a *Portal Session*, one per connection. This Session is different depending on the type of connection (telnet, webclient etc) and thus know how to handle that particular data type. So regardless of how the data arrives, the Session will identify the type of the instruction and any arguments it should have. For example, the telnet protocol will figure that anything arriving normally over the wire should be passed on as a "text" type. +Each client is connected to the game via a *Portal Session*, one per connection. This Session is +different depending on the type of connection (telnet, webclient etc) and thus know how to handle +that particular data type. So regardless of how the data arrives, the Session will identify the type +of the instruction and any arguments it should have. For example, the telnet protocol will figure +that anything arriving normally over the wire should be passed on as a "text" type. ### PortalSessionHandler (ingoing) -The *PortalSessionhandler* manages all connected Sessions in the Portal. Its `data_in` method (called by each Portal Session) will parse the command names and arguments from the protocols and convert them to a standardized form we call the *inputcommand*: +The *PortalSessionhandler* manages all connected Sessions in the Portal. Its `data_in` method +(called by each Portal Session) will parse the command names and arguments from the protocols and +convert them to a standardized form we call the *inputcommand*: ```python (commandname, (args), {kwargs}) ``` -All inputcommands must have a name, but they may or may not have arguments and keyword arguments - in fact no default inputcommands use kwargs at all. The most common inputcommand is "text", which has the argument the player input on the command line: +All inputcommands must have a name, but they may or may not have arguments and keyword arguments - +in fact no default inputcommands use kwargs at all. The most common inputcommand is "text", which +has the argument the player input on the command line: ```python ("text", ("look",), {}) ``` -This inputcommand-structure is pickled together with the unique session-id of the Session to which it belongs. This is then sent over the AMP connection. +This inputcommand-structure is pickled together with the unique session-id of the Session to which +it belongs. This is then sent over the AMP connection. ### ServerSessionHandler (ingoing) -On the Server side, the AMP unpickles the data and associates the session id with the server-side [Session](./Sessions). Data and Session are passed to the server-side `SessionHandler.data_in`. This in turn calls `ServerSession.data_in()` +On the Server side, the AMP unpickles the data and associates the session id with the server-side +[Session](./Sessions). Data and Session are passed to the server-side `SessionHandler.data_in`. This +in turn calls `ServerSession.data_in()` ### ServerSession (ingoing) -The method `ServerSession.data_in` is meant to offer a single place to override if they want to examine *all* data passing into the server from the client. It is meant to call the `ssessionhandler.call_inputfuncs` with the (potentially processed) data (so this is technically a sort of detour back to the sessionhandler). +The method `ServerSession.data_in` is meant to offer a single place to override if they want to +examine *all* data passing into the server from the client. It is meant to call the +`ssessionhandler.call_inputfuncs` with the (potentially processed) data (so this is technically a +sort of detour back to the sessionhandler). -In `call_inputfuncs`, the inputcommand's name is compared against the names of all the *inputfuncs* registered with the server. The inputfuncs are named the same as the inputcommand they are supposed to handle, so the (default) inputfunc for handling our "look" command is called "text". These are just normal functions and one can plugin new ones by simply putting them in a module where Evennia looks for such functions. +In `call_inputfuncs`, the inputcommand's name is compared against the names of all the *inputfuncs* +registered with the server. The inputfuncs are named the same as the inputcommand they are supposed +to handle, so the (default) inputfunc for handling our "look" command is called "text". These are +just normal functions and one can plugin new ones by simply putting them in a module where Evennia +looks for such functions. -If a matching inputfunc is found, it will be called with the Session and the inputcommand's arguments: +If a matching inputfunc is found, it will be called with the Session and the inputcommand's +arguments: ```python text(session, *("look",), **{}) ``` - If no matching inputfunc is found, an inputfunc named "default" will be tried and if that is also not found, an error will be raised. + If no matching inputfunc is found, an inputfunc named "default" will be tried and if that is also +not found, an error will be raised. ### Inputfunc -The [Inputfunc](./Inputfuncs) must be on the form `func(session, *args, **kwargs)`. An exception is the `default` inputfunc which has form `default(session, cmdname, *args, **kwargs)`, where `cmdname` is the un-matched inputcommand string. +The [Inputfunc](./Inputfuncs) must be on the form `func(session, *args, **kwargs)`. An exception is +the `default` inputfunc which has form `default(session, cmdname, *args, **kwargs)`, where `cmdname` +is the un-matched inputcommand string. -This is where the message's path diverges, since just what happens next depends on the type of inputfunc was triggered. In the example of sending "look", the inputfunc is named "text". It will pass the argument to the `cmdhandler` which will eventually lead to the `look` command being executed. +This is where the message's path diverges, since just what happens next depends on the type of +inputfunc was triggered. In the example of sending "look", the inputfunc is named "text". It will +pass the argument to the `cmdhandler` which will eventually lead to the `look` command being +executed. ## The outgoing message path @@ -109,7 +137,11 @@ The call sign of the `msg` method looks like this: msg(text=None, from_obj=None, session=None, options=None, **kwargs) ``` -For our purposes, what is important to know is that with the exception of `from_obj`, `session` and `options`, all keywords given to the `msg` method is the name of an *outputcommand* and its arguments. So `text` is actually such a command, taking a string as its argument. The reason `text` sits as the first keyword argument is that it's so commonly used (`caller.msg("Text")` for example). Here are some examples +For our purposes, what is important to know is that with the exception of `from_obj`, `session` and +`options`, all keywords given to the `msg` method is the name of an *outputcommand* and its +arguments. So `text` is actually such a command, taking a string as its argument. The reason `text` +sits as the first keyword argument is that it's so commonly used (`caller.msg("Text")` for example). +Here are some examples ```python msg("Hello!") # using the 'text' outputfunc @@ -117,39 +149,144 @@ For our purposes, what is important to know is that with the exception of `from_ msg(mycommand=((1,2,3,4), {"foo": "bar"}) ``` -Note the form of the `mycommand` outputfunction. This explicitly defines the arguments and keyword arguments for the function. In the case of the `text` and `prompt` calls we just specify a string - this works too: The system will convert this into a single argument for us later in the message path. +Note the form of the `mycommand` outputfunction. This explicitly defines the arguments and keyword +arguments for the function. In the case of the `text` and `prompt` calls we just specify a string - +this works too: The system will convert this into a single argument for us later in the message +path. -> Note: The `msg` method sits on your Object- and Account typeclasses. It means you can easily override `msg` and make custom- or per-object modifications to the flow of data as it passes through. +> Note: The `msg` method sits on your Object- and Account typeclasses. It means you can easily +override `msg` and make custom- or per-object modifications to the flow of data as it passes +through. ### ServerSession (outgoing) -Nothing is processed on the Session, it just serves as a gathering points for all different `msg`. It immediately passes the data on to ... +Nothing is processed on the Session, it just serves as a gathering points for all different `msg`. +It immediately passes the data on to ... ### ServerSessionHandler (outgoing) -In the *ServerSessionhandler*, the keywords from the `msg` method are collated into one or more *outputcommands* on a standardized form (identical to inputcommands): +In the *ServerSessionhandler*, the keywords from the `msg` method are collated into one or more +*outputcommands* on a standardized form (identical to inputcommands): ``` (commandname, (args), {kwargs}) ``` -This will intelligently convert different input to the same form. So `msg("Hello")` will end up as an outputcommand `("text", ("Hello",), {})`. +This will intelligently convert different input to the same form. So `msg("Hello")` will end up as +an outputcommand `("text", ("Hello",), {})`. -This is also the point where [Inlinefuncs](./TextTags#inline-functions) are parsed, depending on the session to receive the data. Said data is pickled together with the Session id then sent over the AMP bridge. +This is also the point where [Inlinefuncs](./TextTags#inline-functions) are parsed, depending on the +session to receive the data. Said data is pickled together with the Session id then sent over the +AMP bridge. ### PortalSessionHandler (outgoing) -After the AMP connection has unpickled the data and paired the session id to the matching PortalSession, the handler next determines if this Session has a suitable method for handling the outputcommand. +After the AMP connection has unpickled the data and paired the session id to the matching +PortalSession, the handler next determines if this Session has a suitable method for handling the +outputcommand. -The situation is analogous to how inputfuncs work, except that protocols are fixed things that don't need a plugin infrastructure like the inputfuncs are handled. So instead of an "outputfunc", the handler looks for methods on the PortalSession with names of the form `send_`. +The situation is analogous to how inputfuncs work, except that protocols are fixed things that don't +need a plugin infrastructure like the inputfuncs are handled. So instead of an "outputfunc", the +handler looks for methods on the PortalSession with names of the form `send_`. -For example, the common sending of text expects a PortalSession method `send_text`. This will be called as `send_text(*("Hello",), **{})`. If the "prompt" outputfunction was used, send_prompt is called. In all other cases the `send_default(cmdname, *args, **kwargs)` will be called - this is the case for all client-custom outputcommands, like when wanting to tell the client to update a graphic or play a sound. +For example, the common sending of text expects a PortalSession method `send_text`. This will be +called as `send_text(*("Hello",), **{})`. If the "prompt" outputfunction was used, send_prompt is +called. In all other cases the `send_default(cmdname, *args, **kwargs)` will be called - this is the +case for all client-custom outputcommands, like when wanting to tell the client to update a graphic +or play a sound. ### PortalSession (outgoing) -At this point it is up to the session to convert the command into a form understood by this particular protocol. For telnet, `send_text` will just send the argument as a string (since that is what telnet clients expect when "text" is coming). If `send_default` was called (basically everything that is not traditional text or a prompt), it will pack the data as an GMCP or MSDP command packet if the telnet client supports either (otherwise it won't send at all). If sending to the webclient, the data will get packed into a JSON structure at all times. +At this point it is up to the session to convert the command into a form understood by this +particular protocol. For telnet, `send_text` will just send the argument as a string (since that is +what telnet clients expect when "text" is coming). If `send_default` was called (basically +everything that is not traditional text or a prompt), it will pack the data as an GMCP or MSDP +command packet if the telnet client supports either (otherwise it won't send at all). If sending to +the webclient, the data will get packed into a JSON structure at all times. ### Client (outgoing) -Once arrived at the client, the outputcommand is handled in the way supported by the client (or it may be quietly ignored if not). "text" commands will be displayed in the main window while others may trigger changes in the GUI or play a sound etc. +Once arrived at the client, the outputcommand is handled in the way supported by the client (or it +may be quietly ignored if not). "text" commands will be displayed in the main window while others +may trigger changes in the GUI or play a sound etc. +### Full example of Outgoing Message + +For a full outgoing message, you need to have the outgoing function defined in the javascript. See +https://evennia.readthedocs.io/en/latest/Web-Client-Webclient.html for getting set up with custom +webclient code. Once you have a custom plugin defined and loaded, create a new function in the +plugin, onCustomFunc() for example: + +```javascript + var onCustomFunc = function(args, kwargs) { + var = args.var + console.log(var) + } +``` + +You'll also need to add the function to what the main plugin function returns: + +```javascript + return { + init: init, + onCustomFunc, + } +``` + +This defines the function and looks for "var" as a variable that is passed to it. Once you have this +in place in your custom plugin, you also need to update the static/webclient/js/webclient_gui.js +file to recognize the new function when it's called. First you should add a new function inside the +plugin_handler function to recognize the new function: + +```javascript + var onCustomFunc = function (cmdname, args, kwargs) { + for( let n=0; n < ordered_plugins.length; n++ ) { + let plugin = ordered_plugins[n]; + if( 'onCustomFunc' in plugin ) { + if( plugin.onCustomFunc(args, kwargs) ) { + // True -- means this plugin claims this command exclusively. + return; + } + } + } + } +``` + +This looks through all the plugins for a function that corresponds to the custom function being +called. Next, add the custom function to the return statement of the plugin handler: + +```javascript + return { + add: add, + onKeydown: onKeydown, + onBeforeUnload: onBeforeUnload, + onLoggedIn: onLoggedIn, + onText: onText, + onGotOptions: onGotOptions, + onPrompt: onPrompt, + onDefault: onDefault, + onSilence: onSilence, + onConnectionClose: onConnectionClose, + onSend: onSend, + init: init, + postInit: postInit, + onCustomFunc: onCustomFunc, + } +``` +Lastly, you will also need to need to add an entry to the Evennia emitter to tie the python function +call to this new javascript function (this is in the $(document).ready function): + +```javascript + Evennia.emitter.on("customFunc", plugin_handler.onCustomFunc); +``` + +Now you can make a call from your python code to the new custom function to pass information from +the server to the client: + +```python + character.msg(customFunc=({"var": "blarg"})) +``` + +When this code in your python is run, you should be able to see the "blarg" string printed in the +web client console. You should now be able to update the function call and definition to pass any +information needed between server and client. \ No newline at end of file diff --git a/docs/source/MonitorHandler.md b/docs/source/MonitorHandler.md index 046878050f..2deb64080b 100644 --- a/docs/source/MonitorHandler.md +++ b/docs/source/MonitorHandler.md @@ -1,15 +1,19 @@ # MonitorHandler -The *MonitorHandler* is a system for watching changes in properties or Attributes on objects. A monitor can be thought of as a sort of trigger that responds to change. +The *MonitorHandler* is a system for watching changes in properties or Attributes on objects. A +monitor can be thought of as a sort of trigger that responds to change. -The main use for the MonitorHandler is to report changes to the client; for example the client Session may ask Evennia to monitor the value of the Characer's `health` attribute and report whenever it changes. This way the client could for example update its health bar graphic as needed. +The main use for the MonitorHandler is to report changes to the client; for example the client +Session may ask Evennia to monitor the value of the Characer's `health` attribute and report +whenever it changes. This way the client could for example update its health bar graphic as needed. ## Using the MonitorHandler -The MontorHandler is accessed from the singleton `evennia.MONITOR_HANDLER`. The code for the handler is in `evennia.scripts.monitorhandler`. +The MontorHandler is accessed from the singleton `evennia.MONITOR_HANDLER`. The code for the handler +is in `evennia.scripts.monitorhandler`. -Here's how to add a new monitor: +Here's how to add a new monitor: ```python from evennia import MONITOR_HANDLER @@ -19,23 +23,32 @@ MONITOR_HANDLER.add(obj, fieldname, callback, ``` - - `obj` ([Typeclassed](./Typeclasses) entity) - the object to monitor. Since this must be typeclassed, it means you can't monitor changes on [Sessions](./Sessions) with the monitorhandler, for example. - - `fieldname` (str) - the name of a field or [Attribute](./Attributes) on `obj`. If you want to monitor a database field you must specify its full name, including the starting `db_` (like `db_key`, `db_location` etc). Any names not starting with `db_` are instead assumed to be the names of Attributes. This difference matters, since the MonitorHandler will automatically know to watch the `db_value` field of the Attribute. - - `callback`(callable) - This will be called as `callback(fieldname=fieldname, obj=obj, **kwargs)` when the field updates. - - `idstring` (str) - this is used to separate multiple monitors on the same object and fieldname. This is required in order to properly identify and remove the monitor later. It's also used for saving it. + - `obj` ([Typeclassed](./Typeclasses) entity) - the object to monitor. Since this must be +typeclassed, it means you can't monitor changes on [Sessions](./Sessions) with the monitorhandler, for +example. + - `fieldname` (str) - the name of a field or [Attribute](./Attributes) on `obj`. If you want to +monitor a database field you must specify its full name, including the starting `db_` (like +`db_key`, `db_location` etc). Any names not starting with `db_` are instead assumed to be the names +of Attributes. This difference matters, since the MonitorHandler will automatically know to watch +the `db_value` field of the Attribute. + - `callback`(callable) - This will be called as `callback(fieldname=fieldname, obj=obj, **kwargs)` +when the field updates. + - `idstring` (str) - this is used to separate multiple monitors on the same object and fieldname. +This is required in order to properly identify and remove the monitor later. It's also used for +saving it. - `persistent` (bool) - if True, the monitor will survive a server reboot. -Example: +Example: ```python from evennia import MONITOR_HANDLER as monitorhandler -def _monitor_callback(fieldname="", obj=None, **kwargs): +def _monitor_callback(fieldname="", obj=None, **kwargs): # reporting callback that works both # for db-fields and Attributes if fieldname.startswith("db_"): new_value = getattr(obj, fieldname) - else: # an attribute + else: # an attribute new_value = obj.attributes.get(fieldname) obj.msg("%s.%s changed to '%s'." % \ @@ -44,17 +57,20 @@ def _monitor_callback(fieldname="", obj=None, **kwargs): # (we could add _some_other_monitor_callback here too) # monitor Attribute (assume we have obj from before) -monitorhandler.add(obj, "desc", _monitor_callback) +monitorhandler.add(obj, "desc", _monitor_callback) # monitor same db-field with two different callbacks (must separate by id_string) -monitorhandler.add(obj, "db_key", _monitor_callback, id_string="foo") +monitorhandler.add(obj, "db_key", _monitor_callback, id_string="foo") monitorhandler.add(obj, "db_key", _some_other_monitor_callback, id_string="bar") ``` -A monitor is uniquely identified by the combination of the *object instance* it is monitoring, the *name* of the field/attribute to monitor on that object and its `idstring` (`obj` + `fieldname` + `idstring`). The `idstring` will be the empty string unless given explicitly. +A monitor is uniquely identified by the combination of the *object instance* it is monitoring, the +*name* of the field/attribute to monitor on that object and its `idstring` (`obj` + `fieldname` + +`idstring`). The `idstring` will be the empty string unless given explicitly. -So to "un-monitor" the above you need to supply enough information for the system to uniquely find the monitor to remove: +So to "un-monitor" the above you need to supply enough information for the system to uniquely find +the monitor to remove: ``` monitorhandler.remove(obj, "desc") diff --git a/docs/source/NPC-shop-Tutorial.md b/docs/source/NPC-shop-Tutorial.md index c48212a6c4..0ead5df41d 100644 --- a/docs/source/NPC-shop-Tutorial.md +++ b/docs/source/NPC-shop-Tutorial.md @@ -1,23 +1,34 @@ # NPC shop Tutorial -This tutorial will describe how to make an NPC-run shop. We will make use of the [EvMenu](./EvMenu) system to present shoppers with a menu where they can buy things from the store's stock. +This tutorial will describe how to make an NPC-run shop. We will make use of the [EvMenu](./EvMenu) +system to present shoppers with a menu where they can buy things from the store's stock. -Our shop extends over two rooms - a "front" room open to the shop's customers and a locked "store room" holding the wares the shop should be able to sell. We aim for the following features: +Our shop extends over two rooms - a "front" room open to the shop's customers and a locked "store +room" holding the wares the shop should be able to sell. We aim for the following features: - The front room should have an Attribute `storeroom` that points to the store room. - - Inside the front room, the customer should have a command `buy` or `browse`. This will open a menu listing all items available to buy from the store room. + - Inside the front room, the customer should have a command `buy` or `browse`. This will open a +menu listing all items available to buy from the store room. - A customer should be able to look at individual items before buying. - - We use "gold" as an example currency. To determine cost, the system will look for an Attribute `gold_value` on the items in the store room. If not found, a fixed base value of 1 will be assumed. The wealth of the customer should be set as an Attribute `gold` on the Character. If not set, they have no gold and can't buy anything. - - When the customer makes a purchase, the system will check the `gold_value` of the goods and compare it to the `gold` Attribute of the customer. If enough gold is available, this will be deducted and the goods transferred from the store room to the inventory of the customer. + - We use "gold" as an example currency. To determine cost, the system will look for an Attribute +`gold_value` on the items in the store room. If not found, a fixed base value of 1 will be assumed. +The wealth of the customer should be set as an Attribute `gold` on the Character. If not set, they +have no gold and can't buy anything. + - When the customer makes a purchase, the system will check the `gold_value` of the goods and +compare it to the `gold` Attribute of the customer. If enough gold is available, this will be +deducted and the goods transferred from the store room to the inventory of the customer. - We will lock the store room so that only people with the right key can get in there. ### The shop menu -We want to show a menu to the customer where they can list, examine and buy items in the store. This menu should change depending on what is currently for sale. Evennia's *EvMenu* utility will manage the menu for us. It's a good idea to [read up on EvMenu](./EvMenu) if you are not familiar with it. +We want to show a menu to the customer where they can list, examine and buy items in the store. This +menu should change depending on what is currently for sale. Evennia's *EvMenu* utility will manage +the menu for us. It's a good idea to [read up on EvMenu](./EvMenu) if you are not familiar with it. #### Designing the menu -The shopping menu's design is straightforward. First we want the main screen. You get this when you enter a shop and use the `browse` or `buy` command: +The shopping menu's design is straightforward. First we want the main screen. You get this when you +enter a shop and use the `browse` or `buy` command: ``` *** Welcome to ye Old Sword shop! *** @@ -28,7 +39,9 @@ _________________________________________________________ 3. Excalibur (100 gold) ``` -There are only three items to buy in this example but the menu should expand to however many items are needed. When you make a selection you will get a new screen showing the options for that particular item: +There are only three items to buy in this example but the menu should expand to however many items +are needed. When you make a selection you will get a new screen showing the options for that +particular item: ``` You inspect A rusty sword: @@ -53,7 +66,10 @@ After this you should be back to the top level of the shopping menu again and ca #### Coding the menu -EvMenu defines the *nodes* (each menu screen with options) as normal Python functions. Each node must be able to change on the fly depending on what items are currently for sale. EvMenu will automatically make the `quit` command available to us so we won't add that manually. For compactness we will put everything needed for our shop in one module, `mygame/typeclasses/npcshop.py`. +EvMenu defines the *nodes* (each menu screen with options) as normal Python functions. Each node +must be able to change on the fly depending on what items are currently for sale. EvMenu will +automatically make the `quit` command available to us so we won't add that manually. For compactness +we will put everything needed for our shop in one module, `mygame/typeclasses/npcshop.py`. ```python # mygame/typeclasses/npcshop.py @@ -86,9 +102,14 @@ def menunode_shopfront(caller): return text, options ``` -In this code we assume the caller to be *inside* the shop when accessing the menu. This means we can access the shop room via `caller.location` and get its `key` to display as the shop's name. We also assume the shop has an Attribute `storeroom` we can use to get to our stock. We loop over our goods to build up the menu's options. +In this code we assume the caller to be *inside* the shop when accessing the menu. This means we can +access the shop room via `caller.location` and get its `key` to display as the shop's name. We also +assume the shop has an Attribute `storeroom` we can use to get to our stock. We loop over our goods +to build up the menu's options. -Note that *all options point to the same menu node* called `menunode_inspect_and_buy`! We can't know which goods will be available to sale so we rely on this node to modify itself depending on the circumstances. Let's create it now. +Note that *all options point to the same menu node* called `menunode_inspect_and_buy`! We can't know +which goods will be available to sale so we rely on this node to modify itself depending on the +circumstances. Let's create it now. ```python # further down in mygame/typeclasses/npcshop.py @@ -127,15 +148,27 @@ def menunode_inspect_and_buy(caller, raw_string): return text, options ``` -In this menu node we make use of the `raw_string` argument to the node. This is the text the menu user entered on the *previous* node to get here. Since we only allow numbered options in our menu, `raw_input` must be an number for the player to get to this point. So we convert it to an integer index (menu lists start from 1, whereas Python indices always starts at 0, so we need to subtract 1). We then use the index to get the corresponding item from storage. +In this menu node we make use of the `raw_string` argument to the node. This is the text the menu +user entered on the *previous* node to get here. Since we only allow numbered options in our menu, +`raw_input` must be an number for the player to get to this point. So we convert it to an integer +index (menu lists start from 1, whereas Python indices always starts at 0, so we need to subtract +1). We then use the index to get the corresponding item from storage. -We just show the customer the `desc` of the item. In a more elaborate setup you might want to show things like weapon damage and special stats here as well. +We just show the customer the `desc` of the item. In a more elaborate setup you might want to show +things like weapon damage and special stats here as well. -When the user choose the "buy" option, EvMenu will execute the `exec` instruction *before* we go back to the top node (the `goto` instruction). For this we make a little inline function `buy_ware_result`. EvMenu will call the function given to `exec` like any menu node but it does not need to return anything. In `buy_ware_result` we determine if the customer can afford the cost and give proper return messages. This is also where we actually move the bought item into the inventory of the customer. +When the user choose the "buy" option, EvMenu will execute the `exec` instruction *before* we go +back to the top node (the `goto` instruction). For this we make a little inline function +`buy_ware_result`. EvMenu will call the function given to `exec` like any menu node but it does not +need to return anything. In `buy_ware_result` we determine if the customer can afford the cost and +give proper return messages. This is also where we actually move the bought item into the inventory +of the customer. #### The command to start the menu -We could *in principle* launch the shopping menu the moment a customer steps into our shop room, but this would probably be considered pretty annoying. It's better to create a [Command](./Commands) for customers to explicitly wanting to shop around. +We could *in principle* launch the shopping menu the moment a customer steps into our shop room, but +this would probably be considered pretty annoying. It's better to create a [Command](./Commands) for +customers to explicitly wanting to shop around. ```python # mygame/typeclasses/npcshop.py @@ -164,7 +197,10 @@ class CmdBuy(Command): startnode="menunode_shopfront") ``` -This will launch the menu. The `EvMenu` instance is initialized with the path to this very module - since the only global functions available in this module are our menu nodes, this will work fine (you could also have put those in a separate module). We now just need to put this command in a [CmdSet](./Command-Sets) so we can add it correctly to the game: +This will launch the menu. The `EvMenu` instance is initialized with the path to this very module - +since the only global functions available in this module are our menu nodes, this will work fine +(you could also have put those in a separate module). We now just need to put this command in a +[CmdSet](./Command-Sets) so we can add it correctly to the game: ```python from evennia import CmdSet @@ -179,9 +215,13 @@ class ShopCmdSet(CmdSet): There are really only two things that separate our shop from any other Room: - The shop has the `storeroom` Attribute set on it, pointing to a second (completely normal) room. -- It has the `ShopCmdSet` stored on itself. This makes the `buy` command available to users entering the shop. +- It has the `ShopCmdSet` stored on itself. This makes the `buy` command available to users entering +the shop. -For testing we could easily add these features manually to a room using `@py` or other admin commands. Just to show how it can be done we'll instead make a custom [Typeclass](./Typeclasses) for the shop room and make a small command that builders can use to build both the shop and the storeroom at once. +For testing we could easily add these features manually to a room using `@py` or other admin +commands. Just to show how it can be done we'll instead make a custom [Typeclass](./Typeclasses) for +the shop room and make a small command that builders can use to build both the shop and the +storeroom at once. ```python # bottom of mygame/typeclasses/npcshop.py @@ -252,22 +292,43 @@ class CmdBuildShop(Command): self.caller.msg("The shop %s was created!" % shop) ``` -Our typeclass is simple and so is our `buildshop` command. The command (which is for Builders only) just takes the name of the shop and builds the front room and a store room to go with it (always named `"-storage"`. It connects the rooms with a two-way exit. You need to add `CmdBuildShop` [to the default cmdset](./Adding-Command-Tutorial#step-2-adding-the-command-to-a-default-cmdset) before you can use it. Once having created the shop you can now `@teleport` to it or `@open` a new exit to it. You could also easily expand the above command to automatically create exits to and from the new shop from your current location. +Our typeclass is simple and so is our `buildshop` command. The command (which is for Builders only) +just takes the name of the shop and builds the front room and a store room to go with it (always +named `"-storage"`. It connects the rooms with a two-way exit. You need to add +`CmdBuildShop` [to the default cmdset](./Adding-Command-Tutorial#step-2-adding-the-command-to-a- +default-cmdset) before you can use it. Once having created the shop you can now `@teleport` to it or +`@open` a new exit to it. You could also easily expand the above command to automatically create +exits to and from the new shop from your current location. -To avoid customers walking in and stealing everything, we create a [Lock](./Locks) on the storage door. It's a simple lock that requires the one entering to carry an object named `-storekey`. We even create such a key object and drop it in the shop for the new shop keeper to pick up. +To avoid customers walking in and stealing everything, we create a [Lock](./Locks) on the storage +door. It's a simple lock that requires the one entering to carry an object named +`-storekey`. We even create such a key object and drop it in the shop for the new shop +keeper to pick up. -> If players are given the right to name their own objects, this simple lock is not very secure and you need to come up with a more robust lock-key solution. +> If players are given the right to name their own objects, this simple lock is not very secure and +you need to come up with a more robust lock-key solution. -> We don't add any descriptions to all these objects so looking "at" them will not be too thrilling. You could add better default descriptions as part of the `@buildshop` command or leave descriptions this up to the Builder. +> We don't add any descriptions to all these objects so looking "at" them will not be too thrilling. +You could add better default descriptions as part of the `@buildshop` command or leave descriptions +this up to the Builder. ### The shop is open for business! -We now have a functioning shop and an easy way for Builders to create it. All you need now is to `@open` a new exit from the rest of the game into the shop and put some sell-able items in the store room. Our shop does have some shortcomings: +We now have a functioning shop and an easy way for Builders to create it. All you need now is to +`@open` a new exit from the rest of the game into the shop and put some sell-able items in the store +room. Our shop does have some shortcomings: -- For Characters to be able to buy stuff they need to also have the `gold` Attribute set on themselves. -- We manually remove the "door" exit from our items for sale. But what if there are other unsellable items in the store room? What if the shop owner walks in there for example - anyone in the store could then buy them for 1 gold. -- What if someone else were to buy the item we're looking at just before we decide to buy it? It would then be gone and the counter be wrong - the shop would pass us the next item in the list. +- For Characters to be able to buy stuff they need to also have the `gold` Attribute set on +themselves. +- We manually remove the "door" exit from our items for sale. But what if there are other unsellable +items in the store room? What if the shop owner walks in there for example - anyone in the store +could then buy them for 1 gold. +- What if someone else were to buy the item we're looking at just before we decide to buy it? It +would then be gone and the counter be wrong - the shop would pass us the next item in the list. Fixing these issues are left as an exercise. -If you want to keep the shop fully NPC-run you could add a [Script](./Scripts) to restock the shop's store room regularly. This shop example could also easily be owned by a human Player (run for them by a hired NPC) - the shop owner would get the key to the store room and be responsible for keeping it well stocked. +If you want to keep the shop fully NPC-run you could add a [Script](./Scripts) to restock the shop's +store room regularly. This shop example could also easily be owned by a human Player (run for them +by a hired NPC) - the shop owner would get the key to the store room and be responsible for keeping +it well stocked. diff --git a/docs/source/New-Models.md b/docs/source/New-Models.md index 666e9eae61..e8bff71562 100644 --- a/docs/source/New-Models.md +++ b/docs/source/New-Models.md @@ -2,11 +2,18 @@ *Note: This is considered an advanced topic.* -Evennia offers many convenient ways to store object data, such as via Attributes or Scripts. This is sufficient for most use cases. But if you aim to build a large stand-alone system, trying to squeeze your storage requirements into those may be more complex than you bargain for. Examples may be to store guild data for guild members to be able to change, tracking the flow of money across a game-wide economic system or implement other custom game systems that requires the storage of custom data in a quickly accessible way. Whereas [Tags](./Tags) or [Scripts](./Scripts) can handle many situations, sometimes things may be easier to handle by adding your own database model. +Evennia offers many convenient ways to store object data, such as via Attributes or Scripts. This is +sufficient for most use cases. But if you aim to build a large stand-alone system, trying to squeeze +your storage requirements into those may be more complex than you bargain for. Examples may be to +store guild data for guild members to be able to change, tracking the flow of money across a game- +wide economic system or implement other custom game systems that requires the storage of custom data +in a quickly accessible way. Whereas [Tags](./Tags) or [Scripts](./Scripts) can handle many situations, +sometimes things may be easier to handle by adding your own database model. ## Overview of database tables -SQL-type databases (which is what Evennia supports) are basically highly optimized systems for retrieving text stored in tables. A table may look like this +SQL-type databases (which is what Evennia supports) are basically highly optimized systems for +retrieving text stored in tables. A table may look like this ``` id | db_key | db_typeclass_path | db_permissions ... @@ -15,7 +22,9 @@ SQL-type databases (which is what Evennia supports) are basically highly optimiz 2 | Rock | evennia.DefaultObject | None ... ``` -Each line is considerably longer in your database. Each column is referred to as a "field" and every row is a separate object. You can check this out for yourself. If you use the default sqlite3 database, go to your game folder and run +Each line is considerably longer in your database. Each column is referred to as a "field" and every +row is a separate object. You can check this out for yourself. If you use the default sqlite3 +database, go to your game folder and run evennia dbshell @@ -33,21 +42,34 @@ You will drop into the database shell. While there, try: sqlite> .exit -Evennia uses [Django](https://docs.djangoproject.com), which abstracts away the database SQL manipulation and allows you to search and manipulate your database entirely in Python. Each database table is in Django represented by a class commonly called a *model* since it describes the look of the table. In Evennia, Objects, Scripts, Channels etc are examples of Django models that we then extend and build on. +Evennia uses [Django](https://docs.djangoproject.com), which abstracts away the database SQL +manipulation and allows you to search and manipulate your database entirely in Python. Each database +table is in Django represented by a class commonly called a *model* since it describes the look of +the table. In Evennia, Objects, Scripts, Channels etc are examples of Django models that we then +extend and build on. ## Adding a new database table Here is how you add your own database table/models: -1. In Django lingo, we will create a new "application" - a subsystem under the main Evennia program. For this example we'll call it "myapp". Run the following (you need to have a working Evennia running before you do this, so make sure you have run the steps in [Getting Started](./Getting-Started) first): +1. In Django lingo, we will create a new "application" - a subsystem under the main Evennia program. +For this example we'll call it "myapp". Run the following (you need to have a working Evennia +running before you do this, so make sure you have run the steps in [Getting Started](Getting- +Started) first): cd mygame/world evennia startapp myapp -1. A new folder `myapp` is created. "myapp" will also be the name (the "app label") from now on. We chose to put it in the `world/` subfolder here, but you could put it in the root of your `mygame` if that makes more sense. +1. A new folder `myapp` is created. "myapp" will also be the name (the "app label") from now on. We +chose to put it in the `world/` subfolder here, but you could put it in the root of your `mygame` if +that makes more sense. 1. The `myapp` folder contains a few empty default files. What we are -interested in for now is `models.py`. In `models.py` you define your model(s). Each model will be a table in the database. See the next section and don't continue until you have added the models you want. -1. You now need to tell Evennia that the models of your app should be a part of your database scheme. Add this line to your `mygame/server/conf/settings.py`file (make sure to use the path where you put `myapp` and don't forget the comma at the end of the tuple): +interested in for now is `models.py`. In `models.py` you define your model(s). Each model will be a +table in the database. See the next section and don't continue until you have added the models you +want. +1. You now need to tell Evennia that the models of your app should be a part of your database +scheme. Add this line to your `mygame/server/conf/settings.py`file (make sure to use the path where +you put `myapp` and don't forget the comma at the end of the tuple): ``` INSTALLED_APPS = INSTALLED_APPS + ("world.myapp", ) @@ -58,13 +80,20 @@ interested in for now is `models.py`. In `models.py` you define your model(s). E evennia makemigrations myapp evennia migrate -This will add your new database table to the database. If you have put your game under version control (if not, [you should](./Version-Control)), don't forget to `git add myapp/*` to add all items to version control. +This will add your new database table to the database. If you have put your game under version +control (if not, [you should](./Version-Control)), don't forget to `git add myapp/*` to add all items +to version control. ## Defining your models -A Django *model* is the Python representation of a database table. It can be handled like any other Python class. It defines *fields* on itself, objects of a special type. These become the "columns" of the database table. Finally, you create new instances of the model to add new rows to the database. +A Django *model* is the Python representation of a database table. It can be handled like any other +Python class. It defines *fields* on itself, objects of a special type. These become the "columns" +of the database table. Finally, you create new instances of the model to add new rows to the +database. -We won't describe all aspects of Django models here, for that we refer to the vast [Django documentation](https://docs.djangoproject.com/en/2.2/topics/db/models/) on the subject. Here is a (very) brief example: +We won't describe all aspects of Django models here, for that we refer to the vast [Django +documentation](https://docs.djangoproject.com/en/2.2/topics/db/models/) on the subject. Here is a +(very) brief example: ```python from django.db import models @@ -80,15 +109,30 @@ class MyDataStore(models.Model): auto_now_add=True, db_index=True) ``` -We create four fields: two character fields of limited length and one text field which has no maximum length. Finally we create a field containing the current time of us creating this object. +We create four fields: two character fields of limited length and one text field which has no +maximum length. Finally we create a field containing the current time of us creating this object. -> The `db_date_created` field, with exactly this name, is *required* if you want to be able to store instances of your custom model in an Evennia [Attribute](./Attributes). It will automatically be set upon creation and can after that not be changed. Having this field will allow you to do e.g. `obj.db.myinstance = mydatastore`. If you know you'll never store your model instances in Attributes the `db_date_created` field is optional. +> The `db_date_created` field, with exactly this name, is *required* if you want to be able to store +instances of your custom model in an Evennia [Attribute](./Attributes). It will automatically be set +upon creation and can after that not be changed. Having this field will allow you to do e.g. +`obj.db.myinstance = mydatastore`. If you know you'll never store your model instances in Attributes +the `db_date_created` field is optional. -You don't *have* to start field names with `db_`, this is an Evennia convention. It's nevertheless recommended that you do use `db_`, partly for clarity and consistency with Evennia (if you ever want to share your code) and partly for the case of you later deciding to use Evennia's `SharedMemoryModel` parent down the line. +You don't *have* to start field names with `db_`, this is an Evennia convention. It's nevertheless +recommended that you do use `db_`, partly for clarity and consistency with Evennia (if you ever want +to share your code) and partly for the case of you later deciding to use Evennia's +`SharedMemoryModel` parent down the line. -The field keyword `db_index` creates a *database index* for this field, which allows quicker lookups, so it's recommended to put it on fields you know you'll often use in queries. The `null=True` and `blank=True` keywords means that these fields may be left empty or set to the empty string without the database complaining. There are many other field types and keywords to define them, see django docs for more info. +The field keyword `db_index` creates a *database index* for this field, which allows quicker +lookups, so it's recommended to put it on fields you know you'll often use in queries. The +`null=True` and `blank=True` keywords means that these fields may be left empty or set to the empty +string without the database complaining. There are many other field types and keywords to define +them, see django docs for more info. -Similar to using [django-admin](https://docs.djangoproject.com/en/2.2/howto/legacy-databases/) you are able to do `evennia inspectdb` to get an automated listing of model information for an existing database. As is the case with any model generating tool you should only use this as a starting point for your models. +Similar to using [django-admin](https://docs.djangoproject.com/en/2.2/howto/legacy-databases/) you +are able to do `evennia inspectdb` to get an automated listing of model information for an existing +database. As is the case with any model generating tool you should only use this as a starting +point for your models. ## Creating a new model instance @@ -105,33 +149,46 @@ To create a new row in your table, you instantiate the model and then call its ` ``` -Note that the `db_date_created` field of the model is not specified. Its flag `at_now_add=True` makes sure to set it to the current date when the object is created (it can also not be changed further after creation). +Note that the `db_date_created` field of the model is not specified. Its flag `at_now_add=True` +makes sure to set it to the current date when the object is created (it can also not be changed +further after creation). -When you update an existing object with some new field value, remember that you have to save the object afterwards, otherwise the database will not update: +When you update an existing object with some new field value, remember that you have to save the +object afterwards, otherwise the database will not update: ```python my_datastore.db_key = "Larger Sword" my_datastore.save() ``` -Evennia's normal models don't need to explicitly save, since they are based on `SharedMemoryModel` rather than the raw django model. This is covered in the next section. +Evennia's normal models don't need to explicitly save, since they are based on `SharedMemoryModel` +rather than the raw django model. This is covered in the next section. ## Using the `SharedMemoryModel` parent -Evennia doesn't base most of its models on the raw `django.db.models` but on the Evennia base model `evennia.utils.idmapper.models.SharedMemoryModel`. There are two main reasons for this: +Evennia doesn't base most of its models on the raw `django.db.models` but on the Evennia base model +`evennia.utils.idmapper.models.SharedMemoryModel`. There are two main reasons for this: 1. Ease of updating fields without having to explicitly call `save()` 2. On-object memory persistence and database caching -The first (and least important) point means that as long as you named your fields `db_*`, Evennia will automatically create field wrappers for them. This happens in the model's [Metaclass](http://en.wikibooks.org/wiki/Python_Programming/Metaclasses) so there is no speed penalty for this. The name of the wrapper will be the same name as the field, minus the `db_` prefix. So the `db_key` field will have a wrapper property named `key`. You can then do: +The first (and least important) point means that as long as you named your fields `db_*`, Evennia +will automatically create field wrappers for them. This happens in the model's +[Metaclass](http://en.wikibooks.org/wiki/Python_Programming/Metaclasses) so there is no speed +penalty for this. The name of the wrapper will be the same name as the field, minus the `db_` +prefix. So the `db_key` field will have a wrapper property named `key`. You can then do: ```python my_datastore.key = "Larger Sword" ``` -and don't have to explicitly call `save()` afterwards. The saving also happens in a more efficient way under the hood, updating only the field rather than the entire model using django optimizations. Note that if you were to manually add the property or method `key` to your model, this will be used instead of the automatic wrapper and allows you to fully customize access as needed. +and don't have to explicitly call `save()` afterwards. The saving also happens in a more efficient +way under the hood, updating only the field rather than the entire model using django optimizations. +Note that if you were to manually add the property or method `key` to your model, this will be used +instead of the automatic wrapper and allows you to fully customize access as needed. -To explain the second and more important point, consider the following example using the default Django model parent: +To explain the second and more important point, consider the following example using the default +Django model parent: ```python shield = MyDataStore.objects.get(db_key="SmallShield") @@ -145,13 +202,30 @@ And then later: print(shield.cracked) # error! ``` -The outcome of that last print statement is *undefined*! It could *maybe* randomly work but most likely you will get an `AttributeError` for not finding the `cracked` property. The reason is that `cracked` doesn't represent an actual field in the database. It was just added at run-time and thus Django don't care about it. When you retrieve your shield-match later there is *no* guarantee you will get back the *same Python instance* of the model where you defined `cracked`, even if you search for the same database object. +The outcome of that last print statement is *undefined*! It could *maybe* randomly work but most +likely you will get an `AttributeError` for not finding the `cracked` property. The reason is that +`cracked` doesn't represent an actual field in the database. It was just added at run-time and thus +Django don't care about it. When you retrieve your shield-match later there is *no* guarantee you +will get back the *same Python instance* of the model where you defined `cracked`, even if you +search for the same database object. -Evennia relies heavily on on-model handlers and other dynamically created properties. So rather than using the vanilla Django models, Evennia uses `SharedMemoryModel`, which levies something called *idmapper*. The idmapper caches model instances so that we will always get the *same* instance back after the first lookup of a given object. Using idmapper, the above example would work fine and you could retrieve your `cracked` property at any time - until you rebooted when all non-persistent data goes. +Evennia relies heavily on on-model handlers and other dynamically created properties. So rather than +using the vanilla Django models, Evennia uses `SharedMemoryModel`, which levies something called +*idmapper*. The idmapper caches model instances so that we will always get the *same* instance back +after the first lookup of a given object. Using idmapper, the above example would work fine and you +could retrieve your `cracked` property at any time - until you rebooted when all non-persistent data +goes. -Using the idmapper is both more intuitive and more efficient *per object*; it leads to a lot less reading from disk. The drawback is that this system tends to be more memory hungry *overall*. So if you know that you'll *never* need to add new properties to running instances or know that you will create new objects all the time yet rarely access them again (like for a log system), you are probably better off making "plain" Django models rather than using `SharedMemoryModel` and its idmapper. +Using the idmapper is both more intuitive and more efficient *per object*; it leads to a lot less +reading from disk. The drawback is that this system tends to be more memory hungry *overall*. So if +you know that you'll *never* need to add new properties to running instances or know that you will +create new objects all the time yet rarely access them again (like for a log system), you are +probably better off making "plain" Django models rather than using `SharedMemoryModel` and its +idmapper. -To use the idmapper and the field-wrapper functionality you just have to have your model classes inherit from `evennia.utils.idmapper.models.SharedMemoryModel` instead of from the default `django.db.models.Model`: +To use the idmapper and the field-wrapper functionality you just have to have your model classes +inherit from `evennia.utils.idmapper.models.SharedMemoryModel` instead of from the default +`django.db.models.Model`: ```python from evennia.utils.idmapper.models import SharedMemoryModel @@ -168,7 +242,9 @@ class MyDataStore(SharedMemoryModel): ## Searching for your models -To search your new custom database table you need to use its database *manager* to build a *query*. Note that even if you use `SharedMemoryModel` as described in the previous section, you have to use the actual *field names* in the query, not the wrapper name (so `db_key` and not just `key`). +To search your new custom database table you need to use its database *manager* to build a *query*. +Note that even if you use `SharedMemoryModel` as described in the previous section, you have to use +the actual *field names* in the query, not the wrapper name (so `db_key` and not just `key`). ```python from world.myapp import MyDataStore @@ -184,4 +260,5 @@ To search your new custom database table you need to use its database *manager* self.caller.msg(match.db_text) ``` -See the [Django query documentation](https://docs.djangoproject.com/en/2.2/topics/db/queries/) for a lot more information about querying the database. +See the [Django query documentation](https://docs.djangoproject.com/en/2.2/topics/db/queries/) for a +lot more information about querying the database. diff --git a/docs/source/Nicks.md b/docs/source/Nicks.md index dae4c13a02..6b3c9b483b 100644 --- a/docs/source/Nicks.md +++ b/docs/source/Nicks.md @@ -1,13 +1,20 @@ # Nicks -*Nicks*, short for *Nicknames* is a system allowing an object (usually a [Account](./Accounts)) to assign custom replacement names for other game entities. +*Nicks*, short for *Nicknames* is a system allowing an object (usually a [Account](./Accounts)) to +assign custom replacement names for other game entities. -Nicks are not to be confused with *Aliases*. Setting an Alias on a game entity actually changes an inherent attribute on that entity, and everyone in the game will be able to use that alias to address the entity thereafter. A *Nick* on the other hand, is used to map a different way *you alone* can refer to that entity. Nicks are also commonly used to replace your input text which means you can create your own aliases to default commands. +Nicks are not to be confused with *Aliases*. Setting an Alias on a game entity actually changes an +inherent attribute on that entity, and everyone in the game will be able to use that alias to +address the entity thereafter. A *Nick* on the other hand, is used to map a different way *you +alone* can refer to that entity. Nicks are also commonly used to replace your input text which means +you can create your own aliases to default commands. -Default Evennia use Nicks in three flavours that determine when Evennia actually tries to do the substitution. +Default Evennia use Nicks in three flavours that determine when Evennia actually tries to do the +substitution. -- inputline - replacement is attempted whenever you write anything on the command line. This is the default. +- inputline - replacement is attempted whenever you write anything on the command line. This is the +default. - objects - replacement is only attempted when referring to an object - accounts - replacement is only attempted when referring an account @@ -15,13 +22,15 @@ Here's how to use it in the default command set (using the `nick` command): nick ls = look -This is a good one for unix/linux users who are accustomed to using the `ls` command in their daily life. It is equivalent to `nick/inputline ls = look`. +This is a good one for unix/linux users who are accustomed to using the `ls` command in their daily +life. It is equivalent to `nick/inputline ls = look`. - nick/object mycar2 = The red sports car + nick/object mycar2 = The red sports car -With this example, substitutions will only be done specifically for commands expecting an object reference, such as +With this example, substitutions will only be done specifically for commands expecting an object +reference, such as - look mycar2 + look mycar2 becomes equivalent to "`look The red sports car`". @@ -29,13 +38,14 @@ becomes equivalent to "`look The red sports car`". This is useful for commands searching for accounts explicitly: - @find *tom + @find *tom -One can use nicks to speed up input. Below we add ourselves a quicker way to build red buttons. In the future just writing *rb* will be enough to execute that whole long string. +One can use nicks to speed up input. Below we add ourselves a quicker way to build red buttons. In +the future just writing *rb* will be enough to execute that whole long string. nick rb = @create button:examples.red_button.RedButton -Nicks could also be used as the start for building a "recog" system suitable for an RP mud. +Nicks could also be used as the start for building a "recog" system suitable for an RP mud. nick/account Arnold = The mysterious hooded man @@ -43,9 +53,13 @@ The nick replacer also supports unix-style *templating*: nick build $1 $2 = @create/drop $1;$2 -This will catch space separated arguments and store them in the the tags `$1` and `$2`, to be inserted in the replacement string. This example allows you to do `build box crate` and have Evennia see `@create/drop box;crate`. You may use any `$` numbers between 1 and 99, but the markers must match between the nick pattern and the replacement. +This will catch space separated arguments and store them in the the tags `$1` and `$2`, to be +inserted in the replacement string. This example allows you to do `build box crate` and have Evennia +see `@create/drop box;crate`. You may use any `$` numbers between 1 and 99, but the markers must +match between the nick pattern and the replacement. -> If you want to catch "the rest" of a command argument, make sure to put a `$` tag *with no spaces to the right of it* - it will then receive everything up until the end of the line. +> If you want to catch "the rest" of a command argument, make sure to put a `$` tag *with no spaces +to the right of it* - it will then receive everything up until the end of the line. You can also use [shell-type wildcards](http://www.linfo.org/wildcard.html): @@ -60,13 +74,15 @@ You can also use [shell-type wildcards](http://www.linfo.org/wildcard.html): ## Coding with nicks -Nicks are stored as the `Nick` database model and are referred from the normal Evennia [object](./Objects) through the `nicks` property - this is known as the *NickHandler*. The NickHandler offers effective error checking, searches and conversion. +Nicks are stored as the `Nick` database model and are referred from the normal Evennia +[object](./Objects) through the `nicks` property - this is known as the *NickHandler*. The NickHandler +offers effective error checking, searches and conversion. ```python # A command/channel nick: obj.nicks.add("greetjack", "tell Jack = Hello pal!") - # An object nick: + # An object nick: obj.nicks.add("rose", "The red flower", nick_type="object") # An account nick: @@ -82,17 +98,24 @@ Nicks are stored as the `Nick` database model and are referred from the normal E object.nicks.remove("rose", nick_type="object") ``` -In a command definition you can reach the nick handler through `self.caller.nicks`. See the `nick` command in `evennia/commands/default/general.py` for more examples. +In a command definition you can reach the nick handler through `self.caller.nicks`. See the `nick` +command in `evennia/commands/default/general.py` for more examples. -As a last note, The Evennia [channel](./Communications) alias systems are using nicks with the `nick_type="channel"` in order to allow users to create their own custom aliases to channels. +As a last note, The Evennia [channel](./Communications) alias systems are using nicks with the +`nick_type="channel"` in order to allow users to create their own custom aliases to channels. # Advanced note -Internally, nicks are [Attributes](./Attributes) saved with the `db_attrype` set to "nick" (normal Attributes has this set to `None`). +Internally, nicks are [Attributes](./Attributes) saved with the `db_attrype` set to "nick" (normal +Attributes has this set to `None`). -The nick stores the replacement data in the Attribute.db_value field as a tuple with four fields `(regex_nick, template_string, raw_nick, raw_template)`. Here `regex_nick` is the converted regex representation of the `raw_nick` and the `template-string` is a version of the `raw_template` prepared for efficient replacement of any `$`- type markers. The `raw_nick` and `raw_template` are basically the unchanged strings you enter to the `nick` command (with unparsed `$` etc). +The nick stores the replacement data in the Attribute.db_value field as a tuple with four fields +`(regex_nick, template_string, raw_nick, raw_template)`. Here `regex_nick` is the converted regex +representation of the `raw_nick` and the `template-string` is a version of the `raw_template` +prepared for efficient replacement of any `$`- type markers. The `raw_nick` and `raw_template` are +basically the unchanged strings you enter to the `nick` command (with unparsed `$` etc). -If you need to access the tuple for some reason, here's how: +If you need to access the tuple for some reason, here's how: ```python tuple = obj.nicks.get("nickname", return_tuple=True) diff --git a/docs/source/OOB.md b/docs/source/OOB.md index ea8f09ca3d..29b51e2686 100644 --- a/docs/source/OOB.md +++ b/docs/source/OOB.md @@ -1,66 +1,108 @@ # OOB -OOB, or Out-Of-Band, means sending data between Evennia and the user's client without the user prompting it or necessarily being aware that it's being passed. Common uses would be to update client health-bars, handle client button-presses or to display certain tagged text in a different window pane. +OOB, or Out-Of-Band, means sending data between Evennia and the user's client without the user +prompting it or necessarily being aware that it's being passed. Common uses would be to update +client health-bars, handle client button-presses or to display certain tagged text in a different +window pane. ## Briefly on input/outputcommands -Inside Evennia, all server-client communication happens in the same way (so plain text is also an 'OOB message' as far as Evennia is concerned). The message follows the [Message Path](./Messagepath). You should read up on that if you are unfamiliar with it. As the message travels along the path it has a standardized internal form: a tuple with a string, a tuple and a dict: +Inside Evennia, all server-client communication happens in the same way (so plain text is also an +'OOB message' as far as Evennia is concerned). The message follows the [Message Path](./Messagepath). +You should read up on that if you are unfamiliar with it. As the message travels along the path it +has a standardized internal form: a tuple with a string, a tuple and a dict: ("cmdname", (args), {kwargs}) -This is often referred to as an *inputcommand* or *outputcommand*, depending on the direction it's traveling. The end point for an inputcommand, (the 'Evennia-end' of the message path) is a matching [Inputfunc](./Inputfuncs). This function is called as `cmdname(session, *args, **kwargs)` where `session` is the Session-source of the command. Inputfuncs can easily be added by the developer to support/map client commands to actions inside Evennia (see the [inputfunc](./Inputfuncs) page for more details). +This is often referred to as an *inputcommand* or *outputcommand*, depending on the direction it's +traveling. The end point for an inputcommand, (the 'Evennia-end' of the message path) is a matching +[Inputfunc](./Inputfuncs). This function is called as `cmdname(session, *args, **kwargs)` where +`session` is the Session-source of the command. Inputfuncs can easily be added by the developer to +support/map client commands to actions inside Evennia (see the [inputfunc](./Inputfuncs) page for more +details). -When a message is outgoing (at the 'Client-end' of the message path) the outputcommand is handled by a matching *Outputfunc*. This is responsible for converting the internal Evennia representation to a form suitable to send over the wire to the Client. Outputfuncs are hard-coded. Which is chosen and how it processes the outgoing data depends on the nature of the client it's connected to. The only time one would want to add new outputfuncs is as part of developing support for a new Evennia [Protocol](./Custom-Protocols). +When a message is outgoing (at the 'Client-end' of the message path) the outputcommand is handled by +a matching *Outputfunc*. This is responsible for converting the internal Evennia representation to a +form suitable to send over the wire to the Client. Outputfuncs are hard-coded. Which is chosen and +how it processes the outgoing data depends on the nature of the client it's connected to. The only +time one would want to add new outputfuncs is as part of developing support for a new Evennia +[Protocol](./Custom-Protocols). ## Sending and receiving an OOB message -Sending is simple. You just use the normal `msg` method of the object whose session you want to send to. For example in a Command: +Sending is simple. You just use the normal `msg` method of the object whose session you want to send +to. For example in a Command: ```python caller.msg(cmdname=((args, ...), {key:value, ...})) ``` -A special case is the `text` input/outputfunc. It's so common that it's the default of the `msg` method. So these are equivalent: +A special case is the `text` input/outputfunc. It's so common that it's the default of the `msg` +method. So these are equivalent: ```python caller.msg("Hello") caller.msg(text="Hello") ``` -You don't have to specify the full output/input definition. So for example, if your particular command only needs kwargs, you can skip the `(args)` part. Like in the `text` case you can skip writing the tuple if there is only one arg ... and so on - the input is pretty flexible. If there are no args at all you need to give the empty tuple `msg(cmdname=(,)` (giving `None` would mean a single argument `None`). +You don't have to specify the full output/input definition. So for example, if your particular +command only needs kwargs, you can skip the `(args)` part. Like in the `text` case you can skip +writing the tuple if there is only one arg ... and so on - the input is pretty flexible. If there +are no args at all you need to give the empty tuple `msg(cmdname=(,)` (giving `None` would mean a +single argument `None`). -Which commands you can send depends on the client. If the client does not support an explicit OOB protocol (like many old/legacy MUD clients) Evennia can only send `text` to them and will quietly drop any other types of outputfuncs. +Which commands you can send depends on the client. If the client does not support an explicit OOB +protocol (like many old/legacy MUD clients) Evennia can only send `text` to them and will quietly +drop any other types of outputfuncs. -> Remember that a given message may go to multiple clients with different capabilities. So unless you turn off telnet completely and only rely on the webclient, you should never rely on non-`text` OOB messages always reaching all targets. +> Remember that a given message may go to multiple clients with different capabilities. So unless +you turn off telnet completely and only rely on the webclient, you should never rely on non-`text` +OOB messages always reaching all targets. -[Inputfuncs](./Inputfuncs) lists the default inputfuncs available to handle incoming OOB messages. To accept more you need to add more inputfuncs (see that page for more info). +[Inputfuncs](./Inputfuncs) lists the default inputfuncs available to handle incoming OOB messages. To +accept more you need to add more inputfuncs (see that page for more info). ## Supported OOB protocols -Evennia supports clients using one of the following protocols: +Evennia supports clients using one of the following protocols: ### Telnet -By default telnet (and telnet+SSL) supports only the plain `text` outputcommand. Evennia however detects if the Client supports one of two MUD-specific OOB *extensions* to the standard telnet protocol - GMCP or MSDP. Evennia supports both simultaneously and will switch to the protocol the client uses. If the client supports both, GMCP will be used. +By default telnet (and telnet+SSL) supports only the plain `text` outputcommand. Evennia however +detects if the Client supports one of two MUD-specific OOB *extensions* to the standard telnet +protocol - GMCP or MSDP. Evennia supports both simultaneously and will switch to the protocol the +client uses. If the client supports both, GMCP will be used. -> Note that for Telnet, `text` has a special status as the "in-band" operation. So the `text` outputcommand sends the `text` argument directly over the wire, without going through the OOB translations described below. +> Note that for Telnet, `text` has a special status as the "in-band" operation. So the `text` +outputcommand sends the `text` argument directly over the wire, without going through the OOB +translations described below. #### Telnet + GMCP -[GMCP](http://www.gammon.com.au/gmcp), the *Generic Mud Communication Protocol* sends data on the form `cmdname + JSONdata`. Here the cmdname is expected to be on the form "Package.Subpackage". There could also be additional Sub-sub packages etc. The names of these 'packages' and 'subpackages' are not that well standardized beyond what individual MUDs or companies have chosen to go with over the years. You can decide on your own package names, but here are what others are using: +[GMCP](http://www.gammon.com.au/gmcp), the *Generic Mud Communication Protocol* sends data on the +form `cmdname + JSONdata`. Here the cmdname is expected to be on the form "Package.Subpackage". +There could also be additional Sub-sub packages etc. The names of these 'packages' and 'subpackages' +are not that well standardized beyond what individual MUDs or companies have chosen to go with over +the years. You can decide on your own package names, but here are what others are using: - [Aardwolf GMCP](http://www.aardwolf.com/wiki/index.php/Clients/GMCP) - [Discworld GMCP](http://discworld.starturtle.net/lpc/playing/documentation.c?path=/concepts/gmcp) - [Avatar GMCP](http://www.outland.org/infusions/wiclear/index.php?title=MUD%20Protocols&lang=en) - [IRE games GMCP](http://nexus.ironrealms.com/GMCP) -Evennia will translate underscores to `.` and capitalize to fit the specification. So the outputcommand `foo_bar` will become a GMCP command-name `Foo.Bar`. A GMCP command "Foo.Bar" will be come `foo_bar`. To send a GMCP command that turns into an Evennia inputcommand without an underscore, use the `Core` package. So `Core.Cmdname` becomes just `cmdname` in Evennia and vice versa. +Evennia will translate underscores to `.` and capitalize to fit the specification. So the +outputcommand `foo_bar` will become a GMCP command-name `Foo.Bar`. A GMCP command "Foo.Bar" will be +come `foo_bar`. To send a GMCP command that turns into an Evennia inputcommand without an +underscore, use the `Core` package. So `Core.Cmdname` becomes just `cmdname` in Evennia and vice +versa. -On the wire, a GMCP instruction for `("cmdname", ("arg",), {})` will look like this: +On the wire, a GMCP instruction for `("cmdname", ("arg",), {})` will look like this: IAC SB GMCP "cmdname" "arg" IAC SE -where all the capitalized words are telnet character constants specified in `evennia/server/portal/telnet_oob.py`. These are parsed/added by the protocol and we don't include these in the listings below. +where all the capitalized words are telnet character constants specified in +`evennia/server/portal/telnet_oob.py`. These are parsed/added by the protocol and we don't include +these in the listings below. Input/Outputfunc | GMCP-Command ------------------ @@ -70,26 +112,35 @@ Input/Outputfunc | GMCP-Command `[cmd_name, [], {kwargs}]` | Cmd.Name {kwargs} `[cmdname, [args, {kwargs}]` | Core.Cmdname [[args],{kwargs}] -Since Evennia already supplies default inputfuncs that don't match the names expected by the most common GMCP implementations we have a few hard-coded mappings for those: +Since Evennia already supplies default inputfuncs that don't match the names expected by the most +common GMCP implementations we have a few hard-coded mappings for those: GMCP command name | Input/Outputfunc name ----------------- -"Core.Hello" | "client_options" -"Core.Supports.Get" | "client_options" -"Core.Commands.Get" | "get_inputfuncs" +"Core.Hello" | "client_options" +"Core.Supports.Get" | "client_options" +"Core.Commands.Get" | "get_inputfuncs" "Char.Value.Get" | "get_value" "Char.Repeat.Update" | "repeat" "Char.Monitor.Update" | "monitor" -#### Telnet + MSDP +#### Telnet + MSDP -[MSDP](http://tintin.sourceforge.net/msdp/), the *Mud Server Data Protocol*, is a competing standard to GMCP. The MSDP protocol page specifies a range of "recommended" available MSDP command names. Evennia does *not* support those - since MSDP doesn't specify a special format for its command names (like GMCP does) the client can and should just call the internal Evennia inputfunc by its actual name. +[MSDP](http://tintin.sourceforge.net/msdp/), the *Mud Server Data Protocol*, is a competing standard +to GMCP. The MSDP protocol page specifies a range of "recommended" available MSDP command names. +Evennia does *not* support those - since MSDP doesn't specify a special format for its command names +(like GMCP does) the client can and should just call the internal Evennia inputfunc by its actual +name. -MSDP uses Telnet character constants to package various structured data over the wire. MSDP supports strings, arrays (lists) and tables (dicts). These are used to define the cmdname, args and kwargs needed. When sending MSDP for `("cmdname", ("arg",), {})` the resulting MSDP instruction will look like this: +MSDP uses Telnet character constants to package various structured data over the wire. MSDP supports +strings, arrays (lists) and tables (dicts). These are used to define the cmdname, args and kwargs +needed. When sending MSDP for `("cmdname", ("arg",), {})` the resulting MSDP instruction will look +like this: IAC SB MSDP VAR cmdname VAL arg IAC SE -The various available MSDP constants like `VAR` (variable), `VAL` (value), `ARRAYOPEN`/`ARRAYCLOSE` and `TABLEOPEN`/`TABLECLOSE` are specified in `evennia/server/portal/telnet_oob`. +The various available MSDP constants like `VAR` (variable), `VAL` (value), `ARRAYOPEN`/`ARRAYCLOSE` +and `TABLEOPEN`/`TABLECLOSE` are specified in `evennia/server/portal/telnet_oob`. Outputfunc/Inputfunc | MSDP instruction ------------------------- @@ -97,17 +148,22 @@ Outputfunc/Inputfunc | MSDP instruction `[cmdname, [arg], {}]` | VAR cmdname VAL arg `[cmdname, [args],{}]` | VAR cmdname VAL ARRAYOPEN VAL arg VAL arg ... ARRAYCLOSE `[cmdname, [], {kwargs}]` | VAR cmdname VAL TABLEOPEN VAR key VAL val ... TABLECLOSE -`[cmdname, [args], {kwargs}]` | VAR cmdname VAL ARRAYOPEN VAL arg VAL arg ... ARRAYCLOSE VAR cmdname VAL TABLEOPEN VAR key VAL val ... TABLECLOSE +`[cmdname, [args], {kwargs}]` | VAR cmdname VAL ARRAYOPEN VAL arg VAL arg ... ARRAYCLOSE VAR cmdname +VAL TABLEOPEN VAR key VAL val ... TABLECLOSE -Observe that `VAR ... VAL` always identifies cmdnames, so if there are multiple arrays/dicts tagged with the same cmdname they will be appended to the args, kwargs of that inputfunc. Vice-versa, a different `VAR ... VAL` (outside a table) will come out as a second, different command input. +Observe that `VAR ... VAL` always identifies cmdnames, so if there are multiple arrays/dicts tagged +with the same cmdname they will be appended to the args, kwargs of that inputfunc. Vice-versa, a +different `VAR ... VAL` (outside a table) will come out as a second, different command input. ### SSH -SSH only supports the `text` input/outputcommand. +SSH only supports the `text` input/outputcommand. ### Web client -Our web client uses pure JSON structures for all its communication, including `text`. This maps directly to the Evennia internal output/inputcommand, including eventual empty args/kwargs. So the same example `("cmdname", ("arg",), {})` will be sent/received as a valid JSON structure +Our web client uses pure JSON structures for all its communication, including `text`. This maps +directly to the Evennia internal output/inputcommand, including eventual empty args/kwargs. So the +same example `("cmdname", ("arg",), {})` will be sent/received as a valid JSON structure ["cmdname, ["arg"], {}] diff --git a/docs/source/Objects.md b/docs/source/Objects.md index e7d24a3f44..e2f21477e9 100644 --- a/docs/source/Objects.md +++ b/docs/source/Objects.md @@ -1,11 +1,17 @@ # Objects -All in-game objects in Evennia, be it characters, chairs, monsters, rooms or hand grenades are represented by an Evennia *Object*. Objects form the core of Evennia and is probably what you'll spend most time working with. Objects are [Typeclassed](./Typeclasses) entities. +All in-game objects in Evennia, be it characters, chairs, monsters, rooms or hand grenades are +represented by an Evennia *Object*. Objects form the core of Evennia and is probably what you'll +spend most time working with. Objects are [Typeclassed](./Typeclasses) entities. ## How to create your own object types -An Evennia Object is, per definition, a Python class that includes `evennia.DefaultObject` among its parents. In `mygame/typeclasses/objects.py` there is already a class `Object` that inherits from `DefaultObject` and that you can inherit from. You can put your new typeclass directly in that module or you could organize your code in some other way. Here we assume we make a new module `mygame/typeclasses/flowers.py`: +An Evennia Object is, per definition, a Python class that includes `evennia.DefaultObject` among its +parents. In `mygame/typeclasses/objects.py` there is already a class `Object` that inherits from +`DefaultObject` and that you can inherit from. You can put your new typeclass directly in that +module or you could organize your code in some other way. Here we assume we make a new module +`mygame/typeclasses/flowers.py`: ```python # mygame/typeclasses/flowers.py @@ -14,67 +20,109 @@ An Evennia Object is, per definition, a Python class that includes `evennia.Defa class Rose(Object): """ - This creates a simple rose object - """ + This creates a simple rose object + """ def at_object_creation(self): "this is called only once, when object is first created" - # add a persistent attribute 'desc' + # add a persistent attribute 'desc' # to object (silly example). - self.db.desc = "This is a pretty rose with thorns." + self.db.desc = "This is a pretty rose with thorns." ``` -You could save this in the `mygame/typeclasses/objects.py` (then you'd not need to import `Object`) or you can put it in a new module. Let's say we do the latter, making a module `typeclasses/flowers.py`. Now you just need to point to the class *Rose* with the `@create` command to make a new rose: +You could save this in the `mygame/typeclasses/objects.py` (then you'd not need to import `Object`) +or you can put it in a new module. Let's say we do the latter, making a module +`typeclasses/flowers.py`. Now you just need to point to the class *Rose* with the `@create` command +to make a new rose: @create/drop MyRose:flowers.Rose -What the `@create` command actually *does* is to use `evennia.create_object`. You can do the same thing yourself in code: +What the `@create` command actually *does* is to use `evennia.create_object`. You can do the same +thing yourself in code: ```python from evennia import create_object new_rose = create_object("typeclasses.flowers.Rose", key="MyRose") ``` -(The `@create` command will auto-append the most likely path to your typeclass, if you enter the call manually you have to give the full path to the class. The `create.create_object` function is powerful and should be used for all coded object creating (so this is what you use when defining your own building commands). Check out the `ev.create_*` functions for how to build other entities like [Scripts](./Scripts)). +(The `@create` command will auto-append the most likely path to your typeclass, if you enter the +call manually you have to give the full path to the class. The `create.create_object` function is +powerful and should be used for all coded object creating (so this is what you use when defining +your own building commands). Check out the `ev.create_*` functions for how to build other entities +like [Scripts](./Scripts)). -This particular Rose class doesn't really do much, all it does it make sure the attribute `desc`(which is what the `look` command looks for) is pre-set, which is pretty pointless since you will usually want to change this at build time (using the `@desc` command or using the [Spawner](./Spawner-and-Prototypes)). The `Object` typeclass offers many more hooks that is available to use though - see next section. +This particular Rose class doesn't really do much, all it does it make sure the attribute +`desc`(which is what the `look` command looks for) is pre-set, which is pretty pointless since you +will usually want to change this at build time (using the `@desc` command or using the +[Spawner](./Spawner-and-Prototypes)). The `Object` typeclass offers many more hooks that is available +to use though - see next section. ## Properties and functions on Objects -Beyond the properties assigned to all [typeclassed](./Typeclasses) objects (see that page for a list of those), the Object also has the following custom properties: +Beyond the properties assigned to all [typeclassed](./Typeclasses) objects (see that page for a list +of those), the Object also has the following custom properties: -- `aliases` - a handler that allows you to add and remove aliases from this object. Use `aliases.add()` to add a new alias and `aliases.remove()` to remove one. +- `aliases` - a handler that allows you to add and remove aliases from this object. Use +`aliases.add()` to add a new alias and `aliases.remove()` to remove one. - `location` - a reference to the object currently containing this object. -- `home` is a backup location. The main motivation is to have a safe place to move the object to if its `location` is destroyed. All objects should usually have a home location for safety. -- `destination` - this holds a reference to another object this object links to in some way. Its main use is for [Exits](./Objects#Exits), it's otherwise usually unset. -- `nicks` - as opposed to aliases, a [Nick](./Nicks) holds a convenient nickname replacement for a real name, word or sequence, only valid for this object. This mainly makes sense if the Object is used as a game character - it can then store briefer shorts, example so as to quickly reference game commands or other characters. Use nicks.add(alias, realname) to add a new one. -- `account` - this holds a reference to a connected [Account](./Accounts) controlling this object (if any). Note that this is set also if the controlling account is *not* currently online - to test if an account is online, use the `has_account` property instead. -- `sessions` - if `account` field is set *and the account is online*, this is a list of all active sessions (server connections) to contact them through (it may be more than one if multiple connections are allowed in settings). -- `has_account` - a shorthand for checking if an *online* account is currently connected to this object. -- `contents` - this returns a list referencing all objects 'inside' this object (i,e. which has this object set as their `location`). -- `exits` - this returns all objects inside this object that are *Exits*, that is, has the `destination` property set. +- `home` is a backup location. The main motivation is to have a safe place to move the object to if +its `location` is destroyed. All objects should usually have a home location for safety. +- `destination` - this holds a reference to another object this object links to in some way. Its +main use is for [Exits](./Objects#Exits), it's otherwise usually unset. +- `nicks` - as opposed to aliases, a [Nick](./Nicks) holds a convenient nickname replacement for a +real name, word or sequence, only valid for this object. This mainly makes sense if the Object is +used as a game character - it can then store briefer shorts, example so as to quickly reference game +commands or other characters. Use nicks.add(alias, realname) to add a new one. +- `account` - this holds a reference to a connected [Account](./Accounts) controlling this object (if +any). Note that this is set also if the controlling account is *not* currently online - to test if +an account is online, use the `has_account` property instead. +- `sessions` - if `account` field is set *and the account is online*, this is a list of all active +sessions (server connections) to contact them through (it may be more than one if multiple +connections are allowed in settings). +- `has_account` - a shorthand for checking if an *online* account is currently connected to this +object. +- `contents` - this returns a list referencing all objects 'inside' this object (i,e. which has this +object set as their `location`). +- `exits` - this returns all objects inside this object that are *Exits*, that is, has the +`destination` property set. The last two properties are special: -- `cmdset` - this is a handler that stores all [command sets](./Commands#Command_Sets) defined on the object (if any). +- `cmdset` - this is a handler that stores all [command sets](./Commands#Command_Sets) defined on the +object (if any). - `scripts` - this is a handler that manages [Scripts](./Scripts) attached to the object (if any). -The Object also has a host of useful utility functions. See the function headers in `src/objects/objects.py` for their arguments and more details. +The Object also has a host of useful utility functions. See the function headers in +`src/objects/objects.py` for their arguments and more details. -- `msg()` - this function is used to send messages from the server to an account connected to this object. +- `msg()` - this function is used to send messages from the server to an account connected to this +object. - `msg_contents()` - calls `msg` on all objects inside this object. -- `search()` - this is a convenient shorthand to search for a specific object, at a given location or globally. It's mainly useful when defining commands (in which case the object executing the command is named `caller` and one can do `caller.search()` to find objects in the room to operate on). +- `search()` - this is a convenient shorthand to search for a specific object, at a given location +or globally. It's mainly useful when defining commands (in which case the object executing the +command is named `caller` and one can do `caller.search()` to find objects in the room to operate +on). - `execute_cmd()` - Lets the object execute the given string as if it was given on the command line. -- `move_to` - perform a full move of this object to a new location. This is the main move method and will call all relevant hooks, do all checks etc. +- `move_to` - perform a full move of this object to a new location. This is the main move method +and will call all relevant hooks, do all checks etc. - `clear_exits()` - will delete all [Exits](./Objects#Exits) to *and* from this object. -- `clear_contents()` - this will not delete anything, but rather move all contents (except Exits) to their designated `Home` locations. +- `clear_contents()` - this will not delete anything, but rather move all contents (except Exits) to +their designated `Home` locations. - `delete()` - deletes this object, first calling `clear_exits()` and `clear_contents()`. -The Object Typeclass defines many more *hook methods* beyond `at_object_creation`. Evennia calls these hooks at various points. When implementing your custom objects, you will inherit from the base parent and overload these hooks with your own custom code. See `evennia.objects.objects` for an updated list of all the available hooks or the [API for DefaultObject here](api:evennia.objects.objects#defaultobject). +The Object Typeclass defines many more *hook methods* beyond `at_object_creation`. Evennia calls +these hooks at various points. When implementing your custom objects, you will inherit from the +base parent and overload these hooks with your own custom code. See `evennia.objects.objects` for an +updated list of all the available hooks or the [API for DefaultObject +here](api:evennia.objects.objects#defaultobject). ## Subclasses of `Object` -There are three special subclasses of *Object* in default Evennia - *Characters*, *Rooms* and *Exits*. The reason they are separated is because these particular object types are fundamental, something you will always need and in some cases requires some extra attention in order to be recognized by the game engine (there is nothing stopping you from redefining them though). In practice they are all pretty similar to the base Object. +There are three special subclasses of *Object* in default Evennia - *Characters*, *Rooms* and +*Exits*. The reason they are separated is because these particular object types are fundamental, +something you will always need and in some cases requires some extra attention in order to be +recognized by the game engine (there is nothing stopping you from redefining them though). In +practice they are all pretty similar to the base Object. ### Characters @@ -90,20 +138,39 @@ to modify. ### Rooms -*Rooms* are the root containers of all other objects. The only thing really separating a room from any other object is that they have no `location` of their own and that default commands like `@dig` creates objects of this class - so if you want to expand your rooms with more functionality, just inherit from `ev.DefaultRoom`. In `mygame/typeclasses/rooms.py` is an empty `Room` class ready for you to modify. +*Rooms* are the root containers of all other objects. The only thing really separating a room from +any other object is that they have no `location` of their own and that default commands like `@dig` +creates objects of this class - so if you want to expand your rooms with more functionality, just +inherit from `ev.DefaultRoom`. In `mygame/typeclasses/rooms.py` is an empty `Room` class ready for +you to modify. ### Exits -*Exits* are objects connecting other objects (usually *Rooms*) together. An object named *North* or *in* might be an exit, as well as *door*, *portal* or *jump out the window*. An exit has two things that separate them from other objects. Firstly, their *destination* property is set and points to a valid object. This fact makes it easy and fast to locate exits in the database. Secondly, exits define a special [Transit Command](./Commands) on themselves when they are created. This command is named the same as the exit object and will, when called, handle the practicalities of moving the character to the Exits's *destination* - this allows you to just enter the name of the exit on its own to move around, just as you would expect. +*Exits* are objects connecting other objects (usually *Rooms*) together. An object named *North* or +*in* might be an exit, as well as *door*, *portal* or *jump out the window*. An exit has two things +that separate them from other objects. Firstly, their *destination* property is set and points to a +valid object. This fact makes it easy and fast to locate exits in the database. Secondly, exits +define a special [Transit Command](./Commands) on themselves when they are created. This command is +named the same as the exit object and will, when called, handle the practicalities of moving the +character to the Exits's *destination* - this allows you to just enter the name of the exit on its +own to move around, just as you would expect. -The exit functionality is all defined on the Exit typeclass, so you could in principle completely change how exits work in your game (it's not recommended though, unless you really know what you are doing). Exits are [locked](./Locks) using an access_type called *traverse* and also make use of a few hook methods for giving feedback if the traversal fails. See `evennia.DefaultExit` for more info. In `mygame/typeclasses/exits.py` there is an empty `Exit` class for you to modify. +The exit functionality is all defined on the Exit typeclass, so you could in principle completely +change how exits work in your game (it's not recommended though, unless you really know what you are +doing). Exits are [locked](./Locks) using an access_type called *traverse* and also make use of a few +hook methods for giving feedback if the traversal fails. See `evennia.DefaultExit` for more info. +In `mygame/typeclasses/exits.py` there is an empty `Exit` class for you to modify. The process of traversing an exit is as follows: -1. The traversing `obj` sends a command that matches the Exit-command name on the Exit object. The [cmdhandler](./Commands) detects this and triggers the command defined on the Exit. Traversal always involves the "source" (the current location) and the `destination` (this is stored on the Exit object). +1. The traversing `obj` sends a command that matches the Exit-command name on the Exit object. The +[cmdhandler](./Commands) detects this and triggers the command defined on the Exit. Traversal always +involves the "source" (the current location) and the `destination` (this is stored on the Exit +object). 1. The Exit command checks the `traverse` lock on the Exit object 1. The Exit command triggers `at_traverse(obj, destination)` on the Exit object. -1. In `at_traverse`, `object.move_to(destination)` is triggered. This triggers the following hooks, in order: +1. In `at_traverse`, `object.move_to(destination)` is triggered. This triggers the following hooks, +in order: 1. `obj.at_before_move(destination)` - if this returns False, move is aborted. 1. `origin.at_before_leave(obj, destination)` 1. `obj.announce_move_from(destination)` @@ -113,5 +180,6 @@ The process of traversing an exit is as follows: 1. `obj.at_after_move(source)` 1. On the Exit object, `at_after_traverse(obj, source)` is triggered. -If the move fails for whatever reason, the Exit will look for an Attribute `err_traverse` on itself and display this as an error message. If this is not found, the Exit will instead call -`at_failed_traverse(obj)` on itself. +If the move fails for whatever reason, the Exit will look for an Attribute `err_traverse` on itself +and display this as an error message. If this is not found, the Exit will instead call +`at_failed_traverse(obj)` on itself. diff --git a/docs/source/Online-Setup.md b/docs/source/Online-Setup.md index 579f7ea55a..0c0b802a8a 100644 --- a/docs/source/Online-Setup.md +++ b/docs/source/Online-Setup.md @@ -1,36 +1,77 @@ # Online Setup -Evennia development can be made without any Internet connection beyond fetching updates. At some point however, you are likely to want to make your game visible online, either as part opening it to the public or to allow other developers or beta testers access to it. +Evennia development can be made without any Internet connection beyond fetching updates. At some +point however, you are likely to want to make your game visible online, either as part opening it to +the public or to allow other developers or beta testers access to it. ## Connecting from the outside -Accessing your Evennia server from the outside is not hard on its own. Any issues are usually due to the various security measures your computer, network or hosting service has. These will generally (and correctly) block outside access to servers on your machine unless you tell them otherwise. +Accessing your Evennia server from the outside is not hard on its own. Any issues are usually due to +the various security measures your computer, network or hosting service has. These will generally +(and correctly) block outside access to servers on your machine unless you tell them otherwise. -We will start by showing how to host your server on your own local computer. Even if you plan to host your "real" game on a remote host later, setting it up locally is useful practice. We cover remote hosting later in this document. +We will start by showing how to host your server on your own local computer. Even if you plan to +host your "real" game on a remote host later, setting it up locally is useful practice. We cover +remote hosting later in this document. -Out of the box, Evennia uses three ports for outward communication. If your computer has a firewall, these should be open for in/out communication (and only these, other ports used by Evennia are internal to your computer only). +Out of the box, Evennia uses three ports for outward communication. If your computer has a firewall, +these should be open for in/out communication (and only these, other ports used by Evennia are +internal to your computer only). - `4000`, telnet, for traditional mud clients - `4001`, HTTP for the website) - `4002`, websocket, for the web client -Evennia will by default accept incoming connections on all interfaces (`0.0.0.0`) so in principle anyone knowing the ports to use and has the IP address to your machine should be able to connect to your game. +Evennia will by default accept incoming connections on all interfaces (`0.0.0.0`) so in principle +anyone knowing the ports to use and has the IP address to your machine should be able to connect to +your game. - - Make sure Evennia is installed and that you have activated the virtualenv. Start the server with `evennia start --log`. The `--log` (or `-l`) will make sure that the logs are echoed to the terminal. -> Note: If you need to close the log-view, use `Ctrl-C`. Use just `evennia --log` on its own to start tailing the logs again. - - Make sure you can connect with your web browser to `http://localhost:4001` or, alternatively, `http:127.0.0.1:4001` which is the same thing. You should get your Evennia web site and be able to play the game in the web client. Also check so that you can connect with a mud client to host `localhost`, port `4000` or host `127.0.0.1`, port `4000`. -- [Google for "my ip"](https://www.google.se/search?q=my+ip) or use any online service to figure out what your "outward-facing" IP address is. For our purposes, let's say your outward-facing IP is `203.0.113.0`. - - Next try your outward-facing IP by opening `http://203.0.113.0:4001` in a browser. If this works, that's it! Also try telnet, with the server set to `203.0.113.0` and port `4000`. However, most likely it will *not* work. If so, read on. - - If your computer has a firewall, it may be blocking the ports we need (it may also block telnet overall). If so, you need to open the outward-facing ports to in/out communication. See the manual/instructions for your firewall software on how to do this. To test you could also temporarily turn off your firewall entirely to see if that was indeed the problem. - - Another common problem for not being able to connect is that you are using a hardware router (like a wifi router). The router sits 'between' your computer and the Internet. So the IP you find with Google is the *router's* IP, not that of your computer. To resolve this you need to configure your router to *forward* data it gets on its ports to the IP and ports of your computer sitting in your private network. How to do this depends on the make of your router; you usually configure it using a normal web browser. In the router interface, look for "Port forwarding" or maybe "Virtual server". If that doesn't work, try to temporarily wire your computer directly to the Internet outlet (assuming your computer has the ports for it). You'll need to check for your IP again. If that works, you know the problem is the router. + - Make sure Evennia is installed and that you have activated the virtualenv. Start the server with +`evennia start --log`. The `--log` (or `-l`) will make sure that the logs are echoed to the +terminal. +> Note: If you need to close the log-view, use `Ctrl-C`. Use just `evennia --log` on its own to +start tailing the logs again. + - Make sure you can connect with your web browser to `http://localhost:4001` or, alternatively, +`http:127.0.0.1:4001` which is the same thing. You should get your Evennia web site and be able to +play the game in the web client. Also check so that you can connect with a mud client to host +`localhost`, port `4000` or host `127.0.0.1`, port `4000`. +- [Google for "my ip"](https://www.google.se/search?q=my+ip) or use any online service to figure out +what your "outward-facing" IP address is. For our purposes, let's say your outward-facing IP is +`203.0.113.0`. + - Next try your outward-facing IP by opening `http://203.0.113.0:4001` in a browser. If this works, +that's it! Also try telnet, with the server set to `203.0.113.0` and port `4000`. However, most +likely it will *not* work. If so, read on. + - If your computer has a firewall, it may be blocking the ports we need (it may also block telnet +overall). If so, you need to open the outward-facing ports to in/out communication. See the +manual/instructions for your firewall software on how to do this. To test you could also temporarily +turn off your firewall entirely to see if that was indeed the problem. + - Another common problem for not being able to connect is that you are using a hardware router +(like a wifi router). The router sits 'between' your computer and the Internet. So the IP you find +with Google is the *router's* IP, not that of your computer. To resolve this you need to configure +your router to *forward* data it gets on its ports to the IP and ports of your computer sitting in +your private network. How to do this depends on the make of your router; you usually configure it +using a normal web browser. In the router interface, look for "Port forwarding" or maybe "Virtual +server". If that doesn't work, try to temporarily wire your computer directly to the Internet outlet +(assuming your computer has the ports for it). You'll need to check for your IP again. If that +works, you know the problem is the router. -> Note: If you need to reconfigure a router, the router's Internet-facing ports do *not* have to have to have the same numbers as your computer's (and Evennia's) ports! For example, you might want to connect Evennia's outgoing port 4001 to an outgoing router port 80 - this is the port HTTP requests use and web browsers automatically look for - if you do that you could go to `http://203.0.113.0` without having to add the port at the end. This would collide with any other web services you are running through this router though. +> Note: If you need to reconfigure a router, the router's Internet-facing ports do *not* have to +have to have the same numbers as your computer's (and Evennia's) ports! For example, you might want +to connect Evennia's outgoing port 4001 to an outgoing router port 80 - this is the port HTTP +requests use and web browsers automatically look for - if you do that you could go to +`http://203.0.113.0` without having to add the port at the end. This would collide with any other +web services you are running through this router though. ### Settings example -You can connect Evennia to the Internet without any changes to your settings. The default settings are easy to use but are not necessarily the safest. You can customize your online presence in your [settings file](./Server-Conf#settings-file). To have Evennia recognize changed port settings you have to do a full `evennia reboot` to also restart the Portal and not just the Server component. +You can connect Evennia to the Internet without any changes to your settings. The default settings +are easy to use but are not necessarily the safest. You can customize your online presence in your +[settings file](./Server-Conf#settings-file). To have Evennia recognize changed port settings you have +to do a full `evennia reboot` to also restart the Portal and not just the Server component. -Below is an example of a simple set of settings, mostly using the defaults. Evennia will require access to five computer ports, of which three (only) should be open to the outside world. Below we continue to assume that our server address is `203.0.113.0`. +Below is an example of a simple set of settings, mostly using the defaults. Evennia will require +access to five computer ports, of which three (only) should be open to the outside world. Below we +continue to assume that our server address is `203.0.113.0`. ```python # in mygame/server/conf/settings.py @@ -60,57 +101,67 @@ Read on for a description of the individual settings. ### Telnet ```python -# Required. Change to whichever outgoing Telnet port(s) +# Required. Change to whichever outgoing Telnet port(s) # you are allowed to use on your host. TELNET_PORTS = [4000] -# Optional for security. Restrict which telnet -# interfaces we should accept. Should be set to your +# Optional for security. Restrict which telnet +# interfaces we should accept. Should be set to your # outward-facing IP address(es). Default is ´0.0.0.0´ # which accepts all interfaces. TELNET_INTERFACES = ['0.0.0.0'] ``` -The `TELNET_*` settings are the most important ones for getting a traditional base game going. Which IP addresses you have available depends on your server hosting solution (see the next sections). Some hosts will restrict which ports you are allowed you use so make sure to check. +The `TELNET_*` settings are the most important ones for getting a traditional base game going. Which +IP addresses you have available depends on your server hosting solution (see the next sections). +Some hosts will restrict which ports you are allowed you use so make sure to check. -### Web server +### Web server ```python -# Required. This is a list of tuples +# Required. This is a list of tuples # (outgoing_port, internal_port). Only the outgoing -# port should be open to the world! +# port should be open to the world! # set outgoing port to 80 if you want to run Evennia # as the only web server on your machine (if available). WEBSERVER_PORTS = [(4001, 4005)] -# Optional for security. Change this to the IP your -# server can be reached at (normally the same +# Optional for security. Change this to the IP your +# server can be reached at (normally the same # as TELNET_INTERFACES) WEBSERVER_INTERFACES = ['0.0.0.0'] -# Optional for security. Protects against -# man-in-the-middle attacks. Change it to your server's -# IP address or URL when you run a production server. +# Optional for security. Protects against +# man-in-the-middle attacks. Change it to your server's +# IP address or URL when you run a production server. ALLOWED_HOSTS = ['*'] ``` -The web server is always configured with two ports at a time. The *outgoing* port (`4001` by default) is the port external connections can use. If you don't want users to have to specify the port when they connect, you should set this to `80` - this however only works if you are not running any other web server on the machine. -The *internal* port (`4005` by default) is used internally by Evennia to communicate between the Server and the Portal. It should not be available to the outside world. You usually only need to change the outgoing port unless the default internal port is clashing with some other program. +The web server is always configured with two ports at a time. The *outgoing* port (`4001` by +default) is the port external connections can use. If you don't want users to have to specify the +port when they connect, you should set this to `80` - this however only works if you are not running +any other web server on the machine. +The *internal* port (`4005` by default) is used internally by Evennia to communicate between the +Server and the Portal. It should not be available to the outside world. You usually only need to +change the outgoing port unless the default internal port is clashing with some other program. ### Web client ```python # Required. Change this to the main IP address of your server. WEBSOCKET_CLIENT_INTERFACE = '0.0.0.0' -# Optional and needed only if using a proxy or similar. Change -# to the IP or address where the client can reach +# Optional and needed only if using a proxy or similar. Change +# to the IP or address where the client can reach # your server. The ws:// part is then required. If not given, the client -# will use its host location. +# will use its host location. WEBSOCKET_CLIENT_URL = "" # Required. Change to a free port for the websocket client to reach -# the server on. This will be automatically appended -# to WEBSOCKET_CLIENT_URL by the web client. +# the server on. This will be automatically appended +# to WEBSOCKET_CLIENT_URL by the web client. WEBSOCKET_CLIENT_PORT = 4002 ``` -The websocket-based web client needs to be able to call back to the server, and these settings must be changed for it to find where to look. If it cannot find the server you will get an warning in your browser's Console (in the dev tools of the browser), and the client will revert to the AJAX-based of the client instead, which tends to be slower. +The websocket-based web client needs to be able to call back to the server, and these settings must +be changed for it to find where to look. If it cannot find the server you will get an warning in +your browser's Console (in the dev tools of the browser), and the client will revert to the AJAX- +based of the client instead, which tends to be slower. ### Other ports @@ -120,32 +171,45 @@ SSL_PORTS = [4003] SSL_INTERFACES = ['0.0.0.0'] # Optional public facing. Only if you allow SSH connections (off by default). SSH_PORTS = [4004] -SSH_INTERFACES = ['0.0.0.0'] +SSH_INTERFACES = ['0.0.0.0'] # Required private. You should only change this if there is a clash -# with other services on your host. Should NOT be open to the -# outside world. +# with other services on your host. Should NOT be open to the +# outside world. AMP_PORT = 4006 ``` -The `AMP_PORT` is required to work, since this is the internal port linking Evennia's [Server and Portal](./Portal-And-Server) components together. The other ports are encrypted ports that may be useful for custom protocols but are otherwise not used. +The `AMP_PORT` is required to work, since this is the internal port linking Evennia's [Server and +Portal](Portal-And-Server) components together. The other ports are encrypted ports that may be +useful for custom protocols but are otherwise not used. ### Lockdown mode -When you test things out and check configurations you may not want players to drop in on you. Similarly, if you are doing maintenance on a live game you may want to take it offline for a while to fix eventual problems without risking people connecting. To do this, stop the server with `evennia stop` and add `LOCKDOWN_MODE = True` to your settings file. When you start the server again, your game will only be accessible from localhost. +When you test things out and check configurations you may not want players to drop in on you. +Similarly, if you are doing maintenance on a live game you may want to take it offline for a while +to fix eventual problems without risking people connecting. To do this, stop the server with +`evennia stop` and add `LOCKDOWN_MODE = True` to your settings file. When you start the server +again, your game will only be accessible from localhost. ### Registering with the Evennia game directory -Once your game is online you should make sure to register it with the [Evennia Game Index](http://games.evennia.com/). Registering with the index will help people find your server, drum up interest for your game and also shows people that Evennia is being used. You can do this even if you are just starting development - if you don't give any telnet/web address it will appear as _Not yet public_ and just be a teaser. If so, pick _pre-alpha_ as the development status. +Once your game is online you should make sure to register it with the [Evennia Game +Index](http://games.evennia.com/). Registering with the index will help people find your server, +drum up interest for your game and also shows people that Evennia is being used. You can do this +even if you are just starting development - if you don't give any telnet/web address it will appear +as _Not yet public_ and just be a teaser. If so, pick _pre-alpha_ as the development status. -To register, stand in your game dir, run +To register, stand in your game dir, run - evennia connections + evennia connections and follow the instructions. See the [Game index page](./Evennia-Game-Index) for more details. ## SSL -SSL can be very useful for web clients. It will protect the credentials and gameplay of your users over a web client if they are in a public place, and your websocket can also be switched to WSS for the same benefit. SSL certificates used to cost money on a yearly basis, but there is now a program that issues them for free with assisted setup to make the entire process less painful. +SSL can be very useful for web clients. It will protect the credentials and gameplay of your users +over a web client if they are in a public place, and your websocket can also be switched to WSS for +the same benefit. SSL certificates used to cost money on a yearly basis, but there is now a program +that issues them for free with assisted setup to make the entire process less painful. Options that may be useful in combination with an SSL proxy: @@ -162,26 +226,40 @@ WEBSOCKET_CLIENT_URL = "wss://fqdn:4002" ### Let's Encrypt -[Let's Encrypt](https://letsencrypt.org) is a certificate authority offering free certificates to secure a website with HTTPS. To get started issuing a certificate for your web server using Let's Encrypt, see these links: +[Let's Encrypt](https://letsencrypt.org) is a certificate authority offering free certificates to +secure a website with HTTPS. To get started issuing a certificate for your web server using Let's +Encrypt, see these links: - [Let's Encrypt - Getting Started](https://letsencrypt.org/getting-started/) - - The [CertBot Client](https://certbot.eff.org/) is a program for automatically obtaining a certificate, use it and maintain it with your website. + - The [CertBot Client](https://certbot.eff.org/) is a program for automatically obtaining a +certificate, use it and maintain it with your website. -Also, on Freenode visit the #letsencrypt channel for assistance from the community. For an additional resource, Let's Encrypt has a very active [community forum](https://community.letsencrypt.org/). +Also, on Freenode visit the #letsencrypt channel for assistance from the community. For an +additional resource, Let's Encrypt has a very active [community +forum](https://community.letsencrypt.org/). -[A blog where someone sets up Let's Encrypt](https://www.digitalocean.com/community/tutorials/how-to-secure-apache-with-let-s-encrypt-on-ubuntu-16-04) +[A blog where someone sets up Let's Encrypt](https://www.digitalocean.com/community/tutorials/how- +to-secure-apache-with-let-s-encrypt-on-ubuntu-16-04) -The only process missing from all of the above documentation is how to pass verification. This is how Let's Encrypt verifies that you have control over your domain (not necessarily ownership, it's Domain Validation (DV)). This can be done either with configuring a certain path on your web server or through a TXT record in your DNS. Which one you will want to do is a personal preference, but can also be based on your hosting choice. In a controlled/cPanel environment, you will most likely have to use DNS verification. +The only process missing from all of the above documentation is how to pass verification. This is +how Let's Encrypt verifies that you have control over your domain (not necessarily ownership, it's +Domain Validation (DV)). This can be done either with configuring a certain path on your web server +or through a TXT record in your DNS. Which one you will want to do is a personal preference, but can +also be based on your hosting choice. In a controlled/cPanel environment, you will most likely have +to use DNS verification. ## Relevant SSL Proxy Setup Information +- [HAProxy Config](./HAProxy-Config) - this is recommended for use with letsencrypt. This +page also has a more full description on how to set things up. - [Apache webserver configuration](./Apache-Config) (optional) -- [HAProxy Config](HAProxy-Config-(Optional)) ## Hosting locally or remotely? ### Using your own computer as a server -What we showed above is by far the simplest and probably cheapest option: Run Evennia on your own home computer. Moreover, since Evennia is its own web server, you don't need to install anything extra to have a website. +What we showed above is by far the simplest and probably cheapest option: Run Evennia on your own +home computer. Moreover, since Evennia is its own web server, you don't need to install anything +extra to have a website. **Advantages** - Free (except for internet costs and the electrical bill). @@ -191,69 +269,140 @@ What we showed above is by far the simplest and probably cheapest option: Run Ev **Disadvantages** - You need a good internet connection, ideally without any upload/download limits/costs. -- If you want to run a full game this way, your computer needs to always be on. It could be noisy, and as mentioned, the electrical bill must be considered. -- No support or safety - if your house burns down, so will your game. Also, you are yourself responsible for doing regular backups. +- If you want to run a full game this way, your computer needs to always be on. It could be noisy, +and as mentioned, the electrical bill must be considered. +- No support or safety - if your house burns down, so will your game. Also, you are yourself +responsible for doing regular backups. - Potentially not as easy if you don't know how to open ports in your firewall or router. -- Home IP numbers are often dynamically allocated, so for permanent online time you need to set up a DNS to always re-point to the right place (see below). -- You are personally responsible for any use/misuse of your internet connection-- though unlikely (but not impossible) if running your server somehow causes issues for other customers on the network, goes against your ISP's terms of service (many ISPs insist on upselling you to a business-tier connection) or you are the subject of legal action by a copyright holder, you may find your main internet connection terminated as a consequence. +- Home IP numbers are often dynamically allocated, so for permanent online time you need to set up a +DNS to always re-point to the right place (see below). +- You are personally responsible for any use/misuse of your internet connection-- though unlikely +(but not impossible) if running your server somehow causes issues for other customers on the +network, goes against your ISP's terms of service (many ISPs insist on upselling you to a business- +tier connection) or you are the subject of legal action by a copyright holder, you may find your +main internet connection terminated as a consequence. #### Setting up your own machine as a server -[The first section](./Online-Setup#connecting-from-the-outside) of this page describes how to do this and allow users to connect to the IP address of your machine/router. +[The first section](./Online-Setup#connecting-from-the-outside) of this page describes how to do this +and allow users to connect to the IP address of your machine/router. -A complication with using a specific IP address like this is that your home IP might not remain the same. Many ISPs (Internet Service Providers) allocates a *dynamic* IP to you which could change at any time. When that happens, that IP you told people to go to will be worthless. Also, that long string of numbers is not very pretty, is it? It's hard to remember and not easy to use in marketing your game. What you need is to alias it to a more sensible domain name - an alias that follows you around also when the IP changes. +A complication with using a specific IP address like this is that your home IP might not remain the +same. Many ISPs (Internet Service Providers) allocates a *dynamic* IP to you which could change at +any time. When that happens, that IP you told people to go to will be worthless. Also, that long +string of numbers is not very pretty, is it? It's hard to remember and not easy to use in marketing +your game. What you need is to alias it to a more sensible domain name - an alias that follows you +around also when the IP changes. -1. To set up a domain name alias, we recommend starting with a free domain name from [FreeDNS](http://freedns.afraid.org/). Once you register there (it's free) you have access to tens of thousands domain names that people have "donated" to allow you to use for your own sub domain. For example, `strangled.net` is one of those available domains. So tying our IP address to `strangled.net` using the subdomain `evennia` would mean that one could henceforth direct people to `http://evennia.strangled.net:4001` for their gaming needs - far easier to remember! -1. So how do we make this new, nice domain name follow us also if our IP changes? For this we need to set up a little program on our computer. It will check whenever our ISP decides to change our IP and tell FreeDNS that. There are many alternatives to be found from FreeDNS:s homepage, one that works on multiple platforms is [inadyn](http://www.inatech.eu/inadyn/). Get it from their page or, in Linux, through something like `apt-get install inadyn`. -1. Next, you login to your account on FreeDNS and go to the [Dynamic](http://freedns.afraid.org/dynamic/) page. You should have a list of your subdomains. Click the `Direct URL` link and you'll get a page with a text message. Ignore that and look at the URL of the page. It should be ending in a lot of random letters. Everything after the question mark is your unique "hash". Copy this string. +1. To set up a domain name alias, we recommend starting with a free domain name from +[FreeDNS](http://freedns.afraid.org/). Once you register there (it's free) you have access to tens +of thousands domain names that people have "donated" to allow you to use for your own sub domain. +For example, `strangled.net` is one of those available domains. So tying our IP address to +`strangled.net` using the subdomain `evennia` would mean that one could henceforth direct people to +`http://evennia.strangled.net:4001` for their gaming needs - far easier to remember! +1. So how do we make this new, nice domain name follow us also if our IP changes? For this we need +to set up a little program on our computer. It will check whenever our ISP decides to change our IP +and tell FreeDNS that. There are many alternatives to be found from FreeDNS:s homepage, one that +works on multiple platforms is [inadyn](http://www.inatech.eu/inadyn/). Get it from their page or, +in Linux, through something like `apt-get install inadyn`. +1. Next, you login to your account on FreeDNS and go to the +[Dynamic](http://freedns.afraid.org/dynamic/) page. You should have a list of your subdomains. Click +the `Direct URL` link and you'll get a page with a text message. Ignore that and look at the URL of +the page. It should be ending in a lot of random letters. Everything after the question mark is your +unique "hash". Copy this string. 1. You now start inadyn with the following command (Linux): `inadyn --dyndns_system default@freedns.afraid.org -a , &` - where `` would be `evennia.strangled.net` and `` the string of numbers we copied from FreeDNS. The `&` means we run in the background (might not be valid in other operating systems). `inadyn` will henceforth check for changes every 60 seconds. You should put the `inadyn` command string in a startup script somewhere so it kicks into gear whenever your computer starts. + where `` would be `evennia.strangled.net` and `` the string of numbers we copied +from FreeDNS. The `&` means we run in the background (might not be valid in other operating +systems). `inadyn` will henceforth check for changes every 60 seconds. You should put the `inadyn` +command string in a startup script somewhere so it kicks into gear whenever your computer starts. ### Remote hosting -Your normal "web hotel" will probably not be enough to run Evennia. A web hotel is normally aimed at a very specific usage - delivering web pages, at the most with some dynamic content. The "Python scripts" they refer to on their home pages are usually only intended to be CGI-like scripts launched by their webserver. Even if they allow you shell access (so you can install the Evennia dependencies in the first place), resource usage will likely be very restricted. Running a full-fledged game server like Evennia will probably be shunned upon or be outright impossible. If you are unsure, contact your web hotel and ask about their policy on you running third-party servers that will want to open custom ports. +Your normal "web hotel" will probably not be enough to run Evennia. A web hotel is normally aimed at +a very specific usage - delivering web pages, at the most with some dynamic content. The "Python +scripts" they refer to on their home pages are usually only intended to be CGI-like scripts launched +by their webserver. Even if they allow you shell access (so you can install the Evennia dependencies +in the first place), resource usage will likely be very restricted. Running a full-fledged game +server like Evennia will probably be shunned upon or be outright impossible. If you are unsure, +contact your web hotel and ask about their policy on you running third-party servers that will want +to open custom ports. -The options you probably need to look for are *shell account services*, *VPS:es* or *Cloud services*. A "Shell account" service means that you get a shell account on a server and can log in like any normal user. By contrast, a *VPS* (Virtual Private Server) service usually means that you get `root` access, but in a virtual machine. There are also *Cloud*-type services which allows for starting up multiple virtual machines and pay for what resources you use. +The options you probably need to look for are *shell account services*, *VPS:es* or *Cloud +services*. A "Shell account" service means that you get a shell account on a server and can log in +like any normal user. By contrast, a *VPS* (Virtual Private Server) service usually means that you +get `root` access, but in a virtual machine. There are also *Cloud*-type services which allows for +starting up multiple virtual machines and pay for what resources you use. **Advantages** -- Shell accounts/VPS/clouds offer more flexibility than your average web hotel - it's the ability to log onto a shared computer away from home. +- Shell accounts/VPS/clouds offer more flexibility than your average web hotel - it's the ability to +log onto a shared computer away from home. - Usually runs a Linux flavor, making it easy to install Evennia. -- Support. You don't need to maintain the server hardware. If your house burns down, at least your game stays online. Many services guarantee a certain level of up-time and also do regular backups for you. Make sure to check, some offer lower rates in exchange for you yourself being fully responsible for your data/backups. +- Support. You don't need to maintain the server hardware. If your house burns down, at least your +game stays online. Many services guarantee a certain level of up-time and also do regular backups +for you. Make sure to check, some offer lower rates in exchange for you yourself being fully +responsible for your data/backups. - Usually offers a fixed domain name, so no need to mess with IP addresses. -- May have the ability to easily deploy [docker](./Running-Evennia-in-Docker) versions of evennia and/or your game. +- May have the ability to easily deploy [docker](./Running-Evennia-in-Docker) versions of evennia +and/or your game. **Disadvantages** -- Might be pretty expensive (more so than a web hotel). Note that Evennia will normally need at least 100MB RAM and likely much more for a large production game. +- Might be pretty expensive (more so than a web hotel). Note that Evennia will normally need at +least 100MB RAM and likely much more for a large production game. - Linux flavors might feel unfamiliar to users not used to ssh/PuTTy and the Linux command line. -- You are probably sharing the server with many others, so you are not completely in charge. CPU usage might be limited. Also, if the server people decides to take the server down for maintenance, you have no choice but to sit it out (but you'll hopefully be warned ahead of time). +- You are probably sharing the server with many others, so you are not completely in charge. CPU +usage might be limited. Also, if the server people decides to take the server down for maintenance, +you have no choice but to sit it out (but you'll hopefully be warned ahead of time). #### Installing Evennia on a remote server -Firstly, if you are familiar with server infrastructure, consider using [Docker](./Running-Evennia-in-Docker) to deploy your game to the remote server; it will likely ease installation and deployment. Docker images may be a little confusing if you are completely new to them though. +Firstly, if you are familiar with server infrastructure, consider using [Docker](Running-Evennia-in- +Docker) to deploy your game to the remote server; it will likely ease installation and deployment. +Docker images may be a little confusing if you are completely new to them though. -If not using docker, and assuming you know how to connect to your account over ssh/PuTTy, you should be able to follow the [Getting Started](./Getting-Started) instructions normally. You only need Python and GIT pre-installed; these should both be available on any servers (if not you should be able to easily ask for them to be installed). On a VPS or Cloud service you can install them yourself as needed. +If not using docker, and assuming you know how to connect to your account over ssh/PuTTy, you should +be able to follow the [Getting Started](./Getting-Started) instructions normally. You only need Python +and GIT pre-installed; these should both be available on any servers (if not you should be able to +easily ask for them to be installed). On a VPS or Cloud service you can install them yourself as +needed. -If `virtualenv` is not available and you can't get it, you can download it (it's just a single file) from [the virtualenv pypi](https://pypi.python.org/pypi/virtualenv). Using `virtualenv` you can install everything without actually needing to have further `root` access. Ports might be an issue, so make sure you know which ports are available to use and reconfigure Evennia accordingly. +If `virtualenv` is not available and you can't get it, you can download it (it's just a single file) +from [the virtualenv pypi](https://pypi.python.org/pypi/virtualenv). Using `virtualenv` you can +install everything without actually needing to have further `root` access. Ports might be an issue, +so make sure you know which ports are available to use and reconfigure Evennia accordingly. ### Hosting options -To find commercial solutions, browse the web for "shell access", "VPS" or "Cloud services" in your region. You may find useful offers for "low cost" VPS hosting on [Low End Box][7]. The associated [Low End Talk][8] forum can be useful for health checking the many small businesses that offer "value" hosting, and occasionally for technical suggestions. +To find commercial solutions, browse the web for "shell access", "VPS" or "Cloud services" in your +region. You may find useful offers for "low cost" VPS hosting on [Low End Box][7]. The associated +[Low End Talk][8] forum can be useful for health checking the many small businesses that offer +"value" hosting, and occasionally for technical suggestions. -There are all sorts of services available. Below are some international suggestions offered by Evennia users: +There are all sorts of services available. Below are some international suggestions offered by +Evennia users: Hosting name | Type | Lowest price | Comments :--------------:|:-------:--------------- -[silvren.com][1] | Shell account | Free for MU* | Private hobby provider so don't assume backups or expect immediate support. To ask for an account, connect with a MUD client to iweb.localecho.net, port 4201 and ask for "Jarin". -[Digital Ocean][2] | VPS | $5/month | You can get a $50 credit if you use the referral link https://m.do.co/c/8f64fec2670c - if you do, once you've had it long enough to have paid $25 we will get that as a referral bonus to help Evennia development. -[Amazon Web services][3] | Cloud | ~$5/month / on-demand | Free Tier first 12 months. Regions available around the globe. -[Amazon Lightsail][9] | Cloud | $5/month | Free first month. AWS's new "fixed cost" offering. -[Genesis MUD hosting][4] | Shell account | $8/month | Dedicated MUD host with very limited memory offerings. As for 2017, runs a 13 years old Python version (2.4) so you'd need to either convince them to update or compile yourself. Note that Evennia needs *at least* the "Deluxe" package (50MB RAM) and probably *a lot* higher for a production game. This host is *not* recommended for Evennia. +[silvren.com][1] | Shell account | Free for MU* | Private hobby provider so don't assume backups +or expect immediate support. To ask for an account, connect with a MUD client to iweb.localecho.net, +port 4201 and ask for "Jarin". +[Digital Ocean][2] | VPS | $5/month | You get a credit if you use the referral link +https://m.do.co/c/8f64fec2670c - if you do, once you've had it long enough to have paid $25 we will +get that as a referral bonus to help Evennia development. +[Amazon Web services][3] | Cloud | ~$5/month / on-demand | Free Tier first 12 months. Regions +available around the globe. +[Amazon Lightsail][9] | Cloud | $5/month | Free first month. AWS's new "fixed cost" offering. +[Genesis MUD hosting][4] | Shell account | $8/month | Dedicated MUD host with very limited memory +offerings. As for 2017, runs a 13 years old Python version (2.4) so you'd need to either convince +them to update or compile yourself. Note that Evennia needs *at least* the "Deluxe" package (50MB +RAM) and probably *a lot* higher for a production game. This host is *not* recommended for Evennia. [Host1Plus][5] | VPS & Cloud | $4/month | $4-$8/month depending on length of sign-up period. -[Scaleway][6] | Cloud | €3/month / on-demand | EU based (Paris, Amsterdam). Smallest option provides 2GB RAM. -[Prgmr][10] | VPS | $5/month | 1 month free with a year prepay. You likely want some experience with servers with this option as they don't have a lot of support. +[Scaleway][6] | Cloud | €3/month / on-demand | EU based (Paris, Amsterdam). Smallest option +provides 2GB RAM. +[Prgmr][10] | VPS | $5/month | 1 month free with a year prepay. You likely want some experience with +servers with this option as they don't have a lot of support. [Linode][11] | Cloud | $5/month / on-demand | Multiple regions. Smallest option provides 1GB RAM *Please help us expand this list.* @@ -271,7 +420,14 @@ Hosting name | Type | Lowest price | Comments ## Cloud9 -If you are interested in running Evennia in the online dev environment [Cloud9](https://c9.io/), you can spin it up through their normal online setup using the Evennia Linux install instructions. The one extra thing you will have to do is update `mygame/server/conf/settings.py` and add `WEBSERVER_PORTS = [(8080, 4001)]`. This will then let you access the web server and do everything else as normal. +If you are interested in running Evennia in the online dev environment [Cloud9](https://c9.io/), you +can spin it up through their normal online setup using the Evennia Linux install instructions. The +one extra thing you will have to do is update `mygame/server/conf/settings.py` and add +`WEBSERVER_PORTS = [(8080, 4001)]`. This will then let you access the web server and do everything +else as normal. -Note that, as of December 2017, Cloud9 was re-released by Amazon as a service within their AWS cloud service offering. New customers entitled to the 1 year AWS "free tier" may find it provides sufficient resources to operate a Cloud9 development environment without charge. https://aws.amazon.com/cloud9/ +Note that, as of December 2017, Cloud9 was re-released by Amazon as a service within their AWS cloud +service offering. New customers entitled to the 1 year AWS "free tier" may find it provides +sufficient resources to operate a Cloud9 development environment without charge. +https://aws.amazon.com/cloud9/ diff --git a/docs/source/Parsing-command-arguments,-theory-and-best-practices.md b/docs/source/Parsing-command-arguments,-theory-and-best-practices.md index 752728feed..2be955ed90 100644 --- a/docs/source/Parsing-command-arguments,-theory-and-best-practices.md +++ b/docs/source/Parsing-command-arguments,-theory-and-best-practices.md @@ -1,9 +1,14 @@ # Parsing command arguments, theory and best practices -This tutorial will elaborate on the many ways one can parse command arguments. The first step after [adding a command](./Adding-Command-Tutorial) usually is to parse its arguments. There are lots of ways to do it, but some are indeed better than others and this tutorial will try to present them. +This tutorial will elaborate on the many ways one can parse command arguments. The first step after +[adding a command](./Adding-Command-Tutorial) usually is to parse its arguments. There are lots of +ways to do it, but some are indeed better than others and this tutorial will try to present them. -If you're a Python beginner, this tutorial might help you a lot. If you're already familiar with Python syntax, this tutorial might still contain useful information. There are still a lot of things I find in the standard library that come as a surprise, though they were there all along. This might be true for others. +If you're a Python beginner, this tutorial might help you a lot. If you're already familiar with +Python syntax, this tutorial might still contain useful information. There are still a lot of +things I find in the standard library that come as a surprise, though they were there all along. +This might be true for others. In this tutorial we will: @@ -14,29 +19,42 @@ In this tutorial we will: ## What are command arguments? -I'm going to talk about command arguments and parsing a lot in this tutorial. So let's be sure we talk about the same thing before going any further: +I'm going to talk about command arguments and parsing a lot in this tutorial. So let's be sure we +talk about the same thing before going any further: > A command is an Evennia object that handles specific user input. -For instance, the default `look` is a command. After having created your Evennia game, and connected to it, you should be able to type `look` to see what's around. In this context, `look` is a command. +For instance, the default `look` is a command. After having created your Evennia game, and +connected to it, you should be able to type `look` to see what's around. In this context, `look` is +a command. > Command arguments are additional text passed after the command. -Following the same example, you can type `look self` to look at yourself. In this context, `self` is the text specified after `look`. `" self"` is the argument to the `look` command. +Following the same example, you can type `look self` to look at yourself. In this context, `self` +is the text specified after `look`. `" self"` is the argument to the `look` command. -Part of our task as a game developer is to connect user inputs (mostly commands) with actions in the game. And most of the time, entering commands is not enough, we have to rely on arguments for specifying actions with more accuracy. +Part of our task as a game developer is to connect user inputs (mostly commands) with actions in the +game. And most of the time, entering commands is not enough, we have to rely on arguments for +specifying actions with more accuracy. -Take the `say` command. If you couldn't specify what to say as a command argument (`say hello!`), you would have trouble communicating with others in the game. One would need to create a different command for every kind of word or sentence, which is, of course, not practical. +Take the `say` command. If you couldn't specify what to say as a command argument (`say hello!`), +you would have trouble communicating with others in the game. One would need to create a different +command for every kind of word or sentence, which is, of course, not practical. Last thing: what is parsing? -> In our case, parsing is the process by which we convert command arguments into something we can work with. +> In our case, parsing is the process by which we convert command arguments into something we can +work with. -We don't usually use the command argument as is (which is just text, of type `str` in Python). We need to extract useful information. We might want to ask the user for a number, or the name of another character present in the same room. We're going to see how to do all that now. +We don't usually use the command argument as is (which is just text, of type `str` in Python). We +need to extract useful information. We might want to ask the user for a number, or the name of +another character present in the same room. We're going to see how to do all that now. ## Working with strings -In object terms, when you write a command in Evennia (when you write the Python class), the arguments are stored in the `args` attribute. Which is to say, inside your `func` method, you can access the command arguments in `self.args`. +In object terms, when you write a command in Evennia (when you write the Python class), the +arguments are stored in the `args` attribute. Which is to say, inside your `func` method, you can +access the command arguments in `self.args`. ### self.args @@ -61,7 +79,8 @@ class CmdTest(Command): self.msg(f"You have entered: {self.args}.") ``` -If you add this command and test it, you will receive exactly what you have entered without any parsing: +If you add this command and test it, you will receive exactly what you have entered without any +parsing: ``` > test Whatever @@ -70,14 +89,18 @@ You have entered: Whatever. You have entered: . ``` -> The lines starting with `>` indicate what you enter into your client. The other lines are what you receive from the game server. +> The lines starting with `>` indicate what you enter into your client. The other lines are what +you receive from the game server. Notice two things here: -1. The left space between our command key ("test", here) and our command argument is not removed. That's why there are two spaces in our output at line 2. Try entering something like "testok". -2. Even if you don't enter command arguments, the command will still be called with an empty string in `self.args`. +1. The left space between our command key ("test", here) and our command argument is not removed. +That's why there are two spaces in our output at line 2. Try entering something like "testok". +2. Even if you don't enter command arguments, the command will still be called with an empty string +in `self.args`. -Perhaps a slight modification to our code would be appropriate to see what's happening. We will force Python to display the command arguments as a debug string using a little shortcut. +Perhaps a slight modification to our code would be appropriate to see what's happening. We will +force Python to display the command arguments as a debug string using a little shortcut. ```python class CmdTest(Command): @@ -98,7 +121,8 @@ class CmdTest(Command): self.msg(f"You have entered: {self.args!r}.") ``` -The only line we have changed is the last one, and we have added `!r` between our braces to tell Python to print the debug version of the argument (the repr-ed version). Let's see the result: +The only line we have changed is the last one, and we have added `!r` between our braces to tell +Python to print the debug version of the argument (the repr-ed version). Let's see the result: ``` > test Whatever @@ -109,21 +133,32 @@ You have entered: ''. You have entered: " And something with '?". ``` -This displays the string in a way you could see in the Python interpreter. It might be easier to read... to debug, anyway. +This displays the string in a way you could see in the Python interpreter. It might be easier to +read... to debug, anyway. -I insist so much on that point because it's crucial: the command argument is just a string (of type `str`) and we will use this to parse it. What you will see is mostly not Evennia-specific, it's Python-specific and could be used in any other project where you have the same need. +I insist so much on that point because it's crucial: the command argument is just a string (of type +`str`) and we will use this to parse it. What you will see is mostly not Evennia-specific, it's +Python-specific and could be used in any other project where you have the same need. ### Stripping -As you've seen, our command arguments are stored with the space. And the space between the command and the arguments is often of no importance. +As you've seen, our command arguments are stored with the space. And the space between the command +and the arguments is often of no importance. > Why is it ever there? -Evennia will try its best to find a matching command. If the user enters your command key with arguments (but omits the space), Evennia will still be able to find and call the command. You might have seen what happened if the user entered `testok`. In this case, `testok` could very well be a command (Evennia checks for that) but seeing none, and because there's a `test` command, Evennia calls it with the arguments `"ok"`. +Evennia will try its best to find a matching command. If the user enters your command key with +arguments (but omits the space), Evennia will still be able to find and call the command. You might +have seen what happened if the user entered `testok`. In this case, `testok` could very well be a +command (Evennia checks for that) but seeing none, and because there's a `test` command, Evennia +calls it with the arguments `"ok"`. -But most of the time, we don't really care about this left space, so you will often see code to remove it. There are different ways to do it in Python, but a command use case is the `strip` method on `str` and its cousins, `lstrip` and `rstrip`. +But most of the time, we don't really care about this left space, so you will often see code to +remove it. There are different ways to do it in Python, but a command use case is the `strip` +method on `str` and its cousins, `lstrip` and `rstrip`. -- `strip`: removes one or more characters (either spaces or other characters) from both ends of the string. +- `strip`: removes one or more characters (either spaces or other characters) from both ends of the +string. - `lstrip`: same thing but only removes from the left end (left strip) of the string. - `rstrip`: same thing but only removes from the right end (right strip) of the string. @@ -140,7 +175,8 @@ Some Python examples might help: 'Now, what is it' ``` -Usually, since we don't need the space separator, but still want our command to work if there's no separator, we call `lstrip` on the command arguments: +Usually, since we don't need the space separator, but still want our command to work if there's no +separator, we call `lstrip` on the command arguments: ```python class CmdTest(Command): @@ -165,7 +201,9 @@ class CmdTest(Command): self.msg(f"You have entered: {self.args!r}.") ``` -> We are now beginning to override the command's `parse` method, which is typically useful just for argument parsing. This method is executed before `func` and so `self.args` in `func()` will contain our `self.args.lstrip()`. +> We are now beginning to override the command's `parse` method, which is typically useful just for +argument parsing. This method is executed before `func` and so `self.args` in `func()` will contain +our `self.args.lstrip()`. Let's try it: @@ -182,13 +220,18 @@ You have entered: 'And something with lots of spaces'. Spaces at the end of the string are kept, but all spaces at the beginning are removed: -> `strip`, `lstrip` and `rstrip` without arguments will strip spaces, line breaks and other common separators. You can specify one or more characters as a parameter. If you specify more than one character, all of them will be stripped from your original string. +> `strip`, `lstrip` and `rstrip` without arguments will strip spaces, line breaks and other common +separators. You can specify one or more characters as a parameter. If you specify more than one +character, all of them will be stripped from your original string. ### Convert arguments to numbers -As pointed out, `self.args` is a string (of type `str`). What if we want the user to enter a number? +As pointed out, `self.args` is a string (of type `str`). What if we want the user to enter a +number? -Let's take a very simple example: creating a command, `roll`, that allows to roll a six-sided die. The player has to guess the number, specifying the number as argument. To win, the player has to match the number with the die. Let's see an example: +Let's take a very simple example: creating a command, `roll`, that allows to roll a six-sided die. +The player has to guess the number, specifying the number as argument. To win, the player has to +match the number with the die. Let's see an example: ``` > roll 3 @@ -202,7 +245,9 @@ You roll a die. It lands on the number 1. You played 1, you have won! ``` -If that's your first command, it's a good opportunity to try to write it. A command with a simple and finite role always is a good starting choice. Here's how we could (first) write it... but it won't work as is, I warn you: +If that's your first command, it's a good opportunity to try to write it. A command with a simple +and finite role always is a good starting choice. Here's how we could (first) write it... but it +won't work as is, I warn you: ```python from random import randint @@ -242,11 +287,20 @@ class CmdRoll(Command): self.msg(f"You played {self.args}, you have lost.") ``` -If you try this code, Python will complain that you try to compare a number with a string: `figure` is a number and `self.args` is a string and can't be compared as-is in Python. Python doesn't do "implicit converting" as some languages do. By the way, this might be annoying sometimes, and other times you will be glad it tries to encourage you to be explicit rather than implicit about what to do. This is an ongoing debate between programmers. Let's move on! +If you try this code, Python will complain that you try to compare a number with a string: `figure` +is a number and `self.args` is a string and can't be compared as-is in Python. Python doesn't do +"implicit converting" as some languages do. By the way, this might be annoying sometimes, and other +times you will be glad it tries to encourage you to be explicit rather than implicit about what to +do. This is an ongoing debate between programmers. Let's move on! -So we need to convert the command argument from a `str` into an `int`. There are a few ways to do it. But the proper way is to try to convert and deal with the `ValueError` Python exception. +So we need to convert the command argument from a `str` into an `int`. There are a few ways to do +it. But the proper way is to try to convert and deal with the `ValueError` Python exception. -Converting a `str` into an `int` in Python is extremely simple: just use the `int` function, give it the string and it returns an integer, if it could. If it can't, it will raise `ValueError`. So we'll need to catch that. However, we also have to indicate to Evennia that, should the number be invalid, no further parsing should be done. Here's a new attempt at our command with this converting: +Converting a `str` into an `int` in Python is extremely simple: just use the `int` function, give it +the string and it returns an integer, if it could. If it can't, it will raise `ValueError`. So +we'll need to catch that. However, we also have to indicate to Evennia that, should the number be +invalid, no further parsing should be done. Here's a new attempt at our command with this +converting: ```python from random import randint @@ -295,13 +349,24 @@ class CmdRoll(Command): self.msg(f"You played {self.entered}, you have lost.") ``` -Before enjoying the result, let's examine the `parse` method a little more: what it does is try to convert the entered argument from a `str` to an `int`. This might fail (if a user enters `roll something`). In such a case, Python raises a `ValueError` exception. We catch it in our `try/except` block, send a message to the user and raise the `InterruptCommand` exception in response to tell Evennia to not run `func()`, since we have no valid number to give it. +Before enjoying the result, let's examine the `parse` method a little more: what it does is try to +convert the entered argument from a `str` to an `int`. This might fail (if a user enters `roll +something`). In such a case, Python raises a `ValueError` exception. We catch it in our +`try/except` block, send a message to the user and raise the `InterruptCommand` exception in +response to tell Evennia to not run `func()`, since we have no valid number to give it. -In the `func` method, instead of using `self.args`, we use `self.entered` which we have defined in our `parse` method. You can expect that, if `func()` is run, then `self.entered` contains a valid number. +In the `func` method, instead of using `self.args`, we use `self.entered` which we have defined in +our `parse` method. You can expect that, if `func()` is run, then `self.entered` contains a valid +number. -If you try this command, it will work as expected this time: the number is converted as it should and compared to the die roll. You might spend some minutes playing this game. Time out! +If you try this command, it will work as expected this time: the number is converted as it should +and compared to the die roll. You might spend some minutes playing this game. Time out! -Something else we could want to address: in our small example, we only want the user to enter a positive number between 1 and 6. And the user can enter `roll 0` or `roll -8` or `roll 208` for that matter, the game still works. It might be worth addressing. Again, you could write a condition to do that, but since we're catching an exception, we might end up with something cleaner by grouping: +Something else we could want to address: in our small example, we only want the user to enter a +positive number between 1 and 6. And the user can enter `roll 0` or `roll -8` or `roll 208` for +that matter, the game still works. It might be worth addressing. Again, you could write a +condition to do that, but since we're catching an exception, we might end up with something cleaner +by grouping: ```python from random import randint @@ -351,13 +416,19 @@ class CmdRoll(Command): self.msg(f"You played {self.entered}, you have lost.") ``` -Using grouped exceptions like that makes our code easier to read, but if you feel more comfortable checking, afterward, that the number the user entered is in the right range, you can do so in a latter condition. +Using grouped exceptions like that makes our code easier to read, but if you feel more comfortable +checking, afterward, that the number the user entered is in the right range, you can do so in a +latter condition. -> Notice that we have updated our `parse` method only in this last attempt, not our `func()` method which remains the same. This is one goal of separating argument parsing from command processing, these two actions are best kept isolated. +> Notice that we have updated our `parse` method only in this last attempt, not our `func()` method +which remains the same. This is one goal of separating argument parsing from command processing, +these two actions are best kept isolated. ### Working with several arguments -Often a command expects several arguments. So far, in our example with the "roll" command, we only expect one argument: a number and just a number. What if we want the user to specify several numbers? First the number of dice to roll, then the guess? +Often a command expects several arguments. So far, in our example with the "roll" command, we only +expect one argument: a number and just a number. What if we want the user to specify several +numbers? First the number of dice to roll, then the guess? > You won't win often if you roll 5 dice but that's for the example. @@ -367,7 +438,9 @@ So we would like to interpret a command like this: (To be understood: roll 3 dice, my guess is the total number will be 12.) -What we need is to cut our command argument, which is a `str`, break it at the space (we use the space as a delimiter). Python provides the `str.split` method which we'll use. Again, here are some examples from the Python interpreter: +What we need is to cut our command argument, which is a `str`, break it at the space (we use the +space as a delimiter). Python provides the `str.split` method which we'll use. Again, here are +some examples from the Python interpreter: >>> args = "3 12" >>> args.split(" ") @@ -377,9 +450,12 @@ What we need is to cut our command argument, which is a `str`, break it at the s ['a', 'command', 'with', 'several', 'arguments'] >>> -As you can see, `str.split` will "convert" our strings into a list of strings. The specified argument (`" "` in our case) is used as delimiter. So Python browses our original string. When it sees a delimiter, it takes whatever is before this delimiter and append it to a list. +As you can see, `str.split` will "convert" our strings into a list of strings. The specified +argument (`" "` in our case) is used as delimiter. So Python browses our original string. When it +sees a delimiter, it takes whatever is before this delimiter and append it to a list. -The point here is that `str.split` will be used to split our argument. But, as you can see from the above output, we can never be sure of the length of the list at this point: +The point here is that `str.split` will be used to split our argument. But, as you can see from the +above output, we can never be sure of the length of the list at this point: >>> args = "something" >>> args.split(" ") @@ -389,14 +465,20 @@ The point here is that `str.split` will be used to split our argument. But, as [''] >>> -Again we could use a condition to check the number of split arguments, but Python offers a better approach, making use of its exception mechanism. We'll give a second argument to `str.split`, the maximum number of splits to do. Let's see an example, this feature might be confusing at first glance: +Again we could use a condition to check the number of split arguments, but Python offers a better +approach, making use of its exception mechanism. We'll give a second argument to `str.split`, the +maximum number of splits to do. Let's see an example, this feature might be confusing at first +glance: >>> args = "that is something great" >>> args.split(" ", 1) # one split, that is a list with two elements (before, after) ['that', 'is something great'] >>> -Read this example as many times as needed to understand it. The second argument we give to `str.split` is not the length of the list that should be returned, but the number of times we have to split. Therefore, we specify 1 here, but we get a list of two elements (before the separator, after the separator). +Read this example as many times as needed to understand it. The second argument we give to +`str.split` is not the length of the list that should be returned, but the number of times we have +to split. Therefore, we specify 1 here, but we get a list of two elements (before the separator, +after the separator). > What will happen if Python can't split the number of times we ask? @@ -407,9 +489,12 @@ It won't: ['whatever'] >>> -This is one moment I would have hoped for an exception and didn't get one. But there's another way which will raise an exception if there is an error: variable unpacking. +This is one moment I would have hoped for an exception and didn't get one. But there's another way +which will raise an exception if there is an error: variable unpacking. -We won't talk about this feature in details here. It would be complicated. But the code is really straightforward to use. Let's take our example of the roll command but let's add a first argument: the number of dice to roll. +We won't talk about this feature in details here. It would be complicated. But the code is really +straightforward to use. Let's take our example of the roll command but let's add a first argument: +the number of dice to roll. ```python from random import randint @@ -490,13 +575,23 @@ except ValueError: raise InterruptCommand ``` -We split the argument using `str.split` but we capture the result in two variables. Python is smart enough to know that we want what's left of the space in the first variable, what's right of the space in the second variable. If there is not even a space in the string, Python will raise a `ValueError` exception. +We split the argument using `str.split` but we capture the result in two variables. Python is smart +enough to know that we want what's left of the space in the first variable, what's right of the +space in the second variable. If there is not even a space in the string, Python will raise a +`ValueError` exception. -This code is much easier to read than browsing through the returned strings of `str.split`. We can convert both variables the way we did previously. Actually there are not so many changes in this version and the previous one, most of it is due to name changes for clarity. +This code is much easier to read than browsing through the returned strings of `str.split`. We can +convert both variables the way we did previously. Actually there are not so many changes in this +version and the previous one, most of it is due to name changes for clarity. -> Splitting a string with a maximum of splits is a common occurrence while parsing command arguments. You can also see the `str.rspli8t` method that does the same thing but from the right of the string. Therefore, it will attempt to find delimiters at the end of the string and work toward the beginning of it. +> Splitting a string with a maximum of splits is a common occurrence while parsing command +arguments. You can also see the `str.rspli8t` method that does the same thing but from the right of +the string. Therefore, it will attempt to find delimiters at the end of the string and work toward +the beginning of it. -We have used a space as a delimiter. This is absolutely not necessary. You might remember that most default Evennia commands can take an `=` sign as a delimiter. Now you know how to parse them as well: +We have used a space as a delimiter. This is absolutely not necessary. You might remember that +most default Evennia commands can take an `=` sign as a delimiter. Now you know how to parse them +as well: >>> cmd_key = "tel" >>> cmd_args = "book = chest" @@ -509,14 +604,18 @@ We have used a space as a delimiter. This is absolutely not necessary. You mig ### Optional arguments -Sometimes, you'll come across commands that have optional arguments. These arguments are not necessary but they can be set if more information is needed. I will not provide the entire command code here but just enough code to show the mechanism in Python: +Sometimes, you'll come across commands that have optional arguments. These arguments are not +necessary but they can be set if more information is needed. I will not provide the entire command +code here but just enough code to show the mechanism in Python: -Again, we'll use `str.split`, knowing that we might not have any delimiter at all. For instance, the player could enter the "tel" command like this: +Again, we'll use `str.split`, knowing that we might not have any delimiter at all. For instance, +the player could enter the "tel" command like this: > tel book > tell book = chest -The equal sign is optional along with whatever is specified after it. A possible solution in our `parse` method would be: +The equal sign is optional along with whatever is specified after it. A possible solution in our +`parse` method would be: ```python def parse(self): @@ -530,34 +629,51 @@ The equal sign is optional along with whatever is specified after it. A possibl destination = None ``` -This code would place everything the user entered in `obj` if she didn't specify any equal sign. Otherwise, what's before the equal sign will go in `obj`, what's after the equal sign will go in `destination`. This makes for quick testing after that, more robust code with less conditions that might too easily break your code if you're not careful. +This code would place everything the user entered in `obj` if she didn't specify any equal sign. +Otherwise, what's before the equal sign will go in `obj`, what's after the equal sign will go in +`destination`. This makes for quick testing after that, more robust code with less conditions that +might too easily break your code if you're not careful. > Again, here we specified a maximum numbers of splits. If the users enters: > tel book = chest = chair -Then `destination` will contain: `" chest = chair"`. This is often desired, but it's up to you to set parsing however you like. +Then `destination` will contain: `" chest = chair"`. This is often desired, but it's up to you to +set parsing however you like. ## Evennia searches -After this quick tour of some `str` methods, we'll take a look at some Evennia-specific features that you won't find in standard Python. +After this quick tour of some `str` methods, we'll take a look at some Evennia-specific features +that you won't find in standard Python. -One very common task is to convert a `str` into an Evennia object. Take the previous example: having `"book"` in a variable is great, but we would prefer to know what the user is talking about... what is this `"book"`? +One very common task is to convert a `str` into an Evennia object. Take the previous example: +having `"book"` in a variable is great, but we would prefer to know what the user is talking +about... what is this `"book"`? -To get an object from a string, we perform an Evennia search. Evennia provides a `search` method on all typeclassed objects (you will most likely use the one on characters or accounts). This method supports a very wide array of arguments and has [its own tutorial](./Tutorial-Searching-For-Objects). Some examples of useful cases follow: +To get an object from a string, we perform an Evennia search. Evennia provides a `search` method on +all typeclassed objects (you will most likely use the one on characters or accounts). This method +supports a very wide array of arguments and has [its own tutorial](./Tutorial-Searching-For-Objects). +Some examples of useful cases follow: ### Local searches -When an account or a character enters a command, the account or character is found in the `caller` attribute. Therefore, `self.caller` will contain an account or a character (or a session if that's a session command, though that's not as frequent). The `search` method will be available on this caller. +When an account or a character enters a command, the account or character is found in the `caller` +attribute. Therefore, `self.caller` will contain an account or a character (or a session if that's +a session command, though that's not as frequent). The `search` method will be available on this +caller. -Let's take the same example of our little "tel" command. The user can specify an object as argument: +Let's take the same example of our little "tel" command. The user can specify an object as +argument: ```python def parse(self): name = self.args.lstrip() ``` -We then need to "convert" this string into an Evennia object. The Evennia object will be searched in the caller's location and its contents by default (that is to say, if the command has been entered by a character, it will search the object in the character's room and the character's inventory). +We then need to "convert" this string into an Evennia object. The Evennia object will be searched +in the caller's location and its contents by default (that is to say, if the command has been +entered by a character, it will search the object in the character's room and the character's +inventory). ```python def parse(self): @@ -566,7 +682,9 @@ We then need to "convert" this string into an Evennia object. The Evennia objec self.obj = self.caller.search(name) ``` -We specify only one argument to the `search` method here: the string to search. If Evennia finds a match, it will return it and we keep it in the `obj` attribute. If it can't find anything, it will return `None` so we need to check for that: +We specify only one argument to the `search` method here: the string to search. If Evennia finds a +match, it will return it and we keep it in the `obj` attribute. If it can't find anything, it will +return `None` so we need to check for that: ```python def parse(self): @@ -578,11 +696,14 @@ We specify only one argument to the `search` method here: the string to search. raise InterruptCommand ``` -That's it. After this condition, you know that whatever is in `self.obj` is a valid Evennia object (another character, an object, an exit...). +That's it. After this condition, you know that whatever is in `self.obj` is a valid Evennia object +(another character, an object, an exit...). ### Quiet searches -By default, Evennia will handle the case when more than one match is found in the search. The user will be asked to narrow down and re-enter the command. You can, however, ask to be returned the list of matches and handle this list yourself: +By default, Evennia will handle the case when more than one match is found in the search. The user +will be asked to narrow down and re-enter the command. You can, however, ask to be returned the +list of matches and handle this list yourself: ```python def parse(self): @@ -597,11 +718,16 @@ By default, Evennia will handle the case when more than one match is found in th self.obj = objs[0] # Take the first match even if there are several ``` -All we have changed to obtain a list is a keyword argument in the `search` method: `quiet`. If set to `True`, then errors are ignored and a list is always returned, so we need to handle it as such. Notice in this example, `self.obj` will contain a valid object too, but if several matches are found, `self.obj` will contain the first one, even if more matches are available. +All we have changed to obtain a list is a keyword argument in the `search` method: `quiet`. If set +to `True`, then errors are ignored and a list is always returned, so we need to handle it as such. +Notice in this example, `self.obj` will contain a valid object too, but if several matches are +found, `self.obj` will contain the first one, even if more matches are available. ### Global searches -By default, Evennia will perform a local search, that is, a search limited by the location in which the caller is. If you want to perform a global search (search in the entire database), just set the `global_search` keyword argument to `True`: +By default, Evennia will perform a local search, that is, a search limited by the location in which +the caller is. If you want to perform a global search (search in the entire database), just set the +`global_search` keyword argument to `True`: ```python def parse(self): @@ -611,4 +737,12 @@ By default, Evennia will perform a local search, that is, a search limited by th ## Conclusion -Parsing command arguments is vital for most game designers. If you design "intelligent" commands, users should be able to guess how to use them without reading the help, or with a very quick peek at said help. Good commands are intuitive to users. Better commands do what they're told to do. For game designers working on MUDs, commands are the main entry point for users into your game. This is no trivial. If commands execute correctly (if their argument is parsed, if they don't behave in unexpected ways and report back the right errors), you will have happier players that might stay longer on your game. I hope this tutorial gave you some pointers on ways to improve your command parsing. There are, of course, other ways you will discover, or ways you are already using in your code. +Parsing command arguments is vital for most game designers. If you design "intelligent" commands, +users should be able to guess how to use them without reading the help, or with a very quick peek at +said help. Good commands are intuitive to users. Better commands do what they're told to do. For +game designers working on MUDs, commands are the main entry point for users into your game. This is +no trivial. If commands execute correctly (if their argument is parsed, if they don't behave in +unexpected ways and report back the right errors), you will have happier players that might stay +longer on your game. I hope this tutorial gave you some pointers on ways to improve your command +parsing. There are, of course, other ways you will discover, or ways you are already using in your +code. diff --git a/docs/source/Portal-And-Server.md b/docs/source/Portal-And-Server.md index 03ad6de9bc..22aa115db3 100644 --- a/docs/source/Portal-And-Server.md +++ b/docs/source/Portal-And-Server.md @@ -8,7 +8,8 @@ If you are new to the concept, the main purpose of separating the two is to have the Portal but keep the MUD running on the Server. This way one can restart/reload the game (the Server part) without Accounts getting disconnected. -![portal and server layout](https://474a3b9f-a-62cb3a1a-s-sites.googlegroups.com/site/evenniaserver/file-cabinet/evennia_server_portal.png) +![portal and server layout](https://474a3b9f-a-62cb3a1a-s- +sites.googlegroups.com/site/evenniaserver/file-cabinet/evennia_server_portal.png) The Server and Portal are glued together via an AMP (Asynchronous Messaging Protocol) connection. This allows the two programs to communicate seamlessly. diff --git a/docs/source/Profiling.md b/docs/source/Profiling.md index 88f9672b6f..c2faff69c3 100644 --- a/docs/source/Profiling.md +++ b/docs/source/Profiling.md @@ -8,7 +8,8 @@ Sometimes it can be useful to try to determine just how efficient a particular p to figure out if one could speed up things more than they are. There are many ways to test the performance of Python and the running server. -Before digging into this section, remember Donald Knuth's [words of wisdom](https://en.wikipedia.org/wiki/Program_optimization#When_to_optimize): +Before digging into this section, remember Donald Knuth's [words of +wisdom](https://en.wikipedia.org/wiki/Program_optimization#When_to_optimize): > *[...]about 97% of the time: Premature optimization is the root of all evil*. @@ -19,7 +20,8 @@ and maintainability and you may find that a small gain in speed is just not wort ## Simple timer tests -Python's `timeit` module is very good for testing small things. For example, in order to test if it is faster to use a `for` loop or a list comprehension you could use the following code: +Python's `timeit` module is very good for testing small things. For example, in order to test if it +is faster to use a `for` loop or a list comprehension you could use the following code: ```python import timeit @@ -31,52 +33,91 @@ Python's `timeit` module is very good for testing small things. For example, in <<< 5.358283996582031 ``` -The `setup` keyword is used to set up things that should not be included in the time measurement, like `a = []` in the first call. +The `setup` keyword is used to set up things that should not be included in the time measurement, +like `a = []` in the first call. -By default the `timeit` function will re-run the given test 1000000 times and returns the *total time* to do so (so *not* the average per test). A hint is to not use this default for testing something that includes database writes - for that you may want to use a lower number of repeats (say 100 or 1000) using the `number=100` keyword. +By default the `timeit` function will re-run the given test 1000000 times and returns the *total +time* to do so (so *not* the average per test). A hint is to not use this default for testing +something that includes database writes - for that you may want to use a lower number of repeats +(say 100 or 1000) using the `number=100` keyword. ## Using cProfile -Python comes with its own profiler, named cProfile (this is for cPython, no tests have been done with `pypy` at this point). Due to the way Evennia's processes are handled, there is no point in using the normal way to start the profiler (`python -m cProfile evennia.py`). Instead you start the profiler through the launcher: +Python comes with its own profiler, named cProfile (this is for cPython, no tests have been done +with `pypy` at this point). Due to the way Evennia's processes are handled, there is no point in +using the normal way to start the profiler (`python -m cProfile evennia.py`). Instead you start the +profiler through the launcher: evennia --profiler start -This will start Evennia with the Server component running (in daemon mode) under cProfile. You could instead try `--profile` with the `portal` argument to profile the Portal (you would then need to [start the Server separately](./Start-Stop-Reload)). +This will start Evennia with the Server component running (in daemon mode) under cProfile. You could +instead try `--profile` with the `portal` argument to profile the Portal (you would then need to +[start the Server separately](./Start-Stop-Reload)). -Please note that while the profiler is running, your process will use a lot more memory than usual. Memory usage is even likely to climb over time. So don't leave it running perpetually but monitor it carefully (for example using the `top` command on Linux or the Task Manager's memory display on Windows). +Please note that while the profiler is running, your process will use a lot more memory than usual. +Memory usage is even likely to climb over time. So don't leave it running perpetually but monitor it +carefully (for example using the `top` command on Linux or the Task Manager's memory display on +Windows). -Once you have run the server for a while, you need to stop it so the profiler can give its report. Do *not* kill the program from your task manager or by sending it a kill signal - this will most likely also mess with the profiler. Instead either use `evennia.py stop` or (which may be even better), use `@shutdown` from inside the game. +Once you have run the server for a while, you need to stop it so the profiler can give its report. +Do *not* kill the program from your task manager or by sending it a kill signal - this will most +likely also mess with the profiler. Instead either use `evennia.py stop` or (which may be even +better), use `@shutdown` from inside the game. -Once the server has fully shut down (this may be a lot slower than usual) you will find that profiler has created a new file `mygame/server/logs/server.prof`. +Once the server has fully shut down (this may be a lot slower than usual) you will find that +profiler has created a new file `mygame/server/logs/server.prof`. ## Analyzing the profile -The `server.prof` file is a binary file. There are many ways to analyze and display its contents, all of which has only been tested in Linux (If you are a Windows/Mac user, let us know what works). +The `server.prof` file is a binary file. There are many ways to analyze and display its contents, +all of which has only been tested in Linux (If you are a Windows/Mac user, let us know what works). We recommend the -[Runsnake](http://www.vrplumber.com/programming/runsnakerun/) visualizer to see the processor usage of different processes in a graphical form. For more detailed listing of usage time, you can use [KCachegrind](http://kcachegrind.sourceforge.net/html/Home.html). To make KCachegrind work with Python profiles you also need the wrapper script [pyprof2calltree](https://pypi.python.org/pypi/pyprof2calltree/). You can get pyprof2calltree via `pip` whereas KCacheGrind is something you need to get via your package manager or their homepage. +[Runsnake](http://www.vrplumber.com/programming/runsnakerun/) visualizer to see the processor usage +of different processes in a graphical form. For more detailed listing of usage time, you can use +[KCachegrind](http://kcachegrind.sourceforge.net/html/Home.html). To make KCachegrind work with +Python profiles you also need the wrapper script +[pyprof2calltree](https://pypi.python.org/pypi/pyprof2calltree/). You can get pyprof2calltree via +`pip` whereas KCacheGrind is something you need to get via your package manager or their homepage. -How to analyze and interpret profiling data is not a trivial issue and depends on what you are profiling for. Evennia being an asynchronous server can also confuse profiling. Ask on the mailing list if you need help and be ready to be able to supply your `server.prof` file for comparison, along with the exact conditions under which it was obtained. +How to analyze and interpret profiling data is not a trivial issue and depends on what you are +profiling for. Evennia being an asynchronous server can also confuse profiling. Ask on the mailing +list if you need help and be ready to be able to supply your `server.prof` file for comparison, +along with the exact conditions under which it was obtained. ## The Dummyrunner -It is difficult to test "actual" game performance without having players in your game. For this reason Evennia comes with the *Dummyrunner* system. The Dummyrunner is a stress-testing system: a separate program that logs into your game with simulated players (aka "bots" or "dummies"). Once connected these dummies will semi-randomly perform various tasks from a list of possible actions. Use `Ctrl-C` to stop the Dummyrunner. +It is difficult to test "actual" game performance without having players in your game. For this +reason Evennia comes with the *Dummyrunner* system. The Dummyrunner is a stress-testing system: a +separate program that logs into your game with simulated players (aka "bots" or "dummies"). Once +connected these dummies will semi-randomly perform various tasks from a list of possible actions. +Use `Ctrl-C` to stop the Dummyrunner. -> Warning: You should not run the Dummyrunner on a production database. It will spawn many objects and also needs to run with general permissions. +> Warning: You should not run the Dummyrunner on a production database. It will spawn many objects +and also needs to run with general permissions. -To launch the Dummyrunner, first start your server normally (with or without profiling, as above). Then start a new terminal/console window and active your virtualenv there too. In the new terminal, try to connect 10 dummy players: +To launch the Dummyrunner, first start your server normally (with or without profiling, as above). +Then start a new terminal/console window and active your virtualenv there too. In the new terminal, +try to connect 10 dummy players: evennia --dummyrunner 10 -The first time you do this you will most likely get a warning from Dummyrunner. It will tell you to copy an import string to the end of your settings file. Quit the Dummyrunner (`Ctrl-C`) and follow the instructions. Restart Evennia and try `evennia --dummyrunner 10` again. Make sure to remove that extra settings line when running a public server. +The first time you do this you will most likely get a warning from Dummyrunner. It will tell you to +copy an import string to the end of your settings file. Quit the Dummyrunner (`Ctrl-C`) and follow +the instructions. Restart Evennia and try `evennia --dummyrunner 10` again. Make sure to remove that +extra settings line when running a public server. -The actions perform by the dummies is controlled by a settings file. The default Dummyrunner settings file is `evennia/server/server/profiling/dummyrunner_settings.py` but you shouldn't modify this directly. Rather create/copy the default file to `mygame/server/conf/` and modify it there. To make sure to use your file over the default, add the following line to your settings file: +The actions perform by the dummies is controlled by a settings file. The default Dummyrunner +settings file is `evennia/server/server/profiling/dummyrunner_settings.py` but you shouldn't modify +this directly. Rather create/copy the default file to `mygame/server/conf/` and modify it there. To +make sure to use your file over the default, add the following line to your settings file: ```python DUMMYRUNNER_SETTINGS_MODULE = "server/conf/dummyrunner_settings.py" ``` -> Hint: Don't start with too many dummies. The Dummyrunner defaults to taxing the server much more intensely than an equal number of human players. A good dummy number to start with is 10-100. +> Hint: Don't start with too many dummies. The Dummyrunner defaults to taxing the server much more +intensely than an equal number of human players. A good dummy number to start with is 10-100. Once you have the dummyrunner running, stop it with `Ctrl-C`. diff --git a/docs/source/Python-3.md b/docs/source/Python-3.md index 6fcbfd57a4..10cbd03093 100644 --- a/docs/source/Python-3.md +++ b/docs/source/Python-3.md @@ -1,6 +1,7 @@ # Python 3 -> *Note: Evennia only supports Python 2.7+ at this time. This page gathers various development information relevant to server developers.* +> *Note: Evennia only supports Python 2.7+ at this time. This page gathers various development +information relevant to server developers.* Django can work with Python 2 and 3 already, though changes may be required to how the Evennia code uses it. Twisted has much Python 3 compatibility, but not all modules within it have been ported @@ -17,16 +18,20 @@ it still works correctly with Twisted on Python 3. # "Strings" Broadly (and perhaps over-simplified): -* Twisted [expects bytes](http://twistedmatrix.com/trac/wiki/FrequentlyAskedQuestions#WhydontTwistedsnetworkmethodssupportUnicodeobjectsaswellasstrings) -* Django [expects "" to be unicode](https://docs.djangoproject.com/en/1.8/topics/python3/#unicode-literals) +* Twisted [expects bytes](http://twistedmatrix.com/trac/wiki/FrequentlyAskedQuestions#WhydontTwisted +snetworkmethodssupportUnicodeobjectsaswellasstrings) +* Django [expects "" to be unicode](https://docs.djangoproject.com/en/1.8/topics/python3/#unicode- +literals) -I think we should use (roughly speaking) "" for unicode and b"" for bytes everywhere, but I need to look at the impacts of this more closely. +I think we should use (roughly speaking) "" for unicode and b"" for bytes everywhere, but I need to +look at the impacts of this more closely. # Links * http://twistedmatrix.com/documents/current/core/howto/python3.html * https://twistedmatrix.com/trac/wiki/Plan/Python3 -* [Twisted Python3 bugs](https://twistedmatrix.com/trac/query?status=assigned&status=new&status=reopened&group=status&milestone=Python-3.x) +* [Twisted Python3 bugs](https://twistedmatrix.com/trac/query?status=assigned&status=new&status=reop +ened&group=status&milestone=Python-3.x) # Twisted module status diff --git a/docs/source/Python-basic-introduction.md b/docs/source/Python-basic-introduction.md index 1a82f015ae..759aa570d8 100644 --- a/docs/source/Python-basic-introduction.md +++ b/docs/source/Python-basic-introduction.md @@ -1,6 +1,10 @@ # Python basic introduction -This is the first part of our beginner's guide to the basics of using Python with Evennia. It's aimed at you with limited or no programming/Python experience. But also if you are an experienced programmer new to Evennia or Python you might still pick up a thing or two. It is by necessity brief and low on detail. There are countless Python guides and tutorials, books and videos out there for learning more in-depth - use them! +This is the first part of our beginner's guide to the basics of using Python with Evennia. It's +aimed at you with limited or no programming/Python experience. But also if you are an experienced +programmer new to Evennia or Python you might still pick up a thing or two. It is by necessity brief +and low on detail. There are countless Python guides and tutorials, books and videos out there for +learning more in-depth - use them! **Contents:** - [Evennia Hello world](./Python-basic-introduction#evennia-hello-world) @@ -10,13 +14,17 @@ This is the first part of our beginner's guide to the basics of using Python wit - [Looking at the log](./Python-basic-introduction#looking-at-the-log) - (continued in [part 2](./Python-basic-tutorial-part-two)) -This quickstart assumes you have [gotten Evennia started](./Getting-Started). You should make sure that you are able to see the output from the server in the console from which you started it. Log into the game either with a mud client on `localhost:4000` or by pointing a web browser to `localhost:4001/webclient`. Log in as your superuser (the user you created during install). +This quickstart assumes you have [gotten Evennia started](./Getting-Started). You should make sure +that you are able to see the output from the server in the console from which you started it. Log +into the game either with a mud client on `localhost:4000` or by pointing a web browser to +`localhost:4001/webclient`. Log in as your superuser (the user you created during install). Below, lines starting with a single `>` means command input. ### Evennia Hello world -The `py` (or `!` which is an alias) command allows you as a superuser to run raw Python from in-game. From the game's input line, enter the following: +The `py` (or `!` which is an alias) command allows you as a superuser to run raw Python from in- +game. From the game's input line, enter the following: > py print("Hello World!") @@ -25,28 +33,48 @@ You will see > print("Hello world!") Hello World -To understand what is going on: some extra info: The `print(...)` *function* is the basic, in-built way to output text in Python. The quotes `"..."` means you are inputing a *string* (i.e. text). You could also have used single-quotes `'...'`, Python accepts both. +To understand what is going on: some extra info: The `print(...)` *function* is the basic, in-built +way to output text in Python. The quotes `"..."` means you are inputing a *string* (i.e. text). You +could also have used single-quotes `'...'`, Python accepts both. -The first return line (with `>>>`) is just `py` echoing what you input (we won't include that in the examples henceforth). +The first return line (with `>>>`) is just `py` echoing what you input (we won't include that in the +examples henceforth). -> Note: You may sometimes see people/docs refer to `@py` or other commands starting with `@`. Evennia ignores `@` by default, so `@py` is the exact same thing as `py`. +> Note: You may sometimes see people/docs refer to `@py` or other commands starting with `@`. +Evennia ignores `@` by default, so `@py` is the exact same thing as `py`. -The `print` command is a standard Python structure. We can use that here in the `py` command, and it's great for debugging and quick testing. But if you need to send a text to an actual player, `print` won't do, because it doesn't know _who_ to send to. Try this: +The `print` command is a standard Python structure. We can use that here in the `py` command, and +it's great for debugging and quick testing. But if you need to send a text to an actual player, +`print` won't do, because it doesn't know _who_ to send to. Try this: > py me.msg("Hello world!") Hello world! -This looks the same as the `print` result, but we are now actually messaging a specific *object*, `me`. The `me` is something uniquely available in the `py` command (we could also use `self`, it's an alias). It represents "us", the ones calling the `py` command. The `me` is an example of an *Object instance*. Objects are fundamental in Python and Evennia. The `me` object not only represents the character we play in the game, it also contains a lot of useful resources for doing things with that Object. One such resource is `msg`. `msg` works like `print` except it sends the text to the object it is attached to. So if we, for example, had an object `you`, doing `you.msg(...)` would send a message to the object `you`. +This looks the same as the `print` result, but we are now actually messaging a specific *object*, +`me`. The `me` is something uniquely available in the `py` command (we could also use `self`, it's +an alias). It represents "us", the ones calling the `py` command. The `me` is an example of an +*Object instance*. Objects are fundamental in Python and Evennia. The `me` object not only +represents the character we play in the game, it also contains a lot of useful resources for doing +things with that Object. One such resource is `msg`. `msg` works like `print` except it sends the +text to the object it is attached to. So if we, for example, had an object `you`, doing +`you.msg(...)` would send a message to the object `you`. -You access an Object's resources by using the full-stop character `.`. So `self.msg` accesses the `msg` resource and then we call it like we did print, with our "Hello World!" greeting in parentheses. +You access an Object's resources by using the full-stop character `.`. So `self.msg` accesses the +`msg` resource and then we call it like we did print, with our "Hello World!" greeting in +parentheses. -> Important: something like `print(...)` we refer to as a *function*, while `msg(...)` which sits on an object is called a *method*. +> Important: something like `print(...)` we refer to as a *function*, while `msg(...)` which sits on +an object is called a *method*. -For now, `print` and `me.msg` behaves the same, just remember that you're going to mostly be using the latter in the future. Try printing other things. Also try to include `|r` at the start of your string to make the output red in-game. Use `color` to learn more color tags. +For now, `print` and `me.msg` behaves the same, just remember that you're going to mostly be using +the latter in the future. Try printing other things. Also try to include `|r` at the start of your +string to make the output red in-game. Use `color` to learn more color tags. ### Importing modules -Keep your game running, then open a text editor of your choice. If your game folder is called `mygame`, create a new text file `test.py` in the subfolder `mygame/world`. This is how the file structure should look: +Keep your game running, then open a text editor of your choice. If your game folder is called +`mygame`, create a new text file `test.py` in the subfolder `mygame/world`. This is how the file +structure should look: ``` mygame/ @@ -60,26 +88,40 @@ For now, only add one line to `test.py`: print("Hello World!") ``` -Don't forget to save the file. A file with the ending `.py` is referred to as a Python *module*. To use this in-game we have to *import* it. Try this: +Don't forget to save the file. A file with the ending `.py` is referred to as a Python *module*. To +use this in-game we have to *import* it. Try this: ```python > @py import world.test Hello World ``` -If you make some error (we'll cover how to handle errors below) you may need to run the `@reload` command for your changes to take effect. +If you make some error (we'll cover how to handle errors below) you may need to run the `@reload` +command for your changes to take effect. -So importing `world.test` actually means importing `world/test.py`. Think of the period `.` as replacing `/` (or `\` for Windows) in your path. The `.py` ending of `test.py` is also never included in this "Python-path", but _only_ files with that ending can be imported this way. Where is `mygame` in that Python-path? The answer is that Evennia has already told Python that your `mygame` folder is a good place to look for imports. So we don't include `mygame` in the path - Evennia handles this for us. +So importing `world.test` actually means importing `world/test.py`. Think of the period `.` as +replacing `/` (or `\` for Windows) in your path. The `.py` ending of `test.py` is also never +included in this "Python-path", but _only_ files with that ending can be imported this way. Where is +`mygame` in that Python-path? The answer is that Evennia has already told Python that your `mygame` +folder is a good place to look for imports. So we don't include `mygame` in the path - Evennia +handles this for us. -When you import the module, the top "level" of it will execute. In this case, it will immediately print "Hello World". +When you import the module, the top "level" of it will execute. In this case, it will immediately +print "Hello World". -> If you look in the folder you'll also often find new files ending with `.pyc`. These are compiled Python binaries that Python auto-creates when running code. Just ignore them, you should never edit those anyway. +> If you look in the folder you'll also often find new files ending with `.pyc`. These are compiled +Python binaries that Python auto-creates when running code. Just ignore them, you should never edit +those anyway. Now try to run this a second time: ```python > py import world.test ``` -You will *not* see any output this second time or any subsequent times! This is not a bug. Rather it is because Python is being clever - it stores all imported modules and to be efficient it will avoid importing them more than once. So your `print` will only run the first time, when the module is first imported. To see it again you need to `@reload` first, so Python forgets about the module and has to import it again. +You will *not* see any output this second time or any subsequent times! This is not a bug. Rather +it is because Python is being clever - it stores all imported modules and to be efficient it will +avoid importing them more than once. So your `print` will only run the first time, when the module +is first imported. To see it again you need to `@reload` first, so Python forgets about the module +and has to import it again. We'll get back to importing code in the second part of this tutorial. For now, let's press on. @@ -91,8 +133,9 @@ Next, erase the single `print` statement you had in `test.py` and replace it wit me.msg("Hello World!") ``` -As you recall we used this from `py` earlier - it echoed "Hello World!" in-game. -Save your file and `reload` your server - this makes sure Evennia sees the new version of your code. Try to import it from `py` in the same way as earlier: +As you recall we used this from `py` earlier - it echoed "Hello World!" in-game. +Save your file and `reload` your server - this makes sure Evennia sees the new version of your code. +Try to import it from `py` in the same way as earlier: ```python > py import world.test @@ -106,20 +149,33 @@ File "./world/test.py", line 1, in NameError: name 'me' is not defined ``` -This is called a *traceback*. Python's errors are very friendly and will most of the time tell you exactly what and where things are wrong. It's important that you learn to parse tracebacks so you can fix your code. Let's look at this one. A traceback is to be read from the _bottom up_. The last line is the error Python balked at, while the two lines above it details exactly where that error was encountered. +This is called a *traceback*. Python's errors are very friendly and will most of the time tell you +exactly what and where things are wrong. It's important that you learn to parse tracebacks so you +can fix your code. Let's look at this one. A traceback is to be read from the _bottom up_. The last +line is the error Python balked at, while the two lines above it details exactly where that error +was encountered. 1. An error of type `NameError` is the problem ... 2. ... more specifically it is due to the variable `me` not being defined. 3. This happened on the line `me.msg("Hello world!")` ... 4. ... which is on line `1` of the file `./world/test.py`. -In our case the traceback is short. There may be many more lines above it, tracking just how different modules called each other until it got to the faulty line. That can sometimes be useful information, but reading from the bottom is always a good start. +In our case the traceback is short. There may be many more lines above it, tracking just how +different modules called each other until it got to the faulty line. That can sometimes be useful +information, but reading from the bottom is always a good start. -The `NameError` we see here is due to a module being its own isolated thing. It knows nothing about the environment into which it is imported. It knew what `print` is because that is a special [reserved Python keyword](https://docs.python.org/2.5/ref/keywords.html). But `me` is *not* such a reserved word. As far as the module is concerned `me` is just there out of nowhere. Hence the `NameError`. +The `NameError` we see here is due to a module being its own isolated thing. It knows nothing about +the environment into which it is imported. It knew what `print` is because that is a special +[reserved Python keyword](https://docs.python.org/2.5/ref/keywords.html). But `me` is *not* such a +reserved word. As far as the module is concerned `me` is just there out of nowhere. Hence the +`NameError`. ### Our first function -Let's see if we can resolve that `NameError` from the previous section. We know that `me` is defined at the time we use the `@py` command because if we do `py me.msg("Hello World!")` directly in-game it works fine. What if we could *send* that `me` to the `test.py` module so it knows what it is? One way to do this is with a *function*. +Let's see if we can resolve that `NameError` from the previous section. We know that `me` is defined +at the time we use the `@py` command because if we do `py me.msg("Hello World!")` directly in-game +it works fine. What if we could *send* that `me` to the `test.py` module so it knows what it is? One +way to do this is with a *function*. Change your `mygame/world/test.py` file to look like this: @@ -130,44 +186,82 @@ def hello_world(who): Now that we are moving onto multi-line Python code, there are some important things to remember: -- Capitalization matters in Python. It must be `def` and not `DEF`, `who` is not the same as `Who` etc. -- Indentation matters in Python. The second line must be indented or it's not valid code. You should also use a consistent indentation length. We *strongly* recommend that you set up your editor to always indent *4 spaces* (**not** a single tab-character) when you press the TAB key - it will make your life a lot easier. -- `def` is short for "define" and defines a *function* (or a *method*, if sitting on an object). This is a [reserved Python keyword](https://docs.python.org/2.5/ref/keywords.html); try not to use these words anywhere else. -- A function name can not have spaces but otherwise we could have called it almost anything. We call it `hello_world`. Evennia follows [Python's standard naming style](https://github.com/evennia/evennia/blob/master/CODING_STYLE.md#a-quick-list-of-code-style-points) with lowercase letters and underscores. Use this style for now. -- `who` is what we call the *argument* to our function. Arguments are variables we pass to the function. We could have named it anything and we could also have multiple arguments separated by commas. What `who` is depends on what we pass to this function when we *call* it later (hint: we'll pass `me` to it). -- The colon (`:`) at the end of the first line indicates that the header of the function is complete. -- The indentation marks the beginning of the actual operating code of the function (the function's *body*). If we wanted more lines to belong to this function those lines would all have to have to start at this indentation level. -- In the function body we take the `who` argument and treat it as we would have treated `me` earlier - we expect it to have a `.msg` method we can use to send "Hello World" to. +- Capitalization matters in Python. It must be `def` and not `DEF`, `who` is not the same as `Who` +etc. +- Indentation matters in Python. The second line must be indented or it's not valid code. You should +also use a consistent indentation length. We *strongly* recommend that you set up your editor to +always indent *4 spaces* (**not** a single tab-character) when you press the TAB key - it will make +your life a lot easier. +- `def` is short for "define" and defines a *function* (or a *method*, if sitting on an object). +This is a [reserved Python keyword](https://docs.python.org/2.5/ref/keywords.html); try not to use +these words anywhere else. +- A function name can not have spaces but otherwise we could have called it almost anything. We call +it `hello_world`. Evennia follows [Python's standard naming +style](https://github.com/evennia/evennia/blob/master/CODING_STYLE.md#a-quick-list-of-code-style- +points) with lowercase letters and underscores. Use this style for now. +- `who` is what we call the *argument* to our function. Arguments are variables we pass to the +function. We could have named it anything and we could also have multiple arguments separated by +commas. What `who` is depends on what we pass to this function when we *call* it later (hint: we'll +pass `me` to it). +- The colon (`:`) at the end of the first line indicates that the header of the function is +complete. +- The indentation marks the beginning of the actual operating code of the function (the function's +*body*). If we wanted more lines to belong to this function those lines would all have to have to +start at this indentation level. +- In the function body we take the `who` argument and treat it as we would have treated `me` earlier +- we expect it to have a `.msg` method we can use to send "Hello World" to. -First, `reload` your game to make it aware of the updated Python module. Now we have defined our first function, let's use it. +First, `reload` your game to make it aware of the updated Python module. Now we have defined our +first function, let's use it. > reload > py import world.test -Nothing happened! That is because the function in our module won't do anything just by importing it. It will only act when we *call* it. We will need to enter the module we just imported and do so. +Nothing happened! That is because the function in our module won't do anything just by importing it. +It will only act when we *call* it. We will need to enter the module we just imported and do so. > py import world.test ; world.test.hello_world(me) Hello world! There is our "Hello World"! The `;` is the way to put multiple Python-statements on one line. -> Some MUD clients use `;` for their own purposes to separate client-inputs. If so you'll get a `NameError` stating that `world` is not defined. Check so you understand why this is! Change the use of `;` in your client or use the Evennia web client if this is a problem. +> Some MUD clients use `;` for their own purposes to separate client-inputs. If so you'll get a +`NameError` stating that `world` is not defined. Check so you understand why this is! Change the use +of `;` in your client or use the Evennia web client if this is a problem. -In the second statement we access the module path we imported (`world.test`) and reach for the `hello_world` function within. We *call* the function with `me`, which becomes the `who` variable we use inside the `hello_function`. +In the second statement we access the module path we imported (`world.test`) and reach for the +`hello_world` function within. We *call* the function with `me`, which becomes the `who` variable we +use inside the `hello_function`. -> As an exercise, try to pass something else into `hello_world`. Try for example to pass _who_ as the number `5` or the simple string `"foo"`. You'll get errors that they don't have the attribute `msg`. As we've seen, `me` *does* make `msg` available which is why it works (you'll learn more about Objects like `me` in the next part of this tutorial). If you are familiar with other programming languages you may be tempted to start *validating* `who` to make sure it works as expected. This is usually not recommended in Python which suggests it's better to [handle](https://docs.python.org/2/tutorial/errors.html) the error if it happens rather than to make a lot of code to prevent it from happening. See also [duck typing](https://en.wikipedia.org/wiki/Duck_typing). +> As an exercise, try to pass something else into `hello_world`. Try for example to pass _who_ as +the number `5` or the simple string `"foo"`. You'll get errors that they don't have the attribute +`msg`. As we've seen, `me` *does* make `msg` available which is why it works (you'll learn more +about Objects like `me` in the next part of this tutorial). If you are familiar with other +programming languages you may be tempted to start *validating* `who` to make sure it works as +expected. This is usually not recommended in Python which suggests it's better to +[handle](https://docs.python.org/2/tutorial/errors.html) the error if it happens rather than to make +a lot of code to prevent it from happening. See also [duck +typing](https://en.wikipedia.org/wiki/Duck_typing). # Looking at the log -As you start to explore Evennia, it's important that you know where to look when things go wrong. While using the friendly `py` command you'll see errors directly in-game. But if something goes wrong in your code while the game runs, you must know where to find the _log_. +As you start to explore Evennia, it's important that you know where to look when things go wrong. +While using the friendly `py` command you'll see errors directly in-game. But if something goes +wrong in your code while the game runs, you must know where to find the _log_. -Open a terminal (or go back to the terminal you started Evennia in), make sure your `virtualenv` is active and that you are standing in your game directory (the one created with `evennia --init` during installation). Enter +Open a terminal (or go back to the terminal you started Evennia in), make sure your `virtualenv` is +active and that you are standing in your game directory (the one created with `evennia --init` +during installation). Enter ``` evennia --log ``` (or `evennia -l`) -This will show the log. New entries will show up in real time. Whenever you want to leave the log, enter `Ctrl-C` or `Cmd-C` depending on your system. As a game dev it is important to look at the log output when working in Evennia - many errors will only appear with full details here. You may sometimes have to scroll up in the history if you miss it. +This will show the log. New entries will show up in real time. Whenever you want to leave the log, +enter `Ctrl-C` or `Cmd-C` depending on your system. As a game dev it is important to look at the +log output when working in Evennia - many errors will only appear with full details here. You may +sometimes have to scroll up in the history if you miss it. -This tutorial is continued in [Part 2](./Python-basic-tutorial-part-two), where we'll start learning about objects and to explore the Evennia library. +This tutorial is continued in [Part 2](./Python-basic-tutorial-part-two), where we'll start learning +about objects and to explore the Evennia library. diff --git a/docs/source/Python-basic-tutorial-part-two.md b/docs/source/Python-basic-tutorial-part-two.md index 203c01dd65..b1e0820a0d 100644 --- a/docs/source/Python-basic-tutorial-part-two.md +++ b/docs/source/Python-basic-tutorial-part-two.md @@ -1,6 +1,9 @@ # Python basic tutorial part two -[In the first part](./Python-basic-introduction) of this Python-for-Evennia basic tutorial we learned how to run some simple Python code from inside the game. We also made our first new *module* containing a *function* that we called. Now we're going to start exploring the very important subject of *objects*. +[In the first part](./Python-basic-introduction) of this Python-for-Evennia basic tutorial we learned +how to run some simple Python code from inside the game. We also made our first new *module* +containing a *function* that we called. Now we're going to start exploring the very important +subject of *objects*. **Contents:** - [On the subject of objects](./Python-basic-tutorial-part-two#on-the-subject-of-objects) @@ -15,9 +18,11 @@ In the first part of the tutorial we did things like > py me.msg("Hello World!") -To learn about functions and imports we also passed that `me` on to a function `hello_world` in another module. +To learn about functions and imports we also passed that `me` on to a function `hello_world` in +another module. -Let's learn some more about this `me` thing we are passing around all over the place. In the following we assume that we named our superuser Character "Christine". +Let's learn some more about this `me` thing we are passing around all over the place. In the +following we assume that we named our superuser Character "Christine". > py me Christine @@ -31,30 +36,53 @@ These returns look the same at first glance, but not if we examine them more clo > py type(me.key) -> Note: In some MU clients, such as Mudlet and MUSHclient simply returning `type(me)`, you may not see the proper return from the above commands. This is likely due to the HTML-like tags `<...>`, being swallowed by the client. +> Note: In some MU clients, such as Mudlet and MUSHclient simply returning `type(me)`, you may not +see the proper return from the above commands. This is likely due to the HTML-like tags `<...>`, +being swallowed by the client. The `type` function is, like `print`, another in-built function in Python. It tells us that we (`me`) are of the *class* `typeclasses.characters.Character`. Meanwhile `me.key` is a *property* on us, a string. It holds the name of this object. -> When you do `py me`, the `me` is defined in such a way that it will use its `.key` property to represent itself. That is why the result is the same as when doing `py me.key`. Also, remember that as noted in the first part of the tutorial, the `me` is *not* a reserved Python word; it was just defined by the Evennia developers as a convenient short-hand when creating the `py` command. So don't expect `me` to be available elsewhere. +> When you do `py me`, the `me` is defined in such a way that it will use its `.key` property to +represent itself. That is why the result is the same as when doing `py me.key`. Also, remember that +as noted in the first part of the tutorial, the `me` is *not* a reserved Python word; it was just +defined by the Evennia developers as a convenient short-hand when creating the `py` command. So +don't expect `me` to be available elsewhere. -A *class* is like a "factory" or blueprint. From a class you then create individual *instances*. So if class is`Dog`, an instance of `Dog` might be `fido`. Our in-game persona is of a class `Character`. The superuser `christine` is an *instance* of the `Character` class (an instance is also often referred to as an *object*). This is an important concept in *object oriented programming*. You are wise to [familiarize yourself with it](https://en.wikipedia.org/wiki/Class-based_programming) a little. +A *class* is like a "factory" or blueprint. From a class you then create individual *instances*. So +if class is`Dog`, an instance of `Dog` might be `fido`. Our in-game persona is of a class +`Character`. The superuser `christine` is an *instance* of the `Character` class (an instance is +also often referred to as an *object*). This is an important concept in *object oriented +programming*. You are wise to [familiarize yourself with it](https://en.wikipedia.org/wiki/Class- +based_programming) a little. > In other terms: > * class: A description of a thing, all the methods (code) and data (information) > * object: A thing, defined as an *instance* of a class. > -> So in "Fido is a Dog", "Fido" is an object--a unique thing--and "Dog" is a class. Coders would also say, "Fido is an instance of Dog". There can be other dogs too, such as Butch and Fifi. They, too, would be instances of Dog. +> So in "Fido is a Dog", "Fido" is an object--a unique thing--and "Dog" is a class. Coders would +also say, "Fido is an instance of Dog". There can be other dogs too, such as Butch and Fifi. They, +too, would be instances of Dog. > -> As another example: "Christine is a Character", or "Christine is an instance of typeclasses.characters.Character". To start, all characters will be instances of typeclass.characters.Character. +> As another example: "Christine is a Character", or "Christine is an instance of +typeclasses.characters.Character". To start, all characters will be instances of +typeclass.characters.Character. > -> You'll be writing your own class soon! The important thing to know here is how classes and objects relate. +> You'll be writing your own class soon! The important thing to know here is how classes and objects +relate. -The string `'typeclasses.characters.Character'` we got from the `type()` function is not arbitrary. You'll recognize this from when we _imported_ `world.test` in part one. This is a _path_ exactly describing where to find the python code describing this class. Python treats source code files on your hard drive (known as *modules*) as well as folders (known as *packages*) as objects that you access with the `.` operator. It starts looking at a place that Evennia has set up for you - namely the root of your own game directory. +The string `'typeclasses.characters.Character'` we got from the `type()` function is not arbitrary. +You'll recognize this from when we _imported_ `world.test` in part one. This is a _path_ exactly +describing where to find the python code describing this class. Python treats source code files on +your hard drive (known as *modules*) as well as folders (known as *packages*) as objects that you +access with the `.` operator. It starts looking at a place that Evennia has set up for you - namely +the root of your own game directory. -Open and look at your game folder (named `mygame` if you exactly followed the Getting Started instructions) in a file editor or in a new terminal/console. Locate the file `mygame/typeclasses/characters.py` +Open and look at your game folder (named `mygame` if you exactly followed the Getting Started +instructions) in a file editor or in a new terminal/console. Locate the file +`mygame/typeclasses/characters.py` ``` mygame/ @@ -62,7 +90,9 @@ mygame/ characters.py ``` -This represents the first part of the python path - `typeclasses.characters` (the `.py` file ending is never included in the python path). The last bit, `.Character` is the actual class name inside the `characters.py` module. Open that file in a text editor and you will see something like this: +This represents the first part of the python path - `typeclasses.characters` (the `.py` file ending +is never included in the python path). The last bit, `.Character` is the actual class name inside +the `characters.py` module. Open that file in a text editor and you will see something like this: ```python """ @@ -79,9 +109,18 @@ class Character(DefaultCharacter): ``` -There is `Character`, the last part of the path. Note how empty this file is. At first glance one would think a Character had no functionality at all. But from what we have used already we know it has at least the `key` property and the method `msg`! Where is the code? The answer is that this 'emptiness' is an illusion caused by something called *inheritance*. Read on. +There is `Character`, the last part of the path. Note how empty this file is. At first glance one +would think a Character had no functionality at all. But from what we have used already we know it +has at least the `key` property and the method `msg`! Where is the code? The answer is that this +'emptiness' is an illusion caused by something called *inheritance*. Read on. -Firstly, in the same way as the little `hello.py` we did in the first part of the tutorial, this is an example of full, multi-line Python code. Those triple-quoted strings are used for strings that have line breaks in them. When they appear on their own like this, at the top of a python module, class or similar they are called *doc strings*. Doc strings are read by Python and is used for producing online help about the function/method/class/module. By contrast, a line starting with `#` is a *comment*. It is ignored completely by Python and is only useful to help guide a human to understand the code. +Firstly, in the same way as the little `hello.py` we did in the first part of the tutorial, this is +an example of full, multi-line Python code. Those triple-quoted strings are used for strings that +have line breaks in them. When they appear on their own like this, at the top of a python module, +class or similar they are called *doc strings*. Doc strings are read by Python and is used for +producing online help about the function/method/class/module. By contrast, a line starting with `#` +is a *comment*. It is ignored completely by Python and is only useful to help guide a human to +understand the code. The line @@ -89,21 +128,35 @@ The line class Character(DefaultCharacter): ``` -means that the class `Character` is a *child* of the class `DefaultCharacter`. This is called *inheritance* and is another fundamental concept. The answer to the question "where is the code?" is that the code is *inherited* from its parent, `DefaultCharacter`. And that in turn may inherit code from *its* parent(s) and so on. Since our child, `Character` is empty, its functionality is *exactly identical* to that of its parent. The moment we add new things to Character, these will take precedence. And if we add something that already existed in the parent, our child-version will *override* the version in the parent. This is very practical: It means that we can let the parent do the heavy lifting and only tweak the things we want to change. It also means that we could easily have many different Character classes, all inheriting from `DefaultCharacter` but changing different things. And those can in turn also have children ... +means that the class `Character` is a *child* of the class `DefaultCharacter`. This is called +*inheritance* and is another fundamental concept. The answer to the question "where is the code?" is +that the code is *inherited* from its parent, `DefaultCharacter`. And that in turn may inherit code +from *its* parent(s) and so on. Since our child, `Character` is empty, its functionality is *exactly +identical* to that of its parent. The moment we add new things to Character, these will take +precedence. And if we add something that already existed in the parent, our child-version will +*override* the version in the parent. This is very practical: It means that we can let the parent do +the heavy lifting and only tweak the things we want to change. It also means that we could easily +have many different Character classes, all inheriting from `DefaultCharacter` but changing different +things. And those can in turn also have children ... Let's go on an expedition up the inheritance tree. ### Exploring the Evennia library -Let's figure out how to tweak `Character`. Right now we don't know much about `DefaultCharacter` though. Without knowing that we won't know what to override. At the top of the file you find +Let's figure out how to tweak `Character`. Right now we don't know much about `DefaultCharacter` +though. Without knowing that we won't know what to override. At the top of the file you find ```python from evennia import DefaultCharacter ``` -This is an `import` statement again, but on a different form to what we've seen before. `from ... import ...` is very commonly used and allows you to precisely dip into a module to extract just the component you need to use. In this case we head into the `evennia` package to get `DefaultCharacter`. +This is an `import` statement again, but on a different form to what we've seen before. `from ... +import ...` is very commonly used and allows you to precisely dip into a module to extract just the +component you need to use. In this case we head into the `evennia` package to get +`DefaultCharacter`. -Where is `evennia`? To find it you need to go to the `evennia` folder (repository) you originally cloned from us. If you open it, this is how it looks: +Where is `evennia`? To find it you need to go to the `evennia` folder (repository) you originally +cloned from us. If you open it, this is how it looks: ``` evennia/ @@ -114,24 +167,48 @@ evennia/ evennia/ ... ``` -There are lots of things in there. There are some docs but most of those have to do with the distribution of Evennia and does not concern us right now. The `evennia` subfolder is what we are looking for. *This* is what you are accessing when you do `from evennia import ...`. It's set up by Evennia as a good place to find modules when the server starts. The exact layout of the Evennia library [is covered by our directory overview](./Directory-Overview#evennia-library-layout). You can also explore it [online on github](https://github.com/evennia/evennia/tree/master/evennia). +There are lots of things in there. There are some docs but most of those have to do with the +distribution of Evennia and does not concern us right now. The `evennia` subfolder is what we are +looking for. *This* is what you are accessing when you do `from evennia import ...`. It's set up by +Evennia as a good place to find modules when the server starts. The exact layout of the Evennia +library [is covered by our directory overview](./Directory-Overview#evennia-library-layout). You can +also explore it [online on github](https://github.com/evennia/evennia/tree/master/evennia). The structure of the library directly reflects how you import from it. -- To, for example, import [the text justify function](https://github.com/evennia/evennia/blob/master/evennia/utils/utils.py#L201) from `evennia/utils/utils.py` you would do `from evennia.utils.utils import justify`. In your code you could then just call `justify(...)` to access its functionality. -- You could also do `from evennia.utils import utils`. In code you would then have to write `utils.justify(...)`. This is practical if want a lot of stuff from that `utils.py` module and don't want to import each component separately. -- You could also do `import evennia`. You would then have to enter the full `evennia.utils.utils.justify(...)` every time you use it. Using `from` to only import the things you need is usually easier and more readable. -- See [this overview](http://effbot.org/zone/import-confusion.htm) about the different ways to import in Python. +- To, for example, import [the text justify +function](https://github.com/evennia/evennia/blob/master/evennia/utils/utils.py#L201) from +`evennia/utils/utils.py` you would do `from evennia.utils.utils import justify`. In your code you +could then just call `justify(...)` to access its functionality. +- You could also do `from evennia.utils import utils`. In code you would then have to write +`utils.justify(...)`. This is practical if want a lot of stuff from that `utils.py` module and don't +want to import each component separately. +- You could also do `import evennia`. You would then have to enter the full +`evennia.utils.utils.justify(...)` every time you use it. Using `from` to only import the things you +need is usually easier and more readable. +- See [this overview](http://effbot.org/zone/import-confusion.htm) about the different ways to +import in Python. -Now, remember that our `characters.py` module did `from evennia import DefaultCharacter`. But if we look at the contents of the `evennia` folder, there is no `DefaultCharacter` anywhere! This is because Evennia gives a large number of optional "shortcuts", known as [the "flat" API](./Evennia-API). The intention is to make it easier to remember where to find stuff. The flat API is defined in that weirdly named `__init__.py` file. This file just basically imports useful things from all over Evennia so you can more easily find them in one place. +Now, remember that our `characters.py` module did `from evennia import DefaultCharacter`. But if we +look at the contents of the `evennia` folder, there is no `DefaultCharacter` anywhere! This is +because Evennia gives a large number of optional "shortcuts", known as [the "flat" API](Evennia- +API). The intention is to make it easier to remember where to find stuff. The flat API is defined in +that weirdly named `__init__.py` file. This file just basically imports useful things from all over +Evennia so you can more easily find them in one place. -We could [just look at the documenation](github:evennia#typeclasses) to find out where we can look at our `DefaultCharacter` parent. But for practice, let's figure it out. Here is where `DefaultCharacter` [is imported from](https://github.com/evennia/evennia/blob/master/evennia/__init__.py#L188) inside `__init__.py`: +We could [just look at the documenation](github:evennia#typeclasses) to find out where we can look +at our `DefaultCharacter` parent. But for practice, let's figure it out. Here is where +`DefaultCharacter` [is imported +from](https://github.com/evennia/evennia/blob/master/evennia/__init__.py#L188) inside `__init__.py`: ```python from .objects.objects import DefaultCharacter ``` -The period at the start means that it imports beginning from the same location this module sits(i.e. the `evennia` folder). The full python-path accessible from the outside is thus `evennia.objects.objects.DefaultCharacter`. So to import this into our game it'd be perfectly valid to do +The period at the start means that it imports beginning from the same location this module sits(i.e. +the `evennia` folder). The full python-path accessible from the outside is thus +`evennia.objects.objects.DefaultCharacter`. So to import this into our game it'd be perfectly valid +to do ```python from evennia.objects.objects import DefaultCharacter @@ -154,7 +231,8 @@ is the same thing, just a little easier to remember. In the previous section we traced the parent of our `Character` class to be `DefaultCharacter` in -[evennia/objects/objects.py](https://github.com/evennia/evennia/blob/master/evennia/objects/objects.py). +[evennia/objects/objects.py](https://github.com/evennia/evennia/blob/master/evennia/objects/objects. +py). Open that file and locate the `DefaultCharacter` class. It's quite a bit down in this module so you might want to search using your editor's (or browser's) search function. Once you find it, you'll find that the class starts like this: @@ -177,7 +255,8 @@ class DefaultCharacter(DefaultObject): """ super().basetype_setup() self.locks.add(";".join(["get:false()", # noone can pick up the character - "call:false()"])) # no commands can be called on character from outside + "call:false()"])) # no commands can be called on character from +outside # add the default cmdset self.cmdset.add_default(settings.CMDSET_CHARACTER, permanent=True) @@ -197,14 +276,29 @@ class DefaultCharacter(DefaultObject): ``` -... And so on (you can see the full [class online here](https://github.com/evennia/evennia/blob/master/evennia/objects/objects.py#L1915)). Here we have functional code! These methods may not be directly visible in `Character` back in our game dir, but they are still available since `Character` is a child of `DefaultCharacter` above. Here is a brief summary of the methods we find in `DefaultCharacter` (follow in the code to see if you can see roughly where things happen):: +... And so on (you can see the full [class online +here](https://github.com/evennia/evennia/blob/master/evennia/objects/objects.py#L1915)). Here we +have functional code! These methods may not be directly visible in `Character` back in our game dir, +but they are still available since `Character` is a child of `DefaultCharacter` above. Here is a +brief summary of the methods we find in `DefaultCharacter` (follow in the code to see if you can see +roughly where things happen):: -- `basetype_setup` is called by Evennia only once, when a Character is first created. In the `DefaultCharacter` class it sets some particular [Locks](./Locks) so that people can't pick up and puppet Characters just like that. It also adds the [Character Cmdset](./Command-Sets) so that Characters always can accept command-input (this should usually not be modified - the normal hook to override is `at_object_creation`, which is called after `basetype_setup` (it's in the parent)). -- `at_after_move` makes it so that every time the Character moves, the `look` command is automatically fired (this would not make sense for just any regular Object). -- `at_pre_puppet` is called when an Account begins to puppet this Character. When not puppeted, the Character is hidden away to a `None` location. This brings it back to the location it was in before. Without this, "headless" Characters would remain in the game world just standing around. -- `at_post_puppet` is called when puppeting is complete. It echoes a message to the room that his Character has now connected. -- `at_post_unpuppet` is called once stopping puppeting of the Character. This hides away the Character to a `None` location again. -- There are also some utility properties which makes it easier to get some time stamps from the Character. +- `basetype_setup` is called by Evennia only once, when a Character is first created. In the +`DefaultCharacter` class it sets some particular [Locks](./Locks) so that people can't pick up and +puppet Characters just like that. It also adds the [Character Cmdset](./Command-Sets) so that +Characters always can accept command-input (this should usually not be modified - the normal hook to +override is `at_object_creation`, which is called after `basetype_setup` (it's in the parent)). +- `at_after_move` makes it so that every time the Character moves, the `look` command is +automatically fired (this would not make sense for just any regular Object). +- `at_pre_puppet` is called when an Account begins to puppet this Character. When not puppeted, the +Character is hidden away to a `None` location. This brings it back to the location it was in before. +Without this, "headless" Characters would remain in the game world just standing around. +- `at_post_puppet` is called when puppeting is complete. It echoes a message to the room that his +Character has now connected. +- `at_post_unpuppet` is called once stopping puppeting of the Character. This hides away the +Character to a `None` location again. +- There are also some utility properties which makes it easier to get some time stamps from the +Character. Reading the class we notice another thing: @@ -213,24 +307,48 @@ class DefaultCharacter(DefaultObject): # ... ``` -This means that `DefaultCharacter` is in *itself* a child of something called `DefaultObject`! Let's see what this parent class provides. It's in the same module as `DefaultCharacter`, you just need to [scroll up near the top](https://github.com/evennia/evennia/blob/master/evennia/objects/objects.py#L182): +This means that `DefaultCharacter` is in *itself* a child of something called `DefaultObject`! Let's +see what this parent class provides. It's in the same module as `DefaultCharacter`, you just need to +[scroll up near the +top](https://github.com/evennia/evennia/blob/master/evennia/objects/objects.py#L182): ```python class DefaultObject(with_metaclass(TypeclassBase, ObjectDB)): # ... ``` -This is a really big class where the bulk of code defining an in-game object resides. It consists of a large number of methods, all of which thus also becomes available on the `DefaultCharacter` class below *and* by extension in your `Character` class over in your game dir. In this class you can for example find the `msg` method we have been using before. +This is a really big class where the bulk of code defining an in-game object resides. It consists of +a large number of methods, all of which thus also becomes available on the `DefaultCharacter` class +below *and* by extension in your `Character` class over in your game dir. In this class you can for +example find the `msg` method we have been using before. -> You should probably not expect to understand all details yet, but as an exercise, find and read the doc string of `msg`. +> You should probably not expect to understand all details yet, but as an exercise, find and read +the doc string of `msg`. -> As seen, `DefaultObject` actually has multiple parents. In one of those the basic `key` property is defined, but we won't travel further up the inheritance tree in this tutorial. If you are interested to see them, you can find `TypeclassBase` in [evennia/typeclasses/models.py](https://github.com/evennia/evennia/blob/master/evennia/typeclasses/models.py#L93) and `ObjectDB` in [evennia/objects/models.py](https://github.com/evennia/evennia/blob/master/evennia/objects/models.py#L121). We will also not go into the details of [Multiple Inheritance](https://docs.python.org/2/tutorial/classes.html#multiple-inheritance) or [Metaclasses](http://www.onlamp.com/pub/a/python/2003/04/17/metaclasses.html) here. The general rule is that if you realize that you need these features, you already know enough to use them. +> As seen, `DefaultObject` actually has multiple parents. In one of those the basic `key` property +is defined, but we won't travel further up the inheritance tree in this tutorial. If you are +interested to see them, you can find `TypeclassBase` in [evennia/typeclasses/models.py](https://gith +ub.com/evennia/evennia/blob/master/evennia/typeclasses/models.py#L93) and `ObjectDB` in [evennia/obj +ects/models.py](https://github.com/evennia/evennia/blob/master/evennia/objects/models.py#L121). We +will also not go into the details of [Multiple +Inheritance](https://docs.python.org/2/tutorial/classes.html#multiple-inheritance) or +[Metaclasses](http://www.onlamp.com/pub/a/python/2003/04/17/metaclasses.html) here. The general rule +is that if you realize that you need these features, you already know enough to use them. -Remember the `at_pre_puppet` method we looked at in `DefaultCharacter`? If you look at the `at_pre_puppet` hook as defined in `DefaultObject` you'll find it to be completely empty (just a `pass`). So if you puppet a regular object it won't be hiding/retrieving the object when you unpuppet it. The `DefaultCharacter` class *overrides* its parent's functionality with a version of its own. And since it's `DefaultCharacter` that our `Character` class inherits back in our game dir, it's *that* version of `at_pre_puppet` we'll get. Anything not explicitly overridden will be passed down as-is. +Remember the `at_pre_puppet` method we looked at in `DefaultCharacter`? If you look at the +`at_pre_puppet` hook as defined in `DefaultObject` you'll find it to be completely empty (just a +`pass`). So if you puppet a regular object it won't be hiding/retrieving the object when you +unpuppet it. The `DefaultCharacter` class *overrides* its parent's functionality with a version of +its own. And since it's `DefaultCharacter` that our `Character` class inherits back in our game dir, +it's *that* version of `at_pre_puppet` we'll get. Anything not explicitly overridden will be passed +down as-is. -While it's useful to read the code, we should never actually modify anything inside the `evennia` folder. Only time you would want that is if you are planning to release a bug fix or new feature for Evennia itself. Instead you *override* the default functionality inside your game dir. +While it's useful to read the code, we should never actually modify anything inside the `evennia` +folder. Only time you would want that is if you are planning to release a bug fix or new feature for +Evennia itself. Instead you *override* the default functionality inside your game dir. -So to conclude our little foray into classes, objects and inheritance, locate the simple little `at_before_say` method in the `DefaultObject` class: +So to conclude our little foray into classes, objects and inheritance, locate the simple little +`at_before_say` method in the `DefaultObject` class: ```python def at_before_say(self, message, **kwargs): @@ -240,24 +358,37 @@ So to conclude our little foray into classes, objects and inheritance, locate th return message ``` -If you read the doc string you'll find that this can be used to modify the output of `say` before it goes out. You can think of it like this: Evennia knows the name of this method, and when someone speaks, Evennia will make sure to redirect the outgoing message through this method. It makes it ripe for us to replace with a version of our own. +If you read the doc string you'll find that this can be used to modify the output of `say` before it +goes out. You can think of it like this: Evennia knows the name of this method, and when someone +speaks, Evennia will make sure to redirect the outgoing message through this method. It makes it +ripe for us to replace with a version of our own. -> In the Evennia documentation you may sometimes see the term *hook* used for a method explicitly meant to be overridden like this. +> In the Evennia documentation you may sometimes see the term *hook* used for a method explicitly +meant to be overridden like this. -As you can see, the first argument to `at_before_say` is `self`. In Python, the first argument of a method is *always a back-reference to the object instance on which the method is defined*. By convention this argument is always called `self` but it could in principle be named anything. The `self` is very useful. If you wanted to, say, send a message to the same object from inside `at_before_say`, you would do `self.msg(...)`. +As you can see, the first argument to `at_before_say` is `self`. In Python, the first argument of a +method is *always a back-reference to the object instance on which the method is defined*. By +convention this argument is always called `self` but it could in principle be named anything. The +`self` is very useful. If you wanted to, say, send a message to the same object from inside +`at_before_say`, you would do `self.msg(...)`. What can trip up newcomers is that you *don't* include `self` when you *call* the method. Try: > @py me.at_before_say("Hello World!") Hello World! -Note that we don't send `self` but only the `message` argument. Python will automatically add `self` for us. In this case, `self` will become equal to the Character instance `me`. +Note that we don't send `self` but only the `message` argument. Python will automatically add `self` +for us. In this case, `self` will become equal to the Character instance `me`. -By default the `at_before_say` method doesn't do anything. It just takes the `message` input and `return`s it just the way it was (the `return` is another reserved Python word). +By default the `at_before_say` method doesn't do anything. It just takes the `message` input and +`return`s it just the way it was (the `return` is another reserved Python word). -> We won't go into `**kwargs` here, but it (and its sibling `*args`) is also important to understand, extra reading is [here for `**kwargs`](https://stackoverflow.com/questions/1769403/understanding-kwargs-in-python). +> We won't go into `**kwargs` here, but it (and its sibling `*args`) is also important to +understand, extra reading is [here for +`**kwargs`](https://stackoverflow.com/questions/1769403/understanding-kwargs-in-python). -Now, open your game folder and edit `mygame/typeclasses/characters.py`. Locate your `Character` class and modify it as such: +Now, open your game folder and edit `mygame/typeclasses/characters.py`. Locate your `Character` +class and modify it as such: ```python class Character(DefaultCharacter): @@ -269,11 +400,21 @@ class Character(DefaultCharacter): return f"{message} ..." ``` -So we add our own version of `at_before_say`, duplicating the `def` line from the parent but putting new code in it. All we do in this tutorial is to add an ellipsis (`...`) to the message as it passes through the method. +So we add our own version of `at_before_say`, duplicating the `def` line from the parent but putting +new code in it. All we do in this tutorial is to add an ellipsis (`...`) to the message as it passes +through the method. -Note that `f` in front of the string, it means we turned the string into a 'formatted string'. We can now easily inject stuff directly into the string by wrapping them in curly brackets `{ }`. In this example, we put the incoming `message` into the string, followed by an ellipsis. This is only one way to format a string. Python has very powerful [string formatting](https://docs.python.org/2/library/string.html#format-specification-mini-language) and you are wise to learn it well, considering your game will be mainly text-based. +Note that `f` in front of the string, it means we turned the string into a 'formatted string'. We +can now easily inject stuff directly into the string by wrapping them in curly brackets `{ }`. In +this example, we put the incoming `message` into the string, followed by an ellipsis. This is only +one way to format a string. Python has very powerful [string +formatting](https://docs.python.org/2/library/string.html#format-specification-mini-language) and +you are wise to learn it well, considering your game will be mainly text-based. -> You could also copy & paste the relevant method from `DefaultObject` here to get the full doc string. For more complex methods, or if you only want to change some small part of the default behavior, copy & pasting will eliminate the need to constantly look up the original method and keep you sane. +> You could also copy & paste the relevant method from `DefaultObject` here to get the full doc +string. For more complex methods, or if you only want to change some small part of the default +behavior, copy & pasting will eliminate the need to constantly look up the original method and keep +you sane. In-game, now try @@ -281,23 +422,35 @@ In-game, now try > say Hello You say, "Hello ..." -An ellipsis `...` is added to what you said! This is a silly example but you have just made your first code change to core functionality - without touching any of Evennia's original code! We just plugged in our own version of the `at_before_say` method and it replaced the default one. Evennia happily redirected the message through our version and we got a different output. +An ellipsis `...` is added to what you said! This is a silly example but you have just made your +first code change to core functionality - without touching any of Evennia's original code! We just +plugged in our own version of the `at_before_say` method and it replaced the default one. Evennia +happily redirected the message through our version and we got a different output. -> For sane overriding of parent methods you should also be aware of Python's [super](https://docs.python.org/3/library/functions.html#super), which allows you to call the methods defined on a parent in your child class. +> For sane overriding of parent methods you should also be aware of Python's +[super](https://docs.python.org/3/library/functions.html#super), which allows you to call the +methods defined on a parent in your child class. ### The Evennia shell -Now on to some generally useful tools as you continue learning Python and Evennia. We have so far explored using `py` and have inserted Python code directly in-game. We have also modified Evennia's behavior by overriding default functionality with our own. There is a third way to conveniently explore Evennia and Python - the Evennia shell. +Now on to some generally useful tools as you continue learning Python and Evennia. We have so far +explored using `py` and have inserted Python code directly in-game. We have also modified Evennia's +behavior by overriding default functionality with our own. There is a third way to conveniently +explore Evennia and Python - the Evennia shell. -Outside of your game, `cd` to your mygame folder and make sure any needed virtualenv is running. Next: +Outside of your game, `cd` to your mygame folder and make sure any needed virtualenv is running. +Next: > pip install ipython # only needed once -The [`IPython`](https://en.wikipedia.org/wiki/IPython) program is just a nicer interface to the Python interpreter - you only need to install it once, after which Evennia will use it automatically. +The [`IPython`](https://en.wikipedia.org/wiki/IPython) program is just a nicer interface to the +Python interpreter - you only need to install it once, after which Evennia will use it +automatically. > evennia shell -If you did this call from your game dir you will now be in a Python prompt managed by the IPython program. +If you did this call from your game dir you will now be in a Python prompt managed by the IPython +program. IPython ... ... @@ -307,26 +460,46 @@ IPython has some very nice ways to explore what Evennia has to offer. > import evennia > evennia. -That is, write `evennia.` and press the Tab key. You will be presented with a list of all available resources in the Evennia Flat API. We looked at the `__init__.py` file in the `evennia` folder earlier, so some of what you see should be familiar. From the IPython prompt, do: +That is, write `evennia.` and press the Tab key. You will be presented with a list of all available +resources in the Evennia Flat API. We looked at the `__init__.py` file in the `evennia` folder +earlier, so some of what you see should be familiar. From the IPython prompt, do: > from evennia import DefaultCharacter > DefaultCharacter.at_before_say? -Don't forget that you can use `` to auto-complete code as you write. Appending a single `?` to the end will show you the doc-string for `at_before_say` we looked at earlier. Use `??` to get the whole source code. +Don't forget that you can use `` to auto-complete code as you write. Appending a single `?` to +the end will show you the doc-string for `at_before_say` we looked at earlier. Use `??` to get the +whole source code. -Let's look at our over-ridden version instead. Since we started the `evennia shell` from our game dir we can easily get to our code too: +Let's look at our over-ridden version instead. Since we started the `evennia shell` from our game +dir we can easily get to our code too: > from typeclasses.characters import Character > Character.at_before_say?? -This will show us the changed code we just did. Having a window with IPython running is very convenient for quickly exploring code without having to go digging through the file structure! +This will show us the changed code we just did. Having a window with IPython running is very +convenient for quickly exploring code without having to go digging through the file structure! ### Where to go from here -This should give you a running start using Python with Evennia. If you are completely new to programming or Python you might want to look at a more formal Python tutorial. You can find links and resources [on our link page](./Links). +This should give you a running start using Python with Evennia. If you are completely new to +programming or Python you might want to look at a more formal Python tutorial. You can find links +and resources [on our link page](./Links). -We have touched upon many of the concepts here but to use Evennia and to be able to follow along in the code, you will need basic understanding of Python [modules](http://docs.python.org/2/tutorial/modules.html), [variables](http://www.tutorialspoint.com/python/python_variable_types.htm), [conditional statements](http://docs.python.org/tutorial/controlflow.html#if-statements), [loops](http://docs.python.org/tutorial/controlflow.html#for-statements), [functions](http://docs.python.org/tutorial/controlflow.html#defining-functions), [lists, dictionaries, list comprehensions](http://docs.python.org/tutorial/datastructures.html) and [string formatting](http://docs.python.org/tutorial/introduction.html#strings). You should also have a basic understanding of [object-oriented programming](http://www.tutorialspoint.com/python/python_classes_objects.htm) and what Python [Classes](http://docs.python.org/tutorial/classes.html) are. +We have touched upon many of the concepts here but to use Evennia and to be able to follow along in +the code, you will need basic understanding of Python +[modules](http://docs.python.org/2/tutorial/modules.html), +[variables](http://www.tutorialspoint.com/python/python_variable_types.htm), [conditional +statements](http://docs.python.org/tutorial/controlflow.html#if-statements), +[loops](http://docs.python.org/tutorial/controlflow.html#for-statements), +[functions](http://docs.python.org/tutorial/controlflow.html#defining-functions), [lists, +dictionaries, list comprehensions](http://docs.python.org/tutorial/datastructures.html) and [string +formatting](http://docs.python.org/tutorial/introduction.html#strings). You should also have a basic +understanding of [object-oriented +programming](http://www.tutorialspoint.com/python/python_classes_objects.htm) and what Python +[Classes](http://docs.python.org/tutorial/classes.html) are. -Once you have familiarized yourself, or if you prefer to pick Python up as you go, continue to one of the beginning-level [Evennia tutorials](./Tutorials) to gradually build up your understanding. +Once you have familiarized yourself, or if you prefer to pick Python up as you go, continue to one +of the beginning-level [Evennia tutorials](./Tutorials) to gradually build up your understanding. Good luck! diff --git a/docs/source/Quirks.md b/docs/source/Quirks.md index db4645fff5..bb7ec033ca 100644 --- a/docs/source/Quirks.md +++ b/docs/source/Quirks.md @@ -1,38 +1,56 @@ # Quirks -This is a list of various quirks or common stumbling blocks that people often ask about or report when using (or trying to use) Evennia. They are not bugs. +This is a list of various quirks or common stumbling blocks that people often ask about or report +when using (or trying to use) Evennia. They are not bugs. ### Forgetting to use @reload to see changes to your typeclasses -Firstly: Reloading the server is a safe and usually quick operation which will *not* disconnect any accounts. +Firstly: Reloading the server is a safe and usually quick operation which will *not* disconnect any +accounts. -New users tend to forget this step. When editing source code (such as when tweaking typeclasses and commands or adding new commands to command sets) you need to either use the in-game `@reload` command or, from the command line do `python evennia.py reload` before you see your changes. +New users tend to forget this step. When editing source code (such as when tweaking typeclasses and +commands or adding new commands to command sets) you need to either use the in-game `@reload` +command or, from the command line do `python evennia.py reload` before you see your changes. ### Web admin to create new Account -If you use the default login system and are trying to use the Web admin to create a new Player account, you need to consider which `MULTIACCOUNT_MODE` you are in. If you are in `MULTIACCOUNT_MODE` `0` or `1`, the login system expects each Account to also have a Character object named the same as the Account - there is no character creation screen by default. If using the normal mud login screen, a Character with the same name is automatically created and connected to your Account. From the web interface you must do this manually. +If you use the default login system and are trying to use the Web admin to create a new Player +account, you need to consider which `MULTIACCOUNT_MODE` you are in. If you are in +`MULTIACCOUNT_MODE` `0` or `1`, the login system expects each Account to also have a Character +object named the same as the Account - there is no character creation screen by default. If using +the normal mud login screen, a Character with the same name is automatically created and connected +to your Account. From the web interface you must do this manually. -So, when creating the Account, make sure to also create the Character *from the same form* as you create the Account from. This should set everything up for you. Otherwise you need to manually set the "account" property on the Character and the "character" property on the Account to point to each other. You must also set the lockstring of the Character to allow the Account to "puppet" this particular character. +So, when creating the Account, make sure to also create the Character *from the same form* as you +create the Account from. This should set everything up for you. Otherwise you need to manually set +the "account" property on the Character and the "character" property on the Account to point to each +other. You must also set the lockstring of the Character to allow the Account to "puppet" this +particular character. ### Mutable attributes and their connection to the database When storing a mutable object (usually a list or a dictionary) in an Attribute ```python - object.db.mylist = [1,2,3] + object.db.mylist = [1,2,3] ``` -you should know that the connection to the database is retained also if you later extract that Attribute into another variable (what is stored and retrieved is actually a `PackedList` or a `PackedDict` that works just like their namesakes except they save themselves to the database when changed). So if you do +you should know that the connection to the database is retained also if you later extract that +Attribute into another variable (what is stored and retrieved is actually a `PackedList` or a +`PackedDict` that works just like their namesakes except they save themselves to the database when +changed). So if you do ```python alist = object.db.mylist alist.append(4) ``` -this updates the database behind the scenes, so both `alist` and `object.db.mylist` are now `[1,2,3,4]` +this updates the database behind the scenes, so both `alist` and `object.db.mylist` are now +`[1,2,3,4]` -If you don't want this, Evennia provides a way to stably disconnect the mutable from the database by use of `evennia.utils.dbserialize.deserialize`: +If you don't want this, Evennia provides a way to stably disconnect the mutable from the database by +use of `evennia.utils.dbserialize.deserialize`: ```python from evennia.utils.dbserialize import deserialize @@ -41,29 +59,59 @@ If you don't want this, Evennia provides a way to stably disconnect the mutable blist.append(4) ``` -The property `blist` is now `[1,2,3,4]` whereas `object.db.mylist` remains unchanged. If you want to update the database you'd need to explicitly re-assign the updated data to the `mylist` Attribute. +The property `blist` is now `[1,2,3,4]` whereas `object.db.mylist` remains unchanged. If you want to +update the database you'd need to explicitly re-assign the updated data to the `mylist` Attribute. ### Commands are matched by name *or* alias -When merging [command sets](./Commands) it's important to remember that command objects are identified *both* by key *or* alias. So if you have a command with a key `look` and an alias `ls`, introducing another command with a key `ls` will be assumed by the system to be *identical* to the first one. This usually means merging cmdsets will overload one of them depending on priority. Whereas this is logical once you know how command objects are handled, it may be confusing if you are just looking at the command strings thinking they are parsed as-is. +When merging [command sets](./Commands) it's important to remember that command objects are identified +*both* by key *or* alias. So if you have a command with a key `look` and an alias `ls`, introducing +another command with a key `ls` will be assumed by the system to be *identical* to the first one. +This usually means merging cmdsets will overload one of them depending on priority. Whereas this is +logical once you know how command objects are handled, it may be confusing if you are just looking +at the command strings thinking they are parsed as-is. ### Objects turning to `DefaultObject` -A common confusing error for new developers is finding that one or more objects in-game are suddenly of the type `DefaultObject` rather than the typeclass you wanted it to be. This happens when you introduce a critical Syntax error to the module holding your custom class. Since such a module is not valid Python, Evennia can't load it at all to get to the typeclasses within. To keep on running, Evennia will solve this by printing the full traceback to the terminal/console and temporarily fall back to the safe `DefaultObject` until you fix the problem and reload. Most errors of this kind will be caught by any good text editors. Keep an eye on the terminal/console during a reload to catch such errors - you may have to scroll up if your window is small. +A common confusing error for new developers is finding that one or more objects in-game are suddenly +of the type `DefaultObject` rather than the typeclass you wanted it to be. This happens when you +introduce a critical Syntax error to the module holding your custom class. Since such a module is +not valid Python, Evennia can't load it at all to get to the typeclasses within. To keep on running, +Evennia will solve this by printing the full traceback to the terminal/console and temporarily fall +back to the safe `DefaultObject` until you fix the problem and reload. Most errors of this kind will +be caught by any good text editors. Keep an eye on the terminal/console during a reload to catch +such errors - you may have to scroll up if your window is small. ### Overriding of magic methods -Python implements a system of [magic methods](https://docs.python.org/3/reference/datamodel.html#emulating-container-types), usually prefixed and suffixed by double-underscores (`__example__`) that allow object instances to have certain operations performed on them without needing to do things like turn them into strings or numbers first-- for example, is `obj1` greater than or equal to `obj2`? +Python implements a system of [magic +methods](https://docs.python.org/3/reference/datamodel.html#emulating-container-types), usually +prefixed and suffixed by double-underscores (`__example__`) that allow object instances to have +certain operations performed on them without needing to do things like turn them into strings or +numbers first-- for example, is `obj1` greater than or equal to `obj2`? -Neither object is a number, but given `obj1.size == "small"` and `obj2.size == "large"`, how might one compare these two arbitrary English adjective strings to figure out which is greater than the other? By defining the `__ge__` (greater than or equal to) magic method on the object class in which you figure out which word has greater significance, perhaps through use of a mapping table (`{'small':0, 'large':10}`) or other lookup and comparing the numeric values of each. +Neither object is a number, but given `obj1.size == "small"` and `obj2.size == "large"`, how might +one compare these two arbitrary English adjective strings to figure out which is greater than the +other? By defining the `__ge__` (greater than or equal to) magic method on the object class in which +you figure out which word has greater significance, perhaps through use of a mapping table +(`{'small':0, 'large':10}`) or other lookup and comparing the numeric values of each. -Evennia extensively makes use of magic methods on typeclasses to do things like initialize objects, check object existence or iterate over objects in an inventory or container. If you override or interfere with the return values from the methods Evennia expects to be both present and working, it can result in very inconsistent and hard-to-diagnose errors. +Evennia extensively makes use of magic methods on typeclasses to do things like initialize objects, +check object existence or iterate over objects in an inventory or container. If you override or +interfere with the return values from the methods Evennia expects to be both present and working, it +can result in very inconsistent and hard-to-diagnose errors. -The moral of the story-- it can be dangerous to tinker with magic methods on typeclassed objects. Try to avoid doing so. +The moral of the story-- it can be dangerous to tinker with magic methods on typeclassed objects. +Try to avoid doing so. ### Known upstream bugs -- There is currently (Autumn 2017) a bug in the `zope.interface` installer on some Linux Ubuntu distributions (notably Ubuntu 16.04 LTS). Zope is a dependency of Twisted. The error manifests in the server not starting with an error that `zope.interface` is not found even though `pip list` shows it's installed. The reason is a missing empty `__init__.py` file at the root of the zope package. If the virtualenv is named "evenv" as suggested in the [Getting Started](./Getting-Started) instructions, use the following command to fix it: +- There is currently (Autumn 2017) a bug in the `zope.interface` installer on some Linux Ubuntu +distributions (notably Ubuntu 16.04 LTS). Zope is a dependency of Twisted. The error manifests in +the server not starting with an error that `zope.interface` is not found even though `pip list` +shows it's installed. The reason is a missing empty `__init__.py` file at the root of the zope +package. If the virtualenv is named "evenv" as suggested in the [Getting Started](./Getting-Started) +instructions, use the following command to fix it: ```shell touch evenv/local/lib/python2.7/site-packages/zope/__init__.py diff --git a/docs/source/RSS.md b/docs/source/RSS.md index 52827653b2..1c5fe07bb7 100644 --- a/docs/source/RSS.md +++ b/docs/source/RSS.md @@ -1,19 +1,27 @@ # RSS -[RSS](http://en.wikipedia.org/wiki/RSS) is a format for easily tracking updates on websites. The principle is simple - whenever a site is updated, a small text file is updated. An RSS reader can then regularly go online, check this file for updates and let the user know what's new. +[RSS](http://en.wikipedia.org/wiki/RSS) is a format for easily tracking updates on websites. The +principle is simple - whenever a site is updated, a small text file is updated. An RSS reader can +then regularly go online, check this file for updates and let the user know what's new. -Evennia allows for connecting any number of RSS feeds to any number of in-game channels. Updates to the feed will be conveniently echoed to the channel. There are many potential uses for this: For example the MUD might use a separate website to host its forums. Through RSS, the players can then be notified when new posts are made. Another example is to let everyone know you updated your dev blog. Admins might also want to track the latest Evennia updates through our own RSS feed [here](http://code.google.com/feeds/p/evennia/updates/basic). +Evennia allows for connecting any number of RSS feeds to any number of in-game channels. Updates to +the feed will be conveniently echoed to the channel. There are many potential uses for this: For +example the MUD might use a separate website to host its forums. Through RSS, the players can then +be notified when new posts are made. Another example is to let everyone know you updated your dev +blog. Admins might also want to track the latest Evennia updates through our own RSS feed +[here](http://code.google.com/feeds/p/evennia/updates/basic). ## Configuring RSS -To use RSS, you first need to install the [feedparser](http://code.google.com/p/feedparser/) python module. +To use RSS, you first need to install the [feedparser](http://code.google.com/p/feedparser/) python +module. pip install feedparser -Next you activate RSS support in your config file by settting `RSS_ENABLED=True`. +Next you activate RSS support in your config file by settting `RSS_ENABLED=True`. -Start/reload Evennia as a privileged user. You should now have a new command available, `@rss2chan`: +Start/reload Evennia as a privileged user. You should now have a new command available, `@rss2chan`: @rss2chan = @@ -23,12 +31,17 @@ You can connect RSS to any Evennia channel, but for testing, let's set up a new @ccreate rss = RSS feeds are echoed to this channel! -Let's connect Evennia's code-update feed to this channel. The RSS url for evennia updates is `https://github.com/evennia/evennia/commits/master.atom`, so let's add that: +Let's connect Evennia's code-update feed to this channel. The RSS url for evennia updates is +`https://github.com/evennia/evennia/commits/master.atom`, so let's add that: @rss2chan rss = https://github.com/evennia/evennia/commits/master.atom -That's it, really. New Evennia updates will now show up as a one-line title and link in the channel. Give the `@rss2chan` command on its own to show all connections. To remove a feed from a channel, you specify the connection again (use the command to see it in the list) but add the `/delete` switch: +That's it, really. New Evennia updates will now show up as a one-line title and link in the channel. +Give the `@rss2chan` command on its own to show all connections. To remove a feed from a channel, +you specify the connection again (use the command to see it in the list) but add the `/delete` +switch: @rss2chan/delete rss = https://github.com/evennia/evennia/commits/master.atom -You can connect any number of RSS feeds to a channel this way. You could also connect them to the same channels as [IRC](./IRC) to have the feed echo to external chat channels as well. +You can connect any number of RSS feeds to a channel this way. You could also connect them to the +same channels as [IRC](./IRC) to have the feed echo to external chat channels as well. diff --git a/docs/source/Roadmap.md b/docs/source/Roadmap.md index 2e11984310..5dde75a599 100644 --- a/docs/source/Roadmap.md +++ b/docs/source/Roadmap.md @@ -1,4 +1,5 @@ # Roadmap -*As of Autumn 2016, Evennia's development roadmap is tracked through the [Evennia Projects Page](https://github.com/evennia/evennia/projects).* \ No newline at end of file +*As of Autumn 2016, Evennia's development roadmap is tracked through the [Evennia Projects +Page](https://github.com/evennia/evennia/projects).* \ No newline at end of file diff --git a/docs/source/Running-Evennia-in-Docker.md b/docs/source/Running-Evennia-in-Docker.md index 9dd6032f70..1e1a69bb20 100644 --- a/docs/source/Running-Evennia-in-Docker.md +++ b/docs/source/Running-Evennia-in-Docker.md @@ -1,74 +1,131 @@ # Running Evennia in Docker -Evennia has an [official docker image](https://hub.docker.com/r/evennia/evennia/) which makes running an Evennia-based game in a Docker container easy. +Evennia has an [official docker image](https://hub.docker.com/r/evennia/evennia/) which makes +running an Evennia-based game in a Docker container easy. ## Install Evennia through docker -First, install the `docker` program so you can run the Evennia container. You can get it freely from [docker.com](https://www.docker.com/). Linux users can likely also get it through their normal package manager. +First, install the `docker` program so you can run the Evennia container. You can get it freely from +[docker.com](https://www.docker.com/). Linux users can likely also get it through their normal +package manager. -To fetch the latest evennia docker image, run: +To fetch the latest evennia docker image, run: docker pull evennia/evennia -This is a good command to know, it is also how you update to the latest version when we make updates in the future. This tracks the `master` branch of Evennia. +This is a good command to know, it is also how you update to the latest version when we make updates +in the future. This tracks the `master` branch of Evennia. -> Note: If you want to experiment with the (unstable) `develop` branch, use `docker pull evennia/evennia:develop`. +> Note: If you want to experiment with the (unstable) `develop` branch, use `docker pull +evennia/evennia:develop`. -Next `cd` to a place where your game dir is, or where you want to create it. Then run: +Next `cd` to a place where your game dir is, or where you want to create it. Then run: - docker run -it --rm -p 4000:4000 -p 4001:4001 -p 4002:4002 --rm -v $PWD:/usr/src/game --user $UID:$GID evennia/evennia + docker run -it --rm -p 4000:4000 -p 4001:4001 -p 4002:4002 --rm -v $PWD:/usr/src/game --user +$UID:$GID evennia/evennia -Having run this (see next section for a description of what's what), you will be at a prompt inside the docker container: +Having run this (see next section for a description of what's what), you will be at a prompt inside +the docker container: ```bash evennia|docker /usr/src/game $ ``` -This is a normal shell prompt. We are in the `/usr/src/game` location inside the docker container. If you had anything in the folder you started from, you should see it here (with `ls`) since we mounted the current directory to `usr/src/game` (with `-v` above). You have the `evennia` command available and can now proceed to create a new game as per the [Getting Started](./Getting-Started) instructions (you can skip the virtualenv and install 'globally' in the container though). +This is a normal shell prompt. We are in the `/usr/src/game` location inside the docker container. +If you had anything in the folder you started from, you should see it here (with `ls`) since we +mounted the current directory to `/usr/src/game` (with `-v` above). You have the `evennia` command +available and can now proceed to create a new game as per the [Getting Started](./Getting-Started) +instructions (you can skip the virtualenv and install 'globally' in the container though). -You can run Evennia from inside this container if you want to, it's like you are root in a little isolated Linux environment. To exit the container and all processes in there, press `Ctrl-D`. If you created a new game folder, you will find that it has appeared on-disk. +You can run Evennia from inside this container if you want to, it's like you are root in a little +isolated Linux environment. To exit the container and all processes in there, press `Ctrl-D`. If you +created a new game folder, you will find that it has appeared on-disk. -> The game folder or any new files that you created from inside the container will appear as owned by `root`. If you want to edit the files outside of the container you should change the ownership. On Linux/Mac you do this with `sudo chown myname:myname -R mygame`, where you replace `myname` with your username and `mygame` with whatever your game folder is named. +> The game folder or any new files that you created from inside the container will appear as owned +by `root`. If you want to edit the files outside of the container you should change the ownership. +On Linux/Mac you do this with `sudo chown myname:myname -R mygame`, where you replace `myname` with +your username and `mygame` with whatever your game folder is named. ### Description of the `docker run` command ```bash - docker run -it --rm -p 4000:4000 -p 4001:4001 -p 4002:4002 --rm -v $PWD:/usr/src/game --user $UID:$GID evennia/evennia + docker run -it --rm -p 4000:4000 -p 4001:4001 -p 4002:4002 --rm -v $PWD:/usr/src/game --user +$UID:$GID evennia/evennia ``` -This is what it does: +This is what it does: -- `docker run ... evennia/evennia` tells us that we want to run a new container based on the `evennia/evennia` docker image. Everything in between are options for this. The `evennia/evennia` is the name of our [official docker image on the dockerhub repository](https://hub.docker.com/r/evennia/evennia/). If you didn't do `docker pull evennia/evennia` first, the image will be downloaded when running this, otherwise your already downloaded version will be used. It contains everything needed to run Evennia. +- `docker run ... evennia/evennia` tells us that we want to run a new container based on the +`evennia/evennia` docker image. Everything in between are options for this. The `evennia/evennia` is +the name of our [official docker image on the dockerhub +repository](https://hub.docker.com/r/evennia/evennia/). If you didn't do `docker pull +evennia/evennia` first, the image will be downloaded when running this, otherwise your already +downloaded version will be used. It contains everything needed to run Evennia. - `-it` has to do with creating an interactive session inside the container we start. -- `--rm` will make sure to delete the container when it shuts down. This is nice to keep things tidy on your drive. -- `-p 4000:4000 -p 4001:4001 -p 4002:4002` means that we *map* ports `4000`, `4001` and `4002` from inside the docker container to same-numbered ports on our host machine. These are ports for telnet, webserver and websockets. This is what allows your Evennia server to be accessed from outside the container (such as by your MUD client)! -- `-v $PWD:/usr/src/game` mounts the current directory (*outside* the container) to the path `/usr/src/game` *inside* the container. This means that when you edit that path in the container you will actually be modifying the "real" place on your hard drive. If you didn't do this, any changes would only exist inside the container and be gone if we create a new one. Note that in linux a shortcut for the current directory is `$PWD`. If you don't have this for your OS, you can replace it with the full path to the current on-disk directory (like `C:/Development/evennia/game` or wherever you want your evennia files to appear). -- `--user $UID:$GID` ensures the container's modifications to `$PWD` are done with you user and group IDs instead of root's IDs (root is the user running evennia inside the container). This avoids having stale `.pid` files in your filesystem between container reboots which you have to force delete with `sudo rm server/*.pid` before each boot. +- `--rm` will make sure to delete the container when it shuts down. This is nice to keep things tidy +on your drive. +- `-p 4000:4000 -p 4001:4001 -p 4002:4002` means that we *map* ports `4000`, `4001` and `4002` from +inside the docker container to same-numbered ports on our host machine. These are ports for telnet, +webserver and websockets. This is what allows your Evennia server to be accessed from outside the +container (such as by your MUD client)! +- `-v $PWD:/usr/src/game` mounts the current directory (*outside* the container) to the path +`/usr/src/game` *inside* the container. This means that when you edit that path in the container you +will actually be modifying the "real" place on your hard drive. If you didn't do this, any changes +would only exist inside the container and be gone if we create a new one. Note that in linux a +shortcut for the current directory is `$PWD`. If you don't have this for your OS, you can replace it +with the full path to the current on-disk directory (like `C:/Development/evennia/game` or wherever +you want your evennia files to appear). +- `--user $UID:$GID` ensures the container's modifications to `$PWD` are done with you user and +group IDs instead of root's IDs (root is the user running evennia inside the container). This avoids +having stale `.pid` files in your filesystem between container reboots which you have to force +delete with `sudo rm server/*.pid` before each boot. ## Running your game as a docker image -If you run the `docker` command given in the previous section from your game dir you can then easily start Evennia and have a running server without any further fuss. +If you run the `docker` command given in the previous section from your game dir you can then +easily start Evennia and have a running server without any further fuss. -But apart from ease of install, the primary benefit to running an Evennia-based game in a container is to simplify its deployment into a public production environment. Most cloud-based hosting providers these days support the ability to run container-based applications. This makes deploying or updating your game as simple as building a new container image locally, pushing it to your Docker Hub account, and then pulling from Docker Hub into your AWS/Azure/other docker-enabled hosting account. The container eliminates the need to install Python, set up a virtualenv, or run pip to install dependencies. +But apart from ease of install, the primary benefit to running an Evennia-based game in a container +is to simplify its deployment into a public production environment. Most cloud-based hosting +providers these days support the ability to run container-based applications. This makes deploying +or updating your game as simple as building a new container image locally, pushing it to your Docker +Hub account, and then pulling from Docker Hub into your AWS/Azure/other docker-enabled hosting +account. The container eliminates the need to install Python, set up a virtualenv, or run pip to +install dependencies. ### Start Evennia and run through docker -For remote or automated deployment you may want to start Evennia immediately as soon as the docker container comes up. If you already have a game folder with a database set up you can also start the docker container and pass commands directly to it. The command you pass will be the main process to run in the container. From your game dir, run for example this command: +For remote or automated deployment you may want to start Evennia immediately as soon as the docker +container comes up. If you already have a game folder with a database set up you can also start the +docker container and pass commands directly to it. The command you pass will be the main process to +run in the container. From your game dir, run for example this command: - docker run -it --rm -p 4000:4000 -p 4001:4001 -p 4002:4002 --rm -v $PWD:/usr/src/game evennia/evennia evennia start -l + docker run -it --rm -p 4000:4000 -p 4001:4001 -p 4002:4002 --rm -v $PWD:/usr/src/game +evennia/evennia evennia start --log -This will start Evennia as the foreground process, echoing the log to the terminal. Closing the terminal will kill the server. Note that you *must* use a foreground command like `evennia start -l` or `evennia ipstart` to start the server - otherwise the foreground process will finish immediately and the container go down. -### Create your own game image +This will start Evennia as the foreground process, echoing the log to the terminal. Closing the +terminal will kill the server. Note that you *must* use a foreground command like `evennia start +--log` or `evennia ipstart` to start the server - otherwise the foreground process will finish +immediately and the container go down. -These steps assume that you have created or otherwise obtained a game directory already. First, `cd` to your game dir and create a new empty text file named `Dockerfile`. Save the following two lines into it: +### Create your own game image + +You may want to create your own image in order to bake in your gamedir directly into the docker +container for easy upload and deployment. +These steps assume that you have created or otherwise obtained a game directory already. First, `cd` +to your game dir and create a new empty text file named `Dockerfile`. Save the following two lines +into it: ``` FROM evennia/evennia:latest -ENTRYPOINT evennia start -l +ENTRYPOINT evennia start --log ``` -These are instructions for building a new docker image. This one is based on the official `evennia/evennia` image, but also makes sure to start evennia when it runs (so we don't need to enter it and run commands). +These are instructions for building a new docker image. This one is based on the official +`evennia/evennia` image. We add the second line to +make make sure evennia starts immediately along with the container (so we don't need to enter it and +run commands). To build the image: @@ -76,31 +133,50 @@ To build the image: docker build -t mydhaccount/mygame . ``` -(don't forget the period at the end, it will use the `Dockerfile` from the current location). Here `mydhaccount` is the name of your `dockerhub` account. If you don't have a dockerhub account you can build the image locally only (name the container whatever you like in that case, like just `mygame`). +(don't forget the period `.` at the end, it tells docker to use use the `Dockerfile` from the +current location). Here `mydhaccount` is the name of your `dockerhub` account. If you don't have a +dockerhub account you can build the image locally only (name the container whatever you like in that +case, like just `mygame`). -Docker images are stored centrally on your computer. You can see which ones you have available locally with `docker images`. Once built, you have a couple of options to run your game. +Docker images are stored centrally on your computer. You can see which ones you have available +locally with `docker images`. Once built, you have a couple of options to run your game. + +If you have a docker-hub account, you can push your (new or updated) image there: + +```bash + docker push myhdaccount/mygame +``` ### Run container from your game image for development -To run the container based on your game image locally for development, mount the local game directory as before: +To run the container based on your game image locally for development, mount the local game +directory as before: ``` -docker run -it --rm -p 4000:4000 -p 4001:4001 -p 4002:4002 -v $PWD:/usr/src/game --user $UID:$GID mydhaccount/mygame +docker run -it --rm -p 4000:4000 -p 4001:4001 -p 4002:4002 -v $PWD:/usr/src/game --user $UID:$GID +mydhaccount/mygame ``` -Evennia will start and you'll get output in the terminal, perfect for development. You should be able to connect to the game with your clients normally. +Evennia will start and you'll get output in the terminal, perfect for development. You should be +able to connect to the game with your clients normally. ### Deploy game image for production -Each time you rebuild the docker image as per the above instructions, the latest copy of your game directory is actually copied inside the image (at `/usr/src/game/`). If you don't mount your on-disk folder there, the internal one will be used. So for deploying evennia on a server, omit the `-v` option and just give the following command: +Each time you rebuild the docker image as per the above instructions, the latest copy of your game +directory is actually copied inside the image (at `/usr/src/game/`). If you don't mount your on-disk +folder there, the internal one will be used. So for deploying evennia on a server, omit the `-v` +option and just give the following command: ``` docker run -it --rm -d -p 4000:4000 -p 4001:4001 -p 4002:4002 --user $UID:$GID mydhaccount/mygame ``` -Your game will be downloaded from your docker-hub account and a new container will be built using the image and started on the server! If your server environment forces you to use different ports, you can just map the normal ports differently in the command above. +Your game will be downloaded from your docker-hub account and a new container will be built using +the image and started on the server! If your server environment forces you to use different ports, +you can just map the normal ports differently in the command above. -Above we added the `-d` option, which starts the container in *daemon* mode - you won't see any return in the console. You can see it running with `docker ps`: +Above we added the `-d` option, which starts the container in *daemon* mode - you won't see any +return in the console. You can see it running with `docker ps`: ```bash $ docker ps @@ -112,58 +188,77 @@ f6d4ca9b2b22 mygame "/bin/sh -c 'evenn..." About a minute ago ... Note the container ID, this is how you manage the container as it runs. ``` - docker logs f6d4ca9b2b22 + docker logs f6d4ca9b2b22 ``` Looks at the STDOUT output of the container (i.e. the normal server log) ``` - docker logs -f f6d4ca9b2b22 + docker logs -f f6d4ca9b2b22 ``` Tail the log (so it updates to your screen 'live'). ``` - docker pause f6d4ca9b2b22 + docker pause f6d4ca9b2b22 ``` -Suspend the state of the container. +Suspend the state of the container. ``` - docker unpause f6d4ca9b2b22 + docker unpause f6d4ca9b2b22 ``` Un-suspend it again after a pause. It will pick up exactly where it were. ``` - docker stop f6d4ca9b2b22 + docker stop f6d4ca9b2b22 ``` -Stop the container. To get it up again you need to use `docker run`, specifying ports etc. A new container will get a new container id to reference. +Stop the container. To get it up again you need to use `docker run`, specifying ports etc. A new +container will get a new container id to reference. ## How it Works -The `evennia/evennia` docker image holds the evennia library and all of its dependencies. It also has an `ONBUILD` directive which is triggered during builds of images derived from it. This `ONBUILD` directive handles setting up a volume and copying your game directory code into the proper location within the container. +The `evennia/evennia` docker image holds the evennia library and all of its dependencies. It also +has an `ONBUILD` directive which is triggered during builds of images derived from it. This +`ONBUILD` directive handles setting up a volume and copying your game directory code into the proper +location within the container. -In most cases, the Dockerfile for an Evennia-based game will only need the `FROM evennia/evennia:latest` directive, and optionally a `MAINTAINER` directive if you plan to publish your image on Docker Hub and would like to provide contact info. +In most cases, the Dockerfile for an Evennia-based game will only need the `FROM +evennia/evennia:latest` directive, and optionally a `MAINTAINER` directive if you plan to publish +your image on Docker Hub and would like to provide contact info. -For more information on Dockerfile directives, see the [Dockerfile Reference](https://docs.docker.com/engine/reference/builder/). +For more information on Dockerfile directives, see the [Dockerfile +Reference](https://docs.docker.com/engine/reference/builder/). -For more information on volumes and Docker containers, see the Docker site's [Manage data in containers](https://docs.docker.com/engine/tutorials/dockervolumes/) page. +For more information on volumes and Docker containers, see the Docker site's [Manage data in +containers](https://docs.docker.com/engine/tutorials/dockervolumes/) page. ### What if I Don't Want "LATEST"? -A new `evennia/evennia` image is built automatically whenever there is a new commit to the `master` branch of Evennia. It is possible to create your own custom evennia base docker image based on any arbitrary commit. +A new `evennia/evennia` image is built automatically whenever there is a new commit to the `master` +branch of Evennia. It is possible to create your own custom evennia base docker image based on any +arbitrary commit. -1. Use git tools to checkout the commit that you want to base your image upon. (In the example below, we're checking out commit a8oc3d5b.) +1. Use git tools to checkout the commit that you want to base your image upon. (In the example +below, we're checking out commit a8oc3d5b.) ``` -git checkout -b my-stable-branch a8oc3d5b +git checkout -b my-stable-branch a8oc3d5b ``` -2. Change your working directory to the `evennia` directory containing `Dockerfile`. Note that `Dockerfile` has changed over time, so if you are going far back in the commit history you might want to bring a copy of the latest `Dockerfile` with you and use that instead of whatever version was used at the time. -3. Use the `docker build` command to build the image based off of the currently checked out commit. The example below assumes your docker account is **mydhaccount**. +2. Change your working directory to the `evennia` directory containing `Dockerfile`. Note that +`Dockerfile` has changed over time, so if you are going far back in the commit history you might +want to bring a copy of the latest `Dockerfile` with you and use that instead of whatever version +was used at the time. +3. Use the `docker build` command to build the image based off of the currently checked out commit. +The example below assumes your docker account is **mydhaccount**. ``` docker build -t mydhaccount/evennia . ``` -4. Now you have a base evennia docker image built off of a specific commit. To use this image to build your game, you would modify **FROM** directive in the **Dockerfile** for your game directory to be: +4. Now you have a base evennia docker image built off of a specific commit. To use this image to +build your game, you would modify **FROM** directive in the **Dockerfile** for your game directory +to be: ``` FROM mydhacct/evennia:latest -``` +``` -Note: From this point, you can also use the `docker tag` command to set a specific tag on your image and/or upload it into Docker Hub under your account. +Note: From this point, you can also use the `docker tag` command to set a specific tag on your image +and/or upload it into Docker Hub under your account. -5. At this point, build your game using the same `docker build` command as usual. Change your working directory to be your game directory and run +5. At this point, build your game using the same `docker build` command as usual. Change your +working directory to be your game directory and run ``` docker build -t mydhaccountt/mygame . @@ -171,7 +266,10 @@ docker build -t mydhaccountt/mygame . ## Additional Creature Comforts -The Docker ecosystem includes a tool called `docker-compose`, which can orchestrate complex multi-container applications, or in our case, store the default port and terminal parameters that we want specified every time we run our container. A sample `docker-compose.yml` file to run a containerized Evennia game in development might look like this: +The Docker ecosystem includes a tool called `docker-compose`, which can orchestrate complex multi- +container applications, or in our case, store the default port and terminal parameters that we want +specified every time we run our container. A sample `docker-compose.yml` file to run a containerized +Evennia game in development might look like this: ``` version: '2' @@ -183,13 +281,19 @@ services: ports: - "4001-4002:4001-4002" - "4000:4000" - volumes: + volumes: - .:/usr/src/game ``` -With this file in the game directory next to the `Dockerfile`, starting the container is as simple as +With this file in the game directory next to the `Dockerfile`, starting the container is as simple +as ``` docker-compose up ``` -For more information about `docker-compose`, see [Getting Started with docker-compose](https://docs.docker.com/compose/gettingstarted/). +For more information about `docker-compose`, see [Getting Started with docker- +compose](https://docs.docker.com/compose/gettingstarted/). -> Note that with this setup you lose the `--user $UID` option. The problem is that the variable `UID` is not available inside the configuration file `docker-compose.yml`. A workaround is to hardcode your user and group id. In a terminal run `echo $UID:$GID` and if for example you get `1000:1000` you can add to `docker-compose.yml` a line `user: 1000:1000` just below the `image: ...` line. +> Note that with this setup you lose the `--user $UID` option. The problem is that the variable +`UID` is not available inside the configuration file `docker-compose.yml`. A workaround is to +hardcode your user and group id. In a terminal run `echo $UID:$GID` and if for example you get +`1000:1000` you can add to `docker-compose.yml` a line `user: 1000:1000` just below the `image: ...` +line. diff --git a/docs/source/Screenshot.md b/docs/source/Screenshot.md index 17100b5b6d..71352aac94 100644 --- a/docs/source/Screenshot.md +++ b/docs/source/Screenshot.md @@ -1,13 +1,20 @@ # Screenshot -![evennia_screenshot2017](https://user-images.githubusercontent.com/294267/30773728-ea45afb6-a076-11e7-8820-49be2168a6b8.png) +![evennia_screenshot2017](https://user- +images.githubusercontent.com/294267/30773728-ea45afb6-a076-11e7-8820-49be2168a6b8.png) *(right-click and choose your browser's equivalent of "view image" to see it full size)* -This screenshot shows a vanilla [install](./Getting-Started) of the just started Evennia MUD server. In the bottom window we can see the log messages from the running server. +This screenshot shows a vanilla [install](./Getting-Started) of the just started Evennia MUD server. +In the bottom window we can see the log messages from the running server. -In the top left window we see the default website of our new game displayed in a web browser (it has shrunk to accomodate the smaller screen). Evennia contains its own webserver to serve this page. The default site shows some brief info about the database. From here you can also reach Django's *admin interface* for editing the database online. +In the top left window we see the default website of our new game displayed in a web browser (it has +shrunk to accomodate the smaller screen). Evennia contains its own webserver to serve this page. The +default site shows some brief info about the database. From here you can also reach Django's *admin +interface* for editing the database online. -To the upper right is the included web-browser client showing a connection to the server on port 4001. This allows users to access the game without downloading a mud client separately. +To the upper right is the included web-browser client showing a connection to the server on port +4001. This allows users to access the game without downloading a mud client separately. -Bottom right we see a login into the stock game using a third-party MUD client ([Mudlet](http://www.mudlet.org)). This connects to the server via the telnet protocol on port 4000. +Bottom right we see a login into the stock game using a third-party MUD client +([Mudlet](http://www.mudlet.org)). This connects to the server via the telnet protocol on port 4000. diff --git a/docs/source/Scripts.md b/docs/source/Scripts.md index 93353158fd..28082cb68e 100644 --- a/docs/source/Scripts.md +++ b/docs/source/Scripts.md @@ -5,7 +5,7 @@ [Objects](./Objects). Scripts are so flexible that the "Script" is a bit limiting - we had to pick something to name them after all. Other possible names (depending on what you'd use them for) would be `OOBObjects`, -`StorageContainers` or `TimerObjects`. +`StorageContainers` or `TimerObjects`. Scripts can be used for many different things in Evennia: @@ -15,23 +15,23 @@ Scripts can be used for many different things in Evennia: they can also have no time dependence at all. Note though that if all you want is just to have an object method called repeatedly, you should consider using the [TickerHandler](./TickerHandler) which is more limited but is specialized on - just this task. + just this task. - They can describe State changes. A Script is an excellent platform for hosting a persistent, but unique system handler. For example, a Script could be used as the base to track the state of a turn-based combat system. Since Scripts can also operate on a timer they can also update themselves regularly -to perform various actions. -- They can act as data stores for storing game data persistently in the database -(thanks to its ability to have [Attributes](./Attributes)). -- They can be used as OOC stores for sharing data between groups of objects, for +to perform various actions. +- They can act as data stores for storing game data persistently in the database +(thanks to its ability to have [Attributes](./Attributes)). +- They can be used as OOC stores for sharing data between groups of objects, for example for tracking the turns in a turn-based combat system or barter exchange. -Scripts are [Typeclassed](./Typeclasses) entities and are manipulated in a similar -way to how it works for other such Evennia entities: +Scripts are [Typeclassed](./Typeclasses) entities and are manipulated in a similar +way to how it works for other such Evennia entities: ```python -# create a new script -new_script = evennia.create_script(key="myscript", typeclass=...) +# create a new script +new_script = evennia.create_script(key="myscript", typeclass=...) # search (this is always a list, also if there is only one match) list_of_myscript = evennia.search_script("myscript") @@ -41,7 +41,7 @@ list_of_myscript = evennia.search_script("myscript") ## Defining new Scripts A Script is defined as a class and is created in the same way as other -[typeclassed](./Typeclasses) entities. The class has several properties +[typeclassed](./Typeclasses) entities. The class has several properties to control the timer-component of the scripts. These are all _optional_ - leaving them out will just create a Script with no timer components (useful to act as a database store or to hold a persistent game system, for example). @@ -60,21 +60,24 @@ class MyScript(DefaultScript): self.interval = 60 # 1 min repeat def at_repeat(self): - # do stuff every minute + # do stuff every minute ``` -In `mygame/typeclasses/scripts.py` is the `Script` class which inherits from `DefaultScript` already. This is provided as your own base class to do with what you like: You can tweak `Script` if you want to change the default behavior and it is usually convenient to inherit from this instead. Here's an example: +In `mygame/typeclasses/scripts.py` is the `Script` class which inherits from `DefaultScript` +already. This is provided as your own base class to do with what you like: You can tweak `Script` if +you want to change the default behavior and it is usually convenient to inherit from this instead. +Here's an example: ```python - # for example in mygame/typeclasses/scripts.py + # for example in mygame/typeclasses/scripts.py # Script class is defined at the top of this module import random - class Weather(Script): + class Weather(Script): """ - A timer script that displays weather info. Meant to - be attached to a room. + A timer script that displays weather info. Meant to + be attached to a room. """ def at_script_creation(self): @@ -84,12 +87,12 @@ In `mygame/typeclasses/scripts.py` is the `Script` class which inherits from `De self.persistent = True # will survive reload def at_repeat(self): - "called every self.interval seconds." + "called every self.interval seconds." rand = random.random() if rand < 0.5: weather = "A faint breeze is felt." elif rand < 0.7: - weather = "Clouds sweep across the sky." + weather = "Clouds sweep across the sky." else: weather = "There is a light drizzle of rain." # send this message to everyone inside the object this @@ -97,7 +100,7 @@ In `mygame/typeclasses/scripts.py` is the `Script` class which inherits from `De self.obj.msg_contents(weather) ``` -If we put this script on a room, it will randomly report some weather +If we put this script on a room, it will randomly report some weather to everyone in the room every 5 minutes. To activate it, just add it to the script handler (`scripts`) on an @@ -108,10 +111,19 @@ put it on a room called `myroom`: myroom.scripts.add(scripts.Weather) ``` -> Note that `typeclasses` in your game dir is added to the setting `TYPECLASS_PATHS`. +> Note that `typeclasses` in your game dir is added to the setting `TYPECLASS_PATHS`. > Therefore we don't need to give the full path (`typeclasses.scripts.Weather` > but only `scripts.Weather` above. +If you wanted to stop and delete that script on the [Room](./Objects). You could do that +with the script handler by passing the `delete` method with the script key (`self.key`) as: + +``` + myroom.scripts.delete('weather_script') +``` + +> Note that If no key is given, this will delete *all* scripts on the object! + You can also create scripts using the `evennia.create_script` function: ```python @@ -125,14 +137,14 @@ of the weather script that runs every 10 minutes instead (and also not survive a server reload): ```python - create_script('typeclasses.weather.Weather', obj=myroom, + create_script('typeclasses.weather.Weather', obj=myroom, persistent=False, interval=10*60) ``` -From in-game you can use the `@script` command to launch the Script on things: +From in-game you can use the `@script` command to launch the Script on things: ``` - @script here = typeclasses.scripts.Weather + @script here = typeclasses.scripts.Weather ``` You can conveniently view and kill running Scripts by using the `@scripts` @@ -140,59 +152,101 @@ command in-game. ## Properties and functions defined on Scripts -A Script has all the properties of a typeclassed object, such as `db` and `ndb`(see [Typeclasses](./Typeclasses)). Setting `key` is useful in order to manage scripts (delete them by name etc). These are usually set up in the Script's typeclass, but can also be assigned on the fly as keyword arguments to `evennia.create_script`. +A Script has all the properties of a typeclassed object, such as `db` and `ndb`(see +[Typeclasses](./Typeclasses)). Setting `key` is useful in order to manage scripts (delete them by name +etc). These are usually set up in the Script's typeclass, but can also be assigned on the fly as +keyword arguments to `evennia.create_script`. - `desc` - an optional description of the script's function. Seen in script listings. -- `interval` - how often the script should run. If `interval == 0` (default), this script has no timing component, will not repeat and will exist forever. This is useful for Scripts used for storage or acting as bases for various non-time dependent game systems. -- `start_delay` - (bool), if we should wait `interval` seconds before firing for the first time or not. -- `repeats` - How many times we should repeat, assuming `interval > 0`. If repeats is set to `<= 0`, the script will repeat indefinitely. Note that *each* firing of the script (including the first one) counts towards this value. So a `Script` with `start_delay=False` and `repeats=1` will start, immediately fire and shut down right away. -- `persistent`- if this script should survive a server *reset* or server *shutdown*. (You don't need to set this for it to survive a normal reload - the script will be paused and seamlessly restart after the reload is complete). +- `interval` - how often the script should run. If `interval == 0` (default), this script has no +timing component, will not repeat and will exist forever. This is useful for Scripts used for +storage or acting as bases for various non-time dependent game systems. +- `start_delay` - (bool), if we should wait `interval` seconds before firing for the first time or +not. +- `repeats` - How many times we should repeat, assuming `interval > 0`. If repeats is set to `<= 0`, +the script will repeat indefinitely. Note that *each* firing of the script (including the first one) +counts towards this value. So a `Script` with `start_delay=False` and `repeats=1` will start, +immediately fire and shut down right away. +- `persistent`- if this script should survive a server *reset* or server *shutdown*. (You don't need +to set this for it to survive a normal reload - the script will be paused and seamlessly restart +after the reload is complete). There is one special property: -- `obj` - the [Object](./Objects) this script is attached to (if any). You should not need to set this manually. If you add the script to the Object with `myobj.scripts.add(myscriptpath)` or give `myobj` as an argument to the `utils.create.create_script` function, the `obj` property will be set to `myobj` for you. +- `obj` - the [Object](./Objects) this script is attached to (if any). You should not need to set +this manually. If you add the script to the Object with `myobj.scripts.add(myscriptpath)` or give +`myobj` as an argument to the `utils.create.create_script` function, the `obj` property will be set +to `myobj` for you. It's also imperative to know the hook functions. Normally, overriding these are all the customization you'll need to do in Scripts. You can find longer descriptions of these in `src/scripts/scripts.py`. -- `at_script_creation()` - this is usually where the script class sets things like `interval` and `repeats`; things that control how the script runs. It is only called once - when the script is first created. -- `is_valid()` - determines if the script should still be running or not. This is called when running `obj.scripts.validate()`, which you can run manually, but which is also called by Evennia during certain situations such as reloads. This is also useful for using scripts as state managers. If the method returns `False`, the script is stopped and cleanly removed. -- `at_start()` - this is called when the script starts or is unpaused. For persistent scripts this is at least once ever server startup. Note that this will *always* be called right away, also if `start_delay` is `True`. -- `at_repeat()` - this is called every `interval` seconds, or not at all. It is called right away at startup, unless `start_delay` is `True`, in which case the system will wait `interval` seconds before calling. -- `at_stop()` - this is called when the script stops for whatever reason. It's a good place to do custom cleanup. -- `at_server_reload()` - this is called whenever the server is warm-rebooted (e.g. with the `@reload` command). It's a good place to save non-persistent data you might want to survive a reload. +- `at_script_creation()` - this is usually where the script class sets things like `interval` and +`repeats`; things that control how the script runs. It is only called once - when the script is +first created. +- `is_valid()` - determines if the script should still be running or not. This is called when +running `obj.scripts.validate()`, which you can run manually, but which is also called by Evennia +during certain situations such as reloads. This is also useful for using scripts as state managers. +If the method returns `False`, the script is stopped and cleanly removed. +- `at_start()` - this is called when the script starts or is unpaused. For persistent scripts this +is at least once ever server startup. Note that this will *always* be called right away, also if +`start_delay` is `True`. +- `at_repeat()` - this is called every `interval` seconds, or not at all. It is called right away at +startup, unless `start_delay` is `True`, in which case the system will wait `interval` seconds +before calling. +- `at_stop()` - this is called when the script stops for whatever reason. It's a good place to do +custom cleanup. +- `at_server_reload()` - this is called whenever the server is warm-rebooted (e.g. with the +`@reload` command). It's a good place to save non-persistent data you might want to survive a +reload. - `at_server_shutdown()` - this is called when a system reset or systems shutdown is invoked. Running methods (usually called automatically by the engine, but possible to also invoke manually) -- `start()` - this will start the script. This is called automatically whenever you add a new script to a handler. `at_start()` will be called. -- `stop()` - this will stop the script and delete it. Removing a script from a handler will stop it automatically. `at_stop()` will be called. -- `pause()` - this pauses a running script, rendering it inactive, but not deleting it. All properties are saved and timers can be resumed. This is called automatically when the server reloads and will *not* lead to the *at_stop()* hook being called. This is a suspension of the script, not a change of state. -- `unpause()` - resumes a previously paused script. The `at_start()` hook *will* be called to allow it to reclaim its internal state. Timers etc are restored to what they were before pause. The server automatically unpauses all paused scripts after a server reload. -- `force_repeat()` - this will forcibly step the script, regardless of when it would otherwise have fired. The timer will reset and the `at_repeat()` hook is called as normal. This also counts towards the total number of repeats, if limited. -- `time_until_next_repeat()` - for timed scripts, this returns the time in seconds until it next fires. Returns `None` if `interval==0`. -- `remaining_repeats()` - if the Script should run a limited amount of times, this tells us how many are currently left. -- `reset_callcount(value=0)` - this allows you to reset the number of times the Script has fired. It only makes sense if `repeats > 0`. -- `restart(interval=None, repeats=None, start_delay=None)` - this method allows you to restart the Script in-place with different run settings. If you do, the `at_stop` hook will be called and the Script brought to a halt, then the `at_start` hook will be called as the Script starts up with your (possibly changed) settings. Any keyword left at `None` means to not change the original setting. +- `start()` - this will start the script. This is called automatically whenever you add a new script +to a handler. `at_start()` will be called. +- `stop()` - this will stop the script and delete it. Removing a script from a handler will stop it +automatically. `at_stop()` will be called. +- `pause()` - this pauses a running script, rendering it inactive, but not deleting it. All +properties are saved and timers can be resumed. This is called automatically when the server reloads +and will *not* lead to the *at_stop()* hook being called. This is a suspension of the script, not a +change of state. +- `unpause()` - resumes a previously paused script. The `at_start()` hook *will* be called to allow +it to reclaim its internal state. Timers etc are restored to what they were before pause. The server +automatically unpauses all paused scripts after a server reload. +- `force_repeat()` - this will forcibly step the script, regardless of when it would otherwise have +fired. The timer will reset and the `at_repeat()` hook is called as normal. This also counts towards +the total number of repeats, if limited. +- `time_until_next_repeat()` - for timed scripts, this returns the time in seconds until it next +fires. Returns `None` if `interval==0`. +- `remaining_repeats()` - if the Script should run a limited amount of times, this tells us how many +are currently left. +- `reset_callcount(value=0)` - this allows you to reset the number of times the Script has fired. It +only makes sense if `repeats > 0`. +- `restart(interval=None, repeats=None, start_delay=None)` - this method allows you to restart the +Script in-place with different run settings. If you do, the `at_stop` hook will be called and the +Script brought to a halt, then the `at_start` hook will be called as the Script starts up with your +(possibly changed) settings. Any keyword left at `None` means to not change the original setting. ## Global Scripts A script does not have to be connected to an in-game object. If not it is -called a *Global script*. You can create global scripts by simply not supplying an object to store it on: +called a *Global script*. You can create global scripts by simply not supplying an object to store +it on: ```python # adding a global script from evennia import create_script - create_script("typeclasses.globals.MyGlobalEconomy", + create_script("typeclasses.globals.MyGlobalEconomy", key="economy", persistent=True, obj=None) ``` -Henceforth you can then get it back by searching for its key or other identifier with -`evennia.search_script`. In-game, the `scripts` command will show all scripts. +Henceforth you can then get it back by searching for its key or other identifier with +`evennia.search_script`. In-game, the `scripts` command will show all scripts. -Evennia supplies a convenient "container" called `GLOBAL_SCRIPTS` that can offer an easy -way to access global scripts. If you know the name (key) of the script you can get it like so: +Evennia supplies a convenient "container" called `GLOBAL_SCRIPTS` that can offer an easy +way to access global scripts. If you know the name (key) of the script you can get it like so: ```python from evennia import GLOBAL_SCRIPTS @@ -207,50 +261,72 @@ GLOBAL_SCRIPTS.weather.db.current_weather = "Cloudy" ``` -> Note that global scripts appear as properties on `GLOBAL_SCRIPTS` based on their `key`. +> Note that global scripts appear as properties on `GLOBAL_SCRIPTS` based on their `key`. If you were to create two global scripts with the same `key` (even with different typeclasses), -the `GLOBAL_SCRIPTS` container will only return one of them (which one depends on order in -the database). Best is to organize your scripts so that this does not happen. Otherwise, use `evennia.search_script` to get exactly the script you want. +the `GLOBAL_SCRIPTS` container will only return one of them (which one depends on order in +the database). Best is to organize your scripts so that this does not happen. Otherwise, use +`evennia.search_script` to get exactly the script you want. -There are two ways to make a script appear as a property on `GLOBAL_SCRIPTS`. The first is -to manually create a new global script with `create_script` as mentioned above. Often you want this to happen automatically when the server starts though. For this you can use the setting `GLOBAL_SCRIPTS`: +There are two ways to make a script appear as a property on `GLOBAL_SCRIPTS`. The first is +to manually create a new global script with `create_script` as mentioned above. Often you want this +to happen automatically when the server starts though. For this you add a python global dictionary +named `GLOBAL_SCRIPTS` to your `settings.py` file. The `settings.py` fie is located in +`mygame/conf/settings.py`: ```python GLOBAL_SCRIPTS = { - "my_script": { - "typeclass": "scripts.Weather", + "my_script": { + "typeclass": "typeclasses.scripts.Weather", "repeats": -1, "interval": 50, - "desc": "Weather script" + "desc": "Weather script", "persistent": True }, "storagescript": { - "typeclass": "scripts.Storage", + "typeclass": "typeclasses.scripts.Storage", "persistent": True + }, + { + "another_script": { + "typeclass": "typeclasses.another_script.AnotherScript" } } ``` -Here the key (`myscript` and `storagescript` above) is required, all other fields are optional. If `typeclass` is not given, a script of type `settings.BASE_SCRIPT_TYPECLASS` is assumed. The keys related to timing and intervals are only needed if the script is timed. +Here the key (`myscript` and `storagescript` above) is required, all other fields are optional. If +`typeclass` is not given, a script of type `settings.BASE_SCRIPT_TYPECLASS` is assumed. The keys +related to timing and intervals are only needed if the script is timed. -Evennia will use the information in `settings.GLOBAL_SCRIPTS` to automatically create and start these -scripts when the server starts (unless they already exist, based on their `key`). You need to reload the server before the setting is read and new scripts become available. You can then find the `key` you gave as properties on `evennia.GLOBAL_SCRIPTS` -(such as `evennia.GLOBAL_SCRIPTS.storagescript`). +> Note: Provide the full path to the scripts module in GLOBAL_SCRIPTS. In the example with +`another_script`, you can also create separate script modules that exist beyond scrypt.py for +further organizational requirements if needed. + +Evennia will use the information in `settings.GLOBAL_SCRIPTS` to automatically create and start +these +scripts when the server starts (unless they already exist, based on their `key`). You need to reload +the server before the setting is read and new scripts become available. You can then find the `key` +you gave as properties on `evennia.GLOBAL_SCRIPTS` +(such as `evennia.GLOBAL_SCRIPTS.storagescript`). -> Note: Make sure that your Script typeclass does not have any critical errors. If so, you'll see errors in your log and your Script will temporarily fall back to being a `DefaultScript` type. +> Note: Make sure that your Script typeclass does not have any critical errors. If so, you'll see +errors in your log and your Script will temporarily fall back to being a `DefaultScript` type. Moreover, a script defined this way is *guaranteed* to exist when you try to access it: ```python from evennia import GLOBAL_SCRIPTS -# first stop the script +# first stop the script GLOBAL_SCRIPTS.storagescript.stop() # running the `scripts` command now will show no storagescript -# but below now it's recreated again! +# but below now it's recreated again! storage = GLOBAL_SCRIPTS.storagescript ``` -That is, if the script is deleted, next time you get it from `GLOBAL_SCRIPTS`, it will use the information +That is, if the script is deleted, next time you get it from `GLOBAL_SCRIPTS`, it will use the +information in settings to recreate it for you. -> Note that if your goal with the Script is to store persistent data, you should set it as `persistent=True`, either in `settings.GLOBAL_SCRIPTS` or in the Scripts typeclass. Otherwise any data you wanted to store on it will be gone (since a new script of the same name is restarted instead). +> Note that if your goal with the Script is to store persistent data, you should set it as +`persistent=True`, either in `settings.GLOBAL_SCRIPTS` or in the Scripts typeclass. Otherwise any +data you wanted to store on it will be gone (since a new script of the same name is restarted +instead). ## Dealing with Errors @@ -264,16 +340,16 @@ traceback occurred in your script. from evennia.utils import logger -class Weather(DefaultScript): +class Weather(DefaultScript): # [...] def at_repeat(self): - try: + try: # [...] code as above except Exception: - # logs the error + # logs the error logger.log_trace() ``` @@ -296,12 +372,12 @@ thing, try something like the following: > @py self.location.search('matt').scripts.add('bodyfunctions.BodyFunctions') -Here's how you stop it on yourself. +Here's how you stop it on yourself. - > @script/stop self = bodyfunctions.BodyFunctions + > @script/stop self = bodyfunctions.BodyFunctions This will kill the script again. You can use the `@scripts` command to list all -active scripts in the game, if any (there are none by default). +active scripts in the game, if any (there are none by default). For another example of a Script in use, check out the [Turn Based Combat System diff --git a/docs/source/Security.md b/docs/source/Security.md index 6369101da3..67ceef8b5f 100644 --- a/docs/source/Security.md +++ b/docs/source/Security.md @@ -1,20 +1,42 @@ # Security -Hackers these days aren't discriminating, and their backgrounds range from bored teenagers to international intelligence agencies. Their scripts and bots endlessly crawl the web, looking for vulnerable systems they can break into. Who owns the system is irrelevant-- it doesn't matter if it belongs to you or the Pentagon, the goal is to take advantage of poorly-secured systems and see what resources can be controlled or stolen from them. +Hackers these days aren't discriminating, and their backgrounds range from bored teenagers to +international intelligence agencies. Their scripts and bots endlessly crawl the web, looking for +vulnerable systems they can break into. Who owns the system is irrelevant-- it doesn't matter if it +belongs to you or the Pentagon, the goal is to take advantage of poorly-secured systems and see what +resources can be controlled or stolen from them. -If you're considering deploying to a cloud-based host, you have a vested interest in securing your applications-- you likely have a credit card on file that your host can freely bill. Hackers pegging your CPU to mine cryptocurrency or saturating your network connection to participate in a botnet or send spam can run up your hosting bill, get your service suspended or get your address/site blacklisted by ISPs. It can be a difficult legal or political battle to undo this damage after the fact. +If you're considering deploying to a cloud-based host, you have a vested interest in securing your +applications-- you likely have a credit card on file that your host can freely bill. Hackers pegging +your CPU to mine cryptocurrency or saturating your network connection to participate in a botnet or +send spam can run up your hosting bill, get your service suspended or get your address/site +blacklisted by ISPs. It can be a difficult legal or political battle to undo this damage after the +fact. -As a developer about to expose a web application to the threat landscape of the modern internet, here are a few tips to consider to increase the security of your Evennia install. +As a developer about to expose a web application to the threat landscape of the modern internet, +here are a few tips to consider to increase the security of your Evennia install. ### Know your logs -In case of emergency, check your logs! By default they are located in the `server/logs/` folder. Here are some of the more important ones and why you should care: +In case of emergency, check your logs! By default they are located in the `server/logs/` folder. +Here are some of the more important ones and why you should care: -* `http_requests.log` will show you what HTTP requests have been made against Evennia's built-in webserver (TwistedWeb). This is a good way to see if people are innocuously browsing your site or trying to break it through code injection. -* `portal.log` will show you various networking-related information. This is a good place to check for odd or unusual types or amounts of connections to your game, or other networking-related issues-- like when users are reporting an inability to connect. -* `server.log` is the MUX administrator's best friend. Here is where you'll find information pertaining to who's trying to break into your system by guessing at passwords, who created what objects, and more. If your game fails to start or crashes and you can't tell why, this is the first place you should look for answers. Security-related events are prefixed with an `[SS]` so when there's a problem you might want to pay special attention to those. +* `http_requests.log` will show you what HTTP requests have been made against Evennia's built-in +webserver (TwistedWeb). This is a good way to see if people are innocuously browsing your site or +trying to break it through code injection. +* `portal.log` will show you various networking-related information. This is a good place to check +for odd or unusual types or amounts of connections to your game, or other networking-related +issues-- like when users are reporting an inability to connect. +* `server.log` is the MUX administrator's best friend. Here is where you'll find information +pertaining to who's trying to break into your system by guessing at passwords, who created what +objects, and more. If your game fails to start or crashes and you can't tell why, this is the first +place you should look for answers. Security-related events are prefixed with an `[SS]` so when +there's a problem you might want to pay special attention to those. ### Disable development/debugging options -There are a few Evennia/Django options that are set when you first create your game to make it more obvious to you where problems arise. These options should be disabled before you push your game into production-- leaving them on can expose variables or code someone with malicious intent can easily abuse to compromise your environment. +There are a few Evennia/Django options that are set when you first create your game to make it more +obvious to you where problems arise. These options should be disabled before you push your game into +production-- leaving them on can expose variables or code someone with malicious intent can easily +abuse to compromise your environment. In `server/conf/settings.py`: @@ -22,21 +44,39 @@ In `server/conf/settings.py`: DEBUG = False # Disable the in-game equivalent IN_GAME_ERRORS = False - # If you've registered a domain name, force Django to check host headers. Otherwise leave this as-is. + # If you've registered a domain name, force Django to check host headers. Otherwise leave this +as-is. # Note the leading period-- it is not a typo! ALLOWED_HOSTS = ['.example.com'] ### Handle user-uploaded images with care -If you decide to allow users to upload their own images to be served from your site, special care must be taken. Django will read the file headers to confirm it's an image (as opposed to a document or zip archive), but [code can be injected into an image file](https://insinuator.net/2014/05/django-image-validation-vulnerability/) *after* the headers that can be interpreted as HTML and/or give an attacker a web shell through which they can access other filesystem resources. +If you decide to allow users to upload their own images to be served from your site, special care +must be taken. Django will read the file headers to confirm it's an image (as opposed to a document +or zip archive), but [code can be injected into an image +file](https://insinuator.net/2014/05/django-image-validation-vulnerability/) *after* the headers +that can be interpreted as HTML and/or give an attacker a web shell through which they can access +other filesystem resources. -[Django has a more comprehensive overview of how to handle user-uploaded files](https://docs.djangoproject.com/en/dev/topics/security/#user-uploaded-content-security), but in short you should take care to do one of two things-- +[Django has a more comprehensive overview of how to handle user-uploaded +files](https://docs.djangoproject.com/en/dev/topics/security/#user-uploaded-content-security), but +in short you should take care to do one of two things-- -* Serve all user-uploaded assets from a *separate* domain or CDN (*not* a subdomain of the one you already have!). For example, you may be browsing `reddit.com` but note that all the user-submitted images are being served from the `redd.it` domain. There are both security and performance benefits to this (webservers tend to load local resources one-by-one, whereas they will request external resources in bulk). -* If you don't want to pay for a second domain, don't understand what any of this means or can't be bothered with additional infrastructure, then simply reprocess user images upon receipt using an image library. Convert them to a different format, for example. *Destroy the originals!* +* Serve all user-uploaded assets from a *separate* domain or CDN (*not* a subdomain of the one you +already have!). For example, you may be browsing `reddit.com` but note that all the user-submitted +images are being served from the `redd.it` domain. There are both security and performance benefits +to this (webservers tend to load local resources one-by-one, whereas they will request external +resources in bulk). +* If you don't want to pay for a second domain, don't understand what any of this means or can't be +bothered with additional infrastructure, then simply reprocess user images upon receipt using an +image library. Convert them to a different format, for example. *Destroy the originals!* ### Disable the web interface The web interface allows visitors to see an informational page as well as log into a browser-based -telnet client with which to access Evennia. It also provides authentication endpoints against which an attacker can attempt to validate stolen lists of credentials to see which ones might be shared by your users. Django's security is robust, but if you don't want/need these features and fully intend to force your users to use traditional clients to access your game, you might consider disabling either/both to minimize your attack surface. +telnet client with which to access Evennia. It also provides authentication endpoints against which +an attacker can attempt to validate stolen lists of credentials to see which ones might be shared by +your users. Django's security is robust, but if you don't want/need these features and fully intend +to force your users to use traditional clients to access your game, you might consider disabling +either/both to minimize your attack surface. In `server/conf/settings.py`: @@ -46,11 +86,14 @@ In `server/conf/settings.py`: WEBSERVER_ENABLED = False ### Change your ssh port -Automated attacks will often target port 22 seeing as how it's the standard port for SSH traffic. Also, +Automated attacks will often target port 22 seeing as how it's the standard port for SSH traffic. +Also, many public wifi hotspots block ssh traffic over port 22 so you might not be able to access your server from these locations if you like to work remotely or don't have a home internet connection. -If you don't intend on running a website or securing it with TLS, you can mitigate both problems by changing the port used for ssh to 443, which most/all hotspot providers assume is HTTPS traffic and allows through. +If you don't intend on running a website or securing it with TLS, you can mitigate both problems by +changing the port used for ssh to 443, which most/all hotspot providers assume is HTTPS traffic and +allows through. (Ubuntu) In /etc/ssh/sshd_config, change the following variable: @@ -67,7 +110,8 @@ Ubuntu users can make use of the simple ufw utility. Anybody else can use iptabl # Install ufw (if not already) sudo apt-get install ufw -UFW's default policy is to deny everything. We must specify what we want to allow through our firewall. +UFW's default policy is to deny everything. We must specify what we want to allow through our +firewall. # Allow terminal connections to your game sudo ufw allow 4000/tcp @@ -83,13 +127,26 @@ Finally: sudo ufw enable -Now the only ports open will be your administrative ssh port (whichever you chose), and Evennia on 4000-4001. +Now the only ports open will be your administrative ssh port (whichever you chose), and Evennia on +4000-4001. ### Use an external webserver -Though not officially supported, there are some benefits to [deploying a webserver](./Apache-Config) to handle/proxy traffic to your Evennia instance. +Though not officially supported, there are some benefits to [deploying a webserver](./Apache-Config) +to handle/proxy traffic to your Evennia instance. -For example, Evennia's game engine and webservice are tightly integrated. If you bring your game down for maintenance (or if it simply crashes) your website will go down with it. In these cases a standalone webserver can still be used to display a maintenance page or otherwise communicate to your users the reason for the downtime, instead of disappearing off the face of the earth and returning opaque `SERVER NOT FOUND` error messages. +For example, Evennia's game engine and webservice are tightly integrated. If you bring your game +down for maintenance (or if it simply crashes) your website will go down with it. In these cases a +standalone webserver can still be used to display a maintenance page or otherwise communicate to +your users the reason for the downtime, instead of disappearing off the face of the earth and +returning opaque `SERVER NOT FOUND` error messages. -Proper webservers are also written in more efficient programming languages than Python, and while Twisted can handle its own, putting a webserver in front of it is like hiring a bouncer to deal with nuisances and crowds before they even get in the door. +Proper webservers are also written in more efficient programming languages than Python, and while +Twisted can handle its own, putting a webserver in front of it is like hiring a bouncer to deal with +nuisances and crowds before they even get in the door. -Many of the popular webservers also let you plug in additional modules (like [mod_security](https://en.wikipedia.org/wiki/ModSecurity) for Apache) that can be used to detect (and block!) malicious users or requests before they even touch your game or site. There are also automated solutions for installing and configuring TLS (via [Certbot/Let's Encrypt](https://en.wikipedia.org/wiki/Let%27s_Encrypt)) to secure your website against hotspot and ISP snooping. \ No newline at end of file +Many of the popular webservers also let you plug in additional modules (like +[mod_security](https://en.wikipedia.org/wiki/ModSecurity) for Apache) that can be used to detect +(and block!) malicious users or requests before they even touch your game or site. There are also +automated solutions for installing and configuring TLS (via [Certbot/Let's +Encrypt](https://en.wikipedia.org/wiki/Let%27s_Encrypt)) to secure your website against hotspot and +ISP snooping. \ No newline at end of file diff --git a/docs/source/Server-Conf.md b/docs/source/Server-Conf.md index 73d65c0443..eedb0b3d3e 100644 --- a/docs/source/Server-Conf.md +++ b/docs/source/Server-Conf.md @@ -1,23 +1,38 @@ # Server Conf -Evennia runs out of the box without any changes to its settings. But there are several important ways to customize the server and expand it with your own plugins. +Evennia runs out of the box without any changes to its settings. But there are several important +ways to customize the server and expand it with your own plugins. ## Settings file -The "Settings" file referenced throughout the documentation is the file `mygame/server/conf/settings.py`. This is automatically created on the first run of `evennia --init` (see the [Getting Started](./Getting-Started) page). +The "Settings" file referenced throughout the documentation is the file +`mygame/server/conf/settings.py`. This is automatically created on the first run of `evennia --init` +(see the [Getting Started](./Getting-Started) page). -Your new `settings.py` is relatively bare out of the box. Evennia's core settings file is actually [evennia/settings_default.py](https://github.com/evennia/evennia/blob/master/evennia/settings_default.py) and is considerably more extensive (it is also heavily documented so you should refer to this file directly for the available settings). +Your new `settings.py` is relatively bare out of the box. Evennia's core settings file is actually [ +evennia/settings_default.py](https://github.com/evennia/evennia/blob/master/evennia/settings_default +.py) and is considerably more extensive (it is also heavily documented so you should refer to this +file directly for the available settings). -Since `mygame/server/conf/settings.py` is a normal Python module, it simply imports `evennia/settings_default.py` into itself at the top. +Since `mygame/server/conf/settings.py` is a normal Python module, it simply imports +`evennia/settings_default.py` into itself at the top. -This means that if any setting you want to change were to depend on some *other* default setting, you might need to copy & paste both in order to change them and get the effect you want (for most commonly changed settings, this is not something you need to worry about). +This means that if any setting you want to change were to depend on some *other* default setting, +you might need to copy & paste both in order to change them and get the effect you want (for most +commonly changed settings, this is not something you need to worry about). -You should never edit `evennia/settings_default.py`. Rather you should copy&paste the select variables you want to change into your `settings.py` and edit them there. This will overload the previously imported defaults. +You should never edit `evennia/settings_default.py`. Rather you should copy&paste the select +variables you want to change into your `settings.py` and edit them there. This will overload the +previously imported defaults. -> Warning: It may be tempting to copy everything from `settings_default.py` into your own settings file. There is a reason we don't do this out of the box though: it makes it directly clear what changes you did. Also, if you limit your copying to the things you really need you will directly be able to take advantage of upstream changes and additions to Evennia for anything you didn't customize. +> Warning: It may be tempting to copy everything from `settings_default.py` into your own settings +file. There is a reason we don't do this out of the box though: it makes it directly clear what +changes you did. Also, if you limit your copying to the things you really need you will directly be +able to take advantage of upstream changes and additions to Evennia for anything you didn't +customize. -In code, the settings is accessed through +In code, the settings is accessed through ```python from django.conf import settings @@ -27,32 +42,63 @@ In code, the settings is accessed through servername = settings.SERVER_NAME ``` -Each setting appears as a property on the imported `settings` object. You can also explore all possible options with `evennia.settings_full` (this also includes advanced Django defaults that are not touched in default Evennia). +Each setting appears as a property on the imported `settings` object. You can also explore all +possible options with `evennia.settings_full` (this also includes advanced Django defaults that are +not touched in default Evennia). -> It should be pointed out that when importing `settings` into your code like this, it will be *read only*. You *cannot* edit your settings from your code! The only way to change an Evennia setting is to edit `mygame/server/conf/settings.py` directly. You also generally need to restart the server (possibly also the Portal) before a changed setting becomes available. +> It should be pointed out that when importing `settings` into your code like this, it will be *read +only*. You *cannot* edit your settings from your code! The only way to change an Evennia setting is +to edit `mygame/server/conf/settings.py` directly. You also generally need to restart the server +(possibly also the Portal) before a changed setting becomes available. ## Other files in the `server/conf` directory -Apart from the main `settings.py` file, +Apart from the main `settings.py` file, -- `at_initial_setup.py` - this allows you to add a custom startup method to be called (only) the very first time Evennia starts (at the same time as user #1 and Limbo is created). It can be made to start your own global scripts or set up other system/world-related things your game needs to have running from the start. -- `at_server_startstop.py` - this module contains two functions that Evennia will call every time the Server starts and stops respectively - this includes stopping due to reloading and resetting as well as shutting down completely. It's a useful place to put custom startup code for handlers and other things that must run in your game but which has no database persistence. -- `connection_screens.py` - all global string variables in this module are interpreted by Evennia as a greeting screen to show when an Account first connects. If more than one string variable is present in the module a random one will be picked. +- `at_initial_setup.py` - this allows you to add a custom startup method to be called (only) the +very first time Evennia starts (at the same time as user #1 and Limbo is created). It can be made to +start your own global scripts or set up other system/world-related things your game needs to have +running from the start. +- `at_server_startstop.py` - this module contains two functions that Evennia will call every time +the Server starts and stops respectively - this includes stopping due to reloading and resetting as +well as shutting down completely. It's a useful place to put custom startup code for handlers and +other things that must run in your game but which has no database persistence. +- `connection_screens.py` - all global string variables in this module are interpreted by Evennia as +a greeting screen to show when an Account first connects. If more than one string variable is +present in the module a random one will be picked. - `inlinefuncs.py` - this is where you can define custom [Inline functions](./TextTags#inlinefuncs). -- `inputfuncs.py` - this is where you define custom [Input functions](./Inputfuncs) to handle data from the client. -- `lockfuncs.py` - this is one of many possible modules to hold your own "safe" *lock functions* to make available to Evennia's [Locks](./Locks). -- `mssp.py` - this holds meta information about your game. It is used by MUD search engines (which you often have to register with) in order to display what kind of game you are running along with +- `inputfuncs.py` - this is where you define custom [Input functions](./Inputfuncs) to handle data +from the client. +- `lockfuncs.py` - this is one of many possible modules to hold your own "safe" *lock functions* to +make available to Evennia's [Locks](./Locks). +- `mssp.py` - this holds meta information about your game. It is used by MUD search engines (which +you often have to register with) in order to display what kind of game you are running along with statistics such as number of online accounts and online status. - `oobfuncs.py` - in here you can define custom [OOB functions](./OOB). -- `portal_services_plugin.py` - this allows for adding your own custom services/protocols to the Portal. It must define one particular function that will be called by Evennia at startup. There can be any number of service plugin modules, all will be imported and used if defined. More info can be found [here](http://code.google.com/p/evennia/wiki/SessionProtocols#Adding_custom_Protocols). -- `server_services_plugin.py` - this is equivalent to the previous one, but used for adding new services to the Server instead. More info can be found [here](http://code.google.com/p/evennia/wiki/SessionProtocols#Adding_custom_Protocols). +- `portal_services_plugin.py` - this allows for adding your own custom services/protocols to the +Portal. It must define one particular function that will be called by Evennia at startup. There can +be any number of service plugin modules, all will be imported and used if defined. More info can be +found [here](http://code.google.com/p/evennia/wiki/SessionProtocols#Adding_custom_Protocols). +- `server_services_plugin.py` - this is equivalent to the previous one, but used for adding new +services to the Server instead. More info can be found +[here](http://code.google.com/p/evennia/wiki/SessionProtocols#Adding_custom_Protocols). -Some other Evennia systems can be customized by plugin modules but has no explicit template in `conf/`: +Some other Evennia systems can be customized by plugin modules but has no explicit template in +`conf/`: -- *cmdparser.py* - a custom module can be used to totally replace Evennia's default command parser. All this does is to split the incoming string into "command name" and "the rest". It also handles things like error messages for no-matches and multiple-matches among other things that makes this more complex than it sounds. The default parser is *very* generic, so you are most often best served by modifying things further down the line (on the command parse level) than here. -- *at_search.py* - this allows for replacing the way Evennia handles search results. It allows to change how errors are echoed and how multi-matches are resolved and reported (like how the default understands that "2-ball" should match the second "ball" object if there are two of them in the room). +- *cmdparser.py* - a custom module can be used to totally replace Evennia's default command parser. +All this does is to split the incoming string into "command name" and "the rest". It also handles +things like error messages for no-matches and multiple-matches among other things that makes this +more complex than it sounds. The default parser is *very* generic, so you are most often best served +by modifying things further down the line (on the command parse level) than here. +- *at_search.py* - this allows for replacing the way Evennia handles search results. It allows to +change how errors are echoed and how multi-matches are resolved and reported (like how the default +understands that "2-ball" should match the second "ball" object if there are two of them in the +room). ## ServerConf -There is a special database model called `ServerConf` that stores server internal data and settings such as current account count (for interfacing with the webserver), startup status and many other things. It's rarely of use outside the server core itself but may be good to -know about if you are an Evennia developer. +There is a special database model called `ServerConf` that stores server internal data and settings +such as current account count (for interfacing with the webserver), startup status and many other +things. It's rarely of use outside the server core itself but may be good to +know about if you are an Evennia developer. diff --git a/docs/source/Sessions.md b/docs/source/Sessions.md index 719f3a08a4..ae7c1bc8f0 100644 --- a/docs/source/Sessions.md +++ b/docs/source/Sessions.md @@ -1,11 +1,23 @@ # Sessions -An Evennia *Session* represents one single established connection to the server. Depending on the Evennia session, it is possible for a person to connect multiple times, for example using different clients in multiple windows. Each such connection is represented by a session object. +An Evennia *Session* represents one single established connection to the server. Depending on the +Evennia session, it is possible for a person to connect multiple times, for example using different +clients in multiple windows. Each such connection is represented by a session object. -A session object has its own [cmdset](./Command-Sets), usually the "unloggedin" cmdset. This is what is used to show the login screen and to handle commands to create a new account (or [Account](./Accounts) in evennia lingo) read initial help and to log into the game with an existing account. A session object can either be "logged in" or not. Logged in means that the user has authenticated. When this happens the session is associated with an Account object (which is what holds account-centric stuff). The account can then in turn puppet any number of objects/characters. +A session object has its own [cmdset](./Command-Sets), usually the "unloggedin" cmdset. This is what +is used to show the login screen and to handle commands to create a new account (or +[Account](./Accounts) in evennia lingo) read initial help and to log into the game with an existing +account. A session object can either be "logged in" or not. Logged in means that the user has +authenticated. When this happens the session is associated with an Account object (which is what +holds account-centric stuff). The account can then in turn puppet any number of objects/characters. -> Warning: A Session is not *persistent* - it is not a [Typeclass](./Typeclasses) and has no connection to the database. The Session will go away when a user disconnects and you will lose any custom data on it if the server reloads. The `.db` handler on Sessions is there to present a uniform API (so you can assume `.db` exists even if you don't know if you receive an Object or a Session), but this is just an alias to `.ndb`. So don't store any data on Sessions that you can't afford to lose in a reload. You have been warned. +> Warning: A Session is not *persistent* - it is not a [Typeclass](./Typeclasses) and has no +connection to the database. The Session will go away when a user disconnects and you will lose any +custom data on it if the server reloads. The `.db` handler on Sessions is there to present a uniform +API (so you can assume `.db` exists even if you don't know if you receive an Object or a Session), +but this is just an alias to `.ndb`. So don't store any data on Sessions that you can't afford to +lose in a reload. You have been warned. ## Properties on Sessions @@ -14,8 +26,10 @@ Here are some important properties available on (Server-)Sessions - `sessid` - The unique session-id. This is an integer starting from 1. - `address` - The connected client's address. Different protocols give different information here. - `logged_in` - `True` if the user authenticated to this session. -- `account` - The [Account](./Accounts) this Session is attached to. If not logged in yet, this is `None`. -- `puppet` - The [Character/Object](./Objects) currently puppeted by this Account/Session combo. If not logged in or in OOC mode, this is `None`. +- `account` - The [Account](./Accounts) this Session is attached to. If not logged in yet, this is +`None`. +- `puppet` - The [Character/Object](./Objects) currently puppeted by this Account/Session combo. If +not logged in or in OOC mode, this is `None`. - `ndb` - The [Non-persistent Attribute](./Attributes) handler. - `db` - As noted above, Sessions don't have regular Attributes. This is an alias to `ndb`. - `cmdset` - The Session's [CmdSetHandler](./Command-Sets) @@ -24,41 +38,89 @@ Session statistics are mainly used internally by Evennia. - `conn_time` - How long this Session has been connected - `cmd_last` - Last active time stamp. This will be reset by sending `idle` keepalives. -- `cmd_last_visible` - last active time stamp. This ignores `idle` keepalives and representes the last time this session was truly visibly active. +- `cmd_last_visible` - last active time stamp. This ignores `idle` keepalives and representes the +last time this session was truly visibly active. - `cmd_total` - Total number of Commands passed through this Session. ## Multisession mode -The number of sessions possible to connect to a given account at the same time and how it works is given by the `MULTISESSION_MODE` setting: +The number of sessions possible to connect to a given account at the same time and how it works is +given by the `MULTISESSION_MODE` setting: -* `MULTISESSION_MODE=0`: One session per account. When connecting with a new session the old one is disconnected. This is the default mode and emulates many classic mud code bases. In default Evennia, this mode also changes how the `create account` Command works - it will automatically create a Character with the *same name* as the Account. When logging in, the login command is also modified to have the player automatically puppet that Character. This makes the distinction between Account and Character minimal from the player's perspective. -* `MULTISESSION_MODE=1`: Many sessions per account, input/output from/to each session is treated the same. For the player this means they can connect to the game from multiple clients and see the same output in all of them. The result of a command given in one client (that is, through one Session) will be returned to *all* connected Sessions/clients with no distinction. This mode will have the Session(s) auto-create and puppet a Character in the same way as mode 0. -* `MULTISESSION_MODE=2`: Many sessions per account, one character per session. In this mode, puppeting an Object/Character will link the puppet back only to the particular Session doing the puppeting. That is, input from that Session will make use of the CmdSet of that Object/Character and outgoing messages (such as the result of a `look`) will be passed back only to that puppeting Session. If another Session tries to puppet the same Character, the old Session will automatically un-puppet it. From the player's perspective, this will mean that they can open separate game clients and play a different Character in each using one game account. -This mode will *not* auto-create a Character and *not* auto-puppet on login like in modes 0 and 1. Instead it changes how the account-cmdsets's `OOCLook` command works so as to show a simple 'character select' menu. -* `MULTISESSION_MODE=3`: Many sessions per account *and* character. This is the full multi-puppeting mode, where multiple sessions may not only connect to the player account but multiple sessions may also puppet a single character at the same time. From the user's perspective it means one can open multiple client windows, some for controlling different Characters and some that share a Character's input/output like in mode 1. This mode otherwise works the same as mode 2. +* `MULTISESSION_MODE=0`: One session per account. When connecting with a new session the old one is +disconnected. This is the default mode and emulates many classic mud code bases. In default Evennia, +this mode also changes how the `create account` Command works - it will automatically create a +Character with the *same name* as the Account. When logging in, the login command is also modified +to have the player automatically puppet that Character. This makes the distinction between Account +and Character minimal from the player's perspective. +* `MULTISESSION_MODE=1`: Many sessions per account, input/output from/to each session is treated the +same. For the player this means they can connect to the game from multiple clients and see the same +output in all of them. The result of a command given in one client (that is, through one Session) +will be returned to *all* connected Sessions/clients with no distinction. This mode will have the +Session(s) auto-create and puppet a Character in the same way as mode 0. +* `MULTISESSION_MODE=2`: Many sessions per account, one character per session. In this mode, +puppeting an Object/Character will link the puppet back only to the particular Session doing the +puppeting. That is, input from that Session will make use of the CmdSet of that Object/Character and +outgoing messages (such as the result of a `look`) will be passed back only to that puppeting +Session. If another Session tries to puppet the same Character, the old Session will automatically +un-puppet it. From the player's perspective, this will mean that they can open separate game clients +and play a different Character in each using one game account. +This mode will *not* auto-create a Character and *not* auto-puppet on login like in modes 0 and 1. +Instead it changes how the account-cmdsets's `OOCLook` command works so as to show a simple +'character select' menu. +* `MULTISESSION_MODE=3`: Many sessions per account *and* character. This is the full multi-puppeting +mode, where multiple sessions may not only connect to the player account but multiple sessions may +also puppet a single character at the same time. From the user's perspective it means one can open +multiple client windows, some for controlling different Characters and some that share a Character's +input/output like in mode 1. This mode otherwise works the same as mode 2. -> Note that even if multiple Sessions puppet one Character, there is only ever one instance of that Character. +> Note that even if multiple Sessions puppet one Character, there is only ever one instance of that +Character. ## Returning data to the session -When you use `msg()` to return data to a user, the object on which you call the `msg()` matters. The `MULTISESSION_MODE` also matters, especially if greater than 1. +When you use `msg()` to return data to a user, the object on which you call the `msg()` matters. The +`MULTISESSION_MODE` also matters, especially if greater than 1. -For example, if you use `account.msg("hello")` there is no way for evennia to know which session it should send the greeting to. In this case it will send it to all sessions. If you want a specific session you need to supply its session to the `msg` call (`account.msg("hello", session=mysession)`). +For example, if you use `account.msg("hello")` there is no way for evennia to know which session it +should send the greeting to. In this case it will send it to all sessions. If you want a specific +session you need to supply its session to the `msg` call (`account.msg("hello", +session=mysession)`). -On the other hand, if you call the `msg()` message on a puppeted object, like `character.msg("hello")`, the character already knows the session that controls it - it will cleverly auto-add this for you (you can specify a different session if you specifically want to send stuff to another session). +On the other hand, if you call the `msg()` message on a puppeted object, like +`character.msg("hello")`, the character already knows the session that controls it - it will +cleverly auto-add this for you (you can specify a different session if you specifically want to send +stuff to another session). -Finally, there is a wrapper for `msg()` on all command classes: `command.msg()`. This will transparently detect which session was triggering the command (if any) and redirects to that session (this is most often what you want). If you are having trouble redirecting to a given session, `command.msg()` is often the safest bet. +Finally, there is a wrapper for `msg()` on all command classes: `command.msg()`. This will +transparently detect which session was triggering the command (if any) and redirects to that session +(this is most often what you want). If you are having trouble redirecting to a given session, +`command.msg()` is often the safest bet. -You can get the `session` in two main ways: -* [Accounts](./Accounts) and [Objects](./Objects) (including Characters) have a `sessions` property. This is a *handler* that tracks all Sessions attached to or puppeting them. Use e.g. `accounts.sessions.get()` to get a list of Sessions attached to that entity. -* A Command instance has a `session` property that always points back to the Session that triggered it (it's always a single one). It will be `None` if no session is involved, like when a mob or script triggers the Command. +You can get the `session` in two main ways: +* [Accounts](./Accounts) and [Objects](./Objects) (including Characters) have a `sessions` property. +This is a *handler* that tracks all Sessions attached to or puppeting them. Use e.g. +`accounts.sessions.get()` to get a list of Sessions attached to that entity. +* A Command instance has a `session` property that always points back to the Session that triggered +it (it's always a single one). It will be `None` if no session is involved, like when a mob or +script triggers the Command. ## Customizing the Session object -When would one want to customize the Session object? Consider for example a character creation system: You might decide to keep this on the out-of-character level. This would mean that you create the character at the end of some sort of menu choice. The actual char-create cmdset would then normally be put on the account. This works fine as long as you are `MULTISESSION_MODE` below 2. For higher modes, replacing the Account cmdset will affect *all* your connected sessions, also those not involved in character creation. In this case you want to instead put the char-create cmdset on the Session level - then all other sessions will keep working normally despite you creating a new character in one of them. +When would one want to customize the Session object? Consider for example a character creation +system: You might decide to keep this on the out-of-character level. This would mean that you create +the character at the end of some sort of menu choice. The actual char-create cmdset would then +normally be put on the account. This works fine as long as you are `MULTISESSION_MODE` below 2. +For higher modes, replacing the Account cmdset will affect *all* your connected sessions, also those +not involved in character creation. In this case you want to instead put the char-create cmdset on +the Session level - then all other sessions will keep working normally despite you creating a new +character in one of them. -By default, the session object gets the `commands.default_cmdsets.UnloggedinCmdSet` when the user first connects. Once the session is authenticated it has *no* default sets. To add a "logged-in" cmdset to the Session, give the path to the cmdset class with `settings.CMDSET_SESSION`. This set will then henceforth always be present as soon as the account logs in. +By default, the session object gets the `commands.default_cmdsets.UnloggedinCmdSet` when the user +first connects. Once the session is authenticated it has *no* default sets. To add a "logged-in" +cmdset to the Session, give the path to the cmdset class with `settings.CMDSET_SESSION`. This set +will then henceforth always be present as soon as the account logs in. To customize further you can completely override the Session with your own subclass. To replace the default Session class, change `settings.SERVER_SESSION_CLASS` to point to your custom class. This is @@ -70,32 +132,57 @@ changes carefully. *Note: This is considered an advanced topic. You don't need to know this on a first read-through.* -Evennia is split into two parts, the [Portal and the Server](./Portal-And-Server). Each side tracks its own Sessions, syncing them to each other. +Evennia is split into two parts, the [Portal and the Server](./Portal-And-Server). Each side tracks +its own Sessions, syncing them to each other. -The "Session" we normally refer to is actually the `ServerSession`. Its counter-part on the Portal side is the `PortalSession`. Whereas the server sessions deal with game states, the portal session deals with details of the connection-protocol itself. The two are also acting as backups of critical data such as when the server reboots. +The "Session" we normally refer to is actually the `ServerSession`. Its counter-part on the Portal +side is the `PortalSession`. Whereas the server sessions deal with game states, the portal session +deals with details of the connection-protocol itself. The two are also acting as backups of critical +data such as when the server reboots. -New Account connections are listened for and handled by the Portal using the [protocols](./Portal-And-Server) it understands (such as telnet, ssh, webclient etc). When a new connection is established, a `PortalSession` is created on the Portal side. This session object looks different depending on which protocol is used to connect, but all still have a minimum set of attributes that are generic to all +New Account connections are listened for and handled by the Portal using the [protocols](Portal-And- +Server) it understands (such as telnet, ssh, webclient etc). When a new connection is established, a +`PortalSession` is created on the Portal side. This session object looks different depending on +which protocol is used to connect, but all still have a minimum set of attributes that are generic +to all sessions. -These common properties are piped from the Portal, through the AMP connection, to the Server, which is now informed a new connection has been established. On the Server side, a `ServerSession` object is created to represent this. There is only one type of `ServerSession`; It looks the same regardless of how the Account connects. +These common properties are piped from the Portal, through the AMP connection, to the Server, which +is now informed a new connection has been established. On the Server side, a `ServerSession` object +is created to represent this. There is only one type of `ServerSession`; It looks the same +regardless of how the Account connects. -From now on, there is a one-to-one match between the `ServerSession` on one side of the AMP connection and the `PortalSession` on the other. Data arriving to the Portal Session is sent on to its mirror Server session and vice versa. +From now on, there is a one-to-one match between the `ServerSession` on one side of the AMP +connection and the `PortalSession` on the other. Data arriving to the Portal Session is sent on to +its mirror Server session and vice versa. During certain situations, the portal- and server-side sessions are "synced" with each other: -- The Player closes their client, killing the Portal Session. The Portal syncs with the Server to make sure the corresponding Server Session is also deleted. -- The Player quits from inside the game, killing the Server Session. The Server then syncs with the Portal to make sure to close the Portal connection cleanly. -- The Server is rebooted/reset/shutdown - The Server Sessions are copied over ("saved") to the Portal side. When the Server comes back up, this data is returned by the Portal so the two are again in sync. This way an Account's login status and other connection-critical things can survive a server reboot (assuming the Portal is not stopped at the same time, obviously). +- The Player closes their client, killing the Portal Session. The Portal syncs with the Server to +make sure the corresponding Server Session is also deleted. +- The Player quits from inside the game, killing the Server Session. The Server then syncs with the +Portal to make sure to close the Portal connection cleanly. +- The Server is rebooted/reset/shutdown - The Server Sessions are copied over ("saved") to the +Portal side. When the Server comes back up, this data is returned by the Portal so the two are again +in sync. This way an Account's login status and other connection-critical things can survive a +server reboot (assuming the Portal is not stopped at the same time, obviously). ## Sessionhandlers -Both the Portal and Server each have a *sessionhandler* to manage the connections. These handlers are global entities contain all methods for relaying data across the AMP bridge. All types of Sessions hold a reference to their respective Sessionhandler (the property is called `sessionhandler`) so they can relay data. See [protocols](./Custom-Protocols) for more info +Both the Portal and Server each have a *sessionhandler* to manage the connections. These handlers +are global entities contain all methods for relaying data across the AMP bridge. All types of +Sessions hold a reference to their respective Sessionhandler (the property is called +`sessionhandler`) so they can relay data. See [protocols](./Custom-Protocols) for more info on building new protocols. -To get all Sessions in the game (i.e. all currently connected clients), you access the server-side Session handler, which you get by +To get all Sessions in the game (i.e. all currently connected clients), you access the server-side +Session handler, which you get by ``` from evennia.server.sessionhandler import SESSION_HANDLER ``` -> Note: The `SESSION_HANDLER` singleton has an older alias `SESSIONS` that is commonly seen in various places as well. +> Note: The `SESSION_HANDLER` singleton has an older alias `SESSIONS` that is commonly seen in +various places as well. -See the [sessionhandler.py](https://github.com/evennia/evennia/blob/master/evennia/server/sessionhandler.py) module for details on the capabilities of the `ServerSessionHandler`. +See the +[sessionhandler.py](https://github.com/evennia/evennia/blob/master/evennia/server/sessionhandler.py) +module for details on the capabilities of the `ServerSessionHandler`. diff --git a/docs/source/Setting-up-PyCharm.md b/docs/source/Setting-up-PyCharm.md index de54b8c3bc..cacc71b6be 100644 --- a/docs/source/Setting-up-PyCharm.md +++ b/docs/source/Setting-up-PyCharm.md @@ -2,20 +2,27 @@ # Directions for setting up PyCharm with Evennia -[PyCharm](https://www.jetbrains.com/pycharm/) is a Python developer's IDE from Jetbrains available for Windows, Mac and Linux. It is a commercial product but offer free trials, a scaled-down community edition and also generous licenses for OSS projects like Evennia. +[PyCharm](https://www.jetbrains.com/pycharm/) is a Python developer's IDE from Jetbrains available +for Windows, Mac and Linux. It is a commercial product but offer free trials, a scaled-down +community edition and also generous licenses for OSS projects like Evennia. -> This page was originally tested on Windows (so use Windows-style path examples), but should work the same for all platforms. +> This page was originally tested on Windows (so use Windows-style path examples), but should work +the same for all platforms. -First, install Evennia on your local machine with [[Getting Started]]. If you're new to PyCharm, loading your project is as easy as selecting the `Open` option when PyCharm starts, and browsing to your game folder (the one created with `evennia --init`). We refer to it as `mygame` here. +First, install Evennia on your local machine with [[Getting Started]]. If you're new to PyCharm, +loading your project is as easy as selecting the `Open` option when PyCharm starts, and browsing to +your game folder (the one created with `evennia --init`). We refer to it as `mygame` here. -If you want to be able to examine evennia's core code or the scripts inside your virtualenv, you'll need to add them to your project too: +If you want to be able to examine evennia's core code or the scripts inside your virtualenv, you'll +need to add them to your project too: 1. Go to `File > Open...` 1. Select the folder (i.e. the `evennia` root) 1. Select "Open in current window" and "Add to currently opened projects" ## Setting up the project interpreter -It's a good idea to do this before attempting anything further. The rest of this page assumes your project is already configured in PyCharm. +It's a good idea to do this before attempting anything further. The rest of this page assumes your +project is already configured in PyCharm. 1. Go to `File > Settings... > Project: \ > Project Interpreter` 1. Click the Gear symbol `> Add local` @@ -28,53 +35,82 @@ Enjoy seeing all your imports checked properly, setting breakpoints, and live va 1. Launch Evennia in your preferred way (usually from a console/terminal) 1. Open your project in PyCharm 1. In the PyCharm menu, select `Run > Attach to Local Process...` -1. From the list, pick the `twistd` process with the `server.py` parameter (Example: `twistd.exe --nodaemon --logfile=\\server\logs\server.log --python=\\evennia\server\server.py`) +1. From the list, pick the `twistd` process with the `server.py` parameter (Example: `twistd.exe +--nodaemon --logfile=\\server\logs\server.log --python=\\evennia\server\server.py`) -Of course you can attach to the `portal` process as well. If you want to debug the Evennia launcher or runner for some reason (or just learn how they work!), see Run Configuration below. +Of course you can attach to the `portal` process as well. If you want to debug the Evennia launcher +or runner for some reason (or just learn how they work!), see Run Configuration below. -> NOTE: Whenever you reload Evennia, the old Server process will die and a new one start. So when you restart you have to detach from the old and then reattach to the new process that was created. +> NOTE: Whenever you reload Evennia, the old Server process will die and a new one start. So when +you restart you have to detach from the old and then reattach to the new process that was created. -> To make the process less tedious you can apply a filter in settings to show only the server.py process in the list. To do that navigate to: `Settings/Preferences | Build, Execution, Deployment | Python Debugger` and then in `Attach to process` field put in: `twistd.exe" --nodaemon`. This is an example for windows, I don't have a working mac/linux box. +> To make the process less tedious you can apply a filter in settings to show only the server.py +process in the list. To do that navigate to: `Settings/Preferences | Build, Execution, Deployment | +Python Debugger` and then in `Attach to process` field put in: `twistd.exe" --nodaemon`. This is an +example for windows, I don't have a working mac/linux box. ![Example process filter configuration](https://i.imgur.com/vkSheR8.png) ## Setting up an Evennia run configuration -This configuration allows you to launch Evennia from inside PyCharm. Besides convenience, it also allows suspending and debugging the evennia_launcher or evennia_runner at points earlier than you could by running them externally and attaching. In fact by the time the server and/or portal are running the launcher will have exited already. +This configuration allows you to launch Evennia from inside PyCharm. Besides convenience, it also +allows suspending and debugging the evennia_launcher or evennia_runner at points earlier than you +could by running them externally and attaching. In fact by the time the server and/or portal are +running the launcher will have exited already. 1. Go to `Run > Edit Configutations...` 1. Click the plus-symbol to add a new configuration and choose Python -1. Add the script: `\\evenv\Scripts\evennia_launcher.py` (substitute your virtualenv if it's not named `evenv`) +1. Add the script: `\\evenv\Scripts\evennia_launcher.py` (substitute your virtualenv if +it's not named `evenv`) 1. Set script parameters to: `start -l` (-l enables console logging) 1. Ensure the chosen interpreter is from your virtualenv 1. Set Working directory to your `mygame` folder (not evenv nor evennia) -1. You can refer to the PyCharm documentation for general info, but you'll want to set at least a config name (like "MyMUD start" or similar). +1. You can refer to the PyCharm documentation for general info, but you'll want to set at least a +config name (like "MyMUD start" or similar). -Now set up a "stop" configuration by following the same steps as above, but set your Script parameters to: stop (and name the configuration appropriately). +Now set up a "stop" configuration by following the same steps as above, but set your Script +parameters to: stop (and name the configuration appropriately). -A dropdown box holding your new configurations should appear next to your PyCharm run button. Select MyMUD start and press the debug icon to begin debugging. Depending on how far you let the program run, you may need to run your "MyMUD stop" config to actually stop the server, before you'll be able start it again. +A dropdown box holding your new configurations should appear next to your PyCharm run button. +Select MyMUD start and press the debug icon to begin debugging. Depending on how far you let the +program run, you may need to run your "MyMUD stop" config to actually stop the server, before you'll +be able start it again. ## Alternative run configuration - utilizing logfiles as source of data -This configuration takes a bit different approach as instead of focusing on getting the data back through logfiles. Reason for that is this way you can easily separate data streams, for example you rarely want to follow both server and portal at the same time, and this will allow it. This will also make sure to stop the evennia before starting it, essentially working as reload command (it will also include instructions how to disable that part of functionality). We will start by defining a configuration that will stop evennia. This assumes that `upfire` is your pycharm project name, and also the game name, hence the `upfire/upfire` path. +This configuration takes a bit different approach as instead of focusing on getting the data back +through logfiles. Reason for that is this way you can easily separate data streams, for example you +rarely want to follow both server and portal at the same time, and this will allow it. This will +also make sure to stop the evennia before starting it, essentially working as reload command (it +will also include instructions how to disable that part of functionality). We will start by defining +a configuration that will stop evennia. This assumes that `upfire` is your pycharm project name, and +also the game name, hence the `upfire/upfire` path. 1. Go to `Run > Edit Configutations...`\ -1. Click the plus-symbol to add a new configuration and choose the python interpreter to use (should be project default) +1. Click the plus-symbol to add a new configuration and choose the python interpreter to use (should +be project default) 1. Name the configuration as "stop evennia" and fill rest of the fields accordingly to the image: ![Stop run configuration](https://i.imgur.com/gbkXhlG.png) 1. Press `Apply` -Now we will define the start/reload command that will make sure that evennia is not running already, and then start the server in one go. +Now we will define the start/reload command that will make sure that evennia is not running already, +and then start the server in one go. 1. Go to `Run > Edit Configutations...`\ -1. Click the plus-symbol to add a new configuration and choose the python interpreter to use (should be project default) +1. Click the plus-symbol to add a new configuration and choose the python interpreter to use (should +be project default) 1. Name the configuration as "start evennia" and fill rest of the fields accordingly to the image: ![Start run configuration](https://i.imgur.com/5YEjeHq.png) -1. Navigate to the `Logs` tab and add the log files you would like to follow. The picture shows adding `portal.log` which will show itself in `portal` tab when running: +1. Navigate to the `Logs` tab and add the log files you would like to follow. The picture shows +adding `portal.log` which will show itself in `portal` tab when running: ![Configuring logs following](https://i.imgur.com/gWYuOWl.png) 1. Skip the following steps if you don't want the launcher to stop evennia before starting. -1. Head back to `Configuration` tab and press the `+` sign at the bottom, under `Before launch....` and select `Run another configuration` from the submenu that will pop up. +1. Head back to `Configuration` tab and press the `+` sign at the bottom, under `Before launch....` +and select `Run another configuration` from the submenu that will pop up. 1. Click `stop evennia` and make sure that it's added to the list like on the image above. 1. Click `Apply` and close the run configuration window. -You are now ready to go, and if you will fire up `start evennia` configuration you should see following in the bottom panel: +You are now ready to go, and if you will fire up `start evennia` configuration you should see +following in the bottom panel: ![Example of running alternative configuration](https://i.imgur.com/nTfpC04.png) -and you can click through the tabs to check appropriate logs, or even the console output as it is still running in interactive mode. \ No newline at end of file +and you can click through the tabs to check appropriate logs, or even the console output as it is +still running in interactive mode. \ No newline at end of file diff --git a/docs/source/Signals.md b/docs/source/Signals.md index dfc3da8f25..8b027d0a17 100644 --- a/docs/source/Signals.md +++ b/docs/source/Signals.md @@ -54,22 +54,28 @@ signals.SIGNAL_ACCOUNT_POST_CONNECT.connect(myhandler, account) ## Available signals -All signals (including some django-specific defaults) are available in the module `evennia.server.signals` -(with a shortcut `evennia.signals`). Signals are named by the sender type. So `SIGNAL_ACCOUNT_*` returns -`Account` instances as senders, `SIGNAL_OBJECT_*` returns `Object`s etc. Extra keywords (kwargs) should +All signals (including some django-specific defaults) are available in the module +`evennia.server.signals` +(with a shortcut `evennia.signals`). Signals are named by the sender type. So `SIGNAL_ACCOUNT_*` +returns +`Account` instances as senders, `SIGNAL_OBJECT_*` returns `Object`s etc. Extra keywords (kwargs) +should be extracted from the `**kwargs` dict in the signal handler. - `SIGNAL_ACCOUNT_POST_CREATE` - this is triggered at the very end of `Account.create()`. Note that - calling `evennia.create.create_account` (which is called internally by `Account.create`) will *not* + calling `evennia.create.create_account` (which is called internally by `Account.create`) will +*not* trigger this signal. This is because using `Account.create()` is expected to be the most commonly used way for users to themselves create accounts during login. It passes and extra kwarg `ip` with the client IP of the connecting account. - `SIGNAL_ACCOUNT_POST_LOGIN` - this will always fire when the account has authenticated. Sends extra kwarg `session` with the new [Session](./Sessions) object involved. -- `SIGNAL_ACCCOUNT_POST_FIRST_LOGIN` - this fires just before `SIGNAL_ACCOUNT_POST_LOGIN` but only if +- `SIGNAL_ACCCOUNT_POST_FIRST_LOGIN` - this fires just before `SIGNAL_ACCOUNT_POST_LOGIN` but only +if this is the *first* connection done (that is, if there are no previous sessions connected). Also passes the `session` along as a kwarg. -- `SIGNAL_ACCOUNT_POST_LOGIN_FAIL` - sent when someone tried to log into an account by failed. Passes +- `SIGNAL_ACCOUNT_POST_LOGIN_FAIL` - sent when someone tried to log into an account by failed. +Passes the `session` as an extra kwarg. - `SIGNAL_ACCOUNT_POST_LOGOUT` - always fires when an account logs off, no matter if other sessions remain or not. Passes the disconnecting `session` along as a kwarg. @@ -81,16 +87,19 @@ be extracted from the `**kwargs` dict in the signal handler. `session` and `account`. - `SIGNAL_ACCOUNT_POST_RENAME` - triggered by the setting of `Account.username`. Passes extra kwargs `old_name`, `new_name`. -- `SIGNAL_TYPED_OBJECT_POST_RENAME` - triggered when any Typeclassed entity's `key` is changed. Extra +- `SIGNAL_TYPED_OBJECT_POST_RENAME` - triggered when any Typeclassed entity's `key` is changed. +Extra kwargs passed are `old_key` and `new_key`. - `SIGNAL_SCRIPT_POST_CREATE` - fires when a script is first created, after any hooks. - `SIGNAL_CHANNEL_POST_CREATE` - fires when a Channel is first created, after any hooks. - `SIGNAL_HELPENTRY_POST_CREATE` - fires when a help entry is first created. -The `evennia.signals` module also gives you conveneient access to the default Django signals (these use a +The `evennia.signals` module also gives you conveneient access to the default Django signals (these +use a different naming convention). -- `pre_save` - fired when any database entitiy's `.save` method fires, before any saving has happened. +- `pre_save` - fired when any database entitiy's `.save` method fires, before any saving has +happened. - `post_save` - fires after saving a database entity. - `pre_delete` - fires just before a database entity is deleted. - `post_delete` - fires after a database entity was deleted. diff --git a/docs/source/Spawner-and-Prototypes.md b/docs/source/Spawner-and-Prototypes.md index 12ca1a5209..acef957d4c 100644 --- a/docs/source/Spawner-and-Prototypes.md +++ b/docs/source/Spawner-and-Prototypes.md @@ -39,42 +39,50 @@ for more information. Below are further details about how prototypes work and ho ## The prototype -The prototype dictionary can either be created for you by the OLC (see above), be written manually in a Python module (and then referenced by the `@spawn` command/OLC), or created on-the-fly and manually loaded into the spawner function or `@spawn` command. +The prototype dictionary can either be created for you by the OLC (see above), be written manually +in a Python module (and then referenced by the `@spawn` command/OLC), or created on-the-fly and +manually loaded into the spawner function or `@spawn` command. -The dictionary defines all possible database-properties of an Object. It has a fixed set of allowed keys. When preparing to store the prototype in the database (or when using the OLC), some -of these keys are mandatory. When just passing a one-time prototype-dict to the spawner the system is -more lenient and will use defaults for keys not explicitly provided. +The dictionary defines all possible database-properties of an Object. It has a fixed set of allowed +keys. When preparing to store the prototype in the database (or when using the OLC), some +of these keys are mandatory. When just passing a one-time prototype-dict to the spawner the system +is +more lenient and will use defaults for keys not explicitly provided. -In dictionary form, a prototype can look something like this: +In dictionary form, a prototype can look something like this: ```python -{ +{ "prototype_key": "house" "key": "Large house" "typeclass": "typeclasses.rooms.house.House" } ``` -If you wanted to load it into the spawner in-game you could just put all on one line: +If you wanted to load it into the spawner in-game you could just put all on one line: @spawn {"prototype_key="house", "key": "Large house", ...} > Note that the prototype dict as given on the command line must be a valid Python structure - -so you need to put quotes around strings etc. For security reasons, a dict inserted from-in game cannot have any +so you need to put quotes around strings etc. For security reasons, a dict inserted from-in game +cannot have any other advanced Python functionality, such as executable code, `lambda` etc. If builders are supposed -to be able to use such features, you need to offer them through [$protfuncs](./Spawner-and-Prototypes#protfuncs), embedded runnable functions that you have full control to check and vet before running. +to be able to use such features, you need to offer them through [$protfuncs](Spawner-and- +Prototypes#protfuncs), embedded runnable functions that you have full control to check and vet +before running. ### Prototype keys All keys starting with `prototype_` are for book keeping. - `prototype_key` - the 'name' of the prototype. While this can sometimes be skipped (such as when - defining a prototype in a module or feeding a prototype-dict manually to the spawner function), it's good - practice to try to include this. It is used for book-keeping and storing of the prototype so you + defining a prototype in a module or feeding a prototype-dict manually to the spawner function), +it's good + practice to try to include this. It is used for book-keeping and storing of the prototype so you can find it later. - `prototype_parent` - If given, this should be the `prototype_key` of another prototype stored in the system or available in a module. This makes this prototype *inherit* the keys from the parent and only override what is needed. Give a tuple `(parent1, parent2, ...)` for multiple - left-right inheritance. If this is not given, a `typeclass` should usually be defined (below). + left-right inheritance. If this is not given, a `typeclass` should usually be defined (below). - `prototype_desc` - this is optional and used when listing the prototype in in-game listings. - `protototype_tags` - this is optional and allows for tagging the prototype in order to find it easier later. @@ -84,19 +92,26 @@ All keys starting with `prototype_` are for book keeping. The remaining keys determine actual aspects of the objects to spawn from this prototype: - - `key` - the main object identifier. Defaults to "Spawned Object *X*", where *X* is a random integer. - - `typeclass` - A full python-path (from your gamedir) to the typeclass you want to use. If not set, the `prototype_parent` should be - defined, with `typeclass` defined somewhere in the parent chain. When creating a one-time prototype - dict just for spawning, one could omit this - `settings.BASE_OBJECT_TYPECLASS` will be used instead. + - `key` - the main object identifier. Defaults to "Spawned Object *X*", where *X* is a random +integer. + - `typeclass` - A full python-path (from your gamedir) to the typeclass you want to use. If not +set, the `prototype_parent` should be + defined, with `typeclass` defined somewhere in the parent chain. When creating a one-time +prototype + dict just for spawning, one could omit this - `settings.BASE_OBJECT_TYPECLASS` will be used +instead. - `location` - this should be a `#dbref`. - - `home` - a valid `#dbref`. Defaults to `location` or `settings.DEFAULT_HOME` if location does not exist. + - `home` - a valid `#dbref`. Defaults to `location` or `settings.DEFAULT_HOME` if location does not +exist. - `destination` - a valid `#dbref`. Only used by exits. - `permissions` - list of permission strings, like `["Accounts", "may_use_red_door"]` - `locks` - a [lock-string](./Locks) like `"edit:all();control:perm(Builder)"` - `aliases` - list of strings for use as aliases - `tags` - list [Tags](./Tags). These are given as tuples `(tag, category, data)`. - - `attrs` - list of [Attributes](./Attributes). These are given as tuples `(attrname, value, category, lockstring)` - - Any other keywords are interpreted as non-category [Attributes](./Attributes) and their values. This is + - `attrs` - list of [Attributes](./Attributes). These are given as tuples `(attrname, value, +category, lockstring)` + - Any other keywords are interpreted as non-category [Attributes](./Attributes) and their values. +This is convenient for simple Attributes - use `attrs` for full control of Attributes. Deprecated as of Evennia 0.8: @@ -117,7 +132,8 @@ It can be a hard-coded value: ``` -It can also be a *callable*. This callable is called without arguments whenever the prototype is used to +It can also be a *callable*. This callable is called without arguments whenever the prototype is +used to spawn a new object: ```python @@ -135,18 +151,21 @@ prototype: #### Protfuncs -Finally, the value can be a *prototype function* (*Protfunc*). These look like simple function calls that you embed in strings and that has a `$` in front, like +Finally, the value can be a *prototype function* (*Protfunc*). These look like simple function calls +that you embed in strings and that has a `$` in front, like ```python {"key": "$choice(Urfgar, Rick the smelly, Blargh the foul)", "attrs": {"desc": "This is a large $red(and very red) demon. " "He has $randint(2,5) skulls in a chain around his neck."} ``` -At execution time, the place of the protfunc will be replaced with the result of that protfunc being called (this is always a string). A protfunc works in much the same way as an +At execution time, the place of the protfunc will be replaced with the result of that protfunc being +called (this is always a string). A protfunc works in much the same way as an [InlineFunc](./TextTags#inline-functions) - they are actually -parsed using the same parser - except protfuncs are run every time the prototype is used to spawn a new object (whereas an inlinefunc is called when a text is returned to the user). +parsed using the same parser - except protfuncs are run every time the prototype is used to spawn a +new object (whereas an inlinefunc is called when a text is returned to the user). -Here is how a protfunc is defined (same as an inlinefunc). +Here is how a protfunc is defined (same as an inlinefunc). ```python # this is a silly example, you can just color the text red with |r directly! @@ -160,9 +179,13 @@ def red(*args, **kwargs): return "|r{}|n".format(args[0]) ``` -> Note that we must make sure to validate input and raise `ValueError` if that fails. Also, it is *not* possible to use keywords in the call to the protfunc (so something like `$echo(text, align=left)` is invalid). The `kwargs` requred is for internal evennia use and not used at all for protfuncs (only by inlinefuncs). +> Note that we must make sure to validate input and raise `ValueError` if that fails. Also, it is +*not* possible to use keywords in the call to the protfunc (so something like `$echo(text, +align=left)` is invalid). The `kwargs` requred is for internal evennia use and not used at all for +protfuncs (only by inlinefuncs). -To make this protfunc available to builders in-game, add it to a new module and add the path to that module to `settings.PROT_FUNC_MODULES`: +To make this protfunc available to builders in-game, add it to a new module and add the path to that +module to `settings.PROT_FUNC_MODULES`: ```python # in mygame/server/conf/settings.py @@ -170,64 +193,85 @@ To make this protfunc available to builders in-game, add it to a new module and PROT_FUNC_MODULES += ["world.myprotfuncs"] ``` -All *global callables* in your added module will be considered a new protfunc. To avoid this (e.g. to have helper functions that are not protfuncs on their own), name your function something starting with `_`. +All *global callables* in your added module will be considered a new protfunc. To avoid this (e.g. +to have helper functions that are not protfuncs on their own), name your function something starting +with `_`. -The default protfuncs available out of the box are defined in `evennia/prototypes/profuncs.py`. To override the ones available, just add the same-named function in your own protfunc module. +The default protfuncs available out of the box are defined in `evennia/prototypes/profuncs.py`. To +override the ones available, just add the same-named function in your own protfunc module. -| Protfunc | Description | +| Protfunc | Description | | `$random()` | Returns random value in range [0, 1) | | `$randint(start, end)` | Returns random value in range [start, end] | | `$left_justify()` | Left-justify text | | `$right_justify()` | Right-justify text to screen width | | `$center_justify()` | Center-justify text to screen width | -| `$full_justify()` | Spread text across screen width by adding spaces | +| `$full_justify()` | Spread text across screen width by adding spaces | | `$protkey()` | Returns value of another key in this prototype (self-reference) | | `$add(, )` | Returns value1 + value2. Can also be lists, dicts etc | -| `$sub(, )` | Returns value1 - value2 | +| `$sub(, )` | Returns value1 - value2 | | `$mult(, )` | Returns value1 * value2 | | `$div(, )` | Returns value2 / value1 | | `$toint()` | Returns value converted to integer (or value if not possible) | -| `$eval()` | Returns result of [literal-eval](https://docs.python.org/2/library/ast.html#ast.literal_eval) of code string. Only simple python expressions. | -| `$obj()` | Returns object #dbref searched globally by key, tag or #dbref. Error if more than one found." | +| `$eval()` | Returns result of [literal- +eval](https://docs.python.org/2/library/ast.html#ast.literal_eval) of code string. Only simple +python expressions. | +| `$obj()` | Returns object #dbref searched globally by key, tag or #dbref. Error if more +than one found." | | `$objlist()` | Like `$obj`, except always returns a list of zero, one or more results. | | `$dbref(dbref)` | Returns argument if it is formed as a #dbref (e.g. #1234), otherwise error. -For developers with access to Python, using protfuncs in prototypes is generally not useful. Passing real Python functions is a lot more powerful and flexible. Their main use is to allow in-game builders to +For developers with access to Python, using protfuncs in prototypes is generally not useful. Passing +real Python functions is a lot more powerful and flexible. Their main use is to allow in-game +builders to do limited coding/scripting for their prototypes without giving them direct access to raw Python. ## Storing prototypes -A prototype can be defined and stored in two ways, either in the database or as a dict in a module. +A prototype can be defined and stored in two ways, either in the database or as a dict in a module. ### Database prototypes -Stored as [Scripts](./Scripts) in the database. These are sometimes referred to as *database-prototypes* This is the only way for in-game builders to modify and add prototypes. They have the advantage of being easily modifiable and sharable between builders but you need to work with them using in-game tools. +Stored as [Scripts](./Scripts) in the database. These are sometimes referred to as *database- +prototypes* This is the only way for in-game builders to modify and add prototypes. They have the +advantage of being easily modifiable and sharable between builders but you need to work with them +using in-game tools. ### Module-based prototypes -These prototypes are defined as dictionaries assigned to global variables in one of the modules defined in `settings.PROTOTYPE_MODULES`. They can only be modified from outside the game so they are are necessarily "read-only" from in-game and cannot be modified (but copies of them could be made into database-prototypes). These were the only prototypes available before Evennia 0.8. Module based prototypes can be useful in order for developers to provide read-only "starting" or "base" prototypes to build from or if they just prefer to work offline in an external code editor. +These prototypes are defined as dictionaries assigned to global variables in one of the modules +defined in `settings.PROTOTYPE_MODULES`. They can only be modified from outside the game so they are +are necessarily "read-only" from in-game and cannot be modified (but copies of them could be made +into database-prototypes). These were the only prototypes available before Evennia 0.8. Module based +prototypes can be useful in order for developers to provide read-only "starting" or "base" +prototypes to build from or if they just prefer to work offline in an external code editor. -By default `mygame/world/prototypes.py` is set up for you to add your own prototypes. *All global dicts* in this module will be considered by Evennia to be a prototype. You could also tell Evennia to look for prototypes in more modules if you want: +By default `mygame/world/prototypes.py` is set up for you to add your own prototypes. *All global +dicts* in this module will be considered by Evennia to be a prototype. You could also tell Evennia +to look for prototypes in more modules if you want: ```python -# in mygame/server/conf.py +# in mygame/server/conf/settings.py -PROTOTYPE_MODULES = += ["world.myownprototypes", "combat.prototypes"] +PROTOTYPE_MODULES += ["world.myownprototypes", "combat.prototypes"] ``` +> Note the += operator in the above example. This will extend the already defined `world.prototypes` +definition in the settings_default.py file in Evennia. If you would like to completely override the +location of your `PROTOTYPE_MODULES` then set this to just = without the addition operator. -Here is an example of a prototype defined in a module: +Here is an example of a prototype defined in a module: - ```python +```python # in a module Evennia looks at for prototypes, # (like mygame/world/prototypes.py) ORC_SHAMAN = {"key":"Orc shaman", - "typeclass": "typeclasses.monsters.Orc", - "weapon": "wooden staff", - "health": 20} - ``` + "typeclass": "typeclasses.monsters.Orc", + "weapon": "wooden staff", + "health": 20} +``` > Note that in the example above, `"ORC_SHAMAN"` will become the `prototype_key` of this prototype. > It's the only case when `prototype_key` can be skipped in a prototype. However, if `prototype_key` @@ -246,12 +290,15 @@ you can spawn a new goblin with You can also specify the prototype directly as a valid Python dictionary: @spawn {"prototype_key": "shaman", \ - "key":"Orc shaman", \ + "key":"Orc shaman", \ "prototype_parent": "goblin", \ "weapon": "wooden staff", \ "health": 20} -> Note: The `@spawn` command is more lenient about the prototype dictionary than shown here. So you can for example skip the `prototype_key` if you are just testing a throw-away prototype. A random hash will be used to please the validation. You could also skip `prototype_parent/typeclass` - then the typeclass given by `settings.BASE_OBJECT_TYPECLASS` will be used. +> Note: The `@spawn` command is more lenient about the prototype dictionary than shown here. So you +can for example skip the `prototype_key` if you are just testing a throw-away prototype. A random +hash will be used to please the validation. You could also skip `prototype_parent/typeclass` - then +the typeclass given by `settings.BASE_OBJECT_TYPECLASS` will be used. ## Using evennia.prototypes.spawner() @@ -261,17 +308,25 @@ In code you access the spawner mechanism directly via the call new_objects = evennia.prototypes.spawner.spawn(*prototypes) ``` -All arguments are prototype dictionaries. The function will return a -matching list of created objects. Example: +All arguments are prototype dictionaries or the unique `prototype_key`s of prototypes +known to the system (either database- or module-based). The function will return a matching list of +created objects. Example: ```python - obj1, obj2 = evennia.prototypes.spawner.spawn({"key": "Obj1", "desc": "A test"}, - {"key": "Obj2", "desc": "Another test"}) + obj1, obj2, obj3 = evennia.prototypes.spawner.spawn({"key": "Obj1", "desc": "A test"}, + {"key": "Obj2", "desc": "Another test"}, + "GOBLIN_SHAMAN") ``` -> Hint: Same as when using `@spawn`, when spawning from a one-time prototype dict like this, you can skip otherwise required keys, like `prototype_key` or `typeclass`/`prototype_parent`. Defaults will be used. +> Hint: Same as when using `@spawn`, when spawning from a one-time prototype dict like this, you can +skip otherwise required keys, like `prototype_key` or `typeclass`/`prototype_parent`. Defaults will +be used. -Note that no `location` will be set automatically when using `evennia.prototypes.spawner.spawn()`, you +Note that no `location` will be set automatically when using `evennia.prototypes.spawner.spawn()`, +you have to specify `location` explicitly in the prototype dict. -If the prototypes you supply are using `prototype_parent` keywords, the spawner will read prototypes from modules -in `settings.PROTOTYPE_MODULES` as well as those saved to the database to determine the body of available parents. The `spawn` command takes many optional keywords, you can find its definition [in the api docs](github:evennia.prototypes.spawner#spawn). \ No newline at end of file +If the prototypes you supply are using `prototype_parent` keywords, the spawner will read prototypes +from modules +in `settings.PROTOTYPE_MODULES` as well as those saved to the database to determine the body of +available parents. The `spawn` command takes many optional keywords, you can find its definition [in +the api docs](github:evennia.prototypes.spawner#spawn). \ No newline at end of file diff --git a/docs/source/Start-Stop-Reload.md b/docs/source/Start-Stop-Reload.md index e8e90448b4..de92ebf07b 100644 --- a/docs/source/Start-Stop-Reload.md +++ b/docs/source/Start-Stop-Reload.md @@ -5,7 +5,8 @@ You control Evennia from your game folder (we refer to it as `mygame/` here), us program. If the `evennia` program is not available on the command line you must first install Evennia as described in the [Getting Started](./Getting-Started) page. -> Hint: If you ever try the `evennia` command and get an error complaining that the command is not available, make sure your [virtualenv](./Glossary#virtualenv) is active. +> Hint: If you ever try the `evennia` command and get an error complaining that the command is not +available, make sure your [virtualenv](./Glossary#virtualenv) is active. Below are described the various management options. Run @@ -60,12 +61,14 @@ Evennia under the control of some other type of process. ## Reloading The act of *reloading* means the Portal will tell the Server to shut down and then boot it back up -again. Everyone will get a message and the game will be briefly paused for all accounts as the server +again. Everyone will get a message and the game will be briefly paused for all accounts as the +server reboots. Since they are connected to the *Portal*, their connections are not lost. Reloading is as close to a "warm reboot" you can get. It reinitializes all code of Evennia, but -doesn't kill "persistent" [Scripts](./Scripts). It also calls `at_server_reload()` hooks on all objects so you +doesn't kill "persistent" [Scripts](./Scripts). It also calls `at_server_reload()` hooks on all +objects so you can save eventual temporary properties you want. From in-game the `@reload` command is used. You can also reload the server from outside the game: @@ -78,7 +81,8 @@ blocks in-game input. ## Resetting *Resetting* is the equivalent of a "cold reboot" - the Server will shut down and then restarted -again, but will behave as if it was fully shut down. As opposed to a "real" shutdown, no accounts will be disconnected during a +again, but will behave as if it was fully shut down. As opposed to a "real" shutdown, no accounts +will be disconnected during a reset. A reset will however purge all non-persistent scripts and will call `at_server_shutdown()` hooks. It can be a good way to clean unsafe scripts during development, for example. @@ -143,7 +147,8 @@ Note that this functionality is not supported on Windows. ## Django options -The `evennia` program will also pass-through options used by the `django-admin`. These operate on the database in various ways. +The `evennia` program will also pass-through options used by the `django-admin`. These operate on +the database in various ways. ```bash @@ -153,7 +158,8 @@ The `evennia` program will also pass-through options used by the `django-admin`. ``` -For (many) more options, see [the django-admin docs](https://docs.djangoproject.com/en/1.7/ref/django-admin/#usage). +For (many) more options, see [the django-admin +docs](https://docs.djangoproject.com/en/1.7/ref/django-admin/#usage). ## Advanced handling of Evennia processes diff --git a/docs/source/Static-In-Game-Map.md b/docs/source/Static-In-Game-Map.md index c70cc53034..a0c4e3d1b0 100644 --- a/docs/source/Static-In-Game-Map.md +++ b/docs/source/Static-In-Game-Map.md @@ -3,17 +3,30 @@ ## Introduction -This tutorial describes the creation of an in-game map display based on a pre-drawn map. It also details how to use the [Batch code processor](./Batch-Code-Processor) for advanced building. There is also the [Dynamic in-game map tutorial](./Dynamic-In-Game-Map) that works in the opposite direction, by generating a map from an existing grid of rooms. +This tutorial describes the creation of an in-game map display based on a pre-drawn map. It also +details how to use the [Batch code processor](./Batch-Code-Processor) for advanced building. There is +also the [Dynamic in-game map tutorial](./Dynamic-In-Game-Map) that works in the opposite direction, +by generating a map from an existing grid of rooms. -Evennia does not require its rooms to be positioned in a "logical" way. Your exits could be named anything. You could make an exit "west" that leads to a room described to be in the far north. You could have rooms inside one another, exits leading back to the same room or describing spatial geometries impossible in the real world. +Evennia does not require its rooms to be positioned in a "logical" way. Your exits could be named +anything. You could make an exit "west" that leads to a room described to be in the far north. You +could have rooms inside one another, exits leading back to the same room or describing spatial +geometries impossible in the real world. -That said, most games *do* organize their rooms in a logical fashion, if nothing else to retain the sanity of their players. And when they do, the game becomes possible to map. This tutorial will give an example of a simple but flexible in-game map system to further help player's to navigate. We will +That said, most games *do* organize their rooms in a logical fashion, if nothing else to retain the +sanity of their players. And when they do, the game becomes possible to map. This tutorial will give +an example of a simple but flexible in-game map system to further help player's to navigate. We will -To simplify development and error-checking we'll break down the work into bite-size chunks, each building on what came before. For this we'll make extensive use of the [Batch code processor](./Batch-Code-Processor), so you may want to familiarize yourself with that. +To simplify development and error-checking we'll break down the work into bite-size chunks, each +building on what came before. For this we'll make extensive use of the [Batch code processor](Batch- +Code-Processor), so you may want to familiarize yourself with that. -1. **Planning the map** - Here we'll come up with a small example map to use for the rest of the tutorial. -2. **Making a map object** - This will showcase how to make a static in-game "map" object a Character could pick up and look at. -3. **Building the map areas** - Here we'll actually create the small example area according to the map we designed before. +1. **Planning the map** - Here we'll come up with a small example map to use for the rest of the +tutorial. +2. **Making a map object** - This will showcase how to make a static in-game "map" object a +Character could pick up and look at. +3. **Building the map areas** - Here we'll actually create the small example area according to the +map we designed before. 4. **Map code** - This will link the map to the location so our output looks something like this: ``` @@ -27,15 +40,26 @@ To simplify development and error-checking we'll break down the work into bite-s Exits: north(#8), east(#9), south(#10), west(#11) ``` -We will henceforth assume your game folder is name named `mygame` and that you haven't modified the default commands. We will also not be using [Colors](./TextTags#colored-text) for our map since they don't show in the documentation wiki. +We will henceforth assume your game folder is name named `mygame` and that you haven't modified the +default commands. We will also not be using [Colors](./TextTags#colored-text) for our map since they +don't show in the documentation wiki. ## Planning the Map -Let's begin with the fun part! Maps in MUDs come in many different [shapes and sizes](http://journal.imaginary-realities.com/volume-05/issue-01/modern-interface-modern-mud/index.html). Some appear as just boxes connected by lines. Others have complex graphics that are external to the game itself. +Let's begin with the fun part! Maps in MUDs come in many different [shapes and +sizes](http://journal.imaginary-realities.com/volume-05/issue-01/modern-interface-modern- +mud/index.html). Some appear as just boxes connected by lines. Others have complex graphics that are +external to the game itself. -Our map will be in-game text but that doesn't mean we're restricted to the normal alphabet! If you've ever selected the [Wingdings font](https://en.wikipedia.org/wiki/Wingdings) in Microsoft Word you will know there are a multitude of other characters around to use. When creating your game with Evennia you have access to the [UTF-8 character encoding](https://en.wikipedia.org/wiki/UTF-8) which put at your disposal [thousands of letters, number and geometric shapes](http://mcdlr.com/utf-8/#1). +Our map will be in-game text but that doesn't mean we're restricted to the normal alphabet! If +you've ever selected the [Wingdings font](https://en.wikipedia.org/wiki/Wingdings) in Microsoft Word +you will know there are a multitude of other characters around to use. When creating your game with +Evennia you have access to the [UTF-8 character encoding](https://en.wikipedia.org/wiki/UTF-8) which +put at your disposal [thousands of letters, number and geometric shapes](http://mcdlr.com/utf-8/#1). -For this exercise, we've copy-and-pasted from the pallet of special characters used over at [Dwarf Fortress](http://dwarffortresswiki.org/index.php/Character_table) to create what is hopefully a pleasing and easy to understood landscape: +For this exercise, we've copy-and-pasted from the pallet of special characters used over at [Dwarf +Fortress](http://dwarffortresswiki.org/index.php/Character_table) to create what is hopefully a +pleasing and easy to understood landscape: ``` ≈≈↑↑↑↑↑∩∩ @@ -45,23 +69,42 @@ For this exercise, we've copy-and-pasted from the pallet of special characters u ≈≈≈↑│↑∩∩∩ And down the bottom is a camp site with tents. ≈≈O─O─O⌂∩ In the center is the starting location, a crossroads ≈≈≈↑│↑∩∩∩ which connect the four other areas. -≈≈↑▲O▲↑∩∩ +≈≈↑▲O▲↑∩∩ ≈≈↑↑▲↑↑∩∩ ≈≈↑↑↑↑↑∩∩ ``` -There are many considerations when making a game map depending on the play style and requirements you intend to implement. Here we will display a 5x5 character map of the area surrounding the account. This means making sure to account for 2 characters around every visitable location. Good planning at this stage can solve many problems before they happen. +There are many considerations when making a game map depending on the play style and requirements +you intend to implement. Here we will display a 5x5 character map of the area surrounding the +account. This means making sure to account for 2 characters around every visitable location. Good +planning at this stage can solve many problems before they happen. ## Creating a Map Object -In this section we will try to create an actual "map" object that an account can pick up and look at. +In this section we will try to create an actual "map" object that an account can pick up and look +at. -Evennia offers a range of [default commands](./Default-Command-Help) for [creating objects and rooms in-game](./Building-Quickstart). While readily accessible, these commands are made to do very specific, restricted things and will thus not offer as much flexibility to experiment (for an advanced exception see [in-line functions](./TextTags#new-inlinefuncs)). Additionally, entering long descriptions and properties over and over in the game client can become tedious; especially when testing and you may want to delete and recreate things over and over. +Evennia offers a range of [default commands](./Default-Command-Help) for [creating objects and rooms +in-game](Building-Quickstart). While readily accessible, these commands are made to do very +specific, restricted things and will thus not offer as much flexibility to experiment (for an +advanced exception see [in-line functions](./TextTags#new-inlinefuncs)). Additionally, entering long +descriptions and properties over and over in the game client can become tedious; especially when +testing and you may want to delete and recreate things over and over. -To overcome this, Evennia offers [batch processors](./Batch-Processors) that work as input-files created out-of-game. In this tutorial we'll be using the more powerful of the two available batch processors, the [Batch Code Processor ](./Batch-Code-Processor), called with the `@batchcode` command. This is a very powerful tool. It allows you to craft Python files to act as blueprints of your entire game world. These files have access to use Evennia's Python API directly. Batchcode allows for easy editing and creation in whatever text editor you prefer, avoiding having to manually build the world line-by-line inside the game. +To overcome this, Evennia offers [batch processors](./Batch-Processors) that work as input-files +created out-of-game. In this tutorial we'll be using the more powerful of the two available batch +processors, the [Batch Code Processor ](./Batch-Code-Processor), called with the `@batchcode` command. +This is a very powerful tool. It allows you to craft Python files to act as blueprints of your +entire game world. These files have access to use Evennia's Python API directly. Batchcode allows +for easy editing and creation in whatever text editor you prefer, avoiding having to manually build +the world line-by-line inside the game. -> Important warning: `@batchcode`'s power is only rivaled by the `@py` command. Batchcode is so powerful it should be reserved only for the [superuser](./Building-Permissions). Think carefully before you let others (such as `Developer`- level staff) run `@batchcode` on their own - make sure you are okay with them running *arbitrary Python code* on your server. +> Important warning: `@batchcode`'s power is only rivaled by the `@py` command. Batchcode is so +powerful it should be reserved only for the [superuser](./Building-Permissions). Think carefully +before you let others (such as `Developer`- level staff) run `@batchcode` on their own - make sure +you are okay with them running *arbitrary Python code* on your server. -While a simple example, the map object it serves as good way to try out `@batchcode`. Go to `mygame/world` and create a new file there named `batchcode_map.py`: +While a simple example, the map object it serves as good way to try out `@batchcode`. Go to +`mygame/world` and create a new file there named `batchcode_map.py`: ```Python # mygame/world/batchcode_map.py @@ -69,7 +112,7 @@ While a simple example, the map object it serves as good way to try out `@batchc from evennia import create_object from evennia import DefaultObject -# We use the create_object function to call into existence a +# We use the create_object function to call into existence a # DefaultObject named "Map" wherever you are standing. map = create_object(DefaultObject, key="Map", location=caller.location) @@ -93,19 +136,25 @@ map.db.desc = """ caller.msg("A map appears out of thin air and falls to the ground.") ``` -Log into your game project as the superuser and run the command +Log into your game project as the superuser and run the command ``` @batchcode batchcode_map ``` -This will load your `batchcode_map.py` file and execute the code (Evennia will look in your `world/` folder automatically so you don't need to specify it). +This will load your `batchcode_map.py` file and execute the code (Evennia will look in your `world/` +folder automatically so you don't need to specify it). -A new map object should have appeared on the ground. You can view the map by using `look map`. Let's take it with the `get map` command. We'll need it in case we get lost! +A new map object should have appeared on the ground. You can view the map by using `look map`. Let's +take it with the `get map` command. We'll need it in case we get lost! ## Building the map areas -We've just used batchcode to create an object useful for our adventures. But the locations on that map does not actually exist yet - we're all mapped up with nowhere to go! Let's use batchcode to build a game area based on our map. We have five areas outlined: a castle, a cottage, a campsite, a coastal beach and the crossroads which connects them. Create a new batchcode file for this in `mygame/world`, named `batchcode_world.py`. +We've just used batchcode to create an object useful for our adventures. But the locations on that +map does not actually exist yet - we're all mapped up with nowhere to go! Let's use batchcode to +build a game area based on our map. We have five areas outlined: a castle, a cottage, a campsite, a +coastal beach and the crossroads which connects them. Create a new batchcode file for this in +`mygame/world`, named `batchcode_world.py`. ```Python # mygame/world/batchcode_world.py @@ -130,17 +179,17 @@ To the north looms a mighty castle. To the south the glow of a campfire can be s To the east lie a wall of mountains and to the west the dull roar of the open sea. """ -# Here we are creating exits from the centre "crossroads" location to -# destinations to the north, east, south, and west. We will be able +# Here we are creating exits from the centre "crossroads" location to +# destinations to the north, east, south, and west. We will be able # to use the exit by typing it's key e.g. "north" or an alias e.g. "n". -centre_north = create_object(exits.Exit, key="north", +centre_north = create_object(exits.Exit, key="north", aliases=["n"], location=centre, destination=north) -centre_east = create_object(exits.Exit, key="east", +centre_east = create_object(exits.Exit, key="east", aliases=["e"], location=centre, destination=east) -centre_south = create_object(exits.Exit, key="south", +centre_south = create_object(exits.Exit, key="south", aliases=["s"], location=centre, destination=south) -centre_west = create_object(exits.Exit, key="west", +centre_west = create_object(exits.Exit, key="west", aliases=["w"], location=centre, destination=west) # Now we repeat this for the other rooms we'll be implementing. @@ -148,47 +197,57 @@ centre_west = create_object(exits.Exit, key="west", north.db.desc = "An impressive castle surrounds you. " \ "There might be a princess in one of these towers." -north_south = create_object(exits.Exit, key="south", +north_south = create_object(exits.Exit, key="south", aliases=["s"], location=north, destination=centre) # This is where we set up the eastern cottage. east.db.desc = "A cosy cottage nestled among mountains " \ "stretching east as far as the eye can see." -east_west = create_object(exits.Exit, key="west", +east_west = create_object(exits.Exit, key="west", aliases=["w"], location=east, destination=centre) # This is where we set up the southern camp. south.db.desc = "Surrounding a clearing are a number of " \ "tribal tents and at their centre a roaring fire." -south_north = create_object(exits.Exit, key="north", +south_north = create_object(exits.Exit, key="north", aliases=["n"], location=south, destination=centre) # This is where we set up the western coast. west.db.desc = "The dark forest halts to a sandy beach. " \ "The sound of crashing waves calms the soul." -west_east = create_object(exits.Exit, key="east", +west_east = create_object(exits.Exit, key="east", aliases=["e"], location=west, destination=centre) # Lastly, lets make an entrance to our world from the default Limbo room. limbo = search_object('Limbo')[0] -limbo_exit = create_object(exits.Exit, key="enter world", +limbo_exit = create_object(exits.Exit, key="enter world", aliases=["enter"], location=limbo, destination=centre) ``` -Apply this new batch code with `@batchcode batchcode_world`. If there are no errors in the code we now have a nice mini-world to explore. Remember that if you get lost you can look at the map we created! +Apply this new batch code with `@batchcode batchcode_world`. If there are no errors in the code we +now have a nice mini-world to explore. Remember that if you get lost you can look at the map we +created! ## In-game minimap -Now we have a landscape and matching map, but what we really want is a mini-map that displays whenever we move to a room or use the `look` command. +Now we have a landscape and matching map, but what we really want is a mini-map that displays +whenever we move to a room or use the `look` command. -We *could* manually enter a part of the map into the description of every room like we did our map object description. But some MUDs have tens of thousands of rooms! Besides, if we ever changed our map we would have to potentially alter a lot of those room descriptions manually to match the change. So instead we will make one central module to hold our map. Rooms will reference this central location on creation and the map changes will thus come into effect when next running our batchcode. +We *could* manually enter a part of the map into the description of every room like we did our map +object description. But some MUDs have tens of thousands of rooms! Besides, if we ever changed our +map we would have to potentially alter a lot of those room descriptions manually to match the +change. So instead we will make one central module to hold our map. Rooms will reference this +central location on creation and the map changes will thus come into effect when next running our +batchcode. -To make our mini-map we need to be able to cut our full map into parts. To do this we need to put it in a format which allows us to do that easily. Luckily, python allows us to treat strings as lists of characters allowing us to pick out the characters we need. +To make our mini-map we need to be able to cut our full map into parts. To do this we need to put it +in a format which allows us to do that easily. Luckily, python allows us to treat strings as lists +of characters allowing us to pick out the characters we need. `mygame/world/map_module.py` ```Python @@ -206,8 +265,8 @@ world_map = """\ ≈≈↑↑↑↑↑∩∩ """ -# This turns our map string into a list of rows. Because python -# allows us to treat strings as a list of characters, we can access +# This turns our map string into a list of rows. Because python +# allows us to treat strings as a list of characters, we can access # those characters with world_map[5][5] where world_map[row][column]. world_map = world_map.split('\n') @@ -239,7 +298,8 @@ def return_minimap(x, y, radius = 2): return map ``` -With our map_module set up, let's replace our hardcoded map in `mygame/world/batchcode_map.py` with a reference to our map module. Make sure to import our map_module! +With our map_module set up, let's replace our hardcoded map in `mygame/world/batchcode_map.py` with +a reference to our map module. Make sure to import our map_module! ```python # mygame/world/batchcode_map.py @@ -255,11 +315,22 @@ map.db.desc = map_module.return_map() caller.msg("A map appears out of thin air and falls to the ground.") ``` -Log into Evennia as the superuser and run this batchcode. If everything worked our new map should look exactly the same as the old map - you can use `@delete` to delete the old one (use a number to pick which to delete). +Log into Evennia as the superuser and run this batchcode. If everything worked our new map should +look exactly the same as the old map - you can use `@delete` to delete the old one (use a number to +pick which to delete). -Now, lets turn our attention towards our game's rooms. Let's use the `return_minimap` method we created above in order to include a minimap in our room descriptions. This is a little more complicated. +Now, lets turn our attention towards our game's rooms. Let's use the `return_minimap` method we +created above in order to include a minimap in our room descriptions. This is a little more +complicated. -By itself we would have to settle for either the map being *above* the description with `room.db.desc = map_string + description_string`, or the map going *below* by reversing their order. Both options are rather unsatisfactory - we would like to have the map next to the text! For this solution we'll explore the utilities that ship with Evennia. Tucked away in `evennia\evennia\utils` is a little module called [EvTable](github:evennia.utils.evtable) . This is an advanced ASCII table creator for you to utilize in your game. We'll use it by creating a basic table with 1 row and two columns (one for our map and one for our text) whilst also hiding the borders. Open the batchfile again +By itself we would have to settle for either the map being *above* the description with +`room.db.desc = map_string + description_string`, or the map going *below* by reversing their order. +Both options are rather unsatisfactory - we would like to have the map next to the text! For this +solution we'll explore the utilities that ship with Evennia. Tucked away in `evennia\evennia\utils` +is a little module called [EvTable](github:evennia.utils.evtable) . This is an advanced ASCII table +creator for you to utilize in your game. We'll use it by creating a basic table with 1 row and two +columns (one for our map and one for our text) whilst also hiding the borders. Open the batchfile +again ```python # mygame\world\batchcode_world.py @@ -276,61 +347,70 @@ from world import map_module # We pass what we want in our table and EvTable does the rest. # Passing two arguments will create two columns but we could add more. # We also specify no border. -centre.db.desc = evtable.EvTable(map_module.return_minimap(4,5), +centre.db.desc = evtable.EvTable(map_module.return_minimap(4,5), "The merger of two roads. A single lamp post dimly " \ "illuminates the lonely crossroads. To the north " \ "looms a mighty castle. To the south the glow of " \ "a campfire can be seen. To the east lie a wall of " \ - "mountains and to the west the dull roar of the open sea.", + "mountains and to the west the dull roar of the open sea.", border=None) # EvTable allows formatting individual columns and cells. We use that here # to set a maximum width for our description, but letting the map fill -# whatever space it needs. +# whatever space it needs. centre.db.desc.reformat_column(1, width=70) # [...] # The northern castle. -north.db.desc = evtable.EvTable(map_module.return_minimap(4,2), +north.db.desc = evtable.EvTable(map_module.return_minimap(4,2), "An impressive castle surrounds you. There might be " \ - "a princess in one of these towers.", + "a princess in one of these towers.", border=None) -north.db.desc.reformat_column(1, width=70) +north.db.desc.reformat_column(1, width=70) # [...] # The eastern cottage. -east.db.desc = evtable.EvTable(map_module.return_minimap(6,5), +east.db.desc = evtable.EvTable(map_module.return_minimap(6,5), "A cosy cottage nestled among mountains stretching " \ - "east as far as the eye can see.", + "east as far as the eye can see.", border=None) east.db.desc.reformat_column(1, width=70) # [...] # The southern camp. -south.db.desc = evtable.EvTable(map_module.return_minimap(4,7), +south.db.desc = evtable.EvTable(map_module.return_minimap(4,7), "Surrounding a clearing are a number of tribal tents " \ - "and at their centre a roaring fire.", + "and at their centre a roaring fire.", border=None) south.db.desc.reformat_column(1, width=70) # [...] # The western coast. -west.db.desc = evtable.EvTable(map_module.return_minimap(2,5), +west.db.desc = evtable.EvTable(map_module.return_minimap(2,5), "The dark forest halts to a sandy beach. The sound of " \ - "crashing waves calms the soul.", + "crashing waves calms the soul.", border=None) west.db.desc.reformat_column(1, width=70) ``` -Before we run our new batchcode, if you are anything like me you would have something like 100 maps lying around and 3-4 different versions of our rooms extending from limbo. Let's wipe it all and start with a clean slate. In Command Prompt you can run `evennia flush` to clear the database and start anew. It won't reset dbref values however, so if you are at #100 it will start from there. Alternatively you can navigate to `mygame/server` and delete the `evennia.db3` file. Now in Command Prompt use `evennia migrate` to have a completely freshly made database. +Before we run our new batchcode, if you are anything like me you would have something like 100 maps +lying around and 3-4 different versions of our rooms extending from limbo. Let's wipe it all and +start with a clean slate. In Command Prompt you can run `evennia flush` to clear the database and +start anew. It won't reset dbref values however, so if you are at #100 it will start from there. +Alternatively you can navigate to `mygame/server` and delete the `evennia.db3` file. Now in Command +Prompt use `evennia migrate` to have a completely freshly made database. Log in to evennia and run `@batchcode batchcode_world` and you'll have a little world to explore. ## Conclusions -You should now have a mapped little world and a basic understanding of batchcode, EvTable and how easily new game defining features can be added to Evennia. +You should now have a mapped little world and a basic understanding of batchcode, EvTable and how +easily new game defining features can be added to Evennia. -You can easily build from this tutorial by expanding the map and creating more rooms to explore. Why not add more features to your game by trying other tutorials: [Add weather to your world](./Weather-Tutorial), [fill your world with NPC's](./Tutorial-Aggressive-NPCs) or [implement a combat system](./Turn-based-Combat-System). +You can easily build from this tutorial by expanding the map and creating more rooms to explore. Why +not add more features to your game by trying other tutorials: [Add weather to your world](Weather- +Tutorial), [fill your world with NPC's](./Tutorial-Aggressive-NPCs) or [implement a combat +system](Turn-based-Combat-System). diff --git a/docs/source/Tags.md b/docs/source/Tags.md index 682b778e28..4ee667d8b3 100644 --- a/docs/source/Tags.md +++ b/docs/source/Tags.md @@ -1,34 +1,61 @@ # Tags -A common task of a game designer is to organize and find groups of objects and do operations on them. A classic example is to have a weather script affect all "outside" rooms. Another would be for a player casting a magic spell that affects every location "in the dungeon", but not those "outside". Another would be to quickly find everyone joined with a particular guild or everyone currently dead. +A common task of a game designer is to organize and find groups of objects and do operations on +them. A classic example is to have a weather script affect all "outside" rooms. Another would be for +a player casting a magic spell that affects every location "in the dungeon", but not those +"outside". Another would be to quickly find everyone joined with a particular guild or everyone +currently dead. -*Tags* are short text labels that you attach to objects so as to easily be able to retrieve and group them. An Evennia entity can be tagged with any number of Tags. On the database side, Tag entities are *shared* between all objects with that tag. This makes them very efficient but also fundamentally different from [Attributes](./Attributes), each of which always belongs to one *single* object. +*Tags* are short text labels that you attach to objects so as to easily be able to retrieve and +group them. An Evennia entity can be tagged with any number of Tags. On the database side, Tag +entities are *shared* between all objects with that tag. This makes them very efficient but also +fundamentally different from [Attributes](./Attributes), each of which always belongs to one *single* +object. -In Evennia, Tags are technically also used to implement `Aliases` (alternative names for objects) and `Permissions` (simple strings for [Locks](./Locks) to check for). +In Evennia, Tags are technically also used to implement `Aliases` (alternative names for objects) +and `Permissions` (simple strings for [Locks](./Locks) to check for). ## Properties of Tags (and Aliases and Permissions) -Tags are *unique*. This means that there is only ever one Tag object with a given key and category. +Tags are *unique* per object model. This means that for each object model (`Objects`, `Scripts`, +`Msgs`, etc.) there is only ever one Tag object with a given key and category. -> Not specifying a category (default) gives the tag a category of `None`, which is also considered a unique key + category combination. +> Not specifying a category (default) gives the tag a category of `None`, which is also considered a +unique key + category combination. -When Tags are assigned to game entities, these entities are actually sharing the same Tag. This means that Tags are not suitable for storing information about a single object - use an [Attribute](./Attributes) for this instead. Tags are a lot more limited than Attributes but this also makes them very quick to lookup in the database - this is the whole point. +When Tags are assigned to game entities, these entities are actually sharing the same Tag. This +means that Tags are not suitable for storing information about a single object - use an +[Attribute](./Attributes) for this instead. Tags are a lot more limited than Attributes but this also +makes them very quick to lookup in the database - this is the whole point. Tags have the following properties, stored in the database: - **key** - the name of the Tag. This is the main property to search for when looking up a Tag. -- **category** - this category allows for retrieving only specific subsets of tags used for different purposes. You could have one category of tags for "zones", another for "outdoor locations", for example. If not given, the category will be `None`, which is also considered a separate, default, category. -- **data** - this is an optional text field with information about the tag. Remember that Tags are shared between entities, so this field cannot hold any object-specific information. Usually it would be used to hold info about the group of entities the Tag is tagging - possibly used for contextual help like a tool tip. It is not used by default. +- **category** - this category allows for retrieving only specific subsets of tags used for +different purposes. You could have one category of tags for "zones", another for "outdoor +locations", for example. If not given, the category will be `None`, which is also considered a +separate, default, category. +- **data** - this is an optional text field with information about the tag. Remember that Tags are +shared between entities, so this field cannot hold any object-specific information. Usually it would +be used to hold info about the group of entities the Tag is tagging - possibly used for contextual +help like a tool tip. It is not used by default. -There are also two special properties. These should usually not need to be changed or set, it is used internally by Evennia to implement various other uses it makes of the `Tag` object: -- **model** - this holds a *natural-key* description of the model object that this tag deals with, on the form *application.modelclass*, for example `objects.objectdb`. It used by the TagHandler of each entity type for correctly storing the data behind the scenes. -- **tagtype** - this is a "top-level category" of sorts for the inbuilt children of Tags, namely *Aliases* and *Permissions*. The Taghandlers using this special field are especially intended to free up the *category* property for any use you desire. +There are also two special properties. These should usually not need to be changed or set, it is +used internally by Evennia to implement various other uses it makes of the `Tag` object: +- **model** - this holds a *natural-key* description of the model object that this tag deals with, +on the form *application.modelclass*, for example `objects.objectdb`. It used by the TagHandler of +each entity type for correctly storing the data behind the scenes. +- **tagtype** - this is a "top-level category" of sorts for the inbuilt children of Tags, namely +*Aliases* and *Permissions*. The Taghandlers using this special field are especially intended to +free up the *category* property for any use you desire. ## Adding/Removing Tags -You can tag any *typeclassed* object, namely [Objects](./Objects), [Accounts](./Accounts), [Scripts](./Scripts) and [Channels](./Communications). General tags are added by the *Taghandler*. The tag handler is accessed as a property `tags` on the relevant entity: +You can tag any *typeclassed* object, namely [Objects](./Objects), [Accounts](./Accounts), +[Scripts](./Scripts) and [Channels](./Communications). General tags are added by the *Taghandler*. The +tag handler is accessed as a property `tags` on the relevant entity: ```python mychair.tags.add("furniture") @@ -38,32 +65,36 @@ You can tag any *typeclassed* object, namely [Objects](./Objects), [Accounts](./ myaccount.tags.add("guestaccount") mychair.tags.all() # returns a list of Tags - mychair.tags.remove("furniture") - mychair.tags.clear() + mychair.tags.remove("furniture") + mychair.tags.clear() ``` -Adding a new tag will either create a new Tag or re-use an already existing one. Note that there are _two_ "furniture" tags, one with a `None` category, and one with the "luxurious" category. +Adding a new tag will either create a new Tag or re-use an already existing one. Note that there are +_two_ "furniture" tags, one with a `None` category, and one with the "luxurious" category. -When using `remove`, the `Tag` is not deleted but are just disconnected from the tagged object. This makes for very quick operations. The `clear` method removes (disconnects) all Tags from the object. You can also use the default `@tag` command: +When using `remove`, the `Tag` is not deleted but are just disconnected from the tagged object. This +makes for very quick operations. The `clear` method removes (disconnects) all Tags from the object. +You can also use the default `@tag` command: @tag mychair = furniture -This tags the chair with a 'furniture' Tag (the one with a `None` category). +This tags the chair with a 'furniture' Tag (the one with a `None` category). ## Searching for objects with a given tag -Usually tags are used as a quick way to find tagged database entities. You can retrieve all objects with a given Tag like this in code: +Usually tags are used as a quick way to find tagged database entities. You can retrieve all objects +with a given Tag like this in code: ```python import evennia # all methods return Querysets - # search for objects + # search for objects objs = evennia.search_tag("furniture") objs2 = evennia.search_tag("furniture", category="luxurious") dungeon = evennia.search_tag("dungeon#01") - forest_rooms = evennia.search_tag(category="forest") + forest_rooms = evennia.search_tag(category="forest") forest_meadows = evennia.search_tag("meadow", category="forest") magic_meadows = evennia.search_tag("meadow", category="magical") @@ -72,23 +103,28 @@ Usually tags are used as a quick way to find tagged database entities. You can r climates = evennia.search_tag_script(category="climate") # search for accounts - accounts = evennia.search_tag_account("guestaccount") + accounts = evennia.search_tag_account("guestaccount") ``` -> Note that searching for just "furniture" will only return the objects tagged with the "furniture" tag that -has a category of `None`. We must explicitly give the category to get the "luxurious" furniture. +> Note that searching for just "furniture" will only return the objects tagged with the "furniture" +tag that +has a category of `None`. We must explicitly give the category to get the "luxurious" furniture. -Using any of the `search_tag` variants will all return [Django Querysets](https://docs.djangoproject.com/en/2.1/ref/models/querysets/), including if you only have one match. You can treat querysets as lists and iterate over them, or continue building search queries with them. +Using any of the `search_tag` variants will all return [Django +Querysets](https://docs.djangoproject.com/en/2.1/ref/models/querysets/), including if you only have +one match. You can treat querysets as lists and iterate over them, or continue building search +queries with them. -Remember when searching that not setting a category means setting it to `None` - this does *not* mean that category is undefined, rather `None` is considered the default, unnamed category. +Remember when searching that not setting a category means setting it to `None` - this does *not* +mean that category is undefined, rather `None` is considered the default, unnamed category. ```python -import evennia +import evennia myobj1.tags.add("foo") # implies category=None myobj2.tags.add("foo", category="bar") -# this returns a queryset with *only* myobj1 +# this returns a queryset with *only* myobj1 objs = evennia.search_tag("foo") # these return a queryset with *only* myobj2 @@ -106,7 +142,9 @@ There is also an in-game command that deals with assigning and using ([Object-]( ## Using Aliases and Permissions -Aliases and Permissions are implemented using normal TagHandlers that simply save Tags with a different `tagtype`. These handlers are named `aliases` and `permissions` on all Objects. They are used in the same way as Tags above: +Aliases and Permissions are implemented using normal TagHandlers that simply save Tags with a +different `tagtype`. These handlers are named `aliases` and `permissions` on all Objects. They are +used in the same way as Tags above: ```python boy.aliases.add("rascal") @@ -116,11 +154,17 @@ Aliases and Permissions are implemented using normal TagHandlers that simply sav all_aliases = boy.aliases.all() ``` -and so on. Similarly to how `@tag` works in-game, there is also the `@perm` command for assigning permissions and `@alias` command for aliases. +and so on. Similarly to how `@tag` works in-game, there is also the `@perm` command for assigning +permissions and `@alias` command for aliases. ## Assorted notes -Generally, tags are enough on their own for grouping objects. Having no tag `category` is perfectly fine and the normal operation. Simply adding a new Tag for grouping objects is often better than making a new category. So think hard before deciding you really need to categorize your Tags. +Generally, tags are enough on their own for grouping objects. Having no tag `category` is perfectly +fine and the normal operation. Simply adding a new Tag for grouping objects is often better than +making a new category. So think hard before deciding you really need to categorize your Tags. -That said, tag categories can be useful if you build some game system that uses tags. You can then use tag categories to make sure to separate tags created with this system from any other tags created elsewhere. You can then supply custom search methods that *only* find objects tagged with tags of that category. An example of this -is found in the [Zone tutorial](./Zones). +That said, tag categories can be useful if you build some game system that uses tags. You can then +use tag categories to make sure to separate tags created with this system from any other tags +created elsewhere. You can then supply custom search methods that *only* find objects tagged with +tags of that category. An example of this +is found in the [Zone tutorial](./Zones). diff --git a/docs/source/TextTags.md b/docs/source/TextTags.md index 33e9f6cebe..95844dac14 100644 --- a/docs/source/TextTags.md +++ b/docs/source/TextTags.md @@ -1,29 +1,52 @@ # TextTags -This documentation details the various text tags supported by Evennia, namely *colours*, *command links* and *inline functions*. +This documentation details the various text tags supported by Evennia, namely *colours*, *command +links* and *inline functions*. -There is also an [Understanding Color Tags](./Understanding-Color-Tags) tutorial which expands on the use of ANSI color tags and the pitfalls of mixing ANSI and Xterms256 color tags in the same context. +There is also an [Understanding Color Tags](./Understanding-Color-Tags) tutorial which expands on the +use of ANSI color tags and the pitfalls of mixing ANSI and Xterms256 color tags in the same context. ## Coloured text *Note that the Documentation does not display colour the way it would look on the screen.* -Color can be a very useful tool for your game. It can be used to increase readability and make your game more appealing visually. +Color can be a very useful tool for your game. It can be used to increase readability and make your +game more appealing visually. -Remember however that, with the exception of the webclient, you generally don't control the client used to connect to the game. There is, for example, one special tag meaning "yellow". But exactly *which* hue of yellow is actually displayed on the user's screen depends on the settings of their particular mud client. They could even swap the colours around or turn them off altogether if so desired. Some clients don't even support color - text games are also played with special reading equipment by people who are blind or have otherwise diminished eyesight. +Remember however that, with the exception of the webclient, you generally don't control the client +used to connect to the game. There is, for example, one special tag meaning "yellow". But exactly +*which* hue of yellow is actually displayed on the user's screen depends on the settings of their +particular mud client. They could even swap the colours around or turn them off altogether if so +desired. Some clients don't even support color - text games are also played with special reading +equipment by people who are blind or have otherwise diminished eyesight. -So a good rule of thumb is to use colour to enhance your game but don't *rely* on it to display critical information. If you are coding the game, you can add functionality to let users disable colours as they please, as described [here](./Manually-Configuring-Color). +So a good rule of thumb is to use colour to enhance your game but don't *rely* on it to display +critical information. If you are coding the game, you can add functionality to let users disable +colours as they please, as described [here](./Manually-Configuring-Color). -To see which colours your client support, use the default `@color` command. This will list all available colours for ANSI and Xterm256 along with the codes you use for them. You can find a list of all the parsed `ANSI`-colour codes in `evennia/utils/ansi.py`. +To see which colours your client support, use the default `@color` command. This will list all +available colours for ANSI and Xterm256 along with the codes you use for them. You can find a list +of all the parsed `ANSI`-colour codes in `evennia/utils/ansi.py`. ### ANSI colours -Evennia supports the `ANSI` standard for text. This is by far the most supported MUD-color standard, available in all but the most ancient mud clients. The ANSI colours are **r**ed, **g**reen, **y**ellow, **b**lue, **m**agenta, **c**yan, **w**hite and black. They are abbreviated by their first letter except for black which is abbreviated with the letter **x**. In ANSI there are "bright" and "normal" (darker) versions of each color, adding up to a total of 16 colours to use for foreground text. There are also 8 "background" colours. These have no bright alternative in ANSI (but Evennia uses the [Xterm256](./TextTags#xterm256-colours) extension behind the scenes to offer them anyway). +Evennia supports the `ANSI` standard for text. This is by far the most supported MUD-color standard, +available in all but the most ancient mud clients. The ANSI colours are **r**ed, **g**reen, +**y**ellow, **b**lue, **m**agenta, **c**yan, **w**hite and black. They are abbreviated by their +first letter except for black which is abbreviated with the letter **x**. In ANSI there are "bright" +and "normal" (darker) versions of each color, adding up to a total of 16 colours to use for +foreground text. There are also 8 "background" colours. These have no bright alternative in ANSI +(but Evennia uses the [Xterm256](./TextTags#xterm256-colours) extension behind the scenes to offer +them anyway). -To colour your text you put special tags in it. Evennia will parse these and convert them to the correct markup for the client used. If the user's client/console/display supports ANSI colour, they will see the text in the specified colour, otherwise the tags will be stripped (uncolored text). This works also for non-terminal clients, such as the webclient. For the webclient, Evennia will translate the codes to HTML RGB colors. +To colour your text you put special tags in it. Evennia will parse these and convert them to the +correct markup for the client used. If the user's client/console/display supports ANSI colour, they +will see the text in the specified colour, otherwise the tags will be stripped (uncolored text). +This works also for non-terminal clients, such as the webclient. For the webclient, Evennia will +translate the codes to HTML RGB colors. -Here is an example of the tags in action: +Here is an example of the tags in action: |rThis text is bright red.|n This is normal text. |RThis is a dark red text.|n This is normal text. @@ -31,53 +54,79 @@ Here is an example of the tags in action: |b|[yThis is bright blue text on yellow background.|n This is normal text. - `|n` - this tag will turn off all color formatting, including background colors. -- `|#`- markup marks the start of foreground color. The case defines if the text is "bright" or "normal". So `|g` is a bright green and `|G` is "normal" (darker) green. -- `|[#` is used to add a background colour to the text. The case again specifies if it is "bright" or "normal", so `|[c` starts a bright cyan background and `|[C` a darker cyan background. -- `|!#` is used to add foreground color without any enforced brightness/normal information. - These are normal-intensity and are thus always given as uppercase, such as - `|!R` for red. The difference between e.g. `|!R` and `|R` is that - `|!R` will "inherit" the brightness setting from previously set color tags, whereas `|R` will always reset to the normal-intensity red. The `|#` format contains an implicit `|h`/`|H` tag in it: disabling highlighting when switching to a normal color, and enabling it for bright ones. So `|btest |!Rtest2` will result in a bright red `test2` since the brightness setting from `|b` "bleeds over". You could use this to for example quickly switch the intensity of a multitude of color tags. There is no background-color equivalent to `|!` style tags. -- `|h` is used to make any following foreground ANSI colors bright (it has no effect on Xterm colors). This is only relevant to use with `|!` type tags and will be valid until the next `|n`, `|H` or normal (upper-case) `|#` tag. This tag will never affect background colors, those have to be set bright/normal explicitly. Technically, `|h|!G` is identical to `|g`. -- `|H` negates the effects `|h` and returns all ANSI foreground colors (`|!` and `|` types) to 'normal' intensity. It has no effect on background and Xterm colors. +- `|#`- markup marks the start of foreground color. The case defines if the text is "bright" or +"normal". So `|g` is a bright green and `|G` is "normal" (darker) green. +- `|[#` is used to add a background colour to the text. The case again specifies if it is "bright" +or "normal", so `|[c` starts a bright cyan background and `|[C` a darker cyan background. +- `|!#` is used to add foreground color without any enforced brightness/normal information. + These are normal-intensity and are thus always given as uppercase, such as + `|!R` for red. The difference between e.g. `|!R` and `|R` is that + `|!R` will "inherit" the brightness setting from previously set color tags, whereas `|R` will +always reset to the normal-intensity red. The `|#` format contains an implicit `|h`/`|H` tag in it: +disabling highlighting when switching to a normal color, and enabling it for bright ones. So `|btest +|!Rtest2` will result in a bright red `test2` since the brightness setting from `|b` "bleeds over". +You could use this to for example quickly switch the intensity of a multitude of color tags. There +is no background-color equivalent to `|!` style tags. +- `|h` is used to make any following foreground ANSI colors bright (it has no effect on Xterm +colors). This is only relevant to use with `|!` type tags and will be valid until the next `|n`, +`|H` or normal (upper-case) `|#` tag. This tag will never affect background colors, those have to be +set bright/normal explicitly. Technically, `|h|!G` is identical to `|g`. +- `|H` negates the effects `|h` and returns all ANSI foreground colors (`|!` and `|` types) to +'normal' intensity. It has no effect on background and Xterm colors. -> Note: The ANSI standard does not actually support bright backgrounds like `|[r` - the standard only supports "normal" intensity backgrounds. To get around this Evennia instead implements these as [Xterm256 colours](./TextTags#xterm256-colours) behind the scenes. If the client does not support Xterm256 the ANSI colors will be used instead and there will be no visible difference between using upper- and lower-case background tags. +> Note: The ANSI standard does not actually support bright backgrounds like `|[r` - the standard +only supports "normal" intensity backgrounds. To get around this Evennia instead implements these +as [Xterm256 colours](./TextTags#xterm256-colours) behind the scenes. If the client does not support +Xterm256 the ANSI colors will be used instead and there will be no visible difference between using +upper- and lower-case background tags. -If you want to display an ANSI marker as output text (without having any effect), you need to escape it by preceding its `|` with another `|`: +If you want to display an ANSI marker as output text (without having any effect), you need to escape +it by preceding its `|` with another `|`: ``` say The ||r ANSI marker changes text color to bright red. ``` -This will output the raw `|r` without any color change. This can also be necessary if you are doing ansi art that uses `|` with a letter directly following it. +This will output the raw `|r` without any color change. This can also be necessary if you are doing +ansi art that uses `|` with a letter directly following it. Use the command - @color ansi + @color ansi to get a list of all supported ANSI colours and the tags used to produce them. -A few additional ANSI codes are supported: +A few additional ANSI codes are supported: -- `|/` A line break. You cannot put the normal Python `\n` line breaks in text entered inside the game (Evennia will filter this for security reasons). This is what you use instead: use the `|/` marker to format text with line breaks from the game command line. -- `` This will translate into a `TAB` character. This will not always show (or show differently) to the client since it depends on their local settings. It's often better to use multiple spaces. -- `|_` This is a space. You can usually use the normal space character, but if the space is *at the end of the line*, Evennia will likely crop it. This tag will not be cropped but always result in a space. -- `|*` This will invert the current text/background colours. Can be useful to mark things (but see below). +- `|/` A line break. You cannot put the normal Python `\n` line breaks in text entered inside the +game (Evennia will filter this for security reasons). This is what you use instead: use the `|/` +marker to format text with line breaks from the game command line. +- `` This will translate into a `TAB` character. This will not always show (or show differently) to +the client since it depends on their local settings. It's often better to use multiple spaces. +- `|_` This is a space. You can usually use the normal space character, but if the space is *at the +end of the line*, Evennia will likely crop it. This tag will not be cropped but always result in a +space. +- `|*` This will invert the current text/background colours. Can be useful to mark things (but see +below). ##### Caveats of `|*` -The `|*` tag (inverse video) is an old ANSI standard and should usually not be used for more than to mark short snippets of text. If combined with other tags it comes with a series of potentially confusing behaviors: +The `|*` tag (inverse video) is an old ANSI standard and should usually not be used for more than to +mark short snippets of text. If combined with other tags it comes with a series of potentially +confusing behaviors: -* The `|*` tag will only work once in a row:, ie: after using it once it won't have an effect again until you declare another tag. This is an example: +* The `|*` tag will only work once in a row:, ie: after using it once it won't have an effect again +until you declare another tag. This is an example: ``` Normal text, |*reversed text|*, still reversed text. ``` - that is, it will not reverse to normal at the second `|*`. You need to reset it manually: + that is, it will not reverse to normal at the second `|*`. You need to reset it manually: ``` Normal text, |*reversed text|n, normal again. - ``` + ``` * The `|*` tag does not take "bright" colors into account: @@ -85,17 +134,25 @@ The `|*` tag (inverse video) is an old ANSI standard and should usually not be u |RNormal red, |hnow brightened. |*BG is normal red. ``` - So `|*` only considers the 'true' foreground color, ignoring any highlighting. Think of the bright state (`|h`) as something like like `` in HTML: it modifies the _appearance_ of a normal foreground color to match its bright counterpart, without changing its normal color. -* Finally, after a `|*`, if the previous background was set to a dark color (via `|[`), `|!#`) will actually change the background color instead of the foreground: + So `|*` only considers the 'true' foreground color, ignoring any highlighting. Think of the bright +state (`|h`) as something like like `` in HTML: it modifies the _appearance_ of a normal +foreground color to match its bright counterpart, without changing its normal color. +* Finally, after a `|*`, if the previous background was set to a dark color (via `|[`), `|!#`) will +actually change the background color instead of the foreground: ``` |*reversed text |!R now BG is red. ``` -For a detailed explanation of these caveats, see the [Understanding Color Tags](./Understanding-Color-Tags) tutorial. But most of the time you might be better off to simply avoid `|*` and mark your text manually instead. +For a detailed explanation of these caveats, see the [Understanding Color Tags](Understanding-Color- +Tags) tutorial. But most of the time you might be better off to simply avoid `|*` and mark your text +manually instead. ### Xterm256 Colours -The _Xterm256_ standard is a colour scheme that supports 256 colours for text and/or background. While this offers many more possibilities than traditional ANSI colours, be wary that too many text colors will be confusing to the eye. Also, not all clients support Xterm256 - these will instead see the closest equivalent ANSI color. You can mix Xterm256 tags with ANSI tags as you please. +The _Xterm256_ standard is a colour scheme that supports 256 colours for text and/or background. +While this offers many more possibilities than traditional ANSI colours, be wary that too many text +colors will be confusing to the eye. Also, not all clients support Xterm256 - these will instead see +the closest equivalent ANSI color. You can mix Xterm256 tags with ANSI tags as you please. |555 This is pure white text.|n This is normal text. |230 This is olive green text. @@ -106,63 +163,98 @@ The _Xterm256_ standard is a colour scheme that supports 256 colours for text an |=z This is a greyscale value, equal to white. |[=m This is a background greyscale value. -- `|###` - markup consists of three digits, each an integer from 0 to 5. The three digits describe the amount of **r**ed, **g**reen and **b**lue (RGB) components used in the colour. So `|500` means maximum red and none of the other colours - the result is a bright red. `|520` is red with a touch of green - the result is orange. As opposed to ANSI colors, Xterm256 syntax does not worry about bright/normal intensity, a brighter (lighter) color is just achieved by upping all RGB values with the same amount. +- `|###` - markup consists of three digits, each an integer from 0 to 5. The three digits describe +the amount of **r**ed, **g**reen and **b**lue (RGB) components used in the colour. So `|500` means +maximum red and none of the other colours - the result is a bright red. `|520` is red with a touch +of green - the result is orange. As opposed to ANSI colors, Xterm256 syntax does not worry about +bright/normal intensity, a brighter (lighter) color is just achieved by upping all RGB values with +the same amount. - `|[###` - this works the same way but produces a coloured background. -- `|=#` - markup produces the xterm256 gray scale tones, where `#` is a letter from `a` (black) to `z` (white). This offers many more nuances of gray than the normal `|###` markup (which only has four gray tones between solid black and white (`|000`, `|111`, `|222`, `|333` and `|444`)). +- `|=#` - markup produces the xterm256 gray scale tones, where `#` is a letter from `a` (black) to +`z` (white). This offers many more nuances of gray than the normal `|###` markup (which only has +four gray tones between solid black and white (`|000`, `|111`, `|222`, `|333` and `|444`)). - `|[=#` - this works in the same way but produces background gray scale tones. If you have a client that supports Xterm256, you can use @color xterm256 -to get a table of all the 256 colours and the codes that produce them. If the table looks broken up into a few blocks of colors, it means Xterm256 is not supported and ANSI are used as a replacement. You can use the `@options` command to see if xterm256 is active for you. This depends on if your client told Evennia what it supports - if not, and you know what your client supports, you may have to activate some features manually. +to get a table of all the 256 colours and the codes that produce them. If the table looks broken up +into a few blocks of colors, it means Xterm256 is not supported and ANSI are used as a replacement. +You can use the `@options` command to see if xterm256 is active for you. This depends on if your +client told Evennia what it supports - if not, and you know what your client supports, you may have +to activate some features manually. ## Clickable links -Evennia supports clickable links for clients that supports it. This marks certain text so it can be clicked by a mouse and trigger a given Evennia command. To support clickable links, Evennia requires the webclient or an third-party telnet client with [MXP](http://www.zuggsoft.com/zmud/mxp.htm) support (*Note: Evennia only supports clickable links, no other MXP features*). +Evennia supports clickable links for clients that supports it. This marks certain text so it can be +clicked by a mouse and trigger a given Evennia command. To support clickable links, Evennia requires +the webclient or an third-party telnet client with [MXP](http://www.zuggsoft.com/zmud/mxp.htm) +support (*Note: Evennia only supports clickable links, no other MXP features*). - `|lc` to start the link, by defining the command to execute. - `|lt` to continue with the text to show to the user (the link text). - `|le` to end the link text and the link definition. -All elements must appear in exactly this order to make a valid link. For example, +All elements must appear in exactly this order to make a valid link. For example, ``` "If you go |lcnorth|ltto the north|le you will find a cottage." ``` -This will display as "If you go __to the north__ you will find a cottage." where clicking the link will execute the command `north`. If the client does not support clickable links, only the link text will be shown. +This will display as "If you go __to the north__ you will find a cottage." where clicking the link +will execute the command `north`. If the client does not support clickable links, only the link text +will be shown. ## Inline functions -> Note: Inlinefuncs are **not** activated by default. To use them you need to add `INLINEFUNC_ENABLED=True` to your settings file. +> Note: Inlinefuncs are **not** activated by default. To use them you need to add +`INLINEFUNC_ENABLED=True` to your settings file. -Evennia has its own inline text formatting language, known as *inlinefuncs*. It allows the builder to include special function calls in code. They are executed dynamically by each session that receives them. +Evennia has its own inline text formatting language, known as *inlinefuncs*. It allows the builder +to include special function calls in code. They are executed dynamically by each session that +receives them. -To add an inlinefunc, you embed it in a text string like this: +To add an inlinefunc, you embed it in a text string like this: ``` "A normal string with $funcname(arg, arg, ...) embedded inside it." ``` -When this string is sent to a session (with the `msg()` method), these embedded inlinefuncs will be parsed. Their return value (which always is a string) replace their call location in the finalized string. The interesting thing with this is that the function called will have access to which session is seeing the string, meaning the string can end up looking different depending on who is looking. It could of course also vary depending on other factors like game time. +When this string is sent to a session (with the `msg()` method), these embedded inlinefuncs will be +parsed. Their return value (which always is a string) replace their call location in the finalized +string. The interesting thing with this is that the function called will have access to which +session is seeing the string, meaning the string can end up looking different depending on who is +looking. It could of course also vary depending on other factors like game time. -Any number of comma-separated arguments can be given (or none). No keywords are supported. You can also nest inlinefuncs by letting an argument itself also be another `$funcname(arg, arg, ...)` call (down to any depth of nesting). Function call resolution happens as in all programming languages inside-out, with the nested calls replacing the argument with their return strings before calling he parent. +Any number of comma-separated arguments can be given (or none). No keywords are supported. You can +also nest inlinefuncs by letting an argument itself also be another `$funcname(arg, arg, ...)` call +(down to a depth of nesting given by `settings.INLINEFUNC_STACK_MAXSIZE`). Function call resolution +happens as in all programming languages inside-out, with the nested calls replacing the argument +with their return strings before calling he parent. ``` > say "This is $pad(a center-padded text, 30,c,-) of width 30." You say, "This is ---- a center-padded text----- of width 30." + > say "I roll a die and the result is ... a $random(1,6)!" + You say, "I roll a die and the result is ... a 5!" ``` -A special case happens if wanting to use an inlinefunc argument that itself includes a comma - this would be parsed as an argument separator. To escape commas you can either escape each comma manually with a backslash `\,`, or you can embed the entire string in python triple-quotes `"""` or `'''` - this will escape the entire argument, including commas and any nested inlinefunc calls within. +A special case happens if wanting to use an inlinefunc argument that itself includes a comma - this +would be parsed as an argument separator. To escape commas you can either escape each comma manually +with a backslash `\,`, or you can embed the entire string in python triple-quotes `"""` or `'''` - +this will escape the entire argument, including commas and any nested inlinefunc calls within. -Only certain functions are available to use as inlinefuncs and the game developer may add their own functions as needed. +Only certain functions are available to use as inlinefuncs and the game developer may add their own +functions as needed. -### New inlinefuncs +### New inlinefuncs To add new inlinefuncs, edit the file `mygame/server/conf/inlinefuncs.py`. -*All globally defined functions in this module* are considered inline functions by the system. The only exception is functions whose name starts with an underscore `_`. An inlinefunc must be of the following form: +*All globally defined functions in this module* are considered inline functions by the system. The +only exception is functions whose name starts with an underscore `_`. An inlinefunc must be of the +following form: ```python def funcname(*args, **kwargs): @@ -170,11 +262,23 @@ def funcname(*args, **kwargs): return modified_text ``` -where `*args` denotes all the arguments this function will accept as an `$inlinefunc`. The inline function is expected to clean arguments and check that they are valid. If needed arguments are not given, default values should be used. The function should always return a string (even if it's empty). An inlinefunc should never cause a traceback regardless of the input (but it could log errors if desired). +where `*args` denotes all the arguments this function will accept as an `$inlinefunc`. The inline +function is expected to clean arguments and check that they are valid. If needed arguments are not +given, default values should be used. The function should always return a string (even if it's +empty). An inlinefunc should never cause a traceback regardless of the input (but it could log +errors if desired). -Note that whereas the function should accept `**kwargs`, keyword inputs are *not* usable in the call to the inlinefunction. The `kwargs` part is instead intended for Evennia to be able to supply extra information. Currently Evennia sends a single keyword to every inline function and that is `session`, which holds the [serversession](./Sessions) this text is targeted at. Through the session object, a lot of dynamic possibilities are opened up for your inline functions. +Note that whereas the function should accept `**kwargs`, keyword inputs are *not* usable in the call +to the inlinefunction. The `kwargs` part is instead intended for Evennia to be able to supply extra +information. Currently Evennia sends a single keyword to every inline function and that is +`session`, which holds the [serversession](./Sessions) this text is targeted at. Through the session +object, a lot of dynamic possibilities are opened up for your inline functions. -The `settings.INLINEFUNC_MODULES` configuration option is a list that decides which modules should be parsed for inline function definitions. This will include `mygame/server/conf/inlinefuncs.py` but more could be added. The list is read from left to right so if you want to overload default functions you just have to put your custom module-paths later in the list and name your functions the same as default ones. +The `settings.INLINEFUNC_MODULES` configuration option is a list that decides which modules should +be parsed for inline function definitions. This will include `mygame/server/conf/inlinefuncs.py` but +more could be added. The list is read from left to right so if you want to overload default +functions you just have to put your custom module-paths later in the list and name your functions +the same as default ones. Here is an example, the `crop` default inlinefunction: @@ -190,7 +294,7 @@ def crop(*args, **kwargs): crop in characters. suffix (str, optional): End string to mark the fact that a part of the string was cropped. Defaults to `[...]`. - Keyword Args: + Kwargs: session (Session): Session performing the crop. Example: `$crop(text, 50, [...])` @@ -213,10 +317,10 @@ def charactername(*args, **kwargs): """ Inserts the character name of whomever sees the string (so everyone will see their own name). Uses the account - name for OOC communications. + name for OOC communications. Example: - say "This means YOU, $charactername()!" + say "This means YOU, $charactername()!" """ session = kwargs["session"] @@ -228,7 +332,14 @@ def charactername(*args, **kwargs): Evennia itself offers the following default inline functions (mostly as examples): -* `crop(text, width, suffix)` - See above. -* `pad(text, width, align, fillchar)` - this pads the text to `width` (default 78), alignment ("c", "l" or "r", defaulting to "c") and fill-in character (defaults to space). Example: `$pad(40,l,-)` -* `clr(startclr, text, endclr)` - A programmatic way to enter colored text for those who don't want to use the normal `|c` type color markers for some reason. The `color` argument is the same as the color markers except without the actual pre-marker, so `|r` would be just `r`. If `endclr` is not given, it defaults to resetting the color (`n`). Example: `$clr(b, A blue text)` -* `space(number)` - Inserts the given number of spaces. If no argument is given, use 4 spaces. \ No newline at end of file +* `crop(text, width, suffix)` - See above. +* `pad(text, width, align, fillchar)` - this pads the text to `width` (default 78), alignment ("c", +"l" or "r", defaulting to "c") and fill-in character (defaults to space). Example: `$pad(40,l,-)` +* `clr(startclr, text, endclr)` - A programmatic way to enter colored text for those who don't want +to use the normal `|c` type color markers for some reason. The `color` argument is the same as the +color markers except without the actual pre-marker, so `|r` would be just `r`. If `endclr` is not +given, it defaults to resetting the color (`n`). Example: `$clr(b, A blue text)` +* `space(number)` - Inserts the given number of spaces. If no argument is given, use 4 spaces. +* `random()`, `random(max)`, `random(min, max)` - gives a random value between min and max. With no +arguments, give 0 or 1 (on/off). If one argument, returns 0...max. If values are floats, random +value will be a float (so `random(1.0)` replicates the normal Python `random` function). \ No newline at end of file diff --git a/docs/source/TickerHandler.md b/docs/source/TickerHandler.md index a572b89109..66bb7f11b2 100644 --- a/docs/source/TickerHandler.md +++ b/docs/source/TickerHandler.md @@ -1,28 +1,41 @@ # TickerHandler -One way to implement a dynamic MUD is by using "tickers", also known as "heartbeats". A ticker is a timer that fires ("ticks") at a given interval. The tick triggers updates in various game systems. +One way to implement a dynamic MUD is by using "tickers", also known as "heartbeats". A ticker is a +timer that fires ("ticks") at a given interval. The tick triggers updates in various game systems. ## About Tickers -Tickers are very common or even unavoidable in other mud code bases. Certain code bases are even hard-coded to rely on the concept of the global 'tick'. Evennia has no such notion - the decision to use tickers is very much up to the need of your game and which requirements you have. The "ticker recipe" is just one way of cranking the wheels. +Tickers are very common or even unavoidable in other mud code bases. Certain code bases are even +hard-coded to rely on the concept of the global 'tick'. Evennia has no such notion - the decision to +use tickers is very much up to the need of your game and which requirements you have. The "ticker +recipe" is just one way of cranking the wheels. -The most fine-grained way to manage the flow of time is of course to use [Scripts](./Scripts). Many types of operations (weather being the classic example) are however done on multiple objects in the same way at regular intervals, and for this, storing separate Scripts on each object is inefficient. The way to do this is to use a ticker with a "subscription model" - let objects sign up to be triggered at the same interval, unsubscribing when the updating is no longer desired. +The most fine-grained way to manage the flow of time is of course to use [Scripts](./Scripts). Many +types of operations (weather being the classic example) are however done on multiple objects in the +same way at regular intervals, and for this, storing separate Scripts on each object is inefficient. +The way to do this is to use a ticker with a "subscription model" - let objects sign up to be +triggered at the same interval, unsubscribing when the updating is no longer desired. -Evennia offers an optimized implementation of the subscription model - the *TickerHandler*. This is a singleton global handler reachable from `evennia.TICKER_HANDLER`. You can assign any *callable* (a function or, more commonly, a method on a database object) to this handler. The TickerHandler will then call this callable at an interval you specify, and with the arguments you supply when adding it. This continues until the callable un-subscribes from the ticker. The handler survives a reboot and is highly optimized in resource usage. +Evennia offers an optimized implementation of the subscription model - the *TickerHandler*. This is +a singleton global handler reachable from `evennia.TICKER_HANDLER`. You can assign any *callable* (a +function or, more commonly, a method on a database object) to this handler. The TickerHandler will +then call this callable at an interval you specify, and with the arguments you supply when adding +it. This continues until the callable un-subscribes from the ticker. The handler survives a reboot +and is highly optimized in resource usage. -Here is an example of importing `TICKER_HANDLER` and using it: +Here is an example of importing `TICKER_HANDLER` and using it: ```python # we assume that obj has a hook "at_tick" defined on itself - from evennia import TICKER_HANDLER as tickerhandler + from evennia import TICKER_HANDLER as tickerhandler tickerhandler.add(20, obj.at_tick) -``` +``` -That's it - from now on, `obj.at_tick()` will be called every 20 seconds. +That's it - from now on, `obj.at_tick()` will be called every 20 seconds. -You can also import function and tick that: +You can also import function and tick that: ```python from evennia import TICKER_HANDLER as tickerhandler @@ -31,64 +44,93 @@ You can also import function and tick that: tickerhandler.add(30, myfunc) ``` -Removing (stopping) the ticker works as expected: +Removing (stopping) the ticker works as expected: ```python tickerhandler.remove(20, obj.at_tick) - tickerhandler.remove(30, myfunc) + tickerhandler.remove(30, myfunc) ``` -Note that you have to also supply `interval` to identify which subscription to remove. This is because the TickerHandler maintains a pool of tickers and a given callable can subscribe to be ticked at any number of different intervals. +Note that you have to also supply `interval` to identify which subscription to remove. This is +because the TickerHandler maintains a pool of tickers and a given callable can subscribe to be +ticked at any number of different intervals. The full definition of the `tickerhandler.add` method is ```python - tickerhandler.add(interval, callback, + tickerhandler.add(interval, callback, idstring="", persistent=True, *args, **kwargs) ``` -Here `*args` and `**kwargs` will be passed to `callback` every `interval` seconds. If `persistent` is `False`, this subscription will not survive a server reload. +Here `*args` and `**kwargs` will be passed to `callback` every `interval` seconds. If `persistent` +is `False`, this subscription will not survive a server reload. -Tickers are identified and stored by making a key of the callable itself, the ticker-interval, the `persistent` flag and the `idstring` (the latter being an empty string when not given explicitly). +Tickers are identified and stored by making a key of the callable itself, the ticker-interval, the +`persistent` flag and the `idstring` (the latter being an empty string when not given explicitly). -Since the arguments are not included in the ticker's identification, the `idstring` must be used to have a specific callback triggered multiple times on the same interval but with different arguments: +Since the arguments are not included in the ticker's identification, the `idstring` must be used to +have a specific callback triggered multiple times on the same interval but with different arguments: ```python tickerhandler.add(10, obj.update, "ticker1", True, 1, 2, 3) tickerhandler.add(10, obj.update, "ticker2", True, 4, 5) ``` -> Note that, when we want to send arguments to our callback within a ticker handler, we need to specify `idstring` and `persistent` before, unless we call our arguments as keywords, which would often be more readable: +> Note that, when we want to send arguments to our callback within a ticker handler, we need to +specify `idstring` and `persistent` before, unless we call our arguments as keywords, which would +often be more readable: ```python tickerhandler.add(10, obj.update, caller=self, value=118) ``` -If you add a ticker with exactly the same combination of callback, interval and idstring, it will overload the existing ticker. This identification is also crucial for later removing (stopping) the subscription: +If you add a ticker with exactly the same combination of callback, interval and idstring, it will +overload the existing ticker. This identification is also crucial for later removing (stopping) the +subscription: ```python tickerhandler.remove(10, obj.update, idstring="ticker1") tickerhandler.remove(10, obj.update, idstring="ticker2") ``` -The `callable` can be on any form as long as it accepts the arguments you give to send to it in `TickerHandler.add`. +The `callable` can be on any form as long as it accepts the arguments you give to send to it in +`TickerHandler.add`. -> Note that everything you supply to the TickerHandler will need to be pickled at some point to be saved into the database. Most of the time the handler will correctly store things like database objects, but the same restrictions as for [Attributes](./Attributes) apply to what the TickerHandler may store. +> Note that everything you supply to the TickerHandler will need to be pickled at some point to be +saved into the database. Most of the time the handler will correctly store things like database +objects, but the same restrictions as for [Attributes](./Attributes) apply to what the TickerHandler +may store. -When testing, you can stop all tickers in the entire game with `tickerhandler.clear()`. You can also view the currently subscribed objects with `tickerhandler.all()`. +When testing, you can stop all tickers in the entire game with `tickerhandler.clear()`. You can also +view the currently subscribed objects with `tickerhandler.all()`. See the [Weather Tutorial](./Weather-Tutorial) for an example of using the TickerHandler. ### When *not* to use TickerHandler -Using the TickerHandler may sound very useful but it is important to consider when not to use it. Even if you are used to habitually relying on tickers for everything in other code bases, stop and think about what you really need it for. This is the main point: +Using the TickerHandler may sound very useful but it is important to consider when not to use it. +Even if you are used to habitually relying on tickers for everything in other code bases, stop and +think about what you really need it for. This is the main point: -> You should *never* use a ticker to catch *changes*. +> You should *never* use a ticker to catch *changes*. -Think about it - you might have to run the ticker every second to react to the change fast enough. Most likely nothing will have changed at a given moment. So you are doing pointless calls (since skipping the call gives the same result as doing it). Making sure nothing's changed might even be computationally expensive depending on the complexity of your system. Not to mention that you might need to run the check *on every object in the database*. Every second. Just to maintain status quo ... +Think about it - you might have to run the ticker every second to react to the change fast enough. +Most likely nothing will have changed at a given moment. So you are doing pointless calls (since +skipping the call gives the same result as doing it). Making sure nothing's changed might even be +computationally expensive depending on the complexity of your system. Not to mention that you might +need to run the check *on every object in the database*. Every second. Just to maintain status quo +... -Rather than checking over and over on the off-chance that something changed, consider a more proactive approach. Could you implement your rarely changing system to *itself* report when its status changes? It's almost always much cheaper/efficient if you can do things "on demand". Evennia itself uses hook methods for this very reason. +Rather than checking over and over on the off-chance that something changed, consider a more +proactive approach. Could you implement your rarely changing system to *itself* report when its +status changes? It's almost always much cheaper/efficient if you can do things "on demand". Evennia +itself uses hook methods for this very reason. -So, if you consider a ticker that will fire very often but which you expect to have no effect 99% of the time, consider handling things things some other way. A self-reporting on-demand solution is usually cheaper also for fast-updating properties. Also remember that some things may not need to be updated until someone actually is examining or using them - any interim changes happening up to that moment are pointless waste of computing time. +So, if you consider a ticker that will fire very often but which you expect to have no effect 99% of +the time, consider handling things things some other way. A self-reporting on-demand solution is +usually cheaper also for fast-updating properties. Also remember that some things may not need to be +updated until someone actually is examining or using them - any interim changes happening up to that +moment are pointless waste of computing time. -The main reason for needing a ticker is when you want things to happen to multiple objects at the same time without input from something else. \ No newline at end of file +The main reason for needing a ticker is when you want things to happen to multiple objects at the +same time without input from something else. \ No newline at end of file diff --git a/docs/source/Turn-based-Combat-System.md b/docs/source/Turn-based-Combat-System.md index 3023137432..d0a0dc864c 100644 --- a/docs/source/Turn-based-Combat-System.md +++ b/docs/source/Turn-based-Combat-System.md @@ -1,47 +1,100 @@ # Turn based Combat System -This tutorial gives an example of a full, if simplified, combat system for Evennia. It was inspired by the discussions held on the [mailing list](https://groups.google.com/forum/#!msg/evennia/wnJNM2sXSfs/-dbLRrgWnYMJ). +This tutorial gives an example of a full, if simplified, combat system for Evennia. It was inspired +by the discussions held on the [mailing +list](https://groups.google.com/forum/#!msg/evennia/wnJNM2sXSfs/-dbLRrgWnYMJ). ## Overview of combat system concepts Most MUDs will use some sort of combat system. There are several main variations: -- _Freeform_ - the simplest form of combat to implement, common to MUSH-style roleplaying games. This means the system only supplies dice rollers or maybe commands to compare skills and spit out the result. Dice rolls are done to resolve combat according to the rules of the game and to direct the scene. A game master may be required to resolve rule disputes. -- _Twitch_ - This is the traditional MUD hack&slash style combat. In a twitch system there is often no difference between your normal "move-around-and-explore mode" and the "combat mode". You enter an attack command and the system will calculate if the attack hits and how much damage was caused. Normally attack commands have some sort of timeout or notion of recovery/balance to reduce the advantage of spamming or client scripting. Whereas the simplest systems just means entering `kill ` over and over, more sophisticated twitch systems include anything from defensive stances to tactical positioning. -- _Turn-based_ - a turn based system means that the system pauses to make sure all combatants can choose their actions before continuing. In some systems, such entered actions happen immediately (like twitch-based) whereas in others the resolution happens simultaneously at the end of the turn. The disadvantage of a turn-based system is that the game must switch to a "combat mode" and one also needs to take special care of how to handle new combatants and the passage of time. The advantage is that success is not dependent on typing speed or of setting up quick client macros. This potentially allows for emoting as part of combat which is an advantage for roleplay-heavy games. +- _Freeform_ - the simplest form of combat to implement, common to MUSH-style roleplaying games. +This means the system only supplies dice rollers or maybe commands to compare skills and spit out +the result. Dice rolls are done to resolve combat according to the rules of the game and to direct +the scene. A game master may be required to resolve rule disputes. +- _Twitch_ - This is the traditional MUD hack&slash style combat. In a twitch system there is often +no difference between your normal "move-around-and-explore mode" and the "combat mode". You enter an +attack command and the system will calculate if the attack hits and how much damage was caused. +Normally attack commands have some sort of timeout or notion of recovery/balance to reduce the +advantage of spamming or client scripting. Whereas the simplest systems just means entering `kill +` over and over, more sophisticated twitch systems include anything from defensive stances +to tactical positioning. +- _Turn-based_ - a turn based system means that the system pauses to make sure all combatants can +choose their actions before continuing. In some systems, such entered actions happen immediately +(like twitch-based) whereas in others the resolution happens simultaneously at the end of the turn. +The disadvantage of a turn-based system is that the game must switch to a "combat mode" and one also +needs to take special care of how to handle new combatants and the passage of time. The advantage is +that success is not dependent on typing speed or of setting up quick client macros. This potentially +allows for emoting as part of combat which is an advantage for roleplay-heavy games. -To implement a freeform combat system all you need is a dice roller and a roleplaying rulebook. See [contrib/dice.py](https://github.com/evennia/evennia/blob/master/evennia/contrib/dice.py) for an example dice roller. To implement at twitch-based system you basically need a few combat [commands](./Commands), possibly ones with a [cooldown](./Command-Cooldown). You also need a [game rule module](./Implementing-a-game-rule-system) that makes use of it. We will focus on the turn-based variety here. +To implement a freeform combat system all you need is a dice roller and a roleplaying rulebook. See +[contrib/dice.py](https://github.com/evennia/evennia/blob/master/evennia/contrib/dice.py) for an +example dice roller. To implement at twitch-based system you basically need a few combat +[commands](./Commands), possibly ones with a [cooldown](./Command-Cooldown). You also need a [game rule +module](Implementing-a-game-rule-system) that makes use of it. We will focus on the turn-based +variety here. ## Tutorial overview -This tutorial will implement the slightly more complex turn-based combat system. Our example has the following properties: +This tutorial will implement the slightly more complex turn-based combat system. Our example has the +following properties: - Combat is initiated with `attack `, this initiates the combat mode. -- Characters may join an ongoing battle using `attack ` against a character already in combat. -- Each turn every combating character will get to enter two commands, their internal order matters and they are compared one-to-one in the order given by each combatant. Use of `say` and `pose` is free. -- The commands are (in our example) simple; they can either `hit `, `feint ` or `parry `. They can also `defend`, a generic passive defense. Finally they may choose to `disengage/flee`. -- When attacking we use a classic [rock-paper-scissors](https://en.wikipedia.org/wiki/Rock-paper-scissors) mechanic to determine success: `hit` defeats `feint`, which defeats `parry` which defeats `hit`. `defend` is a general passive action that has a percentage chance to win against `hit` (only). -- `disengage/flee` must be entered two times in a row and will only succeed if there is no `hit` against them in that time. If so they will leave combat mode. -- Once every player has entered two commands, all commands are resolved in order and the result is reported. A new turn then begins. -- If players are too slow the turn will time out and any unset commands will be set to `defend`. +- Characters may join an ongoing battle using `attack ` against a character already in +combat. +- Each turn every combating character will get to enter two commands, their internal order matters +and they are compared one-to-one in the order given by each combatant. Use of `say` and `pose` is +free. +- The commands are (in our example) simple; they can either `hit `, `feint ` or +`parry `. They can also `defend`, a generic passive defense. Finally they may choose to +`disengage/flee`. +- When attacking we use a classic [rock-paper-scissors](https://en.wikipedia.org/wiki/Rock-paper- +scissors) mechanic to determine success: `hit` defeats `feint`, which defeats `parry` which defeats +`hit`. `defend` is a general passive action that has a percentage chance to win against `hit` +(only). +- `disengage/flee` must be entered two times in a row and will only succeed if there is no `hit` +against them in that time. If so they will leave combat mode. +- Once every player has entered two commands, all commands are resolved in order and the result is +reported. A new turn then begins. +- If players are too slow the turn will time out and any unset commands will be set to `defend`. For creating the combat system we will need the following components: -- A combat handler. This is the main mechanic of the system. This is a [Script](./Scripts) object created for each combat. It is not assigned to a specific object but is shared by the combating characters and handles all the combat information. Since Scripts are database entities it also means that the combat will not be affected by a server reload. -- A combat [command set](./Command-Sets) with the relevant commands needed for combat, such as the various attack/defend options and the `flee/disengage` command to leave the combat mode. -- A rule resolution system. The basics of making such a module is described in the [rule system tutorial](./Implementing-a-game-rule-system). We will only sketch such a module here for our end-turn combat resolution. -- An `attack` [command](./Commands) for initiating the combat mode. This is added to the default command set. It will create the combat handler and add the character(s) to it. It will also assign the combat command set to the characters. +- A combat handler. This is the main mechanic of the system. This is a [Script](./Scripts) object +created for each combat. It is not assigned to a specific object but is shared by the combating +characters and handles all the combat information. Since Scripts are database entities it also means +that the combat will not be affected by a server reload. +- A combat [command set](./Command-Sets) with the relevant commands needed for combat, such as the +various attack/defend options and the `flee/disengage` command to leave the combat mode. +- A rule resolution system. The basics of making such a module is described in the [rule system +tutorial](Implementing-a-game-rule-system). We will only sketch such a module here for our end-turn +combat resolution. +- An `attack` [command](./Commands) for initiating the combat mode. This is added to the default +command set. It will create the combat handler and add the character(s) to it. It will also assign +the combat command set to the characters. ## The combat handler -The _combat handler_ is implemented as a stand-alone [Script](./Scripts). This Script is created when the first Character decides to attack another and is deleted when no one is fighting any more. Each handler represents one instance of combat and one combat only. Each instance of combat can hold any number of characters but each character can only be part of one combat at a time (a player would need to disengage from the first combat before they could join another). +The _combat handler_ is implemented as a stand-alone [Script](./Scripts). This Script is created when +the first Character decides to attack another and is deleted when no one is fighting any more. Each +handler represents one instance of combat and one combat only. Each instance of combat can hold any +number of characters but each character can only be part of one combat at a time (a player would +need to disengage from the first combat before they could join another). -The reason we don't store this Script "on" any specific character is because any character may leave the combat at any time. Instead the script holds references to all characters involved in the combat. Vice-versa, all characters holds a back-reference to the current combat handler. While we don't use this very much here this might allow the combat commands on the characters to access and update the combat handler state directly. +The reason we don't store this Script "on" any specific character is because any character may leave +the combat at any time. Instead the script holds references to all characters involved in the +combat. Vice-versa, all characters holds a back-reference to the current combat handler. While we +don't use this very much here this might allow the combat commands on the characters to access and +update the combat handler state directly. -_Note: Another way to implement a combat handler would be to use a normal Python object and handle time-keeping with the [TickerHandler](./TickerHandler). This would require either adding custom hook methods on the character or to implement a custom child of the TickerHandler class to track turns. Whereas the TickerHandler is easy to use, a Script offers more power in this case._ +_Note: Another way to implement a combat handler would be to use a normal Python object and handle +time-keeping with the [TickerHandler](./TickerHandler). This would require either adding custom hook +methods on the character or to implement a custom child of the TickerHandler class to track turns. +Whereas the TickerHandler is easy to use, a Script offers more power in this case._ -Here is a basic combat handler. Assuming our game folder is named `mygame`, we store it in `mygame/typeclasses/combat_handler.py`: +Here is a basic combat handler. Assuming our game folder is named `mygame`, we store it in +`mygame/typeclasses/combat_handler.py`: ```python # mygame/typeclasses/combat_handler.py @@ -55,7 +108,7 @@ class CombatHandler(DefaultScript): This implements the combat handler. """ - # standard Script hooks + # standard Script hooks def at_script_creation(self): "Called when script is first created" @@ -64,7 +117,7 @@ class CombatHandler(DefaultScript): self.desc = "handles combat" self.interval = 60 * 2 # two minute timeout self.start_delay = True - self.persistent = True + self.persistent = True # store all combatants self.db.characters = {} @@ -75,7 +128,7 @@ class CombatHandler(DefaultScript): def _init_character(self, character): """ - This initializes handler back-reference + This initializes handler back-reference and combat cmdset on a character """ character.ndb.combat_handler = self @@ -83,20 +136,20 @@ class CombatHandler(DefaultScript): def _cleanup_character(self, character): """ - Remove character from handler and clean + Remove character from handler and clean it of the back-reference and cmdset """ - dbref = character.id + dbref = character.id del self.db.characters[dbref] del self.db.turn_actions[dbref] - del self.db.action_count[dbref] + del self.db.action_count[dbref] del character.ndb.combat_handler character.cmdset.delete("commands.combat.CombatCmdSet") def at_start(self): """ This is called on first start but also when the script is restarted - after a server reboot. We need to re-assign this combat handler to + after a server reboot. We need to re-assign this combat handler to all characters as well as re-assign the cmdset. """ for character in self.db.characters.values(): @@ -110,10 +163,10 @@ class CombatHandler(DefaultScript): def at_repeat(self): """ - This is called every self.interval seconds (turn timeout) or - when force_repeat is called (because everyone has entered their + This is called every self.interval seconds (turn timeout) or + when force_repeat is called (because everyone has entered their commands). We know this by checking the existence of the - `normal_turn_end` NAttribute, set just before calling + `normal_turn_end` NAttribute, set just before calling force_repeat. """ @@ -121,7 +174,7 @@ class CombatHandler(DefaultScript): # we get here because the turn ended normally # (force_repeat was called) - no msg output del self.ndb.normal_turn_end - else: + else: # turn timeout self.msg_all("Turn timer timed out. Continuing.") self.end_turn() @@ -131,7 +184,7 @@ class CombatHandler(DefaultScript): def add_character(self, character): "Add combatant to handler" dbref = character.id - self.db.characters[dbref] = character + self.db.characters[dbref] = character self.db.action_count[dbref] = 0 self.db.turn_actions[dbref] = [("defend", character, None), ("defend", character, None)] @@ -161,13 +214,13 @@ class CombatHandler(DefaultScript): actions are stored in a dictionary keyed to each character, each of which holds a list of max 2 actions. An action is stored as - a tuple (character, action, target). + a tuple (character, action, target). """ dbref = character.id count = self.db.action_count[dbref] - if 0 <= count <= 1: # only allow 2 actions + if 0 <= count <= 1: # only allow 2 actions self.db.turn_actions[dbref][count] = (action, character, target) - else: + else: # report if we already used too many actions return False self.db.action_count[dbref] += 1 @@ -175,22 +228,22 @@ class CombatHandler(DefaultScript): def check_end_turn(self): """ - Called by the command to eventually trigger + Called by the command to eventually trigger the resolution of the turn. We check if everyone has added all their actions; if so we call force the script to repeat immediately (which will call - `self.at_repeat()` while resetting all timers). + `self.at_repeat()` while resetting all timers). """ if all(count > 1 for count in self.db.action_count.values()): self.ndb.normal_turn_end = True - self.force_repeat() + self.force_repeat() def end_turn(self): """ - This resolves all actions by calling the rules module. + This resolves all actions by calling the rules module. It then resets everything and starts the next turn. It is called by at_repeat(). - """ + """ resolve_combat(self, self.db.turn_actions) if len(self.db.characters) < 2: @@ -207,13 +260,21 @@ class CombatHandler(DefaultScript): self.msg_all("Next turn begins ...") ``` -This implements all the useful properties of our combat handler. This Script will survive a reboot and will automatically re-assert itself when it comes back online. Even the current state of the combat should be unaffected since it is saved in Attributes at every turn. An important part to note is the use of the Script's standard `at_repeat` hook and the `force_repeat` method to end each turn. This allows for everything to go through the same mechanisms with minimal repetition of code. +This implements all the useful properties of our combat handler. This Script will survive a reboot +and will automatically re-assert itself when it comes back online. Even the current state of the +combat should be unaffected since it is saved in Attributes at every turn. An important part to note +is the use of the Script's standard `at_repeat` hook and the `force_repeat` method to end each turn. +This allows for everything to go through the same mechanisms with minimal repetition of code. -What is not present in this handler is a way for players to view the actions they set or to change their actions once they have been added (but before the last one has added theirs). We leave this as an exercise. +What is not present in this handler is a way for players to view the actions they set or to change +their actions once they have been added (but before the last one has added theirs). We leave this as +an exercise. ## Combat commands -Our combat commands - the commands that are to be available to us during the combat - are (in our example) very simple. In a full implementation the commands available might be determined by the weapon(s) held by the player or by which skills they know. +Our combat commands - the commands that are to be available to us during the combat - are (in our +example) very simple. In a full implementation the commands available might be determined by the +weapon(s) held by the player or by which skills they know. We create them in `mygame/commands/combat.py`. @@ -239,13 +300,13 @@ class CmdHit(Command): "Implements the command" if not self.args: self.caller.msg("Usage: hit ") - return + return target = self.caller.search(self.args) if not target: return - ok = self.caller.ndb.combat_handler.add_action("hit", - self.caller, - target) + ok = self.caller.ndb.combat_handler.add_action("hit", + self.caller, + target) if ok: self.caller.msg("You add 'hit' to the combat queue") else: @@ -255,7 +316,9 @@ class CmdHit(Command): self.caller.ndb.combat_handler.check_end_turn() ``` -The other commands `CmdParry`, `CmdFeint`, `CmdDefend` and `CmdDisengage` look basically the same. We should also add a custom `help` command to list all the available combat commands and what they do. +The other commands `CmdParry`, `CmdFeint`, `CmdDefend` and `CmdDisengage` look basically the same. +We should also add a custom `help` command to list all the available combat commands and what they +do. We just need to put them all in a cmdset. We do this at the end of the same module: @@ -268,7 +331,7 @@ from evennia import default_cmds class CombatCmdSet(CmdSet): key = "combat_cmdset" mergetype = "Replace" - priority = 10 + priority = 10 no_exits = True def at_cmdset_creation(self): @@ -276,7 +339,7 @@ class CombatCmdSet(CmdSet): self.add(CmdParry()) self.add(CmdFeint()) self.add(CmdDefend()) - self.add(CmdDisengage()) + self.add(CmdDisengage()) self.add(CmdHelp()) self.add(default_cmds.CmdPose()) self.add(default_cmds.CmdSay()) @@ -284,19 +347,32 @@ class CombatCmdSet(CmdSet): ## Rules module -A general way to implement a rule module is found in the [rule system tutorial](./Implementing-a-game-rule-system). Proper resolution would likely require us to change our Characters to store things like strength, weapon skills and so on. So for this example we will settle for a very simplistic rock-paper-scissors kind of setup with some randomness thrown in. We will not deal with damage here but just announce the results of each turn. In a real system the Character objects would hold stats to affect their skills, their chosen weapon affect the choices, they would be able to lose health etc. +A general way to implement a rule module is found in the [rule system tutorial](Implementing-a-game- +rule-system). Proper resolution would likely require us to change our Characters to store things +like strength, weapon skills and so on. So for this example we will settle for a very simplistic +rock-paper-scissors kind of setup with some randomness thrown in. We will not deal with damage here +but just announce the results of each turn. In a real system the Character objects would hold stats +to affect their skills, their chosen weapon affect the choices, they would be able to lose health +etc. -Within each turn, there are "sub-turns", each consisting of one action per character. The actions within each sub-turn happens simultaneously and only once they have all been resolved we move on to the next sub-turn (or end the full turn). +Within each turn, there are "sub-turns", each consisting of one action per character. The actions +within each sub-turn happens simultaneously and only once they have all been resolved we move on to +the next sub-turn (or end the full turn). -*Note: In our simple example the sub-turns don't affect each other (except for `disengage/flee`), nor do any effects carry over between turns. The real power of a turn-based system would be to add real tactical possibilities here though; For example if your hit got parried you could be out of balance and your next action would be at a disadvantage. A successful feint would open up for a subsequent attack and so on ...* +*Note: In our simple example the sub-turns don't affect each other (except for `disengage/flee`), +nor do any effects carry over between turns. The real power of a turn-based system would be to add +real tactical possibilities here though; For example if your hit got parried you could be out of +balance and your next action would be at a disadvantage. A successful feint would open up for a +subsequent attack and so on ...* -Our rock-paper-scissor setup works like this: +Our rock-paper-scissor setup works like this: -- `hit` beats `feint` and `flee/disengage`. It has a random chance to fail against `defend`. +- `hit` beats `feint` and `flee/disengage`. It has a random chance to fail against `defend`. - `parry` beats `hit`. - `feint` beats `parry` and is then counted as a `hit`. - `defend` does nothing but has a chance to beat `hit`. -- `flee/disengage` must succeed two times in a row (i.e. not beaten by a `hit` once during the turn). If so the character leaves combat. +- `flee/disengage` must succeed two times in a row (i.e. not beaten by a `hit` once during the +turn). If so the character leaves combat. ```python @@ -304,7 +380,7 @@ Our rock-paper-scissor setup works like this: import random -# messages +# messages def resolve_combat(combat_handler, actiondict): """ @@ -378,11 +454,16 @@ def resolve_combat(combat_handler, actiondict): combat_handler.remove_character(char) ``` -To make it simple (and to save space), this example rule module actually resolves each interchange twice - first when it gets to each character and then again when handling the target. Also, since we use the combat handler's `msg_all` method here, the system will get pretty spammy. To clean it up, one could imagine tracking all the possible interactions to make sure each pair is only handled and reported once. +To make it simple (and to save space), this example rule module actually resolves each interchange +twice - first when it gets to each character and then again when handling the target. Also, since we +use the combat handler's `msg_all` method here, the system will get pretty spammy. To clean it up, +one could imagine tracking all the possible interactions to make sure each pair is only handled and +reported once. ## Combat initiator command -This is the last component we need, a command to initiate combat. This will tie everything together. We store this with the other combat commands. +This is the last component we need, a command to initiate combat. This will tie everything together. +We store this with the other combat commands. ```python # mygame/commands/combat.py @@ -397,7 +478,7 @@ class CmdAttack(Command): attack This will initiate combat with . If ") + self.caller.msg("Usage: attack ") return target = self.caller.search(self.args) if not target: return # set up combat if target.ndb.combat_handler: - # target is already in combat - join it + # target is already in combat - join it target.ndb.combat_handler.add_character(self.caller) target.ndb.combat_handler.msg_all("%s joins combat!" % self.caller) else: @@ -421,12 +502,19 @@ class CmdAttack(Command): chandler.add_character(self.caller) chandler.add_character(target) self.caller.msg("You attack %s! You are in combat." % target) - target.msg("%s attacks you! You are in combat." % self.caller) + target.msg("%s attacks you! You are in combat." % self.caller) ``` -The `attack` command will not go into the combat cmdset but rather into the default cmdset. See e.g. the [Adding Command Tutorial](./Adding-Command-Tutorial) if you are unsure about how to do this. +The `attack` command will not go into the combat cmdset but rather into the default cmdset. See e.g. +the [Adding Command Tutorial](./Adding-Command-Tutorial) if you are unsure about how to do this. ## Expanding the example -At this point you should have a simple but flexible turn-based combat system. We have taken several shortcuts and simplifications in this example. The output to the players is likely too verbose during combat and too limited when it comes to informing about things surrounding it. Methods for changing your commands or list them, view who is in combat etc is likely needed - this will require play testing for each game and style. There is also currently no information displayed for other people happening to be in the same room as the combat - some less detailed information should probably be echoed to the room to +At this point you should have a simple but flexible turn-based combat system. We have taken several +shortcuts and simplifications in this example. The output to the players is likely too verbose +during combat and too limited when it comes to informing about things surrounding it. Methods for +changing your commands or list them, view who is in combat etc is likely needed - this will require +play testing for each game and style. There is also currently no information displayed for other +people happening to be in the same room as the combat - some less detailed information should +probably be echoed to the room to show others what's going on. diff --git a/docs/source/Tutorial-Aggressive-NPCs.md b/docs/source/Tutorial-Aggressive-NPCs.md index b1a83ed2d9..741639247a 100644 --- a/docs/source/Tutorial-Aggressive-NPCs.md +++ b/docs/source/Tutorial-Aggressive-NPCs.md @@ -1,22 +1,28 @@ # Tutorial Aggressive NPCs -This tutorial shows the implementation of an NPC object that responds to characters entering their location. In this example the NPC has the option to respond aggressively or not, but any actions could be triggered this way. +This tutorial shows the implementation of an NPC object that responds to characters entering their +location. In this example the NPC has the option to respond aggressively or not, but any actions +could be triggered this way. -One could imagine using a [Script](./Scripts) that is constantly checking for newcomers. This would be highly inefficient (most of the time its check would fail). Instead we handle this on-demand by using a couple of existing object hooks to inform the NPC that a Character has entered. +One could imagine using a [Script](./Scripts) that is constantly checking for newcomers. This would be +highly inefficient (most of the time its check would fail). Instead we handle this on-demand by +using a couple of existing object hooks to inform the NPC that a Character has entered. -It is assumed that you already know how to create custom room and character typeclasses, please see the [Basic Game tutorial](./Tutorial-for-basic-MUSH-like-game) if you haven't already done this. +It is assumed that you already know how to create custom room and character typeclasses, please see +the [Basic Game tutorial](./Tutorial-for-basic-MUSH-like-game) if you haven't already done this. -What we will need is the following: +What we will need is the following: - An NPC typeclass that can react when someone enters. - A custom [Room](./Objects#rooms) typeclass that can tell the NPC that someone entered. -- We will also tweak our default `Character` typeclass a little. +- We will also tweak our default `Character` typeclass a little. -To begin with, we need to create an NPC typeclass. Create a new file inside of your typeclasses folder and name it `npcs.py` and then add the following code: +To begin with, we need to create an NPC typeclass. Create a new file inside of your typeclasses +folder and name it `npcs.py` and then add the following code: ```python -from typeclasses.characters import Character +from typeclasses.characters import Character class NPC(Character): """ @@ -24,16 +30,20 @@ class NPC(Character): """ def at_char_entered(self, character): """ - A simple is_aggressive check. + A simple is_aggressive check. Can be expanded upon later. - """ + """ if self.db.is_aggressive: self.execute_cmd(f"say Graaah, die {character}!") else: self.execute_cmd(f"say Greetings, {character}!") ``` -We will define our custom `Character` typeclass below. As for the new `at_char_entered` method we've just defined, we'll ensure that it will be called by the room where the NPC is located, when a player enters that room. You'll notice that right now, the NPC merely speaks. You can expand this part as you like and trigger all sorts of effects here (like combat code, fleeing, bartering or quest-giving) as your game design dictates. +We will define our custom `Character` typeclass below. As for the new `at_char_entered` method we've +just defined, we'll ensure that it will be called by the room where the NPC is located, when a +player enters that room. You'll notice that right now, the NPC merely speaks. You can expand this +part as you like and trigger all sorts of effects here (like combat code, fleeing, bartering or +quest-giving) as your game design dictates. Now your `typeclasses.rooms` module needs to have the following added: @@ -45,29 +55,42 @@ from evennia import utils def at_object_receive(self, obj, source_location): if utils.inherits_from(obj, 'typeclasses.npcs.NPC'): # An NPC has entered return - elif utils.inherits_from(obj, 'typeclasses.characters.Character'): + elif utils.inherits_from(obj, 'typeclasses.characters.Character'): # A PC has entered. # Cause the player's character to look around. obj.execute_cmd('look') for item in self.contents: - if utils.inherits_from(item, 'typeclasses.npcs.NPC'): + if utils.inherits_from(item, 'typeclasses.npcs.NPC'): # An NPC is in the room item.at_char_entered(obj) ``` -`inherits_from` must be given the full path of the class. If the object inherited a class from your `world.races` module, then you would check inheritance with `world.races.Human`, for example. There is no need to import these prior, as we are passing in the full path. As a matter of a fact, `inherits_from` does not properly work if you import the class and only pass in the name of the class. +`inherits_from` must be given the full path of the class. If the object inherited a class from your +`world.races` module, then you would check inheritance with `world.races.Human`, for example. There +is no need to import these prior, as we are passing in the full path. As a matter of a fact, +`inherits_from` does not properly work if you import the class and only pass in the name of the +class. -> Note: [at_object_receive](https://github.com/evennia/evennia/blob/master/evennia/objects/objects.py#L1529) is a default hook of the `DefaultObject` typeclass (and its children). Here we are overriding this hook in our customized room typeclass to suit our needs. +> Note: +[at_object_receive](https://github.com/evennia/evennia/blob/master/evennia/objects/objects.py#L1529) +is a default hook of the `DefaultObject` typeclass (and its children). Here we are overriding this +hook in our customized room typeclass to suit our needs. -This room checks the typeclass of objects entering it (using `utils.inherits_from` and responds to `Characters`, ignoring other NPCs or objects. When triggered the room will look through its contents and inform any `NPCs inside by calling their `at_char_entered` method. +This room checks the typeclass of objects entering it (using `utils.inherits_from` and responds to +`Characters`, ignoring other NPCs or objects. When triggered the room will look through its +contents and inform any `NPCs inside by calling their `at_char_entered` method. -You'll also see that we have added a 'look' into this code. This is because, by default, the `at_object_receive` is carried out *before* the character's `at_after_move` which, we will now overload. This means that a character entering would see the NPC perform its actions before the 'look' command. Deactivate the look command in the default `Character` class within the `typeclasses.characters` module: +You'll also see that we have added a 'look' into this code. This is because, by default, the +`at_object_receive` is carried out *before* the character's `at_after_move` which, we will now +overload. This means that a character entering would see the NPC perform its actions before the +'look' command. Deactivate the look command in the default `Character` class within the +`typeclasses.characters` module: ```python # Add this hook in any blank area within your Character class. def at_after_move(self, source_location): """ - Default is to look around after a move + Default is to look around after a move Note: This has been moved to Room.at_object_receive """ #self.execute_cmd('look') @@ -80,15 +103,18 @@ reload create/drop Orc:npcs.NPC ``` -> Note: You could also give the path as `typeclasses.npcs.NPC`, but Evennia will look into the `typeclasses` folder automatically, so this is a little shorter. +> Note: You could also give the path as `typeclasses.npcs.NPC`, but Evennia will look into the +`typeclasses` folder automatically, so this is a little shorter. -When you enter the aggressive NPC's location, it will default to using its peaceful action (say your name is Anna): +When you enter the aggressive NPC's location, it will default to using its peaceful action (say your +name is Anna): ``` Orc says, "Greetings, Anna!" ``` -Now we turn on the aggressive mode (we do it manually but it could also be triggered by some sort of AI code). +Now we turn on the aggressive mode (we do it manually but it could also be triggered by some sort of +AI code). ``` set orc/is_aggressive = True diff --git a/docs/source/Tutorial-NPCs-listening.md b/docs/source/Tutorial-NPCs-listening.md index b04adb3a85..552e1d463b 100644 --- a/docs/source/Tutorial-NPCs-listening.md +++ b/docs/source/Tutorial-NPCs-listening.md @@ -1,9 +1,12 @@ # Tutorial NPCs listening -This tutorial shows the implementation of an NPC object that responds to characters speaking in their location. In this example the NPC parrots what is said, but any actions could be triggered this way. +This tutorial shows the implementation of an NPC object that responds to characters speaking in +their location. In this example the NPC parrots what is said, but any actions could be triggered +this way. -It is assumed that you already know how to create custom room and character typeclasses, please see the [Basic Game tutorial](./Tutorial-for-basic-MUSH-like-game) if you haven't already done this. +It is assumed that you already know how to create custom room and character typeclasses, please see +the [Basic Game tutorial](./Tutorial-for-basic-MUSH-like-game) if you haven't already done this. What we will need is simply a new NPC typeclass that can react when someone speaks. @@ -18,9 +21,9 @@ class Npc(Character): def at_heard_say(self, message, from_obj): """ A simple listener and response. This makes it easy to change for - subclasses of NPCs reacting differently to says. + subclasses of NPCs reacting differently to says. - """ + """ # message will be on the form ` says, "say_text"` # we want to get only say_text without the quotes and any spaces message = message.split('says, ')[1].strip(' "') @@ -29,7 +32,8 @@ class Npc(Character): return "%s said: '%s'" % (from_obj, message) ``` -When someone in the room speaks to this NPC, its `msg` method will be called. We will modify the NPCs `.msg` method to catch says so the NPC can respond. +When someone in the room speaks to this NPC, its `msg` method will be called. We will modify the +NPCs `.msg` method to catch says so the NPC can respond. ```python @@ -56,18 +60,32 @@ class Npc(Character): # If there is a response if response != None: # speak ourselves, using the return - self.execute_cmd("say %s" % response) + self.execute_cmd("say %s" % response) # this is needed if anyone ever puppets this NPC - without it you would never # get any feedback from the server (not even the results of look) - super().msg(text=text, from_obj=from_obj, **kwargs) + super().msg(text=text, from_obj=from_obj, **kwargs) ``` -So if the NPC gets a say and that say is not coming from the NPC itself, it will echo it using the `at_heard_say` hook. Some things of note in the above example: +So if the NPC gets a say and that say is not coming from the NPC itself, it will echo it using the +`at_heard_say` hook. Some things of note in the above example: -- The `text` input can be on many different forms depending on where this `msg` is called from. Instead of trying to analyze `text` in detail with a range of `if` statements we just assume the form we want and catch the error if it does not match. This simplifies the code considerably. It's called 'leap before you look' and is a Python paradigm that may feel unfamiliar if you are used to other languages. Here we 'swallow' the error silently, which is fine when the code checked is simple. If not we may want to import `evennia.logger.log_trace` and add `log_trace()` in the `except` clause. -- We use `execute_cmd` to fire the `say` command back. We could also have called `self.location.msg_contents` directly but using the Command makes sure all hooks are called (so those seeing the NPC's `say` can in turn react if they want). -- Note the comments about `super` at the end. This will trigger the 'default' `msg` (in the parent class) as well. It's not really necessary as long as no one puppets the NPC (by `@ic `) but it's wise to keep in there since the puppeting player will be totally blind if `msg()` is never returning anything to them! +- The `text` input can be on many different forms depending on where this `msg` is called from. +Instead of trying to analyze `text` in detail with a range of `if` statements we just assume the +form we want and catch the error if it does not match. This simplifies the code considerably. It's +called 'leap before you look' and is a Python paradigm that may feel unfamiliar if you are used to +other languages. Here we 'swallow' the error silently, which is fine when the code checked is +simple. If not we may want to import `evennia.logger.log_trace` and add `log_trace()` in the +`except` clause.
+If you would like to learn more about the `text` list used above refer to the [Out-Of-Band](./OOB) +documentation. +- We use `execute_cmd` to fire the `say` command back. We could also have called +`self.location.msg_contents` directly but using the Command makes sure all hooks are called (so +those seeing the NPC's `say` can in turn react if they want). +- Note the comments about `super` at the end. This will trigger the 'default' `msg` (in the parent +class) as well. It's not really necessary as long as no one puppets the NPC (by `@ic `) but +it's wise to keep in there since the puppeting player will be totally blind if `msg()` is never +returning anything to them! Now that's done, let's create an NPC and see what it has to say for itself. @@ -76,7 +94,8 @@ Now that's done, let's create an NPC and see what it has to say for itself. @create/drop Guild Master:npc.Npc ``` -(you could also give the path as `typeclasses.npc.Npc`, but Evennia will look into the `typeclasses` folder automatically so this is a little shorter). +(you could also give the path as `typeclasses.npc.Npc`, but Evennia will look into the `typeclasses` +folder automatically so this is a little shorter). > say hi You say, "hi" @@ -84,6 +103,10 @@ Now that's done, let's create an NPC and see what it has to say for itself. ## Assorted notes -There are many ways to implement this kind of functionality. An alternative example to overriding `msg` would be to modify the `at_say` hook on the *Character* instead. It could detect that it's sending to an NPC and call the `at_heard_say` hook directly. +There are many ways to implement this kind of functionality. An alternative example to overriding +`msg` would be to modify the `at_say` hook on the *Character* instead. It could detect that it's +sending to an NPC and call the `at_heard_say` hook directly. -While the tutorial solution has the advantage of being contained only within the NPC class, combining this with using the Character class gives more direct control over how the NPC will react. Which way to go depends on the design requirements of your particular game. +While the tutorial solution has the advantage of being contained only within the NPC class, +combining this with using the Character class gives more direct control over how the NPC will react. +Which way to go depends on the design requirements of your particular game. diff --git a/docs/source/Tutorial-Searching-For-Objects.md b/docs/source/Tutorial-Searching-For-Objects.md index 75190242ba..eb66335bcc 100644 --- a/docs/source/Tutorial-Searching-For-Objects.md +++ b/docs/source/Tutorial-Searching-For-Objects.md @@ -1,42 +1,81 @@ # Tutorial Searching For Objects -You will often want to operate on a specific object in the database. For example when a player attacks a named target you'll need to find that target so it can be attacked. Or when a rain storm draws in you need to find all outdoor-rooms so you can show it raining in them. This tutorial explains Evennia's tools for searching. +You will often want to operate on a specific object in the database. For example when a player +attacks a named target you'll need to find that target so it can be attacked. Or when a rain storm +draws in you need to find all outdoor-rooms so you can show it raining in them. This tutorial +explains Evennia's tools for searching. ## Things to search for -The first thing to consider is the base type of the thing you are searching for. Evennia organizes its database into a few main tables: [Objects](./Objects), [Accounts](./Accounts), [Scripts](./Scripts), [Channels](./Communications#channels), [Messages](Communication#Msg) and [Help Entries](./Help-System). Most of the time you'll likely spend your time searching for Objects and the occasional Accounts. +The first thing to consider is the base type of the thing you are searching for. Evennia organizes +its database into a few main tables: [Objects](./Objects), [Accounts](./Accounts), [Scripts](./Scripts), +[Channels](./Communications#channels), [Messages](Communication#Msg) and [Help Entries](./Help-System). +Most of the time you'll likely spend your time searching for Objects and the occasional Accounts. -So to find an entity, what can be searched for? +So to find an entity, what can be searched for? - - The `key` is the name of the entity. While you can get this from `obj.key` the *database field* is actually named `obj.db_key` - this is useful to know only when you do [direct database queries](./Tutorial-Searching-For-Objects#queries-in-django). The one exception is `Accounts`, where the database field for `.key` is instead named `username` (this is a Django requirement). When you don't specify search-type, you'll usually search based on key. *Aliases* are extra names given to Objects using something like `@alias` or `obj.aliases.add('name')`. The main search functions (see below) will automatically search for aliases whenever you search by-key. - - [Tags](./Tags) are the main way to group and identify objects in Evennia. Tags can most often be used (sometimes together with keys) to uniquely identify an object. For example, even though you have two locations with the same name, you can separate them by their tagging (this is how Evennia implements 'zones' seen in other systems). Tags can also have categories, to further organize your data for quick lookups. - - An object's [Attributes](./Attributes) can also used to find an object. This can be very useful but since Attributes can store almost any data they are far less optimized to search for than Tags or keys. -- The object's [Typeclass](./Typeclasses) indicate the sub-type of entity. A Character, Flower or Sword are all types of Objects. A Bot is a kind of Account. The database field is called `typeclass_path` and holds the full Python-path to the class. You can usually specify the `typeclass` as an argument to Evennia's search functions as well as use the class directly to limit queries. -- The `location` is only relevant for [Objects](./Objects) but is a very common way to weed down the number of candidates before starting to search. The reason is that most in-game commands tend to operate on things nearby (in the same room) so the choices can be limited from the start. -- The database id or the '#dbref' is unique (and never re-used) within each database table. So while there is one and only one Object with dbref `#42` there could also be an Account or Script with the dbref `#42` at the same time. In almost all search methods you can replace the "key" search criterion with `"#dbref"` to search for that id. This can occasionally be practical and may be what you are used to from other code bases. But it is considered *bad practice* in Evennia to rely on hard-coded #dbrefs to do your searches. It makes your code tied to the exact layout of the database. It's also not very maintainable to have to remember abstract numbers. Passing the actual objects around and searching by Tags and/or keys will usually get you what you need. + - The `key` is the name of the entity. While you can get this from `obj.key` the *database field* +is actually named `obj.db_key` - this is useful to know only when you do [direct database +queries](Tutorial-Searching-For-Objects#queries-in-django). The one exception is `Accounts`, where +the database field for `.key` is instead named `username` (this is a Django requirement). When you +don't specify search-type, you'll usually search based on key. *Aliases* are extra names given to +Objects using something like `@alias` or `obj.aliases.add('name')`. The main search functions (see +below) will automatically search for aliases whenever you search by-key. + - [Tags](./Tags) are the main way to group and identify objects in Evennia. Tags can most often be +used (sometimes together with keys) to uniquely identify an object. For example, even though you +have two locations with the same name, you can separate them by their tagging (this is how Evennia +implements 'zones' seen in other systems). Tags can also have categories, to further organize your +data for quick lookups. + - An object's [Attributes](./Attributes) can also used to find an object. This can be very useful but +since Attributes can store almost any data they are far less optimized to search for than Tags or +keys. +- The object's [Typeclass](./Typeclasses) indicate the sub-type of entity. A Character, Flower or +Sword are all types of Objects. A Bot is a kind of Account. The database field is called +`typeclass_path` and holds the full Python-path to the class. You can usually specify the +`typeclass` as an argument to Evennia's search functions as well as use the class directly to limit +queries. +- The `location` is only relevant for [Objects](./Objects) but is a very common way to weed down the +number of candidates before starting to search. The reason is that most in-game commands tend to +operate on things nearby (in the same room) so the choices can be limited from the start. +- The database id or the '#dbref' is unique (and never re-used) within each database table. So while +there is one and only one Object with dbref `#42` there could also be an Account or Script with the +dbref `#42` at the same time. In almost all search methods you can replace the "key" search +criterion with `"#dbref"` to search for that id. This can occasionally be practical and may be what +you are used to from other code bases. But it is considered *bad practice* in Evennia to rely on +hard-coded #dbrefs to do your searches. It makes your code tied to the exact layout of the database. +It's also not very maintainable to have to remember abstract numbers. Passing the actual objects +around and searching by Tags and/or keys will usually get you what you need. ## Getting objects inside another -All in-game [Objects](./Objects) have a `.contents` property that returns all objects 'inside' them (that is, all objects which has its `.location` property set to that object. This is a simple way to get everything in a room and is also faster since this lookup is cached and won't hit the database. +All in-game [Objects](./Objects) have a `.contents` property that returns all objects 'inside' them +(that is, all objects which has its `.location` property set to that object. This is a simple way to +get everything in a room and is also faster since this lookup is cached and won't hit the database. -- `roomobj.contents` returns a list of all objects inside `roomobj`. -- `obj.contents` same as for a room, except this usually represents the object's inventory +- `roomobj.contents` returns a list of all objects inside `roomobj`. +- `obj.contents` same as for a room, except this usually represents the object's inventory - `obj.location.contents` gets everything in `obj`'s location (including `obj` itself). -- `roomobj.exits` returns all exits starting from `roomobj` (Exits are here defined as Objects with their `destination` field set). -- `obj.location.contents_get(exclude=obj)` - this helper method returns all objects in `obj`'s location except `obj`. +- `roomobj.exits` returns all exits starting from `roomobj` (Exits are here defined as Objects with +their `destination` field set). +- `obj.location.contents_get(exclude=obj)` - this helper method returns all objects in `obj`'s +location except `obj`. ## Searching using `Object.search` -Say you have a [command](./Commands), and you want it to do something to a target. You might be wondering how you retrieve that target in code, and that's where Evennia's search utilities come in. In the most common case, you'll often use the `search` method of the `Object` or `Account` typeclasses. In a command, the `.caller` property will refer back to the object using the command (usually a `Character`, which is a type of `Object`) while `.args` will contain Command's arguments: +Say you have a [command](./Commands), and you want it to do something to a target. You might be +wondering how you retrieve that target in code, and that's where Evennia's search utilities come in. +In the most common case, you'll often use the `search` method of the `Object` or `Account` +typeclasses. In a command, the `.caller` property will refer back to the object using the command +(usually a `Character`, which is a type of `Object`) while `.args` will contain Command's arguments: ```python # e.g. in file mygame/commands/command.py from evennia import default_cmds -class CmdPoke(default_cmds.MuxCommand): +class CmdPoke(Command): """ Pokes someone. @@ -46,22 +85,35 @@ class CmdPoke(default_cmds.MuxCommand): def func(self): """Executes poke command""" - target = self.caller.search(self.args) - if not target: - # we didn't find anyone, but search has already let the + target = self.caller.search(self.args.lstrip()) + if not target: + # we didn't find anyone, but search has already let the # caller know. We'll just return, since we're done return # we found a target! we'll do stuff to them. - target.msg("You have been poked by %s." % self.caller) - self.caller.msg("You have poked %s." % target) + target.msg(f"{self.caller} pokes you.") + self.caller.msg(f"You poke {target}.") ``` -By default, the search method of a Character will attempt to find a unique object match for the string sent to it (`self.args`, in this case, which is the arguments passed to the command by the player) in the surroundings of the Character - the room or their inventory. If there is no match found, the return value (which is assigned to `target`) will be `None`, and an appropriate failure message will be sent to the Character. If there's not a unique match, `None` will again be returned, and a different error message will be sent asking them to disambiguate the multi-match. By default, the user can then pick out a specific match using with a number and dash preceding the name of the object: `character.search("2-pink unicorn")` will try to find the second pink unicorn in the room. +By default, the search method of a Character will attempt to find a unique object match for the +string sent to it (`self.args`, in this case, which is the arguments passed to the command by the +player) in the surroundings of the Character - the room or their inventory. If there is no match +found, the return value (which is assigned to `target`) will be `None`, and an appropriate failure +message will be sent to the Character. If there's not a unique match, `None` will again be returned, +and a different error message will be sent asking them to disambiguate the multi-match. By default, +the user can then pick out a specific match using with a number and dash preceding the name of the +object: `character.search("2-pink unicorn")` will try to find the second pink unicorn in the room. -The search method has many [arguments](github:evennia.objects.objects#defaultcharactersearch) that allow you to refine the search, such as by designating the location to search in or only matching specific typeclasses. +The search method has many [arguments](github:evennia.objects.objects#defaultcharactersearch) that +allow you to refine the search, such as by designating the location to search in or only matching +specific typeclasses. ## Searching using `utils.search` -Sometimes you will want to find something that isn't tied to the search methods of a character or account. In these cases, Evennia provides a [utility module with a number of search functions](github:evennia.utils.search). For example, suppose you want a command that will find and display all the rooms that are tagged as a 'hangout', for people to gather by. Here's a simple Command to do this: +Sometimes you will want to find something that isn't tied to the search methods of a character or +account. In these cases, Evennia provides a [utility module with a number of search +functions](github:evennia.utils.search). For example, suppose you want a command that will find and +display all the rooms that are tagged as a 'hangout', for people to gather by. Here's a simple +Command to do this: ```python # e.g. in file mygame/commands/command.py @@ -75,13 +127,12 @@ class CmdListHangouts(default_cmds.MuxCommand): def func(self): """Executes 'hangouts' command""" - hangouts = search_tag(key="hangout", - category="location tags") - self.caller.msg("Hangouts available: {}".format( - ", ".join(str(ob) for ob in hangouts))) + hangouts = search_tag(key="hangout", category="location tags") + self.caller.msg(f"Hangouts available: {', '.join(str(ob) for ob in hangouts)}") ``` -This uses the `search_tag` function to find all objects previously tagged with [Tags](./Tags) "hangout" and with category "location tags". +This uses the `search_tag` function to find all objects previously tagged with [Tags](./Tags) +"hangout" and with category "location tags". Other important search methods in `utils.search` are @@ -91,7 +142,8 @@ Other important search methods in `utils.search` are - `search_channel` - `search_message` - `search_help` -- `search_tag` - find Objects with a given Tag. +- `search_tag` - find Objects with a given Tag. [See also here for how to search by +tag](Tags#searching-for-objects-with-a-given-tag). - `search_account_tag` - find Accounts with a given Tag. - `search_script_tag` - find Scripts with a given Tag. - `search_channel_tag` - find Channels with a given Tag. @@ -99,18 +151,36 @@ Other important search methods in `utils.search` are - `search_account_attribute` - find Accounts with a given Attribute. - `search_attribute_object` - this returns the actual Attribute, not the object it sits on. -> Note: All search functions return a Django `queryset` which is technically a list-like representation of the database-query it's about to do. Only when you convert it to a real list, loop over it or try to slice or access any of its contents will the datbase-lookup happen. This means you could yourself customize the query further if you know what you are doing (see the next section). +> Note: All search functions return a Django `queryset` which is technically a list-like +representation of the database-query it's about to do. Only when you convert it to a real list, loop +over it or try to slice or access any of its contents will the datbase-lookup happen. This means you +could yourself customize the query further if you know what you are doing (see the next section). ## Queries in Django *This is an advanced topic.* -Evennia's search methods should be sufficient for the vast majority of situations. But eventually you might find yourself trying to figure out how to get searches for unusual circumstances: Maybe you want to find all characters who are *not* in rooms tagged as hangouts *and* have the lycanthrope tag *and* whose names start with a vowel, but *not* with 'Ab', and *only if* they have 3 or more objects in their inventory ... You could in principle use one of the earlier search methods to find all candidates and then loop over them with a lot of if statements in raw Python. But you can do this much more efficiently by querying the database directly. +Evennia's search methods should be sufficient for the vast majority of situations. But eventually +you might find yourself trying to figure out how to get searches for unusual circumstances: Maybe +you want to find all characters who are *not* in rooms tagged as hangouts *and* have the lycanthrope +tag *and* whose names start with a vowel, but *not* with 'Ab', and *only if* they have 3 or more +objects in their inventory ... You could in principle use one of the earlier search methods to find +all candidates and then loop over them with a lot of if statements in raw Python. But you can do +this much more efficiently by querying the database directly. -Enter [django's querysets](https://docs.djangoproject.com/en/1.11/ref/models/querysets/). A QuerySet is the representation of a database query and can be modified as desired. Only once one tries to retrieve the data of that query is it *evaluated* and does an actual database request. This is useful because it means you can modify a query as much as you want (even pass it around) and only hit the database once you are happy with it. -Evennia's search functions are themselves an even higher level wrapper around Django's queries, and many search methods return querysets. That means that you could get the result from a search function and modify the resulting query to your own ends to further tweak what you search for. +Enter [django's querysets](https://docs.djangoproject.com/en/1.11/ref/models/querysets/). A QuerySet +is the representation of a database query and can be modified as desired. Only once one tries to +retrieve the data of that query is it *evaluated* and does an actual database request. This is +useful because it means you can modify a query as much as you want (even pass it around) and only +hit the database once you are happy with it. +Evennia's search functions are themselves an even higher level wrapper around Django's queries, and +many search methods return querysets. That means that you could get the result from a search +function and modify the resulting query to your own ends to further tweak what you search for. -Evaluated querysets can either contain objects such as Character objects, or lists of values derived from the objects. Queries usually use the 'manager' object of a class, which by convention is the `.objects` attribute of a class. For example, a query of Accounts that contain the letter 'a' could be: +Evaluated querysets can either contain objects such as Character objects, or lists of values derived +from the objects. Queries usually use the 'manager' object of a class, which by convention is the +`.objects` attribute of a class. For example, a query of Accounts that contain the letter 'a' could +be: ```python from typeclasses.accounts import Account @@ -119,14 +189,18 @@ queryset = Account.objects.filter(username__contains='a') ``` -The `filter` method of a manager takes arguments that allow you to define the query, and you can continue to refine the query by calling additional methods until you evaluate the queryset, causing the query to be executed and return a result. For example, if you have the result above, you could, without causing the queryset to be evaluated yet, get rid of matches that contain the letter 'e by doing this: +The `filter` method of a manager takes arguments that allow you to define the query, and you can +continue to refine the query by calling additional methods until you evaluate the queryset, causing +the query to be executed and return a result. For example, if you have the result above, you could, +without causing the queryset to be evaluated yet, get rid of matches that contain the letter 'e by +doing this: ```python queryset = result.exclude(username__contains='e') ``` -> You could also have chained `.exclude` directly to the end of the previous line. +> You could also have chained `.exclude` directly to the end of the previous line. Once you try to access the result, the queryset will be evaluated automatically under the hood: @@ -144,7 +218,9 @@ account = queryset[0] # get first match ### Limiting by typeclass -Although `Character`s, `Exit`s, `Room`s, and other children of `DefaultObject` all shares the same underlying database table, Evennia provides a shortcut to do more specific queries only for those typeclasses. For example, to find only `Character`s whose names start with 'A', you might do: +Although `Character`s, `Exit`s, `Room`s, and other children of `DefaultObject` all shares the same +underlying database table, Evennia provides a shortcut to do more specific queries only for those +typeclasses. For example, to find only `Character`s whose names start with 'A', you might do: ```python Character.objects.filter(db_key__startswith="A") @@ -158,14 +234,18 @@ Npc.objects.filter(db_key__startswith="A") ``` -If you wanted to search both Characters and all its subclasses (like Npc) you use the `*_family` method which is added by Evennia: +If you wanted to search both Characters and all its subclasses (like Npc) you use the `*_family` +method which is added by Evennia: ```python Character.objects.filter_family(db_key__startswith="A") ``` -The higher up in the inheritance hierarchy you go the more objects will be included in these searches. There is one special case, if you really want to include *everything* from a given database table. You do that by searching on the database model itself. These are named `ObjectDB`, `AccountDB`, `ScriptDB` etc. +The higher up in the inheritance hierarchy you go the more objects will be included in these +searches. There is one special case, if you really want to include *everything* from a given +database table. You do that by searching on the database model itself. These are named `ObjectDB`, +`AccountDB`, `ScriptDB` etc. ```python from evennia import AccountDB @@ -175,45 +255,69 @@ all = AccountDB.objects.all() ``` -Here are the most commonly used methods to use with the `objects` managers: +Here are the most commonly used methods to use with the `objects` managers: -- `filter` - query for a listing of objects based on search criteria. Gives empty queryset if none were found. -- `get` - query for a single match - raises exception if none were found, or more than one was found. +- `filter` - query for a listing of objects based on search criteria. Gives empty queryset if none +were found. +- `get` - query for a single match - raises exception if none were found, or more than one was +found. - `all` - get all instances of the particular type. - `filter_family` - like `filter`, but search all sub classes as well. - `get_family` - like `get`, but search all sub classes as well. -- `all_family` - like `all`, but return entities of all subclasses as well. +- `all_family` - like `all`, but return entities of all subclasses as well. ## Multiple conditions -If you pass more than one keyword argument to a query method, the query becomes an `AND` relationship. For example, if we want to find characters whose names start with "A" *and* are also werewolves (have the `lycanthrope` tag), we might do: +If you pass more than one keyword argument to a query method, the query becomes an `AND` +relationship. For example, if we want to find characters whose names start with "A" *and* are also +werewolves (have the `lycanthrope` tag), we might do: ```python queryset = Character.objects.filter(db_key__startswith="A", db_tags__db_key="lycanthrope") ``` -To exclude lycanthropes currently in rooms tagged as hangouts, we might tack on an `.exclude` as before: +To exclude lycanthropes currently in rooms tagged as hangouts, we might tack on an `.exclude` as +before: ```python queryset = quersyet.exclude(db_location__db_tags__db_key="hangout") ``` -Note the syntax of the keywords in building the queryset. For example, `db_location` is the name of the database field sitting on (in this case) the `Character` (Object). Double underscore `__` works like dot-notation in normal Python (it's used since dots are not allowed in keyword names). So the instruction `db_location__db_tags__db_key="hangout"` should be read as such: +Note the syntax of the keywords in building the queryset. For example, `db_location` is the name of +the database field sitting on (in this case) the `Character` (Object). Double underscore `__` works +like dot-notation in normal Python (it's used since dots are not allowed in keyword names). So the +instruction `db_location__db_tags__db_key="hangout"` should be read as such: -1. "On the `Character` object ... (this comes from us building this queryset using the `Character.objects` manager) +1. "On the `Character` object ... (this comes from us building this queryset using the +`Character.objects` manager) 2. ... get the value of the `db_location` field ... (this references a Room object, normally) -3. ... on that location, get the value of the `db_tags` field ... (this is a many-to-many field that can be treated like an object for this purpose. It references all tags on the location) -4. ... through the `db_tag` manager, find all Tags having a field `db_key` set to the value "hangout"." +3. ... on that location, get the value of the `db_tags` field ... (this is a many-to-many field that +can be treated like an object for this purpose. It references all tags on the location) +4. ... through the `db_tag` manager, find all Tags having a field `db_key` set to the value +"hangout"." -This may seem a little complex at first, but this syntax will work the same for all queries. Just remember that all *database-fields* in Evennia are prefaced with `db_`. So even though Evennia is nice enough to alias the `db_key` field so you can normally just do `char.key` to get a character's name, the database field is actually called `db_key` and the real name must be used for the purpose of building a query. +This may seem a little complex at first, but this syntax will work the same for all queries. Just +remember that all *database-fields* in Evennia are prefaced with `db_`. So even though Evennia is +nice enough to alias the `db_key` field so you can normally just do `char.key` to get a character's +name, the database field is actually called `db_key` and the real name must be used for the purpose +of building a query. -> Don't confuse database fields with [Attributes](./Attributes) you set via `obj.db.attr = 'foo'` or `obj.attributes.add()`. Attributes are custom database entities *linked* to an object. They are not separate fields *on* that object like `db_key` or `db_location` are. You can get attached Attributes manually through the `db_attributes` many-to-many field in the same way as `db_tags` above. +> Don't confuse database fields with [Attributes](./Attributes) you set via `obj.db.attr = 'foo'` or +`obj.attributes.add()`. Attributes are custom database entities *linked* to an object. They are not +separate fields *on* that object like `db_key` or `db_location` are. You can get attached Attributes +manually through the `db_attributes` many-to-many field in the same way as `db_tags` above. ### Complex queries -What if you want to have a query with with `OR` conditions or negated requirements (`NOT`)? Enter Django's Complex Query object, [Q](https://docs.djangoproject.com/en/1.11/topics/db/queries/#complex-lookups-with-q-objects). `Q()` objects take a normal django keyword query as its arguments. The special thing is that these Q objects can then be chained together with set operations: `|` for OR, `&` for AND, and preceded with `~` for NOT to build a combined, complex query. +What if you want to have a query with with `OR` conditions or negated requirements (`NOT`)? Enter +Django's Complex Query object, +[Q](https://docs.djangoproject.com/en/1.11/topics/db/queries/#complex-lookups-with-q-objects). `Q()` +objects take a normal django keyword query as its arguments. The special thing is that these Q +objects can then be chained together with set operations: `|` for OR, `&` for AND, and preceded with +`~` for NOT to build a combined, complex query. -In our original Lycanthrope example we wanted our werewolves to have names that could start with any vowel except for the specific beginning "ab". +In our original Lycanthrope example we wanted our werewolves to have names that could start with any +vowel except for the specific beginning "ab". ```python from django.db.models import Q @@ -225,16 +329,26 @@ for letter in ("aeiouy"): query &= ~Q(db_key__istartswith="ab") query = Character.objects.filter(query) -list_of_lycanthropes = list(query) +list_of_lycanthropes = list(query) ``` -In the above example, we construct our query our of several Q objects that each represent one part of the query. We iterate over the list of vowels, and add an `OR` condition to the query using `|=` (this is the same idea as using `+=` which may be more familiar). Each `OR` condition checks that the name starts with one of the valid vowels. Afterwards, we add (using `&=`) an `AND` condition that is negated with the `~` symbol. In other words we require that any match should *not* start with the string "ab". Note that we don't actually hit the database until we convert the query to a list at the end (we didn't need to do that either, but could just have kept the query until we needed to do something with the matches). +In the above example, we construct our query our of several Q objects that each represent one part +of the query. We iterate over the list of vowels, and add an `OR` condition to the query using `|=` +(this is the same idea as using `+=` which may be more familiar). Each `OR` condition checks that +the name starts with one of the valid vowels. Afterwards, we add (using `&=`) an `AND` condition +that is negated with the `~` symbol. In other words we require that any match should *not* start +with the string "ab". Note that we don't actually hit the database until we convert the query to a +list at the end (we didn't need to do that either, but could just have kept the query until we +needed to do something with the matches). ### Annotations and `F` objects -What if we wanted to filter on some condition that isn't represented easily by a field on the object? Maybe we want to find rooms only containing five or more objects? +What if we wanted to filter on some condition that isn't represented easily by a field on the +object? Maybe we want to find rooms only containing five or more objects? -We *could* retrieve all interesting candidates and run them through a for-loop to get and count their `.content` properties. We'd then just return a list of only those objects with enough contents. It would look something like this (note: don't actually do this!): +We *could* retrieve all interesting candidates and run them through a for-loop to get and count +their `.content` properties. We'd then just return a list of only those objects with enough +contents. It would look something like this (note: don't actually do this!): ```python # probably not a good idea to do it this way @@ -246,9 +360,15 @@ rooms = [room for room in queryset if len(room.contents) >= 5] ``` -Once the number of rooms in your game increases, this could become quite expensive. Additionally, in some particular contexts, like when using the web features of Evennia, you must have the result as a queryset in order to use it in operations, such as in Django's admin interface when creating list filters. +Once the number of rooms in your game increases, this could become quite expensive. Additionally, in +some particular contexts, like when using the web features of Evennia, you must have the result as a +queryset in order to use it in operations, such as in Django's admin interface when creating list +filters. -Enter [F objects](https://docs.djangoproject.com/en/1.11/ref/models/expressions/#f-expressions) and *annotations*. So-called F expressions allow you to do a query that looks at a value of each object in the database, while annotations allow you to calculate and attach a value to a query. So, let's do the same example as before directly in the database: +Enter [F objects](https://docs.djangoproject.com/en/1.11/ref/models/expressions/#f-expressions) and +*annotations*. So-called F expressions allow you to do a query that looks at a value of each object +in the database, while annotations allow you to calculate and attach a value to a query. So, let's +do the same example as before directly in the database: ```python from typeclasses.rooms import Room @@ -263,25 +383,38 @@ rooms = (Room.objects.annotate(num_objects=Count('locations_set')) rooms = list(rooms) ``` -Here we first create an annotation `num_objects` of type `Count`, which is a Django class. Note that use of `location_set` in that `Count`. The `*_set` is a back-reference automatically created by Django. In this case it allows you to find all objects that *has the current object as location*. Once we have those, they are counted. -Next we filter on this annotation, using the name `num_objects` as something we can filter for. We use `num_objects__gte=5` which means that `num_objects` should be greater than 5. This is a little harder to get one's head around but much more efficient than lopping over all objects in Python. +Here we first create an annotation `num_objects` of type `Count`, which is a Django class. Note that +use of `location_set` in that `Count`. The `*_set` is a back-reference automatically created by +Django. In this case it allows you to find all objects that *has the current object as location*. +Once we have those, they are counted. +Next we filter on this annotation, using the name `num_objects` as something we can filter for. We +use `num_objects__gte=5` which means that `num_objects` should be greater than 5. This is a little +harder to get one's head around but much more efficient than lopping over all objects in Python. -What if we wanted to compare two parameters against one another in a query? For example, what if instead of having 5 or more objects, we only wanted objects that had a bigger inventory than they had tags? Here an F-object comes in handy: +What if we wanted to compare two parameters against one another in a query? For example, what if +instead of having 5 or more objects, we only wanted objects that had a bigger inventory than they +had tags? Here an F-object comes in handy: ```python from django.db.models import Count, F from typeclasses.rooms import Room -result = (Room.objects.annotate(num_objects=Count('locations_set'), +result = (Room.objects.annotate(num_objects=Count('locations_set'), num_tags=Count('db_tags')) .filter(num_objects__gt=F('num_tags'))) ``` -F-objects allows for wrapping an annotated structure on the right-hand-side of the expression. It will be evaluated on-the-fly as needed. +F-objects allows for wrapping an annotated structure on the right-hand-side of the expression. It +will be evaluated on-the-fly as needed. ### Grouping By and Values -Suppose you used tags to mark someone belonging an organization. Now you want to make a list and need to get the membership count of every organization all at once. That's where annotations and the `.values_list` queryset method come in. Values/Values Lists are an alternate way of returning a queryset - instead of objects, you get a list of dicts or tuples that hold selected properties from the the matches. It also allows you a way to 'group up' queries for returning information. For example, to get a display about each tag per Character and the names of the tag: +Suppose you used tags to mark someone belonging an organization. Now you want to make a list and +need to get the membership count of every organization all at once. That's where annotations and the +`.values_list` queryset method come in. Values/Values Lists are an alternate way of returning a +queryset - instead of objects, you get a list of dicts or tuples that hold selected properties from +the the matches. It also allows you a way to 'group up' queries for returning information. For +example, to get a display about each tag per Character and the names of the tag: ```python result = (Character.objects.filter(db_tags__db_category="organization") @@ -289,7 +422,9 @@ result = (Character.objects.filter(db_tags__db_category="organization") .annotate(cnt=Count('id')) .order_by('-cnt')) ``` -The result queryset will be a list of tuples ordered in descending order by the number of matches, in a format like the following: +The result queryset will be a list of tuples ordered in descending order by the number of matches, +in a format like the following: ``` -[('Griatch Fanclub', 3872), ("Chainsol's Ainneve Testers", 2076), ("Blaufeuer's Whitespace Fixers", 1903), +[('Griatch Fanclub', 3872), ("Chainsol's Ainneve Testers", 2076), ("Blaufeuer's Whitespace Fixers", +1903), ("Volund's Bikeshed Design Crew", 1764), ("Tehom's Misanthropes", 1)] diff --git a/docs/source/Tutorial-Tweeting-Game-Stats.md b/docs/source/Tutorial-Tweeting-Game-Stats.md index c030809e35..660b03ad5c 100644 --- a/docs/source/Tutorial-Tweeting-Game-Stats.md +++ b/docs/source/Tutorial-Tweeting-Game-Stats.md @@ -1,9 +1,12 @@ # Tutorial Tweeting Game Stats -This tutorial will create a simple script that will send a tweet to your already configured twitter account. Please see: [How to connect Evennia to Twitter](./How-to-connect-Evennia-to-Twitter) if you haven't already done so. +This tutorial will create a simple script that will send a tweet to your already configured twitter +account. Please see: [How to connect Evennia to Twitter](./How-to-connect-Evennia-to-Twitter) if you +haven't already done so. -The script could be expanded to cover a variety of statistics you might wish to tweet about regularly, from player deaths to how much currency is in the economy etc. +The script could be expanded to cover a variety of statistics you might wish to tweet about +regularly, from player deaths to how much currency is in the economy etc. ```python # evennia/typeclasses/tweet_stats.py @@ -21,7 +24,7 @@ class TweetStats(DefaultScript): This implements the tweeting of stats to a registered twitter account """ - # standard Script hooks + # standard Script hooks def at_script_creation(self): "Called when script is first created" @@ -50,12 +53,15 @@ class TweetStats(DefaultScript): nobjs = ObjectDB.objects.count() base_char_typeclass = settings.BASE_CHARACTER_TYPECLASS nchars = ObjectDB.objects.filter(db_typeclass_path=base_char_typeclass).count() - nrooms = ObjectDB.objects.filter(db_location__isnull=True).exclude(db_typeclass_path=base_char_typeclass).count() - nexits = ObjectDB.objects.filter(db_location__isnull=False, db_destination__isnull=False).count() + nrooms = ObjectDB.objects.filter(db_location__isnull=True).exclude(db_typeclass_path=bas +e_char_typeclass).count() + nexits = ObjectDB.objects.filter(db_location__isnull=False, +db_destination__isnull=False).count() nother = nobjs - nchars - nrooms - nexits tweet = "Chars: %s, Rooms: %s, Objects: %s" %(nchars, nrooms, nother) - else: - if tweet_output == 2: ##Number of prototypes and 3 random keys - taken from @spawn command + else: + if tweet_output == 2: ##Number of prototypes and 3 random keys - taken from @spawn +command prototypes = spawner.spawn(return_prototypes=True) keys = prototypes.keys() @@ -65,20 +71,26 @@ class TweetStats(DefaultScript): tweet += " %s" % keys[randint(0,len(keys)-1)] for x in range(0,2): ##tweet 3 tweet += ", %s" % keys[randint(0,len(keys)-1)] - # post the tweet + # post the tweet try: response = api.PostUpdate(tweet) except: logger.log_trace("Tweet Error: When attempting to tweet %s" % tweet) ``` -In the `at_script_creation` method, we configure the script to fire immediately (useful for testing) and setup the delay (1 day) as well as script information seen when you use `@scripts` +In the `at_script_creation` method, we configure the script to fire immediately (useful for testing) +and setup the delay (1 day) as well as script information seen when you use `@scripts` -In the `at_repeat` method (which is called immediately and then at interval seconds later) we setup the Twitter API (just like in the initial configuration of twitter). numberTweetOutputs is used to show how many different types of outputs we have (in this case 2). We then build the tweet based on randomly choosing between these outputs. +In the `at_repeat` method (which is called immediately and then at interval seconds later) we setup +the Twitter API (just like in the initial configuration of twitter). numberTweetOutputs is used to +show how many different types of outputs we have (in this case 2). We then build the tweet based on +randomly choosing between these outputs. 1. Shows the number of Player Characters, Rooms and Other/Objects -2. Shows the number of prototypes currently in the game and then selects 3 random keys to show +2. Shows the number of prototypes currently in the game and then selects 3 random keys to show -[Scripts Information](./Scripts) will show you how to add it as a Global script, however, for testing it may be useful to start/stop it quickly from within the game. Assuming that you create the file as `mygame/typeclasses/tweet_stats.py` it can be started by using the following command +[Scripts Information](./Scripts) will show you how to add it as a Global script, however, for testing +it may be useful to start/stop it quickly from within the game. Assuming that you create the file +as `mygame/typeclasses/tweet_stats.py` it can be started by using the following command @script Here = tweet_stats.TweetStats diff --git a/docs/source/Tutorial-Vehicles.md b/docs/source/Tutorial-Vehicles.md index e62ab12339..7ba97d88d5 100644 --- a/docs/source/Tutorial-Vehicles.md +++ b/docs/source/Tutorial-Vehicles.md @@ -1,17 +1,23 @@ # Tutorial Vehicles -This tutorial explains how you can create vehicles that can move around in your world. The tutorial will explain how to create a train, but this can be equally applied to create other kind of vehicles (cars, planes, boats, spaceships, submarines, ...). +This tutorial explains how you can create vehicles that can move around in your world. The tutorial +will explain how to create a train, but this can be equally applied to create other kind of vehicles +(cars, planes, boats, spaceships, submarines, ...). ## How it works -Objects in Evennia have an interesting property: you can put any object inside another object. This is most obvious in rooms: a room in Evennia is just like any other game object (except rooms tend to not themselves be inside anything else). +Objects in Evennia have an interesting property: you can put any object inside another object. This +is most obvious in rooms: a room in Evennia is just like any other game object (except rooms tend to +not themselves be inside anything else). -Our train will be similar: it will be an object that other objects can get inside. We then simply move the Train, which brings along everyone inside it. +Our train will be similar: it will be an object that other objects can get inside. We then simply +move the Train, which brings along everyone inside it. ## Creating our train object -The first step we need to do is create our train object, including a new typeclass. To do this, create a new file, for instance in `mygame/typeclasses/train.py` with the following content: +The first step we need to do is create our train object, including a new typeclass. To do this, +create a new file, for instance in `mygame/typeclasses/train.py` with the following content: ```python # file mygame/typeclasses/train.py @@ -32,18 +38,29 @@ Now we can create our train in our game: @create/drop train:train.TrainObject ``` -Now this is just an object that doesn't do much yet... but we can already force our way inside it and back (assuming we created it in limbo). +Now this is just an object that doesn't do much yet... but we can already force our way inside it +and back (assuming we created it in limbo). ``` -@tel train +@tel train @tel limbo ``` ## Entering and leaving the train -Using the `@tel`command like shown above is obviously not what we want. `@tel` is an admin command and normal players will thus never be able to enter the train! It is also not really a good idea to use [Exits](./Objects#exits) to get in and out of the train - Exits are (at least by default) objects too. They point to a specific destination. If we put an Exit in this room leading inside the train it would stay here when the train moved away (still leading into the train like a magic portal!). In the same way, if we put an Exit object inside the train, it would always point back to this room, regardless of where the Train has moved. Now, one *could* define custom Exit types that move with the train or change their destination in the right way - but this seems to be a pretty cumbersome solution. +Using the `@tel`command like shown above is obviously not what we want. `@tel` is an admin command +and normal players will thus never be able to enter the train! It is also not really a good idea to +use [Exits](./Objects#exits) to get in and out of the train - Exits are (at least by default) objects +too. They point to a specific destination. If we put an Exit in this room leading inside the train +it would stay here when the train moved away (still leading into the train like a magic portal!). In +the same way, if we put an Exit object inside the train, it would always point back to this room, +regardless of where the Train has moved. Now, one *could* define custom Exit types that move with +the train or change their destination in the right way - but this seems to be a pretty cumbersome +solution. -What we will do instead is to create some new [commands](./Commands): one for entering the train and another for leaving it again. These will be stored *on the train object* and will thus be made available to whomever is either inside it or in the same room as the train. +What we will do instead is to create some new [commands](./Commands): one for entering the train and +another for leaving it again. These will be stored *on the train object* and will thus be made +available to whomever is either inside it or in the same room as the train. Let's create a new command module as `mygame/commands/train.py`: @@ -60,7 +77,7 @@ class CmdEnterTrain(Command): enter train This will be available to players in the same location - as the train and allows them to embark. + as the train and allows them to embark. """ key = "enter train" @@ -74,14 +91,14 @@ class CmdEnterTrain(Command): class CmdLeaveTrain(Command): """ - leaving the train + leaving the train Usage: leave train - This will be available to everyone inside the + This will be available to everyone inside the train. It allows them to exit to the train's - current location. + current location. """ key = "leave train" @@ -99,9 +116,13 @@ class CmdSetTrain(CmdSet): self.add(CmdEnterTrain()) self.add(CmdLeaveTrain()) ``` -Note that while this seems like a lot of text, the majority of lines here are taken up by documentation. +Note that while this seems like a lot of text, the majority of lines here are taken up by +documentation. -These commands are work in a pretty straightforward way: `CmdEnterTrain` moves the location of the player to inside the train and `CmdLeaveTrain` does the opposite: it moves the player back to the current location of the train (back outside to its current location). We stacked them in a [cmdset](./Command-Sets) `CmdSetTrain` so they can be used. +These commands are work in a pretty straightforward way: `CmdEnterTrain` moves the location of the +player to inside the train and `CmdLeaveTrain` does the opposite: it moves the player back to the +current location of the train (back outside to its current location). We stacked them in a +[cmdset](./Command-Sets) `CmdSetTrain` so they can be used. To make the commands work we need to add this cmdset to our train typeclass: @@ -113,12 +134,13 @@ from commands.train import CmdSetTrain class TrainObject(DefaultObject): - def at_object_creation(self): + def at_object_creation(self): self.cmdset.add_default(CmdSetTrain) ``` -If we now `@reload` our game and reset our train, those commands should work and we can now enter and leave the train: +If we now `@reload` our game and reset our train, those commands should work and we can now enter +and leave the train: ``` @reload @@ -127,15 +149,27 @@ enter train leave train ``` -Note the switches used with the `@typeclass` command: The `/force` switch is necessary to assign our object the same typeclass we already have. The `/reset` re-triggers the typeclass' `at_object_creation()` hook (which is otherwise only called the very first an instance is created). As seen above, when this hook is called on our train, our new cmdset will be loaded. +Note the switches used with the `@typeclass` command: The `/force` switch is necessary to assign our +object the same typeclass we already have. The `/reset` re-triggers the typeclass' +`at_object_creation()` hook (which is otherwise only called the very first an instance is created). +As seen above, when this hook is called on our train, our new cmdset will be loaded. ## Locking down the commands -If you have played around a bit, you've probably figured out that you can use `leave train` when outside the train and `enter train` when inside. This doesn't make any sense ... so let's go ahead and fix that. We need to tell Evennia that you can not enter the train when you're already inside or leave the train when you're outside. One solution to this is [locks](./Locks): we will lock down the commands so that they can only be called if the player is at the correct location. +If you have played around a bit, you've probably figured out that you can use `leave train` when +outside the train and `enter train` when inside. This doesn't make any sense ... so let's go ahead +and fix that. We need to tell Evennia that you can not enter the train when you're already inside +or leave the train when you're outside. One solution to this is [locks](./Locks): we will lock down +the commands so that they can only be called if the player is at the correct location. -Right now commands defaults to the lock `cmd:all()`. The `cmd` lock type in combination with the `all()` lock function means that everyone can run those commands as long as they are in the same room as the train *or* inside the train. We're going to change this to check the location of the player and *only* allow access if they are inside the train. +Right now commands defaults to the lock `cmd:all()`. The `cmd` lock type in combination with the +`all()` lock function means that everyone can run those commands as long as they are in the same +room as the train *or* inside the train. We're going to change this to check the location of the +player and *only* allow access if they are inside the train. -First of all we need to create a new lock function. Evennia comes with many lock functions built-in already, but none that we can use for locking a command in this particular case. Create a new entry in `mygame/server/conf/lockfuncs.py`: +First of all we need to create a new lock function. Evennia comes with many lock functions built-in +already, but none that we can use for locking a command in this particular case. Create a new entry +in `mygame/server/conf/lockfuncs.py`: ```python @@ -143,18 +177,26 @@ First of all we need to create a new lock function. Evennia comes with many lock def cmdinside(accessing_obj, accessed_obj, *args, **kwargs): """ - Usage: cmdinside() + Usage: cmdinside() Used to lock commands and only allows access if the command - is defined on an object which accessing_obj is inside of. + is defined on an object which accessing_obj is inside of. """ return accessed_obj.obj == accessing_obj.location ``` -If you didn't know, Evennia is by default set up to use all functions in this module as lock functions (there is a setting variable that points to it). +If you didn't know, Evennia is by default set up to use all functions in this module as lock +functions (there is a setting variable that points to it). -Our new lock function, `cmdinside`, is to be used by Commands. The `accessed_obj` is the Command object (in our case this will be `CmdEnterTrain` and `CmdLeaveTrain`) — Every command has an `obj` property: this is the the object on which the command "sits". Since we added those commands to our train object, the `.obj` property will be set to the train object. Conversely, `accessing_obj` is the object that called the command: in our case it's the Character trying to enter or leave the train. +Our new lock function, `cmdinside`, is to be used by Commands. The `accessed_obj` is the Command +object (in our case this will be `CmdEnterTrain` and `CmdLeaveTrain`) — Every command has an `obj` +property: this is the the object on which the command "sits". Since we added those commands to our +train object, the `.obj` property will be set to the train object. Conversely, `accessing_obj` is +the object that called the command: in our case it's the Character trying to enter or leave the +train. -What this function does is to check that the player's location is the same as the train object. If it is, it means the player is inside the train. Otherwise it means the player is somewhere else and the check will fail. +What this function does is to check that the player's location is the same as the train object. If +it is, it means the player is inside the train. Otherwise it means the player is somewhere else and +the check will fail. The next step is to actually use this new lock function to create a lock of type `cmd`: @@ -172,20 +214,29 @@ class CmdLeaveTrain(Command): # ... ``` -Notice how we use the `not` here so that we can use the same `cmdinside` to check if we are inside and outside, without having to create two separate lock functions. After a `@reload` our commands should be locked down appropriately and you should only be able to use them at the right places. +Notice how we use the `not` here so that we can use the same `cmdinside` to check if we are inside +and outside, without having to create two separate lock functions. After a `@reload` our commands +should be locked down appropriately and you should only be able to use them at the right places. -> Note: If you're logged in as the super user (user `#1`) then this lock will not work: the super user ignores lock functions. In order to use this functionality you need to `@quell` first. +> Note: If you're logged in as the super user (user `#1`) then this lock will not work: the super +user ignores lock functions. In order to use this functionality you need to `@quell` first. ## Making our train move -Now that we can enter and leave the train correctly, it's time to make it move. There are different things we need to consider for this: +Now that we can enter and leave the train correctly, it's time to make it move. There are different +things we need to consider for this: -* Who can control your vehicle? The first player to enter it, only players that have a certain "drive" skill, automatically? -* Where should it go? Can the player steer the vehicle to go somewhere else or will it always follow the same route? +* Who can control your vehicle? The first player to enter it, only players that have a certain +"drive" skill, automatically? +* Where should it go? Can the player steer the vehicle to go somewhere else or will it always follow +the same route? -For our example train we're going to go with automatic movement through a predefined route (its track). The train will stop for a bit at the start and end of the route to allow players to enter and leave it. +For our example train we're going to go with automatic movement through a predefined route (its +track). The train will stop for a bit at the start and end of the route to allow players to enter +and leave it. -Go ahead and create some rooms for our train. Make a list of the room ids along the route (using the `@ex` command). +Go ahead and create some rooms for our train. Make a list of the room ids along the route (using the +`@ex` command). ``` @dig/tel South station @@ -245,11 +296,14 @@ class TrainObject(DefaultObject): self.msg_contents("The train is moving forward to %s." % (room.name, )) ``` -We added a lot of code here. Since we changed the `at_object_creation` to add in variables we will have to reset our train object like earlier (using the `@typeclass/force/reset` command). +We added a lot of code here. Since we changed the `at_object_creation` to add in variables we will +have to reset our train object like earlier (using the `@typeclass/force/reset` command). -We are keeping track of a few different things now: whether the train is moving or standing still, which direction the train is heading to and what rooms the train will pass through. +We are keeping track of a few different things now: whether the train is moving or standing still, +which direction the train is heading to and what rooms the train will pass through. -We also added some methods: one to start moving the train, another to stop and a third that actually moves the train to the next room in the list. Or makes it stop driving if it reaches the last stop. +We also added some methods: one to start moving the train, another to stop and a third that actually +moves the train to the next room in the list. Or makes it stop driving if it reaches the last stop. Let's try it out, using `@py` to call the new train functionality: @@ -264,9 +318,13 @@ You should see the train moving forward one step along the rail road. ## Adding in scripts -If we wanted full control of the train we could now just add a command to step it along the track when desired. We want the train to move on its own though, without us having to force it by manually calling the `goto_next_room` method. +If we wanted full control of the train we could now just add a command to step it along the track +when desired. We want the train to move on its own though, without us having to force it by manually +calling the `goto_next_room` method. -To do this we will create two [scripts](./Scripts): one script that runs when the train has stopped at a station and is responsible for starting the train again after a while. The other script will take care of the driving. +To do this we will create two [scripts](./Scripts): one script that runs when the train has stopped at +a station and is responsible for starting the train again after a while. The other script will take +care of the driving. Let's make a new file in `mygame/typeclasses/trainscript.py` @@ -285,7 +343,7 @@ class TrainStoppedScript(DefaultScript): self.start_delay = True def at_repeat(self): - self.obj.start_driving() + self.obj.start_driving() def at_stop(self): self.obj.scripts.add(TrainDrivingScript) @@ -311,9 +369,12 @@ class TrainDrivingScript(DefaultScript): self.obj.scripts.add(TrainStoppedScript) ``` -Those scripts work as a state system: when the train is stopped, it waits for 30 seconds and then starts again. When the train is driving, it moves to the next room every second. The train is always in one of those two states - both scripts take care of adding the other one once they are done. +Those scripts work as a state system: when the train is stopped, it waits for 30 seconds and then +starts again. When the train is driving, it moves to the next room every second. The train is always +in one of those two states - both scripts take care of adding the other one once they are done. -As a last step we need to link the stopped-state script to our train, reload the game and reset our train again., and we're ready to ride it around! +As a last step we need to link the stopped-state script to our train, reload the game and reset our +train again., and we're ready to ride it around! ```python # file typeclasses/train.py @@ -350,8 +411,12 @@ Our train will stop 30 seconds at each end station and then turn around to go ba This train is very basic and still has some flaws. Some more things to do: * Make it look like a train. -* Make it impossible to exit and enter the train mid-ride. This could be made by having the enter/exit commands check so the train is not moving before allowing the caller to proceed. +* Make it impossible to exit and enter the train mid-ride. This could be made by having the +enter/exit commands check so the train is not moving before allowing the caller to proceed. * Have train conductor commands that can override the automatic start/stop. * Allow for in-between stops between the start- and end station -* Have a rail road track instead of hard-coding the rooms in the train object. This could for example be a custom [Exit](./Objects#exits) only traversable by trains. The train will follow the track. Some track segments can split to lead to two different rooms and a player can switch the direction to which room it goes. +* Have a rail road track instead of hard-coding the rooms in the train object. This could for +example be a custom [Exit](./Objects#exits) only traversable by trains. The train will follow the +track. Some track segments can split to lead to two different rooms and a player can switch the +direction to which room it goes. * Create another kind of vehicle! diff --git a/docs/source/Tutorial-World-Introduction.md b/docs/source/Tutorial-World-Introduction.md index abff1e9734..4c45e041ae 100644 --- a/docs/source/Tutorial-World-Introduction.md +++ b/docs/source/Tutorial-World-Introduction.md @@ -1,14 +1,17 @@ # Tutorial World Introduction -The *Tutorial World* is a small and functioning MUD-style game world. It is intended to be deconstructed and used as a way to learn Evennia. The game consists of a single-player quest and has some 20 rooms that you can explore as you seek to discover the whereabouts of a mythical weapon. +The *Tutorial World* is a small and functioning MUD-style game world. It is intended to be +deconstructed and used as a way to learn Evennia. The game consists of a single-player quest and +has some 20 rooms that you can explore as you seek to discover the whereabouts of a mythical weapon. -The source code is fully documented. You can find the whole thing in `evennia/contrib/tutorial_world/`. +The source code is fully documented. You can find the whole thing in +`evennia/contrib/tutorial_world/`. -Some features exemplified by the tutorial world: +Some features exemplified by the tutorial world: - Tutorial command, giving "behind-the-scenes" help for every room and some of the special objects -- Rooms with custom `return_appearance` to show details. +- Rooms with custom `return_appearance` to show details. - Hidden exits - Objects with multiple custom interactions - Large-area rooms @@ -25,33 +28,59 @@ Some features exemplified by the tutorial world: ## Install -The tutorial world consists of a few modules in `evennia/contrib/tutorial_world/` containing custom [Typeclasses](./Typeclasses) for [rooms and objects](./Objects) and associated [Commands](./Commands). +The tutorial world consists of a few modules in `evennia/contrib/tutorial_world/` containing custom +[Typeclasses](./Typeclasses) for [rooms and objects](./Objects) and associated [Commands](./Commands). -These reusable bits and pieces are then put together into a functioning game area ("world" is maybe too big a word for such a small zone) using a [batch script](./Batch-Processors) called `build.ev`. To install, log into the server as the superuser (user #1) and run: +These reusable bits and pieces are then put together into a functioning game area ("world" is maybe +too big a word for such a small zone) using a [batch script](./Batch-Processors) called `build.ev`. To +install, log into the server as the superuser (user #1) and run: @batchcommand tutorial_world.build -The world will be built (this might take a while, so don't rerun the command even if it seems the system has frozen). After finishing you will end up back in Limbo with a new exit called `tutorial`. +The world will be built (this might take a while, so don't rerun the command even if it seems the +system has frozen). After finishing you will end up back in Limbo with a new exit called `tutorial`. -An alternative is +An alternative is @batchcommand/interactive tutorial_world.build -with the /interactive switch you are able to step through the building process at your own pace to see what happens in detail. +with the /interactive switch you are able to step through the building process at your own pace to +see what happens in detail. -To play the tutorial "correctly", you should *not* do so as superuser. The reason for this is that many game systems ignore the presence of a superuser and will thus not work as normal. Use the `@quell` command to limit your powers or log out and reconnect as a different user. As superuser you can of course examine things "under the hood" later if you want. +## Quelling and permissions in the tutorial-world + +Non-superusers entering the tutorial will be auto-`quelled` so they play with their Character's +permission. As superuser you will not be auto-quelled, but it's recommended that you still `quell` +manually to play the tutorial "correctly". The reason for this is that many game systems ignore the +presence of a superuser and will thus not work as normal. + +Use `unquell` if you want to get back your main account-level permissions to examine things under +the hood. When you exit the tutorial (either by winning or using the `abort/give up` command) you +will automatically be unquelled. ## Gameplay -![the castle off the moor](https://images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com/f/22916c25-6299-453d-a221-446ec839f567/da2pmzu-46d63c6d-9cdc-41dd-87d6-1106db5a5e1a.jpg/v1/fill/w_600,h_849,q_75,strp/the_castle_off_the_moor_by_griatch_art_da2pmzu-fullview.jpg?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1cm46YXBwOiIsImlzcyI6InVybjphcHA6Iiwib2JqIjpbW3siaGVpZ2h0IjoiPD04NDkiLCJwYXRoIjoiXC9mXC8yMjkxNmMyNS02Mjk5LTQ1M2QtYTIyMS00NDZlYzgzOWY1NjdcL2RhMnBtenUtNDZkNjNjNmQtOWNkYy00MWRkLTg3ZDYtMTEwNmRiNWE1ZTFhLmpwZyIsIndpZHRoIjoiPD02MDAifV1dLCJhdWQiOlsidXJuOnNlcnZpY2U6aW1hZ2Uub3BlcmF0aW9ucyJdfQ.omuS3D1RmFiZCy9OSXiIita-HxVGrBok3_7asq0rflw) +![the castle off the moor](https://images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com/f/22916c25-6299-4 +53d-a221-446ec839f567/da2pmzu-46d63c6d-9cdc-41dd-87d6-1106db5a5e1a.jpg/v1/fill/w_600,h_849,q_75,strp +/the_castle_off_the_moor_by_griatch_art_da2pmzu-fullview.jpg?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1N +iJ9.eyJzdWIiOiJ1cm46YXBwOiIsImlzcyI6InVybjphcHA6Iiwib2JqIjpbW3siaGVpZ2h0IjoiPD04NDkiLCJwYXRoIjoiXC9m +XC8yMjkxNmMyNS02Mjk5LTQ1M2QtYTIyMS00NDZlYzgzOWY1NjdcL2RhMnBtenUtNDZkNjNjNmQtOWNkYy00MWRkLTg3ZDYtMTEw +NmRiNWE1ZTFhLmpwZyIsIndpZHRoIjoiPD02MDAifV1dLCJhdWQiOlsidXJuOnNlcnZpY2U6aW1hZ2Uub3BlcmF0aW9ucyJdfQ.o +muS3D1RmFiZCy9OSXiIita-HxVGrBok3_7asq0rflw) -*To get into the mood of this miniature quest, imagine you are an adventurer out to find fame and fortune. You have heard rumours of an old castle ruin by the coast. In its depth a warrior princess was buried together with her powerful magical weapon - a valuable prize, if it's true. Of course this is a chance to adventure that you cannot turn down!* +*To get into the mood of this miniature quest, imagine you are an adventurer out to find fame and +fortune. You have heard rumours of an old castle ruin by the coast. In its depth a warrior princess +was buried together with her powerful magical weapon - a valuable prize, if it's true. Of course +this is a chance to adventure that you cannot turn down!* -*You reach the ocean in the midst of a raging thunderstorm. With wind and rain screaming in your face you stand where the moor meets the sea along a high, rocky coast ...* +*You reach the ocean in the midst of a raging thunderstorm. With wind and rain screaming in your +face you stand where the moor meets the sea along a high, rocky coast ...* - Look at everything. -- Some objects are interactive in more than one way. Use the normal `help` command to get a feel for which commands are available at any given time. (use the command `tutorial` to get insight behind the scenes of the tutorial). +- Some objects are interactive in more than one way. Use the normal `help` command to get a feel for +which commands are available at any given time. (use the command `tutorial` to get insight behind +the scenes of the tutorial). - In order to fight, you need to first find some type of weapon. - *slash* is a normal attack @@ -62,18 +91,25 @@ To play the tutorial "correctly", you should *not* do so as superuser. The reas ## Uninstall -Uninstalling the tutorial world basically means deleting all the rooms and objects it consists of. First, move out of the tutorial area. +Uninstalling the tutorial world basically means deleting all the rooms and objects it consists of. +First, move out of the tutorial area. @find tut#01 @find tut#16 -This should locate the first and last rooms created by `build.ev` - *Intro* and *Outro*. If you installed normally, everything created between these two numbers should be part of the tutorial. Note their dbref numbers, for example 5 and 80. Next we just delete all objects in that range: +This should locate the first and last rooms created by `build.ev` - *Intro* and *Outro*. If you +installed normally, everything created between these two numbers should be part of the tutorial. +Note their dbref numbers, for example 5 and 80. Next we just delete all objects in that range: @del 5-80 -You will see some errors since some objects are auto-deleted and so cannot be found when the delete mechanism gets to them. That's fine. You should have removed the tutorial completely once the command finishes. +You will see some errors since some objects are auto-deleted and so cannot be found when the delete +mechanism gets to them. That's fine. You should have removed the tutorial completely once the +command finishes. ## Notes -When reading and learning from the code, keep in mind that *Tutorial World* was created with a very specific goal: to install easily and to not permanently modify the rest of the server. It therefore goes to some length to use only temporary solutions and to clean up after -itself. +When reading and learning from the code, keep in mind that *Tutorial World* was created with a very +specific goal: to install easily and to not permanently modify the rest of the server. It therefore +goes to some length to use only temporary solutions and to clean up after +itself. diff --git a/docs/source/Tutorial-for-basic-MUSH-like-game.md b/docs/source/Tutorial-for-basic-MUSH-like-game.md index c362b4efaa..848fe18509 100644 --- a/docs/source/Tutorial-for-basic-MUSH-like-game.md +++ b/docs/source/Tutorial-for-basic-MUSH-like-game.md @@ -1,30 +1,48 @@ # Tutorial for basic MUSH like game -This tutorial lets you code a small but complete and functioning MUSH-like game in Evennia. A [MUSH](http://en.wikipedia.org/wiki/MUSH) is, for our purposes, a class of roleplay-centric games focused on free form storytelling. Even if you are not interested in MUSH:es, this is still a good first game-type to try since it's not so code heavy. You will be able to use the same principles for building other types of games. +This tutorial lets you code a small but complete and functioning MUSH-like game in Evennia. A +[MUSH](http://en.wikipedia.org/wiki/MUSH) is, for our purposes, a class of roleplay-centric games +focused on free form storytelling. Even if you are not interested in MUSH:es, this is still a good +first game-type to try since it's not so code heavy. You will be able to use the same principles for +building other types of games. -The tutorial starts from scratch. If you did the [First Steps Coding](./First-Steps-Coding) tutorial already you should have some ideas about how to do some of the steps already. +The tutorial starts from scratch. If you did the [First Steps Coding](./First-Steps-Coding) tutorial +already you should have some ideas about how to do some of the steps already. -The following are the (very simplistic and cut-down) features we will implement (this was taken from a feature request from a MUSH user new to Evennia). A Character in this system should: +The following are the (very simplistic and cut-down) features we will implement (this was taken from +a feature request from a MUSH user new to Evennia). A Character in this system should: -- Have a “Power” score from 1 to 10 that measures how strong they are (stand-in for the stat system). -- Have a command (e.g. `+setpower 4`) that sets their power (stand-in for character generation code). -- Have a command (e.g. `+attack`) that lets them roll their power and produce a "Combat Score" between `1` and `10*Power`, displaying the result and editing their object to record this number (stand-in for `+actions` in the command code). -- Have a command that displays everyone in the room and what their most recent "Combat Score" roll was (stand-in for the combat code). +- Have a “Power” score from 1 to 10 that measures how strong they are (stand-in for the stat +system). +- Have a command (e.g. `+setpower 4`) that sets their power (stand-in for character generation +code). +- Have a command (e.g. `+attack`) that lets them roll their power and produce a "Combat Score" +between `1` and `10*Power`, displaying the result and editing their object to record this number +(stand-in for `+actions` in the command code). +- Have a command that displays everyone in the room and what their most recent "Combat Score" roll +was (stand-in for the combat code). - Have a command (e.g. `+createNPC Jenkins`) that creates an NPC with full abilities. -- Have a command to control NPCs, such as `+npc/cmd (name)=(command)` (stand-in for the NPC controlling code). +- Have a command to control NPCs, such as `+npc/cmd (name)=(command)` (stand-in for the NPC +controlling code). -In this tutorial we will assume you are starting from an empty database without any previous modifications. +In this tutorial we will assume you are starting from an empty database without any previous +modifications. ## Server Settings -To emulate a MUSH, the default `MULTISESSION_MODE=0` is enough (one unique session per account/character). This is the default so you don't need to change anything. You will still be able to puppet/unpuppet objects you have permission to, but there is no character selection out of the box in this mode. +To emulate a MUSH, the default `MULTISESSION_MODE=0` is enough (one unique session per +account/character). This is the default so you don't need to change anything. You will still be able +to puppet/unpuppet objects you have permission to, but there is no character selection out of the +box in this mode. -We will assume our game folder is called `mygame` henceforth. You should be fine with the default SQLite3 database. +We will assume our game folder is called `mygame` henceforth. You should be fine with the default +SQLite3 database. ## Creating the Character -First thing is to choose how our Character class works. We don't need to define a special NPC object -- an NPC is after all just a Character without an Account currently controlling them. +First thing is to choose how our Character class works. We don't need to define a special NPC object +-- an NPC is after all just a Character without an Account currently controlling them. Make your changes in the `mygame/typeclasses/characters.py` file: @@ -38,47 +56,65 @@ class Character(DefaultCharacter): [...] """ def at_object_creation(self): - "This is called when object is first created, only." - self.db.power = 1 + "This is called when object is first created, only." + self.db.power = 1 self.db.combat_score = 1 ``` -We defined two new [Attributes](./Attributes) `power` and `combat_score` and set them to default values. Make sure to `@reload` the server if you had it already running (you need to reload every time you update your python code, don't worry, no accounts will be disconnected by the reload). +We defined two new [Attributes](./Attributes) `power` and `combat_score` and set them to default +values. Make sure to `@reload` the server if you had it already running (you need to reload every +time you update your python code, don't worry, no accounts will be disconnected by the reload). -Note that only *new* characters will see your new Attributes (since the `at_object_creation` hook is called when the object is first created, existing Characters won't have it). To update yourself, run +Note that only *new* characters will see your new Attributes (since the `at_object_creation` hook is +called when the object is first created, existing Characters won't have it). To update yourself, +run @typeclass/force self -This resets your own typeclass (the `/force` switch is a safety measure to not do this accidentally), this means that `at_object_creation` is re-run. +This resets your own typeclass (the `/force` switch is a safety measure to not do this +accidentally), this means that `at_object_creation` is re-run. examine self -Under the "Persistent attributes" heading you should now find the new Attributes `power` and `score` set on yourself by `at_object_creation`. If you don't, first make sure you `@reload`ed into the new code, next look at your server log (in the terminal/console) to see if there were any syntax errors in your code that may have stopped your new code from loading correctly. +Under the "Persistent attributes" heading you should now find the new Attributes `power` and `score` +set on yourself by `at_object_creation`. If you don't, first make sure you `@reload`ed into the new +code, next look at your server log (in the terminal/console) to see if there were any syntax errors +in your code that may have stopped your new code from loading correctly. ## Character Generation -We assume in this example that Accounts first connect into a "character generation area". Evennia also supports full OOC menu-driven character generation, but for this example, a simple start room is enough. When in this room (or rooms) we allow character generation commands. In fact, character generation commands will *only* be available in such rooms. +We assume in this example that Accounts first connect into a "character generation area". Evennia +also supports full OOC menu-driven character generation, but for this example, a simple start room +is enough. When in this room (or rooms) we allow character generation commands. In fact, character +generation commands will *only* be available in such rooms. -Note that this again is made so as to be easy to expand to a full-fledged game. With our simple example, we could simply set an `is_in_chargen` flag on the account and have the `+setpower` command check it. Using this method however will make it easy to add more functionality later. +Note that this again is made so as to be easy to expand to a full-fledged game. With our simple +example, we could simply set an `is_in_chargen` flag on the account and have the `+setpower` command +check it. Using this method however will make it easy to add more functionality later. What we need are the following: -- One character generation [Command](./Commands) to set the "Power" on the `Character`. -- A chargen [CmdSet](./Command-Sets) to hold this command. Lets call it `ChargenCmdset`. -- A custom `ChargenRoom` type that makes this set of commands available to players in such rooms. -- One such room to test things in. +- One character generation [Command](./Commands) to set the "Power" on the `Character`. +- A chargen [CmdSet](./Command-Sets) to hold this command. Lets call it `ChargenCmdset`. +- A custom `ChargenRoom` type that makes this set of commands available to players in such rooms. +- One such room to test things in. ### The +setpower command -For this tutorial we will add all our new commands to `mygame/commands/command.py` but you could split your commands into multiple module if you prefered. +For this tutorial we will add all our new commands to `mygame/commands/command.py` but you could +split your commands into multiple module if you prefered. -For this tutorial character generation will only consist of one [Command](./Commands) to set the Character s "power" stat. It will be called on the following MUSH-like form: +For this tutorial character generation will only consist of one [Command](./Commands) to set the +Character s "power" stat. It will be called on the following MUSH-like form: +setpower 4 -Open `command.py` file. It contains documented empty templates for the base command and the "MuxCommand" type used by default in Evennia. We will use the plain `Command` type here, the `MuxCommand` class offers some extra features like stripping whitespace that may be useful - if so, just import from that instead. +Open `command.py` file. It contains documented empty templates for the base command and the +"MuxCommand" type used by default in Evennia. We will use the plain `Command` type here, the +`MuxCommand` class offers some extra features like stripping whitespace that may be useful - if so, +just import from that instead. -Add the following to the end of the `command.py` file: +Add the following to the end of the `command.py` file: ```python # end of command.py @@ -88,11 +124,11 @@ class CmdSetPower(Command): """ set the power of a character - Usage: + Usage: +setpower <1-10> - This sets the power of the current character. This can only be - used during character generation. + This sets the power of the current character. This can only be + used during character generation. """ key = "+setpower" @@ -102,10 +138,10 @@ class CmdSetPower(Command): "This performs the actual command" errmsg = "You must supply a number between 1 and 10." if not self.args: - self.caller.msg(errmsg) + self.caller.msg(errmsg) return try: - power = int(self.args) + power = int(self.args) except ValueError: self.caller.msg(errmsg) return @@ -116,18 +152,23 @@ class CmdSetPower(Command): self.caller.db.power = power self.caller.msg("Your Power was set to %i." % power) ``` -This is a pretty straightforward command. We do some error checking, then set the power on ourself. We use a `help_category` of "mush" for all our commands, just so they are easy to find and separate in the help list. +This is a pretty straightforward command. We do some error checking, then set the power on ourself. +We use a `help_category` of "mush" for all our commands, just so they are easy to find and separate +in the help list. -Save the file. We will now add it to a new [CmdSet](./Command-Sets) so it can be accessed (in a full chargen system you would of course have more than one command here). +Save the file. We will now add it to a new [CmdSet](./Command-Sets) so it can be accessed (in a full +chargen system you would of course have more than one command here). -Open `mygame/commands/default_cmdsets.py` and import your `command.py` module at the top. We also import the default `CmdSet` class for the next step: +Open `mygame/commands/default_cmdsets.py` and import your `command.py` module at the top. We also +import the default `CmdSet` class for the next step: ```python from evennia import CmdSet from commands import command ``` -Next scroll down and define a new command set (based on the base `CmdSet` class we just imported at the end of this file, to hold only our chargen-specific command(s): +Next scroll down and define a new command set (based on the base `CmdSet` class we just imported at +the end of this file, to hold only our chargen-specific command(s): ```python # end of default_cmdsets.py @@ -139,19 +180,23 @@ class ChargenCmdset(CmdSet): key = "Chargen" def at_cmdset_creation(self): "This is called at initialization" - self.add(command.CmdSetPower()) + self.add(command.CmdSetPower()) ``` -In the future you can add any number of commands to this cmdset, to expand your character generation system as you desire. Now we need to actually put that cmdset on something so it's made available to users. We could put it directly on the Character, but that would make it available all the time. It's cleaner to put it on a room, so it's only available when players are in that room. +In the future you can add any number of commands to this cmdset, to expand your character generation +system as you desire. Now we need to actually put that cmdset on something so it's made available to +users. We could put it directly on the Character, but that would make it available all the time. +It's cleaner to put it on a room, so it's only available when players are in that room. ### Chargen areas -We will create a simple Room typeclass to act as a template for all our Chargen areas. Edit `mygame/typeclasses/rooms.py` next: +We will create a simple Room typeclass to act as a template for all our Chargen areas. Edit +`mygame/typeclasses/rooms.py` next: -```python +```python from commands.default_cmdsets import ChargenCmdset -# ... +# ... # down at the end of rooms.py class ChargenRoom(Room): @@ -163,52 +208,74 @@ class ChargenRoom(Room): "this is called only at first creation" self.cmdset.add(ChargenCmdset, permanent=True) ``` -Note how new rooms created with this typeclass will always start with `ChargenCmdset` on themselves. Don't forget the `permanent=True` keyword or you will lose the cmdset after a server reload. For more information about [Command Sets](./Command-Sets) and [Commands](./Commands), see the respective links. +Note how new rooms created with this typeclass will always start with `ChargenCmdset` on themselves. +Don't forget the `permanent=True` keyword or you will lose the cmdset after a server reload. For +more information about [Command Sets](./Command-Sets) and [Commands](./Commands), see the respective +links. ### Testing chargen -First, make sure you have `@reload`ed the server (or use `evennia reload` from the terminal) to have your new python code added to the game. Check your terminal and fix any errors you see - the error traceback lists exactly where the error is found - look line numbers in files you have changed. +First, make sure you have `@reload`ed the server (or use `evennia reload` from the terminal) to have +your new python code added to the game. Check your terminal and fix any errors you see - the error +traceback lists exactly where the error is found - look line numbers in files you have changed. -We can't test things unless we have some chargen areas to test. Log into the game (you should at this point be using the new, custom Character class). Let's dig a chargen area to test. +We can't test things unless we have some chargen areas to test. Log into the game (you should at +this point be using the new, custom Character class). Let's dig a chargen area to test. @dig chargen:rooms.ChargenRoom = chargen,finish -If you read the help for `@dig` you will find that this will create a new room named `chargen`. The part after the `:` is the python-path to the Typeclass you want to use. Since Evennia will automatically try the `typeclasses` folder of our game directory, we just specify `rooms.ChargenRoom`, meaning it will look inside the module `rooms.py` for a class named `ChargenRoom` (which is what we created above). The names given after `=` are the names of exits to and from the room from your current location. You could also append aliases to each one name, such as `chargen;character generation`. +If you read the help for `@dig` you will find that this will create a new room named `chargen`. The +part after the `:` is the python-path to the Typeclass you want to use. Since Evennia will +automatically try the `typeclasses` folder of our game directory, we just specify +`rooms.ChargenRoom`, meaning it will look inside the module `rooms.py` for a class named +`ChargenRoom` (which is what we created above). The names given after `=` are the names of exits to +and from the room from your current location. You could also append aliases to each one name, such +as `chargen;character generation`. -So in summary, this will create a new room of type ChargenRoom and open an exit `chargen` to it and an exit back here named `finish`. If you see errors at this stage, you must fix them in your code. `@reload` -between fixes. Don't continue until the creation seems to have worked okay. +So in summary, this will create a new room of type ChargenRoom and open an exit `chargen` to it and +an exit back here named `finish`. If you see errors at this stage, you must fix them in your code. +`@reload` +between fixes. Don't continue until the creation seems to have worked okay. chargen -This should bring you to the chargen room. Being in there you should now have the `+setpower` command available, so test it out. When you leave (via the `finish` exit), the command will go away and trying `+setpower` should now give you a command-not-found error. Use `ex me` (as a privileged user) to check so the `Power` [Attribute](./Attributes) has been set correctly. +This should bring you to the chargen room. Being in there you should now have the `+setpower` +command available, so test it out. When you leave (via the `finish` exit), the command will go away +and trying `+setpower` should now give you a command-not-found error. Use `ex me` (as a privileged +user) to check so the `Power` [Attribute](./Attributes) has been set correctly. -If things are not working, make sure your typeclasses and commands are free of bugs and that you have entered the paths to the various command sets and commands correctly. Check the logs or command line for tracebacks and errors. +If things are not working, make sure your typeclasses and commands are free of bugs and that you +have entered the paths to the various command sets and commands correctly. Check the logs or command +line for tracebacks and errors. ## Combat System -We will add our combat command to the default command set, meaning it will be available to everyone at all times. The combat system consists of a `+attack` command to get how successful our attack is. We also change the default `look` command to display the current combat score. +We will add our combat command to the default command set, meaning it will be available to everyone +at all times. The combat system consists of a `+attack` command to get how successful our attack is. +We also change the default `look` command to display the current combat score. ### Attacking with the +attack command -Attacking in this simple system means rolling a random "combat score" influenced by the `power` stat set during Character generation: +Attacking in this simple system means rolling a random "combat score" influenced by the `power` stat +set during Character generation: > +attack You +attack with a combat score of 12! -Go back to `mygame/commands/command.py` and add the command to the end like this: +Go back to `mygame/commands/command.py` and add the command to the end like this: -```python +```python import random -# ... +# ... class CmdAttack(Command): """ - issues an attack + issues an attack - Usage: - +attack + Usage: + +attack This will calculate a new combat score based on your Power. Your combat score is visible to everyone in the same location. @@ -221,8 +288,8 @@ class CmdAttack(Command): caller = self.caller power = caller.db.power if not power: - # this can happen if caller is not of - # our custom Character typeclass + # this can happen if caller is not of + # our custom Character typeclass power = 1 combat_score = random.randint(1, 10 * power) caller.db.combat_score = combat_score @@ -230,32 +297,51 @@ class CmdAttack(Command): # announce message = "%s +attack%s with a combat score of %s!" caller.msg(message % ("You", "", combat_score)) - caller.location.msg_contents(message % + caller.location.msg_contents(message % (caller.key, "s", combat_score), exclude=caller) -``` +``` -What we do here is simply to generate a "combat score" using Python's inbuilt `random.randint()` function. We then store that and echo the result to everyone involved. +What we do here is simply to generate a "combat score" using Python's inbuilt `random.randint()` +function. We then store that and echo the result to everyone involved. -To make the `+attack` command available to you in game, go back to `mygame/commands/default_cmdsets.py` and scroll down to the `CharacterCmdSet` class. At the correct place add this line: +To make the `+attack` command available to you in game, go back to +`mygame/commands/default_cmdsets.py` and scroll down to the `CharacterCmdSet` class. At the correct +place add this line: ```python self.add(command.CmdAttack()) ``` -`@reload` Evennia and the `+attack` command should be available to you. Run it and use e.g. `@ex` to make sure the `combat_score` attribute is saved correctly. +`@reload` Evennia and the `+attack` command should be available to you. Run it and use e.g. `@ex` to +make sure the `combat_score` attribute is saved correctly. ### Have "look" show combat scores -Players should be able to view all current combat scores in the room. We could do this by simply adding a second command named something like `+combatscores`, but we will instead let the default `look` command do the heavy lifting for us and display our scores as part of its normal output, like this: +Players should be able to view all current combat scores in the room. We could do this by simply +adding a second command named something like `+combatscores`, but we will instead let the default +`look` command do the heavy lifting for us and display our scores as part of its normal output, like +this: > look Tom Tom (combat score: 3) This is a great warrior. -We don't actually have to modify the `look` command itself however. To understand why, take a look at how the default `look` is actually defined. It sits in `evennia/commands/default/general.py` (or browse it online [here](https://github.com/evennia/evennia/blob/master/evennia/commands/default/general.py#L44)). You will find that the actual return text is done by the `look` command calling a *hook method* named `return_appearance` on the object looked at. All the `look` does is to echo whatever this hook returns. So what we need to do is to edit our custom Character typeclass and overload its `return_appearance` to return what we want (this is where the advantage of having a custom typeclass comes into play for real). +We don't actually have to modify the `look` command itself however. To understand why, take a look +at how the default `look` is actually defined. It sits in `evennia/commands/default/general.py` (or +browse it online +[here](https://github.com/evennia/evennia/blob/master/evennia/commands/default/general.py#L44)). +You will find that the actual return text is done by the `look` command calling a *hook method* +named `return_appearance` on the object looked at. All the `look` does is to echo whatever this hook +returns. So what we need to do is to edit our custom Character typeclass and overload its +`return_appearance` to return what we want (this is where the advantage of having a custom typeclass +comes into play for real). -Go back to your custom Character typeclass in `mygame/typeclasses/characters.py`. The default implementation of `return appearance` is found in `evennia.DefaultCharacter` (or online [here](https://github.com/evennia/evennia/blob/master/evennia/objects/objects.py#L1438)). If you want to make bigger changes you could copy & paste the whole default thing into our overloading method. In our case the change is small though: +Go back to your custom Character typeclass in `mygame/typeclasses/characters.py`. The default +implementation of `return appearance` is found in `evennia.DefaultCharacter` (or online +[here](https://github.com/evennia/evennia/blob/master/evennia/objects/objects.py#L1438)). If you +want to make bigger changes you could copy & paste the whole default thing into our overloading +method. In our case the change is small though: ```python class Character(DefaultCharacter): @@ -263,8 +349,8 @@ class Character(DefaultCharacter): [...] """ def at_object_creation(self): - "This is called when object is first created, only." - self.db.power = 1 + "This is called when object is first created, only." + self.db.power = 1 self.db.combat_score = 1 def return_appearance(self, looker): @@ -284,24 +370,35 @@ class Character(DefaultCharacter): return text ``` -What we do is to simply let the default `return_appearance` do its thing (`super` will call the parent's version of the same method). We then split out the first line of this text, append our `combat_score` and put it back together again. +What we do is to simply let the default `return_appearance` do its thing (`super` will call the +parent's version of the same method). We then split out the first line of this text, append our +`combat_score` and put it back together again. -`@reload` the server and you should be able to look at other Characters and see their current combat scores. +`@reload` the server and you should be able to look at other Characters and see their current combat +scores. -> Note: A potentially more useful way to do this would be to overload the entire `return_appearance` of the `Room`s of your mush and change how they list their contents; in that way one could see all combat scores of all present Characters at the same time as looking at the room. We leave this as an exercise. +> Note: A potentially more useful way to do this would be to overload the entire `return_appearance` +of the `Room`s of your mush and change how they list their contents; in that way one could see all +combat scores of all present Characters at the same time as looking at the room. We leave this as an +exercise. ## NPC system -Here we will re-use the Character class by introducing a command that can create NPC objects. We should also be able to set its Power and order it around. +Here we will re-use the Character class by introducing a command that can create NPC objects. We +should also be able to set its Power and order it around. -There are a few ways to define the NPC class. We could in theory create a custom typeclass for it and put a custom NPC-specific cmdset on all NPCs. This cmdset could hold all manipulation commands. Since we expect NPC manipulation to be a common occurrence among the user base however, we will instead put all relevant NPC commands in the default command set and limit eventual access with [Permissions and Locks](./Locks#Permissions). +There are a few ways to define the NPC class. We could in theory create a custom typeclass for it +and put a custom NPC-specific cmdset on all NPCs. This cmdset could hold all manipulation commands. +Since we expect NPC manipulation to be a common occurrence among the user base however, we will +instead put all relevant NPC commands in the default command set and limit eventual access with +[Permissions and Locks](./Locks#Permissions). ### Creating an NPC with +createNPC -We need a command for creating the NPC, this is a very straightforward command: +We need a command for creating the NPC, this is a very straightforward command: > +createnpc Anna - You created the NPC 'Anna'. + You created the NPC 'Anna'. At the end of `command.py`, create our new command: @@ -316,11 +413,11 @@ class CmdCreateNPC(Command): +createNPC Creates a new, named NPC. The NPC will start with a Power of 1. - """ + """ key = "+createnpc" aliases = ["+createNPC"] locks = "call:not perm(nonpcs)" - help_category = "mush" + help_category = "mush" def func(self): "creates the object and names it" @@ -335,67 +432,81 @@ class CmdCreateNPC(Command): # make name always start with capital letter name = self.args.strip().capitalize() # create npc in caller's location - npc = create_object("characters.Character", - key=name, + npc = create_object("characters.Character", + key=name, location=caller.location, locks="edit:id(%i) and perm(Builders);call:false()" % caller.id) - # announce + # announce message = "%s created the NPC '%s'." - caller.msg(message % ("You", name)) - caller.location.msg_contents(message % (caller.key, name), - exclude=caller) + caller.msg(message % ("You", name)) + caller.location.msg_contents(message % (caller.key, name), + exclude=caller) ``` -Here we define a `+createnpc` (`+createNPC` works too) that is callable by everyone *not* having the `nonpcs` "[permission](./Locks#Permissions)" (in Evennia, a "permission" can just as well be used to block access, it depends on the lock we define). We create the NPC object in the caller's current location, using our custom `Character` typeclass to do so. +Here we define a `+createnpc` (`+createNPC` works too) that is callable by everyone *not* having the +`nonpcs` "[permission](./Locks#Permissions)" (in Evennia, a "permission" can just as well be used to +block access, it depends on the lock we define). We create the NPC object in the caller's current +location, using our custom `Character` typeclass to do so. -We set an extra lock condition on the NPC, which we will use to check who may edit the NPC later -- we allow the creator to do so, and anyone with the Builders permission (or higher). See [Locks](./Locks) for more information about the lock system. +We set an extra lock condition on the NPC, which we will use to check who may edit the NPC later -- +we allow the creator to do so, and anyone with the Builders permission (or higher). See +[Locks](./Locks) for more information about the lock system. -Note that we just give the object default permissions (by not specifying the `permissions` keyword to the `create_object()` call). In some games one might want to give the NPC the same permissions as the Character creating them, this might be a security risk though. +Note that we just give the object default permissions (by not specifying the `permissions` keyword +to the `create_object()` call). In some games one might want to give the NPC the same permissions +as the Character creating them, this might be a security risk though. -Add this command to your default cmdset the same way you did the `+attack` command earlier. `@reload` and it will be available to test. +Add this command to your default cmdset the same way you did the `+attack` command earlier. +`@reload` and it will be available to test. ### Editing the NPC with +editNPC -Since we re-used our custom character typeclass, our new NPC already has a *Power* value - it defaults to 1. How do we change this? +Since we re-used our custom character typeclass, our new NPC already has a *Power* value - it +defaults to 1. How do we change this? -There are a few ways we can do this. The easiest is to remember that the `power` attribute is just a simple [Attribute](./Attributes) stored on the NPC object. So as a Builder or Admin we could set this right away with the default `@set` command: +There are a few ways we can do this. The easiest is to remember that the `power` attribute is just a +simple [Attribute](./Attributes) stored on the NPC object. So as a Builder or Admin we could set this +right away with the default `@set` command: @set mynpc/power = 6 -The `@set` command is too generally powerful though, and thus only available to staff. We will add a custom command that only changes the things we want players to be allowed to change. We could in principle re-work our old `+setpower` command, but let's try something more useful. Let's make a `+editNPC` command. +The `@set` command is too generally powerful though, and thus only available to staff. We will add a +custom command that only changes the things we want players to be allowed to change. We could in +principle re-work our old `+setpower` command, but let's try something more useful. Let's make a +`+editNPC` command. > +editNPC Anna/power = 10 - Set Anna's property 'power' to 10. + Set Anna's property 'power' to 10. -This is a slightly more complex command. It goes at the end of your `command.py` file as before. +This is a slightly more complex command. It goes at the end of your `command.py` file as before. ```python class CmdEditNPC(Command): """ edit an existing NPC - Usage: + Usage: +editnpc [/ [= value]] - + Examples: +editnpc mynpc/power = 5 +editnpc mynpc/power - displays power value - +editnpc mynpc - shows all editable + +editnpc mynpc - shows all editable attributes and values - This command edits an existing NPC. You must have + This command edits an existing NPC. You must have permission to edit the NPC to use this. """ key = "+editnpc" aliases = ["+editNPC"] locks = "cmd:not perm(nonpcs)" - help_category = "mush" + help_category = "mush" def parse(self): "We need to do some parsing here" args = self.args propname, propval = None, None - if "=" in args: - args, propval = [part.strip() for part in args.rsplit("=", 1)] + if "=" in args: + args, propval = [part.strip() for part in args.rsplit("=", 1)] if "/" in args: args, propname = [part.strip() for part in args.rsplit("/", 1)] # store, so we can access it below in func() @@ -408,52 +519,59 @@ class CmdEditNPC(Command): "do the editing" allowed_propnames = ("power", "attribute1", "attribute2") - + caller = self.caller if not self.args or not self.name: - caller.msg("Usage: +editnpc name[/propname][=propval]") + caller.msg("Usage: +editnpc name[/propname][=propval]") return npc = caller.search(self.name) if not npc: return if not npc.access(caller, "edit"): caller.msg("You cannot change this NPC.") - return + return if not self.propname: # this means we just list the values - output = "Properties of %s:" % npc.key - for propname in allowed_propnames: - propvalue = npc.attributes.get(propname, default="N/A") - output += "\n %s = %s" % (propname, propvalue) + output = f"Properties of {npc.key}:" + for propname in allowed_propnames: + output += f"\n {propname} = {npc.attributes.get(propname, default='N/A')}" caller.msg(output) - elif self.propname not in allowed_propnames: - caller.msg("You may only change %s." % - ", ".join(allowed_propnames)) + elif self.propname not in allowed_propnames: + caller.msg(f"You may only change {', '.join(allowed_propnames)}.") elif self.propval: # assigning a new propvalue # in this example, the properties are all integers... - intpropval = int(self.propval) - npc.attributes.add(self.propname, intpropval) - caller.msg("Set %s's property '%s' to %s" % - (npc.key, self.propname, self.propval)) + intpropval = int(self.propval) + npc.attributes.add(self.propname, intpropval) + caller.msg(f"Set {npc.key}'s property {self.propname} to {self.propval}") else: # propname set, but not propval - show current value - caller.msg("%s has property %s = %s" % - (npc.key, self.propname, - npc.attributes.get(self.propname, default="N/A"))) + caller.msg(f"{npc.key} has property {self.propname} = {npc.attributes.get(self.propname, +default='N/A')}") ``` -This command example shows off the use of more advanced parsing but otherwise it's mostly error checking. It searches for the given npc in the same room, and checks so the caller actually has permission to "edit" it before continuing. An account without the proper permission won't even be able to view the properties on the given NPC. It's up to each game if this is the way it should be. +This command example shows off the use of more advanced parsing but otherwise it's mostly error +checking. It searches for the given npc in the same room, and checks so the caller actually has +permission to "edit" it before continuing. An account without the proper permission won't even be +able to view the properties on the given NPC. It's up to each game if this is the way it should be. -Add this to the default command set like before and you should be able to try it out. +Add this to the default command set like before and you should be able to try it out. -_Note: If you wanted a player to use this command to change an on-object property like the NPC's name (the `key` property), you'd need to modify the command since "key" is not an Attribute (it is not retrievable via `npc.attributes.get` but directly via `npc.key`). We leave this as an optional exercise._ +_Note: If you wanted a player to use this command to change an on-object property like the NPC's +name (the `key` property), you'd need to modify the command since "key" is not an Attribute (it is +not retrievable via `npc.attributes.get` but directly via `npc.key`). We leave this as an optional +exercise._ ### Making the NPC do stuff - the +npc command -Finally, we will make a command to order our NPC around. For now, we will limit this command to only be usable by those having the "edit" permission on the NPC. This can be changed if it's possible for anyone to use the NPC. +Finally, we will make a command to order our NPC around. For now, we will limit this command to only +be usable by those having the "edit" permission on the NPC. This can be changed if it's possible for +anyone to use the NPC. -The NPC, since it inherited our Character typeclass has access to most commands a player does. What it doesn't have access to are Session and Player-based cmdsets (which means, among other things that they cannot chat on channels, but they could do that if you just added those commands). This makes the `+npc` command simple: +The NPC, since it inherited our Character typeclass has access to most commands a player does. What +it doesn't have access to are Session and Player-based cmdsets (which means, among other things that +they cannot chat on channels, but they could do that if you just added those commands). This makes +the `+npc` command simple: +npc Anna = say Hello! Anna says, 'Hello!' @@ -465,11 +583,11 @@ class CmdNPC(Command): """ controls an NPC - Usage: + Usage: +npc = This causes the npc to perform a command as itself. It will do so - with its own permissions and accesses. + with its own permissions and accesses. """ key = "+npc" locks = "call:not perm(nonpcs)" @@ -479,8 +597,9 @@ class CmdNPC(Command): "Simple split of the = sign" name, cmdname = None, None if "=" in self.args: - name, cmdname = [part.strip() - for part in self.args.rsplit("=", 1)] + name, cmdname = self.args.rsplit("=", 1) + name = name.strip() + cmdname = cmdname.strip() self.name, self.cmdname = name, cmdname def func(self): @@ -489,7 +608,7 @@ class CmdNPC(Command): if not self.cmdname: caller.msg("Usage: +npc = ") return - npc = caller.search(self.name) + npc = caller.search(self.name) if not npc: return if not npc.access(caller, "edit"): @@ -497,24 +616,36 @@ class CmdNPC(Command): return # send the command order npc.execute_cmd(self.cmdname) - caller.msg("You told %s to do '%s'." % (npc.key, self.cmdname)) + caller.msg(f"You told {npc.key} to do '{self.cmdname}'.") ``` -Note that if you give an erroneous command, you will not see any error message, since that error will be returned to the npc object, not to you. If you want players to see this, you can give the caller's session ID to the `execute_cmd` call, like this: +Note that if you give an erroneous command, you will not see any error message, since that error +will be returned to the npc object, not to you. If you want players to see this, you can give the +caller's session ID to the `execute_cmd` call, like this: ```python npc.execute_cmd(self.cmdname, sessid=self.caller.sessid) ``` -Another thing to remember is however that this is a very simplistic way to control NPCs. Evennia supports full puppeting very easily. An Account (assuming the "puppet" permission was set correctly) could simply do `@ic mynpc` and be able to play the game "as" that NPC. This is in fact just what happens when an Account takes control of their normal Character as well. +Another thing to remember is however that this is a very simplistic way to control NPCs. Evennia +supports full puppeting very easily. An Account (assuming the "puppet" permission was set correctly) +could simply do `@ic mynpc` and be able to play the game "as" that NPC. This is in fact just what +happens when an Account takes control of their normal Character as well. ## Concluding remarks -This ends the tutorial. It looks like a lot of text but the amount of code you have to write is actually relatively short. At this point you should have a basic skeleton of a game and a feel for what is involved in coding your game. +This ends the tutorial. It looks like a lot of text but the amount of code you have to write is +actually relatively short. At this point you should have a basic skeleton of a game and a feel for +what is involved in coding your game. -From here on you could build a few more ChargenRooms and link that to a bigger grid. The `+setpower` command can either be built upon or accompanied by many more to get a more elaborate character generation. +From here on you could build a few more ChargenRooms and link that to a bigger grid. The `+setpower` +command can either be built upon or accompanied by many more to get a more elaborate character +generation. -The simple "Power" game mechanic should be easily expandable to something more full-fledged and useful, same is true for the combat score principle. The `+attack` could be made to target a specific player (or npc) and automatically compare their relevant attributes to determine a result. +The simple "Power" game mechanic should be easily expandable to something more full-fledged and +useful, same is true for the combat score principle. The `+attack` could be made to target a +specific player (or npc) and automatically compare their relevant attributes to determine a result. -To continue from here, you can take a look at the [Tutorial World](./Tutorial-World-Introduction). For more specific ideas, see the [other tutorials and hints](./Tutorials) as well +To continue from here, you can take a look at the [Tutorial World](./Tutorial-World-Introduction). For +more specific ideas, see the [other tutorials and hints](./Tutorials) as well as the [Developer Central](./Developer-Central). diff --git a/docs/source/Tutorials.md b/docs/source/Tutorials.md index db50f37865..4c481471af 100644 --- a/docs/source/Tutorials.md +++ b/docs/source/Tutorials.md @@ -1,43 +1,76 @@ # Tutorials -Before continuing to read these tutorials (and especially before you start to code or build your game in earnest) it's strongly recommended that you read the [Evennia coding introduction](./Coding-Introduction) as well as the [Planning your own game](./Game-Planning) pages first. +Before continuing to read these tutorials (and especially before you start to code or build your +game in earnest) it's strongly recommended that you read the [Evennia coding introduction](Coding- +Introduction) as well as the [Planning your own game](./Game-Planning) pages first. -Please note that it's not within the scope of our tutorials to teach you basic Python. If you are new to the language, expect to have to look up concepts you are unfamiliar with. Usually a quick internet search will give you all info you need. Furthermore, our tutorials tend to focus on implementation and concepts. As such they give only brief explanations to use Evennia features while providing ample links to the relevant detailed documentation. +Please note that it's not within the scope of our tutorials to teach you basic Python. If you are +new to the language, expect to have to look up concepts you are unfamiliar with. Usually a quick +internet search will give you all info you need. Furthermore, our tutorials tend to focus on +implementation and concepts. As such they give only brief explanations to use Evennia features while +providing ample links to the relevant detailed documentation. -The main information resource for builders is the [Builder Documentation](./Builder-Docs). Coders should refer to the [Developer Central](./Developer-Central) for further information. +The main information resource for builders is the [Builder Documentation](./Builder-Docs). Coders +should refer to the [Developer Central](./Developer-Central) for further information. ### Building _Help with populating your game world._ -- [Tutorial: Building Quick-start](./Building-Quickstart) - helps you build your first rocks and crates using Evennia's defaults. -- [Tutorial: Understanding Color Tags](./Understanding-Color-Tags)- explains how you color your game's text. -- [Introduction: The Tutorial World](./Tutorial-World-Introduction) - this introduces the full (if small) solo-adventure game that comes with the Evennia distribution. It is useful both as an example of building and of coding. -- [Tutorial: Building a Giant Mech](./Building-a-mech-tutorial) - this starts as a building tutorial and transitions into writing code. +- [Tutorial: Building Quick-start](./Building-Quickstart) - helps you build your first rocks and +crates using Evennia's defaults. +- [Tutorial: Understanding Color Tags](./Understanding-Color-Tags)- explains how you color your game's +text. +- [Introduction: The Tutorial World](./Tutorial-World-Introduction) - this introduces the full (if +small) solo-adventure game that comes with the Evennia distribution. It is useful both as an example +of building and of coding. +- [Tutorial: Building a Giant Mech](./Building-a-mech-tutorial) - this starts as a building tutorial +and transitions into writing code. ### General Development tutorials _General code practices for newbie game developers._ -To use Evennia, you will need basic understanding of Python [modules](http://docs.python.org/3.7/tutorial/modules.html), [variables](http://www.tutorialspoint.com/python/python_variable_types.htm), [conditional statements](http://docs.python.org/tutorial/controlflow.html#if-statements), [loops](http://docs.python.org/tutorial/controlflow.html#for-statements), [functions](http://docs.python.org/tutorial/controlflow.html#defining-functions), [lists, dictionaries, list comprehensions](http://docs.python.org/tutorial/datastructures.html) and [string formatting](http://docs.python.org/tutorial/introduction.html#strings). You should also have a basic understanding of [object-oriented programming](http://www.tutorialspoint.com/python/python_classes_objects.htm) and what Python [Classes](http://docs.python.org/tutorial/classes.html) are. +To use Evennia, you will need basic understanding of Python +[modules](http://docs.python.org/3.7/tutorial/modules.html), +[variables](http://www.tutorialspoint.com/python/python_variable_types.htm), [conditional +statements](http://docs.python.org/tutorial/controlflow.html#if-statements), +[loops](http://docs.python.org/tutorial/controlflow.html#for-statements), +[functions](http://docs.python.org/tutorial/controlflow.html#defining-functions), [lists, +dictionaries, list comprehensions](http://docs.python.org/tutorial/datastructures.html) and [string +formatting](http://docs.python.org/tutorial/introduction.html#strings). You should also have a basic +understanding of [object-oriented +programming](http://www.tutorialspoint.com/python/python_classes_objects.htm) and what Python +[Classes](http://docs.python.org/tutorial/classes.html) are. -- [Python tutorials for beginners](https://wiki.python.org/moin/BeginnersGuide/NonProgrammers) - external link with tutorials for those not familiar with coding in general or Python in particular. -- [Tutorial: Version Control](./Version-Control) - use GIT to organize your code both for your own game project and for contributing to Evennia. -- MIT offers free courses in many subjects. Their [Introduction to Computer Science and Programming](https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-00sc-introduction-to-computer-science-and-programming-spring-2011/) uses Python as its language of choice. Longer path, but more in-depth. Definitely worth a look. +- [Python tutorials for beginners](https://wiki.python.org/moin/BeginnersGuide/NonProgrammers) - +external link with tutorials for those not familiar with coding in general or Python in particular. +- [Tutorial: Version Control](./Version-Control) - use GIT to organize your code both for your own +game project and for contributing to Evennia. +- MIT offers free courses in many subjects. Their [Introduction to Computer Science and +Programming](https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-00sc- +introduction-to-computer-science-and-programming-spring-2011/) uses Python as its language of +choice. Longer path, but more in-depth. Definitely worth a look. ### Coding - First Step tutorials _Starting tutorials for you who are new to developing with Evennia._ - [Python basic introduction](./Python-basic-introduction) (part 1) - Python intro using Evennia. -- [Python basic introduction](./Python-basic-tutorial-part-two) (part 2) - More on objects, classes and finding where things are. -- [Tutorial: First Steps Coding](./First-Steps-Coding) - learn each basic feature on their own through step-by-step instruction. -- [Tutorial: A small first game](./Tutorial-for-basic-MUSH-like-game) - learn basic features as part of building a small but working game from scratch. -- [Tutorial: Adding new commands](./Adding-Command-Tutorial) - focuses specifically on how to add new commands. +- [Python basic introduction](./Python-basic-tutorial-part-two) (part 2) - More on objects, classes +and finding where things are. +- [Tutorial: First Steps Coding](./First-Steps-Coding) - learn each basic feature on their own through +step-by-step instruction. +- [Tutorial: A small first game](./Tutorial-for-basic-MUSH-like-game) - learn basic features as part +of building a small but working game from scratch. +- [Tutorial: Adding new commands](./Adding-Command-Tutorial) - focuses specifically on how to add new +commands. - [Tutorial: Parsing command argument](./Parsing-command-arguments,-theory-and-best-practices). -- [Tutorial: Adding new objects](./Adding-Object-Typeclass-Tutorial) - focuses specifically on how to add new objects. -- [Tutorial: Searching objects in the database](./Tutorial-Searching-For-Objects) - how to find existing objects so you can operate on them. +- [Tutorial: Adding new objects](./Adding-Object-Typeclass-Tutorial) - focuses specifically on how to +add new objects. +- [Tutorial: Searching objects in the database](./Tutorial-Searching-For-Objects) - how to find +existing objects so you can operate on them. ### Custom objects and typeclasses @@ -49,7 +82,8 @@ _Examples of designing new objects for your game world_ - [Tutorial: Listening NPC's](./Tutorial-NPCs-listening) - [Tutorial: Creating a vehicle](./Tutorial-Vehicles) - [Tutorial: Making an NPC shop](./NPC-shop-Tutorial) (also advanced [EvMenu](./EvMenu) usage) -- [Tutorial: Implementing a Static In Game Map](./Static-In-Game-Map) (also [Batch Code](./Batch-Code-Processor) usage) +- [Tutorial: Implementing a Static In Game Map](./Static-In-Game-Map) (also [Batch Code](Batch-Code- +Processor) usage) - [Tutorial: Implementing a Dynamic In Game Map](./Dynamic-In-Game-Map) - [Tutorial: Writing your own unit tests](./Unit-Testing#testing-for-game-development-mini-tutorial) @@ -65,7 +99,8 @@ _Creating the underlying game mechanics of game play._ _Design various game systems and achieve particular effects._ -- [FAQ](./Coding-FAQ): A place for users to enter their own hints on achieving various goals in Evennia. +- [FAQ](./Coding-FAQ): A place for users to enter their own hints on achieving various goals in +Evennia. - [Tutorial: Adding a Command prompt](./Command-Prompt) - [Tutorial: Creating a Zoning system](./Zones) - [Tutorial: Letting players manually configure color settings](./Manually-Configuring-Color) @@ -78,11 +113,14 @@ _Design various game systems and achieve particular effects._ - [Tutorial: Handling virtual time in your game](./Gametime-Tutorial) - [Tutorial: Setting up a coordinate system for rooms](./Coordinates) - [Tutorial: customize the way channels and channel commands work in your game](./Customize-channels) -- [Tutorial: Adding unit tests to your game project](./Unit-Testing#testing-for-game-development-mini-tutorial) +- [Tutorial: Adding unit tests to your game project](./Unit-Testing#testing-for-game-development-mini- +tutorial) ### Contrib -_This section contains tutorials linked with contribs. These contribs can be used in your game, but you'll need to install them explicitly. They add common features that can earn you time in implementation._ +_This section contains tutorials linked with contribs. These contribs can be used in your game, but +you'll need to install them explicitly. They add common features that can earn you time in +implementation._ - [list of contribs](https://github.com/evennia/evennia/blob/master/evennia/contrib/README.md) @@ -93,18 +131,26 @@ _This section contains tutorials linked with contribs. These contribs can be us _Expanding Evennia's web presence._ -- [Tutorial: Add a new web page](./Add-a-simple-new-web-page) - simple example to see how Django pages hang together. -- [Tutorial: Website customization](./Web-Tutorial) - learn how to start customizing your game's web presence. -- [Tutorial: Bootstrap & Evennia](./Bootstrap-&-Evennia) - Learn more about Bootstrap, the current CSS framework Evennia is using -- [Tutorial: Build a web page displaying a game character](./Web-Character-View-Tutorial) - make a way to view your character on the web page. +- [Tutorial: Add a new web page](./Add-a-simple-new-web-page) - simple example to see how Django pages +hang together. +- [Tutorial: Website customization](./Web-Tutorial) - learn how to start customizing your game's web +presence. +- [Tutorial: Bootstrap & Evennia](./Bootstrap-&-Evennia) - Learn more about Bootstrap, the current CSS +framework Evennia is using +- [Tutorial: Build a web page displaying a game character](./Web-Character-View-Tutorial) - make a way +to view your character on the web page. - [Tutorial: access your help system from your website](./Help-System-Tutorial) - [Tutorial: add a wiki on your website](./Add-a-wiki-on-your-website) -- [Tutorial: Web Character Generation](Web-Character-Generation/) - make a web-based character application form. -- [Tutorial: Bootstrap Components and Utilities](./Bootstrap-Components-and-Utilities) - Describes some common Bootstrap Components and Utilities that might help in designing for Evennia +- [Tutorial: Web Character Generation](Web-Character-Generation/) - make a web-based character +application form. +- [Tutorial: Bootstrap Components and Utilities](./Bootstrap-Components-and-Utilities) - Describes +some common Bootstrap Components and Utilities that might help in designing for Evennia ### Evennia for [Engine]-Users _Hints for new users more familiar with other game engines._ -- [Evennia for Diku Users](./Evennia-for-Diku-Users) - read up on the differences between Diku style muds and Evennia. -- [Evennia for MUSH Users](./Evennia-for-MUSH-Users) - an introduction to Evennia for those accustomed to MUSH-style servers. +- [Evennia for Diku Users](./Evennia-for-Diku-Users) - read up on the differences between Diku style +muds and Evennia. +- [Evennia for MUSH Users](./Evennia-for-MUSH-Users) - an introduction to Evennia for those accustomed +to MUSH-style servers. diff --git a/docs/source/Typeclasses.md b/docs/source/Typeclasses.md index b5891e9dbb..0f66a0d555 100644 --- a/docs/source/Typeclasses.md +++ b/docs/source/Typeclasses.md @@ -1,9 +1,14 @@ # Typeclasses -*Typeclasses* form the core of Evennia data storage. It allows Evennia to represent any number of different game entities as Python classes, without having to modify the database schema for every new type. +*Typeclasses* form the core of Evennia data storage. It allows Evennia to represent any number of +different game entities as Python classes, without having to modify the database schema for every +new type. -In Evennia the most important game entities, [Accounts](./Accounts), [Objects](./Objects), [Scripts](./Scripts) and [Channels](./Communications#Channels) are all Python classes inheriting, at varying distance, from `evennia.typeclasses.models.TypedObject`. In the documentation we refer to these objects as being "typeclassed" or even "being a typeclass". +In Evennia the most important game entities, [Accounts](./Accounts), [Objects](./Objects), +[Scripts](./Scripts) and [Channels](./Communications#Channels) are all Python classes inheriting, at +varying distance, from `evennia.typeclasses.models.TypedObject`. In the documentation we refer to +these objects as being "typeclassed" or even "being a typeclass". This is how the inheritance looks for the typeclasses in Evennia: @@ -24,9 +29,17 @@ This is how the inheritance looks for the typeclasses in Evennia: Exit ``` -- **Level 1** above is the "database model" level. This describes the database tables and fields (this is technically a [Django model](https://docs.djangoproject.com/en/2.2/topics/db/models/)). -- **Level 2** is where we find Evennia's default implementations of the various game entities, on top of the database. These classes define all the hook methods that Evennia calls in various situations. `DefaultObject` is a little special since it's the parent for `DefaultCharacter`, `DefaultRoom` and `DefaultExit`. They are all grouped under level 2 because they all represents defaults to build from. -- **Level 3**, finally, holds empty template classes created in your game directory. This is the level you are meant to modify and tweak as you please, overloading the defaults as befits your game. The templates inherit directly from their defaults, so `Object` inherits from `DefaultObject` and `Room` inherits from `DefaultRoom`. +- **Level 1** above is the "database model" level. This describes the database tables and fields +(this is technically a [Django model](https://docs.djangoproject.com/en/2.2/topics/db/models/)). +- **Level 2** is where we find Evennia's default implementations of the various game entities, on +top of the database. These classes define all the hook methods that Evennia calls in various +situations. `DefaultObject` is a little special since it's the parent for `DefaultCharacter`, +`DefaultRoom` and `DefaultExit`. They are all grouped under level 2 because they all represents +defaults to build from. +- **Level 3**, finally, holds empty template classes created in your game directory. This is the +level you are meant to modify and tweak as you please, overloading the defaults as befits your game. +The templates inherit directly from their defaults, so `Object` inherits from `DefaultObject` and +`Room` inherits from `DefaultRoom`. The `typeclass/list` command will provide a list of all typeclasses known to Evennia. This can be useful for getting a feel for what is available. Note @@ -37,10 +50,16 @@ to Evennia you must import that module from somewhere. ### Difference between typeclasses and classes -All Evennia classes inheriting from class in the table above share one important feature and two important limitations. This is why we don't simply call them "classes" but "typeclasses". +All Evennia classes inheriting from class in the table above share one important feature and two +important limitations. This is why we don't simply call them "classes" but "typeclasses". - 1. A typeclass can save itself to the database. This means that some properties (actually not that many) on the class actually represents database fields and can only hold very specific data types. This is detailed [below](./Typeclasses#about-typeclass-properties). - 1. Due to its connection to the database, the typeclass' name must be *unique* across the _entire_ server namespace. That is, there must never be two same-named classes defined anywhere. So the below code would give an error (since `DefaultObject` is now globally found both in this module and in the default library): + 1. A typeclass can save itself to the database. This means that some properties (actually not that +many) on the class actually represents database fields and can only hold very specific data types. +This is detailed [below](./Typeclasses#about-typeclass-properties). + 1. Due to its connection to the database, the typeclass' name must be *unique* across the _entire_ +server namespace. That is, there must never be two same-named classes defined anywhere. So the below +code would give an error (since `DefaultObject` is now globally found both in this module and in the +default library): ```python from evennia import DefaultObject as BaseObject @@ -48,7 +67,12 @@ All Evennia classes inheriting from class in the table above share one important pass ``` - 1. A typeclass' `__init__` method should normally not be overloaded. This has mostly to do with the fact that the `__init__` method is not called in a predictable way. Instead Evennia suggest you use the `at_*_creation` hooks (like `at_object_creation` for Objects) for setting things the very first time the typeclass is saved to the database or the `at_init` hook which is called every time the object is cached to memory. If you know what you are doing and want to use `__init__`, it *must* both accept arbitrary keyword arguments and use `super` to call its parent:: + 1. A typeclass' `__init__` method should normally not be overloaded. This has mostly to do with the +fact that the `__init__` method is not called in a predictable way. Instead Evennia suggest you use +the `at_*_creation` hooks (like `at_object_creation` for Objects) for setting things the very first +time the typeclass is saved to the database or the `at_init` hook which is called every time the +object is cached to memory. If you know what you are doing and want to use `__init__`, it *must* +both accept arbitrary keyword arguments and use `super` to call its parent:: ```python def __init__(self, **kwargs): @@ -58,12 +82,13 @@ All Evennia classes inheriting from class in the table above share one important ``` Apart from this, a typeclass works like any normal Python class and you can -treat it as such. +treat it as such. ## Creating a new typeclass -It's easy to work with Typeclasses. Either you use an existing typeclass or you create a new Python class inheriting from an existing typeclass. Here is an example of creating a new type of Object: +It's easy to work with Typeclasses. Either you use an existing typeclass or you create a new Python +class inheriting from an existing typeclass. Here is an example of creating a new type of Object: ```python from evennia import DefaultObject @@ -75,7 +100,8 @@ It's easy to work with Typeclasses. Either you use an existing typeclass or you ``` -You can now create a new `Furniture` object in two ways. First (and usually not the most convenient) way is to create an instance of the class and then save it manually to the database: +You can now create a new `Furniture` object in two ways. First (and usually not the most +convenient) way is to create an instance of the class and then save it manually to the database: ```python chair = Furniture(db_key="Chair") @@ -83,7 +109,9 @@ chair.save() ``` -To use this you must give the database field names as keywords to the call. Which are available depends on the entity you are creating, but all start with `db_*` in Evennia. This is a method you may be familiar with if you know Django from before. +To use this you must give the database field names as keywords to the call. Which are available +depends on the entity you are creating, but all start with `db_*` in Evennia. This is a method you +may be familiar with if you know Django from before. It is recommended that you instead use the `create_*` functions to create typeclassed entities: @@ -96,11 +124,19 @@ chair = create_object(Furniture, key="Chair") chair = create_object("furniture.Furniture", key="Chair") ``` -The `create_object` (`create_account`, `create_script` etc) takes the typeclass as its first argument; this can both be the actual class or the python path to the typeclass as found under your game directory. So if your `Furniture` typeclass sits in `mygame/typeclasses/furniture.py`, you could point to it as `typeclasses.furniture.Furniture`. Since Evennia will itself look in `mygame/typeclasses`, you can shorten this even further to just `furniture.Furniture`. The create-functions take a lot of extra keywords allowing you to set things like [Attributes](./Attributes) and [Tags](./Tags) all in one go. These keywords don't use the `db_*` prefix. This will also automatically save the new instance to the database, so you don't need to call `save()` explicitly. +The `create_object` (`create_account`, `create_script` etc) takes the typeclass as its first +argument; this can both be the actual class or the python path to the typeclass as found under your +game directory. So if your `Furniture` typeclass sits in `mygame/typeclasses/furniture.py`, you +could point to it as `typeclasses.furniture.Furniture`. Since Evennia will itself look in +`mygame/typeclasses`, you can shorten this even further to just `furniture.Furniture`. The create- +functions take a lot of extra keywords allowing you to set things like [Attributes](./Attributes) and +[Tags](./Tags) all in one go. These keywords don't use the `db_*` prefix. This will also automatically +save the new instance to the database, so you don't need to call `save()` explicitly. ### About typeclass properties -An example of a database field is `db_key`. This stores the "name" of the entity you are modifying and can thus only hold a string. This is one way of making sure to update the `db_key`: +An example of a database field is `db_key`. This stores the "name" of the entity you are modifying +and can thus only hold a string. This is one way of making sure to update the `db_key`: ```python chair.db_key = "Table" @@ -110,7 +146,9 @@ print(chair.db_key) <<< Table ``` -That is, we change the chair object to have the `db_key` "Table", then save this to the database. However, you almost never do things this way; Evennia defines property wrappers for all the database fields. These are named the same as the field, but without the `db_` part: +That is, we change the chair object to have the `db_key` "Table", then save this to the database. +However, you almost never do things this way; Evennia defines property wrappers for all the database +fields. These are named the same as the field, but without the `db_` part: ```python chair.key = "Table" @@ -120,47 +158,73 @@ print(chair.key) ``` -The `key` wrapper is not only shorter to write, it will make sure to save the field for you, and does so more efficiently by levering sql update mechanics under the hood. So whereas it is good to be aware that the field is named `db_key` you should use `key` as much as you can. +The `key` wrapper is not only shorter to write, it will make sure to save the field for you, and +does so more efficiently by levering sql update mechanics under the hood. So whereas it is good to +be aware that the field is named `db_key` you should use `key` as much as you can. -Each typeclass entity has some unique fields relevant to that type. But all also share the following fields (the wrapper name without `db_` is given): +Each typeclass entity has some unique fields relevant to that type. But all also share the +following fields (the wrapper name without `db_` is given): - - `key` (str): The main identifier for the entity, like "Rose", "myscript" or "Paul". `name` is an alias. + - `key` (str): The main identifier for the entity, like "Rose", "myscript" or "Paul". `name` is an +alias. - `date_created` (datetime): Time stamp when this object was created. - `typeclass_path` (str): A python path pointing to the location of this (type)class There is one special field that doesn't use the `db_` prefix (it's defined by Django): - - `id` (int): the database id (database ref) of the object. This is an ever-increasing, unique integer. It can also be accessed as `dbid` (database ID) or `pk` (primary key). The `dbref` property returns the string form "#id". + - `id` (int): the database id (database ref) of the object. This is an ever-increasing, unique +integer. It can also be accessed as `dbid` (database ID) or `pk` (primary key). The `dbref` property +returns the string form "#id". The typeclassed entity has several common handlers: - `tags` - the [TagHandler](./Tags) that handles tagging. Use `tags.add()` , `tags.get()` etc. - - `locks` - the [LockHandler](./Locks) that manages access restrictions. Use `locks.add()`, `locks.get()` etc. - - `attributes` - the [AttributeHandler](./Attributes) that manages Attributes on the object. Use `attributes.add()` + - `locks` - the [LockHandler](./Locks) that manages access restrictions. Use `locks.add()`, +`locks.get()` etc. + - `attributes` - the [AttributeHandler](./Attributes) that manages Attributes on the object. Use +`attributes.add()` etc. - `db` (DataBase) - a shortcut property to the AttributeHandler; allowing `obj.db.attrname = value` - - `nattributes` - the [Non-persistent AttributeHandler](./Attributes) for attributes not saved in the database. - - `ndb` (NotDataBase) - a shortcut property to the Non-peristent AttributeHandler. Allows `obj.ndb.attrname = value` + - `nattributes` - the [Non-persistent AttributeHandler](./Attributes) for attributes not saved in the +database. + - `ndb` (NotDataBase) - a shortcut property to the Non-peristent AttributeHandler. Allows +`obj.ndb.attrname = value` -Each of the typeclassed entities then extend this list with their own properties. Go to the respective pages for [Objects](./Objects), [Scripts](./Scripts), [Accounts](./Accounts) and [Channels](./Communications) for more info. It's also recommended that you explore the available entities using [Evennia's flat API](./Evennia-API) to explore which properties and methods they have available. +Each of the typeclassed entities then extend this list with their own properties. Go to the +respective pages for [Objects](./Objects), [Scripts](./Scripts), [Accounts](./Accounts) and +[Channels](./Communications) for more info. It's also recommended that you explore the available +entities using [Evennia's flat API](./Evennia-API) to explore which properties and methods they have +available. ### Overloading hooks -The way to customize typeclasses is usually to overload *hook methods* on them. Hooks are methods that Evennia call in various situations. An example is the `at_object_creation` hook on `Objects`, which is only called once, the very first time this object is saved to the database. Other examples are the `at_login` hook of Accounts and the `at_repeat` hook of Scripts. +The way to customize typeclasses is usually to overload *hook methods* on them. Hooks are methods +that Evennia call in various situations. An example is the `at_object_creation` hook on `Objects`, +which is only called once, the very first time this object is saved to the database. Other examples +are the `at_login` hook of Accounts and the `at_repeat` hook of Scripts. ### Querying for typeclasses -Most of the time you search for objects in the database by using convenience methods like the `caller.search()` of [Commands](./Commands) or the search functions like `evennia.search_objects`. +Most of the time you search for objects in the database by using convenience methods like the +`caller.search()` of [Commands](./Commands) or the search functions like `evennia.search_objects`. -You can however also query for them directly using [Django's query language](https://docs.djangoproject.com/en/1.7/topics/db/queries/). This makes use of a _database manager_ that sits on all typeclasses, named `objects`. This manager holds methods that allow database searches against that particular type of object (this is the way Django normally works too). When using Django queries, you need to use the full field names (like `db_key`) to search: +You can however also query for them directly using [Django's query +language](https://docs.djangoproject.com/en/1.7/topics/db/queries/). This makes use of a _database +manager_ that sits on all typeclasses, named `objects`. This manager holds methods that allow +database searches against that particular type of object (this is the way Django normally works +too). When using Django queries, you need to use the full field names (like `db_key`) to search: ```python matches = Furniture.objects.get(db_key="Chair") ``` -It is important that this will *only* find objects inheriting directly from `Furniture` in your database. If there was a subclass of `Furniture` named `Sitables` you would not find any chairs derived from `Sitables` with this query (this is not a Django feature but special to Evennia). To find objects from subclasses Evennia instead makes the `get_family` and `filter_family` query methods available: +It is important that this will *only* find objects inheriting directly from `Furniture` in your +database. If there was a subclass of `Furniture` named `Sitables` you would not find any chairs +derived from `Sitables` with this query (this is not a Django feature but special to Evennia). To +find objects from subclasses Evennia instead makes the `get_family` and `filter_family` query +methods available: ```python # search for all furnitures and subclasses of furnitures @@ -169,20 +233,27 @@ matches = Furniture.objects.filter_family(db_key__startswith="Chair") ``` -To make sure to search, say, all `Scripts` *regardless* of typeclass, you need to query from the database model itself. So for Objects, this would be `ObjectDB` in the diagram above. Here's an example for Scripts: +To make sure to search, say, all `Scripts` *regardless* of typeclass, you need to query from the +database model itself. So for Objects, this would be `ObjectDB` in the diagram above. Here's an +example for Scripts: ```python from evennia import ScriptDB matches = ScriptDB.objects.filter(db_key__contains="Combat") ``` -When querying from the database model parent you don't need to use `filter_family` or `get_family` - you will always query all children on the database model. +When querying from the database model parent you don't need to use `filter_family` or `get_family` - +you will always query all children on the database model. ## Updating existing typeclass instances -If you already have created instances of Typeclasses, you can modify the *Python code* at any time - due to how Python inheritance works your changes will automatically be applied to all children once you have reloaded the server. +If you already have created instances of Typeclasses, you can modify the *Python code* at any time - +due to how Python inheritance works your changes will automatically be applied to all children once +you have reloaded the server. -However, database-saved data, like `db_*` fields, [Attributes](./Attributes), [Tags](./Tags) etc, are not themselves embedded into the class and will *not* be updated automatically. This you need to manage yourself, by searching for all relevant objects and updating or adding the data: +However, database-saved data, like `db_*` fields, [Attributes](./Attributes), [Tags](./Tags) etc, are +not themselves embedded into the class and will *not* be updated automatically. This you need to +manage yourself, by searching for all relevant objects and updating or adding the data: ```python # add a worth Attribute to all existing Furniture @@ -191,7 +262,11 @@ for obj in Furniture.objects.all(): obj.db.worth = 100 ``` -A common use case is putting all Attributes in the `at_*_creation` hook of the entity, such as `at_object_creation` for `Objects`. This is called every time an object is created - and only then. This is usually what you want but it does mean already existing objects won't get updated if you change the contents of `at_object_creation` later. You can fix this in a similar way as above (manually setting each Attribute) or with something like this: +A common use case is putting all Attributes in the `at_*_creation` hook of the entity, such as +`at_object_creation` for `Objects`. This is called every time an object is created - and only then. +This is usually what you want but it does mean already existing objects won't get updated if you +change the contents of `at_object_creation` later. You can fix this in a similar way as above +(manually setting each Attribute) or with something like this: ```python # Re-run at_object_creation only on those objects not having the new Attribute @@ -200,26 +275,36 @@ for obj in Furniture.objects.all(): obj.at_object_creation() ``` -The above examples can be run in the command prompt created by `evennia shell`. You could also run it all in-game using `@py`. That however requires you to put the code (including imports) as one single line using `;` and [list comprehensions](http://www.secnetix.de/olli/Python/list_comprehensions.hawk), like this (ignore the line break, that's only for readability in the wiki): +The above examples can be run in the command prompt created by `evennia shell`. You could also run +it all in-game using `@py`. That however requires you to put the code (including imports) as one +single line using `;` and [list +comprehensions](http://www.secnetix.de/olli/Python/list_comprehensions.hawk), like this (ignore the +line break, that's only for readability in the wiki): ``` @py from typeclasses.furniture import Furniture; [obj.at_object_creation() for obj in Furniture.objects.all() if not obj.db.worth] ``` -It is recommended that you plan your game properly before starting to build, to avoid having to retroactively update objects more than necessary. +It is recommended that you plan your game properly before starting to build, to avoid having to +retroactively update objects more than necessary. ## Swap typeclass -If you want to swap an already existing typeclass, there are two ways to do so: From in-game and via code. From inside the game you can use the default `@typeclass` command: +If you want to swap an already existing typeclass, there are two ways to do so: From in-game and via +code. From inside the game you can use the default `@typeclass` command: ``` @typeclass objname = path.to.new.typeclass ``` There are two important switches to this command: -- `/reset` - This will purge all existing Attributes on the object and re-run the creation hook (like `at_object_creation` for Objects). This assures you get an object which is purely of this new class. -- `/force` - This is required if you are changing the class to be *the same* class the object already has - it's a safety check to avoid user errors. This is usually used together with `/reset` to re-run the creation hook on an existing class. +- `/reset` - This will purge all existing Attributes on the object and re-run the creation hook +(like `at_object_creation` for Objects). This assures you get an object which is purely of this new +class. +- `/force` - This is required if you are changing the class to be *the same* class the object +already has - it's a safety check to avoid user errors. This is usually used together with `/reset` +to re-run the creation hook on an existing class. In code you instead use the `swap_typeclass` method which you can find on all typeclassed entities: @@ -228,20 +313,42 @@ obj_to_change.swap_typeclass(new_typeclass_path, clean_attributes=False, run_start_hooks="all", no_default=True, clean_cmdsets=False) ``` -The arguments to this method are described [in the API docs here](github:evennia.typeclasses.models#typedobjectswap_typeclass). +The arguments to this method are described [in the API docs +here](github:evennia.typeclasses.models#typedobjectswap_typeclass). ## How typeclasses actually work *This is considered an advanced section.* -Technically, typeclasses are [Django proxy models](https://docs.djangoproject.com/en/1.7/topics/db/models/#proxy-models). The only database models that are "real" in the typeclass system (that is, are represented by actual tables in the database) are `AccountDB`, `ObjectDB`, `ScriptDB` and `ChannelDB` (there are also [Attributes](./Attributes) and [Tags](./Tags) but they are not typeclasses themselves). All the subclasses of them are "proxies", extending them with Python code without actually modifying the database layout. +Technically, typeclasses are [Django proxy +models](https://docs.djangoproject.com/en/1.7/topics/db/models/#proxy-models). The only database +models that are "real" in the typeclass system (that is, are represented by actual tables in the +database) are `AccountDB`, `ObjectDB`, `ScriptDB` and `ChannelDB` (there are also +[Attributes](./Attributes) and [Tags](./Tags) but they are not typeclasses themselves). All the +subclasses of them are "proxies", extending them with Python code without actually modifying the +database layout. -Evennia modifies Django's proxy model in various ways to allow them to work without any boiler plate (for example you don't need to set the Django "proxy" property in the model `Meta` subclass, Evennia handles this for you using metaclasses). Evennia also makes sure you can query subclasses as well as patches django to allow multiple inheritance from the same base class. +Evennia modifies Django's proxy model in various ways to allow them to work without any boiler plate +(for example you don't need to set the Django "proxy" property in the model `Meta` subclass, Evennia +handles this for you using metaclasses). Evennia also makes sure you can query subclasses as well as +patches django to allow multiple inheritance from the same base class. ### Caveats -Evennia uses the *idmapper* to cache its typeclasses (Django proxy models) in memory. The idmapper allows things like on-object handlers and properties to be stored on typeclass instances and to not get lost as long as the server is running (they will only be cleared on a Server reload). Django does not work like this by default; by default every time you search for an object in the database you'll get a *different* instance of that object back and anything you stored on it that was not in the database would be lost. The bottom line is that Evennia's Typeclass instances subside in memory a lot longer than vanilla Django model instance do. +Evennia uses the *idmapper* to cache its typeclasses (Django proxy models) in memory. The idmapper +allows things like on-object handlers and properties to be stored on typeclass instances and to not +get lost as long as the server is running (they will only be cleared on a Server reload). Django +does not work like this by default; by default every time you search for an object in the database +you'll get a *different* instance of that object back and anything you stored on it that was not in +the database would be lost. The bottom line is that Evennia's Typeclass instances subside in memory +a lot longer than vanilla Django model instance do. -There is one caveat to consider with this, and that relates to [making your own models](./New-Models): Foreign relationships to typeclasses are cached by Django and that means that if you were to change an object in a foreign relationship via some other means than via that relationship, the object seeing the relationship may not reliably update but will still see its old cached version. Due to typeclasses staying so long in memory, stale caches of such relationships could be more visible than common in Django. See the [closed issue #1098 and its comments](https://github.com/evennia/evennia/issues/1098) for examples and solutions. +There is one caveat to consider with this, and that relates to [making your own models](New- +Models): Foreign relationships to typeclasses are cached by Django and that means that if you were +to change an object in a foreign relationship via some other means than via that relationship, the +object seeing the relationship may not reliably update but will still see its old cached version. +Due to typeclasses staying so long in memory, stale caches of such relationships could be more +visible than common in Django. See the [closed issue #1098 and its +comments](https://github.com/evennia/evennia/issues/1098) for examples and solutions. diff --git a/docs/source/Understanding-Color-Tags.md b/docs/source/Understanding-Color-Tags.md index 7386f8ac59..dea3e95a49 100644 --- a/docs/source/Understanding-Color-Tags.md +++ b/docs/source/Understanding-Color-Tags.md @@ -2,39 +2,64 @@ This tutorial aims at dispelling confusions regarding the use of color tags within Evennia. -Correct understanding of this topic requires having read the [TextTags](./TextTags) page and learned Evennia's color tags. Here we'll explain by examples the reasons behind the unexpected (or apparently incoherent) behaviors of some color tags, as mentioned _en passant_ in the [TextTags](./TextTags) page. +Correct understanding of this topic requires having read the [TextTags](./TextTags) page and learned +Evennia's color tags. Here we'll explain by examples the reasons behind the unexpected (or +apparently incoherent) behaviors of some color tags, as mentioned _en passant_ in the +[TextTags](./TextTags) page. -All you'll need for this tutorial is access to a running instance of Evennia via a color-enabled client. The examples provided are just commands that you can type in your client. +All you'll need for this tutorial is access to a running instance of Evennia via a color-enabled +client. The examples provided are just commands that you can type in your client. Evennia, ANSI and Xterm256 ========================== -All modern MUD clients support colors; nevertheless, the standards to which all clients abide dates back to old day of terminals, and when it comes to colors we are dealing with ANSI and Xterm256 standards. +All modern MUD clients support colors; nevertheless, the standards to which all clients abide dates +back to old day of terminals, and when it comes to colors we are dealing with ANSI and Xterm256 +standards. -Evennia handles transparently, behind the scenes, all the code required to enforce these standards—so, if a user connects with a client which doesn't support colors, or supports only ANSI (16 colors), Evennia will take all due steps to ensure that the output will be adjusted to look right at the client side. +Evennia handles transparently, behind the scenes, all the code required to enforce these +standards—so, if a user connects with a client which doesn't support colors, or supports only ANSI +(16 colors), Evennia will take all due steps to ensure that the output will be adjusted to look +right at the client side. -As for you, the developer, all you need to care about is knowing how to correctly use the color tags within your MUD. Most likely, you'll be adding colors to help pages, descriptions, automatically generated text, etc. +As for you, the developer, all you need to care about is knowing how to correctly use the color tags +within your MUD. Most likely, you'll be adding colors to help pages, descriptions, automatically +generated text, etc. -You are free to mix together ANSI and Xterm256 color tags, but you should be aware of a few pitfalls. ANSI and Xterm256 coexist without conflicts in Evennia, but in many ways they don't «see» each other: ANSI-specific color tags will have no effect on Xterm-defined colors, as we shall see here. +You are free to mix together ANSI and Xterm256 color tags, but you should be aware of a few +pitfalls. ANSI and Xterm256 coexist without conflicts in Evennia, but in many ways they don't «see» +each other: ANSI-specific color tags will have no effect on Xterm-defined colors, as we shall see +here. ANSI ==== -ANSI has a set of 16 colors, to be more precise: ANSI has 8 basic colors which come in _dark_ and _bright_ flavours—with _dark_ being _normal_. The colors are: red, green, yellow, blue, magenta, cyan, white and black. White in its dark version is usually referred to as gray, and black in its bright version as darkgray. Here, for sake of simplicity they'll be referred to as dark and bright: bright/dark black, bright/dark white. +ANSI has a set of 16 colors, to be more precise: ANSI has 8 basic colors which come in _dark_ and +_bright_ flavours—with _dark_ being _normal_. The colors are: red, green, yellow, blue, magenta, +cyan, white and black. White in its dark version is usually referred to as gray, and black in its +bright version as darkgray. Here, for sake of simplicity they'll be referred to as dark and bright: +bright/dark black, bright/dark white. The default colors of MUD clients is normal (dark) white on normal black (ie: gray on black). -It's important to grasp that in the ANSI standard bright colors apply only to text (foreground), not to background. Evennia allows to bypass this limitation via Xterm256, but doing so will impact the behavior of ANSI tags, as we shall see. +It's important to grasp that in the ANSI standard bright colors apply only to text (foreground), not +to background. Evennia allows to bypass this limitation via Xterm256, but doing so will impact the +behavior of ANSI tags, as we shall see. -Also, it's important to remember that the 16 ANSI colors are a convention, and the final user can always customize their appearance—he might decide to have green show as red, and dark green as blue, etc. +Also, it's important to remember that the 16 ANSI colors are a convention, and the final user can +always customize their appearance—he might decide to have green show as red, and dark green as blue, +etc. Xterm256 ======== -The 16 colors of ANSI should be more than enough to handle simple coloring of text. But when an author wants to be sure that a given color will show as he intended it, she might choose to rely on Xterm256 colors. +The 16 colors of ANSI should be more than enough to handle simple coloring of text. But when an +author wants to be sure that a given color will show as he intended it, she might choose to rely on +Xterm256 colors. -Xterm256 doesn't rely on a palette of named colors, it instead represent colors by their values. So, a red color could be `|[500` (bright and pure red), or `|[300` (darker red), and so on. +Xterm256 doesn't rely on a palette of named colors, it instead represent colors by their values. So, +a red color could be `|[500` (bright and pure red), or `|[300` (darker red), and so on. ANSI Color Tags in Evennia ========================== @@ -49,9 +74,12 @@ Let's proceed by examples. In your MUD client type: say Normal |* Negative -Evennia should output the word "Normal" normally (ie: gray on black) and "Negative" in reversed colors (ie: black on gray). +Evennia should output the word "Normal" normally (ie: gray on black) and "Negative" in reversed +colors (ie: black on gray). -This is pretty straight forward, the `|*` ANSI *invert* tag switches between foreground and background—from now on, **FG** and **BG** shorthands will be used to refer to foreground and background. +This is pretty straight forward, the `|*` ANSI *invert* tag switches between foreground and +background—from now on, **FG** and **BG** shorthands will be used to refer to foreground and +background. But take mental note of this: `|*` has switched *dark white* and *dark black*. @@ -59,50 +87,79 @@ Now try this: say |w Bright white FG |* Negative -You'll notice that the word "Negative" is not black on white, it's darkgray on gray. Why is this? Shouldn't it be black text on a white BG? Two things are happening here. +You'll notice that the word "Negative" is not black on white, it's darkgray on gray. Why is this? +Shouldn't it be black text on a white BG? Two things are happening here. -As mentioned, ANSI has 8 base colors, the dark ones. The bright ones are achieved by means of *highlighting* the base/dark/normal colors, and they only apply to FG. +As mentioned, ANSI has 8 base colors, the dark ones. The bright ones are achieved by means of +*highlighting* the base/dark/normal colors, and they only apply to FG. -What happened here is that when we set the bright white FG with `|w`, Evennia translated this into the ANSI sequence of Highlight On + White FG. In terms of Evennia's color tags, it's as if we typed: +What happened here is that when we set the bright white FG with `|w`, Evennia translated this into +the ANSI sequence of Highlight On + White FG. In terms of Evennia's color tags, it's as if we typed: say |h|!W Bright white FG |* Negative -Furthermore, the Highlight-On property (which only works for BG!) is preserved after the FG/BG switch, this being the reason why we see black as darkgray: highlighting makes it *bright black* (ie: darkgray). +Furthermore, the Highlight-On property (which only works for BG!) is preserved after the FG/BG +switch, this being the reason why we see black as darkgray: highlighting makes it *bright black* +(ie: darkgray). -As for the BG being also grey, that is normal—ie: you are seeing *normal white* (ie: dark white = gray). Remember that since there are no bright BG colors, the ANSI `|*` tag will transpose any FG color in its normal/dark version. So here the FG's bright white became dark white in the BG! In reality, it was always normal/dark white, except that in the FG is seen as bright because of the highlight tag behind the scenes. +As for the BG being also grey, that is normal—ie: you are seeing *normal white* (ie: dark white = +gray). Remember that since there are no bright BG colors, the ANSI `|*` tag will transpose any FG +color in its normal/dark version. So here the FG's bright white became dark white in the BG! In +reality, it was always normal/dark white, except that in the FG is seen as bright because of the +highlight tag behind the scenes. Let's try the same thing with some color: say |m |[G Bright Magenta on Dark Green |* Negative -Again, the BG stays dark because of ANSI rules, and the FG stays bright because of the implicit `|h` in `|m`. +Again, the BG stays dark because of ANSI rules, and the FG stays bright because of the implicit `|h` +in `|m`. -Now, let's see what happens if we set a bright BG and then invert—yes, Evennia kindly allows us to do it, even if it's not within ANSI expectations. +Now, let's see what happens if we set a bright BG and then invert—yes, Evennia kindly allows us to +do it, even if it's not within ANSI expectations. say |[b Dark White on Bright Blue |* Negative -Before color inversion, the BG does show in bright blue, and after inversion (as expected) it's *dark white* (gray). The bright blue of the BG survived the inversion and gave us a bright blue FG. This behavior is tricky though, and not as simple as it might look. +Before color inversion, the BG does show in bright blue, and after inversion (as expected) it's +*dark white* (gray). The bright blue of the BG survived the inversion and gave us a bright blue FG. +This behavior is tricky though, and not as simple as it might look. -If the inversion were to be pure ANSI, the bright blue would have been accounted just as normal blue, and should have converted to normal blue in the FG (after all, there was no highlighting on). The fact is that in reality this color is not bright blue at all, it just an Xterm version of it! +If the inversion were to be pure ANSI, the bright blue would have been accounted just as normal +blue, and should have converted to normal blue in the FG (after all, there was no highlighting on). +The fact is that in reality this color is not bright blue at all, it just an Xterm version of it! To demonstrate this, type: say |[b Dark White on Bright Blue |* Negative |H un-bright -The `|H` Highlight-Off tag should have turned *dark blue* the last word; but it didn't because it couldn't: in order to enforce the non-ANSI bright BG Evennia turned to Xterm, and Xterm entities are not affected by ANSI tags! +The `|H` Highlight-Off tag should have turned *dark blue* the last word; but it didn't because it +couldn't: in order to enforce the non-ANSI bright BG Evennia turned to Xterm, and Xterm entities are +not affected by ANSI tags! -So, we are getting at the heart of all confusions and possible odd-behaviors pertaining color tags in Evennia: apart from Evennia's translations from- and to- ANSI/Xterm, the two systems are independent and transparent to each other. +So, we are getting at the heart of all confusions and possible odd-behaviors pertaining color tags +in Evennia: apart from Evennia's translations from- and to- ANSI/Xterm, the two systems are +independent and transparent to each other. -The bright blue of the previous example was just an Xterm representation of the ANSI standard blue. Try to change the default settings of your client, so that blue shows as some other color, you'll then realize the difference when Evennia is sending a true ANSI color (which will show up according to your settings) and when instead it's sending an Xterm representation of that color (which will show up always as defined by Evennia). +The bright blue of the previous example was just an Xterm representation of the ANSI standard blue. +Try to change the default settings of your client, so that blue shows as some other color, you'll +then realize the difference when Evennia is sending a true ANSI color (which will show up according +to your settings) and when instead it's sending an Xterm representation of that color (which will +show up always as defined by Evennia). -You'll have to keep in mind that the presence of an Xterm BG or FG color might affect the way your tags work on the text. For example: +You'll have to keep in mind that the presence of an Xterm BG or FG color might affect the way your +tags work on the text. For example: say |[b Bright Blue BG |* Negative |!Y Dark Yellow |h not bright -Here the `|h` tag no longer affects the FG color. Even though it was changed via the `|!` tag, the ANSI system is out-of-tune because of the intrusion of an Xterm color (bright blue BG, then moved to FG with `|*`). +Here the `|h` tag no longer affects the FG color. Even though it was changed via the `|!` tag, the +ANSI system is out-of-tune because of the intrusion of an Xterm color (bright blue BG, then moved to +FG with `|*`). -All unexpected ANSI behaviours are the result of mixing Xterm colors (either on purpose or either via bright BG colors). The `|n` tag will restore things in place and ANSI tags will respond properly again. So, at the end is just an issue of being mindful when using Xterm colors or bright BGs, and avoid wild mixing them with ANSI tags without normalizing (`|n`) things again. +All unexpected ANSI behaviours are the result of mixing Xterm colors (either on purpose or either +via bright BG colors). The `|n` tag will restore things in place and ANSI tags will respond properly +again. So, at the end is just an issue of being mindful when using Xterm colors or bright BGs, and +avoid wild mixing them with ANSI tags without normalizing (`|n`) things again. Try this: @@ -112,21 +169,30 @@ And then: say |[B Dark Blue BG |* Negative |!R Red BG?? -In this second example the `|!` changes the BG color instead of the FG! In fact, the odd behavior is the one from the former example, non the latter. When you invert FG and BG with `|*` you actually inverting their references. This is why the last example (which has a normal/dark BG!) allows `|!` to change the BG color. In the first example, it's again the presence of an Xterm color (bright blue BG) which changes the default behavior. +In this second example the `|!` changes the BG color instead of the FG! In fact, the odd behavior is +the one from the former example, non the latter. When you invert FG and BG with `|*` you actually +inverting their references. This is why the last example (which has a normal/dark BG!) allows `|!` +to change the BG color. In the first example, it's again the presence of an Xterm color (bright blue +BG) which changes the default behavior. Try this: `say Normal |* Negative |!R Red BG` -This is the normal behavior, and as you can see it allows `|!` to change BG color after the inversion of FG and BG. +This is the normal behavior, and as you can see it allows `|!` to change BG color after the +inversion of FG and BG. -As long as you have an understanding of how ANSI works, it should be easy to handle color tags avoiding the pitfalls of Xterm-ANSI promisquity. +As long as you have an understanding of how ANSI works, it should be easy to handle color tags +avoiding the pitfalls of Xterm-ANSI promisquity. One last example: `say Normal |* Negative |* still Negative` -Shows that `|*` only works once in a row and will not (and should not!) revert back if used again. Nor it will have any effect until the `|n` tag is called to "reset" ANSI back to normal. This is how it is meant to work. +Shows that `|*` only works once in a row and will not (and should not!) revert back if used again. +Nor it will have any effect until the `|n` tag is called to "reset" ANSI back to normal. This is how +it is meant to work. -ANSI operates according to a simple states-based mechanism, and it's important to understand the positive effect of resetting with the `|n` tag, and not try to +ANSI operates according to a simple states-based mechanism, and it's important to understand the +positive effect of resetting with the `|n` tag, and not try to push it over the limit, so to speak. diff --git a/docs/source/Unit-Testing.md b/docs/source/Unit-Testing.md index a5e4d5d6b3..edf43efda8 100644 --- a/docs/source/Unit-Testing.md +++ b/docs/source/Unit-Testing.md @@ -1,11 +1,19 @@ # Unit Testing -*Unit testing* means testing components of a program in isolation from each other to make sure every part works on its own before using it with others. Extensive testing helps avoid new updates causing unexpected side effects as well as alleviates general code rot (a more comprehensive wikipedia article on unit testing can be found [here](http://en.wikipedia.org/wiki/Unit_test)). +*Unit testing* means testing components of a program in isolation from each other to make sure every +part works on its own before using it with others. Extensive testing helps avoid new updates causing +unexpected side effects as well as alleviates general code rot (a more comprehensive wikipedia +article on unit testing can be found [here](http://en.wikipedia.org/wiki/Unit_test)). -A typical unit test set calls some function or method with a given input, looks at the result and makes sure that this result looks as expected. Rather than having lots of stand-alone test programs, Evennia makes use of a central *test runner*. This is a program that gathers all available tests all over the Evennia source code (called *test suites*) and runs them all in one go. Errors and tracebacks are reported. +A typical unit test set calls some function or method with a given input, looks at the result and +makes sure that this result looks as expected. Rather than having lots of stand-alone test programs, +Evennia makes use of a central *test runner*. This is a program that gathers all available tests all +over the Evennia source code (called *test suites*) and runs them all in one go. Errors and +tracebacks are reported. -By default Evennia only tests itself. But you can also add your own tests to your game code and have Evennia run those for you. +By default Evennia only tests itself. But you can also add your own tests to your game code and have +Evennia run those for you. ## Running the Evennia test suite @@ -13,37 +21,57 @@ To run the full Evennia test suite, go to your game folder and issue the command evennia test evennia -This will run all the evennia tests using the default settings. You could also run only a subset of all tests by specifying a subpackage of the library: +This will run all the evennia tests using the default settings. You could also run only a subset of +all tests by specifying a subpackage of the library: evennia test evennia.commands.default -A temporary database will be instantiated to manage the tests. If everything works out you will see how many tests were run and how long it took. If something went wrong you will get error messages. If you contribute to Evennia, this is a useful sanity check to see you haven't introduced an unexpected bug. +A temporary database will be instantiated to manage the tests. If everything works out you will see +how many tests were run and how long it took. If something went wrong you will get error messages. +If you contribute to Evennia, this is a useful sanity check to see you haven't introduced an +unexpected bug. ## Running tests with custom settings file -If you have implemented your own tests for your game (see below) you can run them from your game dir with +If you have implemented your own tests for your game (see below) you can run them from your game dir +with evennia test . -The period (`.`) means to run all tests found in the current directory and all subdirectories. You could also specify, say, `typeclasses` or `world` if you wanted to just run tests in those subdirs. +The period (`.`) means to run all tests found in the current directory and all subdirectories. You +could also specify, say, `typeclasses` or `world` if you wanted to just run tests in those subdirs. -Those tests will all be run using the default settings. To run the tests with your own settings file you must use the `--settings` option: +Those tests will all be run using the default settings. To run the tests with your own settings file +you must use the `--settings` option: evennia test --settings settings.py . -The `--settings` option of Evennia takes a file name in the `mygame/server/conf` folder. It is normally used to swap settings files for testing and development. In combination with `test`, it forces Evennia to use this settings file over the default one. +The `--settings` option of Evennia takes a file name in the `mygame/server/conf` folder. It is +normally used to swap settings files for testing and development. In combination with `test`, it +forces Evennia to use this settings file over the default one. ## Writing new tests -Evennia's test suite makes use of Django unit test system, which in turn relies on Python's *unittest* module. +Evennia's test suite makes use of Django unit test system, which in turn relies on Python's +*unittest* module. -> If you want to help out writing unittests for Evennia, take a look at Evennia's [coveralls.io page](https://coveralls.io/github/evennia/evennia). There you see which modules have any form of test coverage and which does not. +> If you want to help out writing unittests for Evennia, take a look at Evennia's [coveralls.io +page](https://coveralls.io/github/evennia/evennia). There you see which modules have any form of +test coverage and which does not. -To make the test runner find the tests, they must be put in a module named `test*.py` (so `test.py`, `tests.py` etc). Such a test module will be found wherever it is in the package. It can be a good idea to look at some of Evennia's `tests.py` modules to see how they look. +To make the test runner find the tests, they must be put in a module named `test*.py` (so `test.py`, +`tests.py` etc). Such a test module will be found wherever it is in the package. It can be a good +idea to look at some of Evennia's `tests.py` modules to see how they look. -Inside a testing file, a `unittest.TestCase` class is used to test a single aspect or component in various ways. Each test case contains one or more *test methods* - these define the actual tests to run. You can name the test methods anything you want as long as the name starts with "`test_`". Your `TestCase` class can also have a method `setUp()`. This is run before each test, setting up and storing whatever preparations the test methods need. Conversely, a `tearDown()` method can optionally do cleanup after each test. +Inside a testing file, a `unittest.TestCase` class is used to test a single aspect or component in +various ways. Each test case contains one or more *test methods* - these define the actual tests to +run. You can name the test methods anything you want as long as the name starts with "`test_`". +Your `TestCase` class can also have a method `setUp(self):`. This is run before each test, setting +up and storing whatever preparations the test methods need. Conversely, a `tearDown(self):` method +can optionally do cleanup after each test. -To test the results, you use special methods of the `TestCase` class. Many of those start with "`assert`", such as `assertEqual` or `assertTrue`. +To test the results, you use special methods of the `TestCase` class. Many of those start with +"`assert`", such as `assertEqual` or `assertTrue`. Example of a `TestCase` class: @@ -57,24 +85,31 @@ Example of a `TestCase` class: "This tests a function myfunc." def test_return_value(self): - "test method. Makes sure return value is as expected." + "test method. Makes sure return value is as expected." expected_return = "This is me being nice." actual_return = myfunc() - # test + # test self.assertEqual(expected_return, actual_return) def test_alternative_call(self): "test method. Calls with a keyword argument." expected_return = "This is me being baaaad." actual_return = myfunc(bad=True) # test - self.assertEqual(expected_return, actual_return) + self.assertEqual(expected_return, actual_return) ``` -You might also want to read the [documentation for the unittest module](http://docs.python.org/library/unittest.html). +You might also want to read the [documentation for the unittest +module](http://docs.python.org/library/unittest.html). ### Using the EvenniaTest class -Evennia offers a custom TestCase, the `evennia.utils.test_resources.EvenniaTest` class. This class initiates a range of useful properties on themselves for testing Evennia systems. Examples are `.account` and `.session` representing a mock connected Account and its Session and `.char1` and `char2` representing Characters complete with a location in the test database. These are all useful when testing Evennia system requiring any of the default Evennia typeclasses as inputs. See the full definition of the `EvenniaTest` class in [evennia/utils/test_resources.py](https://github.com/evennia/evennia/blob/master/evennia/utils/test_resources.py). +Evennia offers a custom TestCase, the `evennia.utils.test_resources.EvenniaTest` class. This class +initiates a range of useful properties on themselves for testing Evennia systems. Examples are +`.account` and `.session` representing a mock connected Account and its Session and `.char1` and +`.char2` representing Characters complete with a location in the test database. These are all useful +when testing Evennia system requiring any of the default Evennia typeclasses as inputs. See the full +definition of the `EvenniaTest` class in [evennia/utils/test_resources.py](https://github.com/evenni +a/evennia/blob/master/evennia/utils/test_resources.py). ```python # in a test module @@ -91,9 +126,15 @@ class TestObject(EvenniaTest): ### Testing in-game Commands -In-game Commands are a special case. Tests for the default commands are put in `evennia/commands/default/tests.py`. This uses a custom `CommandTest` class that inherits from `evennia.utils.test_resources.EvenniaTest` described above. `CommandTest` supplies extra convenience functions for executing commands and check that their return values (calls of `msg()` returns expected values. It uses Characters and Sessions generated on the `EvenniaTest` class to call each class). +In-game Commands are a special case. Tests for the default commands are put in +`evennia/commands/default/tests.py`. This uses a custom `CommandTest` class that inherits from +`evennia.utils.test_resources.EvenniaTest` described above. `CommandTest` supplies extra convenience +functions for executing commands and check that their return values (calls of `msg()` returns +expected values. It uses Characters and Sessions generated on the `EvenniaTest` class to call each +class). -Each command tested should have its own `TestCase` class. Inherit this class from the `CommandTest` class in the same module to get access to the command-specific utilities mentioned. +Each command tested should have its own `TestCase` class. Inherit this class from the `CommandTest` +class in the same module to get access to the command-specific utilities mentioned. ```python from evennia.commands.default.tests import CommandTest @@ -104,18 +145,28 @@ Each command tested should have its own `TestCase` class. Inherit this class fro self.call(general.CmdLook(), "Char2", "Char2(#7)") "tests the look command by simple call, with target as room" def test_mycmd_room(self): - self.call(general.CmdLook(), "Room", + self.call(general.CmdLook(), "Room", "Room(#1)\nroom_desc\nExits: out(#3)\n" "You see: Obj(#4), Obj2(#5), Char2(#7)") ``` ### Unit testing contribs with custom models -A special case is if you were to create a contribution to go to the `evennia/contrib` folder that uses its [own database models](./New-Models). The problem with this is that Evennia (and Django) will only recognize models in `settings.INSTALLED_APPS`. If a user wants to use your contrib, they will be required to add your models to their settings file. But since contribs are optional you cannot add the model to Evennia's central `settings_default.py` file - this would always create your optional models regardless of if the user wants them. But at the same time a contribution is a part of the Evennia distribution and its unit tests should be run with all other Evennia tests using `evennia test evennia`. +A special case is if you were to create a contribution to go to the `evennia/contrib` folder that +uses its [own database models](./New-Models). The problem with this is that Evennia (and Django) will +only recognize models in `settings.INSTALLED_APPS`. If a user wants to use your contrib, they will +be required to add your models to their settings file. But since contribs are optional you cannot +add the model to Evennia's central `settings_default.py` file - this would always create your +optional models regardless of if the user wants them. But at the same time a contribution is a part +of the Evennia distribution and its unit tests should be run with all other Evennia tests using +`evennia test evennia`. -The way to do this is to only temporarily add your models to the `INSTALLED_APPS` directory when the test runs. here is an example of how to do it. +The way to do this is to only temporarily add your models to the `INSTALLED_APPS` directory when the +test runs. here is an example of how to do it. -> Note that this solution, derived from this [stackexchange answer](http://stackoverflow.com/questions/502916/django-how-to-create-a-model-dynamically-just-for-testing#503435) is currently untested! Please report your findings. +> Note that this solution, derived from this [stackexchange +answer](http://stackoverflow.com/questions/502916/django-how-to-create-a-model-dynamically-just-for- +testing#503435) is currently untested! Please report your findings. ```python # a file contrib/mycontrib/tests.py @@ -166,11 +217,16 @@ class TestMyModel(EvenniaTest): ### A note on adding new tests -Having an extensive tests suite is very important for avoiding code degradation as Evennia is developed. Only a small fraction of the Evennia codebase is covered by test suites at this point. Writing new tests is not hard, it's more a matter of finding the time to do so. So adding new tests is really an area where everyone can contribute, also with only limited Python skills. +Having an extensive tests suite is very important for avoiding code degradation as Evennia is +developed. Only a small fraction of the Evennia codebase is covered by test suites at this point. +Writing new tests is not hard, it's more a matter of finding the time to do so. So adding new tests +is really an area where everyone can contribute, also with only limited Python skills. ### A note on making the test runner faster -If you have custom models with a large number of migrations, creating the test database can take a very long time. If you don't require migrations to run for your tests, you can disable them with the django-test-without-migrations package. To install it, simply: +If you have custom models with a large number of migrations, creating the test database can take a +very long time. If you don't require migrations to run for your tests, you can disable them with the +django-test-without-migrations package. To install it, simply: ``` $ pip install django-test-without-migrations @@ -193,26 +249,42 @@ evennia test --settings settings.py --nomigrations . ## Testing for Game development (mini-tutorial) -Unit testing can be of paramount importance to game developers. When starting with a new game, it is recommended to look into unit testing as soon as possible; an already huge game is much harder to write tests for. The benefits of testing a game aren't different from the ones regarding library testing. For example it is easy to introduce bugs that affect previously working code. Testing is there to ensure your project behaves the way it should and continue to do so. +Unit testing can be of paramount importance to game developers. When starting with a new game, it is +recommended to look into unit testing as soon as possible; an already huge game is much harder to +write tests for. The benefits of testing a game aren't different from the ones regarding library +testing. For example it is easy to introduce bugs that affect previously working code. Testing is +there to ensure your project behaves the way it should and continue to do so. -If you have never used unit testing (with Python or another language), you might want to check the [official Python documentation about unit testing](https://docs.python.org/2/library/unittest.html), particularly the first section dedicated to a basic example. +If you have never used unit testing (with Python or another language), you might want to check the +[official Python documentation about unit testing](https://docs.python.org/2/library/unittest.html), +particularly the first section dedicated to a basic example. ### Basic testing using Evennia -Evennia's test runner can be used to launch tests in your game directory (let's call it 'mygame'). Evennia's test runner does a few useful things beyond the normal Python unittest module: +Evennia's test runner can be used to launch tests in your game directory (let's call it 'mygame'). +Evennia's test runner does a few useful things beyond the normal Python unittest module: -* It creates and sets up an empty database, with some useful objects (accounts, characters and rooms, among others). -* It provides simple ways to test commands, which can be somewhat tricky at times, if not tested properly. +* It creates and sets up an empty database, with some useful objects (accounts, characters and +rooms, among others). +* It provides simple ways to test commands, which can be somewhat tricky at times, if not tested +properly. -Therefore, you should use the command-line to execute the test runner, while specifying your own game directories (not the one containing evennia). Go to your game directory (referred as 'mygame' in this section) and execute the test runner: +Therefore, you should use the command-line to execute the test runner, while specifying your own +game directories (not the one containing evennia). Go to your game directory (referred as 'mygame' +in this section) and execute the test runner: - evennia --settings settings.py test commands + evennia test --settings settings.py commands -This command will execute Evennia's test runner using your own settings file. It will set up a dummy database of your choice and look into the 'commands' package defined in your game directory (`mygame/commands` in this example) to find tests. The test module's name should begin with 'test' and contain one or more `TestCase`. A full example can be found below. +This command will execute Evennia's test runner using your own settings file. It will set up a dummy +database of your choice and look into the 'commands' package defined in your game directory +(`mygame/commands` in this example) to find tests. The test module's name should begin with 'test' +and contain one or more `TestCase`. A full example can be found below. ### A simple example -In your game directory, go to `commands` and create a new file `tests.py` inside (it could be named anything starting with `test`). We will start by making a test that has nothing to do with Commands, just to show how unit testing works: +In your game directory, go to `commands` and create a new file `tests.py` inside (it could be named +anything starting with `test`). We will start by making a test that has nothing to do with Commands, +just to show how unit testing works: ```python # mygame/commands/tests.py @@ -228,11 +300,12 @@ In your game directory, go to `commands` and create a new file `tests.py` inside self.assertEqual('foo'.upper(), 'FOO') ``` -This example, inspired from the Python documentation, is used to test the 'upper()' method of the 'str' class. Not very useful, but it should give you a basic idea of how tests are used. +This example, inspired from the Python documentation, is used to test the 'upper()' method of the +'str' class. Not very useful, but it should give you a basic idea of how tests are used. Let's execute that test to see if it works. - > evennia --settings settings.py test commands + > evennia test --settings settings.py commands TESTING: Using specified settings file 'server.conf.settings'. @@ -248,15 +321,27 @@ Let's execute that test to see if it works. OK Destroying test database for alias 'default'... -We specified the `commands` package to the evennia test command since that's where we put our test file. In this case we could just as well just said `.` to search all of `mygame` for testing files. If we have a lot of tests it may be useful to test only a single set at a time though. We get an information text telling us we are using our custom settings file (instead of Evennia's default file) and then the test runs. The test passes! Change the "FOO" string to something else in the test to see how it looks when it fails. +We specified the `commands` package to the evennia test command since that's where we put our test +file. In this case we could just as well just said `.` to search all of `mygame` for testing files. +If we have a lot of tests it may be useful to test only a single set at a time though. We get an +information text telling us we are using our custom settings file (instead of Evennia's default +file) and then the test runs. The test passes! Change the "FOO" string to something else in the test +to see how it looks when it fails. ### Testing commands -This section will test the proper execution of the 'abilities' command, as described in the [First Steps Coding](./First-Steps-Coding) page. Follow this tutorial to create the 'abilities' command, we will need it to test it. +This section will test the proper execution of the 'abilities' command, as described in the [First +Steps Coding](First-Steps-Coding) page. Follow this tutorial to create the 'abilities' command, we +will need it to test it. -Testing commands in Evennia is a bit more complex than the simple testing example we have seen. Luckily, Evennia supplies a special test class to do just that ... we just need to inherit from it and use it properly. This class is called 'CommandTest' and is defined in the 'evennia.commands.default.tests' package. To create a test for our 'abilities' command, we just need to create a class that inherits from 'CommandTest' and add methods. +Testing commands in Evennia is a bit more complex than the simple testing example we have seen. +Luckily, Evennia supplies a special test class to do just that ... we just need to inherit from it +and use it properly. This class is called 'CommandTest' and is defined in the +'evennia.commands.default.tests' package. To create a test for our 'abilities' command, we just +need to create a class that inherits from 'CommandTest' and add methods. -We could create a new test file for this but for now we just append to the `tests.py` file we already have in `commands` from before. +We could create a new test file for this but for now we just append to the `tests.py` file we +already have in `commands` from before. ```python # bottom of mygame/commands/tests.py @@ -274,15 +359,32 @@ We could create a new test file for this but for now we just append to the `test self.call(CmdAbilities(), "", "STR: 5, AGI: 4, MAG: 2") ``` -* Line 1-4: we do some importing. 'CommandTest' is going to be our base class for our test, so we need it. We also import our command ('CmdAbilities' in this case). Finally we import the 'Character' typeclass. We need it, since 'CommandTest' doesn't use 'Character', but 'DefaultCharacter', which means the character calling the command won't have the abilities we have written in the 'Character' typeclass. -* Line 6-8: that's the body of our test. Here, a single command is tested in an entire class. Default commands are usually grouped by category in a single class. There is no rule, as long as you know where you put your tests. Note that we set the 'character_typeclass' class attribute to Character. As explained above, if you didn't do that, the system would create a 'DefaultCharacter' object, not a 'Character'. You can try to remove line 4 and 8 to see what happens when running the test. -* Line 10-11: our unique testing method. Note its name: it should begin by 'test_'. Apart from that, the method is quite simple: it's an instance method (so it takes the 'self' argument) but no other arguments are needed. Line 11 uses the 'call' method, which is defined in 'CommandTest'. It's a useful method that compares a command against an expected result. It would be like comparing two strings with 'assertEqual', but the 'call' method does more things, including testing the command in a realistic way (calling its hooks in the right order, so you don't have to worry about that). +* Line 1-4: we do some importing. 'CommandTest' is going to be our base class for our test, so we +need it. We also import our command ('CmdAbilities' in this case). Finally we import the +'Character' typeclass. We need it, since 'CommandTest' doesn't use 'Character', but +'DefaultCharacter', which means the character calling the command won't have the abilities we have +written in the 'Character' typeclass. +* Line 6-8: that's the body of our test. Here, a single command is tested in an entire class. +Default commands are usually grouped by category in a single class. There is no rule, as long as +you know where you put your tests. Note that we set the 'character_typeclass' class attribute to +Character. As explained above, if you didn't do that, the system would create a 'DefaultCharacter' +object, not a 'Character'. You can try to remove line 4 and 8 to see what happens when running the +test. +* Line 10-11: our unique testing method. Note its name: it should begin by 'test_'. Apart from +that, the method is quite simple: it's an instance method (so it takes the 'self' argument) but no +other arguments are needed. Line 11 uses the 'call' method, which is defined in 'CommandTest'. +It's a useful method that compares a command against an expected result. It would be like comparing +two strings with 'assertEqual', but the 'call' method does more things, including testing the +command in a realistic way (calling its hooks in the right order, so you don't have to worry about +that). -Line 11 can be understood as: test the 'abilities' command (first parameter), with no argument (second parameter), and check that the character using it receives his/her abilities (third parameter). +Line 11 can be understood as: test the 'abilities' command (first parameter), with no argument +(second parameter), and check that the character using it receives his/her abilities (third +parameter). Let's run our new test: - > evennia --settings settings.py test commands + > evennia test --settings settings.py commands [...] Creating test database for alias 'default'... .. @@ -292,5 +394,47 @@ Let's run our new test: OK Destroying test database for alias 'default'... -Two tests were executed, since we have kept 'TestString' from last time. In case of failure, you will get much more information to help you fix the bug. +Two tests were executed, since we have kept 'TestString' from last time. In case of failure, you +will get much more information to help you fix the bug. +### Testing Dynamic Output + +Having read the unit test tutorial on [Testing commands](./Unit-Testing#testing-commands) we can see +the code expects static unchanging numbers. While very good for learning it is unlikely a project +will have nothing but static output to test. Here we are going to learn how to test against dynamic +output.
+ +This tutorial assumes you have a basic understanding of what regular expressions are. If you do not +I recommend reading the `Introduction` and `Simple Pattern` sections at [Python regular expressions +tutorial](https://docs.python.org/3/howto/regex.html). If you do plan on making a complete Evennia +project learning regular expressions will save a great deal of time.
+ +Append the code below to your `tests.py` file.
+ +```python + # bottom of mygame/commands/tests.py + + class TestDynamicAbilities(CommandTest): + + character_typeclass = Character + + def test_simple(self): + cmd_abil_result = self.call(CmdAbilities(), "") + self.assertRegex(cmd_abil_result, "STR: \d+, AGI: \d+, MAG: \d+") +``` + +Noticed that we removed the test string from `self.call`. That method always returns the string it +found from the commands output. If we remove the string to test against, all `self.call` will do is +return the screen output from the command object passed to it.
+ +We are instead using the next line to test our command's output. +[assertRegex](https://docs.python.org/3/library/unittest.html#unittest.TestCase.assertRegex) is a +method of `unittest.TestCase` this is inherited to `TestDynamicAbilities` from `CommandTest` who +inherited it from `EvenniaTest`.
+ +What we are doing is testing the result of the `CmdAbilities` method or command against a regular +expression pattern. In this case, `"STR: \d+, AGI: \d+, MAG: \d+"`. `\d` in regular expressions or +regex are digits (numbers), the `+` is to state we want 1 or more of that pattern. Together `\d+` is +telling [assertRegex](https://docs.python.org/3/library/unittest.html#unittest.TestCase.assertRegex) +that in that position of the string we expect 1 or more digits (numbers) to appear in the +string.
diff --git a/docs/source/Updating-Your-Game.md b/docs/source/Updating-Your-Game.md index 1cd548b27d..7e1c0eedab 100644 --- a/docs/source/Updating-Your-Game.md +++ b/docs/source/Updating-Your-Game.md @@ -1,71 +1,103 @@ # Updating Your Game -Fortunately, it's extremely easy to keep your Evennia server up-to-date. If you haven't already, see the [Getting Started guide](./Getting-Started) and get everything running. +Fortunately, it's extremely easy to keep your Evennia server up-to-date. If you haven't already, see +the [Getting Started guide](./Getting-Started) and get everything running. ### Updating with the latest Evennia code changes -Very commonly we make changes to the Evennia code to improve things. There are many ways to get told when to update: You can subscribe to the RSS feed or manually check up on the feeds from http://www.evennia.com. You can also simply fetch the latest regularly. +Very commonly we make changes to the Evennia code to improve things. There are many ways to get told +when to update: You can subscribe to the RSS feed or manually check up on the feeds from +http://www.evennia.com. You can also simply fetch the latest regularly. When you're wanting to apply updates, simply `cd` to your cloned `evennia` root directory and type: git pull -assuming you've got the command line client. If you're using a graphical client, you will probably want to navigate to the `evennia` directory and either right click and find your client's pull function, or use one of the menus (if applicable). +assuming you've got the command line client. If you're using a graphical client, you will probably +want to navigate to the `evennia` directory and either right click and find your client's pull +function, or use one of the menus (if applicable). You can review the latest changes with git log -or the equivalent in the graphical client. You can also see the latest changes online [here](https://github.com/evennia/evennia/blob/master/CHANGELOG.md). +or the equivalent in the graphical client. You can also see the latest changes online +[here](https://github.com/evennia/evennia/blob/master/CHANGELOG.md). -You will always need to do `evennia reload` (or `reload` from -in-game) from your game-dir to have the new code affect your game. If you want to be really sure you should run a full `evennia reboot` so that both Server and Portal can restart (this will disconnect everyone though, so if you know the Portal has had no updates you don't have to do that). +You will always need to do `evennia reload` (or `reload` from -in-game) from your game-dir to have +the new code affect your game. If you want to be really sure you should run a full `evennia reboot` +so that both Server and Portal can restart (this will disconnect everyone though, so if you know the +Portal has had no updates you don't have to do that). ### Upgrading Evennia dependencies -On occasion we update the versions of third-party libraries Evennia depend on (or we may add a new dependency). This will be announced on the mailing list/forum. If you run into errors when starting Evennia, always make sure you have the latest versions of everything. In some cases, like for Django, starting the server may also give warning saying that you are using a working, but too-old version that should not be used in production. +On occasion we update the versions of third-party libraries Evennia depend on (or we may add a new +dependency). This will be announced on the mailing list/forum. If you run into errors when starting +Evennia, always make sure you have the latest versions of everything. In some cases, like for +Django, starting the server may also give warning saying that you are using a working, but too-old +version that should not be used in production. -Upgrading `evennia` will automatically fetch all the latest packages that it now need. First `cd` to your cloned `evennia` folder. Make sure your `virtualenv` is active and use +Upgrading `evennia` will automatically fetch all the latest packages that it now need. First `cd` to +your cloned `evennia` folder. Make sure your `virtualenv` is active and use - pip install --upgrade -e . + pip install --upgrade -e . -Remember the period (`.`) at the end - that applies the upgrade to the current location (your `evennia` dir). +Remember the period (`.`) at the end - that applies the upgrade to the current location (your +`evennia` dir). -> The `-e` means that we are _linking_ the evennia sources rather than copying them into the environment. This means we can most of the time just update the sources (with `git pull`) and see those changes directly applied to our installed `evennia` package. Without installing/upgrading the package with `-e`, we would have to remember to upgrade the package every time we downloaded any new source-code changes. +> The `-e` means that we are _linking_ the evennia sources rather than copying them into the +environment. This means we can most of the time just update the sources (with `git pull`) and see +those changes directly applied to our installed `evennia` package. Without installing/upgrading the +package with `-e`, we would have to remember to upgrade the package every time we downloaded any new +source-code changes. -Follow the upgrade output to make sure it finishes without errors. To check what packages are currently available in your python environment after the upgrade, use +Follow the upgrade output to make sure it finishes without errors. To check what packages are +currently available in your python environment after the upgrade, use - pip list + pip list -This will show you the version of all installed packages. The `evennia` package will also show the location of its source code. +This will show you the version of all installed packages. The `evennia` package will also show the +location of its source code. ## Migrating the Database Schema -Whenever we change the database layout of Evennia upstream (such as when we add new features) you will need to *migrate* your existing database. When this happens it will be clearly noted in the `git log` (it will say something to the effect of "Run migrations"). Database changes will also be announced on the Evennia [mailing list](https://groups.google.com/forum/#!forum/evennia). +Whenever we change the database layout of Evennia upstream (such as when we add new features) you +will need to *migrate* your existing database. When this happens it will be clearly noted in the +`git log` (it will say something to the effect of "Run migrations"). Database changes will also be +announced on the Evennia [mailing list](https://groups.google.com/forum/#!forum/evennia). When the database schema changes, you just go to your game folder and run evennia migrate -> Hint: If the `evennia` command is not found, you most likely need to activate your [virtualenv](./Glossary#virtualenv). +> Hint: If the `evennia` command is not found, you most likely need to activate your +[virtualenv](./Glossary#virtualenv). ## Resetting your database -Should you ever want to start over completely from scratch, there is no need to re-download Evennia or anything like that. You just need to clear your database. Once you are done, you just rebuild it from scratch as described in [step 2](./Getting-Started#step-2-setting-up-your-game) of the [Getting Started guide](./Getting-Started). +Should you ever want to start over completely from scratch, there is no need to re-download Evennia +or anything like that. You just need to clear your database. Once you are done, you just rebuild it +from scratch as described in [step 2](./Getting-Started#step-2-setting-up-your-game) of the [Getting +Started guide](Getting-Started). First stop a running server with evennia stop -If you run the default `SQlite3` database (to change this you need to edit your `settings.py` file), the database is actually just a normal file in `mygame/server/` called `evennia.db3`. *Simply delete that file* - that's it. Now run `evennia migrate` to recreate a new, fresh one. +If you run the default `SQlite3` database (to change this you need to edit your `settings.py` file), +the database is actually just a normal file in `mygame/server/` called `evennia.db3`. *Simply delete +that file* - that's it. Now run `evennia migrate` to recreate a new, fresh one. If you run some other database system you can instead flush the database: evennia flush -This will empty the database. However, it will not reset the internal counters of the database, so you will start with higher dbref values. If this is okay, this is all you need. +This will empty the database. However, it will not reset the internal counters of the database, so +you will start with higher dbref values. If this is okay, this is all you need. -Django also offers an easy way to start the database's own management should we want more direct control: +Django also offers an easy way to start the database's own management should we want more direct +control: evennia dbshell @@ -74,13 +106,28 @@ In e.g. MySQL you can then do something like this (assuming your MySQL database mysql> DROP DATABASE Evennia; mysql> exit -> NOTE: Under Windows OS, in order to access SQLite dbshell you need to [download the SQLite command-line shell program](https://www.sqlite.org/download.html). It's a single executable file (sqlite3.exe) that you should place in the root of either your MUD folder or Evennia's (it's the same, in both cases Django will find it). +> NOTE: Under Windows OS, in order to access SQLite dbshell you need to [download the SQLite +command-line shell program](https://www.sqlite.org/download.html). It's a single executable file +(sqlite3.exe) that you should place in the root of either your MUD folder or Evennia's (it's the +same, in both cases Django will find it). ## More about schema migrations -If and when an Evennia update modifies the database *schema* (that is, the under-the-hood details as to how data is stored in the database), you must update your existing database correspondingly to match the change. If you don't, the updated Evennia will complain that it cannot read the database properly. Whereas schema changes should become more and more rare as Evennia matures, it may still happen from time to time. +If and when an Evennia update modifies the database *schema* (that is, the under-the-hood details as +to how data is stored in the database), you must update your existing database correspondingly to +match the change. If you don't, the updated Evennia will complain that it cannot read the database +properly. Whereas schema changes should become more and more rare as Evennia matures, it may still +happen from time to time. -One way one could handle this is to apply the changes manually to your database using the database's command line. This often means adding/removing new tables or fields as well as possibly convert existing data to match what the new Evennia version expects. It should be quite obvious that this quickly becomes cumbersome and error-prone. If your database doesn't contain anything critical yet it's probably easiest to simply reset it and start over rather than to bother converting. +One way one could handle this is to apply the changes manually to your database using the database's +command line. This often means adding/removing new tables or fields as well as possibly convert +existing data to match what the new Evennia version expects. It should be quite obvious that this +quickly becomes cumbersome and error-prone. If your database doesn't contain anything critical yet +it's probably easiest to simply reset it and start over rather than to bother converting. -Enter *migrations*. Migrations keeps track of changes in the database schema and applies them automatically for you. Basically, whenever the schema changes we distribute small files called "migrations" with the source. Those tell the system exactly how to implement the change so you don't have to do so manually. When a migration has been added we will tell you so on Evennia's mailing lists and in commit messages - -you then just run `evennia migrate` to be up-to-date again. +Enter *migrations*. Migrations keeps track of changes in the database schema and applies them +automatically for you. Basically, whenever the schema changes we distribute small files called +"migrations" with the source. Those tell the system exactly how to implement the change so you don't +have to do so manually. When a migration has been added we will tell you so on Evennia's mailing +lists and in commit messages - +you then just run `evennia migrate` to be up-to-date again. diff --git a/docs/source/Using-MUX-as-a-Standard.md b/docs/source/Using-MUX-as-a-Standard.md index 2bd6dc0bbc..e82ae270e1 100644 --- a/docs/source/Using-MUX-as-a-Standard.md +++ b/docs/source/Using-MUX-as-a-Standard.md @@ -1,15 +1,26 @@ # Using MUX as a Standard -Evennia allows for any command syntax. If you like the way DikuMUDs, LPMuds or MOOs handle things, you could emulate that with Evennia. If you are ambitious you could even design a whole new style, perfectly fitting your own dreams of the ideal game. +Evennia allows for any command syntax. If you like the way DikuMUDs, LPMuds or MOOs handle things, +you could emulate that with Evennia. If you are ambitious you could even design a whole new style, +perfectly fitting your own dreams of the ideal game. -We do offer a default however. The default Evennia setup tends to *resemble* [MUX2](http://www.tinymux.org/), and its cousins [PennMUSH](http://www.pennmush.org), [TinyMUSH](http://tinymush.sourceforge.net/), and [RhostMUSH](http://www.rhostmush.org/). While the reason for this similarity is partly historical, these codebases offer very mature feature sets for administration and building. +We do offer a default however. The default Evennia setup tends to *resemble* +[MUX2](http://www.tinymux.org/), and its cousins [PennMUSH](http://www.pennmush.org), +[TinyMUSH](http://tinymush.sourceforge.net/), and [RhostMUSH](http://www.rhostmush.org/). While the +reason for this similarity is partly historical, these codebases offer very mature feature sets for +administration and building. -Evennia is *not* a MUX system though. It works very differently in many ways. For example, Evennia deliberately lacks an online softcode language (a policy explained on our [softcode policy page](./Soft-Code)). Evennia also does not shy from using its own syntax when deemed appropriate: the MUX syntax has grown organically over a long time and is, frankly, rather arcane in places. All in all the default command syntax should at most be referred to as "MUX-like" or "MUX-inspired". +Evennia is *not* a MUX system though. It works very differently in many ways. For example, Evennia +deliberately lacks an online softcode language (a policy explained on our [softcode policy +page](Soft-Code)). Evennia also does not shy from using its own syntax when deemed appropriate: the +MUX syntax has grown organically over a long time and is, frankly, rather arcane in places. All in +all the default command syntax should at most be referred to as "MUX-like" or "MUX-inspired". ## Documentation policy -All the commands in the default command sets should have their doc-strings formatted on a similar form: +All the commands in the default command sets should have their doc-strings formatted on a similar +form: ```python """ @@ -30,13 +41,15 @@ All the commands in the default command sets should have their doc-strings forma """ ``` -- Two spaces are used for *indentation* in all default commands. -- Square brackets `[ ]` surround *optional, skippable arguments*. -- Angled brackets `< >` surround a _description_ of what to write rather than the exact syntax. -- *Explicit choices are separated by `|`. To avoid this being parsed as a color code, use `||` (this will come out as a single `|`) or put spaces around the character ("` | `") if there's plenty of room. -- The `Switches` and `Examples` blocks are optional based on the Command. +- Two spaces are used for *indentation* in all default commands. +- Square brackets `[ ]` surround *optional, skippable arguments*. +- Angled brackets `< >` surround a _description_ of what to write rather than the exact syntax. +- *Explicit choices are separated by `|`. To avoid this being parsed as a color code, use `||` (this +will come out as a single `|`) or put spaces around the character ("` | `") if there's plenty of +room. +- The `Switches` and `Examples` blocks are optional based on the Command. -Here is the `nick` command as an example: +Here is the `nick` command as an example: ```python """ @@ -61,7 +74,9 @@ Here is the `nick` command as an example: """ ``` -For commands that *require arguments*, the policy is for it to return a `Usage:` string if the command is entered without any arguments. So for such commands, the Command body should contain something to the effect of +For commands that *require arguments*, the policy is for it to return a `Usage:` string if the +command is entered without any arguments. So for such commands, the Command body should contain +something to the effect of ```python if not self.args: diff --git a/docs/source/Using-Travis.md b/docs/source/Using-Travis.md index 448f831df7..8d2e8c5067 100644 --- a/docs/source/Using-Travis.md +++ b/docs/source/Using-Travis.md @@ -1,25 +1,37 @@ # Using Travis -Evennia uses [Travis CI](http://travis-ci.org/) to check that it's building successfully after every commit to its Github repository (you can for example see the `build: passing` badge at the top of Evennia's [Readme file](https://github.com/evennia/evennia)). If your game is open source on Github you may also use Travis for free. See [the Travis docs](http://docs.travis-ci.com/user/getting-started/) for how to get started. +Evennia uses [Travis CI](http://travis-ci.org/) to check that it's building successfully after every +commit to its Github repository (you can for example see the `build: passing` badge at the top of +Evennia's [Readme file](https://github.com/evennia/evennia)). If your game is open source on Github +you may use Travis for free. See [the Travis docs](http://docs.travis-ci.com/user/getting-started/) +for how to get started. -After logging in you will get to point Travis to your repository on github. One further thing you need to set up yourself is a Travis config file named `.travis.yml` (note the initial period `.`). This should be created in the root of your game directory. The idea with this file is that it describes what Travis needs to import and build in order to create an instance of Evennia from scratch and then run validation tests on it. Here is an example: +After logging in you need to point Travis to your repository on github. One further thing you need +to set up yourself is a Travis config file named `.travis.yml` (note the initial period `.`). This +should be created in the _root_ of your game directory. ``` yaml +dist: xenial language: python +cache: pip + python: - - "2.7" + - "3.7" + - "3.8" + install: - - git clone https://github.com/evennia/evennia.git - - cd evennia - - pip install -e . - - cd $TRAVIS_BUILD_DIR + - git clone https://github.com/evennia/evennia.git ../evennia + - pip install -e ../evennia + script: - - evennia migrate - - evennia test evennia - - evennia test + - evennia test --settings settings.py + ``` -This will tell travis how to download Evennia, install it, set up a database and then run the test suite. -You need to add this file to git (`git add .travis.yml`) and then commit your changes before Travis will be able to see it. +Here we tell Travis how to download and install Evennia into a folder a level up from your game dir. +It will then install the server (so the `evennia` command is available) and run the tests only for +your game dir (based on your `settings.py` file in `server/conf/`). -For properly testing your game you of course also need to write unittests. [We have a page](./Unit-Testing) on how we set those up for Evennia, you should be able to refer to that for making tests fitting your game. \ No newline at end of file +Running this will not actually do anything though, because there are no unit tests in your game dir +yet. [We have a page](./Unit-Testing) on how we set those up for Evennia, you should be able to refer +to that for making tests fitting your game. \ No newline at end of file diff --git a/docs/source/Version-Control.md b/docs/source/Version-Control.md index 1bff149831..81b9337822 100644 --- a/docs/source/Version-Control.md +++ b/docs/source/Version-Control.md @@ -1,32 +1,49 @@ # Version Control -Version control software allows you to track the changes you make to your code, as well as being able to easily backtrack these changes, share your development efforts and more. Even if you are not contributing to Evennia itself, and only wish to develop your own MU* using Evennia, having a version control system in place is a good idea (and standard coding practice). For an introduction to the concept, start with the Wikipedia article [here](http://en.wikipedia.org/wiki/Version_control). Evennia uses the version control system [Git](https://git-scm.com/) and this is what will be covered henceforth. Note that this page also deals with commands for Linux operating systems, and the steps below may vary for other systems, however where possible links will be provided for alternative instructions. +Version control software allows you to track the changes you make to your code, as well as being +able to easily backtrack these changes, share your development efforts and more. Even if you are not +contributing to Evennia itself, and only wish to develop your own MU* using Evennia, having a +version control system in place is a good idea (and standard coding practice). For an introduction +to the concept, start with the Wikipedia article +[here](http://en.wikipedia.org/wiki/Version_control). Evennia uses the version control system +[Git](https://git-scm.com/) and this is what will be covered henceforth. Note that this page also +deals with commands for Linux operating systems, and the steps below may vary for other systems, +however where possible links will be provided for alternative instructions. -For more help on using Git, please refer to the [Official GitHub documentation](https://help.github.com/articles/set-up-git#platform-all). +For more help on using Git, please refer to the [Official GitHub +documentation](https://help.github.com/articles/set-up-git#platform-all). ## Setting up Git -If you have gotten Evennia installed, you will have Git already and can skip to **Step 2** below. Otherwise you will need to install Git on your platform. You can find expanded instructions for installation [here](http://git-scm.com/book/en/Getting-Started-Installing-Git). +If you have gotten Evennia installed, you will have Git already and can skip to **Step 2** below. +Otherwise you will need to install Git on your platform. You can find expanded instructions for +installation [here](http://git-scm.com/book/en/Getting-Started-Installing-Git). ### Step 1: Install Git - **Fedora Linux** - yum install git-core + yum install git-core -- **Debian Linux** _(Ubuntu, Linux Mint, etc.)_ +- **Debian Linux** _(Ubuntu, Linux Mint, etc.)_ - apt-get install git + apt-get install git -- **Windows**: It is recommended to use [Git for Windows](http://msysgit.github.io/). -- **Mac**: Mac platforms offer two methods for installation, one via MacPorts, which you can find out about [here](http://git-scm.com/book/en/Getting-Started-Installing-Git#Installing-on-Mac), or you can use the [Git OSX Installer](https://sourceforge.net/projects/git-osx-installer/). +- **Windows**: It is recommended to use [Git for Windows](http://msysgit.github.io/). +- **Mac**: Mac platforms offer two methods for installation, one via MacPorts, which you can find +out about [here](http://git-scm.com/book/en/Getting-Started-Installing-Git#Installing-on-Mac), or +you can use the [Git OSX Installer](https://sourceforge.net/projects/git-osx-installer/). ### Step 2: Define user/e-mail Settings for Git -To avoid a common issue later, you will need to set a couple of settings; first you will need to tell Git your username, followed by your e-mail address, so that when you commit code later you will be properly credited. +To avoid a common issue later, you will need to set a couple of settings; first you will need to +tell Git your username, followed by your e-mail address, so that when you commit code later you will +be properly credited. -> Note that your commit information will be visible to everyone if you ever contribute to Evennia or use an online service like github to host your code. So if you are not comfortable with using your real, full name online, put a nickname here. +> Note that your commit information will be visible to everyone if you ever contribute to Evennia or +use an online service like github to host your code. So if you are not comfortable with using your +real, full name online, put a nickname here. 1. Set the default name for git to use when you commit: @@ -39,53 +56,75 @@ To avoid a common issue later, you will need to set a couple of settings; first ## Putting your game folder under version control -> Note: The game folder's version control is completely separate from Evennia's repository. +> Note: The game folder's version control is completely separate from Evennia's repository. -After you have set up your game you will have created a new folder to host your particular game (let's call this folder `mygame` for now). +After you have set up your game you will have created a new folder to host your particular game +(let's call this folder `mygame` for now). -This folder is *not* under version control at this point. +This folder is *not* under version control at this point. git init mygame -Your mygame folder is now ready for version control! Now add all the content and make a first commit: +Your mygame folder is now ready for version control! Now add all the content and make a first +commit: cd mygame git add * git commit -m "Initial commit" -Read on for help on what these commands do. +Read on for help on what these commands do. ### Tracking files -When working on your code or fix bugs in your local branches you may end up creating new files. If you do you must tell Git to track them by using the add command: +When working on your code or fix bugs in your local branches you may end up creating new files. If +you do you must tell Git to track them by using the add command: ``` git add ``` -You can check the current status of version control with `git status`. This will show if you have any modified, added or otherwise changed files. Some files, like database files, logs and temporary PID files are usually *not* tracked in version control. These should either not show up or have a question mark in front of them. +You can check the current status of version control with `git status`. This will show if you have +any modified, added or otherwise changed files. Some files, like database files, logs and temporary +PID files are usually *not* tracked in version control. These should either not show up or have a +question mark in front of them. ### Controlling tracking -You will notice that some files are not covered by your git version control, notably your settings file (`mygame/server/conf/settings.py`) and your sqlite3 database file `mygame/server/evennia.db3`. This is controlled by the hidden file `mygame/.gitignore`. Evennia creates this file as part of the creation of your game directory. Everything matched in this file will be ignored by GIT. If you want to, for example, include your settings file for collaborators to access, remove that entry in `.gitignore`. +You will notice that some files are not covered by your git version control, notably your settings +file (`mygame/server/conf/settings.py`) and your sqlite3 database file `mygame/server/evennia.db3`. +This is controlled by the hidden file `mygame/.gitignore`. Evennia creates this file as part of the +creation of your game directory. Everything matched in this file will be ignored by GIT. If you want +to, for example, include your settings file for collaborators to access, remove that entry in +`.gitignore`. -> Note: You should *never* put your sqlite3 database file into git by removing its entry in `.gitignore`. GIT is for backing up your code, not your database. That way lies madness and a good chance you'll confuse yourself so that after a few commits and reverts don't know what is in your database or not. If you want to backup your database, do so by simply copying the file on your hard drive to a backup-name. +> Note: You should *never* put your sqlite3 database file into git by removing its entry in +`.gitignore`. GIT is for backing up your code, not your database. That way lies madness and a good +chance you'll confuse yourself so that after a few commits and reverts don't know what is in your +database or not. If you want to backup your database, do so by simply copying the file on your hard +drive to a backup-name. ### Committing your Code -> Committing means storing the current snapshot of your code within git. This creates a "save point" or "history" of your development process. You can later jump back and forth in your history, for example to figure out just when a bug was introduced or see what results the code used to produce compared to now. +> Committing means storing the current snapshot of your code within git. This creates a "save point" +or "history" of your development process. You can later jump back and forth in your history, for +example to figure out just when a bug was introduced or see what results the code used to produce +compared to now. -It's usually a good idea to commit your changes often. Committing is fast and local only - you will never commit anything online at this point. To commit your changes, use +It's usually a good idea to commit your changes often. Committing is fast and local only - you will +never commit anything online at this point. To commit your changes, use ``` -git commit --all -``` +git commit --all +``` -This will save all changes you made since last commit. The command will open a text editor where you can add a message detailing the changes you've made. Make it brief but informative. You can see the history of commits with `git log`. If you don't want to use the editor you can set the message directly by using the `-m` flag: +This will save all changes you made since last commit. The command will open a text editor where you +can add a message detailing the changes you've made. Make it brief but informative. You can see the +history of commits with `git log`. If you don't want to use the editor you can set the message +directly by using the `-m` flag: ``` -git commit --all -m "This fixes a bug in the combat code." +git commit --all -m "This fixes a bug in the combat code." ``` ### Changing your mind @@ -96,83 +135,129 @@ If you have non-committed changes that you realize you want to throw away, you c git checkout ``` -This will revert the file to the state it was in at your last `commit`, throwing away the changes you did to it since. It's a good way to make wild experiments without having to remember just what you changed. If you do ` git checkout .` you will throw away _all_ changes since the last commit. +This will revert the file to the state it was in at your last `commit`, throwing away the changes +you did to it since. It's a good way to make wild experiments without having to remember just what +you changed. If you do ` git checkout .` you will throw away _all_ changes since the last commit. ### Pushing your code online -So far your code is only located on your private machine. A good idea is to back it up online. The easiest way to do this is to push it to your own remote repository on GitHub. +So far your code is only located on your private machine. A good idea is to back it up online. The +easiest way to do this is to push it to your own remote repository on GitHub. -1. Make sure you have your game directory setup under git version control as described above. Make sure to commit any changes. -2. Create a new, empty repository on Github. Github explains how [here](https://help.github.com/articles/create-a-repo/) (do *not* "Initialize the repository with a README" or else you'll create unrelated histories). -3. From your local game dir, do `git remote add origin ` where `` is the URL to your online repo. This tells your game dir that it should be pushing to the remote online dir. +1. Make sure you have your game directory setup under git version control as described above. Make +sure to commit any changes. +2. Create a new, empty repository on Github. Github explains how +[here](https://help.github.com/articles/create-a-repo/) (do *not* "Initialize the repository with a +README" or else you'll create unrelated histories). +3. From your local game dir, do `git remote add origin ` where `` is the URL +to your online repo. This tells your game dir that it should be pushing to the remote online dir. 4. `git remote -v` to verify the online dir. 5. `git push origin master` now pushes your game dir online so you can see it on github.com. -You can commit your work locally (`git commit --all -m "Make a change that ..."`) as many times as you want. When you want to push those changes to your online repo, you do `git push`. You can also `git clone ` from your online repo to somewhere else (like your production server) and henceforth do `git pull` to update that to the latest thing you pushed. +You can commit your work locally (`git commit --all -m "Make a change that ..."`) as many times as +you want. When you want to push those changes to your online repo, you do `git push`. You can also +`git clone ` from your online repo to somewhere else (like your production +server) and henceforth do `git pull` to update that to the latest thing you pushed. -Note that GitHub's repos are, by default publicly visible by all. Creating a publicly visible online clone might not be what you want for all parts of your development process - you may prefer a more private venue when sharing your revolutionary work with your team. If that's the case you can change your repository to "Private" in the github settings. Then your code will only be visible to those you specifically grant access. +Note that GitHub's repos are, by default publicly visible by all. Creating a publicly visible online +clone might not be what you want for all parts of your development process - you may prefer a more +private venue when sharing your revolutionary work with your team. If that's the case you can change +your repository to "Private" in the github settings. Then your code will only be visible to those +you specifically grant access. ## Forking Evennia -This helps you set up an online *fork* of Evennia so you can easily commit fixes and help with upstream development. +This helps you set up an online *fork* of Evennia so you can easily commit fixes and help with +upstream development. ### Step 1: Fork the evennia/master repository -> Before proceeding with the following step, make sure you have registered and created an account on [GitHub.com](https://github.com/). This is necessary in order to create a fork of Evennia's master repository, and to push your commits to your fork either for yourself or for contributing to Evennia. +> Before proceeding with the following step, make sure you have registered and created an account on +[GitHub.com](https://github.com/). This is necessary in order to create a fork of Evennia's master +repository, and to push your commits to your fork either for yourself or for contributing to +Evennia. -A _fork_ is a clone of the master repository that you can make your own commits and changes to. At the top of [this page](https://github.com/evennia/evennia), click the "Fork" button, as it appears below. ![](https://github-images.s3.amazonaws.com/help/bootcamp/Bootcamp-Fork.png) +A _fork_ is a clone of the master repository that you can make your own commits and changes to. At +the top of [this page](https://github.com/evennia/evennia), click the "Fork" button, as it appears +below. ![](https://github-images.s3.amazonaws.com/help/bootcamp/Bootcamp-Fork.png) ### Step 2: Clone your fork -The fork only exists online as of yet. In a terminal, change your directory to the folder you wish to develop in. From this directory run the following command: +The fork only exists online as of yet. In a terminal, change your directory to the folder you wish +to develop in. From this directory run the following command: ``` git clone https://github.com/yourusername/evennia.git ``` -This will download your fork to your computer. It creates a new folder `evennia/` at your current location. +This will download your fork to your computer. It creates a new folder `evennia/` at your current +location. ### Step 3: Configure remotes -A _remote_ is a repository stored on another computer, in this case on GitHub's server. When a repository is cloned, it has a default remote called `origin`. This points to your fork on GitHub, not the original repository it was forked from. To easily keep track of the original repository (that is, Evennia's official repository), you need to add another remote. The standard name for this remote is "upstream". +A _remote_ is a repository stored on another computer, in this case on GitHub's server. When a +repository is cloned, it has a default remote called `origin`. This points to your fork on GitHub, +not the original repository it was forked from. To easily keep track of the original repository +(that is, Evennia's official repository), you need to add another remote. The standard name for this +remote is "upstream". -Below we change the active directory to the newly cloned "evennia" directory and then assign the original Evennia repository to a remote called "upstream": +Below we change the active directory to the newly cloned "evennia" directory and then assign the +original Evennia repository to a remote called "upstream": ``` cd evennia git remote add upstream https://github.com/evennia/evennia.git ``` -If you also want to access Evennia's `develop` branch (the bleeding edge development branch) do the following: +If you also want to access Evennia's `develop` branch (the bleeding edge development branch) do the +following: ``` git fetch upstream develop git checkout develop ``` -You should now have the upstream branch available locally. You can use this instead of `master` below if you are contributing new features rather than bug fixes. +You should now have the upstream branch available locally. You can use this instead of `master` +below if you are contributing new features rather than bug fixes. ## Working with your fork -> A _branch_ is a separate instance of your code. Changes you do to code in a branch does not affect that in other branches (so if you for example add/commit a file to one branch and then switches to another branch, that file will be gone until you switch back to the first branch again). One can switch between branches at will and create as many branches as one needs for a given project. The content of branches can also be merged together or deleted without affecting other branches. This is not only a common way to organize development but also to test features without messing with existing code. +> A _branch_ is a separate instance of your code. Changes you do to code in a branch does not affect +that in other branches (so if you for example add/commit a file to one branch and then switches to +another branch, that file will be gone until you switch back to the first branch again). One can +switch between branches at will and create as many branches as one needs for a given project. The +content of branches can also be merged together or deleted without affecting other branches. This is +not only a common way to organize development but also to test features without messing with +existing code. -The default _branch_ of git is called the "master" branch. As a rule of thumb, you should *never* make modifications directly to your local copy of the master branch. Rather keep the master clean and only update it by pulling our latest changes to it. Any work you do should instead happen in a local, other branches. +The default _branch_ of git is called the "master" branch. As a rule of thumb, you should *never* +make modifications directly to your local copy of the master branch. Rather keep the master clean +and only update it by pulling our latest changes to it. Any work you do should instead happen in a +local, other branches. ### Making a work branch ``` git checkout -b myfixes -``` +``` -This command will checkout and automatically create the new branch `myfixes` on your machine. If you stared out in the master branch, *myfixes* will be a perfect copy of the master branch. You can see which branch you are on with `git branch` and change between different branches with `git checkout `. +This command will checkout and automatically create the new branch `myfixes` on your machine. If you +stared out in the master branch, *myfixes* will be a perfect copy of the master branch. You can see +which branch you are on with `git branch` and change between different branches with `git checkout +`. -Branches are fast and cheap to create and manage. It is common practice to create a new branch for every bug you want to work on or feature you want to create, then create a *pull request* for that branch to be merged upstream (see below). Not only will this organize your work, it will also make sure that *your* master branch version of Evennia is always exactly in sync with the upstream version's master branch. +Branches are fast and cheap to create and manage. It is common practice to create a new branch for +every bug you want to work on or feature you want to create, then create a *pull request* for that +branch to be merged upstream (see below). Not only will this organize your work, it will also make +sure that *your* master branch version of Evennia is always exactly in sync with the upstream +version's master branch. ### Updating with upstream changes -When Evennia's official repository updates, first make sure to commit all your changes to your branch and then checkout the "clean" master branch: +When Evennia's official repository updates, first make sure to commit all your changes to your +branch and then checkout the "clean" master branch: ``` git commit --all @@ -185,26 +270,44 @@ Pull the latest changes from upstream: git pull upstream master ``` -This should sync your local master branch with upstream Evennia's master branch. Now we go back to our own work-branch (let's say it's still called "myfixes") and _merge_ the updated master into our branch. +This should sync your local master branch with upstream Evennia's master branch. Now we go back to +our own work-branch (let's say it's still called "myfixes") and _merge_ the updated master into our +branch. ``` git checkout myfixes git merge master ``` -If everything went well, your `myfixes` branch will now have the latest version of Evennia merged with whatever changes you have done. Use `git log` to see what has changed. You may need to restart the server or run `manage.py migrate` if the database schema changed (this will be seen in the commit log and on the mailing list). See the [Git manuals](http://git-scm.com/documentation) for learning more about useful day-to-day commands, and special situations such as dealing with merge collisions. +If everything went well, your `myfixes` branch will now have the latest version of Evennia merged +with whatever changes you have done. Use `git log` to see what has changed. You may need to restart +the server or run `manage.py migrate` if the database schema changed (this will be seen in the +commit log and on the mailing list). See the [Git manuals](http://git-scm.com/documentation) for +learning more about useful day-to-day commands, and special situations such as dealing with merge +collisions. ## Sharing your Code Publicly -Up to this point your `myfixes` branch only exists on your local computer. No one else can see it. If you want a copy of this branch to also appear in your online fork on GitHub, make sure to have checked out your "myfixes" branch and then run the following: +Up to this point your `myfixes` branch only exists on your local computer. No one else can see it. +If you want a copy of this branch to also appear in your online fork on GitHub, make sure to have +checked out your "myfixes" branch and then run the following: ``` git push -u origin myfixes ``` -This will create a new _remote branch_ named "myfixes" in your online repository (which is refered to as "origin" by default); the `-u` flag makes sure to set this to the default push location. Henceforth you can just use `git push` from your myfixes branch to push your changes online. This is a great way to keep your source backed-up and accessible. Remember though that by default your repository will be public so everyone will be able to browse and download your code (same way as you can with Evennia itself). If you want secrecy you can change your repository to "Private" in the Github settings. Note though that if you do, you might have trouble contributing to Evennia (since we can't see the code you want to share). +This will create a new _remote branch_ named "myfixes" in your online repository (which is refered +to as "origin" by default); the `-u` flag makes sure to set this to the default push location. +Henceforth you can just use `git push` from your myfixes branch to push your changes online. This is +a great way to keep your source backed-up and accessible. Remember though that by default your +repository will be public so everyone will be able to browse and download your code (same way as you +can with Evennia itself). If you want secrecy you can change your repository to "Private" in the +Github settings. Note though that if you do, you might have trouble contributing to Evennia (since +we can't see the code you want to share). -*Note: If you hadn't setup a public key on GitHub or aren't asked for a username/password, you might get an error `403: Forbidden Access` at this stage. In that case, some users have reported that the workaround is to create a file `.netrc` under your home directory and add your credentials there:* +*Note: If you hadn't setup a public key on GitHub or aren't asked for a username/password, you might +get an error `403: Forbidden Access` at this stage. In that case, some users have reported that the +workaround is to create a file `.netrc` under your home directory and add your credentials there:* ```bash machine github.com @@ -214,9 +317,19 @@ password ## Committing fixes to Evennia -_Contributing_ can mean both bug-fixes or adding new features to Evennia. Please note that if your change is not already listed and accepted in the [Issue Tracker](https://github.com/evennia/evennia/issues), it is recommended that you first hit the developer mailing list or IRC chat to see beforehand if your feature is deemed suitable to include as a core feature in the engine. When it comes to bug-fixes, other developers may also have good input on how to go about resolving the issue. +_Contributing_ can mean both bug-fixes or adding new features to Evennia. Please note that if your +change is not already listed and accepted in the [Issue +Tracker](https://github.com/evennia/evennia/issues), it is recommended that you first hit the +developer mailing list or IRC chat to see beforehand if your feature is deemed suitable to include +as a core feature in the engine. When it comes to bug-fixes, other developers may also have good +input on how to go about resolving the issue. -To contribute you need to have [forked Evennia](./Version-Control#forking-evennia) first. As described above you should do your modification in a separate local branch (not in the master branch). This branch is what you then present to us (as a *Pull request*, PR, see below). We can then merge your change into the upstream master and you then do `git pull` to update master usual. Now that the master is updated with your fixes, you can safely delete your local work branch. Below we describe this work flow. +To contribute you need to have [forked Evennia](./Version-Control#forking-evennia) first. As described +above you should do your modification in a separate local branch (not in the master branch). This +branch is what you then present to us (as a *Pull request*, PR, see below). We can then merge your +change into the upstream master and you then do `git pull` to update master usual. Now that the +master is updated with your fixes, you can safely delete your local work branch. Below we describe +this work flow. First update the Evennia master branch to the latest Evennia version: @@ -231,17 +344,32 @@ Next, create a new branch to hold your contribution. Let's call it the "fixing_s git checkout -b fixing_strange_bug ``` -It is wise to make separate branches for every fix or series of fixes you want to contribute. You are now in your new `fixing_strange_bug` branch. You can list all branches with `git branch` and jump between branches with `git checkout `. Code and test things in here, committing as you go: +It is wise to make separate branches for every fix or series of fixes you want to contribute. You +are now in your new `fixing_strange_bug` branch. You can list all branches with `git branch` and +jump between branches with `git checkout `. Code and test things in here, committing as +you go: ``` git commit --all -m "Fix strange bug in look command. Resolves #123." ``` -You can make multiple commits if you want, depending on your work flow and progress. Make sure to always make clear and descriptive commit messages so it's easy to see what you intended. To refer to, say, issue number 123, write `#123`, it will turn to a link on GitHub. If you include the text "Resolves #123", that issue will be auto-closed on GitHub if your commit gets merged into main Evennia. +You can make multiple commits if you want, depending on your work flow and progress. Make sure to +always make clear and descriptive commit messages so it's easy to see what you intended. To refer +to, say, issue number 123, write `#123`, it will turn to a link on GitHub. If you include the text +"Resolves #123", that issue will be auto-closed on GitHub if your commit gets merged into main +Evennia. ->If you refer to in-game commands that start with `@`(such as `@examine`), please put them in backticks \`, for example \`@examine\`. The reason for this is that GitHub uses `@username` to refer to GitHub users, so if you forget the ticks, any user happening to be named `examine` will get a notification .... +>If you refer to in-game commands that start with `@`(such as `@examine`), please put them in +backticks \`, for example \`@examine\`. The reason for this is that GitHub uses `@username` to refer +to GitHub users, so if you forget the ticks, any user happening to be named `examine` will get a +notification .... -If you implement multiple separate features/bug-fixes, split them into different branches if they are very different and should be handled as separate PRs. You can do any number of commits to your branch as you work. Once you are at a stage where you want to show the world what you did you might want to consider making it clean for merging into Evennia's master branch by using [git rebase](https://www.git-scm.com/book/en/v2/Git-Branching-Rebasing) (this is not always necessary, and if it sounds too hard, say so and we'll handle it on our end). +If you implement multiple separate features/bug-fixes, split them into different branches if they +are very different and should be handled as separate PRs. You can do any number of commits to your +branch as you work. Once you are at a stage where you want to show the world what you did you might +want to consider making it clean for merging into Evennia's master branch by using [git +rebase](https://www.git-scm.com/book/en/v2/Git-Branching-Rebasing) (this is not always necessary, +and if it sounds too hard, say so and we'll handle it on our end). Once you are ready, push your work to your online Evennia fork on github, in a new remote branch: @@ -249,40 +377,51 @@ Once you are ready, push your work to your online Evennia fork on github, in a n git push -u origin fixing_strange_bug ``` -The `-u` flag is only needed the first time - this tells GIT to create a remote branch. If you already created the remote branch earlier, just stand in your `fixing_strange_bug` branch and do `git push`. +The `-u` flag is only needed the first time - this tells GIT to create a remote branch. If you +already created the remote branch earlier, just stand in your `fixing_strange_bug` branch and do +`git push`. -Now you should tell the Evennia developers that they should consider merging your brilliant changes into Evennia proper. [Create a pull request](https://github.com/evennia/evennia/pulls) and follow the instructions. Make sure to specifically select your `fixing_strange_bug` branch to be the source of the merge. Evennia developers will then be able to examine your request and merge it if it's deemed suitable. +Now you should tell the Evennia developers that they should consider merging your brilliant changes +into Evennia proper. [Create a pull request](https://github.com/evennia/evennia/pulls) and follow +the instructions. Make sure to specifically select your `fixing_strange_bug` branch to be the source +of the merge. Evennia developers will then be able to examine your request and merge it if it's +deemed suitable. -Once your changes have been merged into Evennia your local `fixing_strange_bug` can be deleted (since your changes are now available in the "clean" Evennia repository). Do +Once your changes have been merged into Evennia your local `fixing_strange_bug` can be deleted +(since your changes are now available in the "clean" Evennia repository). Do ``` git branch -D fixing_strange_bug ``` -to delete your work branch. Update your master branch (`checkout master` and then `git pull`) and you should get your fix back, now as a part of official Evennia! +to delete your work branch. Update your master branch (`checkout master` and then `git pull`) and +you should get your fix back, now as a part of official Evennia! ## GIT tips and tricks -Some of the GIT commands can feel a little long and clunky if you need to do them often. Luckily you can create aliases for those. Here are some useful commands to run: +Some of the GIT commands can feel a little long and clunky if you need to do them often. Luckily you +can create aliases for those. Here are some useful commands to run: ``` -# git st +# git st # - view brief status info git config --global alias.st 'status -s' ``` -Above, you only need to ever enter the `git config ...` command once - you have then added the new alias. Afterwards, just do `git st` to get status info. All the examples below follow the same template. +Above, you only need to ever enter the `git config ...` command once - you have then added the new +alias. Afterwards, just do `git st` to get status info. All the examples below follow the same +template. ``` -# git cl +# git cl # - clone a repository git config --global alias.cl clone ``` ``` -# git cma "commit message" +# git cma "commit message" # - commit all changes without opening editor for message git config --global alias.cma 'commit -a -m' ``` @@ -301,7 +440,7 @@ git config --global alias.fl 'log -u' ``` # git co [branchname] -# - checkout +# - checkout git config --global alias.co checkout ``` @@ -314,7 +453,8 @@ git config --global alias.br branch ``` # git ls # - view log tree -git config --global alias.ls 'log --pretty=format:"%C(green)%h\ %C(yellow)[%ad]%Cred%d\ %Creset%s%Cblue\ [%cn]" --decorate --date=relative --graph' +git config --global alias.ls 'log --pretty=format:"%C(green)%h\ %C(yellow)[%ad]%Cred%d\ +%Creset%s%Cblue\ [%cn]" --decorate --date=relative --graph' ``` ``` @@ -329,5 +469,7 @@ git config --global alias.diff 'diff --word-diff' git config --global alias.grep 'grep -Ii' ``` -To get a further feel for GIT there is also [a good YouTube talk about it](https://www.youtube.com/watch?v=1ffBJ4sVUb4#t=1m58s) - it's a bit long but it will help you understand the underlying ideas behind GIT +To get a further feel for GIT there is also [a good YouTube talk about +it](https://www.youtube.com/watch?v=1ffBJ4sVUb4#t=1m58s) - it's a bit long but it will help you +understand the underlying ideas behind GIT (which in turn makes it a lot more intuitive to use). diff --git a/docs/source/Weather-Tutorial.md b/docs/source/Weather-Tutorial.md index 6997bc2679..8842861206 100644 --- a/docs/source/Weather-Tutorial.md +++ b/docs/source/Weather-Tutorial.md @@ -1,27 +1,36 @@ # Weather Tutorial -This tutorial will have us create a simple weather system for our MUD. The way we want to use this is to have all outdoor rooms echo weather-related messages to the room at regular and semi-random intervals. Things like "Clouds gather above", "It starts to rain" and so on. +This tutorial will have us create a simple weather system for our MUD. The way we want to use this +is to have all outdoor rooms echo weather-related messages to the room at regular and semi-random +intervals. Things like "Clouds gather above", "It starts to rain" and so on. -One could imagine every outdoor room in the game having a script running on themselves that fires regularly. For this particular example it is however more efficient to do it another way, namely by using a "ticker-subscription" model. The principle is simple: Instead of having each Object individually track the time, they instead subscribe to be called by a global ticker who handles time keeping. Not only does this centralize and organize much of the code in one place, it also has less computing overhead. +One could imagine every outdoor room in the game having a script running on themselves that fires +regularly. For this particular example it is however more efficient to do it another way, namely by +using a "ticker-subscription" model. The principle is simple: Instead of having each Object +individually track the time, they instead subscribe to be called by a global ticker who handles time +keeping. Not only does this centralize and organize much of the code in one place, it also has less +computing overhead. -Evennia offers the [TickerHandler](./TickerHandler) specifically for using the subscription model. We will use it for our weather system. +Evennia offers the [TickerHandler](./TickerHandler) specifically for using the subscription model. We +will use it for our weather system. -We will assume you know how to make your own Typeclasses. If not see one of the beginning tutorials. We will create a new WeatherRoom typeclass that is aware of the day-night cycle. +We will assume you know how to make your own Typeclasses. If not see one of the beginning tutorials. +We will create a new WeatherRoom typeclass that is aware of the day-night cycle. ```python import random from evennia import DefaultRoom, TICKER_HANDLER - ECHOES = ["The sky is clear.", + ECHOES = ["The sky is clear.", "Clouds gather overhead.", "It's starting to drizzle.", "A breeze of wind is felt.", - "The wind is picking up"] # etc + "The wind is picking up"] # etc class WeatherRoom(DefaultRoom): - "This room is ticked at regular intervals" + "This room is ticked at regular intervals" def at_object_creation(self): "called only when the object is first created" @@ -33,8 +42,13 @@ We will assume you know how to make your own Typeclasses. If not see one of the self.msg_contents(echo) ``` -In the `at_object_creation` method, we simply added ourselves to the TickerHandler and tell it to call `at_weather_update` every hour (`60*60` seconds). During testing you might want to play with a shorter time duration. +In the `at_object_creation` method, we simply added ourselves to the TickerHandler and tell it to +call `at_weather_update` every hour (`60*60` seconds). During testing you might want to play with a +shorter time duration. -For this to work we also create a custom hook `at_weather_update(*args, **kwargs)`, which is the call sign required by TickerHandler hooks. +For this to work we also create a custom hook `at_weather_update(*args, **kwargs)`, which is the +call sign required by TickerHandler hooks. -Henceforth the room will inform everyone inside it when the weather changes. This particular example is of course very simplistic - the weather echoes are just randomly chosen and don't care what weather came before it. Expanding it to be more realistic is a useful exercise. +Henceforth the room will inform everyone inside it when the weather changes. This particular example +is of course very simplistic - the weather echoes are just randomly chosen and don't care what +weather came before it. Expanding it to be more realistic is a useful exercise. diff --git a/docs/source/Web-Character-Generation.md b/docs/source/Web-Character-Generation.md index 7005a90a49..e570af528c 100644 --- a/docs/source/Web-Character-Generation.md +++ b/docs/source/Web-Character-Generation.md @@ -3,38 +3,58 @@ ## Introduction -This tutorial will create a simple web-based interface for generating a new in-game Character. Accounts will need to have first logged into the website (with their `AccountDB` account). Once finishing character generation the Character will be created immediately and the Accounts can then log into the game and play immediately (the Character will not require staff approval or anything like that). This guide does not go over how to create an AccountDB on the website with the right permissions to transfer to their web-created characters. +This tutorial will create a simple web-based interface for generating a new in-game Character. +Accounts will need to have first logged into the website (with their `AccountDB` account). Once +finishing character generation the Character will be created immediately and the Accounts can then +log into the game and play immediately (the Character will not require staff approval or anything +like that). This guide does not go over how to create an AccountDB on the website with the right +permissions to transfer to their web-created characters. -It is probably most useful to set `MULTISESSION_MODE = 2` or `3` (which gives you a character-selection screen when you log into the game later). Other modes can be used with some adaptation to auto-puppet the new Character. +It is probably most useful to set `MULTISESSION_MODE = 2` or `3` (which gives you a character- +selection screen when you log into the game later). Other modes can be used with some adaptation to +auto-puppet the new Character. -You should have some familiarity with how Django sets up its Model Template View framework. You need to understand what is happening in the basic [Web Character View tutorial](./Web-Character-View-Tutorial). If you don’t understand the listed tutorial or have a grasp of Django basics, please look at the [Django tutorial](https://docs.djangoproject.com/en/1.8/intro/) to get a taste of what Django does, before throwing Evennia into the mix (Evennia shares its API and attributes with the website interface). This guide will outline the format of the models, views, urls, and html templates needed. +You should have some familiarity with how Django sets up its Model Template View framework. You need +to understand what is happening in the basic [Web Character View tutorial](Web-Character-View- +Tutorial). If you don’t understand the listed tutorial or have a grasp of Django basics, please look +at the [Django tutorial](https://docs.djangoproject.com/en/1.8/intro/) to get a taste of what Django +does, before throwing Evennia into the mix (Evennia shares its API and attributes with the website +interface). This guide will outline the format of the models, views, urls, and html templates +needed. ## Pictures -Here are some screenshots of the simple app we will be making. +Here are some screenshots of the simple app we will be making. Index page, with no character application yet done: *** -![Index page, with no character application yet done.](https://lh3.googleusercontent.com/-57KuSWHXQ_M/VWcULN152tI/AAAAAAAAEZg/kINTmVlHf6M/w425-h189-no/webchargen_index2.gif) +![Index page, with no character application yet done.](https://lh3.googleusercontent.com/-57KuSWHXQ_ +M/VWcULN152tI/AAAAAAAAEZg/kINTmVlHf6M/w425-h189-no/webchargen_index2.gif) *** -Having clicked the "create" link you get to create your character (here we will only have name and background, you can add whatever is needed to fit your game): +Having clicked the "create" link you get to create your character (here we will only have name and +background, you can add whatever is needed to fit your game): *** -![Character creation.](https://lh3.googleusercontent.com/-ORiOEM2R_yQ/VWcUKgy84rI/AAAAAAAAEZY/B3CBh3FHii4/w607-h60-no/webchargen_creation.gif) +![Character creation.](https://lh3.googleusercontent.com/-ORiOEM2R_yQ/VWcUKgy84rI/AAAAAAAAEZY/B3CBh3 +FHii4/w607-h60-no/webchargen_creation.gif) *** -Back to the index page. Having entered our character application (we called our character "TestApp") you see it listed: +Back to the index page. Having entered our character application (we called our character "TestApp") +you see it listed: *** -![Having entered an application.](https://lh6.googleusercontent.com/-HlxvkvAimj4/VWcUKjFxEiI/AAAAAAAAEZo/gLppebr05JI/w321-h194-no/webchargen_index1.gif) +![Having entered an application.](https://lh6.googleusercontent.com/-HlxvkvAimj4/VWcUKjFxEiI/AAAAAAA +AEZo/gLppebr05JI/w321-h194-no/webchargen_index1.gif) *** -We can also view an already written character application by clicking on it - this brings us to the *detail* page: +We can also view an already written character application by clicking on it - this brings us to the +*detail* page: *** -![Detail view of character application.](https://lh6.googleusercontent.com/-2m1UhSE7s_k/VWcUKfLRfII/AAAAAAAAEZc/UFmBOqVya4k/w267-h175-no/webchargen_detail.gif) +![Detail view of character application.](https://lh6.googleusercontent.com/-2m1UhSE7s_k/VWcUKfLRfII/ +AAAAAAAAEZc/UFmBOqVya4k/w267-h175-no/webchargen_detail.gif) *** ## Installing an App @@ -43,13 +63,19 @@ Assuming your game is named "mygame", navigate to your `mygame/` directory, and evennia startapp chargen -This will initialize a new Django app we choose to call "chargen". It is directory containing some basic starting things Django needs. You will need to move this directory: for the time being, it is in your `mygame` directory. Better to move it in your `mygame/web` directory, so you have `mygame/web/chargen` in the end. +This will initialize a new Django app we choose to call "chargen". It is directory containing some +basic starting things Django needs. You will need to move this directory: for the time being, it is +in your `mygame` directory. Better to move it in your `mygame/web` directory, so you have +`mygame/web/chargen` in the end. -Next, navigate to `mygame/server/conf/settings.py` and add or edit the following line to make Evennia (and Django) aware of our new app: +Next, navigate to `mygame/server/conf/settings.py` and add or edit the following line to make +Evennia (and Django) aware of our new app: INSTALLED_APPS += ('web.chargen',) -After this, we will get into defining our *models* (the description of the database storage), *views* (the server-side website content generators), *urls* (how the web browser finds the pages) and *templates* (how the web page should be structured). +After this, we will get into defining our *models* (the description of the database storage), +*views* (the server-side website content generators), *urls* (how the web browser finds the pages) +and *templates* (how the web page should be structured). ### Installing - Checkpoint: @@ -60,21 +86,26 @@ After this, we will get into defining our *models* (the description of the datab Models are created in `mygame/web/chargen/models.py`. -A [Django database model](./New-Models) is a Python class that describes the database storage of the data you want to manage. Any data you choose to store is stored in the same database as the game and you have access to all the game's objects here. +A [Django database model](./New-Models) is a Python class that describes the database storage of the +data you want to manage. Any data you choose to store is stored in the same database as the game and +you have access to all the game's objects here. -We need to define what a character application actually is. This will differ from game to game so for this tutorial we will define a simple character sheet with the following database fields: +We need to define what a character application actually is. This will differ from game to game so +for this tutorial we will define a simple character sheet with the following database fields: * `app_id` (AutoField): Primary key for this character application sheet. * `char_name` (CharField): The new character's name. * `date_applied` (DateTimeField): Date that this application was received. * `background` (TextField): Character story background. -* `account_id` (IntegerField): Which account ID does this application belong to? This is an AccountID from the AccountDB object. +* `account_id` (IntegerField): Which account ID does this application belong to? This is an +AccountID from the AccountDB object. * `submitted` (BooleanField): `True`/`False` depending on if the application has been submitted yet. -> Note: In a full-fledged game, you’d likely want them to be able to select races, skills, attributes and so on. +> Note: In a full-fledged game, you’d likely want them to be able to select races, skills, +attributes and so on. -Our `models.py` file should look something like this: +Our `models.py` file should look something like this: ```python # in mygame/web/chargen/models.py @@ -90,25 +121,35 @@ class CharApp(models.Model): submitted = models.BooleanField(default=False) ``` -You should consider how you are going to link your application to your account. For this tutorial, we are using the account_id attribute on our character application model in order to keep track of which characters are owned by which accounts. Since the account id is a primary key in Evennia, it is a good candidate, as you will never have two of the same IDs in Evennia. You can feel free to use anything else, but for the purposes of this guide, we are going to use account ID to join the character applications with the proper account. +You should consider how you are going to link your application to your account. For this tutorial, +we are using the account_id attribute on our character application model in order to keep track of +which characters are owned by which accounts. Since the account id is a primary key in Evennia, it +is a good candidate, as you will never have two of the same IDs in Evennia. You can feel free to use +anything else, but for the purposes of this guide, we are going to use account ID to join the +character applications with the proper account. ### Model - Checkpoint: -* you should have filled out `mygame/web/chargen/models.py` with the model class shown above (eventually adding fields matching what you need for your game). +* you should have filled out `mygame/web/chargen/models.py` with the model class shown above +(eventually adding fields matching what you need for your game). ## Create Views -*Views* are server-side constructs that make dynamic data available to a web page. We are going to add them to `mygame/web/chargen.views.py`. Each view in our example represents the backbone of a specific web page. We will use three views and three pages here: +*Views* are server-side constructs that make dynamic data available to a web page. We are going to +add them to `mygame/web/chargen.views.py`. Each view in our example represents the backbone of a +specific web page. We will use three views and three pages here: -* The index (managing `index.html`). This is what you see when you navigate to `http://yoursite.com/chargen`. -* The detail display sheet (manages `detail.html`). A page that passively displays the stats of a given Character. -* Character creation sheet (manages `create.html`). This is the main form with fields to fill in. +* The index (managing `index.html`). This is what you see when you navigate to +`http://yoursite.com/chargen`. +* The detail display sheet (manages `detail.html`). A page that passively displays the stats of a +given Character. +* Character creation sheet (manages `create.html`). This is the main form with fields to fill in. ### *Index* view Let’s get started with the index first. -We’ll want characters to be able to see their created characters so let’s +We’ll want characters to be able to see their created characters so let’s ```python # file mygame/web/chargen.views.py @@ -127,12 +168,14 @@ def index(request): ### *Detail* view -Our detail page will have pertinent character application information our users can see. Since this is a basic demonstration, our detail page will only show two fields: +Our detail page will have pertinent character application information our users can see. Since this +is a basic demonstration, our detail page will only show two fields: * Character name * Character background -We will use the account ID again just to double-check that whoever tries to check our character page is actually the account who owns the application. +We will use the account ID again just to double-check that whoever tries to check our character page +is actually the account who owns the application. ```python # file mygame/web/chargen.views.py @@ -143,16 +186,19 @@ def detail(request, app_id): background = app.background submitted = app.submitted p_id = request.user.id - context = {'name': name, 'background': background, + context = {'name': name, 'background': background, 'p_id': p_id, 'submitted': submitted} return render(request, 'chargen/detail.html', context) ``` ## *Creating* view -Predictably, our *create* function will be the most complicated of the views, as it needs to accept information from the user, validate the information, and send the information to the server. Once the form content is validated will actually create a playable Character. +Predictably, our *create* function will be the most complicated of the views, as it needs to accept +information from the user, validate the information, and send the information to the server. Once +the form content is validated will actually create a playable Character. -The form itself we will define first. In our simple example we are just looking for the Character's name and background. This form we create in `mygame/web/chargen/forms.py`: +The form itself we will define first. In our simple example we are just looking for the Character's +name and background. This form we create in `mygame/web/chargen/forms.py`: ```python # file mygame/web/chargen/forms.py @@ -164,7 +210,7 @@ class AppForm(forms.Form): background = forms.CharField(label='Background') ``` -Now we make use of this form in our view. +Now we make use of this form in our view. ```python # file mygame/web/chargen/views.py @@ -188,8 +234,8 @@ def creating(request): submitted = True if 'save' in request.POST: submitted = False - app = CharApp(char_name=name, background=background, - date_applied=applied_date, account_id=user.id, + app = CharApp(char_name=name, background=background, + date_applied=applied_date, account_id=user.id, submitted=submitted) app.save() if submitted: @@ -197,9 +243,9 @@ def creating(request): typeclass = settings.BASE_CHARACTER_TYPECLASS home = ObjectDB.objects.get_id(settings.GUEST_HOME) # turn the permissionhandler to a string - perms = str(user.permissions) + perms = str(user.permissions) # create the character - char = create.create_object(typeclass=typeclass, key=name, + char = create.create_object(typeclass=typeclass, key=name, home=home, permissions=perms) user.db._playable_characters.append(char) # add the right locks for the character so the account can @@ -213,7 +259,10 @@ def creating(request): return render(request, 'chargen/create.html', {'form': form}) ``` -> Note also that we basically create the character using the Evennia API, and we grab the proper permissions from the `AccountDB` object and copy them to the character object. We take the user permissions attribute and turn that list of strings into a string object in order for the create_object function to properly process the permissions. +> Note also that we basically create the character using the Evennia API, and we grab the proper +permissions from the `AccountDB` object and copy them to the character object. We take the user +permissions attribute and turn that list of strings into a string object in order for the +create_object function to properly process the permissions. Most importantly, the following attributes must be set on the created character object: @@ -223,7 +272,10 @@ Most importantly, the following attributes must be set on the created character * Character name (key) * The Character's home room location (`#2` by default) -Other attributes are strictly speaking optional, such as the `background` attribute on our character. It may be a good idea to decompose this function and create a separate _create_character function in order to set up your character object the account owns. But with the Evennia API, setting custom attributes is as easy as doing it in the meat of your Evennia game directory. +Other attributes are strictly speaking optional, such as the `background` attribute on our +character. It may be a good idea to decompose this function and create a separate _create_character +function in order to set up your character object the account owns. But with the Evennia API, +setting custom attributes is as easy as doing it in the meat of your Evennia game directory. After all of this, our `views.py` file should look like something like this: @@ -253,7 +305,7 @@ def detail(request, app_id): background = app.background submitted = app.submitted p_id = request.user.id - context = {'name': name, 'background': background, + context = {'name': name, 'background': background, 'p_id': p_id, 'submitted': submitted} return render(request, 'chargen/detail.html', context) @@ -268,8 +320,8 @@ def creating(request): submitted = True if 'save' in request.POST: submitted = False - app = CharApp(char_name=name, background=background, - date_applied=applied_date, account_id=user.id, + app = CharApp(char_name=name, background=background, + date_applied=applied_date, account_id=user.id, submitted=submitted) app.save() if submitted: @@ -277,9 +329,9 @@ def creating(request): typeclass = settings.BASE_CHARACTER_TYPECLASS home = ObjectDB.objects.get_id(settings.GUEST_HOME) # turn the permissionhandler to a string - perms = str(user.permissions) + perms = str(user.permissions) # create the character - char = create.create_object(typeclass=typeclass, key=name, + char = create.create_object(typeclass=typeclass, key=name, home=home, permissions=perms) user.db._playable_characters.append(char) # add the right locks for the character so the account can @@ -296,12 +348,14 @@ def creating(request): ### Create Views - Checkpoint: * you’ve defined a `views.py` that has an index, detail, and creating functions. -* you’ve defined a forms.py with the `AppForm` class needed by the `creating` function of `views.py`. +* you’ve defined a forms.py with the `AppForm` class needed by the `creating` function of +`views.py`. * your `mygame/web/chargen` directory should now have a `views.py` and `forms.py` file ## Create URLs -URL patterns helps redirect requests from the web browser to the right views. These patterns are created in `mygame/web/chargen/urls.py`. +URL patterns helps redirect requests from the web browser to the right views. These patterns are +created in `mygame/web/chargen/urls.py`. ```python # file mygame/web/chargen/urls.py @@ -319,9 +373,13 @@ urlpatterns = [ ] ``` -You could change the format as you desire. To make it more secure, you could remove app_id from the "detail" url, and instead just fetch the account’s applications using a unifying field like account_id to find all the character application objects to display. +You could change the format as you desire. To make it more secure, you could remove app_id from the +"detail" url, and instead just fetch the account’s applications using a unifying field like +account_id to find all the character application objects to display. -We must also update the main `mygame/web/urls.py` file (that is, one level up from our chargen app), so the main website knows where our app's views are located. Find the `patterns` variable, and change it to include: +We must also update the main `mygame/web/urls.py` file (that is, one level up from our chargen app), +so the main website knows where our app's views are located. Find the `patterns` variable, and +change it to include: ```python # in file mygame/web/urls.py @@ -351,15 +409,21 @@ urlpatterns = custom_patterns + urlpatterns ## HTML Templates -So we have our url patterns, views, and models defined. Now we must define our HTML templates that the actual user will see and interact with. For this tutorial we us the basic *prosimii* template that comes with Evennia. +So we have our url patterns, views, and models defined. Now we must define our HTML templates that +the actual user will see and interact with. For this tutorial we us the basic *prosimii* template +that comes with Evennia. -Take note that we use `user.is_authenticated` to make sure that the user cannot create a character without logging in. +Take note that we use `user.is_authenticated` to make sure that the user cannot create a character +without logging in. These files will all go into the `/mygame/web/chargen/templates/chargen/` directory. ### index.html -This HTML template should hold a list of all the applications the account currently has active. For this demonstration, we will only list the applications that the account has submitted. You could easily adjust this to include saved applications, or other types of applications if you have different kinds. +This HTML template should hold a list of all the applications the account currently has active. For +this demonstration, we will only list the applications that the account has submitted. You could +easily adjust this to include saved applications, or other types of applications if you have +different kinds. Please refer back to `views.py` to see where we define the variables these templates make use of. @@ -387,7 +451,10 @@ Please refer back to `views.py` to see where we define the variables these templ ### detail.html -This page should show a detailed character sheet of their application. This will only show their name and character background. You will likely want to extend this to show many more fields for your game. In a full-fledged character generation, you may want to extend the boolean attribute of submitted to allow accounts to save character applications and submit them later. +This page should show a detailed character sheet of their application. This will only show their +name and character background. You will likely want to extend this to show many more fields for your +game. In a full-fledged character generation, you may want to extend the boolean attribute of +submitted to allow accounts to save character applications and submit them later. ```html @@ -412,7 +479,11 @@ This page should show a detailed character sheet of their application. This will ### create.html -Our create HTML template will use the Django form we defined back in views.py/forms.py to drive the majority of the application process. There will be a form input for every field we defined in forms.py, which is handy. We have used POST as our method because we are sending information to the server that will update the database. As an alternative, GET would be much less secure. You can read up on documentation elsewhere on the web for GET vs. POST. +Our create HTML template will use the Django form we defined back in views.py/forms.py to drive the +majority of the application process. There will be a form input for every field we defined in +forms.py, which is handy. We have used POST as our method because we are sending information to the +server that will update the database. As an alternative, GET would be much less secure. You can read +up on documentation elsewhere on the web for GET vs. POST. ```html @@ -432,9 +503,10 @@ Our create HTML template will use the Django form we defined back in views.py/fo {% endblock %} ``` -### Templates - Checkpoint: +### Templates - Checkpoint: -* Create a `index.html`, `detail.html` and `create.html` template in your `mygame/web/chargen/templates/chargen` directory +* Create a `index.html`, `detail.html` and `create.html` template in your +`mygame/web/chargen/templates/chargen` directory ## Activating your new character generation @@ -457,29 +529,49 @@ evennia makemigrations evennia migrate ``` -This will create and update the models. If you see any errors at this stage, read the traceback carefully, it should be relatively easy to figure out where the error is. +This will create and update the models. If you see any errors at this stage, read the traceback +carefully, it should be relatively easy to figure out where the error is. -Login to the website (you need to have previously registered an Player account with the game to do this). Next you navigate to `http://yourwebsite.com/chargen` (if you are running locally this will be something like `http://localhost:4001/chargen` and you will see your new app in action. +Login to the website (you need to have previously registered an Player account with the game to do +this). Next you navigate to `http://yourwebsite.com/chargen` (if you are running locally this will +be something like `http://localhost:4001/chargen` and you will see your new app in action. -This should hopefully give you a good starting point in figuring out how you’d like to approach your own web generation. The main difficulties are in setting the appropriate settings on your newly created character object. Thankfully, the Evennia API makes this easy. +This should hopefully give you a good starting point in figuring out how you’d like to approach your +own web generation. The main difficulties are in setting the appropriate settings on your newly +created character object. Thankfully, the Evennia API makes this easy. ## Adding a no CAPCHA reCAPCHA on your character generation -As sad as it is, if your server is open to the web, bots might come to visit and take advantage of your open form to create hundreds, thousands, millions of characters if you give them the opportunity. This section shows you how to use the [No CAPCHA reCAPCHA](https://www.google.com/recaptcha/intro/invisible.html) designed by Google. Not only is it easy to use, it is user-friendly... for humans. A simple checkbox to check, except if Google has some suspicion, in which case you will have a more difficult test with an image and the usual text inside. It's worth pointing out that, as long as Google doesn't suspect you of being a robot, this is quite useful, not only for common users, but to screen-reader users, to which reading inside of an image is pretty difficult, if not impossible. And to top it all, it will be so easy to add in your website. +As sad as it is, if your server is open to the web, bots might come to visit and take advantage of +your open form to create hundreds, thousands, millions of characters if you give them the +opportunity. This section shows you how to use the [No CAPCHA +reCAPCHA](https://www.google.com/recaptcha/intro/invisible.html) designed by Google. Not only is it +easy to use, it is user-friendly... for humans. A simple checkbox to check, except if Google has +some suspicion, in which case you will have a more difficult test with an image and the usual text +inside. It's worth pointing out that, as long as Google doesn't suspect you of being a robot, this +is quite useful, not only for common users, but to screen-reader users, to which reading inside of +an image is pretty difficult, if not impossible. And to top it all, it will be so easy to add in +your website. ### Step 1: Obtain a SiteKey and secret from Google -The first thing is to ask Google for a way to safely authenticate your website to their service. To do it, we need to create a site key and a secret. Go to [https://www.google.com/recaptcha/admin](https://www.google.com/recaptcha/admin) to create such a site key. It's quite easy when you have a Google account. +The first thing is to ask Google for a way to safely authenticate your website to their service. To +do it, we need to create a site key and a secret. Go to +[https://www.google.com/recaptcha/admin](https://www.google.com/recaptcha/admin) to create such a +site key. It's quite easy when you have a Google account. -When you have created your site key, save it safely. Also copy your secret key as well. You should find both information on the web page. Both would contain a lot of letters and figures. +When you have created your site key, save it safely. Also copy your secret key as well. You should +find both information on the web page. Both would contain a lot of letters and figures. ### Step 2: installing and configuring the dedicated Django app -Since Evennia runs on Django, the easiest way to add our CAPCHA and perform the proper check is to install the dedicated Django app. Quite easy: +Since Evennia runs on Django, the easiest way to add our CAPCHA and perform the proper check is to +install the dedicated Django app. Quite easy: pip install django-nocaptcha-recaptcha -And add it to the installed apps in your settings. In your `mygame/server/conf/settings.py`, you might have something like this: +And add it to the installed apps in your settings. In your `mygame/server/conf/settings.py`, you +might have something like this: ```python # ... @@ -489,7 +581,8 @@ INSTALLED_APPS += ( ) ``` -Don't close the setting file just yet. We have to add in the site key and secret key. You can add them below: +Don't close the setting file just yet. We have to add in the site key and secret key. You can add +them below: ```python # NoReCAPCHA site key @@ -500,7 +593,9 @@ NORECAPTCHA_SECRET_KEY = "PUT YOUR SECRET KEY HERE" ### Step 3: Adding the CAPCHA to our form -Finally we have to add the CAPCHA to our form. It will be pretty easy too. First, open your `web/chargen/forms.py` file. We're going to add a new field, but hopefully, all the hard work has been done for us. Update at your convenience, You might end up with something like this: +Finally we have to add the CAPCHA to our form. It will be pretty easy too. First, open your +`web/chargen/forms.py` file. We're going to add a new field, but hopefully, all the hard work has +been done for us. Update at your convenience, You might end up with something like this: ```python from django import forms @@ -514,13 +609,17 @@ class AppForm(forms.Form): As you see, we added a line of import (line 2) and a field in our form. -And lastly, we need to update our HTML file to add in the Google library. You can open `web/chargen/templates/chargen/create.html`. There's only one line to add: +And lastly, we need to update our HTML file to add in the Google library. You can open +`web/chargen/templates/chargen/create.html`. There's only one line to add: ```html ``` -And you should put it at the bottom of the page. Just before the closing body would be good, but for the time being, the base page doesn't provide a footer block, so we'll put it in the content block. Note that it's not the best place, but it will work. In the end, your `web/chargen/templates/chargen/create.html` file should look like this: +And you should put it at the bottom of the page. Just before the closing body would be good, but +for the time being, the base page doesn't provide a footer block, so we'll put it in the content +block. Note that it's not the best place, but it will work. In the end, your +`web/chargen/templates/chargen/create.html` file should look like this: ```html {% extends "base.html" %} @@ -539,4 +638,6 @@ And you should put it at the bottom of the page. Just before the closing body w {% endblock %} ``` -Reload and open [http://localhost:4001/chargen/create](http://localhost:4001/chargen/create/) and you should see your beautiful CAPCHA just before the "submit" button. Try not to check the checkbox to see what happens. And do the same while checking the checkbox! +Reload and open [http://localhost:4001/chargen/create](http://localhost:4001/chargen/create/) and +you should see your beautiful CAPCHA just before the "submit" button. Try not to check the checkbox +to see what happens. And do the same while checking the checkbox! diff --git a/docs/source/Web-Character-View-Tutorial.md b/docs/source/Web-Character-View-Tutorial.md index 2d2c244021..880093be8a 100644 --- a/docs/source/Web-Character-View-Tutorial.md +++ b/docs/source/Web-Character-View-Tutorial.md @@ -1,52 +1,84 @@ # Web Character View Tutorial -**Before doing this tutorial you will probably want to read the intro in [Basic Web tutorial](./Web-Tutorial).** +**Before doing this tutorial you will probably want to read the intro in [Basic Web tutorial](Web- +Tutorial).** -In this tutorial we will create a web page that displays the stats of a game character. For this, and all other pages we want to make specific to our game, we'll need to create our own Django "app" +In this tutorial we will create a web page that displays the stats of a game character. For this, +and all other pages we want to make specific to our game, we'll need to create our own Django "app" -We'll call our app `character`, since it will be dealing with character information. From your game dir, run +We'll call our app `character`, since it will be dealing with character information. From your game +dir, run evennia startapp character -This will create a directory named `character` in the root of your game dir. It contains all basic files that a Django app needs. To keep `mygame` well ordered, move it to your `mygame/web/` directory instead: +This will create a directory named `character` in the root of your game dir. It contains all basic +files that a Django app needs. To keep `mygame` well ordered, move it to your `mygame/web/` +directory instead: mv character web/ -Note that we will not edit all files in this new directory, many of the generated files are outside the scope of this tutorial. +Note that we will not edit all files in this new directory, many of the generated files are outside +the scope of this tutorial. -In order for Django to find our new web app, we'll need to add it to the `INSTALLED_APPS` setting. Evennia's default installed apps are already set, so in `server/conf/settings.py`, we'll just extend them: +In order for Django to find our new web app, we'll need to add it to the `INSTALLED_APPS` setting. +Evennia's default installed apps are already set, so in `server/conf/settings.py`, we'll just extend +them: ```python INSTALLED_APPS += ('web.character',) ``` -> Note: That end comma is important. It makes sure that Python interprets the addition as a tuple instead of a string. +> Note: That end comma is important. It makes sure that Python interprets the addition as a tuple +instead of a string. -The first thing we need to do is to create a *view* and an *URL pattern* to point to it. A view is a function that generates the web page that a visitor wants to see, while the URL pattern lets Django know what URL should trigger the view. The pattern may also provide some information of its own as we shall see. +The first thing we need to do is to create a *view* and an *URL pattern* to point to it. A view is a +function that generates the web page that a visitor wants to see, while the URL pattern lets Django +know what URL should trigger the view. The pattern may also provide some information of its own as +we shall see. -Here is our `character/urls.py` file (**Note**: you may have to create this file if a blank one wasn't generated for you): +Here is our `character/urls.py` file (**Note**: you may have to create this file if a blank one +wasn't generated for you): ```python # URL patterns for the character app from django.conf.urls import url -from web.character.views import sheet +from web.character.views import sheet urlpatterns = [ url(r'^sheet/(?P\d+)/$', sheet, name="sheet") ] ``` -This file contains all of the URL patterns for the application. The `url` function in the `urlpatterns` list are given three arguments. The first argument is a pattern-string used to identify which URLs are valid. Patterns are specified as *regular expressions*. Regular expressions are used to match strings and are written in a special, very compact, syntax. A detailed description of regular expressions is beyond this tutorial but you can learn more about them [here](https://docs.python.org/2/howto/regex.html). For now, just accept that this regular expression requires that the visitor's URL looks something like this: +This file contains all of the URL patterns for the application. The `url` function in the +`urlpatterns` list are given three arguments. The first argument is a pattern-string used to +identify which URLs are valid. Patterns are specified as *regular expressions*. Regular expressions +are used to match strings and are written in a special, very compact, syntax. A detailed description +of regular expressions is beyond this tutorial but you can learn more about them +[here](https://docs.python.org/2/howto/regex.html). For now, just accept that this regular +expression requires that the visitor's URL looks something like this: ```` sheet/123/ ```` -That is, `sheet/` followed by a number, rather than some other possible URL pattern. We will interpret this number as object ID. Thanks to how the regular expression is formulated, the pattern recognizer stores the number in a variable called `object_id`. This will be passed to the view (see below). We add the imported view function (`sheet`) in the second argument. We also add the `name` keyword to identify the URL pattern itself. You should always name your URL patterns, this makes them easy to refer to in html templates using the `{% url %}` tag (but we won't get more into that in this tutorial). +That is, `sheet/` followed by a number, rather than some other possible URL pattern. We will +interpret this number as object ID. Thanks to how the regular expression is formulated, the pattern +recognizer stores the number in a variable called `object_id`. This will be passed to the view (see +below). We add the imported view function (`sheet`) in the second argument. We also add the `name` +keyword to identify the URL pattern itself. You should always name your URL patterns, this makes +them easy to refer to in html templates using the `{% url %}` tag (but we won't get more into that +in this tutorial). -> Security Note: Normally, users do not have the ability to see object IDs within the game (it's restricted to superusers only). Exposing the game's object IDs to the public like this enables griefers to perform what is known as an [account enumeration attack](http://www.sans.edu/research/security-laboratory/article/attacks-browsing) in the efforts of hijacking your superuser account. Consider this: in every Evennia installation, there are two objects that we can *always* expect to exist and have the same object IDs-- Limbo (#2) and the superuser you create in the beginning (#1). Thus, the griefer can get 50% of the information they need to hijack the admin account (the admin's username) just by navigating to `sheet/1`! +> Security Note: Normally, users do not have the ability to see object IDs within the game (it's +restricted to superusers only). Exposing the game's object IDs to the public like this enables +griefers to perform what is known as an [account enumeration +attack](http://www.sans.edu/research/security-laboratory/article/attacks-browsing) in the efforts of +hijacking your superuser account. Consider this: in every Evennia installation, there are two +objects that we can *always* expect to exist and have the same object IDs-- Limbo (#2) and the +superuser you create in the beginning (#1). Thus, the griefer can get 50% of the information they +need to hijack the admin account (the admin's username) just by navigating to `sheet/1`! Next we create `views.py`, the view file that `urls.py` refers to. @@ -72,11 +104,20 @@ def sheet(request, object_id): return render(request, 'character/sheet.html', {'character': character}) ``` -As explained earlier, the URL pattern parser in `urls.py` parses the URL and passes `object_id` to our view function `sheet`. We do a database search for the object using this number. We also make sure such an object exists and that it is actually a Character. The view function is also handed a `request` object. This gives us information about the request, such as if a logged-in user viewed it - we won't use that information here but it is good to keep in mind. +As explained earlier, the URL pattern parser in `urls.py` parses the URL and passes `object_id` to +our view function `sheet`. We do a database search for the object using this number. We also make +sure such an object exists and that it is actually a Character. The view function is also handed a +`request` object. This gives us information about the request, such as if a logged-in user viewed it +- we won't use that information here but it is good to keep in mind. -On the last line, we call the `render` function. Apart from the `request` object, the `render` function takes a path to an html template and a dictionary with extra data you want to pass into said template. As extra data we pass the Character object we just found. In the template it will be available as the variable "character". +On the last line, we call the `render` function. Apart from the `request` object, the `render` +function takes a path to an html template and a dictionary with extra data you want to pass into +said template. As extra data we pass the Character object we just found. In the template it will be +available as the variable "character". -The html template is created as `templates/character/sheet.html` under your `character` app folder. You may have to manually create both `template` and its subfolder `character`. Here's the template to create: +The html template is created as `templates/character/sheet.html` under your `character` app folder. +You may have to manually create both `template` and its subfolder `character`. Here's the template +to create: ````html {% extends "base.html" %} @@ -127,17 +168,32 @@ The html template is created as `templates/character/sheet.html` under your `cha {% endblock %} ```` -In Django templates, `{% ... %}` denotes special in-template "functions" that Django understands. The `{{ ... }}` blocks work as "slots". They are replaced with whatever value the code inside the block returns. +In Django templates, `{% ... %}` denotes special in-template "functions" that Django understands. +The `{{ ... }}` blocks work as "slots". They are replaced with whatever value the code inside the +block returns. -The first line, `{% extends "base.html" %}`, tells Django that this template extends the base template that Evennia is using. The base template is provided by the theme. Evennia comes with the open-source third-party theme `prosimii`. You can find it and its `base.html` in `evennia/web/templates/prosimii`. Like other templates, these can be overwritten. +The first line, `{% extends "base.html" %}`, tells Django that this template extends the base +template that Evennia is using. The base template is provided by the theme. Evennia comes with the +open-source third-party theme `prosimii`. You can find it and its `base.html` in +`evennia/web/templates/prosimii`. Like other templates, these can be overwritten. -The next line is `{% block content %}`. The `base.html` file has `block`s, which are placeholders that templates can extend. The main block, and the one we use, is named `content`. +The next line is `{% block content %}`. The `base.html` file has `block`s, which are placeholders +that templates can extend. The main block, and the one we use, is named `content`. -We can access the `character` variable anywhere in the template because we passed it in the `render` call at the end of `view.py`. That means we also have access to the Character's `db` attributes, much like you would in normal Python code. You don't have the ability to call functions with arguments in the template-- in fact, if you need to do any complicated logic, you should do it in `view.py` and pass the results as more variables to the template. But you still have a great deal of flexibility in how you display the data. +We can access the `character` variable anywhere in the template because we passed it in the `render` +call at the end of `view.py`. That means we also have access to the Character's `db` attributes, +much like you would in normal Python code. You don't have the ability to call functions with +arguments in the template-- in fact, if you need to do any complicated logic, you should do it in +`view.py` and pass the results as more variables to the template. But you still have a great deal of +flexibility in how you display the data. -We can do a little bit of logic here as well. We use the `{% for %} ... {% endfor %}` and `{% if %} ... {% else %} ... {% endif %}` structures to change how the template renders depending on how many skills the user has, or if the user is approved (assuming your game has an approval system). +We can do a little bit of logic here as well. We use the `{% for %} ... {% endfor %}` and `{% if %} +... {% else %} ... {% endif %}` structures to change how the template renders depending on how many +skills the user has, or if the user is approved (assuming your game has an approval system). -The last file we need to edit is the master URLs file. This is needed in order to smoothly integrate the URLs from your new `character` app with the URLs from Evennia's existing pages. Find the file `web/urls.py` and update its `patterns` list as follows: +The last file we need to edit is the master URLs file. This is needed in order to smoothly integrate +the URLs from your new `character` app with the URLs from Evennia's existing pages. Find the file +`web/urls.py` and update its `patterns` list as follows: ```python # web/urls.py @@ -147,11 +203,15 @@ custom_patterns = [ ] ``` -Now reload the server with `evennia reload` and visit the page in your browser. If you haven't changed your defaults, you should be able to find the sheet for character `#1` at `http://localhost:4001/character/sheet/1/` +Now reload the server with `evennia reload` and visit the page in your browser. If you haven't +changed your defaults, you should be able to find the sheet for character `#1` at +`http://localhost:4001/character/sheet/1/` -Try updating the stats in-game and refresh the page in your browser. The results should show immediately. +Try updating the stats in-game and refresh the page in your browser. The results should show +immediately. -As an optional final step, you can also change your character typeclass to have a method called 'get_absolute_url'. +As an optional final step, you can also change your character typeclass to have a method called +'get_absolute_url'. ```python # typeclasses/characters.py @@ -160,6 +220,10 @@ As an optional final step, you can also change your character typeclass to have from django.urls import reverse return reverse('character:sheet', kwargs={'object_id':self.id}) ``` -Doing so will give you a 'view on site' button in the top right of the Django Admin Objects changepage that links to your new character sheet, and allow you to get the link to a character's page by using {{ object.get_absolute_url }} in any template where you have a given object. +Doing so will give you a 'view on site' button in the top right of the Django Admin Objects +changepage that links to your new character sheet, and allow you to get the link to a character's +page by using {{ object.get_absolute_url }} in any template where you have a given object. -*Now that you've made a basic page and app with Django, you may want to read the full Django tutorial to get a better idea of what it can do. [You can find Django's tutorial here](https://docs.djangoproject.com/en/1.8/intro/tutorial01/).* \ No newline at end of file +*Now that you've made a basic page and app with Django, you may want to read the full Django +tutorial to get a better idea of what it can do. [You can find Django's tutorial +here](https://docs.djangoproject.com/en/1.8/intro/tutorial01/).* \ No newline at end of file diff --git a/docs/source/Web-Features.md b/docs/source/Web-Features.md index 4f03f1a516..40709ef43f 100644 --- a/docs/source/Web-Features.md +++ b/docs/source/Web-Features.md @@ -1,33 +1,64 @@ # Web Features -Evennia is its own webserver and hosts a default website and browser webclient. +Evennia is its own webserver and hosts a default website and browser webclient. -## Web site +## Web site -The Evennia website is a Django application that ties in with the MUD database. Since the website shares this database you could, for example, tell website visitors how many accounts are logged into the game at the moment, how long the server has been up and any other database information you may want. During development you can access the website by pointing your browser to `http://localhost:4001`. +The Evennia website is a Django application that ties in with the MUD database. Since the website +shares this database you could, for example, tell website visitors how many accounts are logged into +the game at the moment, how long the server has been up and any other database information you may +want. During development you can access the website by pointing your browser to +`http://localhost:4001`. -> You may also want to set `DEBUG = True` in your settings file for debugging the website. You will then see proper tracebacks in the browser rather than just error codes. Note however that this will *leak memory a lot* (it stores everything all the time) and is *not to be used in production*. It's recommended to only use `DEBUG` for active web development and to turn it off otherwise. +> You may also want to set `DEBUG = True` in your settings file for debugging the website. You will +then see proper tracebacks in the browser rather than just error codes. Note however that this will +*leak memory a lot* (it stores everything all the time) and is *not to be used in production*. It's +recommended to only use `DEBUG` for active web development and to turn it off otherwise. -A Django (and thus Evennia) website basically consists of three parts, a [view](https://docs.djangoproject.com/en/1.9/topics/http/views/) an associated [template](https://docs.djangoproject.com/en/1.9/topics/templates/) and an `urls.py` file. Think of the view as the Python back-end and the template as the HTML files you are served, optionally filled with data from the back-end. The urls file is a sort of mapping that tells Django that if a specific URL is given in the browser, a particular view should be triggered. You are wise to review the Django documentation for details on how to use these components. +A Django (and thus Evennia) website basically consists of three parts, a +[view](https://docs.djangoproject.com/en/1.9/topics/http/views/) an associated +[template](https://docs.djangoproject.com/en/1.9/topics/templates/) and an `urls.py` file. Think of +the view as the Python back-end and the template as the HTML files you are served, optionally filled +with data from the back-end. The urls file is a sort of mapping that tells Django that if a specific +URL is given in the browser, a particular view should be triggered. You are wise to review the +Django documentation for details on how to use these components. -Evennia's default website is located in [evennia/web/website](https://github.com/evennia/evennia/tree/master/evennia/web/website). In this folder you'll find the simple default view as well as subfolders `templates` and `static`. Static files are things like images, CSS files and Javascript. +Evennia's default website is located in +[evennia/web/website](https://github.com/evennia/evennia/tree/master/evennia/web/website). In this +folder you'll find the simple default view as well as subfolders `templates` and `static`. Static +files are things like images, CSS files and Javascript. ### Customizing the Website -You customize your website from your game directory. In the folder `web` you'll find folders `static`, `templates`, `static_overrides` and `templates_overrides`. The first two of those are populated automatically by Django and used to serve the website. You should not edit anything in them - the change will be lost. To customize the website you'll need to copy the file you want to change from the `web/website/template/` or `web/website/static/ path to the corresponding place under one of `_overrides` directories. +You customize your website from your game directory. In the folder `web` you'll find folders +`static`, `templates`, `static_overrides` and `templates_overrides`. The first two of those are +populated automatically by Django and used to serve the website. You should not edit anything in +them - the change will be lost. To customize the website you'll need to copy the file you want to +change from the `web/website/template/` or `web/website/static/ path to the corresponding place +under one of `_overrides` directories. -Example: To override or modify `evennia/web/website/template/website/index.html` you need to add/modify `mygame/web/template_overrides/website/index.html`. +Example: To override or modify `evennia/web/website/template/website/index.html` you need to +add/modify `mygame/web/template_overrides/website/index.html`. -The detailed description on how to customize the website is best described in tutorial form. See the [Web Tutorial](./Web-Tutorial) for more information. +The detailed description on how to customize the website is best described in tutorial form. See the +[Web Tutorial](./Web-Tutorial) for more information. ### Overloading Django views -The Python backend for every HTML page is called a [Django view](https://docs.djangoproject.com/en/1.9/topics/http/views/). A view can do all sorts of functions, but the main one is to update variables data that the page can display, like how your out-of-the-box website will display statistics about number of users and database objects. +The Python backend for every HTML page is called a [Django +view](https://docs.djangoproject.com/en/1.9/topics/http/views/). A view can do all sorts of +functions, but the main one is to update variables data that the page can display, like how your +out-of-the-box website will display statistics about number of users and database objects. -To re-point a given page to a `view.py` of your own, you need to modify `mygame/web/urls.py`. An [URL pattern](https://docs.djangoproject.com/en/1.9/topics/http/urls/) is a [regular expression](https://en.wikipedia.org/wiki/Regular_expression) that you need to enter in the address field of your web browser to get to the page in question. If you put your own URL pattern *before* the default ones, your own view will be used instead. The file `urls.py` even marks where you should put your change. +To re-point a given page to a `view.py` of your own, you need to modify `mygame/web/urls.py`. An +[URL pattern](https://docs.djangoproject.com/en/1.9/topics/http/urls/) is a [regular +expression](https://en.wikipedia.org/wiki/Regular_expression) that you need to enter in the address +field of your web browser to get to the page in question. If you put your own URL pattern *before* +the default ones, your own view will be used instead. The file `urls.py` even marks where you should +put your change. -Here's an example: +Here's an example: ```python # mygame/web/urls.py @@ -49,30 +80,53 @@ urlpatterns = patterns + urlpatterns ``` -Django will always look for a list named `urlpatterns` which consists of the results of `url()` calls. It will use the *first* match it finds in this list. Above, we add a new URL redirect from the root of the website. It will now our own function `myview` from a new module `mygame/web/myviews.py`. +Django will always look for a list named `urlpatterns` which consists of the results of `url()` +calls. It will use the *first* match it finds in this list. Above, we add a new URL redirect from +the root of the website. It will now our own function `myview` from a new module +`mygame/web/myviews.py`. -> If our game is found on `http://mygame.com`, the regular expression `"^"` means we just entered `mygame.com` in the address bar. If we had wanted to add a view for `http://mygame.com/awesome`, the regular expression would have been `^/awesome`. +> If our game is found on `http://mygame.com`, the regular expression `"^"` means we just entered +`mygame.com` in the address bar. If we had wanted to add a view for `http://mygame.com/awesome`, the +regular expression would have been `^/awesome`. -Look at [evennia/web/website/views.py](https://github.com/evennia/evennia/blob/master/evennia/web/website/views.py#L82) to see the inputs and outputs you must have to define a view. Easiest may be to copy the default file to `mygame/web` to have something to modify and expand on. +Look at [evennia/web/website/views.py](https://github.com/evennia/evennia/blob/master/evennia/web/we +bsite/views.py#L82) to see the inputs and outputs you must have to define a view. Easiest may be to +copy the default file to `mygame/web` to have something to modify and expand on. -Restart the server and reload the page in the browser - the website will now use your custom view. If there are errors, consider turning on `settings.DEBUG` to see the full tracebacks - in debug mode you will also log all requests in `mygame/server/logs/http_requests.log`. +Restart the server and reload the page in the browser - the website will now use your custom view. +If there are errors, consider turning on `settings.DEBUG` to see the full tracebacks - in debug mode +you will also log all requests in `mygame/server/logs/http_requests.log`. ## Web client Evennia comes with a MUD client accessible from a normal web browser. During -development you can try it at `http://localhost:4001/webclient`. +development you can try it at `http://localhost:4001/webclient`. [See the Webclient page](./Webclient) for more details. ## The Django 'Admin' Page -Django comes with a built-in [admin website](https://docs.djangoproject.com/en/1.10/ref/contrib/admin/). This is accessible by clicking the 'admin' button from your game website. The admin site allows you to see, edit and create objects in your database from a graphical interface. +Django comes with a built-in [admin +website](https://docs.djangoproject.com/en/1.10/ref/contrib/admin/). This is accessible by clicking +the 'admin' button from your game website. The admin site allows you to see, edit and create objects +in your database from a graphical interface. -The behavior of default Evennia models are controlled by files `admin.py` in the Evennia package. New database models you choose to add yourself (such as in the Web Character View Tutorial) can/will also have `admin.py` files. New models are registered to the admin website by a call of `admin.site.register(model class, admin class)` inside an admin.py file. It is an error to attempt to register a model that has already been registered. +The behavior of default Evennia models are controlled by files `admin.py` in the Evennia package. +New database models you choose to add yourself (such as in the Web Character View Tutorial) can/will +also have `admin.py` files. New models are registered to the admin website by a call of +`admin.site.register(model class, admin class)` inside an admin.py file. It is an error to attempt +to register a model that has already been registered. -To overload Evennia's admin files you don't need to modify Evennia itself. To customize you can call `admin.site.unregister(model class)`, then follow that with `admin.site.register` in one of your own admin.py files in a new app that you add. +To overload Evennia's admin files you don't need to modify Evennia itself. To customize you can call +`admin.site.unregister(model class)`, then follow that with `admin.site.register` in one of your own +admin.py files in a new app that you add. ## More reading -Evennia relies on Django for its web features. For details on expanding your web experience, the [Django documentation](https://docs.djangoproject.com/en) or the [Django Book](http://www.djangobook.com/en/2.0/index.html) are the main resources to look into. In Django lingo, the Evennia is a django "project" that consists of Django "applications". For the sake of web implementation, the relevant django "applications" in default Evennia are `web/website` or `web/webclient`. +Evennia relies on Django for its web features. For details on expanding your web experience, the +[Django documentation](https://docs.djangoproject.com/en) or the [Django +Book](http://www.djangobook.com/en/2.0/index.html) are the main resources to look into. In Django +lingo, the Evennia is a django "project" that consists of Django "applications". For the sake of web +implementation, the relevant django "applications" in default Evennia are `web/website` or +`web/webclient`. diff --git a/docs/source/Web-Tutorial.md b/docs/source/Web-Tutorial.md index f99ece569c..f2c07b69c4 100644 --- a/docs/source/Web-Tutorial.md +++ b/docs/source/Web-Tutorial.md @@ -1,33 +1,70 @@ # Web Tutorial -Evennia uses the [Django](https://www.djangoproject.com/) web framework as the basis of both its database configuration and the website it provides. While a full understanding of Django requires reading the Django documentation, we have provided this tutorial to get you running with the basics and how they pertain to Evennia. This text details getting everything set up. The [Web-based Character view Tutorial](./Web-Character-View-Tutorial) gives a more explicit example of making a custom web page connected to your game, and you may want to read that after finishing this guide. +Evennia uses the [Django](https://www.djangoproject.com/) web framework as the basis of both its +database configuration and the website it provides. While a full understanding of Django requires +reading the Django documentation, we have provided this tutorial to get you running with the basics +and how they pertain to Evennia. This text details getting everything set up. The [Web-based +Character view Tutorial](Web-Character-View-Tutorial) gives a more explicit example of making a +custom web page connected to your game, and you may want to read that after finishing this guide. ## A Basic Overview -Django is a web framework. It gives you a set of development tools for building a website quickly and easily. +Django is a web framework. It gives you a set of development tools for building a website quickly +and easily. -Django projects are split up into *apps* and these apps all contribute to one project. For instance, you might have an app for conducting polls, or an app for showing news posts or, like us, one for creating a web client. +Django projects are split up into *apps* and these apps all contribute to one project. For instance, +you might have an app for conducting polls, or an app for showing news posts or, like us, one for +creating a web client. -Each of these applications has a `urls.py` file, which specifies what [URL](http://en.wikipedia.org/wiki/Uniform_resource_locator)s are used by the app, a `views.py` file for the code that the URLs activate, a `templates` directory for displaying the results of that code in [HTML](http://en.wikipedia.org/wiki/Html) for the user, and a `static` folder that holds assets like [CSS](http://en.wikipedia.org/wiki/CSS), [Javascript](http://en.wikipedia.org/wiki/Javascript), and Image files (You may note your mygame/web folder does not have a `static` or `template` folder. This is intended and explained further below). Django applications may also have a `models.py` file for storing information in the database. We will not change any models here, take a look at the [New Models](./New-Models) page (as well as the [Django docs](https://docs.djangoproject.com/en/1.7/topics/db/models/) on models) if you are interested. +Each of these applications has a `urls.py` file, which specifies what +[URL](http://en.wikipedia.org/wiki/Uniform_resource_locator)s are used by the app, a `views.py` file +for the code that the URLs activate, a `templates` directory for displaying the results of that code +in [HTML](http://en.wikipedia.org/wiki/Html) for the user, and a `static` folder that holds assets +like [CSS](http://en.wikipedia.org/wiki/CSS), [Javascript](http://en.wikipedia.org/wiki/Javascript), +and Image files (You may note your mygame/web folder does not have a `static` or `template` folder. +This is intended and explained further below). Django applications may also have a `models.py` file +for storing information in the database. We "cmd: attr(locktest, 80, compare=gt)"will not change any +models here, take a look at the [New Models](./New-Models) page (as well as the [Django +docs](https://docs.djangoproject.com/en/1.7/topics/db/models/) on models) if you are interested. -There is also a root `urls.py` that determines the URL structure for the entire project. A starter `urls.py` is included in the default game template, and automatically imports all of Evennia's default URLs for you. This is located in `web/urls.py`. +There is also a root `urls.py` that determines the URL structure for the entire project. A starter +`urls.py` is included in the default game template, and automatically imports all of Evennia's +default URLs for you. This is located in `web/urls.py`. ## Changing the logo on the front page -Evennia's default logo is a fun little googly-eyed snake wrapped around a gear globe. As cute as it is, it probably doesn't represent your game. So one of the first things you may wish to do is replace it with a logo of your own. +Evennia's default logo is a fun little googly-eyed snake wrapped around a gear globe. As cute as it +is, it probably doesn't represent your game. So one of the first things you may wish to do is +replace it with a logo of your own. -Django web apps all have _static assets_: CSS files, Javascript files, and Image files. In order to make sure the final project has all the static files it needs, the system collects the files from every app's `static` folder and places it in the `STATIC_ROOT` defined in `settings.py`. By default, the Evennia `STATIC_ROOT` is in `web/static`. +Django web apps all have _static assets_: CSS files, Javascript files, and Image files. In order to +make sure the final project has all the static files it needs, the system collects the files from +every app's `static` folder and places it in the `STATIC_ROOT` defined in `settings.py`. By default, +the Evennia `STATIC_ROOT` is in `web/static`. -Because Django pulls files from all of those separate places and puts them in one folder, it's possible for one file to overwrite another. We will use this to plug in our own files without having to change anything in the Evennia itself. +Because Django pulls files from all of those separate places and puts them in one folder, it's +possible for one file to overwrite another. We will use this to plug in our own files without having +to change anything in the Evennia itself. -By default, Evennia is configured to pull files you put in the `web/static_overrides` *after* all other static files. That means that files in `static_overrides` folder will overwrite any previously loaded files *having the same path under its static folder*. This last part is important to repeat: To overload the static resource from a standard `static` folder you need to replicate the path of folders and file names from that `static` folder in exactly the same way inside `static_overrides`. +By default, Evennia is configured to pull files you put in the `web/static_overrides` *after* all +other static files. That means that files in `static_overrides` folder will overwrite any previously +loaded files *having the same path under its static folder*. This last part is important to repeat: +To overload the static resource from a standard `static` folder you need to replicate the path of +folders and file names from that `static` folder in exactly the same way inside `static_overrides`. -Let's see how this works for our logo. The default web application is in the Evennia library itself, in `evennia/web/`. We can see that there is a `static` folder here. If we browse down, we'll eventually find the full path to the Evennia logo file: `evennia/web/static/evennia_general/images/evennia_logo.png`. +Let's see how this works for our logo. The default web application is in the Evennia library itself, +in `evennia/web/`. We can see that there is a `static` folder here. If we browse down, we'll +eventually find the full path to the Evennia logo file: +`evennia/web/website/static/website/images/evennia_logo.png`. -Inside our `static_overrides` we must replicate the part of the path inside the `static` folder, in other words, we must replicate `evennia_general/images/evennia_logo.png`. +Inside our `static_overrides` we must replicate the part of the path inside the website's `static` +folder, in other words, we must replicate `website/images/evennia_logo.png`. -So, to change the logo, we need to create the folder path `evennia_general/images/` in `static_overrides`. We then rename our own logo file to `evennia_logo.png` and copy it there. The final path for this file would thus be: `web/static_overrides/evennia_general/images/evennia_logo.png` in your local game folder. +So, to change the logo, we need to create the folder path `website/images/` in `static_overrides`. +You may already have this folder structure prepared for you. We then rename our own logo file to +`evennia_logo.png` and copy it there. The final path for this file would thus be: +`mygame/web/static_overrides/website/images/evennia_logo.png`. To get this file pulled in, just change to your own game directory and reload the server: @@ -35,7 +72,8 @@ To get this file pulled in, just change to your own game directory and reload th evennia reload ``` -This will reload the configuration and bring in the new static file(s). If you didn't want to reload the server you could instead use +This will reload the configuration and bring in the new static file(s). If you didn't want to reload +the server you could instead use ``` evennia collectstatic @@ -43,22 +81,47 @@ evennia collectstatic to only update the static files without any other changes. -> **Note**: Evennia will collect static files automatically during startup. So if `evennia collectstatic` reports finding 0 files to collect, make sure you didn't start the engine at some point - if so the collector has already done its work! To make sure, connect to the website and check so the logo has actually changed to your own version. +> **Note**: Evennia will collect static files automatically during startup. So if `evennia +collectstatic` reports finding 0 files to collect, make sure you didn't start the engine at some +point - if so the collector has already done its work! To make sure, connect to the website and +check so the logo has actually changed to your own version. -> **Note**: Sometimes the static asset collector can get confused. If no matter what you do, your overridden files aren't getting copied over the defaults, try removing the target file (or everything) in the `web/static` directory, and re-running `collectstatic` to gather everything from scratch. +> **Note**: Sometimes the static asset collector can get confused. If no matter what you do, your +overridden files aren't getting copied over the defaults, try removing the target file (or +everything) in the `web/static` directory, and re-running `collectstatic` to gather everything from +scratch. ## Changing the Front Page's Text -The default front page for Evennia contains information about the Evennia project. You'll probably want to replace this information with information about your own project. Changing the page template is done in a similar way to changing static resources. +The default front page for Evennia contains information about the Evennia project. You'll probably +want to replace this information with information about your own project. Changing the page template +is done in a similar way to changing static resources. -Like static files, Django looks through a series of template folders to find the file it wants. The difference is that Django does not copy all of the template files into one place, it just searches through the template folders until it finds a template that matches what it's looking for. This means that when you edit a template, the changes are instant. You don't have to reload the server or run any extra commands to see these changes - reloading the web page in your browser is enough. +Like static files, Django looks through a series of template folders to find the file it wants. The +difference is that Django does not copy all of the template files into one place, it just searches +through the template folders until it finds a template that matches what it's looking for. This +means that when you edit a template, the changes are instant. You don't have to reload the server or +run any extra commands to see these changes - reloading the web page in your browser is enough. -To replace the index page's text, we'll need to find the template for it. We'll go into more detail about how to determine which template is used for rendering a page in the [Web-based Character view Tutorial](./Web-Character-View-Tutorial). For now, you should know that the template we want to change is stored in `evennia/web/website/templates/website/index.html`. +To replace the index page's text, we'll need to find the template for it. We'll go into more detail +about how to determine which template is used for rendering a page in the [Web-based Character view +Tutorial](Web-Character-View-Tutorial). For now, you should know that the template we want to change +is stored in `evennia/web/website/templates/website/index.html`. -To replace this template file, you will put your changed template inside the `web/template_overrides/website` directory in your game folder. In the same way as with static resources you must replicate the path inside the default `template` directory exactly. So we must copy our replacement template named `index.html` there (or create the `website` directory in web/template_overrides` if it does not exist, first). The final path to the file should thus be: `web/template_overrides/website/index.html` within your game directory. +To replace this template file, you will put your changed template inside the +`web/template_overrides/website` directory in your game folder. In the same way as with static +resources you must replicate the path inside the default `template` directory exactly. So we must +copy our replacement template named `index.html` there (or create the `website` directory in +web/template_overrides` if it does not exist, first). The final path to the file should thus be: +`web/template_overrides/website/index.html` within your game directory. -Note that it is usually easier to just copy the original template over and edit it in place. The original file already has all the markup and tags, ready for editing. +Note that it is usually easier to just copy the original template over and edit it in place. The +original file already has all the markup and tags, ready for editing. ## Further reading -For further hints on working with the web presence, you could now continue to the [Web-based Character view Tutorial](./Web-Character-View-Tutorial) where you learn to make a web page that displays in-game character stats. You can also look at [Django's own tutorial](https://docs.djangoproject.com/en/1.7/intro/tutorial01/) to get more insight in how Django works and what possibilities exist. +For further hints on working with the web presence, you could now continue to the [Web-based +Character view Tutorial](Web-Character-View-Tutorial) where you learn to make a web page that +displays in-game character stats. You can also look at [Django's own +tutorial](https://docs.djangoproject.com/en/3.1/) to get more insight in how Django works and what +possibilities exist. diff --git a/docs/source/Webclient-brainstorm.md b/docs/source/Webclient-brainstorm.md index 7a70b1f865..941338a73d 100644 --- a/docs/source/Webclient-brainstorm.md +++ b/docs/source/Webclient-brainstorm.md @@ -6,78 +6,106 @@ ## From Chat on 2019/09/02 ``` - Griatch (IRC)APP @friarzen: Could one (with goldenlayout) programmatically provide pane positions and sizes? + Griatch (IRC)APP @friarzen: Could one (with goldenlayout) programmatically provide pane positions +and sizes? I recall it was not trivial for the old split.js solution. friarzen take a look at the goldenlayout_default_config.js It is kinda cryptic but that is the layout json. - Griatch (IRC)APP @friarzen: Hm, so dynamically replacing the goldenlayout_config in the global scope at the right + Griatch (IRC)APP @friarzen: Hm, so dynamically replacing the goldenlayout_config in the global +scope at the right thing would do it? friarzen yep - friarzen the biggest pain in the butt is that goldenlayout_config needs to be set before the goldenlayout init() + friarzen the biggest pain in the butt is that goldenlayout_config needs to be set before the +goldenlayout init() is called, which isn't trivial with the current structure, but it isn't impossible. Griatch (IRC)APP One could in principle re-run init() at a later date though, right? friarzen Hmm...not sure I've ever tried it... seems doable off the top of my head... -right now, that whole file exists to be overridden on page load as a separate + ``` -Remember, plugins are load-order dependent, so make sure the new `