Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

gainGP issue

Newbie Spellweaver
Joined
May 24, 2017
Messages
57
Reaction score
1
Hello everyone,

So lately there's been this issue that's been driving me nuts, so basically everytime I gain guild points from any NPC I'll basically only get that x amount and it will not increase until the next server restart.

For example: If I finish a quest and get 2 guild points and then re-do the quest again and gain 2 more guild points, it will just register as 2 guild points in the guild meaning the points won't add up and will just stay as 2.

However if I restart the server and do the quest again it will add up and become 4, and the same goes for another server restart. I hope that made sense. :/

The weird thing is that I've compared every single gaingp method with HeavenMS/MoopleDEV and they are basically the same which is weird...so then I thought it might have to do with wrong op codes but my GUILD_OPERATION send/recv codes are correct (I think?)

These are my opcodes and the gaingp method in MapleGuild.java for reference:
PHP:
public void gainGP(int amount) {        
this.gp += amount;        
this.writeToDB(false);        
this.guildMessage(MaplePacketCreator.updateGP(this.id, this.gp));    
}

Sendops:
Code:
GUILD_OPERATION: 0x41

Recvops:
Code:
GUILD_OPERATION: 0x7E

I hope someone can shed some light on this as I am very lost on what is going on here. Thanks.
 
Junior Spellweaver
Joined
Sep 16, 2017
Messages
156
Reaction score
36
You should have a function called getGuild in WorldRegistryImpl.java; could you post it here please?

I was looking at the one from TiredStory source, but I'm not sure whether yours is the same. There might actually be a specific difference in there.
 
Upvote 0
Newbie Spellweaver
Joined
May 24, 2017
Messages
57
Reaction score
1
You should have a function called getGuild in WorldRegistryImpl.java; could you post it here please?

I was looking at the one from TiredStory source, but I'm not sure whether yours is the same. There might actually be a specific difference in there.

Do you mean this one?

Code:
public MapleGuild getGuild(int id, MapleGuildCharacter mgc, int world) {
synchronized (guilds) {  

if (guilds.get(id) != null) {    

return guilds.get(id); 
}           
if (mgc == null) {                
return null;            
}            
MapleGuild g = new MapleGuild(id, world);
if (g.getId() == -1) {              
return null;           
}          
guilds.put(id, g);        
return g;      
}    
}
 
Upvote 0
Junior Spellweaver
Joined
Sep 16, 2017
Messages
156
Reaction score
36
That seems to be fine, so let's try another thing.

Please edit, once again, the gainGP function, but this time in a different way:

Code:
public void gainGP(int amount) {
[B]    this.guildMessage(MaplePacketCreator.serverNotice(5, this.toString()));
[/B]    this.gp += amount;
    this.writeToDB(false);
    this.guildMessage(MaplePacketCreator.updateGP(this.id, this.gp));
}

What we're trying to test is whether you're obtaining a different object instance every time you try to add GP. If that's the case, we'll just have to figure out where that happens.

Please try gaining GP two times consecutively, like we did before. We won't need to test the channel changing this time, so one test will suffice.
 
Upvote 0
Newbie Spellweaver
Joined
May 24, 2017
Messages
57
Reaction score
1
That seems to be fine, so let's try another thing.

Please edit, once again, the gainGP function, but this time in a different way:

Code:
public void gainGP(int amount) {
[B]    this.guildMessage(MaplePacketCreator.serverNotice(5, this.toString()));
[/B]    this.gp += amount;
    this.writeToDB(false);
    this.guildMessage(MaplePacketCreator.updateGP(this.id, this.gp));
}

What we're trying to test is whether you're obtaining a different object instance every time you try to add GP. If that's the case, we'll just have to figure out where that happens.

Please try gaining GP two times consecutively, like we did before. We won't need to test the channel changing this time, so one test will suffice.

I've tried doing it and this was the resulting message.

 
Upvote 0
Junior Spellweaver
Joined
Sep 16, 2017
Messages
156
Reaction score
36
I see, so the object is the same. I wonder what I'm overlooking.

Two questions then:

1) After you've gained the 2 GP, try gaining something like 5, the second time. I'm assuming the value would become 5 instead of 2, but it's worth a try I guess.

2) Try setting an NPC to show you how many GP your guild has, by using something like cm.getGuild().getGP(). It'd be better if this was a separate NPC from the one that gives you GP: this way, you can first gain GP, then check the amount independently.
I'm curious to see whether the value is lost right after it's set.
 
Upvote 0
Newbie Spellweaver
Joined
May 24, 2017
Messages
57
Reaction score
1
I see, so the object is the same. I wonder what I'm overlooking.

Two questions then:

1) After you've gained the 2 GP, try gaining something like 5, the second time. I'm assuming the value would become 5 instead of 2, but it's worth a try I guess.

2) Try setting an NPC to show you how many GP your guild has, by using something like cm.getGuild().getGP(). It'd be better if this was a separate NPC from the one that gives you GP: this way, you can first gain GP, then check the amount independently.
I'm curious to see whether the value is lost right after it's set.

I can see at this point you've realised how odd this issue is. I still feel that it's solution is in plain sight that I just can't see it.

