public Server_(String map, int clientport, bool storeCombatLog) { Log.Init(); MapName = map; this.clientport = clientport; Socket = new Common.Network.UdpServer(clientport); Socket.OnSocketError += new Common.Network.UdpServer.SocketErrorDelegate((e, ep) => { throw new Exception(e.ToString()); }); Socket.OnReceive += new Common.Network.UdpServer.ReceiveDelegate((d, e) => Invoke(() => Socket_OnReceive(d, e))); InitNetworkOut(); Socket.Start(); Log.WriteLine("Client comm inited at port " + clientport); if (storeCombatLog) { combatLog = new StreamWriter("Logs/CombatLog-" + DateTime.Now.ToString("yyyyMMdd-HH.mm") + ".log"); combatLog.AutoFlush = true; } //BinaryFormatter f = new BinaryFormatter(); Common.XmlFormatter f = new Common.XmlFormatter(); FileStream r = new FileStream("Maps/" + MapName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); Map = (Common.Map.Map)f.Deserialize(r); r.Close(); if (File.Exists("Maps/" + MapName + ".terrain")) { BinaryFormatter bf = new BinaryFormatter(); r = new FileStream("Maps/" + MapName + ".terrain", FileMode.Open, FileAccess.Read, FileShare.ReadWrite); Map.Heightmap = (float[,])bf.Deserialize(r); r.Close(); } int nplayers = 0; List<Common.Map.Team> slotToTeam = new List<Common.Map.Team>(); for (int i = 0; i < Map.Teams.Length; i++) { nplayers += Map.Teams[i].NumberOfPlayers; for (int x = 0; x < Map.Teams[i].NumberOfPlayers; x++) slotToTeam.Add(Map.Teams[i]); } Players = new Player[nplayers]; SlotToTeam = slotToTeam.ToArray(); Log.WriteLine(); state = new States.Lobby(this); state.Enter(); updateTimer = new Timer(new TimerCallback(Update)); updateTimer.Change(updatePeriod, 0); lastUpdate = DateTime.Now; Log.WriteLine("Server started!"); GameStats = new Common.GameStats(); }
public void Shutdown() { shuttingDown = true; if(combatLog != null) combatLog.Close(); Log.Close(); Common.Network.UdpServer temp = Socket; Socket = null; temp.Close(); /*System.Drawing.Bitmap b = new System.Drawing.Bitmap(800, (int)(800 * Config.worldwidth / Config.worldheight)); for(int x=0; x < b.Width; x++) for(int y=0; y < b.Height; y++) b.SetPixel(x, y, System.Drawing.Color.Black); ObjectsManager.Dump(b); b.Save("world.png", System.Drawing.Imaging.ImageFormat.Png);*/ }