Exemplo n.º 1
0
        private void NetPlayerComponent_OnClientInfoReceived(NetConnection connection, NetworkPlayer player)
        {
            DashCMD.WriteImportant("[MatchScreen] '{0}' has joined!", player.Name);
            Chat(string.Format("'{0}' has joined!", player.Name));

            // Initate handshake with this new connection
            if (processNewConnections && !handshakeComponent.Initiate(connection))
            {
                connection.Disconnect("Failed to initiate handshake!");
            }
        }
 bool TryConnect(IPEndPoint to, out NetDenialReason?denialReason)
 {
     if (client.Connect(to, out denialReason))
     {
         DashCMD.WriteImportant("Successfully connected to server!");
         return(true);
     }
     else
     {
         DashCMD.WriteError("Failed to connect to server: {0}", denialReason.Value);
         return(false);
     }
 }
Exemplo n.º 3
0
        protected void LogOpenGLDrivers()
        {
            string gl_version       = GL.GetString(StringName.Version);
            string gl_vendor        = GL.GetString(StringName.Vendor);
            string gl_gpu           = GL.GetString(StringName.Renderer);
            string gl_shaderversion = GL.GetString(StringName.ShadingLanguageVersion);

            DashCMD.WriteImportant("OpenGL Drivers:");
            DashCMD.WriteStandard("Vendor: {0}", args: gl_vendor);
            DashCMD.WriteStandard("GPU: {0}", gl_gpu);
            DashCMD.WriteStandard("Version: {0}", gl_version);
            DashCMD.WriteStandard("Shader Version: {0}", gl_shaderversion);
        }
        void UnloadWorld()
        {
            // Reset some network values so this screen
            // can be reused
            handshake = null;

            // Dispose of the world if it exists
            if (World != null)
            {
                DashCMD.WriteImportant("[MultiplayerScreen] Unloading world...");
                World.Dispose();
            }

            hud.Disable();
            announcementTime = 0;
            objectComponent.HoldInstantiationPackets = true;
        }
Exemplo n.º 5
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("");
            });
        }
        void CreateWorkers()
        {
            if (workers == null)
            {
                workers = new TerrainWorker[Math.Max(Environment.ProcessorCount - (GlobalNetwork.IsServer ? 2 : 1), 2)];
                for (int i = 0; i < workers.Length; i++)
                {
                    workers[i] = new TerrainWorker();
                }

                DashCMD.WriteImportant("[FixedTerrain] Created {0} background threads.", workers.Length);
            }

            for (int i = 0; i < workers.Length; i++)
            {
                workers[i].SetTerrain(this);
            }
        }
Exemplo n.º 7
0
 public bool LoadFromFile(string fileName)
 {
     DashCMD.WriteImportant("[ServerWorld] Loading world '{0}'...", fileName);
     try
     {
         Description = WorldIO.Load(CurrentWorldName = fileName);
         SetTerrain(Description.Terrain);
         Terrain.LockBottomLayer = true;
         DashCMD.WriteImportant("[ServerWorld] Successfully loaded world '{0}'.", fileName);
         return(true);
     }
     catch (IOException ioex)
     {
         DashCMD.WriteError("[ServerWorld] Failed to load world '{0}'!", fileName);
         DashCMD.WriteError(ioex);
         return(false);
     }
 }
Exemplo n.º 8
0
        static void CreateServerConfigIfMissing()
        {
            if (!File.Exists("server.cfg"))
            {
                try
                {
                    using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("AceOfSpades.Server.cfg.server.default.cfg"))
                        using (FileStream fs = File.Open("./server.cfg", FileMode.Create, FileAccess.Write))
                        {
                            stream.Seek(0, SeekOrigin.Begin);
                            stream.CopyTo(fs);
                        }

                    DashCMD.WriteImportant("Created default server.cfg");
                }
                catch (Exception e)
                {
                    DashCMD.WriteError("Failed to create server.cfg!");
                    DashCMD.WriteError(e);
                }
            }
        }
Exemplo n.º 9
0
 public virtual void Stop()
 {
     DashCMD.WriteImportant("[Gamemode] Stopping '{0}'...", Type);
     OnStopped();
 }
Exemplo n.º 10
0
 private void NetPlayerComponent_OnClientLeave(NetConnection connection, NetworkPlayer player)
 {
     DashCMD.WriteImportant("[MatchScreen] '{0}' has left!", player.Name);
     Chat(string.Format("'{0}' has left!", player.Name));
 }
