Commit f548456a authored by mercury233's avatar mercury233

test

parent 8d0c7b3b
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
#include "../ocgcore/card.h" #include "../ocgcore/card.h"
#include <algorithm> #include <algorithm>
#include "lzma/LzmaLib.h" #include "lzma/LzmaLib.h"
#include <sstream>
namespace ygo { namespace ygo {
...@@ -20,157 +19,141 @@ Replay::~Replay() { ...@@ -20,157 +19,141 @@ Replay::~Replay() {
delete[] replay_data; delete[] replay_data;
delete[] comp_data; delete[] comp_data;
} }
std::wstring SA2W(std::string& strA)
{
setlocale(LC_ALL, "chs");
const char* _Source = strA.c_str();
size_t _Dsize = strA.size() + 1;
wchar_t *_Dest = new wchar_t[_Dsize];
wmemset(_Dest, 0, _Dsize);
mbstowcs(_Dest,_Source,_Dsize);
std::wstring result = _Dest;
delete []_Dest;
setlocale(LC_ALL, "C");
return result;
}
void Replay::BeginRecord() { void Replay::BeginRecord() {
if (ygo::replay_mode>0) { #ifdef YGOPRO_SERVER_MODE
if(ygo::replay_mode == 0) return;
#endif //YGOPRO_SERVER_MODE
#ifdef _WIN32 #ifdef _WIN32
if(is_recording) if(is_recording)
CloseHandle(recording_fp); CloseHandle(recording_fp);
std::stringstream ss; time_t nowtime = time(NULL);
ss<<ygo::aServerPort; struct tm *localedtime = localtime(&nowtime);
std::string ssss; wchar_t tmppath[80];
ssss=ss.str(); wcsftime(tmppath, 80, "./replay/%Y-%m-%d %H-%M-%S %%u.yrp", localedtime);
wchar_t path[80];
std::wstring comPrefix = L"./replay/"; myswprintf(path, tmppath, ygo::aServerPort);
recording_fp = CreateFileW(path, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_FLAG_WRITE_THROUGH, NULL);
std::wstring comID =comPrefix+ SA2W(ssss)+L"Replay.yrp" ; if(recording_fp == INVALID_HANDLE_VALUE)
return;
recording_fp = CreateFileW(comID.c_str(), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_FLAG_WRITE_THROUGH, NULL);
if(recording_fp == INVALID_HANDLE_VALUE)
return;
#else #else
if(is_recording) if(is_recording)
fclose(fp); fclose(fp);
time_t nowtime = time(NULL); time_t nowtime = time(NULL);
struct tm *localedtime = localtime(&nowtime); struct tm *localedtime = localtime(&nowtime);
char tmppath[40]; char tmppath[40];
strftime(tmppath, 40, "./replay/%Y-%m-%d %H-%M-%S %%u.yrp", localedtime); strftime(tmppath, 40, "./replay/%Y-%m-%d %H-%M-%S %%u.yrp", localedtime);
char path[40]; char path[40];
sprintf(path, tmppath, ygo::aServerPort); sprintf(path, tmppath, ygo::aServerPort);
fp = fopen(path, "wb"); fp = fopen(path, "wb");
if(!fp) if(!fp)
return; return;
#endif #endif
}
pdata = replay_data; pdata = replay_data;
is_recording = true; is_recording = true;
} }
void Replay::WriteHeader(ReplayHeader& header) { void Replay::WriteHeader(ReplayHeader& header) {
pheader = header; pheader = header;
if (ygo::replay_mode>0) { #ifdef YGOPRO_SERVER_MODE
if(ygo::replay_mode == 0) return;
#endif //YGOPRO_SERVER_MODE
#ifdef _WIN32 #ifdef _WIN32
DWORD size; DWORD size;
WriteFile(recording_fp, &header, sizeof(header), &size, NULL); WriteFile(recording_fp, &header, sizeof(header), &size, NULL);
#else #else
fwrite(&header, sizeof(header), 1, fp); fwrite(&header, sizeof(header), 1, fp);
fflush(fp); fflush(fp);
#endif #endif
}
} }
void Replay::WriteData(const void* data, unsigned int length, bool flush) { void Replay::WriteData(const void* data, unsigned int length, bool flush) {
if(!is_recording) if(!is_recording)
return; return;
memcpy(pdata, data, length); memcpy(pdata, data, length);
pdata += length; pdata += length;
if (ygo::replay_mode>0) { #ifdef YGOPRO_SERVER_MODE
if(ygo::replay_mode == 0) return;
#endif //YGOPRO_SERVER_MODE
#ifdef _WIN32 #ifdef _WIN32
DWORD size; DWORD size;
WriteFile(recording_fp, data, length, &size, NULL); WriteFile(recording_fp, data, length, &size, NULL);
#else #else
fwrite(data, length, 1, fp); fwrite(data, length, 1, fp);
if(flush) if(flush)
fflush(fp); fflush(fp);
#endif #endif
}
} }
void Replay::WriteInt32(int data, bool flush) { void Replay::WriteInt32(int data, bool flush) {
if(!is_recording) if(!is_recording)
return; return;
*((int*)(pdata)) = data; *((int*)(pdata)) = data;
pdata += 4; pdata += 4;
if (ygo::replay_mode>0) { #ifdef YGOPRO_SERVER_MODE
if(ygo::replay_mode == 0) return;
#endif //YGOPRO_SERVER_MODE
#ifdef _WIN32 #ifdef _WIN32
DWORD size; DWORD size;
WriteFile(recording_fp, &data, sizeof(int), &size, NULL); WriteFile(recording_fp, &data, sizeof(int), &size, NULL);
#else #else
fwrite(&data, sizeof(int), 1, fp); fwrite(&data, sizeof(int), 1, fp);
if(flush) if(flush)
fflush(fp); fflush(fp);
#endif #endif
}
} }
void Replay::WriteInt16(short data, bool flush) { void Replay::WriteInt16(short data, bool flush) {
if(!is_recording) if(!is_recording)
return; return;
*((short*)(pdata)) = data; *((short*)(pdata)) = data;
pdata += 2; pdata += 2;
if (ygo::replay_mode>0) { #ifdef YGOPRO_SERVER_MODE
if(ygo::replay_mode == 0) return;
#endif //YGOPRO_SERVER_MODE
#ifdef _WIN32 #ifdef _WIN32
DWORD size; DWORD size;
WriteFile(recording_fp, &data, sizeof(short), &size, NULL); WriteFile(recording_fp, &data, sizeof(short), &size, NULL);
#else #else
fwrite(&data, sizeof(short), 1, fp); fwrite(&data, sizeof(short), 1, fp);
if(flush) if(flush)
fflush(fp); fflush(fp);
#endif #endif
}
} }
void Replay::WriteInt8(char data, bool flush) { void Replay::WriteInt8(char data, bool flush) {
if(!is_recording) if(!is_recording)
return; return;
*pdata = data; *pdata = data;
pdata++; pdata++;
if (ygo::replay_mode>0) { #ifdef YGOPRO_SERVER_MODE
if(ygo::replay_mode == 0) return;
#endif //YGOPRO_SERVER_MODE
#ifdef _WIN32 #ifdef _WIN32
DWORD size; DWORD size;
WriteFile(recording_fp, &data, sizeof(char), &size, NULL); WriteFile(recording_fp, &data, sizeof(char), &size, NULL);
#else #else
fwrite(&data, sizeof(char), 1, fp); fwrite(&data, sizeof(char), 1, fp);
if(flush) if(flush)
fflush(fp); fflush(fp);
#endif #endif
}
} }
void Replay::Flush() { void Replay::Flush() {
if(!is_recording) if(!is_recording)
return; return;
if (ygo::replay_mode>0) { #ifdef YGOPRO_SERVER_MODE
if(ygo::replay_mode == 0) return;
#endif //YGOPRO_SERVER_MODE
#ifdef _WIN32 #ifdef _WIN32
#else #else
fflush(fp); fflush(fp);
#endif #endif
}
} }
void Replay::EndRecord() { void Replay::EndRecord() {
if(!is_recording) if(!is_recording)
return; return;
if (ygo::replay_mode>0) { #ifdef YGOPRO_SERVER_MODE
if(ygo::replay_mode == 0) return;
#endif //YGOPRO_SERVER_MODE
#ifdef _WIN32 #ifdef _WIN32
CloseHandle(recording_fp); CloseHandle(recording_fp);
#else #else
fclose(fp); fclose(fp);
#endif #endif
}
pheader.datasize = pdata - replay_data; pheader.datasize = pdata - replay_data;
pheader.flag |= REPLAY_COMPRESSED; pheader.flag |= REPLAY_COMPRESSED;
size_t propsize = 5; size_t propsize = 5;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment