DragonPrime - LoGD Resource Community
Welcome Guest
  • Good morning, Guest.
    Please log in, or register.
  • June 27, 2017, 06:57:58 AM
Home Forums News Downloads Login Register Advanced Search
* * *
DragonPrime Menu
Login
 
 
Resource Pages
Search

Pages: [1]   Go Down
  Print  
Author Topic: Titles Error  (Read 2521 times)
0 Members and 1 Guest are viewing this topic.
KaosKaizer
Mod God
*****
Offline Offline

Posts: 1016


Zeno's Arrow never hits the mark.


View Profile
« on: June 28, 2009, 04:42:31 PM »

Quite an odd one here...
1.1.1
For some odd reason, when my players DK, their old DK Title becomes part of their name.
Example:
Farmboy Shane.
Farmboy Shane slays the Dragon and becomes a Page.
Farmboy Shane is now Page Farmboy Shane when he should be Page Shane.

In the User Editor, it looks like this:
Quote
Character Name: [ Farmboy Shane ]
Dragonkill Title: [ Page ]
Custom Title: [ ]

Any suggestions on how to fix this or what could have even caused it in the first place? It happens with every user, every time, regardless of how many DKs they have. IE, Page Farmboy, Gladiator Page, etc...
« Last Edit: June 28, 2009, 04:45:27 PM by kaizerDRAGON » Logged

My Mods
I'm not currently a fully active member of DP, though I do respond to most PMs.
Boris735
Mod God
*****
Offline Offline

Posts: 564


View Profile
« Reply #1 on: June 28, 2009, 08:13:52 PM »

I can't provide an answer, but perhaps the following will help point in the right direction.

The character names are stored in the database including the title, so the picture that the editor presents to you is slightly misleading.  What is actually stored is (prior to the DK):

Character Name: [ Farmboy Shane ]
Dragonkill Title: [ Farmboy ]

When your title changes (in this case, when you DK), the code has to extract the name part by looking for the substring corresponding to your existing title and removing it, then adding in the new title.  That is, the process goes something like this:

  • Get name ("Farmboy Shane") and title ("Farmboy").
  • If title is part of name, remove everything up to and including it from the name, plus any extra spaces.  In this case, name becomes "Shane".
  • Get the new title ("Page").
  • Set the new title, and prepend it to the name -- title becomes "Page", name becomes "Page Shane".

The behaviour you see occurs because something goes wrong in the second step above; the old title is not being correctly removed, presumably because it is not found.  As a result, the name remains unchanged ("Farmboy Shane"), and when the new title is prepended this becomes ("Page Farmboy Shane").

I can't really guess offhand why the title is not being removed properly.  It could be that something is setting the title to be empty during the dragonkill process, perhaps.  If you're comfortable editing a core file (make a backup, of course!) you could insert some debug information in dragon.php at around line 210, which reads:

Code:
  // Set the new title.
  $newname = change_player_title($newtitle);
  $session['user']['title'] = $newtitle;
  $session['user']['name'] = $newname;

You could change this to the following, for instance:

Code:
  // Set the new title.
  debug("Old name: '{$session['user']['name']}'`n");
  debug("Old title: '{$session['user']['title']}'`n");
  debug("New title: '$newtitle'`n");
  $newname = change_player_title($newtitle);
  debug("New name: '$newname'`n");
  $session['user']['title'] = $newtitle;
  $session['user']['name'] = $newname;

and enable debug output for your character.  Or bundle up that information into a mail message and systemmail it to your admin account, which would let you find out what is happening on every DK.  Hopefully something obviously wrong will strike you about the results that you see.  (For instance, maybe the old title is empty, or clearly not part of the name for some reason.)
Logged
KaosKaizer
Mod God
*****
Offline Offline

Posts: 1016


Zeno's Arrow never hits the mark.


View Profile
« Reply #2 on: June 29, 2009, 12:02:55 AM »

Okay, I made the change, and then logged in with my devnull admin, and slayed the dragon two times.
Quote
Old name: 'Farmboy devnull`0'`n
Old title: 'Farmboy'`n
New title: 'Page'`n
New name: 'Page devnull`0'`n
****************************************
Old name: 'Page devnull`0'`n
Old title: 'Page'`n
New title: 'Squire'`n
New name: 'Squire devnull`0'`n

I do not know what happened, but for some odd reason, it fixed itself. I have done nothing shortly before it was fixed, so I have no clue what was causing it or what fixed it Undecided. Thanks for the help.
Logged

My Mods
I'm not currently a fully active member of DP, though I do respond to most PMs.
KaosKaizer
Mod God
*****
Offline Offline

Posts: 1016


