コード例 #1
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="StringResources">The StringResources to use.</param>
        public ServerConnection(LockingDictionary <uint, string> StringResources)
        {
            // init the queues (receive, send, logs, exceptions)
            ReceiveQueue   = new LockingQueue <GameMessage>();
            SendQueue      = new LockingQueue <GameMessage>();
            ExceptionQueue = new LockingQueue <Exception>();

            // the debugqueue to give back sent packets (with crc/...) if activated
            OutgoingPacketLog = new LockingQueue <GameMessage>();

            // save reference to string dictionary
            stringResources = StringResources;

            // setup the packetcontroller
            messageController = new MessageControllerClient(StringResources);

            // hook up listeners
            messageController.MessageAvailable    += new GameMessageEventHandler(OnMessageControllerNewMessageAvailable);
            messageController.ServerSaveChanged   += new ServerSaveChangedEventHandler(OnMessageControllerNewServerSave);
            messageController.HandlerError        += new HandlerErrorEventHandler(OnMessageControllerHandlerError);
            messageController.ProtocolModeChanged += new EventHandler(OnMessageControllerProtocolModeChanged);

            // setup the ping timer
            timPing          = new System.Timers.Timer();
            timPing.Enabled  = false;
            timPing.Interval = PINGINTERVAL;
            timPing.Elapsed += new ElapsedEventHandler(OnPingTimerElapsed);
        }
コード例 #2
0
        private void ClearQueue(LockingQueue <CommandPacket> queue)
        {
            CommandPacket item;

            while (queue.TryDequeue(out item))
            {
                item.Observer.OnCompleted();
            }
        }
コード例 #3
0
        /// <summary>
        /// Overwritten Init method.
        /// This method connects to the M59 server.
        /// So we connect to IRC here as well.
        /// </summary>
        public override void Init()
        {
            // base handler connecting to m59 server
            base.Init();

            // create IRC command queues
            ChatCommandQueue  = new LockingQueue <string>();
            AdminCommandQueue = new LockingQueue <string>();
            WhoXQueryQueue    = new WhoXQueryQueue();

            // Whether bot echoes to IRC or not.
            DisplayMessages = true;

            // Create list for keeping track of user registration.
            UserRegistration = new Dictionary <string, bool>();

            // Init list of recent admins to send a command.
            RecentAdmins = new List <string>();

            // create an IRC client instance
            IrcClient = new StandardIrcClient();
            IrcClient.FloodPreventer = new FloodPreventer(Config.MaxBurst, Config.Refill);

            // hook up IRC client event handlers
            // beware! these are executed by the internal workthread
            // of the library.
            IrcClient.Connected         += OnIrcClientConnected;
            IrcClient.ConnectFailed     += OnIrcClientConnectFailed;
            IrcClient.Disconnected      += OnIrcClientDisconnected;
            IrcClient.Registered        += OnIrcClientRegistered;
            IrcClient.ProtocolError     += OnIrcClientProtocolError;
            IrcClient.WhoXReplyReceived += OnWhoXReplyReceived;

            // build our IRC connection info
            IrcUserRegistrationInfo regInfo = new IrcUserRegistrationInfo();

            regInfo.UserName = Config.NickName;
            regInfo.RealName = Config.NickName;
            regInfo.NickName = Config.NickName;

            // if password is set
            if (!String.Equals(Config.IRCPassword, String.Empty))
            {
                regInfo.Password = Config.IRCPassword;
            }

            // log IRC connecting
            Log("SYS", "Connecting IRC to " + Config.IRCServer + ":" + Config.IRCPort);

            // connect the lib internally (this is async)
            IrcClient.Connect(Config.IRCServer, Config.IRCPort, false, regInfo);
        }
コード例 #4
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="M59ResourceManager">Will be used to resolve/load resources</param>
        /// <param name="ServerConnection">Reads incoming messages from this ServerConnection</param>
        public MessageEnrichment(ResourceManager M59ResourceManager, ServerConnection ServerConnection)
        {
            // init output queue
            OutputQueue = new LockingQueue <GameMessage>();

            // save references
            resourceManager  = M59ResourceManager;
            serverConnection = ServerConnection;

            // mark running
            IsRunning = true;

            // start own workthread
            workThread = new Thread(ThreadProc);
            workThread.Start();
        }
コード例 #5
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="M59ResourceManager">Will be used to resolve/load resources</param>
        /// <param name="ServerConnection">Reads incoming messages from this ServerConnection</param>
        public MessageEnrichment(ResourceManager M59ResourceManager, ServerConnection ServerConnection)
        {
            // init output queue
            OutputQueue = new LockingQueue<GameMessage>();

            // save references
            resourceManager = M59ResourceManager;
            serverConnection = ServerConnection;
            
            // mark running
            IsRunning = true;

            // start own workthread
            workThread = new Thread(ThreadProc);
            workThread.IsBackground = true;
            workThread.Start();
        }
