X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/070f97038a36f1c8e5401f0701f1313ea33148cc..fd350a649f3454ebef042b0e6b727f3c5d18400b:/projects/rscriptd/listener.cpp diff --git a/projects/rscriptd/listener.cpp b/projects/rscriptd/listener.cpp index 8737b3b8..9e03988c 100644 --- a/projects/rscriptd/listener.cpp +++ b/projects/rscriptd/listener.cpp @@ -33,10 +33,10 @@ #include #include +#include "stg/scriptexecuter.h" +#include "stg/locker.h" +#include "stg/common.h" #include "listener.h" -#include "script_executer.h" -#include "stg_locker.h" -#include "common.h" void InitEncrypt(BLOWFISH_CTX * ctx, const std::string & password); void Decrypt(BLOWFISH_CTX * ctx, char * dst, const char * src, int len8); @@ -162,9 +162,9 @@ return false; //----------------------------------------------------------------------------- void * LISTENER::Run(void * d) { -LISTENER * ia = static_cast(d); +LISTENER * listener = static_cast(d); -ia->Runner(); +listener->Runner(); return NULL; } @@ -183,9 +183,9 @@ receiverStopped = true; //----------------------------------------------------------------------------- void * LISTENER::RunProcessor(void * d) { -LISTENER * ia = static_cast(d); +LISTENER * listener = static_cast(d); -ia->ProcessorRunner(); +listener->ProcessorRunner(); return NULL; } @@ -215,8 +215,6 @@ if (listenSocket < 0) return true; } -printfd(__FILE__, "Port: %d\n", port); - struct sockaddr_in listenAddr; listenAddr.sin_family = AF_INET; listenAddr.sin_port = htons(port); @@ -250,7 +248,7 @@ RS_PACKET_HEADER packetHead; iov[0].iov_base = reinterpret_cast(&packetHead); iov[0].iov_len = sizeof(packetHead); iov[1].iov_base = buffer; -iov[1].iov_len = sizeof(buffer); +iov[1].iov_len = sizeof(buffer) - sizeof(packetHead); size_t dataLen = 0; while (dataLen < sizeof(buffer)) @@ -321,9 +319,9 @@ if (strncmp((char *)packetTail.magic, RS_ID, RS_MAGIC_LEN)) } std::stringstream params; -params << data.login << " " +params << "\"" << data.login << "\" " << inet_ntostring(data.ip) << " " - << ntohl(data.id) << " " + << data.id << " " << (char *)packetTail.params; data.params = params.str(); @@ -333,9 +331,10 @@ return false; //----------------------------------------------------------------------------- void LISTENER::ProcessPending() { -printfd(__FILE__, "Pending data size: %d\n", pending.size()); std::list::iterator it(pending.begin()); -while (it != pending.end()) +size_t count = 0; +printfd(__FILE__, "Pending: %d\n", pending.size()); +while (it != pending.end() && count < 256) { std::vector::iterator uit( std::lower_bound( @@ -375,10 +374,11 @@ while (it != pending.end()) users.erase(uit); } } - - STG_LOCKER lock(&mutex, __FILE__, __LINE__); - pending.erase(it++); + ++it; + ++count; } +STG_LOCKER lock(&mutex, __FILE__, __LINE__); +pending.erase(pending.begin(), it); } //----------------------------------------------------------------------------- void LISTENER::ProcessTimeouts() @@ -410,7 +410,7 @@ bool LISTENER::Connect(const UserData & data) const printfd(__FILE__, "Connect %s\n", data.login.c_str()); if (access(scriptOnConnect.c_str(), X_OK) == 0) { - if (ScriptExec(scriptOnConnect + " " + data.params)) + if (ScriptExec((scriptOnConnect + " " + data.params).c_str())) { WriteServLog("Script %s cannot be executed for an unknown reason.", scriptOnConnect.c_str()); return true; @@ -429,7 +429,7 @@ bool LISTENER::Disconnect(const UserData & data) const printfd(__FILE__, "Disconnect %s\n", data.login.c_str()); if (access(scriptOnDisconnect.c_str(), X_OK) == 0) { - if (ScriptExec(scriptOnDisconnect + " " + data.params)) + if (ScriptExec((scriptOnDisconnect + " " + data.params).c_str())) { WriteServLog("Script %s cannot be executed for an unknown reson.", scriptOnDisconnect.c_str()); return true; @@ -456,34 +456,6 @@ if (strncmp((char *)header.protoVer, "02", RS_PROTO_VER_LEN)) return false; } //----------------------------------------------------------------------------- -bool LISTENER::WaitPackets(int sd) const -{ -fd_set rfds; -FD_ZERO(&rfds); -FD_SET(sd, &rfds); - -struct timeval tv; -tv.tv_sec = 0; -tv.tv_usec = 500000; - -int res = select(sd + 1, &rfds, NULL, NULL, &tv); -if (res == -1) // Error - { - if (errno != EINTR) - { - printfd(__FILE__, "Error on select: '%s'\n", strerror(errno)); - } - return false; - } - -if (res == 0) // Timeout - { - return false; - } - -return true; -} -//----------------------------------------------------------------------------- inline void InitEncrypt(BLOWFISH_CTX * ctx, const std::string & password) {