Esempio n. 1
0
        static void Main(string[] args)
        {
            DashCMD.Start();
            DashCMD.Title = "Ace Of Spades Server";
            DashCMD.WriteLine("Game Version: {0}", ConsoleColor.Magenta, GameVersion.Current);

            SimulatedGame game = null;

            ProgramExceptionHandler.RunMainWithHandler(
                () => // tryAction
            {
                LoadServerConfig();

                game = new ServerGame();
                game.Start("AOSServer Game Thread");

                DashCMD.Listen(false);
            },
                () => // finallAyction
            {
                DashCMD.Stop();
            },
                () => // shutdownAction
            {
                if (game.IsRunning)
                {
                    game.Stop();
                }

                Console.WriteLine("Press any key to exit...");
                Console.ReadKey();
            });
        }
Esempio n. 2
0
        private void CharacterController_OnCollision(object sender, PhysicsBodyComponent e)
        {
            if (this.intel == null)
            {
                Intel intel = e.GameObject as Intel;

                if (intel != null)
                {
                    if (intel.RequestOwnership(this))
                    {
                        DashCMD.WriteLine("[SPPlayer] Picked up the intel", ConsoleColor.Green);
                        this.intel          = intel;
                        intel.IsIconVisible = false;
                    }
                }
            }

            CommandPost commandPost = e.GameObject as CommandPost;

            if (commandPost != null)
            {
                if (commandPost.Team == Team)
                {
                    Refresh();

                    if (intel != null)
                    {
                        intel.Return();
                        intel.IsIconVisible = true;
                        intel = null;
                    }
                }
            }
        }
        public MasterRenderer(int screenWidth, int screenHeight, GraphicsOptions options = null)
        {
            Instance    = this;
            GFXSettings = options ?? new GraphicsOptions();

            ScreenWidth  = screenWidth;
            ScreenHeight = screenHeight;

            if (GLVersion == 0)
            {
                int major = GL.GetInteger(GetPName.MajorVersion);
                int minor = GL.GetInteger(GetPName.MinorVersion);
                GLVersion = major + minor * 0.1f;

                //if (major < 4)
                //    throw new Exception(string.Format("OpenGL 4.0 or later is required to run this game. This machine is running: {0}", GLVersion));
                if (major < 4)
                {
                    DashCMD.WriteWarning("[OpenGL] OpenGL 4.0 or later is required to run this game properly!. This machine is running: {0}", GLVersion);
                }
                else
                {
                    DashCMD.WriteLine("[OpenGL] Version: {0}", ConsoleColor.DarkGray, GLVersion);
                }
            }

            GLError.Begin();

            Camera camera = new Camera(this);

            camera.MakeActive();

            Lights = new LightList();

            Texture.Blank = GLoader.LoadBlankTexture(Color.White);

            Renderer3Ds = new Dictionary <Type, Renderer3D>();
            Renderer2Ds = new Dictionary <Type, Renderer2D>();

            Gui     = new GuiRenderer(this);
            Sprites = new SpriteRenderer(this);
            Sky     = new SkyboxRenderer(this);

            AddRenderer(Gui);
            AddRenderer(Sprites);

            activePipeline = new ForwardPipeline(this);

            StateManager.Enable(EnableCap.CullFace);
            StateManager.Enable(EnableCap.DepthTest);

            GL.CullFace(CullFaceMode.Back);

            ErrorCode mInitError = GLError.End();

            if (mInitError != ErrorCode.NoError)
            {
                throw new Exception(string.Format("Uncaught master renderer init opengl error: {0}", mInitError));
            }
        }
 void WriteDebug(string message, params object[] args)
 {
     if (DashCMD.GetCVar <bool>("log_css"))
     {
         DashCMD.WriteLine(message, args);
     }
 }
Esempio n. 5
0
        protected override void Resized(int width, int height)
        {
            DashCMD.WriteLine("Resized({0},{1})", width, height);

            if (activeScreen != null)
            {
                activeScreen.OnScreenResized(width, height);
            }
        }
Esempio n. 6
0
        public MainWindow(GraphicsOptions options)
            : base("Ace of Spades", 960, 540, true, options)
        {
            GlobalNetwork.IsClient = true;
            screens = new Dictionary <string, GameScreen>();

            DashCMD.Title = "Console: Ace of Spades Client";
            DashCMD.WriteLine("Game Version: {0}", ConsoleColor.Magenta, GameVersion.Current);
        }
Esempio n. 7
0
 public void DropIntel()
 {
     if (Intel != null)
     {
         Intel.Drop(yeet: ClientSnapshot.DropIntel);
         Intel = null;
         DashCMD.WriteLine("[ServerMPPlayer] Intel has been dropped!", ConsoleColor.Green);
     }
 }
