protected override void Load() { //Move to stop _TSGetMainThread error on OSX MinimumWindowSize = new Point(640, 480); SetVSync(Config.VSync); new IdentityCamera(this); uithread = Thread.CurrentThread.ManagedThreadId; useintromovies = _cfg.IntroMovies; FLLog.Info("Platform", Platform.RunningOS.ToString() + (IntPtr.Size == 4 ? " 32-bit" : " 64-bit")); FLLog.Info("Available Threads", Environment.ProcessorCount.ToString()); //Cache ResourceManager = new ResourceManager(this); //Init Audio FLLog.Info("Audio", "Initialising Audio"); Audio = new AudioManager(this); if (_cfg.MuteMusic) { Audio.Music.Volume = 0f; } //Load data FLLog.Info("Game", "Loading game data"); GameData = new LegacyGameData(_cfg.FreelancerPath, ResourceManager); IntroMovies = GameData.GetIntroMovies(); MpvOverride = _cfg.MpvOverride; Thread GameDataLoaderThread = new Thread(() => { GameData.LoadData(); Sound = new SoundManager(GameData, Audio); FLLog.Info("Game", "Finished loading game data"); InitialLoadComplete = true; }); GameDataLoaderThread.Name = "GamedataLoader"; GameDataLoaderThread.Start(); // Renderer2D = new Renderer2D(RenderState); Fonts = new FontManager(this); Billboards = new Billboards(); Nebulae = new NebulaVertices(); var vp = new ViewportManager(RenderState); vp.Push(0, 0, Width, Height); Screenshots = new ScreenshotManager(this); if (useintromovies && IntroMovies.Count > 0) { ChangeState(new IntroMovie(this, 0)); } else { ChangeState(new LoadingDataState(this)); } }
void NetThread() { FLLog.Info("Server", "Loading Game Data..."); GameData.LoadData(); FLLog.Info("Server", "Finished Loading Game Data"); Database = new ServerDatabase(DbConnectionString, GameData); var netconf = new NetPeerConfiguration(AppIdentifier); netconf.EnableMessageType(NetIncomingMessageType.DiscoveryRequest); netconf.EnableMessageType(NetIncomingMessageType.ConnectionApproval); netconf.Port = Port; netconf.MaximumConnections = 200; NetServer = new NetServer(netconf); NetServer.Start(); FLLog.Info("Server", "Listening on port " + Port); NetIncomingMessage im; while (running) { while ((im = NetServer.ReadMessage()) != null) { switch (im.MessageType) { case NetIncomingMessageType.DebugMessage: case NetIncomingMessageType.ErrorMessage: case NetIncomingMessageType.WarningMessage: case NetIncomingMessageType.VerboseDebugMessage: FLLog.Info("Lidgren", im.ReadString()); NetServer.Recycle(im); break; case NetIncomingMessageType.ConnectionApproval: //Ban IP? im.SenderConnection.Approve(); NetServer.Recycle(im); break; case NetIncomingMessageType.DiscoveryRequest: NetOutgoingMessage dresp = NetServer.CreateMessage(); //Include Server Data dresp.Write(ServerName); dresp.Write(ServerDescription); dresp.Write(NetServer.ConnectionsCount); dresp.Write(NetServer.Configuration.MaximumConnections); //Send off NetServer.SendDiscoveryResponse(dresp, im.SenderEndPoint); NetServer.Recycle(im); break; case NetIncomingMessageType.StatusChanged: NetConnectionStatus status = (NetConnectionStatus)im.ReadByte(); string reason = im.ReadString(); FLLog.Info("Lidgren", NetUtility.ToHexString(im.SenderConnection.RemoteUniqueIdentifier) + " " + status + ": " + reason); if (status == NetConnectionStatus.Connected) { FLLog.Info("Lidgren", "Remote hail: " + im.SenderConnection.RemoteHailMessage.ReadString()); BeginAuthentication(NetServer, im.SenderConnection); } NetServer.Recycle(im); break; case NetIncomingMessageType.Data: var kind = (PacketKind)im.ReadByte(); if (im.SenderConnection.Tag == TagConnecting) { if (kind == PacketKind.Authentication) { var authkind = (AuthenticationKind)im.ReadByte(); var guid = new Guid(im.ReadBytes(16)); if (guid == Guid.Empty) { im.SenderConnection.Disconnect("Invalid UUID"); } FLLog.Info("Lidgren", "GUID for " + im.SenderEndPoint + " = " + guid.ToString()); var p = new NetPlayer(im.SenderConnection, this, guid); im.SenderConnection.Tag = p; AsyncManager.RunTask(() => p.DoAuthSuccess()); } else { im.SenderConnection.Disconnect("Invalid Packet"); } } else { var player = (NetPlayer)im.SenderConnection.Tag; AsyncManager.RunTask(() => player.ProcessPacket(im, kind)); } break; } } Thread.Sleep(1); //Reduce CPU load } Database.Dispose(); }