Example #1
0
        private MonitorEvent(SocketEvents monitorEvent, [NotNull] string addr, [NotNull] object arg)
        {
            m_monitorEvent = monitorEvent;
            m_addr = addr;
            m_arg = arg;

            if (arg is int)
                m_flag = ValueInteger;
            else if (arg is AsyncSocket)
                m_flag = ValueChannel;
            else
                m_flag = 0;
        }
Example #2
0
 internal static Error TryChangeSocketEventRegistration(int port, SafeHandle socket, SocketEvents currentEvents, SocketEvents newEvents, IntPtr data)
 {
     bool release = false;
     try
     {
         socket.DangerousAddRef(ref release);
         return DangerousTryChangeSocketEventRegistration(port, (int)socket.DangerousGetHandle(), currentEvents, newEvents, data);
     }
     finally
     {
         if (release)
         {
             socket.DangerousRelease();
         }
     }
 }
Example #3
0
 internal static extern Error TryChangeSocketEventRegistration(IntPtr port, IntPtr socket, SocketEvents currentEvents, SocketEvents newEvents, IntPtr data);
Example #4
0
 /// <summary>
 /// Create a new NetMQMonitorSocketEventArgs that contains the given monitor, address, and socket.
 /// </summary>
 /// <param name="monitor">The <see cref="NetMQMonitor"/> that raised this event.</param>
 /// <param name="address">The address of the event.</param>
 /// <param name="socketEvent">The type of socket event that occurred.</param>
 /// <param name="socket">The socket upon which this event occurred.</param>
 public NetMQMonitorSocketEventArgs([NotNull] NetMQMonitor monitor, [NotNull] string address, [NotNull] AsyncSocket socket, SocketEvents socketEvent)
     : base(monitor, address, socketEvent)
 {
     Socket = socket;
 }
Example #5
0
        /// <summary>
        /// Program entry.
        /// </summary>
        /// <param name="args">Process arguments.</param>
        public static void Main(string[] args)
        {
            Console.Title = "ProjectX V3 - Game Server";

            try
            {
                config = new XmlConfig();
                config.LoadConfig(Database.ServerDatabase.DatabaseLocation + "\\Config.xml");
            }
            catch (Exception e)
            {
                Console.WriteLine("Could not load the config.");
                Console.WriteLine("Error:");
                Console.WriteLine(e);
                Console.ReadLine();
                return;
            }

            if (!Database.ServerDatabase.Load())
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Could not load the database.");
                Console.ReadLine();
                return;
            }

            Threads.GlobalThreads.Start();

            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("Starting the server...");
            try
            {
                Network.GameAuth.Start();
                SocketEvents sockEvents = new SocketEvents();
                sockEvents.OnConnection    = new ConnectionEvent(Network.NetworkConnections.Handle_Connection);
                sockEvents.OnDisconnection = new ConnectionEvent(Network.NetworkConnections.Handle_Disconnection);
                sockEvents.OnReceive       = new BufferEvent(Network.NetworkConnections.Handle_Receive);
                BeginServer(sockEvents, config.ReadInt32("GamePort"));

                ProjectX_V3_Lib.Native.Kernel32.SetConsoleCtrlHandler(
                    new ProjectX_V3_Lib.Native.Kernel32.ConsoleEventHandler(Console_CloseEvent),
                    true);

                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("The server is open...");
                Console.ResetColor();
            }
            catch (Exception e)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Could not open the server...");
                Console.WriteLine(e.ToString());
                Console.ReadLine();
                return;
            }

            while (true)
            {
                HandleCmd(Console.ReadLine());
            }
        }
Example #6
0
 public MonitorEvent(SocketEvents monitorEvent, [NotNull] string addr, [NotNull] AsyncSocket arg)
     : this(monitorEvent, addr, (object)arg)
 {
 }
