Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            // On the server a logon manager needs to be defined. Write a logonmanager class that handles logins
            NetLobby.LogonManager = new LogonManager(NetLobby.KeySize, "There is no secret.");
            StopRunningSemaphore  = new ManualResetEvent(false);

            PlayerDatabase.Add(PlayerDatabaseEntry.Generate("test", "pass", NetLobby.KeySize));

            var listener = new Listener();

            listener.OnConnected    += new Listener.ConnectionDelegate(listener_OnConnected);
            listener.OnDisconnected += new Listener.ConnectionDelegate(listener_OnDisconnected);

            listener.Start();
            Console.WriteLine(">> Server started. <<");

            // Runs this server until IsRunning is set to false
            StopRunningSemaphore.WaitOne();
            listener.IsRunning = false;
            Console.WriteLine(">> Server terminated. <<");
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Looks up username in the database. Provide data for more finegrained searches.
        /// </summary>
        /// <param name="username"></param>
        /// <param name="salt"></param>
        /// <returns></returns>
        public NetBigInteger Lookup(String username, Byte[] data, out Byte[] salt)
        {
            // SERVER LOOKUP
            // You could connect servers with eachother using this same protocol. Let's say we defined
            // this by passing 31 to data[0]. Safer would be to use a code generator, such as google
            // authenticator. It's very easy to implement and a lot more secure. But for the sake of
            // sample, this code allows a server to authenticate with username, pre-set _secret.

            // You could ALSO use data to decide between different servers (alpha, beta, gamma) but keep
            // the logging in centralized. Use it however you like.

            if (data != null && data.Length > 0 && data[0] == 31)
            {
                return(Handshake.PasswordVerifier(username, _secret, _keySize, out salt));
            }

            // USER LOOKUP
            // Here you would lookup the player from the database. A sample database entry class is
            // provided. Most safe would be to seperate verifier/salt data from player information
            // as you don't need the former after authentication.
            salt = new Byte[0];

            // Get salt and v from the database. This means that the verifier was already generated,
            // preferably on adding into the database. Make sure this step is secure.
            var player = PlayerDatabase.Find(username);

            if (player == null || String.IsNullOrEmpty(player.Username))
            {
                return(null);
            }
            if (player.IsBanned)
            {
                throw new Exception("That player (" + username + ") is banned.");
            }

            // Set salt and obtained username
            salt     = player.Salt;
            username = player.Username;
            return(new NetBigInteger(1, player.Verifier));
        }