Esempio n. 8
0
 void DropIntel()
 {
     if (intel != null)
     {
         intel.Drop(yeet: true);
         intel.IsIconVisible = true;
         intel = null;
         DashCMD.WriteLine("[SPPlayer] Dropped the intel", ConsoleColor.Green);
     }
 }
Esempio n. 9
0
 private void CharacterController_OnCollision(object sender, PhysicsBodyComponent e)
 {
     if (Intel == null)
     {
         if (e.GameObject is Intel intel)
         {
             if (intel.RequestOwnership(this))
             {
                 DashCMD.WriteLine("[ServerMPPlayer] Intel has been picked up!", ConsoleColor.Green);
                 Intel = intel;
             }
         }
     }
 }
Esempio n. 10
0
 void Start()
 {
     if (With.Stats.MTU > 0)
     {
         // If we are late and the MTU is already set,
         // don't hook into mtu event
         InitiateTerrainTransfer();
     }
     else
     {
         DashCMD.WriteLine("[HS] Awaiting MTU for {0}...", With);
         With.OnMTUSet += With_OnMTUSet;
     }
 }
        void R_RemoveNetPlayer(NetConnection server, NetBuffer data, ushort numArgs)
        {
            ushort        playerId = data.ReadUInt16();
            NetworkPlayer netPlayer;

            if (netPlayers.TryGetValue(playerId, out netPlayer))
            {
                snapshotComponent.WorldSnapshot.NetworkPlayerListSnapshot.RemoveNetPlayer(netPlayer);
                netPlayers.Remove(playerId);
                DashCMD.WriteLine("[NPM] Removed NetPlayer[{0}]", playerId);

                if (OnNetPlayerRemoved != null)
                {
                    OnNetPlayerRemoved(this, netPlayer);
                }
            }
        }
Esempio n. 12
0
        void InitializeCMD()
        {
            if (DashCMD.IsCommandDefined("time"))
            {
                return;
            }

            DashCMD.SetCVar <float>("time_autoshift", 0);

            //DashCMD.AddCommand("saveworld", "Saves the current world to file", "saveworld <filename>",
            //    (args) =>
            //    {
            //        if (args.Length != 1)
            //            DashCMD.ShowSyntax("saveworld");
            //        else
            //        {
            //            string fileName = args[0];
            //            WorldIO.Save(fileName, new WorldDescription(Terrain));
            //            DashCMD.WriteImportant("Saved world: {0}.aosw", fileName);
            //        }
            //    });

            DashCMD.AddCommand("time", "Changes the time of day", "time [0-24]",
                               (args) =>
            {
                if (args.Length == 0)
                {
                    DashCMD.WriteLine("Current Time: {0}", timeOfDay);
                }
                else
                {
                    try
                    {
                        float newTime = float.Parse(args[0]);
                        newTime       = MathHelper.Clamp(newTime, 0, 24);

                        timeOfDay = newTime;
                    }
                    catch (Exception)
                    {
                        DashCMD.WriteError("Invalid time.");
                    }
                }
            });
        }
        void R_AddNetPlayer(NetConnection server, NetBuffer data, ushort numArgs)
        {
            ushort playerId   = data.ReadUInt16();
            string playerName = data.ReadString();

            DashCMD.WriteLine("[NPM] Got NetPlayer[{1}] '{0}'", playerName, playerId);

            NetworkPlayer netPlayer = new NetworkPlayer(playerName, playerId);

            netPlayers.Add(playerId, netPlayer);

            snapshotComponent.WorldSnapshot.NetworkPlayerListSnapshot.AddNetPlayer(netPlayer, false);

            if (OnNetPlayerAdded != null)
            {
                OnNetPlayerAdded(this, netPlayer);
            }
        }
        static void NetLogger_MessageLogged(NetLog log)
        {
            switch (log.Type)
            {
            case NetLogType.Error:
                DashCMD.WriteError(log.Message); break;

            case NetLogType.Warning:
                DashCMD.WriteWarning(log.Message); break;

            case NetLogType.Important:
                DashCMD.WriteLine(log.Message, ConsoleColor.Green); break;

            case NetLogType.Verbose:
                DashCMD.WriteLine(log.Message, ConsoleColor.DarkGray); break;

            default:
                DashCMD.WriteStandard(log.Message); break;
            }
        }
        void R_AddInitialNetPlayers(NetConnection server, NetBuffer data, ushort numArgs)
        {
            OurNetPlayerId = data.ReadUInt16();
            ushort numPlayers = data.ReadUInt16();

            for (int i = 0; i < numPlayers; i++)
            {
                ushort playerId   = data.ReadUInt16();
                string playerName = data.ReadString();
                Team   team       = (Team)data.ReadByte();
                ushort?charId     = null;
                if (data.ReadBool()) // Only read charId if the player has a character
                {
                    charId = data.ReadUInt16();
                }

                DashCMD.WriteLine("[NPM] Got NetPlayer[{1}] '{0}' on team {2}", playerName, playerId, team);

                NetworkPlayer player = new NetworkPlayer(playerName, playerId);
                player.Team        = team;
                player.CharacterId = charId;

                if (!netPlayers.ContainsKey(playerId))
                {
                    snapshotComponent.WorldSnapshot.NetworkPlayerListSnapshot.AddNetPlayer(player, false);
                    netPlayers.Add(playerId, player);
                }
                else
                {
                    DashCMD.WriteError("[NPM] Got NetPlayer[{1}] '{0}', but we already added this player!",
                                       playerName, playerId);
                }
            }

            if (OnNetPlayersInitialized != null)
            {
                OnNetPlayersInitialized(this, EventArgs.Empty);
            }
        }