Example #7
0
 /// <summary>
 /// Create a new NetMQMonitorSocketEventArgs that contains the given monitor, address, and socket.
 /// </summary>
 /// <param name="monitor">The <see cref="NetMQMonitor"/> that raised this event.</param>
 /// <param name="address">The address of the event.</param>
 /// <param name="socketEvent">The type of socket event that occurred.</param>
 /// <param name="socket">The socket upon which this event occurred.</param>
 public NetMQMonitorSocketEventArgs([NotNull] NetMQMonitor monitor, [NotNull] string address, [NotNull] AsyncSocket socket, SocketEvents socketEvent)
     : base(monitor, address, socketEvent)
 {
     Socket = socket;
 }
Example #8
0
 public MonitorEvent(SocketEvents monitorEvent,  string addr,  AsyncSocket arg)
     : this(monitorEvent, addr, (object)arg)
 {
 }
Example #9
0
 private void ValueServer_OnBaseReceive(SocketEvents.ReceiveEventArgs e)
 {
     if (OnReceive != null)
         OnReceive(e);
 }
Example #10
0
 /// <summary>
 /// Create a new NetMQMonitorSocketEventArgs that contains the given monitor, address, and socket.
 /// </summary>
 /// <param name="monitor">The <see cref="NetMQMonitor"/> that raised this event.</param>
 /// <param name="address">The address of the event.</param>
 /// <param name="socketEvent">The type of socket event that occurred.</param>
 /// <param name="socket">The socket upon which this event occurred.</param>
 public NetMQMonitorSocketEventArgs(NetMQMonitor monitor, string address, AsyncSocket socket, SocketEvents socketEvent)
     : base(monitor, address, socketEvent)
 {
     Socket = socket;
 }
Example #11
0
 /// <summary>
 /// Create a new NetMQMonitorErrorEventArgs that contains the given monitor, address, and error-code.
 /// </summary>
 /// <param name="monitor">The <see cref="NetMQMonitor"/> that raised this event.</param>
 /// <param name="address">The address of the event.</param>
 /// <param name="socketEvent">The type of socket event that occurred.</param>
 /// <param name="errorCode">The error code associated with this event.</param>
 public NetMQMonitorErrorEventArgs(NetMQMonitor monitor, string address, ErrorCode errorCode, SocketEvents socketEvent)
     : base(monitor, address, socketEvent)
 {
     ErrorCode = errorCode;
 }
Example #12
0
 /// <summary>
 /// Create a new NetMQMonitorIntervalEventArgs containing the given NetMQMonitor, address, and interval.
 /// </summary>
 /// <param name="monitor">the NetMQMonitor</param>
 /// <param name="address">The a string denoting the address</param>
 /// <param name="interval">The interval, in milliseconds.</param>
 /// <param name="socketEvent">The type of socket event that occurred.</param>
 public NetMQMonitorIntervalEventArgs(NetMQMonitor monitor, string address, int interval, SocketEvents socketEvent)
     : base(monitor, address, socketEvent)
 {
     Interval = interval;
 }
Example #13
0
 /// <summary>
 /// Create a new NetMQMonitorEventArgs that contains the given monitor and address.
 /// </summary>
 /// <param name="monitor">The <see cref="NetMQMonitor"/> that raised this event.</param>
 /// <param name="address">The address of the event.</param>
 /// <param name="socketEvent">The type of socket event that occurred.</param>
 protected NetMQMonitorEventArgs(NetMQMonitor monitor, string address, SocketEvents socketEvent)
 {
     Monitor     = monitor;
     Address     = address;
     SocketEvent = socketEvent;
 }
Example #14
0
        internal static Error TryChangeSocketEventRegistration(int port, SafeHandle socket, SocketEvents currentEvents, SocketEvents newEvents, IntPtr data)
        {
            bool release = false;

            try
            {
                socket.DangerousAddRef(ref release);
                return(DangerousTryChangeSocketEventRegistration(port, (int)socket.DangerousGetHandle(), currentEvents, newEvents, data));
            }
            finally
            {
                if (release)
                {
                    socket.DangerousRelease();
                }
            }
        }
