private AOSClient(NetClientConfig config) : base(config) { if (Instance != null) { throw new Exception("An AOSClient 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 OnConnected += AOSClient_OnConnected; OnDisconnected += AOSClient_OnDisconnected; }
/// <summary> /// Creates and attempts to start an AOSClient with /// the game specific config. /// </summary> public static bool Initialize() { GlobalNetwork.SetupLogging(); ConfigSection netSection = Program.ConfigFile.GetSection("Network"); IPAddress bindIp = null; int? bindPort = null; if (netSection != null) { bool autoFindEndpoint = netSection.GetBoolean("auto-find-endpoint") ?? true; if (!autoFindEndpoint) { IPAddress.TryParse(netSection.GetString("bind-to-ip"), out bindIp); bindPort = netSection.GetInteger("bind-to-port"); } } if (bindIp == null) { bindIp = NetHelper.GetInternalIP(); } if (!bindPort.HasValue) { bindPort = 0; } NetClientConfig config = new NetClientConfig(); config.DontApplyPingControl = true; AOSClient client = new AOSClient(config); return(client.Start(new IPEndPoint(bindIp, bindPort.Value))); }