PDA

View Full Version : Keyring


James76
09-14-2008, 01:01 PM
Discussion: http://eqemulator.net/forums/showthread.php?t=26177

Please forgive the indent loss. This should be straight-forward. The last modification in Doors::HandleClick, the /*NEW*/ lines indicate what to add, just look for the start and don't miss the curly braces.

================================================== ========================
[in SQL]

drop table if exists `keyring`;
create table `keyring`(
`char_id` integer not null,
`item_id` integer not null
) engine=MyISAM DEFAULT CHARSET=latin1;


================================================== ========================
[in ./common/database.cpp add to method Database::DeleteCharacter(char *name)]:

#if DEBUG >= 5
printf(" keyring");
#endif
RunQuery(query, MakeAnyLenString(&query, "DELETE FROM keyring WHERE char_id='%d'", charid), errbuf, NULL, &affected_rows);
if(query)
{
safe_delete_array(query);
query = NULL;
}


================================================== ========================
[in ./zone/client.h add to header:]
#include <list>


================================================== ========================
[in ./zone/client.h add to private section of Client class definition:]
std::list<int32> keyring;


================================================== ========================
[in ./zone/client.h add to public section of Client class definition:]
void KeyRingLoad();
void KeyRingAdd(int32 item_id);
bool KeyRingCheck(int32 item_id);
void KeyRingList();


================================================== ========================
[in ./zone/client.cpp add to constructor:]
keyring.clear();


================================================== ========================
[in ./zone/client.cpp add:]
void Client::KeyRingLoad()
{
char errbuf[MYSQL_ERRMSG_SIZE];
char *query = 0;
MYSQL_RES *result;
MYSQL_ROW row;
query = new char[256];

keyring.clear();
sprintf(query, "SELECT item_id FROM keyring WHERE char_id='%i' ORDER BY item_id",character_id);
if (database.RunQuery(query, strlen(query), errbuf, &result))
{
safe_delete_array(query);
while(0 != (row = mysql_fetch_row(result))){
keyring.push_back(atoi(row[0]));
}
mysql_free_result(result);
}else {
cerr << "Error in Client::KeyRingLoad query '" << query << "' " << errbuf << endl;
safe_delete_array(query);
return;
}
}

void Client::KeyRingAdd(int32 item_id)
{
char errbuf[MYSQL_ERRMSG_SIZE];
char *query = 0;
int32 affected_rows = 0;
query = new char[256];
bool bFound = KeyRingCheck(item_id);
if(!bFound){
sprintf(query, "INSERT INTO keyring(char_id,item_id) VALUES(%i,%i)",character_id,item_id);
if(database.RunQuery(query, strlen(query), errbuf, 0, &affected_rows))
{
Message(4,"Added to keyring.");
safe_delete_array(query);
}
else
{
cerr << "Error in Doors::HandleClick query '" << query << "' " << errbuf << endl;
safe_delete_array(query);
return;
}
keyring.push_back(item_id);
}
}

bool Client::KeyRingCheck(int32 item_id)
{
for(std::list<int32>::iterator iter = keyring.begin();
iter != keyring.end();
++iter)
{
if(*iter == item_id)
return true;
}
return false;
}

void Client::KeyRingList()
{
Message(4,"Keys on Keyring:");
const Item_Struct *item = 0;
for(std::list<int32>::iterator iter = keyring.begin();
iter != keyring.end();
++iter)
{
if ((item = database.GetItem(*iter))!=NULL) {
Message(4,item->Name);
}
}
}


================================================== ========================
[in ./common/emu_oplist.h add]
N(OP_KeyRing),


================================================== ========================
[in patch_Titanium.conf add]
OP_KeyRing=0x68c4


================================================== ========================
[in ./zone/client_packet.h add]
void Handle_OP_KeyRing(const EQApplicationPacket *app);


================================================== ========================
[in ./zone/client_packet.cpp in function MapOpcodes() add]
ConnectedOpcodes[OP_KeyRing] = &Client::Handle_OP_KeyRing;


================================================== ========================
[in ./zone/client_packet.cpp add]
void Client::Handle_OP_KeyRing(const EQApplicationPacket *app)
{
KeyRingList();
}


================================================== ========================
[in ./zone/client_packet.cpp, insert in Client::FinishConnState2() just after SetEndurance():]
KeyRingLoad();

