我们在之前写了断线重连的内容

客户端断线重连

接下来把自动登录的部分补上。由于我们并没有具体写自动登录的逻辑,所以大部分是伪代码。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
using SimpleServer.Business;
public void Update()
{
//...

//断开连接后,连接服务器自动登录
//注意,只有确定了客户端点击登录过才能自动登录,这里没有加上这步判断
if(!string.IsNullOrEmpty(SecretKey) && m_Socket.Connected && m_IsReconnect)
{
//在本地保存了账户的token,使用token自动登录
//下面是伪代码
//ProtocolManager.LoginRequest(LoginType.Token, "userName", "password", (res, token) =>
//{
// if(res == LoginResult.Success)
// {

// }
// else
// {

// }
//});
m_IsReconnect = false;
}
MsgUpdate();
}