private string DoLogin(string formatString) { AnalysisStr analy = new AnalysisStr(formatString); DBFunction dbf = new DBFunction(); string format = "Server#" + OpType.LOGIN_RES + "#"; format += (dbf.Login(analy.GetParaIndexOf(0), analy.GetParaIndexOf(1)) == true?1:0); if (dbf.Login(analy.GetParaIndexOf(0), analy.GetParaIndexOf(1))) { string IP = endPoint.Address.ToString(); int Port = endPoint.Port; OLList.OnLined(new SmallUser(analy.GetUserID(), IP, Port)); string msg = "Server#" + OpType.INFORM_FRIENDS + "#" + analy.GetParaIndexOf(0); foreach (string userID in OLList.GetAllOLUsersID()) { if (dbf.IsFriend(analy.GetParaIndexOf(0), userID)) { SmallUser sUser = OLList.GetUserByID(userID); CClient client = new CClient(sUser.IPAddress, sUser.IPPort); client.ConnectToServer(); client.GetNetworkStream(); client.Communicate(msg); client.ReLeaseAll(); } } } return(format); }
//检测函数,检测客户端是否关闭,检测异常关闭以及挂掉 public void TrueOnLineUsers() { foreach (string userID in OLList.GetAllOLUsersID()) { if (OLList.IsOnLine(userID)) { try { CClient client = new CClient(OLList.GetUserByID(userID).IPAddress, OLList.GetUserByID(userID).IPPort); client.ConnectToServer(); client.GetNetworkStream(); client.Communicate("###"); client.ReLeaseAll(); } catch (Exception e) { OLList.OffLined(userID); System.Console.WriteLine(userID + "客户端异常关闭,现在在线用户数量:" + OLList.Length()); } } } }