================================================== ========================
[in ./zone/doors.cpp in method Doors::HandleClick(...) add code on lines]
if (sender->GetGM()) // GM can always open locks - should probably be changed to require a key
{
sender->Message_StringID(4,DOORS_GM);
if( !IsDoorOpen() || opentype == 58 )
{
md->action = OPEN_DOOR;
}
else
{
md->action = CLOSE_DOOR;
}
}
else if (playerkey)
{ // they have something they are trying to open it with
if (keyneeded && keyneeded == playerkey)
{ // key required and client is using the right key
/*NEW*/ sender->KeyRingAdd(playerkey);
sender->Message(4,"You got it open!"); // more debug spam
if( !IsDoorOpen() || opentype == 58 )
{
md->action = OPEN_DOOR;
}
else
{
md->action = CLOSE_DOOR;
}
}
}
else if(lockpicks != NULL)
{
if(sender->GetSkill(PICK_LOCK))
{
if(lockpicks->GetItem()->ItemType == ItemTypeLockPick)
{
float modskill=sender->GetSkill(PICK_LOCK);
sender->CheckIncreaseSkill(PICK_LOCK, 1);
#if EQDEBUG>=5
LogFile->write(EQEMuLog::Debug,"Client has lockpicks: skill=%f", modskill);
#endif

if(GetLockpick() <= modskill)
{
if(!IsDoorOpen())
{
md->action = OPEN_DOOR;
}
else
{
md->action = CLOSE_DOOR;
}
sender->Message_StringID(4,DOORS_SUCCESSFUL_PICK);
}
else
{
sender->Message_StringID(4,DOORS_INSUFFICIENT_SKILL);
return;
}
}
else
{
sender->Message_StringID(4,DOORS_NO_PICK);
return;
}
}
else
{
sender->Message_StringID(4,DOORS_CANT_PICK);
return;
}
}
else
{ // locked door and nothing to open it with
/*NEW*/ if(keyneeded != 0){
/*NEW*/ //search for key on keyring
/*NEW*/ if(sender->KeyRingCheck(keyneeded)){
/*NEW*/ sender->Message(4,"You got it open!"); // more debug spam
/*NEW*/ if( !IsDoorOpen() || opentype == 58 )
/*NEW*/ {
/*NEW*/ md->action = OPEN_DOOR;
/*NEW*/ }
/*NEW*/ else
/*NEW*/ {
/*NEW*/ md->action = CLOSE_DOOR;
/*NEW*/ }
/*NEW*/ }
/*NEW*/ }
/*NEW*/ else
/*NEW*/ {
sender->Message_StringID(4,DOORS_LOCKED);
return;
/*NEW*/ }
}

================================================== ========================

James76
09-14-2008, 09:03 PM
Great work! Would you mind posting a diff, or at the least approximate line numbers?

Sure, for the larger files, np. The rest is simple, just add your methods anywhere to the file (usually at bottom) or modify near the top..

Working down my list of mods,

line 493 ./common/database.cpp

line 46 ./zone/client.h (header section)
line 877 ./zone/client.h (private section)
line 190 ./zone/client.h (public section)

line 3281 ./zone/client.cpp (4 methods to insert)

line 318 ./zone/client_packet.cpp
line 7000 ./zone/client_packet.cpp (add Client::Handle_OP_KeyRing())
line 6436 ./zone/client_packet.cpp (mod FinishConnState2())

line 165 ./zone/doors.cpp (this is start of section)



You may find it easier to open some sort of text editor, copy my entire post over, and delete each section as you add it in.

James76
09-16-2008, 01:09 AM
ok I had some time to look at this... i disabled my code and I found I could click on the door for a while and it still wouldn't open. It looks like Client::Message_StringID(4,DOORS_LOCKED) has been hijacked with a flags check to unlock the door....

So one fix and one change.

In ./zone/doors.cpp it should look like:


