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; }
public override void Load(object[] args) { if (client == null) { // Attempt to start AOSClient if not already started if (AOSClient.Instance == null && !AOSClient.Initialize()) { throw new Exception("Failed to initialize AOSClient!"); } // Setup some common shortcuts client = AOSClient.Instance; snapshotComponent = client.GetComponent <SnapshotNetComponent>(); objectComponent = client.GetComponent <ObjectNetComponent>(); netPlayerComponent = client.GetComponent <NetPlayerComponent>(); // Grab the screen channel channel = client.GetChannel(AOSChannelType.Screen); // Make sure to move on the initialization to specific screens. OnClientInitialized(); } base.Load(args); }
public Handshake(AOSClient client, MultiplayerScreen screen, NetInboundPacket packet) { this.client = client; this.screen = screen; Start(packet); }
public SnapshotNetComponent(AOSClient client) : base(client) { snapshotSystem = new SnapshotSystem(client); charSnapshotSystem = new CharacterSnapshotSystem(this, snapshotSystem); objectComponent = client.GetComponent <ObjectNetComponent>(); objectComponent.OnCreatableInstantiated += ObjectComponent_OnCreatableInstantiated; objectComponent.OnCreatableDestroyed += ObjectComponent_OnCreatableDestroyed; DashCMD.AddScreen(new DashCMDScreen("snapshot", "Displays information about the snapshot system.", true, (screen) => { screen.WriteLine("Snapshot Round-Trip Time: {0}s", rtt); screen.WriteLine("Last Outbound Snapshot:", ConsoleColor.Cyan); screen.WriteLine("PacketHeader: {0} bytes", lastOutboundPacketStats.PacketHeader); screen.WriteLine("Acks: {0} bytes", lastOutboundPacketStats.Acks); screen.WriteLine("PlayerData: {0} bytes", lastOutboundPacketStats.PlayerData); screen.WriteLine("Total: {0} bytes", lastOutboundPacketStats.Total); }) { SleepTime = 30 }); DashCMD.SetCVar("cl_tickrate", DEFAULT_TICKRATE); DashCMD.SetCVar("cl_await_sv_snap", false); //DashCMD.SetCVar("cl_tickrate", 25); //DashCMD.SetCVar("cl_await_sv_snap", true); syncTime = tickrate; }
public ClientMPPlayer(MasterRenderer renderer, World world, Camera camera, Vector3 position, Team team) : base(renderer, world, camera, position, team) { this.camera = camera; camfx = new CameraFX(this, camera); // Setup ClientInput Snapshot AOSClient client = AOSClient.Instance; SnapshotNetComponent snc = client.GetComponent <SnapshotNetComponent>(); SnapshotSystem ss = snc.SnapshotSystem; ClientSnapshot = new ClientPlayerSnapshot(ss, client.ServerConnection); Camera.Active.FOV = Camera.Active.DefaultFOV; Camera.Active.FPSMouseSensitivity = Camera.Active.DefaultFPSMouseSensitivity; Camera.Active.ArcBallMouseSensitivity = Camera.Active.DefaultArcBallMouseSensitivity; CreateStarterBackpack(); AudioBuffer hitAudioBuffer = AssetManager.LoadSound("Impacts/hit-player-local.wav"); if (hitAudioBuffer != null) { hitAudioSource = new AudioSource(hitAudioBuffer); hitAudioSource.IsSourceRelative = true; hitAudioSource.Gain = 0.2f; } AudioBuffer flashlightAudioBuffer = AssetManager.LoadSound("Player/flashlight.wav"); if (flashlightAudioBuffer != null) { flashlightAudioSource = new AudioSource(flashlightAudioBuffer); flashlightAudioSource.IsSourceRelative = true; flashlightAudioSource.Gain = 0.2f; } AudioBuffer jumpAudioBuffer = AssetManager.LoadSound("Player/jump.wav"); if (jumpAudioBuffer != null) { jumpAudioSource = new AudioSource(jumpAudioBuffer); jumpAudioSource.IsSourceRelative = true; jumpAudioSource.Gain = 0.2f; } AudioBuffer landAudioBuffer = AssetManager.LoadSound("Player/land.wav"); if (landAudioBuffer != null) { landAudioSource = new AudioSource(landAudioBuffer); landAudioSource.IsSourceRelative = true; landAudioSource.Gain = 0.2f; } walkingAudioSource = new CyclicAudioSource("Player/footstep.wav", 8, 0f); runningAudioSource = new CyclicAudioSource("Player/run.wav", 12, 0f); }
public ObjectNetComponent(AOSClient client) : base(client) { instCallbacks = new Dictionary <string, NetInstantiationCallback>(); netObjects = new NetCreatableCollection(); heldInstantiationPackets = new Queue <NetInboundPacket>(); heldDestroyPackets = new Queue <NetInboundPacket>(); }
public NetPlayerComponent(AOSClient client) : base(client) { netPlayers = new Dictionary <ushort, NetworkPlayer>(); channel = client.GetChannel(AOSChannelType.NetInterface); snapshotComponent = client.GetComponent <SnapshotNetComponent>(); channel.AddRemoteEvent("Client_AddNetPlayer", R_AddNetPlayer); channel.AddRemoteEvent("Client_RemoveNetPlayer", R_RemoveNetPlayer); channel.AddRemoteEvent("Client_AddInitialNetPlayers", R_AddInitialNetPlayers); }
public MPWorld(MasterRenderer renderer) : base(renderer) { players = new Dictionary <ushort, ClientPlayer>(); physEntities = new Dictionary <ushort, GameObject>(); TimeOfDay = 10; // Grab network components and the world channel client = AOSClient.Instance; snapshotComponent = client.GetComponent <SnapshotNetComponent>(); objectComponent = client.GetComponent <ObjectNetComponent>(); channel = client.GetChannel(AOSChannelType.World); // Add remotes channel.AddRemoteEvent("Client_ThrowGrenade", R_ThrowGrenade); channel.AddRemoteEvent("Client_ShootMelon", R_ShootMelon); channel.AddRemoteEvent("Client_ServerImpact", R_ServerImpact); channel.AddRemoteEvent("Client_RolledBackServerPlayer", R_RolledBackServerPlayer); // Hook into component events objectComponent.OnCreatableInstantiated += ObjectComponent_OnCreatableInstantiated; objectComponent.OnCreatableDestroyed += ObjectComponent_OnCreatableDestroyed; snapshotComponent.OnWorldSnapshotInbound += SnapshotComponent_OnWorldSnapshotInbound; }
/// <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))); }
public NetComponent(AOSClient client) { this.client = client; }