Author Topic: Restoring Sub-Realms  (Read 1293 times)

Andrew

  • Game Master / Lead Developer
  • Administrator
  • Sr. Member
  • *****
  • Posts: 1768
  • Karma: +75/-7
  • Mildly Amused
    • View Profile
    • Lemuria Community Fan Site
Restoring Sub-Realms
« on: July 12, 2016, 04:09:09 PM »
Bit of a W.i.P., but I've started work on bringing the ability to restore dead realms into the game. Right now, this will ONLY apply to subrealms of your current realm, and you have to be the Ruler (more complex stuff will come later).

The List of Work (To be kept updated as the work progresses!):
restoreRealm method: https://github.com/Zanaras/mightandfealty/blob/realm-revive/src/BM2/SiteBundle/Service/RealmManager.php#L214
findDeadInferiors method: https://github.com/Zanaras/mightandfealty/blob/realm-revive/src/BM2/SiteBundle/Entity/Realm.php#L124
restoreAction method: https://github.com/Zanaras/mightandfealty/blob/realm-revive/src/BM2/SiteBundle/Controller/RealmController.php#L601
RestoreRealmType.php created: https://github.com/Zanaras/mightandfealty/blob/realm-revive/src/BM2/SiteBundle/Form/RealmRestoreType.php
diplomacyRestoreTest method: https://github.com/Zanaras/mightandfealty/blob/realm-revive/src/BM2/SiteBundle/Service/Dispatcher.php#L1428
History Translation: https://github.com/Zanaras/mightandfealty/blob/realm-revive/src/BM2/SiteBundle/Resources/translations/communication.en.yml#L218
Diplomacy Menu Translation: https://github.com/Zanaras/mightandfealty/blob/realm-revive/src/BM2/SiteBundle/Resources/translations/politics.en.yml#L406
Action unavailability messages: https://github.com/Zanaras/mightandfealty/blob/realm-revive/src/BM2/SiteBundle/Resources/translations/messages.en.yml#L1437 (and the line below this one)

When I have time later this week, I'll work on cobbling together the pages in the game to actually do all this, but, with some assistance from Delvin_Anaris (a BM dev) I think I've managed to atleast get the function to a point where it won't kill the game. This probably won't be pretty when I finish it, but it'll work.
« Last Edit: July 15, 2016, 04:41:35 PM by Andrew »
Standing for the creation of interesting things since Year 1, Week 5, Day 4.
Favorite cold beverage: Strawberry Shake
My hobbies: Fixing computers, video games, anime, manga, some other stuff, sleep (in no particular order)

Andrew

  • Game Master / Lead Developer
  • Administrator
  • Sr. Member
  • *****
  • Posts: 1768
  • Karma: +75/-7
  • Mildly Amused
    • View Profile
    • Lemuria Community Fan Site
Re: Restoring Sub-Realms
« Reply #1 on: July 13, 2016, 12:37:38 PM »
Translation and html.twig files have been created. I'm slowly starting to grasp how the game actually generates a page, from looking at the files involved in making a page, and the output of those files when presented to a user. It's looking like I should be able to utilize the existing FormBuilder function to some degree to actually generate the selectable list, but I'm bouncing back and forth too much, trying to figure out all the pieces of this puzzle, to really dig into understand the FormBuilder function right now.
Standing for the creation of interesting things since Year 1, Week 5, Day 4.
Favorite cold beverage: Strawberry Shake
My hobbies: Fixing computers, video games, anime, manga, some other stuff, sleep (in no particular order)

Andrew

  • Game Master / Lead Developer
  • Administrator
  • Sr. Member
  • *****
  • Posts: 1768
  • Karma: +75/-7
  • Mildly Amused
    • View Profile
    • Lemuria Community Fan Site
Re: Restoring Sub-Realms
« Reply #2 on: July 13, 2016, 02:53:28 PM »
Whoa, alright, this is... interesting. From what I can understand, the forms loaded, at least for the realm management menus anyways (because that's where I'm working) are based on the RealmController.php. Each form that is loaded is loaded based on what I originally thought was commented text that appears right before it:

Code: [Select]
   /**
     * @Route("/{realm}/subrealm", requirements={"realm"="\d+"})
     * @Template
     */

