コード例 #1
0
        public CommunicatorCore(IChatForm form)
        {
            if (form == null)
            {
                throw new ArgumentNullException("form");
            }

            fConnected = false;
            fForm      = form;
            fLogger    = LogManager.GetLogger(ProtocolHelper.LOG_FILE, ProtocolHelper.LOG_LEVEL, "ChatDHTCP");
            fPeers     = new List <Peer>();
            fSTUNInfo  = null;

            fProfile = new UserProfile();

            fDatabase = IDatabase.CreateDefault();
            fDatabase.Connect();
            fDatabase.LoadProfile(fProfile);

            fDHTClient                   = new DHTClient(DHTClient.IPAnyAddress, DHTClient.PublicDHTPort, this, ProtocolHelper.CLIENT_VER);
            fDHTClient.PeersFound       += OnPeersFound;
            fDHTClient.PeerPinged       += OnPeerPinged;
            fDHTClient.QueryReceived    += OnQueryReceive;
            fDHTClient.ResponseReceived += OnResponseReceive;

            NATHolePunching();

            fTCPClient              = new TCPDuplexClient();
            fTCPClient.DataReceive += OnDataReceive;

            fTCPListenerPort = ProtocolHelper.PublicTCPPort;
        }
コード例 #2
0
 public ChatService(IChatForm form)
 {
     this.form = form;
     Clients   = new BindingList <ClientModel>();
     form.ClientsListBox.DataSource    = Clients;
     form.ClientsListBox.DisplayMember = "Name";
     form.ClientsListBox.ValueMember   = "SessionId";
 }
コード例 #3
0
        void notifyIcon1_MouseClick(object sender, MouseEventArgs e)
        {
            try
            {
                if (e.Button != MouseButtons.Left)
                {
                    return;
                }

                lock (this.locker)
                {
                    if (this.friendQueue.Count > 0)
                    {
                        UnhandleFriendMessageBox cache = this.friendQueue[0];
                        this.friendQueue.RemoveAt(0);
                        IChatForm form = this.twinkleNotifySupporter.GetChatForm(cache.User);
                        if (form != null) //如果为null,表示刚删除好友
                        {
                            form.HandleReceivedMessage(cache.MessageList);
                        }

                        this.DetectUnhandleMessage();

                        if (this.UnhandleMessageGone != null)
                        {
                            this.UnhandleMessageGone(UnhandleMessageType.Friend, cache.User);
                        }
                        return;
                    }

                    if (this.groupQueue.Count > 0)
                    {
                        UnhandleGroupMessageBox cache = this.groupQueue[0];
                        this.groupQueue.RemoveAt(0);
                        IGroupChatForm form = this.twinkleNotifySupporter.GetGroupChatForm(cache.Group);
                        form.HandleReceivedMessage(cache.MessageList);

                        this.DetectUnhandleMessage();

                        if (this.UnhandleMessageGone != null)
                        {
                            this.UnhandleMessageGone(UnhandleMessageType.Group, cache.Group);
                        }
                        return;
                    }
                }

                if (this.MouseClick != null)
                {
                    this.MouseClick(sender, e);
                }
            }
            catch (Exception ee)
            {
                MessageBox.Show(ee.Message + " - " + ee.StackTrace);
            }
        }
コード例 #4
0
        public HostService(IChatForm form) : base(form)
        {
            serviceHost = new ServiceHost(this, new Uri("net.tcp://localhost:8080/SecuredChat/"));
            serviceHost.AddServiceEndpoint(typeof(IHostService), GetBinding(), "tcp");

            serviceHost.Opened  += ServiceHost_StateChanegd;
            serviceHost.Closed  += ServiceHost_StateChanegd;
            serviceHost.Faulted += ServiceHost_StateChanegd;
        }
コード例 #5
0
ファイル: Client.cs プロジェクト: Veyron154/academitCS
 public Client(string name, IChatForm form, int port, string host)
 {
     _name = name;
     _host = host;
     _port = port;
     _form = form;
     _formatter = new BinaryFormatter();
     _client = new TcpClient();
 }
コード例 #6
0
 public Client(string name, IChatForm form, int port, string host)
 {
     _name      = name;
     _host      = host;
     _port      = port;
     _form      = form;
     _formatter = new BinaryFormatter();
     _client    = new TcpClient();
 }
コード例 #7
0
        public void PushFriendMessage(string userID, int informationType, byte[] info, object tag)
        {
            lock (this.locker)
            {
                try
                {
                    this.twinkleNotifySupporter.PlayAudioAsyn(); //播放消息提示音
                    //首先查看是否已经存在对应的聊天窗口
                    IChatForm form = this.twinkleNotifySupporter.GetExistedChatForm(userID);
                    if (form != null)
                    {
                        form.HandleReceivedMessage(informationType, info, tag);
                        return;
                    }

                    //接下来准备将消息压入queue
                    UnhandleFriendMessageBox cache = null;
                    lock (this.locker)
                    {
                        //先查看queue中目标好友对应的Cache是否存在
                        for (int i = 0; i < this.friendQueue.Count; i++)
                        {
                            if (this.friendQueue[i].User == userID)
                            {
                                cache = this.friendQueue[i];
                                break;
                            }
                        }

                        if (cache == null) //如果不存在,则为好友新建一个Cache
                        {
                            cache = new UnhandleFriendMessageBox(userID);
                            this.friendQueue.Add(cache);
                            //触发UnhandleMessageOccured事件
                            if (this.UnhandleMessageOccured != null)
                            {
                                this.UnhandleMessageOccured(UnhandleMessageType.Friend, userID);
                            }
                        }

                        cache.MessageList.Add(new Parameter <int, byte[], object>(informationType, info, tag));
                    }

                    string userName = this.twinkleNotifySupporter.GetFriendName(userID);
                    this.notifyIcon1.Text = string.Format("{0}({1})  {2}条消息", userName, userID, cache.MessageList.Count);
                    //获取好友的头像,将其作为托盘图标
                    this.twinkleIcon = this.twinkleNotifySupporter.GetHeadIcon(userID);
                    this.ControlTimer(true); //启动闪烁
                }
                catch (Exception ee)
                {
                    MessageBox.Show(ee.Message);
                }
            }
        }
