Ejemplo n.º 1
0
        // 用户登录
        private void MessageUserLogin(MessageInfo messageInfo)
        {
            Debug.Log("账号登录");
            RequestLogin  _info   = ProtoTransfer.DeserializeProtoBuf3 <RequestLogin>(messageInfo.Buffer);
            User          user    = UserManager.Instance.GetUserByAccount(_info.Account);
            ResponseLogin _result = new ResponseLogin();

            if (user != null)
            {
                if (user.AccountData.Password == _info.Password)
                {
                    if (user.UserState == UserState.OffLine)
                    {
                        UserManager.Instance.UserLogin(_info.Account);
                        _result.Result = true;
                        _result.Token  = user.Token;
                    }
                    else
                    {
                        _result.Result = false;
                        _result.Reason = "账号已经登录";
                    }
                }
                else
                {
                    _result.Result = false;
                    _result.Reason = "账号或者密码错误";
                }
            }
            else
            {
                _result.Result = false;
                _result.Reason = "账号不存在";
            }

            MessageBuffer _message = new MessageBuffer((int)MessageID.ScResponseLogin, ProtoTransfer.SerializeProtoBuf3(_result), user == null ? 0 : user.Id);

            Debug.Log("账号登录:" + _result.Result.ToString());
            Send(new MessageInfo(_message, messageInfo.Session));
        }
Ejemplo n.º 2
0
        private void MessageToFile(ref Message message, string fileName)
        {
            // We copy the message to a buffer, and because it can only be used once, must create the message again from the buffer to
            // allow the SOAP service to get access to the message. This is only necessary because we print the stream details.
            MessageBuffer buffer = message.CreateBufferedCopy(Int32.MaxValue);

            message = buffer.CreateMessage();

            // Create a copy of the buffered message for use in the print so that we don't touch the original 'message' object.
            var copy = buffer.CreateMessage();

            // Create a string representation of the message to be written to a file.
            string strMessage = MessageString(ref copy);

            // Write the output.
            using (System.IO.FileStream outStream = new System.IO.FileStream($"{fileName}.txt", System.IO.FileMode.OpenOrCreate))
            {
                StreamWriter myWriter = new StreamWriter(outStream);
                myWriter.Write(strMessage);
                myWriter.Close();
            }
        }
Ejemplo n.º 3
0
        // 注册账号
        private void MessageUserRegister(MessageInfo messageInfo)
        {
            Debug.Log("注册账号");
            RequestRegigter  _info   = ProtoTransfer.DeserializeProtoBuf3 <RequestRegigter>(messageInfo.Buffer);
            bool             isUsing = UserManager.Instance.IsValidAccount(_info.Account);
            ResponseRegister _result = new ResponseRegister();

            if (isUsing)
            {
                _result.Result = false;
                _result.Reason = "账号已存在!";
            }
            else
            {
                _result.Result = true;
                UserManager.Instance.AddUser(_info.Account, messageInfo.Session, new UserAccountData(_info.Account, _info.Password));
            }
            MessageBuffer _message = new MessageBuffer((int)MessageID.ScResponseRegister, ProtoTransfer.SerializeProtoBuf3(_result), 0);

            Send(new MessageInfo(_message, messageInfo.Session));

            Debug.Log("注册账号:" + _result.Result.ToString());
        }
Ejemplo n.º 4
0
 public static T DeserializeProtoBuf3 <T>(MessageBuffer buffer) where T : Google.Protobuf.IMessage, new()
 {
     return(DeserializeProtoBuf3 <T>(buffer.Body()));
 }
Ejemplo n.º 5
0
 /// <summary>
 /// 序列化解析
 /// </summary>
 public static T DeserializeProtoBuf2 <T>(MessageBuffer buffer) where T : class, ProtoBuf.IExtensible
 {
     return(DeserializeProtoBuf2 <T>(buffer.Body()));
 }
Ejemplo n.º 6
0
 public void OnReceiveMessageKCP(MessageBuffer messageBuffer)
 {
     OnReceiveMessage_KCP?.Invoke(new MessageInfo(messageBuffer, this));
 }