As for what you have asked:

1) I've tried that in the past and as you assumed it will just set the value to whatever you want whether it be 1 or 2 or 5.


2) I've tested this starting with 0 GP, and after I attempted to gain 2 GP it will show that I gained 2 GP in the guild menu but in the NPC it will state that you have 0 GP. After I restarted the server the NPC will state that you have 2 GP.

I'm guessing the game isn't registering any GP gained when I gain it at all?
 
Upvote 0
Junior Spellweaver
Joined
Sep 16, 2017
Messages
156
Reaction score
36
I really don't get how it can not be a duplicate object issue.
Let's try another thing then.

Set this code portion on an npc please:

Code:
var guild = cm.getGuild();

guild.gainGP(2);
cm.getPlayer().dropMessage("The guild GP: " + guild.getGP()); // Or whichever print method you prefer using

guild.gainGP(3);
cm.getPlayer().dropMessage("The guild GP: " + guild.getGP()); // Or whichever print method you prefer using, again

Then, after testing, try changing that to this:

Code:
cm.getGuild().gainGP(2);
cm.getPlayer().dropMessage("The guild GP: " + cm.getGuild().getGP()); // Or whichever print method you prefer using

cm.getGuild().gainGP(3);
cm.getPlayer().dropMessage("The guild GP: " + cm.getGuild().getGP()); // Or whichever print method you prefer using, again
 
Upvote 0
Mythic Archon
Joined
Jul 2, 2013
Messages
723
Reaction score
70
I feel like everything you guys are doing now is everything I already mentioned and or can be done more efficiently with debugger. :s
 
Upvote 0
Junior Spellweaver
Joined
Sep 16, 2017
Messages
156
Reaction score
36
I feel like everything you guys are doing now is everything I already mentioned and or can be done more efficiently with debugger. :s

The problem is that the guild is not reloaded between the two GP gains; also, the GP is "correctly" saved in the database (since restarting the server, that ofcourse includes reloading the guilds, sets the proper amount of GP, atleast for the first new gain), which makes me heavily lean towards the object being somehow duplicated somewhere I have yet to see.

I'm trying to first get some hints from simple NPC tests, before delving deeper in case that won't prove to be enough.
 
Upvote 0
Newbie Spellweaver
Joined
May 24, 2017
Messages
57
Reaction score
1
I really don't get how it can not be a duplicate object issue.
Let's try another thing then.

Set this code portion on an npc please:

Code:
var guild = cm.getGuild();

guild.gainGP(2);
cm.getPlayer().dropMessage("The guild GP: " + guild.getGP()); // Or whichever print method you prefer using

guild.gainGP(3);
cm.getPlayer().dropMessage("The guild GP: " + guild.getGP()); // Or whichever print method you prefer using, again

Then, after testing, try changing that to this:

Code:
cm.getGuild().gainGP(2);
cm.getPlayer().dropMessage("The guild GP: " + cm.getGuild().getGP()); // Or whichever print method you prefer using

cm.getGuild().gainGP(3);
cm.getPlayer().dropMessage("The guild GP: " + cm.getGuild().getGP()); // Or whichever print method you prefer using, again

I might have stumbled upon something so bear with me please.

So I tried your first test and this was the result:

So before attempting your second test I went to disband my guild and create a new one and after creating it I noticed that it registered me as offline in the guild menu until I CCed that it would register me as online and so I wanted to test this using your 2nd test so here's what I did...

After creating a new guild and while still being registered as offline I attempted to gain GP and this was the result: .

It only registered me as online after I changed channels, the result was the same after changing channels and attempting to gain GP.


So I wanted to test this further and what I did was I created a new guild and while I was registered as offline I attempted to disband it and after pressing "Yes to disband" the guild wouldn't disappear from neither below your IGN or viewing it in guild menu. So I changed channel and I still could view it and then I tried to disband it again and this message popped up:

While this is happening if you choose "Create a guild" it will allow you to create a guild and just overwrite the previous one you had but you will still be registered as offline until you CC.
 
Upvote 0
Junior Spellweaver
Joined
Sep 16, 2017
Messages
156
Reaction score
36
Ahh, there we go. It's somehow grabbing a "new" guild every time you try to call for your MapleGuild object.

We'll go ahead and take a look at the way TiredStory handles guilds once I'm awake tomorrow, since I've noticed it relies on MapleGuildCharacter a bit more than on other sources. But for now, I'll be going to sleep. c:
 
Upvote 0
Newbie Spellweaver
Joined
May 24, 2017
Messages
57
Reaction score
1
Well I’m glad we got to a result (I think?). I appreciate you assisting me on this and I look forward to your reply tomorrow. :)
 
Upvote 0
Mythic Archon
Joined
Jul 2, 2013
Messages
723
Reaction score
70
Ahh, there we go. It's somehow grabbing a "new" guild every time you try to call for your MapleGuild object.

We'll go ahead and take a look at the way TiredStory handles guilds once I'm awake tomorrow, since I've noticed it relies on MapleGuildCharacter a bit more than on other sources. But for now, I'll be going to sleep. c:

Well if you look at his screen shots, the hash of the guild object is the same.