Esempio n. 16
0
        public override PlayerRaycastResult RaycastPlayers(Ray ray, float maxDist = float.MaxValue, params Player[] ignore)
        {
            bool sv_impacts  = DashCMD.GetCVar <bool>("sv_impacts");
            bool sv_hitboxes = DashCMD.GetCVar <bool>("sv_hitboxes");

            ServerMPPlayer hitPlayer   = null;
            float?         hitPlayerAt = null;

            foreach (ServerMPPlayer otherPlayer in players.Values)
            {
                // Make sure we aren't ignoring this player
                if (ignore.Length == 0 || !Array.Exists(ignore, (x => x == otherPlayer)))
                {
                    Vector3 otherPlayerPosition;
                    float   otherPlayerCamYaw;
                    if (rollbackTime.HasValue)
                    {
                        // We are applying rollback, so find the players old transform
                        int otherPlayerPing = DashCMD.GetCVar <bool>("rp_usetargetping") ? otherPlayer.StateInfo.Owner.Stats.Ping : 0;
                        int rollbackFrame   = MathHelper.Clamp(otherPlayerPing + rollbackTime.Value, 0, 1000);

                        if (sv_hitboxes)
                        {
                            DashCMD.WriteLine("[RB] Rolling back bullet-player transform by {0}ms [target ping: {1}ms]",
                                              ConsoleColor.Green, rollbackTime, otherPlayerPing);
                        }

                        PlayerTransform otherPlayerTransform = otherPlayer.RollbackTransform(Environment.TickCount - rollbackFrame);
                        otherPlayerPosition = otherPlayerTransform.Position;
                        otherPlayerCamYaw   = otherPlayerTransform.CameraYaw;
                    }
                    else
                    {
                        // No rollback currently, use current transform
                        otherPlayerPosition = otherPlayer.Transform.Position;
                        otherPlayerCamYaw   = otherPlayer.GetCamera().Yaw;
                    }

                    if (sv_hitboxes)
                    {
                        channel.FireEventForAllConnections("Client_RolledBackServerPlayer",
                                                           otherPlayerPosition.X, otherPlayerPosition.Y,
                                                           otherPlayerPosition.Z, (byte)otherPlayer.Team);
                    }

                    Ray newRay = new Ray(ray.Origin - otherPlayerPosition, ray.Direction);

                    float?dist;
                    // Check for intersection
                    if (newRay.Intersects(otherPlayer.GetOrientatedBoundingBox(otherPlayerCamYaw), out dist))
                    {
                        // If the distance is out of bounds, ignore
                        if (dist.Value > maxDist)
                        {
                            continue;
                        }

                        // Only update the intersected player if it was closer than the last
                        if (!hitPlayerAt.HasValue || dist.Value < hitPlayerAt.Value)
                        {
                            hitPlayer   = otherPlayer;
                            hitPlayerAt = dist.Value;
                        }
                    }
                }
            }

            if (hitPlayer != null)
            {
                return(new PlayerRaycastResult(ray, true, ray.Origin + ray.Direction * hitPlayerAt.Value, hitPlayerAt, hitPlayer));
            }
            else
            {
                return(new PlayerRaycastResult(ray));
            }
        }