コード例 #6
0
        /// <summary>
        /// Overwritten Init method.
        /// This method connects to the M59 server.
        /// So we connect to IRC here as well.
        /// </summary>
        public override void Init()
        {
            // base handler connecting to m59 server
            base.Init();

            // create IRC command queues
            ChatCommandQueue  = new LockingQueue <string>();
            AdminCommandQueue = new LockingQueue <string>();
            IRCSendQueue      = new IRCQueryQueue();
            WhoXQueryQueue    = new WhoXQueryQueue();

            // Whether bot echoes to IRC or not.
            DisplayMessages = true;

            // Create list for keeping track of user registration.
            UserRegistration = new Dictionary <string, bool>();

            // Init list of recent admins to send a command.
            RecentAdmins = new List <string>();

            // create an IRC client instance, with connection info
            IrcClient = new IrcClient(Config.IRCServer,
                                      new IrcUser(Config.NickName, Config.NickName, Config.IRCPassword, Config.NickName));

            // TODO: does ChatSharp use something like this?
            //IrcClient.FloodPreventer = new FloodPreventer(Config.MaxBurst, Config.Refill);

            // hook up IRC client event handlers
            // beware! these are executed by the internal workthread
            // of the library.
            IrcClient.ConnectionComplete += OnIrcClientConnected;

            // ChatSharp doesn't have fine-grained error handling
            // to my knowledge, likely we have to disconnect on any
            // network error.
            IrcClient.NetworkError += OnIrcClientDisconnected;

            IrcClient.WhoxReceived += OnWhoXReplyReceived;

            // log IRC connecting
            Log("SYS", "Connecting IRC to " + Config.IRCServer + ":" + Config.IRCPort);

            // connect the lib internally (this is async)
            IrcClient.ConnectAsync();
        }
コード例 #7
0
        /// <summary>
        /// Overwritten Init method.
        /// This method connects to the M59 server.
        /// So we connect to IRC here as well.
        /// </summary>
        public override void Init()
        {
            // base handler connecting to m59 server
            base.Init();

            // create IRC command queues
            ChatCommandQueue  = new LockingQueue <string>();
            AdminCommandQueue = new LockingQueue <string>();

            // create an IRC client instance
            IrcClient = new IrcClient();
            IrcClient.FloodPreventer = new FloodPreventer(Config.MaxBurst, Config.Refill);

            // hook up IRC client event handlers
            // beware! these are executed by the internal workthread
            // of the library.
            IrcClient.Connected     += OnIrcClientConnected;
            IrcClient.ConnectFailed += OnIrcClientConnectFailed;
            IrcClient.Disconnected  += OnIrcClientDisconnected;
            IrcClient.Registered    += OnIrcClientRegistered;
            IrcClient.ProtocolError += OnIrcClientProtocolError;

            // build our IRC connection info
            IrcUserRegistrationInfo regInfo = new IrcUserRegistrationInfo();

            regInfo.UserName = Config.NickName;
            regInfo.RealName = Config.NickName;
            regInfo.NickName = Config.NickName;

            // if password is set
            if (!String.Equals(Config.IRCPassword, String.Empty))
            {
                regInfo.Password = Config.IRCPassword;
            }

            // log IRC connecting
            Log("SYS", "Connecting IRC to " + Config.IRCServer + ":" + Config.IRCPort);

            // connect the lib internally (this is async)
            IrcClient.Connect(Config.IRCServer, Config.IRCPort, false, regInfo);
        }
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="StringResources">The StringResources to use.</param>
        public ServerConnection(LockingDictionary<uint, string> StringResources)
        {
            // init the queues (receive, send, logs, exceptions)
            ReceiveQueue = new LockingQueue<GameMessage>();
            SendQueue = new LockingQueue<GameMessage>();
            ExceptionQueue = new LockingQueue<Exception>();

            // the debugqueue to give back sent packets (with crc/...) if activated
            OutgoingPacketLog = new LockingQueue<GameMessage>();

            // save reference to string dictionary
            stringResources = StringResources;

            // setup the packetcontroller
            messageController = new MessageControllerClient(StringResources);

            // hook up listeners
            messageController.MessageAvailable += new GameMessageEventHandler(OnMessageControllerNewMessageAvailable);
            messageController.ServerSaveChanged += new ServerSaveChangedEventHandler(OnMessageControllerNewServerSave);
            messageController.HandlerError += new HandlerErrorEventHandler(OnMessageControllerHandlerError);
            messageController.ProtocolModeChanged += new EventHandler(OnMessageControllerProtocolModeChanged);

            // setup the ping timer
            timPing = new System.Timers.Timer();
            timPing.Enabled = false;
            timPing.Interval = PINGINTERVAL;
            timPing.Elapsed += new ElapsedEventHandler(OnPingTimerElapsed);
        }
コード例 #9
0
 public WhoXQueryQueue()
 {
     Queue         = new LockingQueue <Tuple <DateTime, string> >();
     LastQueryTime = DateTime.UtcNow;
 }
コード例 #10
0
 public IRCQueryQueue()
 {
     Queue         = new LockingQueue <IrcMessage>();
     LastQueryTime = DateTime.UtcNow;
 }