mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-07 16:45:10 +00:00
注册登录Demo
注册登录Demo
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
using TEngine.Core.Network;
|
||||
using System.Collections.Generic;
|
||||
using TEngine;
|
||||
using TEngine.Core.Network;
|
||||
using TEngine.Logic;
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
@@ -21,8 +24,27 @@ namespace GameLogic
|
||||
else
|
||||
{
|
||||
hasError = response.ErrorCode != 0;
|
||||
if (ErrCodeTextMap.TryGetValue(response.ErrorCode,out var ret))
|
||||
{
|
||||
Log.Error(ret);
|
||||
}
|
||||
}
|
||||
|
||||
return hasError;
|
||||
}
|
||||
|
||||
//Remark 这里图方便注册错误码文本,正常应该走文本配置表。
|
||||
public static Dictionary<int, string> ErrCodeTextMap = new Dictionary<int, string>
|
||||
{
|
||||
{
|
||||
ErrorCode.ERR_AccountAlreadyRegisted, "账户已经被注册了"
|
||||
},
|
||||
{
|
||||
ErrorCode.ERR_AccountOrPasswordError, "账户或者密码错误"
|
||||
},
|
||||
{
|
||||
ErrorCode.ERR_UserNotOnline, "用户当前不在线"
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
@@ -63,6 +63,18 @@ class NetWorkDemoUI : UIWindow
|
||||
|
||||
private void OnClickRegisterBtn()
|
||||
{
|
||||
if (GameClient.Instance.Status == GameClientStatus.StatusInit)
|
||||
{
|
||||
Log.Info("没有连接到服务器、请先点击连接到服务器按钮在进行此操作");
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(m_inputName.text) || string.IsNullOrEmpty(m_inputPassWord.text))
|
||||
{
|
||||
Log.Info("请输入账号和密码");
|
||||
return;
|
||||
}
|
||||
PlayerNetSys.Instance.DoRegisterReq(m_inputName.text,m_inputPassWord.text);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@@ -2,6 +2,7 @@
|
||||
using TEngine;
|
||||
using TEngine.Core;
|
||||
using TEngine.Core.Network;
|
||||
using UnityEngine;
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
@@ -18,8 +19,11 @@ namespace GameLogic
|
||||
base.Init();
|
||||
//注册登录消息回调。
|
||||
GameClient.Instance.RegisterMsgHandler(OuterOpcode.H_G2C_LoginResponse,OnLoginRes);
|
||||
//注册注册账号消息回调。
|
||||
GameClient.Instance.RegisterMsgHandler(OuterOpcode.H_G2C_RegisterResponse,OnRegisterRes);
|
||||
}
|
||||
|
||||
#region Login
|
||||
/// <summary>
|
||||
/// 登录消息回调。
|
||||
/// </summary>
|
||||
@@ -28,6 +32,7 @@ namespace GameLogic
|
||||
{
|
||||
if (NetworkUtils.CheckError(response))
|
||||
{
|
||||
Debug.Log("登录失败!");
|
||||
GameClient.Instance.Status = GameClientStatus.StatusConnected;
|
||||
return;
|
||||
}
|
||||
@@ -56,5 +61,43 @@ namespace GameLogic
|
||||
GameClient.Instance.Send(loginRequest);
|
||||
GameClient.Instance.Status = GameClientStatus.StatusLogin;
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Register
|
||||
/// <summary>
|
||||
/// 注册消息回调。
|
||||
/// </summary>
|
||||
/// <param name="response">网络回复消息包。</param>
|
||||
public void OnRegisterRes(IResponse response)
|
||||
{
|
||||
if (NetworkUtils.CheckError(response))
|
||||
{
|
||||
return;
|
||||
}
|
||||
H_G2C_RegisterResponse ret = (H_G2C_RegisterResponse)response;
|
||||
Log.Debug(ret.ToJson());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 注册消息请求。
|
||||
/// </summary>
|
||||
/// <param name="userName">用户名。</param>
|
||||
/// <param name="passWord">用户密码。</param>
|
||||
public void DoRegisterReq(string userName,string passWord)
|
||||
{
|
||||
H_C2G_RegisterRequest registerQuest =new H_C2G_RegisterRequest()
|
||||
{
|
||||
UserName = userName,
|
||||
Password = passWord
|
||||
};
|
||||
GameClient.Instance.Send(registerQuest);
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
@@ -152,6 +152,33 @@ namespace TEngine
|
||||
[ProtoMember(91, IsRequired = true)]
|
||||
public int ErrorCode { get; set; }
|
||||
[ProtoMember(1)]
|
||||
public uint UID { get; set; }
|
||||
[ProtoMember(2)]
|
||||
public string Text { get; set; }
|
||||
}
|
||||
/// <summary>
|
||||
/// 客户端发送消息请求注册账户
|
||||
/// </summary>
|
||||
[ProtoContract]
|
||||
public partial class H_C2G_RegisterRequest : AProto, IRequest
|
||||
{
|
||||
[ProtoIgnore]
|
||||
public H_G2C_RegisterResponse ResponseType { get; set; }
|
||||
public uint OpCode() { return OuterOpcode.H_C2G_RegisterRequest; }
|
||||
[ProtoMember(1)]
|
||||
public string UserName { get; set; }
|
||||
[ProtoMember(2)]
|
||||
public string Password { get; set; }
|
||||
[ProtoMember(3)]
|
||||
public uint SDKUID { get; set; }
|
||||
}
|
||||
[ProtoContract]
|
||||
public partial class H_G2C_RegisterResponse : AProto, IResponse
|
||||
{
|
||||
public uint OpCode() { return OuterOpcode.H_G2C_RegisterResponse; }
|
||||
[ProtoMember(91, IsRequired = true)]
|
||||
public int ErrorCode { get; set; }
|
||||
[ProtoMember(1)]
|
||||
public uint UID { get; set; }
|
||||
}
|
||||
}
|
||||
|
@@ -16,5 +16,7 @@ namespace TEngine
|
||||
public const int H_M2C_ReceiveAddressMessageToServer = 190000003;
|
||||
public const int H_C2G_LoginRequest = 110000003;
|
||||
public const int H_G2C_LoginResponse = 160000003;
|
||||
public const int H_C2G_RegisterRequest = 110000004;
|
||||
public const int H_G2C_RegisterResponse = 160000004;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user