增加错误消息,专门处理令牌协议的错误消息

This commit is contained in:
nnhy 2016-05-18 07:38:26 +00:00
parent 509bef4aa0
commit 104624792e
3 changed files with 61 additions and 4 deletions

30
TokenNet/ErrorMessage.cpp Normal file
View File

@ -0,0 +1,30 @@
#include "ErrorMessage.h"
#include "Message\BinaryPair.h"
// 初始化消息各字段为0
ErrorMessage::ErrorMessage() : ErrorContent("")
{
ErrorCode = 0;
}
// 读取消息
bool ErrorMessage::Read(const Message& msg)
{
auto ms = msg.ToStream();
BinaryPair bp(ms);
bp.Get("ErrorCode", ErrorCode);
bp.Get("ErrorMessage", ErrorContent);
return true;
}
// 写入消息
void ErrorMessage::ErrorMessage::Write(Message& msg) const
{
auto ms = msg.ToStream();
BinaryPair bp(ms);
bp.Set("ErrorCode", ErrorCode);
bp.Set("ErrorMessage", ErrorContent);
}

23
TokenNet/ErrorMessage.h Normal file
View File

@ -0,0 +1,23 @@
#ifndef __ErrorMessage_H__
#define __ErrorMessage_H__
#include "Sys.h"
#include "Message\Message.h"
// 错误消息
class ErrorMessage
{
public:
byte ErrorCode; // 错误码
String ErrorContent; // 错误内容
// 初始化消息
ErrorMessage();
// 读取消息
bool Read(const Message& msg);
// 写入消息
void Write(Message& msg) const;
};
#endif

View File

@ -12,6 +12,7 @@
#include "LoginMessage.h"
#include "RegisterMessage.h"
#include "TokenDataMessage.h"
#include "ErrorMessage.h"
#include "Security\RC4.h"
@ -381,11 +382,14 @@ void TokenClient::OnRegister(TokenMessage& msg ,Controller* ctrl)
if(msg.Error)
{
auto ms = msg.ToStream();
byte result = ms.ReadByte();
//auto ms = msg.ToStream();
//byte result = ms.ReadByte();
ErrorMessage em;
em.Read(msg);
debug_printf("注册失败,错误码 0x%02X", result);
ms.ReadString().Show(true);
debug_printf("注册失败,错误码 0x%02X", em.ErrorCode);
//ms.ReadString().Show(true);
em.ErrorContent.Show(true);
return;
}