protected void Application_Error(object src, EventArgs e) { Log.log("Application Error... "); HttpContext context = HttpContext.Current; Exception exception = Server.GetLastError(); Log.log(" Error: " + exception.Message); try { if (null == exception) { throw new AlnitakException("A excepção recebida em Application_Error é null"); } if (exception is HttpUnhandledException) { ExceptionInfo info = (ExceptionInfo)context.Cache[OrionGlobals.SessionId + "AlnitakException"]; endRequest(info, null); } ExceptionLog.log(exception); Log.log("... Done!"); Log.log("Going transfer..."); context.Server.Transfer(OrionGlobals.resolveBase(OrionGlobals.getConfigurationValue("pagePath", "globalError"))); } catch (System.Threading.ThreadAbortException) { Log.log("$$$$$$$ Thread Abort"); } catch (Exception ex) { Log.log("... Exception: " + ex.Message); ExceptionInfo info = (ExceptionInfo)context.Cache[OrionGlobals.SessionId + "AlnitakException"]; endRequest(info, new ExceptionInfo(ex)); } }
protected override void OnLoad(EventArgs e) { try { ExceptionInfo exceptionInfo = (ExceptionInfo)HttpContext.Current.Cache[OrionGlobals.SessionId + "AlnitakException"]; IPrincipal user = HttpContext.Current.User; if (user != null) { if (user.IsInRole("admin")) { adminContent.Visible = true; if (exceptionInfo != null) { setException(exceptionInfo); } } else { adminContent.Visible = false; } } } catch (Exception exp) { setException(ExceptionLog.log(exp)); } base.OnLoad(e); }
protected override void OnError(EventArgs e) { base.OnError(e); Log.log("Error..."); releaseLock(); Exception exp = Server.GetLastError(); if (exp != null) { if (null != HttpContext.Current.Cache[OrionGlobals.SessionId + "ExceptionNumber"]) { HttpContext.Current.Response.Redirect(OrionGlobals.resolveBase(OrionGlobals.getConfigurationValue("pagePath", "globalError"))); } HttpContext.Current.Cache[OrionGlobals.SessionId + "ExceptionNumber"] = 1; ExceptionLog.log(exp); HttpContext.Current.Response.Redirect(OrionGlobals.resolveBase("orionsbelterror.aspx")); } HttpContext.Current.Cache[OrionGlobals.SessionId + "ExceptionNumber"] = 1; exp = Server.GetLastError(); if (exp == null) { Log.log("\tError: {0}", "null"); return; } else { Log.log("\tError: {0}", exp.ToString()); } ExceptionLog.log(exp); HttpContext.Current.Response.Redirect(OrionGlobals.resolveBase("orionsbelterror.aspx")); }
protected override void OnError(EventArgs e) { base.OnError(e); Exception exception = Server.GetLastError(); ExceptionLog.log(exception); HttpContext.Current.Response.Redirect(OrionGlobals.resolveBase(OrionGlobals.getConfigurationValue("pagePath", "globalError"))); }
/// <summary> /// Preenche um User com os seus dados /// </summary> public override void fillUser( User user ) { NpgsqlConnection conn = new NpgsqlConnection(OrionGlobals.getConnectionString("connectionStringPG")); NpgsqlCommand cmd = new NpgsqlCommand("OrionsBelt_UsersGetUser", conn); cmd.CommandType=CommandType.StoredProcedure; cmd.CommandTimeout = 0; cmd.Parameters.Add("@user_mail",user.Mail); try { conn.Open(); reader = cmd.ExecuteReader(); if( reader.HasRows ) { reader.Read(); user.Nick = (string) getField("user_nick"); user.UserId = (int) getField("user_id"); if ( getField("user_ruler_id") != DBNull.Value ) user.RulerId = (int) getField("user_ruler_id"); user.EloRanking = (int) getField("user_rank"); user.RegistDate = (DateTime) getField("user_registDate"); user.LastLogin = (DateTime) getField("user_lastLogin"); user.Skin = (int) getField("user_skin"); user.Lang = (string) getField("user_lang"); user.ImagesDir = (string) getField("user_imagesDir"); user.Website = (string) getField("user_website"); user.Avatar = (string) getField("user_avatar"); user.Msn = (string) getField("user_msn"); user.Icq = (string) getField("user_icq"); user.Jabber = (string) getField("user_jabber"); user.Aim = (string) getField("user_aim"); user.Yahoo = (string) getField("user_yahoo"); user.AllianceId = (int) reader["user_alliance_id"]; user.AllianceRank = AllianceInfo.ToAllianceRank( reader["user_alliance_rank"].ToString() ); user.Wins = (int) reader["user_wins"]; user.Losses = (int) reader["user_losses"]; }else { ExceptionLog.log("User não encontrado", "Mail: " + user.Mail==null?"null":user.Mail ); } reader = null; } catch( NpgsqlException e ) { throw new AlnitakException("Erro ao executar o procedimento 'OrionsBelt_UsersGetUser' @ NpgsqlServerUserutility::fillUser ",e); } finally { conn.Close(); } }
/// <summary>Mostra o controlo</summary> protected override void Render(HtmlTextWriter writer) { #if WIKI #if DEBUG Check(GetFederation(), "Federation"); #endif if (WikiSearch != null) { WriteSearchResults(writer); return; } string currentTopic = "Orionsbelt.Orionsbelt"; OrionTopic obj = (OrionTopic)Context.Items["WikiTopic"]; if (obj != null) { currentTopic = obj.ToString(); } if (obj != null && !obj.Exists) { writer.WriteLine("Lamentamos, mas o tpico {0} ainda no foi adicionado.", obj.ToString()); ExceptionLog.log("WikiTopic", string.Format("Access detected to WikiTopic '{0}' that does not exist.", obj.ToString())); return; } FlexWiki.AbsoluteTopicName topic = new FlexWiki.AbsoluteTopicName(currentTopic); string display = GetDisplay(topic); OrionGlobals.RegisterRequest(Chronos.Messaging.MessageType.ResearchManagement, string.Format("{0} - {1}", CultureModule.getContent("help"), display)); FlexWiki.Federation fed = GetFederation(); string formattedBody = fed.GetTopicFormattedContent(topic, false); writer.WriteLine("<div id='TopicTip'></div>"); writer.WriteLine("<div id='wiki'>"); WriteLocation(writer, topic, display); CheckPreviewImage(writer, topic); writer.WriteLine("<h1>{0}</h1>", display); writer.WriteLine(formattedBody); writer.WriteLine("</div>"); #else writer.WriteLine("<p>This <b>orionsbelt</b> version was compiled without Wiki support!</p>"); writer.WriteLine("<p>If this is an online version... then... er... maybe we forgot the wiki, please warn us!</p>"); #endif }
protected override void OnLoad(EventArgs args) { base.OnLoad(args); try { User user = (User)Context.User; Ruler ruler = Universe.instance.getRuler(user.RulerId); Result result = Universe.CheckRestrictions(ruler); Visible = !result.Ok; ResultSet = result; if (Visible) { Title = info.getContent("restrictions_title"); } } catch (Exception ex) { ExceptionLog.log(ex); } }
/// <summary>Escreve um item</summary> private void writeLine(ref StringBuilder allMessages, Message message, bool bold) { if (ShowImages) { allMessages.Append("<td class='resourceCell'>"); if (message.Info != null) { allMessages.Append(string.Format("<img src='{0}' />", OrionGlobals.getCommonImagePath("messages/" + message.Info.Category + ".gif")) ); } allMessages.Append("</td>"); } string line = string.Empty; try { allMessages.Append("<td class='resource'>"); line = info.getContent(message.Info.Name); if (bold) { allMessages.Append("<b>"); } allMessages.Append(message.Info.localize(message, line, new MessageDecorator(info))); if (bold) { allMessages.Append("</b>"); } allMessages.Append("</td>"); allMessages.Append("<td class='resourceCell'>"); allMessages.Append(message.Turn.ToString()); allMessages.Append("</td>"); } catch (Exception e) { Log.log("-------------- MESSAGE ERROR ------------"); Log.log(e); ExceptionLog.log(e); allMessages.Append("<span class='error'>[Error translating]</span> " + message.ToString()); } }
public static void RankingBattleEndend(Ruler one, Ruler two, BattleResult result) { try { User uone = UserUtility.bd.getUser(one.ForeignId); User utwo = UserUtility.bd.getUser(two.ForeignId); Ranking.Update(uone, utwo, result); if (result == BattleResult.NumberOneVictory) { ++uone.Wins; ++utwo.Losses; } else { ++utwo.Wins; ++uone.Losses; } UserUtility.bd.saveUser(uone, string.Empty); UserUtility.bd.saveUser(utwo, string.Empty); if (uone.AllianceId > 0 && utwo.AllianceId > 0 && uone.AllianceId != utwo.AllianceId) { AllianceInfo aone = AllianceUtility.Persistance.Get(uone.AllianceId); AllianceInfo atwo = AllianceUtility.Persistance.Get(utwo.AllianceId); Ranking.Update(aone, atwo, result); ++aone.RankingBattles; ++atwo.RankingBattles; AllianceUtility.Persistance.Save(aone); AllianceUtility.Persistance.Save(atwo); } } catch (Exception ex) { ExceptionLog.log(ex); } }
/// <summary>Prepara o controlo</summary> protected override void OnLoad(EventArgs args) { base.OnLoad(args); try { Ruler scanner = getRuler(); Scan scan = ScanUtility.Persistence.GetScan(ScanId); if (scan == null) { throw new Exception("No scan with id '" + ScanId + "' found"); } if (!scan.Success) { throw new Exception("Trying to access an unsucceceful scan"); } Planet source = scanner.getPlanet(scan.SourcePlanetId); if (source == null) { throw new Exception("Ruler '" + scanner.Id + "' don't own planet '" + scan.SourcePlanetId + ""); } Planet planet = scan.TargetPlanet; OrionGlobals.RegisterRequest(Chronos.Messaging.MessageType.Scan, string.Format("{0} - {1}", info.getContent("section_scanreport"), planet.Coordinate)); scanWiki.NavigateUrl = Wiki.GetUrl("Scan"); scanWiki.Text = info.getContent("Wiki_Scan"); scanWiki.CssClass = "docs"; img.ImageUrl = OrionGlobals.getCommonImagePath("planets/" + planet.Info.Id + ".jpg"); img.EnableViewState = false; if (scan.TargetPlanetOwner != -1) { name.Text = planet.Name; ruler.Text = OrionGlobals.getLink(Universe.instance.getRuler(scan.TargetPlanetOwner)); } else { name.Text = "?"; ruler.Text = info.getContent("scan_inhabited"); } coordinate.Text = planet.Coordinate.ToString(); diameter.Text = planet.Info.Diameter.ToString(); mass.Text = planet.Info.Mass.ToString(); temperature.Text = planet.Info.Temperature; escape.Text = planet.Info.EscapeVelocity.ToString(); terrain.Text = info.getContent(planet.Info.Terrain.Description); cultureValue.Text = scan.Culture.ToString(); travelTime.Text = Chronos.Core.Fleet.TravelTime(source.Coordinate, scan.Target).ToString(); inBattle.ImageUrl = OrionGlobals.YesNoImage(scan.InBattle); if (scan.ScanLevel == 1) { return; } level2.Visible = true; fillPanel(mineral, "mineral", planet.Info.MPRatio); fillPanel(food, "food", planet.Info.FoodRatio); fillPanel(gold, "gold", planet.Info.GoldRatio); fillPanel(energy, "energy", planet.Info.EnergyRatio); fillPanel(groundSpace, "groundSpace", planet.Info.GroundSpace); fillPanel(waterSpace, "waterSpace", planet.Info.WaterSpace); fillPanel(orbitSpace, "orbitSpace", planet.Info.OrbitSpace); if (scan.ScanLevel == 2) { return; } level3.Visible = true; fleetNumber.Text = scan.NumberOfFleets.ToString(); shipsNumber.Text = scan.TotalShips.ToString(); hasStarPort.ImageUrl = OrionGlobals.YesNoImage(scan.HasStarPort); hasCommsSatellite.ImageUrl = OrionGlobals.YesNoImage(scan.HasCommsSatellite); hasGate.ImageUrl = OrionGlobals.YesNoImage(scan.HasGate); hasStarGate.ImageUrl = OrionGlobals.YesNoImage(scan.HasStarGate); hasHospital.ImageUrl = OrionGlobals.YesNoImage(scan.HasHospital); hasLandReclamation.ImageUrl = OrionGlobals.YesNoImage(scan.HasLandReclamation); hasMineralExtractor.ImageUrl = OrionGlobals.YesNoImage(scan.HasMineralExtractor); hasSpa.ImageUrl = OrionGlobals.YesNoImage(scan.HasSpa); hasStockMarkets.ImageUrl = OrionGlobals.YesNoImage(scan.HasStockMarkets); hasWaterReclamation.ImageUrl = OrionGlobals.YesNoImage(scan.HasWaterReclamation); hasIonCannon.ImageUrl = OrionGlobals.YesNoImage(scan.HasIonCannon); hasTurret.ImageUrl = OrionGlobals.YesNoImage(scan.HasTurret); } catch (Exception ex) { Visible = false; Chronos.Utils.Log.log(ex); ExceptionLog.log(ex); } }
private void Application_BeginRequest(Object source, EventArgs e) { //obter o HttpContext HttpContext Context = HttpContext.Current; // verificar o wiki string path = CheckWiki(Context.Request.Path); // obter os paths do ficheiro e da base string requestPath = OrionGlobals.removePathInfo(path); string requestBasePath = OrionGlobals.getSectionPath(requestPath); Log.log("Request to: {0}", requestPath); try { //Descobrir qual a seco pedida e adiciona-la ao Items Log.log("Checking for {0} section... ", requestPath); SectionInfo sectionInfo = SectionUtility.getSectionInfoFromFullPath(requestPath); if (sectionInfo == null) { Log.log("\tsectionInfo is null"); //normalmente acontece quando e named page sectionInfo = SectionUtility.getSectionInfoFromBasePath(requestBasePath); } else { Log.log("\tsectionInfo ok"); } //quando imagem cai aqui ou outra coisa qq que n seja seco if (sectionInfo == null) { Log.log("\tsectionInfo is null"); return; } //adiciona aos items a Items Context.Items["SectionInfo"] = sectionInfo; Log.log("\tSectionInfo: {0}", sectionInfo.sectionName); //Descobrir qual a skin corrente MasterSkinInfo masterSkinInfo = MasterSkinUtility.getMasterSkinInfoFromId(sectionInfo.sectionSkinId); if (masterSkinInfo == null) { masterSkinInfo = MasterSkinUtility.getMasterSkinInfoFromId(1); } //adiciona o nmero da skin (Caso a skin tenha vrios esquemas de cor) storeSkinNumber(masterSkinInfo.masterSkinCount); //adiciona aos items a Items Context.Items["MasterSkinInfo"] = masterSkinInfo; PageInfo pageInfo = getPageInfo(sectionInfo, masterSkinInfo, requestPath); if (pageInfo != null) { Context.Items["PageInfo"] = pageInfo; Chronos.Utils.Log.log("Request: " + requestPath); Log.log("Rewriting Path to '{0}'...", OrionGlobals.UrlBasePage); if (requestPath.IndexOf(".aspx") >= 0) { Log.log("\tDone!"); Context.RewritePath(OrionGlobals.UrlBasePage); } else { Log.log("\tNot rewrited! '{0}' isn't aspx", requestPath); } } else { Log.log("PageInfo is null for '{0}'", requestPath); } } catch (Exception exception) { try { ExceptionLog.log(exception); } catch (Exception exp) { HttpContext.Current.Cache[OrionGlobals.SessionId + "AlnitakException"] = new ExceptionInfo(exp);; } //mostrar a pgina de erro global HttpContext.Current.Server.Transfer(OrionGlobals.resolveBase(OrionGlobals.getConfigurationValue("pagePath", "globalError"))); } }
/// <summary>Mostra o menu que indica todas as categorias possíveis</summary> private void showError(HtmlTextWriter writer) { writer.WriteLine(info.getContent("invalid_request")); ExceptionLog.log("Invalid Request", Page.Request.RawUrl); }
/// <summary>Marca o incio da aplicacao</summary> protected void Application_Start(object src, EventArgs e) { Log.log("---"); Log.log(OrionGlobals.AlnitakInfo); Log.log(Chronos.Utils.Platform.ChronosInfo); Log.log("---"); Log.log("Starting Alnitak..."); GenericIdentity identity = new GenericIdentity("guest"); defaultPrincipal = new GenericPrincipal(identity, defaultRoles); DateTime now = DateTime.Now; DateTime dressUp = now; Universe.Events.TurnStart += new EventHandler(turnStart); Universe.Events.TurnEnd += new EventHandler(turnEnd); Universe.Events.TurnError += new EventHandler(Events_TurnError); if (OrionGlobals.TraceTurn) { Universe.Events.UniverseTrace += new EventHandler(Events_TraceUniverse); } try { Log.log("Loading Universe..."); Universe.Parameters = OrionGlobals.Persistence; Universe.instance = Universe.load(); if (null == Universe.instance) { Universe.instance = new Universe(); Universe.instance.init(); } Log.log("Done!"); dressUp = DateTime.Now; } catch (Exception ex) { Log.log(ex); ExceptionLog.log(ex); } finally { try{ ChronosStats stats = new ChronosStats(); stats.StartTime = now; stats.DressUp = dressUp - now; Application["ChronosStats"] = stats; Application["AlnitakOnlineUsers"] = new UserWatcher(); Application["AlnitakOnlineUsersCount"] = 0; OrionGlobals.getRoles(); if (OrionGlobals.IsTurnTimeSpecified) { Universe.instance.TurnTime = OrionGlobals.TurnTime; } Universe.instance.start(); Universe.RankingBattleEnded += new Universe.RankingBattleHandler(OrionGlobals.RankingBattleEndend); Log.log("... Done!"); } catch (Exception ex) { throw new AlnitakException(ex.Message); } } }
/// <summary> /// Apanha os erros ocorridos na passagem de turno /// </summary> private void Events_TurnError(object sender, EventArgs e) { ExceptionLog.log(((Universe.TurnErrorEventArgs)e).Error); }