This is what defines what form is loaded where, because one of the first lines for the function for each page that requires a form defines $form as one or another different action to create a specific form (literally "createForm"), where it determines which form it actually needs by passing a specific variable to the FormBuilder function through the createForm function.

I really hope Tom doesn't come in and tell me this is all sorts of wrong, because it feels like a lot more of the code is starting to make sense to me. I'm still not sure whether or not this is the correct way to build a page in, but I do have a bit more respect for the amount of work that went into the game's individual pages. I've spent probably an order of magnitude (or two, perhaps) trying to make ONE page than I have creating the functions I need for what I'm doing to actually work. Mind you, I've never don this before, but I also hadn't made my own entire function before this either, and including debugging, the restoreRealm function took all of probably half an hour.

From what I understand it looks like I've got a function to finish to add the form to the page, and then a php file to drop in the /BM2/SiteBundle/Form/ directory that will actually grab all of the data pertinent to this page.
Standing for the creation of interesting things since Year 1, Week 5, Day 4.
Favorite cold beverage: Strawberry Shake
My hobbies: Fixing computers, video games, anime, manga, some other stuff, sleep (in no particular order)

Andrew

  • Game Master / Lead Developer
  • Administrator
  • Sr. Member
  • *****
  • Posts: 1768
  • Karma: +75/-7
  • Mildly Amused
    • View Profile
    • Lemuria Community Fan Site
Re: Restoring Sub-Realms
« Reply #3 on: July 13, 2016, 03:02:44 PM »
Tom, if you wouldn't mind, would you be able to explain how the files in mightandfealty/src/BM2/SiteBundle/Form/ work?

I know that I need to have a form.php file for the form itself, that builds the information that is presented in the form, but it's getting into database queries. If you'd be willing to help me through making a form that queries for abandoned direct subrealms of a realm, it'd be greatly appreciated. I've given you collaborator access to my fork of the M&F code, if you want to make a file that'd query that in https://github.com/Zanaras/mightandfealty/tree/realm-revive/src/BM2/SiteBundle/Form or comment one of the forms there out a bit so I know what the options are for them. Or you could even explain here if you're willing.

I know that I also need to build this form into RealmController.php. I know that I can do that, if I can understand this. And from there, well, it should just leave me submitting all the changes to you for review and addition.
Standing for the creation of interesting things since Year 1, Week 5, Day 4.
Favorite cold beverage: Strawberry Shake
My hobbies: Fixing computers, video games, anime, manga, some other stuff, sleep (in no particular order)

Tom

  • Head Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 6325
  • Karma: +102/-15
    • View Profile
    • Might & Fealty
Re: Restoring Sub-Realms
« Reply #4 on: July 14, 2016, 07:12:40 AM »
Translation and html.twig files have been created. I'm slowly starting to grasp how the game actually generates a page

It's standard Symfony2 and any of the many, many tutorials or introductions to that framework will help you tremendously to get into the code.

Tom

  • Head Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 6325
  • Karma: +102/-15
    • View Profile
    • Might & Fealty
Re: Restoring Sub-Realms
« Reply #5 on: July 14, 2016, 07:15:11 AM »
Whoa, alright, this is... interesting. From what I can understand, the forms loaded, at least for the realm management menus anyways (because that's where I'm working) are based on the RealmController.php. Each form that is loaded is loaded based on what I originally thought was commented text that appears right before it:

Code: [Select]
   /**
     * @Route("/{realm}/subrealm", requirements={"realm"="\d+"})
     * @Template
     */


Yes, that is annotation, not comment. It is explained here:
http://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/routing.html
and here:
http://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/view.html


You won't understand the code without understanding Symfony2. I strongly recommend checking pages like http://symfony.com/doc/current/quick_tour/the_big_picture.html

Tom

  • Head Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 6325
  • Karma: +102/-15
    • View Profile
    • Might & Fealty
Re: Restoring Sub-Realms
« Reply #6 on: July 14, 2016, 07:16:37 AM »
From what I understand it looks like I've got a function to finish to add the form to the page, and then a php file to drop in the /BM2/SiteBundle/Form/ directory that will actually grab all of the data pertinent to this page.

Forms are explained here:
http://symfony.com/doc/current/book/forms.html

