Exemple #1
0
        private void LoadEvents()
        {
            // TODO: Load these dynamically..
            Core.LogServer("Registering events..");
            Core.LogServer("Registering event: chatMessage");
            EventHandlers.Add("chatMessage", new Action <int, String, String>(ChatMessage));

            Core.LogServer("Registering event: playerDropped");
            EventHandlers.Add("playerDropped", new Action <Player, String>(PlayerDropped));
        }
Exemple #2
0
        private void LoadCommands()
        {
            Assembly      assembly           = Assembly.GetExecutingAssembly();
            List <String> commands           = new List <String>();
            int           registeredCommands = 0;

            foreach (TypeInfo typeInfo in assembly.DefinedTypes)
            {
                if (!typeInfo.FullName.Contains("Commands"))
                {
                    continue;
                }

                commands.Add(typeInfo.FullName);
            }

            foreach (String command in commands)
            {
                String commandName = command.ToLower().Replace("server.commands.", "");
                Type   commandType = assembly.GetType(command);

                if (commandType == null)
                {
                    Core.LogServer("Can't create command object for '" + commandName + "', class doesn't exist..");
                    continue;
                }

                CommandBase commandObject = (CommandBase)Activator.CreateInstance(commandType);
                if (commandObject == null)
                {
                    Core.LogServer("Command '" + commandName + "' not registered, couldn't create instance..");
                    continue;
                }

                Core.LogServer("Command registered: " + commandName);

                registeredCommands++;
                Core.GetInstance().RegisterCommand(commandName, commandObject);
            }

            if (registeredCommands == commands.Count)
            {
                Core.LogServer("All commands registered successfully!");
            }
            else
            {
                Core.LogServer("Registered " + registeredCommands + "/" + commands.Count + " successfully");
            }
        }