示例#1
0
void ResNickMan::AddReservedNick(const char * sNick, const bool &bFromScript/* = false*/) {
    uint32_t ulHash = HashNick(sNick, strlen(sNick));

    if(CheckReserved(sNick, ulHash) == false) {
        ReservedNick * pNewNick = new ReservedNick(sNick, ulHash);
        if(pNewNick == NULL) {
			AppendDebugLog("%s - [MEM] Cannot allocate pNewNick in ResNickMan::AddReservedNick\n", 0);
        	return;
        } else if(pNewNick->sNick == NULL) {
            delete pNewNick;

			AppendDebugLog("%s - [MEM] Cannot allocate pNewNick->sNick in ResNickMan::AddReservedNick\n", 0);
        	return;
        }

        if(ReservedNicks == NULL) {
            ReservedNicks = pNewNick;
        } else {
            ReservedNicks->prev = pNewNick;
            pNewNick->next = ReservedNicks;
            ReservedNicks = pNewNick;
        }

        pNewNick->bFromScript = bFromScript;
    }
}
示例#2
0
void classUsers::AddBot2NickList(char * Nick, const size_t &szNickLen, const bool &isOp) {
    // $NickList nick$$nick2$$|

    if(nickListSize < nickListLen+szNickLen+2) {
        char * pOldBuf = nickList;
#ifdef _WIN32
        nickList = (char *)HeapReAlloc(hPtokaXHeap, HEAP_NO_SERIALIZE, (void *)pOldBuf, nickListSize+NICKLISTSIZE+1);
#else
		nickList = (char *)realloc(pOldBuf, nickListSize+NICKLISTSIZE+1);
#endif
        if(nickList == NULL) {
            nickList = pOldBuf;

			AppendDebugLog("%s - [MEM] Cannot reallocate %" PRIu64 " bytes in classUsers::AddBot2NickList for NickList\n", (uint64_t)(nickListSize+NICKLISTSIZE+1));

            return;
		}
        nickListSize += NICKLISTSIZE;
    }

    memcpy(nickList+nickListLen-1, Nick, szNickLen);
    nickListLen += (uint32_t)(szNickLen+2);

    nickList[nickListLen-3] = '$';
    nickList[nickListLen-2] = '$';
    nickList[nickListLen-1] = '|';
    nickList[nickListLen] = '\0';

    iZNickListLen = 0;

    if(isOp == false)
        return;

    if(opListSize < opListLen+szNickLen+2) {
        char * pOldBuf = opList;
#ifdef _WIN32
        opList = (char *)HeapReAlloc(hPtokaXHeap, HEAP_NO_SERIALIZE, (void *)pOldBuf, opListSize+OPLISTSIZE+1);
#else
		opList = (char *)realloc(pOldBuf, opListSize+OPLISTSIZE+1);
#endif
        if(opList == NULL) {
            opList = pOldBuf;

            AppendDebugLog("%s - [MEM] Cannot reallocate %" PRIu64 " bytes in classUsers::AddBot2NickList for opList\n", (uint64_t)(opListSize+OPLISTSIZE+1));

            return;
        }
        opListSize += OPLISTSIZE;
    }

    memcpy(opList+opListLen-1, Nick, szNickLen);
    opListLen += (uint32_t)(szNickLen+2);

    opList[opListLen-3] = '$';
    opList[opListLen-2] = '$';
    opList[opListLen-1] = '|';
    opList[opListLen] = '\0';

    iZOpListLen = 0;
}
示例#3
0
void clsEventQueue::AddNormal(uint8_t ui8Id, char * sMsg) {
	if(ui8Id != EVENT_RSTSCRIPT && ui8Id != EVENT_STOPSCRIPT) {
		event * next = NormalS;

		while(next != NULL) {
			event * cur = next;
			next = cur->next;

			if(cur->ui8Id == ui8Id) {
                return;
            }
		}
	}

    event * pNewEvent = new event();

	if(pNewEvent == NULL) {
		AppendDebugLog("%s - [MEM] Cannot allocate pNewEvent in clsEventQueue::AddNormal\n", 0);
        return;
    }

    if(sMsg != NULL) {
        size_t szLen = strlen(sMsg);
#ifdef _WIN32
		pNewEvent->sMsg = (char *)HeapAlloc(clsServerManager::hLibHeap, HEAP_NO_SERIALIZE, szLen+1);
#else
		pNewEvent->sMsg = (char *)malloc(szLen+1);
#endif
		if(pNewEvent->sMsg == NULL) {
            delete pNewEvent;

			AppendDebugLog("%s - [MEM] Cannot allocate %" PRIu64 " bytes for pNewEvent->sMsg in clsEventQueue::AddNormal\n", (uint64_t)(szLen+1));

            return;
        }

        memcpy(pNewEvent->sMsg, sMsg, szLen);
        pNewEvent->sMsg[szLen] = '\0';
    } else {
		pNewEvent->sMsg = NULL;
    }

    pNewEvent->ui8Id = ui8Id;

    if(NormalS == NULL) {
        NormalS = pNewEvent;
        pNewEvent->prev = NULL;
    } else {
        pNewEvent->prev = NormalE;
        NormalE->next = pNewEvent;
    }

    NormalE = pNewEvent;
    pNewEvent->next = NULL;
}
示例#4
0
void classUsers::AddBot2MyInfos(char * MyInfo) {
	size_t len = strlen(MyInfo);
	if(myInfosTag != NULL) {
	    if(strstr(myInfosTag, MyInfo) == NULL ) {
            if(myInfosTagSize < myInfosTagLen+len) {
                char * pOldBuf = myInfosTag;
#ifdef _WIN32
                myInfosTag = (char *)HeapReAlloc(hPtokaXHeap, HEAP_NO_SERIALIZE, (void *)pOldBuf, myInfosTagSize+MYINFOLISTSIZE+1);
#else
				myInfosTag = (char *)realloc(pOldBuf, myInfosTagSize+MYINFOLISTSIZE+1);
#endif
                if(myInfosTag == NULL) {
                    myInfosTag = pOldBuf;

					AppendDebugLog("%s - [MEM] Cannot reallocate %" PRIu64 " bytes for myInfosTag in classUsers::AddBot2MyInfos\n", (uint64_t)(myInfosTagSize+MYINFOLISTSIZE+1));

                    return;
                }
                myInfosTagSize += MYINFOLISTSIZE;
            }
        	memcpy(myInfosTag+myInfosTagLen, MyInfo, len);
            myInfosTagLen += (uint32_t)len;
            myInfosTag[myInfosTagLen] = '\0';
            iZMyInfosLen = 0;
        }
    }
    if(myInfos != NULL) {
    	if(strstr(myInfos, MyInfo) == NULL ) {
            if(myInfosSize < myInfosLen+len) {
                char * pOldBuf = myInfos;
#ifdef _WIN32
                myInfos = (char *)HeapReAlloc(hPtokaXHeap, HEAP_NO_SERIALIZE, (void *)pOldBuf, myInfosSize+MYINFOLISTSIZE+1);
#else
				myInfos = (char *)realloc(pOldBuf, myInfosSize+MYINFOLISTSIZE+1);
#endif
                if(myInfos == NULL) {
                    myInfos = pOldBuf;

					AppendDebugLog("%s - [MEM] Cannot reallocate %" PRIu64 " bytes for myInfos in classUsers::AddBot2MyInfos\n", (uint64_t)(myInfosSize+MYINFOLISTSIZE+1));

                    return;
                }
                myInfosSize += MYINFOLISTSIZE;
            }
        	memcpy(myInfos+myInfosLen, MyInfo, len);
            myInfosLen += (uint32_t)len;
            myInfos[myInfosLen] = '\0';
            iZMyInfosTagLen = 0;
         }
    }
}
示例#5
0
void GlobalDataQueue::InsertQueueItem(char * sCommand, const size_t &szLen, void * pBeforeItem, const uint8_t &ui8CmdType) {
    QueueItem * pNewItem = new QueueItem();
    if(pNewItem == NULL) {
		AppendDebugLog("%s - [MEM] Cannot allocate pNewItem in GlobalDataQueue::InsertQueueItem\n", 0);
    	return;
    }

#ifdef _WIN32
    pNewItem->sCommand1 = (char *)HeapAlloc(hPtokaXHeap, HEAP_NO_SERIALIZE, szLen);
#else
	pNewItem->sCommand1 = (char *)malloc(szLen+1);
#endif
    if(pNewItem->sCommand1 == NULL) {
        delete pNewItem;

		AppendDebugLog("%s - [MEM] Cannot allocate %" PRIu64 " bytes for pNewItem->sCommand1 in GlobalDataQueue::InsertQueueItem\n", (uint64_t)(szLen+1));

        return;
    }

    memcpy(pNewItem->sCommand1, sCommand, szLen);
    pNewItem->sCommand1[szLen] = '\0';

	pNewItem->szLen1 = szLen;

    pNewItem->sCommand2 = NULL;
    pNewItem->szLen2 = 0;

	pNewItem->ui8CommandType = ui8CmdType;

	pNewItem->pNext = (QueueItem *)pBeforeItem;

    QueueItem * pNext = pNewQueueItems[0];
    if(pNext == pBeforeItem) {
        pNewQueueItems[0] = pNewItem;
        return;
    }

    while(pNext != NULL) {
        QueueItem * pCur = pNext;
        pNext = pCur->pNext;

        if(pNext == pBeforeItem) {
            pCur->pNext = pNewItem;
            return;
        }
    }
}
示例#6
0
// appends data to the OpListQueue
void clsGlobalDataQueue::OpListStore(char * sNick) {
    if(OpListQueue.szLen == 0) {
        OpListQueue.szLen = sprintf(OpListQueue.sBuffer, "$OpList %s$$|", sNick);
    } else {
        int iDataLen = sprintf(msg, "%s$$|", sNick);
        if(CheckSprintf(iDataLen, 128, "clsGlobalDataQueue::OpListStore2") == true) {
            if(OpListQueue.szSize < OpListQueue.szLen+iDataLen) {
                size_t szAllignLen = Allign256(OpListQueue.szLen+iDataLen);
                char * pOldBuf = OpListQueue.sBuffer;
#ifdef _WIN32
                OpListQueue.sBuffer = (char *)HeapReAlloc(clsServerManager::hLibHeap, HEAP_NO_SERIALIZE, (void *)pOldBuf, szAllignLen);
#else
				OpListQueue.sBuffer = (char *)realloc(pOldBuf, szAllignLen);
#endif
                if(OpListQueue.sBuffer == NULL) {
                    OpListQueue.sBuffer = pOldBuf;

                    AppendDebugLog("%s - [MEM] Cannot reallocate %" PRIu64 " bytes in clsGlobalDataQueue::OpListStore\n", (uint64_t)szAllignLen);

                    return;
                }
                OpListQueue.szSize = (uint32_t)(szAllignLen-1);
            }
            memcpy(OpListQueue.sBuffer+OpListQueue.szLen-1, msg, iDataLen);
            OpListQueue.szLen += iDataLen-1;
            OpListQueue.sBuffer[OpListQueue.szLen] = '\0';
        }
    }
}
示例#7
0
void classUsers::Add2OpList(User * u) {
    if(opListSize < opListLen+u->ui8NickLen+2) {
        char * pOldBuf = opList;
#ifdef _WIN32
        opList = (char *)HeapReAlloc(hPtokaXHeap, HEAP_NO_SERIALIZE, (void *)pOldBuf, opListSize+OPLISTSIZE+1);
#else
		opList = (char *)realloc(pOldBuf, opListSize+OPLISTSIZE+1);
#endif
        if(opList == NULL) {
            opList = pOldBuf;
            u->ui32BoolBits |= User::BIT_ERROR;
            UserClose(u);

            AppendDebugLog("%s - [MEM] Cannot reallocate %" PRIu64 " bytes in classUsers::Add2OpList for opList\n", (uint64_t)(opListSize+OPLISTSIZE+1));

            return;
        }
        opListSize += OPLISTSIZE;
    }

    memcpy(opList+opListLen-1, u->sNick, u->ui8NickLen);
    opListLen += (uint32_t)(u->ui8NickLen+2);

    opList[opListLen-3] = '$';
    opList[opListLen-2] = '$';
    opList[opListLen-1] = '|';
    opList[opListLen] = '\0';

    iZOpListLen = 0;
}
示例#8
0
void classUsers::Add2MyInfosTag(User * u) {
    if(myInfosTagSize < myInfosTagLen+u->ui16MyInfoLongLen) {
        char * pOldBuf = myInfosTag;
#ifdef _WIN32
        myInfosTag = (char *)HeapReAlloc(hPtokaXHeap, HEAP_NO_SERIALIZE, (void *)pOldBuf, myInfosTagSize+MYINFOLISTSIZE+1);
#else
		myInfosTag = (char *)realloc(pOldBuf, myInfosTagSize+MYINFOLISTSIZE+1);
#endif
        if(myInfosTag == NULL) {
            myInfosTag = pOldBuf;
            u->ui32BoolBits |= User::BIT_ERROR;
            UserClose(u);

			AppendDebugLog("%s - [MEM] Cannot reallocate %" PRIu64 " bytes in classUsers::Add2MyInfosTag\n", (uint64_t)(myInfosTagSize+MYINFOLISTSIZE+1));

            return;
        }
        myInfosTagSize += MYINFOLISTSIZE;
    }

    memcpy(myInfosTag+myInfosTagLen, u->sMyInfoLong, u->ui16MyInfoLongLen);
    myInfosTagLen += u->ui16MyInfoLongLen;

    myInfosTag[myInfosTagLen] = '\0';

    iZMyInfosTagLen = 0;
}
示例#9
0
string & string::operator+=(const string & sStr) {
    if(sStr.c_str() == sEmpty) {
        return *this;
    }

    char * oldbuf = sData;

    if(sData == sEmpty) {
        sData = (char *)malloc(szDataLen+sStr.size()+1);
    } else {
        sData = (char *)realloc(oldbuf, szDataLen+sStr.size()+1);
    }

    if(sData == NULL) {
        sData = oldbuf;

        AppendDebugLog("%s - [MEM] Cannot allocate %" PRIu64 " bytes for sData in string::operator+=(string)\n", (uint64_t)(szDataLen+sStr.size()+1));

        return *this;
    }

    memcpy(sData+szDataLen, sStr.c_str(), sStr.size());
	szDataLen += sStr.size();
	sData[szDataLen] = '\0';

    return *this;
}
示例#10
0
ReservedNicksManager::ReservedNick * ReservedNicksManager::ReservedNick::CreateReservedNick(const char * sNewNick, const uint32_t ui32NickHash) {
    ReservedNick * pReservedNick = new (std::nothrow) ReservedNick();

    if(pReservedNick == NULL) {
        AppendDebugLog("%s - [MEM] Cannot allocate new pReservedNick in ReservedNick::CreateReservedNick\n");

        return NULL;
    }

    size_t szNickLen = strlen(sNewNick);
#ifdef _WIN32
    pReservedNick->m_sNick = (char *)HeapAlloc(ServerManager::m_hPtokaXHeap, HEAP_NO_SERIALIZE, szNickLen+1);
#else
	pReservedNick->m_sNick = (char *)malloc(szNickLen+1);
#endif
    if(pReservedNick->m_sNick == NULL) {
        AppendDebugLogFormat("[MEM] Cannot allocate %zu bytes in ReservedNick::CreateReservedNick\n", szNickLen+1);

        delete pReservedNick;
        return NULL;
    }
    memcpy(pReservedNick->m_sNick, sNewNick, szNickLen);
    pReservedNick->m_sNick[szNickLen] = '\0';

	pReservedNick->m_ui32Hash = ui32NickHash;

    return pReservedNick;
}
示例#11
0
string & string::operator+=(const char * sTxt) {
    size_t szLen = strlen(sTxt);

    char * oldbuf = sData;

    if(sData == sEmpty) {
        sData = (char *)malloc(szDataLen+szLen+1);
    } else {
        sData = (char *)realloc(oldbuf, szDataLen+szLen+1);
    }

    if(sData == NULL) {
        sData = oldbuf;

        AppendDebugLog("%s - [MEM] Cannot allocate %" PRIu64 " bytes for sData in string::operator+=(char)\n", (uint64_t)(szDataLen+szLen+1));

        return *this;
    }

    memcpy(sData+szDataLen, sTxt, szLen);
	szDataLen += szLen;
	sData[szDataLen] = '\0';

    return *this;
}
示例#12
0
void theLoop::Looper() {
#ifdef _WIN32
	KillTimer(NULL, srvLoopTimer);
#endif

	// PPK ... two loop stategy for saving badwith
	if(bRecv == true) {
		ReceiveLoop();
	} else {
		SendLoop();
		eventqueue->ProcessEvents();
	}

	if(bServerTerminated == false) {
		bRecv = !bRecv;

#ifdef _WIN32
        srvLoopTimer = SetTimer(NULL, 0, 100, NULL);

	    if(srvLoopTimer == 0) {
	        AppendDebugLog("%s - [ERR] Cannot start Looper in theLoop::Looper\n", 0);
	        exit(EXIT_FAILURE);
	    }
#endif
	} else {
	    // tell the scripts about the end
	    ScriptManager->OnExit();
	    
	    // send last possible global data
	    g_GlobalDataQueue->SendFinalQueue();
	    
	    ServerFinalStop(true);
	}
}
示例#13
0
void classUsers::Add2UserIP(User * cur) {
    int m = sprintf(msg,"$%s %s$", cur->sNick, cur->sIP);
    if(CheckSprintf(m, 1024, "classUsers::Add2UserIP") == false) {
        return;
    }

    if(userIPListSize < userIPListLen+m) {
        char * pOldBuf = userIPList;
#ifdef _WIN32
        userIPList = (char *)HeapReAlloc(hPtokaXHeap, HEAP_NO_SERIALIZE, (void *)pOldBuf, userIPListSize+IPLISTSIZE+1);
#else
		userIPList = (char *)realloc(pOldBuf, userIPListSize+IPLISTSIZE+1);
#endif
        if(userIPList == NULL) {
            userIPList = pOldBuf;
            cur->ui32BoolBits |= User::BIT_ERROR;
            UserClose(cur);

			AppendDebugLog("%s - [MEM] Cannot reallocate %" PRIu64 " bytes in classUsers::Add2UserIP\n", (uint64_t)(userIPListSize+IPLISTSIZE+1));

            return;
        }
        userIPListSize += IPLISTSIZE;
    }

    memcpy(userIPList+userIPListLen-1, msg+1, m-1);
    userIPListLen += m;

    userIPList[userIPListLen-2] = '$';
    userIPList[userIPListLen-1] = '|';
    userIPList[userIPListLen] = '\0';

    iZUserIPListLen = 0;
}
示例#14
0
void clsGlobalDataQueue::SingleItemStore(char * sData, const size_t &szDataLen, User * pFromUser, const int32_t &i32Profile, const uint8_t &ui8Type) {
    SingleDataItem * pNewItem = new SingleDataItem();
    if(pNewItem == NULL) {
		AppendDebugLog("%s - [MEM] Cannot allocate pNewItem in clsGlobalDataQueue::SingleItemStore\n", 0);
    	return;
    }

    if(sData != NULL) {
#ifdef _WIN32
        pNewItem->sData = (char *)HeapAlloc(clsServerManager::hLibHeap, HEAP_NO_SERIALIZE, szDataLen+1);
#else
		pNewItem->sData = (char *)malloc(szDataLen+1);
#endif
        if(pNewItem->sData == NULL) {
            delete pNewItem;

			AppendDebugLog("%s - [MEM] Cannot allocate %" PRIu64 " bytes in clsGlobalDataQueue::SingleItemStore\n", (uint64_t)(szDataLen+1));

            return;
        }

        memcpy(pNewItem->sData, sData, szDataLen);
        pNewItem->sData[szDataLen] = '\0';
    } else {
        pNewItem->sData = NULL;
    }

	pNewItem->szDataLen = szDataLen;

	pNewItem->pFromUser = pFromUser;

	pNewItem->ui8Type = ui8Type;

	pNewItem->pPrev = NULL;
	pNewItem->pNext = NULL;

    pNewItem->i32Profile = i32Profile;

    if(pNewSingleItems[0] == NULL) {
        pNewSingleItems[0] = pNewItem;
        pNewSingleItems[1] = pNewItem;
    } else {
        pNewItem->pPrev = pNewSingleItems[1];
        pNewSingleItems[1]->pNext = pNewItem;
        pNewSingleItems[1] = pNewItem;
    }
}
示例#15
0
void classUsers::Add2RecTimes(User * curUser) {
    time_t acc_time;
    time(&acc_time);

    if(ProfileMan->IsAllowed(curUser, ProfileManager::NOUSRSAMEIP) == true ||
        (acc_time-curUser->LoginTime) >= SettingManager->iShorts[SETSHORT_MIN_RECONN_TIME]) {
        return;
    }

    RecTime * pNewRecTime = new RecTime();

	if(pNewRecTime == NULL) {
		AppendDebugLog("%s - [MEM] Cannot allocate pNewRecTime in classUsers::Add2RecTimes\n", 0);
        return;
	}

#ifdef _WIN32
    pNewRecTime->sNick = (char *)HeapAlloc(hPtokaXHeap, HEAP_NO_SERIALIZE, curUser->ui8NickLen+1);
#else
	pNewRecTime->sNick = (char *)malloc(curUser->ui8NickLen+1);
#endif
	if(pNewRecTime->sNick == NULL) {
        delete pNewRecTime;

        AppendDebugLog("%s - [MEM] Cannot allocate %" PRIu64 " bytes in classUsers::Add2RecTimes\n", (uint64_t)(curUser->ui8NickLen+1));

        return;
    }

    memcpy(pNewRecTime->sNick, curUser->sNick, curUser->ui8NickLen);
    pNewRecTime->sNick[curUser->ui8NickLen] = '\0';

	pNewRecTime->ui64DisConnTick = ui64ActualTick-(acc_time-curUser->LoginTime);
    pNewRecTime->ui32NickHash = curUser->ui32NickHash;

    memcpy(pNewRecTime->ui128IpHash, curUser->ui128IpHash, 16);

    pNewRecTime->prev = NULL;
    pNewRecTime->next = RecTimeList;

	if(RecTimeList != NULL) {
		RecTimeList->prev = pNewRecTime;
	}

	RecTimeList = pNewRecTime;
}
示例#16
0
bool UdpDebug::New(User * pUser, const uint16_t ui16Port) {
	UdpDbgItem * pNewDbg = new (std::nothrow) UdpDbgItem();
    if(pNewDbg == NULL) {
		AppendDebugLog("%s - [MEM] Cannot allocate pNewDbg in UdpDebug::New\n");
    	return false;
    }

    // initialize dbg item
#ifdef _WIN32
    pNewDbg->m_sNick = (char *)HeapAlloc(ServerManager::m_hPtokaXHeap, HEAP_NO_SERIALIZE, pUser->m_ui8NickLen+1);
#else
	pNewDbg->m_sNick = (char *)malloc(pUser->m_ui8NickLen+1);
#endif
    if(pNewDbg->m_sNick == NULL) {
		AppendDebugLogFormat("[MEM] Cannot allocate %" PRIu8 " bytes for sNick in UdpDebug::New\n", pUser->m_ui8NickLen+1);

		delete pNewDbg;
        return false;
    }

    memcpy(pNewDbg->m_sNick, pUser->m_sNick, pUser->m_ui8NickLen);
    pNewDbg->m_sNick[pUser->m_ui8NickLen] = '\0';

    pNewDbg->m_ui32Hash = pUser->m_ui32NickHash;

    struct in6_addr i6addr;
    memcpy(&i6addr, &pUser->m_ui128IpHash, 16);

    bool bIPv6 = (IN6_IS_ADDR_V4MAPPED(&i6addr) == 0);

    if(bIPv6 == true) {
        ((struct sockaddr_in6 *)&pNewDbg->m_sasTo)->sin6_family = AF_INET6;
        ((struct sockaddr_in6 *)&pNewDbg->m_sasTo)->sin6_port = htons(ui16Port);
        memcpy(((struct sockaddr_in6 *)&pNewDbg->m_sasTo)->sin6_addr.s6_addr, pUser->m_ui128IpHash, 16);
        pNewDbg->m_sasLen = sizeof(struct sockaddr_in6);
    } else {
        ((struct sockaddr_in *)&pNewDbg->m_sasTo)->sin_family = AF_INET;
        ((struct sockaddr_in *)&pNewDbg->m_sasTo)->sin_port = htons(ui16Port);
        ((struct sockaddr_in *)&pNewDbg->m_sasTo)->sin_addr.s_addr = inet_addr(pUser->m_sIP);
        pNewDbg->m_sasLen = sizeof(struct sockaddr_in);
    }

    pNewDbg->m_Socket = socket((bIPv6 == true ? AF_INET6 : AF_INET), SOCK_DGRAM, IPPROTO_UDP);
#ifdef _WIN32
    if(pNewDbg->m_Socket == INVALID_SOCKET) {
        int iErr = WSAGetLastError();
#else
    if(pNewDbg->m_Socket == -1) {
#endif
        pUser->SendFormat("UdpDebug::New1", true, "*** [ERR] %s: %s (%d).|", LanguageManager::m_Ptr->m_sTexts[LAN_UDP_SCK_CREATE_ERR],
#ifdef _WIN32
			WSErrorStr(iErr), iErr);
#else
			ErrnoStr(errno), errno);
#endif
        delete pNewDbg;
        return false;
    }
示例#17
0
PXBReader::~PXBReader() {
#ifdef _WIN32
        if(pItemDatas != NULL) {
            if(HeapFree(clsServerManager::hPtokaXHeap, HEAP_NO_SERIALIZE, pItemDatas) == 0) {
                AppendDebugLog("%s - [MEM] Cannot deallocate pItemDatas in PXBReader::~PXBReader\n");
            }
        }
#else
		free(pItemDatas);
#endif

#ifdef _WIN32
        if(ui16ItemLengths != NULL) {
            if(HeapFree(clsServerManager::hPtokaXHeap, HEAP_NO_SERIALIZE, (void *)ui16ItemLengths) == 0) {
                AppendDebugLog("%s - [MEM] Cannot deallocate ui16ItemLengths in PXBReader::~PXBReader\n");
            }
        }
#else
		free(ui16ItemLengths);
#endif

#ifdef _WIN32
        if(sItemIdentifiers != NULL) {
            if(HeapFree(clsServerManager::hPtokaXHeap, HEAP_NO_SERIALIZE, (void *)sItemIdentifiers) == 0) {
                AppendDebugLog("%s - [MEM] Cannot deallocate sItemIdentifiers in PXBReader::~PXBReader\n");
            }
        }
#else
		free(sItemIdentifiers);
#endif

#ifdef _WIN32
        if(ui8ItemValues != NULL) {
            if(HeapFree(clsServerManager::hPtokaXHeap, HEAP_NO_SERIALIZE, (void *)ui8ItemValues) == 0) {
                AppendDebugLog("%s - [MEM] Cannot deallocate ui8ItemValues in PXBReader::~PXBReader\n");
            }
        }
#else
		free(ui8ItemValues);
#endif

    if(pFile != NULL) {
        fclose(pFile);
    }
}
示例#18
0
ReservedNicksManager::ReservedNick::~ReservedNick() {
#ifdef _WIN32
	if(m_sNick != NULL && HeapFree(ServerManager::m_hPtokaXHeap, HEAP_NO_SERIALIZE, (void *)m_sNick) == 0) {
        AppendDebugLog("%s - [MEM] Cannot deallocate m_sNick in ReservedNicksManager::ReservedNick::~ReservedNick\n");
    }
#else
	free(m_sNick);
#endif
}
示例#19
0
ResNickMan::ReservedNick::~ReservedNick() {
#ifdef _WIN32
	if(sNick != NULL && HeapFree(hPtokaXHeap, HEAP_NO_SERIALIZE, (void *)sNick) == 0) {
        AppendDebugLog("%s - [MEM] Cannot deallocate sNick in ResNickMan::ReservedNick::~ReservedNick\n", 0);
    }
#else
	free(sNick);
#endif
}
示例#20
0
bool PXBReader::PrepareArrays(const uint8_t &ui8Size) {
#ifdef _WIN32
    pItemDatas = (void **)HeapAlloc(clsServerManager::hPtokaXHeap, HEAP_NO_SERIALIZE | HEAP_ZERO_MEMORY, ui8Size*sizeof(void *));
#else
	pItemDatas = (void **)calloc(ui8Size, sizeof(void *));
#endif
    if(pItemDatas == NULL) {
		AppendDebugLog("%s - [MEM] Cannot create pItemDatas in PXBReader::PrepareArrays\n");
		return false;
    }

#ifdef _WIN32
    ui16ItemLengths = (uint16_t *)HeapAlloc(clsServerManager::hPtokaXHeap, HEAP_NO_SERIALIZE | HEAP_ZERO_MEMORY, ui8Size*sizeof(uint16_t));
#else
	ui16ItemLengths = (uint16_t *)calloc(ui8Size, sizeof(uint16_t));
#endif
    if(ui16ItemLengths == NULL) {
		AppendDebugLog("%s - [MEM] Cannot create ui16ItemLengths in PXBReader::PrepareArrays\n");
		return false;
    }

#ifdef _WIN32
    sItemIdentifiers = (char *)HeapAlloc(clsServerManager::hPtokaXHeap, HEAP_NO_SERIALIZE | HEAP_ZERO_MEMORY, ui8Size*(sizeof(char)*2));
#else
	sItemIdentifiers = (char *)calloc(ui8Size, sizeof(char)*2);
#endif
    if(sItemIdentifiers == NULL) {
		AppendDebugLog("%s - [MEM] Cannot create sItemIdentifiers in PXBReader::PrepareArrays\n");
		return false;
    }

#ifdef _WIN32
    ui8ItemValues = (uint8_t *)HeapAlloc(clsServerManager::hPtokaXHeap, HEAP_NO_SERIALIZE | HEAP_ZERO_MEMORY, ui8Size*sizeof(ui8ItemValues));
#else
	ui8ItemValues = (uint8_t *)calloc(ui8Size, sizeof(ui8ItemValues));
#endif
    if(ui8ItemValues == NULL) {
		AppendDebugLog("%s - [MEM] Cannot create ui8ItemValues in PXBReader::PrepareArrays\n");
		return false;
    }

	ui8AllocatedSize = ui8Size;
	return true;
}
示例#21
0
clsZlibUtility::~clsZlibUtility() {
#ifdef _WIN32
    if(pZbuffer != NULL) {
        if(HeapFree(clsServerManager::hPtokaXHeap, HEAP_NO_SERIALIZE, (void *)pZbuffer) == 0) {
			AppendDebugLog("%s - [MEM] Cannot deallocate pZbuffer in clsZlibUtility::~clsZlibUtility\n");
        }
    }
#else
	free(pZbuffer);
#endif
}
示例#22
0
clsTextFilesManager::TextFile::~TextFile() {
#ifdef _WIN32
    if(sCommand != NULL) {
        if(HeapFree(clsServerManager::hLibHeap, HEAP_NO_SERIALIZE, (void *)sCommand) == 0) {
			AppendDebugLog("%s - [MEM] Cannot deallocate sCommand in clsTextFilesManager::TextFile::~TextFile\n", 0);
        }
    }
#else
	free(sCommand);
#endif

#ifdef _WIN32
    if(sText != NULL) {
        if(HeapFree(clsServerManager::hLibHeap, HEAP_NO_SERIALIZE, (void *)sText) == 0) {
			AppendDebugLog("%s - [MEM] Cannot deallocate sText in clsTextFilesManager::TextFile::~TextFile\n", 0);
        }
    }
#else
	free(sText);
#endif
}
示例#23
0
void * clsGlobalDataQueue::InsertBlankQueueItem(void * pAfterItem, const uint8_t &ui8CmdType) {
    QueueItem * pNewItem = new QueueItem();
    if(pNewItem == NULL) {
		AppendDebugLog("%s - [MEM] Cannot allocate pNewItem in clsGlobalDataQueue::InsertBlankQueueItem\n", 0);
    	return NULL;
    }

    pNewItem->sCommand1 = NULL;
	pNewItem->szLen1 = 0;

    pNewItem->sCommand2 = NULL;
    pNewItem->szLen2 = 0;

	pNewItem->ui8CommandType = ui8CmdType;

    if(pAfterItem == pNewQueueItems[0]) {
        pNewItem->pNext = pNewQueueItems[0];
        pNewQueueItems[0] = pNewItem;
        return pNewItem;
    }

    QueueItem * pNext = pNewQueueItems[0];

    while(pNext != NULL) {
        QueueItem * pCur = pNext;
        pNext = pCur->pNext;

        if(pCur == pAfterItem) {
            if(pCur->pNext == NULL) {
                pNewQueueItems[1] = pNewItem;
            }

            pNewItem->pNext = pCur->pNext;
            pCur->pNext = pNewItem;
            return pNewItem;
        }
    }

	pNewItem->pNext = NULL;

    if(pNewQueueItems[0] == NULL) {
        pNewQueueItems[0] = pNewItem;
        pNewQueueItems[1] = pNewItem;
    } else {
        pNewQueueItems[1]->pNext = pNewItem;
        pNewQueueItems[1] = pNewItem;
    }

    return pNewItem;
}
示例#24
0
bool classUsers::CheckRecTime(User * curUser) {
    RecTime * next = RecTimeList;

    while(next != NULL) {
        RecTime * cur = next;
        next = cur->next;

        // check expires...
        if(cur->ui64DisConnTick+SettingManager->iShorts[SETSHORT_MIN_RECONN_TIME] <= ui64ActualTick) {
#ifdef _WIN32
            if(cur->sNick != NULL) {
                if(HeapFree(hPtokaXHeap, HEAP_NO_SERIALIZE, (void *)cur->sNick) == 0) {
                    AppendDebugLog("%s - [MEM] Cannot deallocate cur->sNick in classUsers::CheckRecTime\n", 0);
                }
            }
#else
			free(cur->sNick);
#endif

            if(cur->prev == NULL) {
                if(cur->next == NULL) {
                    RecTimeList = NULL;
                } else {
                    cur->next->prev = NULL;
                    RecTimeList = cur->next;
                }
            } else if(cur->next == NULL) {
                cur->prev->next = NULL;
            } else {
                cur->prev->next = cur->next;
                cur->next->prev = cur->prev;
            }

            delete cur;
            continue;
        }

        if(cur->ui32NickHash == curUser->ui32NickHash && memcmp(cur->ui128IpHash, curUser->ui128IpHash, 16) == 0 && strcasecmp(cur->sNick, curUser->sNick) == 0) {
            int imsgLen = sprintf(msg, "<%s> %s %" PRIu64 " %s.|", SettingManager->sPreTexts[SetMan::SETPRETXT_HUB_SEC], LanguageManager->sTexts[LAN_PLEASE_WAIT], 
                (cur->ui64DisConnTick+SettingManager->iShorts[SETSHORT_MIN_RECONN_TIME])-ui64ActualTick, LanguageManager->sTexts[LAN_SECONDS_BEFORE_RECONN]);
            if(CheckSprintf(imsgLen, 1024, "classUsers::CheckRecTime1") == true) {
                UserSendChar(curUser, msg, imsgLen);
            }
            return true;
        }
    }

    return false;
}
示例#25
0
UDPThread * UDPThread::Create(const int &iAddressFamily) {
    UDPThread * pUDPThread = new (std::nothrow) UDPThread();
    if(pUDPThread == NULL) {
        AppendDebugLog("%s - [MEM] Cannot allocate pUDPThread in UDPThread::Create\n");
        return NULL;
    }

    if(pUDPThread->Listen(iAddressFamily) == true) {
        pUDPThread->Resume();
        return pUDPThread;
    } else {
        delete pUDPThread;
        return NULL;
    }
}
示例#26
0
UdpDebug::UdpDbgItem::~UdpDbgItem() {
#ifdef _WIN32
    if(m_sNick != NULL) {
        if(HeapFree(ServerManager::m_hPtokaXHeap, HEAP_NO_SERIALIZE, (void *)m_sNick) == 0) {
            AppendDebugLog("%s - [MEM] Cannot deallocate m_sNick in UdpDebug::UdpDbgItem::~UdpDbgItem\n");
        }
    }
#else
	free(m_sNick);
#endif

#ifdef _WIN32
	closesocket(m_Socket);
#else
	close(m_Socket);
#endif
}
示例#27
0
void clsGlobalDataQueue::FillBlankQueueItem(char * sCommand, const size_t &szLen, void * pQueueItem) {
#ifdef _WIN32
    ((QueueItem *)pQueueItem)->sCommand1 = (char *)HeapAlloc(clsServerManager::hLibHeap, HEAP_NO_SERIALIZE, szLen+1);
#else
	((QueueItem *)pQueueItem)->sCommand1 = (char *)malloc(szLen+1);
#endif
    if(((QueueItem *)pQueueItem)->sCommand1 == NULL) {
		AppendDebugLog("%s - [MEM] Cannot allocate %" PRIu64 " bytes for pNewItem->sCommand1 in clsGlobalDataQueue::FillBlankQueueItem\n", (uint64_t)(szLen+1));

        return;
    }

    memcpy(((QueueItem *)pQueueItem)->sCommand1, sCommand, szLen);
    ((QueueItem *)pQueueItem)->sCommand1[szLen] = '\0';

	((QueueItem *)pQueueItem)->szLen1 = szLen;
}
示例#28
0
void string::stralloc(const char * sTxt, const size_t &szLen) {
	szDataLen = szLen;

	if(szDataLen == 0) {
		sData = (char *)sEmpty;
		return;
	}

	sData = (char *)malloc(szDataLen+1);
	if(sData == NULL) {
		AppendDebugLog("%s - [MEM] Cannot allocate %" PRIu64 " bytes for sData in string::stralloc\n", (uint64_t)(szDataLen+1));

        return;
	}

	memcpy(sData, sTxt, szDataLen);
	sData[szDataLen] = '\0';
}
示例#29
0
void UdpDebug::CreateBuffer() {
	if(m_sDebugBuffer != NULL) {
		return;
	}

#ifdef _WIN32
	m_sDebugBuffer = (char *)HeapAlloc(ServerManager::m_hPtokaXHeap, HEAP_NO_SERIALIZE, 4+256+65535);
#else
	m_sDebugBuffer = (char *)malloc(4+256+65535);
#endif
    if(m_sDebugBuffer == NULL) {
		AppendDebugLog("%s - [MEM] Cannot allocate 4+256+65535 bytes for m_sDebugBuffer in UdpDebug::CreateBuffer\n");

        exit(EXIT_FAILURE);
    }

	UpdateHubName();
}
示例#30
0
void theLoop::AcceptSocket(const SOCKET &s, const sockaddr_storage &addr) {
#else
void theLoop::AcceptSocket(const int &s, const sockaddr_storage &addr) {
#endif
    AcceptedSocket * pNewSocket = new AcceptedSocket();
    if(pNewSocket == NULL) {
#ifdef _WIN32
		shutdown(s, SD_SEND);
		closesocket(s);
#else
		shutdown(s, SHUT_RDWR);
		close(s);
#endif

		AppendDebugLog("%s - [MEM] Cannot allocate pNewSocket in theLoop::AcceptSocket\n", 0);
    	return;
    }

    pNewSocket->s = s;

    memcpy(&pNewSocket->addr, &addr, sizeof(sockaddr_storage));

    pNewSocket->next = NULL;

#ifdef _WIN32
    EnterCriticalSection(&csAcceptQueue);
#else
    pthread_mutex_lock(&mtxAcceptQueue);
#endif

    if(AcceptedSocketsS == NULL) {
        AcceptedSocketsS = pNewSocket;
        AcceptedSocketsE = pNewSocket;
    } else {
        AcceptedSocketsE->next = pNewSocket;
        AcceptedSocketsE = pNewSocket;
    }

#ifdef _WIN32
    LeaveCriticalSection(&csAcceptQueue);
#else
	pthread_mutex_unlock(&mtxAcceptQueue);
#endif
}