Esempio n. 17
0
        public override void FireBullet(Player _player, Vector3 origin, Vector3 dir, Vector3 recoil,
                                        int blockDamage, float playerDamage, float maxDist = float.MaxValue)
        {
            ServerMPPlayer player = (ServerMPPlayer)_player;

            bool sv_impacts  = DashCMD.GetCVar <bool>("sv_impacts");
            bool sv_hitboxes = DashCMD.GetCVar <bool>("sv_hitboxes");

            int shooterPing    = player.StateInfo.Owner.Stats.Ping;
            int rollbackOffset = DashCMD.GetCVar <int>("rp_rollback_offset");
            int bulletDelta    = player.LastBulletDeltaTime;

            if (sv_hitboxes)
            {
                DashCMD.WriteLine("[RB] Starting bullet {0}ms delta with {1}ms offset",
                                  ConsoleColor.Green, bulletDelta, rollbackOffset);
            }

            // Raycast
            BeginRollback(shooterPing + bulletDelta + rollbackOffset);
            Ray ray = new Ray(origin, dir + recoil);
            WorldRaycastResult result = Raycast(ray, true, maxDist, player);

            EndRollback();

            // Handle intersection
            if (result.Intersects)
            {
                if (result.HitTerrain)
                {
                    // Damage terrain
                    TerrainRaycastResult tResult = result.TerrainResult;

                    if (blockDamage > 0)
                    {
                        tResult.Chunk.DamageBlock(tResult.BlockIndex.Value, blockDamage);
                    }
                }
                else if (result.HitPlayer)
                {
                    // Damage player
                    PlayerRaycastResult pResult = result.PlayerResult;

                    bool ff   = DashCMD.GetCVar <bool>("mp_friendlyfire");
                    bool infh = DashCMD.GetCVar <bool>("ch_infhealth");

                    if (!infh && (ff || player.Team != pResult.Player.Team))
                    {
                        DamagePlayer(player, player.ItemManager.SelectedItem.GetType().Name, (ServerMPPlayer)pResult.Player,
                                     playerDamage, origin);

                        if (sv_impacts)
                        {
                            DashCMD.WriteLine("[IMP] Hit player for {0} damage. Health After: {1}", playerDamage, pResult.Player.Health);
                        }
                    }
                }

                ImpactAt(result.IntersectionPosition.Value);
            }
        }
        private void World_OnPlayerKilled(PlayerDamage damageEvent)
        {
            ServerMPPlayer killer    = (ServerMPPlayer)damageEvent.Attacker;
            ServerMPPlayer assistant = (ServerMPPlayer)damageEvent.AttackerAssistant;
            ServerMPPlayer killed    = (ServerMPPlayer)damageEvent.Attacked;
            string         item      = damageEvent.Cause;

            if (killer == killed)
            {
                // Kill was actually suicide
                killer = null;
            }

            // Killer only gets credit within 6.5s of players death
            if (Environment.TickCount - damageEvent.DamagedAt >= 6500)
            {
                killer = null;
            }
            // Assistant only gets credit within 8s of players death
            if (Environment.TickCount - damageEvent.AttackerAssistedAt >= 8000)
            {
                assistant = null;
            }

            // Get network players
            string        leftName = "", rightName = "", assistantName = "";
            NetworkPlayer killerNetPlayer = null, killedNetPlayer = null, assistantNetPlayer = null;

            if (killer != null && netPlayerComponent.TryGetPlayer(killer.StateInfo.Owner, out killerNetPlayer))
            {
                leftName = killerNetPlayer.Name;
            }
            if (killed != null && netPlayerComponent.TryGetPlayer(killed.StateInfo.Owner, out killedNetPlayer))
            {
                rightName = killedNetPlayer.Name;
            }
            if (assistant != null && netPlayerComponent.TryGetPlayer(assistant.StateInfo.Owner, out assistantNetPlayer))
            {
                assistantName = assistantNetPlayer.Name;
            }

            // Announce feed item
            AddFeedItem(
                leftName, assistantName,
                killer != null ? World.GetTeamColor(killer.Team) : Color.White,
                item,
                rightName, killed != null ? World.GetTeamColor(killed.Team) : Color.White);

            // Notify gamemode
            currentGamemode.OnPlayerKilled(killer, killerNetPlayer, assistant, assistantNetPlayer, killed, killedNetPlayer, item);

            // Debug
            if (killer != null)
            {
                if (assistant != null)
                {
                    DashCMD.WriteLine("[MatchScreen] '{0} + {1} [ {2} ] {3}'", leftName, assistantName, item, rightName);
                }
                else
                {
                    DashCMD.WriteLine("[MatchScreen] '{0} [ {1} ] {2}'", leftName, item, rightName);
                }
            }
            else
            {
                DashCMD.WriteLine("[MatchScreen] '[ {0} ] {1}'", item, rightName);
            }
        }
Esempio n. 19
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);
                }
            }));
        }