Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ylmbtm committed Feb 21, 2021
1 parent 7441d54 commit eb7d007
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 87 deletions.
48 changes: 44 additions & 4 deletions Server/Src/ServerEngine/CommonFunc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,13 @@ tm CommonFunc::GetCurrTmTime()
return _tm_time;
}

UINT64 CommonFunc::GetDayBeginTime()
UINT64 CommonFunc::GetDayBeginTime(UINT64 uTime)
{
time_t t = (time_t)GetCurrTime();
if (uTime == 0)
{
uTime = GetCurrTime();
}
time_t t = (time_t)uTime;
tm* t_tm = localtime(&t);
t_tm->tm_hour = 0;
t_tm->tm_min = 0;
Expand All @@ -92,13 +96,38 @@ UINT64 CommonFunc::GetDayBeginTime()
return (UINT64)t;
}

UINT64 CommonFunc::GetWeekBeginTime()
UINT64 CommonFunc::GetWeekBeginTime(UINT64 uTime)
{
time_t t = (time_t)GetCurrTime();
if (uTime == 0)
{
uTime = GetCurrTime();
}

time_t t = (time_t)uTime;
tm* t_tm = localtime(&t);
return (UINT64)t - (t_tm->tm_wday == 0 ? 6 : t_tm->tm_wday - 1) * 86400 - t_tm->tm_hour * 3600 - t_tm->tm_min * 60 - t_tm->tm_sec;
}


UINT64 CommonFunc::GetMonthBeginTime(UINT64 uTime)
{
if (uTime == 0)
{
uTime = GetCurrTime();
}
time_t t = (time_t)uTime;
tm* t_tm = localtime(&t);
tm newtm;
newtm.tm_year = t_tm->tm_year;
newtm.tm_mon = t_tm->tm_mon;
newtm.tm_mday = 1;
newtm.tm_hour = 0;
newtm.tm_min = 0;
newtm.tm_sec = 0;

return mktime(&newtm);
}

time_t CommonFunc::YearTimeToSec(INT32 nYear, INT32 nMonth, INT32 nDay, INT32 nHour, INT32 nMin, INT32 nSec)
{
time_t t = (time_t)GetCurrTime();
Expand Down Expand Up @@ -296,6 +325,17 @@ BOOL CommonFunc::IsSameWeek(UINT64 uTime)
return (SrcWeekBegin - SrcWeekDest) / (86400 * 7) <= 0;
}

BOOL CommonFunc::IsSameMonth(UINT64 uTime)
{
time_t t = uTime;
tm t_tmSrc = *localtime(&t);

time_t t_mon = GetCurrTime();
tm t_tmDest = *localtime(&t_mon);

return (t_tmSrc.tm_mon == t_tmDest.tm_mon);
}

