示例#1
0
        /// <summary>
        /// Begin listening for incoming TCP connections on the specified port number
        /// </summary>
        public void StartListening()
        {
            int port = SiusConf.GetSetting.Integer("port");

            // TCP port numbers are 16 bits in length, so they can only be within the range of 0 - 65535
            if (port <= 0 || port >= 65535)
            {
                SiusLog.Log(SiusLog.ERROR, "server", "An error occured when trying to define a port number. Please make sure the port is within the range of 1 - 65534");
                Sius.Connected = false;
                return;
            }

            string    address = SiusConf.GetSetting.String("ip");
            IPAddress localAddr;

            // check if the IP Address is valid
            if (SiusUtil.IsValidIP(address) == false)
            {
                SiusLog.Log(SiusLog.ERROR, "server", "Unable to retrieve IP Address. Please make sure that you are using a valid IP Address such as 127.0.0.1");
                Sius.Connected = false;
                return;
            }
            else
            {
                localAddr = IPAddress.Parse(address);
            }

            // Log our port and ip address
            SiusLog.Log(SiusLog.INFORMATION, "server", "Server port: " + port + ", Server IP: " + address);

            // Create TCP Listener and start checking for incoming connections
            try
            {
                Listening = new TcpListener(localAddr, port);
                Listening.Start();
            }
            catch (SocketException e)
            {
                SiusLog.Log(SiusLog.ERROR, "connect", e.Message);
                Sius.Connected = false;
                return;
            }

            // Server is connected!
            Sius.Connected = true;

            // Start a new thread
            thrListener = new Thread(KeepListening);
            thrListener.Start();
        }
示例#2
0
        public static string GetChannelList(string channel)
        {
            string users = "";

            for (int i = 0; i < PlayerList.Count; i++)
            {
                PlayerStruct p = (PlayerStruct)PlayerList[i];

                if (SiusUtil.StringInArray(channel, p.Chat))
                {
                    if (string.IsNullOrEmpty(users))
                    {
                        users = p.name;
                    }
                    else
                    {
                        users = users + "," + p.name;
                    }
                }
            }
            return(users);
        }