unsigned long SV_TryClient(ServerConnection* conn, unsigned long id1, unsigned long id2, std::string login, std::string nickname, unsigned char sex) { char* data = NULL; unsigned long size = 0; std::string nickname1 = nickname; std::string nickname2; if(!Login_GetCharacter(login, id1, id2, size, data, nickname2) || !data) { Printf(LOG_Error, "[DB] Error: Login_GetCharacter(\"%s\", %u, %u, <size>, <data>, <nickname>).\n", login.c_str(), id1, id2); return 0xBADFACE0; } size_t n1w = nickname1.find_first_of('|'); if(n1w != nickname1.npos) nickname1.erase(n1w); if(nickname1 != nickname2) { Printf(LOG_Hacking, "[CS] %s - Hacking: tried to change nickname from \"%s\" to \"%s\"!\n", login.c_str(), nickname2.c_str(), nickname1.c_str()); return 0xBADFACE2; } SESSION_AddLogin(id1, id2); Packet pack; pack << (uint8_t)0xDD; pack << (uint32_t)(size + nickname.length() + login.length() + 1 + 4 * 7 + 5 - 5 - 5); pack << (uint32_t)id1 << (uint32_t)id2; pack << (uint32_t)login.length(); pack << (uint32_t)nickname.length(); pack << (uint32_t)size; pack << (uint32_t)sex; pack.AppendData((uint8_t*)data, size); pack.AppendData((uint8_t*)login.c_str(), login.length()); pack.AppendData((uint8_t*)nickname.c_str(), nickname.length()); delete[] data; if(SOCK_SendPacket(conn->Socket, pack, conn->Version) != 0) { SESSION_DelLogin(id1, id2); return 0xBADFACE1; } return 0; }
HRESULT CStreamParser::ParseRawSSA(Packet *pPacket) { int i, layer = 0, max_duration = 0; size_t size, line_size, data_size = pPacket->GetDataSize(); const char *start, *end, *data = (char *)pPacket->GetData(); char buffer[2048]; while(data_size) { int duration = ass_get_duration(data); max_duration = FFMAX(duration, max_duration); end = (char *)memchr(data, '\n', data_size); size = line_size = end ? end-data+1 : data_size; size -= end ? (end[-1]=='\r')+1 : 0; start = data; for (i=0; i<3; i++, start++) if (!(start = (char *)memchr(start, ',', size-(start-data)))) break; size -= start - data; // ASS packages with layer sscanf_s(data, "Dialogue: %d,", &layer); i = _snprintf_s(buffer, sizeof(buffer), "%I64d,%d,", 0, layer); size = FFMIN(i+size, sizeof(buffer)); memcpy(buffer+i, start, size-i); Packet *p = new Packet(); p->pmt = pPacket->pmt; pPacket->pmt = nullptr; p->bDiscontinuity = pPacket->bDiscontinuity; p->bSyncPoint = pPacket->bSyncPoint; p->StreamId = pPacket->StreamId; p->rtStart = pPacket->rtStart; p->rtStop = p->rtStart + (duration * 10000); p->AppendData(buffer, size); Queue(p); data += line_size; data_size -= line_size; } SAFE_DELETE(pPacket); return S_FALSE; }
HRESULT CStreamParser::ParseSRT(Packet *pPacket) { int ts_start, ts_end, x1 = -1, y1 = -1, x2 = -1, y2 = -1; const char *ptr = (const char *)pPacket->GetData(); const char *end = ptr + pPacket->GetDataSize(); if (pPacket->GetDataSize() == 0) return S_FALSE; while(ptr && end > ptr && *ptr) { // Read the embeded timestamp and find the start of the subtitle ptr = read_srt_ts(ptr, &ts_start, &ts_end, &x1, &y1, &x2, &y2); if (ptr) { const char *linestart = ptr; while (end > ptr) { if (*ptr != ' ' && *ptr != '\n' && *ptr != '\r') { ptr += strcspn(ptr, "\n") + 1; } else { if (*ptr++ == '\n') break; } } int size = ptr - linestart; Packet *p = new Packet(); p->pmt = pPacket->pmt; pPacket->pmt = nullptr; p->bDiscontinuity = pPacket->bDiscontinuity; p->bSyncPoint = pPacket->bSyncPoint; p->StreamId = pPacket->StreamId; p->rtStart = pPacket->rtStart; p->rtStop = pPacket->rtStop; p->AppendData(linestart, size); Queue(p); } } SAFE_DELETE(pPacket); return S_FALSE; }