Exemplo n.º 11
0
        public MatchScreen(ServerGame game)
            : base(game, "Match")
        {
            gamemodes = new Dictionary <GamemodeType, NetworkedGamemode>()
            {
                { GamemodeType.TDM, new TDMGamemode(this) },
                { GamemodeType.CTF, new CTFGamemode(this) }
            };

            // Setup default multiplayer cvars
            DashCMD.SetCVar("ch_infammo", false);
            DashCMD.SetCVar("ch_infhealth", false);
            DashCMD.SetCVar("mp_friendlyfire", false);

            DashCMD.SetCVar("sv_impacts", false);
            DashCMD.SetCVar("sv_hitboxes", false);

            DashCMD.SetCVar("rp_rollback_constant", false);
            DashCMD.SetCVar("rp_rollback_factor", 0.5f);
            DashCMD.SetCVar("rp_rollback_offset", 0);
            DashCMD.SetCVar("rp_usetargetping", false);

            DashCMD.SetCVar("gm_neverend", false);

            DashCMD.AddCommand("world", "Changes the world", "world [filename | *]",
                               (args) =>
            {
                if (args.Length != 1)
                {
                    DashCMD.WriteImportant("Current World: {0}", World.CurrentWorldName);
                }
                else
                {
                    string worldFile = args[0];
                    ChangeWorld(worldFile);
                }
            });

            DashCMD.AddCommand("worlds", "Lists all worlds", "worlds",
                               (args) =>
            {
                string[] worlds = Directory.GetFiles("Content/Worlds");
                DashCMD.WriteImportant("Available Worlds ({0}):", worlds.Length);
                for (int i = 0; i < worlds.Length; i++)
                {
                    DashCMD.WriteStandard("  {0}", Path.GetFileNameWithoutExtension(worlds[i]));
                }
            });

            DashCMD.AddCommand("gamemode", "Changes the gamemode", "gamemode [mode]",
                               (args) =>
            {
                if (args.Length != 1)
                {
                    DashCMD.WriteImportant("Current Gamemode: {0}",
                                           currentGamemode != null ? currentGamemode.Type.ToString() : "None");
                }
                else
                {
                    GamemodeType type;
                    if (Enum.TryParse(args[0], true, out type))
                    {
                        ChangeWorld(World.CurrentWorldName, type);
                    }
                    else
                    {
                        DashCMD.WriteError("Gamemode '{0}' does not exist!", type);
                    }
                }
            });

            DashCMD.AddCommand("say", "Announces a global message", "say <message>",
                               (args) =>
            {
                if (args.Length == 0)
                {
                    DashCMD.ShowSyntax("say");
                }
                else
                {
                    Announce(DashCMD.CombineArgs(args), 5);
                }
            });

            DashCMD.AddCommand("chat", "Sends a chat message from the user 'SERVER'", "chat <message>",
                               (args) =>
            {
                if (args.Length == 0)
                {
                    DashCMD.ShowSyntax("chat");
                }
                else
                {
                    Chat(DashCMD.CombineArgs(args));
                }
            });
        }
