Skip to content

Commit

Permalink
[6913] Fixed guild creation after adding stronger checks.
Browse files Browse the repository at this point in the history
Fixed _return_ typo in guild charter sign code.
Merged some sql queries into one.

Signed-off-by: ApoC <apoc@nymfe.net>
  • Loading branch information
apoc committed Dec 16, 2008
1 parent ab6a2c0 commit f574317
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 36 deletions.
60 changes: 25 additions & 35 deletions src/game/PetitionsHandler.cpp
Expand Up @@ -250,15 +250,16 @@ void WorldSession::HandlePetitionShowSignOpcode(WorldPacket & recv_data)
// solve (possible) some strange compile problems with explicit use GUID_LOPART(petitionguid) at some GCC versions (wrong code optimization in compiler?)
uint32 petitionguid_low = GUID_LOPART(petitionguid);

QueryResult *result = CharacterDatabase.PQuery("SELECT petitionguid, type FROM petition WHERE petitionguid = '%u'", petitionguid_low);
QueryResult *result = CharacterDatabase.PQuery("SELECT type FROM petition WHERE petitionguid = '%u'", petitionguid_low);
if(!result)
{
sLog.outError("any petition on server...");
return;
}
Field *fields = result->Fetch();
uint32 type = fields[1].GetUInt32();
uint32 type = fields[0].GetUInt32();
delete result;

// if guild petition and has guild => error, return;
if(type==9 && _player->GetGuildId())
return;
Expand Down Expand Up @@ -317,6 +318,7 @@ void WorldSession::SendPetitionQueryOpcode(uint64 petitionguid)
QueryResult *result = CharacterDatabase.PQuery(
"SELECT ownerguid, name, "
" (SELECT COUNT(playerguid) FROM petition_sign WHERE petition_sign.petitionguid = '%u') AS signs "
"type "
"FROM petition WHERE petitionguid = '%u'", GUID_LOPART(petitionguid), GUID_LOPART(petitionguid));

if(result)
Expand All @@ -325,6 +327,7 @@ void WorldSession::SendPetitionQueryOpcode(uint64 petitionguid)
ownerguid = MAKE_NEW_GUID(fields[0].GetUInt32(), 0, HIGHGUID_PLAYER);
name = fields[1].GetCppString();
signs = fields[2].GetUInt8();
type = fields[3].GetUInt32();
delete result;
}
else
Expand All @@ -333,20 +336,6 @@ void WorldSession::SendPetitionQueryOpcode(uint64 petitionguid)
return;
}

QueryResult *result2 = CharacterDatabase.PQuery("SELECT type FROM petition WHERE petitionguid = '%u'", GUID_LOPART(petitionguid));

if(result2)
{
Field* fields = result2->Fetch();
type = fields[0].GetUInt32();
delete result2;
}
else
{
sLog.outDebug("CMSG_PETITION_QUERY failed for petition (GUID: %u)", GUID_LOPART(petitionguid));
return;
}

WorldPacket data(SMSG_PETITION_QUERY_RESPONSE, (4+8+name.size()+1+1+4*13));
data << GUID_LOPART(petitionguid); // guild/team guid (in mangos always same as GUID_LOPART(petition guid)
data << ownerguid; // charter owner guid
Expand Down Expand Up @@ -398,13 +387,13 @@ void WorldSession::HandlePetitionRenameOpcode(WorldPacket & recv_data)
if(!item)
return;

QueryResult *result2 = CharacterDatabase.PQuery("SELECT type FROM petition WHERE petitionguid = '%u'", GUID_LOPART(petitionguid));
QueryResult *result = CharacterDatabase.PQuery("SELECT type FROM petition WHERE petitionguid = '%u'", GUID_LOPART(petitionguid));

if(result2)
if(result)
{
Field* fields = result2->Fetch();
Field* fields = result->Fetch();
type = fields[0].GetUInt32();
delete result2;
delete result;
}
else
{
Expand Down Expand Up @@ -549,11 +538,9 @@ void WorldSession::HandlePetitionSignOpcode(WorldPacket & recv_data)
SendGuildCommandResult(GUILD_INVITE_S, _player->GetName(), ALREADY_INVITED_TO_GUILD);
return;
}
return;
}

signs += 1;
if(signs > type) // client signs maximum
if(++signs > type) // client signs maximum
return;

//client doesn't allow to sign petition two times by one character, but not check sign by another character from same account
Expand Down Expand Up @@ -637,14 +624,26 @@ void WorldSession::HandleOfferPetitionOpcode(WorldPacket & recv_data)

uint8 signs = 0;
uint64 petitionguid, plguid;
uint32 type;
uint32 type, junk;
Player *player;
recv_data >> type;
recv_data >> junk; // this is not petition type!
recv_data >> petitionguid; // petition guid
recv_data >> plguid; // player guid
sLog.outDebug("OFFER PETITION: type %u, GUID1 %u, to player id: %u", type, GUID_LOPART(petitionguid), GUID_LOPART(plguid));

player = ObjectAccessor::FindPlayer(plguid);
if (!player)
return;

QueryResult *result = CharacterDatabase.PQuery("SELECT type FROM petition WHERE petitionguid = '%u'", GUID_LOPART(petitionguid));
if (!result)
return;

Field *fields = result->Fetch();
type = fields[0].GetUInt32();
delete result;

sLog.outDebug("OFFER PETITION: type %u, GUID1 %u, to player id: %u", type, GUID_LOPART(petitionguid), GUID_LOPART(plguid));

if (!sWorld.getConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_GUILD) && GetPlayer()->GetTeam() != player->GetTeam() )
{
if(type != 9)
Expand Down Expand Up @@ -695,15 +694,6 @@ void WorldSession::HandleOfferPetitionOpcode(WorldPacket & recv_data)
}
}

QueryResult *result = CharacterDatabase.PQuery("SELECT petitionguid FROM petition WHERE petitionguid = '%u'", GUID_LOPART(petitionguid));
if(!result)
{
sLog.outError("any petition on server...");
return;
}

delete result;

result = CharacterDatabase.PQuery("SELECT playerguid FROM petition_sign WHERE petitionguid = '%u'", GUID_LOPART(petitionguid));
// result==NULL also correct charter without signs
if(result)
Expand Down
2 changes: 1 addition & 1 deletion src/shared/revision_nr.h
@@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "6912"
#define REVISION_NR "6913"
#endif // __REVISION_NR_H__

0 comments on commit f574317

Please sign in to comment.