diff --git a/OpenRA.Server/Server.cs b/OpenRA.Server/Server.cs new file mode 100644 index 0000000000..6abf3054e9 --- /dev/null +++ b/OpenRA.Server/Server.cs @@ -0,0 +1,75 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Net.Sockets; +using System.Threading; +using System.IO; +using System.Net; + +namespace OpenRA.Server +{ + static class Server + { + static void Main(string[] args) + { + var listener = new TcpListener(IPAddress.Any, 1234); + var clients = new List(); + + listener.Start(); + + for (; ; ) + { + try + { + var conn = listener.AcceptTcpClient(); + conn.NoDelay = true; + Console.WriteLine("Accepted connection from {0}", + conn.Client.RemoteEndPoint.ToString()); + + new Thread(() => + { + lock (clients) + clients.Add(conn); + + var ns = conn.GetStream(); + + try + { + for (; ; ) + { + var frame = BitConverter.ToInt32(ns.Read(4), 0); + var length = BitConverter.ToInt32(ns.Read(4), 0); + var data = ns.Read(length); + + lock (clients) + foreach (var c in clients) + if (c != conn) + { + var otherStream = c.GetStream(); + otherStream.Write(BitConverter.GetBytes(frame)); + otherStream.Write(BitConverter.GetBytes(length)); + otherStream.Write(data); + } + } + } + catch (Exception e) + { + Console.WriteLine("Client dropped: {0}", conn.Client.RemoteEndPoint.ToString()); + + lock (clients) + clients.Remove(conn); + } + }) { IsBackground = true }.Start(); + } + catch (Exception e) + { + Console.WriteLine(e.ToString()); + } + } + } + + public static void Write(this Stream s, byte[] data) { s.Write(data, 0, data.Length); } + public static byte[] Read(this Stream s, int len) { var data = new byte[len]; s.Read(data, 0, len); return data; } + } +} diff --git a/OpenRa.Game/Graphics/Sheet.cs b/OpenRa.Game/Graphics/Sheet.cs index cff0e3518c..645a1ffee3 100644 --- a/OpenRa.Game/Graphics/Sheet.cs +++ b/OpenRa.Game/Graphics/Sheet.cs @@ -2,6 +2,7 @@ using System.Drawing; using System.IO; using Ijw.DirectX; using OpenRa.FileFormats; +using System.Drawing.Imaging; namespace OpenRa.Game.Graphics { @@ -27,11 +28,7 @@ namespace OpenRa.Game.Graphics void Resolve() { - string filename = string.Format("../../../sheet-{0}.png", suffix++); - bitmap.Save(filename); - - using (Stream s = File.OpenRead(filename)) - texture = Texture.Create(s, renderer.Device); + texture = Texture.CreateFromBitmap(bitmap, renderer.Device); } public Texture Texture diff --git a/OpenRa.Game/Support/Log.cs b/OpenRa.Game/Support/Log.cs index 96dd48e05a..194ac41f4c 100644 --- a/OpenRa.Game/Support/Log.cs +++ b/OpenRa.Game/Support/Log.cs @@ -7,7 +7,7 @@ namespace OpenRa.Game { static class Log { - static StreamWriter writer = File.CreateText("../../../log.txt"); + static StreamWriter writer = File.CreateText("log.txt"); static Log() {