Example #1
0
        private static void ProcessMessage(object rawMessage, object tag)
        {
            if (rawMessage is FunctionRequestMessage)
            {
                FunctionRequestMessage functionRequestMessage = rawMessage as FunctionRequestMessage;
                Base.ClientControlManager.MF.Handle(new Packet(functionRequestMessage.Packet), functionRequestMessage.ClientID);
                return;
            }
            int    id     = (int)tag;
            Packet packet = default(Packet);

            if (rawMessage is ChildProcessLogListRequestMessage)
            {
                ChildProcessLogListRequestMessage childProcessLogListRequestMessage = rawMessage as ChildProcessLogListRequestMessage;
                RCProcess rcprocess = Base.Client[childProcessLogListRequestMessage.ProcessName];
                ChildProcessLogListReplyMessage value = new ChildProcessLogListReplyMessage(childProcessLogListRequestMessage.ClientID, rcprocess.Name, rcprocess.ChildProcesses);
                packet = SerializeWriter.ToBinary <ChildProcessLogListReplyMessage>(value);
            }
            else if (rawMessage is ChildProcessLogRequestMessage)
            {
                ChildProcessLogRequestMessage childProcessLogRequestMessage = rawMessage as ChildProcessLogRequestMessage;
                RCProcess rcprocess2 = Base.Client[childProcessLogRequestMessage.ProcessName];
                List <RCProcess.ChildProcessLog> log      = null;
                RCProcess.ChildProcessLogs       childLog = rcprocess2.GetChildLog(childProcessLogRequestMessage.ProcessID);
                if (childLog != null)
                {
                    log = childLog.LogLiness;
                }
                ChildProcessLogReplyMessage value2 = new ChildProcessLogReplyMessage(childProcessLogRequestMessage.ClientID, childProcessLogRequestMessage.ProcessName, childProcessLogRequestMessage.ProcessID, log);
                packet = SerializeWriter.ToBinary <ChildProcessLogReplyMessage>(value2);
            }
            else if (rawMessage is ChildProcessLogConnectMessage)
            {
                ChildProcessLogConnectMessage childProcessLogConnectMessage = rawMessage as ChildProcessLogConnectMessage;
                RCProcess rcprocess3 = Base.Client[childProcessLogConnectMessage.ProcessName];
                RCProcess.ChildProcessLogs childLog2 = rcprocess3.GetChildLog(childProcessLogConnectMessage.ProcessID);
                if (childLog2 != null && childLog2.CanConnect)
                {
                    childLog2.OnLog += Base.ClientControlManager.ClientProcessChildProcessLog;
                }
            }
            else if (rawMessage is ChildProcessLogDisconnectMessage)
            {
                ChildProcessLogDisconnectMessage childProcessLogDisconnectMessage = rawMessage as ChildProcessLogDisconnectMessage;
                RCProcess rcprocess4 = Base.Client[childProcessLogDisconnectMessage.ProcessName];
                RCProcess.ChildProcessLogs childLog3 = rcprocess4.GetChildLog(childProcessLogDisconnectMessage.ProcessID);
                if (childLog3 != null)
                {
                    childLog3.OnLog -= Base.ClientControlManager.ClientProcessChildProcessLog;
                }
            }
            else if (rawMessage is ExeInfoRequestMessage)
            {
                ExeInfoRequestMessage exeInfoRequestMessage = rawMessage as ExeInfoRequestMessage;
                RCProcess             rcprocess5            = Base.Client[exeInfoRequestMessage.ProcessName];
                ExeInfoReplyMessage   exeInfoReplyMessage   = new ExeInfoReplyMessage(exeInfoRequestMessage.ClientID, rcprocess5.Name);
                try
                {
                    DirectoryInfo   directoryInfo = new DirectoryInfo(Path.Combine(BaseConfiguration.WorkingDirectory, rcprocess5.WorkingDirectory));
                    List <FileInfo> list          = new List <FileInfo>();
                    list.AddRange(directoryInfo.GetFiles("*.dll", SearchOption.AllDirectories));
                    list.AddRange(directoryInfo.GetFiles("*.exe", SearchOption.AllDirectories));
                    foreach (FileInfo fileInfo in list)
                    {
                        exeInfoReplyMessage.AddFile(fileInfo.FullName.Substring(directoryInfo.FullName.Length + 1), fileInfo.LastWriteTime);
                    }
                }
                finally
                {
                    packet = SerializeWriter.ToBinary <ExeInfoReplyMessage>(exeInfoReplyMessage);
                }
            }
            if (packet.Bytes.Array != null)
            {
                FunctionReplyMessage message = new FunctionReplyMessage(packet.Bytes, id);
                Base.ClientControlManager.Send <FunctionReplyMessage>(message);
            }
        }
