public EchoServerFixture() { Task.Run(() => { EasyServer server = new EasyServer(); server.ConnectHandler(socket => { socket.Receive(receivedData => { socket.Send(receivedData, sendSize => { }); }); socket.CloseHandler(() => { }); socket.ExceptionHandler(exception => { }); }); server.ExceptionHandler(exception => { }); server.Start("127.0.0.1", EchoServerPort); }); }
static void Main(string[] args) { Log.Info("CharacterCacher", "Lancement"); Assembly.Load("Common"); if (!EasyServer.InitLog("CharacterCacher", "Configs/CharacterCacher.log")) { return; } if (!EasyServer.InitConfig("Configs/CharacterCacher.xml", "CharacterCacher")) { return; } if (!EasyServer.InitMysqlDB("Configs/CharacterCacher.db", "Characters")) { return; } if (!EasyServer.InitRpcServer("CharacterCacher", EasyServer.GetConfValue <string>("CharacterCacher", "CharacterCacher", "Key"), EasyServer.GetConfValue <int>("CharacterCacher", "CharacterCacher", "Port"))) { return; } CharMgr = new CharacterMgr(); CharacterMgr.Database = EasyServer.GetDatabase("Characters"); CharMgr.LoadRealms(); EasyServer.StartConsole(); }
private void openToolStripMenuItem_Click(object sender, EventArgs e) { Stopwatch w = new Stopwatch(); w.Start(); OpenFileDialog dialog = new OpenFileDialog(); if (dialog.ShowDialog() != DialogResult.OK) { return; } string fileLabel = Path.GetFileNameWithoutExtension(dialog.FileName); treeDb.Nodes[0].Text = "Database (" + fileLabel + ")"; if (Server != null) { Server.Close(); } Server = new EasyServer(); Server.Attach(dialog.FileName); refreshToolStripMenuItem_Click(null, EventArgs.Empty); w.Stop(); labelStatus.Text = "Elapsed : " + w.ElapsedMilliseconds; }
public void ServerIdleTimeoutTest() { int port = 16001; bool timeout = false; CountdownEvent countdownEvent = new CountdownEvent(1); EasyServer server = new EasyServer(); Task.Run(() => { server.ConnectHandler(socket => { socket.SocketConfiguration.IdleTimeout = 2000; string socketId = socket.SocketId; socket.IdleTimeoutHandler(() => { _output.WriteLine($"[{socketId}] server idle timeout handler"); timeout = true; countdownEvent.Signal(); }); socket.CloseHandler(() => { _output.WriteLine($"[{socketId}] server socket close handler"); }); socket.ExceptionHandler(exception => { _output.WriteLine($"[{socketId}] server socket exception handler - {exception}"); }); socket.Receive(receivedData => { string stringData = Encoding.UTF8.GetString(receivedData); _output.WriteLine($"[{socketId}] server socket receive - {stringData}:{stringData.Length}"); }); }); server.ExceptionHandler(exception => { _output.WriteLine($"server start exception handler - {exception}"); }); server.Start("127.0.0.1", port); }).Wait(1000); EasyClient client = new EasyClient(); client.ConnectHandler(socket => { // skip }); client.ExceptionHandler(exception => { _output.WriteLine($"client connect exception handler - {exception}"); }); client.Connect("127.0.0.1", port); countdownEvent.Wait(5000); server.Stop(); Assert.True(timeout); }
public static void InitDB() { rebornAPB = new Database(EasyServer.GetConfValue <string>("Database", "Database", "IP"), EasyServer.GetConfValue <int>("Database", "Database", "Port"), EasyServer.GetConfValue <string>("Database", "Database", "Username"), EasyServer.GetConfValue <string>("Database", "Database", "Password"), EasyServer.GetConfValue <string>("Database", "Database", "Database")); AccountTable = new Table <AccountEntry>(rebornAPB); CharacterTable = new Table <CharacterEntry>(rebornAPB); FriendTable = new Table <FriendEntry>(rebornAPB); IgnoreTable = new Table <IgnoreEntry>(rebornAPB); }
private void closeToolStripMenuItem_Click(object sender, EventArgs e) { if (Server != null) { Server.Close(); Server = null; treeDb.Nodes[0].Text = "Database"; treeDb.Nodes[0].Nodes.Clear(); } }
public void OnClick(object sender, EventArgs e) { Control Con = (sender as Button); MethodInfo Info = GetType().GetMethod(Con.Tag as string); Log.Info("Function", "Name=" + (string)Con.Tag); if (Info == null) { Log.Error("Function", "Function not find : " + (string)Con.Tag); return; } Config = EasyServer.GetConf("Config"); List <string> Params = new List <string>(); ConfigElement Button = null;; foreach (ConfigElement Element in Config.Children.Values) { if (Element["Tag"].GetString() == Con.Tag as string) { Button = Element; break; } } foreach (ConfigElement Element in Button.Children["OnClick"].Children.Values) { string TagToFind = Element.GetString(); string TagValue = GetTag(TagToFind); Log.Info("OnClick", TagToFind + " Add value : " + TagValue); if (TagValue.Length > 0) { Params.Add(TagValue); } } if (Info.GetParameters().Length != Params.Count) { Log.Error("OnClick", "Function :" + Con.Tag + ", Invalid Params Count : Function=" + Info.GetParameters().Length + ",Xml=" + Params.Count); return; } if (Info != null) { Info.Invoke(this, Params.ToArray()); } }
static void Main(string[] args) { Log.Info("LobbyServer", "Starting..."); if (!EasyServer.InitLog("Lobby", "Configs/Logs.conf") || !EasyServer.InitConfig("Configs/Lobby.xml", "Lobby") || !EasyServer.InitConfig("Configs/Database.xml", "Database")) { return; } if (!EasyServer.Listen <TcpServer>(EasyServer.GetConfValue <int>("Lobby", "LoginServer", "Port"), "LoginServer")) { return; } worldListener = new World.Listener(EasyServer.GetConfValue <string>("Lobby", "WorldListener", "IP"), EasyServer.GetConfValue <int>("Lobby", "WorldListener", "Port")); Databases.InitDB(); Databases.Load(true); try { HttpServer.MapHandlers(); HttpServer server = new HttpServer(); server.Start(); } catch { Log.Error("HTTP", "If you want to use HTTP stuff, start this server with Admin rights"); } Log.Succes("LobbyServer", "Server initialisation complete!"); clients.Clear(); worlds.Clear(); Timer aTimer = new Timer(1000); aTimer.Elapsed += OnTimedEvent; aTimer.AutoReset = true; aTimer.Enabled = true; Log.Enter(); Console.WriteLine("For available console commands, type /commands"); Log.Enter(); bool done = false; while (!done) { string command; command = Console.ReadLine(); ProccessCommand(command); } EasyServer.StartConsole(); }
static void Main(string[] args) { Log.Info("WorldServer", "Starting..."); if (!EasyServer.InitLog("World", "Configs/Logs.conf") || !EasyServer.InitConfig("Configs/World.xml", "World") || !EasyServer.InitConfig("Configs/Database.xml", "Database")) { return; } Port = EasyServer.GetConfValue <int>("World", "WorldServer", "Port"); IP1 = EasyServer.GetConfValue <byte>("World", "WorldServer", "IP1"); IP2 = EasyServer.GetConfValue <byte>("World", "WorldServer", "IP2"); IP3 = EasyServer.GetConfValue <byte>("World", "WorldServer", "IP3"); IP4 = EasyServer.GetConfValue <byte>("World", "WorldServer", "IP4"); if (!EasyServer.Listen <TcpServer>(Port, "WorldInfo")) { return; } Databases.InitDB(); Databases.Load(false); FileMgr = new FileManager(); Password = EasyServer.GetConfValue <string>("World", "LobbyCommunication", "Password"); WorldName = EasyServer.GetConfValue <string>("World", "WorldInfo", "Name"); ID = EasyServer.GetConfValue <byte>("World", "WorldInfo", "Id"); Lobby = new Client(EasyServer.GetConfValue <string>("World", "LobbyCommunication", "Ip"), EasyServer.GetConfValue <int>("World", "LobbyCommunication", "Port")); districtsListener = new Listener(EasyServer.GetConfValue <string>("World", "DistrictListener", "Ip"), EasyServer.GetConfValue <int>("World", "DistrictListener", "Port")); clients.Clear(); Timer aTimer = new Timer(10000); aTimer.Elapsed += OnTimedEvent; aTimer.AutoReset = true; aTimer.Enabled = true; Log.Enter(); Console.WriteLine("For available console commands, type /commands"); Log.Enter(); bool done = false; while (!done) { string command; command = Console.ReadLine(); ProccessCommand(command); } EasyServer.StartConsole(); }
protected override void OnStart(string[] args) { Thread thread = new Thread( p => { try { EasyServer server = new EasyServer(); server.ListenTcp(); } catch (Exception ex) { EventLog.WriteEntry(ex.Message); throw; } }); thread.IsBackground = true; thread.Start(); }
private void newDatabaseToolStripMenuItem_Click(object sender, EventArgs e) { SaveFileDialog dialog = new SaveFileDialog(); if (dialog.ShowDialog() != DialogResult.OK) { return; } string fileLabel = Path.GetFileNameWithoutExtension(dialog.FileName); treeDb.Nodes[0].Text = "Database (" + fileLabel + ")"; if (Server != null) { Server.Close(); } Server = new EasyServer(); if (fileLabel != "memory") { Server.Attach(dialog.FileName); } }
public Startup(ILogger <Startup> logger, IConfiguration config, EasyServer server) { _logger = logger; _config = config; _server = server; }
public void Load(EasyServer server) { Load(server, false, -1); }
public void LoadConfig() { if (!EasyServer.InitConfig("Configs/Conf.xml", "Config")) { return; } Config = EasyServer.GetConf("Config"); foreach (KeyValuePair <string, ConfigElement> Elements in Config.Children) { ConfigElement Element = Elements.Value; Log.Info("Control", "New control : " + Elements.Key); if (Elements.Key == "Master") { string Name = Element["Name"].GetString("Launcher"); int W = Element["Width"].GetInt(100); int H = Element["Height"].GetInt(100); int Resize = Element["Resize"].GetInt(100); Log.Info("Scale", "X=" + W + ",Y=" + H); this.Name = Name; this.Text = Name; this.AutoScaleDimensions = new SizeF(W, H); this.AutoScaleMode = AutoScaleMode.Font; this.FormBorderStyle = Resize <= 0 ? FormBorderStyle.FixedToolWindow : FormBorderStyle.Sizable; this.ClientSize = new Size(Width, Height); this.Size = new System.Drawing.Size(W, H); } else { string Type = Element["Type"].GetString("label"); string Name = Element["Name"].GetString("Unknown"); string Text = Element["Text"].GetString(""); int W = Element["Width"].GetInt(100); int H = Element["Height"].GetInt(20); int X = Element["X"].GetInt(0); int Y = Element["Y"].GetInt(0); int Transparency = Element["Tranparency"].GetInt(0); string Tag = Element["Tag"].GetString(""); string[] BackColor = Element["BackColor"].GetString("1,1,1").Split(','); string[] ForeColor = Element["ForeColor"].GetString("255,255,255").Split(','); Log.Info("Tag", "Tag=" + Tag); Control Con; switch (Type) { case "textArea": int Masked = Element["Masked"].GetInt(0); if (Masked == 0) { Con = new TextBox(); } else { Con = new MaskedTextBox(); } if (Transparency > 0) { (Con as TextBoxBase).BorderStyle = BorderStyle.None; } break; case "Label": Con = new Label(); break; case "button": Con = new Button(); Con.Click += new EventHandler(this.OnClick); break; case "picture": Con = new PictureBox(); (Con as PictureBox).ImageLocation = Element["Image"].GetString(); (Con as PictureBox).InitialImage = null; break; default: Con = new Label(); break; } Con.Name = Name; Con.Text = Text; Con.Location = new System.Drawing.Point(X, Y); Con.Size = new System.Drawing.Size(W, H); if (Con is Label) { (Con as Label).AutoSize = true; } Con.Tag = Tag; if (BackColor.Length >= 3) { Con.BackColor = Color.FromArgb(int.Parse(BackColor[0]), int.Parse(BackColor[1]), int.Parse(BackColor[2])); } if (ForeColor.Length >= 3) { Con.ForeColor = Color.FromArgb(int.Parse(ForeColor[0]), int.Parse(ForeColor[1]), int.Parse(ForeColor[2])); } _Controls.Add(Con); } } }
static void Main(string[] args) { Log.Info("DistrictServer", "Starting..."); #region District if (!EasyServer.InitLog("World", "Configs/Logs.conf") || !EasyServer.InitConfig("Configs/District.xml", "District")) { return; } switch (EasyServer.GetConfValue <string>("District", "District", "Type")) { case "social": Type = 1; break; case "financial": Type = 2; break; case "waterfront": Type = 21; break; case "tutorial": Type = 14; break; } switch (EasyServer.GetConfValue <string>("District", "District", "Language")) { case "en": Language = 0; break; case "fr": Language = 1; break; case "it": Language = 2; break; case "ge": Language = 3; break; case "es": Language = 4; break; case "ru": Language = 5; break; } if ((Type == 21 || Type == 2) && EasyServer.GetConfValue <bool>("District", "District", "Hardcore")) { Type += 6; } #endregion Log.Info("World.Client", "Connecting to world at 127.0.0.1:2108..."); Password = "******"; ID = EasyServer.GetConfValue <byte>("District", "District", "Id"); Port = EasyServer.GetConfValue <string>("District", "District", "Port"); IP = GetPublicIP(); try { string line = null; StreamReader file = new StreamReader("Configs\\token.id"); while ((line = file.ReadLine()) != null) { Token = line; } file.Close(); } catch (FileNotFoundException) { Log.Error("Token", "\"_rtoken.id\" file not found!"); return; } if (IP == null) { return; } World = new World.Client("127.0.0.1", 2108); listener = new Listener(Convert.ToInt32(Port)); EasyServer.StartConsole(); }
public void ClosedSocketFromServer() { int port = 15001; string data = "testData"; bool closed = false; EasyServer server = new EasyServer(); Task.Run(() => { server.ConnectHandler(socket => { string socketId = socket.SocketId; socket.CloseHandler(() => { _output.WriteLine($"[{socketId}] server socket close handler"); }); socket.ExceptionHandler(exception => { _output.WriteLine($"[{socketId}] server socket exception handler - {exception}"); }); socket.Receive(receivedData => { string stringData = Encoding.UTF8.GetString(receivedData); _output.WriteLine($"[{socketId}] server socket receive - {stringData}:{stringData.Length}"); socket.Close(); }); }); server.ExceptionHandler(exception => { _output.WriteLine($"server start exception handler - {exception}"); }); server.Start("127.0.0.1", port); }).Wait(1500); EasyClient client = new EasyClient(); CountdownEvent countdownEvent = new CountdownEvent(1); client.ConnectHandler(socket => { string socketId = socket.SocketId; socket.CloseHandler(() => { _output.WriteLine($"[{socketId}] client socket close handler"); closed = true; countdownEvent.Signal(); }); socket.ExceptionHandler(exception => { _output.WriteLine($"[{socketId}] client socket close handler"); }); byte[] sendData = Encoding.UTF8.GetBytes(data); socket.Send(sendData, sendSize => { _output.WriteLine($"[{socketId}] client socket send - {data}:{data.Length}"); }); socket.Receive(receivedData => { string stringData = Encoding.UTF8.GetString(receivedData); _output.WriteLine($"[{socketId}] client socket receive - {stringData}:{stringData.Length}"); }); }); client.ExceptionHandler(exception => { _output.WriteLine($"client connect exception handler - {exception}"); }); client.Connect("127.0.0.1", port); countdownEvent.Wait(); server.Stop(); Assert.True(closed); }
static void Main(string[] args) { Log.Info("LobbyServer", "Starting..."); if (!EasyServer.InitLog("Lobby", "Configs/Logs.conf") || !EasyServer.InitConfig("Configs/Lobby.xml", "Lobby") || !EasyServer.InitConfig("Configs/Database.xml", "Database")) { return; } if (!EasyServer.Listen <TcpServer>(EasyServer.GetConfValue <int>("Lobby", "LoginServer", "Port"), "LoginServer")) { return; } worldListener = new World.Listener(EasyServer.GetConfValue <string>("Lobby", "WorldListener", "IP"), EasyServer.GetConfValue <int>("Lobby", "WorldListener", "Port")); Databases.InitDB(); Databases.Load(true); FileMgr = new FileManager(); string sVersion = EasyServer.GetConfValue <string>("Lobby", "LoginServer", "GameVersion"); if (sVersion == "RTW_CB") { version = GameVersion.RTW_CB; Log.Info("Version", "Supported game version: 0.6.0.509927 (RTW closed beta)"); } else if (sVersion == "RTW_DVD") { version = GameVersion.RTW_DVD; Log.Info("Version", "Supported game version: 1.1.0.534979 (RTW DVD release)"); } else if (sVersion == "RTW_LAST") { version = GameVersion.RTW_LAST; Log.Info("Version", "Supported game version: 1.4.1.555239 (last RTW patch)"); } else if (sVersion == "G1_LATEST") { version = GameVersion.G1_LATEST; Log.Info("Version", "Supported game version: 1.19.4.766569 (latest G1 patch)"); } else if (sVersion == "G1_ENGUPD") { version = GameVersion.G1_ENGUPD; Log.Info("Version", "Supported game version: 2.0.0.750394 (G1 engine update)"); } else { version = GameVersion.INVALID; Log.Error("Version", "Invalid game version"); } try { HttpServer.MapHandlers(); HttpServer server = new HttpServer(); server.Start(); } catch { Log.Error("HTTP", "If you want to use HTTP stuff, start this server with Admin rights"); } Log.Succes("LobbyServer", "Server initialisation complete!"); clients.Clear(); worlds.Clear(); Timer aTimer = new Timer(10000); aTimer.Elapsed += OnTimedEvent; aTimer.AutoReset = true; aTimer.Enabled = true; Log.Enter(); Console.WriteLine("For available console commands, type /commands"); Log.Enter(); bool done = false; while (!done) { string command; command = Console.ReadLine(); ProccessCommand(command); } EasyServer.StartConsole(); }
public void Load(EasyServer server, bool recover, long recoveryPoint) { long filesize = stream.Length; long inTransaction = -1; long prevPos = 0; long oldSize = 0; long startPosition = 0; try { while (filesize > 0) { startPosition = stream.Position; uint tableId = reader.ReadUInt32(); EasyTable table = null; #region Deleted row OR Transaction Atomicity if (tableId == 0) { uint sz = reader.ReadUInt32(); filesize -= sz; prevPos = 0; reader.ReadBytes((int)sz - 8); continue; } else if (tableId == TRANSTART) { if (recover && recoveryPoint > -1 && recoveryPoint == startPosition) { //actual recovery //TODO: truncate file :) maybr seek -1 return; } if (inTransaction > -1) { if (!recover) { throw new Exception(RECOVERMSG); } else { throw new RecoverException(); } } inTransaction = startPosition; continue; } else if (tableId == TRANEND) { if (inTransaction == -1) { if (!recover) { throw new Exception(RECOVERMSG); } else { throw new RecoverException(); } } else { inTransaction = -1; //everyting is ok. } continue; } #endregion table = server.FindTable(tableId); uint size = reader.ReadUInt32(); filesize -= size; #region Row size control if (prevPos != 0) { if (stream.Position - prevPos != oldSize) { throw new Exception("Corrupt Internal Error"); } } prevPos = stream.Position; oldSize = size; #endregion table.RowColumn.Insert(stream.Position - 8); #region Read Value while ((stream.Position - startPosition) < size) { uint columnId = reader.ReadUInt32(); EasyBaseColumn column = table.FindColumn(columnId); if (column is EasyUIntColumn) { column.Insert(reader.ReadUInt32()); } else if (column is EasyIntColumn) { column.Insert(reader.ReadInt32()); } else if (column is EasyStringColumn) { column.Insert(reader.ReadString()); } else if (column is EasyDecimalColumn) { column.Insert(reader.ReadDecimal()); } else if (column is EasyBoolColumn) { column.Insert(reader.ReadDecimal()); } } #endregion #region if row does not include all columns, complete the others /* Insert or update cannot gueranty to supply data for all columns. * Because table can altered at any time. (Alter table add column) */ int rowCount = table.RowColumn.GetRowCount(); foreach (EasyBaseColumn column in table.Columns) { if (column.GetRowCount() < rowCount) { column.Insert(null); } column.SetIdentity(); } #endregion if (table.Id == 1) //'tables' table { server.CreateTableFromSchema(); } //TODO: if this is a column and table is already created then add this new column } } catch (RecoverException rexp) { if (!recover) { throw; } this.CloseFile(); Load(server, true, inTransaction); } }