Zeno's Arrow never hits the mark.


View Profile
« Reply #3 on: June 30, 2009, 11:22:24 AM »

// Grabs the closest thing to him and pounds it into dust

The error is back, and it will not affect my SU's at all it would seem!
Logged

My Mods
I'm not currently a fully active member of DP, though I do respond to most PMs.
Boris735
Mod God
*****
Offline Offline

Posts: 564


View Profile
« Reply #4 on: June 30, 2009, 07:41:05 PM »

So try the other suggestion -- put this information in a mail to your admin account.  Then you'll find out the fields for each person who DKs, even if they don't have superuser access.  Note: Make sure to use the values of name and title before the call to change_player_title(), and the new name and new title after that call.

I should ask the obvious question: Have you made any changes to dragon.php aside from the debug output that you just tried?  In particular, explicitly setting the user's title field rather than calling change_player_title() could lead to this kind of issue.  Maybe you just need to upload a clean copy.

As a temporary measure while you are trying to work out what causes it, you could add the following module to check for this happening and fix it afterwards.  (It's a quick hack, and if someone happens to include two titles in their name then it will erroneously change them because I didn't anchor the replacement, but the likelihood of that mattering is pretty small.)

Code:
<?php
function dktitlefix_getmoduleinfo() {
  
$info = array(
    
"name" => "DK title fix",
    
"version" => "1.0",
    
"author" => "`!Boris735",
    
"category" => "Administrative",
    
"description" => "Fix DK title bug experienced by kaizerDRAGON",
  );
  return 
$info;
}

function 
dktitlefix_install() {
  
module_addhook("dragonkilltext");
  return 
true;
}

function 
dktitlefix_uninstall() {
}

function 
dktitlefix_dohook($hookname$args) {
  global 
$session;

  switch (
$hookname) {
  case 
"dragonkilltext":
    require_once(
"lib/titles.php");

    
$dks $session['user']['dragonkills'];
    
$gender $session['user']['sex'];
    
$thistitle get_dk_title($dks$gender);
    
$thattitle get_dk_title($dks-1$genderex);
    
$name $session['user']['name'];
    
$newname str_replace("$thistitle $thattitle"$thistitle$name);
    
$session['user']['name'] = $newname;
    break;
  }
  return 
$args;
}

function 
dktitlefix_run() {
}
?>


EDIT: Corrected syntax error as pointed out by kaizerDRAGON.
« Last Edit: July 01, 2009, 07:19:58 PM by Boris735 » Logged
KaosKaizer
Mod God
*****
Offline Offline

Posts: 1016


Zeno's Arrow never hits the mark.


View Profile
« Reply #5 on: July 01, 2009, 12:27:13 AM »

Well, yes, other than the debug change, I did edit dragon.php, but nothing that should mess with the titles, and I was having the error even before. The change was to allow gold in bank to be kept after DK...and I have tried uploading clean copies as well

I will try wrapping it all into a systemmail to my main account, and thanks for the temp module, I hope I get this sorted out soon...