Example #15
0
 internal static extern Error DangerousTryChangeSocketEventRegistration(int port, int socket, SocketEvents currentEvents, SocketEvents newEvents, IntPtr data);
Example #16
0
        /// <summary>
        /// Begins the server.
        /// </summary>
        /// <param name="sockEvents">The socket events.</param>
        /// <param name="port">The port.</param>
        private static void BeginServer(SocketEvents sockEvents, int port)
        {
            SocketServer server = new SocketServer(sockEvents);

            server.Start(config.ReadString("IPAddress"), port);
        }
Example #17
0
 /// <summary>
 /// 反注册一条事件
 /// </summary>
 /// <param name="socketEvent">Socket事件</param>
 /// <param name="callback">回调</param>
 public void Off(SocketEvents socketEvent, Action <object> callback)
 {
     emmiter.Off(socketEvent, callback);
 }
 internal static partial Error TryChangeSocketEventRegistration(IntPtr port, SafeHandle socket, SocketEvents currentEvents, SocketEvents newEvents, IntPtr data);
Example #19
0
 /// <summary>
 /// 触发一个Socket事件
 /// </summary>
 /// <param name="socketEvent">Socket事件</param>
 /// <param name="payload">载荷</param>
 public void Trigger(SocketEvents socketEvent, object payload)
 {
     emmiter.Trigger(socketEvent, payload);
 }
Example #20
0
 /// <summary>
 /// Create a new NetMQMonitorSocketEventArgs that contains the given monitor, address, and socket.
 /// </summary>
 /// <param name="monitor">The <see cref="NetMQMonitor"/> that raised this event.</param>
 /// <param name="address">The address of the event.</param>
 /// <param name="socketEvent">The type of socket event that occurred.</param>
 /// <param name="socket">The socket upon which this event occurred.</param>
 public NetMQMonitorSocketEventArgs( NetMQMonitor monitor,  string address,  AsyncSocket socket, SocketEvents socketEvent)
     : base(monitor, address, socketEvent)
 {
     Socket = socket;
 }
Example #21
0
 internal static extern Error TryChangeSocketEventRegistration(int port, int socket, SocketEvents currentEvents, SocketEvents newEvents, IntPtr data);
Example #22
0
        /// <summary>
        /// Register the given events to monitor on the given endpoint.
        /// </summary>
        /// <param name="addr">a string denoting the endpoint to monitor. If this is null - monitoring is stopped.</param>
        /// <param name="events">the SocketEvent to monitor for</param>
        /// <exception cref="NetMQException">Maximum number of sockets reached.</exception>
        /// <exception cref="ProtocolNotSupportedException">The protocol of <paramref name="addr"/> is not supported.</exception>
        /// <exception cref="TerminatingException">The socket has been stopped.</exception>
        public void Monitor([CanBeNull] string addr, SocketEvents events)
        {
            CheckContextTerminated();

            // Support de-registering monitoring endpoints as well
            if (addr == null)
            {
                StopMonitor();
                return;
            }

            string address;
            string protocol;
            DecodeAddress(addr, out address, out protocol);

            CheckProtocol(protocol);

            // Event notification only supported over inproc://
            if (protocol != Address.InProcProtocol)
                throw new ProtocolNotSupportedException($"In SocketBase.Monitor({addr},), protocol must be inproc");

            // Register events to monitor
            m_monitorEvents = events;

            m_monitorSocket = Ctx.CreateSocket(ZmqSocketType.Pair);

            // Never block context termination on pending event messages
            const int linger = 0;

            try
            {
                m_monitorSocket.SetSocketOption(ZmqSocketOption.Linger, linger);
            }
            catch (NetMQException)
            {
                StopMonitor();
                throw;
            }

            // Spawn the monitor socket endpoint
            try
            {
                m_monitorSocket.Bind(addr);
            }
            catch (NetMQException)
            {
                StopMonitor();
                throw;
            }
        }
Example #23
0
 public MonitorEvent(SocketEvents monitorEvent, [NotNull] string addr, ErrorCode arg)
     : this(monitorEvent, addr, (int)arg)
 {
 }