Example #2
0
        private void _ProcessMessage(object rawMessage, object tag)
        {
            User user = tag as User;

            if (user == null)
            {
                return;
            }
            try
            {
                if (!(rawMessage is RemoteControlSystem.ClientMessage.PingMessage))
                {
                    if (rawMessage is LoginMessage)
                    {
                        LoginMessage loginMessage = rawMessage as LoginMessage;
                        if (user.IsValid)
                        {
                            throw new ArgumentException("Cannot login twice - " + loginMessage.Account);
                        }
                        this.Login(user, loginMessage.Account, loginMessage.Password);
                    }
                    else if (rawMessage is NotifyMessage)
                    {
                        this.CheckAuthority(user, Authority.Supervisor);
                        this.NotifyMessage(user, rawMessage as NotifyMessage);
                    }
                    else if (rawMessage is ChangeMyPasswordMessage)
                    {
                        this.CheckAuthority(user, Authority.UserMonitor);
                        ChangeMyPasswordMessage changeMyPasswordMessage = rawMessage as ChangeMyPasswordMessage;
                        this.ChangeMyPassword(user, changeMyPasswordMessage.OldPassword, changeMyPasswordMessage.NewPassword);
                    }
                    else if (rawMessage is GetUserListMessage)
                    {
                        this.CheckAuthority(user, Authority.Supervisor);
                        this.GetUserList(user);
                    }
                    else if (rawMessage is AddUserMessage)
                    {
                        this.CheckAuthority(user, Authority.Supervisor);
                        AddUserMessage addUserMessage = rawMessage as AddUserMessage;
                        this.AddUser(user, addUserMessage.Account, addUserMessage.Password, addUserMessage.Authority);
                    }
                    else if (rawMessage is RemoveUserMessage)
                    {
                        this.CheckAuthority(user, Authority.Supervisor);
                        RemoveUserMessage removeUserMessage = rawMessage as RemoveUserMessage;
                        this.RemoveUser(user, removeUserMessage.Account);
                    }
                    else if (rawMessage is ChangePasswordMessage)
                    {
                        this.CheckAuthority(user, Authority.Supervisor);
                        ChangePasswordMessage changePasswordMessage = rawMessage as ChangePasswordMessage;
                        this.ChangePassword(user, changePasswordMessage.Account, changePasswordMessage.NewPassword);
                    }
                    else if (rawMessage is ChangeAuthorityMessage)
                    {
                        this.CheckAuthority(user, Authority.Supervisor);
                        ChangeAuthorityMessage changeAuthorityMessage = rawMessage as ChangeAuthorityMessage;
                        this.ChangeAuthority(user, changeAuthorityMessage.Account, changeAuthorityMessage.Authority);
                    }
                    else if (rawMessage is GetUserAuthMesssage)
                    {
                        this.CheckAuthority(user, Authority.UserWatcher);
                        this.GetUserAuthority(user, rawMessage as GetUserAuthMesssage);
                    }
                    else if (rawMessage is ControlEnterMessage)
                    {
                        this.CheckAuthority(user, Authority.ChiefGM);
                        this.ControlEnter(user);
                    }
                    else if (rawMessage is ControlFinishMessage)
                    {
                        this.CheckMutex(user);
                        this.ControlFinish(user);
                    }
                    else if (rawMessage is ControlRequestMessage)
                    {
                        this.CheckAuthority(user, Authority.UserKicker);
                        ControlRequestMessage controlRequestMessage = rawMessage as ControlRequestMessage;
                        this.SendControlProtocol(user, controlRequestMessage.Packet, controlRequestMessage.IDs);
                    }
                    else if (rawMessage is WorkGroupChangeMessage)
                    {
                        this.CheckMutex(user);
                        WorkGroupChangeMessage workGroupChangeMessage = rawMessage as WorkGroupChangeMessage;
                        this.WorkGroupChange(user, workGroupChangeMessage.WorkGroup);
                    }
                    else if (rawMessage is ServerGroupChangeMessage)
                    {
                        this.CheckMutex(user);
                        ServerGroupChangeMessage serverGroupChangeMessage = rawMessage as ServerGroupChangeMessage;
                        this.ServerGroupChange(user, serverGroupChangeMessage.ServerGroup);
                    }
                    else if (rawMessage is TemplateChangeMessage)
                    {
                        this.CheckMutex(user);
                        TemplateChangeMessage templateChangeMessage = rawMessage as TemplateChangeMessage;
                        this.TemplateChange(user, templateChangeMessage.Template);
                    }
                    else if (rawMessage is ChildProcessLogRequestMessage)
                    {
                        ChildProcessLogRequestMessage childProcessLogRequestMessage = rawMessage as ChildProcessLogRequestMessage;
                        this.SendFunctionProtocol(user, SerializeWriter.ToBinary <ChildProcessLogRequestMessage>(childProcessLogRequestMessage).Bytes, childProcessLogRequestMessage.ClientID);
                    }
                    else if (rawMessage is ChildProcessLogListRequestMessage)
                    {
                        ChildProcessLogListRequestMessage childProcessLogListRequestMessage = rawMessage as ChildProcessLogListRequestMessage;
                        this.SendFunctionProtocol(user, SerializeWriter.ToBinary <ChildProcessLogListRequestMessage>(childProcessLogListRequestMessage).Bytes, childProcessLogListRequestMessage.ClientID);
                    }
                    else if (rawMessage is ChildProcessLogConnectMessage)
                    {
                        ChildProcessLogConnectMessage childProcessLogConnectMessage = rawMessage as ChildProcessLogConnectMessage;
                        this.logManager.AddListener(user, childProcessLogConnectMessage.ClientID, childProcessLogConnectMessage.ProcessName, childProcessLogConnectMessage.ProcessID);
                    }
                    else if (rawMessage is ChildProcessLogDisconnectMessage)
                    {
                        ChildProcessLogDisconnectMessage childProcessLogDisconnectMessage = rawMessage as ChildProcessLogDisconnectMessage;
                        this.logManager.RemoveListener(user, childProcessLogDisconnectMessage.ClientID, childProcessLogDisconnectMessage.ProcessName, childProcessLogDisconnectMessage.ProcessID);
                    }
                    else
                    {
                        if (!(rawMessage is ExeInfoRequestMessage))
                        {
                            throw new RCServerException("Invalid packet! try to update latest version");
                        }
                        ExeInfoRequestMessage exeInfoRequestMessage = rawMessage as ExeInfoRequestMessage;
                        this.SendFunctionProtocol(user, SerializeWriter.ToBinary <ExeInfoRequestMessage>(exeInfoRequestMessage).Bytes, exeInfoRequestMessage.ClientID);
                    }
                }
            }
            catch (RCServerException ex)
            {
                this.NotifyMessage(user, MessageType.Error, ex.Message, new object[0]);
            }
            catch (Exception ex2)
            {
                if (rawMessage == null)
                {
                    this.NotifyMessage(MessageType.Message, ex2.ToString(), new object[0]);
                }
                else
                {
                    IPAddress address = user.Connection.RemoteEndPoint.Address;
                    this.NotifyMessage(MessageType.Message, "[{0}/{1}] - {2}", new object[]
                    {
                        user.ClientId,
                        address.ToString(),
                        ex2.ToString()
                    });
                    user.Connection.Disconnect();
                }
            }
        }