Exemplo n.º 12
0
        public PlayerTransform RollbackTransform(int timeFrame, bool suppressLog = false)
        {
            PlayerTransform pt1 = null, pt2 = null;

            for (int i = 0; i < playerTransforms.Count; i++)
            {
                PlayerTransform pt      = playerTransforms[i];
                int             tickOff = Math.Abs(pt.Ticks - timeFrame);

                // Don't process anything more than a second off
                if (tickOff > 1000)
                {
                    continue;
                }

                if (pt1 == null || tickOff < Math.Abs(pt1.Ticks - timeFrame))
                {
                    pt1 = pt;
                }
            }

            for (int i = 0; i < playerTransforms.Count; i++)
            {
                PlayerTransform pt = playerTransforms[i];
                if (pt == pt1)
                {
                    continue;
                }

                int tickOff = Math.Abs(pt.Ticks - timeFrame);

                // Don't process anything more than a second off
                if (tickOff > 1000)
                {
                    continue;
                }

                if (pt2 == null || tickOff < Math.Abs(pt2.Ticks - timeFrame))
                {
                    pt2 = pt;
                }
            }

            if (pt1 != null && pt2 != null)
            {
                if (pt2.Ticks > pt1.Ticks)
                {
                    PlayerTransform temp = pt2;
                    pt2 = pt1;
                    pt1 = temp;
                }

                // Interpolate
                float timeI = pt1.Ticks == pt2.Ticks ? 0f : (float)(timeFrame - pt2.Ticks) / (pt1.Ticks - pt2.Ticks);
                //timeI = MathHelper.Clamp(timeI, 0f, 1f);

                if (DashCMD.GetCVar <bool>("sv_hitboxes") && !suppressLog)
                {
                    DashCMD.WriteImportant("[RB] Rolling back transform by {0}%. [timeFrame: {3}, pt2: {1}, pt1: {2}]",
                                           timeI * 100, pt2.Ticks, pt1.Ticks, timeFrame);
                }

                Vector3 position = Interpolation.Lerp(pt2.Position, pt1.Position, timeI);
                float   camPitch = Interpolation.LerpDegrees(pt2.CameraPitch, pt1.CameraPitch, timeI);
                float   camYaw   = Interpolation.LerpDegrees(pt2.CameraYaw, pt1.CameraYaw, timeI);

                return(new PlayerTransform(position, camYaw, camPitch, timeFrame));
            }
            else if (pt1 != null && pt2 == null)
            {
                // Take pt1
                return(pt1);
            }
            else
            {
                // Take current
                return(new PlayerTransform(Transform.Position, camera.Yaw, camera.Pitch, Environment.TickCount));
            }
        }
Exemplo n.º 13
0
 public override bool Connect(IPEndPoint serverAddress, string password, out NetDenialReason?denialReason)
 {
     DashCMD.WriteImportant("Connecting to {0}...", serverAddress);
     return(base.Connect(serverAddress, password, out denialReason));
 }
Exemplo n.º 14
0
        void InitializeDebugging()
        {
            DashCMD.AddCommand("endpoint", "Displays the server's ip endpoint.",
                               (args) =>
            {
                DashCMD.WriteLine("Bound IPEndPoint: {0}", AOSServer.Instance.BoundEndPoint);
                DashCMD.WriteLine("Receive IPEndPoint: {0}", AOSServer.Instance.ReceiveEndPoint);
                DashCMD.WriteLine("");
            });

            DashCMD.AddCommand("exit", "Stops the server.",
                               (args) =>
            {
                DashCMD.WriteImportant("Shutting down server...");
                AOSServer.Instance.Shutdown("Server shutting down...");
                Stop();
                DashCMD.Stop();
            });

            DashCMD.AddScreen(new DashCMDScreen("dt", "", true,
                                                (screen) =>
            {
                screen.WriteLine("DeltaTime: {0}s", lastDeltaTime);
            })
            {
                SleepTime = 30
            });

            DashCMD.AddScreen(new DashCMDScreen("network", "", true,
                                                (screen) =>
            {
                screen.WriteLine("General Stats:", ConsoleColor.Green);
                screen.WriteLine("Heartbeat Compution Time: {0}ms", AOSServer.Instance.HeartbeatComputionTimeMS);

                int totalPhysicalPS = 0;
                int totalVirtualPS  = 0;

                foreach (NetConnection client in server.Connections.Values)
                {
                    totalPhysicalPS += client.Stats.PhysicalPacketsReceivedPerSecond;
                    totalVirtualPS  += client.Stats.PacketsReceivedPerSecond;
                }

                screen.WriteLine("Total PPackets r/s: {0}", totalPhysicalPS);
                screen.WriteLine("Total VPackets r/s: {0}", totalVirtualPS);

                screen.WriteLine("");
                foreach (NetConnection client in server.Connections.Values)
                {
                    screen.WriteLine("[{0}]:", ConsoleColor.Green, client);
                    screen.WriteLine("Send Rate: {0}", client.PacketSendRate);
                    screen.WriteLine("MTU: {0}", client.Stats.MTU);
                    screen.WriteLine("Ping: {0}", client.Stats.Ping);
                    screen.WriteLine("VPackets s/s: {0}", client.Stats.PacketsSentPerSecond);
                    screen.WriteLine("VPackets r/s: {0}", client.Stats.PacketsReceivedPerSecond);
                    screen.WriteLine("Packets Lost: {0}", client.Stats.PacketsLost);
                    screen.WriteLine("PPackets s/s: {0}", client.Stats.PhysicalPacketsSentPerSecond);
                    screen.WriteLine("PPackets r/s: {0}", client.Stats.PhysicalPacketsReceivedPerSecond);
                }
            }));
        }