Daleborn

  • Jr. Member
  • **
  • Posts: 41
  • Karma: +0/-0
  • All the Dales!
    • View Profile
Re: Restoring Sub-Realms
« Reply #7 on: July 14, 2016, 09:26:58 AM »
This sounds interesting. Perfect opportunity for players to get rulership of a sub-realm.
Born of the Dales, 'nuff said.
My fanfic: https://m.fanfiction.net/s/11968618/1/

Andrew

  • Game Master / Lead Developer
  • Administrator
  • Sr. Member
  • *****
  • Posts: 1768
  • Karma: +75/-7
  • Mildly Amused
    • View Profile
    • Lemuria Community Fan Site
Re: Restoring Sub-Realms
« Reply #8 on: July 14, 2016, 01:31:33 PM »
This sounds interesting. Perfect opportunity for players to get rulership of a sub-realm.

It won't do that directly. What this will do, because it's so much easier to code (I mean, this "little thing" has turned into a 3-day, thus far, project), is simply make the ruler of higher level realm the rulership of any inactive subrealm. From there you can do any of the other actions, like abdicate that realm to a nearby character, for instance.

It's standard Symfony2 and any of the many, many tutorials or introductions to that framework will help you tremendously to get into the code.
Yes, that is annotation, not comment. It is explained here:
http://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/routing.html
and here:
http://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/view.html


You won't understand the code without understanding Symfony2. I strongly recommend checking pages like http://symfony.com/doc/current/quick_tour/the_big_picture.html
From these links, I've reached the conclusion that I have a grasp of how Symfony generates a page. And it looks like my sparse (and incomplete) assumptions based on looking at the rest of the game code were correct. Though confirmation of the formatting is nice. If I've got this right, generating a page is a combination of a [name]Controller.php file and a particular twig.html. Which one covers which is determined by the @Template, which if they're named the same, like my new restore entry, then you don't need to define @Template. It'll automatically grab the appropriately named and placed .html.twig. The html.twig's can build on each other though, so rather than have to rebuild every page, you just have it build on a lesser page's work, and it fills in the rest.

Anyways, as far as I'm aware, all I've got left to do is actually make the form.
« Last Edit: July 14, 2016, 01:45:37 PM by Andrew »
Standing for the creation of interesting things since Year 1, Week 5, Day 4.
Favorite cold beverage: Strawberry Shake
My hobbies: Fixing computers, video games, anime, manga, some other stuff, sleep (in no particular order)

Andrew

  • Game Master / Lead Developer
  • Administrator
  • Sr. Member
  • *****
  • Posts: 1768
  • Karma: +75/-7
  • Mildly Amused
    • View Profile
    • Lemuria Community Fan Site
Re: Restoring Sub-Realms
« Reply #9 on: July 14, 2016, 01:41:47 PM »
Make the form, figure out of the diplomacyRestoreTest needs to return true or false, make sure everything actually passes variables and works right based on how I coded it, and then actually test this all somehow--suggestions are welcome on that bit. I'm not quite sure how I'm going to test this.

But yeah, that should be all I have left for this.
Standing for the creation of interesting things since Year 1, Week 5, Day 4.
Favorite cold beverage: Strawberry Shake
My hobbies: Fixing computers, video games, anime, manga, some other stuff, sleep (in no particular order)

Andrew

  • Game Master / Lead Developer
  • Administrator
  • Sr. Member
  • *****
  • Posts: 1768
  • Karma: +75/-7
  • Mildly Amused
    • View Profile
    • Lemuria Community Fan Site
Re: Restoring Sub-Realms
« Reply #10 on: July 15, 2016, 04:06:20 PM »
I can almost declare this a victory! Five hours and 1 partially ignored wife later (she understands, I was focused), I believe I completed this (almost)!

Tom, on the files in the Forms directory, they all declare an intention. For instance the QuestType.php has 'intention' defined as 'quest_7523' and SubrealmType.php defines 'intention' as 'estates_824'. I've figured out every other part of these files, but I am lost on where/what the purpose of 'intention' is.
Standing for the creation of interesting things since Year 1, Week 5, Day 4.
Favorite cold beverage: Strawberry Shake
My hobbies: Fixing computers, video games, anime, manga, some other stuff, sleep (in no particular order)

