| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- using DeepCore;
- using DeepCore.IO;
- using DeepCore.Reflection;
- using DeepMMO.Attributes;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Reflection;
- using System.Text;
- namespace DeepMMO.Protocol
- {
- /// <summary>
- /// 网络序列化标识接口
- /// </summary>
- public interface INetProtocol : ISerializable { }
- public interface INetProtocolS2C { }
- public interface INetProtocolC2S { }
- public interface INetProtocolBotIgnore { }
- //---------------------------------------------------------------------------------------------
- /// <summary>
- /// 请求
- /// </summary>
- public abstract class Request : INetProtocol, INetProtocolC2S
- {
- public override string ToString()
- {
- return string.Format("{0}", GetType().Name);
- }
- }
- /// <summary>
- /// 回馈
- /// </summary>
- public abstract class Response : INetProtocol, INetProtocolS2C
- {
- [MessageCodeAttribute("成功")]
- public const int CODE_OK = 200;
- [MessageCodeAttribute("未知错误")]
- public const int CODE_ERROR = 500;
- /// <summary>
- /// 返回码
- /// </summary>
- public int s2c_code = CODE_OK;
- /// <summary>
- /// 返回信息(优先网络消息,如果网络消息为空,则从MessageCode中找)
- /// </summary>
- public string s2c_msg;
- /// <summary>
- /// 内部消息,用于一个系统的反馈,传递给原始请求
- /// </summary>
- public Response InnerResponse;
-
- /// <summary>
- /// 请求是否成功
- /// </summary>
- public bool IsSuccess
- {
- get { return s2c_code >= 200 && s2c_code <= 299; }
- }
- public override string ToString()
- {
- return string.Format("{0}: {1} : {2}", GetType().Name, s2c_code, s2c_msg);
- }
- public static bool CheckSuccess(Response rsp)
- {
- return (rsp != null && rsp.IsSuccess);
- }
- public virtual void EndRead()
- {
- if (s2c_msg == null)
- {
- if (s2c_code == CODE_OK || s2c_code == CODE_ERROR)
- {
- if (InnerResponse != null)
- {
- InnerResponse.EndRead();
- s2c_msg = InnerResponse.s2c_msg;
- }
- }
- if (s2c_msg == null)
- {
- s2c_msg = MessageCodeManager.Instance.GetCodeMessage(this);
- }
- if (s2c_msg == null && InnerResponse != null)
- {
- s2c_msg = InnerResponse.s2c_msg;
- }
- }
- }
- }
- /// <summary>
- /// 单向通知
- /// </summary>
- public abstract class Notify : INetProtocol
- {
- }
- //---------------------------------------------------------------------------------------------
- //---------------------------------------------------------------------------------------------
- }
|