Example #1
0
        protected override void ExecuteImpl()
        {
            GroupInfo gi   = GroupInfoManager.FindGroup(m_groupKey);
            UserInfo  user = UserInfoManager.FindUser(m_remoteIP);

            Workbench.GroupAddUser(gi, user);
        }
Example #2
0
        protected override void ExecuteImpl()
        {
            GroupInfo gi = GroupInfoManager.FindGroup(m_groupKey);

            if (gi != null)
            {
                if (m_text.Contains(TextCommand_IsAlive))
                {
                    OutgoingPackagePool.AddFirst(NetPackageGenerater.AppendGroupTextMessage(gi.Key, MsgInputConfig.FormatMessage("I'm alive."), m_remoteIP));
                    return;
                }
                else if (m_text.Contains(TextCommand_Version))
                {
                    OutgoingPackagePool.AddFirst(NetPackageGenerater.AppendGroupTextMessage(gi.Key, MsgInputConfig.FormatMessage(DataManager.Version), m_remoteIP));
                    return;
                }
                else if (m_text.Contains(TextCommand_Dead_Pkg_Count))
                {
                    OutgoingPackagePool.AddFirst(NetPackageGenerater.AppendTextMessage(MsgInputConfig.FormatMessage(Logger.Get_Dead_Pkg_Counter()), m_remoteIP));
                    return;
                }
            }

            UserInfo usr = UserInfoManager.FindUser(m_remoteIP);

            if (gi != null && usr != null)
            {
                gi.AppendMessage(m_text, usr.Username);
            }
        }
Example #3
0
        public static void ClientLeave(IPEndPoint remoteIP)
        {
            UserInfo user = UserInfoManager.FindUser(remoteIP);

            if (user == null)
            {
                return;
            }

            s_singleton.Invoke(new DoAction(delegate
            {
                IPAddress addr = remoteIP.Address;
                int port       = remoteIP.Port;

                Logger.WriteLine(string.Format("User Leave: {0}, IP: {1}", user.Username, user.RemoteIP));

                user.IsAlive = false;
                s_singleton.m_users.DeleteUser(user);

                GroupInfo[] groups = GroupInfoManager.GetGroupArray();
                foreach (GroupInfo group in groups)
                {
                    group.DeleteUser(user);
                }
            }));
        }
Example #4
0
        public static void AddClient(string name, IPEndPoint remoteIP)
        {
            s_singleton.Invoke(new DoAction(delegate
            {
                IPAddress addr = remoteIP.Address;
                int port       = remoteIP.Port;

                UserInfo user = UserInfoManager.FindUser(remoteIP);
                if (user == null)
                {
                    user = new UserInfo(new IPEndPoint(addr, port), name);
                    UserInfoManager.AddUser(user);

                    GroupInfo[] groups = GroupInfoManager.GetGroupArray();
                    foreach (GroupInfo grp in groups)
                    {
                        OutgoingPackagePool.AddFirst(NetPackageGenerater.FindGroupUser(grp.Key, remoteIP));
                    }
                }
                else if (user.Username != name)
                {
                    user.Username = name;
                    s_singleton.m_users.UpdateUserName(user);
                }

                user.IsAlive = true;
                s_singleton.m_users.AddUser(user);
            }));
        }
Example #5
0
        private bool thread_outgoing(int ellapse)
        {
            s_tempPackages.Clear();

            OutgoingPackagePool.GrabProcessPackages(ellapse, s_tempPackages, 5);
            OutgoingPackagePool.DequeueUnprocess(s_tempPackages);

            foreach (NetPackage p in s_tempPackages)
            {
                if (p.OrderID == 1)
                {
                    Logger.CounterCommand_Send((NetCommandType)p.CommandID);

                    if (p.CommandID != NetCommandType.RemoveProcessedPackage &&
                        p.CommandID != NetCommandType.AddUser)
                    {
                        UserInfo userinfo = UserInfoManager.FindUser(p.RemoteEP);
                        string   user     = (userinfo == null) ? "no user" : userinfo.Username;

                        Logger.WriteLine(string.Format("--->> Command: {0}. Package ID: {1}. Target User: {2}", p.CommandID, p.ID, user));
                    }
                }

                int length = m_send_socket.SendTo(p.Buffer, p.Buffer.Length, SocketFlags.None, p.RemoteEP);
            }

            OutgoingPackagePool.RemoveDeadProcessed();

            return(s_tempPackages.Count != 0);
        }
