Example #1
0
        protected void RegisterControlMessage <T>(MyControlMessageEnum msg, ControlMessageHandler <T> handler) where T : struct
        {
            MyControlMessageCallback <T> callback = new MyControlMessageCallback <T>(handler, MySyncLayer.GetSerializer <T>());

            m_controlMessageHandlers.Add((int)msg, callback);
            m_controlMessageTypes.Add(typeof(T), msg);
        }
Example #2
0
        internal void RegisterControlMessage <T>(MyControlMessageEnum msg, ControlMessageHandler <T> handler, MyMessagePermissions permission) where T : struct
        {
            MyControlMessageCallback <T> callback = new MyControlMessageCallback <T>(handler, MySyncLayer.GetSerializer <T>(), permission);

            m_controlMessageHandlers.Add((int)msg, callback);
            m_controlMessageTypes.Add(typeof(T), msg);
        }
Example #3
0
        /// <summary>
        /// This method is run by the calling thread of Run so as not to interupt the
        /// message processing pump.
        /// </summary>
        /// <param name="msg"></param>
        private void DoDispatchMessage(IMessage msg)
        {
            if (msg.Type == Enums.SystemPacketType.CarType)
            {
                CarMessageHandler.Invoke(msg);
            }
            else if (msg.Type == Enums.SystemPacketType.ControlType)
            {
                if (ControlMessageHandler != null)
                {
                    ControlMessageHandler.Invoke(msg);
                }
            }
            else
            {
                if (msg is EndOfSession)
                {
                    // Tell the thread to stop blocking and exit after it's processed the remainder of messages.
                    Stop(JoinMethod.DontJoin, false);
                }

                if (msg is EventId)
                {
                    CurrentEventType = (msg as EventId).EventType;
                }

                SystemMessageHandler.Invoke(msg);
            }
        }
Example #4
0
 public Server(int port)
 {
     Clients                = new ConcurrentDictionary <IntPtr, Client>();
     Port                   = port;
     PacketHandlers         = new WorldPacketHandler[256];
     ControlMessageHandlers = new ControlMessageHandler[64];
     ExpectedConnections    = new ConcurrentDictionary <uint, Redirect>();
     for (int i = 0; i < 256; ++i)
     {
         PacketHandlers[i] = (c, p) => Logger.WarnFormat("Server: Unhandled opcode 0x{0:X2}", p.Opcode);
     }
 }
Example #5
0
 public Server(int port)
 {
     Clients                = new ConcurrentDictionary <IntPtr, Client>();
     Port                   = port;
     PacketHandlers         = new WorldPacketHandler[256];
     ControlMessageHandlers = new ControlMessageHandler[64];
     Throttles              = new Dictionary <byte, IPacketThrottle>();
     ExpectedConnections    = new ConcurrentDictionary <uint, Redirect>();
     for (int i = 0; i < 256; ++i)
     {
         PacketHandlers[i] = (c, p) => GameLog.Warning($"{GetType().Name}: Unhandled opcode 0x{p.Opcode:X2}");
     }
     Task.Run(ProcessOutbound);
 }
Example #6
0
        public Server(int port)
        {
            
            Port = port;
            PacketHandlers = new WorldPacketHandler[256];
            ControlMessageHandlers = new ControlMessageHandler[64];
            ExpectedConnections = new ConcurrentDictionary<uint, Redirect>();

            for (int i = 0; i < 256; ++i)
                PacketHandlers[i] = (c, p) => Logger.WarnFormat("World: Unhandled opcode 0x{0:X2}", p.Opcode);

            TcpListener = new TcpListener(IPAddress.Any, port);
            Logger.InfoFormat("Starting TcpListener: {0}:{1}", IPAddress.Any.ToString(), port);
            TcpListener.Start();
        }
Example #7
0
        public Server(int port)
        {
            Port                   = port;
            PacketHandlers         = new WorldPacketHandler[256];
            ControlMessageHandlers = new ControlMessageHandler[64];
            ExpectedConnections    = new ConcurrentDictionary <uint, Redirect>();

            for (int i = 0; i < 256; ++i)
            {
                PacketHandlers[i] = (c, p) => Logger.WarnFormat("World: Unhandled opcode 0x{0:X2}", p.Opcode);
            }

            TcpListener = new TcpListener(IPAddress.Any, port);
            Logger.InfoFormat("Starting TcpListener: {0}:{1}", IPAddress.Any.ToString(), port);
            TcpListener.Start();
        }
Example #8
0
 public MyControlMessageCallback(ControlMessageHandler <TMsg> callback, ISerializer <TMsg> serializer, MyMessagePermissions permission)
 {
     this.Callback   = callback;
     this.Serializer = serializer;
     this.Permission = permission;
 }
 public MyControlMessageCallback(ControlMessageHandler <TMsg> callback, ISerializer <TMsg> serializer)
 {
     this.Callback   = callback;
     this.Serializer = serializer;
 }