static void Main(string[] args) { Environment.ExitCode = -69; LoggerFactory.DefaultMethod = (con) => new Log4NetLogger(con.Name); Log = LoggerFactory.Create(nameof(Service)); //This will catch any exceptions that happen after this line AppDomain.CurrentDomain.UnhandledException += CurrentDomainUnhandledException; Signal.OnException += Signal_OnException; AppDomain.CurrentDomain.AssemblyLoad += CurrentDomain_AssemblyLoad; AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve; ApiClient.DefaultUrl = new Uri(AppConfig.Instance.ApiUrl); HostedGames.Init(); var handshaker = new DefaultHandshaker(); var connectionCreator = new TcpConnectionCreator(handshaker); Client = new GameServiceClient(connectionCreator); Client.ReconnectRetryCount = int.MaxValue; //retry forever basically using (_service = new Service()) { _service.Run(args); } ConsoleUtils.TryWaitForKey(); }
private async Task <object> ChatClient_RequestReceived(object sender, RequestReceivedEventArgs args) { if (args.Request.Name == nameof(IClientHostingRPC.HostGame)) { try { var game = HostedGame.GetFromPacket(args.Request); if (game == null) { throw new InvalidOperationException("game is null"); } game.HostUser = args.Request.Origin ?? throw new InvalidOperationException("args.Request.Origin is null"); Log.InfoFormat("Host game from {0}", args.Request.Origin); var endTime = DateTime.Now.AddSeconds(10); while (SasUpdater.Instance.IsUpdating) { await Task.Delay(100); if (endTime > DateTime.Now) { throw new Exception("Couldn't host, sas is updating"); } } var id = await HostedGames.HostGame(game); if (id == Guid.Empty) { throw new InvalidOperationException("id == Guid.Empty"); } game = HostedGames.Get(id); if (game == null) { throw new InvalidOperationException("game from HostedGames is null"); } if (game.HostUser == null) { throw new InvalidOperationException("game.HostUser is null"); } return(game); } catch (Exception ex) { Log.Error($"{nameof(ChatClient_RequestReceived)}", ex); return(new ErrorResponseData(Communication.ErrorResponseCodes.UnhandledServerError, "Problem starting SAS", false)); } } return(null); }
protected override void Dispose(bool disposing) { Log.Info($"{nameof(Dispose)}"); base.Dispose(disposing); Log.Info($"{nameof(Dispose)}: Client"); Client.Dispose(); Log.Info($"{nameof(Dispose)}: HostedGames"); HostedGames.Stop(); Log.Info($"{nameof(Dispose)}: SasUpdater"); SasUpdater.Instance.Dispose(); Log.Info($"{nameof(Dispose)}: Done"); }
protected override void OnStart(string[] args) { try { Log.Info($"{nameof(OnStart)}"); Client.Start().Wait(); Log.Info($"{nameof(OnStart)}: Starting Hosted Games"); HostedGames.Start(); Log.Info($"{nameof(OnStart)}: Starting Sas Updater"); SasUpdater.Instance.Start(); _startTime = DateTime.Now; Log.Info($"{nameof(OnStart)}: Done"); } catch (Exception ex) { Signal.Exception(ex); throw; } }
static void Main(string[] args) { try { LoggerFactory.DefaultMethod = (con) => new Log4NetLogger(con.Name); Signal.OnException += Signal_OnException; ApiClient.DefaultUrl = new Uri(AppConfig.Instance.ApiUrl); AppDomain.CurrentDomain.UnhandledException += CurrentDomainUnhandledException; AppDomain.CurrentDomain.AssemblyLoad += CurrentDomain_AssemblyLoad; AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve; HostedGames.Init(); Client = new GameServiceClient(); using (_service = new Service()) { _service.Run(args); } } catch (Exception e) { Log.Fatal("Fatal Main Error", e); } ConsoleUtils.TryWaitForKey(); }