RanvierMUD / ranviermud

A node.js based MUD game engine
https://ranviermud.com
MIT License
796 stars 247 forks source link

Player equipment not iterable. #316

Closed AndrewECooper closed 6 years ago

AndrewECooper commented 6 years ago

After logging in I create a new character.

I would expect the new character to be loaded and to start in Test Room 1.

When loading the character the server throws an error. The user sees "Failed to log in to your character. Please contact an administrator." The server records that "this.equipment is not iterable." at line 244 of Player.js.

Log in. Create a character. Error happens when creating / loading the new character.

Issue also happens if you reconnect, log back in, and then select the character you previously created.

Version of Ranvier: 2.0

2018-01-13T15:02:10.582Z - warn: TypeError: this.equipment is not iterable at Player.serialize (/home/andrew/Projects/ranviermud/src/Player.js:244:39) at Player.save (/home/andrew/Projects/ranviermud/src/Player.js:173:41) at Quest.instance.on (/home/andrew/Projects/ranviermud/src/QuestFactory.js:47:14) at emitOne (events.js:116:13) at Quest.emit (events.js:211:7) at Quest.emit (/home/andrew/Projects/ranviermud/src/Quest.js:38:11) at Quest.instance.on (/home/andrew/Projects/ranviermud/src/QuestFactory.js:52:16) at emitNone (events.js:106:13) at Quest.emit (events.js:208:7) at Quest.emit (/home/andrew/Projects/ranviermud/src/Quest.js:38:11)


I'm new to Ranvier. I was trying to test it out but couldn't get past this issue. I fixed the problem but am unsure whether this is the best solution. I changed the serialize() method on the Player class to the following...

serialize() {
    let data = Object.assign(super.serialize(), {
      account: this.account.name,
      experience: this.experience,
      inventory: this.inventory && this.inventory.serialize(),
      metadata: this.metadata,
      password: this.password,
      playerClass: this.playerClass && this.playerClass.id,
      prompt: this.prompt,
      quests: this.questTracker.serialize(),
      role: this.role,
    });

    if (this.equipment) {
      if (!(typeof this.equipment[Symbol.iterator] === "function")) this.equipment = new Map();
      let eq = {};
      for (let [ slot, item ] of this.equipment) {
        eq[slot] = item.serialize();
      }
      data.equipment = eq;
    } else {
      data.equipment = null;
    }

    return data;
  }

Right after checking to see if equipment exists, I then check to see if it is iterable. If it isn't, I set it equal to a new Map object. This allows the code to continue. Before, this.equipment was set to something of type object but wasn't iterable.

Note that this problem only happens when the character is first created. Once the character gets past this point the first time it never has this problem again that I can see.

I tried to find a way to fix the issue without altering the Player.js code since it is core. I couldn't really see a way though. Like I said, I'm new to the code base.

shawncplus commented 6 years ago

Please pull the latest changes. This should be fixed as of yesterday

shawncplus commented 6 years ago

If not hop in the slack and I'll help you debug

AndrewECooper commented 6 years ago

Cool. I'll pull the latest. Can you send me an invite to the Slack. I tried before but never got an invite.

Thanks,

Andrew

On Sat, Jan 13, 2018 at 11:13 PM, Shawn Biddle notifications@github.com wrote:

If not hop in the slack and I'll help you debug

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/shawncplus/ranviermud/issues/316#issuecomment-357487491, or mute the thread https://github.com/notifications/unsubscribe-auth/ABFyon-i_cG6hyQgzOigeVKY6NNYv--Nks5tKX70gaJpZM4Rdd9v .

shawncplus commented 6 years ago

Hmm, you tried this link? https://ranviermud.signup.team

AndrewECooper commented 6 years ago

I tried again. I worked this time. Not sure what the problem was before. Thanks for the link.

On Sun, Jan 14, 2018 at 12:04 AM, Shawn Biddle notifications@github.com wrote:

Hmm, you tried this link? https://ranviermud.signup.team

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/shawncplus/ranviermud/issues/316#issuecomment-357489073, or mute the thread https://github.com/notifications/unsubscribe-auth/ABFyotHeAptObwWQdzxTrzgd2d7k2hbOks5tKYrHgaJpZM4Rdd9v .