::EDIT::
I had to modify line 34 of your module:
Code:
    $session['user']['name' = $newname;
should be:
Code:
    $session['user']['name'] = $newname;
« Last Edit: July 01, 2009, 07:09:10 PM by kaizerDRAGON » Logged

My Mods
I'm not currently a fully active member of DP, though I do respond to most PMs.
KaosKaizer
Mod God
*****
Offline Offline

Posts: 1016


Zeno's Arrow never hits the mark.


View Profile
« Reply #6 on: July 01, 2009, 07:02:57 PM »

Wait, I do have one question about titles, that may help me fix it.

Does it check the users name for the title of the gender they are at time of DK or for both genders?

IE...User is female at time of DK, but started game as male. User ran across a special before DKing, and that special changed their gender to female, but left their title Farmboy.
So, when user DKs, does it check their name for Farmgirl or both Farmgirl and Farmboy?
Logged

My Mods
I'm not currently a fully active member of DP, though I do respond to most PMs.
Boris735
Mod God
*****
Offline Offline

Posts: 564


View Profile
« Reply #7 on: July 01, 2009, 07:41:33 PM »

Sorry about that syntax error, I corrected it above just in case anyone else grabs that code again later.

Your observation may well explain the problem -- it depends what happened when they changed gender.  To answer your question, it checks only for the gender that they are at the time of DK.  So if their gender has changed without the title being properly updated to reflect the issue, then it could cause this problem.

However, that depends what happened on gender change.  If all that happens is that the gender is changed (bad, of course, since the title should also be adjusted) then the title and name fields are in agreement although they no longer reflect the user's gender.  This means that the title will still be found as the substring of the name and will thus be extractable.

If the title was also changed when the gender was altered, but this was done incorrectly by setting $session['user']['title'], then the title and name will be in disagreement and the kind of behaviour that you observed will arise.  When the title is changed then the name must also be changed, which requires calling change_player_title() plus a bit more fiddling.  Sample code below.

You should be able to check this possibility easily enough with your admin character.  Get rid of any custom title, trigger the gender changing event, and see if the title and name are still in agreement.  If not, that code needs changing.

Here's the right way to change a player's gender:

Code:
function change_player_gender($newgender=-1) {
  global $session;

  $gender = $session['user']['sex'];
  if ($gender == $newgender)
    return;
  if ($newgender < 0)
    $newgender = ($gender == SEX_MALE) ? SEX_FEMALE : SEX_MALE;

  require_once("lib/titles.php");
  require_once("lib/names.php");
  $dks = $session['user']['dragonkills'];
  $oldtitle = get_dk_title($dks, $gender);
  $newtitle = get_dk_title($dks, $newgender);
  $session['user']['sex'] = $newgender;
  if ($newtitle != $oldtitle) {
    $newname = change_player_title($newtitle);
    $session['user']['title'] = $newtitle;
    $session['user']['name'] = $newname;
  }
}
« Last Edit: July 01, 2009, 07:43:39 PM by Boris735 » Logged
KaosKaizer
Mod God
*****
Offline Offline

Posts: 1016


Zeno's Arrow never hits the mark.


View Profile
« Reply #8 on: July 01, 2009, 08:00:16 PM »

The offending module: Cookie Jar by Night
The offending code:
Code:
case 7:
output("You reach in to the cookie jar and pull out a Snickerdoodle. Such a strange shape of it!");
output("`nYou eat the Snickerdoodle, you wonder if anyone is watching you eat the Snickerdoodle...");
output("`n`nSomething has changed withen you!!");
if ($session['user']['sex'] ==0){
$session['user']['sex'] =1;
}else{
$session['user']['sex'] =0;
}
debuglog("sex change from the cookie jar");
tlschema("nav");
addnav("Go to The Village","village.php");
tlschema();
break;

all this code does is change the gender. It doesn't alter the titles at all. However, I do know that there are other portions of this module that cause a disagreement between name and title. Specifically, there is 1 case that changes the players title to "Cookie Monster"(or something similiar), but does not alter their name.
Code:
case 5:
$title = get_module_setting("cookienewtitle");
output("`0You reach in to the cookie jar and pull out a Peanut Butter Cookie. You wonder how long it has been in there..");
output("`nOh well... You eat the Peanut Butter Cookie, still pondering how long it has been in there.");
output("`n`nYou get the title of `b`^%s`0`b!!",$title);
$session['user']['title'] =$title;
debuglog("got $title title from the cookie jar");
tlschema("nav");
addnav("Go to The Village","village.php");
tlschema();
break;

I can't remember when the titles problem started occuring, but I do know I have had this module installed for a while. This may be what is causing the errors.
« Last Edit: July 01, 2009, 08:03:52 PM by kaizerDRAGON » Logged

My Mods
I'm not currently a fully active member of DP, though I do respond to most PMs.
Boris735
Mod God
*****
Offline Offline

Posts: 564


View Profile
« Reply #9 on: July 02, 2009, 12:32:28 AM »

The first part is an incomplete way to change the gender, as discussed earlier, but shouldn't cause the mismatch.  The second definitely does, as you note, and could indeed cause the kind of problems that you've noted.

(And, incidentally, it highlights an issue with the gender changing code I proposed earlier -- if the title has already been changed to something other than a DK title, such as "Cookie Monster", then the gender change code will reset the title to the DK title for the new gender.  That is probably not the appropriate thing to do, and just serves to highlight the complications involved in an apparently simple concept like changing gender.)
Logged
KaosKaizer
Mod God
*****
Offline Offline

Posts: 1016


Zeno's Arrow never hits the mark.


View Profile
« Reply #10 on: July 02, 2009, 01:21:26 AM »

Thanks for all the help, Boris.

I deactivated this module right after my last post, and it hasn't happened since(and I had several people to DK today.)
Logged

My Mods
I'm not currently a fully active member of DP, though I do respond to most PMs.
Pages: [1]   Go Up
  Print  
 
Jump to:  


*
DragonPrime Notices
Version 1.1.2 is the current supported version and is available for download.

Support Us
No funds raised yet this year
Your help is greatly appreciated!
Recent Topics
DragonPrime LoGD
Who's Online
32 Guests, 0 Users
Home Forums News Downloads Login Register Advanced Search