static void Main(string[] args) { LoadConfig(); if (GetConfigString("Debug/console") == "true") { DashCMD.Start(true); DashCMD.Listen(true); DashCMD.WriteStandard("Loaded config '{0}'", ConfigFile.Name); } ProgramExceptionHandler.RunMainWithHandler(tryAction: () => { ConfigSection gfx = GetConfigSection("Graphics"); if (gfx == null) { DashCMD.WriteError("[game.cfg] Graphics section was not found!"); } GraphicsOptions options = gfx != null ? GraphicsOptions.Init(gfx) : null; using (MainWindow window = new MainWindow(options)) window.Run(60); }, finallyAction: DashCMD.Stop, shutdownAction: () => { }); }
void R_SwitchGamemode(NetConnection server, NetBuffer data, ushort numArgs) { DashCMD.WriteStandard("Switching gamemode..."); GamemodeType type = (GamemodeType)data.ReadByte(); if (currentGamemode != null) { currentGamemode.Stop(); } currentGamemode = null; hud.SetGamemode(null); NetworkedGamemode gamemode; if (gamemodes.TryGetValue(type, out gamemode)) { currentGamemode = gamemode; currentGamemode.Start(); hud.SetGamemode(gamemode); leaderboard.SetGamemode(gamemode); objectComponent.HoldInstantiationPackets = false; } else { string message = string.Format("Failed to switch to gamemode '{0}'!", type); DashCMD.WriteError("[MultiplayerScreen] {0}", message); client.Disconnect("Critical client-side error"); Window.SwitchScreen("MainMenu", message); } }
void WriteDebug(string msg, params object[] args) { if (DashCMD.GetCVar <bool>("log_snapshots")) { DashCMD.WriteStandard(msg, args); } }
void InitiateTerrainTransfer() { DashCMD.WriteStandard("[HS] Initiating handshake with {0}...", With); NetOutboundPacket initPacket = new NetOutboundPacket(NetDeliveryMethod.ReliableOrdered); initPacket.Write((byte)CustomPacketType.HandshakeInitiate); int packetSize = With.Stats.MTU; ThreadPool.QueueUserWorkItem((obj) => { terrainData = new HandshakeTerrainData(world.Terrain, packetSize); initPacket.Write((ushort)terrainData.Sections.Length); initPacket.Write(terrainData.TotalPacketSize); initPacket.Write(terrainData.UncompressedSize); DashCMD.WriteStandard( "[HS] Prepared terrain packet for {0}. Sections: {1} ({2} bytes max each), Total Size: {3} bytes", With, terrainData.Sections.Length, packetSize, terrainData.TotalPacketSize); With.SendPacket(initPacket); SendNextTerrainChunk(); }); }
public static GraphicsOptions Init(ConfigSection graphicsSection) { ConfigSection presets = graphicsSection.GetSection("Presets"); if (presets == null) { DashCMD.WriteError("[game.cfg - GraphicsOptions] Graphics.Presets was not found!"); return(null); } string usedPreset = graphicsSection.GetString("preset"); if (usedPreset == null) { DashCMD.WriteError("[game.cfg - GraphicsOptions] Graphics.preset was not found!"); return(null); } foreach (DictionaryEntry pair in presets.Children) { ConfigSection preset = pair.Value as ConfigSection; if (preset == null) { DashCMD.WriteWarning("[game.cfg - GraphicsOptions] Invalid token '{0}' in Graphics.Presets", pair.Key); continue; } bool fxaa = preset.GetBoolean("fxaa") ?? false; bool shadows = preset.GetBoolean("shadows") ?? false; int shadowRes = preset.GetInteger("shadowRes") ?? 1; int pcfSamples = preset.GetInteger("shadowPCF") ?? 1; FogQuality fogQuality = preset.GetEnum <FogQuality>("fogQuality") ?? FogQuality.Low; GraphicsOptions options = new GraphicsOptions() { ApplyFXAA = fxaa, RenderShadows = shadows, ShadowResolution = shadowRes, ShadowPCFSamples = pcfSamples, FogQuality = fogQuality }; allOptions.Add((string)pair.Key, options); } GraphicsOptions usedOptions; if (allOptions.TryGetValue(usedPreset, out usedOptions)) { DashCMD.WriteStandard("[game.cfg - GraphicsOptions] Using preset '{0}'", usedPreset); return(usedOptions); } else { DashCMD.WriteError("[game.cfg - GraphicsOptions] Specified preset '{0}' was not found!", usedPreset); return(null); } }
public virtual void OnNetworkInstantiated(NetCreatableInfo stateInfo) { StateInfo = stateInfo; if (DashCMD.GetCVar <bool>("log_mpplayer")) { DashCMD.WriteStandard("[MPPlayer - {1}] Instantiated with id {0}", stateInfo.Id, stateInfo.IsAppOwner ? "Ours" : "Not Ours"); } }
public virtual void OnNetworkDestroy() { if (DashCMD.GetCVar <bool>("log_mpplayer")) { DashCMD.WriteStandard("[MPPlayer - {1}] Destroyed with id {0}", StateInfo.Id, StateInfo.IsAppOwner ? "Ours" : "Not Ours"); } Dispose(); }
public void SendClientInfo(string playerName) { DashCMD.WriteStandard("[NPM] Sending client info..."); NetBuffer data = new NetBuffer(); data.Write(playerName); GameVersion.Current.Serialize(data); channel.FireEvent("Server_ClientInfo", client.ServerConnection, RemoteFlag.None, NetDeliveryMethod.ReliableOrdered, data); }
public void Complete() { DashCMD.WriteStandard("[HS] Completed handshake with {0}.", client.ServerConnection); NetOutboundPacket completePacket = new NetOutboundPacket(NetDeliveryMethod.ReliableOrdered); completePacket.Write((byte)CustomPacketType.HandshakeComplete); client.SendPacket(completePacket); screen.OnHandshakeComplete(); }
void Start(NetInboundPacket packet) { DashCMD.WriteStandard("[HS] Started handshake with {0}...", client.ServerConnection); ushort numTerrainSections = packet.ReadUInt16(); terrainDataFullSize = packet.ReadInt32(); terrainUncompressedSize = packet.ReadInt32(); terrainData = new byte[numTerrainSections][]; DashCMD.WriteStandard("[HS] Awaiting {0} terrain data sections...", numTerrainSections); }
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); }
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(""); }); }
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)); } } } }); }
/// <summary> /// Loads a shader from a file. /// <para>At this stage, there is no auto-cleanup for this shader. /// Auto-Cleanup takes place once this is loaded to a ShaderProgram.</para> /// </summary> public static GLShader LoadShader(string path, ShaderType type) { GLShader shader; string fileName = Path.GetFileName(path); // If shader is not found, load and compile it if (!GManager.TryGetShader(fileName, out shader)) { path = Path.Combine(RootDirectory, "Shaders/", path); // Allocate the shader Id shader = GManager.CreateShader(fileName, type); uint shaderId = shader.Id; // Load the shader from the file string shaderCode = LoadFileToString(path); // Load the shader's sourcecode to the GL shader GL.ShaderSource(shaderId, shaderCode); // Compile the shader for the GPU GL.CompileShader(shaderId); // Check the compilation status int status = GL.GetShader(shaderId, ShaderParameter.CompileStatus); string log = GL.GetShaderInfoLog(shaderId); // Log if (status == 0) { throw new GLoaderException(String.Format("Failed to compile {0}. Reason: {1}", Path.GetFileName(path), log)); } else if (LogShaderCompilation) { if (string.IsNullOrWhiteSpace(log)) { DashCMD.WriteStandard("Compiled {0} with id {1}.", Path.GetFileName(path), shaderId); } else { DashCMD.WriteStandard("Compiled {0} with id {1}. Status: {2}", Path.GetFileName(path), shaderId, log); } } } return(shader); }
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; } }
public void OnLevelChunkInbound(NetInboundPacket packet) { ushort dataLength = packet.ReadUInt16(); terrainData[terrainDataI] = packet.ReadBytes(dataLength); terrainDataRead += dataLength; if (OnTerrainProgressReported != null) { OnTerrainProgressReported(terrainDataRead, terrainDataFullSize); } DashCMD.WriteStandard("[HS] Received terrain data {0}/{1} bytes", terrainDataRead, terrainDataFullSize); terrainDataI++; if (terrainDataI < terrainData.Length) { // Send terrain ack to ask for next part NetOutboundPacket ack = new NetOutboundPacket(NetDeliveryMethod.ReliableOrdered); ack.Write((byte)CustomPacketType.WorldSectionAck); client.SendPacket(ack); } else { if (OnTerrainProgressReported != null) { OnTerrainProgressReported(terrainDataFullSize, terrainDataFullSize); } // Uncompress the data and notify the screen we are done downloading. HandshakeTerrainData data = new HandshakeTerrainData(terrainData, terrainUncompressedSize); screen.OnHandshakeDoneDownloading(data); } }
public void HandshakeCompleted(Handshake h) { DashCMD.WriteStandard("[HS] Completed handshake with {0}.", h.With); handshakes.Remove(h.With); screen.OnHandshakeComplete(h); }
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)); } }); }
public void LoadServerTerrain(NetBuffer data) { SetTerrain(new FixedTerrain(Renderer)); DashCMD.WriteStandard("[MPWorld] Loading server world..."); ushort numChunks = data.ReadUInt16(); Chunk currentChunk = null; int blockI = 0; int ci = 0; while (ci <= numChunks && data.Position < data.Data.Length) { byte type = data.ReadByte(); if (type == 0) // New Chunk { int ix = data.ReadInt16(); int iy = data.ReadInt16(); int iz = data.ReadInt16(); if (currentChunk != null) { currentChunk.BakeColors(); } IndexPosition ipos = new IndexPosition(ix, iy, iz); currentChunk = new Chunk(Terrain, ipos, AceOfSpades.Terrain.ChunkToWorldCoords(ipos)); currentChunk.InitBlocks(Chunk.HSIZE, Chunk.VSIZE, Chunk.HSIZE); currentChunk.State = ChunkState.Unlit; currentChunk.IsDirty = true; Terrain.Chunks.TryAdd(ipos, currentChunk); blockI = 0; ci++; } else if (type == 1) // Block section { ushort numBlocks = data.ReadUInt16(); byte d = data.ReadByte(); Nybble2 n = new Nybble2(d); byte r, g, b; byte mat = n.Lower; if (mat == Block.CUSTOM.Material) { r = data.ReadByte(); g = data.ReadByte(); b = data.ReadByte(); } else { if (mat == Block.GRASS.Material) { r = Block.GRASS.R; g = Block.GRASS.G; b = Block.GRASS.B; } else { r = Block.STONE.R; g = Block.STONE.G; b = Block.STONE.B; } } Block block = new Block(n, r, g, b); for (int i = 0; i < numBlocks; i++) { int z = blockI % Chunk.HSIZE; int y = (blockI / Chunk.HSIZE) % Chunk.VSIZE; int x = blockI / (Chunk.VSIZE * Chunk.HSIZE); currentChunk.Blocks[z, y, x] = block; blockI++; } } } if (currentChunk != null) { currentChunk.BakeColors(); } Terrain.CreatedFromFile(); }