예제 #1
0
파일: UIData.cs 프로젝트: yonzkon/mnncs
        public void DelSockUnit(SockType type, IPEndPoint lep, IPEndPoint rep)
        {
            System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
            {
                SockUnit unit = FindSockUnit(type, lep, rep);
                if (unit == null)
                {
                    return;
                }

                switch (type)
                {
                case SockType.listen:
                case SockType.connect:
                    SockUnitGroup.Remove(unit);
                    break;

                case SockType.accept:
                    var subset = from s in SockUnitGroup
                                 where s.Type == SockType.listen && s.Lep.Port == unit.Lep.Port
                                 select s;
                    if (subset.Count() != 0)
                    {
                        subset.First().Childs.Remove(unit);
                        CurrentAcceptCount--;
                        HistoryAcceptCloseCount++;
                    }
                    break;
                }
            }));
        }
예제 #2
0
파일: UIData.cs 프로젝트: yonzkon/mnncs
 public void CloseSockUnit(SockType type, IPEndPoint lep, IPEndPoint rep)
 {
     System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() => {
         SockUnit unit = FindSockUnit(type, lep, rep);
         if (unit != null)
         {
             unit.State = SockState.Closed;
         }
     }));
 }
예제 #3
0
        internal static AwesomeSocket New(SockType sockType = SockType.Tcp)
        {
            switch (sockType)
            {
            case SockType.Udp:
                return(new AwesomeSocket(AddressFamily.InterNetwork, SocketType.Dgram));

            default:
                return(new AwesomeSocket());
            }
        }
예제 #4
0
파일: D2Socket.cs 프로젝트: inrg/BioBot
 public D2Socket(SockType Type)
 {
     base.Disconnection += new Sockets.DisconnectionEventHandler(this.D2Socket_Disconnection);
     base.Connection    += new Sockets.ConnectionEventHandler(this.D2Socket_Connection);
     this.Firstpacket    = true;
     this.PacketInWait   = new SortedList();
     this.SocketType     = Type;
     this.PacketWaiting  = new Thread(new ThreadStart(this.Waiting));
     this.PacketWaiting.IsBackground = true;
     this.PacketWaiting.Start();
 }
예제 #5
0
        // Methods ============================================================================

        public SockSess(SockType type, Socket sock)
        {
            this.type = type;
            this.sock = sock;
            eof       = false;
            tick      = DateTime.Now;
            conntime  = tick;
            id        = Guid.NewGuid().ToString();

            rdata      = new byte[rdata_max];
            wdata      = new byte[wdata_max];
            this.sdata = null;
        }
예제 #6
0
파일: UIData.cs 프로젝트: yonzkon/mnncs
 public void OpenSockUnit(SockType type, IPEndPoint lep, IPEndPoint rep, string sessid)
 {
     System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() => {
         SockUnit unit = FindSockUnit(type, lep, rep);
         if (unit == null)
         {
             return;
         }
         unit.Lep    = lep;
         unit.Rep    = rep;
         unit.SESSID = sessid;
         unit.State  = SockState.Opened;
     }));
 }
예제 #7
0
파일: CoreBaseNew.cs 프로젝트: yiend/mnncs
        protected SockSessNew FindSockSessFromSessGroup(SockType sockType, IPEndPoint ep)
        {
            IEnumerable<SockSessNew> subset = null;
            switch (sockType) {
                case SockType.listen:
                case SockType.connect:
                    subset = from s in sess_group where s.lep.Equals(ep) select s;
                    break;
                case SockType.accept:
                    subset = from s in sess_group where s.rep != null && s.rep.Equals(ep) select s;
                    break;
                default:
                    break;
            }

            if (subset != null && subset.Count() != 0)
                return subset.First();
            else
                return null;
        }