INT32 CommonFunc::DiffWeeks(UINT64 uTimeSrc, UINT64 uTimeDest)
{
time_t t = uTimeSrc;
Expand Down
60 changes: 33 additions & 27 deletions Server/Src/ServerEngine/CommonFunc.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,75 +7,81 @@

namespace CommonFunc
{
UINT32 GetProcessorNum();
UINT32 GetProcessorNum();

std::string GetCurrentWorkDir();
std::string GetCurrentWorkDir();

BOOL SetCurrentWorkDir(std::string strPath);
BOOL SetCurrentWorkDir(std::string strPath);

std::string GetCurrentExeDir();
std::string GetCurrentExeDir();

BOOL CreateDir(std::string& strDir);
BOOL CreateDir(std::string& strDir);

BOOL GetDirFiles(const char* pszDir, char* pszFileType, std::vector<std::string>& vtFileList, BOOL bRecursion);
BOOL GetDirFiles(const char* pszDir, char* pszFileType, std::vector<std::string>& vtFileList, BOOL bRecursion);

BOOL IsSameDay(UINT64 uTime);
BOOL IsSameDay(UINT64 uTime);

BOOL IsSameWeek(UINT64 uTime);

BOOL IsSameMonth(UINT64 uTime);

INT32 DiffWeeks(UINT64 uTimeSrc, UINT64 uTimeDest);

INT32 DiffDays(UINT64 uTimeSrc, UINT64 uTimeDest);

UINT64 GetCurrTime(); //获取当前的秒数
UINT64 GetCurrTime(); //获取当前的秒数

UINT64 GetCurMsTime(); //获取当前的毫秒数

UINT64 GetCurMsTime(); //获取当前的毫秒数
tm GetCurrTmTime();

tm GetCurrTmTime();
UINT64 GetDayBeginTime(UINT64 uTime = 0); //获取当天起点的秒数

UINT64 GetDayBeginTime(); //获取当天起点的秒数
UINT64 GetWeekBeginTime(UINT64 uTime = 0); //获取当周起点的秒数

UINT64 GetWeekBeginTime(); //获取当周起点的秒数
UINT64 GetMonthBeginTime(UINT64 uTime = 0);//获取当月起点的秒数

time_t YearTimeToSec(INT32 nYear, INT32 nMonth, INT32 nDay, INT32 nHour, INT32 nMin, INT32 nSec);
time_t YearTimeToSec(INT32 nYear, INT32 nMonth, INT32 nDay, INT32 nHour, INT32 nMin, INT32 nSec);

std::string TimeToString(time_t tTime);

time_t DateStringToTime(std::string strDate);

UINT64 GetTickCount();
UINT64 GetTickCount();

UINT32 GetCurThreadID();
UINT32 GetCurThreadID();

UINT32 GetCurProcessID();
UINT32 GetCurProcessID();

VOID Sleep(UINT32 dwMilliseconds);
VOID Sleep(UINT32 dwMilliseconds);

UINT32 GetFreePhysMemory();
UINT32 GetFreePhysMemory();

INT32 GetRandNum(INT32 nType);

UINT32 GetLastError();
UINT32 GetLastError();

std::string GetLastErrorStr(INT32 nError);

// HANDLE CreateShareMemory(std::string strName, INT32 nSize);
//
// HANDLE OpenShareMemory(std::string strName);
// HANDLE OpenShareMemory(std::string strName);

HANDLE CreateShareMemory(UINT32 dwModuleID, UINT32 dwAreaID, INT32 nPage, INT32 nSize);

HANDLE CreateShareMemory(UINT32 dwModuleID, INT32 nPage, INT32 nSize);
HANDLE OpenShareMemory(UINT32 dwModuleID, UINT32 dwAreaID, INT32 nPage);

HANDLE OpenShareMemory(UINT32 dwModuleID, INT32 nPage);
CHAR* GetShareMemory(HANDLE hShm);

CHAR* GetShareMemory(HANDLE hShm);
BOOL ReleaseShareMemory(CHAR* pMem);

BOOL ReleaseShareMemory(CHAR* pMem);
BOOL CloseShareMemory(HANDLE hShm);

BOOL CloseShareMemory(HANDLE hShm);
BOOL ClearShareMemory(UINT32 dwAreaID);

BOOL DbgTrace(char* format, ...);
BOOL DbgTrace(char* format, ...);

BOOL KillProcess(UINT64 dwPid);
BOOL KillProcess(UINT64 dwPid);

BOOL IsProcessExist(UINT64 dwPid);

Expand Down
112 changes: 56 additions & 56 deletions Server/Src/ServerEngine/Platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,64 +44,64 @@
#include <dirent.h>
#include <netdb.h>

#define WSAEWOULDBLOCK EWOULDBLOCK
#define WSAEINPROGRESS EINPROGRESS
#define WSAEALREADY EALREADY
#define WSAENOTSOCK ENOTSOCK
#define WSAEDESTADDRREQ EDESTADDRREQ
#define WSAEMSGSIZE EMSGSIZE
#define WSAEPROTOTYPE EPROTOTYPE
#define WSAENOPROTOOPT ENOPROTOOPT
#define WSAEPROTONOSUPPORT EPROTONOSUPPORT
#define WSAESOCKTNOSUPPORT ESOCKTNOSUPPORT
#define WSAEOPNOTSUPP EOPNOTSUPP
#define WSAEPFNOSUPPORT EPFNOSUPPORT
#define WSAEAFNOSUPPORT EAFNOSUPPORT
#define WSAEADDRINUSE EADDRINUSE
#define WSAEADDRNOTAVAIL EADDRNOTAVAIL
#define WSAENETDOWN ENETDOWN
#define WSAENETUNREACH ENETUNREACH
#define WSAENETRESET ENETRESET
#define WSAECONNABORTED ECONNABORTED
#define WSAECONNRESET ECONNRESET
#define WSAENOBUFS ENOBUFS
#define WSAEISCONN EISCONN
#define WSAENOTCONN ENOTCONN
#define WSAESHUTDOWN ESHUTDOWN
#define WSAETOOMANYREFS ETOOMANYREFS
#define WSAETIMEDOUT ETIMEDOUT
#define WSAECONNREFUSED ECONNREFUSED
#define WSAELOOP ELOOP
#define WSAENAMETOOLONG ENAMETOOLONG
#define WSAEHOSTDOWN EHOSTDOWN
#define WSAEHOSTUNREACH EHOSTUNREACH
#define WSAENOTEMPTY ENOTEMPTY
#define WSAEPROCLIM EPROCLIM
#define WSAEUSERS EUSERS
#define WSAEDQUOT EDQUOT
#define WSAESTALE ESTALE
#define WSAEREMOTE EREMOTE
#define WSAEWOULDBLOCK EWOULDBLOCK
#define WSAEINPROGRESS EINPROGRESS
#define WSAEALREADY EALREADY
#define WSAENOTSOCK ENOTSOCK
#define WSAEDESTADDRREQ EDESTADDRREQ
#define WSAEMSGSIZE EMSGSIZE
#define WSAEPROTOTYPE EPROTOTYPE
#define WSAENOPROTOOPT ENOPROTOOPT
#define WSAEPROTONOSUPPORT EPROTONOSUPPORT
#define WSAESOCKTNOSUPPORT ESOCKTNOSUPPORT
#define WSAEOPNOTSUPP EOPNOTSUPP
#define WSAEPFNOSUPPORT EPFNOSUPPORT
#define WSAEAFNOSUPPORT EAFNOSUPPORT
#define WSAEADDRINUSE EADDRINUSE
#define WSAEADDRNOTAVAIL EADDRNOTAVAIL
#define WSAENETDOWN ENETDOWN
#define WSAENETUNREACH ENETUNREACH
#define WSAENETRESET ENETRESET
#define WSAECONNABORTED ECONNABORTED
#define WSAECONNRESET ECONNRESET
#define WSAENOBUFS ENOBUFS
#define WSAEISCONN EISCONN
#define WSAENOTCONN ENOTCONN
#define WSAESHUTDOWN ESHUTDOWN
#define WSAETOOMANYREFS ETOOMANYREFS
#define WSAETIMEDOUT ETIMEDOUT
#define WSAECONNREFUSED ECONNREFUSED
#define WSAELOOP ELOOP
#define WSAENAMETOOLONG ENAMETOOLONG
#define WSAEHOSTDOWN EHOSTDOWN
#define WSAEHOSTUNREACH EHOSTUNREACH
#define WSAENOTEMPTY ENOTEMPTY
#define WSAEPROCLIM EPROCLIM
#define WSAEUSERS EUSERS
#define WSAEDQUOT EDQUOT
#define WSAESTALE ESTALE
#define WSAEREMOTE EREMOTE

typedef char INT8;
typedef unsigned char UINT8;
typedef short INT16;
typedef unsigned short UINT16;
typedef int INT32;
typedef unsigned int UINT32;
typedef int BOOL;
typedef void VOID;
typedef float FLOAT;
typedef double DOUBLE;
typedef long long INT64;
typedef unsigned long long UINT64;
typedef char BYTE;
typedef char CHAR;
typedef int SOCKET;
typedef int HANDLE;
typedef char INT8;
typedef unsigned char UINT8;
typedef short INT16;
typedef unsigned short UINT16;
typedef int INT32;
typedef unsigned int UINT32;
typedef int BOOL;
typedef void VOID;
typedef float FLOAT;
typedef double DOUBLE;
typedef long long INT64;
typedef unsigned long long UINT64;
typedef unsigned char BYTE;
typedef char CHAR;
typedef int SOCKET;
typedef int HANDLE;

#define INVALID_SOCKET (-1)
#define TRUE 1
#define FALSE 0
#define INVALID_SOCKET (-1)
#define TRUE 1
#define FALSE 0
#define INVALID_HANDLE_VALUE 0
#endif

Expand Down

0 comments on commit eb7d007

Please sign in to comment.