public void Process(Socket workerSock) { NewUserOnlineMsg msg = new NewUserOnlineMsg(); msg.ReceiveFrom(workerSock); if (!UserService.LoginOk) { return; } if (msg.UserName == UserService.LoginUserName) { return; } if (UserService.CurrentUsersFriend == null) { return; } var x = UserService.CurrentUsersFriend.Find(u => u.UserName == msg.UserName); if (x != null) { x.IPEnd = new IPEndPoint(IPAddress.Parse(msg.Ip), 0); Console.WriteLine(">New friend {0}【{1}】 online", msg.UserName, msg.Ip); } }
public void Process(Socket workerSock) { LoginMsg login = new LoginMsg(); login.ReceiveFrom(workerSock); string userName = login.UserName; string userPwd = login.UserPwd; var userService = new UserService(userName, userPwd); bool loginResult = userService.CheckLogin(); if (loginResult) { OnlineUserInfo user = new OnlineUserInfo { UserName = userName, IPEnd = workerSock.RemoteEndPoint as IPEndPoint }; foreach (var s in Server.TheTcpHelper.AcceptedSockets) { NewUserOnlineMsg newUserOnlineMsg = new NewUserOnlineMsg(user.UserName, user.IPEnd.Address.ToString()); newUserOnlineMsg.Send(s); } UserService.LoginUsers.Add(user); if (!UserService.DicUserSockets.ContainsKey(user.UserName)) { UserService.DicUserSockets.Add(user.UserName, workerSock); } } var r = loginResult ? LOGIN_RESULT.OK : LOGIN_RESULT.PWD_ERROR; Console.WriteLine("{0} login {1}", userName, r); LoginResultMsg loginResultMsg = new LoginResultMsg(r); loginResultMsg.Send(workerSock); }