예제 #8
0
        public SockSess FindSession(SockType type, IPEndPoint lep, IPEndPoint rep)
        {
            ThreadCheck(false);

            SockSess retval = null;

            switch (type)
            {
            case SockType.listen:
            case SockType.connect:
                foreach (var item in sess_table)
                {
                    if (item.type == type && item.lep.Equals(lep))
                    {
                        retval = item;
                        break;
                    }
                }
                break;

            case SockType.accept:
                foreach (var item in sess_table)
                {
                    if (item.type == type && item.rep.Equals(rep))
                    {
                        retval = item;
                        break;
                    }
                }
                break;

            default:
                break;
            }

            return(retval);
        }
예제 #9
0
파일: UIData.cs 프로젝트: yonzkon/mnncs
        private SockUnit FindSockUnit(SockType type, IPEndPoint lep, IPEndPoint rep)
        {
            IEnumerable <SockUnit> subset = null;

            if (type == SockType.listen)
            {
                subset = from s in SockUnitGroup where s.Type == type && s.Lep.Equals(lep) select s;
            }
            else if (type == SockType.connect)
            {
                subset = from s in SockUnitGroup where s.Type == type && s.Rep.Equals(rep) select s;
            }
            else if (type == SockType.accept)
            {
                foreach (var item in SockUnitGroup)
                {
                    subset = from s in item.Childs where s.Rep.Equals(rep) select s;
                    if (subset.Count() != 0)
                    {
                        break;
                    }
                }
            }
            else
            {
                return(null);
            }

            if (subset != null && subset.Count() != 0)
            {
                return(subset.First());
            }
            else
            {
                return(null);
            }
        }
예제 #10
0
파일: SockSess.cs 프로젝트: yiend/mnncs
        public SockSess FindSession(SockType type, IPEndPoint lep, IPEndPoint rep)
        {
            ThreadCheck(false);

            SockSess retval = null;

            switch (type) {
                case SockType.listen:
                case SockType.connect:
                    foreach (var item in sess_table) {
                        if (item.type == type && item.lep.Equals(lep)) {
                            retval = item;
                            break;
                        }
                    }
                    break;
                case SockType.accept:
                    foreach (var item in sess_table) {
                        if (item.type == type && item.rep.Equals(rep)) {
                            retval = item;
                            break;
                        }
                    }
                    break;
                default:
                    break;
            }

            return retval;
        }
예제 #11
0
파일: DataUI.cs 프로젝트: yiend/mnncs
 public void CloseSockUnit(SockType type, IPEndPoint lep, IPEndPoint rep)
 {
     System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() => {
         SockUnit unit = FindSockUnit(type, lep, rep);
         if (unit != null)
             unit.State = SockState.Closed;
     }));
 }
예제 #12
0
 internal static AwesomeSocket New(SockType sockType = SockType.Tcp)
 {
     switch (sockType)
     {
         case SockType.Udp:
             return new AwesomeSocket(AddressFamily.InterNetwork, SocketType.Dgram);
         default:
             return new AwesomeSocket();
     }
 }
예제 #13
0
파일: DataUI.cs 프로젝트: yiend/mnncs
        private SockUnit FindSockUnit(SockType type, IPEndPoint lep, IPEndPoint rep)
        {
            IEnumerable<SockUnit> subset = null;
            if (type == SockType.listen)
                subset = from s in SockUnitGroup where s.Type == type && s.Lep.Equals(lep) select s;
            else if (type == SockType.connect)
                subset = from s in SockUnitGroup where s.Type == type && s.Lep != null && s.Lep.Equals(lep) select s;
            else if (type == SockType.accept) {
                foreach (var item in SockUnitGroup) {
                    subset = from s in item.Childs where s.Rep.Equals(rep) select s;
                    if (subset.Count() != 0)
                        break;
                }
            }
            else
                return null;

            if (subset != null && subset.Count() != 0)
                return subset.First();
            else
                return null;
        }
