Skip to content

Commit

Permalink
除超级管理员外,其他账户不允许同时在线
Browse files Browse the repository at this point in the history
  • Loading branch information
dathlin committed Jul 7, 2017
1 parent 0fa9cd9 commit 826659d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
2 changes: 1 addition & 1 deletion 软件系统客户端模版/FormMainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ private void ThreadPoolDownloadSizeLarge()
if (result.Content[0] == 'Y')
{
byte[] data = Convert.FromBase64String(result.Content.Substring(1));
string path32 = path + @"\" + PortraitSupport.SmallPortrait;
string path32 = path + @"\" + PortraitSupport.LargePortrait;
System.IO.File.WriteAllBytes(path32, data);
System.Diagnostics.Process.Start(path32);
}
Expand Down
40 changes: 37 additions & 3 deletions 软件系统服务端模版/FormServerWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -495,8 +495,18 @@ private void DataProcessingWithStartA(AsyncStateOne state, int customer, string
//提取账户,密码
string name = SoftBasic.GetValueFromJsonObject(json, UserAccount.UserNameText, "");
string password = SoftBasic.GetValueFromJsonObject(json, UserAccount.PasswordText, "");
net_simplify_server.SendMessage(state, customer, UserServer.ServerAccounts.CheckAccountJson(
name, password, state.GetRemoteEndPoint().Address.ToString()));

UserAccount account = UserServer.ServerAccounts.CheckAccount(name, password, state.GetRemoteEndPoint().Address.ToString());
//检测是否重复登录
if(account.LoginEnable)
{
if(IsClinetOnline(account.UserName))
{
account.LoginEnable = false;
account.ForbidMessage = "该账户已经登录";
}
}
net_simplify_server.SendMessage(state, customer, JObject.FromObject(account).ToString());
}
else if (customer == CommonHeadCode.SimplifyHeadCode.更新公告)
{
Expand Down Expand Up @@ -849,7 +859,7 @@ private void Net_socket_server_AllClientsStatusChange(string data)
{
//此处决定要不要将在线客户端的数据发送所有客户端
net_socket_server.SendAllClients(CommonHeadCode.MultiNetHeadCode.总在线信息, data);

Net_Socket_All_Clients = data;
if (IsWindowShow && IsHandleCreated)
{
BeginInvoke(new Action(() =>
Expand All @@ -860,6 +870,30 @@ private void Net_socket_server_AllClientsStatusChange(string data)
}
}

/// <summary>
/// 所有在线客户端的信息
/// </summary>
private string Net_Socket_All_Clients = string.Empty;
/// <summary>
/// 用来判断客户端是否已经在线,除了超级管理员,其他的账户不允许重复在线,重复登录的账户予以特殊标记
/// </summary>
/// <returns>该客户端是否在线</returns>
private bool IsClinetOnline(string userName)
{
if (userName == "admin") return false;
if(Net_Socket_All_Clients.Contains($"Name:{userName}#"))
{
return true;
}
else if(Net_Socket_All_Clients.EndsWith($"Name:{userName}"))
{
return true;
}
else
{
return false;
}
}

#endregion

Expand Down

0 comments on commit 826659d

Please sign in to comment.