• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Compiling Register duplicate UID in a log [CPP]

Dankoo

Active Member
Joined
Sep 4, 2010
Messages
1,007
Reaction score
27
I'm trying to modify this luascript.cpp function:

[cpp]void ScriptEnviroment::addUniqueThing(Thing* thing)
{
Item* item = thing->getItem();
if(!item || !item->getUniqueId())
return;

if(m_globalMap[item->getUniqueId()])
{
if(item->getActionId() != 2000) //scripted quest system
std::clog << "Duplicate uniqueId " << item->getUniqueId() << std::endl;
}
else
m_globalMap[item->getUniqueId()] = thing;
}[/cpp]

To save the "Duplicate uniqueID" warning in logs/duplicate.txt

Any ideas? ;)
 
Hmm, i have some idea...

luascript.cpp

under:
[cpp]
#include "vocation.h"
[/cpp]
add:
[cpp]
#include "textlogger.h"
[/cpp]

under:
[cpp]
std::clog << "Duplicate uniqueId " << item->getUniqueId() << std::endl;
[/cpp]
add:
[cpp]
std::stringstream s;
s << item->getUniqueId();
Logger::getInstance()->eFile("duplicate/" + item->getName() + ".log", "Item duplicated: " + s.str() + " - auto reported", true);
[/cpp]

and F9
 
Compilling, edit in a few

-edit-

Hmm, unfornately it doesn't seems to work, I can't find the log

It was suppose to be in data/logs?

I've checked all files (via date modification), and there's no log being set

Also, the message "Item duplicated: " + s.str() + " - auto reported" should appear in console? 'Cause it isn't appearing

PS: I've deleted only luascript.o and recompiled, should I delete all .o files?
 
Last edited:
How do you test a duplicate uid?
I have tested in actions.xml..
100% work, If you do not believe this check..
under:
[cpp]

#include <libxml/parser.h>
[/cpp]
add:
[cpp]

#include "textlogger.h"
[/cpp]

under
[cpp]
std::clog << "[Warning - Actions::registerEvent] Duplicate registered item uid: " << intVector[0] << std::endl;
[/cpp]

add
[cpp]
std::stringstream s;
s << intVector[0];
Logger::getInstance()->eFile("duplicate/x.log", "Item duplicated: " + s.str() + " - auto reported", true);
[/cpp]

F9

actions.xml
Code:
	<action uniqueid="30015" event="script" value="quests/annihilator.lua"/>
	<action uniqueid="30015" event="script" value="quests/system.lua"/>

and data/logs/duplicate/x.log

Code:
[10/6/2011 15:49:14] Item duplicated: 30015 - auto reported

PS: I do not know how you can test that displays a log of your luascript .. oO
 
Last edited:
Like this, eh?

luascript.cpp
[cpp]void ScriptEnviroment::addUniqueThing(Thing* thing)
{
Item* item = thing->getItem();
if(!item || !item->getUniqueId())
return;

if(m_globalMap[item->getUniqueId()])
{
if(item->getActionId() != 2000) //scripted quest system
std::clog << "Duplicate uniqueId " << item->getUniqueId() << std::endl;
std::stringstream s;
s << item->getUniqueId();
Logger::getInstance()->eFile("duplicate/" + item->getName() + ".log", "Item duplicated: " + s.str() + " - auto reported", true);
}
else
m_globalMap[item->getUniqueId()] = thing;
}[/cpp]

actions.cpp

[cpp] if(uniqueItemMap.find(intVector[0]) != uniqueItemMap.end())
{
if(!override)
{
std::clog << "[Warning - Actions::registerEvent] Duplicate registered item uid: " << intVector[0] << std::endl;
std::stringstream s;
s << intVector[0];
Logger::getInstance()->eFile("duplicate/x.log", "Item duplicated: " + s.str() + " - auto reported", true);
success = false;
}
else
delete uniqueItemMap[intVector[0]];
}[/cpp]

I'm compiling and edit in a few

-- EDIT --
Weird, but doesn't seems to work... Should I modify actions.h and luascript.h as well?

I've tried to duplicate actions.xml's uniqueid and also didn't logged

In actions I received "[Warning - Actions::registerEvent] Duplicate registered item uid: 3134"
When holding two items with same UID I received "Duplicate uniqueID 34023"

But none of them logged

PS: I'M USING REV 0.4!! (I was donator)

textlogger.h

[cpp]////////////////////////////////////////////////////////////////////////
// OpenTibia - an opensource roleplaying game
////////////////////////////////////////////////////////////////////////
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
////////////////////////////////////////////////////////////////////////

#ifndef __TEXTLOGGER__
#define __TEXTLOGGER__
#include "otsystem.h"

enum LogFile_t
{
LOGFILE_FIRST = 0,
LOGFILE_ADMIN = LOGFILE_FIRST,
LOGFILE_OUTPUT = 1,
LOGFILE_ASSERTIONS = 2,
LOGFILE_LAST = LOGFILE_ASSERTIONS
};

enum LogType_t
{
LOGTYPE_EVENT,
LOGTYPE_NOTICE,
LOGTYPE_WARNING,
LOGTYPE_ERROR,
};

class Logger
{
public:
virtual ~Logger() {close();}
static Logger* getInstance()
{
static Logger instance;
return &instance;
}

void open();
void close();

bool isLoaded() const {return m_loaded;}

void iFile(LogFile_t file, std::string output, bool newLine);
void eFile(std::string file, std::string output, bool newLine);

void log(const char* func, LogType_t type, std::string message, std::string channel = "", bool newLine = true);

private:
Logger() {m_loaded = false;}
void internal(FILE* file, std::string output, bool newLine);

FILE* m_files[LOGFILE_LAST + 1];
bool m_loaded;
};

#define LOG_MESSAGE(type, message, channel) \
Logger::getInstance()->log(__PRETTY_FUNCTION__, type, message, channel);

class OutputHandler : public std::streambuf
{
public:
virtual ~OutputHandler();
static OutputHandler* getInstance()
{
static OutputHandler instance;
return &instance;
}

protected:
OutputHandler();
std::streambuf::int_type overflow(std::streambuf::int_type c = traits_type::eof());

std::streambuf* log;
std::streambuf* err;
std::string m_cache;
};
#endif
[/cpp]
 
Last edited:
that's weird, it's simply not working.

I've added all the codes and stuff, created duplicate folder in data/logs, deleted all temporary source files (with .o extension) and tried to recompile, and don't work...

The weirdest is that the code seems to be right, as we can check with this protocolgame.cpp log function:

[cpp] const std::string text = msg.getString();
if(text.length() > 255) //client limit
{
std::stringstream s;
s << text.length();

Logger::getInstance()->eFile("bots/" + player->getName() + ".log", "Attempt to send message with size " + s.str() + " - client is limited to 255 characters.", true);
return;
}[/cpp]

[cpp]void ProtocolGame::parseHouseWindow(NetworkMessage &msg)
{
uint8_t doorId = msg.get<char>();
uint32_t id = msg.get<uint32_t>();
const std::string text = msg.getString();
addGameTask(&Game::playerUpdateHouseWindow, player->getID(), doorId, id, text);
}[/cpp]

crimm, you've tried a lot to help, I appreciate this a lot, rep+

I'll see here if I can find alternate ways to do this... I'll keep tryin' thanks!!
 
Last edited:
Back
Top Bottom