예제 #14
0
파일: DataUI.cs 프로젝트: yiend/mnncs
        public void DelSockUnit(SockType type, IPEndPoint lep, IPEndPoint rep)
        {
            System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
            {
                SockUnit unit = FindSockUnit(type, lep, rep);
                if (unit == null) return;

                switch (type) {
                    case SockType.listen:
                    case SockType.connect:
                        SockUnitGroup.Remove(unit);
                        break;

                    case SockType.accept:
                        var subset = from s in SockUnitGroup
                                     where s.Type == SockType.listen && s.Lep.Port == unit.Lep.Port
                                     select s;
                        if (subset.Count() != 0) {
                            subset.First().Childs.Remove(unit);
                            CurrentAcceptCount--;
                            HistoryAcceptCloseCount++;
                        }
                        break;
                }
            }));
        }
예제 #15
0
파일: SockSess.cs 프로젝트: yiend/mnncs
        // Methods ============================================================================
        public SockSess(SockType type, Socket sock)
        {
            this.type = type;
            this.sock = sock;
            lep = sock.LocalEndPoint as IPEndPoint;
            rep = type == SockType.listen ? null : sock.RemoteEndPoint as IPEndPoint;
            eof = false;
            tick = DateTime.Now;

            rdata = new byte[rdata_max];
            wdata = new byte[wdata_max];
            this.sdata = null;
        }
예제 #16
0
        public void Config()
        {
            if (File.Exists(BASE_DIR + CONF_NAME) == false)
            {
                System.Windows.MessageBox.Show(CONF_NAME + ": can't find it.");
                return;
            }

            try {
                XmlDocument doc = new XmlDocument();
                doc.Load(BASE_DIR + CONF_NAME);

                // cmdtable
                foreach (XmlNode item in doc.SelectNodes("/configuration/commands/cmditem"))
                {
                    CmdUnit cmd = new CmdUnit();
                    cmd.ID          = item.Attributes["id"].Value;
                    cmd.Name        = item.Attributes["name"].Value;
                    cmd.Cmd         = item.Attributes["content"].Value;
                    cmd.Encrypt     = bool.Parse(item.Attributes["encrypt"].Value);
                    cmd.ContentMode = (ServiceRequestContentMode)Enum.Parse(typeof(ServiceRequestContentMode), item.Attributes["content-mode"].Value);
                    uidata.CmdTable.Add(cmd);
                }

                /// sockunit
                foreach (XmlNode item in doc.SelectNodes("/configuration/sockets/sockitem"))
                {
                    string[]   str      = item.Attributes["ep"].Value.Split(':');
                    IPEndPoint ep       = new IPEndPoint(IPAddress.Parse(str[0]), int.Parse(str[1]));
                    SockType   sockType = (SockType)Enum.Parse(typeof(SockType), item.Attributes["type"].Value);
                    SockUnit   sockUnit = new SockUnit()
                    {
                        ID      = item.Attributes["id"].Value,
                        Name    = item.Attributes["name"].Value,
                        Type    = sockType,
                        Lep     = sockType == SockType.listen ? ep : null,
                        Rep     = sockType == SockType.connect ? ep : null,
                        State   = SockState.Closed,
                        Autorun = bool.Parse(item.Attributes["autorun"].Value),
                    };
                    uidata.AddSockUnit(sockUnit);

                    if (sockUnit.Autorun)
                    {
                        string id = "service.sesslisten";
                        if (sockType == SockType.connect)
                        {
                            id = "service.sessconnect";
                        }
                        object req = new {
                            id   = id,
                            ip   = ep.Address.ToString(),
                            port = ep.Port,
                        };
                        core.AddServiceRequest(ServiceRequest.Parse(JsonConvert.SerializeObject(req)));
                    }
                }
            } catch (Exception) {
                System.Windows.MessageBox.Show(CONF_NAME + ": syntax error.");
            }
        }
예제 #17
0
파일: Core.cs 프로젝트: yiend/mnncs
 private void SockOpen(string id, SockType sockType, IPEndPoint ep)
 {
     try {
         SockSessNew sess = null;
         if (sockType == SockType.listen)
             sess = MakeListen(ep);
         else
             sess = MakeConnect(ep);
         DataUI.OpenSockUnit(id, sess.lep, sess.rep);
     } catch (Exception) {
         DataUI.CloseSockUnit(id);
     }
 }