static void Main(string[] args) { // create a configuration NetPeerConfiguration config = new NetPeerConfiguration("LidgrenChat"); // needs to be same on client and server! config.MaximumConnections = 64; config.Port = 7777; // Server configs if (File.Exists("serverconfig.txt")) { using (StreamReader sr = new StreamReader("serverconfig.txt")) { config.Port = Convert.ToInt32(sr.ReadLine().Split('=')[1]); algo = new NetXtea(sr.ReadLine().Split('=')[1]); adminCode = sr.ReadLine().Split('=')[1]; welcomeStr = sr.ReadLine().Split('=')[1]; } } server = new NetServer(config); server.Start(); Console.WriteLine("Server has started on port " + server.Port); while (true) { Update(); System.Threading.Thread.Sleep(50); // temp code } }
/// <summary> /// Constructor /// </summary> /// <param name="manager">Local NetPeer</param> /// <param name="con">NetConnection</param> /// <param name="key">Encryption key</param> /// <param name="nodeId">Node Id</param> public Connection(NetPeer manager, NetConnection con, INetEncryption encryption, String nodeId) { // This keep alive timer is used to overcome BAD connections that drop ping/pong messages a lot. // It simply sends an empty message every five seconds. As long as some messages are retained // and received on the connection, all will be well _keepAliveTimer = new System.Timers.Timer(5000); _keepAliveTimer.Elapsed += new ElapsedEventHandler((Object state, ElapsedEventArgs args) => this.SendMessage(this.NetManager.CreateMessage(0), NetDeliveryMethod.Unreliable)); this.Username = (con.Tag as Handshake).Username; this.NetManager = manager; this.NetConnection = con; this.NetConnection.Tag = this; this.NodeId = nodeId; if (encryption != null) { _netEncryption = encryption; } else { // You could write code that makes it possible to transfer users between server // where you don't have any encryption key YET. The place to start that would // be here. this.IsTransfering = true; _netEncryption = new NetXtea(new Byte[16]); } // Not connected until everything is done. System.Threading.Thread.MemoryBarrier(); _connected = true; _keepAliveTimer.Start(); }
/// <summary> /// Constructor /// </summary> /// <param name="manager">Local NetPeer</param> /// <param name="con">NetConnection</param> /// <param name="key">Encryption key</param> /// <param name="nodeId">Node Id</param> public Connection(NetPeer manager, NetConnection con, INetEncryption encryption, String nodeId) { NetManager = manager; NetConnection = con; _connected = true; _netEncryption = encryption; NetConnection.Tag = this; NodeId = nodeId; }
private static string[] CommandStrings; // pour les cmd recus des clients static Network() { NetPeerConfiguration config = new NetPeerConfiguration("the-morpher"); config.AutoFlushSendQueue = false; config.PingInterval = 1F; config.ConnectionTimeout = 10; //config.PingInterval = 100; //config.ConnectionTimeout = 600; netClient = new NetClient(config); netClient.RegisterReceivedCallback(new SendOrPostCallback(GotMessage)); algo = new NetXtea("the-morpher"); }
/// <summary> /// Constructor /// </summary> /// <param name="manager">Local NetPeer</param> /// <param name="con">NetConnection</param> /// <param name="key">Node Id</param> public Connection(NetPeer manager, NetConnection con, INetEncryption encryption) : this(manager, con, encryption, "SomeNodeIdGenerationCode") { }
/// <summary> /// Constructor /// </summary> /// <param name="manager"></param> /// <param name="con"></param> /// <param name="encryption"></param> public Connection(NetPeer manager, NetConnection con, INetEncryption encryption) : this(manager, con, encryption, String.Empty) { }
/// <summary> /// Sets the encryption for this connection (see the comments about transfering clients) /// </summary> /// <param name="key"></param> internal void SetEncryption(INetEncryption enc) { _netEncryption = enc; }
/// <summary> /// Encrypt this message using the provided algorithm; no more writing can be done before sending it or the message will be corrupt! /// </summary> public bool Encrypt(INetEncryption encryption) { return(encryption.Encrypt(this)); }
/// <summary> /// Encrypt this message using the provided algorithm; no more writing can be done before sending it or the message will be corrupt! /// </summary> public bool Encrypt(INetEncryption encryption) { return encryption.Encrypt(this); }
/// <summary> /// Sets the key (when transfered servers) /// </summary> /// <param name="key"></param> internal void SetEncryptionKey(Byte[] key) { _netEncryption = new NetXtea(key); }
private void Initialize() { Encryption = new NetXtea(GameServerConfiguration.EncryptionKey); #if DEBUG _configuration.SimulatedMinimumLatency = GameServerConfiguration.SimulatedMinimumLatency; _configuration.SimulatedRandomLatency = GameServerConfiguration.SimulatedRandomLatency; _configuration.SimulatedDuplicatesChance = GameServerConfiguration.SimulatedDuplicates; _configuration.SimulatedLoss = GameServerConfiguration.SimulatedPacketLoss; #endif if (_role == NetworkAgentRoleEnum.Server) { _configuration.EnableMessageType(NetIncomingMessageType.DiscoveryRequest); _configuration.Port = _port; //Casts the NetPeer to a NetServer _peer = new NetServer(_configuration); } else if (_role == NetworkAgentRoleEnum.Client) { _configuration.EnableMessageType(NetIncomingMessageType.DiscoveryResponse); //Casts the NetPeer to a NetClient _peer = new NetClient(_configuration); } _peer.Start(); _incomingMessages = new List<NetIncomingMessage>(); _outgoingMessage = _peer.CreateMessage(); }
static ChatMessage() { encrypter = new NetXorEncryption(secret); }