示例#1
0
        public AOSServer(NetServerConfig config)
            : base(config)
        {
            if (Instance != null)
            {
                throw new Exception("An AOSServer already exists!");
            }

            Instance    = this;
            components  = new Dictionary <Type, NetComponent>();
            packetHooks = new List <NetPacketHookCallback>();

            // Create each game channel
            foreach (object o in Enum.GetValues(typeof(AOSChannelType)))
            {
                CreateChannel((ushort)o);
            }

            // Add network components
            AddComponent(new ObjectNetComponent(this));
            AddComponent(new SnapshotNetComponent(this));
            AddComponent(new NetPlayerComponent(this));

            foreach (NetComponent component in components.Values)
            {
                component.Initialize();
            }

            // Hook into base events
            OnUserConnected    += AOSServer_OnUserConnected;
            OnUserDisconnected += AOSServer_OnUserDisconnected;

            // Add some diag commands
            DashCMD.AddCommand("list", "Shows a list of all connected players.",
                               (args) =>
            {
                DashCMD.WriteImportant("Players ({0}):", Connections.Count);
                foreach (NetConnection conn in Connections.Values)
                {
                    DashCMD.WriteStandard("  {0}", conn);
                }

                DashCMD.WriteStandard("");
            });
        }
示例#2
0
        /// <summary>
        /// Creates and attempts to start an AOSServer with
        /// the game specific config.
        /// </summary>
        public static bool Initialize(int maxConnections, IPEndPoint endPoint, IPEndPoint receiveEndPoint = null)
        {
            GlobalNetwork.SetupLogging();

            NetServerConfig config = new NetServerConfig();

            config.MaxConnections       = maxConnections;
            config.DontApplyPingControl = true;

            AOSServer server = new AOSServer(config);

            bool success = server.Start(endPoint);

            if (success)
            {
                GlobalNetwork.IsServer    = true;
                GlobalNetwork.IsConnected = true;
            }

            return(success);
        }