// 请求匹配 private void MessageRequestMatch(MessageInfo messageInfo) { RequestMatch _info = ProtoTransfer.DeserializeProtoBuf3 <RequestMatch>(messageInfo.Buffer); User user = UserManager.Instance.GetUserByToken(_info.Token); MatchManager.Instance.AddMatchUser(user); MessageBuffer _message = new MessageBuffer((int)MessageID.ScResponseMatch, ProtoTransfer.SerializeProtoBuf3(new ResponseRequestMatch()), user.Id); Debug.Log("用户请求匹配"); Send(new MessageInfo(_message, messageInfo.Session)); }
// 取消匹配 private void MessageCancelMatch(MessageInfo messageInfo) { RequestCancelMatch _info = ProtoTransfer.DeserializeProtoBuf3 <RequestCancelMatch>(messageInfo.Buffer); User user = UserManager.Instance.GetUserByToken(_info.Token); bool _result = MatchManager.Instance.CancleMatch(user); if (_result && user != null) { MessageBuffer _message = new MessageBuffer((int)MessageID.ScResponseCancelMatch, ProtoTransfer.SerializeProtoBuf3(new ResponseCancelMatch()), user.Id); Debug.Log("用户取消匹配"); Send(new MessageInfo(_message, messageInfo.Session)); } }
// Ping private void MessagePing(MessageInfo messageInfo) { RequestPing requestPing = ProtoTransfer.DeserializeProtoBuf3 <RequestPing>(messageInfo.Buffer); User user = UserManager.Instance.GetUserByToken(requestPing.Token); if (user != null) { ResponsePing responsePing = new ResponsePing() { Uid = user.Id, Token = user.Token }; MessageBuffer _message = new MessageBuffer((int)MessageID.ScResponsePing, ProtoTransfer.SerializeProtoBuf3(responsePing), user.Id); Send(new MessageInfo(_message, messageInfo.Session)); } }
// 用户登录 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)); }
// 注册账号 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()); }
public T Get <T>() where T : Google.Protobuf.IMessage, new() { T t = ProtoTransfer.DeserializeProtoBuf3 <T>(mData); return(t); }