From 2c6eba93ae0c4ba28c445d40b6e74ba926de86c0 Mon Sep 17 00:00:00 2001 From: KimLS Date: Sat, 31 Jan 2015 22:21:52 -0800 Subject: [PATCH] Back to ST profiling, wont bother profiling the common library for now. --- common/CMakeLists.txt | 2 + common/eq_packet.cpp | 30 ---- common/eq_stream.cpp | 42 ------ common/eq_stream_factory.cpp | 5 - common/eqemu_logsys.cpp | 13 -- common/uuid.cpp | 44 ++++++ common/uuid.h | 26 ++++ eqperf/CMakeLists.txt | 4 +- eqperf/eqp_profile_event.cpp | 12 +- eqperf/eqp_profile_event.h | 3 + eqperf/eqp_profile_function.h | 3 +- eqperf/eqp_profiler.cpp | 57 ++++++-- eqperf/eqp_profiler.h | 13 +- eqperf/eqp_profiler_node.cpp | 4 +- loginserver/CMakeLists.txt | 4 +- loginserver/client.cpp | 17 ++- loginserver/client_manager.cpp | 15 +- loginserver/config.cpp | 7 +- loginserver/database_mysql.cpp | 17 ++- loginserver/database_postgresql.cpp | 12 +- loginserver/encryption.cpp | 17 ++- loginserver/error_log.cpp | 214 ---------------------------- loginserver/error_log.h | 79 ---------- loginserver/login_server.h | 1 - loginserver/main.cpp | 2 +- loginserver/server_manager.cpp | 19 ++- loginserver/world_server.cpp | 15 +- 27 files changed, 194 insertions(+), 483 deletions(-) create mode 100644 common/uuid.cpp create mode 100644 common/uuid.h delete mode 100644 loginserver/error_log.cpp delete mode 100644 loginserver/error_log.h diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 4ee46a41f..a11a2378d 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -62,6 +62,7 @@ SET(common_sources timeoutmgr.cpp timer.cpp unix.cpp + uuid.cpp worldconn.cpp xml_parser.cpp platform.cpp @@ -181,6 +182,7 @@ SET(common_headers types.h unix.h useperl.h + uuid.h version.h worldconn.h xml_parser.h diff --git a/common/eq_packet.cpp b/common/eq_packet.cpp index 9b2b77577..3486beca2 100644 --- a/common/eq_packet.cpp +++ b/common/eq_packet.cpp @@ -39,11 +39,9 @@ EQPacket::EQPacket(EmuOpcode op, const unsigned char *buf, uint32 len) : BasePacket(buf, len), emu_opcode(op) { - _eqp_mt } void EQPacket::build_raw_header_dump(char *buffer, uint16 seq) const { - _eqp_mt BasePacket::build_raw_header_dump(buffer, seq); buffer += strlen(buffer); @@ -52,20 +50,17 @@ void EQPacket::build_raw_header_dump(char *buffer, uint16 seq) const { void EQPacket::DumpRawHeader(uint16 seq, FILE *to) const { - _eqp_mt char buff[196]; build_raw_header_dump(buff, seq); fprintf(to, "%s", buff); } void EQPacket::build_header_dump(char *buffer) const { - _eqp_mt sprintf(buffer, "[EmuOpCode 0x%04x Size=%u]", emu_opcode, size); } void EQPacket::DumpRawHeaderNoTime(uint16 seq, FILE *to) const { - _eqp_mt if (src_ip) { std::string sIP,dIP;; sIP=long2ip(src_ip); @@ -80,7 +75,6 @@ void EQPacket::DumpRawHeaderNoTime(uint16 seq, FILE *to) const void EQProtocolPacket::build_raw_header_dump(char *buffer, uint16 seq) const { - _eqp_mt BasePacket::build_raw_header_dump(buffer, seq); buffer += strlen(buffer); @@ -89,7 +83,6 @@ void EQProtocolPacket::build_raw_header_dump(char *buffer, uint16 seq) const void EQProtocolPacket::DumpRawHeader(uint16 seq, FILE *to) const { - _eqp_mt char buff[196]; build_raw_header_dump(buff, seq); fprintf(to, "%s", buff); @@ -97,13 +90,11 @@ void EQProtocolPacket::DumpRawHeader(uint16 seq, FILE *to) const void EQProtocolPacket::build_header_dump(char *buffer) const { - _eqp_mt sprintf(buffer, "[ProtoOpCode 0x%04x Size=%u]",opcode,size); } void EQProtocolPacket::DumpRawHeaderNoTime(uint16 seq, FILE *to) const { - _eqp_mt if (src_ip) { std::string sIP,dIP;; sIP=long2ip(src_ip); @@ -118,7 +109,6 @@ void EQProtocolPacket::DumpRawHeaderNoTime(uint16 seq, FILE *to) const void EQApplicationPacket::build_raw_header_dump(char *buffer, uint16 seq) const { - _eqp_mt BasePacket::build_raw_header_dump(buffer, seq); buffer += strlen(buffer); @@ -131,7 +121,6 @@ void EQApplicationPacket::build_raw_header_dump(char *buffer, uint16 seq) const void EQApplicationPacket::DumpRawHeader(uint16 seq, FILE *to) const { - _eqp_mt char buff[196]; build_raw_header_dump(buff, seq); fprintf(to, "%s", buff); @@ -139,7 +128,6 @@ void EQApplicationPacket::DumpRawHeader(uint16 seq, FILE *to) const void EQApplicationPacket::build_header_dump(char *buffer) const { - _eqp_mt #ifdef STATIC_OPCODE sprintf(buffer, "[OpCode 0x%04x Size=%u]\n", emu_opcode,size); #else @@ -149,7 +137,6 @@ void EQApplicationPacket::build_header_dump(char *buffer) const void EQApplicationPacket::DumpRawHeaderNoTime(uint16 seq, FILE *to) const { - _eqp_mt if (src_ip) { std::string sIP,dIP;; sIP=long2ip(src_ip); @@ -168,7 +155,6 @@ void EQApplicationPacket::DumpRawHeaderNoTime(uint16 seq, FILE *to) const void EQRawApplicationPacket::build_raw_header_dump(char *buffer, uint16 seq) const { - _eqp_mt BasePacket::build_raw_header_dump(buffer, seq); buffer += strlen(buffer); @@ -181,7 +167,6 @@ void EQRawApplicationPacket::build_raw_header_dump(char *buffer, uint16 seq) con void EQRawApplicationPacket::DumpRawHeader(uint16 seq, FILE *to) const { - _eqp_mt char buff[196]; build_raw_header_dump(buff, seq); fprintf(to, "%s", buff); @@ -189,7 +174,6 @@ void EQRawApplicationPacket::DumpRawHeader(uint16 seq, FILE *to) const void EQRawApplicationPacket::build_header_dump(char *buffer) const { - _eqp_mt #ifdef STATIC_OPCODE sprintf(buffer, "[OpCode 0x%04x (0x%04x) Size=%u]\n", emu_opcode, opcode,size); #else @@ -199,7 +183,6 @@ void EQRawApplicationPacket::build_header_dump(char *buffer) const void EQRawApplicationPacket::DumpRawHeaderNoTime(uint16 seq, FILE *to) const { - _eqp_mt if (src_ip) { std::string sIP,dIP;; sIP=long2ip(src_ip); @@ -218,7 +201,6 @@ void EQRawApplicationPacket::DumpRawHeaderNoTime(uint16 seq, FILE *to) const uint32 EQProtocolPacket::serialize(unsigned char *dest) const { - _eqp_mt if (opcode>0xff) { *(uint16 *)dest=opcode; } else { @@ -232,7 +214,6 @@ uint32 EQProtocolPacket::serialize(unsigned char *dest) const uint32 EQApplicationPacket::serialize(uint16 opcode, unsigned char *dest) const { - _eqp_mt uint8 OpCodeBytes = app_opcode_size; if (app_opcode_size==1) @@ -256,7 +237,6 @@ uint32 EQApplicationPacket::serialize(uint16 opcode, unsigned char *dest) const bool EQProtocolPacket::combine(const EQProtocolPacket *rhs) { - _eqp_mt bool result=false; if (opcode==OP_Combined && size+rhs->size+5<256) { unsigned char *tmpbuffer=new unsigned char [size+rhs->size+3]; @@ -288,7 +268,6 @@ bool EQProtocolPacket::combine(const EQProtocolPacket *rhs) bool EQProtocolPacket::ValidateCRC(const unsigned char *buffer, int length, uint32 Key) { - _eqp_mt bool valid=false; // OP_SessionRequest, OP_SessionResponse, OP_OutOfSession are not CRC'd if (buffer[0]==0x00 && (buffer[1]==OP_SessionRequest || buffer[1]==OP_SessionResponse || buffer[1]==OP_OutOfSession)) { @@ -308,7 +287,6 @@ bool EQProtocolPacket::ValidateCRC(const unsigned char *buffer, int length, uint uint32 EQProtocolPacket::Decompress(const unsigned char *buffer, const uint32 length, unsigned char *newbuf, uint32 newbufsize) { - _eqp_mt uint32 newlen=0; uint32 flag_offset=0; newbuf[0]=buffer[0]; @@ -334,7 +312,6 @@ uint32 EQProtocolPacket::Decompress(const unsigned char *buffer, const uint32 le } uint32 EQProtocolPacket::Compress(const unsigned char *buffer, const uint32 length, unsigned char *newbuf, uint32 newbufsize) { - _eqp_mt uint32 flag_offset=1,newlength; //dump_message_column(buffer,length,"Before: "); newbuf[0]=buffer[0]; @@ -358,7 +335,6 @@ uint32 EQProtocolPacket::Compress(const unsigned char *buffer, const uint32 leng void EQProtocolPacket::ChatDecode(unsigned char *buffer, int size, int DecodeKey) { - _eqp_mt if ((size >= 2) && buffer[1]!=0x01 && buffer[0]!=0x02 && buffer[0]!=0x1d) { int Key=DecodeKey; unsigned char *test=(unsigned char *)malloc(size); @@ -384,7 +360,6 @@ void EQProtocolPacket::ChatDecode(unsigned char *buffer, int size, int DecodeKey void EQProtocolPacket::ChatEncode(unsigned char *buffer, int size, int EncodeKey) { - _eqp_mt if (buffer[1]!=0x01 && buffer[0]!=0x02 && buffer[0]!=0x1d) { int Key=EncodeKey; char *test=(char*)malloc(size); @@ -408,12 +383,10 @@ void EQProtocolPacket::ChatEncode(unsigned char *buffer, int size, int EncodeKey } EQApplicationPacket *EQApplicationPacket::Copy() const { - _eqp_mt return(new EQApplicationPacket(*this)); } EQRawApplicationPacket *EQProtocolPacket::MakeAppPacket() const { - _eqp_mt EQRawApplicationPacket *res = new EQRawApplicationPacket(opcode, pBuffer, size); res->copyInfo(this); return(res); @@ -423,12 +396,10 @@ EQRawApplicationPacket::EQRawApplicationPacket(uint16 opcode, const unsigned cha : EQApplicationPacket(OP_Unknown, buf, len), opcode(opcode) { - _eqp_mt } EQRawApplicationPacket::EQRawApplicationPacket(const unsigned char *buf, const uint32 len) : EQApplicationPacket(OP_Unknown, buf+sizeof(uint16), len-sizeof(uint16)) { - _eqp_mt if(GetExecutablePlatform() != ExePlatformUCS) { opcode = *((const uint16 *) buf); if(opcode == 0x0000) @@ -462,7 +433,6 @@ EQRawApplicationPacket::EQRawApplicationPacket(const unsigned char *buf, const u } void DumpPacket(const EQApplicationPacket* app, bool iShowInfo) { - _eqp_mt if (iShowInfo) { std::cout << "Dumping Applayer: 0x" << std::hex << std::setfill('0') << std::setw(4) << app->GetOpcode() << std::dec; std::cout << " size:" << app->size << std::endl; diff --git a/common/eq_stream.cpp b/common/eq_stream.cpp index 6005a6d9c..d4264e55f 100644 --- a/common/eq_stream.cpp +++ b/common/eq_stream.cpp @@ -49,7 +49,6 @@ uint16 EQStream::MaxWindowSize=2048; void EQStream::init(bool resetSession) { - _eqp_mt // we only reset these statistics if it is a 'new' connection if ( resetSession ) { @@ -92,7 +91,6 @@ void EQStream::init(bool resetSession) { EQRawApplicationPacket *EQStream::MakeApplicationPacket(EQProtocolPacket *p) { - _eqp_mt EQRawApplicationPacket *ap=nullptr; Log.Out(Logs::Detail, Logs::Netcode, _L "Creating new application packet, length %d" __L, p->size); // _raw(NET__APP_CREATE_HEX, 0xFFFF, p); @@ -102,7 +100,6 @@ EQRawApplicationPacket *EQStream::MakeApplicationPacket(EQProtocolPacket *p) EQRawApplicationPacket *EQStream::MakeApplicationPacket(const unsigned char *buf, uint32 len) { - _eqp_mt EQRawApplicationPacket *ap=nullptr; Log.Out(Logs::Detail, Logs::Netcode, _L "Creating new application packet, length %d" __L, len); ap = new EQRawApplicationPacket(buf, len); @@ -110,7 +107,6 @@ EQRawApplicationPacket *EQStream::MakeApplicationPacket(const unsigned char *buf } EQProtocolPacket *EQStream::MakeProtocolPacket(const unsigned char *buf, uint32 len) { - _eqp_mt uint16 proto_opcode = ntohs(*(const uint16 *)buf); //advance over opcode. @@ -122,7 +118,6 @@ EQProtocolPacket *EQStream::MakeProtocolPacket(const unsigned char *buf, uint32 void EQStream::ProcessPacket(EQProtocolPacket *p) { - _eqp_mt uint32 processed=0, subpacket_length=0; if (p == nullptr) return; @@ -520,7 +515,6 @@ void EQStream::ProcessPacket(EQProtocolPacket *p) void EQStream::QueuePacket(const EQApplicationPacket *p, bool ack_req) { - _eqp_mt if(p == nullptr) return; @@ -532,7 +526,6 @@ void EQStream::QueuePacket(const EQApplicationPacket *p, bool ack_req) void EQStream::FastQueuePacket(EQApplicationPacket **p, bool ack_req) { - _eqp_mt EQApplicationPacket *pack=*p; *p = nullptr; //clear caller's pointer.. effectively takes ownership @@ -562,7 +555,6 @@ void EQStream::FastQueuePacket(EQApplicationPacket **p, bool ack_req) void EQStream::SendPacket(uint16 opcode, EQApplicationPacket *p) { - _eqp_mt uint32 chunksize,used; uint32 length; @@ -607,7 +599,6 @@ void EQStream::SendPacket(uint16 opcode, EQApplicationPacket *p) void EQStream::SequencedPush(EQProtocolPacket *p) { - _eqp_mt #ifdef COLLECTOR delete p; #else @@ -636,7 +627,6 @@ if(NextSequencedSend > SequencedQueue.size()) { void EQStream::NonSequencedPush(EQProtocolPacket *p) { - _eqp_mt #ifdef COLLECTOR delete p; #else @@ -649,7 +639,6 @@ void EQStream::NonSequencedPush(EQProtocolPacket *p) void EQStream::SendAck(uint16 seq) { - _eqp_mt uint16 Seq=htons(seq); Log.Out(Logs::Detail, Logs::Netcode, _L "Sending ack with sequence %d" __L, seq); SetLastAckSent(seq); @@ -658,7 +647,6 @@ void EQStream::SendAck(uint16 seq) void EQStream::SendOutOfOrderAck(uint16 seq) { - _eqp_mt Log.Out(Logs::Detail, Logs::Netcode, _L "Sending out of order ack with sequence %d" __L, seq); uint16 Seq=htons(seq); NonSequencedPush(new EQProtocolPacket(OP_OutOfOrderAck,(unsigned char *)&Seq,sizeof(uint16))); @@ -666,7 +654,6 @@ uint16 Seq=htons(seq); void EQStream::Write(int eq_fd) { - _eqp_mt std::queue ReadyToSend; bool SeqEmpty=false, NonSeqEmpty=false; std::deque::iterator sitr; @@ -862,7 +849,6 @@ void EQStream::Write(int eq_fd) void EQStream::WritePacket(int eq_fd, EQProtocolPacket *p) { - _eqp_mt uint32 length; sockaddr_in address; address.sin_family = AF_INET; @@ -901,7 +887,6 @@ void EQStream::WritePacket(int eq_fd, EQProtocolPacket *p) void EQStream::SendSessionResponse() { - _eqp_mt EQProtocolPacket *out=new EQProtocolPacket(OP_SessionResponse,nullptr,sizeof(SessionResponse)); SessionResponse *Response=(SessionResponse *)out->pBuffer; Response->Session=htonl(Session); @@ -924,7 +909,6 @@ void EQStream::SendSessionResponse() void EQStream::SendSessionRequest() { - _eqp_mt EQProtocolPacket *out=new EQProtocolPacket(OP_SessionRequest,nullptr,sizeof(SessionRequest)); SessionRequest *Request=(SessionRequest *)out->pBuffer; memset(Request,0,sizeof(SessionRequest)); @@ -938,7 +922,6 @@ void EQStream::SendSessionRequest() void EQStream::_SendDisconnect() { - _eqp_mt if(GetState() == CLOSED) return; @@ -951,7 +934,6 @@ void EQStream::_SendDisconnect() void EQStream::InboundQueuePush(EQRawApplicationPacket *p) { - _eqp_mt MInboundQueue.lock(); InboundQueue.push_back(p); MInboundQueue.unlock(); @@ -959,7 +941,6 @@ void EQStream::InboundQueuePush(EQRawApplicationPacket *p) EQApplicationPacket *EQStream::PopPacket() { - _eqp_mt EQRawApplicationPacket *p=nullptr; MInboundQueue.lock(); @@ -987,7 +968,6 @@ EQApplicationPacket *EQStream::PopPacket() EQRawApplicationPacket *EQStream::PopRawPacket() { - _eqp_mt EQRawApplicationPacket *p=nullptr; MInboundQueue.lock(); @@ -1015,7 +995,6 @@ EQRawApplicationPacket *EQStream::PopRawPacket() EQRawApplicationPacket *EQStream::PeekPacket() { - _eqp_mt EQRawApplicationPacket *p=nullptr; MInboundQueue.lock(); @@ -1030,7 +1009,6 @@ EQRawApplicationPacket *EQStream::PeekPacket() void EQStream::InboundQueueClear() { - _eqp_mt EQApplicationPacket *p=nullptr; Log.Out(Logs::Detail, Logs::Netcode, _L "Clearing inbound queue" __L); @@ -1049,7 +1027,6 @@ void EQStream::InboundQueueClear() bool EQStream::HasOutgoingData() { - _eqp_mt bool flag; //once closed, we have nothing more to say @@ -1075,7 +1052,6 @@ bool EQStream::HasOutgoingData() void EQStream::OutboundQueueClear() { - _eqp_mt EQProtocolPacket *p=nullptr; Log.Out(Logs::Detail, Logs::Netcode, _L "Clearing outbound queue" __L); @@ -1098,7 +1074,6 @@ void EQStream::OutboundQueueClear() void EQStream::PacketQueueClear() { - _eqp_mt EQProtocolPacket *p=nullptr; Log.Out(Logs::Detail, Logs::Netcode, _L "Clearing future packet queue" __L); @@ -1115,7 +1090,6 @@ void EQStream::PacketQueueClear() void EQStream::Process(const unsigned char *buffer, const uint32 length) { - _eqp_mt static unsigned char newbuffer[2048]; uint32 newlength=0; if (EQProtocolPacket::ValidateCRC(buffer,length,Key)) { @@ -1140,7 +1114,6 @@ void EQStream::Process(const unsigned char *buffer, const uint32 length) long EQStream::GetNextAckToSend() { - _eqp_mt MAcks.lock(); long l=NextAckToSend; MAcks.unlock(); @@ -1150,7 +1123,6 @@ long EQStream::GetNextAckToSend() long EQStream::GetLastAckSent() { - _eqp_mt MAcks.lock(); long l=LastAckSent; MAcks.unlock(); @@ -1160,7 +1132,6 @@ long EQStream::GetLastAckSent() void EQStream::AckPackets(uint16 seq) { - _eqp_mt std::deque::iterator itr, tmp; MOutboundQueue.lock(); @@ -1215,7 +1186,6 @@ void EQStream::AckPackets(uint16 seq) void EQStream::SetNextAckToSend(uint32 seq) { - _eqp_mt MAcks.lock(); Log.Out(Logs::Detail, Logs::Netcode, _L "Set Next Ack To Send to %lu" __L, (unsigned long)seq); NextAckToSend=seq; @@ -1224,7 +1194,6 @@ void EQStream::SetNextAckToSend(uint32 seq) void EQStream::SetLastAckSent(uint32 seq) { - _eqp_mt MAcks.lock(); Log.Out(Logs::Detail, Logs::Netcode, _L "Set Last Ack Sent to %lu" __L, (unsigned long)seq); LastAckSent=seq; @@ -1233,7 +1202,6 @@ void EQStream::SetLastAckSent(uint32 seq) void EQStream::ProcessQueue() { - _eqp_mt if(PacketQueue.empty()) { return; } @@ -1249,7 +1217,6 @@ void EQStream::ProcessQueue() EQProtocolPacket *EQStream::RemoveQueue(uint16 seq) { - _eqp_mt std::map::iterator itr; EQProtocolPacket *qp=nullptr; if ((itr=PacketQueue.find(seq))!=PacketQueue.end()) { @@ -1262,7 +1229,6 @@ EQProtocolPacket *EQStream::RemoveQueue(uint16 seq) void EQStream::SetStreamType(EQStreamType type) { - _eqp_mt Log.Out(Logs::Detail, Logs::Netcode, _L "Changing stream type from %s to %s" __L, StreamTypeString(StreamType), StreamTypeString(type)); StreamType=type; switch (StreamType) { @@ -1293,7 +1259,6 @@ void EQStream::SetStreamType(EQStreamType type) const char *EQStream::StreamTypeString(EQStreamType t) { - _eqp_mt switch (t) { case LoginStream: return "Login"; @@ -1323,7 +1288,6 @@ const char *EQStream::StreamTypeString(EQStreamType t) //returns SeqFuture if `seq` is later than `expected_seq` EQStream::SeqOrder EQStream::CompareSequence(uint16 expected_seq , uint16 seq) { - _eqp_mt if (expected_seq==seq) { // Curent return SeqInOrder; @@ -1337,7 +1301,6 @@ EQStream::SeqOrder EQStream::CompareSequence(uint16 expected_seq , uint16 seq) } void EQStream::SetState(EQStreamState state) { - _eqp_mt MState.lock(); Log.Out(Logs::Detail, Logs::Netcode, _L "Changing state from %d to %d" __L, State, state); State=state; @@ -1346,7 +1309,6 @@ void EQStream::SetState(EQStreamState state) { void EQStream::CheckTimeout(uint32 now, uint32 timeout) { - _eqp_mt bool outgoing_data = HasOutgoingData(); //up here to avoid recursive locking EQStreamState orig_state = GetState(); @@ -1385,7 +1347,6 @@ void EQStream::CheckTimeout(uint32 now, uint32 timeout) { void EQStream::Decay() { - _eqp_mt MRate.lock(); uint32 rate=DecayRate; MRate.unlock(); @@ -1398,7 +1359,6 @@ void EQStream::Decay() void EQStream::AdjustRates(uint32 average_delta) { - _eqp_mt if(GetExecutablePlatform() == ExePlatformWorld || GetExecutablePlatform() == ExePlatformZone) { if (average_delta && (average_delta <= AVERAGE_DELTA_MAX)) { MRate.lock(); @@ -1424,7 +1384,6 @@ void EQStream::AdjustRates(uint32 average_delta) } void EQStream::Close() { - _eqp_mt if(HasOutgoingData()) { //there is pending data, wait for it to go out. Log.Out(Logs::Detail, Logs::Netcode, _L "Stream requested to Close(), but there is pending data, waiting for it." __L); @@ -1441,7 +1400,6 @@ void EQStream::Close() { //this could be expanded to check more than the fitst opcode if //we needed more complex matching EQStream::MatchState EQStream::CheckSignature(const Signature *sig) { - _eqp_mt EQRawApplicationPacket *p = nullptr; MatchState res = MatchNotReady; diff --git a/common/eq_stream_factory.cpp b/common/eq_stream_factory.cpp index 205be8418..9a227994b 100644 --- a/common/eq_stream_factory.cpp +++ b/common/eq_stream_factory.cpp @@ -65,7 +65,6 @@ EQStreamFactory::EQStreamFactory(EQStreamType type, int port, uint32 timeout) void EQStreamFactory::Close() { - _eqp_mt Stop(); #ifdef _WINDOWS @@ -78,7 +77,6 @@ void EQStreamFactory::Close() bool EQStreamFactory::Open() { - _eqp_mt struct sockaddr_in address; #ifndef WIN32 pthread_t t1,t2; @@ -120,7 +118,6 @@ bool EQStreamFactory::Open() std::shared_ptr EQStreamFactory::Pop() { - _eqp_mt std::shared_ptr s = nullptr; MNewStreams.lock(); if (NewStreams.size()) { @@ -135,7 +132,6 @@ std::shared_ptr EQStreamFactory::Pop() void EQStreamFactory::Push(std::shared_ptr s) { - _eqp_mt MNewStreams.lock(); NewStreams.push(s); MNewStreams.unlock(); @@ -220,7 +216,6 @@ void EQStreamFactory::ReaderLoop() void EQStreamFactory::CheckTimeout() { - _eqp_mt //lock streams the entire time were checking timeouts, it should be fast. MStreams.lock(); diff --git a/common/eqemu_logsys.cpp b/common/eqemu_logsys.cpp index 902b2f227..139e07dd2 100644 --- a/common/eqemu_logsys.cpp +++ b/common/eqemu_logsys.cpp @@ -89,7 +89,6 @@ EQEmuLogSys::~EQEmuLogSys() void EQEmuLogSys::LoadLogSettingsDefaults() { - _eqp_mt /* Get Executable platform currently running this code (Zone/World/etc) */ log_platform = GetExecutablePlatformInt(); @@ -124,7 +123,6 @@ void EQEmuLogSys::LoadLogSettingsDefaults() std::string EQEmuLogSys::FormatOutMessageString(uint16 log_category, const std::string &in_message) { - _eqp_mt std::string category_string; if (log_category > 0 && Logs::LogCategoryName[log_category]) category_string = StringFormat("[%s] ", Logs::LogCategoryName[log_category]); @@ -133,7 +131,6 @@ std::string EQEmuLogSys::FormatOutMessageString(uint16 log_category, const std:: void EQEmuLogSys::ProcessGMSay(uint16 debug_level, uint16 log_category, const std::string &message) { - _eqp_mt /* Check if category enabled for process */ if (log_settings[log_category].log_to_gmsay == 0) return; @@ -153,7 +150,6 @@ void EQEmuLogSys::ProcessGMSay(uint16 debug_level, uint16 log_category, const st void EQEmuLogSys::ProcessLogWrite(uint16 debug_level, uint16 log_category, const std::string &message) { - _eqp_mt if (log_category == Logs::Crash) { char time_stamp[80]; EQEmuLogSys::SetCurrentTimeStamp(time_stamp); @@ -180,7 +176,6 @@ void EQEmuLogSys::ProcessLogWrite(uint16 debug_level, uint16 log_category, const } uint16 EQEmuLogSys::GetWindowsConsoleColorFromCategory(uint16 log_category) { - _eqp_mt switch (log_category) { case Logs::Status: case Logs::Normal: @@ -204,7 +199,6 @@ uint16 EQEmuLogSys::GetWindowsConsoleColorFromCategory(uint16 log_category) { } std::string EQEmuLogSys::GetLinuxConsoleColorFromCategory(uint16 log_category) { - _eqp_mt switch (log_category) { case Logs::Status: case Logs::Normal: @@ -228,7 +222,6 @@ std::string EQEmuLogSys::GetLinuxConsoleColorFromCategory(uint16 log_category) { } uint16 EQEmuLogSys::GetGMSayColorFromCategory(uint16 log_category) { - _eqp_mt switch (log_category) { case Logs::Status: case Logs::Normal: @@ -253,7 +246,6 @@ uint16 EQEmuLogSys::GetGMSayColorFromCategory(uint16 log_category) { void EQEmuLogSys::ProcessConsoleMessage(uint16 debug_level, uint16 log_category, const std::string &message) { - _eqp_mt /* Check if category enabled for process */ if (log_settings[log_category].log_to_console == 0) return; @@ -281,7 +273,6 @@ void EQEmuLogSys::ProcessConsoleMessage(uint16 debug_level, uint16 log_category, void EQEmuLogSys::Out(Logs::DebugLevel debug_level, uint16 log_category, std::string message, ...) { - _eqp_mt const bool log_to_console = log_settings[log_category].log_to_console > 0; const bool log_to_file = log_settings[log_category].log_to_file > 0; const bool log_to_gmsay = log_settings[log_category].log_to_gmsay > 0; @@ -303,7 +294,6 @@ void EQEmuLogSys::Out(Logs::DebugLevel debug_level, uint16 log_category, std::st void EQEmuLogSys::SetCurrentTimeStamp(char* time_stamp) { - _eqp_mt time_t raw_time; struct tm * time_info; time(&raw_time); @@ -313,7 +303,6 @@ void EQEmuLogSys::SetCurrentTimeStamp(char* time_stamp) void EQEmuLogSys::MakeDirectory(const std::string &directory_name) { - _eqp_mt #ifdef _WINDOWS struct _stat st; if (_stat(directory_name.c_str(), &st) == 0) // exists @@ -329,7 +318,6 @@ void EQEmuLogSys::MakeDirectory(const std::string &directory_name) void EQEmuLogSys::CloseFileLogs() { - _eqp_mt if (process_log.is_open()) { process_log.close(); } @@ -337,7 +325,6 @@ void EQEmuLogSys::CloseFileLogs() void EQEmuLogSys::StartFileLogs(const std::string &log_name) { - _eqp_mt EQEmuLogSys::CloseFileLogs(); /* When loading settings, we must have been given a reason in category based logging to output to a file in order to even create or open one... */ diff --git a/common/uuid.cpp b/common/uuid.cpp new file mode 100644 index 000000000..caa18438b --- /dev/null +++ b/common/uuid.cpp @@ -0,0 +1,44 @@ +/* + EQEMu: Everquest Server Emulator + Copyright (C) 2001-2014 EQEMu Development Team (http://eqemulator.net) + + 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; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY except by those people which sell it, which + are required to give you total support for your newly bought product; + 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, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include "uuid.h" + +#ifdef WIN32 +#include +#else +#include +#endif + +std::string CreateUUID() { +#ifdef WIN32 + UUID uuid; + UuidCreate(&uuid); + unsigned char *str = nullptr; + UuidToStringA(&uuid, &str); + std::string s((char*)str); + RpcStringFreeA(&str); + return s; +#else + char str[64] = { 0 }; + uuid_t uuid; + uuid_generate_random(uuid); + uuid_unparse(uuid, str); + return str; +#endif +} diff --git a/common/uuid.h b/common/uuid.h new file mode 100644 index 000000000..f31d79d20 --- /dev/null +++ b/common/uuid.h @@ -0,0 +1,26 @@ +/* + EQEMu: Everquest Server Emulator + Copyright (C) 2001-2014 EQEMu Development Team (http://eqemulator.net) + + 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; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY except by those people which sell it, which + are required to give you total support for your newly bought product; + 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, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +#ifndef COMMON_UUID_H +#define COMMON_UUID_H + +#include + +std::string CreateUUID(); + +#endif diff --git a/eqperf/CMakeLists.txt b/eqperf/CMakeLists.txt index 3a59573ba..4668ac6aa 100644 --- a/eqperf/CMakeLists.txt +++ b/eqperf/CMakeLists.txt @@ -15,8 +15,6 @@ SET(eqperf_headers eqp_profiler_node.h ) -ADD_LIBRARY(eqperf SHARED ${eqperf_sources} ${eqperf_headers}) - -INSTALL(TARGETS eqperf RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}) +ADD_LIBRARY(eqperf ${eqperf_sources} ${eqperf_headers}) SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin) diff --git a/eqperf/eqp_profile_event.cpp b/eqperf/eqp_profile_event.cpp index 1e84cfc2b..c8a9a1309 100644 --- a/eqperf/eqp_profile_event.cpp +++ b/eqperf/eqp_profile_event.cpp @@ -7,7 +7,7 @@ EQP::CPU::ST::Event::Event(const char *function_name) { name_ = nullptr; start_ = GetCurrentTimer(); - EQP::CPU::ST::GetProfiler().EventStarted(function_name_, name_); + identifier_ = EQP::CPU::ST::GetProfiler().EventStarted(function_name_, name_); } EQP::CPU::ST::Event::Event(const char *function_name, const char *name) { @@ -15,13 +15,13 @@ EQP::CPU::ST::Event::Event(const char *function_name, const char *name) { name_ = name; start_ = GetCurrentTimer(); - EQP::CPU::ST::GetProfiler().EventStarted(function_name_, name_); + identifier_ = EQP::CPU::ST::GetProfiler().EventStarted(function_name_, name_); } EQP::CPU::ST::Event::~Event() { uint64_t end = GetCurrentTimer(); - EQP::CPU::ST::GetProfiler().EventFinished(end - start_); + EQP::CPU::ST::GetProfiler().EventFinished(end - start_, identifier_); } EQP::CPU::MT::Event::Event(const char *function_name) { @@ -29,7 +29,7 @@ EQP::CPU::MT::Event::Event(const char *function_name) { name_ = nullptr; start_ = GetCurrentTimer(); - EQP::CPU::MT::GetProfiler().EventStarted(function_name_, name_); + identifier_ = EQP::CPU::MT::GetProfiler().EventStarted(function_name_, name_); } EQP::CPU::MT::Event::Event(const char *function_name, const char *name) { @@ -37,11 +37,11 @@ EQP::CPU::MT::Event::Event(const char *function_name, const char *name) { name_ = name; start_ = GetCurrentTimer(); - EQP::CPU::MT::GetProfiler().EventStarted(function_name_, name_); + identifier_ = EQP::CPU::MT::GetProfiler().EventStarted(function_name_, name_); } EQP::CPU::MT::Event::~Event() { uint64_t end = GetCurrentTimer(); - EQP::CPU::MT::GetProfiler().EventFinished(end - start_); + EQP::CPU::MT::GetProfiler().EventFinished(end - start_, identifier_); } diff --git a/eqperf/eqp_profile_event.h b/eqperf/eqp_profile_event.h index 24a7cc9bf..8479474b5 100644 --- a/eqperf/eqp_profile_event.h +++ b/eqperf/eqp_profile_event.h @@ -1,5 +1,6 @@ #pragma once +#include #include #include "eqp_profile_function.h" @@ -19,6 +20,7 @@ namespace EQP const char *function_name_; const char *name_; uint64_t start_; + std::string identifier_; }; } @@ -34,6 +36,7 @@ namespace EQP const char *function_name_; const char *name_; uint64_t start_; + std::string identifier_; }; } } diff --git a/eqperf/eqp_profile_function.h b/eqperf/eqp_profile_function.h index 2e4a26634..0d19d6082 100644 --- a/eqperf/eqp_profile_function.h +++ b/eqperf/eqp_profile_function.h @@ -9,7 +9,8 @@ #endif #ifdef _MSC_VER -#define EQP_EXPORT __declspec(dllexport) +//#define EQP_EXPORT __declspec(dllexport) +#define EQP_EXPORT #else #define EQP_EXPORT #endif diff --git a/eqperf/eqp_profiler.cpp b/eqperf/eqp_profiler.cpp index d27881f6a..b04c54c47 100644 --- a/eqperf/eqp_profiler.cpp +++ b/eqperf/eqp_profiler.cpp @@ -4,6 +4,7 @@ #include #include #include +#include "../common/uuid.h" EQP::CPU::ST::Profiler st_profiler; EQP::CPU::MT::Profiler mt_profiler; @@ -12,6 +13,7 @@ struct EQP::CPU::MT::Profiler::impl { std::mutex lock_; std::unordered_map nodes_; + std::string identifier_; }; EQP::CPU::ST::Profiler &EQP::CPU::ST::GetProfiler() { @@ -26,13 +28,14 @@ EQP::CPU::ST::Profiler::Profiler() { root_ = new ProfilerNode; root_->SetParent(root_); current_ = root_; + identifier_ = CreateUUID(); } EQP::CPU::ST::Profiler::~Profiler() { delete root_; } -void EQP::CPU::ST::Profiler::EventStarted(const char *func, const char *name) { +std::string EQP::CPU::ST::Profiler::EventStarted(const char *func, const char *name) { std::string cur_name = func; if(name) { cur_name += " - "; @@ -48,9 +51,14 @@ void EQP::CPU::ST::Profiler::EventStarted(const char *func, const char *name) { current_->GetNodes()[cur_name] = t; current_ = t; } + + return identifier_; } -void EQP::CPU::ST::Profiler::EventFinished(uint64_t time) { +void EQP::CPU::ST::Profiler::EventFinished(uint64_t time, std::string ident) { + if(ident.compare(identifier_) != 0) { + return; + } current_->GetTime() += time; current_->GetCount()++; current_ = current_->GetParent(); @@ -65,6 +73,7 @@ void EQP::CPU::ST::Profiler::Clear() { root_->SetTime(0); root_->SetCount(0); current_ = root_; + identifier_ = CreateUUID(); } void EQP::CPU::ST::Profiler::Dump(std::ostream &stream, int num) { @@ -84,13 +93,21 @@ void EQP::CPU::ST::Profiler::Dump(std::ostream &stream, int num) { std::sort(sorted_vec.begin(), sorted_vec.end(), [](const ProfilerNodeDump& a, const ProfilerNodeDump& b) { return a.node->GetTime() > b.node->GetTime(); }); + std::streamsize p = stream.precision(); + double m_cycles = total / 1000.0; + + stream << std::fixed; + stream.precision(2); + stream << m_cycles << "k cycles" << std::endl; + stream.precision(p); + int i = 0; for(auto &iter : sorted_vec) { if(num > 0 && i >= num) { break; } - iter.node->Dump(stream, iter.name, total, 0, num); + iter.node->Dump(stream, iter.name, total, 1, num); ++i; } } @@ -107,13 +124,14 @@ EQP::CPU::MT::Profiler::ThreadInfo::~ThreadInfo() { EQP::CPU::MT::Profiler::Profiler() { imp_ = new impl; + imp_->identifier_ = CreateUUID(); } EQP::CPU::MT::Profiler::~Profiler() { delete imp_; } -void EQP::CPU::MT::Profiler::EventStarted(const char *func, const char *name) { +std::string EQP::CPU::MT::Profiler::EventStarted(const char *func, const char *name) { std::string cur_name = func; if(name) { cur_name += " - "; @@ -121,7 +139,7 @@ void EQP::CPU::MT::Profiler::EventStarted(const char *func, const char *name) { } ThreadInfo *ti = nullptr; - imp_->lock_.lock(); + std::lock_guard lg(imp_->lock_); auto ti_search = imp_->nodes_.find(std::this_thread::get_id()); if(ti_search == imp_->nodes_.end()) { ti = new ThreadInfo; @@ -129,7 +147,6 @@ void EQP::CPU::MT::Profiler::EventStarted(const char *func, const char *name) { } else { ti = ti_search->second; } - imp_->lock_.unlock(); auto search = ti->current_->GetNodes().find(cur_name); if(search != ti->current_->GetNodes().end()) { @@ -141,20 +158,24 @@ void EQP::CPU::MT::Profiler::EventStarted(const char *func, const char *name) { ti->current_->GetNodes()[cur_name] = t; ti->current_ = t; } + + return imp_->identifier_; } -void EQP::CPU::MT::Profiler::EventFinished(uint64_t time) { +void EQP::CPU::MT::Profiler::EventFinished(uint64_t time, std::string ident) { ThreadInfo *ti = nullptr; - imp_->lock_.lock(); + std::lock_guard lg(imp_->lock_); + if(ident.compare(imp_->identifier_) != 0) { + return; + } + auto ti_search = imp_->nodes_.find(std::this_thread::get_id()); if(ti_search == imp_->nodes_.end()) { - imp_->lock_.unlock(); return; } else { ti = ti_search->second; } - imp_->lock_.unlock(); ti->current_->GetTime() += time; ti->current_->GetCount()++; @@ -162,19 +183,18 @@ void EQP::CPU::MT::Profiler::EventFinished(uint64_t time) { } void EQP::CPU::MT::Profiler::Clear() { - imp_->lock_.lock(); + std::lock_guard lg(imp_->lock_); for(auto &iter : imp_->nodes_) { delete iter.second; } imp_->nodes_.clear(); - imp_->lock_.unlock(); + imp_->identifier_ = CreateUUID(); } void EQP::CPU::MT::Profiler::Dump(std::ostream &stream, int num) { - imp_->lock_.lock(); + std::lock_guard lg(imp_->lock_); for(auto &iter : imp_->nodes_) { - stream << "Thread: " << iter.first << std::endl; uint64_t total = 0; std::vector sorted_vec; sorted_vec.reserve(iter.second->root_->GetNodes().size() + 1); @@ -191,6 +211,14 @@ void EQP::CPU::MT::Profiler::Dump(std::ostream &stream, int num) { std::sort(sorted_vec.begin(), sorted_vec.end(), [](const ProfilerNodeDump& a, const ProfilerNodeDump& b) { return a.node->GetTime() > b.node->GetTime(); }); + std::streamsize p = stream.precision(); + double m_cycles = total / 1000.0; + + stream << std::fixed; + stream.precision(2); + stream << "Thread: " << iter.first << ", " << m_cycles << "k cycles" << std::endl; + stream.precision(p); + int i = 0; for(auto &t_iter : sorted_vec) { if(num > 0 && i >= num) { @@ -202,6 +230,5 @@ void EQP::CPU::MT::Profiler::Dump(std::ostream &stream, int num) { stream << std::endl; } - imp_->lock_.unlock(); } diff --git a/eqperf/eqp_profiler.h b/eqperf/eqp_profiler.h index 0a32eed8b..f7e2779e9 100644 --- a/eqperf/eqp_profiler.h +++ b/eqperf/eqp_profiler.h @@ -26,13 +26,14 @@ namespace EQP Profiler(); ~Profiler(); - void EventStarted(const char *func, const char *name); - void EventFinished(uint64_t time); - void Clear(); + std::string EventStarted(const char *func, const char *name); + void EventFinished(uint64_t time, std::string ident); void Dump(std::ostream &stream, int num = 0); + void Clear(); private: Node *root_; Node *current_; + std::string identifier_; }; EQP_EXPORT Profiler &GetProfiler(); @@ -54,10 +55,10 @@ namespace EQP Profiler(); ~Profiler(); - void EventStarted(const char *func, const char *name); - void EventFinished(uint64_t time); - void Clear(); + std::string EventStarted(const char *func, const char *name); + void EventFinished(uint64_t time, std::string ident); void Dump(std::ostream &stream, int num = 0); + void Clear(); private: struct impl; impl *imp_; diff --git a/eqperf/eqp_profiler_node.cpp b/eqperf/eqp_profiler_node.cpp index 751b8f878..de98be75e 100644 --- a/eqperf/eqp_profiler_node.cpp +++ b/eqperf/eqp_profiler_node.cpp @@ -21,7 +21,7 @@ void EQP::CPU::ProfilerNode::Dump(std::ostream &stream, const std::string &func, stream << std::setw(node_level * 2) << " "; } - double m_cycles = time_ / 1000000.0; + double m_cycles = time_ / 1000.0; double m_avg_cycles = m_cycles / count_; double percentage = time_ * 100 / static_cast(total_time); @@ -29,7 +29,7 @@ void EQP::CPU::ProfilerNode::Dump(std::ostream &stream, const std::string &func, stream << std::fixed; stream.precision(2); - stream << m_cycles << "M cycles, " << count_ << " calls, " << m_avg_cycles << "M cycles avg, "; + stream << m_cycles << "k cycles, " << count_ << " calls, " << m_avg_cycles << "k cycles avg, "; stream << func.c_str() << " "; stream << percentage << "%"; stream << std::endl; diff --git a/loginserver/CMakeLists.txt b/loginserver/CMakeLists.txt index d5b91854c..5eb56fb94 100644 --- a/loginserver/CMakeLists.txt +++ b/loginserver/CMakeLists.txt @@ -6,7 +6,6 @@ SET(eqlogin_sources config.cpp database_mysql.cpp database_postgresql.cpp - error_log.cpp main.cpp server_manager.cpp world_server.cpp @@ -26,7 +25,6 @@ SET(eqlogin_headers database_postgresql.h encryption.h eq_crypto_api.h - error_log.h login_server.h login_structures.h options.h @@ -48,6 +46,7 @@ TARGET_LINK_LIBRARIES(loginserver common ${PERF_LIBS} debug ${MySQL_LIBRARY_DEBU IF(MSVC) SET_TARGET_PROPERTIES(loginserver PROPERTIES LINK_FLAGS_RELEASE "/OPT:REF /OPT:ICF") TARGET_LINK_LIBRARIES(loginserver "Ws2_32.lib") + TARGET_LINK_LIBRARIES(loginserver "rpcrt4") ENDIF(MSVC) IF(MINGW) @@ -62,6 +61,7 @@ IF(UNIX) TARGET_LINK_LIBRARIES(loginserver "rt") ENDIF(NOT DARWIN) TARGET_LINK_LIBRARIES(loginserver "pthread") + TARGET_LINK_LIBRARIES(loginserver "uuid") TARGET_LINK_LIBRARIES(loginserver "EQEmuAuthCrypto") TARGET_LINK_LIBRARIES(loginserver "cryptopp") ADD_DEFINITIONS(-fPIC) diff --git a/loginserver/client.cpp b/loginserver/client.cpp index b3dd82128..8429c3f98 100644 --- a/loginserver/client.cpp +++ b/loginserver/client.cpp @@ -16,7 +16,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "client.h" -#include "error_log.h" #include "login_server.h" #include "login_structures.h" #include "../common/misc_functions.h" @@ -26,7 +25,7 @@ extern LoginServer server; Client::Client(std::shared_ptr c, LSClientVersion v) { - _eqp_mt + _eqp connection = c; version = v; status = cs_not_sent_session_ready; @@ -37,7 +36,7 @@ Client::Client(std::shared_ptr c, LSClientVersion v) bool Client::Process() { - _eqp_mt + _eqp EQApplicationPacket *app = connection->PopPacket(); while(app) { @@ -116,7 +115,7 @@ bool Client::Process() void Client::Handle_SessionReady(const char* data, unsigned int size) { - _eqp_mt + _eqp if(status != cs_not_sent_session_ready) { Log.Out(Logs::General, Logs::Netcode, "Session ready received again after already being received."); @@ -178,7 +177,7 @@ void Client::Handle_SessionReady(const char* data, unsigned int size) void Client::Handle_Login(const char* data, unsigned int size) { - _eqp_mt + _eqp if(status != cs_waiting_for_login) { Log.Out(Logs::General, Logs::Netcode, "Login received after already having logged in."); @@ -333,7 +332,7 @@ void Client::Handle_Login(const char* data, unsigned int size) void Client::Handle_Play(const char* data) { - _eqp_mt + _eqp if(status != cs_logged_in) { Log.Out(Logs::General, Logs::Error, "Client sent a play request when they either were not logged in, discarding."); @@ -357,7 +356,7 @@ void Client::Handle_Play(const char* data) void Client::SendServerListPacket() { - _eqp_mt + _eqp EQApplicationPacket *outapp = server.SM->CreateServerListPacket(this); if(server.options.IsDumpOutPacketsOn()) @@ -371,7 +370,7 @@ void Client::SendServerListPacket() void Client::SendPlayResponse(EQApplicationPacket *outapp) { - _eqp_mt + _eqp if(server.options.IsTraceOn()) { Log.Out(Logs::Detail, Logs::Netcode, "Sending play response for %s.", GetAccountName().c_str()); @@ -383,7 +382,7 @@ void Client::SendPlayResponse(EQApplicationPacket *outapp) void Client::GenerateKey() { - _eqp_mt + _eqp key.clear(); int count = 0; while(count < 10) diff --git a/loginserver/client_manager.cpp b/loginserver/client_manager.cpp index efc9da3db..fb5fd189b 100644 --- a/loginserver/client_manager.cpp +++ b/loginserver/client_manager.cpp @@ -16,7 +16,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "client_manager.h" -#include "error_log.h" #include "login_server.h" #include "../common/eqemu_logsys.h" @@ -25,7 +24,7 @@ extern bool run_server; ClientManager::ClientManager() { - _eqp_mt + _eqp int titanium_port = atoi(server.config->GetVariable("Titanium", "port").c_str()); titanium_stream = new EQStreamFactory(LoginStream, titanium_port); titanium_ops = new RegularOpcodeManager; @@ -69,7 +68,7 @@ ClientManager::ClientManager() ClientManager::~ClientManager() { - _eqp_mt + _eqp if(titanium_stream) { titanium_stream->Close(); @@ -95,7 +94,7 @@ ClientManager::~ClientManager() void ClientManager::Process() { - _eqp_mt + _eqp ProcessDisconnect(); std::shared_ptr cur = titanium_stream->Pop(); while(cur) @@ -141,7 +140,7 @@ void ClientManager::Process() void ClientManager::ProcessDisconnect() { - _eqp_mt + _eqp list::iterator iter = clients.begin(); while(iter != clients.end()) { @@ -161,7 +160,7 @@ void ClientManager::ProcessDisconnect() void ClientManager::UpdateServerList() { - _eqp_mt + _eqp list::iterator iter = clients.begin(); while(iter != clients.end()) { @@ -172,7 +171,7 @@ void ClientManager::UpdateServerList() void ClientManager::RemoveExistingClient(unsigned int account_id) { - _eqp_mt + _eqp list::iterator iter = clients.begin(); while(iter != clients.end()) { @@ -191,7 +190,7 @@ void ClientManager::RemoveExistingClient(unsigned int account_id) Client *ClientManager::GetClient(unsigned int account_id) { - _eqp_mt + _eqp Client *cur = nullptr; int count = 0; list::iterator iter = clients.begin(); diff --git a/loginserver/config.cpp b/loginserver/config.cpp index df9d0a39c..0eb783a29 100644 --- a/loginserver/config.cpp +++ b/loginserver/config.cpp @@ -17,7 +17,6 @@ */ #include "../common/global_define.h" #include "config.h" -#include "error_log.h" #include "../common/eqemu_logsys.h" /** @@ -27,7 +26,7 @@ */ std::string Config::GetVariable(std::string title, std::string parameter) { - _eqp_mt + _eqp std::map >::iterator iter = vars.find(title); if(iter != vars.end()) { @@ -47,7 +46,7 @@ std::string Config::GetVariable(std::string title, std::string parameter) */ void Config::Parse(const char *file_name) { - _eqp_mt + _eqp if(file_name == nullptr) { Log.Out(Logs::Detail, Logs::Error, "Config::Parse(), file_name passed was null."); @@ -146,7 +145,7 @@ void Config::Parse(const char *file_name) */ void Config::Tokenize(FILE *input, std::list &tokens) { - _eqp_mt + _eqp char c = fgetc(input); std::string lexeme; diff --git a/loginserver/database_mysql.cpp b/loginserver/database_mysql.cpp index 2437ab277..0f77026e9 100644 --- a/loginserver/database_mysql.cpp +++ b/loginserver/database_mysql.cpp @@ -20,7 +20,6 @@ #ifdef EQEMU_MYSQL_ENABLED #include "database_mysql.h" -#include "error_log.h" #include "login_server.h" #include "../common/eqemu_logsys.h" @@ -30,7 +29,7 @@ extern LoginServer server; DatabaseMySQL::DatabaseMySQL(string user, string pass, string host, string port, string name) { - _eqp_mt + _eqp this->user = user; this->pass = pass; this->host = host; @@ -56,7 +55,7 @@ DatabaseMySQL::DatabaseMySQL(string user, string pass, string host, string port, DatabaseMySQL::~DatabaseMySQL() { - _eqp_mt + _eqp if(db) { mysql_close(db); @@ -65,7 +64,7 @@ DatabaseMySQL::~DatabaseMySQL() bool DatabaseMySQL::GetLoginDataFromAccountName(string name, string &password, unsigned int &id) { - _eqp_mt + _eqp if(!db) { return false; @@ -104,7 +103,7 @@ bool DatabaseMySQL::GetLoginDataFromAccountName(string name, string &password, u bool DatabaseMySQL::GetWorldRegistration(string long_name, string short_name, unsigned int &id, string &desc, unsigned int &list_id, unsigned int &trusted, string &list_desc, string &account, string &password) { - _eqp_mt + _eqp if(!db) { return false; @@ -180,7 +179,7 @@ bool DatabaseMySQL::GetWorldRegistration(string long_name, string short_name, un void DatabaseMySQL::UpdateLSAccountData(unsigned int id, string ip_address) { - _eqp_mt + _eqp if(!db) { return; @@ -200,7 +199,7 @@ void DatabaseMySQL::UpdateLSAccountData(unsigned int id, string ip_address) void DatabaseMySQL::UpdateLSAccountInfo(unsigned int id, string name, string password, string email) { - _eqp_mt + _eqp if(!db) { return; @@ -220,7 +219,7 @@ void DatabaseMySQL::UpdateLSAccountInfo(unsigned int id, string name, string pas void DatabaseMySQL::UpdateWorldRegistration(unsigned int id, string long_name, string ip_address) { - _eqp_mt + _eqp if(!db) { return; @@ -246,7 +245,7 @@ void DatabaseMySQL::UpdateWorldRegistration(unsigned int id, string long_name, s bool DatabaseMySQL::CreateWorldRegistration(string long_name, string short_name, unsigned int &id) { - _eqp_mt + _eqp if(!db) { return false; diff --git a/loginserver/database_postgresql.cpp b/loginserver/database_postgresql.cpp index dfc9d91aa..c6c5c459b 100644 --- a/loginserver/database_postgresql.cpp +++ b/loginserver/database_postgresql.cpp @@ -30,7 +30,7 @@ extern LoginServer server; DatabasePostgreSQL::DatabasePostgreSQL(string user, string pass, string host, string port, string name) { - _eqp_mt_mt + _eqp_mt db = nullptr; db = PQsetdbLogin(host.c_str(), port.c_str(), nullptr, nullptr, name.c_str(), user.c_str(), pass.c_str()); if(!db) @@ -48,7 +48,7 @@ DatabasePostgreSQL::DatabasePostgreSQL(string user, string pass, string host, st DatabasePostgreSQL::~DatabasePostgreSQL() { - _eqp_mt_mt + _eqp_mt if(db) { PQfinish(db); @@ -57,7 +57,7 @@ DatabasePostgreSQL::~DatabasePostgreSQL() bool DatabasePostgreSQL::GetLoginDataFromAccountName(string name, string &password, unsigned int &id) { - _eqp_mt_mt + _eqp_mt if(!db) { return false; @@ -106,7 +106,7 @@ bool DatabasePostgreSQL::GetLoginDataFromAccountName(string name, string &passwo bool DatabasePostgreSQL::GetWorldRegistration(string long_name, string short_name, unsigned int &id, string &desc, unsigned int &list_id, unsigned int &trusted, string &list_desc, string &account, string &password) { - _eqp_mt_mt + _eqp_mt if(!db) { return false; @@ -164,7 +164,7 @@ bool DatabasePostgreSQL::GetWorldRegistration(string long_name, string short_nam void DatabasePostgreSQL::UpdateLSAccountData(unsigned int id, string ip_address) { - _eqp_mt_mt + _eqp_mt if(!db) { return; @@ -200,7 +200,7 @@ void DatabasePostgreSQL::UpdateLSAccountData(unsigned int id, string ip_address) void DatabasePostgreSQL::UpdateWorldRegistration(unsigned int id, string long_name, string ip_address) { - _eqp_mt_mt + _eqp_mt if(!db) { return; diff --git a/loginserver/encryption.cpp b/loginserver/encryption.cpp index 6bc993028..30c2362bf 100644 --- a/loginserver/encryption.cpp +++ b/loginserver/encryption.cpp @@ -18,12 +18,11 @@ #include "../common/global_define.h" #include "../common/eqemu_logsys.h" #include "encryption.h" -#include "error_log.h" #include bool Encryption::LoadCrypto(std::string name) { - _eqp_mt + _eqp if(!Load(name.c_str())) { Log.Out(Logs::Detail, Logs::Error, "Failed to load %s from the operating system.", name.c_str()); @@ -58,7 +57,7 @@ bool Encryption::LoadCrypto(std::string name) char *Encryption::DecryptUsernamePassword(const char* encrypted_buffer, unsigned int buffer_size, int mode) { - _eqp_mt + _eqp if(decrypt_func) { return decrypt_func(encrypted_buffer, buffer_size, mode); @@ -68,7 +67,7 @@ char *Encryption::DecryptUsernamePassword(const char* encrypted_buffer, unsigned char *Encryption::Encrypt(const char* buffer, unsigned int buffer_size, unsigned int &out_size) { - _eqp_mt + _eqp if(encrypt_func) { return encrypt_func(buffer, buffer_size, out_size); @@ -78,7 +77,7 @@ char *Encryption::Encrypt(const char* buffer, unsigned int buffer_size, unsigned void Encryption::DeleteHeap(char *buffer) { - _eqp_mt + _eqp if(delete_func) { delete_func(buffer); @@ -87,7 +86,7 @@ void Encryption::DeleteHeap(char *buffer) bool Encryption::Load(const char *name) { - _eqp_mt + _eqp SetLastError(0); #ifdef UNICODE int name_length = strlen(name); @@ -115,7 +114,7 @@ bool Encryption::Load(const char *name) void Encryption::Unload() { - _eqp_mt + _eqp if(h_dll) { FreeLibrary(h_dll); @@ -125,7 +124,7 @@ void Encryption::Unload() bool Encryption::GetSym(const char *name, void **sym) { - _eqp_mt + _eqp if(Loaded()) { *sym = GetProcAddress(h_dll, name); @@ -139,7 +138,7 @@ bool Encryption::GetSym(const char *name, void **sym) void *Encryption::GetSym(const char *name) { - _eqp_mt + _eqp if(Loaded()) { return GetProcAddress(h_dll, name); diff --git a/loginserver/error_log.cpp b/loginserver/error_log.cpp deleted file mode 100644 index 5906734fd..000000000 --- a/loginserver/error_log.cpp +++ /dev/null @@ -1,214 +0,0 @@ -/* EQEMu: Everquest Server Emulator - Copyright (C) 2001-2010 EQEMu Development Team (http://eqemulator.net) - - 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; version 2 of the License. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY except by those people which sell it, which - are required to give you total support for your newly bought product; - 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, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ -#include -#include "error_log.h" - -const char *eqLogTypes[_log_largest_type] = -{ - "Debug", - "Error", - "Database", - "Network", - "Network Trace", - "Network Error", - "World", - "World Error", - "Client", - "Client Error" -}; - -ErrorLog::ErrorLog(const char* file_name) -{ - _eqp_mt - log_mutex = new Mutex(); - error_log = fopen(file_name, "w"); -} - -ErrorLog::~ErrorLog() -{ - _eqp_mt - log_mutex->lock(); - if(error_log) - { - fclose(error_log); - } - log_mutex->unlock(); - delete log_mutex; -} - -void ErrorLog::Log(eqLogType type, const char *message, ...) -{ - _eqp_mt - if(type >= _log_largest_type) - { - return; - } - - va_list argptr; - char *buffer = new char[4096]; - va_start(argptr, message); - vsnprintf(buffer, 4096, message, argptr); - va_end(argptr); - - time_t m_clock; - struct tm *m_time; - time(&m_clock); - m_time = localtime(&m_clock); - - log_mutex->lock(); - printf("[%s] [%02d.%02d.%02d - %02d:%02d:%02d] %s\n", - eqLogTypes[type], - m_time->tm_mon+1, - m_time->tm_mday, - m_time->tm_year%100, - m_time->tm_hour, - m_time->tm_min, - m_time->tm_sec, - buffer); - - if(error_log) - { - fprintf(error_log, "[%s] [%02d.%02d.%02d - %02d:%02d:%02d] %s\n", - eqLogTypes[type], - m_time->tm_mon+1, - m_time->tm_mday, - m_time->tm_year%100, - m_time->tm_hour, - m_time->tm_min, - m_time->tm_sec, - buffer); - fflush(error_log); - } - - log_mutex->unlock(); - delete[] buffer; -} - -void ErrorLog::LogPacket(eqLogType type, const char *data, size_t size) -{ - _eqp_mt - if(type >= _log_largest_type) - { - return; - } - - log_mutex->lock(); - time_t m_clock; - struct tm *m_time; - time(&m_clock); - m_time = localtime(&m_clock); - - log_mutex->lock(); - printf("[%s] [%02d.%02d.%02d - %02d:%02d:%02d] dumping packet of size %u:\n", - eqLogTypes[type], - m_time->tm_mon+1, - m_time->tm_mday, - m_time->tm_year%100, - m_time->tm_hour, - m_time->tm_min, - m_time->tm_sec, - (unsigned int)size); - - if(error_log) - { - fprintf(error_log, "[%s] [%02d.%02d.%02d - %02d:%02d:%02d] dumping packet of size %u\n", - eqLogTypes[type], - m_time->tm_mon+1, - m_time->tm_mday, - m_time->tm_year%100, - m_time->tm_hour, - m_time->tm_min, - m_time->tm_sec, - (unsigned int)size); - } - - char ascii[17]; //16 columns + 1 null term - memset(ascii, 0, 17); - - size_t j = 0; - size_t i = 0; - for(; i < size; ++i) - { - if(i % 16 == 0) - { - if(i != 0) - { - printf(" | %s\n", ascii); - if(error_log) - { - fprintf(error_log, " | %s\n", ascii); - } - } - printf("%.4u: ", (unsigned int)i); - memset(ascii, 0, 17); - j = 0; - } - else if(i % 8 == 0) - { - printf("- "); - if(error_log) - { - fprintf(error_log, "- "); - } - } - - printf("%02X ", (unsigned int)data[i]); - if(error_log) - { - fprintf(error_log, "%02X ", (unsigned int)data[i]); - } - - if(data[i] >= 32 && data[i] < 127) - { - ascii[j++] = data[i]; - } - else - { - ascii[j++] = '.'; - } - } - - size_t k = (i - 1) % 16; - if(k < 8) - { - printf(" "); - if(error_log) - { - fprintf(error_log, " "); - } - } - - for(size_t h = k + 1; h < 16; ++h) - { - printf(" "); - if(error_log) - { - fprintf(error_log, " "); - } - } - - printf(" | %s\n", ascii); - if(error_log) - { - fprintf(error_log, " | %s\n", ascii); - fflush(error_log); - } - - log_mutex->unlock(); -} - diff --git a/loginserver/error_log.h b/loginserver/error_log.h deleted file mode 100644 index ad54e12b7..000000000 --- a/loginserver/error_log.h +++ /dev/null @@ -1,79 +0,0 @@ -/* EQEMu: Everquest Server Emulator - Copyright (C) 2001-2010 EQEMu Development Team (http://eqemulator.net) - - 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; version 2 of the License. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY except by those people which sell it, which - are required to give you total support for your newly bought product; - 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, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ -#ifndef EQEMU_ERROR_LOG_H -#define EQEMU_ERROR_LOG_H - -#include -#include -#include -#include - -#include "../common/mutex.h" - -/** - * Dictates the log type specified in ErrorLog for Log(...) - */ -enum eqLogType -{ - log_debug, - log_error, - log_database, - log_network, - log_network_trace, - log_network_error, - log_world, - log_world_error, - log_client, - log_client_error, - _log_largest_type -}; - -/** - * Basic error logging class. - * Thread safe logging class that records time and date to both a file and to console(if exists). - */ -class ErrorLog -{ -public: - /** - * Constructor: opens the log file for writing and creates our mutex for writing to the log. - */ - ErrorLog(const char* file_name); - - /** - * Closes the file and destroys the mutex. - */ - ~ErrorLog(); - - /** - * Writes to the log system a variable message. - */ - void Log(eqLogType type, const char *message, ...); - - /** - * Writes to the log system a packet. - */ - void LogPacket(eqLogType type, const char *data, size_t size); - -protected: - Mutex *log_mutex; - FILE* error_log; -}; - -#endif - diff --git a/loginserver/login_server.h b/loginserver/login_server.h index f83154b8f..11701a990 100644 --- a/loginserver/login_server.h +++ b/loginserver/login_server.h @@ -18,7 +18,6 @@ #ifndef EQEMU_LOGINSERVER_H #define EQEMU_LOGINSERVER_H -#include "error_log.h" #include "config.h" #include "database.h" #include "database_mysql.h" diff --git a/loginserver/main.cpp b/loginserver/main.cpp index 74ae2f251..d39dd2ea0 100644 --- a/loginserver/main.cpp +++ b/loginserver/main.cpp @@ -49,7 +49,7 @@ void CatchSignal(int sig_num) std::ofstream profile_out(prof_name, std::ofstream::out); if(profile_out.good()) { - EQP::CPU::MT::GetProfiler().Dump(profile_out, 5); + EQP::CPU::ST::GetProfiler().Dump(profile_out, 10); } #endif } diff --git a/loginserver/server_manager.cpp b/loginserver/server_manager.cpp index 69460cf04..5b5fe0098 100644 --- a/loginserver/server_manager.cpp +++ b/loginserver/server_manager.cpp @@ -17,7 +17,6 @@ */ #include "server_manager.h" #include "login_server.h" -#include "error_log.h" #include "login_structures.h" #include "../common/eqemu_logsys.h" #include @@ -27,7 +26,7 @@ extern bool run_server; ServerManager::ServerManager() { - _eqp_mt + _eqp char error_buffer[TCPConnection_ErrorBufferSize]; int listen_port = atoi(server.config->GetVariable("options", "listen_port").c_str()); @@ -45,7 +44,7 @@ ServerManager::ServerManager() ServerManager::~ServerManager() { - _eqp_mt + _eqp if(tcps) { tcps->Close(); @@ -55,7 +54,7 @@ ServerManager::~ServerManager() void ServerManager::Process() { - _eqp_mt + _eqp ProcessDisconnect(); EmuTCPConnection *tcp_c = nullptr; while(tcp_c = tcps->NewQueuePop()) @@ -97,7 +96,7 @@ void ServerManager::Process() void ServerManager::ProcessDisconnect() { - _eqp_mt + _eqp list::iterator iter = world_servers.begin(); while(iter != world_servers.end()) { @@ -120,7 +119,7 @@ void ServerManager::ProcessDisconnect() WorldServer* ServerManager::GetServerByAddress(unsigned int address) { - _eqp_mt + _eqp list::iterator iter = world_servers.begin(); while(iter != world_servers.end()) { @@ -136,7 +135,7 @@ WorldServer* ServerManager::GetServerByAddress(unsigned int address) EQApplicationPacket *ServerManager::CreateServerListPacket(Client *c) { - _eqp_mt + _eqp unsigned int packet_size = sizeof(ServerListHeader_Struct); unsigned int server_count = 0; in_addr in; @@ -274,7 +273,7 @@ EQApplicationPacket *ServerManager::CreateServerListPacket(Client *c) void ServerManager::SendUserToWorldRequest(unsigned int server_id, unsigned int client_account_id) { - _eqp_mt + _eqp list::iterator iter = world_servers.begin(); bool found = false; while(iter != world_servers.end()) @@ -305,7 +304,7 @@ void ServerManager::SendUserToWorldRequest(unsigned int server_id, unsigned int bool ServerManager::ServerExists(string l_name, string s_name, WorldServer *ignore) { - _eqp_mt + _eqp list::iterator iter = world_servers.begin(); while(iter != world_servers.end()) { @@ -327,7 +326,7 @@ bool ServerManager::ServerExists(string l_name, string s_name, WorldServer *igno void ServerManager::DestroyServerByName(string l_name, string s_name, WorldServer *ignore) { - _eqp_mt + _eqp list::iterator iter = world_servers.begin(); while(iter != world_servers.end()) { diff --git a/loginserver/world_server.cpp b/loginserver/world_server.cpp index 985859438..66a183e02 100644 --- a/loginserver/world_server.cpp +++ b/loginserver/world_server.cpp @@ -16,7 +16,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "world_server.h" -#include "error_log.h" #include "login_server.h" #include "login_structures.h" #include "../common/eqemu_logsys.h" @@ -25,7 +24,7 @@ extern LoginServer server; WorldServer::WorldServer(EmuTCPConnection *c) { - _eqp_mt + _eqp connection = c; zones_booted = 0; players_online = 0; @@ -40,7 +39,7 @@ WorldServer::WorldServer(EmuTCPConnection *c) WorldServer::~WorldServer() { - _eqp_mt + _eqp if(connection) { connection->Free(); @@ -49,7 +48,7 @@ WorldServer::~WorldServer() void WorldServer::Reset() { - _eqp_mt + _eqp zones_booted = 0; players_online = 0; status = 0; @@ -62,7 +61,7 @@ void WorldServer::Reset() bool WorldServer::Process() { - _eqp_mt + _eqp ServerPacket *app = nullptr; while(app = connection->PopPacket()) { @@ -241,7 +240,7 @@ bool WorldServer::Process() void WorldServer::Handle_NewLSInfo(ServerNewLSInfo_Struct* i) { - _eqp_mt + _eqp if(logged_in) { Log.Out(Logs::General, Logs::Netcode, "WorldServer::Handle_NewLSInfo called but the login server was already marked as logged in, aborting."); @@ -506,7 +505,7 @@ void WorldServer::Handle_NewLSInfo(ServerNewLSInfo_Struct* i) void WorldServer::Handle_LSStatus(ServerLSStatus_Struct *s) { - _eqp_mt + _eqp players_online = s->num_players; zones_booted = s->num_zones; status = s->status; @@ -514,7 +513,7 @@ void WorldServer::Handle_LSStatus(ServerLSStatus_Struct *s) void WorldServer::SendClientAuth(unsigned int ip, string account, string key, unsigned int account_id) { - _eqp_mt + _eqp ServerPacket *outapp = new ServerPacket(ServerOP_LSClientAuth, sizeof(ServerLSClientAuth)); ServerLSClientAuth* slsca = (ServerLSClientAuth*)outapp->pBuffer;