// a key is required or the door is locked but can be picked or both
sender->Message(4,"This is locked..."); // debug spam - should probably go
if (sender->GetGM()) // GM can always open locks - should probably be changed to require a key
{
sender->Message_StringID(4,DOORS_GM);
if( !IsDoorOpen() || opentype == 58 )
{
md->action = OPEN_DOOR;
}
else
{
md->action = CLOSE_DOOR;
}
}
else if (playerkey)
{ // they have something they are trying to open it with
if (keyneeded && keyneeded == playerkey)
{ // key required and client is using the right key
/*NEW*/ sender->KeyRingAdd(playerkey);
sender->Message(4,"You got it open!"); // more debug spam
if( !IsDoorOpen() || opentype == 58 )
{
md->action = OPEN_DOOR;
}
else
{
md->action = CLOSE_DOOR;
}
}
}
else if(lockpicks != NULL)
{
if(sender->GetSkill(PICK_LOCK))
{
if(lockpicks->GetItem()->ItemType == ItemTypeLockPick)
{
float modskill=sender->GetSkill(PICK_LOCK);
sender->CheckIncreaseSkill(PICK_LOCK, 1);
#if EQDEBUG>=5
LogFile->write(EQEMuLog::Debug,"Client has lockpicks: skill=%f", modskill);
#endif

if(GetLockpick() <= modskill)
{
if(!IsDoorOpen())
{
md->action = OPEN_DOOR;
}
else
{
md->action = CLOSE_DOOR;
}
sender->Message_StringID(4,DOORS_SUCCESSFUL_PICK);
}
else
{
sender->Message_StringID(4,DOORS_INSUFFICIENT_SKILL);
return;
}
}
else
{
sender->Message_StringID(4,DOORS_NO_PICK);
return;
}
}
else
{
sender->Message_StringID(4,DOORS_CANT_PICK);
return;
}
}
else
{ // locked door and nothing to open it with
//search for key on keyring
/*NEW*/ if(sender->KeyRingCheck(keyneeded)){
/*NEW*/ sender->Message(4,"You got it open!"); // more debug spam
/*NEW*/ if( !IsDoorOpen() || opentype == 58 )
/*NEW*/ {
/*NEW*/ md->action = OPEN_DOOR;
/*NEW*/ }
/*NEW*/ else
/*NEW*/ {
/*NEW*/ md->action = CLOSE_DOOR;
/*NEW*/ }
/*NEW*/ }
/*NEW*/ else
/*NEW*/ {
sender->Message_StringID(4,DOORS_LOCKED);
return;
/*NEW*/ }
}
}



Then in ./zone/client.cpp add to very start of Client::KeyRingAdd()

if(0==item_id)return;

Now the PoI factory door works. The message is still FUNKY but whatever.

Angelox
09-29-2008, 07:17 AM
Here's a fix for what I think were non working clicky-portals - what would happen is, for instance if I clicked on the zin to chariasis, I'd get the 'locked' message and zone anyways (any clicky zone that required a key would return 'locked' and port you anyway);

in doors.cpp at around line 287 replace this;
if (opentype == 58 && strncmp(dest_zone,"NONE",strlen("NONE")) != 0 ){ // Teleport door!
if ( strncmp(dest_zone,zone_name,strlen(zone_name)) == 0) {
//dunno why, but this dosent seem to work all the time:
//sender->GMMove(dest_x,dest_y,dest_z);
sender->MovePC(dest_x, dest_y, dest_z, dest_heading);
}
else {
sender->MovePC(dest_zone, dest_x, dest_y, dest_z, dest_heading);
}
}
}

with this;

if (opentype == 58 && strncmp(dest_zone,"NONE",strlen("NONE")) != 0 ){ // Teleport door!
if (( strncmp(dest_zone,zone_name,strlen(zone_name)) == 0) && (keyneeded && keyneeded == playerkey)) {
sender->KeyRingAdd(playerkey);
sender->MovePC(dest_x, dest_y, dest_z, dest_heading);
}
if (( strncmp(dest_zone,zone_name,strlen(zone_name)) == 0) && (!keyneeded)) {
sender->MovePC(dest_x, dest_y, dest_z, dest_heading);
}
else if (( !IsDoorOpen() || opentype == 58 ) && (keyneeded && keyneeded == playerkey)) {
sender->KeyRingAdd(playerkey);
sender->MovePC(dest_zone, dest_x, dest_y, dest_z, dest_heading);
}
if (( !IsDoorOpen() || opentype == 58 ) && (!keyneeded)) {
sender->MovePC(dest_zone, dest_x, dest_y, dest_z, dest_heading);
}
}
}


I tested under many circumstances (PoK stone, Charasis, Paineel entrance, FrozenShadow mirrors, etc.) , seems to work ok.
You need '#gm off' to see keys work properly