public static void Initialize(string file) { // Initialize exception logger if (!Directory.Exists("Crashes")) { Directory.CreateDirectory("Crashes"); } var el = new LogWriter("Crashes", "WorldNode.log"); ExceptionLog.Initialize(el); // Initialize unhandled exception handler/logger AppDomain.CurrentDomain.UnhandledException += (o, e) => { try { var ex = (Exception)e.ExceptionObject; ExceptionLog.Write(ex); } catch (Exception) { throw; } }; config = new Config(file); if (config != null) { IsInitialized = true; LogLevel = (LogType)config.Read("Log.Level", 0x7, true); LogDirectory = config.Read("Log.Directory", "Logs/Node"); LogConsoleFile = config.Read("Log.Console.File", ""); LogPacketFile = config.Read("Log.Packet.File", ""); LogWriter fl = null; if (LogConsoleFile != "") { if (!Directory.Exists(LogDirectory)) { Directory.CreateDirectory(LogDirectory); } fl = new LogWriter(LogDirectory, LogConsoleFile); } Log.Initialize(LogLevel, fl); if (LogPacketFile != "") { PacketLog.Initialize(LogDirectory, LogPacketFile); } } ReadConfig(); }
public ServerBase(string ip, int port) { var bindIP = IPAddress.None; if (!IPAddress.TryParse(ip, out bindIP)) { Log.Normal($"Server can't be started: Invalid IP-Address ({ip})"); Console.ReadKey(true); Environment.Exit(0); } try { listener = new TcpListener(bindIP, port); listener.Start(); if (isRunning = listener.Server.IsBound) { new Thread(AcceptConnection).Start(200); } } catch (Exception ex) { ExceptionLog.Write(ex); Log.Error(ex.Message); } }
public Server(string ip, int port) { var bindIP = IPAddress.None; if (!IPAddress.TryParse(ip, out bindIP)) { Log.Message(LogType.Normal, "CharacterServer can't be started: Invalid IP-Address ({0})", ip); Console.ReadKey(true); Environment.Exit(0); } try { listener = new TcpListener(bindIP, port); listener.Start(); if (isRunning = listener.Server.IsBound) { Task.Factory.StartNew(AcceptConnection); } } catch (Exception ex) { ExceptionLog.Write(ex); Log.Message(LogType.Error, "{0}", ex.Message); } }
public bool Execute(string sql, params object[] args) { var sqlString = new StringBuilder(); // Fix for floating point problems on some languages sqlString.AppendFormat(CultureInfo.GetCultureInfo("en-US").NumberFormat, sql); try { using (var sqlCommand = new MySqlCommand(sqlString.ToString(), connection)) { var mParams = new List <MySqlParameter>(args.Length); foreach (var a in args) { mParams.Add(new MySqlParameter("", a)); } sqlCommand.Parameters.AddRange(mParams.ToArray()); sqlCommand.ExecuteNonQuery(); } return(true); } catch (Exception ex) { ExceptionLog.Write(ex); } return(false); }
static LogHelper() { var path = System.AppDomain.CurrentDomain.BaseDirectory + @"LogConfig\Log4net.xml"; ExceptionLog.Write(path); log4net.Config.XmlConfigurator.Configure(new FileInfo(path)); }
public bool CreateConnection(string host, string user, string password, string database, int port, bool pooling, int minPoolSize, int maxPoolSize) { var pools = string.Format(";Min Pool Size={0};Max Pool Size={1}", minPoolSize, maxPoolSize); var connectionString = "Server=" + host + ";User Id=" + user + ";Port=" + port + ";" + "Password="******";Database=" + database + ";Allow Zero Datetime=True;" + "Pooling=" + pooling + ";CharSet=utf8"; if (pooling) { connectionString += pools; } try { connection = new MySqlConnection(connectionString); connection.Open(); } catch (Exception ex) { ExceptionLog.Write(ex); } return(connection.State == ConnectionState.Open); }
public override void Process(object sender, SocketAsyncEventArgs e) { try { var socket = e.UserToken as Socket; var recievedBytes = e.BytesTransferred; if (recievedBytes != 0) { if (Crypt != null && Crypt.IsInitialized) { while (recievedBytes > 0) { Decrypt(dataBuffer); var length = BitConverter.ToUInt16(dataBuffer, 0) + 4; var packetData = new byte[length]; Buffer.BlockCopy(dataBuffer, 0, packetData, 0, length); var packet = new Packet(dataBuffer, 4); if (length > recievedBytes) { packetQueue.Enqueue(packet); } Task.Run(() => ProcessPacket(packet)); recievedBytes -= length; Buffer.BlockCopy(dataBuffer, length, dataBuffer, 0, recievedBytes); } } else { var packet = new Packet(dataBuffer); Task.Run(() => ProcessPacket(packet)); } client.ReceiveAsync(e); } } catch (Exception ex) { Dispose(); ExceptionLog.Write(ex); Log.Error(ex.Message); } }
private static void AsyncCallback(IAsyncResult ar) { try { AsyncResult result = (AsyncResult)ar; ((AsyncMethodCaller)result.AsyncDelegate).EndInvoke(ar); } catch (Exception exception) { ExceptionLog.Write(exception); } }
public DeviceAtlasData(FileLog objEventLog, ExceptionLog objExceptionEventLog) { Tree = null; try { Tree = Api.GetTreeFromFile((string)ConfigurationManager.AppSettings["DeviceAtlasDataPath"]); } catch (Exception e) { objExceptionEventLog.Write("Exception while reading DA hash tree from file: ", e); } return; }
public override async Task Send(Framework.Network.Packets.ServerPacket packet) { try { packet.Write(); packet.Packet.Finish(); if (packet.Packet.Header != null) { if (packet.Packet.Header.Size > 0x100) { packet = await Compress(packet); } PacketLog.Write <ServerMessage>(packet.Packet.Header.Message, packet.Packet.Data, client.RemoteEndPoint); } if (Crypt != null && Crypt.IsInitialized) { Encrypt(packet.Packet); } var socketEventargs = new SocketAsyncEventArgs(); socketEventargs.SetBuffer(packet.Packet.Data, 0, packet.Packet.Data.Length); if (!client.Connected) { return; } socketEventargs.Completed += SendCompleted; socketEventargs.UserToken = packet; socketEventargs.RemoteEndPoint = client.RemoteEndPoint; socketEventargs.SocketFlags = SocketFlags.None; client.SendAsync(socketEventargs); } catch (Exception ex) { Dispose(); ExceptionLog.Write(ex); Log.Error(ex.ToString()); } }
void Process(object sender, SocketAsyncEventArgs e) { try { var socket = e.UserToken as Socket; var recievedBytes = e.BytesTransferred; if (recievedBytes != 0) { // Enable packet encryption. if (Crypt == null && dataBuffer[0] == 0x45 && dataBuffer[1] == 0x01) { Crypt = new BNetCrypt(SecureRemotePassword.SessionKey); Buffer.BlockCopy(dataBuffer, 2, dataBuffer, 0, recievedBytes -= 2); Log.Debug($"Encryption for account '{Account.Id}' enabled"); } if (Crypt != null && Crypt.IsInitialized) { Crypt.Decrypt(dataBuffer, recievedBytes); } ProcessPacket(recievedBytes); if (client != null) { client.ReceiveAsync(e); } } else { socket.Close(); } } catch (Exception ex) { Dispose(); ExceptionLog.Write(ex); Log.Error(ex.Message); } }
public void ShowRptData() { try { string strReportName = System.Web.HttpContext.Current.Session["ReportName"].ToString(); string cardCode = System.Web.HttpContext.Current.Session["CardCode"].ToString(); string cardName = System.Web.HttpContext.Current.Session["CardName"].ToString(); string startDate = System.Web.HttpContext.Current.Session["StartDate"].ToString(); string endDate = System.Web.HttpContext.Current.Session["EndDate"].ToString(); ReportDocument rd = new ReportDocument(); string strRptPath = System.Web.HttpContext.Current.Server.MapPath("~/") + "Report//" + strReportName; ExceptionLog.Write(string.Format("the report path is {0}", strRptPath)); rd.Load(strRptPath); TableLogOnInfo logInfo = new TableLogOnInfo(); logInfo.ConnectionInfo.ServerName = "."; logInfo.ConnectionInfo.DatabaseName = "SBO_GS_TEST"; logInfo.ConnectionInfo.UserID = "sa"; logInfo.ConnectionInfo.Password = "******"; rd.Database.Tables[0].ApplyLogOnInfo(logInfo); if (!string.IsNullOrEmpty(cardName)) { rd.SetParameterValue("cardname", cardName); } if (!string.IsNullOrEmpty(startDate)) { rd.SetParameterValue("Sdate", Convert.ToDateTime(startDate)); } if (!string.IsNullOrEmpty(startDate)) { rd.SetParameterValue("Edate", Convert.ToDateTime(endDate)); } rd.ExportToHttpResponse(ExportFormatType.PortableDocFormat, System.Web.HttpContext.Current.Response, false, "crReport"); Session["ReportName"] = null; Session["CardCode"] = null; Session["CardName"] = null; Session["StartDate"] = null; Session["EndDate"] = null; } catch (Exception ex) { Response.Write(ex.ToString()); } }
public SQLResult Select(string sql, params object[] args) { var sqlString = new StringBuilder(); // Fix for floating point problems on some languages sqlString.AppendFormat(CultureInfo.GetCultureInfo("en-US").NumberFormat, sql); try { using (var sqlCommand = new MySqlCommand(sqlString.ToString(), connection)) { var mParams = new List <MySqlParameter>(args.Length); foreach (var a in args) { mParams.Add(new MySqlParameter("", a)); } sqlCommand.Parameters.AddRange(mParams.ToArray()); using (var SqlData = sqlCommand.ExecuteReader(CommandBehavior.Default)) { if (SqlData.HasRows) { using (var retData = new SQLResult()) { retData.Load(SqlData); retData.Count = retData.Rows.Count; return(retData); } } } } } catch (Exception ex) { ExceptionLog.Write(ex); } return(null); }
public override Exception HandlerException(Microsoft.Practices.Unity.InterceptionExtension.IMethodInvocation input, Exception exception) { if (exception is WebFaultException <ExceptionDetail> ) { string note = FormmatException(exception.StackTrace, exception.Message); ExceptionLog.Write(note); throw exception; } if (!(exception is GenericException)) { exception = new GenericException(exception); string notepad = FormmatException(exception.StackTrace, exception.Message); ExceptionLog.Write(notepad); } ExceptionDetail detail = new ExceptionDetail(exception); var result = new WebFaultException <ExceptionDetail>(detail, HttpStatusCode.BadRequest); throw result; }
protected override void OnException(ExceptionContext filterContext) { filterContext.ExceptionHandled = true; InfoModel errormodel = new InfoModel() { Title = "错误", Code = -1 }; JsonModel resultModel = new JsonModel() { Code = -1 }; var wcfException = filterContext.Exception as FaultException <ExceptionDetail>; if (wcfException != null) { errormodel.Message = GetWcfExceptionDetail(wcfException.Detail); errormodel.Type = wcfException.Detail.HelpLink; string notepad = FormmatException(wcfException.StackTrace, wcfException.Message); ExceptionLog.Write(notepad); } else { errormodel.Message = GetExceptionDetail(filterContext.Exception); string notepad = FormmatException(filterContext.Exception.StackTrace, filterContext.Exception.Message); ExceptionLog.Write(notepad); } if (HttpContext.Request.Headers["X-Requested-With"] == "XMLHttpRequest") { JavaScriptSerializer jsonSerializer = new JavaScriptSerializer(); resultModel.Data = "createDialog('" + Url.Content("~/base/exception") + "'," + jsonSerializer.Serialize(errormodel) + ")"; filterContext.Result = Json(resultModel); //filterContext.Result = Content("createDialog('" + Url.Content("~/base/exception") + "'," + jsonSerializer.Serialize(errormodel) + ")", "application/javascript"); //base.OnException(filterContext); } else { filterContext.Result = View("~/Views/Template/ExceptionPage.cshtml", errormodel); } base.OnException(filterContext); }
public void Send(AuthPacket packet) { try { packet.Finish(); if (packet.Header != null) { PacketLog.Write <AuthServerMessage>(packet.Header.Message, packet.Data, client.RemoteEndPoint); } if (Crypt != null && Crypt.IsInitialized) { Crypt.Encrypt(packet.Data, packet.Data.Length); } var socketEventargs = new SocketAsyncEventArgs(); socketEventargs.SetBuffer(packet.Data, 0, packet.Data.Length); socketEventargs.Completed += SendCompleted; socketEventargs.UserToken = packet; socketEventargs.RemoteEndPoint = client.RemoteEndPoint; socketEventargs.SocketFlags = SocketFlags.None; client.Send(packet.Data); } catch (Exception ex) { Dispose(); ExceptionLog.Write(ex); Log.Error(ex.Message); } }