Skip to content

Commit

Permalink
修正客户端无法自动登陆的问题;修正Windows版本服务器初始化时无法创建表的问题;修正几处代码中的笔误;默认关闭心跳包检测,减少日志输出。
Browse files Browse the repository at this point in the history
  • Loading branch information
balloonwj committed Jun 18, 2019
1 parent 3f6c6a6 commit 843d60a
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 52 deletions.
6 changes: 3 additions & 3 deletions flamingoclient/Source/EncodingUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ENCODE_API EncodeUtil
{
public:
//===BEGIN: 注意:以下6个函数,需要在外部释放返回的字符串指针,否则会有内存泄露
static wchar_t* EncodeUtil::AnsiToUnicode(const char* lpszStr);
static wchar_t* AnsiToUnicode(const char* lpszStr);
static char* UnicodeToAnsi(const wchar_t* lpszStr);
static char* AnsiToUtf8(const char* lpszStr);
static char* Utf8ToAnsi(const char* lpszStr);
Expand All @@ -28,15 +28,15 @@ class ENCODE_API EncodeUtil
//===END: 注意:以下6个函数,需要在外部释放返回的字符串指针,否则会有内存泄露

//===BEGIN: 以下函数第一个参数是需要转换的源字符串指针,第二个参数是存放转换后的目标缓冲区指针,第三个参数是目标缓冲区的大小
static bool EncodeUtil::AnsiToUnicode(const char* lpszAnsi, wchar_t* lpszUnicode, int nLen);
static bool AnsiToUnicode(const char* lpszAnsi, wchar_t* lpszUnicode, int nLen);
static bool UnicodeToAnsi(const wchar_t* lpszUnicode, char* lpszAnsi, int nLen);
static bool AnsiToUtf8(const char* lpszAnsi, char* lpszUtf8, int nLen);
static bool Utf8ToAnsi(const char* lpszUtf8, char* lpszAnsi, int nLen);
static bool UnicodeToUtf8(const wchar_t* lpszUnicode, char* lpszUtf8, int nLen);
static bool Utf8ToUnicode(const char* lpszUtf8, wchar_t* lpszUnicode, int nLen);
//===END: 以下函数第一个参数是需要转换的源字符串指针,第二个参数是存放转换后的目标缓冲区指针,第三个参数是目标缓冲区的大小

static std::wstring EncodeUtil::AnsiToUnicode(const std::string& strAnsi);
static std::wstring AnsiToUnicode(const std::string& strAnsi);
static std::string UnicodeToAnsi(const std::wstring& strUnicode);
static std::string AnsiToUtf8(const std::string& strAnsi);
static std::string Utf8ToAnsi(const std::string& strUtf8);
Expand Down
20 changes: 17 additions & 3 deletions flamingoclient/Source/LoginDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ BOOL CLoginDlg::GetLoginAccountInfo(LOGIN_ACCOUNT_INFO* lpAccount)
return TRUE;
}

BOOL CLoginDlg::SetLoginAccountInfo(const LOGIN_ACCOUNT_INFO* lpAccount)
{
if (NULL == lpAccount)
return FALSE;

memcpy(&m_stAccountInfo, lpAccount, sizeof(LOGIN_ACCOUNT_INFO));
return TRUE;
}

void CLoginDlg::SetDefaultAccount(PCTSTR pszDefaultAccount)
{
m_strDefaultAccount = pszDefaultAccount;
Expand Down Expand Up @@ -200,9 +209,7 @@ void CLoginDlg::OnBtn_Login(UINT uNotifyCode, int nID, CWindow wndCtl)
// 记录当前用户信息
m_lpFMGClient->m_UserMgr.m_UserInfo.m_strAccount = m_stAccountInfo.szUser;

HANDLE hLoginThread = (HANDLE)::_beginthreadex(NULL, 0, LoginThreadProc, this, 0, NULL);
if (hLoginThread != NULL)
::CloseHandle(hLoginThread);
DoLogin();

EndDialog(IDOK);
}
Expand Down Expand Up @@ -701,4 +708,11 @@ void CLoginDlg::StatusMenuBtn_SetIconPic(CSkinButton& btnStatus, long nStatus)

