Esempio n. 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("");
            });
        }
Esempio n. 2
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.");
                    }
                }
            });
        }
 static AssetManager()
 {
     DashCMD.AddCommand("unusedfonts", "Locates any unused fonts",
                        (args) =>
     {
         string[] files = Directory.GetFiles(GLoader.GetContentRelativePath("Fonts"));
         foreach (string file in files)
         {
             if (file.EndsWith(".fnt"))
             {
                 if (!fonts.ContainsKey(file))
                 {
                     DashCMD.WriteStandard("[unusedfonts] {0}", Path.GetFileNameWithoutExtension(file));
                 }
             }
         }
     });
 }
        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));
                }
            });
        }
Esempio n. 5
0
        protected override void Load()
        {
            base.Load();
            LogOpenGLDrivers();

            //if (AL.Efx == null)
            //    throw new Exception("Sound card does not support OpenAL Efx!");

            AL.DistanceModel(ALDistanceModel.LinearDistance);

            // 1 meter = 1 block
            Camera.Active.AudioListener.EfxMetersPerUnit = 1f / Block.CUBE_SIZE;

            LoadFromConfig();

            DashCMD.SetCVar("r_vsync", GetVSync());
            DashCMD.SetCVar("r_targfps", TargetFrameRate);
            DashCMD.SetCVar("r_exp_shadows", false);

            GLError.Begin();
            Renderer.AddRenderer(new VoxelRenderer(Renderer));
            Renderer.AddRenderer(new EntityRenderer(Renderer));
            Renderer.AddRenderer(new ChunkRenderer(Renderer));
            Renderer.AddRenderer(new DebugRenderer(Renderer));

            Light sun = new Light(new Vector3(2, 1, 2), LightType.Directional, 1.75f, new Color(255, 255, 255, 255));

            Renderer.Lights.Add(sun);
            Renderer.Sun = sun;

            Camera.Active.SetMode(CameraMode.ArcBall);
            Camera.Active.SmoothCamera = true;

            StaticGui = new StaticGui(this, Renderer);

            SetupDefaultBinds();

            AddScreen(new MainMenuScreen(this));
            AddScreen(new SingleplayerScreen(this));
            AddScreen(new MultiplayerScreen(this));
            AddScreen(new NewText.NewTextScreen(this));

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

#if DEBUG
            DashCMD.AddCommand("connect",
                               "Connects to a server",
                               "connect <ip:port>",
                               (args) =>
            {
                if (args.Length < 1)
                {
                    DashCMD.ShowSyntax("connect");
                    return;
                }

                string[] parts = args[0].Split(':');
                if (parts.Length != 2)
                {
                    DashCMD.WriteError("Invalid arguments. (connect ip:port)");
                    return;
                }

                IPAddress ip;
                if (!NetHelper.TryParseIP(parts[0], out ip))
                {
                    DashCMD.WriteError("Invalid ip address");
                    return;
                }

                int port;
                if (!int.TryParse(parts[1], out port))
                {
                    DashCMD.WriteError("Invalid port.");
                    return;
                }

                SwitchScreen("Multiplayer", new IPEndPoint(ip, port), "TestPlayer1");
            });
#endif
            SwitchScreen("MainMenu");
        }
        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);
                }
            }));
        }