예제 #1
0
 public Command(string command, string commandArgs, string descSmall, string descLarge, User.PermissionLevel permission)
 {
     this.command           = command;
     this.command_args      = commandArgs;
     this.description_small = descSmall;
     this.description_Long  = descLarge;
     this.permission        = permission;
 }
예제 #2
0
 public CommandDescription(string _command, string _command_args, string _description_small, User.PermissionLevel permission, CommandExecuter.CommandFunction _callback)
 {
     command           = _command.ToLower();
     command_args      = _command_args;
     description_small = _description_small;
     description_Long  = string.Empty;
     this.permission   = permission;
     callback          = _callback;
 }
예제 #3
0
 public CommandDescription(string _command, string _command_args, string _description_small, User.PermissionLevel permission, string _callback)
 {
     command           = _command.ToLower();
     command_args      = _command_args;
     description_small = _description_small;
     description_Long  = string.Empty;
     this.permission   = permission;
     callback          = GetCallbackFromString(_command, _callback);
 }
 public CommandDescription(string _command, string _command_args, string _description_small, User.PermissionLevel permission, CommandExecuter.CommandFunction _callback)
 {
     command = _command.ToLower();
     command_args = _command_args;
     description_small = _description_small;
     description_Long = string.Empty;
     this.permission = permission;
     callback = _callback;
 }
 public CommandDescription(string _command, string _command_args, string _description_small, User.PermissionLevel permission, string _callback)
 {
     command = _command.ToLower();
     command_args = _command_args;
     description_small = _description_small;
     description_Long = string.Empty;
     this.permission = permission;
     callback = GetCallbackFromString(_command, _callback);
 }
예제 #6
0
        private Traffic Login_CMD(string args)
        {
            MessageTypes type    = MessageTypes.None;
            string       message = string.Empty;

            try {
                Login                loginData    = JsonConvert.DeserializeObject <Login>(args);
                ResponseType         responseType = ResponseType.Failed;
                User.PermissionLevel permission   = User.PermissionLevel.None;
                string               sessionKey   = string.Empty;
                if (_server.WorldLoaded)
                {
                    if (_server.DB.UserExists(loginData.name))
                    {
                        User user;
                        if (_server.Users.UserExists(loginData.name))
                        {
                            user = _server.Users.GetUser(loginData.name);
                        }
                        else
                        {
                            user = _server.Users.CreateUser(loginData.name);
                        }
                        bool loggedIn = user.Login(HashHelper.HashPasswordServer(loginData.password, loginData.salt));
                        responseType = loggedIn ? ResponseType.Successfull : ResponseType.Failed;
                        permission   = loggedIn ? user.Permission : User.PermissionLevel.None;
                        sessionKey   = user.SessionKey;
                        message      = user.LoginMessage;
                        Logger.Log("User {0} logged in.", loginData.name);
                        LoginResponse response = new LoginResponse(responseType, permission.ToString(), sessionKey, GameServer.Instance.GameTime.Tick, message);
                        return(new Traffic("loginresponse", JsonConvert.SerializeObject(response)));
                    }
                    else
                    {
                        message = "User not found!";
                        type    = MessageTypes.User_Not_Found;
                    }
                }
                else
                {
                    message = "No world instance loaded!";
                    type    = MessageTypes.World_Not_Loaded;
                    //Logger.LogWarning("User {0} tried to log in with no world loaded!", loginData.name);
                }
            }
            catch (Exception e) {
                Logger.LogError(e.StackTrace);
            }
            return(new Traffic("message", JsonConvert.SerializeObject(new Message("_server_", type, message))));
        }
예제 #7
0
        public static CommandDescription[] GetCommands(string file)
        {
            List <CommandDescription> commands = new List <CommandDescription>();
            FileIniDataParser         parser   = new FileIniDataParser();

            parser.Parser.Configuration.CommentString = "#";
            if (File.Exists(file))
            {
                IniData config = parser.ReadFile(file);
                foreach (SectionData section in config.Sections)
                {
                    string command                  = section.SectionName;
                    string command_args             = string.Empty;
                    string description_small        = string.Empty;
                    string description_Long         = string.Empty;
                    User.PermissionLevel permission = User.PermissionLevel.Server;
                    string callback                 = string.Empty;

                    if (config [command].ContainsKey("command_args"))
                    {
                        command_args = config [command] ["command_args"];
                    }

                    if (config [command].ContainsKey("description_small"))
                    {
                        description_small = config [command] ["description_small"];
                    }
                    else
                    {
                        Logger.LogError("Failed to parse Command \"" + command + "\": Short description not specified.");
                    }

                    if (config [command].ContainsKey("description_Long"))
                    {
                        description_Long = config [command] ["description_Long"];
                    }

                    if (config[command].ContainsKey("permission"))
                    {
                        string permissionStr = config[command]["permission"];
                        User.PermissionLevel tmpPerm;
                        if (Enum.TryParse(permissionStr, true, out tmpPerm))
                        {
                            permission = tmpPerm;
                        }
                    }

                    if (config [command].ContainsKey("function"))
                    {
                        callback = config [command] ["function"];
                    }
                    else
                    {
                        Logger.LogError("Failed to parse Command \"" + command + "\": Function not specified.");
                    }

                    commands.Add(new CommandDescription(command, command_args, description_small, description_Long, permission, callback));
                }
            }
            else
            {
                Logger.LogError("Command file not found.");
            }
            return(commands.ToArray());
        }