private void ReceiveLowLevelVersionExchangeCallback(PyDataType ar) { try { LowLevelVersionExchange exchange = ar; // reply with the node LowLevelVersionExchange LowLevelVersionExchange reply = new LowLevelVersionExchange { Codename = Game.CODENAME, Birthday = Game.BIRTHDAY, Build = Game.BUILD, MachoVersion = Game.MACHO_VERSION, Version = Game.VERSION, Region = Game.REGION, IsNode = true, NodeIdentifier = "Node" }; this.ClusterConnection.Send(reply); // set the new handler this.ClusterConnection.SetReceiveCallback(ReceiveNodeInitialState); } catch (Exception e) { Log.Error($"Exception caught on LowLevelVersionExchange: {e.Message}"); throw; } }
private void ReceiveLowLevelVersionExchangeCallback(PyDataType ar) { try { LowLevelVersionExchange exchange = CheckLowLevelVersionExchange(ar); // reply with the node LowLevelVersionExchange LowLevelVersionExchange reply = new LowLevelVersionExchange(); reply.codename = Common.Constants.Game.codename; reply.birthday = Common.Constants.Game.birthday; reply.build = Common.Constants.Game.build; reply.machoVersion = Common.Constants.Game.machoVersion; reply.version = Common.Constants.Game.version; reply.region = Common.Constants.Game.region; reply.isNode = true; reply.nodeIdentifier = "Node"; this.Socket.Send(reply); // set the new handler this.Socket.SetReceiveCallback(ReceiveNodeInitialState); } catch (Exception e) { Log.Error($"Exception caught on LowLevelVersionExchange: {e.Message}"); throw; } }
protected LowLevelVersionExchange CheckLowLevelVersionExchange(PyDataType exchange) { LowLevelVersionExchange data = exchange; if (data.birthday != Common.Constants.Game.birthday) { throw new Exception("Wrong birthday in LowLevelVersionExchange"); } if (data.build != Common.Constants.Game.build) { throw new Exception("Wrong build in LowLevelVersionExchange"); } if (data.codename != Common.Constants.Game.codename + "@" + Common.Constants.Game.region) { throw new Exception("Wrong codename in LowLevelVersionExchange"); } if (data.machoVersion != Common.Constants.Game.machoVersion) { throw new Exception("Wrong machoVersion in LowLevelVersionExchange"); } if (data.version != Common.Constants.Game.version) { throw new Exception("Wrong version in LowLevelVersionExchange"); } if (data.isNode == true) { if (data.nodeIdentifier != "Node") { throw new Exception("Wrong node string in LowLevelVersionExchange"); } } return(data); }
public bool CheckLowLevelVersionExchange(PyTuple packet) { LowLevelVersionExchange data = new LowLevelVersionExchange(); if (data.Decode(packet) == false) { Log.Error("Client", "Wrong LowLevelVersionExchange packet"); return(false); } if (data.birthday != Common.Constants.Game.birthday) { Log.Error("Client", "Wrong birthday in LowLevelVersionExchange"); return(false); } if (data.build != Common.Constants.Game.build) { Log.Error("Client", "Wrong build in LowLevelVersionExchange"); return(false); } if (data.codename != Common.Constants.Game.codename + "@" + Common.Constants.Game.region) { Log.Error("Client", "Wrong codename in LowLevelVersionExchange"); return(false); } if (data.machoVersion != Common.Constants.Game.machoVersion) { Log.Error("Client", "Wrong machoVersion in LowLevelVersionExchange"); return(false); } if (data.version != Common.Constants.Game.version) { Log.Error("Client", "Wrong version in LowLevelVersionExchange"); return(false); } if (data.isNode == true) { if (data.nodeIdentifier != "Node") { Log.Error("Client", "Wrong node string in LowLevelVersionExchange"); return(false); } Type = ConnectionType.Node; } else { Type = ConnectionType.Client; } return(true); }
private void ReceiveLowLevelVersionExchangeCallback(PyDataType ar) { try { LowLevelVersionExchange exchange = ar; } catch (Exception e) { Log.Error($"Exception caught on LowLevelVersionExchange: {e.Message}"); throw; } // assign the new packet handler to wait for commands again this.Socket.SetReceiveCallback(ReceiveCommandCallback); }
private void SendLowLevelVersionExchange() { Log.Debug("Sending LowLevelVersionExchange..."); LowLevelVersionExchange data = new LowLevelVersionExchange(); data.codename = Common.Constants.Game.codename; data.birthday = Common.Constants.Game.birthday; data.build = Common.Constants.Game.build; data.machoVersion = Common.Constants.Game.machoVersion; data.version = Common.Constants.Game.version; data.usercount = this.ConnectionManager.ClientsCount; data.region = Common.Constants.Game.region; this.Socket.Send(data); }
private void SendLowLevelVersionExchange() { Log.Debug("Client", "Sending LowLevelVersionExchange..."); LowLevelVersionExchange data = new LowLevelVersionExchange(); data.codename = Common.Constants.Game.codename; data.birthday = Common.Constants.Game.birthday; data.build = Common.Constants.Game.build; data.machoVersion = Common.Constants.Game.machoVersion; data.version = Common.Constants.Game.version; data.usercount = ClientManager.GetClientsCount(); data.region = Common.Constants.Game.region; Send(data.Encode(false)); }
protected void SendLowLevelVersionExchange() { Log.Debug("Sending LowLevelVersionExchange..."); LowLevelVersionExchange data = new LowLevelVersionExchange { Codename = Game.CODENAME, Birthday = Game.BIRTHDAY, Build = Game.BUILD, MachoVersion = Game.MACHO_VERSION, Version = Game.VERSION, UserCount = this.ConnectionManager.ClientsCount, Region = Game.REGION }; this.Socket.Send(data); }
private void ReceiveLowLevelVersionExchangeCallback(PyDataType ar) { try { LowLevelVersionExchange exchange = ar; // TODO: CHECK NETWORK OF THE NODE TO ENSURE UNAUTHORIZED CONNECTIONS DONT REACH A NODE STATE if (exchange.IsNode) { this.ConvertToNodeConnection(); } else { this.ConvertToClientConnection(); } } catch (Exception e) { Log.Error($"Exception caught on LowLevelVersionExchange {e.Message}"); throw; } }
static void Main(string[] args) { Log.Init("evesharp"); Log.Info("Main", "Starting node..."); Log.Info("Database", "Loading database.conf file"); string[] lines = File.ReadAllLines("database.conf"); Database.Database.Username = lines[0]; Database.Database.Password = lines[1]; Database.Database.Host = lines[2]; Database.Database.DB = lines[3]; Log.Trace("Database", "Connecting to database..."); if (Database.Database.Init() == false) { Log.Error("Main", "Cannot connect to database"); while (true) { ; } } /* * SHA1 sha1 = SHA1.Create(); * byte[] hash = sha1.ComputeHash(Encoding.ASCII.GetBytes("password")); * char[] strHash = new char[20]; * * for (int i = 0; i < 20; i++) * { * strHash[i] = (char)hash[i]; * } * * string str = new string(strHash); * * Database.Database.Query("INSERT INTO account(accountID, accountName, password, role, online, banned)VALUES(NULL, 'Username', '" + str + "', 2, 0, 0);"); * * Database.Database.Query("INSERT INTO account(accountID, accountName, password, role, online, banned)VALUES(NULL, 'Username', SHA1('password'), 2, 0, 0);");*/ Log.Info("Main", "Connection to the DB sucessfull"); Log.Info("Main", "Generating default cache data"); Cache.GenerateCache(); Log.Debug("Main", "Done"); Log.Info("Main", "Connecting to proxy..."); proxyConnection = new TCPSocket(ushort.Parse(proxy[0, 1]), false); if (proxyConnection.Connect(proxy[0, 0]) == false) { Log.Error("Main", "Cannot connect to proxy. Halting"); Database.Database.Stop(); while (true) { ; } } Log.Trace("Main", "Server started"); while (true) { Thread.Sleep(1); try { byte[] data = new byte[proxyConnection.Available]; int bytes = proxyConnection.Recv(data); if (bytes == -1) { // Proxy is closing, shutdown the node break; } else if (bytes > 0) { packetizer.QueuePackets(data, bytes); int p = packetizer.ProcessPackets(); for (int i = 0; i < p; i++) { byte[] packet = packetizer.PopItem(); PyObject obj = Unmarshal.Process <PyObject>(packet); if (obj is PyObjectData) { PyObjectData info = obj as PyObjectData; if (info.Name == "machoNet.nodeInfo") { // Update our local info NodeInfo nodeinfo = new NodeInfo(); if (nodeinfo.Decode(info) == true) { nodeID = nodeinfo.nodeID; Log.Debug("Main", "Found machoNet.nodeInfo, our new node id is " + nodeID.ToString("X4")); SystemManager.LoadSolarSystems(nodeinfo.solarSystems); } } else { // Client packet PyPacket clientpacket = new PyPacket(); if (clientpacket.Decode(info) == false) { Log.Error("Main", "Unknown packet"); } else { // Something similar to Async calls new Thread(new ParameterizedThreadStart(HandlePacket)).Start(clientpacket); } } } else if (obj is PyChecksumedStream) // Checksumed packets { PyPacket clientpacket = new PyPacket(); if (clientpacket.Decode(obj) == false) { Log.Error("Main", "Cannot decode packet"); } else { new Thread(new ParameterizedThreadStart(HandlePacket)).Start(clientpacket); } } else if (obj is PyTuple) { // The only tuple packet is the LowLevelVersionExchange LowLevelVersionExchange ex = new LowLevelVersionExchange(); if (ex.Decode(obj) == false) { Log.Error("Main", "LowLevelVersionExchange error"); } // Reply with the node LowLevelVersionExchange LowLevelVersionExchange reply = new LowLevelVersionExchange(); reply.codename = Common.Constants.Game.codename; reply.birthday = Common.Constants.Game.birthday; reply.build = Common.Constants.Game.build; reply.machoVersion = Common.Constants.Game.machoVersion; reply.version = Common.Constants.Game.version; reply.region = Common.Constants.Game.region; Send(reply.Encode(true)); } else if (obj is PyObjectEx) { Log.Error("PyObjectEx", PrettyPrinter.Print(obj)); } else { Log.Error("Main", PrettyPrinter.Print(obj)); Log.Error("Main", "Unhandled packet type"); } } } } catch (Exception) { } } /* Code to ADD an account: * SHA1 sha1 = SHA1.Create(); * byte[] hash = sha1.ComputeHash(Encoding.ASCII.GetBytes("password")); * char[] strHash = new char[20]; * * for (int i = 0; i < 20; i++) * { * strHash[i] = (char)hash[i]; * } * * string str = new string(strHash); * * Database.Database.Query("INSERT INTO account(accountID, accountName, password, role, online, banned)VALUES(NULL, 'Username', '" + str + "', 2, 0, 0);"); */ }
static void Main(string[] args) { Log.Init("evesharp"); Log.Info("Main", "Starting node..."); Log.Trace("Database", "Connecting to database..."); if (Database.Database.Init() == false) { Log.Error("Main", "Cannot connect to database"); while (true) { ; } } /* * DBRowDescriptor descriptor = new DBRowDescriptor(); * * descriptor.AddColumn("itemID", FieldType.I4); * descriptor.AddColumn("custominfo", FieldType.Str); * * PyPackedRow packed = new PyPackedRow(descriptor); * * packed.SetValue("itemID", new PyInt(500)); * packed.SetValue("custominfo", new PyString("hello world")); * * byte[] marshaled = Marshal.Marshal.Process(packed); * * PyPackedRow unmarshaled = Unmarshal.Process<PyPackedRow>(marshaled); * * Console.WriteLine(PrettyPrinter.Print(unmarshaled)); */ byte[] raw = new byte[] { 1, 0, 55, 1, 22, 33, 0, 33, 25, 33, 14, 0, 0, 25, 45 }; MemoryStream output = new MemoryStream(raw); BinaryReader reader = new BinaryReader(output); MemoryStream stream = new MemoryStream(); BinaryWriter streamWriter = new BinaryWriter(stream); BinaryReader streamReader = new BinaryReader(stream); PyPackedRow.ZeroCompress(reader, output, streamWriter); byte[] compressed = stream.ToArray(); stream.Seek(0, SeekOrigin.Begin); byte[] uncompress = PyPackedRow.LoadZeroCompressed(streamReader); while (true) { Thread.Sleep(1); } /* * SHA1 sha1 = SHA1.Create(); * byte[] hash = sha1.ComputeHash(Encoding.ASCII.GetBytes("password")); * char[] strHash = new char[20]; * * for (int i = 0; i < 20; i++) * { * strHash[i] = (char)hash[i]; * } * * string str = new string(strHash); * * Database.Database.Query("INSERT INTO account(accountID, accountName, password, role, online, banned)VALUES(NULL, 'Username', '" + str + "', 2, 0, 0);"); */ Log.Info("Main", "Connection to the DB sucessfull"); Log.Trace("Main", "Registering services..."); SvcMgr.AddService(new Services.Network.machoNet()); SvcMgr.AddService(new Services.Network.alert()); SvcMgr.AddService(new Services.CacheSvc.objectCaching()); Log.Info("Main", "Done"); Log.Info("Main", "Connecting to proxy..."); proxyConnection = new TCPSocket(ushort.Parse(proxy[0, 1]), false); if (proxyConnection.Connect(proxy[0, 0]) == false) { Log.Error("Main", "Cannot connect to proxy. Halting"); Database.Database.Stop(); while (true) { ; } } Log.Trace("Main", "Server started"); while (true) { Thread.Sleep(1); try { byte[] data = new byte[proxyConnection.Available]; int bytes = proxyConnection.Recv(data); if (bytes == -1) { // Proxy is closing, shutdown the node break; } else if (bytes > 0) { packetizer.QueuePackets(data, bytes); int p = packetizer.ProcessPackets(); for (int i = 0; i < p; i++) { byte[] packet = packetizer.PopItem(); PyObject obj = Unmarshal.Process <PyObject>(packet); if (obj is PyObjectData) { PyObjectData info = obj as PyObjectData; if (info.Name == "machoNet.nodeInfo") { // Update our local info NodeInfo nodeinfo = new NodeInfo(); if (nodeinfo.Decode(info) == true) { nodeID = nodeinfo.nodeID; SystemManager.LoadSolarSystems(nodeinfo.solarSystems); } } else { // Client packet PyPacket clientpacket = new PyPacket(); if (clientpacket.Decode(info) == false) { Log.Error("Main", "Unknown packet"); } else { // Something similar to Async calls new Thread(new ParameterizedThreadStart(HandlePacket)).Start(clientpacket); } } } else if (obj is PyChecksumedStream) // Checksumed packets { PyPacket clientpacket = new PyPacket(); if (clientpacket.Decode(obj) == false) { Log.Error("Main", "Cannot decode packet"); } else { new Thread(new ParameterizedThreadStart(HandlePacket)).Start(clientpacket); } } else if (obj is PyTuple) { // The only tuple packet is the LowLevelVersionExchange LowLevelVersionExchange ex = new LowLevelVersionExchange(); if (ex.Decode(obj) == false) { Log.Error("Main", "LowLevelVersionExchange error"); } // Reply with the node LowLevelVersionExchange LowLevelVersionExchange reply = new LowLevelVersionExchange(); reply.codename = Common.Constants.Game.codename; reply.birthday = Common.Constants.Game.birthday; reply.build = Common.Constants.Game.build; reply.machoVersion = Common.Constants.Game.machoVersion; reply.version = Common.Constants.Game.version; reply.region = Common.Constants.Game.region; Send(reply.Encode(true)); } else if (obj is PyObjectEx) { Log.Error("PyObjectEx", PrettyPrinter.Print(obj)); } else { Log.Error("Main", PrettyPrinter.Print(obj)); Log.Error("Main", "Unhandled packet type"); } } } } catch (Exception) { } } /* Code to ADD an account: * SHA1 sha1 = SHA1.Create(); * byte[] hash = sha1.ComputeHash(Encoding.ASCII.GetBytes("password")); * char[] strHash = new char[20]; * * for (int i = 0; i < 20; i++) * { * strHash[i] = (char)hash[i]; * } * * string str = new string(strHash); * * Database.Database.Query("INSERT INTO account(accountID, accountName, password, role, online, banned)VALUES(NULL, 'Username', '" + str + "', 2, 0, 0);"); */ }