Well I’m glad we got to a result (I think?). I appreciate you assisting me on this and I look forward to your reply tomorrow. :)

The fastest way to check this is to do what you did earlier. Do two test where you gain GP two separate times. One test where you gain GP twice without changing channels and one test where you do change channels after the second time. The reason I say is because I want to see the server's hash of that guild object, whether it is the same or not after changing channels.

Similiar to how you did it here,
sFvldwY - gainGP issue - RaGEZONE Forums


but make sure you print the guild object as well like you did here
E0bYZRJ - gainGP issue - RaGEZONE Forums
 

Attachments

You must be registered for see attachments list
Upvote 0
Junior Spellweaver
Joined
Sep 16, 2017
Messages
156
Reaction score
36
Well if you look at his screen shots, the hash of the guild object is the same.
That's exactly what confused me, until I noticed the overriding of hashCode and equals methods in TiredStory's MapleGuild class:

Code:
@Override
public boolean equals(Object other) {
    if (!(other instanceof MapleGuildCharacter)) {
        return false;
    }
    MapleGuildCharacter o = (MapleGuildCharacter) other;
    return (o.getId() == id && o.getName().equals(name));
}

@Override
public int hashCode() {
    int hash = 3;
    hash = 89 * hash + (this.name != null ? this.name.hashCode() : 0);
    hash = 89 * hash + this.id;
    return hash;
}

For starters, equals() will always return false, regardless of the objects, because MapleGuild will never be of type MapleGuildCharacter ofcourse.

Additionally, hashCode() only depends on the name's hashCode (two identical Strings will return the same hashCode), and the id; due to this, as long as "two" guilds have same name and same id, the code won't change.

Morty , after you've performed Zydee's tests, please try commenting out the equals() and hashCode() functions in your MapleGuild.java class, and repeat the tests.

I'll be back this evening so that we can look more into this.
 
Upvote 0
Newbie Spellweaver
Joined
May 24, 2017
Messages
57
Reaction score
1
That's exactly what confused me, until I noticed the overriding of hashCode and equals methods in TiredStory's MapleGuild class:

Code:
@Override
public boolean equals(Object other) {
    if (!(other instanceof MapleGuildCharacter)) {
        return false;
    }
    MapleGuildCharacter o = (MapleGuildCharacter) other;
    return (o.getId() == id && o.getName().equals(name));
}

@Override
public int hashCode() {
    int hash = 3;
    hash = 89 * hash + (this.name != null ? this.name.hashCode() : 0);
    hash = 89 * hash + this.id;
    return hash;
}

For starters, equals() will always return false, regardless of the objects, because MapleGuild will never be of type MapleGuildCharacter ofcourse.

Additionally, hashCode() only depends on the name's hashCode (two identical Strings will return the same hashCode), and the id; due to this, as long as "two" guilds have same name and same id, the code won't change.

@Morty , after you've performed Zydee's tests, please try commenting out the equals() and hashCode() functions in your MapleGuild.java class, and repeat the tests.

I'll be back this evening so that we can look more into this.

Alright, I've done the two tests.

These are the first two tests without commenting out the two functions:

1st result: (without changing channels)

2nd result: (with changing channels)

These are the same tests done with commenting out the two functions.

1st result: (without changing channels)

2nd result: (with changing channels)


It seems that after commenting out the two functions the hash object was different this time.
 
Last edited:
Upvote 0
Mythic Archon
Joined
Jul 2, 2013
Messages
723
Reaction score
70
So it looks like you're creating a new object every time, and based on your code

Code:
public MapleGuild getGuild(int id, MapleGuildCharacter mgc, int world) {    synchronized(guilds) {        if (guilds.get(id) != null) {            return guilds.get(id);        }        if (mgc == null) {            return null;        }        MapleGuild g = new MapleGuild(id, world);        if (g.getId() == -1) {            return null;        }        guilds.put(id, g);        return g;    }}

this should be the only time a new guild object is created. (if not find where else it's created; but it should be here or else theres no reason to nest get and create like this). Though it wouldn't make sense as guild id should be constant, something you can try is to print out the guild id argument being printed out every time this is called to see if it is constant. The reason I say this is because for the offchance it is not constant, it being the guild id, the server is creating a new guild object, storing it, and returning the new guild object.

Step by step:

If the guild ID 5 was passed in, but the real guild ID was 2, the server has now created a new guild object and stored it. Now two guild objects exist, 2 and 5. If this happened again, the previous step would repeat and repeat, with new guild objects every time.

Highly unlikely this is the case, but it's all i can think of based only on that code segment you pasted.
 
Upvote 0
Junior Spellweaver
Joined
Sep 16, 2017
Messages
156
Reaction score
36
You're right. And I just realized I took something for granted which may instead be the issue.

Could you post the code of your function getGuild() in AbstractPlayerInteraction.java, please?
(For context, it's the function that gets called via cm.getGuild() )
 
Upvote 0
Newbie Spellweaver
Joined
Mar 25, 2016
Messages
86
Reaction score
26
lmaooooo this guy just got helped for over a week and ends up fixing it himself and helping no one else
 
Upvote 0
Back
Top