コード例 #1
0
ファイル: Nexus.cs プロジェクト: szopenfx/code
 /// <summary>
 /// Send chat message to everybody
 /// </summary>
 /// <param name="message">The message to send</param>
 public void SendChatMessage(string message)
 {
     _Interface.ChatMessage(
         Configuration.Username() + ": (public) " + message
     );
     foreach (Peer p in _Peers.Peers)
     {
         try
         {
             ProtocolWriter pw = new ProtocolWriter(p.IPAddr, Configuration.ProtocolPort());
             pw.Chat("public", Configuration.Username(), message);
         }
         catch (Exception e)
         {
             throw new BullshitException
                 ("NO WAI!! Teh " + p.UserName + " iz not resp0ndz00ring (" + e.Message + ")");
         }
     }
 }
コード例 #2
0
ファイル: Nexus.cs プロジェクト: szopenfx/code
        /// <summary>
        /// Reject the chess invitation
        /// </summary>
        /// <param name="UserName">Username</param>
        /// <param name="Port">Port</param>
        public void RejectChessGame(string UserName, int Port)
        {
            Console.WriteLine("Nexus.RejectChessGame(" + UserName + "," + Port.ToString() + ")");

            // get peer's IP + protocol port
            IPAddress IPAddr = _Peers.GetPeer(UserName).IPAddr;
            int RemotePort = Configuration.ProtocolPort();

            // send rejection message
            ProtocolWriter pw = new ProtocolWriter(IPAddr, RemotePort);
            pw.RejectGame(Configuration.Username(), Port);
        }
コード例 #3
0
ファイル: Nexus.cs プロジェクト: szopenfx/code
        /// <summary>
        /// Performs a search on peers, and displays the data
        /// </summary>
        /// <param name="SearchString">The string to be searched for</param>
        public void PerformSearchOnPeers(string SearchString)
        {
            foreach (Peer CurrentPeer in _Peers.Peers)
            {
                Console.WriteLine(CurrentPeer.UserName);
                XmlDocument PeerSearchResult = new ProtocolWriter(CurrentPeer.IPAddr, Configuration.ProtocolPort()).Search(SearchString);

                foreach (XmlNode SearchNode in PeerSearchResult.LastChild.ChildNodes)
                {
                    string Source = "(unknown)";
                    string Size = "(unknown)";
                    string Type = "(unknown)";
                    string Name = "(unknown)";

                    foreach (XmlNode ItemNode in SearchNode.ChildNodes)
                    {

                        switch (ItemNode.LocalName)
                        {
                            case "source":
                                {
                                    Source = ItemNode.InnerText;
                                    break;
                                }
                            case "filename":
                                {
                                    Name = ItemNode.InnerText;
                                    break;
                                }
                            case "size":
                                {
                                    Console.WriteLine(ItemNode.InnerText);
                                    Size = ItemNode.InnerText;
                                    break;
                                }
                            case "filetype":
                                {
                                    Type = ItemNode.InnerText;
                                    break;
                                }
                        }
                    }
                    _Interface.DisplaySearchResult(Name, Convert.ToInt64(Size), CurrentPeer.UserName, CurrentPeer.IPAddr.ToString(), Source, Type);
                }

            }
        }
コード例 #4
0
ファイル: Nexus.cs プロジェクト: szopenfx/code
        /// <summary>
        /// Send an invitation for a game of chess to a peer
        /// </summary>
        /// <param name="UserIndex">Index of the user to be invited</param>
        public void InviteForChess(int UserIndex)
        {
            Console.WriteLine("Nexus.InviteForChess(" + UserIndex.ToString() + ")");

            // get remote IP address and a local port
            IPAddress PeerIP = _Peers.GetPeer(UserIndex).IPAddr;
            int LocalPort = GetLowestChessListenPort();

            // start chess server
            ChessProtocol cp = new ChessProtocol(LocalPort, this);

            // send invitation
            ProtocolWriter pw = new ProtocolWriter(PeerIP, Configuration.ProtocolPort());
            pw.InitGame(Configuration.Username(), LocalPort);
        }
コード例 #5
0
ファイル: Nexus.cs プロジェクト: szopenfx/code
 /// <summary>
 /// Add peer to Peer list and send "Identify yourself" command to peer
 /// </summary>
 /// <param name="IPAddr">IP address of peer as string</param>
 public void AddPeer(string IPAddr)
 {
     try
     {
         int port = Configuration.ProtocolPort();
         IPAddress ip = IPAddress.Parse(IPAddr);
         ProtocolWriter pw = new ProtocolWriter(ip, port);
         ProtocolWriter.IdentifyObject id = pw.Identify();
         _Peers.NewPeer(ip);
         _Peers.SetPeerName(IPAddr, id.Name);
         _Interface.AddUser(id.Name);
         Console.WriteLine(id.IP + " " + id.Name);
     }
     catch(Exception e)
     {
         throw new BullshitException("Yuor IP adrizzle iz teh bullshit (" + e.Message + ")");
     }
 }
コード例 #6
0
ファイル: Nexus.cs プロジェクト: szopenfx/code
        /// <summary>
        /// Accept the chess invitation
        /// </summary>
        /// <param name="UserName">Username</param>
        /// <param name="Port">Port</param>
        public void AcceptChessGame(string UserName, int Port)
        {
            Console.WriteLine("Nexus.AcceptChessGame(" + UserName + "," + Port.ToString() + ")");

            // get peer's IP + protocol port
            IPAddress IPAddr = _Peers.GetPeer(UserName).IPAddr;
            int RemotePort = Configuration.ProtocolPort();

            // send acceptance message
            ProtocolWriter pw = new ProtocolWriter(IPAddr, RemotePort);
            pw.AcceptGame(Configuration.Username(), Port);

            // connect to chess server
            ChessProtocol cp = new ChessProtocol(IPAddr, Port);
        }