コード例 #8
0
        public CommunicatorCore(IChatForm form)
        {
            if (form == null)
            {
                throw new ArgumentNullException("form");
            }

            fConnectionState = ConnectionState.Disconnected;
            fForm            = form;
            fLogger          = LogManager.GetLogger(ProtocolHelper.LOG_FILE, ProtocolHelper.LOG_LEVEL, "CommCore");
            fPeers           = new List <Peer>();

            fProfile = new UserProfile();

            fDatabase = new GKNetDatabase();
            fDatabase.Connect();
            fDatabase.LoadProfile(fProfile);

            fBlockchainNode = new BlockchainNode(this, fDatabase);

            fDataPlugins = new List <IDataPlugin>();
            LoadPlugins(Utilities.GetAppPath());

            Port = DHTClient.PublicDHTPort;
            fLogger.WriteInfo("Port: {0}", Port);

            try {
                fSTUNInfo       = STUNUtility.Detect(Port);
                fPublicEndPoint = (fSTUNInfo.NetType != STUN_NetType.UdpBlocked) ? fSTUNInfo.PublicEndPoint : null;
            } catch (Exception ex) {
                fLogger.WriteError("DetectSTUN() error", ex);
                fPublicEndPoint = null;
            }

            if (UPnPEnabled)
            {
                CreatePortMapping();
            }

            fDHTClient = new DHTClient(new IPEndPoint(DHTClient.IPAnyAddress, Port), this, ProtocolHelper.CLIENT_VER);
            fDHTClient.PublicEndPoint    = fPublicEndPoint;
            fDHTClient.PeersFound       += OnPeersFound;
            fDHTClient.PeerPinged       += OnPeerPinged;
            fDHTClient.QueryReceived    += OnQueryReceive;
            fDHTClient.ResponseReceived += OnResponseReceive;

            InitializePeers();

            fTCPClient              = new TCPDuplexClient();
            fTCPClient.DataReceive += OnDataReceive;

            fTCPListenerPort = ProtocolHelper.PublicTCPPort;
        }
コード例 #9
0
        public void messageHandle(String channel, String message)
        {
            IChatForm inControl = getBroker(channel);

            if (inControl != null)
            {
                inControl.Receive(JSON.Deserialize <Json.Message>(message));
            }
            else
            {
                throw new Exception("Incoming message from known channel wasn't proceeded.");
            }
        }
コード例 #10
0
        public CommunicatorCore(IChatForm form)
        {
            if (form == null)
            {
                throw new ArgumentNullException("form");
            }

            fConnected = false;
            fForm      = form;
            fLogger    = LogManager.GetLogger(ProtocolHelper.LOG_FILE, ProtocolHelper.LOG_LEVEL, "ChatDHTCP");
            fProfile   = new UserProfile();
            fParser    = new BencodeParser();
            fPeers     = new List <Peer>();
            fSTUNInfo  = null;

            int dhtPort = DHTClient.PublicDHTPort;

            fDHTClient             = new DHTClient(DHTClient.IPAnyAddress, dhtPort, this, CLIENT_VER);
            fDHTClient.PeersFound += delegate(object sender, PeersFoundEventArgs e) {
                fLogger.WriteInfo(string.Format("Found DHT peers: {0}", e.Peers.Count));

                bool changed = false;
                foreach (var p in e.Peers)
                {
                    changed = UpdatePeer(p);
                }

                if (changed)
                {
                    fForm.OnPeersListChanged();
                }
            };
            fDHTClient.PeerPinged += delegate(object sender, PeerPingedEventArgs e) {
                fLogger.WriteInfo(string.Format("Peer pinged: {0}", e.EndPoint));

                bool changed = CheckPeer(e.EndPoint);

                if (changed)
                {
                    fForm.OnPeersListChanged();
                    SendData(e.EndPoint, ProtocolHelper.CreateGetPeerInfoQuery());
                }
            };
            fDHTClient.QueryReceived    += OnQueryReceive;
            fDHTClient.ResponseReceived += OnResponseReceive;

            NATHolePunching();

            fTCPClient              = new TCPDuplexClient();
            fTCPClient.DataReceive += OnDataReceive;
        }
コード例 #11
0
        public ClientService(IChatForm form) : base(form)
        {
            string username = Form.ClientName;

            if (string.IsNullOrWhiteSpace(username))
            {
                if (System.DirectoryServices.AccountManagement.UserPrincipal.Current != null)
                {
                    username = System.DirectoryServices.AccountManagement.UserPrincipal.Current.DisplayName;
                }
                else
                {
                    username = Environment.UserName;
                }
            }

            clientModel = new ClientModel {
                Name = username
            };
        }
コード例 #12
0
 public chatPresenter(ChatForm v, chatRepo r)
 {
     _v = v;
     _r = r;
 }
コード例 #13
0
 public void addBroker(String identifier, IChatForm broker)
 {
     messageBrokers.Add(identifier, broker);
 }