Andrew

  • Game Master / Lead Developer
  • Administrator
  • Sr. Member
  • *****
  • Posts: 1768
  • Karma: +75/-7
  • Mildly Amused
    • View Profile
    • Lemuria Community Fan Site
Re: Restoring Sub-Realms
« Reply #11 on: July 17, 2016, 07:28:28 PM »
All right, I've done some more research and I think this might be input validation. But I've also no idea how to generate this number. This should be literally the last thing needed to complete this push, and actually make the game do something *new*, but I've no idea what it does or what it is checked against (if anything). Searching the repository for them only returns the one in the form pages, which may mean it's validated outside of the game, if it IS validation.

Tom, every time the game generates a form, each form sets 'intention' to that form followed by a number. Chat's for instance, is 'chat_14'. You can see them all by looking at this search: https://github.com/tvogt/mightandfealty/search?p=1&q=intention&type=Code&utf8=%E2%9C%93

The only thing stopping me from completing this is knowing what the number string for this feature's form would be. Right now I know it's realmrestore_{numbers} but I don't know how to figure out the number sequence.
Standing for the creation of interesting things since Year 1, Week 5, Day 4.
Favorite cold beverage: Strawberry Shake
My hobbies: Fixing computers, video games, anime, manga, some other stuff, sleep (in no particular order)

Andrew

  • Game Master / Lead Developer
  • Administrator
  • Sr. Member
  • *****
  • Posts: 1768
  • Karma: +75/-7
  • Mildly Amused
    • View Profile
    • Lemuria Community Fan Site
Re: Restoring Sub-Realms
« Reply #12 on: July 21, 2016, 01:35:55 PM »
Since I don't appear to be getting answer, a pull request has been submitted to bring this to the live server. Hopefully my random numbers are sufficient.
Standing for the creation of interesting things since Year 1, Week 5, Day 4.
Favorite cold beverage: Strawberry Shake
My hobbies: Fixing computers, video games, anime, manga, some other stuff, sleep (in no particular order)

Andrew

  • Game Master / Lead Developer
  • Administrator
  • Sr. Member
  • *****
  • Posts: 1768
  • Karma: +75/-7
  • Mildly Amused
    • View Profile
    • Lemuria Community Fan Site
Re: Restoring Sub-Realms
« Reply #13 on: July 26, 2016, 03:26:17 PM »
Tom, if I know if this works, I can pretty easily do a few other things, to include a couple workarounds for broken realm abdication elections, as well as finally adding the ability to tax estates.
Standing for the creation of interesting things since Year 1, Week 5, Day 4.
Favorite cold beverage: Strawberry Shake
My hobbies: Fixing computers, video games, anime, manga, some other stuff, sleep (in no particular order)

De-Legro

  • M&F Dev Team
  • Sr. Member
  • *****
  • Posts: 3072
  • Karma: +105/-54
    • View Profile
Re: Restoring Sub-Realms
« Reply #14 on: July 27, 2016, 12:16:50 PM »
All right, I've done some more research and I think this might be input validation. But I've also no idea how to generate this number. This should be literally the last thing needed to complete this push, and actually make the game do something *new*, but I've no idea what it does or what it is checked against (if anything). Searching the repository for them only returns the one in the form pages, which may mean it's validated outside of the game, if it IS validation.

Tom, every time the game generates a form, each form sets 'intention' to that form followed by a number. Chat's for instance, is 'chat_14'. You can see them all by looking at this search: https://github.com/tvogt/mightandfealty/search?p=1&q=intention&type=Code&utf8=%E2%9C%93

The only thing stopping me from completing this is knowing what the number string for this feature's form would be. Right now I know it's realmrestore_{numbers} but I don't know how to figure out the number sequence.

"If you want to secure a form submission against CSRF attacks, you could supply an "intention" string. This way you make sure that the form can only be bound to pages that are designed to handle the form, that is, that use the same intention string to validate the CSRF token with isCsrfTokenValid()."

I don't know how Tom is doing it, but on my own projects the intention was just a string I made up for each form.
« Last Edit: July 29, 2016, 11:41:49 AM by Andrew »
He who was once known as Blackfyre