예제 #1
0
        public Server()
        {
            antiGCList  = new List <object>();
            IRCCommands = new IRCCommandList();

            BaseIRCLib.Database.SetDatabase(this);
            BaseIRCLib.Server.SetServer(this);

            Steamworks.Load();
            steamClient  = Steamworks.CreateInterface <ISteamClient009>("SteamClient009");
            clientEngine = Steamworks.CreateInterface <IClientEngine>("CLIENTENGINE_INTERFACE_VERSION001");

            pipe = steamClient.CreateSteamPipe();
            user = steamClient.ConnectToGlobalUser(pipe);

            clientFriends = Steamworks.CastInterface <IClientFriends>(clientEngine.GetIClientFriends(user, pipe, "CLIENTFRIENDS_INTERFACE_VERSION001"));
            clientUser    = Steamworks.CastInterface <ISteamUser014>(steamClient.GetISteamUser(user, pipe, "SteamUser014"));
            //clientUser = Steamworks.CastInterface<IClientUser>(clientEngine.GetIClientUser(user, pipe, "CLIENTUSER_INTERFACE_VERSION001"));

            Callback <PersonaStateChange_t>    stateChange   = new Callback <PersonaStateChange_t>(StateChange, PersonaStateChange_t.k_iCallback);
            Callback <FriendChatMsg_t>         friendMessage = new Callback <FriendChatMsg_t>(FriendMessage, FriendChatMsg_t.k_iCallback);
            Callback <ChatRoomMsg_t>           chatMessage   = new Callback <ChatRoomMsg_t>(ChatMessage, ChatRoomMsg_t.k_iCallback);
            Callback <ChatMemberStateChange_t> chatResult    = new Callback <ChatMemberStateChange_t>(ChatResult, ChatMemberStateChange_t.k_iCallback);
            Callback <ChatRoomInvite_t>        chatInvite    = new Callback <ChatRoomInvite_t>(ChatInvite, ChatRoomInvite_t.k_iCallback);

            if (File.Exists("clients.list"))
            {
                clientList = ClientList.LoadClients("clients.list");
            }
            else
            {
                clientList = new ClientList();
                clientList.Save("clients.list");
            }

            foreach (string f in Directory.GetFiles(Path.Combine(Directory.GetCurrentDirectory(), "Commands"), "*.dll"))
            {
                Assembly fA = Assembly.LoadFile(f);
                foreach (Type m in fA.GetTypes())
                {
                    object a = fA.CreateInstance(m.FullName);
                    if (a == null)
                    {
                        Console.WriteLine("Skipping implementation of {0}", m.Name);
                        continue;
                    }

                    antiGCList.Add(a);

                    RegisterCommands(a);
                }
            }
        }
예제 #2
0
        public static void RegisterCommands(object commandClass)
        {
            IRCCommandList returnValue      = IRCCommands;
            Type           commandClassType = commandClass.GetType();

            int maxCom = 0; int place = 0;

            Console.WriteLine("Registering {0}...", commandClass.GetType().Name);

            foreach (MethodInfo methodInfo in commandClassType.GetMethods())
            {
                foreach (Attribute attr in Attribute.GetCustomAttributes(methodInfo))
                {
                    if (attr.GetType() == typeof(IRCCommand) || attr.GetType() == typeof(IRCCommandPlaceholder))
                    {
                        maxCom++;
                        if (attr.GetType() == typeof(IRCCommandPlaceholder))
                        {
                            place++;
                        }

                        IRCCommand      command    = (IRCCommand)attr;
                        ParameterInfo[] parameters = methodInfo.GetParameters();

                        if (parameters.Length != 1 && parameters[0].ParameterType != typeof(IMessage))
                        {
                            Console.WriteLine("\tCommand {0} ({1}) not registered, argument mismatch (requires one argument of type 'Message')", command.Name, methodInfo.Name);
                            continue;
                        }

                        Console.WriteLine("\tCommand {0} {1} registered{2}", command.Name, (command.MinimumArguments != -1 ? "(" + command.MinimumArguments + (command.MaximumArguments != command.MinimumArguments ? "-" + command.MaximumArguments : "") + " argument" + (command.MinimumArguments == 1 && command.MaximumArguments == 1 ? "" : "s") + ")" : "(no arguments)"), (attr.GetType() == typeof(IRCCommandPlaceholder) ? " (Placeholder implementation)" : ""));
                        returnValue.AddCommand(command, commandClass, methodInfo);
                    }
                }
            }

            if (maxCom != 0)
            {
                Console.WriteLine("{0} Commands implemented on {1} with {2} ({3}%)", maxCom, commandClass.GetType().Name, place + " placeholder" + (place != 1 ? "s" : ""), Math.Round((place / (double)maxCom) * 100));
            }
            else
            {
                Console.WriteLine("No commands implemented on {0}", commandClass.GetType().Name);
            }
        }