private void Io_OnClientMessage(MasterControlClient session, RouterMessage msg)
 {
     if (session.authenticated)
     {
         //Authenticated commands
         if (msg.opcode == MasterConnectionOpcodes.OPCODE_MASTER_CONFIG)
         {
             HandleRequestConfigCommand(session, msg);
         }
         else if (msg.opcode == MasterConnectionOpcodes.OPCODE_MASTER_GETUSERCFG)
         {
             HandleGetUserConfigCmd(session, msg);
         }
         else if (msg.opcode == MasterConnectionOpcodes.OPCODE_MASTER_INSTANCE_LOG)
         {
             HandleInstanceLogCommand(session, msg);
         }
         else
         {
             logger.Log("Io_OnClientMessage", $"Client {session.GetDebugName()} sent an unknown command.", DeltaLogLevel.Debug);
         }
     }
     else
     {
         //Unauthenticated commands
         if (msg.opcode == MasterConnectionOpcodes.OPCODE_MASTER_LOGIN)
         {
             HandleLoginCommand(session, msg);
         }
         else
         {
             logger.Log("Io_OnClientMessage", $"Client {session.GetDebugName()} sent unauthenticated command that was not LOGIN.", DeltaLogLevel.Debug);
         }
     }
 }
 private void Io_OnClientDropped(MasterControlClient session)
 {
     logger.Log("Io_OnClientConnected", $"Dropped client {session.GetDebugName()}", DeltaLogLevel.Low);
     if (session.server != null)
     {
         session.server.DisconnectTransport();
     }
 }
        private void HandleLoginCommand(MasterControlClient session, RouterMessage msg)
        {
            //Get details
            int loginId = BitConverter.ToInt16(msg.payload, 0);

            byte[] loginKey = new byte[16];
            Array.Copy(msg.payload, 2, loginKey, 0, 16);

            //Search for a server
            DeltaManagerServer server = null;

            lock (Program.servers)
            {
                foreach (var s in Program.servers)
                {
                    if (s.id == loginId)
                    {
                        //Authenticate key
                        if (BinaryTool.CompareBytes(s.key, loginKey))
                        {
                            server = s;
                        }
                    }
                }
            }

            //Check if it was successful
            if (server != null)
            {
                //Set
                server.SetTransport(session);
                session.authenticated = true;

                //Log
                logger.Log("HandleLoginCommand", $"Client {session.GetDebugName()} successfully logged in as server ID {server.id}.", DeltaLogLevel.Low);
            }
            else
            {
                //Failed
                logger.Log("HandleLoginCommand", $"Client {session.GetDebugName()} attempted login, but failed.", DeltaLogLevel.Low);
            }
        }
 private void Io_OnClientConnected(MasterControlClient session)
 {
     logger.Log("Io_OnClientConnected", $"Connected client {session.GetDebugName()}", DeltaLogLevel.Low);
 }