Example #6
0
            public void AddPackage(NetPackage package)
            {
                if (package == null)
                {
                    return;
                }

                if (m_finishedContents.ContainsKey(package.ContentID))
                {
                    return;
                }

                Content content = null;

                if (m_contents.ContainsKey(package.ContentID))
                {
                    content = m_contents[package.ContentID];
                }
                else
                {
                    content = new Content(package.ContentID);
                    m_contents.Add(package.ContentID, content);
                }

                content.Add(package);

                if (content.IsFull())
                {
                    Cmd    cmd  = null;
                    byte[] data = content.CombineData();

                    UserInfo usr     = UserInfoManager.FindUser(RemoteEP);
                    string   usrname = (usr == null) ? "no user" : usr.Username;

                    Logger.CounterCommand_Recv(content.CommandType);
                    if (content.CommandType != NetCommandType.RemoveProcessedPackage)
                    {
                        Logger.WriteLine("<<--- command: " + content.CommandType.ToString() + " from :" + usrname);
                    }

                    cmd = GenerateCommand(content, cmd, data);

                    CommandPool.AddCommand(cmd);

                    m_contents.Remove(content.ID);
                    m_finishedContents.Add(content.ID, content.ID);
                }
            }
Example #7
0
        public NP_AppendImageMessageCmd(byte[] data, IPEndPoint remoteIP)
        {
            m_user = UserInfoManager.FindUser(remoteIP);
            int length = Helper.GetInt(data);

            m_filename = Helper.GetString(data, 4, length);
            m_filename = Path.Combine(DataManager.GetCustomFaceFolderPath(), m_filename);

            int fileDataOffset = length + 4;
            int fileDataLength = data.Length - fileDataOffset;

            MemoryStream ms = new MemoryStream(data, fileDataOffset, fileDataLength);

            byte[] imgData = ms.ToArray();
            ms.Dispose();

            GenerateImageFile(imgData, ref m_filename);
        }
Example #8
0
        protected override void ExecuteImpl()
        {
            if (string.IsNullOrEmpty(m_groupKey))
            {
                return;
            }

            UserInfo usr = UserInfoManager.FindUser(m_remoteIP);

            if (usr == null)
            {
                Workbench.AddClient(m_username, m_remoteIP);
            }

            GroupInfo grp = GroupInfoManager.FindGroup(m_groupKey);

            if (grp != null)
            {
                Workbench.GroupAddUser(grp, usr);
                OutgoingPackagePool.AddFirst(NetPackageGenerater.AddGroupUser(m_groupKey, m_remoteIP));
            }
        }
Example #9
0
        protected override void ExecuteImpl()
        {
            if (m_text.Contains(TextCommand_IsAlive))
            {
                OutgoingPackagePool.AddFirst(NetPackageGenerater.AppendTextMessage(MsgInputConfig.FormatMessage("I'm alive."), m_remoteIP));
                return;
            }
            else if (m_text.Contains(TextCommand_Version))
            {
                OutgoingPackagePool.AddFirst(NetPackageGenerater.AppendTextMessage(MsgInputConfig.FormatMessage(DataManager.Version), m_remoteIP));
                return;
            }
            else if (m_text.Contains(TextCommand_Dead_Pkg_Count))
            {
                OutgoingPackagePool.AddFirst(NetPackageGenerater.AppendTextMessage(MsgInputConfig.FormatMessage(Logger.Get_Dead_Pkg_Counter()), m_remoteIP));
                return;
            }

            UserInfo usr = UserInfoManager.FindUser(m_remoteIP);;

            usr.AppendMessage(m_text, usr.Username);
            Logger.WriteLine("Add message:" + m_text);
        }
Example #10
0
        public static void RemoveDeadProcessed()
        {
            lock (m_lockobject)
            {
                if (s_singleton.m_processed.Count != 0)
                {
                    m_removedIDs.Clear();

                    foreach (PackageLife pkg in s_singleton.m_processed.Values)
                    {
                        if (pkg.IsDead)
                        {
                            Logger.Counter_Dead_Pkg();

                            UserInfo info = UserInfoManager.FindUser(pkg.NetPackage.RemoteEP);
                            string   user = (info == null) ? "no user" : info.Username;

                            if (pkg.NetPackage.OrderID == 1)
                            {
                                Logger.WriteLine(string.Format("Package with command '{0}' is dead. To user: {1}", (NetCommandType)pkg.NetPackage.CommandID, user));
                            }
                            else
                            {
                                Logger.WriteLine(string.Format("Part package with command '{0}' is dead. To user: {1}", (NetCommandType)pkg.NetPackage.CommandID, user));
                            }

                            m_removedIDs.Add(pkg.NetPackage.ID);
                        }
                    }

                    foreach (int id in m_removedIDs)
                    {
                        s_singleton.m_processed.Remove(id);
                    }
                }
            }
        }