btnStatus.SetIconPic(lpszFileName);
btnStatus.Invalidate();
}

void CLoginDlg::DoLogin()
{
HANDLE hLoginThread = (HANDLE)::_beginthreadex(NULL, 0, LoginThreadProc, this, 0, NULL);
if (hLoginThread != NULL)
::CloseHandle(hLoginThread);
}
4 changes: 4 additions & 0 deletions flamingoclient/Source/LoginDlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,13 @@ class CLoginDlg : public CDialogImpl<CLoginDlg>

public:
BOOL GetLoginAccountInfo(LOGIN_ACCOUNT_INFO* lpAccount);
BOOL SetLoginAccountInfo(const LOGIN_ACCOUNT_INFO* lpAccount);

void SetDefaultAccount(PCTSTR pszDefaultAccount);
void SetDefaultPassword(PCTSTR pszDefaultPassword);

void DoLogin();

private:
BOOL OnInitDialog(CWindow wndFocus, LPARAM lInitParam);
void OnSysCommand(UINT nID, CPoint pt);
Expand Down
2 changes: 2 additions & 0 deletions flamingoclient/Source/MainDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1440,6 +1440,8 @@ bool CMainDlg::StartLogin(BOOL bAutoLogin/* = FALSE*/)
if (!bRet)
return true;

