/// <summary> /// 监听 /// </summary> public void begin() { while (true) { if (!ConsolePlusLib.Core.Server.UserQuitFlag) { return; } try { for (int i = 0; i < ConsolePlusLib.Console.Server.getOnlineUsers().Count; i++) { ConsolePlusLib.Senders.User user = ConsolePlusLib.Console.Server.getOnlineUsers()[i]; if (!this.isConnecting(user.getClient())) { UserQuitArg arguments = new UserQuitArg(user); if (UserQuitEvent != null) { UserQuitEvent(this, arguments); } ConsolePlusLib.Console.Server.getHandler().reciveMessageEnd(user); ConsolePlusLib.Console.Out.println((user.getPrefix() == null ? "" : user.getPrefix()) + "<" + (user.getName() == null ? user.getIP() + ":" + user.getPort() : user.getName()) + ">" + "下线了!"); ConsolePlusLib.Console.Server.getOnlineUsers().Remove(user); } } } catch (Exception) { } } }
/// <summary> /// 发送信息到用户 /// </summary> /// <param name="user"></param> /// <param name="message"></param> public void sendMessage(User user, String message) { MessageSender sender = new MessageSender(user); sender.send(message); }
/// <summary> /// 停止监听指定用户的信息 /// </summary> /// <param name="user"></param> public void reciveMessageEnd(User user) { user.Thread.Abort(); }
/// <summary> /// 开始监听指定用户的信息 /// </summary> public void reciveMessageBegin(User user) { MessageReciver reciver = new MessageReciver(user); user.Thread = new Thread(reciver.begin); user.Thread.Start(); }
public UserQuitArg(ConsolePlusLib.Senders.User user) { this.User = user; }