Example #24
0
 /// <summary>
 /// Create a new NetMQMonitorIntervalEventArgs containing the given NetMQMonitor, address, and interval.
 /// </summary>
 /// <param name="monitor">the NetMQMonitor</param>
 /// <param name="address">The a string denoting the address</param>
 /// <param name="interval">The interval, in milliseconds.</param>
 /// <param name="socketEvent">The type of socket event that occurred.</param>
 public NetMQMonitorIntervalEventArgs([NotNull] NetMQMonitor monitor, [NotNull] string address, int interval, SocketEvents socketEvent)
     : base(monitor, address, socketEvent)
 {
     Interval = interval;
 }
Example #25
0
 public MonitorEvent(SocketEvents monitorEvent, string addr, AsyncSocket arg)
     : this(monitorEvent, addr, (object)arg)
 {
 }
Example #26
0
 internal static extern Error TryChangeSocketEventRegistration(IntPtr port, SafeHandle socket, SocketEvents currentEvents, SocketEvents newEvents, IntPtr data);
Example #27
0
 /// <summary>
 /// If there is a monitor-socket, close it and set monitor-events to 0.
 /// </summary>
 private void StopMonitor()
 {
     if (m_monitorSocket != null)
     {
         m_monitorSocket.Close();
         m_monitorSocket = null;
         m_monitorEvents = 0;
     }
 }
Example #28
0
        /// <summary>
        /// Create a new monitor object
        /// </summary>
        /// <param name="monitoredSocket">Socket to monitor</param>
        /// <param name="endpoint">Bind endpoint</param>
        /// <param name="eventsToMonitor">Flag enum of the events to monitored</param>
        public NetMQMonitor([NotNull] NetMQSocket monitoredSocket, [NotNull] string endpoint, SocketEvents eventsToMonitor)
        {
            Endpoint = endpoint;
            Timeout  = TimeSpan.FromSeconds(0.5);

            monitoredSocket.Monitor(endpoint, eventsToMonitor);

            m_monitoringSocket = new PairSocket();
            m_monitoringSocket.Options.Linger = TimeSpan.Zero;
            m_monitoringSocket.ReceiveReady  += Handle;

            m_ownsMonitoringSocket = true;
        }
Example #29
0
 /// <summary>
 /// Create a new NetMQMonitorEventArgs that contains the given monitor and address.
 /// </summary>
 /// <param name="monitor">The <see cref="NetMQMonitor"/> that raised this event.</param>
 /// <param name="address">The address of the event.</param>
 /// <param name="socketEvent">The type of socket event that occurred.</param>
 protected NetMQMonitorEventArgs([NotNull] NetMQMonitor monitor, [NotNull] string address, SocketEvents socketEvent)
 {
     Monitor = monitor;
     Address = address;
     SocketEvent = socketEvent;
 }
Example #30
0
 public MonitorEvent(SocketEvents monitorEvent, [NotNull] string addr, ErrorCode arg)
     : this(monitorEvent, addr, (int)arg)
 {
 }
Example #31
0
 /// <summary>
 /// Create a new NetMQMonitorErrorEventArgs that contains the given monitor, address, and error-code.
 /// </summary>
 /// <param name="monitor">The <see cref="NetMQMonitor"/> that raised this event.</param>
 /// <param name="address">The address of the event.</param>
 /// <param name="socketEvent">The type of socket event that occurred.</param>
 /// <param name="errorCode">The error code associated with this event.</param>
 public NetMQMonitorErrorEventArgs([NotNull] NetMQMonitor monitor, [NotNull] string address, ErrorCode errorCode, SocketEvents socketEvent)
     : base(monitor, address, socketEvent)
 {
     ErrorCode = errorCode;
 }
Example #32
0
 public MonitorEvent(SocketEvents monitorEvent, [NotNull] string addr, [NotNull] AsyncSocket arg)
     : this(monitorEvent, addr, (object)arg)
 {
 }