m_LoginDlg.SetLoginAccountInfo(&m_stAccountInfo);
m_LoginDlg.DoLogin();
}
else
{
Expand Down
3 changes: 1 addition & 2 deletions flamingoclient/iAutoUpdate/iUpdateAuto.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@
<ClCompile>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_CRT_SECURE_NO_WARNINGS;_CRT_NON_CONFORMING_SWPRINTFS;_USE_32BIT_TIME_T;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>
</MinimalRebuild>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<PrecompiledHeader />
Expand Down
54 changes: 24 additions & 30 deletions flamingoserver/base/AsyncLog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,16 +140,14 @@ bool CAsyncLog::Output(long nLevel, const char* pszFmt, ...)
}
else
{
//为了让FATAL级别的日志能立即crash程序,采取同步写日志的方法
if (m_strFileName.empty())
{
std::cout << strLine << std::endl;
//为了让FATAL级别的日志能立即crash程序,采取同步写日志的方法
std::cout << strLine << std::endl;
#ifdef _WIN32
OutputDebugStringA(strLine.c_str());
OutputDebugStringA("\n");
OutputDebugStringA(strLine.c_str());
OutputDebugStringA("\n");
#endif
}
else

if (!m_strFileName.empty())
{
if (m_hLogFile == nullptr)
{
Expand Down Expand Up @@ -245,16 +243,14 @@ bool CAsyncLog::Output(long nLevel, const char* pszFileName, int nLineNo, const
}
else
{
//为了让FATAL级别的日志能立即crash程序,采取同步写日志的方法
if (m_strFileName.empty())
{
std::cout << strLine << std::endl;
//为了让FATAL级别的日志能立即crash程序,采取同步写日志的方法
std::cout << strLine << std::endl;
#ifdef _WIN32
OutputDebugStringA(strLine.c_str());
OutputDebugStringA("\n");
OutputDebugStringA(strLine.c_str());
OutputDebugStringA("\n");
#endif
}
else

if (!m_strFileName.empty())
{
if (m_hLogFile == nullptr)
{
Expand Down Expand Up @@ -386,17 +382,17 @@ void CAsyncLog::MakeLinePrefix(long nLevel, std::string& strPrefix)
//级别
strPrefix = "[INFO]";
if (nLevel == LOG_LEVEL_TRACE)
strPrefix = "[Trace]";
strPrefix = "[TRACE]";
else if (nLevel == LOG_LEVEL_DEBUG)
strPrefix = "[Debug]";
strPrefix = "[DEBUG]";
else if (nLevel == LOG_LEVEL_WARNING)
strPrefix = "[Warning]";
strPrefix = "[WARN]";
else if (nLevel == LOG_LEVEL_ERROR)
strPrefix = "[Error]";
strPrefix = "[ERROR]";
else if (nLevel == LOG_LEVEL_SYSERROR)
strPrefix = "[SYSE]";
else if (nLevel == LOG_LEVEL_FATAL)
strPrefix = "[Fatal]";
strPrefix = "[FATAL]";
else if (nLevel == LOG_LEVEL_CRITICAL)
strPrefix = "[CRITICAL]";

Expand Down Expand Up @@ -522,17 +518,15 @@ void CAsyncLog::WriteThreadProc()

strLine = m_listLinesToWrite.front();
m_listLinesToWrite.pop_front();
}

if (m_strFileName.empty())
{
std::cout << strLine << std::endl;
}

std::cout << strLine << std::endl;
#ifdef _WIN32
OutputDebugStringA(strLine.c_str());
OutputDebugStringA("\n");
OutputDebugStringA(strLine.c_str());
OutputDebugStringA("\n");
#endif
}
else

if (!m_strFileName.empty())
{
if (!WriteToFile(strLine))
return;
Expand Down
2 changes: 1 addition & 1 deletion flamingoserver/base/AsyncLog.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ enum LOG_LEVEL
#define LOGE(...) CAsyncLog::Output(LOG_LEVEL_ERROR, __FILE__, __LINE__, __VA_ARGS__)
#define LOGSYSE(...) CAsyncLog::Output(LOG_LEVEL_SYSERROR, __FILE__, __LINE__, __VA_ARGS__)
#define LOGF(...) CAsyncLog::Output(LOG_LEVEL_FATAL, __FILE__, __LINE__, __VA_ARGS__) //为了让FATAL级别的日志能立即crash程序,采取同步写日志的方法
#define LOGC(...) CAsyncLog::Output(LOG_LEVEL_CRITICAL, __FILE__, __LINE__, __VA_ARGS__) //为了让FATAL级别的日志能立即crash程序,采取同步写日志的方法
#define LOGC(...) CAsyncLog::Output(LOG_LEVEL_CRITICAL, __FILE__, __LINE__, __VA_ARGS__) //关键信息,无视日志级别,总是输出

//用于输出数据包的二进制格式
#define LOG_DEBUG_BIN(buf, buflength) CAsyncLog::OutputBinary(buf, buflength)
Expand Down
8 changes: 4 additions & 4 deletions flamingoserver/base/ConfigFileReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ int CConfigFileReader::SetConfigValue(const char* name, const char* value)
m_config_map.insert(std::make_pair(name, value));
}

return _WriteFIle();
return _WriteFile();
}
void CConfigFileReader::_LoadFile(const char* filename)
{
Expand Down Expand Up @@ -80,7 +80,7 @@ void CConfigFileReader::_LoadFile(const char* filename)
m_load_ok = true;
}

int CConfigFileReader::_WriteFIle(const char* filename)
int CConfigFileReader::_WriteFile(const char* filename)
{
FILE* fp = NULL;
if(filename == NULL)
Expand Down Expand Up @@ -132,7 +132,7 @@ char* CConfigFileReader::_TrimSpace(char* name)
{
// remove starting space or tab
char* start_pos = name;
while ( (*start_pos == ' ') || (*start_pos == '\t') )
while ( (*start_pos == ' ') || (*start_pos == '\t') || (*start_pos == '\r'))
{
start_pos++;
}
Expand All @@ -142,7 +142,7 @@ char* CConfigFileReader::_TrimSpace(char* name)

// remove ending space or tab
char* end_pos = name + strlen(name) - 1;
while ( (*end_pos == ' ') || (*end_pos == '\t') )
while ( (*end_pos == ' ') || (*end_pos == '\t') || (*end_pos == '\r'))
{
*end_pos = 0;
end_pos--;
Expand Down
2 changes: 1 addition & 1 deletion flamingoserver/base/ConfigFileReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class CConfigFileReader

private:
void _LoadFile(const char* filename);
int _WriteFIle(const char* filename = NULL);
int _WriteFile(const char* filename = NULL);
void _ParseLine(char* line);
char* _TrimSpace(char* name);

Expand Down
4 changes: 2 additions & 2 deletions flamingoserver/chatserversrc/ChatSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ m_isLogin(false)

//#ifndef _DEBUG
//����ע�͵��������ڵ���
EnableHearbeatCheck();
//EnableHearbeatCheck();
//#endif
}

Expand Down Expand Up @@ -1836,5 +1836,5 @@ void ChatSession::CheckHeartbeat(const std::shared_ptr<TcpConnection>& conn)
return;

conn->forceClose();
LOGI("in max no-package time, no package, close the connection, userid: %d, clientType: %d, client address: %s", m_userinfo.userid, m_userinfo.clienttype, conn->peerAddress().toIpPort().c_str());
//LOGI("in max no-package time, no package, close the connection, userid: %d, clientType: %d, client address: %s", m_userinfo.userid, m_userinfo.clienttype, conn->peerAddress().toIpPort().c_str());
}
6 changes: 3 additions & 3 deletions flamingoserver/mysqlapi/DatabaseMysql.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,23 +178,23 @@ bool CDatabaseMysql::Execute(const char* sql)
if (CR_SERVER_GONE_ERROR == uErrno)
{
//LOGI << "CDatabaseMysql::Query, mysql is disconnected!";
if (false == Initialize(m_DBInfo.strHost, m_DBInfo.strUser,
m_DBInfo.strPwd, m_DBInfo.strDBName))
if (false == Initialize(m_DBInfo.strHost, m_DBInfo.strUser, m_DBInfo.strPwd, m_DBInfo.strDBName))
{
return false;
}
//LOGI << sql;
iTempRet = mysql_real_query(m_Mysql, sql, strlen(sql));
if (iTempRet)
{
//LOGE << "SQL: " << sql;
LOGE("sql error: %s, sql: %s", mysql_error(m_Mysql), sql);
//LOGE << "query ERROR: " << mysql_error(m_Mysql);
}
}
else
{
//LOGE << "SQL: " << sql;
//LOGE << "query ERROR: " << mysql_error(m_Mysql);
LOGE("sql error: %s, sql: %s", mysql_error(m_Mysql), sql);
}
return false;
}
Expand Down
7 changes: 4 additions & 3 deletions flamingoserver/mysqlmgr/MysqlManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ CMysqlManager::CMysqlManager(void)
info.m_mapField["f_id"] = { "f_id", "bigint(20) NOT NULL AUTO_INCREMENT COMMENT '自增ID'", "bigint(20)" };
info.m_mapField["f_user_id1"] = { "f_user_id1", "bigint(20) NOT NULL COMMENT '用户ID'", "bigint(20)" };
info.m_mapField["f_user_id2"] = { "f_user_id2", "bigint(20) NOT NULL COMMENT '用户ID'", "bigint(20)" };
info.m_mapField["f_user1_teamname"] = { "f_user1_teamname", "VARCHAR(32) NOT NULL DEFAULT '我的好友' COMMENT '用户2在用户1的好友分组名称'", "VARCHAR(32)" };
info.m_mapField["f_user2_teamname"] = { "f_user2_teamname", "VARCHAR(32) NOT NULL DEFAULT '我的好友' COMMENT '用户1在用户2的好友分组名称'", "VARCHAR(32)" };
info.m_mapField["f_user1_teamname"] = { "f_user1_teamname", "VARCHAR(32) NOT NULL DEFAULT 'My Friends' COMMENT '用户2在用户1的好友分组名称'", "VARCHAR(32)" };
info.m_mapField["f_user2_teamname"] = { "f_user2_teamname", "VARCHAR(32) NOT NULL DEFAULT 'My Friends' COMMENT '用户1在用户2的好友分组名称'", "VARCHAR(32)" };
info.m_mapField["f_user1_markname"] = { "f_user1_markname", "VARCHAR(32) COMMENT '用户2在用户1的备注名称'", "VARCHAR(32)" },
info.m_mapField["f_user2_markname"] = { "f_user2_markname", "VARCHAR(32) COMMENT '用户1在用户2的备注名称'", "VARCHAR(32)" },
info.m_mapField["f_remark"] = { "f_remark", "varchar(64) NULL COMMENT '备注'", "varchar(64)" };
Expand Down Expand Up @@ -329,6 +329,7 @@ bool CMysqlManager::_CreateTable(const STableInfo& table)
return true;
}

return false;
LOGE("Create table error, sql: %s", ss.str().c_str());
return false;
}

0 comments on commit 843d60a

Please sign in to comment.