static void Main(string[] args) { var config = new NetPeerConfiguration("enctest"); var client = new NetClient(config); client.Start(); System.Threading.Thread.Sleep(100); // give server time to start up client.Connect("localhost", 14242); var encryption = new NetAESEncryption(client, "Hallonpalt"); // loop forever while (true) { // read messages var inc = client.ReadMessage(); if (inc != null) { switch (inc.MessageType) { case NetIncomingMessageType.DebugMessage: case NetIncomingMessageType.WarningMessage: case NetIncomingMessageType.VerboseDebugMessage: case NetIncomingMessageType.ErrorMessage: Console.WriteLine(inc.ReadString()); break; case NetIncomingMessageType.StatusChanged: var status = (NetConnectionStatus)inc.ReadByte(); Console.WriteLine(inc.SenderConnection + " (" + status + ") " + inc.ReadString()); break; } } // if we're connected, get input and send if (client.ServerConnection != null && client.ServerConnection.Status == NetConnectionStatus.Connected) { Console.WriteLine("Type a message:"); var input = Console.ReadLine(); var msg = client.CreateMessage(); msg.Write(input); encryption.Encrypt(msg); var ok = client.SendMessage(msg, NetDeliveryMethod.ReliableOrdered); Console.WriteLine("Message sent: " + ok); } } }
static void Main(string[] args) { var config = new NetPeerConfiguration("enctest"); config.MaximumConnections = 1; config.Port = 14242; var server = new NetServer(config); server.Start(); var encryption = new NetAESEncryption(server, "Hallonpalt"); // loop forever while (true) { var inc = server.ReadMessage(); if (inc != null) { switch (inc.MessageType) { case NetIncomingMessageType.DebugMessage: case NetIncomingMessageType.WarningMessage: case NetIncomingMessageType.VerboseDebugMessage: case NetIncomingMessageType.ErrorMessage: Console.WriteLine(inc.ReadString()); break; case NetIncomingMessageType.StatusChanged: var status = (NetConnectionStatus)inc.ReadByte(); Console.WriteLine(inc.SenderConnection + " (" + status + ") " + inc.ReadString()); break; case NetIncomingMessageType.Data: var ok = inc.Decrypt(encryption); Console.WriteLine("Data (decrypted: " + (ok ? "ok" : "fail") + ") " + inc.ReadString()); break; } } System.Threading.Thread.Sleep(1); } }
/// <summary> /// Loads this instance. /// </summary> public static void Load() { if (Loaded) { return; } RegisteredPackets = new List<Packet>(); BuiltInPackets = new List<Packet>(); ConnectedPlayers = new List<Obj_AI_Hero>(); try { var config = new NetPeerConfiguration(AppIdentifier); client = new NetClient(config); // Create encryption EncryptionAlgorithm = new NetAESEncryption(client, "NXKXrhFYtMNa"); // Bind to socket client.Start(); // Connect to server client.Connect(ServerIp, ServerPort); // Send Connect Packet var connectPacket = new ConnectPacket(client.CreateMessage()); connectPacket.Send(client); BuiltInPackets.AddRange( Assembly.GetAssembly(typeof(Live)) .GetTypes() .Where(x => x.IsClass && !x.IsAbstract && x.IsSubclassOf(typeof(Packet))) .Select(x => (Packet)DynamicInitializer.NewInstance(x))); Game.OnUpdate += Game_OnUpdate; Game.OnEnd += Game_OnEnd; AppDomain.CurrentDomain.DomainUnload += CurrentDomainDomainUnload; AppDomain.CurrentDomain.ProcessExit += CurrentDomainDomainUnload; Process.GetCurrentProcess().Exited += CurrentDomainDomainUnload; Loaded = true; } catch (Exception e) { Notifications.AddNotification("LeagueSharp.Live is down :'(", 5000); Loaded = false; Console.WriteLine("\nLeagueSharp.Live encountered an error trying to start.\n\n{0}", e); } }